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



commit ff4a743bbb3edc518fc10bcfef116b23102676cc
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
    (cherry picked from commit 9be0ee6968fbd9677c0eadca8df13ecffa6551b3)
    
    Conflicts:
    
    	doc/reference/vte-sections.txt
    	src/vte.c
    	src/vte.h

 doc/reference/vte-sections.txt |    2 +
 src/caps.c                     |    4 +
 src/osc                        |    2 +
 src/vte-private.h              |    4 +
 src/vte.c                      |  137 +++++++++++++++++++++++++++++++++++++++-
 src/vtebuffer.h                |    6 ++
 src/vteseq-n.gperf             |    2 +
 src/vteseq.c                   |   64 +++++++++++++++++++
 8 files changed, 220 insertions(+), 1 deletions(-)
---
diff --git a/doc/reference/vte-sections.txt b/doc/reference/vte-sections.txt
index 14a6669..9f72600 100644
--- a/doc/reference/vte-sections.txt
+++ b/doc/reference/vte-sections.txt
@@ -101,6 +101,8 @@ vte_buffer_feed
 vte_buffer_feed_child
 vte_buffer_feed_child_binary
 vte_buffer_reset
+vte_buffer_get_current_directory_uri
+vte_buffer_get_current_file_uri
 vte_buffer_get_icon_title
 vte_buffer_get_window_title
 vte_buffer_get_status_line
diff --git a/src/caps.c b/src/caps.c
index 1cdb905..2b383c0 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 b31b126..2c8905b 100644
--- a/src/vte-private.h
+++ b/src/vte-private.h
@@ -283,6 +283,10 @@ struct _VteBufferPrivate {
 	gchar *window_title_changed;
         gchar *icon_title;
 	gchar *icon_title_changed;
+        gchar *current_directory_uri;
+        gchar *current_directory_uri_changed;
+        gchar *current_file_uri;
+        gchar *current_file_uri_changed;
 
         /* Cursor */
         gboolean cursor_visible;
diff --git a/src/vte.c b/src/vte.c
index eec9fb0..62a3326 100644
--- a/src/vte.c
+++ b/src/vte.c
@@ -170,6 +170,8 @@ enum {
         BUFFER_PROP_ICON_TITLE,
         BUFFER_PROP_WINDOW_TITLE,
         BUFFER_PROP_PTY,
+        BUFFER_PROP_CURRENT_DIRECTORY_URI,
+        BUFFER_PROP_CURRENT_FILE_URI,
 };
 
 enum {
@@ -196,6 +198,8 @@ enum {
         BUFFER_TEXT_DELETED,
         BUFFER_CONTENTS_CHANGED,
         BUFFER_BELL,
+        BUFFER_CURRENT_DIRECTORY_URI_CHANGED,
+        BUFFER_CURRENT_FILE_URI_CHANGED,
         LAST_BUFFER_SIGNAL,
 };
 
@@ -11182,6 +11186,7 @@ vte_view_class_init(VteViewClass *klass)
                              g_cclosure_marshal_VOID__VOID,
 			     G_TYPE_NONE, 0);
 
+
         /**
          * VteView::text-scrolled:
          * @vteterminal: the object which received the signal
@@ -12301,6 +12306,35 @@ vte_buffer_get_icon_title(VteBuffer *buffer)
 }
 
 /**
+ * vte_buffer_get_current_directory_uri:
+ * @buffer: a #VteBuffer
+ *
+ * Returns: (transfer none): the URI of the current directory of the
+ *   process running in the buffer, or %NULL
+ */
+const char *
+vte_buffer_get_current_directory_uri(VteBuffer *buffer)
+{
+        g_return_val_if_fail(VTE_IS_BUFFER(buffer), NULL);
+        return buffer->pvt->current_directory_uri;
+}
+
+/**
+ * vte_buffer_get_current_file_uri:
+ * @buffer: a #VteBuffer
+ *
+ * Returns: (transfer none): the URI of the current file the
+ *   process running in the buffer is operating on, or %NULL if
+ *   not set
+ */
+const char *
+vte_buffer_get_current_file_uri(VteBuffer *buffer)
+{
+        g_return_val_if_fail(VTE_IS_BUFFER(buffer), NULL);
+        return buffer->pvt->current_file_uri;
+}
+
+/**
  * vte_buffer_set_pty:
  * @terminal: a #VteView
  * @pty: (allow-none): a #VtePty, or %NULL
@@ -12654,6 +12688,22 @@ vte_buffer_emit_window_title_changed(VteBuffer *buffer)
 }
 
 static void
+vte_buffer_emit_current_directory_uri_changed(VteBuffer *buffer)
+{
+        _vte_debug_print(VTE_DEBUG_SIGNALS,
+                        "Emitting `current-directory-uri-changed'.\n");
+        g_signal_emit(buffer, buffer_signals[BUFFER_CURRENT_DIRECTORY_URI_CHANGED], 0);
+}
+
+static void
+vte_buffer_emit_current_file_uri_changed(VteBuffer *buffer)
+{
+        _vte_debug_print(VTE_DEBUG_SIGNALS,
+                        "Emitting `current-file-uri-changed'.\n");
+        g_signal_emit(buffer, buffer_signals[BUFFER_CURRENT_FILE_URI_CHANGED], 0);
+}
+
+static void
 vte_view_emit_pending_signals(VteView *terminal)
 {
         VteBuffer *buffer;
@@ -12698,6 +12748,24 @@ vte_view_emit_pending_signals(VteView *terminal)
                 g_object_notify(buffer_object, "icon-title");
 	}
 
+        if (buffer->pvt->current_directory_uri_changed) {
+                g_free (buffer->pvt->current_directory_uri);
+                buffer->pvt->current_directory_uri = buffer->pvt->current_directory_uri_changed;
+                buffer->pvt->current_directory_uri_changed = NULL;
+
+                vte_buffer_emit_current_directory_uri_changed(buffer);
+                g_object_notify(buffer_object, "current-directory-uri");
+        }
+
+        if (buffer->pvt->current_file_uri_changed) {
+                g_free (buffer->pvt->current_file_uri);
+                buffer->pvt->current_file_uri = buffer->pvt->current_file_uri_changed;
+                buffer->pvt->current_file_uri_changed = NULL;
+
+                vte_buffer_emit_current_file_uri_changed(buffer);
+                g_object_notify(buffer_object, "current-file-uri");
+        }
+
 	/* Flush any pending "inserted" signals. */
 	vte_buffer_emit_cursor_moved(buffer);
 	vte_buffer_emit_pending_text_signals(buffer, 0);
@@ -13659,7 +13727,6 @@ vte_buffer_init(VteBuffer *buffer)
 
         /* Cursor */
         pvt->cursor_visible = TRUE;
-
 }
 
 static void
