[vte/vte-0-34] emulation: Add sequences to set current directory and file



commit 9be0ee6968fbd9677c0eadca8df13ecffa6551b3
Author: Christian Persch <chpe gnome org>
Date:   Fri Jun 1 19:42:03 2012 +0200

    emulation: Add sequences to set current directory and file
    
    Add sequences
      OSC 6 ; URI BEL
      OSC 6 ; URI ST
      OSC 7 ; URI BEL
      OSC 7 ; URI ST
    that set the current file (OSC 7) and current directory (OSC 6) as an URI.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=675987

 doc/reference/vte-sections.txt |    2 +
 src/caps.c                     |    4 +
 src/osc                        |    2 +
 src/vte-private.h              |    4 +
 src/vte.c                      |  146 +++++++++++++++++++++++++++++++++++++++-
 src/vte.h                      |    2 +
 src/vteseq-n.gperf             |    2 +
 src/vteseq.c                   |   64 +++++++++++++++++
 8 files changed, 225 insertions(+), 1 deletions(-)
---
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index 1a7d821..8a473b0 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -141,6 +141,8 @@ vte_terminal_get_column_count
 vte_terminal_get_icon_title
 vte_terminal_get_row_count
 vte_terminal_get_window_title
+vte_terminal_get_current_directory_uri
+vte_terminal_get_current_file_uri
 
 <SUBSECTION Private>
 VTE_IS_TERMINAL_ANTI_ALIAS
