Permalink
Browse files

* unify context menu of various sql editors, by supporting all contai…

…ned editors instead of searching for one with the name "SynMemoBody"

* disable actions which need to modify the contents on readonly editors
* add "save to textfile" and "un/comment" actions to the unified context menu
  • Loading branch information...
ansgarbecker committed May 18, 2017
1 parent 7a48774 commit a50c21a38322f8eed7f86e88906866ff9746cde4
Showing with 41 additions and 79 deletions.
  1. +24 −2 source/helpers.pas
  2. +10 −1 source/main.pas
  3. +0 −15 source/routine_editor.dfm
  4. +0 −4 source/routine_editor.pas
  5. +0 −42 source/table_editor.dfm
  6. +7 −15 source/table_editor.pas
View
@@ -1854,6 +1854,7 @@ procedure TDBObjectEditor.Init(Obj: TDBObject);
SynMemo: TSynMemo;
popup: TPopupMenu;
Item: TMenuItem;
i: Integer;
begin
Mainform.ShowStatusMsg(_('Initializing editor ...'));
Mainform.LogSQL(Self.ClassName+'.Init, using object "'+Obj.Name+'"', lcDebug);
@@ -1867,23 +1868,44 @@ procedure TDBObjectEditor.Init(Obj: TDBObject);
if Assigned(editName) and editName.CanFocus then
editName.SetFocus;
end;
SynMemo := FindComponent('SynMemoBody') as TSynMemo;
if Assigned(SynMemo) and (not Assigned(SynMemo.PopupMenu)) then begin
for i:=0 to ComponentCount-1 do begin
if not(Components[i] is TSynMemo) then
Continue;
SynMemo := Components[i] as TSynMemo;
if (not Assigned(SynMemo)) or Assigned(SynMemo.PopupMenu) then
Continue;
popup := TPopupMenu.Create(Self);
popup.Images := MainForm.ImageListMain;
Item := TMenuItem.Create(popup);
Item.Action := MainForm.actCopy;
popup.Items.Add(Item);
Item := TMenuItem.Create(popup);
Item.Action := MainForm.actCut;
popup.Items.Add(Item);
Item := TMenuItem.Create(popup);
Item.Action := MainForm.actPaste;
popup.Items.Add(Item);
Item := TMenuItem.Create(popup);
Item.Action := MainForm.actSelectAll;
popup.Items.Add(Item);
Item := TMenuItem.Create(popup);
Item.Action := MainForm.actSaveSynMemoToTextfile;
popup.Items.Add(Item);
Item := TMenuItem.Create(popup);
Item.Action := MainForm.actToggleComment;
popup.Items.Add(Item);
SynMemo.PopupMenu := popup;
end;
end;
View
@@ -5394,6 +5394,7 @@ procedure TMainForm.ValidateControls(Sender: TObject);
inDataTab, inDataOrQueryTab, inDataOrQueryTabNotEmpty, inGrid: Boolean;
GridHasChanges, EnableTimestamp: Boolean;
Grid: TVirtualStringTree;
inSynMemo, inSynMemoEditable: Boolean;
Results: TDBQuery;
RowNum: PInt64;
begin
@@ -5438,7 +5439,15 @@ procedure TMainForm.ValidateControls(Sender: TObject);
actExportData.Enabled := inDataOrQueryTabNotEmpty;
actDataSetNull.Enabled := inDataOrQueryTab and Assigned(Results) and Assigned(Grid.FocusedNode);
actSaveSynMemoToTextfile.Enabled := ActiveSynMemo(True) <> nil;
inSynMemo := ActiveSynMemo(True) <> nil;
inSynMemoEditable := inSynMemo and (not ActiveSynMemo(True).ReadOnly);
actSaveSynMemoToTextfile.Enabled := inSynMemo;
actToggleComment.Enabled := inSynMemoEditable;
if inSynMemo then begin
actCut.Enabled := inSynMemoEditable;
actPaste.Enabled := inSynMemoEditable;
end;
ValidateQueryControls(Sender);
UpdateLineCharPanel;
View
@@ -394,7 +394,6 @@ object frmRoutineEditor: TfrmRoutineEditor
Font.Height = -13
Font.Name = 'Courier New'
Font.Style = []
PopupMenu = popupSQLmemo
TabOrder = 0
Gutter.Font.Charset = DEFAULT_CHARSET
Gutter.Font.Color = clWindowText
@@ -419,18 +418,4 @@ object frmRoutineEditor: TfrmRoutineEditor
Images = MainForm.ImageListMain
TabOrder = 5
end
object popupSQLmemo: TPopupMenu
Images = MainForm.ImageListMain
Left = 47
Top = 244
object Selectall1: TMenuItem
Action = MainForm.actSelectAll
end
object Copy1: TMenuItem
Action = MainForm.actCopy
end
object Saveastextfile1: TMenuItem
Action = MainForm.actSaveSynMemoToTextfile
end
end
end
@@ -44,10 +44,6 @@ TfrmRoutineEditor = class(TFrame)
btnMoveUpParam: TToolButton;
btnMoveDownParam: TToolButton;
lblDisabledWhy: TLabel;
popupSQLmemo: TPopupMenu;
Selectall1: TMenuItem;
Copy1: TMenuItem;
Saveastextfile1: TMenuItem;
spltTop: TSplitter;
procedure comboTypeSelect(Sender: TObject);
procedure btnSaveClick(Sender: TObject);
View
@@ -183,10 +183,6 @@ object frmTableEditor: TfrmTableEditor
object tabBasic: TTabSheet
Caption = 'Basic'
ImageIndex = 14
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0
DesignSize = (
686
121)
@@ -232,10 +228,6 @@ object frmTableEditor: TfrmTableEditor
object tabOptions: TTabSheet
Caption = 'Options'
ImageIndex = 39
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0
DesignSize = (
686
121)
@@ -508,10 +500,6 @@ object frmTableEditor: TfrmTableEditor
object tabForeignKeys: TTabSheet
Caption = 'Foreign keys'
ImageIndex = 136
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0
object tlbForeignKeys: TToolBar
Left = 0
Top = 0
@@ -630,10 +618,6 @@ object frmTableEditor: TfrmTableEditor
object tabPartitions: TTabSheet
Caption = 'Partitions'
ImageIndex = 186
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0
object SynMemoPartitions: TSynMemo
Left = 0
Top = 0
@@ -646,7 +630,6 @@ object frmTableEditor: TfrmTableEditor
Font.Height = -13
Font.Name = 'Courier New'
Font.Style = []
PopupMenu = popupSQLmemo
TabOrder = 0
Gutter.AutoSize = True
Gutter.DigitCount = 2
@@ -668,10 +651,6 @@ object frmTableEditor: TfrmTableEditor
object tabCREATEcode: TTabSheet
Caption = 'CREATE code'
ImageIndex = 119
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0
object SynMemoCREATEcode: TSynMemo
Left = 0
Top = 0
@@ -684,7 +663,6 @@ object frmTableEditor: TfrmTableEditor
Font.Height = -13
Font.Name = 'Courier New'
Font.Style = []
PopupMenu = popupSQLmemo
TabOrder = 0
Gutter.AutoSize = True
Gutter.DigitCount = 2
@@ -706,10 +684,6 @@ object frmTableEditor: TfrmTableEditor
object tabALTERCode: TTabSheet
Caption = 'ALTER code'
ImageIndex = 119
ExplicitLeft = 0
ExplicitTop = 0
ExplicitWidth = 0
ExplicitHeight = 0
object SynMemoALTERcode: TSynMemo
Left = 0
Top = 0
@@ -722,7 +696,6 @@ object frmTableEditor: TfrmTableEditor
Font.Height = -13
Font.Name = 'Courier New'
Font.Style = []
PopupMenu = popupSQLmemo
TabOrder = 0
Gutter.AutoSize = True
Gutter.DigitCount = 2
@@ -905,19 +878,4 @@ object frmTableEditor: TfrmTableEditor
ImageIndex = 13
end
end
object popupSQLmemo: TPopupMenu
Images = MainForm.ImageListMain
OnPopup = popupSQLmemoPopup
Left = 376
Top = 360
object menuSQLSelectAll: TMenuItem
Action = MainForm.actSelectAll
end
object menuSQLCopy: TMenuItem
Action = MainForm.actCopy
end
object Saveastextfile1: TMenuItem
Action = MainForm.actSaveSynMemoToTextfile
end
end
end
View
@@ -81,16 +81,12 @@ TfrmTableEditor = class(TFrame)
btnClearForeignKeys: TToolButton;
menuCopyColumnCell: TMenuItem;
N2: TMenuItem;
popupSQLmemo: TPopupMenu;
menuSQLCopy: TMenuItem;
menuSQLSelectAll: TMenuItem;
pnlNoForeignKeys: TPanel;
listForeignKeys: TVirtualStringTree;
menuCopyColumns: TMenuItem;
menuPasteColumns: TMenuItem;
tabPartitions: TTabSheet;
SynMemoPartitions: TSynMemo;
Saveastextfile1: TMenuItem;
procedure Modification(Sender: TObject);
procedure btnAddColumnClick(Sender: TObject);
procedure btnRemoveColumnClick(Sender: TObject);
@@ -170,7 +166,6 @@ TfrmTableEditor = class(TFrame)
var InitialStates: TVirtualNodeInitStates);
procedure listColumnsGetNodeDataSize(Sender: TBaseVirtualTree; var NodeDataSize: Integer);
procedure listColumnsNodeMoved(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure popupSQLmemoPopup(Sender: TObject);
procedure listColumnsKeyPress(Sender: TObject; var Key: Char);
procedure vtHandleClickOrKeyPress(Sender: TVirtualStringTree;
Node: PVirtualNode; Column: TColumnIndex; HitPositions: THitPositions);
@@ -1883,6 +1878,13 @@ procedure TfrmTableEditor.PageControlMainChange(Sender: TObject);
else
ListForeignKeys.Margins.Bottom := GetTextHeight(pnlNoForeignKeys.Font)+4;
ListForeignKeys.Repaint;
end
// Ensure SynMemo's have focus, otherwise Select-All and Copy actions may fail
else if PageControlMain.ActivePage = tabCREATEcode then begin
SynMemoCreateCode.SetFocus;
end
else if PageControlMain.ActivePage = tabALTERcode then begin
SynMemoAlterCode.SetFocus;
end;
UpdateSQLcode;
end;
@@ -2333,16 +2335,6 @@ procedure TfrmTableEditor.btnHelpClick(Sender: TObject);
end;
procedure TfrmTableEditor.popupSQLmemoPopup(Sender: TObject);
begin
// Ensure SynMemo's have focus, otherwise Select-All and Copy actions may fail
if PageControlMain.ActivePage = tabCREATEcode then
SynMemoCreateCode.SetFocus
else if PageControlMain.ActivePage = tabALTERcode then
SynMemoAlterCode.SetFocus;
end;
procedure TfrmTableEditor.menuCopyColumnsClick(Sender: TObject);
var
Node: PVirtualNode;

0 comments on commit a50c21a

Please sign in to comment.