diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2021-11-22 20:36:41 +0100 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2021-11-22 20:37:16 +0100 |
commit | 047e49051b0824e621f04de6f420b559e1fe135c (patch) | |
tree | eb06ff6b0ba63acfee1254fafd3a5864ad8173ba | |
parent | 4ed6aa6ad73367124b2fc98c44aeeb1d96da7cbf (diff) | |
download | fiv-047e49051b0824e621f04de6f420b559e1fe135c.tar.gz fiv-047e49051b0824e621f04de6f420b559e1fe135c.tar.xz fiv-047e49051b0824e621f04de6f420b559e1fe135c.zip |
Register for opening directories
-rw-r--r-- | fastiv-browse.desktop | 11 | ||||
-rw-r--r-- | fastiv.c | 27 | ||||
-rw-r--r-- | meson.build | 2 |
3 files changed, 32 insertions, 8 deletions
diff --git a/fastiv-browse.desktop b/fastiv-browse.desktop new file mode 100644 index 0000000..bdf01dc --- /dev/null +++ b/fastiv-browse.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Type=Application +Name=fastiv +GenericName=File Browser +Icon=fastiv +Exec=fastiv --browse %f +NoDisplay=true +Terminal=false +StartupNotify=true +Categories=Utility;FileTools; +MimeType=inode/directory; @@ -321,18 +321,25 @@ on_item_activated(G_GNUC_UNUSED FastivBrowser *browser, const char *path, } static gboolean -open_any_path(const char *path) +open_any_path(const char *path, gboolean force_browser) { GStatBuf st; gchar *canonical = g_canonicalize_filename(path, g.directory); gboolean success = !g_stat(canonical, &st); - if (!success) + if (!success) { show_error_dialog(g_error_new(G_FILE_ERROR, g_file_error_from_errno(errno), "%s: %s", path, g_strerror(errno))); - else if (S_ISDIR(st.st_mode)) + } else if (S_ISDIR(st.st_mode)) { load_directory(canonical); - else + } else if (force_browser) { + // GNOME, e.g., invokes this as a hint to focus the particular file, + // which we can't currently do yet. + gchar *directory = g_path_get_dirname(canonical); + load_directory(directory); + g_free(directory); + } else { open(canonical); + } g_free(canonical); return success; } @@ -346,7 +353,7 @@ on_open_location(G_GNUC_UNUSED GtkPlacesSidebar *sidebar, GFile *location, if (flags & GTK_PLACES_OPEN_NEW_WINDOW) spawn_path(path); else - open_any_path(path); + open_any_path(path, FALSE); g_free(path); } } @@ -520,7 +527,8 @@ on_button_press_browser(G_GNUC_UNUSED GtkWidget *widget, GdkEventButton *event) int main(int argc, char *argv[]) { - gboolean show_version = FALSE, show_supported_media_types = FALSE; + gboolean show_version = FALSE, show_supported_media_types = FALSE, + browse = FALSE; gchar **path_args = NULL; const GOptionEntry options[] = { {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &path_args, @@ -528,6 +536,9 @@ main(int argc, char *argv[]) {"list-supported-media-types", 0, G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &show_supported_media_types, "Output supported media types and exit", NULL}, + {"browse", 0, G_OPTION_FLAG_IN_MAIN, + G_OPTION_ARG_NONE, &browse, + "Start in filesystem browsing mode", NULL}, {"version", 'V', G_OPTION_FLAG_IN_MAIN, G_OPTION_ARG_NONE, &show_version, "Output version information and exit", NULL}, {}, @@ -699,8 +710,8 @@ main(int argc, char *argv[]) g.files = g_ptr_array_new_full(16, g_free); g.directory = g_get_current_dir(); - if (!path_arg || !open_any_path(path_arg)) - open_any_path(g.directory); + if (!path_arg || !open_any_path(path_arg, browse)) + open_any_path(g.directory, FALSE); // Try to get half of the screen vertically, in 4:3 aspect ratio. // diff --git a/meson.build b/meson.build index 970f81a..1561d19 100644 --- a/meson.build +++ b/meson.build @@ -56,6 +56,8 @@ endif install_data('fastiv.desktop', install_dir : get_option('datadir') + '/applications') +install_data('fastiv-browse.desktop', + install_dir : get_option('datadir') + '/applications') install_data('fastiv.svg', install_dir : get_option('datadir') + '/icons/hicolor/scalable/apps') |