[Xfce4-commits] [apps/mousepad] 18/45: Move word-wrap from MousepadDocument to MousepadView

noreply at xfce.org noreply at xfce.org
Fri Jul 11 13:03:23 CEST 2014


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

mbrush pushed a commit to branch master
in repository apps/mousepad.

commit b48d3d76a52f0883e30140a1a526432daa69aedf
Author: Matthew Brush <mbrush at codebrainz.ca>
Date:   Sun Jul 6 21:57:05 2014 -0700

    Move word-wrap from MousepadDocument to MousepadView
    
    And bind from GSettings. Remove now uneeded code from this change and
    also some for previous color-scheme property addition.
---
 mousepad/mousepad-document.c        |   47 -----------------------------------
 mousepad/mousepad-document.h        |    3 ---
 mousepad/mousepad-encoding-dialog.c |    2 +-
 mousepad/mousepad-view.c            |   44 ++++++++++++++++++++++++++++++++
 mousepad/mousepad-view.h            |    5 ++++
 mousepad/mousepad-window.c          |    5 +---
 6 files changed, 51 insertions(+), 55 deletions(-)

diff --git a/mousepad/mousepad-document.c b/mousepad/mousepad-document.c
index e520b7b..d363ce7 100644
--- a/mousepad/mousepad-document.c
+++ b/mousepad/mousepad-document.c
@@ -96,9 +96,6 @@ struct _MousepadDocumentPrivate
   /* utf-8 valid document names */
   gchar               *utf8_filename;
   gchar               *utf8_basename;
-
-  /* settings */
-  guint                word_wrap : 1;
 };
 
 
@@ -176,9 +173,6 @@ static void
 mousepad_document_init (MousepadDocument *document)
 {
   GtkTargetList        *target_list;
-  gboolean              word_wrap;
-  gchar                *color_scheme;
-  GtkSourceStyleScheme *scheme = NULL;
 
   /* private structure */
   document->priv = MOUSEPAD_DOCUMENT_GET_PRIVATE (document);
@@ -215,21 +209,6 @@ mousepad_document_init (MousepadDocument *document)
   target_list = gtk_drag_dest_get_target_list (GTK_WIDGET (document->textview));
   gtk_target_list_add_table (target_list, drop_targets, G_N_ELEMENTS (drop_targets));
 
-  /* read all the default settings */
-  word_wrap = mousepad_settings_get_boolean ("view-word-wrap");
-  color_scheme = mousepad_settings_get_string ("view-color-scheme");
-
-  /* set all the settings */
-  mousepad_document_set_word_wrap (document, word_wrap);
-
-  if (g_strcmp0 (color_scheme, "none") != 0)
-    scheme =  gtk_source_style_scheme_manager_get_scheme (gtk_source_style_scheme_manager_get_default (), color_scheme);
-  gtk_source_buffer_set_highlight_syntax (GTK_SOURCE_BUFFER (document->buffer), (scheme != NULL));
-  gtk_source_buffer_set_style_scheme (GTK_SOURCE_BUFFER (document->buffer), scheme);
-
-  /* cleanup */
-  g_free (color_scheme);
-
   /* attach signals to the text view and buffer */
   g_signal_connect (G_OBJECT (document->buffer), "notify::cursor-position", G_CALLBACK (mousepad_document_notify_cursor_position), document);
   g_signal_connect (G_OBJECT (document->buffer), "notify::has-selection", G_CALLBACK (mousepad_document_notify_has_selection), document);
@@ -463,22 +442,6 @@ mousepad_document_set_overwrite (MousepadDocument *document,
 
 
 void
-mousepad_document_set_word_wrap (MousepadDocument *document,
-                                 gboolean          word_wrap)
-{
-  mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (document));
-
-  /* store the setting */
-  document->priv->word_wrap = word_wrap;
-
-  /* set the wrapping mode */
-  gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (document->textview),
-                               word_wrap ? GTK_WRAP_WORD : GTK_WRAP_NONE);
-}
-
-
-
-void
 mousepad_document_focus_textview (MousepadDocument *document)
 {
   mousepad_return_if_fail (MOUSEPAD_IS_DOCUMENT (document));
@@ -598,13 +561,3 @@ mousepad_document_get_filename (MousepadDocument *document)
 
   return document->priv->utf8_filename;
 }
-
-
-
-gboolean
-mousepad_document_get_word_wrap (MousepadDocument *document)
-{
-  mousepad_return_val_if_fail (MOUSEPAD_IS_DOCUMENT (document), FALSE);
-
-  return document->priv->word_wrap;
-}
diff --git a/mousepad/mousepad-document.h b/mousepad/mousepad-document.h
index cbe3f4f..41a720e 100644
--- a/mousepad/mousepad-document.h
+++ b/mousepad/mousepad-document.h
@@ -63,9 +63,6 @@ MousepadDocument *mousepad_document_new            (void);
 void              mousepad_document_set_overwrite  (MousepadDocument *document,
                                                     gboolean          overwrite);
 
-void              mousepad_document_set_word_wrap  (MousepadDocument *document,
-                                                    gboolean          word_wrap);
-
 void              mousepad_document_focus_textview (MousepadDocument *document);
 
 void              mousepad_document_send_signals   (MousepadDocument *document);
