* Fixed bug #12723: added popup menu to data dictionary editor

git-svn-id: trunk@20759 -
This commit is contained in:
michael 2009-06-27 15:52:21 +00:00
parent 18d16e10cf
commit 3588b71b7c
5 changed files with 167 additions and 10 deletions

1
.gitattributes vendored
View File

@ -4739,6 +4739,7 @@ tools/lazdatadesktop/bitmaps/btnup.bmp -text
tools/lazdatadesktop/bitmaps/btnup.xpm -text
tools/lazdatadesktop/bitmaps/ddconnection.png -text svneol=unset#image/png
tools/lazdatadesktop/bitmaps/dddatadict.png -text svneol=unset#image/png
tools/lazdatadesktop/bitmaps/dddeleteobject.png -text svneol=unset#image/png
tools/lazdatadesktop/bitmaps/dddomain.png -text svneol=unset#image/png
tools/lazdatadesktop/bitmaps/dddomains.png -text svneol=unset#image/png
tools/lazdatadesktop/bitmaps/ddfield.png -text svneol=unset#image/png

Binary file not shown.

After

Width:  |  Height:  |  Size: 619 B

View File

@ -1,7 +1,8 @@
#!/bin/sh
../../lazres ../dicteditor.lrs ddtables.png ddtable.png ddfields.png ddfield.png\
ddindexes.png ddindex.png ddforeignkeys.png ddforeignkey.png ddtabledata.png\
dddatadict.png ddconnection.png ddsequences.png ddsequence.png dddomains.png dddomain.png
dddatadict.png ddconnection.png ddsequences.png ddsequence.png dddomains.png dddomain.png\
dddeleteobject.png

View File

@ -247,3 +247,30 @@ LazarusResources.Add('dddomain','PNG',[
+#200#153'='#200#254#255'_8'#29#240#1#208#13#141#159'e?w'#168#0#0#0#0'IEND'
+#174'B`'#130
]);
LazarusResources.Add('dddeleteobject','PNG',[
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#16#0#0#0#16#8#2#0#0#0#144#145'h6'#0
+#0#0#6'tRNS'#0#0#0#0#0#0'n'#166#7#145#0#0#2' IDATx'#218'c`'#128#1'60'#224#227
+#227'srr'#242#242#242#178#179#179#211#209#209#129#139'3'#160#1#184'Pks'#225
+#135#183'7>}|'#249#238#237#147#227#199'v'#5#7#185#161')'#128'r'#4#4#4#14#29
+'Xzp'#255#210#170#202't'#15'w'#7'uuU3S'#189#246#214#162#5#243':'#22'/'#236'Z'
+#186#184#7'E'#143#182#182#246#229#139'{'#238#220':'#242#232#193#249#157#219
+#23#165'$E[Z'#152#217#216#24'''&'#4#207#154#209#188'}'#235#236#205#155'f,Y'
+#212#141#226#164#23'O.'#249#248#242#211#199''''#175'^'#222'z'#250#232#210
+#213'K'#251#14#31'\'#190'~'#237#148#3#251#150#28';'#178'f'#199#182'9'#149#229
+'i('#26#186':K?'#190#189#244#251#199#203#159'_'#223#254#248#254#238#199#247
+'7_??{'#243#234#230#189#187#167#231#206#238'LN'#10#137#8#247'B'#209#16#20#232
+'V\'#152':'#238#196''''#15'O'#188'|z'#254#209#131#211#23'/'#158#238#235#173
+'/+M'#201'H'#143'pv'#178#208#212'PB'#209' //mbb'#224#237#233#146#145#158'T'
+#144#159#150#157#157#146#151#19#27#17#238'mii(.&*%%&/'''#137#162'AKKy'#193
+#130#169#190#190#14'ff'#6'ZZj'#250#250'Z'#252#252#188#220#220#156#2#2#188'vv'
+#22'&&'#218'**'#242'('#26#180#181'U'#150'.'#153#185'}'#219#186#194#130#244
+#133#11''''#149#20''';8'#152'ffF[Z'#234'gf'#198#219#219#155#168#169')'#160'h'
+#208#209'Q]'#187'v'#241#205#155#151#186#187#235#175']='#215#209'Q'#29#17#238
+'?yr'#187#151#151'mEEv@'#128#147#166#166#18#22#13#183'n]'#238#239'k'#188'{'
+#247#202#154#213'3cc'#131#22','#152#12'tdee'#14#22#13'@'''#213#213#149#222
+#184'q'#177#183#183#225#238#221#203#200#26#128'6'#184#184'Xh'#160#133#146#186
+#186#162#179#179'm__[\\'#232#173'['#23' '#26#166'Li'#1'j'#136#141#13#6#170'V'
+'V'#150'EO|'#16#224#228'h'#213#223'_]U'#149#227#226'b'#147#147#19'gj'#170#163
+#167#167#137#158#248#208#180#1#25#252#252#252#172#172#172'X'#210')'#3#3#0'0'
+#176#228#240#198#251#5#222#0#0#0#0'IEND'#174'B`'#130
]);

