diff options
| -rw-r--r-- | UCore.pas | 14 | ||||
| -rw-r--r-- | UMain.pas | 7 |
2 files changed, 17 insertions, 4 deletions
@@ -157,6 +157,8 @@ type TWorkerThread = class(TThread) VFSAskPassword_Display: boolean; VFSAskPassword_Result: LongBool; + VFSCallbackCancelled: boolean; + constructor Create; destructor Destroy; override; end; @@ -2610,6 +2612,7 @@ begin VFSCallbackEvent := TSimpleEvent.Create; VFSAskQuestion_Display := False; VFSAskPassword_Display := False; + VFSCallbackCancelled := False; end; destructor TOpenDirThread.Destroy; @@ -2630,6 +2633,7 @@ procedure TOpenDirThread.Execute; var tt: TDateTime; begin FThreadID := pthread_self; + VFSCallbackCancelled := False; try // Writeln('execute.'); tt := Now; @@ -2676,13 +2680,15 @@ end; procedure vfs_ask_question_callback(const AMessage: PChar; const Choices: PPChar; choice: PInteger; user_data: Pointer); cdecl; var Thread: TOpenDirThread; begin + Thread := user_data; + if pthread_self = Application.ThreadID then begin DebugMsg(['!! (WARNING): vfs_ask_question_callback called from the main thread, expected spawn from a OpenDirThread']); HandleVFSAskQuestionCallback(FMain.FWidget, AMessage, Choices, choice); + if (choice <> nil) and (Thread <> nil) and (Thread is TOpenDirThread) then Thread.VFSCallbackCancelled := choice^ < 0; Exit; end; - Thread := user_data; if (Thread <> nil) and (Thread is TOpenDirThread) and (pthread_self = Thread.FThreadID) then begin DebugMsg(['******* vfs_ask_question_callback spawned, user_data = 0x', IntToHex(QWord(user_data), 16), ', ThreadID = 0x', IntToHex(pthread_self, 16)]); Thread.VFSAskQuestion_Message := AMessage; @@ -2691,6 +2697,7 @@ begin Thread.VFSAskQuestion_Display := True; Thread.VFSCallbackEvent.WaitFor(INFINITE); DebugMsg(['******* thread: resuming...']); + if (choice <> nil) then Thread.VFSCallbackCancelled := choice^ < 0; Exit; end; @@ -2704,13 +2711,15 @@ function vfs_ask_password_callback(const AMessage: PChar; const default_user: PC user_data: Pointer): LongBool; cdecl; var Thread: TOpenDirThread; begin + Thread := user_data; + if pthread_self = Application.ThreadID then begin DebugMsg(['!! (WARNING): vfs_ask_password_callback called from the main thread, expected spawn from a OpenDirThread']); Result := HandleVFSAskPasswordCallback(FMain.FWidget, AMessage, default_user, default_domain, flags, username, password, anonymous, domain, password_save); + if (Thread <> nil) and (Thread is TOpenDirThread) then Thread.VFSCallbackCancelled := Result = False; Exit; end; - Thread := user_data; if (Thread <> nil) and (Thread is TOpenDirThread) and (pthread_self = Thread.FThreadID) then begin DebugMsg(['******* vfs_ask_password_callback spawned, user_data = 0x', IntToHex(QWord(user_data), 16), ', ThreadID = 0x', IntToHex(pthread_self, 16), ', Application.ThreadID = 0x', IntToHex(Application.ThreadID, 16)]); Thread.VFSAskPassword_Message := AMessage; @@ -2727,6 +2736,7 @@ begin Thread.VFSCallbackEvent.WaitFor(INFINITE); DebugMsg(['******* thread: resuming...']); Result := Thread.VFSAskPassword_Result; + Thread.VFSCallbackCancelled := Result = False; Exit; end; @@ -1858,8 +1858,11 @@ begin OpenDirThread.Free; end else if OpenDirThread.ChDirResult <> 0 then begin - if OpenDirThread.ChDirResult = 1 then Application.MessageBox(Format(LANGErrorGettingListingForSPanelNoPath, [LANGPanelStrings[LeftPanel], 'Exception']), [mbOK], mbError, mbNone, mbOK) - else Application.MessageBox(Format(LANGErrorGettingListingForSPanel, [LANGPanelStrings[LeftPanel], GetErrorString(OpenDirThread.ChDirResult), NewPath]), [mbOK], mbError, mbNone, mbOK); + if not OpenDirThread.VFSCallbackCancelled then begin + // Drop the error message if one of the callback dialogs were cancelled + if OpenDirThread.ChDirResult = 1 then Application.MessageBox(Format(LANGErrorGettingListingForSPanelNoPath, [LANGPanelStrings[LeftPanel], 'Exception']), [mbOK], mbError, mbNone, mbOK) + else Application.MessageBox(Format(LANGErrorGettingListingForSPanel, [LANGPanelStrings[LeftPanel], GetErrorString(OpenDirThread.ChDirResult), NewPath]), [mbOK], mbError, mbNone, mbOK); + end; DebugMsg(['TFMain.ChangingDir: Freeing thread...']); OpenDirThread.Free; end else begin |
