# Subject: Per document indent sizes.
# Author: Jiří Techet <techet@gmail.com>
# Last-Update: 2010-09-10

=== modified file 'geany.glade'
Index: geany-bzr/geany.glade
===================================================================
--- geany-bzr.orig/geany.glade
+++ geany-bzr/geany.glade
@@ -1424,6 +1424,106 @@
 		      </child>

 		      <child>
+			<widget class="GtkMenuItem" id="indent_width1">
+			  <property name="visible">True</property>
+			  <property name="label" translatable="yes">Indent Widt_h</property>
+			  <property name="use_underline">True</property>
+
+			  <child>
+			    <widget class="GtkMenu" id="indent_width1_menu">
+
+			      <child>
+				<widget class="GtkRadioMenuItem" id="indent_width_1">
+				  <property name="visible">True</property>
+				  <property name="label" translatable="yes">_1</property>
+				  <property name="use_underline">True</property>
+				  <property name="active">True</property>
+				  <signal name="activate" handler="on_indent_width_1_activate" last_modification_time="Mon, 09 Aug 2010 21:16:01 GMT"/>
+				</widget>
+			      </child>
+
+			      <child>
+				<widget class="GtkRadioMenuItem" id="indent_width_2">
+				  <property name="visible">True</property>
+				  <property name="label" translatable="yes">_2</property>
+				  <property name="use_underline">True</property>
+				  <property name="active">True</property>
+				  <property name="group">indent_width_1</property>
+				  <signal name="activate" handler="on_indent_width_2_activate" last_modification_time="Mon, 09 Aug 2010 21:16:01 GMT"/>
+				</widget>
+			      </child>
+
+			      <child>
+				<widget class="GtkRadioMenuItem" id="indent_width_3">
+				  <property name="visible">True</property>
+				  <property name="label" translatable="yes">_3</property>
+				  <property name="use_underline">True</property>
+				  <property name="active">True</property>
+				  <property name="group">indent_width_1</property>
+				  <signal name="activate" handler="on_indent_width_3_activate" last_modification_time="Mon, 09 Aug 2010 21:16:01 GMT"/>
+				</widget>
+			      </child>
+
+			      <child>
+				<widget class="GtkRadioMenuItem" id="indent_width_4">
+				  <property name="visible">True</property>
+				  <property name="label" translatable="yes">_4</property>
+				  <property name="use_underline">True</property>
+				  <property name="active">True</property>
+				  <property name="group">indent_width_1</property>
+				  <signal name="activate" handler="on_indent_width_4_activate" last_modification_time="Mon, 09 Aug 2010 21:16:01 GMT"/>
+				</widget>
+			      </child>
+
+			      <child>
+				<widget class="GtkRadioMenuItem" id="indent_width_5">
+				  <property name="visible">True</property>
+				  <property name="label" translatable="yes">_5</property>
+				  <property name="use_underline">True</property>
+				  <property name="active">True</property>
+				  <property name="group">indent_width_1</property>
+				  <signal name="activate" handler="on_indent_width_5_activate" last_modification_time="Mon, 09 Aug 2010 21:16:01 GMT"/>
+				</widget>
+			      </child>
+
+			      <child>
+				<widget class="GtkRadioMenuItem" id="indent_width_6">
+				  <property name="visible">True</property>
+				  <property name="label" translatable="yes">_6</property>
+				  <property name="use_underline">True</property>
+				  <property name="active">True</property>
+				  <property name="group">indent_width_1</property>
+				  <signal name="activate" handler="on_indent_width_6_activate" last_modification_time="Mon, 09 Aug 2010 21:16:01 GMT"/>
+				</widget>
+			      </child>
+
+			      <child>
+				<widget class="GtkRadioMenuItem" id="indent_width_7">
+				  <property name="visible">True</property>
+				  <property name="label" translatable="yes">_7</property>
+				  <property name="use_underline">True</property>
+				  <property name="active">True</property>
+				  <property name="group">indent_width_1</property>
+				  <signal name="activate" handler="on_indent_width_7_activate" last_modification_time="Mon, 09 Aug 2010 21:16:01 GMT"/>
+				</widget>
+			      </child>
+
+			      <child>
+				<widget class="GtkRadioMenuItem" id="indent_width_8">
+				  <property name="visible">True</property>
+				  <property name="label" translatable="yes">_8</property>
+				  <property name="use_underline">True</property>
+				  <property name="active">True</property>
+				  <property name="group">indent_width_1</property>
+				  <signal name="activate" handler="on_indent_width_8_activate" last_modification_time="Mon, 09 Aug 2010 21:16:01 GMT"/>
+				</widget>
+			      </child>
+			    </widget>
+			  </child>
+			</widget>
+		      </child>
+
+		      <child>
 			<widget class="GtkSeparatorMenuItem" id="separator45">
 			  <property name="visible">True</property>
 			</widget>
