Skip to content

Commit

Permalink
add lazy loading advanced setting
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Oct 26, 2023
1 parent 7fb7d28 commit ecd3764
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
1 change: 1 addition & 0 deletions do/settings_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ var (
"after UseDefaultState in FileStates)"),
mkField("RestoreSession", Bool, true,
"if true and SessionData isn't empty, that session will be restored at startup").setExpert(),
mkField("LazyLoading", Bool, true, "when restoring session, delay loading of documents until their tab is selected").setVersion("3.6"),
mkField("UiLanguage", String, nil,
"ISO code of the current UI language").setDoc("[ISO code](langs.html) of the current UI language"),
mkField("InverseSearchCmdLine", String, nil,
Expand Down
2 changes: 1 addition & 1 deletion do/settings_gen_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ func updateSumatraWebsite() string {
cmd.Dir = dir
runCmdLoggedMust(cmd)
}
dir = filepath.Join(dir, "www")
dir = filepath.Join(dir, "server", "www")
panicIf(!dirExists(dir), "directory for sumatra website '%s' doesn't exist", dir)
return dir
}
Expand Down
1 change: 1 addition & 0 deletions docs/releasenotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Next version:

3.6
* -search now copies search term to find box so that F3 works
* add LazyLoading advanced setting

3.5.2 (2023-10-25)
* fix not showing tab text
Expand Down
19 changes: 12 additions & 7 deletions src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ struct GlobalPrefs {
// if true and SessionData isn't empty, that session will be restored
// at startup
bool restoreSession;
// when restoring session, delay loading of documents until their tab
// is selected
bool lazyLoading;
// ISO code of the current UI language
char* uiLanguage;
// pattern used to launch the LaTeX editor when doing inverse search
Expand Down Expand Up @@ -654,7 +657,7 @@ static const StructInfo gFILETIMEInfo = {sizeof(FILETIME), 2, gFILETIMEFields, "

static const FieldInfo gGlobalPrefsFields[] = {
{(size_t)-1, SettingType::Comment,
(intptr_t) "For documentation, see https://www.sumatrapdfreader.org/settings/settings3-5.html"},
(intptr_t) "For documentation, see https://www.sumatrapdfreader.org/settings/settings3-6.html"},
{offsetof(GlobalPrefs, theme), SettingType::String, (intptr_t) ""},
{offsetof(GlobalPrefs, fixedPageUI), SettingType::Struct, (intptr_t)&gFixedPageUIInfo},
{offsetof(GlobalPrefs, comicBookUI), SettingType::Struct, (intptr_t)&gComicBookUIInfo},
Expand All @@ -676,6 +679,7 @@ static const FieldInfo gGlobalPrefsFields[] = {
{offsetof(GlobalPrefs, rememberOpenedFiles), SettingType::Bool, true},
{offsetof(GlobalPrefs, rememberStatePerDocument), SettingType::Bool, true},
{offsetof(GlobalPrefs, restoreSession), SettingType::Bool, true},
{offsetof(GlobalPrefs, lazyLoading), SettingType::Bool, true},
{offsetof(GlobalPrefs, uiLanguage), SettingType::String, 0},
{offsetof(GlobalPrefs, inverseSearchCmdLine), SettingType::String, 0},
{offsetof(GlobalPrefs, enableTeXEnhancements), SettingType::Bool, false},
Expand Down Expand Up @@ -719,13 +723,14 @@ static const FieldInfo gGlobalPrefsFields[] = {
{(size_t)-1, SettingType::Comment, (intptr_t) "Settings below are not recognized by the current version"},
};
static const StructInfo gGlobalPrefsInfo = {
sizeof(GlobalPrefs), 61, gGlobalPrefsFields,
sizeof(GlobalPrefs), 62, gGlobalPrefsFields,
"\0Theme\0FixedPageUI\0ComicBookUI\0ChmUI\0\0SelectionHandlers\0ExternalViewers\0\0ZoomLevels\0ZoomIncrement\0\0Pri"
"nterDefaults\0ForwardSearch\0Annotations\0DefaultPasswords\0\0RememberOpenedFiles\0RememberStatePerDocument\0Resto"
"reSession\0UiLanguage\0InverseSearchCmdLine\0EnableTeXEnhancements\0DefaultDisplayMode\0DefaultZoom\0Shortcuts\0Es"
"cToExit\0ReuseInstance\0ReloadModifiedDocuments\0\0MainWindowBackground\0FullPathInTitle\0ShowMenubar\0ShowToolbar"
"\0ShowFavorites\0ShowToc\0NoHomeTab\0TocDy\0SidebarDx\0ToolbarSize\0TabWidth\0TreeFontSize\0TreeFontWeightOffset\0"
"TreeFontName\0SmoothScroll\0ShowStartPage\0CheckForUpdates\0VersionToSkip\0WindowState\0WindowPos\0UseTabs\0UseSys"
"Colors\0CustomScreenDPI\0\0FileStates\0SessionData\0ReopenOnce\0TimeOfLastUpdateCheck\0OpenCountWeek\0\0"};
"reSession\0LazyLoading\0UiLanguage\0InverseSearchCmdLine\0EnableTeXEnhancements\0DefaultDisplayMode\0DefaultZoom\0"
"Shortcuts\0EscToExit\0ReuseInstance\0ReloadModifiedDocuments\0\0MainWindowBackground\0FullPathInTitle\0ShowMenubar"
"\0ShowToolbar\0ShowFavorites\0ShowToc\0NoHomeTab\0TocDy\0SidebarDx\0ToolbarSize\0TabWidth\0TreeFontSize\0TreeFontW"
"eightOffset\0TreeFontName\0SmoothScroll\0ShowStartPage\0CheckForUpdates\0VersionToSkip\0WindowState\0WindowPos\0Us"
"eTabs\0UseSysColors\0CustomScreenDPI\0\0FileStates\0SessionData\0ReopenOnce\0TimeOfLastUpdateCheck\0OpenCountWeek"
"\0\0"};

#endif
9 changes: 3 additions & 6 deletions src/SumatraPDF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ bool gDebugShowLinks = false;
// so always disable
bool gShowFrameRate = false;

// if true, Enable lazyload session tabs on startup
bool gEnableLazyLoad = true;

// in plugin mode, the window's frame isn't drawn and closing and
// fullscreen are disabled, so that SumatraPDF can be displayed
// embedded (e.g. in a web browser)
Expand Down Expand Up @@ -1269,7 +1266,7 @@ void ReloadDocument(MainWindow* win, bool autoRefresh) {
return;
}
// TODO: maybe should ensure it never is called for IsAboutTab() ?
// This only happens if gEnableLazyLoad is true
// This only happens if gLazyLoading is true
if (tab->IsAboutTab()) {
return;
}
Expand Down Expand Up @@ -1976,7 +1973,7 @@ void LoadModelIntoTab(WindowTab* tab) {
}

MainWindow* win = tab->win;
if (gEnableLazyLoad && win->ctrl && !tab->ctrl && !tab->IsAboutTab()) {
if (gGlobalPrefs->lazyLoading && win->ctrl && !tab->ctrl && !tab->IsAboutTab()) {
NotificationCreateArgs args;
args.hwndParent = win->hwndCanvas;
args.msg = str::FormatTemp(_TRA("Please wait - loading..."));
Expand Down Expand Up @@ -2027,7 +2024,7 @@ void LoadModelIntoTab(WindowTab* tab) {

SetFocus(win->hwndFrame);
if (!tab->IsAboutTab()) {
if (gEnableLazyLoad && !tab->ctrl) {
if (gGlobalPrefs->lazyLoading && !tab->ctrl) {
ReloadDocument(win, false);
} else {
if (tab->reloadOnFocus) {
Expand Down
2 changes: 0 additions & 2 deletions src/SumatraPDF.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ extern HCURSOR gCursorDrag;
extern bool gCrashOnOpen;
extern HWND gLastActiveFrameHwnd;

extern bool gEnableLazyLoad;

#define gPluginMode (gPluginURL != nullptr)

void InitializePolicies(bool restrict);
Expand Down
4 changes: 2 additions & 2 deletions src/SumatraStartup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1286,10 +1286,10 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) {
logf("WinMain: skipping RestoreTabOnStartup() because state->filePath is empty\n");
continue;
}
RestoreTabOnStartup(win, state, gEnableLazyLoad);
RestoreTabOnStartup(win, state, gGlobalPrefs->lazyLoading);
}
TabsSelect(win, data->tabIndex - 1);
if (gEnableLazyLoad) {
if (gGlobalPrefs->lazyLoading) {
ReloadDocument(win, false);
}
}
Expand Down

0 comments on commit ecd3764

Please sign in to comment.