Skip to content

Commit 7a889f1

Browse files
committed
Fix: If the translation is in the Popup, cancel when the window is closed
1 parent dd6fa1b commit 7a889f1

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

forms/formpopup.pas

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ TformPopupTrayslate = class(TForm)
9090

9191
implementation
9292

93-
uses consts, mainform, localize, darkutils, controlshelper;
93+
uses Consts, mainform, localize, darkutils, controlshelper;
9494

9595
{$R *.lfm}
9696

@@ -130,6 +130,10 @@ procedure TformPopupTrayslate.FormShow(Sender: TObject);
130130
procedure TformPopupTrayslate.FormHide(Sender: TObject);
131131
begin
132132
FDropTarget.Unregister;
133+
134+
if Assigned(formTrayslate.TranslateTarget) and (formTrayslate.TranslateTarget is TMemo) and
135+
(formTrayslate.TranslateTarget = MemoTarget) then
136+
formTrayslate.CancelTranslate;
133137
end;
134138

135139
procedure TformPopupTrayslate.FormShortCut(var Msg: TLMKey; var Handled: boolean);

forms/mainform.pas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ TformTrayslate = class(TForm)
360360
FPopupRecentPair: TComponent;
361361
FRawTranslate: string;
362362
FSettingsPage: integer;
363+
FTranslateTarget: TWinControl;
363364

364365
// Non sorted combo named languages
365366
FLanguages: TStringList;
@@ -594,6 +595,7 @@ TformTrayslate = class(TForm)
594595
property LastDarkMode: boolean read FLastDarkMode write FLastDarkMode;
595596
property CustomPoFile: string read FCustomPoFile write FCustomPoFile;
596597
property RawTranslate: string read FRawTranslate write FRawTranslate;
598+
property TranslateTarget:TWinControl read FTranslateTarget;
597599
property MouseHook: TGlobalMouseHook read FMouseHook write FMouseHook;
598600
property KeyHook: TGlobalKeyboardHook read FKeyHook write FKeyHook;
599601
property HotKeyApp: THotKeyData read FHotKeyApp write FHotKeyApp;
@@ -3932,6 +3934,7 @@ function TformTrayslate.TranslateThread(ATrans: TTranslate; AText: string; AMemo
39323934
Th := TTranslateThread.Create(ATrans, False);
39333935
FTranslateThread := Th;
39343936
FActiveThreads.Add(Th);
3937+
FTranslateTarget := AMemo;
39353938
UpdateTranslateButtonState;
39363939
Screen.Cursor := crAppStart;
39373940
TimerAnimate.Enabled := True;
@@ -3989,6 +3992,8 @@ procedure TformTrayslate.ThreadDone(Sender: TObject);
39893992

39903993
if not Visible and (not Assigned(formPopupTrayslate) or not formPopupTrayslate.Visible) then
39913994
ShowCustomHint(TrayIcon.Hint);
3995+
3996+
FTranslateTarget := nil;
39923997
end;
39933998

39943999
procedure TformTrayslate.CancelTranslate;
@@ -4000,6 +4005,7 @@ procedure TformTrayslate.CancelTranslate;
40004005
FTranslateThread := nil;
40014006
end;
40024007
FCancelled := True;
4008+
FTranslateTarget := nil;
40034009
finally
40044010
UpdateTranslateButtonState;
40054011
TimerAnimate.Enabled := False;

0 commit comments

Comments
 (0)