[anjuta] sourceview: Use common settings for indentation



commit 70b56b507a51aa99d3bb779cdc630ebadab6d8f8
Author: SÃbastien Granjoux <seb sfo free fr>
Date:   Sun Apr 22 12:16:17 2012 +0200

    sourceview: Use common settings for indentation

 plugins/sourceview/anjuta-editor-sourceview.ui     |   90 +++++++++++++++-----
 ....gnome.anjuta.plugins.sourceview.gschema.xml.in |    5 -
 plugins/sourceview/sourceview-prefs.c              |   31 +++++---
 plugins/sourceview/sourceview-private.h            |    1 +
 4 files changed, 90 insertions(+), 37 deletions(-)
---
diff --git a/plugins/sourceview/anjuta-editor-sourceview.ui b/plugins/sourceview/anjuta-editor-sourceview.ui
index 4a86a9c..3081475 100644
--- a/plugins/sourceview/anjuta-editor-sourceview.ui
+++ b/plugins/sourceview/anjuta-editor-sourceview.ui
@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <requires lib="gtk+" version="2.16"/>
+  <!-- interface-requires gtk+ 3.0 -->
   <object class="GtkAdjustment" id="adjustment1">
     <property name="lower">1</property>
     <property name="upper">100</property>
     <property name="value">4</property>
     <property name="step_increment">1</property>
-    <property name="page_increment">10</property>
+    <property name="page_increment">8</property>
   </object>
   <object class="GtkAdjustment" id="adjustment2">
     <property name="upper">200</property>
@@ -14,6 +14,13 @@
     <property name="step_increment">1</property>
     <property name="page_increment">10</property>
   </object>
+  <object class="GtkAdjustment" id="adjustment3">
+    <property name="lower">1</property>
+    <property name="upper">100</property>
+    <property name="value">4</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">8</property>
+  </object>
   <object class="GtkWindow" id="preferences_dialog">
     <property name="can_focus">False</property>
     <property name="title">window1</property>
@@ -43,10 +50,24 @@
                       <object class="GtkGrid" id="grid1">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="n_rows">2</property>
-                        <property name="n_columns">2</property>
                         <child>
-                          <placeholder/>
+                          <object class="GtkCheckButton" id="preferences:.editor.use-tabs">
+                            <property name="label" translatable="yes">Use tabs for indentation</property>
+                            <property name="use_action_appearance">False</property>
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">False</property>
+                            <property name="use_action_appearance">False</property>
+                            <property name="use_underline">True</property>
+                            <property name="xalign">0</property>
+                            <property name="draw_indicator">True</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">0</property>
+                            <property name="top_attach">2</property>
+                            <property name="width">1</property>
+                            <property name="height">1</property>
+                          </packing>
                         </child>
                         <child>
                           <object class="GtkLabel" id="label122">
@@ -58,13 +79,16 @@
                           </object>
                           <packing>
                             <property name="left_attach">0</property>
-                            <property name="top_attach">0</property>
+                            <property name="top_attach">1</property>
                             <property name="width">1</property>
                             <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkSpinButton" id="preferences_spin:int:4:1:tabsize">
+                          <placeholder/>
+                        </child>
+                        <child>
+                          <object class="GtkSpinButton" id="preferences:.editor.tab-width">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="invisible_char">â</property>
@@ -75,25 +99,39 @@
                           </object>
                           <packing>
                             <property name="left_attach">1</property>
-                            <property name="top_attach">0</property>
+                            <property name="top_attach">1</property>
                             <property name="width">1</property>
                             <property name="height">1</property>
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkCheckButton" id="preferences_toggle:bool:1:0:use-tabs">
-                            <property name="label" translatable="yes">Use tabs for indentation</property>
+                          <object class="GtkSpinButton" id="preferences:.editor.indent-width">
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
-                            <property name="receives_default">False</property>
-                            <property name="use_action_appearance">False</property>
-                            <property name="use_underline">True</property>
+                            <property name="invisible_char">â</property>
+                            <property name="invisible_char_set">True</property>
+                            <property name="adjustment">adjustment3</property>
+                            <property name="climb_rate">1</property>
+                            <property name="numeric">True</property>
+                          </object>
+                          <packing>
+                            <property name="left_attach">1</property>
+                            <property name="top_attach">0</property>
+                            <property name="width">1</property>
+                            <property name="height">1</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="label1">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
                             <property name="xalign">0</property>
