Patch for "Open Terminal Here" keyboard shortcut
Aaron Lewis
the.warl0ck.1989 at gmail.com
Sun Nov 6 17:07:51 CET 2011
Hi Jogy,
That's very good idea !
But I tried this patch , but here i got a problem ,
When terminal is opened with "F4" , have you tried to close that
Thunar Window ? It's unable to be closed.
And multiple terminal (Press F4 for more than one time won't work ..)
A better implemention could be like this:
static gboolean thunar_window_open_term(ThunarWindow *window) {
char *command = g_strdup_printf("/usr/bin/xfce4-terminal --working-directory %s" , g_file_get_path(window->current_directory->gfile) );
g_spawn_command_line_async(command , NULL);
free (command);
return TRUE;
}
On 21:09 Sun 06 Nov , Jogy Antony wrote:
> Hello
>
> I am new to the open source world. I have made a patch to add a
> shortcut key to "Open Terminal Here" to be integrated with Thunar.
> This is a popular request. See
>
> http://forum.xfce.org/viewtopic.php?id=3885
> http://forum.xfce.org/viewtopic.php?id=4703
> http://www.linuxformat.com/forums/viewtopic.php?p=74240
>
> I am sorry, it is a little bit of a hack. Would it be possible for me
> to get it integrated to XFCE ?
> diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c
> index a42d982..e912071 100644
> --- a/thunar/thunar-window.c
> +++ b/thunar/thunar-window.c
> @@ -62,7 +62,8 @@
> #include <thunar/thunar-window-ui.h>
>
> #include <glib.h>
> -
> +#include <stdio.h>
> +#include <stdlib.h>
>
>
> /* Property identifiers */
> @@ -78,6 +79,7 @@ enum
> /* Signal identifiers */
> enum
> {
> + OPEN_TERMHERE,
> BACK,
> RELOAD,
> TOGGLE_SIDEPANE,
> @@ -99,6 +101,7 @@ static void thunar_window_set_property (GObject
> guint prop_id,
> const GValue *value,
> GParamSpec *pspec);
> +static gboolean thunar_window_open_term (ThunarWindow *window);
> static gboolean thunar_window_back (ThunarWindow *window);
> static gboolean thunar_window_reload (ThunarWindow *window);
> static gboolean thunar_window_toggle_sidepane (ThunarWindow *window);
> @@ -216,6 +219,7 @@ struct _ThunarWindowClass
> GtkWindowClass __parent__;
>
> /* internal action signals */
> + gboolean (*open_term) (ThunarWindow *window);
> gboolean (*back) (ThunarWindow *window);
> gboolean (*reload) (ThunarWindow *window);
> gboolean (*toggle_sidepane) (ThunarWindow *window);
> @@ -342,7 +346,30 @@ static guint window_signals[LAST_SIGNAL];
> G_DEFINE_TYPE_WITH_CODE (ThunarWindow, thunar_window, GTK_TYPE_WINDOW,
> G_IMPLEMENT_INTERFACE (THUNAR_TYPE_BROWSER, NULL))
>
> -
> +static gboolean thunar_window_open_term(ThunarWindow *window) {
> + char *init_command = "/usr/bin/xfce4-terminal --working-directory ";
> + char *path = g_file_get_path(window->current_directory->gfile);
> + char *final_command;
> + if( (final_command = malloc(strlen(init_command) + strlen(path))) == NULL ) {
> + fprintf(stderr,"Failed to allocate memory\n");
> + return FALSE;
> + }
> + sprintf(final_command,"%s%s",init_command,path);
> + pid_t fork_pid = fork();
> + if(fork_pid < 0) {
> + fprintf(stderr,"Failed to fork");
> + free(final_command);
> + return FALSE;
> + }
> + if(fork_pid == 0) {
> + system(final_command);
> + exit(0);
> + }
> +
> + wait(NULL);
> + free(final_command);
> + return TRUE;
> +}
>
> static void
> thunar_window_class_init (ThunarWindowClass *klass)
> @@ -361,7 +388,9 @@ thunar_window_class_init (ThunarWindowClass *klass)
> gtkwidget_class->realize = thunar_window_realize;
> gtkwidget_class->unrealize = thunar_window_unrealize;
> gtkwidget_class->configure_event = thunar_window_configure_event;
> -
> +
> +
> + klass->open_term = thunar_window_open_term;
> klass->back = thunar_window_back;
> klass->reload = thunar_window_reload;
> klass->toggle_sidepane = thunar_window_toggle_sidepane;
> @@ -426,6 +455,17 @@ thunar_window_class_init (ThunarWindowClass *klass)
> THUNAR_ZOOM_LEVEL_NORMAL,
> EXO_PARAM_READWRITE));
>
> + window_signals[OPEN_TERMHERE] =
> + g_signal_new (I_("open_term"),
> + G_TYPE_FROM_CLASS (klass),
> + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
> + G_STRUCT_OFFSET (ThunarWindowClass, open_term),
> + g_signal_accumulator_true_handled, NULL,
> + _thunar_marshal_BOOLEAN__VOID,
> + G_TYPE_BOOLEAN, 0);
> +
> +
> +
> /**
> * ThunarWindow::back:
> * @window : a #ThunarWindow instance.
> @@ -527,6 +567,7 @@ thunar_window_class_init (ThunarWindowClass *klass)
>
> /* setup the key bindings for the windows */
> binding_set = gtk_binding_set_by_class (klass);
> + gtk_binding_entry_add_signal (binding_set, GDK_F4, 0, "open_term", 0);
> gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0, "back", 0);
> gtk_binding_entry_add_signal (binding_set, GDK_F5, 0, "reload", 0);
> gtk_binding_entry_add_signal (binding_set, GDK_F9, 0, "toggle-sidepane", 0);
> _______________________________________________
> Xfce4-dev mailing list
> Xfce4-dev at xfce.org
> https://mail.xfce.org/mailman/listinfo/xfce4-dev
--
Best Regards,
Aaron Lewis - PGP: 0xDFE6C29E ( http://pgp.mit.edu/ )
Finger Print: 9482 448F C7C3 896C 1DFE 7DD3 2492 A7D0 DFE6 C29E
More information about the Xfce4-dev
mailing list