[gnome-builder/wip/libide] libide: make indent-width -1 to 32. -1 defaults to tab width



commit 07f875af9943ad4a2faf7a3e08415adf8b786284
Author: Christian Hergert <christian hergert me>
Date:   Sat Feb 14 19:49:02 2015 -0800

    libide: make indent-width -1 to 32. -1 defaults to tab width

 libide/editorconfig/editorconfig.c |   22 +++++++++++++++++++---
 libide/ide-file-settings.c         |   24 ++++++++++++------------
 libide/ide-file-settings.h         |    4 ++--
 tools/ide-list-file-settings.c     |    2 +-
 4 files changed, 34 insertions(+), 18 deletions(-)
---
diff --git a/libide/editorconfig/editorconfig.c b/libide/editorconfig/editorconfig.c
index d787e92..4a46d83 100644
--- a/libide/editorconfig/editorconfig.c
+++ b/libide/editorconfig/editorconfig.c
@@ -80,7 +80,7 @@ parse_key (GKeyFile     *key_file,
       ret = TRUE;
       goto cleanup;
     }
-  else if (g_str_equal (key, "indent_size") || g_str_equal (key, "tab_width"))
+  else if (g_str_equal (key, "tab_width"))
     {
       GError *local_error = NULL;
       gint v;
@@ -94,7 +94,23 @@ parse_key (GKeyFile     *key_file,
         }
 
       g_value_init (value, G_TYPE_UINT);
-      g_value_set_uint (value, MAX (0, v));
+      g_value_set_uint (value, MAX (1, v));
+    }
+  else if (g_str_equal (key, "indent_size"))
+    {
+      GError *local_error = NULL;
+      gint v;
+
+      v = g_key_file_get_integer (key_file, group, key, &local_error);
+
+      if (local_error)
+        {
+          g_propagate_error (error, local_error);
+          goto cleanup;
+        }
+
+      g_value_init (value, G_TYPE_INT);
+      g_value_set_int (value, MAX (-1, v));
     }
   else if (g_str_equal (key, "trim_trailing_whitespace") || g_str_equal (key, "insert_final_newline"))
     {
@@ -301,7 +317,7 @@ editorconfig_read (GFile         *file,
 
   queue = g_queue_new ();
   iter = g_object_ref (file);
- 
+
   do
     {
       GFile *parent;
diff --git a/libide/ide-file-settings.c b/libide/ide-file-settings.c
index e31b36c..7abf736 100644
--- a/libide/ide-file-settings.c
+++ b/libide/ide-file-settings.c
@@ -26,8 +26,8 @@ typedef struct
 {
   gchar                *encoding;
   IdeFile              *file;
+  gint                  indent_width : 7;
   IdeIndentStyle        indent_style : 2;
-  guint                 indent_width : 6;
   guint                 insert_trailing_newline : 1;
   guint                 tab_width : 6;
   guint                 trim_trailing_whitespace : 1;
@@ -146,24 +146,24 @@ ide_file_settings_set_indent_style (IdeFileSettings *self,
     }
 }
 
-guint
+gint
 ide_file_settings_get_indent_width (IdeFileSettings *self)
 {
   IdeFileSettingsPrivate *priv = ide_file_settings_get_instance_private (self);
 
-  g_return_val_if_fail (IDE_IS_FILE_SETTINGS (self), 0);
+  g_return_val_if_fail (IDE_IS_FILE_SETTINGS (self), -1);
 
   return priv->indent_width;
 }
 
 void
 ide_file_settings_set_indent_width (IdeFileSettings *self,
-                                    guint            indent_width)
+                                    gint             indent_width)
 {
   IdeFileSettingsPrivate *priv = ide_file_settings_get_instance_private (self);
 
   g_return_if_fail (IDE_IS_FILE_SETTINGS (self));
-  g_return_if_fail (indent_width > 0);
+  g_return_if_fail (indent_width >= -1);
   g_return_if_fail (indent_width < 32);
 
   if (priv->indent_width != indent_width)
@@ -399,7 +399,7 @@ ide_file_settings_set_property (GObject      *object,
       break;
 
     case PROP_INDENT_WIDTH:
-      ide_file_settings_set_indent_width (self, g_value_get_uint (value));
+      ide_file_settings_set_indent_width (self, g_value_get_int (value));
       break;
 
     case PROP_INSERT_TRAILING_NEWLINE:
@@ -467,11 +467,11 @@ ide_file_settings_class_init (IdeFileSettingsClass *klass)
                                    gParamSpecs [PROP_INDENT_STYLE]);
 
   gParamSpecs [PROP_INDENT_WIDTH] =
-    g_param_spec_uint ("indent-width",
-                       _("Indent Width"),
-                       _("The width to use when indenting."),
-                       1, 32, 8,
-                       (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+    g_param_spec_int ("indent-width",
+                      _("Indent Width"),
+                      _("The width to use when indenting."),
+                      -1, 32, -1,
+                      (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   g_object_class_install_property (object_class, PROP_INDENT_WIDTH,
                                    gParamSpecs [PROP_INDENT_WIDTH]);
 
@@ -531,7 +531,7 @@ ide_file_settings_init (IdeFileSettings *self)
   IdeFileSettingsPrivate *priv = ide_file_settings_get_instance_private (self);
 
   priv->indent_style = IDE_INDENT_STYLE_SPACES;
-  priv->indent_width = 8;
+  priv->indent_width = -1;
   priv->insert_trailing_newline = TRUE;
   priv->newline_type = GTK_SOURCE_NEWLINE_TYPE_LF;
   priv->right_margin_position = 80;
diff --git a/libide/ide-file-settings.h b/libide/ide-file-settings.h
index 16a28a1..59a7c1d 100644
--- a/libide/ide-file-settings.h
+++ b/libide/ide-file-settings.h
@@ -40,7 +40,7 @@ struct _IdeFileSettingsClass
 const gchar          *ide_file_settings_get_encoding                 (IdeFileSettings      *self);
 IdeFile              *ide_file_settings_get_file                     (IdeFileSettings      *self);
 IdeIndentStyle        ide_file_settings_get_indent_style             (IdeFileSettings      *self);
-guint                 ide_file_settings_get_indent_width             (IdeFileSettings      *self);
+gint                  ide_file_settings_get_indent_width             (IdeFileSettings      *self);
 gboolean              ide_file_settings_get_insert_trailing_newline  (IdeFileSettings      *self);
 GtkSourceNewlineType  ide_file_settings_get_newline_type             (IdeFileSettings      *self);
 guint                 ide_file_settings_get_right_margin_position    (IdeFileSettings      *self);
@@ -51,7 +51,7 @@ void                  ide_file_settings_set_encoding                 (IdeFileSet
 void                  ide_file_settings_set_indent_style             (IdeFileSettings      *self,
                                                                       IdeIndentStyle        indent_style);
 void                  ide_file_settings_set_indent_width             (IdeFileSettings      *self,
-                                                                      guint                 indent_width);
+                                                                      gint                  indent_width);
 void                  ide_file_settings_set_insert_trailing_newline  (IdeFileSettings      *self,
                                                                       gboolean              
insert_trailing_newline);
 void                  ide_file_settings_set_newline_type             (IdeFileSettings      *self,
diff --git a/tools/ide-list-file-settings.c b/tools/ide-list-file-settings.c
index 9dc4294..c7cc63c 100644
--- a/tools/ide-list-file-settings.c
+++ b/tools/ide-list-file-settings.c
@@ -89,7 +89,7 @@ load_settings_cb (GObject      *object,
 
   g_print ("# %s\n", ide_file_get_path (file));
   g_print ("encoding = %s\n", ide_file_settings_get_encoding (settings) ?: "default");
-  g_print ("indent_width = %u\n", ide_file_settings_get_indent_width (settings));
+  g_print ("indent_width = %d\n", ide_file_settings_get_indent_width (settings));
   g_print ("tab_width = %u\n", ide_file_settings_get_tab_width (settings));
   g_print ("insert_trailing_newline = %s\n", ide_file_settings_get_insert_trailing_newline (settings) ? 
"true" : "false");
   g_print ("trim_trailing_whitespace = %s\n", ide_file_settings_get_trim_trailing_whitespace (settings) ? 
"true" : "false");


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