gnome-commander r2494 - in branches/gcmd-1-3: . src



Author: epiotr
Date: Tue Mar 24 18:23:20 2009
New Revision: 2494
URL: http://svn.gnome.org/viewvc/gnome-commander?rev=2494&view=rev

Log:
Added support for embedded terminal

Added:
   branches/gcmd-1-3/src/gcmd-helper.cc
Modified:
   branches/gcmd-1-3/ChangeLog
   branches/gcmd-1-3/configure.in
   branches/gcmd-1-3/src/Makefile.am
   branches/gcmd-1-3/src/gnome-cmd-cmdline.cc
   branches/gcmd-1-3/src/gnome-cmd-data.cc
   branches/gcmd-1-3/src/gnome-cmd-data.h
   branches/gcmd-1-3/src/gnome-cmd-file-selector.cc
   branches/gcmd-1-3/src/gnome-cmd-main-menu.cc
   branches/gcmd-1-3/src/gnome-cmd-main-win.cc
   branches/gcmd-1-3/src/gnome-cmd-main-win.h
   branches/gcmd-1-3/src/gnome-cmd-user-actions.cc
   branches/gcmd-1-3/src/gnome-cmd-user-actions.h

Modified: branches/gcmd-1-3/configure.in
==============================================================================
--- branches/gcmd-1-3/configure.in	(original)
+++ branches/gcmd-1-3/configure.in	Tue Mar 24 18:23:20 2009
@@ -47,6 +47,7 @@
 GNOME_REQ=2.0.0
 GNOMEUI_REQ=2.4.0
 GNOMEVFS_REQ=2.0.0
+VTE_REQ=0.11
 PYTHON_REQ=2.4
 EXIV2_REQ=0.14
 TAGLIB_REQ=1.4
@@ -58,6 +59,7 @@
 AC_SUBST(GNOME_REQ)
 AC_SUBST(GNOMEUI_REQ)
 AC_SUBST(GNOMEVFS_REQ)
+AC_SUBST(VTE_REQ)
 AC_SUBST(PYTHON_REQ)
 AC_SUBST(EXIV2_REQ)
 AC_SUBST(TAGLIB_REQ)
@@ -191,6 +193,10 @@
 fi
 
 
+dnl Check for vte support
+PKG_CHECK_MODULES(VTE, vte >= $VTE_REQ, have_vte=yes, have_vte=no)
+
+
 dnl Check for exiv2 support
 AC_ARG_WITH(libexiv2, [  --without-exiv2         disable EXIF and IPTC support])
 have_exiv2=no
@@ -434,6 +440,7 @@
 echo "  gnome    : ${GNOME_VERSION}	in ${GNOME_PREFIX}"
 echo "  gnomeui  : ${GNOMEUI_VERSION}	in ${GNOMEUI_PREFIX}"
 echo "  gnome-vfs: ${GNOMEVFS_VERSION}	in ${GNOMEVFS_PREFIX}"
+echo "  vte      : ${VTE_REQ}	in ${GLIB_PREFIX}"
 if test "x$have_python" = "xyes"; then
 echo "  python   : ${PYTHON_VERSION}	in ${PY_EXEC_PREFIX}"
 fi

Modified: branches/gcmd-1-3/src/Makefile.am
==============================================================================
--- branches/gcmd-1-3/src/Makefile.am	(original)
+++ branches/gcmd-1-3/src/Makefile.am	Tue Mar 24 18:23:20 2009
@@ -7,11 +7,12 @@
 	-I$(top_srcdir) \
 	$(GNOMEUI_CFLAGS) \
 	$(GNOMEVFS_CFLAGS) \
+	$(VTE_CFLAGS) \
 	$(PYTHON_CFLAGS) \
 	-DDATADIR=\""$(datadir)"\"\
 	-DPLUGIN_DIR=\""$(libdir)/$(PACKAGE)/plugins"\"
 
-bin_PROGRAMS = gnome-commander gcmd-block
+bin_PROGRAMS = gnome-commander gcmd-block gcmd-helper
 
 gnome_commander_SOURCES = \
 	cap.cc cap.h \