diff --git a/mousepad/mousepad-encoding-dialog.c b/mousepad/mousepad-encoding-dialog.c
index fae5e46..9a0fc3e 100644
--- a/mousepad/mousepad-encoding-dialog.c
+++ b/mousepad/mousepad-encoding-dialog.c
@@ -210,7 +210,7 @@ mousepad_encoding_dialog_init (MousepadEncodingDialog *dialog)
   gtk_text_view_set_editable (GTK_TEXT_VIEW (dialog->document->textview), FALSE);
   gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (dialog->document->textview), FALSE);
   gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (dialog->document->textview), FALSE);
-  mousepad_document_set_word_wrap (dialog->document, FALSE);
+  mousepad_view_set_word_wrap (dialog->document->textview, FALSE);
   gtk_widget_show (GTK_WIDGET (dialog->document));
 }
 
diff --git a/mousepad/mousepad-view.c b/mousepad/mousepad-view.c
index 33b041d..f5508f1 100644
--- a/mousepad/mousepad-view.c
+++ b/mousepad/mousepad-view.c
@@ -139,6 +139,7 @@ enum
   PROP_SHOW_WHITESPACE,
   PROP_SHOW_LINE_ENDINGS,
   PROP_COLOR_SCHEME,
+  PROP_WORD_WRAP,
   NUM_PROPERTIES
 };
 
@@ -201,6 +202,15 @@ mousepad_view_class_init (MousepadViewClass *klass)
                          "The id of the syntax highlighting color scheme to use",
                          NULL,
                          G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
+
+  g_object_class_install_property (
+    gobject_class,
+    PROP_WORD_WRAP,
+    g_param_spec_boolean ("word-wrap",
+                          "WordWrap",
+                          "Whether to virtually wrap long lines in the view",
+                          FALSE,
+                          G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
 }
 
 
@@ -238,6 +248,7 @@ mousepad_view_init (MousepadView *view)
   mousepad_settings_bind ("view-smart-home-end", view, "smart-home-end", G_SETTINGS_BIND_DEFAULT);
   mousepad_settings_bind ("view-tab-width", view, "tab-width", G_SETTINGS_BIND_DEFAULT);
   mousepad_settings_bind ("view-color-scheme", view, "color-scheme", G_SETTINGS_BIND_DEFAULT);
+  mousepad_settings_bind ("view-word-wrap", view, "word-wrap", G_SETTINGS_BIND_DEFAULT);
 }
 
 
@@ -282,6 +293,9 @@ mousepad_view_set_property (GObject      *object,
     case PROP_COLOR_SCHEME:
       mousepad_view_set_color_scheme (view, g_value_get_string (value));
       break;
+    case PROP_WORD_WRAP:
+      mousepad_view_set_word_wrap (view, g_value_get_boolean (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -312,6 +326,9 @@ mousepad_view_get_property (GObject    *object,
     case PROP_COLOR_SCHEME:
       g_value_set_string (value, mousepad_view_get_color_scheme (view));
       break;
+    case PROP_WORD_WRAP:
+      g_value_set_boolean (value, mousepad_view_get_word_wrap (view));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -2620,3 +2637,30 @@ mousepad_view_get_color_scheme (MousepadView *view)
 
   return "none";
 }
+
+
+
+void
+mousepad_view_set_word_wrap (MousepadView *view,
+                             gboolean      enabled)
+{
+  g_return_if_fail (MOUSEPAD_IS_VIEW (view));
+
+  gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view),
+                               enabled ? GTK_WRAP_WORD : GTK_WRAP_NONE);
+  g_object_notify (G_OBJECT (view), "word-wrap");
+}
+
+
+
+gboolean
+mousepad_view_get_word_wrap (MousepadView *view)
+{
+  GtkWrapMode mode;
+
+  g_return_val_if_fail (MOUSEPAD_IS_VIEW (view), FALSE);
+
+  mode = gtk_text_view_get_wrap_mode (GTK_TEXT_VIEW (view));
+
+  return (mode == GTK_WRAP_WORD);
+}
diff --git a/mousepad/mousepad-view.h b/mousepad/mousepad-view.h
index f2bf88f..aaf3808 100644
--- a/mousepad/mousepad-view.h
+++ b/mousepad/mousepad-view.h
@@ -115,6 +115,11 @@ void            mousepad_view_set_color_scheme          (MousepadView      *view
 
 const gchar    *mousepad_view_get_color_scheme          (MousepadView      *view);
 
+void            mousepad_view_set_word_wrap             (MousepadView      *view,
+                                                         gboolean           enabled);
+
+gboolean        mousepad_view_get_word_wrap             (MousepadView      *view);
+
 G_END_DECLS
 
 #endif /* !__MOUSEPAD_VIEW_H__ */
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index 1d255fe..3662261 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -2268,7 +2268,7 @@ mousepad_window_update_actions (MousepadWindow *window)
       gtk_action_set_sensitive (action, sensitive);
 
       /* toggle the document settings */
-      active = mousepad_document_get_word_wrap (document);
+      active = mousepad_settings_get_boolean ("view-word-wrap");
       action = gtk_action_group_get_action (window->action_group, "word-wrap");
       gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), active);
 
@@ -4855,9 +4855,6 @@ mousepad_window_action_word_wrap (GtkToggleAction *action,
 
       /* store this as the last used wrap mode */
       mousepad_settings_set_boolean ("view-word-wrap", active);
-
-      /* set the wrapping mode of the current document */
-      mousepad_document_set_word_wrap (window->active, active);
     }
 }
 

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


More information about the Xfce4-commits mailing list