summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-03-29 13:40:54 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-03-29 13:41:35 +0300
commitf9117532955f0d8935971eb1053f13f9ecab7662 (patch)
tree843914f355dc8da3cadaa6bd450075c7dc501054
parent6074a467110bfb4e40c3e659cc674d7bbaa82d5a (diff)
Preferences: Collapse preformatted blocks on page load
IssueID #180
-rw-r--r--src/app.c13
-rw-r--r--src/gmdocument.c3
-rw-r--r--src/prefs.c1
-rw-r--r--src/prefs.h4
-rw-r--r--src/ui/documentwidget.c3
-rw-r--r--src/ui/listwidget.c4
-rw-r--r--src/ui/util.c3
7 files changed, 26 insertions, 5 deletions
diff --git a/src/app.c b/src/app.c
index d4d5f5a6..ba282440 100644
--- a/src/app.c
+++ b/src/app.c
@@ -217,20 +217,22 @@ static iString *serializePrefs_App_(const iApp *d) {
217 appendFormat_String(str, "prefs.dialogtab arg:%d\n", d->prefs.dialogTab); 217 appendFormat_String(str, "prefs.dialogtab arg:%d\n", d->prefs.dialogTab);
218 appendFormat_String(str, "font.set arg:%d\n", d->prefs.font); 218 appendFormat_String(str, "font.set arg:%d\n", d->prefs.font);
219 appendFormat_String(str, "headingfont.set arg:%d\n", d->prefs.headingFont); 219 appendFormat_String(str, "headingfont.set arg:%d\n", d->prefs.headingFont);
220 appendFormat_String(str, "prefs.mono.gemini.changed arg:%d\n", d->prefs.monospaceGemini);
221 appendFormat_String(str, "prefs.mono.gopher.changed arg:%d\n", d->prefs.monospaceGopher);
222 appendFormat_String(str, "zoom.set arg:%d\n", d->prefs.zoomPercent); 220 appendFormat_String(str, "zoom.set arg:%d\n", d->prefs.zoomPercent);
223 appendFormat_String(str, "smoothscroll arg:%d\n", d->prefs.smoothScrolling); 221 appendFormat_String(str, "smoothscroll arg:%d\n", d->prefs.smoothScrolling);
224 appendFormat_String(str, "imageloadscroll arg:%d\n", d->prefs.loadImageInsteadOfScrolling); 222 appendFormat_String(str, "imageloadscroll arg:%d\n", d->prefs.loadImageInsteadOfScrolling);
225 appendFormat_String(str, "cachesize.set arg:%d\n", d->prefs.maxCacheSize); 223 appendFormat_String(str, "cachesize.set arg:%d\n", d->prefs.maxCacheSize);
226 appendFormat_String(str, "decodeurls arg:%d\n", d->prefs.decodeUserVisibleURLs); 224 appendFormat_String(str, "decodeurls arg:%d\n", d->prefs.decodeUserVisibleURLs);
227 appendFormat_String(str, "linewidth.set arg:%d\n", d->prefs.lineWidth); 225 appendFormat_String(str, "linewidth.set arg:%d\n", d->prefs.lineWidth);
226 /* TODO: Set up an array of booleans in Prefs and do these in a loop. */
227 appendFormat_String(str, "prefs.mono.gemini.changed arg:%d\n", d->prefs.monospaceGemini);
228 appendFormat_String(str, "prefs.mono.gopher.changed arg:%d\n", d->prefs.monospaceGopher);
228 appendFormat_String(str, "prefs.biglede.changed arg:%d\n", d->prefs.bigFirstParagraph); 229 appendFormat_String(str, "prefs.biglede.changed arg:%d\n", d->prefs.bigFirstParagraph);
229 appendFormat_String(str, "prefs.plaintext.wrap.changed arg:%d\n", d->prefs.plainTextWrap); 230 appendFormat_String(str, "prefs.plaintext.wrap.changed arg:%d\n", d->prefs.plainTextWrap);
230 appendFormat_String(str, "prefs.sideicon.changed arg:%d\n", d->prefs.sideIcon); 231 appendFormat_String(str, "prefs.sideicon.changed arg:%d\n", d->prefs.sideIcon);
231 appendFormat_String(str, "prefs.centershort.changed arg:%d\n", d->prefs.centerShortDocs); 232 appendFormat_String(str, "prefs.centershort.changed arg:%d\n", d->prefs.centerShortDocs);
232 appendFormat_String(str, "quoteicon.set arg:%d\n", d->prefs.quoteIcon ? 1 : 0); 233 appendFormat_String(str, "prefs.collapsepreonload.changed arg:%d\n", d->prefs.collapsePreOnLoad);
233 appendFormat_String(str, "prefs.hoverlink.changed arg:%d\n", d->prefs.hoverLink); 234 appendFormat_String(str, "prefs.hoverlink.changed arg:%d\n", d->prefs.hoverLink);
235 appendFormat_String(str, "quoteicon.set arg:%d\n", d->prefs.quoteIcon ? 1 : 0);
234 appendFormat_String(str, "theme.set arg:%d auto:1\n", d->prefs.theme); 236 appendFormat_String(str, "theme.set arg:%d auto:1\n", d->prefs.theme);
235 appendFormat_String(str, "accent.set arg:%d\n", d->prefs.accent); 237 appendFormat_String(str, "accent.set arg:%d\n", d->prefs.accent);
236 appendFormat_String(str, "ostheme arg:%d\n", d->prefs.useSystemTheme); 238 appendFormat_String(str, "ostheme arg:%d\n", d->prefs.useSystemTheme);
@@ -1715,6 +1717,10 @@ iBool handleCommand_App(const char *cmd) {
1715 postCommand_App("theme.changed"); 1717 postCommand_App("theme.changed");
1716 return iTrue; 1718 return iTrue;
1717 } 1719 }
1720 else if (equal_Command(cmd, "prefs.collapsepreonload.changed")) {
1721 d->prefs.collapsePreOnLoad = arg_Command(cmd) != 0;
1722 return iTrue;
1723 }
1718 else if (equal_Command(cmd, "prefs.hoverlink.changed")) { 1724 else if (equal_Command(cmd, "prefs.hoverlink.changed")) {
1719 d->prefs.hoverLink = arg_Command(cmd) != 0; 1725 d->prefs.hoverLink = arg_Command(cmd) != 0;
1720 postRefresh_App(); 1726 postRefresh_App();
@@ -1944,6 +1950,7 @@ iBool handleCommand_App(const char *cmd) {
1944 setToggle_Widget(findChild_Widget(dlg, "prefs.plaintext.wrap"), d->prefs.plainTextWrap); 1950 setToggle_Widget(findChild_Widget(dlg, "prefs.plaintext.wrap"), d->prefs.plainTextWrap);
1945 setToggle_Widget(findChild_Widget(dlg, "prefs.sideicon"), d->prefs.sideIcon); 1951 setToggle_Widget(findChild_Widget(dlg, "prefs.sideicon"), d->prefs.sideIcon);
1946 setToggle_Widget(findChild_Widget(dlg, "prefs.centershort"), d->prefs.centerShortDocs); 1952 setToggle_Widget(findChild_Widget(dlg, "prefs.centershort"), d->prefs.centerShortDocs);
1953 setToggle_Widget(findChild_Widget(dlg, "prefs.collapsepreonload"), d->prefs.collapsePreOnLoad);
1947 updateColorThemeButton_(findChild_Widget(dlg, "prefs.doctheme.dark"), d->prefs.docThemeDark); 1954 updateColorThemeButton_(findChild_Widget(dlg, "prefs.doctheme.dark"), d->prefs.docThemeDark);
1948 updateColorThemeButton_(findChild_Widget(dlg, "prefs.doctheme.light"), d->prefs.docThemeLight); 1955 updateColorThemeButton_(findChild_Widget(dlg, "prefs.doctheme.light"), d->prefs.docThemeLight);
1949 updateFontButton_(findChild_Widget(dlg, "prefs.font"), d->prefs.font); 1956 updateFontButton_(findChild_Widget(dlg, "prefs.font"), d->prefs.font);
diff --git a/src/gmdocument.c b/src/gmdocument.c
index 7fddc575..313fd40a 100644
--- a/src/gmdocument.c
+++ b/src/gmdocument.c
@@ -432,6 +432,9 @@ static void doLayout_GmDocument_(iGmDocument *d) {
432 meta.flags = constValue_Array(oldPreMeta, preIndex, iGmPreMeta).flags & 432 meta.flags = constValue_Array(oldPreMeta, preIndex, iGmPreMeta).flags &
433 folded_GmPreMetaFlag; 433 folded_GmPreMetaFlag;
434 } 434 }
435 else if (prefs->collapsePreOnLoad) {
436 meta.flags |= folded_GmPreMetaFlag;
437 }
435 pushBack_Array(&d->preMeta, &meta); 438 pushBack_Array(&d->preMeta, &meta);
436 continue; 439 continue;
437 } 440 }
diff --git a/src/prefs.c b/src/prefs.c
index 119dfd56..8a1bda79 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -40,6 +40,7 @@ void init_Prefs(iPrefs *d) {
40 d->hoverLink = iTrue; 40 d->hoverLink = iTrue;
41 d->smoothScrolling = iTrue; 41 d->smoothScrolling = iTrue;
42 d->loadImageInsteadOfScrolling = iFalse; 42 d->loadImageInsteadOfScrolling = iFalse;
43 d->collapsePreOnLoad = iFalse;
43 d->decodeUserVisibleURLs = iTrue; 44 d->decodeUserVisibleURLs = iTrue;
44 d->maxCacheSize = 10; 45 d->maxCacheSize = 10;
45 d->font = nunito_TextFont; 46 d->font = nunito_TextFont;
diff --git a/src/prefs.h b/src/prefs.h
index 1bd434d0..232c6fc3 100644
--- a/src/prefs.h
+++ b/src/prefs.h
@@ -32,6 +32,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
32 32
33iDeclareType(Prefs) 33iDeclareType(Prefs)
34 34
35/* TODO: Refactor at least the boolean values into an array for easier manipulation.
36 Then they can be (de)serialized as a group. Need to use a systematic command naming
37 convention for notifications. */
35struct Impl_Prefs { 38struct Impl_Prefs {
36 /* UI state */ 39 /* UI state */
37 int dialogTab; 40 int dialogTab;
@@ -53,6 +56,7 @@ struct Impl_Prefs {
53 iBool hoverLink; 56 iBool hoverLink;
54 iBool smoothScrolling; 57 iBool smoothScrolling;
55 iBool loadImageInsteadOfScrolling; 58 iBool loadImageInsteadOfScrolling;
59 iBool collapsePreOnLoad;
56 iString searchUrl; 60 iString searchUrl;
57 /* Network */ 61 /* Network */
58 iString caFile; 62 iString caFile;
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 5d85e275..3b5ddb7c 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -2506,6 +2506,9 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
2506 setCursor_Window(get_Window(), SDL_SYSTEM_CURSOR_HAND); 2506 setCursor_Window(get_Window(), SDL_SYSTEM_CURSOR_HAND);
2507 } 2507 }
2508 else { 2508 else {
2509 if (value_Anim(&d->altTextOpacity) < 0.667f) {
2510 setValue_Anim(&d->altTextOpacity, 0, 0); /* keep it hidden while moving */
2511 }
2509 updateHover_DocumentWidget_(d, mpos); 2512 updateHover_DocumentWidget_(d, mpos);
2510 } 2513 }
2511 } 2514 }
diff --git a/src/ui/listwidget.c b/src/ui/listwidget.c
index ac64091f..942c46dd 100644
--- a/src/ui/listwidget.c
+++ b/src/ui/listwidget.c
@@ -199,6 +199,7 @@ int visCount_ListWidget(const iListWidget *d) {
199 (int) size_PtrArray(&d->items)); 199 (int) size_PtrArray(&d->items));
200} 200}
201 201
202#if 0
202static iRanges visRange_ListWidget_(const iListWidget *d) { 203static iRanges visRange_ListWidget_(const iListWidget *d) {
203 if (d->itemHeight == 0) { 204 if (d->itemHeight == 0) {
204 return (iRanges){ 0, 0 }; 205 return (iRanges){ 0, 0 };
@@ -207,6 +208,7 @@ static iRanges visRange_ListWidget_(const iListWidget *d) {
207 vis.end = iMin(size_PtrArray(&d->items), vis.start + visCount_ListWidget(d) + 1); 208 vis.end = iMin(size_PtrArray(&d->items), vis.start + visCount_ListWidget(d) + 1);
208 return vis; 209 return vis;
209} 210}
211#endif
210 212
211size_t itemIndex_ListWidget(const iListWidget *d, iInt2 pos) { 213size_t itemIndex_ListWidget(const iListWidget *d, iInt2 pos) {
212 const iRect bounds = innerBounds_Widget(constAs_Widget(d)); 214 const iRect bounds = innerBounds_Widget(constAs_Widget(d));
@@ -339,11 +341,11 @@ static void drawItem_ListWidget_(const iListWidget *d, iPaint *p, size_t index,
339 const iRect itemRect = { pos, init_I2(width_Rect(bounds), d->itemHeight) }; 341 const iRect itemRect = { pos, init_I2(width_Rect(bounds), d->itemHeight) };
340 class_ListItem(item)->draw(item, p, itemRect, d); 342 class_ListItem(item)->draw(item, p, itemRect, d);
341} 343}
342#endif
343 344
344static const iListItem *item_ListWidget_(const iListWidget *d, size_t pos) { 345static const iListItem *item_ListWidget_(const iListWidget *d, size_t pos) {
345 return constAt_PtrArray(&d->items, pos); 346 return constAt_PtrArray(&d->items, pos);
346} 347}
348#endif
347 349
348static void draw_ListWidget_(const iListWidget *d) { 350static void draw_ListWidget_(const iListWidget *d) {
349 const iWidget *w = constAs_Widget(d); 351 const iWidget *w = constAs_Widget(d);
diff --git a/src/ui/util.c b/src/ui/util.c
index 64b32bad..870d1cad 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -1899,6 +1899,8 @@ iWidget *makePreferences_Widget(void) {
1899 addChild_Widget(values, iClob(makeToggle_Widget("prefs.hoverlink"))); 1899 addChild_Widget(values, iClob(makeToggle_Widget("prefs.hoverlink")));
1900 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.centershort}"))); 1900 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.centershort}")));
1901 addChild_Widget(values, iClob(makeToggle_Widget("prefs.centershort"))); 1901 addChild_Widget(values, iClob(makeToggle_Widget("prefs.centershort")));
1902 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.collapsepreonload}")));
1903 addChild_Widget(values, iClob(makeToggle_Widget("prefs.collapsepreonload")));
1902 makeTwoColumnHeading_("${heading.prefs.scrolling}", headings, values); 1904 makeTwoColumnHeading_("${heading.prefs.scrolling}", headings, values);
1903 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.smoothscroll}"))); 1905 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.smoothscroll}")));
1904 addChild_Widget(values, iClob(makeToggle_Widget("prefs.smoothscroll"))); 1906 addChild_Widget(values, iClob(makeToggle_Widget("prefs.smoothscroll")));
@@ -2018,7 +2020,6 @@ iWidget *makePreferences_Widget(void) {
2018 appendTwoColumnPage_(tabs, "${heading.prefs.style}", '4', &headings, &values); 2020 appendTwoColumnPage_(tabs, "${heading.prefs.style}", '4', &headings, &values);
2019 makeTwoColumnHeading_("${heading.prefs.fonts}", headings, values); 2021 makeTwoColumnHeading_("${heading.prefs.fonts}", headings, values);
2020 /* Fonts. */ { 2022 /* Fonts. */ {
2021 iWidget *fonts;
2022 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.headingfont}"))); 2023 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.headingfont}")));
2023 addFontButtons_(values, "headingfont"); 2024 addFontButtons_(values, "headingfont");
2024 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.font}"))); 2025 addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.font}")));