diff options
author | Benedikt Meurer <benny@xfce.org> | 2005-09-11 00:07:08 +0000 |
---|---|---|
committer | Benedikt Meurer <benny@xfce.org> | 2005-09-11 00:07:08 +0000 |
commit | 450cd047230e9bd467a99de829b628ec0270af22 (patch) | |
tree | e66e84ee192e2de6da6e88ea1d60f6c5ddb651a5 /examples | |
parent | fe2091e1c9bb84053761cda63507feae30b37332 (diff) | |
download | thunar-450cd047230e9bd467a99de829b628ec0270af22.tar.gz |
2005-09-09 Benedikt Meurer <benny@xfce.org>
* configure.in.in: Substitute version information.
* thunar/thunar-window.c(thunar_window_action_about): Escape the
copyright sign.
* thunar/thunar-gdk-pixbuf-extensions.{c,h},
thunar/thunar-gtk-extensions.{c,h}, thunar/thunar-desktop-view.c,
thunar/thunar-icon-factory.c, thunar/thunar-icon-renderer.c,
thunar/thunar-standard-view.c, thunar/thunar-window.c,
thunar/Makefile.am: Merge the GdkPixbuf and GTK+ extensions into
the thunar namespace.
* configure.in.in, thunarx/: Import the initial extensions library.
* configure.in.in, docs/Makefile.am, Makefile.am, docs/reference/:
Import the reference manual for the extensions library.
* thunar/thunar-file.c: Implement the ThunarxFileInfo interface.
* thunar/thunar-extension-manager.{c,h}, thunar/Makefile.am: Import the
ThunarExtensionManager class.
* thunar/thunar-standard-view-ui.xml, thunar/thunar-standard-view.c: Add
support for context menu providers to the standard views.
* po/POTFILES.in: Add thunarx/thunarx-property-page.c here.
* thunar/thunar-properties-dialog.c: Add support for property page
providers here.
* Makefile.am, configure.in.in, examples/Makefile.am,
examples/open-terminal-here/: Add "Open Terminal Here" menu provider
example.
(Old svn revision: 17553)
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Makefile.am | 6 | ||||
-rw-r--r-- | examples/open-terminal-here/Makefile.am | 40 | ||||
-rw-r--r-- | examples/open-terminal-here/README | 15 | ||||
-rw-r--r-- | examples/open-terminal-here/open-terminal-here.c | 246 |
4 files changed, 307 insertions, 0 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am new file mode 100644 index 00000000..0811c7e9 --- /dev/null +++ b/examples/Makefile.am @@ -0,0 +1,6 @@ +# $Id$ + +SUBDIRS = \ + open-terminal-here + +# vi:set ts=8 sw=8 noet ai nocindent syntax=automake: diff --git a/examples/open-terminal-here/Makefile.am b/examples/open-terminal-here/Makefile.am new file mode 100644 index 00000000..75d02531 --- /dev/null +++ b/examples/open-terminal-here/Makefile.am @@ -0,0 +1,40 @@ +# $Id$ + +INCLUDES = \ + -I$(top_builddir) \ + -I$(top_srcdir) \ + -DG_LOG_DOMAIN=\"OpenTerminalHere\" + +extensionsdir = $(libdir)/thunarx-$(THUNAR_VERSION_API) +extensions_LTLIBRARIES = \ + open-terminal-here.la + +open_terminal_here_la_SOURCES = \ + open-terminal-here.c + +open_terminal_here_la_CFLAGS = \ + $(GTK_CFLAGS) + +open_terminal_here_la_DEPENDENCIES = \ + $(top_builddir)/thunarx/libthunarx-$(THUNAR_VERSION_API).la + +open_terminal_here_la_LIBADD = \ + $(top_builddir)/thunarx/libthunarx-$(THUNAR_VERSION_API).la \ + $(GTK_LIBS) + +open_terminal_here_la_LDFLAGS = \ + -avoid-version \ + -export-dynamic \ + -module + +CLEANFILES = \ + open-terminal-here.la + +EXTRA_DIST = \ + README + +# Don't install/uninstall examples by default +install: +uninstall: + +# vi:set ts=8 sw=8 noet ai nocindent syntax=automake: diff --git a/examples/open-terminal-here/README b/examples/open-terminal-here/README new file mode 100644 index 00000000..d56759f0 --- /dev/null +++ b/examples/open-terminal-here/README @@ -0,0 +1,15 @@ +This is an example for a Thunar Extension that provides additional context +menu items. It adds an "Open Terminal Here" action to the folder context +menu and to the file context menu of directories, and thereby allows you +to open a new Terminal instance in the given folder. + +The example is mainly provided for developers to get an idea about how +to write an extension that implements the ThunarxMenuProvider interface. + +The extension is not installed by default, as every installed extension +increases the resources required to run Thunar. If you want to install +this extension, you can use the command + + make install-extensionsLTLIBRARIES + +in this directory. diff --git a/examples/open-terminal-here/open-terminal-here.c b/examples/open-terminal-here/open-terminal-here.c new file mode 100644 index 00000000..e512b3fd --- /dev/null +++ b/examples/open-terminal-here/open-terminal-here.c @@ -0,0 +1,246 @@ +/* $Id$ */ +/*- + * Copyright (c) 2005 Benedikt Meurer <benny@xfce.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#ifdef HAVE_MEMORY_H +#include <memory.h> +#endif +#ifdef HAVE_STRING_H +#include <string.h> +#endif + +#include <thunarx/thunarx.h> + + + +/* make sure to export the required public functions */ +#ifdef HAVE_GNUC_VISIBILITY +extern void thunar_extension_initialize (GTypeModule *module) __attribute__((visibility("default"))); +extern void thunar_extension_shutdown (void) __attribute__((visibility("default"))); +extern void thunar_extension_list_types (const GType **types, gint *n_types) __attribute__((visibility("default"))); +#else +extern G_MODULE_EXPORT void thunar_extension_initialize (GTypeModule *module); +extern G_MODULE_EXPORT void thunar_extension_shutdown (void); +extern G_MODULE_EXPORT void thunar_extension_list_types (const GType **types, gint *n_types); +#endif + + + +static GType type_list[1]; + + + +typedef struct _OpenTerminalHereClass OpenTerminalHereClass; +typedef struct _OpenTerminalHere OpenTerminalHere; + + + +static void open_terminal_here_register_type (GTypeModule *module); +static void open_terminal_here_menu_provider_init (ThunarxMenuProviderIface *iface); +static GList *open_terminal_here_get_file_actions (ThunarxMenuProvider *provider, + GtkWidget *window, + GList *files); +static GList *open_terminal_here_get_folder_actions (ThunarxMenuProvider *provider, + GtkWidget *window, + ThunarxFileInfo *folder); +static void open_terminal_here_activated (GtkAction *action, + GtkWidget *window); + + + +struct _OpenTerminalHereClass +{ + GObjectClass __parent__; +}; + +struct _OpenTerminalHere +{ + GObject __parent__; +}; + + + +static void +open_terminal_here_register_type (GTypeModule *module) +{ + static const GTypeInfo info = + { + sizeof (OpenTerminalHereClass), + NULL, + NULL, + NULL, + NULL, + NULL, + sizeof (OpenTerminalHere), + 0, + NULL, + NULL, + }; + + static const GInterfaceInfo menu_provider_info = + { + (GInterfaceInitFunc) open_terminal_here_menu_provider_init, + NULL, + NULL, + }; + + type_list[0] = g_type_module_register_type (module, G_TYPE_OBJECT, "OpenTerminalHere", &info, 0); + g_type_module_add_interface (module, type_list[0], THUNARX_TYPE_MENU_PROVIDER, &menu_provider_info); +} + + + +static void +open_terminal_here_menu_provider_init (ThunarxMenuProviderIface *iface) +{ + iface->get_file_actions = open_terminal_here_get_file_actions; + iface->get_folder_actions = open_terminal_here_get_folder_actions; +} + + + +static GList* +open_terminal_here_get_file_actions (ThunarxMenuProvider *provider, + GtkWidget *window, + GList *files) +{ + /* check if we have a directory here */ + if (G_LIKELY (files != NULL && files->next == NULL && thunarx_file_info_is_directory (files->data))) + return open_terminal_here_get_folder_actions (provider, window, files->data); + + return NULL; +} + + + +static GList* +open_terminal_here_get_folder_actions (ThunarxMenuProvider *provider, + GtkWidget *window, + ThunarxFileInfo *folder) +{ + GtkAction *action = NULL; + gchar *scheme; + gchar *path; + gchar *uri; + + /* determine the uri scheme of the folder and check if we support it */ + scheme = thunarx_file_info_get_uri_scheme (folder); + if (G_LIKELY (strcmp (scheme, "file") == 0)) + { + /* determine the local path to the folder */ + uri = thunarx_file_info_get_uri (folder); + path = g_filename_from_uri (uri, NULL, NULL); + g_free (uri); + + /* check if we have a valid path here */ + if (G_LIKELY (path != NULL)) + { + action = gtk_action_new ("OpenTerminalHere::open-terminal-here", "Open Terminal Here", "Open Terminal in this folder", NULL); + g_signal_connect (G_OBJECT (action), "activate", G_CALLBACK (open_terminal_here_activated), window); + g_object_set_data_full (G_OBJECT (action), "open-terminal-here-path", path, g_free); + } + } + g_free (scheme); + + return (action != NULL) ? g_list_prepend (NULL, action) : NULL; +} + + + +static void +open_terminal_here_activated (GtkAction *action, + GtkWidget *window) +{ + const gchar *path; + GtkWidget *dialog; + GError *error = NULL; + gchar *command; + + /* determine the folder path */ + path = g_object_get_data (G_OBJECT (action), "open-terminal-here-path"); + if (G_UNLIKELY (path == NULL)) + return; + + /* build up the command line for the terminal */ + command = g_strdup_printf ("Terminal --working-directory \"%s\"", path); + + //g_message ("COMMAND=\"%s\"", command);return; + + /* try to run the terminal command */ + if (!gdk_spawn_command_line_on_screen (gtk_widget_get_screen (window), command, &error)) + { + /* display an error dialog */ + dialog = gtk_message_dialog_new (GTK_WINDOW (window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + "Failed to open terminal in folder %s.", + path); + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s.", error->message); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); + g_error_free (error); + } + + /* cleanup */ + g_free (command); +} + + + +void +thunar_extension_initialize (GTypeModule *module) +{ + const gchar *mismatch; + + /* verify that the thunarx versions are compatible */ + mismatch = thunarx_check_version (THUNARX_MAJOR_VERSION, THUNARX_MINOR_VERSION, THUNARX_MICRO_VERSION); + if (G_UNLIKELY (mismatch != NULL)) + { + g_warning ("Version mismatch: %s", mismatch); + return; + } + + g_message ("Initializing OpenTerminalHere extension"); + + open_terminal_here_register_type (module); +} + + + +void +thunar_extension_shutdown (void) +{ + g_message ("Shutting down OpenTerminalHere extension"); +} + + + +void +thunar_extension_list_types (const GType **types, + gint *n_types) +{ + *types = type_list; + *n_types = G_N_ELEMENTS (type_list); +} + |