-                            <property name="draw_indicator">True</property>
+                            <property name="yalign">0</property>
+                            <property name="label" translatable="yes">Indentation size in spaces:</property>
                           </object>
                           <packing>
                             <property name="left_attach">0</property>
-                            <property name="top_attach">1</property>
+                            <property name="top_attach">0</property>
                             <property name="width">1</property>
                             <property name="height">1</property>
                           </packing>
@@ -153,6 +191,7 @@
                             <child>
                               <object class="GtkCheckButton" id="preferences_toggle:bool:1:0:syntax-highlight">
                                 <property name="label" translatable="yes">Highlight syntax</property>
+                                <property name="use_action_appearance">False</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="receives_default">False</property>
@@ -169,6 +208,7 @@
                             <child>
                               <object class="GtkCheckButton" id="preferences_toggle:bool:0:0:brackets-highlight">
                                 <property name="label" translatable="yes">Highlight matching brackets</property>
+                                <property name="use_action_appearance">False</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="receives_default">False</property>
@@ -185,6 +225,7 @@
                             <child>
                               <object class="GtkCheckButton" id="preferences_toggle:bool:1:0:backup">
                                 <property name="label" translatable="yes">Create backup files</property>
+                                <property name="use_action_appearance">False</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="receives_default">False</property>
@@ -201,6 +242,7 @@
                             <child>
                               <object class="GtkCheckButton" id="preferences_toggle:bool:0:0:autocomplete">
                                 <property name="label" translatable="yes">Enable autocompletion for document words</property>
+                                <property name="use_action_appearance">False</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="receives_default">False</property>
@@ -266,6 +308,7 @@
                             <child>
                               <object class="GtkCheckButton" id="preferences_toggle:bool:0:0:currentline-highlight">
                                 <property name="label" translatable="yes">Highlight current line</property>
+                                <property name="use_action_appearance">False</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="receives_default">False</property>
@@ -282,6 +325,7 @@
                             <child>
                               <object class="GtkCheckButton" id="preferences_toggle:bool:1:0:margin-linenumber-visible">
                                 <property name="label" translatable="yes">Show line numbers</property>
+                                <property name="use_action_appearance">False</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="receives_default">False</property>
@@ -298,6 +342,7 @@
                             <child>
                               <object class="GtkCheckButton" id="preferences_toggle:bool:1:0:margin-marker-visible">
                                 <property name="label" translatable="yes">Show marks</property>
+                                <property name="use_action_appearance">False</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="receives_default">False</property>
@@ -314,6 +359,7 @@
                             <child>
                               <object class="GtkCheckButton" id="preferences_toggle:bool:1:0:rightmargin-visible">
                                 <property name="label" translatable="yes">Show right margin</property>
+                                <property name="use_action_appearance">False</property>
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
                                 <property name="receives_default">False</property>
@@ -336,6 +382,12 @@
                                 <property name="column_spacing">5</property>
                                 <property name="row_spacing">5</property>
                                 <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                                <child>
                                   <object class="GtkLabel" id="label19">
                                     <property name="visible">True</property>
                                     <property name="can_focus">False</property>
@@ -348,12 +400,6 @@
                                   </packing>
                                 </child>
                                 <child>
-                                  <placeholder/>
-                                </child>
-                                <child>
-                                  <placeholder/>
-                                </child>
-                                <child>
                                   <object class="GtkSpinButton" id="preferences_spin:int:80:0:rightmargin-position">
                                     <property name="visible">True</property>
                                     <property name="can_focus">True</property>
@@ -454,6 +500,7 @@
                         <property name="row_spacing">5</property>
                         <child>
                           <object class="GtkFontButton" id="preferences_font:font:Monospace 12:0:font">
