Permalink
Browse files

Make detection of current editor in save-to-file action a bit more st…

…able. Closes #353
  • Loading branch information...
ansgarbecker committed Dec 26, 2018
1 parent 39f06c8 commit 07a0c30560c7899ec1ea505c3e6fd398d36b7477
Showing with 26 additions and 11 deletions.
  1. +4 −1 out/locale/en/LC_MESSAGES/default.po
  2. +22 −10 source/main.pas
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: HeidiSQL\n"
"POT-Creation-Date: 2012-11-05 21:40\n"
"PO-Revision-Date: 2018-12-20 13:41+0100\n"
"PO-Revision-Date: 2018-12-26 19:28+0100\n"
"Last-Translator: Ansgar Becker <anse@heidisql.com>\n"
"Language-Team: English (http://www.transifex.com/projects/p/heidisql/language/en/)\n"
"MIME-Version: 1.0\n"
@@ -4863,6 +4863,9 @@ msgstr "Cannot reformat"
msgid "Please select a non-readonly SQL editor first."
msgstr "Please select a non-readonly SQL editor first."

msgid "No SQL editor focused. ActiveControl is %s"
msgstr "No SQL editor focused. ActiveControl is %s"

#: main.pas:9768
msgid "The current editor is empty."
msgstr "The current editor is empty."
@@ -4196,21 +4196,33 @@ procedure TMainform.CallSQLHelpWithKeyword( keyword: String );

procedure TMainForm.actSaveSynMemoToTextfileExecute(Sender: TObject);
var
Comp: TComponent;
Memo: TSynMemo;
Dialog: TSaveDialog;
Item: TMenuItem;
begin
// Save to textfile, from any TSynMemo (SQL log, "CREATE code" tab in editor, ...)
Dialog := TSaveDialog.Create(Self);
Dialog.Options := Dialog.Options + [ofOverwritePrompt];
Dialog.Filter := _('SQL files')+' (*.sql)|*.sql|'+_('All files')+' (*.*)|*.*';
Dialog.DefaultExt := 'sql';
if Dialog.Execute then begin
Item := (Sender as TAction).ActionComponent as TMenuItem;
Memo := (Item.GetParentMenu as TPopupMenu).PopupComponent as TSynMemo;
Screen.Cursor := crHourGlass;
SaveUnicodeFile(Dialog.FileName, Memo.Text);
Screen.Cursor := crDefault;
Item := (Sender as TAction).ActionComponent as TMenuItem;
Comp := (Item.GetParentMenu as TPopupMenu).PopupComponent;
// Try to find memo from menu item's popup component, and if that fails, check ActiveControl.
// See #353
if Assigned(Comp) and (Comp is TSynMemo) then begin
Memo := Comp as TSynMemo;
end else if ActiveControl is TSynMemo then begin
Memo := ActiveControl as TSynMemo;
end;
if Assigned(Memo) then begin
Dialog := TSaveDialog.Create(Self);
Dialog.Options := Dialog.Options + [ofOverwritePrompt];
Dialog.Filter := _('SQL files')+' (*.sql)|*.sql|'+_('All files')+' (*.*)|*.*';
Dialog.DefaultExt := 'sql';
if Dialog.Execute then begin
Screen.Cursor := crHourGlass;
SaveUnicodeFile(Dialog.FileName, Memo.Text);
Screen.Cursor := crDefault;
end;
end else begin
ErrorDialog(f_('No SQL editor focused. ActiveControl is %s', [ActiveControl.Name]));
end;
end;

0 comments on commit 07a0c30

Please sign in to comment.