Ignore:
Timestamp:
Nov 24, 2011, 10:03:48 AM (13 years ago)
Author:
chronos
Message:
  • Modified: Item list is separated from MainForm as ItemListForm.
  • Modified: Now it is possible to open multiple forms for same operation as View, Edit, Add, List. Open forms are listed in main windows tab list.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UMainForm.pas

    r30 r31  
    2929    AObjectGroupAddGroup: TAction;
    3030    AObjectGroupDelete: TAction;
    31     AItemView: TAction;
    32     AItemEdit: TAction;
    33     AItemAdd: TAction;
    34     AItemDelete: TAction;
    3531    ActionListItem: TActionList;
    36     ButtonEdit: TButton;
    37     ButtonView: TButton;
    38     ButtonAdd: TButton;
    39     ButtonDelete: TButton;
    4032    ImageListActions: TImageList;
    4133    Label1: TLabel;
    42     Label2: TLabel;
    43     ListView1: TListView;
    4434    MainMenu1: TMainMenu;
    4535    MenuItem1: TMenuItem;
     
    6454    MenuItem8: TMenuItem;
    6555    MenuItem9: TMenuItem;
     56    PageControl1: TPageControl;
    6657    Panel1: TPanel;
    6758    Panel2: TPanel;
     
    7667    procedure AExitExecute(Sender: TObject);
    7768    procedure AImportStructureExecute(Sender: TObject);
    78     procedure AItemAddExecute(Sender: TObject);
    79     procedure AItemDeleteExecute(Sender: TObject);
    80     procedure AItemEditExecute(Sender: TObject);
    81     procedure AItemViewExecute(Sender: TObject);
    8269    procedure AObjectEditExecute(Sender: TObject);
    8370    procedure AObjectGroupAddGroupExecute(Sender: TObject);
     
    8572    procedure ASettingsExecute(Sender: TObject);
    8673    procedure AToggleFullscreenExecute(Sender: TObject);
    87     procedure ButtonAddClick(Sender: TObject);
    8874    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    8975    procedure FormCreate(Sender: TObject);
    9076    procedure FormDestroy(Sender: TObject);
    9177    procedure FormShow(Sender: TObject);
    92     procedure ListView1Data(Sender: TObject; Item: TListItem);
    93     procedure ListView1DblClick(Sender: TObject);
    94     procedure ListView1KeyPress(Sender: TObject; var Key: char);
    95     procedure ListView1Resize(Sender: TObject);
    96     procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
    97       Selected: Boolean);
    9878    procedure MenuItem17Click(Sender: TObject);
    9979    procedure MenuItem19Click(Sender: TObject);
    10080    procedure TreeView1Change(Sender: TObject; Node: TTreeNode);
     81    procedure TreeView1DblClick(Sender: TObject);
    10182  private
    10283    OriginalBounds: TRect;
     
    10687    procedure SaveToRegistry;
    10788  public
    108     SelectedObjectId: Integer;
    109     SelectedObject: TChronisObject;
    110     SelectedItem: Integer;
    11189    PersistentForm: TPersistentForm;
    11290    TreeState: TTreeState;
    11391    Report: TReport;
     92    TabForms: TListObject; // TListObject<TForm>
    11493    procedure UpdateInterface;
    11594    procedure LoadTree;
    116     procedure LoadItemList;
    117   end; 
     95    procedure AddTabForm(Form: TForm);
     96  end;
    11897
    11998var
     
    132111uses
    133112  UItemView, UItemEdit, UItemAdd, ULoginForm, USettingForm, UApplicationInfo,
    134   UCore, UImportStructureForm, UAboutForm, ULoginProfileForm, UChronisClientDirect;
     113  UCore, UImportStructureForm, UAboutForm, ULoginProfileForm, UChronisClientDirect,
     114  UItemList;
    135115
    136116{$R *.lfm}
     
    175155procedure TMainForm.FormCreate(Sender: TObject);
    176156begin
     157  TabForms := TListObject.Create;
     158  TabForms.OwnsObjects := False;
    177159  TreeState := TTreeState.Create;
    178160  Report := TReport.Create;
    179161  Report.Base := Core.System;
    180   SelectedObject := TChronisObject.Create;
    181   SelectedObject.Base := Core.System;
    182162  PersistentForm := TPersistentForm.Create;
    183163  PersistentForm.RegistryKey := Core.RegistryKey;
     
    189169  TreeState.Free;
    190170  PersistentForm.Free;
     171  TabForms.Free;
    191172end;
    192173
    193174procedure TMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    194175begin
     176  ADisconnect.Execute;
    195177  PersistentForm.Save(Self);
    196178  SaveToRegistry;
    197179end;
    198180
    199 procedure TMainForm.ButtonAddClick(Sender: TObject);
    200 begin
    201 
    202 end;
    203 
    204 procedure TMainForm.AItemViewExecute(Sender: TObject);
    205 begin
    206   if Assigned(ListView1.Selected) then
    207     ItemViewForm.Show;
    208 end;
    209 
    210181procedure TMainForm.AObjectEditExecute(Sender: TObject);
    211182begin
    212   if Assigned(TreeView1.Selected) then begin
     183(*  if Assigned(TreeView1.Selected) then begin
    213184    SelectedObjectId := 9;
    214185    SelectedItem := Integer(TreeView1.Selected.Data);
    215186    ItemEditForm.Show;
    216   end;
     187  end;*)
    217188end;
    218189
     
    224195procedure TMainForm.AObjectGroupEditExecute(Sender: TObject);
    225196begin
    226   if Assigned(TreeView1.Selected) then begin
     197(*  if Assigned(TreeView1.Selected) then begin
    227198    SelectedObjectId := 8;
    228199    SelectedItem := Integer(TreeView1.Selected.Data);
    229200    ItemEditForm.Show;
    230   end;
     201  end;*)
    231202end;
    232203
     
    263234end;
    264235
    265 procedure TMainForm.AItemEditExecute(Sender: TObject);
    266 begin
    267   ItemEditForm.Show;
    268 end;
    269 
    270236procedure TMainForm.AExitExecute(Sender: TObject);
    271237begin
     
    276242begin
    277243  ImportStructureForm.ShowModal;
    278 end;
    279 
    280 procedure TMainForm.AItemAddExecute(Sender: TObject);
    281 begin
    282   ItemAddForm.ShowModal;
    283 end;
    284 
    285 procedure TMainForm.AItemDeleteExecute(Sender: TObject);
    286 begin
    287   if MessageDlg(SItemDeletion, SReallyWantToDelete, mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin
    288 
    289   end;
    290244end;
    291245
     
    315269procedure TMainForm.ADisconnectExecute(Sender: TObject);
    316270begin
    317   Core.System.Database.Disconnect;
    318   TreeView1.Items.Clear;
    319   ListView1.Items.Clear;
    320   Core.System.Types.Clear;
    321   FreeAndNil(Core.Client);
     271  if Core.System.Database.Connected then begin
     272    Core.System.Database.Disconnect;
     273    TreeView1.Items.Clear;
     274    Core.System.Types.Clear;
     275    FreeAndNil(Core.Client);
     276  end;
    322277end;
    323278
    324279procedure TMainForm.AAboutExecute(Sender: TObject);
    325280begin
    326   AboutForm.ShowModal;
     281  try
     282    AboutForm := TAboutForm.Create(nil);
     283    AboutForm.ShowModal;
     284  finally
     285    FreeAndNil(AboutForm);
     286  end;
    327287end;
    328288
     
    332292  LoadFromRegistry;
    333293  AConnect.Execute;
    334 end;
    335 
    336 procedure TMainForm.ListView1Data(Sender: TObject; Item: TListItem);
    337 var
    338   I: Integer;
    339 begin
    340   if Item.Index < Report.Count then
    341   with TReportLine(Report[Item.Index]) do begin
    342     Item.Caption := Items[0];
    343     for I := 1 to Report.Columns.Count - 1 do
    344     if not TReportColumn(Report.Columns[I]).VirtualItem then begin
    345       Item.SubItems.Add(Items[I]);
    346     end;
    347   end;
    348 end;
    349 
    350 procedure TMainForm.ListView1DblClick(Sender: TObject);
    351 begin
    352   AItemViewExecute(Self);
    353 end;
    354 
    355 procedure TMainForm.ListView1KeyPress(Sender: TObject; var Key: char);
    356 begin
    357   if Key = #13 then AItemViewExecute(Self);
    358 end;
    359 
    360 procedure TMainForm.ListView1Resize(Sender: TObject);
    361 var
    362   I: Integer;
    363 begin
    364   for I := 0 to ListView1.Columns.Count - 1 do
    365     ListView1.Columns[I].Width := ListView1.Width div ListView1.Columns.Count;
    366 end;
    367 
    368 procedure TMainForm.ListView1SelectItem(Sender: TObject; Item: TListItem;
    369   Selected: Boolean);
    370 begin
    371   if Assigned(ListView1.Selected) then
    372     SelectedItem := TReportLine(Report[ListView1.Selected.Index]).Id
    373     else SelectedItem := 0;
    374 
    375   ButtonDelete.Enabled := Assigned(ListView1.Selected);
    376   ButtonView.Enabled := Assigned(ListView1.Selected);
    377   ButtonEdit.Enabled := Assigned(ListView1.Selected);
    378294end;
    379295
     
    395311    if TreeView1.Selected.ImageIndex = 0 then begin
    396312      TreeView1.PopupMenu := PopupMenuObjectGroup;
    397       ListView1.Visible := False;
     313      PageControl1.Visible := False;
    398314    end;
    399315    if TreeView1.Selected.ImageIndex = 1 then begin
    400316      TreeView1.PopupMenu := PopupMenuObject;
    401       LoadItemList;
    402     end;
     317      //LoadItemList;
     318    end;
     319  end;
     320end;
     321
     322procedure TMainForm.TreeView1DblClick(Sender: TObject);
     323var
     324  NewItemListForm: TItemListForm;
     325begin
     326  if Assigned(TreeView1.Selected) then begin
     327    NewItemListForm := TItemListForm.Create(Self);
     328    NewItemListForm.SelectedObject.Id := Integer(TreeView1.Selected.Data);
     329    AddTabForm(NewItemListForm);
    403330  end;
    404331end;
     
    448375end;
    449376
    450 procedure TMainForm.LoadItemList;
     377procedure TMainForm.AddTabForm(Form: TForm);
    451378var
    452   NewColumn: TListColumn;
    453   I: Integer;
    454 begin
    455   SelectedObjectId := 0;
    456   if Assigned(TreeView1.Selected) then
    457   with ListView1 do begin
    458     Visible := True;
    459     SelectedObject.Load(Integer(TreeView1.Selected.Data));
    460     Report.Load(SelectedObject);
    461 
    462     Report.FillListColumns(Columns);
    463     Items.Count := Report.Count;
    464     Refresh;
    465   end;
    466   ListView1Resize(Self);
    467   ListView1SelectItem(Self, nil, False);
     379  NewTabSheet: TTabSheet;
     380begin
     381  TabForms.Add(Form);
     382  NewTabSheet := PageControl1.AddTabSheet;
     383  NewTabSheet.DockSite := True;
     384  NewTabSheet.UseDockManager := True;
     385  NewTabSheet.Caption := Form.Caption;
     386  Form.DragKind := dkDock;
     387  Form.DragMode := dmAutomatic;
     388  Form.Show;
     389  Form.ManualDock(NewTabSheet);
     390  PageControl1.TabIndex := PageControl1.PageCount - 1;
    468391end;
    469392
Note: See TracChangeset for help on using the changeset viewer.