Index: geany-bzr/src/callbacks.c
===================================================================
--- geany-bzr.orig/src/callbacks.c
+++ geany-bzr/src/callbacks.c
@@ -2025,7 +2025,7 @@
 	doc = document_get_current();
 	g_return_if_fail(doc != NULL);

-	editor_set_indent_type(doc->editor, type);
+	editor_set_indent(doc->editor, type, doc->editor->indent_width);
 	ui_update_statusbar(doc, -1);
 }

@@ -2347,3 +2347,81 @@
 }


+
+static void set_indent_width(guint width)
+{
+	GeanyDocument *doc;
+
+	if (ignore_callback)
+		return;
+
+	doc = document_get_current();
+	g_return_if_fail(doc != NULL);
+
+	editor_set_indent(doc->editor, doc->editor->indent_type, width);
+}
+
+
+void
+on_indent_width_1_activate             (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+	set_indent_width(1);
+}
+
+
+void
+on_indent_width_2_activate             (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+	set_indent_width(2);
+}
+
+
+void
+on_indent_width_3_activate             (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+	set_indent_width(3);
+}
+
+
+void
+on_indent_width_4_activate             (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+	set_indent_width(4);
+}
+
+
+void
+on_indent_width_5_activate             (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+	set_indent_width(5);
+}
+
+
+void
+on_indent_width_6_activate             (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+	set_indent_width(6);
+}
+
+
+void
+on_indent_width_7_activate             (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+	set_indent_width(7);
+}
+
+
+void
+on_indent_width_8_activate             (GtkMenuItem     *menuitem,
+                                        gpointer         user_data)
+{
+	set_indent_width(8);
+}
+
Index: geany-bzr/src/callbacks.h
===================================================================
--- geany-bzr.orig/src/callbacks.h
+++ geany-bzr/src/callbacks.h
@@ -644,3 +644,35 @@
 void
 on_goto_tag_declaration1               (GtkMenuItem     *menuitem,
                                         gpointer         user_data);