@@ -100,6 +101,7 @@
 gnome_commander_LDADD = \
 	$(GNOMEUI_LIBS) \
 	$(GNOMEVFS_LIBS) \
+	$(VTE_LIBS) \
 	$(EXIV2_LIBS) \
 	$(TAGLIB_LIBS) \
 	$(CHM_LIBS) \
@@ -117,3 +119,5 @@
 	$(GNOMEVFS_LIBS)
 
 gcmd_block_SOURCES = block.cc
+
+gcmd_helper_SOURCES = gcmd-helper.cc

Added: branches/gcmd-1-3/src/gcmd-helper.cc
==============================================================================
--- (empty file)
+++ branches/gcmd-1-3/src/gcmd-helper.cc	Tue Mar 24 18:23:20 2009
@@ -0,0 +1,50 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+const char *progname;
+
+void
+error(const char *msg, const char *arg="")
+{
+    fprintf(stderr, "%s: %s%s%s\n", progname, msg, (*arg ? ": " : ""), arg);
+    exit(1);
+}
+
+void
+writestring(const char *s, FILE *f)
+{
+    size_t size = strlen(s)+1;
+    if (fwrite(s, 1, size, f) != size)
+        error("Cannot write output file, disk full?");
+}
+
+int
+main(int argc, char **argv)
+{
+    progname = argv[0];
+    if (argc != 2)
+        error("One command line argument expected");
+
+    const char *fname = argv[1];
+    FILE *f = fopen(fname, "w");
+    if (f==NULL)
+        error(fname, strerror(errno));
+
+    const size_t bufsize = 4096;
+    char cwd[bufsize];
+    if (getcwd(cwd, bufsize)==NULL)
+        error("Cannot get current directory");
+
+    writestring(cwd, f);
+
+    for (char **pvar = environ; *pvar!=NULL; pvar++)
+        writestring(*pvar, f);
+
+    fclose(f);
+
+    return 0;
+}
+

Modified: branches/gcmd-1-3/src/gnome-cmd-cmdline.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-cmdline.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-cmdline.cc	Tue Mar 24 18:23:20 2009
@@ -69,6 +69,77 @@
     update_history_combo (cmdline);
 }
 
