[gthumb] added a 'Open in Terminal' command in the folder tree context menu



commit 0f88b3a9bfc02a8e2537b3aa48594c24b1e9ab5f
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Feb 23 10:06:05 2020 +0100

    added a 'Open in Terminal' command in the folder tree context menu

 data/gschemas/meson.build                          |   1 +
 .../gschemas/org.gnome.gthumb.terminal.gschema.xml |  27 ++++++
 extensions/meson.build                             |   1 +
 extensions/terminal/actions.c                      |  54 +++++++++++
 extensions/terminal/actions.h                      |  29 ++++++
 extensions/terminal/callbacks.c                    | 106 +++++++++++++++++++++
 extensions/terminal/callbacks.h                    |  32 +++++++
 extensions/terminal/main.c                         |  53 +++++++++++
 extensions/terminal/meson.build                    |  32 +++++++
 extensions/terminal/preferences.h                  |  37 +++++++
 .../terminal/terminal.extension.desktop.in.in      |  12 +++
 gthumb/gth-main.c                                  |   1 +
 12 files changed, 385 insertions(+)
---
diff --git a/data/gschemas/meson.build b/data/gschemas/meson.build
index 7afc8c85..9bbd822f 100644
--- a/data/gschemas/meson.build
+++ b/data/gschemas/meson.build
@@ -23,6 +23,7 @@ gschema_files = files(
   'org.gnome.gthumb.resize-images.gschema.xml',
   'org.gnome.gthumb.rotate.gschema.xml',
   'org.gnome.gthumb.slideshow.gschema.xml',
+  'org.gnome.gthumb.terminal.gschema.xml',
   'org.gnome.gthumb.webalbums.gschema.xml'
 )
 
diff --git a/data/gschemas/org.gnome.gthumb.terminal.gschema.xml 
b/data/gschemas/org.gnome.gthumb.terminal.gschema.xml
new file mode 100644
index 00000000..bf9297bc
--- /dev/null
+++ b/data/gschemas/org.gnome.gthumb.terminal.gschema.xml
@@ -0,0 +1,27 @@
+<!--
+  gThumb
+
+  Copyright © 2020 Free Software Foundation, Inc.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+-->
+<schemalist>
+
+  <schema id="org.gnome.gthumb.terminal" path="/org/gnome/gthumb/terminal/" gettext-domain="gthumb">
+    <key name="command" type="s">
+      <default>'gnome-terminal --window --working-directory=%f'</default>
+    </key>
+  </schema>
+
+</schemalist>
diff --git a/extensions/meson.build b/extensions/meson.build
index 33df1d0f..e2224912 100644
--- a/extensions/meson.build
+++ b/extensions/meson.build
@@ -75,3 +75,4 @@ subdir('selections')
 subdir('slideshow')
 subdir('desktop_background')
 subdir('find_duplicates')