+
+void
+on_indent_width_1_activate             (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
+
+void
+on_indent_width_2_activate             (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
+
+void
+on_indent_width_3_activate             (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
+
+void
+on_indent_width_4_activate             (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
+
+void
+on_indent_width_5_activate             (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
+
+void
+on_indent_width_6_activate             (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
+
+void
+on_indent_width_7_activate             (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
+
+void
+on_indent_width_8_activate             (GtkMenuItem     *menuitem,
+                                        gpointer         user_data);
Index: geany-bzr/src/document.c
===================================================================
--- geany-bzr.orig/src/document.c
+++ geany-bzr/src/document.c
@@ -1143,11 +1143,11 @@
 	{
 		case GEANY_FILETYPES_MAKE:
 			/* force using tabs for indentation for Makefiles */
-			editor_set_indent_type(doc->editor, GEANY_INDENT_TYPE_TABS);
+			editor_set_indent(doc->editor, GEANY_INDENT_TYPE_TABS, iprefs->width);
 			return;
 		case GEANY_FILETYPES_F77:
 			/* force using spaces for indentation for Fortran 77 */
-			editor_set_indent_type(doc->editor, GEANY_INDENT_TYPE_SPACES);
+			editor_set_indent(doc->editor, GEANY_INDENT_TYPE_SPACES, iprefs->width);
 			return;
 	}
 	if (iprefs->detect_type)
@@ -1176,7 +1176,7 @@
 				DOC_FILENAME(doc));
 		}
 	}
-	editor_set_indent_type(doc->editor, type);
+	editor_set_indent(doc->editor, type, iprefs->width);
 }


@@ -1325,7 +1325,7 @@

 		/* set indentation settings after setting the filetype */
 		if (reload)
-			editor_set_indent_type(doc->editor, doc->editor->indent_type); /* resetup sci */
+			editor_set_indent(doc->editor, doc->editor->indent_type, doc->editor->indent_width); /* resetup sci */
 		else
 			document_apply_indent_settings(doc);

Index: geany-bzr/src/editor.c
===================================================================
--- geany-bzr.orig/src/editor.c
+++ geany-bzr/src/editor.c
@@ -1064,6 +1064,7 @@
 		return &iprefs;

 	iprefs.type = editor->indent_type;
+	iprefs.width = editor->indent_width;

 	/* if per-document auto-indent is enabled, but we don't have a global mode set,
 	 * just use basic auto-indenting */
@@ -4568,11 +4569,18 @@
  */
 void editor_set_indent_type(GeanyEditor *editor, GeanyIndentType type)
 {
+	editor_set_indent(editor, type, editor->indent_width);
+}
+
+
+void editor_set_indent(GeanyEditor *editor, GeanyIndentType type, gint width)
+{
 	const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor);
 	ScintillaObject *sci = editor->sci;
 	gboolean use_tabs = type != GEANY_INDENT_TYPE_SPACES;

 	editor->indent_type = type;
+	editor->indent_width = width;
 	sci_set_use_tabs(sci, use_tabs);

 	if (type == GEANY_INDENT_TYPE_BOTH)
@@ -4588,9 +4596,9 @@
 		}
 	}
 	else
-		sci_set_tab_width(sci, iprefs->width);
+		sci_set_tab_width(sci, width);

-	SSM(sci, SCI_SETINDENT, iprefs->width, 0);
+	SSM(sci, SCI_SETINDENT, width, 0);

 	/* remove indent spaces on backspace, if using any spaces to indent */
 	SSM(sci, SCI_SETBACKSPACEUNINDENTS, type != GEANY_INDENT_TYPE_TABS, 0);
@@ -4827,7 +4835,7 @@
 	sci = create_new_sci(editor);
 	editor->sci = sci;

-	editor_set_indent_type(editor, iprefs->type);
+	editor_set_indent(editor, iprefs->type, iprefs->width);
 	editor_set_font(editor, interface_prefs.editor_font);
 	editor_apply_update_prefs(editor);

@@ -4998,7 +5006,7 @@
 		editor_get_long_line_column(), editor_prefs.long_line_color);

 	/* update indent width, tab width */
-	editor_set_indent_type(editor, editor->indent_type);
+	editor_set_indent(editor, editor->indent_type, editor->indent_width);
 	sci_set_tab_indents(sci, editor_prefs.use_tab_to_indent);

 	sci_set_autoc_max_height(sci, editor_prefs.symbolcompletion_max_height);
Index: geany-bzr/src/editor.h
===================================================================
--- geany-bzr.orig/src/editor.h
+++ geany-bzr/src/editor.h
@@ -162,6 +162,7 @@
 	gfloat			 scroll_percent;
 	GeanyIndentType	 indent_type;	/* Use editor_get_indent_prefs() instead. */
 	gboolean		 line_breaking;	/**< Whether to split long lines as you type. */
+	gint			 indent_width;
 };


@@ -286,6 +287,8 @@

 void editor_set_indent_type(GeanyEditor *editor, GeanyIndentType type);

+void editor_set_indent(GeanyEditor *editor, GeanyIndentType type, gint width);
+
 void editor_set_line_wrapping(GeanyEditor *editor, gboolean wrap);

 gboolean editor_goto_pos(GeanyEditor *editor, gint pos, gboolean mark);
Index: geany-bzr/src/interface.c
===================================================================
--- geany-bzr.orig/src/interface.c
+++ geany-bzr/src/interface.c
@@ -197,6 +197,17 @@
   GtkWidget *tabs1;
   GtkWidget *spaces1;
   GtkWidget *tabs_and_spaces1;
+  GtkWidget *indent_width1;
+  GtkWidget *indent_width1_menu;
+  GSList *indent_width_1_group = NULL;
+  GtkWidget *indent_width_1;
+  GtkWidget *indent_width_2;
+  GtkWidget *indent_width_3;
+  GtkWidget *indent_width_4;
+  GtkWidget *indent_width_5;
+  GtkWidget *indent_width_6;
+  GtkWidget *indent_width_7;
+  GtkWidget *indent_width_8;
   GtkWidget *separator45;
   GtkWidget *set_file_readonly1;
   GtkWidget *menu_write_unicode_bom1;
