[Xfce4-commits] [apps/xfce4-terminal] 01/01: Add "Copy as HTML" to Edit and context menus

noreply at xfce.org noreply at xfce.org
Sat Jul 22 03:38:27 CEST 2017


This is an automated email from the git hooks/post-receive script.

f   2   4   0   4       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-terminal.

commit e03b02912483df4cfeaeb1738604badda796fe51
Author: Igor <f2404 at yandex.ru>
Date:   Fri Jul 21 21:36:31 2017 -0400

    Add "Copy as HTML" to Edit and context menus
    
    This action copies text in HTML format preserving its color, boldness, etc.
    The functionality will be available starting from vte 0.50 release.
---
 terminal/terminal-screen.c | 28 +++++++++++++++++++++++++++-
 terminal/terminal-screen.h |  3 +++
 terminal/terminal-window.c | 40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/terminal/terminal-screen.c b/terminal/terminal-screen.c
index 74dff03..472c677 100644
--- a/terminal/terminal-screen.c
+++ b/terminal/terminal-screen.c
@@ -1263,7 +1263,11 @@ terminal_screen_vte_selection_changed (VteTerminal    *terminal,
   g_object_get (G_OBJECT (screen->preferences),
                 "misc-copy-on-select", &copy_on_select, NULL);
   if (copy_on_select && vte_terminal_get_has_selection (terminal))
+#if VTE_CHECK_VERSION (0, 49, 2)
+    vte_terminal_copy_clipboard_format (terminal, VTE_FORMAT_TEXT);
+#else
     vte_terminal_copy_clipboard (terminal);
+#endif
 
   g_signal_emit (G_OBJECT (screen), screen_signals[SELECTION_CHANGED], 0);
 }
@@ -2068,14 +2072,36 @@ terminal_screen_has_selection (TerminalScreen *screen)
  * terminal_screen_copy_clipboard:
  * @screen  : A #TerminalScreen.
  *
- * Places the selected text in the terminal in the #GDK_SELECTIN_CLIPBOARD selection.
+ * Places the selected text in the terminal in the #GDK_SELECTION_CLIPBOARD selection.
  **/
 void
 terminal_screen_copy_clipboard (TerminalScreen *screen)
 {
   terminal_return_if_fail (TERMINAL_IS_SCREEN (screen));
+#if VTE_CHECK_VERSION (0, 49, 2)
+  vte_terminal_copy_clipboard_format (VTE_TERMINAL (screen->terminal), VTE_FORMAT_TEXT);
+#else
   vte_terminal_copy_clipboard (VTE_TERMINAL (screen->terminal));
+#endif
+}
+
+
+
+/**
+ * terminal_screen_copy_clipboard_html:
+ * @screen  : A #TerminalScreen.
+ *
+ * Places the selected text in the terminal in the #GDK_SELECTION_CLIPBOARD selection
+ * as HTML (preserving colors, bold font, etc).
+ **/
+#if VTE_CHECK_VERSION (0, 49, 2)
+void
+terminal_screen_copy_clipboard_html (TerminalScreen *screen)
+{
+  terminal_return_if_fail (TERMINAL_IS_SCREEN (screen));
+  vte_terminal_copy_clipboard_format (VTE_TERMINAL (screen->terminal), VTE_FORMAT_HTML);
 }
+#endif
 
 
 
