Skip to content

Commit

Permalink
hopefully fix unwanted restoring of session when tabs are disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Kowalczyk committed Nov 21, 2023
1 parent 93d33bc commit ba4010a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/EditAnnotations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ static void UpdateUIForSelectedAnnotation(EditAnnotationsWindow* ew, Annotation*
DoSaveEmbed(ew, annot);

// TODO: not sure it should be here as it might trigger recursive loop
//SetSelectedAnnotation(ew->tab, annot);
// SetSelectedAnnotation(ew->tab, annot);
ew->listBox->SetCurrentSelection(itemNo);
ew->buttonDelete->SetIsVisible(true);
if (setEditFocus && ew->editContents->IsVisible()) {
Expand Down
10 changes: 7 additions & 3 deletions src/SumatraStartup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) {
bool showStartPage = false;
bool restoreSession = false;
HANDLE hMutex = nullptr;
HWND existingInstanceHwnd = nullptr;
HWND existingHwnd = nullptr;
WindowTab* tabToSelect = nullptr;
const char* logFilePath = nullptr;
Expand Down Expand Up @@ -1230,12 +1231,15 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) {
goto Exit;
}

// only call FindPrevInstWindow() once
existingInstanceHwnd = FindPrevInstWindow(&hMutex);

if (flags.printDialog || flags.stressTestPath || gPluginMode) {
// TODO: pass print request through to previous instance?
} else if (flags.reuseDdeInstance || flags.dde) {
existingHwnd = FindWindow(FRAME_CLASS_NAME, nullptr);
} else if (gGlobalPrefs->reuseInstance || gGlobalPrefs->useTabs) {
existingHwnd = FindPrevInstWindow(&hMutex);
existingHwnd = existingInstanceHwnd;
}

// call before creating first window and menu. Otherwise menu shortcuts will be missing
Expand Down Expand Up @@ -1281,11 +1285,11 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) {
gGlobalPrefs->sessionData = new Vec<SessionData*>();
// do not restore a session if tabs are disabled and SumatraPDF is already running
if (sessionData->size() > 0 && !gPluginURL) {
bool noRestore = !gGlobalPrefs->useTabs && (FindPrevInstWindow(&hMutex) != nullptr);
bool noRestore = !gGlobalPrefs->useTabs && (existingInstanceHwnd != nullptr);
if (!noRestore) {
restoreSession = gGlobalPrefs->restoreSession;
} else {
logf("not restoring a session because the same exe is already running and tabas are disabled\n");
logf("not restoring a session because the same exe is already running and tabs are disabled\n");
}
}

Expand Down

0 comments on commit ba4010a

Please sign in to comment.