View File

@ -29,7 +29,7 @@ interface
uses
Classes, SysUtils, FileUtil, fpdatadict, Controls, ComCtrls, StdCtrls,
ExtCtrls, Graphics, ImgList, RTTIGrids, LResources;
ExtCtrls, Graphics, ImgList, RTTIGrids, LResources, menus, dialogs;
Type
TEditObjectType = (eotUnknown,eotDictionary,
@ -60,11 +60,23 @@ Type
FAllowDoubleClick : TEditObjectType;
FDDNode,
FTablesNode : TTreeNode;
FMenu : TPopupMenu;
FMINewTable,
FMINewField,
FMINewIndex,
FMINewSequence,
FMINewForeignKey,
FMINewDomain,
FMIDeleteObject: TMenuItem;
{$ifndef onlyoldobjects}
FSequencesNode,
FDomainsNode : TTreeNode;
{$endif}
Function AddNewItemPopup(ObjectType: TEditObjectType; AImageIndex : Integer) : TMenuItem;
procedure CreateGUI;
procedure DoDoubleClick(Sender: TObject);
procedure DoNewObject(Sender: TObject);
procedure DoDeleteObject(Sender: TObject);
function CurrentObjectWithType(AType: TEditObjectType): TObject;
function GetCurrentObject: TPersistent;
Function NewNode (TV : TTreeView;ParentNode : TTreeNode; ACaption : String; AImageIndex : Integer) : TTreeNode;
@ -87,6 +99,7 @@ Type
function GetCurrentForeignKey : TDDForeignKeyDef;
function GetCurrentDomain : TDDDomainDef;
{$endif}
procedure DoPopup(Sender: TObject);
Procedure DeleteGlobalObject(AObject : TObject);
Procedure DeleteTableObject(AObject : TObject);
procedure SelectGlobalObjectList(AObjectType: TEditObjectType);
@ -156,12 +169,12 @@ Const
iiForeignKey = 12;
iiDomains = 13;
iiDomain = 14;
IIMaxObject = IIDomain; // Should be last
iiDelete = iiMaxObject+1;
implementation
uses DB, MemDS, Dialogs, fpcodegenerator;
uses DB, MemDS, fpcodegenerator, TypInfo;
ResourceString
SNodeDataDictionary = 'Datadictionary';
@ -172,6 +185,37 @@ ResourceString
SNodeForeignkeys = 'Foreign keys';
SNewDictionary = 'New dictionary';
SNodeIndexes = 'Indexes';
STable = 'Table';
SField = 'Field';
SIndex = 'Index';
SSequence = 'Sequence';
SForeignKey = 'Foreign key';
SDomain = 'Domain';
SNew = 'New %s';
SErrUnknownType = 'Unknown object type: %d';
SNewObject = 'Create new %s';
SNameFor = 'Enter a name for the new %s';
SDeleteObject = 'Delete this %s';
SObject = 'Object';
Function ObjectTypeName(ObjectType : TEditObjectType) : String;
Var
S : String;
begin
Case ObjectType of
eotTable : S:=STable;
eotField : S:=SField;
eotIndex : S:=SIndex;
eotSequence : S:=SSequence;
eotForeignKey : S:=SForeignKey;
eotDomain : S:=SDomain
else
Raise EDataDict.CreateFmt(SErrUnknownType,[Ord(ObjectType)]);
end;
Result:=S;
end;
Function CreateDatasetFromTabledef(TD : TDDTableDef;AOwner : TComponent = Nil) : TDataset;
@ -285,24 +329,68 @@ begin
end;
{$endif onlyoldobjects}
procedure TDataDictEditor.DoPopup(Sender: TObject);
Var
B : Boolean;
EOT : TEditObjectType;
begin
// Check availablility of items;
B:=CurrentTable<>Nil;
FMINewField.Enabled:=B;
FMINewIndex.Enabled:=B;
FMINewForeignKey.Enabled:=B;
EOT:=ObjectType;
B:=EOT in SingleObjectTypes;
FMIDeleteObject.Enabled:=B;
If B then
FMIDeleteObject.Caption:=Format(SDeleteObject,[ObjectTypeName(EOT)])
else
FMIDeleteObject.Caption:=Format(SDeleteObject,[SObject]);
end;
Function TDataDictEditor.AddNewItemPopup(ObjectType : TEditObjectType; AImageIndex : Integer) : TMenuItem;
Var
S: String;
begin
Result:=TMenuItem.Create(Self);
Result.Name:='NewItem'+GetEnumName(TypeInfo(TEditObjectType),Ord(ObjectType));
Result.Tag:=Ord(ObjectType);
S:=ObjectTypeName(ObjectType);
Result.Caption:=Format(SNew,[S]);
Result.OnClick:=@DoNewObject;
Result.ImageIndex:=AImageIndex;
FMenu.Items.Add(Result);
end;
constructor TDataDictEditor.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FDD:=TFPDataDictionary.Create;
CreateGUI;
end;
Procedure TDataDictEditor.CreateGUI;
Const
ImageNames : Array[0..IIMaxObject] of string =
ImageNames : Array[0..IIMaxObject+1] of string =
('dddatadict','ddtables','ddtable','ddfields','ddfield',
'ddtables','ddtabledata','ddindexes','ddindex',
'ddsequences','ddsequence',
'ddforeignkeys','ddforeignkey',
'dddomains','dddomain');
'dddomains','dddomain','dddeleteobject');
Var
P : TPortableNetworkGraphic;
I : Integer;
begin
inherited Create(AOwner);
FDD:=TFPDataDictionary.Create;
FEdit:=TPanel.Create(Self);
FEdit.Parent:=Self;
FEdit.Name:='FEdit';
@ -318,8 +406,23 @@ begin
FTV.Align:=alClient;
FTV.OnSelectionChanged:=@DoSelectNode;
FTV.ShowLines:=True;
FMenu:=TPopupMenu.Create(Self);
FMenu.Name:='FMenu';
FMenu.OnPopup:=@DoPopup;
FMINewTable:=AddNewItemPopup(eotTable,iiTable);
FMINewField:=AddNewItemPopup(eotField,iiField);
FMINewIndex:=AddNewItemPopup(eotIndex,iiIndex);
FMINewSequence:=AddNewItemPopup(eotSequence,iiSequence);
FMINewForeignKey:=AddNewItemPopup(eotForeignKey,iiForeignKey);
FMINewDomain:=AddNewItemPopup(eotDomain,iiDomain);
FMIDeleteObject:=TMenuItem.Create(Self);
FMIDeleteObject.Caption:=Format(SDeleteObject,[SObject]);
FMIDeleteObject.OnClick:=@DoDeleteObject;
FMIDeleteObject.ImageIndex:=IIDelete;
FMenu.Items.Add(FMIDeleteObject);
FTV.PopupMenu:=FMenu;
FIMgList:=TImageList.Create(Self);
For I:=0 to 14 do
For I:=0 to IIMaxObject+1 do
begin
P:=TPortableNetworkGraphic.Create;
try
@ -330,6 +433,7 @@ begin
end;
end;
FTV.Images:=FImgList;
FMenu.Images:=FImgList;
ShowDictionary;
end;
@ -595,7 +699,31 @@ begin
FTV.Selected:=FindNodeWithData(FTV,N.Data);
end;
procedure TDataDictEditor.DoNewObject(Sender: TObject);
Var
EOT : TEditObjectType;
S,N : String;
begin
EOT:=TEditObjectType((Sender as TMenuItem).Tag);
S:=ObjectTypeName(EOT);
if InputQuery(Format(SNewObject,[S]),Format(SNameFor,[S]),N) then
begin
case EOT of
eotField : NewField(N,CurrentTable);
eotIndex : NewIndex(N,CurrentTable);
eotForeignKey : NewIndex(N,CurrentTable);
else
NewGlobalObject(N,EOT);
end;
end;
end;
procedure TDataDictEditor.DoDeleteObject(Sender: TObject);
begin
DeleteCurrentObject;
end;
function TDataDictEditor.SelectNextNode(ANode: TTreeNode; ADefault : TTreeNode): TTreeNode;