From 64a20813de671035c4a3a6d4b1568cf14f73f448 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Thu, 17 Sep 2020 08:20:39 +0300 Subject: Added a "Save Page" menu item --- src/app.c | 13 +++++++++++-- src/app.h | 1 + src/ui/window.c | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/app.c b/src/app.c index c6b9a548..c33664f9 100644 --- a/src/app.c +++ b/src/app.c @@ -73,8 +73,9 @@ static const char *dataDir_App_ = "~/AppData/Roaming/fi.skyjake.Lagrange"; static const char *dataDir_App_ = "~/.config/lagrange"; #endif #define EMB_BIN2 "../resources.binary" /* fallback from build/executable dir */ -static const char *prefsFileName_App_ = "prefs.cfg"; -static const char *stateFileName_App_ = "state.binary"; +static const char *prefsFileName_App_ = "prefs.cfg"; +static const char *stateFileName_App_ = "state.binary"; +static const char *downloadDir_App_ = "~/Downloads"; struct Impl_App { iCommandLine args; @@ -103,6 +104,7 @@ struct Impl_App { iBool useSystemTheme; iString gopherProxy; iString httpProxy; + iString downloadDir; }; static iApp app_; @@ -161,6 +163,7 @@ static iString *serializePrefs_App_(const iApp *d) { appendFormat_String(str, "ostheme arg:%d\n", d->useSystemTheme); appendFormat_String(str, "proxy.gopher address:%s\n", cstr_String(&d->gopherProxy)); appendFormat_String(str, "proxy.http address:%s\n", cstr_String(&d->httpProxy)); + appendFormat_String(str, "downloads path:%s\n", cstr_String(&d->downloadDir)); return str; } @@ -312,6 +315,7 @@ static void init_App_(iApp *d, int argc, char **argv) { d->tabEnum = 0; /* generates unique IDs for tab pages */ init_String(&d->gopherProxy); init_String(&d->httpProxy); + initCStr_String(&d->downloadDir, downloadDir_App_); setThemePalette_Color(d->theme); #if defined (iPlatformApple) setupApplication_MacOS(); @@ -386,6 +390,7 @@ static void init_App_(iApp *d, int argc, char **argv) { static void deinit_App(iApp *d) { saveState_App_(d); savePrefs_App_(d); + deinit_String(&d->downloadDir); deinit_String(&d->httpProxy); deinit_String(&d->gopherProxy); save_Bookmarks(d->bookmarks, dataDir_App_); @@ -783,6 +788,10 @@ iBool handleCommand_App(const char *cmd) { d->retainWindowSize = arg_Command(cmd); return iTrue; } + else if (equal_Command(cmd, "downloads")) { + setCStr_String(&d->downloadDir, suffixPtr_Command(cmd, "path")); + return iTrue; + } else if (equal_Command(cmd, "open")) { const iString *url = collectNewCStr_String(suffixPtr_Command(cmd, "url")); iUrl parts; diff --git a/src/app.h b/src/app.h index a5b1266d..acc3e952 100644 --- a/src/app.h +++ b/src/app.h @@ -48,6 +48,7 @@ enum iUserEventCode { const iString *execPath_App (void); const iString *dataDir_App (void); +const iString *downloadDir_App (void); const iString *debugInfo_App (void); int run_App (int argc, char **argv); diff --git a/src/ui/window.c b/src/ui/window.c index 38df42e0..fbcf42fe 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -91,10 +91,13 @@ static iBool handleRootCommands_(iWidget *root, const char *cmd) { #endif #if !defined (iHaveNativeMenus) +/* TODO: Submenus wouldn't hurt here. */ static const iMenuItem navMenuItems[] = { { "New Tab", 't', KMOD_PRIMARY, "tabs.new" }, { "Open Location...", SDLK_l, KMOD_PRIMARY, "focus.set id:url" }, { "---", 0, 0, NULL }, + { "Save Page", SDLK_s, KMOD_PRIMARY, "document.save" }, + { "---", 0, 0, NULL }, { "Copy Source Text", SDLK_c, KMOD_PRIMARY, "copy" }, { "Bookmark This Page", SDLK_d, KMOD_PRIMARY, "bookmark.add" }, { "---", 0, 0, NULL }, @@ -104,7 +107,7 @@ static const iMenuItem navMenuItems[] = { { "Reset Zoom", SDLK_0, KMOD_PRIMARY, "zoom.set arg:100" }, { "---", 0, 0, NULL }, { "Preferences...", SDLK_COMMA, KMOD_PRIMARY, "preferences" }, - { "Help", 0, 0, "!open url:about:help" }, + { "Help", SDLK_F1, 0, "!open url:about:help" }, { "Release Notes", 0, 0, "!open url:about:version" }, { "---", 0, 0, NULL }, { "Quit Lagrange", 'q', KMOD_PRIMARY, "quit" } @@ -116,6 +119,8 @@ static const iMenuItem navMenuItems[] = { static const iMenuItem fileMenuItems[] = { { "New Tab", SDLK_t, KMOD_PRIMARY, "tabs.new" }, { "Open Location...", SDLK_l, KMOD_PRIMARY, "focus.set id:url" }, + { "---", 0, 0, NULL }, + { "Save Page", SDLK_s, KMOD_PRIMARY, "document.save" }, }; static const iMenuItem editMenuItems[] = { -- cgit v1.2.3