From 501d543492150447797903aec483dfd861f49c42 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Fri, 25 Jul 2008 15:05:27 +0000 Subject: [PATCH 02/22] Note: this breaks the plugin API for indentation editor_prefs. Add GeanyIndentPrefs struct from some GeanyEditorPrefs fields (maybe this struct will get used elsewhere too). Add editor_init(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2821 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 9 +++++++++ src/editor.c | 10 ++++++++++ src/editor.h | 29 ++++++++++++++++++----------- src/main.c | 2 +- src/plugindata.h | 4 ++-- 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 20f177ca..79ea20da 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-07-25 Nick Treleaven + + * src/plugindata.h, src/main.c, src/editor.c, src/editor.h: + Note: this breaks the plugin API for indentation editor_prefs. + Add GeanyIndentPrefs struct from some GeanyEditorPrefs fields (maybe + this struct will get used elsewhere too). + Add editor_init(). + + 2008-07-25 Nick Treleaven * src/interface.c, src/ui_utils.c, geany.glade: diff --git a/src/editor.c b/src/editor.c index a6065353..49692f1f 100644 --- a/src/editor.c +++ b/src/editor.c @@ -3662,3 +3662,13 @@ GeanyEditor *editor_create(GeanyDocument *doc) return editor; } + +void editor_init(void) +{ + static GeanyIndentPrefs indent_prefs; + + memset(&editor_prefs, 0, sizeof(GeanyEditorPrefs)); + memset(&indent_prefs, 0, sizeof GeanyIndentPrefs); + editor_prefs->indentation = &indent_prefs; +} + diff --git a/src/editor.h b/src/editor.h index b381409c..9cac1f18 100644 --- a/src/editor.h +++ b/src/editor.h @@ -51,14 +51,25 @@ typedef enum INDENT_BASIC, INDENT_CURRENTCHARS, INDENT_MATCHBRACES -} IndentMode; +} GeanyIndentMode; -/* These are the default prefs when creating a new editor window. - * Some of these can be overridden per document. - * Remember to increment abi_version in plugindata.h when changing items. */ +typedef struct GeanyIndentPrefs +{ + gint width; /**< Indent width. */ + gint tab_width; /**< Width of a tab, if @c custom_tab_width is set. */ + gboolean custom_tab_width; /**< Whether a tab is a different size from an indent. */ + gboolean use_tabs; /**< Whether to (mainly) use tabs or spaces to indent. */ + gboolean use_tab_to_indent; /* hidden pref */ + GeanyIndentMode mode; +} +GeanyIndentPrefs; + + +/** Default prefs when creating a new editor window. + * Some of these can be overridden per document. */ typedef struct GeanyEditorPrefs { - /* display */ + GeanyIndentPrefs *indentation; /**< Indentation prefs. */ gboolean show_white_space; gboolean show_indent_guide; gboolean show_line_endings; @@ -69,16 +80,10 @@ typedef struct GeanyEditorPrefs gboolean show_linenumber_margin; /* view menu */ gboolean show_scrollbars; /* hidden pref */ gboolean scroll_stop_at_last_line; /* hidden pref */ - - /* behaviour */ gboolean line_wrapping; gboolean use_indicators; gboolean folding; gboolean unfold_all_children; - gint tab_width; - gboolean use_tabs; - gboolean use_tab_to_indent; /* hidden pref */ - IndentMode indent_mode; gboolean disable_dnd; gboolean smart_home_key; gboolean newline_strip; @@ -125,6 +130,8 @@ extern EditorInfo editor_info; +void editor_init(void); + GeanyEditor *editor_create(GeanyDocument *doc); void on_editor_notification(GtkWidget* editor, gint scn, gpointer lscn, gpointer user_data); diff --git a/src/main.c b/src/main.c index 588bf7a5..a292a5f7 100644 --- a/src/main.c +++ b/src/main.c @@ -740,7 +740,6 @@ gint main(gint argc, gchar **argv) memset(&prefs, 0, sizeof(GeanyPrefs)); memset(&interface_prefs, 0, sizeof(GeanyInterfacePrefs)); memset(&toolbar_prefs, 0, sizeof(GeanyToolbarPrefs)); - memset(&editor_prefs, 0, sizeof(GeanyEditorPrefs)); memset(&file_prefs, 0, sizeof(GeanyFilePrefs)); memset(&search_prefs, 0, sizeof(GeanySearchPrefs)); memset(&tool_prefs, 0, sizeof(GeanyToolPrefs)); @@ -800,6 +799,7 @@ gint main(gint argc, gchar **argv) load_settings(); msgwin_init(); + editor_init(); build_init(); search_init(); ui_create_insert_menu_items(); diff --git a/src/plugindata.h b/src/plugindata.h index 9c691f85..a8b6b932 100644 --- a/src/plugindata.h +++ b/src/plugindata.h @@ -36,12 +36,12 @@ /* The API version should be incremented whenever any plugin data types below are * modified or appended to. */ -static const gint api_version = 82; +static const gint api_version = 83; /* The ABI version should be incremented whenever existing fields in the plugin * data types below have to be changed or reordered. It should stay the same if fields * are only appended, as this doesn't affect existing fields. */ -static const gint abi_version = 43; +static const gint abi_version = 44; /** Check the plugin can be loaded by Geany. * This performs runtime checks that try to ensure: From c72767edb54253fdec5c14291a24feabe6da87c8 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Fri, 25 Jul 2008 15:10:53 +0000 Subject: [PATCH 03/22] Add separate Width indent pref. Add 'Custom tab width' checkbox pref. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2822 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 3 + geany.glade | 156 +++++++++++++++++++++++++++++++----------------- src/interface.c | 75 +++++++++++++++-------- 3 files changed, 152 insertions(+), 82 deletions(-) diff --git a/ChangeLog b/ChangeLog index 79ea20da..f169f184 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ Add GeanyIndentPrefs struct from some GeanyEditorPrefs fields (maybe this struct will get used elsewhere too). Add editor_init(). + * src/interface.c, geany.glade: + Add separate Width indent pref. + Add 'Custom tab width' checkbox pref. 2008-07-25 Nick Treleaven diff --git a/geany.glade b/geany.glade index 8ac05bb5..0ac114c7 100644 --- a/geany.glade +++ b/geany.glade @@ -5354,7 +5354,7 @@ Bottom True - 4 + 5 2 False 3 @@ -5381,8 +5381,8 @@ Bottom 0 1 - 3 - 4 + 4 + 5 fill @@ -5401,64 +5401,13 @@ Match braces 1 2 - 3 - 4 + 4 + 5 fill fill - - - True - The width in chars, which one tab character will take - True - 1 - 0 - True - GTK_UPDATE_IF_VALID - False - True - 1 1 99 1 10 10 - - - 1 - 2 - 2 - 3 - fill - - - - - - - True - Tab width: - False - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 - - - 0 - 1 - 2 - 3 - fill - - - - True @@ -5565,6 +5514,101 @@ Match braces + + + + True + Width: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 2 + 3 + fill + + + + + + + True + The width in chars of a single indent + True + 1 + 0 + True + GTK_UPDATE_IF_VALID + False + True + 1 1 99 1 10 10 + + + 1 + 2 + 2 + 3 + + + + + + + True + Make tabs have a different size from the indent width + True + Custom tab width: + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + 1 + 3 + 4 + fill + + + + + + + True + The width in chars, which one tab character will take + True + 1 + 0 + True + GTK_UPDATE_IF_VALID + False + True + 1 1 99 1 10 10 + + + 1 + 2 + 3 + 4 + + + 0 diff --git a/src/interface.c b/src/interface.c index b5f2361b..54dbe908 100644 --- a/src/interface.c +++ b/src/interface.c @@ -2669,15 +2669,18 @@ create_prefs_dialog (void) GtkWidget *table13; GtkWidget *label183; GtkWidget *combo_auto_indent_mode; - GtkObject *spin_tab_width_adj; - GtkWidget *spin_tab_width; - GtkWidget *label116; GtkWidget *hbox8; GtkWidget *radio_indent_tabs; GSList *radio_indent_tabs_group = NULL; GtkWidget *radio_indent_spaces; GtkWidget *label200; GtkWidget *check_detect_indent; + GtkWidget *label220; + GtkObject *spin_indent_width_adj; + GtkWidget *spin_indent_width; + GtkWidget *check_custom_tab_width; + GtkObject *spin_tab_width_adj; + GtkWidget *spin_tab_width; GtkWidget *label195; GtkWidget *frame14; GtkWidget *alignment17; @@ -3588,7 +3591,7 @@ create_prefs_dialog (void) gtk_widget_show (vbox25); gtk_container_add (GTK_CONTAINER (alignment30), vbox25); - table13 = gtk_table_new (4, 2, FALSE); + table13 = gtk_table_new (5, 2, FALSE); gtk_widget_show (table13); gtk_box_pack_start (GTK_BOX (vbox25), table13, FALSE, TRUE, 0); gtk_table_set_row_spacings (GTK_TABLE (table13), 3); @@ -3596,13 +3599,13 @@ create_prefs_dialog (void) label183 = gtk_label_new (_("Auto-indent mode:")); gtk_widget_show (label183); - gtk_table_attach (GTK_TABLE (table13), label183, 0, 1, 3, 4, + gtk_table_attach (GTK_TABLE (table13), label183, 0, 1, 4, 5, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); combo_auto_indent_mode = gtk_combo_box_new_text (); gtk_widget_show (combo_auto_indent_mode); - gtk_table_attach (GTK_TABLE (table13), combo_auto_indent_mode, 1, 2, 3, 4, + gtk_table_attach (GTK_TABLE (table13), combo_auto_indent_mode, 1, 2, 4, 5, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); gtk_combo_box_append_text (GTK_COMBO_BOX (combo_auto_indent_mode), _("None")); @@ -3610,24 +3613,6 @@ create_prefs_dialog (void) gtk_combo_box_append_text (GTK_COMBO_BOX (combo_auto_indent_mode), _("Current chars")); gtk_combo_box_append_text (GTK_COMBO_BOX (combo_auto_indent_mode), _("Match braces")); - spin_tab_width_adj = gtk_adjustment_new (1, 1, 99, 1, 10, 10); - spin_tab_width = gtk_spin_button_new (GTK_ADJUSTMENT (spin_tab_width_adj), 1, 0); - gtk_widget_show (spin_tab_width); - gtk_table_attach (GTK_TABLE (table13), spin_tab_width, 1, 2, 2, 3, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - gtk_tooltips_set_tip (tooltips, spin_tab_width, _("The width in chars, which one tab character will take"), NULL); - gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin_tab_width), TRUE); - gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (spin_tab_width), GTK_UPDATE_IF_VALID); - gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spin_tab_width), TRUE); - - label116 = gtk_label_new (_("Tab width:")); - gtk_widget_show (label116); - gtk_table_attach (GTK_TABLE (table13), label116, 0, 1, 2, 3, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - gtk_misc_set_alignment (GTK_MISC (label116), 0, 0.5); - hbox8 = gtk_hbox_new (FALSE, 12); gtk_widget_show (hbox8); gtk_table_attach (GTK_TABLE (table13), hbox8, 1, 2, 0, 1, @@ -3662,6 +3647,42 @@ create_prefs_dialog (void) (GtkAttachOptions) (0), 0, 0); gtk_tooltips_set_tip (tooltips, check_detect_indent, _("Whether to detect the indentation type from file contents when a file is opened."), NULL); + label220 = gtk_label_new (_("Width:")); + gtk_widget_show (label220); + gtk_table_attach (GTK_TABLE (table13), label220, 0, 1, 2, 3, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label220), 0, 0.5); + + spin_indent_width_adj = gtk_adjustment_new (1, 1, 99, 1, 10, 10); + spin_indent_width = gtk_spin_button_new (GTK_ADJUSTMENT (spin_indent_width_adj), 1, 0); + gtk_widget_show (spin_indent_width); + gtk_table_attach (GTK_TABLE (table13), spin_indent_width, 1, 2, 2, 3, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_tooltips_set_tip (tooltips, spin_indent_width, _("The width in chars of a single indent"), NULL); + gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin_indent_width), TRUE); + gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (spin_indent_width), GTK_UPDATE_IF_VALID); + gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spin_indent_width), TRUE); + + check_custom_tab_width = gtk_check_button_new_with_mnemonic (_("Custom tab width:")); + gtk_widget_show (check_custom_tab_width); + gtk_table_attach (GTK_TABLE (table13), check_custom_tab_width, 0, 1, 3, 4, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_tooltips_set_tip (tooltips, check_custom_tab_width, _("Make tabs have a different size from the indent width"), NULL); + + spin_tab_width_adj = gtk_adjustment_new (1, 1, 99, 1, 10, 10); + spin_tab_width = gtk_spin_button_new (GTK_ADJUSTMENT (spin_tab_width_adj), 1, 0); + gtk_widget_show (spin_tab_width); + gtk_table_attach (GTK_TABLE (table13), spin_tab_width, 1, 2, 3, 4, + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_tooltips_set_tip (tooltips, spin_tab_width, _("The width in chars, which one tab character will take"), NULL); + gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin_tab_width), TRUE); + gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (spin_tab_width), GTK_UPDATE_IF_VALID); + gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spin_tab_width), TRUE); + label195 = gtk_label_new (_("Indentation")); gtk_widget_show (label195); gtk_frame_set_label_widget (GTK_FRAME (frame27), label195); @@ -4865,13 +4886,15 @@ create_prefs_dialog (void) GLADE_HOOKUP_OBJECT (prefs_dialog, table13, "table13"); GLADE_HOOKUP_OBJECT (prefs_dialog, label183, "label183"); GLADE_HOOKUP_OBJECT (prefs_dialog, combo_auto_indent_mode, "combo_auto_indent_mode"); - GLADE_HOOKUP_OBJECT (prefs_dialog, spin_tab_width, "spin_tab_width"); - GLADE_HOOKUP_OBJECT (prefs_dialog, label116, "label116"); GLADE_HOOKUP_OBJECT (prefs_dialog, hbox8, "hbox8"); GLADE_HOOKUP_OBJECT (prefs_dialog, radio_indent_tabs, "radio_indent_tabs"); GLADE_HOOKUP_OBJECT (prefs_dialog, radio_indent_spaces, "radio_indent_spaces"); GLADE_HOOKUP_OBJECT (prefs_dialog, label200, "label200"); GLADE_HOOKUP_OBJECT (prefs_dialog, check_detect_indent, "check_detect_indent"); + GLADE_HOOKUP_OBJECT (prefs_dialog, label220, "label220"); + GLADE_HOOKUP_OBJECT (prefs_dialog, spin_indent_width, "spin_indent_width"); + GLADE_HOOKUP_OBJECT (prefs_dialog, check_custom_tab_width, "check_custom_tab_width"); + GLADE_HOOKUP_OBJECT (prefs_dialog, spin_tab_width, "spin_tab_width"); GLADE_HOOKUP_OBJECT (prefs_dialog, label195, "label195"); GLADE_HOOKUP_OBJECT (prefs_dialog, frame14, "frame14"); GLADE_HOOKUP_OBJECT (prefs_dialog, alignment17, "alignment17"); From 677b91f140945430788f68ac2b4931053d5b8e8c Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 28 Jul 2008 11:52:19 +0000 Subject: [PATCH 04/22] Replace 'Custom tab width' option with a 'Tabs & Spaces' Indent Type radio option, and a Tab Width spin entry. Replace GeanyIndentPrefs::use_tabs with GeanyIndentType field 'type'. (Still won't compile ;-)). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2827 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 9 ++ geany.glade | 256 ++++++++++++++++++++++++++++-------------------- src/editor.h | 32 +++--- src/interface.c | 124 +++++++++++++---------- 4 files changed, 251 insertions(+), 170 deletions(-) diff --git a/ChangeLog b/ChangeLog index f169f184..03643678 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-07-28 Nick Treleaven + + * src/interface.c, src/editor.h, geany.glade: + Replace 'Custom tab width' option with a 'Tabs & Spaces' Indent Type + radio option, and a Tab Width spin entry. + Replace GeanyIndentPrefs::use_tabs with GeanyIndentType field 'type'. + (Still won't compile ;-)). + + 2008-07-25 Nick Treleaven * src/plugindata.h, src/main.c, src/editor.c, src/editor.h: diff --git a/geany.glade b/geany.glade index 0ac114c7..cc402cbb 100644 --- a/geany.glade +++ b/geany.glade @@ -5354,7 +5354,7 @@ Bottom True - 5 + 7 2 False 3 @@ -5369,7 +5369,7 @@ Bottom GTK_JUSTIFY_LEFT False False - 0.5 + 0 0.5 0 0 @@ -5381,8 +5381,8 @@ Bottom 0 1 - 4 - 5 + 6 + 7 fill @@ -5401,69 +5401,13 @@ Match braces 1 2 - 4 - 5 + 6 + 7 fill fill - - - True - False - 12 - - - - True - Whether to use tabs or spaces when indentation is inserted. - True - _Tabs - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - False - False - - - - - - True - Whether to use tabs or spaces when indentation is inserted. - True - _Spaces - True - GTK_RELIEF_NORMAL - True - False - False - True - radio_indent_tabs - - - 0 - False - False - - - - - 1 - 2 - 0 - 1 - fill - - - True @@ -5485,29 +5429,6 @@ Match braces 0 1 - 0 - 1 - fill - - - - - - - True - Whether to detect the indentation type from file contents when a file is opened. - True - Detect from file - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 1 - 2 1 2 fill @@ -5536,8 +5457,8 @@ Match braces 0 1 - 2 - 3 + 0 + 1 fill @@ -5559,18 +5480,18 @@ Match braces 1 2 - 2 - 3 + 0 + 1 - + True - Make tabs have a different size from the indent width + Use spaces when inserting indentation True - Custom tab width: + _Spaces True GTK_RELIEF_NORMAL True @@ -5579,8 +5500,56 @@ Match braces True - 0 - 1 + 1 + 2 + 2 + 3 + fill + + + + + + + True + Use one tab per indent + True + _Tabs + True + GTK_RELIEF_NORMAL + True + False + False + True + radio_indent_spaces + + + 1 + 2 + 1 + 2 + fill + + + + + + + True + Use spaces if the total indent is less than the tab width, otherwise use both + True + T_abs & Spaces + True + GTK_RELIEF_NORMAL + True + False + False + True + radio_indent_spaces + + + 1 + 2 3 4 fill @@ -5589,23 +5558,98 @@ Match braces - + True - The width in chars, which one tab character will take - True - 1 - 0 - True - GTK_UPDATE_IF_VALID - False - True - 1 1 99 1 10 10 + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 24 + 0 + + + + True + False + 12 + + + + True + Tab Width: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + False + False + + + + + + True + The width of a tab when Tabs & Spaces is set for a document + True + 1 + 0 + True + GTK_UPDATE_IF_VALID + False + True + 8 1 99 1 10 10 + + + 0 + True + True + + + + 1 2 - 3 - 4 + 4 + 5 + fill + + + + + + True + Whether to detect the indentation type from file contents when a file is opened. + True + Detect from file + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 1 + 2 + 5 + 6 + fill diff --git a/src/editor.h b/src/editor.h index 9cac1f18..b8318def 100644 --- a/src/editor.h +++ b/src/editor.h @@ -45,22 +45,32 @@ #define SSM(s, m, w, l) scintilla_send_message(s, m, w, l) +/** Whether to use tabs, spaces or both to indent. */ typedef enum { - INDENT_NONE = 0, - INDENT_BASIC, - INDENT_CURRENTCHARS, - INDENT_MATCHBRACES -} GeanyIndentMode; + GEANY_INDENT_TYPE_TABS /**< Tabs. */ + GEANY_INDENT_TYPE_SPACES /**< Spaces. */ + GEANY_INDENT_TYPE_BOTH /**< Both. */ +} +GeanyIndentType; + +typedef enum +{ + GEANY_AUTOINDENT_NONE = 0, + GEANY_AUTOINDENT_BASIC, + GEANY_AUTOINDENT_CURRENTCHARS, + GEANY_AUTOINDENT_MATCHBRACES +} +GeanyAutoIndent; + typedef struct GeanyIndentPrefs { - gint width; /**< Indent width. */ - gint tab_width; /**< Width of a tab, if @c custom_tab_width is set. */ - gboolean custom_tab_width; /**< Whether a tab is a different size from an indent. */ - gboolean use_tabs; /**< Whether to (mainly) use tabs or spaces to indent. */ - gboolean use_tab_to_indent; /* hidden pref */ - GeanyIndentMode mode; + gint width; /**< Indent width. */ + GeanyIndentType type; /**< Whether to use tabs, spaces or both to indent. */ + gint tab_width; /**< Width of a tab, when using GEANY_INDENT_TYPE_BOTH. */ + gboolean use_tab_to_indent; /* hidden pref makes pressing Tab key like Ctrl-I */ + GeanyAutoIndent auto_indent_mode; } GeanyIndentPrefs; diff --git a/src/interface.c b/src/interface.c index 54dbe908..46d891ef 100644 --- a/src/interface.c +++ b/src/interface.c @@ -2669,18 +2669,20 @@ create_prefs_dialog (void) GtkWidget *table13; GtkWidget *label183; GtkWidget *combo_auto_indent_mode; - GtkWidget *hbox8; - GtkWidget *radio_indent_tabs; - GSList *radio_indent_tabs_group = NULL; - GtkWidget *radio_indent_spaces; GtkWidget *label200; - GtkWidget *check_detect_indent; GtkWidget *label220; GtkObject *spin_indent_width_adj; GtkWidget *spin_indent_width; - GtkWidget *check_custom_tab_width; + GtkWidget *radio_indent_spaces; + GSList *radio_indent_spaces_group = NULL; + GtkWidget *radio_indent_tabs; + GtkWidget *radio_indent_both; + GtkWidget *alignment41; + GtkWidget *hbox12; + GtkWidget *label221; GtkObject *spin_tab_width_adj; GtkWidget *spin_tab_width; + GtkWidget *check_detect_indent; GtkWidget *label195; GtkWidget *frame14; GtkWidget *alignment17; @@ -3591,7 +3593,7 @@ create_prefs_dialog (void) gtk_widget_show (vbox25); gtk_container_add (GTK_CONTAINER (alignment30), vbox25); - table13 = gtk_table_new (5, 2, FALSE); + table13 = gtk_table_new (7, 2, FALSE); gtk_widget_show (table13); gtk_box_pack_start (GTK_BOX (vbox25), table13, FALSE, TRUE, 0); gtk_table_set_row_spacings (GTK_TABLE (table13), 3); @@ -3599,13 +3601,14 @@ create_prefs_dialog (void) label183 = gtk_label_new (_("Auto-indent mode:")); gtk_widget_show (label183); - gtk_table_attach (GTK_TABLE (table13), label183, 0, 1, 4, 5, + gtk_table_attach (GTK_TABLE (table13), label183, 0, 1, 6, 7, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label183), 0, 0.5); combo_auto_indent_mode = gtk_combo_box_new_text (); gtk_widget_show (combo_auto_indent_mode); - gtk_table_attach (GTK_TABLE (table13), combo_auto_indent_mode, 1, 2, 4, 5, + gtk_table_attach (GTK_TABLE (table13), combo_auto_indent_mode, 1, 2, 6, 7, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); gtk_combo_box_append_text (GTK_COMBO_BOX (combo_auto_indent_mode), _("None")); @@ -3613,43 +3616,16 @@ create_prefs_dialog (void) gtk_combo_box_append_text (GTK_COMBO_BOX (combo_auto_indent_mode), _("Current chars")); gtk_combo_box_append_text (GTK_COMBO_BOX (combo_auto_indent_mode), _("Match braces")); - hbox8 = gtk_hbox_new (FALSE, 12); - gtk_widget_show (hbox8); - gtk_table_attach (GTK_TABLE (table13), hbox8, 1, 2, 0, 1, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0); - - radio_indent_tabs = gtk_radio_button_new_with_mnemonic (NULL, _("_Tabs")); - gtk_widget_show (radio_indent_tabs); - gtk_box_pack_start (GTK_BOX (hbox8), radio_indent_tabs, FALSE, FALSE, 0); - gtk_tooltips_set_tip (tooltips, radio_indent_tabs, _("Whether to use tabs or spaces when indentation is inserted."), NULL); - gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_indent_tabs), radio_indent_tabs_group); - radio_indent_tabs_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_indent_tabs)); - - radio_indent_spaces = gtk_radio_button_new_with_mnemonic (NULL, _("_Spaces")); - gtk_widget_show (radio_indent_spaces); - gtk_box_pack_start (GTK_BOX (hbox8), radio_indent_spaces, FALSE, FALSE, 0); - gtk_tooltips_set_tip (tooltips, radio_indent_spaces, _("Whether to use tabs or spaces when indentation is inserted."), NULL); - gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_indent_spaces), radio_indent_tabs_group); - radio_indent_tabs_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_indent_spaces)); - label200 = gtk_label_new (_("Type:")); gtk_widget_show (label200); - gtk_table_attach (GTK_TABLE (table13), label200, 0, 1, 0, 1, + gtk_table_attach (GTK_TABLE (table13), label200, 0, 1, 1, 2, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (label200), 0, 0.5); - check_detect_indent = gtk_check_button_new_with_mnemonic (_("Detect from file")); - gtk_widget_show (check_detect_indent); - gtk_table_attach (GTK_TABLE (table13), check_detect_indent, 1, 2, 1, 2, - (GtkAttachOptions) (GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - gtk_tooltips_set_tip (tooltips, check_detect_indent, _("Whether to detect the indentation type from file contents when a file is opened."), NULL); - label220 = gtk_label_new (_("Width:")); gtk_widget_show (label220); - gtk_table_attach (GTK_TABLE (table13), label220, 0, 1, 2, 3, + gtk_table_attach (GTK_TABLE (table13), label220, 0, 1, 0, 1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_misc_set_alignment (GTK_MISC (label220), 0, 0.5); @@ -3657,7 +3633,7 @@ create_prefs_dialog (void) spin_indent_width_adj = gtk_adjustment_new (1, 1, 99, 1, 10, 10); spin_indent_width = gtk_spin_button_new (GTK_ADJUSTMENT (spin_indent_width_adj), 1, 0); gtk_widget_show (spin_indent_width); - gtk_table_attach (GTK_TABLE (table13), spin_indent_width, 1, 2, 2, 3, + gtk_table_attach (GTK_TABLE (table13), spin_indent_width, 1, 2, 0, 1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (0), 0, 0); gtk_tooltips_set_tip (tooltips, spin_indent_width, _("The width in chars of a single indent"), NULL); @@ -3665,24 +3641,64 @@ create_prefs_dialog (void) gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (spin_indent_width), GTK_UPDATE_IF_VALID); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spin_indent_width), TRUE); - check_custom_tab_width = gtk_check_button_new_with_mnemonic (_("Custom tab width:")); - gtk_widget_show (check_custom_tab_width); - gtk_table_attach (GTK_TABLE (table13), check_custom_tab_width, 0, 1, 3, 4, + radio_indent_spaces = gtk_radio_button_new_with_mnemonic (NULL, _("_Spaces")); + gtk_widget_show (radio_indent_spaces); + gtk_table_attach (GTK_TABLE (table13), radio_indent_spaces, 1, 2, 2, 3, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (0), 0, 0); - gtk_tooltips_set_tip (tooltips, check_custom_tab_width, _("Make tabs have a different size from the indent width"), NULL); + gtk_tooltips_set_tip (tooltips, radio_indent_spaces, _("Use spaces when inserting indentation"), NULL); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_indent_spaces), radio_indent_spaces_group); + radio_indent_spaces_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_indent_spaces)); - spin_tab_width_adj = gtk_adjustment_new (1, 1, 99, 1, 10, 10); + radio_indent_tabs = gtk_radio_button_new_with_mnemonic (NULL, _("_Tabs")); + gtk_widget_show (radio_indent_tabs); + gtk_table_attach (GTK_TABLE (table13), radio_indent_tabs, 1, 2, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_tooltips_set_tip (tooltips, radio_indent_tabs, _("Use one tab per indent"), NULL); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_indent_tabs), radio_indent_spaces_group); + radio_indent_spaces_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_indent_tabs)); + + radio_indent_both = gtk_radio_button_new_with_mnemonic (NULL, _("T_abs & Spaces")); + gtk_widget_show (radio_indent_both); + gtk_table_attach (GTK_TABLE (table13), radio_indent_both, 1, 2, 3, 4, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_tooltips_set_tip (tooltips, radio_indent_both, _("Use spaces if the total indent is less than the tab width, otherwise use both"), NULL); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_indent_both), radio_indent_spaces_group); + radio_indent_spaces_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_indent_both)); + + alignment41 = gtk_alignment_new (0.5, 0.5, 1, 1); + gtk_widget_show (alignment41); + gtk_table_attach (GTK_TABLE (table13), alignment41, 1, 2, 4, 5, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), 0, 0); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment41), 0, 0, 24, 0); + + hbox12 = gtk_hbox_new (FALSE, 12); + gtk_widget_show (hbox12); + gtk_container_add (GTK_CONTAINER (alignment41), hbox12); + + label221 = gtk_label_new (_("Tab Width:")); + gtk_widget_show (label221); + gtk_box_pack_start (GTK_BOX (hbox12), label221, FALSE, FALSE, 0); + + spin_tab_width_adj = gtk_adjustment_new (8, 1, 99, 1, 10, 10); spin_tab_width = gtk_spin_button_new (GTK_ADJUSTMENT (spin_tab_width_adj), 1, 0); gtk_widget_show (spin_tab_width); - gtk_table_attach (GTK_TABLE (table13), spin_tab_width, 1, 2, 3, 4, - (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), - (GtkAttachOptions) (0), 0, 0); - gtk_tooltips_set_tip (tooltips, spin_tab_width, _("The width in chars, which one tab character will take"), NULL); + gtk_box_pack_start (GTK_BOX (hbox12), spin_tab_width, TRUE, TRUE, 0); + gtk_tooltips_set_tip (tooltips, spin_tab_width, _("The width of a tab when Tabs & Spaces is set for a document"), NULL); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin_tab_width), TRUE); gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (spin_tab_width), GTK_UPDATE_IF_VALID); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spin_tab_width), TRUE); + check_detect_indent = gtk_check_button_new_with_mnemonic (_("Detect from file")); + gtk_widget_show (check_detect_indent); + gtk_table_attach (GTK_TABLE (table13), check_detect_indent, 1, 2, 5, 6, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_tooltips_set_tip (tooltips, check_detect_indent, _("Whether to detect the indentation type from file contents when a file is opened."), NULL); + label195 = gtk_label_new (_("Indentation")); gtk_widget_show (label195); gtk_frame_set_label_widget (GTK_FRAME (frame27), label195); @@ -4886,15 +4902,17 @@ create_prefs_dialog (void) GLADE_HOOKUP_OBJECT (prefs_dialog, table13, "table13"); GLADE_HOOKUP_OBJECT (prefs_dialog, label183, "label183"); GLADE_HOOKUP_OBJECT (prefs_dialog, combo_auto_indent_mode, "combo_auto_indent_mode"); - GLADE_HOOKUP_OBJECT (prefs_dialog, hbox8, "hbox8"); - GLADE_HOOKUP_OBJECT (prefs_dialog, radio_indent_tabs, "radio_indent_tabs"); - GLADE_HOOKUP_OBJECT (prefs_dialog, radio_indent_spaces, "radio_indent_spaces"); GLADE_HOOKUP_OBJECT (prefs_dialog, label200, "label200"); - GLADE_HOOKUP_OBJECT (prefs_dialog, check_detect_indent, "check_detect_indent"); GLADE_HOOKUP_OBJECT (prefs_dialog, label220, "label220"); GLADE_HOOKUP_OBJECT (prefs_dialog, spin_indent_width, "spin_indent_width"); - GLADE_HOOKUP_OBJECT (prefs_dialog, check_custom_tab_width, "check_custom_tab_width"); + GLADE_HOOKUP_OBJECT (prefs_dialog, radio_indent_spaces, "radio_indent_spaces"); + GLADE_HOOKUP_OBJECT (prefs_dialog, radio_indent_tabs, "radio_indent_tabs"); + GLADE_HOOKUP_OBJECT (prefs_dialog, radio_indent_both, "radio_indent_both"); + GLADE_HOOKUP_OBJECT (prefs_dialog, alignment41, "alignment41"); + GLADE_HOOKUP_OBJECT (prefs_dialog, hbox12, "hbox12"); + GLADE_HOOKUP_OBJECT (prefs_dialog, label221, "label221"); GLADE_HOOKUP_OBJECT (prefs_dialog, spin_tab_width, "spin_tab_width"); + GLADE_HOOKUP_OBJECT (prefs_dialog, check_detect_indent, "check_detect_indent"); GLADE_HOOKUP_OBJECT (prefs_dialog, label195, "label195"); GLADE_HOOKUP_OBJECT (prefs_dialog, frame14, "frame14"); GLADE_HOOKUP_OBJECT (prefs_dialog, alignment17, "alignment17"); From cadbe70a57fadd2fe2e0113e0ddf4da18ffbd7c3 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 28 Jul 2008 13:38:12 +0000 Subject: [PATCH 05/22] Add missing commas (oops). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2828 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- src/editor.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/editor.h b/src/editor.h index b8318def..9009ace9 100644 --- a/src/editor.h +++ b/src/editor.h @@ -48,8 +48,8 @@ /** Whether to use tabs, spaces or both to indent. */ typedef enum { - GEANY_INDENT_TYPE_TABS /**< Tabs. */ - GEANY_INDENT_TYPE_SPACES /**< Spaces. */ + GEANY_INDENT_TYPE_TABS, /**< Tabs. */ + GEANY_INDENT_TYPE_SPACES, /**< Spaces. */ GEANY_INDENT_TYPE_BOTH /**< Both. */ } GeanyIndentType; From 264ad738ff009a2ca16760079fa69d8ec6dc4ba0 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 28 Jul 2008 13:42:14 +0000 Subject: [PATCH 06/22] Move toggle_prefs to a function toggle_items_foreach(), which takes a PREF_DISPLAY or PREF_UPDATE argument. This means the PrefEntry array can contain runtime fields, so can read pointer contents. Add pref_item_callbacks array of functions to call like toggle_items_foreach(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2829 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 6 ++++ src/prefs.c | 81 ++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 61 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 03643678..b2b19090 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,12 @@ radio option, and a Tab Width spin entry. Replace GeanyIndentPrefs::use_tabs with GeanyIndentType field 'type'. (Still won't compile ;-)). + * src/prefs.c: + Move toggle_prefs to a function toggle_items_foreach(), which takes + a PREF_DISPLAY or PREF_UPDATE argument. This means the PrefEntry + array can contain runtime fields, so can read pointer contents. + Add pref_item_callbacks array of functions to call like + toggle_items_foreach(). 2008-07-25 Nick Treleaven diff --git a/src/prefs.c b/src/prefs.c index 8ce75eab..c1c2217f 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -89,7 +89,14 @@ static void on_prefs_print_radio_button_toggled(GtkToggleButton *togglebutton, g static void on_prefs_print_page_header_toggled(GtkToggleButton *togglebutton, gpointer user_data); -/* used in e.g. init_toggle_button_prefs(). */ +typedef enum PrefCallbackAction +{ + PREF_DISPLAY, + PREF_UPDATE +} +PrefCallbackAction; + + typedef struct PrefEntry { const gchar *widget_name; @@ -97,14 +104,44 @@ typedef struct PrefEntry } PrefEntry; -static PrefEntry toggle_prefs[] = -{ - {"check_cmdline_new_files", &file_prefs.cmdline_new_files}, - {"check_ask_suppress_search_dialogs", &search_prefs.suppress_dialogs}, - {"check_search_use_current_word", &search_prefs.use_current_word}, - {"check_fif_current_dir", &search_prefs.use_current_file_dir}, - {NULL, NULL} /* must be terminated */ +static void toggle_items_foreach(PrefCallbackAction action) +{ + guint i; + PrefEntry items[] = + { + {"check_cmdline_new_files", &file_prefs.cmdline_new_files}, + + {"check_ask_suppress_search_dialogs", &search_prefs.suppress_dialogs}, + {"check_search_use_current_word", &search_prefs.use_current_word}, + {"check_fif_current_dir", &search_prefs.use_current_file_dir}, + }; + + for (i = 0; i < G_N_ELEMENTS(items); i++) + { + PrefEntry *pe = &items[i]; + GtkWidget *widget = lookup_widget(ui_widgets.prefs_dialog, pe->widget_name); + gboolean *setting = pe->setting; + + switch (action) + { + case PREF_DISPLAY: + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), *setting); + break; + case PREF_UPDATE: + *setting = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); + break; + } + } +} + + +typedef void (*PrefItemsCallback)(PrefCallbackAction action); + +/* List of functions which hold the PrefEntry arrays. This allows access to + * runtime setting fields like EditorPrefs::indentation->width. */ +PrefItemsCallback pref_item_callbacks[] = { + toggle_items_foreach }; @@ -180,16 +217,12 @@ static void init_keybindings(void) } -static void init_toggle_button_prefs() +static void init_prefs(void) { - PrefEntry *pe; + guint i; - for (pe = toggle_prefs; pe->widget_name != NULL; pe++) - { - GtkWidget *widget = lookup_widget(ui_widgets.prefs_dialog, pe->widget_name); - - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), *(gboolean*)pe->setting); - } + for (i = 0; i < G_N_ELEMENTS(pref_item_callbacks); i++) + pref_item_callbacks[i](PREF_DISPLAY); } @@ -198,7 +231,7 @@ void prefs_init_dialog(void) GtkWidget *widget; GdkColor *color; - init_toggle_button_prefs(); + init_prefs(); /* General settings */ /* startup */ @@ -614,16 +647,12 @@ void prefs_init_dialog(void) } -static void update_toggle_button_prefs() +static void update_prefs(void) { - PrefEntry *pe; + guint i; - for (pe = toggle_prefs; pe->widget_name != NULL; pe++) - { - GtkWidget *widget = lookup_widget(ui_widgets.prefs_dialog, pe->widget_name); - - *(gboolean*)pe->setting = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - } + for (i = 0; i < G_N_ELEMENTS(pref_item_callbacks); i++) + pref_item_callbacks[i](PREF_UPDATE); } @@ -638,7 +667,7 @@ on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_data) GtkWidget *widget; guint i; - update_toggle_button_prefs(); + update_prefs(); /* General settings */ /* startup */ From da4a914d5eb7d711cd6e3ba8457e7d7e992ef84c Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 28 Jul 2008 13:50:55 +0000 Subject: [PATCH 07/22] Add spin_items_foreach(). Bind spin_indent_width, spin_tab_width widgets to settings. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2830 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 3 +++ src/prefs.c | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index b2b19090..b27b4c8e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,9 @@ array can contain runtime fields, so can read pointer contents. Add pref_item_callbacks array of functions to call like toggle_items_foreach(). + * src/prefs.c: + Add spin_items_foreach(). + Bind spin_indent_width, spin_tab_width widgets to settings. 2008-07-25 Nick Treleaven diff --git a/src/prefs.c b/src/prefs.c index c1c2217f..1a5e2ca9 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -136,12 +136,41 @@ static void toggle_items_foreach(PrefCallbackAction action) } +static void spin_items_foreach(PrefCallbackAction action) +{ + guint i; + PrefEntry items[] = + { + {"spin_indent_width", &editor_prefs.indentation->width}, + {"spin_tab_width", &editor_prefs.indentation->tab_width}, + }; + + for (i = 0; i < G_N_ELEMENTS(items); i++) + { + PrefEntry *pe = &items[i]; + GtkWidget *widget = lookup_widget(ui_widgets.prefs_dialog, pe->widget_name); + gint *setting = pe->setting; + + switch (action) + { + case PREF_DISPLAY: + gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), *setting); + break; + case PREF_UPDATE: + *setting = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); + break; + } + } +} + + typedef void (*PrefItemsCallback)(PrefCallbackAction action); /* List of functions which hold the PrefEntry arrays. This allows access to * runtime setting fields like EditorPrefs::indentation->width. */ PrefItemsCallback pref_item_callbacks[] = { - toggle_items_foreach + toggle_items_foreach, + spin_items_foreach }; @@ -433,9 +462,6 @@ void prefs_init_dialog(void) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.final_new_line); /* Editor settings */ - widget = lookup_widget(ui_widgets.prefs_dialog, "spin_tab_width"); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), editor_prefs.tab_width); - widget = lookup_widget(ui_widgets.prefs_dialog, "check_replace_tabs"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.replace_tabs); @@ -842,9 +868,6 @@ on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_data) /* Editor settings */ - widget = lookup_widget(ui_widgets.prefs_dialog, "spin_tab_width"); - editor_prefs.tab_width = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); - widget = lookup_widget(ui_widgets.prefs_dialog, "spin_long_line"); editor_prefs.long_line_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); From 5dc0ae673b630170b072c99f2a51b1e033b27fc4 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 28 Jul 2008 17:28:19 +0000 Subject: [PATCH 08/22] Add ui_radio_menu_item_set_active_index(), ui_radio_menu_item_get_active_index(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2831 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 3 +++ src/ui_utils.c | 43 ++++++++++++++++++++++++++++++++++++++++++- src/ui_utils.h | 4 ++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b27b4c8e..9d4720dc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,9 @@ * src/prefs.c: Add spin_items_foreach(). Bind spin_indent_width, spin_tab_width widgets to settings. + * src/ui_utils.c, src/ui_utils.h: + Add ui_radio_menu_item_set_active_index(), + ui_radio_menu_item_get_active_index(). 2008-07-25 Nick Treleaven diff --git a/src/ui_utils.c b/src/ui_utils.c index a303b6eb..e17dff2f 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -706,7 +706,8 @@ void ui_document_show_hide(GeanyDocument *doc) item = lookup_widget(main_widgets.window, "menu_use_auto_indentation1"); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), doc->editor->auto_indent); - gtk_widget_set_sensitive(item, editor_prefs.indent_mode != INDENT_NONE); + gtk_widget_set_sensitive(item, + editor_prefs.indentation->auto_indent_mode != GEANY_AUTOINDENT_NONE); item = lookup_widget(main_widgets.window, doc->editor->use_tabs ? "tabs1" : "spaces1"); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE); @@ -1505,3 +1506,43 @@ void ui_init(void) init_document_widgets(); } + + +void ui_radio_menu_item_set_active_index(GtkRadioMenuItem *widget, guint idx) +{ + GSList *item = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(widget)); + guint i; + + for (i = 0; item != NULL; item = g_slist_next(item), i++) + { + if (i == idx) + { + GtkCheckMenuItem *radio = item->data; + + gtk_check_menu_item_set_active(radio, TRUE); + return; + } + } + g_warning("Index %u is out of range for group of widget %s", + idx, gtk_widget_get_name(GTK_WIDGET(widget))); +} + + +guint ui_radio_menu_item_get_active_index(GtkRadioMenuItem *widget) +{ + GSList *item = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(widget)); + guint i; + + for (i = 0; item != NULL; item = g_slist_next(item), i++) + { + GtkCheckMenuItem *radio = item->data; + + if (gtk_check_menu_item_get_active(radio)) + return i; + } + g_warning("No active group item for widget %s", + gtk_widget_get_name(GTK_WIDGET(widget))); + return 0; +} + + diff --git a/src/ui_utils.h b/src/ui_utils.h index bd6efb4f..dfe60d95 100644 --- a/src/ui_utils.h +++ b/src/ui_utils.h @@ -151,6 +151,10 @@ void ui_setup_open_button_callback(GtkWidget *open_btn, const gchar *title, void ui_table_add_row(GtkTable *table, gint row, ...) G_GNUC_NULL_TERMINATED; +void ui_radio_menu_item_set_active_index(GtkRadioMenuItem *widget, guint index); + +guint ui_radio_menu_item_get_active_index(GtkRadioMenuItem *widget); + /* End of 'generic' functions */ From a03eb964abce6b33b6e889a227169349fcef3cf6 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 28 Jul 2008 17:31:33 +0000 Subject: [PATCH 09/22] Add radio_items_foreach(), combo_items_foreach(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2832 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 2 ++ src/prefs.c | 87 +++++++++++++++++++++++++++++++++++------------------ 2 files changed, 60 insertions(+), 29 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9d4720dc..a7372096 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,8 @@ * src/ui_utils.c, src/ui_utils.h: Add ui_radio_menu_item_set_active_index(), ui_radio_menu_item_get_active_index(). + * src/prefs.c: + Add radio_items_foreach(), combo_items_foreach(). 2008-07-25 Nick Treleaven diff --git a/src/prefs.c b/src/prefs.c index 1a5e2ca9..f8b0aab3 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -164,13 +164,70 @@ static void spin_items_foreach(PrefCallbackAction action) } +static void radio_items_foreach(PrefCallbackAction action) +{ + guint i; + /* Only add one widget per radio-group */ + PrefEntry items[] = + { + {"radio_indent_spaces", &editor_prefs.indentation->type}, + }; + + for (i = 0; i < G_N_ELEMENTS(items); i++) + { + PrefEntry *pe = &items[i]; + GtkWidget *widget = lookup_widget(ui_widgets.prefs_dialog, pe->widget_name); + gint *setting = pe->setting; + + switch (action) + { + case PREF_DISPLAY: + ui_radio_menu_item_set_active_index(GTK_RADIO_MENU_ITEM(widget), *setting); + break; + case PREF_UPDATE: + *setting = ui_radio_menu_item_get_active_index(GTK_RADIO_MENU_ITEM(widget)); + break; + } + } +} + + +static void combo_items_foreach(PrefCallbackAction action) +{ + guint i; + PrefEntry items[] = + { + {"combo_auto_indent_mode", &editor_prefs.indentation->type}, + }; + + for (i = 0; i < G_N_ELEMENTS(items); i++) + { + PrefEntry *pe = &items[i]; + GtkWidget *widget = lookup_widget(ui_widgets.prefs_dialog, pe->widget_name); + gint *setting = pe->setting; + + switch (action) + { + case PREF_DISPLAY: + gtk_combo_box_set_active(GTK_COMBO_BOX(widget), *setting); + break; + case PREF_UPDATE: + *setting = gtk_combo_box_get_active(GTK_COMBO_BOX(widget)); + break; + } + } +} + + typedef void (*PrefItemsCallback)(PrefCallbackAction action); /* List of functions which hold the PrefEntry arrays. This allows access to * runtime setting fields like EditorPrefs::indentation->width. */ PrefItemsCallback pref_item_callbacks[] = { toggle_items_foreach, - spin_items_foreach + spin_items_foreach, + radio_items_foreach, + combo_items_foreach }; @@ -474,9 +531,6 @@ void prefs_init_dialog(void) widget = lookup_widget(ui_widgets.prefs_dialog, "check_line_end"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.show_line_endings); - widget = lookup_widget(ui_widgets.prefs_dialog, "combo_auto_indent_mode"); - gtk_combo_box_set_active(GTK_COMBO_BOX(widget), editor_prefs.indent_mode); - widget = lookup_widget(ui_widgets.prefs_dialog, "check_detect_indent"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.detect_tab_mode); @@ -506,12 +560,6 @@ void prefs_init_dialog(void) widget = lookup_widget(ui_widgets.prefs_dialog, "check_newline_strip"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.newline_strip); - if (editor_prefs.use_tabs) - widget = lookup_widget(ui_widgets.prefs_dialog, "radio_indent_tabs"); - else - widget = lookup_widget(ui_widgets.prefs_dialog, "radio_indent_spaces"); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE); - widget = lookup_widget(ui_widgets.prefs_dialog, "check_indicators"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.use_indicators); @@ -887,9 +935,6 @@ on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_data) widget = lookup_widget(ui_widgets.prefs_dialog, "check_line_end"); editor_prefs.show_line_endings = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - widget = lookup_widget(ui_widgets.prefs_dialog, "combo_auto_indent_mode"); - editor_prefs.indent_mode = gtk_combo_box_get_active(GTK_COMBO_BOX(widget)); - widget = lookup_widget(ui_widgets.prefs_dialog, "check_line_wrapping"); editor_prefs.line_wrapping = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); @@ -911,22 +956,6 @@ on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_data) widget = lookup_widget(ui_widgets.prefs_dialog, "check_newline_strip"); editor_prefs.newline_strip = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - widget = lookup_widget(ui_widgets.prefs_dialog, "radio_indent_tabs"); - { - gboolean use_tabs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - - /* override each document setting only if the default has changed */ - if (editor_prefs.use_tabs != use_tabs) - { - editor_prefs.use_tabs = use_tabs; - for (i = 0; i < documents_array->len; i++) - { - if (documents[i]->is_valid) - editor_set_use_tabs(documents[i]->editor, editor_prefs.use_tabs); - } - } - } - widget = lookup_widget(ui_widgets.prefs_dialog, "check_detect_indent"); editor_prefs.detect_tab_mode = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); From 4bb4f83374add99cd2ea73f67a9290e6d826dd22 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Tue, 29 Jul 2008 14:43:34 +0000 Subject: [PATCH 10/22] Move detect_tab_mode editor pref to indentation pref 'detect_type'. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2833 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 6 ++++++ src/editor.h | 2 +- src/prefs.c | 11 ++++------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index a7372096..fd18f3b6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-07-29 Nick Treleaven + + * src/prefs.c, src/editor.h: + Move detect_tab_mode editor pref to indentation pref 'detect_type'. + + 2008-07-28 Nick Treleaven * src/interface.c, src/editor.h, geany.glade: diff --git a/src/editor.h b/src/editor.h index 9009ace9..f1026fe8 100644 --- a/src/editor.h +++ b/src/editor.h @@ -71,6 +71,7 @@ typedef struct GeanyIndentPrefs gint tab_width; /**< Width of a tab, when using GEANY_INDENT_TYPE_BOTH. */ gboolean use_tab_to_indent; /* hidden pref makes pressing Tab key like Ctrl-I */ GeanyAutoIndent auto_indent_mode; + gboolean detect_type; } GeanyIndentPrefs; @@ -106,7 +107,6 @@ typedef struct GeanyEditorPrefs gboolean brace_match_ltgt; /* whether to highlight < and > chars (hidden pref) */ gboolean use_gtk_word_boundaries; /* hidden pref */ gboolean complete_snippets_whilst_editing; /* hidden pref */ - gboolean detect_tab_mode; gint line_break_column; gboolean auto_continue_multiline; } GeanyEditorPrefs; diff --git a/src/prefs.c b/src/prefs.c index f8b0aab3..eb30621b 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -115,6 +115,8 @@ static void toggle_items_foreach(PrefCallbackAction action) {"check_ask_suppress_search_dialogs", &search_prefs.suppress_dialogs}, {"check_search_use_current_word", &search_prefs.use_current_word}, {"check_fif_current_dir", &search_prefs.use_current_file_dir}, + + {"check_detect_indent", &editor_prefs.indentation->detect_type} }; for (i = 0; i < G_N_ELEMENTS(items); i++) @@ -167,7 +169,8 @@ static void spin_items_foreach(PrefCallbackAction action) static void radio_items_foreach(PrefCallbackAction action) { guint i; - /* Only add one widget per radio-group */ + /* Only add one widget per radio-group; the setting is the index of the selected radio item + * in the group. */ PrefEntry items[] = { {"radio_indent_spaces", &editor_prefs.indentation->type}, @@ -531,9 +534,6 @@ void prefs_init_dialog(void) widget = lookup_widget(ui_widgets.prefs_dialog, "check_line_end"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.show_line_endings); - widget = lookup_widget(ui_widgets.prefs_dialog, "check_detect_indent"); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.detect_tab_mode); - widget = lookup_widget(ui_widgets.prefs_dialog, "check_line_wrapping"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.line_wrapping); @@ -956,9 +956,6 @@ on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_data) widget = lookup_widget(ui_widgets.prefs_dialog, "check_newline_strip"); editor_prefs.newline_strip = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - widget = lookup_widget(ui_widgets.prefs_dialog, "check_detect_indent"); - editor_prefs.detect_tab_mode = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); - widget = lookup_widget(ui_widgets.prefs_dialog, "check_auto_multiline"); editor_prefs.auto_continue_multiline = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); From 03154dbb577ab804a37bf3adcbd9194287c038a5 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Tue, 29 Jul 2008 17:46:21 +0000 Subject: [PATCH 11/22] Replace init_prefs(), update_prefs() with common prefs_action() function. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2834 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 3 +++ src/prefs.c | 33 ++++++++++++--------------------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/ChangeLog b/ChangeLog index fd18f3b6..e7fbf82d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,9 @@ * src/prefs.c, src/editor.h: Move detect_tab_mode editor pref to indentation pref 'detect_type'. + * src/prefs.c: + Replace init_prefs(), update_prefs() with common prefs_action() + function. 2008-07-28 Nick Treleaven diff --git a/src/prefs.c b/src/prefs.c index eb30621b..a7552b70 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -224,7 +224,7 @@ static void combo_items_foreach(PrefCallbackAction action) typedef void (*PrefItemsCallback)(PrefCallbackAction action); -/* List of functions which hold the PrefEntry arrays. This allows access to +/* List of functions which hold the PrefEntry arrays. These allow access to * runtime setting fields like EditorPrefs::indentation->width. */ PrefItemsCallback pref_item_callbacks[] = { toggle_items_foreach, @@ -234,6 +234,15 @@ PrefItemsCallback pref_item_callbacks[] = { }; +static void prefs_action(PrefCallbackAction action) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS(pref_item_callbacks); i++) + pref_item_callbacks[i](action); +} + + enum { KB_TREE_ACTION, @@ -306,21 +315,12 @@ static void init_keybindings(void) } -static void init_prefs(void) -{ - guint i; - - for (i = 0; i < G_N_ELEMENTS(pref_item_callbacks); i++) - pref_item_callbacks[i](PREF_DISPLAY); -} - - void prefs_init_dialog(void) { GtkWidget *widget; GdkColor *color; - init_prefs(); + prefs_action(PREF_DISPLAY); /* General settings */ /* startup */ @@ -721,15 +721,6 @@ void prefs_init_dialog(void) } -static void update_prefs(void) -{ - guint i; - - for (i = 0; i < G_N_ELEMENTS(pref_item_callbacks); i++) - pref_item_callbacks[i](PREF_UPDATE); -} - - /* * callbacks */ @@ -741,7 +732,7 @@ on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_data) GtkWidget *widget; guint i; - update_prefs(); + prefs_action(PREF_UPDATE); /* General settings */ /* startup */ From 7a0e8a687d7643c31c06cd8a262f30b3ef855dd7 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Tue, 29 Jul 2008 17:49:29 +0000 Subject: [PATCH 12/22] Update to use foreach-style functions for SettingEntry arrays, like the PrefEntry code in prefs.c. Update for new indentation setting names. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2835 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 4 ++ src/keyfile.c | 137 ++++++++++++++++++++++++++++++++++---------------- 2 files changed, 97 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index e7fbf82d..e8c8b3be 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,10 @@ * src/prefs.c: Replace init_prefs(), update_prefs() with common prefs_action() function. + * src/keyfile.c: + Update to use foreach-style functions for SettingEntry arrays, like + the PrefEntry code in prefs.c. + Update for new indentation setting names. 2008-07-28 Nick Treleaven diff --git a/src/keyfile.c b/src/keyfile.c index fd322b14..83553bab 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -89,27 +89,107 @@ static gint hpan_position; static gint vpan_position; -/* Used in e.g. save_bool_prefs(). */ +typedef enum SettingCallbackAction +{ + SETTING_READ, + SETTING_WRITE +} +SettingCallbackAction; + + typedef struct SettingEntry { + gpointer setting; const gchar *group; const gchar *key_name; - gpointer setting; gpointer default_value; } SettingEntry; -static SettingEntry bool_prefs[] = -{ - {PACKAGE, "cmdline_new_files", &file_prefs.cmdline_new_files, GINT_TO_POINTER(TRUE)}, - {PACKAGE, "pref_main_suppress_search_dialogs", &search_prefs.suppress_dialogs, GINT_TO_POINTER(FALSE)}, - {PACKAGE, "pref_main_search_use_current_word", &search_prefs.use_current_word, GINT_TO_POINTER(TRUE)}, - {"search", "pref_search_current_file_dir", &search_prefs.use_current_file_dir, GINT_TO_POINTER(TRUE)}, - {NULL, NULL, NULL, NULL} /* must be terminated */ +static void bool_settings_foreach(GKeyFile *config, SettingCallbackAction action) +{ + guint i; + SettingEntry items[] = + { + {&file_prefs.cmdline_new_files, PACKAGE, "cmdline_new_files", (gpointer)TRUE}, + + {&search_prefs.suppress_dialogs, PACKAGE, "pref_main_suppress_search_dialogs", (gpointer)FALSE}, + {&search_prefs.use_current_word, PACKAGE, "pref_main_search_use_current_word", (gpointer)TRUE}, + {&search_prefs.use_current_file_dir, "search", "pref_search_current_file_dir", (gpointer)TRUE}, + + {&editor_prefs.indentation->detect_type, PACKAGE, "check_detect_indent", (gpointer)FALSE}, + }; + + for (i = 0; i < G_N_ELEMENTS(items); i++) + { + SettingEntry *se = &items[i]; + gboolean *setting = se->setting; + + switch (action) + { + case SETTING_READ: + *setting = utils_get_setting_boolean(config, se->group, se->key_name, + GPOINTER_TO_INT(se->default_value)); + break; + case SETTING_WRITE: + g_key_file_set_boolean(config, se->group, se->key_name, *setting); + break; + } + } +} + + +static void int_settings_foreach(GKeyFile *config, SettingCallbackAction action) +{ + guint i; + SettingEntry items[] = + { + {&editor_prefs.indentation->width, PACKAGE, "pref_editor_tab_width", (gpointer)4}, + {&editor_prefs.indentation->tab_width, PACKAGE, "indent_tab_width", (gpointer)8}, + {&editor_prefs.indentation->auto_indent_mode, PACKAGE, "indent_mode", + (gpointer)GEANY_AUTOINDENT_CURRENTCHARS}, + {&editor_prefs.indentation->type, PACKAGE, "indent_type", (gpointer)GEANY_INDENT_TYPE_TABS}, + }; + + for (i = 0; i < G_N_ELEMENTS(items); i++) + { + SettingEntry *se = &items[i]; + gboolean *setting = se->setting; + + switch (action) + { + case SETTING_READ: + *setting = utils_get_setting_integer(config, se->group, se->key_name, + GPOINTER_TO_INT(se->default_value)); + break; + case SETTING_WRITE: + g_key_file_set_integer(config, se->group, se->key_name, *setting); + break; + } + } +} + + +typedef void (*SettingItemsCallback)(GKeyFile *config, SettingCallbackAction action); + +/* List of functions which hold the SettingEntry arrays. These allow access to + * runtime setting fields like EditorPrefs::indentation->width. */ +SettingItemsCallback setting_item_callbacks[] = { + bool_settings_foreach, + int_settings_foreach }; +static void settings_action(GKeyFile *config, SettingCallbackAction action) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS(setting_item_callbacks); i++) + setting_item_callbacks[i](config, action); +} + + static void save_recent_files(GKeyFile *config) { gchar **recent_files = g_new0(gchar*, file_prefs.mru_length + 1); @@ -205,20 +285,9 @@ void configuration_save_session_files(GKeyFile *config) } -static void save_bool_prefs(GKeyFile *config) -{ - SettingEntry *pe; - - for (pe = bool_prefs; pe->group != NULL; pe++) - { - g_key_file_set_boolean(config, pe->group, pe->key_name, *(gboolean*)pe->setting); - } -} - - static void save_dialog_prefs(GKeyFile *config) { - save_bool_prefs(config); + settings_action(config, SETTING_WRITE); /* Some of the key names are not consistent, but this is for backwards compatibility */ @@ -262,15 +331,11 @@ static void save_dialog_prefs(GKeyFile *config) g_key_file_set_integer(config, PACKAGE, "symbolcompletion_min_chars", editor_prefs.symbolcompletion_min_chars); g_key_file_set_boolean(config, PACKAGE, "use_folding", editor_prefs.folding); g_key_file_set_boolean(config, PACKAGE, "unfold_all_children", editor_prefs.unfold_all_children); - g_key_file_set_integer(config, PACKAGE, "indent_mode", editor_prefs.indent_mode); - g_key_file_set_integer(config, PACKAGE, "check_detect_indent", editor_prefs.detect_tab_mode); g_key_file_set_boolean(config, PACKAGE, "use_indicators", editor_prefs.use_indicators); g_key_file_set_boolean(config, PACKAGE, "line_wrapping", editor_prefs.line_wrapping); g_key_file_set_boolean(config, PACKAGE, "auto_close_xml_tags", editor_prefs.auto_close_xml_tags); g_key_file_set_boolean(config, PACKAGE, "complete_snippets", editor_prefs.complete_snippets); g_key_file_set_boolean(config, PACKAGE, "auto_complete_symbols", editor_prefs.auto_complete_symbols); - g_key_file_set_integer(config, PACKAGE, "pref_editor_tab_width", editor_prefs.tab_width); - g_key_file_set_boolean(config, PACKAGE, "pref_editor_use_tabs", editor_prefs.use_tabs); g_key_file_set_boolean(config, PACKAGE, "pref_editor_disable_dnd", editor_prefs.disable_dnd); g_key_file_set_boolean(config, PACKAGE, "pref_editor_smart_home_key", editor_prefs.smart_home_key); g_key_file_set_boolean(config, PACKAGE, "pref_editor_newline_strip", editor_prefs.newline_strip); @@ -422,7 +487,7 @@ static void save_ui_prefs(GKeyFile *config) static void save_hidden_prefs(GKeyFile *config) { write_hidden_pref_boolean(config, PACKAGE, "show_editor_scrollbars", editor_prefs.show_scrollbars); - write_hidden_pref_boolean(config, PACKAGE, "use_tab_to_indent", editor_prefs.use_tab_to_indent); + write_hidden_pref_boolean(config, PACKAGE, "use_tab_to_indent", editor_prefs.indentation->use_tab_to_indent); write_hidden_pref_boolean(config, PACKAGE, "brace_match_ltgt", editor_prefs.brace_match_ltgt); write_hidden_pref_boolean(config, PACKAGE, "use_gtk_word_boundaries", editor_prefs.use_gtk_word_boundaries); write_hidden_pref_boolean(config, PACKAGE, "complete_snippets_whilst_editing", editor_prefs.complete_snippets_whilst_editing); @@ -511,18 +576,6 @@ void configuration_load_session_files(GKeyFile *config) } -static void load_bool_prefs(GKeyFile *config) -{ - SettingEntry *pe; - - for (pe = bool_prefs; pe->group != NULL; pe++) - { - *(gboolean*)pe->setting = utils_get_setting_boolean(config, pe->group, pe->key_name, - GPOINTER_TO_INT(pe->default_value)); - } -} - - #define GEANY_GET_SETTING(propertyname, value, default_value) \ if (g_object_class_find_property( \ G_OBJECT_GET_CLASS(G_OBJECT(gtk_settings_get_default())), propertyname)) \ @@ -536,7 +589,7 @@ static void load_dialog_prefs(GKeyFile *config) gchar *tmp_string, *tmp_string2; const gchar *default_charset = NULL; - load_bool_prefs(config); + settings_action(config, SETTING_READ); /* general */ prefs.confirm_exit = utils_get_setting_boolean(config, PACKAGE, "pref_main_confirm_exit", FALSE); @@ -574,9 +627,7 @@ static void load_dialog_prefs(GKeyFile *config) editor_prefs.symbolcompletion_min_chars = utils_get_setting_integer(config, PACKAGE, "symbolcompletion_min_chars", GEANY_MIN_SYMBOLLIST_CHARS); editor_prefs.symbolcompletion_max_height = utils_get_setting_integer(config, PACKAGE, "symbolcompletion_max_height", GEANY_MAX_SYMBOLLIST_HEIGHT); editor_prefs.line_wrapping = utils_get_setting_boolean(config, PACKAGE, "line_wrapping", FALSE); /* default is off for better performance */ - editor_prefs.indent_mode = utils_get_setting_integer(config, PACKAGE, "indent_mode", INDENT_CURRENTCHARS); - editor_prefs.detect_tab_mode = utils_get_setting_integer(config, PACKAGE, "check_detect_indent", FALSE); - editor_prefs.use_tab_to_indent = utils_get_setting_boolean(config, PACKAGE, "use_tab_to_indent", FALSE); + editor_prefs.indentation->use_tab_to_indent = utils_get_setting_boolean(config, PACKAGE, "use_tab_to_indent", FALSE); editor_prefs.use_indicators = utils_get_setting_boolean(config, PACKAGE, "use_indicators", TRUE); editor_prefs.show_indent_guide = utils_get_setting_boolean(config, PACKAGE, "show_indent_guide", FALSE); editor_prefs.show_white_space = utils_get_setting_boolean(config, PACKAGE, "show_white_space", FALSE); @@ -590,8 +641,6 @@ static void load_dialog_prefs(GKeyFile *config) editor_prefs.show_markers_margin = utils_get_setting_boolean(config, PACKAGE, "show_markers_margin", TRUE); editor_prefs.show_linenumber_margin = utils_get_setting_boolean(config, PACKAGE, "show_linenumber_margin", TRUE); editor_prefs.brace_match_ltgt = utils_get_setting_boolean(config, PACKAGE, "brace_match_ltgt", FALSE); - editor_prefs.tab_width = utils_get_setting_integer(config, PACKAGE, "pref_editor_tab_width", 4); - editor_prefs.use_tabs = utils_get_setting_boolean(config, PACKAGE, "pref_editor_use_tabs", TRUE); editor_prefs.disable_dnd = utils_get_setting_boolean(config, PACKAGE, "pref_editor_disable_dnd", FALSE); editor_prefs.smart_home_key = utils_get_setting_boolean(config, PACKAGE, "pref_editor_smart_home_key", TRUE); editor_prefs.newline_strip = utils_get_setting_boolean(config, PACKAGE, "pref_editor_newline_strip", FALSE); From 287e8353304d47581156dd1ac2f54e20351fe966 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Tue, 29 Jul 2008 17:54:52 +0000 Subject: [PATCH 13/22] Rename *_items_foreach() *_prefs_foreach(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2836 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- src/prefs.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/prefs.c b/src/prefs.c index a7552b70..dc6544ab 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -105,7 +105,7 @@ typedef struct PrefEntry PrefEntry; -static void toggle_items_foreach(PrefCallbackAction action) +static void toggle_prefs_foreach(PrefCallbackAction action) { guint i; PrefEntry items[] = @@ -138,7 +138,7 @@ static void toggle_items_foreach(PrefCallbackAction action) } -static void spin_items_foreach(PrefCallbackAction action) +static void spin_prefs_foreach(PrefCallbackAction action) { guint i; PrefEntry items[] = @@ -166,7 +166,7 @@ static void spin_items_foreach(PrefCallbackAction action) } -static void radio_items_foreach(PrefCallbackAction action) +static void radio_prefs_foreach(PrefCallbackAction action) { guint i; /* Only add one widget per radio-group; the setting is the index of the selected radio item @@ -195,7 +195,7 @@ static void radio_items_foreach(PrefCallbackAction action) } -static void combo_items_foreach(PrefCallbackAction action) +static void combo_prefs_foreach(PrefCallbackAction action) { guint i; PrefEntry items[] = @@ -227,10 +227,10 @@ typedef void (*PrefItemsCallback)(PrefCallbackAction action); /* List of functions which hold the PrefEntry arrays. These allow access to * runtime setting fields like EditorPrefs::indentation->width. */ PrefItemsCallback pref_item_callbacks[] = { - toggle_items_foreach, - spin_items_foreach, - radio_items_foreach, - combo_items_foreach + toggle_prefs_foreach, + spin_prefs_foreach, + radio_prefs_foreach, + combo_prefs_foreach }; From 4b8035844d3e8b651b598fb69a4af3999e68bf70 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 30 Jul 2008 15:26:49 +0000 Subject: [PATCH 14/22] Move use_tab_to_indent pref back to editor_prefs (should be unique). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2838 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 6 ++++++ src/editor.h | 8 +++++--- src/keyfile.c | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index e8c8b3be..73a2c2de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-07-30 Nick Treleaven + + * src/keyfile.c, src/editor.h: + Move use_tab_to_indent pref back to editor_prefs (should be unique). + + 2008-07-29 Nick Treleaven * src/prefs.c, src/editor.h: diff --git a/src/editor.h b/src/editor.h index f1026fe8..75372f9b 100644 --- a/src/editor.h +++ b/src/editor.h @@ -64,23 +64,24 @@ typedef enum GeanyAutoIndent; +/** Indentation prefs that might be different according to project or filetype. + * Use @c editor_get_indent_prefs() to lookup the prefs for a particular document. */ typedef struct GeanyIndentPrefs { gint width; /**< Indent width. */ GeanyIndentType type; /**< Whether to use tabs, spaces or both to indent. */ gint tab_width; /**< Width of a tab, when using GEANY_INDENT_TYPE_BOTH. */ - gboolean use_tab_to_indent; /* hidden pref makes pressing Tab key like Ctrl-I */ GeanyAutoIndent auto_indent_mode; gboolean detect_type; } GeanyIndentPrefs; -/** Default prefs when creating a new editor window. +/* Default prefs when creating a new editor window. * Some of these can be overridden per document. */ typedef struct GeanyEditorPrefs { - GeanyIndentPrefs *indentation; /**< Indentation prefs. */ + GeanyIndentPrefs *indentation; /*< Default indentation prefs. @see editor_get_indent_prefs(). */ gboolean show_white_space; gboolean show_indent_guide; gboolean show_line_endings; @@ -96,6 +97,7 @@ typedef struct GeanyEditorPrefs gboolean folding; gboolean unfold_all_children; gboolean disable_dnd; + gboolean use_tab_to_indent; /* hidden pref makes pressing Tab key like Ctrl-I */ gboolean smart_home_key; gboolean newline_strip; gboolean auto_complete_symbols; diff --git a/src/keyfile.c b/src/keyfile.c index 83553bab..fc0db9e8 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -487,7 +487,7 @@ static void save_ui_prefs(GKeyFile *config) static void save_hidden_prefs(GKeyFile *config) { write_hidden_pref_boolean(config, PACKAGE, "show_editor_scrollbars", editor_prefs.show_scrollbars); - write_hidden_pref_boolean(config, PACKAGE, "use_tab_to_indent", editor_prefs.indentation->use_tab_to_indent); + write_hidden_pref_boolean(config, PACKAGE, "use_tab_to_indent", editor_prefs.use_tab_to_indent); write_hidden_pref_boolean(config, PACKAGE, "brace_match_ltgt", editor_prefs.brace_match_ltgt); write_hidden_pref_boolean(config, PACKAGE, "use_gtk_word_boundaries", editor_prefs.use_gtk_word_boundaries); write_hidden_pref_boolean(config, PACKAGE, "complete_snippets_whilst_editing", editor_prefs.complete_snippets_whilst_editing); @@ -627,7 +627,7 @@ static void load_dialog_prefs(GKeyFile *config) editor_prefs.symbolcompletion_min_chars = utils_get_setting_integer(config, PACKAGE, "symbolcompletion_min_chars", GEANY_MIN_SYMBOLLIST_CHARS); editor_prefs.symbolcompletion_max_height = utils_get_setting_integer(config, PACKAGE, "symbolcompletion_max_height", GEANY_MAX_SYMBOLLIST_HEIGHT); editor_prefs.line_wrapping = utils_get_setting_boolean(config, PACKAGE, "line_wrapping", FALSE); /* default is off for better performance */ - editor_prefs.indentation->use_tab_to_indent = utils_get_setting_boolean(config, PACKAGE, "use_tab_to_indent", FALSE); + editor_prefs.use_tab_to_indent = utils_get_setting_boolean(config, PACKAGE, "use_tab_to_indent", FALSE); editor_prefs.use_indicators = utils_get_setting_boolean(config, PACKAGE, "use_indicators", TRUE); editor_prefs.show_indent_guide = utils_get_setting_boolean(config, PACKAGE, "show_indent_guide", FALSE); editor_prefs.show_white_space = utils_get_setting_boolean(config, PACKAGE, "show_white_space", FALSE); From 1d55dae69f561102d64079c2e8863666c6c222ae Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Thu, 31 Jul 2008 14:47:03 +0000 Subject: [PATCH 15/22] Add 'Tabs and Spaces' Document menu indent option. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2844 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 6 ++ geany.glade | 53 +++++++----- src/editor.h | 6 +- src/interface.c | 212 +++++++++++++++++++++++++----------------------- 4 files changed, 153 insertions(+), 124 deletions(-) diff --git a/ChangeLog b/ChangeLog index 73a2c2de..0027b8c5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-07-31 Nick Treleaven + + * src/interface.c, src/editor.h, geany.glade: + Add 'Tabs and Spaces' Document menu indent option. + + 2008-07-30 Nick Treleaven * src/keyfile.c, src/editor.h: diff --git a/geany.glade b/geany.glade index cc402cbb..ccefa21d 100644 --- a/geany.glade +++ b/geany.glade @@ -58,7 +58,7 @@ True - + True gtk-new 1 @@ -148,7 +148,7 @@ - + True gtk-save 1 @@ -169,7 +169,7 @@ - + True gtk-revert-to-saved 1 @@ -189,7 +189,7 @@ True - + True gtk-revert-to-saved 1 @@ -277,7 +277,7 @@ - + True gtk-close 1 @@ -299,7 +299,7 @@ - + True gtk-close 1 @@ -498,7 +498,7 @@ - + True gtk-indent 1 @@ -519,7 +519,7 @@ - + True gtk-unindent 1 @@ -575,7 +575,7 @@ True - + True gtk-add 1 @@ -660,7 +660,7 @@ True - + True gtk-add 1 @@ -692,7 +692,7 @@ True - + True gtk-add 1 @@ -790,7 +790,7 @@ - + True gtk-find-and-replace 1 @@ -865,7 +865,7 @@ - + True gtk-jump-to 1 @@ -900,7 +900,7 @@ - + True gtk-select-font 1 @@ -1098,6 +1098,17 @@ + + + + True + T_abs and Spaces + True + False + tabs1 + + + @@ -1329,7 +1340,7 @@ - + True gtk-new 1 @@ -1350,7 +1361,7 @@ - + True gtk-open 1 @@ -1371,7 +1382,7 @@ - + True gtk-close 1 @@ -1430,7 +1441,7 @@ - + True gtk-select-color 1 @@ -1472,7 +1483,7 @@ - + True gtk-refresh 1 @@ -1506,7 +1517,7 @@ - + True gtk-help 1 @@ -5538,7 +5549,7 @@ Match braces True Use spaces if the total indent is less than the tab width, otherwise use both True - T_abs & Spaces + T_abs and Spaces True GTK_RELIEF_NORMAL True diff --git a/src/editor.h b/src/editor.h index 75372f9b..809ca111 100644 --- a/src/editor.h +++ b/src/editor.h @@ -125,7 +125,7 @@ typedef struct GeanyEditor gboolean auto_indent; /**< @c TRUE if auto-indentation is enabled. */ /** Percentage to scroll view by on paint, if positive. */ gfloat scroll_percent; - gboolean use_tabs; /**< @c TRUE if tabs are used for indentation. */ + GeanyIndentType indent_type; /* Use editor_get_indent_prefs() instead. */ gboolean line_breaking; /**< Whether to split long lines as you type. */ } GeanyEditor; @@ -235,7 +235,9 @@ void editor_ensure_final_newline(GeanyDocument *doc); void editor_insert_color(GeanyDocument *doc, const gchar *colour); -void editor_set_use_tabs(GeanyEditor *editor, gboolean use_tabs); +const GeanyIndentPrefs *editor_get_indent_prefs(GeanyEditor *editor); + +void editor_set_indent_type(GeanyEditor *editor, GeanyIndentType type); void editor_set_line_wrapping(GeanyEditor *editor, gboolean wrap); diff --git a/src/interface.c b/src/interface.c index 46d891ef..5a246038 100644 --- a/src/interface.c +++ b/src/interface.c @@ -37,7 +37,7 @@ create_window1 (void) GtkWidget *file1_menu; GtkWidget *menu_new1; GtkWidget *menu_new_with_template1; - GtkWidget *image2548; + GtkWidget *image2576; GtkWidget *menu_new_with_template1_menu; GtkWidget *invisible2; GtkWidget *separator12; @@ -48,11 +48,11 @@ create_window1 (void) GtkWidget *menu_save1; GtkWidget *menu_save_as1; GtkWidget *menu_save_all1; - GtkWidget *image2549; + GtkWidget *image2577; GtkWidget *menu_reload1; - GtkWidget *image2550; + GtkWidget *image2578; GtkWidget *menu_reload_as1; - GtkWidget *image2551; + GtkWidget *image2579; GtkWidget *menu_reload_as1_menu; GtkWidget *invisible7; GtkWidget *separator21; @@ -63,9 +63,9 @@ create_window1 (void) GtkWidget *separator14; GtkWidget *menu_close1; GtkWidget *close_other_documents1; - GtkWidget *image2552; + GtkWidget *image2580; GtkWidget *menu_close_all1; - GtkWidget *image2553; + GtkWidget *image2581; GtkWidget *menu_separatormenuitem1; GtkWidget *menu_quit1; GtkWidget *edit1; @@ -90,16 +90,16 @@ create_window1 (void) GtkWidget *menu_duplicate_line1; GtkWidget *separator29; GtkWidget *menu_increase_indent1; - GtkWidget *image2554; + GtkWidget *image2582; GtkWidget *menu_decrease_indent1; - GtkWidget *image2555; + GtkWidget *image2583; GtkWidget *separator37; GtkWidget *send_selection_to2; GtkWidget *send_selection_to2_menu; GtkWidget *invisible13; GtkWidget *separator18; GtkWidget *add_comments1; - GtkWidget *image2556; + GtkWidget *image2584; GtkWidget *add_comments1_menu; GtkWidget *menu_add_changelog_entry1; GtkWidget *insert_file_header1; @@ -108,11 +108,11 @@ create_window1 (void) GtkWidget *insert_gpl_notice2; GtkWidget *insert_bsd_license_notice2; GtkWidget *insert_date1; - GtkWidget *image2557; + GtkWidget *image2585; GtkWidget *insert_date1_menu; GtkWidget *invisible8; GtkWidget *insert_include2; - GtkWidget *image2558; + GtkWidget *image2586; GtkWidget *insert_include2_menu; GtkWidget *invisible4; GtkWidget *separator9; @@ -124,7 +124,7 @@ create_window1 (void) GtkWidget *find_previous1; GtkWidget *find_in_files1; GtkWidget *replace1; - GtkWidget *image2559; + GtkWidget *image2587; GtkWidget *separator33; GtkWidget *find_nextsel1; GtkWidget *find_prevsel1; @@ -133,11 +133,11 @@ create_window1 (void) GtkWidget *previous_message1; GtkWidget *separator32; GtkWidget *go_to_line1; - GtkWidget *image2560; + GtkWidget *image2588; GtkWidget *menu_view1; GtkWidget *menu_view1_menu; GtkWidget *menu_change_font1; - GtkWidget *image2561; + GtkWidget *image2589; GtkWidget *menu_separator4; GtkWidget *menu_toggle_all_additional_widgets1; GtkWidget *menu_fullscreen1; @@ -160,6 +160,7 @@ create_window1 (void) GSList *tabs1_group = NULL; GtkWidget *tabs1; GtkWidget *spaces1; + GtkWidget *tabs_and_spaces1; GtkWidget *separator45; GtkWidget *set_file_readonly1; GtkWidget *menu_write_unicode_bom1; @@ -189,26 +190,26 @@ create_window1 (void) GtkWidget *menu_project1; GtkWidget *menu_project1_menu; GtkWidget *project_new1; - GtkWidget *image2562; + GtkWidget *image2590; GtkWidget *project_open1; - GtkWidget *image2563; + GtkWidget *image2591; GtkWidget *project_close1; - GtkWidget *image2564; + GtkWidget *image2592; GtkWidget *separator34; GtkWidget *project_properties1; GtkWidget *menu_build1; GtkWidget *tools1; GtkWidget *tools1_menu; GtkWidget *menu_choose_color1; - GtkWidget *image2565; + GtkWidget *image2593; GtkWidget *menu_count_words1; GtkWidget *load_tags1; GtkWidget *menu_reload_configuration1; - GtkWidget *image2566; + GtkWidget *image2594; GtkWidget *menu_help1; GtkWidget *menu_help1_menu; GtkWidget *help1; - GtkWidget *image2567; + GtkWidget *image2595; GtkWidget *keyboard_shortcuts1; GtkWidget *website1; GtkWidget *separator16; @@ -311,9 +312,9 @@ create_window1 (void) gtk_widget_show (menu_new_with_template1); gtk_container_add (GTK_CONTAINER (file1_menu), menu_new_with_template1); - image2548 = gtk_image_new_from_stock ("gtk-new", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2548); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_new_with_template1), image2548); + image2576 = gtk_image_new_from_stock ("gtk-new", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2576); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_new_with_template1), image2576); menu_new_with_template1_menu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_new_with_template1), menu_new_with_template1_menu); @@ -356,25 +357,25 @@ create_window1 (void) gtk_container_add (GTK_CONTAINER (file1_menu), menu_save_all1); gtk_tooltips_set_tip (tooltips, menu_save_all1, _("Saves all open files"), NULL); - image2549 = gtk_image_new_from_stock ("gtk-save", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2549); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_save_all1), image2549); + image2577 = gtk_image_new_from_stock ("gtk-save", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2577); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_save_all1), image2577); menu_reload1 = gtk_image_menu_item_new_with_mnemonic (_("_Reload")); gtk_widget_show (menu_reload1); gtk_container_add (GTK_CONTAINER (file1_menu), menu_reload1); - image2550 = gtk_image_new_from_stock ("gtk-revert-to-saved", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2550); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_reload1), image2550); + image2578 = gtk_image_new_from_stock ("gtk-revert-to-saved", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2578); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_reload1), image2578); menu_reload_as1 = gtk_image_menu_item_new_with_mnemonic (_("R_eload As")); gtk_widget_show (menu_reload_as1); gtk_container_add (GTK_CONTAINER (file1_menu), menu_reload_as1); - image2551 = gtk_image_new_from_stock ("gtk-revert-to-saved", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2551); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_reload_as1), image2551); + image2579 = gtk_image_new_from_stock ("gtk-revert-to-saved", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2579); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_reload_as1), image2579); menu_reload_as1_menu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_reload_as1), menu_reload_as1_menu); @@ -418,18 +419,18 @@ create_window1 (void) gtk_widget_show (close_other_documents1); gtk_container_add (GTK_CONTAINER (file1_menu), close_other_documents1); - image2552 = gtk_image_new_from_stock ("gtk-close", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2552); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (close_other_documents1), image2552); + image2580 = gtk_image_new_from_stock ("gtk-close", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2580); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (close_other_documents1), image2580); menu_close_all1 = gtk_image_menu_item_new_with_mnemonic (_("C_lose All")); gtk_widget_show (menu_close_all1); gtk_container_add (GTK_CONTAINER (file1_menu), menu_close_all1); gtk_tooltips_set_tip (tooltips, menu_close_all1, _("Closes all open files"), NULL); - image2553 = gtk_image_new_from_stock ("gtk-close", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2553); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_close_all1), image2553); + image2581 = gtk_image_new_from_stock ("gtk-close", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2581); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_close_all1), image2581); menu_separatormenuitem1 = gtk_separator_menu_item_new (); gtk_widget_show (menu_separatormenuitem1); @@ -533,17 +534,17 @@ create_window1 (void) gtk_widget_show (menu_increase_indent1); gtk_container_add (GTK_CONTAINER (menu_format1_menu), menu_increase_indent1); - image2554 = gtk_image_new_from_stock ("gtk-indent", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2554); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_increase_indent1), image2554); + image2582 = gtk_image_new_from_stock ("gtk-indent", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2582); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_increase_indent1), image2582); menu_decrease_indent1 = gtk_image_menu_item_new_with_mnemonic (_("_Decrease Indent")); gtk_widget_show (menu_decrease_indent1); gtk_container_add (GTK_CONTAINER (menu_format1_menu), menu_decrease_indent1); - image2555 = gtk_image_new_from_stock ("gtk-unindent", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2555); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_decrease_indent1), image2555); + image2583 = gtk_image_new_from_stock ("gtk-unindent", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2583); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_decrease_indent1), image2583); separator37 = gtk_separator_menu_item_new (); gtk_widget_show (separator37); @@ -569,9 +570,9 @@ create_window1 (void) gtk_widget_show (add_comments1); gtk_container_add (GTK_CONTAINER (edit1_menu), add_comments1); - image2556 = gtk_image_new_from_stock ("gtk-add", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2556); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (add_comments1), image2556); + image2584 = gtk_image_new_from_stock ("gtk-add", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2584); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (add_comments1), image2584); add_comments1_menu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (add_comments1), add_comments1_menu); @@ -610,9 +611,9 @@ create_window1 (void) gtk_widget_show (insert_date1); gtk_container_add (GTK_CONTAINER (edit1_menu), insert_date1); - image2557 = gtk_image_new_from_stock ("gtk-add", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2557); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (insert_date1), image2557); + image2585 = gtk_image_new_from_stock ("gtk-add", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2585); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (insert_date1), image2585); insert_date1_menu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (insert_date1), insert_date1_menu); @@ -624,9 +625,9 @@ create_window1 (void) gtk_widget_show (insert_include2); gtk_container_add (GTK_CONTAINER (edit1_menu), insert_include2); - image2558 = gtk_image_new_from_stock ("gtk-add", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2558); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (insert_include2), image2558); + image2586 = gtk_image_new_from_stock ("gtk-add", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2586); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (insert_include2), image2586); insert_include2_menu = gtk_menu_new (); gtk_menu_item_set_submenu (GTK_MENU_ITEM (insert_include2), insert_include2_menu); @@ -670,9 +671,9 @@ create_window1 (void) gtk_widget_show (replace1); gtk_container_add (GTK_CONTAINER (search1_menu), replace1); - image2559 = gtk_image_new_from_stock ("gtk-find-and-replace", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2559); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (replace1), image2559); + image2587 = gtk_image_new_from_stock ("gtk-find-and-replace", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2587); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (replace1), image2587); separator33 = gtk_separator_menu_item_new (); gtk_widget_show (separator33); @@ -709,9 +710,9 @@ create_window1 (void) gtk_widget_show (go_to_line1); gtk_container_add (GTK_CONTAINER (search1_menu), go_to_line1); - image2560 = gtk_image_new_from_stock ("gtk-jump-to", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2560); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (go_to_line1), image2560); + image2588 = gtk_image_new_from_stock ("gtk-jump-to", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2588); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (go_to_line1), image2588); menu_view1 = gtk_menu_item_new_with_mnemonic (_("_View")); gtk_widget_show (menu_view1); @@ -725,9 +726,9 @@ create_window1 (void) gtk_container_add (GTK_CONTAINER (menu_view1_menu), menu_change_font1); gtk_tooltips_set_tip (tooltips, menu_change_font1, _("Change the default font"), NULL); - image2561 = gtk_image_new_from_stock ("gtk-select-font", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2561); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_change_font1), image2561); + image2589 = gtk_image_new_from_stock ("gtk-select-font", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2589); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_change_font1), image2589); menu_separator4 = gtk_separator_menu_item_new (); gtk_widget_show (menu_separator4); @@ -829,6 +830,11 @@ create_window1 (void) gtk_container_add (GTK_CONTAINER (indent_type1_menu), spaces1); gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (spaces1), TRUE); + tabs_and_spaces1 = gtk_radio_menu_item_new_with_mnemonic (tabs1_group, _("T_abs and Spaces")); + tabs1_group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (tabs_and_spaces1)); + gtk_widget_show (tabs_and_spaces1); + gtk_container_add (GTK_CONTAINER (indent_type1_menu), tabs_and_spaces1); + separator45 = gtk_separator_menu_item_new (); gtk_widget_show (separator45); gtk_container_add (GTK_CONTAINER (menu_document1_menu), separator45); @@ -952,25 +958,25 @@ create_window1 (void) gtk_widget_show (project_new1); gtk_container_add (GTK_CONTAINER (menu_project1_menu), project_new1); - image2562 = gtk_image_new_from_stock ("gtk-new", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2562); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (project_new1), image2562); + image2590 = gtk_image_new_from_stock ("gtk-new", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2590); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (project_new1), image2590); project_open1 = gtk_image_menu_item_new_with_mnemonic (_("_Open")); gtk_widget_show (project_open1); gtk_container_add (GTK_CONTAINER (menu_project1_menu), project_open1); - image2563 = gtk_image_new_from_stock ("gtk-open", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2563); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (project_open1), image2563); + image2591 = gtk_image_new_from_stock ("gtk-open", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2591); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (project_open1), image2591); project_close1 = gtk_image_menu_item_new_with_mnemonic (_("_Close")); gtk_widget_show (project_close1); gtk_container_add (GTK_CONTAINER (menu_project1_menu), project_close1); - image2564 = gtk_image_new_from_stock ("gtk-close", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2564); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (project_close1), image2564); + image2592 = gtk_image_new_from_stock ("gtk-close", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2592); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (project_close1), image2592); separator34 = gtk_separator_menu_item_new (); gtk_widget_show (separator34); @@ -997,9 +1003,9 @@ create_window1 (void) gtk_container_add (GTK_CONTAINER (tools1_menu), menu_choose_color1); gtk_tooltips_set_tip (tooltips, menu_choose_color1, _("Open a color chooser dialog, to interactively pick colors from a palette."), NULL); - image2565 = gtk_image_new_from_stock ("gtk-select-color", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2565); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_choose_color1), image2565); + image2593 = gtk_image_new_from_stock ("gtk-select-color", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2593); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_choose_color1), image2593); menu_count_words1 = gtk_menu_item_new_with_mnemonic (_("_Word Count")); gtk_widget_show (menu_count_words1); @@ -1016,9 +1022,9 @@ create_window1 (void) gtk_container_add (GTK_CONTAINER (tools1_menu), menu_reload_configuration1); gtk_tooltips_set_tip (tooltips, menu_reload_configuration1, _("Reload configuration data like snippets, templates and filetype extensions."), NULL); - image2566 = gtk_image_new_from_stock ("gtk-refresh", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2566); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_reload_configuration1), image2566); + image2594 = gtk_image_new_from_stock ("gtk-refresh", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2594); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_reload_configuration1), image2594); menu_help1 = gtk_menu_item_new_with_mnemonic (_("_Help")); gtk_widget_show (menu_help1); @@ -1031,9 +1037,9 @@ create_window1 (void) gtk_widget_show (help1); gtk_container_add (GTK_CONTAINER (menu_help1_menu), help1); - image2567 = gtk_image_new_from_stock ("gtk-help", GTK_ICON_SIZE_MENU); - gtk_widget_show (image2567); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (help1), image2567); + image2595 = gtk_image_new_from_stock ("gtk-help", GTK_ICON_SIZE_MENU); + gtk_widget_show (image2595); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (help1), image2595); keyboard_shortcuts1 = gtk_menu_item_new_with_mnemonic (_("_Keyboard Shortcuts")); gtk_widget_show (keyboard_shortcuts1); @@ -1556,6 +1562,9 @@ create_window1 (void) g_signal_connect ((gpointer) spaces1, "activate", G_CALLBACK (on_spaces1_activate), NULL); + g_signal_connect ((gpointer) tabs_and_spaces1, "activate", + G_CALLBACK (on_tabs_and_spaces1_activate), + NULL); g_signal_connect ((gpointer) set_file_readonly1, "toggled", G_CALLBACK (on_set_file_readonly1_toggled), NULL); @@ -1734,7 +1743,7 @@ create_window1 (void) GLADE_HOOKUP_OBJECT (window1, file1_menu, "file1_menu"); GLADE_HOOKUP_OBJECT (window1, menu_new1, "menu_new1"); GLADE_HOOKUP_OBJECT (window1, menu_new_with_template1, "menu_new_with_template1"); - GLADE_HOOKUP_OBJECT (window1, image2548, "image2548"); + GLADE_HOOKUP_OBJECT (window1, image2576, "image2576"); GLADE_HOOKUP_OBJECT (window1, menu_new_with_template1_menu, "menu_new_with_template1_menu"); GLADE_HOOKUP_OBJECT (window1, invisible2, "invisible2"); GLADE_HOOKUP_OBJECT (window1, separator12, "separator12"); @@ -1745,11 +1754,11 @@ create_window1 (void) GLADE_HOOKUP_OBJECT (window1, menu_save1, "menu_save1"); GLADE_HOOKUP_OBJECT (window1, menu_save_as1, "menu_save_as1"); GLADE_HOOKUP_OBJECT (window1, menu_save_all1, "menu_save_all1"); - GLADE_HOOKUP_OBJECT (window1, image2549, "image2549"); + GLADE_HOOKUP_OBJECT (window1, image2577, "image2577"); GLADE_HOOKUP_OBJECT (window1, menu_reload1, "menu_reload1"); - GLADE_HOOKUP_OBJECT (window1, image2550, "image2550"); + GLADE_HOOKUP_OBJECT (window1, image2578, "image2578"); GLADE_HOOKUP_OBJECT (window1, menu_reload_as1, "menu_reload_as1"); - GLADE_HOOKUP_OBJECT (window1, image2551, "image2551"); + GLADE_HOOKUP_OBJECT (window1, image2579, "image2579"); GLADE_HOOKUP_OBJECT (window1, menu_reload_as1_menu, "menu_reload_as1_menu"); GLADE_HOOKUP_OBJECT (window1, invisible7, "invisible7"); GLADE_HOOKUP_OBJECT (window1, separator21, "separator21"); @@ -1760,9 +1769,9 @@ create_window1 (void) GLADE_HOOKUP_OBJECT (window1, separator14, "separator14"); GLADE_HOOKUP_OBJECT (window1, menu_close1, "menu_close1"); GLADE_HOOKUP_OBJECT (window1, close_other_documents1, "close_other_documents1"); - GLADE_HOOKUP_OBJECT (window1, image2552, "image2552"); + GLADE_HOOKUP_OBJECT (window1, image2580, "image2580"); GLADE_HOOKUP_OBJECT (window1, menu_close_all1, "menu_close_all1"); - GLADE_HOOKUP_OBJECT (window1, image2553, "image2553"); + GLADE_HOOKUP_OBJECT (window1, image2581, "image2581"); GLADE_HOOKUP_OBJECT (window1, menu_separatormenuitem1, "menu_separatormenuitem1"); GLADE_HOOKUP_OBJECT (window1, menu_quit1, "menu_quit1"); GLADE_HOOKUP_OBJECT (window1, edit1, "edit1"); @@ -1787,16 +1796,16 @@ create_window1 (void) GLADE_HOOKUP_OBJECT (window1, menu_duplicate_line1, "menu_duplicate_line1"); GLADE_HOOKUP_OBJECT (window1, separator29, "separator29"); GLADE_HOOKUP_OBJECT (window1, menu_increase_indent1, "menu_increase_indent1"); - GLADE_HOOKUP_OBJECT (window1, image2554, "image2554"); + GLADE_HOOKUP_OBJECT (window1, image2582, "image2582"); GLADE_HOOKUP_OBJECT (window1, menu_decrease_indent1, "menu_decrease_indent1"); - GLADE_HOOKUP_OBJECT (window1, image2555, "image2555"); + GLADE_HOOKUP_OBJECT (window1, image2583, "image2583"); GLADE_HOOKUP_OBJECT (window1, separator37, "separator37"); GLADE_HOOKUP_OBJECT (window1, send_selection_to2, "send_selection_to2"); GLADE_HOOKUP_OBJECT (window1, send_selection_to2_menu, "send_selection_to2_menu"); GLADE_HOOKUP_OBJECT (window1, invisible13, "invisible13"); GLADE_HOOKUP_OBJECT (window1, separator18, "separator18"); GLADE_HOOKUP_OBJECT (window1, add_comments1, "add_comments1"); - GLADE_HOOKUP_OBJECT (window1, image2556, "image2556"); + GLADE_HOOKUP_OBJECT (window1, image2584, "image2584"); GLADE_HOOKUP_OBJECT (window1, add_comments1_menu, "add_comments1_menu"); GLADE_HOOKUP_OBJECT (window1, menu_add_changelog_entry1, "menu_add_changelog_entry1"); GLADE_HOOKUP_OBJECT (window1, insert_file_header1, "insert_file_header1"); @@ -1805,11 +1814,11 @@ create_window1 (void) GLADE_HOOKUP_OBJECT (window1, insert_gpl_notice2, "insert_gpl_notice2"); GLADE_HOOKUP_OBJECT (window1, insert_bsd_license_notice2, "insert_bsd_license_notice2"); GLADE_HOOKUP_OBJECT (window1, insert_date1, "insert_date1"); - GLADE_HOOKUP_OBJECT (window1, image2557, "image2557"); + GLADE_HOOKUP_OBJECT (window1, image2585, "image2585"); GLADE_HOOKUP_OBJECT (window1, insert_date1_menu, "insert_date1_menu"); GLADE_HOOKUP_OBJECT (window1, invisible8, "invisible8"); GLADE_HOOKUP_OBJECT (window1, insert_include2, "insert_include2"); - GLADE_HOOKUP_OBJECT (window1, image2558, "image2558"); + GLADE_HOOKUP_OBJECT (window1, image2586, "image2586"); GLADE_HOOKUP_OBJECT (window1, insert_include2_menu, "insert_include2_menu"); GLADE_HOOKUP_OBJECT (window1, invisible4, "invisible4"); GLADE_HOOKUP_OBJECT (window1, separator9, "separator9"); @@ -1821,7 +1830,7 @@ create_window1 (void) GLADE_HOOKUP_OBJECT (window1, find_previous1, "find_previous1"); GLADE_HOOKUP_OBJECT (window1, find_in_files1, "find_in_files1"); GLADE_HOOKUP_OBJECT (window1, replace1, "replace1"); - GLADE_HOOKUP_OBJECT (window1, image2559, "image2559"); + GLADE_HOOKUP_OBJECT (window1, image2587, "image2587"); GLADE_HOOKUP_OBJECT (window1, separator33, "separator33"); GLADE_HOOKUP_OBJECT (window1, find_nextsel1, "find_nextsel1"); GLADE_HOOKUP_OBJECT (window1, find_prevsel1, "find_prevsel1"); @@ -1830,11 +1839,11 @@ create_window1 (void) GLADE_HOOKUP_OBJECT (window1, previous_message1, "previous_message1"); GLADE_HOOKUP_OBJECT (window1, separator32, "separator32"); GLADE_HOOKUP_OBJECT (window1, go_to_line1, "go_to_line1"); - GLADE_HOOKUP_OBJECT (window1, image2560, "image2560"); + GLADE_HOOKUP_OBJECT (window1, image2588, "image2588"); GLADE_HOOKUP_OBJECT (window1, menu_view1, "menu_view1"); GLADE_HOOKUP_OBJECT (window1, menu_view1_menu, "menu_view1_menu"); GLADE_HOOKUP_OBJECT (window1, menu_change_font1, "menu_change_font1"); - GLADE_HOOKUP_OBJECT (window1, image2561, "image2561"); + GLADE_HOOKUP_OBJECT (window1, image2589, "image2589"); GLADE_HOOKUP_OBJECT (window1, menu_separator4, "menu_separator4"); GLADE_HOOKUP_OBJECT (window1, menu_toggle_all_additional_widgets1, "menu_toggle_all_additional_widgets1"); GLADE_HOOKUP_OBJECT (window1, menu_fullscreen1, "menu_fullscreen1"); @@ -1856,6 +1865,7 @@ create_window1 (void) GLADE_HOOKUP_OBJECT (window1, indent_type1_menu, "indent_type1_menu"); 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, separator45, "separator45"); GLADE_HOOKUP_OBJECT (window1, set_file_readonly1, "set_file_readonly1"); GLADE_HOOKUP_OBJECT (window1, menu_write_unicode_bom1, "menu_write_unicode_bom1"); @@ -1884,26 +1894,26 @@ create_window1 (void) GLADE_HOOKUP_OBJECT (window1, menu_project1, "menu_project1"); GLADE_HOOKUP_OBJECT (window1, menu_project1_menu, "menu_project1_menu"); GLADE_HOOKUP_OBJECT (window1, project_new1, "project_new1"); - GLADE_HOOKUP_OBJECT (window1, image2562, "image2562"); + GLADE_HOOKUP_OBJECT (window1, image2590, "image2590"); GLADE_HOOKUP_OBJECT (window1, project_open1, "project_open1"); - GLADE_HOOKUP_OBJECT (window1, image2563, "image2563"); + GLADE_HOOKUP_OBJECT (window1, image2591, "image2591"); GLADE_HOOKUP_OBJECT (window1, project_close1, "project_close1"); - GLADE_HOOKUP_OBJECT (window1, image2564, "image2564"); + GLADE_HOOKUP_OBJECT (window1, image2592, "image2592"); GLADE_HOOKUP_OBJECT (window1, separator34, "separator34"); GLADE_HOOKUP_OBJECT (window1, project_properties1, "project_properties1"); GLADE_HOOKUP_OBJECT (window1, menu_build1, "menu_build1"); GLADE_HOOKUP_OBJECT (window1, tools1, "tools1"); GLADE_HOOKUP_OBJECT (window1, tools1_menu, "tools1_menu"); GLADE_HOOKUP_OBJECT (window1, menu_choose_color1, "menu_choose_color1"); - GLADE_HOOKUP_OBJECT (window1, image2565, "image2565"); + GLADE_HOOKUP_OBJECT (window1, image2593, "image2593"); GLADE_HOOKUP_OBJECT (window1, menu_count_words1, "menu_count_words1"); GLADE_HOOKUP_OBJECT (window1, load_tags1, "load_tags1"); GLADE_HOOKUP_OBJECT (window1, menu_reload_configuration1, "menu_reload_configuration1"); - GLADE_HOOKUP_OBJECT (window1, image2566, "image2566"); + GLADE_HOOKUP_OBJECT (window1, image2594, "image2594"); GLADE_HOOKUP_OBJECT (window1, menu_help1, "menu_help1"); GLADE_HOOKUP_OBJECT (window1, menu_help1_menu, "menu_help1_menu"); GLADE_HOOKUP_OBJECT (window1, help1, "help1"); - GLADE_HOOKUP_OBJECT (window1, image2567, "image2567"); + GLADE_HOOKUP_OBJECT (window1, image2595, "image2595"); GLADE_HOOKUP_OBJECT (window1, keyboard_shortcuts1, "keyboard_shortcuts1"); GLADE_HOOKUP_OBJECT (window1, website1, "website1"); GLADE_HOOKUP_OBJECT (window1, separator16, "separator16"); @@ -3659,7 +3669,7 @@ create_prefs_dialog (void) gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_indent_tabs), radio_indent_spaces_group); radio_indent_spaces_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_indent_tabs)); - radio_indent_both = gtk_radio_button_new_with_mnemonic (NULL, _("T_abs & Spaces")); + radio_indent_both = gtk_radio_button_new_with_mnemonic (NULL, _("T_abs and Spaces")); gtk_widget_show (radio_indent_both); gtk_table_attach (GTK_TABLE (table13), radio_indent_both, 1, 2, 3, 4, (GtkAttachOptions) (GTK_FILL), From d3fbdf278b54ef0be0980ea67f730433a42cf615 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 4 Aug 2008 14:07:49 +0000 Subject: [PATCH 16/22] Fix build; currently auto-indentation doesn't support inserting tabs and spaces, only spaces. Also Tabs & Spaces cannot be detected yet when opening files. Default file templates still only use tabs. Add editor_get_indent_prefs() which should be used to get the right settings for a document/editor instead of reading any default prefs. This could also support project/filetype indentation prefs quite easily. Don't change per-document auto-indent setting after changing default auto-indentation type. Remove ui_radio_menu_item_*(), not good to use as they depended on the order of widget creation, so don't work well with Glade. Use RadioPrefEntry array instead. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2853 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 19 ++++++ src/callbacks.c | 71 +++++++++----------- src/callbacks.h | 4 ++ src/document.c | 71 ++++++++++++-------- src/editor.c | 167 +++++++++++++++++++++++++++++++++++------------- src/editor.h | 2 +- src/keyfile.c | 10 +-- src/main.c | 11 +--- src/prefs.c | 26 +++++--- src/ui_utils.c | 69 ++++++++------------ src/ui_utils.h | 4 -- 11 files changed, 273 insertions(+), 181 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0027b8c5..dcba37b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2008-08-04 Nick Treleaven + + * src/ui_utils.h, src/prefs.c, src/callbacks.c, src/callbacks.h, + src/keyfile.c, src/document.c, src/main.c, src/editor.c, + src/editor.h, src/ui_utils.c: + Fix build; currently auto-indentation doesn't support inserting tabs + and spaces, only spaces. Also Tabs & Spaces cannot be detected yet + when opening files. Default file templates still only use tabs. + Add editor_get_indent_prefs() which should be used to get the right + settings for a document/editor instead of reading any default prefs. + This could also support project/filetype indentation prefs quite + easily. + Don't change per-document auto-indent setting after changing default + auto-indentation type. + Remove ui_radio_menu_item_*(), not good to use as they depended on + the order of widget creation, so don't work well with Glade. Use + RadioPrefEntry array instead. + + 2008-07-31 Nick Treleaven * src/interface.c, src/editor.h, geany.glade: diff --git a/src/callbacks.c b/src/callbacks.c index 1a019947..264edc5c 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -1701,6 +1701,18 @@ on_menu_duplicate_line1_activate (GtkMenuItem *menuitem, } +static void change_line_indent(GeanyEditor *editor, gboolean increase) +{ + const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor); + ScintillaObject *sci = editor->sci; + gint line = sci_get_current_line(sci); + gint width = sci_get_line_indentation(sci, line); + + width += increase ? iprefs->width : -iprefs->width; + sci_set_line_indentation(sci, line, width); +} + + void on_menu_increase_indent1_activate (GtkMenuItem *menuitem, gpointer user_data) @@ -1715,18 +1727,7 @@ on_menu_increase_indent1_activate (GtkMenuItem *menuitem, } else { - gint line, ind_pos, old_pos, new_pos, step; - - old_pos = sci_get_current_position(doc->editor->sci); - line = sci_get_line_from_position(doc->editor->sci, old_pos); - ind_pos = sci_get_line_indent_position(doc->editor->sci, line); - /* when using tabs increase cur pos by 1, when using space increase it by tab_width */ - step = (doc->editor->use_tabs) ? 1 : editor_prefs.tab_width; - new_pos = (old_pos > ind_pos) ? old_pos + step : old_pos; - - sci_set_current_position(doc->editor->sci, ind_pos, TRUE); - sci_cmd(doc->editor->sci, SCI_TAB); - sci_set_current_position(doc->editor->sci, new_pos, TRUE); + change_line_indent(doc->editor, TRUE); } } @@ -1745,25 +1746,7 @@ on_menu_decrease_indent1_activate (GtkMenuItem *menuitem, } else { - gint line, ind_pos, old_pos, new_pos, step, indent; - - old_pos = sci_get_current_position(doc->editor->sci); - line = sci_get_line_from_position(doc->editor->sci, old_pos); - ind_pos = sci_get_line_indent_position(doc->editor->sci, line); - step = (doc->editor->use_tabs) ? 1 : editor_prefs.tab_width; - new_pos = (old_pos >= ind_pos) ? old_pos - step : old_pos; - - if (ind_pos == sci_get_position_from_line(doc->editor->sci, line)) - return; - - sci_set_current_position(doc->editor->sci, ind_pos, TRUE); - indent = sci_get_line_indentation(doc->editor->sci, line); - indent -= editor_prefs.tab_width; - if (indent < 0) - indent = 0; - sci_set_line_indentation(doc->editor->sci, line, indent); - - sci_set_current_position(doc->editor->sci, new_pos, TRUE); + change_line_indent(doc->editor, FALSE); } } @@ -2079,31 +2062,39 @@ gboolean on_motion_event(GtkWidget *widget, GdkEventMotion *event, gpointer user } -void -on_tabs1_activate (GtkMenuItem *menuitem, - gpointer user_data) +static void set_indent_type(GeanyIndentType type) { GeanyDocument *doc = document_get_current(); if (doc == NULL || ignore_callback) return; - editor_set_use_tabs(doc->editor, TRUE); + editor_set_indent_type(doc->editor, type); ui_update_statusbar(doc, -1); } +void +on_tabs1_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + set_indent_type(GEANY_INDENT_TYPE_TABS); +} + + void on_spaces1_activate (GtkMenuItem *menuitem, gpointer user_data) { - GeanyDocument *doc = document_get_current(); + set_indent_type(GEANY_INDENT_TYPE_SPACES); +} - if (doc == NULL || ignore_callback) - return; - editor_set_use_tabs(doc->editor, FALSE); - ui_update_statusbar(doc, -1); +void +on_tabs_and_spaces1_activate (GtkMenuItem *menuitem, + gpointer user_data) +{ + set_indent_type(GEANY_INDENT_TYPE_BOTH); } diff --git a/src/callbacks.h b/src/callbacks.h index 37a7662f..4ec2ee31 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -626,3 +626,7 @@ on_menu_reload_configuration1_activate (GtkMenuItem *menuitem, void on_find_document_usage1_activate (GtkMenuItem *menuitem, gpointer user_data); + +void +on_tabs_and_spaces1_activate (GtkMenuItem *menuitem, + gpointer user_data); diff --git a/src/document.c b/src/document.c index 6cb866b2..983a41ee 100644 --- a/src/document.c +++ b/src/document.c @@ -303,15 +303,18 @@ void document_set_text_changed(GeanyDocument *doc, gboolean changed) void document_apply_update_prefs(GeanyDocument *doc) { ScintillaObject *sci; + GeanyEditor *editor; g_return_if_fail(doc != NULL); - sci = doc->editor->sci; + editor = doc->editor; + sci = editor->sci; sci_set_mark_long_lines(sci, editor_prefs.long_line_type, editor_prefs.long_line_column, editor_prefs.long_line_color); - sci_set_tab_width(sci, editor_prefs.tab_width); + /* update indent width, tab width */ + editor_set_indent_type(editor, editor->indent_type); sci_set_autoc_max_height(sci, editor_prefs.symbolcompletion_max_height); @@ -321,8 +324,6 @@ void document_apply_update_prefs(GeanyDocument *doc) sci_set_folding_margin_visible(sci, editor_prefs.folding); - doc->editor->auto_indent = (editor_prefs.indent_mode != INDENT_NONE); - sci_assign_cmdkey(sci, SCK_HOME, editor_prefs.smart_home_key ? SCI_VCHOMEWRAP : SCI_HOMEWRAP); sci_assign_cmdkey(sci, SCK_END, SCI_LINEENDWRAP); @@ -571,7 +572,6 @@ GeanyDocument *document_new_file(const gchar *utf8_filename, GeanyFiletype *ft, if (text != NULL) sci_convert_eols(doc->editor->sci, file_prefs.default_eol_character); - editor_set_use_tabs(doc->editor, editor_prefs.use_tabs); sci_set_undo_collection(doc->editor->sci, TRUE); sci_empty_undo_buffer(doc->editor->sci); @@ -883,11 +883,18 @@ static void set_cursor_position(GeanyEditor *editor, gint pos) } -static gboolean detect_use_tabs(ScintillaObject *sci) +static GeanyIndentType detect_indent_type(GeanyEditor *editor) { + const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor); + ScintillaObject *sci = editor->sci; gint line; + gboolean use_tabs; gsize tabs = 0, spaces = 0; + /* TODO: tabs & spaces detection */ + if (iprefs->type == GEANY_INDENT_TYPE_BOTH) + return GEANY_INDENT_TYPE_BOTH; + for (line = 0; line < sci_get_line_count(sci); line++) { gint pos = sci_get_position_from_line(sci, line); @@ -905,34 +912,42 @@ static gboolean detect_use_tabs(ScintillaObject *sci) } } if (spaces == 0 && tabs == 0) - return editor_prefs.use_tabs; + return iprefs->type; /* Skew comparison by a factor of 2 in favour of default editor pref */ - if (editor_prefs.use_tabs) - return ! (spaces > tabs * 2); + if (iprefs->type == GEANY_INDENT_TYPE_TABS) + use_tabs = ! (spaces > tabs * 2); else - return (tabs > spaces * 2); + use_tabs = (tabs > spaces * 2); + + return use_tabs ? GEANY_INDENT_TYPE_TABS : GEANY_INDENT_TYPE_SPACES; } -static void set_indentation(GeanyDocument *doc) +static void set_indentation(GeanyEditor *editor) { - /* force using tabs for indentation for Makefiles */ - if (FILETYPE_ID(doc->file_type) == GEANY_FILETYPES_MAKE) - editor_set_use_tabs(doc->editor, TRUE); - /* force using spaces for indentation for Fortran 77 */ - else if (FILETYPE_ID(doc->file_type) == GEANY_FILETYPES_F77) - editor_set_use_tabs(doc->editor, FALSE); - else if (! editor_prefs.detect_tab_mode) - editor_set_use_tabs(doc->editor, editor_prefs.use_tabs); - else - { /* detect & set tabs/spaces */ - gboolean use_tabs = detect_use_tabs(doc->editor->sci); + const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor); - if (use_tabs != editor_prefs.use_tabs) - ui_set_statusbar(TRUE, _("Setting %s indentation mode."), - (use_tabs) ? _("Tabs") : _("Spaces")); - editor_set_use_tabs(doc->editor, use_tabs); + switch (FILETYPE_ID(editor->document->file_type)) + { + case GEANY_FILETYPES_MAKE: + /* force using tabs for indentation for Makefiles */ + editor_set_indent_type(editor, GEANY_INDENT_TYPE_TABS); + break; + case GEANY_FILETYPES_F77: + /* force using spaces for indentation for Fortran 77 */ + editor_set_indent_type(editor, GEANY_INDENT_TYPE_SPACES); + break; + default: + if (iprefs->detect_type) + { /* detect & set tabs/spaces */ + GeanyIndentType type = detect_indent_type(editor); + + if (type != iprefs->type) + ui_set_statusbar(TRUE, _("Setting %s indentation mode."), + (type == GEANY_INDENT_TYPE_TABS) ? _("Tabs") : _("Spaces")); + editor_set_indent_type(editor, type); + } } } @@ -1061,9 +1076,9 @@ GeanyDocument *document_open_file_full(GeanyDocument *doc, const gchar *filename /* set indentation settings after setting the filetype */ if (reload) - editor_set_use_tabs(doc->editor, doc->editor->use_tabs); /* resetup sci */ + editor_set_indent_type(doc->editor, doc->editor->indent_type); /* resetup sci */ else - set_indentation(doc); + set_indentation(doc->editor); document_set_text_changed(doc, FALSE); /* also updates tab state */ ui_document_show_hide(doc); /* update the document menu */ diff --git a/src/editor.c b/src/editor.c index 49692f1f..b1252e84 100644 --- a/src/editor.c +++ b/src/editor.c @@ -706,33 +706,79 @@ void on_editor_notification(GtkWidget *widget, gint scn, gpointer lscn, gpointer } +static gint get_tab_width(const GeanyIndentPrefs *indent_prefs) +{ + if (indent_prefs->type == GEANY_INDENT_TYPE_BOTH) + return indent_prefs->tab_width; + + return indent_prefs->width; /* tab width = indent width */ +} + + /* Returns a string containing width chars of whitespace, filled with simple space - * characters or with the right number of tab characters, according to the - * use_tabs setting. (Result is filled with tabs *and* spaces if width isn't a multiple of + * characters or with the right number of tab characters, according to the indent prefs. + * (Result is filled with tabs *and* spaces if width isn't a multiple of * editor_prefs.tab_width). */ static gchar * -get_whitespace(gint width, gboolean use_tabs) +get_whitespace(const GeanyIndentPrefs *iprefs, gint width) { - gchar *str; - g_return_val_if_fail(width > 0, NULL); - if (use_tabs) + if (iprefs->type == GEANY_INDENT_TYPE_SPACES) + { + return g_strnfill(width, ' '); + } + else { /* first fill text with tabs and fill the rest with spaces */ - gint tabs = width / editor_prefs.tab_width; - gint spaces = width % editor_prefs.tab_width; + const gint tab_width = get_tab_width(iprefs); + gint tabs = width / tab_width; + gint spaces = width % tab_width; gint len = tabs + spaces; + gchar *str; str = g_malloc(len + 1); memset(str, '\t', tabs); memset(str + tabs, ' ', spaces); str[len] = '\0'; + return str; } - else - str = g_strnfill(width, ' '); +} - return str; + +static const GeanyIndentPrefs * +get_default_indent_prefs(void) +{ + /* In future this might depend on project or filetype. */ + return editor_prefs.indentation; +} + + +/** Get the indentation prefs for the editor. + * In future, the prefs might be different according to project or filetype. + * @warning Always get a fresh result instead of keeping a pointer to it if the editor + * settings may have changed, or if this function has been called for a different @a editor. */ +const GeanyIndentPrefs * +editor_get_indent_prefs(GeanyEditor *editor) +{ + static GeanyIndentPrefs iprefs; + + g_return_val_if_fail(editor != NULL, NULL); + + iprefs = *get_default_indent_prefs(); + + iprefs.type = editor->indent_type; + if (!editor->auto_indent) + iprefs.auto_indent_mode = GEANY_AUTOINDENT_NONE; + return &iprefs; +} + + +static gchar *get_single_indent(GeanyEditor *editor) +{ + const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor); + + return get_whitespace(iprefs, iprefs->width); } @@ -745,9 +791,9 @@ static void check_python_indent(GeanyEditor *editor, gint pos) if (sci_get_char_at(sci, last_char) == ':' && sci_get_style_at(sci, last_char) == SCE_P_OPERATOR) { - /* creates and inserts one tabulator sign or + /* creates and inserts one tab char or * whitespace of the amount of the tab width */ - gchar *text = get_whitespace(editor_prefs.tab_width, editor->use_tabs); + gchar *text = get_single_indent(editor); sci_add_text(sci, text); g_free(text); } @@ -763,10 +809,12 @@ static void on_new_line_added(GeanyEditor *editor) /* simple indentation */ if (editor->auto_indent) { + gint auto_indent_mode = editor_get_indent_prefs(editor)->auto_indent_mode; + get_indent(editor, pos, FALSE); sci_add_text(sci, indent); - if (editor_prefs.indent_mode > INDENT_BASIC && + if (auto_indent_mode > GEANY_AUTOINDENT_BASIC && FILETYPE_ID(editor->document->file_type) == GEANY_FILETYPES_PYTHON) check_python_indent(editor, pos); } @@ -808,20 +856,23 @@ static gboolean lexer_has_braces(ScintillaObject *sci) } -/* in place indentation of one tab or equivalent spaces */ -static void do_indent(gchar *buf, gsize len, guint *idx, gboolean use_tabs) +/* in place indentation of one tab or equivalent spaces. + * idx is the index into buf. */ +static void do_indent(const GeanyIndentPrefs *iprefs, gchar *buf, gsize len, guint *idx) { guint j = *idx; - if (use_tabs) + if (iprefs->type == GEANY_INDENT_TYPE_TABS) { if (j < len - 1) /* leave room for a \0 terminator. */ buf[j++] = '\t'; } else - { /* insert as many spaces as a tab would take */ + { + /* insert as many spaces as an indent takes. + * TODO: insert tabs for GEANY_INDENT_TYPE_BOTH */ guint k; - for (k = 0; k < (guint) editor_prefs.tab_width && k < len - 1; k++) + for (k = 0; k < (guint) iprefs->width && k < len - 1; k++) buf[j++] = ' '; } *idx = j; @@ -836,6 +887,7 @@ static void get_indent(GeanyEditor *editor, gint pos, gboolean use_this_line) guint i, len, j = 0; gint prev_line; gchar *linebuf; + const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor); prev_line = sci_get_line_from_position(sci, pos); @@ -848,7 +900,7 @@ static void get_indent(GeanyEditor *editor, gint pos, gboolean use_this_line) { if (linebuf[i] == ' ' || linebuf[i] == '\t') /* simple indentation */ indent[j++] = linebuf[i]; - else if (editor_prefs.indent_mode <= INDENT_BASIC) + else if (iprefs->auto_indent_mode <= GEANY_AUTOINDENT_BASIC) break; else if (use_this_line) break; @@ -861,7 +913,7 @@ static void get_indent(GeanyEditor *editor, gint pos, gboolean use_this_line) * " { return bless({}, shift); }" (Perl) */ if (linebuf[i] == '{' && i == (len - 1)) { - do_indent(indent, sizeof(indent), &j, editor->use_tabs); + do_indent(iprefs, indent, sizeof(indent), &j); break; } else @@ -874,7 +926,7 @@ static void get_indent(GeanyEditor *editor, gint pos, gboolean use_this_line) * e.g. for (...) { */ if (linebuf[k] == '{') { - do_indent(indent, sizeof(indent), &j, editor->use_tabs); + do_indent(iprefs, indent, sizeof(indent), &j); } break; } @@ -944,13 +996,14 @@ static gint brace_match(ScintillaObject *sci, gint pos) /* Called after typing '}'. */ void editor_close_block(GeanyDocument *doc, gint pos) { + const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(doc->editor); gint x = 0, cnt = 0; gint line, line_len, eol_char_len; gchar *text, *line_buf; ScintillaObject *sci; gint line_indent, last_indent; - if (editor_prefs.indent_mode < INDENT_CURRENTCHARS) + if (iprefs->auto_indent_mode < GEANY_AUTOINDENT_CURRENTCHARS) return; if (doc == NULL || doc->file_type == NULL) return; @@ -979,7 +1032,7 @@ void editor_close_block(GeanyDocument *doc, gint pos) if ((line_len - eol_char_len - 1) != cnt) return; - if (editor_prefs.indent_mode == INDENT_MATCHBRACES) + if (iprefs->auto_indent_mode == GEANY_AUTOINDENT_MATCHBRACES) { gint start_brace = brace_match(sci, pos); @@ -998,13 +1051,13 @@ void editor_close_block(GeanyDocument *doc, gint pos) /* fall through - unmatched brace (possibly because of TCL, PHP lexer bugs) */ } - /* INDENT_CURRENTCHARS */ + /* GEANY_AUTOINDENT_CURRENTCHARS */ line_indent = sci_get_line_indentation(sci, line); last_indent = sci_get_line_indentation(sci, line - 1); if (line_indent < last_indent) return; - line_indent -= editor_prefs.tab_width; + line_indent -= iprefs->width; line_indent = MAX(0, line_indent); sci_set_line_indentation(sci, line, line_indent); } @@ -1578,7 +1631,7 @@ static gboolean snippets_complete_constructs(GeanyEditor *editor, gint pos, cons get_indent(editor, pos, TRUE); lindent = g_strconcat(editor_get_eol_char(editor->document), indent, NULL); - whitespace = get_whitespace(editor_prefs.tab_width, editor->use_tabs); + whitespace = get_single_indent(editor); /* remove the typed word, it will be added again by the used auto completion * (not really necessary but this makes the auto completion more flexible, @@ -1825,10 +1878,10 @@ static void auto_table(GeanyEditor *editor, gint pos) } /* get indent string for generated code */ - if (editor_prefs.indent_mode == INDENT_NONE) + if (editor->auto_indent) indent_str = g_strdup(""); else - indent_str = get_whitespace(editor_prefs.tab_width, editor->use_tabs); + indent_str = get_single_indent(editor); table = g_strconcat("\n", indent, indent_str, "\n", indent, indent_str, indent_str, "\n", @@ -2435,10 +2488,11 @@ static void auto_multiline(GeanyEditor *editor, gint pos) gint cur_line = sci_get_current_line(sci); gint indent_pos = sci_get_line_indent_position(sci, cur_line); gint indent_len = sci_get_col_from_position(sci, indent_pos); + gint indent_width = editor_get_indent_prefs(editor)->width; /* if there is one too many spaces, delete the last space, * to return to the indent used before the multiline comment was started. */ - if (indent_len % editor_prefs.tab_width == 1) + if (indent_len % indent_width == 1) SSM(sci, SCI_DELETEBACKNOTLINE, 0, 0); /* remove whitespace indent */ g_free(previous_line); return; @@ -2765,10 +2819,23 @@ void editor_scroll_to_line(ScintillaObject *sci, gint line, gfloat percent_of_vi } +/* creates and inserts one tab or whitespace of the amount of the tab width */ void editor_insert_alternative_whitespace(GeanyEditor *editor) { - /* creates and inserts one tab or whitespace of the amount of the tab width */ - gchar *text = get_whitespace(editor_prefs.tab_width, ! editor->use_tabs); + gchar *text; + GeanyIndentPrefs iprefs = *editor_get_indent_prefs(editor); + + switch (iprefs.type) + { + case GEANY_INDENT_TYPE_TABS: + iprefs.type = GEANY_INDENT_TYPE_SPACES; + break; + case GEANY_INDENT_TYPE_SPACES: + case GEANY_INDENT_TYPE_BOTH: /* most likely we want a tab */ + iprefs.type = GEANY_INDENT_TYPE_TABS; + break; + } + text = get_whitespace(&iprefs, iprefs.width); sci_add_text(editor->sci, text); g_free(text); } @@ -3490,14 +3557,24 @@ void editor_set_line_wrapping(GeanyEditor *editor, gboolean wrap) } -void editor_set_use_tabs(GeanyEditor *editor, gboolean use_tabs) +/* Also sets indent width, tab width. */ +void editor_set_indent_type(GeanyEditor *editor, GeanyIndentType type) { - g_return_if_fail(editor != NULL); + const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor); + ScintillaObject *sci = editor->sci; + gboolean use_tabs = type != GEANY_INDENT_TYPE_SPACES; - editor->use_tabs = use_tabs; - sci_set_use_tabs(editor->sci, use_tabs); - /* remove indent spaces on backspace, if using spaces to indent */ - SSM(editor->sci, SCI_SETBACKSPACEUNINDENTS, ! use_tabs, 0); + editor->indent_type = type; + sci_set_use_tabs(sci, use_tabs); + + if (type == GEANY_INDENT_TYPE_BOTH) + sci_set_tab_width(sci, iprefs->tab_width); + else + sci_set_tab_width(sci, iprefs->width); + SSM(sci, SCI_SETINDENT, iprefs->width, 0); + + /* remove indent spaces on backspace, if using any spaces to indent */ + SSM(sci, SCI_SETBACKSPACEUNINDENTS, type != GEANY_INDENT_TYPE_TABS, 0); } @@ -3648,17 +3725,19 @@ static ScintillaObject *create_new_sci(GeanyDocument *doc) GeanyEditor *editor_create(GeanyDocument *doc) { + const GeanyIndentPrefs *iprefs = get_default_indent_prefs(); GeanyEditor *editor = g_new0(GeanyEditor, 1); editor->document = doc; - editor->auto_indent = (editor_prefs.indent_mode != INDENT_NONE); + editor->sci = create_new_sci(doc); + editor_set_indent_type(editor, iprefs->type); + editor_set_font(editor, interface_prefs.editor_font); + + editor->auto_indent = (iprefs->auto_indent_mode != GEANY_AUTOINDENT_NONE); editor->line_wrapping = editor_prefs.line_wrapping; editor->scroll_percent = -1.0F; editor->line_breaking = FALSE; - - editor->sci = create_new_sci(doc); - editor_set_font(editor, interface_prefs.editor_font); return editor; } @@ -3668,7 +3747,7 @@ void editor_init(void) static GeanyIndentPrefs indent_prefs; memset(&editor_prefs, 0, sizeof(GeanyEditorPrefs)); - memset(&indent_prefs, 0, sizeof GeanyIndentPrefs); - editor_prefs->indentation = &indent_prefs; + memset(&indent_prefs, 0, sizeof(GeanyIndentPrefs)); + editor_prefs.indentation = &indent_prefs; } diff --git a/src/editor.h b/src/editor.h index 809ca111..c1006ea3 100644 --- a/src/editor.h +++ b/src/editor.h @@ -48,8 +48,8 @@ /** Whether to use tabs, spaces or both to indent. */ typedef enum { - GEANY_INDENT_TYPE_TABS, /**< Tabs. */ GEANY_INDENT_TYPE_SPACES, /**< Spaces. */ + GEANY_INDENT_TYPE_TABS, /**< Tabs. */ GEANY_INDENT_TYPE_BOTH /**< Both. */ } GeanyIndentType; diff --git a/src/keyfile.c b/src/keyfile.c index fc0db9e8..dc46cb57 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -230,7 +230,7 @@ static gchar *get_session_file_string(GeanyDocument *doc) ft->name, doc->readonly, encodings_get_idx_from_charset(doc->encoding), - doc->editor->use_tabs, + doc->editor->indent_type, doc->editor->auto_indent, doc->editor->line_wrapping, doc->file_name); @@ -923,15 +923,15 @@ static gboolean open_session_file(gchar **tmp) guint pos; const gchar *ft_name; gchar *locale_filename; - gint enc_idx; - gboolean ro, use_tabs, auto_indent, line_wrapping; + gint enc_idx, indent_type; + gboolean ro, auto_indent, line_wrapping; gboolean ret = FALSE; pos = atoi(tmp[0]); ft_name = tmp[1]; ro = atoi(tmp[2]); enc_idx = atoi(tmp[3]); - use_tabs = atoi(tmp[4]); + indent_type = atoi(tmp[4]); auto_indent = atoi(tmp[5]); line_wrapping = atoi(tmp[6]); /* try to get the locale equivalent for the filename */ @@ -947,7 +947,7 @@ static gboolean open_session_file(gchar **tmp) if (doc) { - editor_set_use_tabs(doc->editor, use_tabs); + editor_set_indent_type(doc->editor, indent_type); editor_set_line_wrapping(doc->editor, line_wrapping); doc->editor->auto_indent = auto_indent; ret = TRUE; diff --git a/src/main.c b/src/main.c index a292a5f7..4fadc944 100644 --- a/src/main.c +++ b/src/main.c @@ -252,14 +252,6 @@ static void apply_settings(void) gtk_widget_hide(ui_widgets.statusbar); } - ignore_callback = TRUE; - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM( - lookup_widget(main_widgets.window, "menu_line_wrapping1")), editor_prefs.line_wrapping); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM( - lookup_widget(main_widgets.window, "menu_use_auto_indentation1")), - (editor_prefs.indent_mode != INDENT_NONE)); - ignore_callback = FALSE; - /* connect the toolbar dropdown menu for the new button */ gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON( lookup_widget(main_widgets.window, "menutoolbutton1")), ui_widgets.new_file_menu); @@ -794,12 +786,13 @@ gint main(gint argc, gchar **argv) main_init(); gtk_widget_set_size_request(main_widgets.window, GEANY_WINDOW_MINIMAL_WIDTH, GEANY_WINDOW_MINIMAL_HEIGHT); gtk_window_set_default_size(GTK_WINDOW(main_widgets.window), GEANY_WINDOW_DEFAULT_WIDTH, GEANY_WINDOW_DEFAULT_HEIGHT); + encodings_init(); + editor_init(); load_settings(); msgwin_init(); - editor_init(); build_init(); search_init(); ui_create_insert_menu_items(); diff --git a/src/prefs.c b/src/prefs.c index dc6544ab..b3411f6a 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -166,29 +166,39 @@ static void spin_prefs_foreach(PrefCallbackAction action) } +typedef struct RadioPrefEntry +{ + const gchar *widget_name; + gpointer setting; + gint value; +} +RadioPrefEntry; + static void radio_prefs_foreach(PrefCallbackAction action) { guint i; - /* Only add one widget per radio-group; the setting is the index of the selected radio item - * in the group. */ - PrefEntry items[] = + RadioPrefEntry items[] = { - {"radio_indent_spaces", &editor_prefs.indentation->type}, + {"radio_indent_spaces", &editor_prefs.indentation->type, GEANY_INDENT_TYPE_SPACES}, + {"radio_indent_tabs", &editor_prefs.indentation->type, GEANY_INDENT_TYPE_TABS}, + {"radio_indent_both", &editor_prefs.indentation->type, GEANY_INDENT_TYPE_BOTH}, }; for (i = 0; i < G_N_ELEMENTS(items); i++) { - PrefEntry *pe = &items[i]; + RadioPrefEntry *pe = &items[i]; GtkWidget *widget = lookup_widget(ui_widgets.prefs_dialog, pe->widget_name); gint *setting = pe->setting; switch (action) { case PREF_DISPLAY: - ui_radio_menu_item_set_active_index(GTK_RADIO_MENU_ITEM(widget), *setting); + if (*setting == pe->value) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE); break; case PREF_UPDATE: - *setting = ui_radio_menu_item_get_active_index(GTK_RADIO_MENU_ITEM(widget)); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) + *setting = pe->value; break; } } @@ -200,7 +210,7 @@ static void combo_prefs_foreach(PrefCallbackAction action) guint i; PrefEntry items[] = { - {"combo_auto_indent_mode", &editor_prefs.indentation->type}, + {"combo_auto_indent_mode", &editor_prefs.indentation->auto_indent_mode}, }; for (i = 0; i < G_N_ELEMENTS(items); i++) diff --git a/src/ui_utils.c b/src/ui_utils.c index e17dff2f..e3c8a57f 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -174,8 +174,19 @@ void ui_update_statusbar(GeanyDocument *doc, gint pos) /* OVR = overwrite/overtype, INS = insert */ (sci_get_overtype(doc->editor->sci) ? _("OVR") : _("INS"))); g_string_append(stats_str, sp); - g_string_append(stats_str, - (doc->editor->use_tabs) ? _("TAB") : _("SP ")); /* SP = space */ + + switch (editor_get_indent_prefs(doc->editor)->type) + { + case GEANY_INDENT_TYPE_TABS: + g_string_append(stats_str, _("TAB")); + break; + case GEANY_INDENT_TYPE_SPACES: + g_string_append(stats_str, _("SP")); /* SP = space */ + break; + case GEANY_INDENT_TYPE_BOTH: + g_string_append(stats_str, _("T/S")); /* T/S = tabs and spaces */ + break; + } g_string_append(stats_str, sp); g_string_append_printf(stats_str, _("mode: %s"), editor_get_eol_char_name(doc)); @@ -687,6 +698,7 @@ void ui_document_show_hide(GeanyDocument *doc) { gchar *widget_name; GtkWidget *item; + const GeanyIndentPrefs *iprefs; if (doc == NULL) doc = document_get_current(); @@ -704,12 +716,23 @@ void ui_document_show_hide(GeanyDocument *doc) GTK_CHECK_MENU_ITEM(lookup_widget(main_widgets.window, "line_breaking1")), doc->editor->line_breaking); + iprefs = editor_get_indent_prefs(doc->editor); + item = lookup_widget(main_widgets.window, "menu_use_auto_indentation1"); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), doc->editor->auto_indent); gtk_widget_set_sensitive(item, - editor_prefs.indentation->auto_indent_mode != GEANY_AUTOINDENT_NONE); + iprefs->auto_indent_mode != GEANY_AUTOINDENT_NONE); - item = lookup_widget(main_widgets.window, doc->editor->use_tabs ? "tabs1" : "spaces1"); + switch (iprefs->type) + { + case GEANY_INDENT_TYPE_SPACES: + widget_name = "spaces1"; break; + case GEANY_INDENT_TYPE_TABS: + widget_name = "tabs1"; break; + case GEANY_INDENT_TYPE_BOTH: + widget_name = "tabs_and_spaces1"; break; + } + item = lookup_widget(main_widgets.window, widget_name); gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE); gtk_check_menu_item_set_active( @@ -1508,41 +1531,3 @@ void ui_init(void) } -void ui_radio_menu_item_set_active_index(GtkRadioMenuItem *widget, guint idx) -{ - GSList *item = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(widget)); - guint i; - - for (i = 0; item != NULL; item = g_slist_next(item), i++) - { - if (i == idx) - { - GtkCheckMenuItem *radio = item->data; - - gtk_check_menu_item_set_active(radio, TRUE); - return; - } - } - g_warning("Index %u is out of range for group of widget %s", - idx, gtk_widget_get_name(GTK_WIDGET(widget))); -} - - -guint ui_radio_menu_item_get_active_index(GtkRadioMenuItem *widget) -{ - GSList *item = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(widget)); - guint i; - - for (i = 0; item != NULL; item = g_slist_next(item), i++) - { - GtkCheckMenuItem *radio = item->data; - - if (gtk_check_menu_item_get_active(radio)) - return i; - } - g_warning("No active group item for widget %s", - gtk_widget_get_name(GTK_WIDGET(widget))); - return 0; -} - - diff --git a/src/ui_utils.h b/src/ui_utils.h index dfe60d95..bd6efb4f 100644 --- a/src/ui_utils.h +++ b/src/ui_utils.h @@ -151,10 +151,6 @@ void ui_setup_open_button_callback(GtkWidget *open_btn, const gchar *title, void ui_table_add_row(GtkTable *table, gint row, ...) G_GNUC_NULL_TERMINATED; -void ui_radio_menu_item_set_active_index(GtkRadioMenuItem *widget, guint index); - -guint ui_radio_menu_item_get_active_index(GtkRadioMenuItem *widget); - /* End of 'generic' functions */ From 9cfcf0602b789deda5a8ae59e243659098b97c39 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Mon, 4 Aug 2008 14:10:16 +0000 Subject: [PATCH 17/22] Implemented 'distinguish between tab width vs. indent width'. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2854 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- TODO | 3 --- 1 file changed, 3 deletions(-) diff --git a/TODO b/TODO index 891c2d6c..10fe7a71 100644 --- a/TODO +++ b/TODO @@ -18,9 +18,6 @@ Note: features included in brackets have lower priority. o recent projects menu o project indentation settings support o improve Compile toolbar button for Make (drop down radio list?) - o (for spaces indentation, distinguish between tab width vs. indent - width, e.g. GTK code uses indent width of 2 spaces, and any tabs are - worth 8 spaces.) o (selectable menu of arguments to use for Make, from Make Custom) o (DBUS) o (indent wrapped lines - Scintilla issue) From 6140e5089d5ef7b2531935e3e89927fbe8c8ea5c Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Tue, 5 Aug 2008 14:46:27 +0000 Subject: [PATCH 18/22] Add get_indent_size_after_line() to replace get_indent() for clarity, and to fix Tabs & Spaces auto-indentation > basic. Change editor_close_block() to use sci_get_line_indentation() for clarity. Make editor_close_block() static. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2857 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 10 ++++ src/editor.c | 146 ++++++++++++++++++++++++++++++++++++++------------- src/editor.h | 2 - 3 files changed, 120 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index dcba37b2..862b0557 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-08-05 Nick Treleaven + + * src/editor.c, src/editor.h: + Add get_indent_size_after_line() to replace get_indent() for + clarity, and to fix Tabs & Spaces auto-indentation > basic. + Change editor_close_block() to use sci_get_line_indentation() for + clarity. + Make editor_close_block() static. + + 2008-08-04 Nick Treleaven * src/ui_utils.h, src/prefs.c, src/callbacks.c, src/callbacks.h, diff --git a/src/editor.c b/src/editor.c index b1252e84..408debc6 100644 --- a/src/editor.c +++ b/src/editor.c @@ -75,11 +75,12 @@ static gchar indent[100]; static void on_new_line_added(GeanyEditor *editor); static gboolean handle_xml(GeanyEditor *editor, gchar ch); static void get_indent(GeanyEditor *editor, gint pos, gboolean use_this_line); +static void insert_indent_after_line(GeanyEditor *editor, gint line); static void auto_multiline(GeanyEditor *editor, gint pos); static gboolean is_comment(gint lexer, gint prev_style, gint style); static void auto_close_bracket(ScintillaObject *sci, gint pos, gchar c); static void auto_table(GeanyEditor *editor, gint pos); - +static void close_block(GeanyEditor *editor, gint pos); void editor_snippets_free() @@ -437,7 +438,7 @@ static void on_char_added(GeanyEditor *editor, SCNotification *nt) case '}': { /* closing bracket handling */ if (editor->auto_indent) - editor_close_block(editor->document, pos - 1); + close_block(editor, pos - 1); break; } default: @@ -722,7 +723,10 @@ static gint get_tab_width(const GeanyIndentPrefs *indent_prefs) static gchar * get_whitespace(const GeanyIndentPrefs *iprefs, gint width) { - g_return_val_if_fail(width > 0, NULL); + g_return_val_if_fail(width >= 0, NULL); + + if (width == 0) + return g_strdup(""); if (iprefs->type == GEANY_INDENT_TYPE_SPACES) { @@ -782,24 +786,6 @@ static gchar *get_single_indent(GeanyEditor *editor) } -static void check_python_indent(GeanyEditor *editor, gint pos) -{ - ScintillaObject *sci = editor->sci; - gint last_char = pos - editor_get_eol_char_len(editor->document) - 1; - - /* add extra indentation for Python after colon */ - if (sci_get_char_at(sci, last_char) == ':' && - sci_get_style_at(sci, last_char) == SCE_P_OPERATOR) - { - /* creates and inserts one tab char or - * whitespace of the amount of the tab width */ - gchar *text = get_single_indent(editor); - sci_add_text(sci, text); - g_free(text); - } -} - - static void on_new_line_added(GeanyEditor *editor) { ScintillaObject *sci = editor->sci; @@ -809,14 +795,7 @@ static void on_new_line_added(GeanyEditor *editor) /* simple indentation */ if (editor->auto_indent) { - gint auto_indent_mode = editor_get_indent_prefs(editor)->auto_indent_mode; - - get_indent(editor, pos, FALSE); - sci_add_text(sci, indent); - - if (auto_indent_mode > GEANY_AUTOINDENT_BASIC && - FILETYPE_ID(editor->document->file_type) == GEANY_FILETYPES_PYTHON) - check_python_indent(editor, pos); + insert_indent_after_line(editor, line - 1); } if (editor_prefs.auto_continue_multiline) @@ -880,7 +859,7 @@ static void do_indent(const GeanyIndentPrefs *iprefs, gchar *buf, gsize len, gui /* "use_this_line" to auto-indent only if it is a real new line - * and ignore the case of editor_close_block */ + * and ignore the case of close_block */ static void get_indent(GeanyEditor *editor, gint pos, gboolean use_this_line) { ScintillaObject *sci = editor->sci; @@ -904,7 +883,7 @@ static void get_indent(GeanyEditor *editor, gint pos, gboolean use_this_line) break; else if (use_this_line) break; - else /* editor_close_block */ + else /* close_block */ { if (! lexer_has_braces(sci)) break; @@ -937,6 +916,97 @@ static void get_indent(GeanyEditor *editor, gint pos, gboolean use_this_line) } +static gint get_brace_indent(ScintillaObject *sci, gint line) +{ + guint i, len; + gint ret = 0; + gchar *linebuf; + + len = sci_get_line_length(sci, line); + linebuf = sci_get_line(sci, line); + + for (i = 0; i < len; i++) + { + /* i == (len - 1) prevents wrong indentation after lines like + * " { return bless({}, shift); }" (Perl) */ + if (linebuf[i] == '{' && i == (len - 1)) + { + ret++; + break; + } + else + { + gint k = len - 1; + + while (k > 0 && isspace(linebuf[k])) k--; + + /* if last non-whitespace character is a { increase indentation by a tab + * e.g. for (...) { */ + if (linebuf[k] == '{') + { + ret++; + } + break; + } + } + g_free(linebuf); + return ret; +} + + +static gint get_python_indent(ScintillaObject *sci, gint line) +{ + gint last_char = sci_get_line_end_position(sci, line) - 1; + + /* add extra indentation for Python after colon */ + if (sci_get_char_at(sci, last_char) == ':' && + sci_get_style_at(sci, last_char) == SCE_P_OPERATOR) + { + return 1; + } + return 0; +} + + +static gint get_indent_size_after_line(GeanyEditor *editor, gint line) +{ + ScintillaObject *sci = editor->sci; + gint size; + const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor); + + g_return_val_if_fail(line >= 0, 0); + + size = sci_get_line_indentation(sci, line); + + if (iprefs->auto_indent_mode > GEANY_AUTOINDENT_BASIC) + { + if (lexer_has_braces(sci)) + size += iprefs->width * get_brace_indent(sci, line); + else + if (FILETYPE_ID(editor->document->file_type) == GEANY_FILETYPES_PYTHON) + size += iprefs->width * get_python_indent(sci, line); + } + return size; +} + + +static void insert_indent_after_line(GeanyEditor *editor, gint line) +{ + ScintillaObject *sci = editor->sci; + gint size = get_indent_size_after_line(editor, line); + const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor); + + if (size > 0) + { + gchar *text; + + text = get_whitespace(iprefs, size); + sci_add_text(sci, text); + g_free(text); + } +} + + static void auto_close_bracket(ScintillaObject *sci, gint pos, gchar c) { if (! editor_prefs.complete_snippets || SSM(sci, SCI_GETLEXER, 0, 0) != SCLEX_LATEX) @@ -956,7 +1026,7 @@ static void auto_close_bracket(ScintillaObject *sci, gint pos, gchar c) /* Finds a corresponding matching brace to the given pos * (this is taken from Scintilla Editor.cxx, - * fit to work with editor_close_block) */ + * fit to work with close_block) */ static gint brace_match(ScintillaObject *sci, gint pos) { gchar chBrace = sci_get_char_at(sci, pos); @@ -994,9 +1064,10 @@ static gint brace_match(ScintillaObject *sci, gint pos) /* Called after typing '}'. */ -void editor_close_block(GeanyDocument *doc, gint pos) +static void close_block(GeanyEditor *editor, gint pos) { - const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(doc->editor); + GeanyDocument *doc = editor->document; + const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor); gint x = 0, cnt = 0; gint line, line_len, eol_char_len; gchar *text, *line_buf; @@ -1039,13 +1110,16 @@ void editor_close_block(GeanyDocument *doc, gint pos) if (start_brace >= 0) { gint line_start; + gint brace_line = sci_get_line_from_position(sci, start_brace); + gint size = sci_get_line_indentation(sci, brace_line); + gchar *ind = get_whitespace(iprefs, size); - get_indent(doc->editor, start_brace, TRUE); - text = g_strconcat(indent, "}", NULL); + text = g_strconcat(ind, "}", NULL); line_start = sci_get_position_from_line(sci, line); sci_set_anchor(sci, line_start); SSM(sci, SCI_REPLACESEL, 0, (sptr_t) text); g_free(text); + g_free(ind); return; } /* fall through - unmatched brace (possibly because of TCL, PHP lexer bugs) */ diff --git a/src/editor.h b/src/editor.h index c1006ea3..d9ca9b21 100644 --- a/src/editor.h +++ b/src/editor.h @@ -150,8 +150,6 @@ void on_editor_notification(GtkWidget* editor, gint scn, gpointer lscn, gpointer gboolean editor_start_auto_complete(GeanyDocument *doc, gint pos, gboolean force); -void editor_close_block(GeanyDocument *doc, gint pos); - gboolean editor_complete_snippet(GeanyDocument *doc, gint pos); void editor_auto_latex(GeanyDocument *doc, gint pos); From 51badbd829000d59b3dbfd65b5df349a5acde80d Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Thu, 7 Aug 2008 11:49:06 +0000 Subject: [PATCH 19/22] Set 'Detect from file' indent type setting insensitive when Tabs & Spaces is set. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2859 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 7 +++++++ geany.glade | 1 + src/callbacks.c | 12 ++++++++++++ src/callbacks.h | 4 ++++ src/interface.c | 4 ++++ 5 files changed, 28 insertions(+) diff --git a/ChangeLog b/ChangeLog index 862b0557..da51204b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-08-07 Nick Treleaven + + * src/interface.c, src/callbacks.c, src/callbacks.h, geany.glade: + Set 'Detect from file' indent type setting insensitive when Tabs & + Spaces is set. + + 2008-08-05 Nick Treleaven * src/editor.c, src/editor.h: diff --git a/geany.glade b/geany.glade index ccefa21d..fd75a0df 100644 --- a/geany.glade +++ b/geany.glade @@ -5557,6 +5557,7 @@ Match braces False True radio_indent_spaces + 1 diff --git a/src/callbacks.c b/src/callbacks.c index 264edc5c..71d00552 100644 --- a/src/callbacks.c +++ b/src/callbacks.c @@ -2216,3 +2216,15 @@ on_menu_reload_configuration1_activate (GtkMenuItem *menuitem, main_reload_configuration(); } + +void +on_radio_indent_both_toggled (GtkToggleButton *togglebutton, + gpointer user_data) +{ + GtkWidget *check = lookup_widget(ui_widgets.prefs_dialog, "check_detect_indent"); + gboolean active; + + active = gtk_toggle_button_get_active(togglebutton); + gtk_widget_set_sensitive(check, !active); +} + diff --git a/src/callbacks.h b/src/callbacks.h index 4ec2ee31..b6d194e7 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -630,3 +630,7 @@ on_find_document_usage1_activate (GtkMenuItem *menuitem, void on_tabs_and_spaces1_activate (GtkMenuItem *menuitem, gpointer user_data); + +void +on_radio_indent_both_toggled (GtkToggleButton *togglebutton, + gpointer user_data); diff --git a/src/interface.c b/src/interface.c index 5a246038..54b4496a 100644 --- a/src/interface.c +++ b/src/interface.c @@ -4785,6 +4785,10 @@ create_prefs_dialog (void) gtk_dialog_add_action_widget (GTK_DIALOG (prefs_dialog), button5, GTK_RESPONSE_OK); GTK_WIDGET_SET_FLAGS (button5, GTK_CAN_DEFAULT); + g_signal_connect ((gpointer) radio_indent_both, "toggled", + G_CALLBACK (on_radio_indent_both_toggled), + NULL); + /* Store pointers to all widgets, for use by lookup_widget(). */ GLADE_HOOKUP_OBJECT_NO_REF (prefs_dialog, prefs_dialog, "prefs_dialog"); GLADE_HOOKUP_OBJECT_NO_REF (prefs_dialog, dialog_vbox3, "dialog_vbox3"); From 2bc72a08c308c3194ebf06a1e496bb2c8e7f09f7 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Thu, 7 Aug 2008 12:03:56 +0000 Subject: [PATCH 20/22] Remove opening-brace indent code from get_indent() as it's now in get_brace_indent(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2860 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 3 ++ src/editor.c | 82 +++++++++------------------------------------------- 2 files changed, 17 insertions(+), 68 deletions(-) diff --git a/ChangeLog b/ChangeLog index da51204b..11ea558b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,9 @@ * src/interface.c, src/callbacks.c, src/callbacks.h, geany.glade: Set 'Detect from file' indent type setting insensitive when Tabs & Spaces is set. + * src/editor.c: + Remove opening-brace indent code from get_indent() as it's now in + get_brace_indent(). 2008-08-05 Nick Treleaven diff --git a/src/editor.c b/src/editor.c index 408debc6..a48612cd 100644 --- a/src/editor.c +++ b/src/editor.c @@ -74,7 +74,7 @@ static gchar indent[100]; static void on_new_line_added(GeanyEditor *editor); static gboolean handle_xml(GeanyEditor *editor, gchar ch); -static void get_indent(GeanyEditor *editor, gint pos, gboolean use_this_line); +static void get_indent(GeanyEditor *editor, gint pos); static void insert_indent_after_line(GeanyEditor *editor, gint line); static void auto_multiline(GeanyEditor *editor, gint pos); static gboolean is_comment(gint lexer, gint prev_style, gint style); @@ -835,45 +835,20 @@ static gboolean lexer_has_braces(ScintillaObject *sci) } -/* in place indentation of one tab or equivalent spaces. - * idx is the index into buf. */ -static void do_indent(const GeanyIndentPrefs *iprefs, gchar *buf, gsize len, guint *idx) -{ - guint j = *idx; - - if (iprefs->type == GEANY_INDENT_TYPE_TABS) - { - if (j < len - 1) /* leave room for a \0 terminator. */ - buf[j++] = '\t'; - } - else - { - /* insert as many spaces as an indent takes. - * TODO: insert tabs for GEANY_INDENT_TYPE_BOTH */ - guint k; - for (k = 0; k < (guint) iprefs->width && k < len - 1; k++) - buf[j++] = ' '; - } - *idx = j; -} - - -/* "use_this_line" to auto-indent only if it is a real new line - * and ignore the case of close_block */ -static void get_indent(GeanyEditor *editor, gint pos, gboolean use_this_line) +/* Read indent chars for the line that pos is on into indent global variable. + * Note: Use sci_get_line_indentation() and get_whitespace() instead in any new code. */ +static void get_indent(GeanyEditor *editor, gint pos) { ScintillaObject *sci = editor->sci; guint i, len, j = 0; - gint prev_line; + gint line; gchar *linebuf; const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor); - prev_line = sci_get_line_from_position(sci, pos); + line = sci_get_line_from_position(sci, pos); - if (! use_this_line) - prev_line--; - len = sci_get_line_length(sci, prev_line); - linebuf = sci_get_line(sci, prev_line); + len = sci_get_line_length(sci, line); + linebuf = sci_get_line(sci, line); for (i = 0; i < len && j <= (sizeof(indent) - 1); i++) { @@ -881,35 +856,6 @@ static void get_indent(GeanyEditor *editor, gint pos, gboolean use_this_line) indent[j++] = linebuf[i]; else if (iprefs->auto_indent_mode <= GEANY_AUTOINDENT_BASIC) break; - else if (use_this_line) - break; - else /* close_block */ - { - if (! lexer_has_braces(sci)) - break; - - /* i == (len - 1) prevents wrong indentation after lines like - * " { return bless({}, shift); }" (Perl) */ - if (linebuf[i] == '{' && i == (len - 1)) - { - do_indent(iprefs, indent, sizeof(indent), &j); - break; - } - else - { - gint k = len - 1; - - while (k > 0 && isspace(linebuf[k])) k--; - - /* if last non-whitespace character is a { increase indentation by a tab - * e.g. for (...) { */ - if (linebuf[k] == '{') - { - do_indent(iprefs, indent, sizeof(indent), &j); - } - break; - } - } } indent[j] = '\0'; g_free(linebuf); @@ -1596,7 +1542,7 @@ void editor_auto_latex(GeanyDocument *doc, gint pos) /* get the indentation */ if (editor->auto_indent) - get_indent(editor, pos, TRUE); + get_indent(editor, pos); eol = g_strconcat(editor_get_eol_char(doc), indent, NULL); construct = g_strdup_printf("%s\\end%s{%s}", eol, full_cmd, env); @@ -1703,7 +1649,7 @@ static gboolean snippets_complete_constructs(GeanyEditor *editor, gint pos, cons return FALSE; } - get_indent(editor, pos, TRUE); + get_indent(editor, pos); lindent = g_strconcat(editor_get_eol_char(editor->document), indent, NULL); whitespace = get_single_indent(editor); @@ -1933,7 +1879,7 @@ static void auto_table(GeanyEditor *editor, gint pos) if (SSM(sci, SCI_GETLEXER, 0, 0) != SCLEX_HTML) return; - get_indent(editor, pos, TRUE); + get_indent(editor, pos); indent_pos = sci_get_line_indent_position(sci, sci_get_line_from_position(sci, pos)); if ((pos - 7) != indent_pos) /* 7 == strlen("") */ { @@ -2326,7 +2272,7 @@ void editor_do_comment_toggle(GeanyDocument *doc) gint a = (first_line_was_comment) ? - co_len : co_len; /* don't modify sel_start when the selection starts within indentation */ - get_indent(doc->editor, sel_start, TRUE); + get_indent(doc->editor, sel_start); if ((sel_start - first_line_start) <= (gint) strlen(indent)) a = 0; @@ -2833,7 +2779,7 @@ void editor_insert_multiline_comment(GeanyDocument *doc) if (editor->auto_indent && ! have_multiline_comment && doc->file_type->comment_use_indent) { - get_indent(editor, editor_info.click_pos, TRUE); + get_indent(editor, editor_info.click_pos); text = g_strdup_printf("%s\n%s\n%s\n", indent, indent, indent); text_len = strlen(text); } @@ -3093,7 +3039,7 @@ void editor_smart_line_indentation(GeanyDocument *doc, gint pos) /* get previous line and use it for get_indent to use that line * (otherwise it would fail on a line only containing "{" in advanced indentation mode) */ - get_indent(doc->editor, sci_get_position_from_line(sci, first_line - 1), TRUE); + get_indent(doc->editor, sci_get_position_from_line(sci, first_line - 1)); smart_line_indentation(doc, first_line, last_line); From a6eac00cc13ff002ff2e36a70d42b12896c4a2d9 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Thu, 7 Aug 2008 15:30:52 +0000 Subject: [PATCH 21/22] Add editor_get_indent_prefs() to the API. Make editor_get_indent_prefs() return default prefs if editor is NULL. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2861 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 4 ++++ src/editor.c | 11 +++++++---- src/plugindata.h | 2 ++ src/plugins.c | 3 ++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 11ea558b..76da18bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,10 @@ * src/editor.c: Remove opening-brace indent code from get_indent() as it's now in get_brace_indent(). + * src/plugindata.h, src/plugins.c, src/editor.c: + Add editor_get_indent_prefs() to the API. + Make editor_get_indent_prefs() return default prefs if editor is + NULL. 2008-08-05 Nick Treleaven diff --git a/src/editor.c b/src/editor.c index a48612cd..f5bf57c1 100644 --- a/src/editor.c +++ b/src/editor.c @@ -753,7 +753,7 @@ get_whitespace(const GeanyIndentPrefs *iprefs, gint width) static const GeanyIndentPrefs * get_default_indent_prefs(void) { - /* In future this might depend on project or filetype. */ + /* In future this might depend on the current project. */ return editor_prefs.indentation; } @@ -761,16 +761,19 @@ get_default_indent_prefs(void) /** Get the indentation prefs for the editor. * In future, the prefs might be different according to project or filetype. * @warning Always get a fresh result instead of keeping a pointer to it if the editor - * settings may have changed, or if this function has been called for a different @a editor. */ + * settings may have changed, or if this function has been called for a different @a editor. + * @param editor The editor, or @c NULL to get the default indent prefs. + * @return The indent prefs. */ const GeanyIndentPrefs * editor_get_indent_prefs(GeanyEditor *editor) { static GeanyIndentPrefs iprefs; - g_return_val_if_fail(editor != NULL, NULL); - iprefs = *get_default_indent_prefs(); + if (!editor) + return &iprefs; + iprefs.type = editor->indent_type; if (!editor->auto_indent) iprefs.auto_indent_mode = GEANY_AUTOINDENT_NONE; diff --git a/src/plugindata.h b/src/plugindata.h index a8b6b932..8370adf1 100644 --- a/src/plugindata.h +++ b/src/plugindata.h @@ -444,6 +444,8 @@ typedef struct EditorFuncs void (*set_indicator) (struct GeanyEditor *editor, gint start, gint end); void (*set_indicator_on_line) (struct GeanyEditor *editor, gint line); void (*clear_indicators) (struct GeanyEditor *editor); + + const struct GeanyIndentPrefs* (*get_indent_prefs)(struct GeanyEditor *editor); /* Remember to convert any GeanyDocument or ScintillaObject pointers in any * appended functions to GeanyEditor pointers. */ } diff --git a/src/plugins.c b/src/plugins.c index 6f623e1e..8f944406 100644 --- a/src/plugins.c +++ b/src/plugins.c @@ -114,7 +114,8 @@ static DocumentFuncs doc_funcs = { static EditorFuncs editor_funcs = { &editor_set_indicator, &editor_set_indicator_on_line, - &editor_clear_indicators + &editor_clear_indicators, + &editor_get_indent_prefs }; static ScintillaFuncs sci_funcs = { From ec1e9de8dc87dde3fc52028069a84bba48cceea7 Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Thu, 7 Aug 2008 15:32:56 +0000 Subject: [PATCH 22/22] Fix using editor_get_indent_prefs(). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/branches/custom-tab-width@2862 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 2 ++ plugins/export.c | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 76da18bc..30ded01b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,8 @@ Add editor_get_indent_prefs() to the API. Make editor_get_indent_prefs() return default prefs if editor is NULL. + * plugins/export.c: + Fix using editor_get_indent_prefs(). 2008-08-05 Nick Treleaven diff --git a/plugins/export.c b/plugins/export.c index dffb9257..76b7ebef 100644 --- a/plugins/export.c +++ b/plugins/export.c @@ -347,6 +347,7 @@ static void on_file_save_dialog_response(GtkDialog *dialog, gint response, gpoin static void write_latex_file(GeanyDocument *doc, const gchar *filename, gboolean use_zoom) { + GeanyEditor *editor = doc->editor; gint i, style = -1, old_style = 0, column = 0; gchar c, c_next, *tmp; /* 0 - fore, 1 - back, 2 - bold, 3 - italic, 4 - font size, 5 - used(0/1) */ @@ -408,8 +409,8 @@ static void write_latex_file(GeanyDocument *doc, const gchar *filename, gboolean } case '\t': { - gint tab_stop = geany->editor_prefs->tab_width - - (column % geany->editor_prefs->tab_width); + gint tab_width = p_editor->get_indent_prefs(editor)->tab_width; + gint tab_stop = tab_width - (column % tab_width); column += tab_stop - 1; /* -1 because we add 1 at the end of the loop */ g_string_append_printf(body, "\\hspace*{%dem}", tab_stop); @@ -551,6 +552,7 @@ static void write_latex_file(GeanyDocument *doc, const gchar *filename, gboolean static void write_html_file(GeanyDocument *doc, const gchar *filename, gboolean use_zoom) { + GeanyEditor *editor = doc->editor; gint i, style = -1, old_style = 0, column = 0; gchar c, c_next; /* 0 - fore, 1 - back, 2 - bold, 3 - italic, 4 - font size, 5 - used(0/1) */ @@ -625,8 +627,8 @@ static void write_html_file(GeanyDocument *doc, const gchar *filename, gboolean case '\t': { gint j; - gint tab_stop = geany->editor_prefs->tab_width - - (column % geany->editor_prefs->tab_width); + gint tab_width = p_editor->get_indent_prefs(editor)->tab_width; + gint tab_stop = tab_width - (column % tab_width); column += tab_stop - 1; /* -1 because we add 1 at the end of the loop */ for (j = 0; j < tab_stop; j++)