@@ -13754,6 +13821,10 @@ vte_buffer_finalize(GObject *object)
         g_free(buffer->pvt->icon_title);
         g_free(buffer->pvt->window_title_changed);
         g_free(buffer->pvt->icon_title_changed);
+        g_free(buffer->pvt->current_directory_uri_changed);
+        g_free(buffer->pvt->current_directory_uri);
+        g_free(buffer->pvt->current_file_uri_changed);
+        g_free(buffer->pvt->current_file_uri);
 
         G_OBJECT_CLASS(vte_buffer_parent_class)->finalize(object);
 }
@@ -13770,6 +13841,12 @@ vte_buffer_get_property (GObject *object,
         case BUFFER_PROP_BACKSPACE_BINDING:
                 g_value_set_enum(value, buffer->pvt->backspace_binding);
                 break;
+        case BUFFER_PROP_CURRENT_DIRECTORY_URI:
+                g_value_set_string (value, vte_buffer_get_current_directory_uri (buffer));
+                break;
+        case BUFFER_PROP_CURRENT_FILE_URI:
+                g_value_set_string (value, vte_buffer_get_current_file_uri (buffer));
+                break;
         case BUFFER_PROP_DELETE_BINDING:
                 g_value_set_enum(value, buffer->pvt->delete_binding);
                 break;
@@ -13825,6 +13902,8 @@ vte_buffer_set_property (GObject *object,
                 vte_buffer_set_pty(buffer, g_value_get_object (value));
                 break;
         /* Not writable */
+        case BUFFER_PROP_CURRENT_DIRECTORY_URI:
+        case BUFFER_PROP_CURRENT_FILE_URI:
         case BUFFER_PROP_ICON_TITLE:
         case BUFFER_PROP_WINDOW_TITLE:
                 g_assert_not_reached ();
@@ -13915,6 +13994,38 @@ vte_buffer_class_init(VteBufferClass *klass)
                              2, G_TYPE_STRING, G_TYPE_UINT);
 
         /**
+          * VteBuffer::current-directory-uri-changed:
+          * @buffer: the object which received the signal
+          *
+          * Emitted when the current directory URI is modified.
+          */
+        buffer_signals[BUFFER_CURRENT_DIRECTORY_URI_CHANGED] =
+                g_signal_new(I_("current-directory-uri-changed"),
+                             G_OBJECT_CLASS_TYPE(klass),
+                             G_SIGNAL_RUN_LAST,
+                             G_STRUCT_OFFSET(VteBufferClass, current_directory_uri_changed),
+                             NULL,
+                             NULL,
+                             g_cclosure_marshal_VOID__VOID,
+                             G_TYPE_NONE, 0);
+
+        /**
+          * VteBuffer::current-file-uri-changed:
+          * @buffer: the object which received the signal
+          *
+          * Emitted when the current file URI is modified.
+          */
+        buffer_signals[BUFFER_CURRENT_FILE_URI_CHANGED] =
+                g_signal_new(I_("current-file-uri-changed"),
+                             G_OBJECT_CLASS_TYPE(klass),
+                             G_SIGNAL_RUN_LAST,
+                             G_STRUCT_OFFSET(VteBufferClass, current_file_uri_changed),
+                             NULL,
+                             NULL,
+                             g_cclosure_marshal_VOID__VOID,
+                             G_TYPE_NONE, 0);
+
+        /**
          * VteView::emulation-changed:
          * @vteterminal: the object which received the signal
          *
@@ -14286,6 +14397,30 @@ vte_buffer_class_init(VteBufferClass *klass)
                                     G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
         /**
+          * VteBuffer:current-directory-uri:
+          *
+          * The current directory URI, or %NULL if unset.
+          */
+        g_object_class_install_property
+                (gobject_class,
+                 BUFFER_PROP_CURRENT_DIRECTORY_URI,
+                 g_param_spec_string ("current-directory-uri", NULL, NULL,
+                                      NULL,
+                                      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+        /**
+          * VteBuffer:current-file-uri:
+          *
+          * The current file URI, or %NULL if unset.
+          */
+        g_object_class_install_property
+                (gobject_class,
+                 BUFFER_PROP_CURRENT_FILE_URI,
+                 g_param_spec_string ("current-file-uri", NULL, NULL,
+                                      NULL,
+                                      G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
+        /**
          * VteBuffer:delete-binding:
          *
          * Controls what string or control sequence the terminal sends to its child
diff --git a/src/vtebuffer.h b/src/vtebuffer.h
index 430dd6d..b147087 100644
--- a/src/vtebuffer.h
+++ b/src/vtebuffer.h
@@ -71,6 +71,8 @@ struct _VteBufferClass {
   void (*encoding_changed)     (VteBuffer *buffer);
   void (*icon_title_changed)   (VteBuffer* buffer);
   void (*window_title_changed) (VteBuffer* buffer);
+  void (*current_directory_uri_changed) (VteBuffer* buffer);
+  void (*current_file_uri_changed)      (VteBuffer* buffer);
   void (*status_line_changed)  (VteBuffer* buffer);
   void (*eof)                  (VteBuffer* buffer);
   void (*child_exited)         (VteBuffer *buffer,
@@ -158,6 +160,10 @@ const char *vte_buffer_get_window_title (VteBuffer *buffer);
 
 const char *vte_buffer_get_icon_title   (VteBuffer *buffer);
 
+const char *vte_buffer_get_current_directory_uri  (VteBuffer *buffer);
+
+const char *vte_buffer_get_current_file_uri       (VteBuffer *buffer);
+
 const char *vte_buffer_get_status_line  (VteBuffer *buffer);
 
 void vte_buffer_set_size                (VteBuffer *buffer,
diff --git a/src/vteseq-n.gperf b/src/vteseq-n.gperf
index c143fb1..abe4af2 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 d201bcc..5e08520 100644
--- a/src/vteseq.c
+++ b/src/vteseq.c
@@ -2451,6 +2451,70 @@ vte_sequence_handler_set_icon_and_window_title (VteBuffer *buffer, GValueArray *
 	vte_sequence_handler_set_title_internal(buffer, params, TRUE, TRUE);
 }
 
+static void
+vte_sequence_handler_set_current_directory_uri (VteBuffer *buffer, 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_buffer_ucs4_to_utf8 (buffer, 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(buffer->pvt->current_directory_uri_changed);
+        buffer->pvt->current_directory_uri_changed = uri;
+}
+
+static void
+vte_sequence_handler_set_current_file_uri (VteBuffer *buffer, 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_buffer_ucs4_to_utf8 (buffer, 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(buffer->pvt->current_file_uri_changed);
+        buffer->pvt->current_file_uri_changed = uri;
+}
+
 /* Restrict the scrolling region. */
 static void
 vte_sequence_handler_set_scrolling_region (VteBuffer *buffer, GValueArray *params)



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