+char *g_tempfile = NULL;
+char **g_env = NULL;
+bool g_command_running = FALSE;
+
+static void run_in_terminal (GnomeCmdMainWin *mw, const gchar *command, const gchar *dir)
+{
+    if (strspn(command, " \t") == strlen(command))     // command empty or all whitespace
+        return;
+
+    if (g_command_running)
+    {
+        gnome_cmd_show_message (GTK_WINDOW (mw), _("There was a problem with the command"), _("The previous command is still running in the terminal."));
+
+        return;
+    }
+
+    VteTerminal *terminal = gnome_cmd_main_win_get_terminal (mw);
+
+    vte_terminal_feed (terminal, "\r\n", 2);
+    vte_terminal_feed (terminal, dir, strlen(dir));
+    vte_terminal_feed (terminal, "$ ", 2);                  // "$" -> 'g_env["PS1"]'
+    vte_terminal_feed (terminal, command, strlen(command)); // XXX strlen OK utf8-wise?
+    vte_terminal_feed (terminal, "\r\n", 2);
+
+    if (g_tempfile == NULL)
+    {
+        const char *tmp_dir = getenv("TMP");
+        if (tmp_dir == NULL || tmp_dir[0] == 0)
+            tmp_dir = getenv("TEMP");
+        if (tmp_dir == NULL || tmp_dir[0] == 0)
+            tmp_dir = "/tmp";
+        g_tempfile = g_strdup_printf ("%s/gcmd-%d-XXXXXXXX", tmp_dir, (int) getpid());
+        mktemp(g_tempfile); // cannot use mkstemp() because helper prog will need to write this file
+    }
+
+    // PROBLEM WITH VTE_TERMINAL: when it receives SIGCHILD, it stops reading the pipe, so it loses the rest of the output!
+    // Workaround used here: append "; sleep 1" to the end of the command to give the terminal more time (i.e. delay SIGCHILD)
+    // Another possible workaround: steal SIGCHILD handler from VTE so it doesn't get notified...?
+
+    // if the command contains "&", bash reports "illegal token"; workaround is to put the command in parens
+    // HOWEVER, still these processes will immediately die as the shell exists; how to make them orphaned so that they survive...?
+    bool paren = command[strlen(command)-1] == '&';
+
+    // gcmd-helper will save cwd and env[] into the temp file, which we'll read afterwards
+    // gchar *full_command = g_strdup_printf ("%s%s%s; %s/bin/gcmd-helper %s; sleep 1", (paren?"(":""), command, (paren?")":""), PREFIX, g_tempfile);
+    gchar *full_command = g_strdup_printf ("%s%s%s; /home/andras/gcmd-devel/gcmd-1-3/src/gcmd-helper %s; sleep 1", (paren?"(":""), command, (paren?")":""), g_tempfile); //XXX debug
+    unlink(g_tempfile);
+
+    DEBUG('g', "running: %s\nin dir: %s\n", full_command, dir);
+
+    // from gnome-exec.c:
+    char *user_shell = gnome_util_user_shell ();
+    char *argv[4];
+    argv[0] = user_shell;
+    argv[1] = "-c";
+    argv[2] = (char *) full_command;
+    argv[3] = NULL;
+
+    pid_t command_pid = vte_terminal_fork_command (terminal, argv[0], argv, g_env, dir, TRUE, TRUE, TRUE);
+    g_free (full_command);
+    if (command_pid == -1)
+        return;  // launch failed
+
+    DEBUG('g', " pid: %d\n", (int) command_pid);
+
+    gnome_cmd_main_win_hide_panels (mw);
+    gnome_cmd_main_win_focus_terminal (mw); // we'll get it back the focus when terminal emits "child-exited" signal
+
+    g_command_running = TRUE;
+}
+
 
 static void on_exec (GnomeCmdCmdline *cmdline, gboolean term)
 {
@@ -105,7 +176,8 @@
             {
                 gchar *fpath = gnome_cmd_file_get_real_path (GNOME_CMD_FILE (fs->get_directory()));
 
-                run_command_indir (cmdline_text, fpath, term);
+                // run_command_indir (cmdline_text, fpath, term);
+                run_in_terminal (main_win, cmdline_text, fpath);
                 g_free (fpath);
             }
 
@@ -131,7 +203,7 @@
             break;
     }
 
-    return gnome_cmd_cmdline_keypressed (cmdline, event) || gnome_cmd_main_win_keypressed (main_win, event);
+    return gnome_cmd_cmdline_keypressed (cmdline, event) || !gnome_cmd_data.terminal_visibility && gnome_cmd_main_win_keypressed (main_win, event);
 }
 
 

Modified: branches/gcmd-1-3/src/gnome-cmd-data.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-data.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-data.cc	Tue Mar 24 18:23:20 2009
@@ -1070,6 +1070,7 @@
     concombo_visibility = TRUE;
     cmdline_visibility = TRUE;
     buttonbar_visibility = TRUE;
+    terminal_visibility = FALSE;
 
     use_ls_colors = FALSE;
 

Modified: branches/gcmd-1-3/src/gnome-cmd-data.h
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-data.h	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-data.h	Tue Mar 24 18:23:20 2009
@@ -170,6 +170,7 @@
     gboolean                     concombo_visibility;
     gboolean                     cmdline_visibility;
     gboolean                     buttonbar_visibility;
+    gboolean                     terminal_visibility;
 
     gboolean                     use_ls_colors;
 