diff --git a/terminal/terminal-screen.h b/terminal/terminal-screen.h
index a8b7c37..ad151b2 100644
--- a/terminal/terminal-screen.h
+++ b/terminal/terminal-screen.h
@@ -78,6 +78,9 @@ void            terminal_screen_set_working_directory     (TerminalScreen *scree
 gboolean        terminal_screen_has_selection             (TerminalScreen *screen);
 
 void            terminal_screen_copy_clipboard            (TerminalScreen *screen);
+#if VTE_CHECK_VERSION (0, 49, 2)
+void            terminal_screen_copy_clipboard_html       (TerminalScreen *screen);
+#endif
 void            terminal_screen_paste_clipboard           (TerminalScreen *screen);
 void            terminal_screen_paste_primary             (TerminalScreen *screen);
 
diff --git a/terminal/terminal-window.c b/terminal/terminal-window.c
index 671eef8..d0938cf 100644
--- a/terminal/terminal-window.c
+++ b/terminal/terminal-window.c
@@ -185,6 +185,10 @@ static void         terminal_window_action_close_window           (GtkAction
                                                                    TerminalWindow         *window);
 static void         terminal_window_action_copy                   (GtkAction              *action,
                                                                    TerminalWindow         *window);
+#if VTE_CHECK_VERSION (0, 49, 2)
+static void         terminal_window_action_copy_html              (GtkAction              *action,
+                                                                   TerminalWindow         *window);
+#endif
 static void         terminal_window_action_paste                  (GtkAction              *action,
                                                                    TerminalWindow         *window);
 static void         terminal_window_action_paste_selection        (GtkAction              *action,
@@ -323,6 +327,9 @@ static const GtkActionEntry action_entries[] =
     { "close-window", "application-exit", N_ ("Close _Window"), "<control><shift>q", NULL, G_CALLBACK (terminal_window_action_close_window), },
   { "edit-menu", NULL, N_ ("_Edit"), NULL, NULL, NULL, },
     { "copy", "edit-copy", N_ ("_Copy"), "<control><shift>c", N_ ("Copy to clipboard"), G_CALLBACK (terminal_window_action_copy), },
+#if VTE_CHECK_VERSION (0, 49, 2)
+    { "copy-html", "edit-copy", N_ ("Copy as _HTML"), NULL, N_ ("Copy to clipboard as HTML"), G_CALLBACK (terminal_window_action_copy_html), },
+#endif
     { "paste", "edit-paste", N_ ("_Paste"), "<control><shift>v", N_ ("Paste from clipboard"), G_CALLBACK (terminal_window_action_paste), },
     { "paste-selection", NULL, N_ ("Paste _Selection"), NULL, NULL, G_CALLBACK (terminal_window_action_paste_selection), },
     { "select-all", "edit-select-all", N_ ("Select _All"), "<control><shift>a", NULL, G_CALLBACK (terminal_window_action_select_all), },
@@ -458,7 +465,24 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 
   window->priv->ui_manager = gtk_ui_manager_new ();
   gtk_ui_manager_insert_action_group (window->priv->ui_manager, window->priv->action_group, 0);
+#if VTE_CHECK_VERSION (0, 49, 2)
+  {
+    /* add "Copy as HTML" to Edit and context menus */
+    const gchar *p1 = strstr (terminal_window_ui, "<menuitem action=\"paste\"/>"); // Edit menu
+    const gchar *p2 = strstr (p1 + 1, "<menuitem action=\"paste\"/>"); // context menu
+    const guint length_new = terminal_window_ui_length + 2 * strlen ("<menuitem action=\"copy-html\"/>");
+    gchar *ui_new = g_new0 (gchar, length_new + 1);
+    strncpy (ui_new, terminal_window_ui, p1 - terminal_window_ui);
+    strcat (ui_new, "<menuitem action=\"copy-html\"/>");
+    strncat (ui_new, p1, p2 - p1);
+    strcat (ui_new, "<menuitem action=\"copy-html\"/>");
+    strcat (ui_new, p2);
+    gtk_ui_manager_add_ui_from_string (window->priv->ui_manager, ui_new, length_new, NULL);
+    g_free (ui_new);
+  }
+#else
   gtk_ui_manager_add_ui_from_string (window->priv->ui_manager, terminal_window_ui, terminal_window_ui_length, NULL);
+#endif
 
   accel_group = gtk_ui_manager_get_accel_group (window->priv->ui_manager);
 G_GNUC_END_IGNORE_DEPRECATIONS
@@ -905,6 +929,10 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 
       gtk_action_set_sensitive (window->priv->action_copy,
                                 terminal_screen_has_selection (window->priv->active));
+#if VTE_CHECK_VERSION (0, 49,2)
+      gtk_action_set_sensitive (terminal_window_get_action (window, "copy-html"),
+                                terminal_screen_has_selection (window->priv->active));
+#endif
 
       can_search = terminal_screen_search_has_gregex (window->priv->active);
       gtk_action_set_sensitive (window->priv->action_search_next, can_search);
@@ -1641,6 +1669,18 @@ terminal_window_action_copy (GtkAction      *action,
 
 
 
+#if VTE_CHECK_VERSION (0, 49, 2)
+static void
+terminal_window_action_copy_html (GtkAction      *action,
+                                  TerminalWindow *window)
+{
+  if (G_LIKELY (window->priv->active != NULL))
+    terminal_screen_copy_clipboard_html (window->priv->active);
+}
+#endif
+
+
+
 static void
 terminal_window_action_paste (GtkAction      *action,
                               TerminalWindow *window)

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list