diff --git a/src/caps.c b/src/caps.c
index c7217e0..7f20bc3 100644
--- a/src/caps.c
+++ b/src/caps.c
@@ -524,6 +524,8 @@ struct _vte_capability_string _vte_xterm_capability_strings[] = {
 	{OSC "2;%s" BEL, "set-window-title", 0},
 	{OSC "3;%s" BEL, "set-xproperty", 0},
 	{OSC "4;%s" BEL, "change-color", 0},
+        {OSC "6;%s" BEL, "set-current-file-uri", 0},
+        {OSC "7;%s" BEL, "set-current-directory-uri", 0},
 	{OSC "10;%s" BEL, "change-foreground-colors", 0},
 	{OSC "11;%s" BEL, "change-background-colors", 0},
 	{OSC "12;%s" BEL, "change-cursor-colors", 0},
@@ -543,6 +545,8 @@ struct _vte_capability_string _vte_xterm_capability_strings[] = {
 	{OSC "2;%s" ST, "set-window-title", 0},
 	{OSC "3;%s" ST, "set-xproperty", 0},
 	{OSC "4;%s" ST, "change-color", 0},
+        {OSC "6;%s" ST, "set-current-file-uri", 0},
+        {OSC "7;%s" ST, "set-current-directory-uri", 0},
 	{OSC "10;%s" ST, "change-foreground-colors", 0},
 	{OSC "11;%s" ST, "change-background-colors", 0},
 	{OSC "12;%s" ST, "change-cursor-colors", 0},
diff --git a/src/osc b/src/osc
index 1a8d41f..34dc9ea 100755
--- a/src/osc
+++ b/src/osc
@@ -8,6 +8,8 @@ if [ "$#" -eq 0 ] ; then
 	echo "	0 'title'	change icon name and window title"
 	echo "	1 'title'	change icon name"
 	echo "	2 'title'	change window title"
+	echo "	6 'uri'		change current file uri"
+	echo "	7 'uri'		change current directory uri"
 	echo "	12 'color'	change cursor color"
 	exit
 fi
diff --git a/src/vte-private.h b/src/vte-private.h
index 981bc79..d2cc6a3 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -363,6 +363,10 @@ struct _VteTerminalPrivate {
 	/* window name changes */
 	gchar *window_title_changed;
 	gchar *icon_title_changed;
+        gchar *current_directory_uri;
+        gchar *current_directory_uri_changed;
+        gchar *current_file_uri;
+        gchar *current_file_uri_changed;
 
 	/* Background images/"transparency". */
 	guint root_pixmap_changed_tag;
diff --git a/src/vte.c b/src/vte.c
index a60bb71..3801f74 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -174,6 +174,8 @@ enum {
         PROP_BACKSPACE_BINDING,
         PROP_CURSOR_BLINK_MODE,
         PROP_CURSOR_SHAPE,
+        PROP_CURRENT_DIRECTORY_URI,
+        PROP_CURRENT_FILE_URI,
         PROP_DELETE_BINDING,
         PROP_EMULATION,
         PROP_ENCODING,
@@ -9022,6 +9024,10 @@ vte_terminal_finalize(GObject *object)
 	/* discard title updates */
 	g_free(terminal->pvt->window_title_changed);
 	g_free(terminal->pvt->icon_title_changed);
+        g_free(terminal->pvt->current_directory_uri_changed);
+        g_free(terminal->pvt->current_directory_uri);
+        g_free(terminal->pvt->current_file_uri_changed);
+        g_free(terminal->pvt->current_file_uri);
 
 	/* Free public-facing data. */
 	g_free(terminal->window_title);
@@ -11581,6 +11587,12 @@ vte_terminal_get_property (GObject *object,
                 case PROP_CURSOR_BLINK_MODE:
                         g_value_set_enum (value, vte_terminal_get_cursor_blink_mode (terminal));
                         break;
+                case PROP_CURRENT_DIRECTORY_URI:
+                        g_value_set_string (value, vte_terminal_get_current_directory_uri (terminal));
+                        break;
+                case PROP_CURRENT_FILE_URI:
+                        g_value_set_string (value, vte_terminal_get_current_file_uri (terminal));
+                        break;
                 case PROP_CURSOR_SHAPE:
                         g_value_set_enum (value, vte_terminal_get_cursor_shape (terminal));
                         break;
@@ -11737,6 +11749,8 @@ vte_terminal_set_property (GObject *object,
                         break;
 
                 /* Not writable */
+                case PROP_CURRENT_DIRECTORY_URI:
+                case PROP_CURRENT_FILE_URI:
                 case PROP_ICON_TITLE:
                 case PROP_WINDOW_TITLE:
                         g_assert_not_reached ();
@@ -11971,6 +11985,41 @@ vte_terminal_class_init(VteTerminalClass *klass)
                              g_cclosure_marshal_VOID__VOID,
 			     G_TYPE_NONE, 0);
 
+
+        /**
+         * VteTerminal::current-directory-uri-changed:
+         * @vteterminal: the object which received the signal
+         *
+         * Emitted when the current directory URI is modified.
+         *
+         * Since: 0.34
+         */
+                g_signal_new(I_("current-directory-uri-changed"),
+                             G_OBJECT_CLASS_TYPE(klass),
+                             G_SIGNAL_RUN_LAST,
+                             0,
+                             NULL,
+                             NULL,
+                             g_cclosure_marshal_VOID__VOID,
+                             G_TYPE_NONE, 0);
+
+        /**
+         * VteTerminal::current-file-uri-changed:
+         * @vteterminal: the object which received the signal
+         *
+         * Emitted when the current file URI is modified.
+         *
+         * Since: 0.34
+         */
+                g_signal_new(I_("current-file-uri-changed"),
+                             G_OBJECT_CLASS_TYPE(klass),
+                             G_SIGNAL_RUN_LAST,
+                             0,
+                             NULL,
+                             NULL,
+                             g_cclosure_marshal_VOID__VOID,
+                             G_TYPE_NONE, 0);
+
         /**
          * VteTerminal::encoding-changed:
          * @vteterminal: the object which received the signal
@@ -12812,7 +12861,35 @@ vte_terminal_class_init(VteTerminalClass *klass)
                  g_param_spec_string ("window-title", NULL, NULL,
                                       NULL,
                                       G_PARAM_READABLE | STATIC_PARAMS));
-     
+
+        /**
+         * VteTerminal:current-directory-uri:
+         *
+         * The current directory URI, or %NULL if unset.
+         *
+         * Since: 0.34
+         */
+        g_object_class_install_property
+                (gobject_class,
+                 PROP_CURRENT_DIRECTORY_URI,
+                 g_param_spec_string ("current-directory-uri", NULL, NULL,
+                                      NULL,
+                                      G_PARAM_READABLE | STATIC_PARAMS));
+
+        /**
+         * VteTerminal:current-file-uri:
+         *
+         * The current file URI, or %NULL if unset.
+         *
+         * Since: 0.34
+         */
+        g_object_class_install_property
+                (gobject_class,
+                 PROP_CURRENT_FILE_URI,
+                 g_param_spec_string ("current-file-uri", NULL, NULL,
+                                      NULL,
+                                      G_PARAM_READABLE | STATIC_PARAMS));
+
         /**
          * VteTerminal:word-chars:
          *
@@ -14324,6 +14401,39 @@ vte_terminal_get_icon_title(VteTerminal *terminal)
 }
 
 /**
+ * vte_terminal_get_current_directory_uri:
+ * @terminal: a #VteTerminal
+ *
+ * Returns: (transfer none): the URI of the current directory of the
+ *   process running in the terminal, or %NULL
+ *
+ * Since: 0.34
+ */
+const char *
+vte_terminal_get_current_directory_uri(VteTerminal *terminal)
+{
+        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), NULL);
+        return terminal->pvt->current_directory_uri;
+}
+
+/**
+ * vte_terminal_get_current_file_uri:
+ * @terminal: a #VteTerminal
+ *
+ * Returns: (transfer none): the URI of the current file the
+ *   process running in the terminal is operating on, or %NULL if
+ *   not set
+ *
+ * Since: 0.34
+ */
+const char *
+vte_terminal_get_current_file_uri(VteTerminal *terminal)
+{
+        g_return_val_if_fail(VTE_IS_TERMINAL(terminal), NULL);
+        return terminal->pvt->current_file_uri;
+}
+
+/**
  * vte_terminal_set_pty:
  * @terminal: a #VteTerminal
  * @pty_master: a file descriptor of the master end of a PTY, or %-1
@@ -14744,6 +14854,22 @@ vte_terminal_emit_window_title_changed(VteTerminal *terminal)
 }
 
 static void
+vte_terminal_emit_current_directory_uri_changed(VteTerminal *terminal)
+{
+        _vte_debug_print(VTE_DEBUG_SIGNALS,
+                        "Emitting `current-directory-uri-changed'.\n");
+        g_signal_emit_by_name(terminal, "current-directory-uri-changed");
+}
+
+static void
+vte_terminal_emit_current_file_uri_changed(VteTerminal *terminal)
+{
+        _vte_debug_print(VTE_DEBUG_SIGNALS,
+                        "Emitting `current-file-uri-changed'.\n");
+        g_signal_emit_by_name(terminal, "current-file-uri-changed");
+}
+
+static void
 vte_terminal_emit_pending_signals(VteTerminal *terminal)
 {
         GObject *object;
@@ -14783,6 +14909,24 @@ vte_terminal_emit_pending_signals(VteTerminal *terminal)
                 g_object_notify(object, "icon-title");
 	}
 
+	if (terminal->pvt->current_directory_uri_changed) {
+                g_free (terminal->pvt->current_directory_uri);
+                terminal->pvt->current_directory_uri = terminal->pvt->current_directory_uri_changed;
+                terminal->pvt->current_directory_uri_changed = NULL;
+
+                vte_terminal_emit_current_directory_uri_changed(terminal);
+                g_object_notify(object, "current-directory-uri");
+        }
+
+        if (terminal->pvt->current_file_uri_changed) {
+                g_free (terminal->pvt->current_file_uri);
+                terminal->pvt->current_file_uri = terminal->pvt->current_file_uri_changed;
+                terminal->pvt->current_file_uri_changed = NULL;
+
+                vte_terminal_emit_current_file_uri_changed(terminal);
+                g_object_notify(object, "current-file-uri");
+        }
+
 	/* Flush any pending "inserted" signals. */
 	vte_terminal_emit_cursor_moved(terminal);
 	vte_terminal_emit_pending_text_signals(terminal, 0);
diff --git a/src/vte.h b/src/vte.h
index 4e514a1..ed3fafe 100644
--- a/src/vte.h
+++ b/src/vte.h
@@ -496,6 +496,8 @@ glong vte_terminal_get_row_count(VteTerminal *terminal);
 glong vte_terminal_get_column_count(VteTerminal *terminal);
 const char *vte_terminal_get_window_title(VteTerminal *terminal);
 const char *vte_terminal_get_icon_title(VteTerminal *terminal);
+const char *vte_terminal_get_current_directory_uri(VteTerminal *terminal);
+const char *vte_terminal_get_current_file_uri(VteTerminal *terminal);
 
 int vte_terminal_get_child_exit_status(VteTerminal *terminal);
 
diff --git a/src/vteseq-n.gperf b/src/vteseq-n.gperf
index 8cbcb21..197183e 100644
--- a/src/vteseq-n.gperf
+++ b/src/vteseq-n.gperf
@@ -129,3 +129,5 @@ struct vteseq_n_struct {
 "send-secondary-device-attributes", VTE_SEQUENCE_HANDLER(vte_sequence_handler_send_secondary_device_attributes)
 #"change-mouse-cursor-background-colors", VTE_SEQUENCE_HANDLER_NULL
 #"change-mouse-cursor-foreground-colors", VTE_SEQUENCE_HANDLER_NULL
+"set-current-directory-uri", VTE_SEQUENCE_HANDLER(vte_sequence_handler_set_current_directory_uri)
+"set-current-file-uri", VTE_SEQUENCE_HANDLER(vte_sequence_handler_set_current_file_uri)
diff --git a/src/vteseq.c b/src/vteseq.c
index 7fb4707..23745a1 100644
--- a/src/vteseq.c
+++ b/src/vteseq.c
@@ -2534,6 +2534,70 @@ vte_sequence_handler_set_icon_and_window_title (VteTerminal *terminal, GValueArr
 	vte_sequence_handler_set_title_internal(terminal, params, TRUE, TRUE);
 }
 
+static void
+vte_sequence_handler_set_current_directory_uri (VteTerminal *terminal, GValueArray *params)
+{
+        GValue *value;
+        char *uri, *filename;
+
+        uri = NULL;
+        if (params != NULL && params->n_values > 0) {
+                value = g_value_array_get_nth(params, 0);
+
+                if (G_VALUE_HOLDS_POINTER(value)) {
+                        uri = vte_ucs4_to_utf8 (terminal, g_value_get_pointer (value));
+                } else if (G_VALUE_HOLDS_STRING(value)) {
+                        /* Copy the string into the buffer. */
+                        uri = g_value_dup_string(value);
+                }
+        }
+
+        /* Validate URI */
+        filename = g_filename_from_uri (uri, NULL, NULL);
+        if (filename == NULL) {
+                /* invalid URI */
+                g_free (uri);
+                uri = NULL;
+        } else {
+                g_free (filename);
+        }
+
+        g_free(terminal->pvt->current_directory_uri_changed);
+        terminal->pvt->current_directory_uri_changed = uri;
+}
+
+static void
+vte_sequence_handler_set_current_file_uri (VteTerminal *terminal, GValueArray *params)
+{
+        GValue *value;
+        char *uri, *filename;
+
+        uri = NULL;
+        if (params != NULL && params->n_values > 0) {
+                value = g_value_array_get_nth(params, 0);
+
+                if (G_VALUE_HOLDS_POINTER(value)) {
+                        uri = vte_ucs4_to_utf8 (terminal, g_value_get_pointer (value));
+                } else if (G_VALUE_HOLDS_STRING(value)) {
+                        /* Copy the string into the buffer. */
+                        uri = g_value_dup_string(value);
+                }
+        }
+
+        /* Validate URI */
+        filename = g_filename_from_uri (uri, NULL, NULL);
+        if (filename == NULL) {
+                /* invalid URI */
+                g_free (uri);
+                uri = NULL;
+        } else {
+                g_free (filename);
+        }
+
+        g_free(terminal->pvt->current_file_uri_changed);
+        terminal->pvt->current_file_uri_changed = uri;
+}
+
 /* Restrict the scrolling region. */
 static void
 vte_sequence_handler_set_scrolling_region (VteTerminal *terminal, GValueArray *params)



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