Modified: branches/gcmd-1-3/src/gnome-cmd-file-selector.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-file-selector.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-file-selector.cc	Tue Mar 24 18:23:20 2009
@@ -1816,6 +1816,11 @@
     {
         switch (event->keyval)
         {
+            case GDK_O:
+            case GDK_o:
+                view_terminal ();
+                return TRUE;
+
             case GDK_V:
             case GDK_v:
                 gnome_cmd_file_selector_cap_paste (this);

Modified: branches/gcmd-1-3/src/gnome-cmd-main-menu.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-main-menu.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-main-menu.cc	Tue Mar 24 18:23:20 2009
@@ -718,7 +718,7 @@
     MenuData options_menu_uiinfo[] =
     {
         {
-            MENU_TYPE_ITEM, _("_Options..."), "Ctrl+O", NULL,
+            MENU_TYPE_ITEM, _("_Options..."), "Ctrl+Shift+O", NULL,
             (gpointer) options_edit, NULL,
             GNOME_APP_PIXMAP_STOCK, GTK_STOCK_PREFERENCES,
             NULL

Modified: branches/gcmd-1-3/src/gnome-cmd-main-win.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-main-win.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-main-win.cc	Tue Mar 24 18:23:20 2009
@@ -22,6 +22,7 @@
 #include <sys/wait.h>
 #include <sys/types.h>
 #include <unistd.h>
+#include <glib/gstdio.h>
 
 #include "gnome-cmd-includes.h"
 #include "gnome-cmd-cmdline.h"
@@ -101,6 +102,7 @@
     GtkWidget *cmdline_sep;
     GtkWidget *buttonbar;
     GtkWidget *buttonbar_sep;
+    GtkWidget *terminal;
 
     GtkWidget *tb_first_btn;
     GtkWidget *tb_back_btn;
@@ -694,6 +696,157 @@
 }
 
 
+static char *read_file (const char *filename, size_t maxsize, size_t &size)
+{
+    struct stat statbuf;
+    if (g_stat (filename, &statbuf) != 0)
+        return NULL;
+
+    FILE *f = fopen(filename, "r");
+    if (f == NULL)
+        return NULL;
+
+    size = statbuf.st_size;
+    size = min(size, maxsize); // impose some sensible limit on file size
+
+    char *buf = (char *) g_malloc (size+1);
+    size = fread(buf, 1, size, f);
+    fclose(f);
+
+    buf[size] = 0; // just to be safe
+
+    return buf;
+}
+
+
+// the following variables are defined and used in gnome_cmd_cmdline.cc
+extern char *g_tempfile;
+extern char **g_env;
+extern bool g_command_running;
+
+
+static void on_terminal_child_exited (GtkWidget *vte, GnomeCmdMainWin *mw)
+{
+    DEBUG('g', "done\n");
+    g_command_running = FALSE;
+
+    if (!gnome_cmd_data.terminal_visibility)
+        gnome_cmd_main_win_show_panels (mw);
+
+    gnome_cmd_main_win_focus_cmdline (mw);
+
+    // read the temp file, created by gcmd_helper
+    size_t size = 0;
+    char *buf = read_file (g_tempfile, 1024*1024, size);
+    if (buf != NULL)
+    {
+        // first string is the working directory when the shell exited
+        const char *working_dir = buf;
+        char *envstrings = buf + strlen(buf) + 1;
+
+        gnome_cmd_main_win_get_fs (main_win, ACTIVE)->goto_directory(working_dir);
+
+        // then environment variables set in the shell, in NAME=VALUE form
+        if (g_env != NULL)
+        {
+            for (char **p = g_env; *p; ++p)
+                g_free (*p);
+            g_free (g_env);
+            g_env = NULL;
+        }
+
+        // count strings
+        int n = 0;
+        for (char *s = envstrings; s < buf+size; s += strlen(s) + 1)
+            ++n;
+
+        // build new g_env[]
+        g_env = g_new (char *, n+1);
+        char *s = envstrings;
+        for (int i=0; i<n; ++i)
+        {
+            DEBUG('g', "  env[%d] @%d: '%s'\n", i, s-envstrings, s);
+            g_env[i] = g_strdup (s);
+            s += strlen(s) + 1;
+        }
+        g_env[n] = NULL;
+
+        g_free (buf);
+    }
+}
+
+
+static void on_terminal_popup_menu__copy (GtkMenuItem *menuitem, GtkWidget *vte)
+{
+    vte_terminal_copy_clipboard (VTE_TERMINAL (vte));
+}
+
+
+inline void terminal_popup_menu (GtkWidget *vte, GnomeCmdMainWin *mw, GdkEventButton *event=NULL)
+{
+    GtkWidget *menu = gtk_menu_new ();
+    GtkWidget *menuitem;
+
+    menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL);
+
+    if (vte_terminal_get_has_selection (VTE_TERMINAL (vte)))
+        g_signal_connect (menuitem, "activate", G_CALLBACK (on_terminal_popup_menu__copy), vte);
+    else
+        gtk_widget_set_sensitive (menuitem, FALSE);
+
+    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+
+    gtk_menu_shell_append (GTK_MENU_SHELL (menu), gtk_separator_menu_item_new ());
+
+    menuitem = gtk_menu_item_new_with_label (_("Hide terminal"));
+    g_signal_connect (menuitem, "activate", G_CALLBACK (view_terminal), NULL);
+    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
+
+    gtk_widget_show_all (menu);
+    gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
+                    (event != NULL) ? event->button : 0, gdk_event_get_time ((GdkEvent*) event));
+}
+
+
+static gboolean on_terminal_popup_menu (GtkWidget *vte, GnomeCmdMainWin *mw)
+{
+    terminal_popup_menu (vte, mw);
+
+    return TRUE;
+}
+
+
+static gboolean on_terminal_button_pressed (GtkWidget *vte, GdkEventButton *event, GnomeCmdMainWin *mw)
+{
+    if (event->type==GDK_BUTTON_PRESS && event->button==3)
+    {
+        terminal_popup_menu (vte, mw, event);
+
+        return TRUE;
+    }
+
+    return FALSE;
+}
+
+
+static gboolean on_terminal_key_pressed (GtkWidget *vte, GdkEventKey *event, GnomeCmdMainWin *mw)
+{
+    if (state_is_ctrl (event->state))
+        switch (event->keyval)
+        {
+            case GDK_O:
+            case GDK_o:
+                view_terminal ();
+                return TRUE;
+
+            default:
+                return FALSE;
+        }
+
+    return FALSE;
+}
+
+
 /*******************************
  * Gtk class implementation
  *******************************/
@@ -820,9 +973,20 @@
     gtk_widget_show (mw->priv->file_selector[RIGHT]);
     gtk_paned_pack2 (GTK_PANED (mw->priv->paned), mw->priv->file_selector[RIGHT], TRUE, TRUE);
 
+    // GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+    // gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+    // gtk_box_pack_start (GTK_BOX (mw->priv->vbox), scrolled_window, TRUE, TRUE, 0);
+
+    GtkWidget *terminal = mw->priv->terminal = vte_terminal_new ();
+    gtk_widget_ref (terminal);
+    gtk_object_set_data_full (GTK_OBJECT (main_win), "vbox", terminal, (GtkDestroyNotify) gtk_widget_unref);
+    // gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (terminal));
+    gtk_box_pack_start (GTK_BOX (mw->priv->vbox), terminal, TRUE, TRUE, 0);
+
     gnome_cmd_main_win_update_toolbar_visibility (main_win);
     gnome_cmd_main_win_update_cmdline_visibility (main_win);
     gnome_cmd_main_win_update_buttonbar_visibility (main_win);
+    gnome_cmd_main_win_update_panels_visibility (main_win);
 
     gtk_signal_connect (GTK_OBJECT (main_win), "realize", GTK_SIGNAL_FUNC (on_main_win_realize), mw);
     gtk_signal_connect (GTK_OBJECT (mw->priv->file_selector[LEFT]), "changed-dir", GTK_SIGNAL_FUNC (on_fs_dir_change), mw);
@@ -843,6 +1007,11 @@
     gtk_signal_connect (GTK_OBJECT (mw->priv->paned), "button-press-event", GTK_SIGNAL_FUNC (on_slide_button_press), mw);
     g_signal_connect (mw, "window-state-event", GTK_SIGNAL_FUNC (on_window_state_event), NULL);
 
+    g_signal_connect (terminal, "child-exited", G_CALLBACK (on_terminal_child_exited), mw);
+    g_signal_connect (terminal, "key-press-event", G_CALLBACK (on_terminal_key_pressed), mw);
+    g_signal_connect (terminal, "button-press-event", G_CALLBACK (on_terminal_button_pressed), mw);
+    g_signal_connect (terminal, "popup-menu", G_CALLBACK (on_terminal_popup_menu), mw);
+
     gnome_cmd_main_win_get_fs (mw, LEFT)->update_connections();
     gnome_cmd_main_win_get_fs (mw, RIGHT)->update_connections();
 
@@ -932,6 +1101,27 @@
 }
 
 