+subdir('terminal')
diff --git a/extensions/terminal/actions.c b/extensions/terminal/actions.c
new file mode 100644
index 00000000..b411238c
--- /dev/null
+++ b/extensions/terminal/actions.c
@@ -0,0 +1,54 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2020 Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <config.h>
+#include <glib/gi18n.h>
+#include <gthumb.h>
+#include "actions.h"
+#include "preferences.h"
+
+
+void
+gth_browser_activate_folder_context_open_in_terminal (GSimpleAction *action,
+                                                     GVariant      *parameter,
+                                                     gpointer       user_data)
+{
+       GthBrowser  *browser = GTH_BROWSER (user_data);
+       GthFileData *file_data;
+       GList       *file_list;
+       GSettings   *settings;
+       char        *command;
+
+       file_data = gth_browser_get_folder_popup_file_data (browser);
+       if (file_data == NULL)
+               return;
+       file_list = g_list_prepend (NULL, file_data->file);
+
+       settings = g_settings_new (GTHUMB_TERMINAL_SCHEMA);
+       command = g_settings_get_string (settings, PREF_TERMINAL_COMMAND);
+       _g_launch_command (GTK_WIDGET (browser), command, _("Terminal"), G_APP_INFO_CREATE_NONE, file_list);
+
+       g_free (command);
+       g_object_unref (settings);
+       g_list_free (file_list);
+       g_object_unref (file_data);
+}
diff --git a/extensions/terminal/actions.h b/extensions/terminal/actions.h
new file mode 100644
index 00000000..ba708b2e
--- /dev/null
+++ b/extensions/terminal/actions.h
@@ -0,0 +1,29 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2020 Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef ACTIONS_H
+#define ACTIONS_H
+
+#include <gthumb.h>
+
+DEF_ACTION_CALLBACK (gth_browser_activate_folder_context_open_in_terminal)
+
+#endif /* ACTIONS_H */
diff --git a/extensions/terminal/callbacks.c b/extensions/terminal/callbacks.c
new file mode 100644
index 00000000..da383bd0
--- /dev/null
+++ b/extensions/terminal/callbacks.c
@@ -0,0 +1,106 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2020 Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <config.h>
+#include <glib/gi18n.h>
+#include <glib-object.h>
+#include <gthumb.h>
+#include "actions.h"
+#include "callbacks.h"
+
+
+#define BROWSER_DATA_KEY "terminal-browser-data"
+
+
+static const GActionEntry actions[] = {
+       { "folder-context-open-in-terminal", gth_browser_activate_folder_context_open_in_terminal }
+};
+
+
+static const GthMenuEntry folder_context_open_entries[] = {
+       { N_("Open in Terminal"), "win.folder-context-open-in-terminal" }
+};
+
+
+static const GthShortcut shortcuts[] = {
+       { "folder-context-open-in-terminal", N_("Open in Terminal"), GTH_SHORTCUT_CONTEXT_BROWSER_VIEWER, 
GTH_SHORTCUT_CATEGORY_FILE_MANAGER, "<Primary>t" },
+};
+
+
+typedef struct {
+       guint folder_context_open_id;
+} BrowserData;
+
+
+static void
+browser_data_free (BrowserData *data)
+{
+       g_free (data);
+}
+
+
+void
+terminal__gth_browser_construct_cb (GthBrowser *browser)
+{
+       BrowserData *data;
+
+       g_return_if_fail (GTH_IS_BROWSER (browser));
+
+       data = g_new0 (BrowserData, 1);
+       g_object_set_data_full (G_OBJECT (browser),
+                               BROWSER_DATA_KEY,
+                               data,
+                               (GDestroyNotify) browser_data_free);
+
+       g_action_map_add_action_entries (G_ACTION_MAP (browser),
+                                        actions,
+                                        G_N_ELEMENTS (actions),
+                                        browser);
+       gth_window_add_shortcuts (GTH_WINDOW (browser),
+                                 shortcuts,
+                                 G_N_ELEMENTS (shortcuts));
+}
+
+
+void
+terminal__gth_browser_folder_tree_popup_before_cb (GthBrowser    *browser,
+                                                  GthFileSource *file_source,
+                                                  GthFileData   *folder)
+{
+       BrowserData *data;
+
+       data = g_object_get_data (G_OBJECT (browser), BROWSER_DATA_KEY);
+       g_return_if_fail (data != NULL);
+
+       if (GTH_IS_FILE_SOURCE_VFS (file_source)) {
+               if (data->folder_context_open_id == 0)
+                       data->folder_context_open_id =
+                                       gth_menu_manager_append_entries (gth_browser_get_menu_manager 
(browser, GTH_BROWSER_MENU_MANAGER_FOLDER_OPEN_ACTIONS),
+                                                                        folder_context_open_entries,
+                                                                        G_N_ELEMENTS 
(folder_context_open_entries));
+       }
+       else {
+               if (data->folder_context_open_id != 0)
+                       gth_menu_manager_remove_entries (gth_browser_get_menu_manager (browser, 
GTH_BROWSER_MENU_MANAGER_FOLDER_OPEN_ACTIONS), data->folder_context_open_id);
+               data->folder_context_open_id = 0;
+       }
+}
diff --git a/extensions/terminal/callbacks.h b/extensions/terminal/callbacks.h
new file mode 100644
index 00000000..c88c8089
--- /dev/null
+++ b/extensions/terminal/callbacks.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2020 Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CALLBACKS_H
+#define CALLBACKS_H
+
+#include <gthumb.h>
+
+void   terminal__gth_browser_construct_cb                      (GthBrowser     *browser);
+void   terminal__gth_browser_folder_tree_popup_before_cb       (GthBrowser     *browser,
+                                                                GthFileSource  *file_source,
+                                                                GthFileData    *folder);
+
+#endif /* CALLBACKS_H */
diff --git a/extensions/terminal/main.c b/extensions/terminal/main.c
new file mode 100644
index 00000000..7bfacf1c
--- /dev/null
+++ b/extensions/terminal/main.c
@@ -0,0 +1,53 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2020 Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <config.h>
+#include <gtk/gtk.h>
+#include <gthumb.h>
+#include "callbacks.h"
+
+
+G_MODULE_EXPORT void
+gthumb_extension_activate (void)
+{
+       gth_hook_add_callback ("gth-browser-construct", 10, G_CALLBACK (terminal__gth_browser_construct_cb), 
NULL);
+       gth_hook_add_callback ("gth-browser-folder-tree-popup-before", 10, G_CALLBACK 
(terminal__gth_browser_folder_tree_popup_before_cb), NULL);
+}
+
+
+G_MODULE_EXPORT void
+gthumb_extension_deactivate (void)
+{
+}
+
+
+G_MODULE_EXPORT gboolean
+gthumb_extension_is_configurable (void)
+{
+       return FALSE;
+}
+
+
+G_MODULE_EXPORT void
+gthumb_extension_configure (GtkWindow *parent)
+{
+}
diff --git a/extensions/terminal/meson.build b/extensions/terminal/meson.build
new file mode 100644
index 00000000..95224aa9
--- /dev/null
+++ b/extensions/terminal/meson.build
@@ -0,0 +1,32 @@
+source_files = files(
+  'actions.c',
+  'callbacks.c',
+  'main.c'
+)
+
+shared_module('terminal',
+  sources : source_files,
+  dependencies : extension_common_deps,
+  include_directories : [ config_inc, gthumb_inc ],
+  c_args : c_args,
+  install : true,
+  install_dir : extensions_install_dir,
+  install_rpath : extensions_install_dir
+)
+
+# .extension file
+
+extension_in_file = configure_file(
+  input : 'terminal.extension.desktop.in.in',
+  output : 'terminal.extension.in',
+  configuration : extension_data
+)
+
+i18n.merge_file(
+  input : extension_in_file,
+  output : 'terminal.extension',
+  type : 'desktop',
+  po_dir : po_dir,
+  install : true,
+  install_dir : extensions_install_dir
+)
diff --git a/extensions/terminal/preferences.h b/extensions/terminal/preferences.h
new file mode 100644
index 00000000..84f58f7e
--- /dev/null
+++ b/extensions/terminal/preferences.h
@@ -0,0 +1,37 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ *  GThumb
+ *
+ *  Copyright (C) 2020 Free Software Foundation, Inc.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PREFERENCES_H
+#define PREFERENCES_H
+
+G_BEGIN_DECLS
+
+/* schema */
+
+#define GTHUMB_TERMINAL_SCHEMA GTHUMB_SCHEMA ".terminal"
+
+/* keys */
+
+#define PREF_TERMINAL_COMMAND "command"
+
+G_END_DECLS
+
+#endif /* PREFERENCES_H */
diff --git a/extensions/terminal/terminal.extension.desktop.in.in 
b/extensions/terminal/terminal.extension.desktop.in.in
new file mode 100644
index 00000000..669b2d4a
--- /dev/null
+++ b/extensions/terminal/terminal.extension.desktop.in.in
@@ -0,0 +1,12 @@
+[Extension]
+Name=Terminal
+Comment=Open a folder in a terminal
+Authors=gthumb development team
+Copyright=Copyright © 2009-2013 The Free Software Foundation, Inc.
+Version=@GTHUMB_VERSION@
+Icon=utilities-terminal
+Category=Browser
+
+[Loader]
+Type=module
+API=@GTHUMB_API_VERSION@
diff --git a/gthumb/gth-main.c b/gthumb/gth-main.c
index 3316b089..3b235c0b 100644
--- a/gthumb/gth-main.c
+++ b/gthumb/gth-main.c
@@ -1385,6 +1385,7 @@ gth_main_activate_extensions (void)
                "search",
                "selections",
                "slideshow",
+               "terminal",
                "webalbums",
                NULL
        };


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]