@@ -967,6 +978,61 @@
   gtk_container_add (GTK_CONTAINER (indent_type1_menu), tabs_and_spaces1);
   gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (tabs_and_spaces1), TRUE);

+  indent_width1 = gtk_menu_item_new_with_mnemonic (_("Indent Widt_h"));
+  gtk_widget_show (indent_width1);
+  gtk_container_add (GTK_CONTAINER (menu_document1_menu), indent_width1);
+
+  indent_width1_menu = gtk_menu_new ();
+  gtk_menu_item_set_submenu (GTK_MENU_ITEM (indent_width1), indent_width1_menu);
+
+  indent_width_1 = gtk_radio_menu_item_new_with_mnemonic (indent_width_1_group, _("_1"));
+  indent_width_1_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (indent_width_1));
+  gtk_widget_show (indent_width_1);
+  gtk_container_add (GTK_CONTAINER (indent_width1_menu), indent_width_1);
+  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (indent_width_1), TRUE);
+
+  indent_width_2 = gtk_radio_menu_item_new_with_mnemonic (indent_width_1_group, _("_2"));
+  indent_width_1_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (indent_width_2));
+  gtk_widget_show (indent_width_2);
+  gtk_container_add (GTK_CONTAINER (indent_width1_menu), indent_width_2);
+  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (indent_width_2), TRUE);
+
+  indent_width_3 = gtk_radio_menu_item_new_with_mnemonic (indent_width_1_group, _("_3"));
+  indent_width_1_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (indent_width_3));
+  gtk_widget_show (indent_width_3);
+  gtk_container_add (GTK_CONTAINER (indent_width1_menu), indent_width_3);
+  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (indent_width_3), TRUE);
+
+  indent_width_4 = gtk_radio_menu_item_new_with_mnemonic (indent_width_1_group, _("_4"));
+  indent_width_1_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (indent_width_4));
+  gtk_widget_show (indent_width_4);
+  gtk_container_add (GTK_CONTAINER (indent_width1_menu), indent_width_4);
+  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (indent_width_4), TRUE);
+
+  indent_width_5 = gtk_radio_menu_item_new_with_mnemonic (indent_width_1_group, _("_5"));
+  indent_width_1_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (indent_width_5));
+  gtk_widget_show (indent_width_5);
+  gtk_container_add (GTK_CONTAINER (indent_width1_menu), indent_width_5);
+  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (indent_width_5), TRUE);
+
+  indent_width_6 = gtk_radio_menu_item_new_with_mnemonic (indent_width_1_group, _("_6"));
+  indent_width_1_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (indent_width_6));
+  gtk_widget_show (indent_width_6);
+  gtk_container_add (GTK_CONTAINER (indent_width1_menu), indent_width_6);
+  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (indent_width_6), TRUE);
+
+  indent_width_7 = gtk_radio_menu_item_new_with_mnemonic (indent_width_1_group, _("_7"));
+  indent_width_1_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (indent_width_7));
+  gtk_widget_show (indent_width_7);
+  gtk_container_add (GTK_CONTAINER (indent_width1_menu), indent_width_7);
+  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (indent_width_7), TRUE);
+
+  indent_width_8 = gtk_radio_menu_item_new_with_mnemonic (indent_width_1_group, _("_8"));
+  indent_width_1_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (indent_width_8));
+  gtk_widget_show (indent_width_8);
+  gtk_container_add (GTK_CONTAINER (indent_width1_menu), indent_width_8);
+  gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (indent_width_8), TRUE);
+
   separator45 = gtk_separator_menu_item_new ();
   gtk_widget_show (separator45);
   gtk_container_add (GTK_CONTAINER (menu_document1_menu), separator45);
@@ -1584,6 +1650,30 @@
   g_signal_connect ((gpointer) tabs_and_spaces1, "activate",
                     G_CALLBACK (on_tabs_and_spaces1_activate),
                     NULL);