+void gnome_cmd_main_win_hide_panels (GnomeCmdMainWin *mw)
+{
+    gtk_widget_hide (mw->priv->paned);
+    gtk_widget_show (mw->priv->terminal);
+}
+
+
+void gnome_cmd_main_win_show_panels (GnomeCmdMainWin *mw)
+{
+    gtk_widget_show (mw->priv->paned);
+    gtk_widget_hide (mw->priv->terminal);
+}
+
+
+void gnome_cmd_main_win_focus_terminal (GnomeCmdMainWin *mw)
+{
+    gtk_widget_grab_focus (mw->priv->terminal);
+    mw->priv->focused_widget = mw->priv->terminal;
+}
+
+
 void gnome_cmd_main_win_focus_cmdline (GnomeCmdMainWin *mw)
 {
     if (gnome_cmd_data.cmdline_visibility)
@@ -1141,6 +1331,14 @@
 }
 
 
+VteTerminal *gnome_cmd_main_win_get_terminal (GnomeCmdMainWin *mw)
+{
+    g_return_val_if_fail (GNOME_CMD_IS_MAIN_WIN (mw), NULL);
+
+    return VTE_TERMINAL (mw->priv->terminal);
+}
+
+
 void gnome_cmd_main_win_update_bookmarks (GnomeCmdMainWin *mw)
 {
     g_return_if_fail (GNOME_CMD_IS_MAIN_WIN (mw));
@@ -1238,8 +1436,8 @@
             pos += 2;
         gtk_box_pack_start (GTK_BOX (mw->priv->vbox), mw->priv->cmdline_sep, FALSE, TRUE, 0);
         gtk_box_pack_start (GTK_BOX (mw->priv->vbox), mw->priv->cmdline, FALSE, TRUE, 1);
-        gtk_box_reorder_child (GTK_BOX (mw->priv->vbox), mw->priv->cmdline_sep, pos);
-        gtk_box_reorder_child (GTK_BOX (mw->priv->vbox), mw->priv->cmdline, pos+1);
+        gtk_box_reorder_child (GTK_BOX (mw->priv->vbox), mw->priv->cmdline_sep, pos+1);
+        gtk_box_reorder_child (GTK_BOX (mw->priv->vbox), mw->priv->cmdline, pos+2);
     }
     else
     {
@@ -1288,7 +1486,6 @@
     slide_set_50_50 (NULL, NULL);
 }
 
