Ignore:
Timestamp:
Jun 3, 2010, 5:25:10 PM (14 years ago)
Author:
george
Message:
  • Přidáno: Knihovna pro uchování stavu rozevření stromu.
  • Přidáno: Ikonky stromu skupin.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UMainForm.pas

    r3 r4  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
    9   StdCtrls, USqlDatabase, DOM, XMLRead, XMLWrite, UPersistentForm, UItemView;
     9  StdCtrls, ActnList, Menus, ExtCtrls, USqlDatabase, DOM, XMLRead, XMLWrite,
     10  UPersistentForm, UTreeState;
    1011
    1112const
     
    1314
    1415type
     16  TValueType = (vtNone, vtInteger, vtString, vtText, vtDateTime, vtFloat, vtImage, vtBoolean,
     17  vtIPv4, vtMAC, vtIPv6, vtFile, vtGPS, vtEnumeration, vtHyperlink, vtPassword,
     18  vtReference, vtDate, vtTime, vtColor);
    1519
    1620  { TMainForm }
    1721
    1822  TMainForm = class(TForm)
     23    AObjectGroupEdit: TAction;
     24    AObjectGroupAddObject: TAction;
     25    AObjectGroupAddGroup: TAction;
     26    AObjectGroupDelete: TAction;
     27    AItemView: TAction;
     28    AItemEdit: TAction;
     29    AItemAdd: TAction;
     30    AItemDelete: TAction;
     31    ActionListItem: TActionList;
     32    ButtonAdd: TButton;
     33    ButtonRemove: TButton;
     34    ImageListActions: TImageList;
    1935    Label1: TLabel;
    2036    Label2: TLabel;
    2137    ListView1: TListView;
     38    MenuItem1: TMenuItem;
     39    MenuItem2: TMenuItem;
     40    MenuItem3: TMenuItem;
     41    MenuItem4: TMenuItem;
     42    MenuItem5: TMenuItem;
     43    MenuItem6: TMenuItem;
     44    MenuItem7: TMenuItem;
     45    MenuItem8: TMenuItem;
     46    Panel1: TPanel;
     47    Panel2: TPanel;
     48    PopupMenuObjectGroup: TPopupMenu;
     49    PopupMenuObject: TPopupMenu;
     50    PopupMenuItem: TPopupMenu;
     51    Splitter1: TSplitter;
    2252    TreeView1: TTreeView;
     53    procedure AItemAddExecute(Sender: TObject);
     54    procedure AItemEditExecute(Sender: TObject);
     55    procedure AItemViewExecute(Sender: TObject);
     56    procedure AObjectGroupAddGroupExecute(Sender: TObject);
     57    procedure ButtonAddClick(Sender: TObject);
    2358    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    2459    procedure FormCreate(Sender: TObject);
     60    procedure FormDestroy(Sender: TObject);
    2561    procedure FormShow(Sender: TObject);
    2662    procedure ListView1DblClick(Sender: TObject);
     
    3773    PersistentForm: TPersistentForm;
    3874    Database: TSQLDatabase;
     75    TreeState: TTreeState;
    3976    procedure LoadTree;
    4077    procedure LoadItemList;
     
    4582
    4683implementation
     84
     85uses
     86  UItemView, UItemEdit;
    4787
    4888{$R *.lfm}
     
    87127  LoadConfiguration;
    88128  Database.Connect;
     129  TreeState := TTreeState.Create;
    89130  PersistentForm := TPersistentForm.Create;
    90131end;
    91132
     133procedure TMainForm.FormDestroy(Sender: TObject);
     134begin
     135  TreeState.Destroy;
     136  Database.Destroy;
     137  PersistentForm.Destroy;
     138end;
     139
    92140procedure TMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    93141begin
    94142  PersistentForm.Save(Self);
     143end;
     144
     145procedure TMainForm.ButtonAddClick(Sender: TObject);
     146begin
     147
     148end;
     149
     150procedure TMainForm.AItemViewExecute(Sender: TObject);
     151begin
     152  ItemViewForm.Show;
     153end;
     154
     155procedure TMainForm.AObjectGroupAddGroupExecute(Sender: TObject);
     156begin
     157
     158end;
     159
     160procedure TMainForm.AItemEditExecute(Sender: TObject);
     161begin
     162  ItemEditForm.Show;
     163end;
     164
     165procedure TMainForm.AItemAddExecute(Sender: TObject);
     166begin
     167
    95168end;
    96169
     
    103176procedure TMainForm.ListView1DblClick(Sender: TObject);
    104177begin
    105   ItemViewForm.Show;
     178  AItemViewExecute(Self);
    106179end;
    107180
    108181procedure TMainForm.ListView1KeyPress(Sender: TObject; var Key: char);
    109182begin
    110   if Key = #13 then ListView1DblClick(Sender);
     183  if Key = #13 then AItemViewExecute(Self);
    111184end;
    112185
     
    125198    SelectedItem := Integer(ListView1.Selected.Data)
    126199    else SelectedItem := 0;
     200
     201  AItemDelete.Enabled := Assigned(ListView1.Selected);
     202  AItemView.Enabled := Assigned(ListView1.Selected);
     203  AItemEdit.Enabled := Assigned(ListView1.Selected);
    127204end;
    128205
     
    130207begin
    131208  LoadItemList;
     209  AObjectGroupDelete.Enabled := Assigned(TreeView1.Selected);
     210  AObjectGroupEdit.Enabled := Assigned(TreeView1.Selected);
     211  if Assigned(TreeView1.Selected) then begin
     212    if TreeView1.Selected.ImageIndex = 0 then
     213      TreeView1.PopupMenu := PopupMenuObjectGroup;
     214    if TreeView1.Selected.ImageIndex = 1 then
     215      TreeView1.PopupMenu := PopupMenuObject;
     216  end;
    132217end;
    133218
     
    142227begin
    143228  with TreeView1, Items do begin
     229    TreeState.SaveTree(TreeView1);
    144230    Clear;
    145231    AddChild(nil, 'Skupiny');
    146     DbRows := Database.Query('SELECT * FROM `MenuGroup`');
     232    TopItem.ImageIndex := 0;
     233    TopItem.SelectedIndex := 0;
     234    DbRows := Database.Query('SELECT * FROM `ObjectGroup`');
    147235    for I := 0 to DbRows.Count - 1 do begin
    148236      NewNode := AddChild(TopItem, DbRows[I].Values['Name']);
    149       ObjectDbRows := Database.Query('SELECT * FROM `Object` WHERE `MenuGroup`=' + DbRows[I].Values['Id']);
     237      NewNode.ImageIndex := 0;
     238      NewNode.SelectedIndex := 0;
     239      ObjectDbRows := Database.Query('SELECT * FROM `Object` WHERE `Group`=' + DbRows[I].Values['Id']);
    150240      for O := 0 to ObjectDbRows.Count - 1 do begin
    151241        NewObjectNode := AddChild(NewNode, ObjectDbRows[O].Values['Name']);
    152         NewObjectNode.ImageIndex := StrToInt(ObjectDbRows[O].Values['Id']);
     242        NewObjectNode.Data := Pointer(StrToInt(ObjectDbRows[O].Values['Id']));
     243        NewObjectNode.ImageIndex := 1;
     244        NewObjectNode.SelectedIndex := 1;
    153245      end;
    154246      ObjectDbRows.Destroy;
     
    156248    TopItem.Expand(True);
    157249    DbRows.Destroy;
     250    TreeState.LoadTree(TreeView1);
    158251  end;
    159252end;
     
    173266  with ListView1, Items do begin
    174267    Clear;
    175     DbRows := Database.Query('SELECT * FROM `Object` WHERE `Id`=' + IntToStr(TreeView1.Selected.ImageIndex));
     268    DbRows := Database.Query('SELECT * FROM `Object` WHERE `Id`=' + IntToStr(Integer(TreeView1.Selected.Data)));
    176269    if DbRows.Count = 1 then begin
    177270      SelectedObject := StrToInt(DbRows[0].Values['Id']);
Note: See TracChangeset for help on using the changeset viewer.