+                            <property name="use_action_appearance">False</property>
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">False</property>
@@ -469,6 +516,7 @@
                         <child>
                           <object class="GtkCheckButton" id="preferences_toggle:bool:1:0:font-use-theme">
                             <property name="label" translatable="yes">Use theme font</property>
+                            <property name="use_action_appearance">False</property>
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">False</property>
diff --git a/plugins/sourceview/org.gnome.anjuta.plugins.sourceview.gschema.xml.in b/plugins/sourceview/org.gnome.anjuta.plugins.sourceview.gschema.xml.in
index f8839d0..82ac0a3 100644
--- a/plugins/sourceview/org.gnome.anjuta.plugins.sourceview.gschema.xml.in
+++ b/plugins/sourceview/org.gnome.anjuta.plugins.sourceview.gschema.xml.in
@@ -17,11 +17,6 @@
 		</key>
 		<key name="print-linenumbers" type="b">
 			<default>false</default>
-		</key>		<key name="tabsize" type="i">
-			<default>4</default>
-		</key>
-		<key name="use-tabs" type="b">
-			<default>true</default>
 		</key>
 		<key name="syntax-highlight" type="b">
 			<default>true</default>
diff --git a/plugins/sourceview/sourceview-prefs.c b/plugins/sourceview/sourceview-prefs.c
index def8e34..77b0d25 100644
--- a/plugins/sourceview/sourceview-prefs.c
+++ b/plugins/sourceview/sourceview-prefs.c
@@ -21,20 +21,19 @@
 #include <gtksourceview/completion-providers/words/gtksourcecompletionwords.h>
 
 #include <libanjuta/anjuta-debug.h>
+#include <libanjuta/interfaces/ianjuta-editor.h>
 
 #define REGISTER_NOTIFY(settings, key, func) \
 	g_signal_connect (settings, "changed::" key, G_CALLBACK(func), sv);
 
+#define ANJUTA_PREF_SCHEMA_PREFIX "org.gnome.anjuta."
 #define PREF_SCHEMA "org.gnome.anjuta.plugins.sourceview"
 #define MSGMAN_PREF_SCHEMA "org.gnome.anjuta.plugins.message-manager"
 
-
 /* Editor preferences */
 #define HIGHLIGHT_SYNTAX           "syntax-highlight"
 #define HIGHLIGHT_CURRENT_LINE	   "currentline-highlight"
-#define USE_TABS                   "use-tabs"
 #define HIGHLIGHT_BRACKETS         "brackets-highlight"
-#define TAB_SIZE                   "tabsize"
 #define INDENT_SIZE                "indent-size"
 #define AUTOCOMPLETION             "autocomplete"
 
@@ -45,7 +44,6 @@
 #define MSGMAN_COLOR_WARNING		  "color-warning"
 #define MSGMAN_COLOR_IMPORTANT		  "color-important"
 
-
 #define FONT_THEME "font-use-theme"
 #define FONT "font"
 #define DESKTOP_FIXED_FONT "/desktop/gnome/interface/monospace_font_name"
@@ -264,7 +262,8 @@ sourceview_prefs_init(Sourceview* sv)
 	 */
 	sv->priv->settings = g_settings_new (PREF_SCHEMA);
 	sv->priv->msgman_settings = g_settings_new (MSGMAN_PREF_SCHEMA);