-
 void gnome_cmd_main_win_add_plugin_menu (GnomeCmdMainWin *mw, PluginData *data)
 {
     g_return_if_fail (GNOME_CMD_IS_MAIN_WIN (mw));
@@ -1330,3 +1527,4 @@
 {
     slide_set_50_50 (NULL, NULL);
 }
+

Modified: branches/gcmd-1-3/src/gnome-cmd-main-win.h
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-main-win.h	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-main-win.h	Tue Mar 24 18:23:20 2009
@@ -30,6 +30,8 @@
 
 struct GnomeCmdMainWinPrivate;
 
+#include <vte/vte.h>
+
 #include "gnome-cmd-file-selector.h"
 #include "gnome-cmd-advrename-dialog.h"
 #include "gnome-cmd-cmdline.h"
@@ -61,11 +63,16 @@
 void gnome_cmd_main_win_switch_fs (GnomeCmdMainWin *mw, GnomeCmdFileSelector *fs);
 
 GnomeCmdCmdline *gnome_cmd_main_win_get_cmdline (GnomeCmdMainWin *mw);
+VteTerminal *gnome_cmd_main_win_get_terminal (GnomeCmdMainWin *mw);
 
 void gnome_cmd_main_win_update_style (GnomeCmdMainWin *mw);
 
 void gnome_cmd_main_win_new_cwd (GnomeCmdMainWin *mw, const gchar *cwd);
 
+void gnome_cmd_main_win_hide_panels (GnomeCmdMainWin *mw);
+void gnome_cmd_main_win_show_panels (GnomeCmdMainWin *mw);
+void gnome_cmd_main_win_focus_terminal (GnomeCmdMainWin *mw);
+
 void gnome_cmd_main_win_focus_cmdline (GnomeCmdMainWin *mw);
 void gnome_cmd_main_win_focus_file_lists (GnomeCmdMainWin *mw);
 void gnome_cmd_main_win_refocus (GnomeCmdMainWin *mw);
@@ -78,6 +85,22 @@
 void gnome_cmd_main_win_update_buttonbar_visibility (GnomeCmdMainWin *mw);
 void gnome_cmd_main_win_update_list_orientation (GnomeCmdMainWin *mw);
 
+inline void gnome_cmd_main_win_update_panels_visibility (GnomeCmdMainWin *mw)
+{
+    g_return_if_fail (GNOME_CMD_IS_MAIN_WIN (mw));
+
+    if (gnome_cmd_data.terminal_visibility)
+        gnome_cmd_main_win_hide_panels (mw);
+    else
+        gnome_cmd_main_win_show_panels (mw);
+}
+
+inline void gnome_cmd_main_win_toggle_terminal_visibility (GnomeCmdMainWin *mw)
+{
+    gnome_cmd_data.terminal_visibility = !gnome_cmd_data.terminal_visibility;
+    gnome_cmd_main_win_update_panels_visibility (mw);
+}
+
 void gnome_cmd_main_win_add_plugin_menu (GnomeCmdMainWin *mw, PluginData *data);
 
 GnomeCmdState *gnome_cmd_main_win_get_state (GnomeCmdMainWin *mw);

Modified: branches/gcmd-1-3/src/gnome-cmd-user-actions.cc
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-user-actions.cc	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-user-actions.cc	Tue Mar 24 18:23:20 2009
@@ -292,7 +292,7 @@
     }
 
     if (!registered("options.edit"))
