Skip to content

Commit

Permalink
Make detection of current editor in save-to-file action a bit more st…
Browse files Browse the repository at this point in the history
…able. Closes #353
  • Loading branch information
ansgarbecker committed Dec 26, 2018
1 parent 39f06c8 commit 07a0c30
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
5 changes: 4 additions & 1 deletion out/locale/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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."
Expand Down
32 changes: 22 additions & 10 deletions source/main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 07a0c30

Please sign in to comment.