-    
+	sv->priv->editor_settings = g_settings_new (ANJUTA_PREF_SCHEMA_PREFIX IANJUTA_EDITOR_PREF_SCHEMA);
+
 	/* Bind simple options to GSettings */
 	g_settings_bind (sv->priv->settings, HIGHLIGHT_SYNTAX,
 			 sv->priv->document, "highlight-syntax",
@@ -272,9 +271,12 @@ sourceview_prefs_init(Sourceview* sv)
 	g_settings_bind (sv->priv->settings, HIGHLIGHT_CURRENT_LINE,
 			 sv->priv->view, "highlight-current-line",
 			 G_SETTINGS_BIND_GET);
-	g_settings_bind (sv->priv->settings, TAB_SIZE,
+	g_settings_bind (sv->priv->editor_settings, IANJUTA_EDITOR_TAB_WIDTH_KEY,
 			 sv->priv->view, "tab-width",
 			 G_SETTINGS_BIND_GET);
+	g_settings_bind (sv->priv->editor_settings, IANJUTA_EDITOR_INDENT_WIDTH_KEY,
+			 sv->priv->view, "indent-width",
+			 G_SETTINGS_BIND_GET);
 	g_settings_bind (sv->priv->settings, HIGHLIGHT_BRACKETS,
 			 sv->priv->document, "highlight-matching-brackets",
 			 G_SETTINGS_BIND_GET);
@@ -294,11 +296,14 @@ sourceview_prefs_init(Sourceview* sv)
 	g_settings_bind (sv->priv->settings, VIEW_LINENUMBERS,
 			 sv->priv->view, "show-line-numbers",
 			 G_SETTINGS_BIND_GET);
-	
+
 	/* Init non-simple options */
-	gtk_source_view_set_indent_width(GTK_SOURCE_VIEW(sv->priv->view), -1); /* Same as tab width */
+	gtk_source_view_set_indent_width(GTK_SOURCE_VIEW(sv->priv->view),
+	                                 g_settings_get_int (sv->priv->editor_settings, IANJUTA_EDITOR_INDENT_WIDTH_KEY));
+	gtk_source_view_set_tab_width(GTK_SOURCE_VIEW(sv->priv->view),
+	                                 g_settings_get_int (sv->priv->editor_settings, IANJUTA_EDITOR_TAB_WIDTH_KEY));
 	gtk_source_view_set_insert_spaces_instead_of_tabs(GTK_SOURCE_VIEW(sv->priv->view),
-	                                                  !g_settings_get_boolean (sv->priv->settings, USE_TABS));
+	                                                  !g_settings_get_boolean (sv->priv->editor_settings, IANJUTA_EDITOR_USE_TABS_KEY));
 
 	gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (sv->priv->view),
 	                             g_settings_get_boolean (sv->priv->settings, VIEW_EOL) ? GTK_WRAP_WORD : GTK_WRAP_NONE);
@@ -317,9 +322,9 @@ sourceview_prefs_init(Sourceview* sv)
 	on_notify_autocompletion(sv->priv->settings, AUTOCOMPLETION, sv);
 
 	/* Register notifications */
-	REGISTER_NOTIFY (sv->priv->settings, USE_TABS, on_notify_use_tab_for_indentation);
-	REGISTER_NOTIFY (sv->priv->settings, AUTOCOMPLETION, on_notify_autocompletion);
+	REGISTER_NOTIFY (sv->priv->editor_settings, IANJUTA_EDITOR_USE_TABS_KEY, on_notify_use_tab_for_indentation);
 
+	REGISTER_NOTIFY (sv->priv->settings, AUTOCOMPLETION, on_notify_autocompletion);
 	REGISTER_NOTIFY (sv->priv->settings, VIEW_WHITE_SPACES, on_notify_view_spaces);
 	REGISTER_NOTIFY (sv->priv->settings, VIEW_EOL, on_notify_view_eol);
 	REGISTER_NOTIFY (sv->priv->settings, VIEW_LINE_WRAP, on_notify_line_wrap);
@@ -344,4 +349,8 @@ void sourceview_prefs_destroy(Sourceview* sv)
 	{
 		g_clear_object (&sv->priv->msgman_settings);
 	}
+	if (sv->priv->editor_settings)
+	{
+		g_clear_object (&sv->priv->editor_settings);
+	}
 }
diff --git a/plugins/sourceview/sourceview-private.h b/plugins/sourceview/sourceview-private.h
index 5326388..1f32e58 100644
--- a/plugins/sourceview/sourceview-private.h
+++ b/plugins/sourceview/sourceview-private.h
@@ -45,6 +45,7 @@ struct SourceviewPrivate {
 	/* Preferences */
 	GSettings* settings;
 	GSettings* msgman_settings;
+	GSettings* editor_settings;
 	GList* notify_ids;
 
 	/* Popup menu */



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