+  g_signal_connect ((gpointer) indent_width_1, "activate",
+                    G_CALLBACK (on_indent_width_1_activate),
+                    NULL);
+  g_signal_connect ((gpointer) indent_width_2, "activate",
+                    G_CALLBACK (on_indent_width_2_activate),
+                    NULL);
+  g_signal_connect ((gpointer) indent_width_3, "activate",
+                    G_CALLBACK (on_indent_width_3_activate),
+                    NULL);
+  g_signal_connect ((gpointer) indent_width_4, "activate",
+                    G_CALLBACK (on_indent_width_4_activate),
+                    NULL);
+  g_signal_connect ((gpointer) indent_width_5, "activate",
+                    G_CALLBACK (on_indent_width_5_activate),
+                    NULL);
+  g_signal_connect ((gpointer) indent_width_6, "activate",
+                    G_CALLBACK (on_indent_width_6_activate),
+                    NULL);
+  g_signal_connect ((gpointer) indent_width_7, "activate",
+                    G_CALLBACK (on_indent_width_7_activate),
+                    NULL);
+  g_signal_connect ((gpointer) indent_width_8, "activate",
+                    G_CALLBACK (on_indent_width_8_activate),
+                    NULL);
   g_signal_connect ((gpointer) set_file_readonly1, "toggled",
                     G_CALLBACK (on_set_file_readonly1_toggled),
                     NULL);
@@ -1846,6 +1936,16 @@
   GLADE_HOOKUP_OBJECT (window1, tabs1, "tabs1");
   GLADE_HOOKUP_OBJECT (window1, spaces1, "spaces1");
   GLADE_HOOKUP_OBJECT (window1, tabs_and_spaces1, "tabs_and_spaces1");
+  GLADE_HOOKUP_OBJECT (window1, indent_width1, "indent_width1");
+  GLADE_HOOKUP_OBJECT (window1, indent_width1_menu, "indent_width1_menu");
+  GLADE_HOOKUP_OBJECT (window1, indent_width_1, "indent_width_1");
+  GLADE_HOOKUP_OBJECT (window1, indent_width_2, "indent_width_2");
+  GLADE_HOOKUP_OBJECT (window1, indent_width_3, "indent_width_3");
+  GLADE_HOOKUP_OBJECT (window1, indent_width_4, "indent_width_4");
+  GLADE_HOOKUP_OBJECT (window1, indent_width_5, "indent_width_5");
+  GLADE_HOOKUP_OBJECT (window1, indent_width_6, "indent_width_6");
+  GLADE_HOOKUP_OBJECT (window1, indent_width_7, "indent_width_7");
+  GLADE_HOOKUP_OBJECT (window1, indent_width_8, "indent_width_8");
   GLADE_HOOKUP_OBJECT (window1, separator45, "separator45");
   GLADE_HOOKUP_OBJECT (window1, set_file_readonly1, "set_file_readonly1");
   GLADE_HOOKUP_OBJECT (window1, menu_write_unicode_bom1, "menu_write_unicode_bom1");
Index: geany-bzr/src/keyfile.c
===================================================================
--- geany-bzr.orig/src/keyfile.c
+++ geany-bzr/src/keyfile.c
@@ -988,7 +988,7 @@

 		if (doc)
 		{
-			editor_set_indent_type(doc->editor, indent_type);
+			editor_set_indent(doc->editor, indent_type, doc->editor->indent_width);
 			editor_set_line_wrapping(doc->editor, line_wrapping);
 			doc->editor->line_breaking = line_breaking;
 			doc->editor->auto_indent = auto_indent;
Index: geany-bzr/src/ui_utils.c
===================================================================
--- geany-bzr.orig/src/ui_utils.c
+++ geany-bzr/src/ui_utils.c
@@ -893,6 +893,16 @@
 	item = ui_lookup_widget(main_widgets.window, widget_name);
 	gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);

+	if (iprefs->width >= 1 && iprefs->width <= 8)
+	{
+		gchar *name;
+
+		name = g_strdup_printf("indent_width_%d", iprefs->width);
+		item = ui_lookup_widget(main_widgets.window, name);
+		gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
+		g_free(name);
+	}
+
 	gtk_check_menu_item_set_active(
 			GTK_CHECK_MENU_ITEM(ui_lookup_widget(main_widgets.window, "set_file_readonly1")),
 			doc->readonly);