-        register_action(GDK_CONTROL_MASK, GDK_O, "options.edit");
+        register_action(GDK_CONTROL_MASK | GDK_SHIFT_MASK, GDK_O, "options.edit");
 
     if (!registered("plugins.execute_python"))
     {
@@ -343,6 +343,12 @@
     if (!registered("view.close_tab"))
         register_action(GDK_CONTROL_MASK, GDK_W, "view.close_tab");
 
+    if (!registered("view.terminal"))
+    {
+        unregister(GDK_CONTROL_MASK, GDK_O);                       // unregister CTRL+O as it was used previously for options.edit
+        register_action(GDK_CONTROL_MASK, GDK_O, "view.terminal");
+    }
+
     unregister(GDK_F9);                                 // unregister F9 if defined in [key-bindings]
     register_action(GDK_F9, "edit.search");             // and overwrite it with edit.search action
 
@@ -1392,6 +1398,13 @@
 }
 
 
+void view_terminal (GtkMenuItem *menuitem, gpointer not_used)
+{
+    if (!GTK_WIDGET_REALIZED (main_win)) return;
+    gnome_cmd_main_win_toggle_terminal_visibility (main_win);
+}
+
+
 /************** Options Menu **************/
 void options_edit (GtkMenuItem *menuitem, gpointer not_used)
 {

Modified: branches/gcmd-1-3/src/gnome-cmd-user-actions.h
==============================================================================
--- branches/gcmd-1-3/src/gnome-cmd-user-actions.h	(original)
+++ branches/gcmd-1-3/src/gnome-cmd-user-actions.h	Tue Mar 24 18:23:20 2009
@@ -289,6 +289,7 @@
 GNOME_CMD_USER_ACTION(view_root);
 GNOME_CMD_USER_ACTION(view_new_tab);
 GNOME_CMD_USER_ACTION(view_close_tab);
+GNOME_CMD_USER_ACTION(view_terminal);
 
 /************** Bookmarks Menu **************/
 GNOME_CMD_USER_ACTION(bookmarks_add_current);



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