Skip to content

Commit

Permalink
use ShowErrorLoadingNotification() and remove duplicated code; notifi…
Browse files Browse the repository at this point in the history
…cations always have close button (used to not have close button if timeout was non-zero
  • Loading branch information
kjk committed Nov 16, 2023
1 parent c885a19 commit 396903b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 11 deletions.
8 changes: 2 additions & 6 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ void LinkHandler::LaunchFile(const char* pathOrig, IPageDestination* link) {
}

IPageDestination* remoteLink = link;
char* fullPath = path::GetDirTemp(win->ctrl->GetFilePath());
TempStr fullPath = path::GetDirTemp(win->ctrl->GetFilePath());
fullPath = path::JoinTemp(fullPath, path);

// TODO: respect link->ld.gotor.new_window for PDF documents ?
Expand All @@ -517,11 +517,7 @@ void LinkHandler::LaunchFile(const char* pathOrig, IPageDestination* link) {
// consider bad UI and thus simply don't)
bool ok = OpenFileExternally(fullPath);
if (!ok) {
TempStr msg = str::FormatTemp(_TRA("Error loading %s"), fullPath);
NotificationCreateArgs nargs;
nargs.hwndParent = win->hwndCanvas;
nargs.warning = true;
ShowNotification(nargs);
ShowErrorLoadingNotification(newWin, fullPath, true);
}
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct NotificationWnd : ProgressUpdateUI, Wnd {
bool WasCanceled() override;

bool HasClose() const {
return (timeoutMs == 0) || (progressMsg != nullptr);
return true;
}

bool HasProgress() const {
Expand Down
9 changes: 5 additions & 4 deletions src/SumatraPDF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1667,13 +1667,14 @@ static void ShowFileNotFound(MainWindow* win, const char* path, bool noSavePrefs
LoadDocumentMarkNotExist(win, path, noSavePrefs);
}

static void ShowErrorLoading(MainWindow* win, const char* path, bool noSavePrefs) {
void ShowErrorLoadingNotification(MainWindow* win, const char* path, bool noSavePrefs) {
// TODO: same message as in Canvas.cpp to not introduce
// new translation. Find a better message e.g. why failed.
NotificationCreateArgs nargs;
nargs.hwndParent = win->hwndCanvas;
nargs.msg = str::FormatTemp(_TRA("Error loading %s"), path);
nargs.warning = true;
nargs.timeoutMs = 1000 * 5;
ShowNotification(nargs);
LoadDocumentMarkNotExist(win, path, noSavePrefs);
}
Expand Down Expand Up @@ -1867,7 +1868,7 @@ void LoadDocumentAsync(LoadArgs* argsIn) {
args->ctrl = CreateControllerForEngineOrFile(engine, path, &pwdUI, win);
RemoveNotification(wndNotif);
if (!args->ctrl) {
ShowErrorLoading(win, path, args->noSavePrefs);
ShowErrorLoadingNotification(win, path, args->noSavePrefs);
delete args;
return;
}
Expand Down Expand Up @@ -1896,7 +1897,7 @@ void LoadDocumentAsync(LoadArgs* argsIn) {
MainWindow* win = args->win;
const char* path = args->FilePath();
if (!args->ctrl) {
ShowErrorLoading(win, path, args->noSavePrefs);
ShowErrorLoadingNotification(win, path, args->noSavePrefs);
delete args;
return;
}
Expand Down Expand Up @@ -1956,7 +1957,7 @@ MainWindow* LoadDocument(LoadArgs* args) {
}

if (!ctrl) {
ShowErrorLoading(win, path, args->noSavePrefs);
ShowErrorLoadingNotification(win, path, args->noSavePrefs);
return win;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/SumatraPDF.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,4 @@ bool DocIsSupportedFileType(Kind);
char* GetLogFilePath();
void ShowSavedAnnotationsNotification(HWND hwndParent, const char* path);
void ShowSavedAnnotationsFailedNotification(HWND hwndParent, const char* path, const char* mupdfErr);
void ShowErrorLoadingNotification(MainWindow* win, const char* path, bool noSavePrefs);

0 comments on commit 396903b

Please sign in to comment.