From 7c27b1e0095a4e248d8b9e4fe50666cadd075dcb Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 10 Mar 2010 16:20:34 +0000 Subject: [PATCH] Apply patch from Eugene Arshinov to add project long line marker customisation (thanks). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@4751 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 5 + geany.glade | 292 +++++++++++++++++++++++++++++++++++++++++++++++------- src/editor.c | 33 +++++- src/editor.h | 18 +++- src/interface.c | 122 ++++++++++++++++++++--- src/keybindings.c | 4 +- src/keyfile.c | 16 ++- src/plugindata.h | 2 +- src/prefs.c | 31 +++--- src/project.c | 70 ++++++++++++- src/project.h | 4 +- 11 files changed, 515 insertions(+), 82 deletions(-) diff --git a/ChangeLog b/ChangeLog index 14558564e..139dfca4c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,11 @@ * doc/geany.txt, doc/geany.html: Warn about some GNU extensions for regular expressions & clarify some points. + * src/interface.c, src/keybindings.c, src/project.c, src/project.h, + src/prefs.c, src/plugindata.h, src/keyfile.c, src/editor.c, + src/editor.h, geany.glade: + Apply patch from Eugene Arshinov to add project long line marker + customisation (thanks). 2010-03-10 Lex Trotman diff --git a/geany.glade b/geany.glade index 1198170f0..483b5054f 100644 --- a/geany.glade +++ b/geany.glade @@ -7057,26 +7057,6 @@ Match braces False - - - - True - True - Disabled - True - GTK_RELIEF_NORMAL - True - False - False - True - radio_long_line_line - - - 0 - False - False - - 1 @@ -7093,22 +7073,16 @@ Match braces - + True - <b>Long line marker</b> - False - True - GTK_JUSTIFY_LEFT - False - False - 0.5 - 0.5 - 0 - 0 - PANGO_ELLIPSIZE_NONE - -1 - False - 0 + True + Long line marker + True + GTK_RELIEF_NORMAL + True + False + False + True label_item @@ -9966,6 +9940,254 @@ Match braces tab + + + + 6 + True + False + 3 + + + + True + 0 + 0.5 + GTK_SHADOW_NONE + + + + True + 0.5 + 0.5 + 1 + 1 + 0 + 0 + 12 + 0 + + + + True + 4 + 2 + False + 3 + 12 + + + + True + Display: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + Long line marker: + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + 0 + 1 + 3 + 4 + fill + + + + + + + True + True + Disabled + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 1 + 2 + 0 + 1 + fill + + + + + + + True + True + Custom + True + GTK_RELIEF_NORMAL + True + False + False + True + radio_long_line_disabled + + + 1 + 2 + 2 + 3 + fill + + + + + + + True + True + Use global settings + True + GTK_RELIEF_NORMAL + True + False + False + True + radio_long_line_disabled + + + 1 + 2 + 1 + 2 + fill + + + + + + + True + True + 1 + 0 + True + GTK_UPDATE_ALWAYS + False + True + 72 0 1000 1 10 0 + + + 1 + 2 + 3 + 4 + fill + + + + + + + + + + + True + <b>Long line marker</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + label_item + + + + + 0 + False + True + + + + + + + + + False + True + + + + + + True + Editor + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + PANGO_ELLIPSIZE_NONE + -1 + False + 0 + + + tab + + 0 diff --git a/src/editor.c b/src/editor.c index 58fae2d9c..97837f012 100644 --- a/src/editor.c +++ b/src/editor.c @@ -272,6 +272,35 @@ static gboolean is_style_php(gint style) } +gint editor_get_long_line_type(void) +{ + if (app->project) + switch (app->project->long_line_behaviour) + { + case 0: /* marker disabled */ + return 2; + case 1: /* use global settings */ + break; + case 2: /* custom (enabled) */ + return editor_prefs.long_line_global_type; + } + + if (!editor_prefs.long_line_global_enabled) + return 2; + else + return editor_prefs.long_line_global_type; +} + + +gint editor_get_long_line_column(void) +{ + if (app->project && app->project->long_line_behaviour != 1 /* use global settings */) + return app->project->long_line_column; + else + return editor_prefs.long_line_global_column; +} + + void editor_toggle_fold(GeanyEditor *editor, gint line, gint modifiers) { ScintillaObject *sci; @@ -4850,8 +4879,8 @@ void editor_apply_update_prefs(GeanyEditor *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_mark_long_lines(sci, editor_get_long_line_type(), + editor_get_long_line_column(), editor_prefs.long_line_color); /* update indent width, tab width */ editor_set_indent_type(editor, editor->indent_type); diff --git a/src/editor.h b/src/editor.h index eaf3a5877..38f8e9df6 100644 --- a/src/editor.h +++ b/src/editor.h @@ -100,16 +100,19 @@ typedef struct GeanyIndentPrefs GeanyIndentPrefs; -/* Default prefs when creating a new editor window. - * Some of these can be overridden per document. */ +/** Default prefs when creating a new editor window. + * Some of these can be overridden per document or per project. */ typedef struct GeanyEditorPrefs { GeanyIndentPrefs *indentation; /*< Default indentation prefs. @see editor_get_indent_prefs(). */ gboolean show_white_space; gboolean show_indent_guide; gboolean show_line_endings; - gint long_line_type; /* 0 - line, 1 - background, 2 - none */ - gint long_line_column; + /* 0 - line, 1 - background. This setting may be overriden when a project is opened. Use + * @c editor_get_long_line_type(). */ + gint long_line_global_type; + /* This setting may be overriden when a project is opened. Use @c editor_get_long_line_column(). */ + gint long_line_global_column; gchar *long_line_color; gboolean show_markers_margin; /* view menu */ gboolean show_linenumber_margin; /* view menu */ @@ -140,6 +143,8 @@ typedef struct GeanyEditorPrefs gboolean completion_drops_rest_of_word; gchar *color_scheme; gint show_virtual_space; + /* This setting may be overriden when a project is opened. Use @c editor_get_long_line_type(). */ + gboolean long_line_global_enabled; } GeanyEditorPrefs; @@ -223,6 +228,11 @@ void editor_snippets_init(void); void editor_snippets_free(void); +/* 0 - line, 1 - background, 2 - disabled */ +gint editor_get_long_line_type(void); + +gint editor_get_long_line_column(void); + /* General editing functions */ void editor_find_current_word(GeanyEditor *editor, gint pos, gchar *word, size_t wordlen, diff --git a/src/interface.c b/src/interface.c index 96518d77a..af8270612 100644 --- a/src/interface.c +++ b/src/interface.c @@ -2579,8 +2579,7 @@ create_prefs_dialog (void) GtkWidget *radio_long_line_line; GSList *radio_long_line_line_group = NULL; GtkWidget *radio_long_line_background; - GtkWidget *radio_long_line_disabled; - GtkWidget *label155; + GtkWidget *check_long_line; GtkWidget *frame40; GtkWidget *alignment47; GtkWidget *vbox48; @@ -4003,16 +4002,9 @@ create_prefs_dialog (void) gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_long_line_background), radio_long_line_line_group); radio_long_line_line_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_long_line_background)); - radio_long_line_disabled = gtk_radio_button_new_with_mnemonic (NULL, _("Disabled")); - gtk_widget_show (radio_long_line_disabled); - gtk_box_pack_start (GTK_BOX (hbox5), radio_long_line_disabled, FALSE, FALSE, 0); - gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_long_line_disabled), radio_long_line_line_group); - radio_long_line_line_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_long_line_disabled)); - - label155 = gtk_label_new (_("Long line marker")); - gtk_widget_show (label155); - gtk_frame_set_label_widget (GTK_FRAME (frame8), label155); - gtk_label_set_use_markup (GTK_LABEL (label155), TRUE); + check_long_line = gtk_check_button_new_with_mnemonic (_("Long line marker")); + gtk_widget_show (check_long_line); + gtk_frame_set_label_widget (GTK_FRAME (frame8), check_long_line); frame40 = gtk_frame_new (NULL); gtk_widget_show (frame40); @@ -4993,8 +4985,7 @@ create_prefs_dialog (void) GLADE_HOOKUP_OBJECT (prefs_dialog, hbox5, "hbox5"); GLADE_HOOKUP_OBJECT (prefs_dialog, radio_long_line_line, "radio_long_line_line"); GLADE_HOOKUP_OBJECT (prefs_dialog, radio_long_line_background, "radio_long_line_background"); - GLADE_HOOKUP_OBJECT (prefs_dialog, radio_long_line_disabled, "radio_long_line_disabled"); - GLADE_HOOKUP_OBJECT (prefs_dialog, label155, "label155"); + GLADE_HOOKUP_OBJECT (prefs_dialog, check_long_line, "check_long_line"); GLADE_HOOKUP_OBJECT (prefs_dialog, frame40, "frame40"); GLADE_HOOKUP_OBJECT (prefs_dialog, alignment47, "alignment47"); GLADE_HOOKUP_OBJECT (prefs_dialog, vbox48, "vbox48"); @@ -5164,6 +5155,20 @@ create_project_dialog (void) GtkObject *spin_tab_width_adj; GtkWidget *spin_tab_width; GtkWidget *label227; + GtkWidget *vbox47; + GtkWidget *frame40; + GtkWidget *alignment48; + GtkWidget *table18; + GtkWidget *label241; + GtkWidget *label240; + GtkWidget *radio_long_line_disabled; + GSList *radio_long_line_disabled_group = NULL; + GtkWidget *radio_long_line_custom; + GtkWidget *radio_long_line_default; + GtkObject *spin_long_line_adj; + GtkWidget *spin_long_line; + GtkWidget *label239; + GtkWidget *label238; GtkWidget *dialog_action_area4; GtkWidget *cancelbutton1; GtkWidget *okbutton1; @@ -5293,6 +5298,83 @@ create_project_dialog (void) gtk_widget_show (label227); gtk_notebook_set_tab_label (GTK_NOTEBOOK (project_notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (project_notebook), 0), label227); + vbox47 = gtk_vbox_new (FALSE, 3); + gtk_widget_show (vbox47); + gtk_container_add (GTK_CONTAINER (project_notebook), vbox47); + gtk_container_set_border_width (GTK_CONTAINER (vbox47), 6); + + frame40 = gtk_frame_new (NULL); + gtk_widget_show (frame40); + gtk_box_pack_start (GTK_BOX (vbox47), frame40, FALSE, TRUE, 0); + gtk_frame_set_shadow_type (GTK_FRAME (frame40), GTK_SHADOW_NONE); + + alignment48 = gtk_alignment_new (0.5, 0.5, 1, 1); + gtk_widget_show (alignment48); + gtk_container_add (GTK_CONTAINER (frame40), alignment48); + gtk_alignment_set_padding (GTK_ALIGNMENT (alignment48), 0, 0, 12, 0); + + table18 = gtk_table_new (4, 2, FALSE); + gtk_widget_show (table18); + gtk_container_add (GTK_CONTAINER (alignment48), table18); + gtk_table_set_row_spacings (GTK_TABLE (table18), 3); + gtk_table_set_col_spacings (GTK_TABLE (table18), 12); + + label241 = gtk_label_new (_("Display:")); + gtk_widget_show (label241); + gtk_table_attach (GTK_TABLE (table18), label241, 0, 1, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label241), 0, 0.5); + + label240 = gtk_label_new (_("Long line marker:")); + gtk_widget_show (label240); + gtk_table_attach (GTK_TABLE (table18), label240, 0, 1, 3, 4, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_misc_set_alignment (GTK_MISC (label240), 0, 0.5); + + radio_long_line_disabled = gtk_radio_button_new_with_mnemonic (NULL, _("Disabled")); + gtk_widget_show (radio_long_line_disabled); + gtk_table_attach (GTK_TABLE (table18), radio_long_line_disabled, 1, 2, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_long_line_disabled), radio_long_line_disabled_group); + radio_long_line_disabled_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_long_line_disabled)); + + radio_long_line_custom = gtk_radio_button_new_with_mnemonic (NULL, _("Custom")); + gtk_widget_show (radio_long_line_custom); + gtk_table_attach (GTK_TABLE (table18), radio_long_line_custom, 1, 2, 2, 3, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_long_line_custom), radio_long_line_disabled_group); + radio_long_line_disabled_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_long_line_custom)); + + radio_long_line_default = gtk_radio_button_new_with_mnemonic (NULL, _("Use global settings")); + gtk_widget_show (radio_long_line_default); + gtk_table_attach (GTK_TABLE (table18), radio_long_line_default, 1, 2, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_long_line_default), radio_long_line_disabled_group); + radio_long_line_disabled_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_long_line_default)); + + spin_long_line_adj = gtk_adjustment_new (72, 0, 1000, 1, 10, 0); + spin_long_line = gtk_spin_button_new (GTK_ADJUSTMENT (spin_long_line_adj), 1, 0); + gtk_widget_show (spin_long_line); + gtk_table_attach (GTK_TABLE (table18), spin_long_line, 1, 2, 3, 4, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (0), 0, 0); + gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin_long_line), TRUE); + gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spin_long_line), TRUE); + + label239 = gtk_label_new (_("Long line marker")); + gtk_widget_show (label239); + gtk_frame_set_label_widget (GTK_FRAME (frame40), label239); + gtk_label_set_use_markup (GTK_LABEL (label239), TRUE); + + label238 = gtk_label_new (_("Editor")); + gtk_widget_show (label238); + gtk_notebook_set_tab_label (GTK_NOTEBOOK (project_notebook), gtk_notebook_get_nth_page (GTK_NOTEBOOK (project_notebook), 1), label238); + dialog_action_area4 = GTK_DIALOG (project_dialog)->action_area; gtk_widget_show (dialog_action_area4); gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area4), GTK_BUTTONBOX_END); @@ -5326,6 +5408,18 @@ create_project_dialog (void) GLADE_HOOKUP_OBJECT (project_dialog, label231, "label231"); GLADE_HOOKUP_OBJECT (project_dialog, spin_tab_width, "spin_tab_width"); GLADE_HOOKUP_OBJECT (project_dialog, label227, "label227"); + GLADE_HOOKUP_OBJECT (project_dialog, vbox47, "vbox47"); + GLADE_HOOKUP_OBJECT (project_dialog, frame40, "frame40"); + GLADE_HOOKUP_OBJECT (project_dialog, alignment48, "alignment48"); + GLADE_HOOKUP_OBJECT (project_dialog, table18, "table18"); + GLADE_HOOKUP_OBJECT (project_dialog, label241, "label241"); + GLADE_HOOKUP_OBJECT (project_dialog, label240, "label240"); + GLADE_HOOKUP_OBJECT (project_dialog, radio_long_line_disabled, "radio_long_line_disabled"); + GLADE_HOOKUP_OBJECT (project_dialog, radio_long_line_custom, "radio_long_line_custom"); + GLADE_HOOKUP_OBJECT (project_dialog, radio_long_line_default, "radio_long_line_default"); + GLADE_HOOKUP_OBJECT (project_dialog, spin_long_line, "spin_long_line"); + GLADE_HOOKUP_OBJECT (project_dialog, label239, "label239"); + GLADE_HOOKUP_OBJECT (project_dialog, label238, "label238"); GLADE_HOOKUP_OBJECT_NO_REF (project_dialog, dialog_action_area4, "dialog_action_area4"); GLADE_HOOKUP_OBJECT (project_dialog, cancelbutton1, "cancelbutton1"); GLADE_HOOKUP_OBJECT (project_dialog, okbutton1, "okbutton1"); diff --git a/src/keybindings.c b/src/keybindings.c index e9c96678a..2645f3ea4 100644 --- a/src/keybindings.c +++ b/src/keybindings.c @@ -2339,10 +2339,10 @@ static void reflow_paragraph(GeanyEditor *editor) /* use line break column if enabled */ column = editor_prefs.line_break_column; } - else if (editor_prefs.long_line_type != 2) + else if (editor_get_long_line_type() != 2) { /* use long line if enabled */ - column = editor_prefs.long_line_column; + column = editor_get_long_line_column(); } else { diff --git a/src/keyfile.c b/src/keyfile.c index 813e661f6..c229f0563 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -368,8 +368,9 @@ static void save_dialog_prefs(GKeyFile *config) g_key_file_set_boolean(config, PACKAGE, "show_line_endings", editor_prefs.show_line_endings); g_key_file_set_boolean(config, PACKAGE, "show_markers_margin", editor_prefs.show_markers_margin); g_key_file_set_boolean(config, PACKAGE, "show_linenumber_margin", editor_prefs.show_linenumber_margin); - g_key_file_set_integer(config, PACKAGE, "long_line_type", editor_prefs.long_line_type); - g_key_file_set_integer(config, PACKAGE, "long_line_column", editor_prefs.long_line_column); + g_key_file_set_boolean(config, PACKAGE, "long_line_enabled", editor_prefs.long_line_global_enabled); + g_key_file_set_integer(config, PACKAGE, "long_line_type", editor_prefs.long_line_global_type); + g_key_file_set_integer(config, PACKAGE, "long_line_column", editor_prefs.long_line_global_column); g_key_file_set_string(config, PACKAGE, "long_line_color", editor_prefs.long_line_color); /* editor */ @@ -660,9 +661,15 @@ static void load_dialog_prefs(GKeyFile *config) interface_prefs.msgwin_scribble_visible = utils_get_setting_boolean(config, PACKAGE, "msgwin_scribble_visible", TRUE); /* display, editor */ - editor_prefs.long_line_type = utils_get_setting_integer(config, PACKAGE, "long_line_type", 0); + editor_prefs.long_line_global_enabled = utils_get_setting_boolean(config, PACKAGE, "long_line_enabled", TRUE); + editor_prefs.long_line_global_type = utils_get_setting_integer(config, PACKAGE, "long_line_type", 0); + if (editor_prefs.long_line_global_type == 2) /* backward compatibility */ + { + editor_prefs.long_line_global_type = 0; + editor_prefs.long_line_global_enabled = FALSE; + } editor_prefs.long_line_color = utils_get_setting_string(config, PACKAGE, "long_line_color", "#C2EBC2"); - editor_prefs.long_line_column = utils_get_setting_integer(config, PACKAGE, "long_line_column", 72); + editor_prefs.long_line_global_column = utils_get_setting_integer(config, PACKAGE, "long_line_column", 72); 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 */ @@ -1112,4 +1119,3 @@ void configuration_finalize(void) g_ptr_array_free(keyfile_groups, TRUE); g_ptr_array_free(pref_groups, TRUE); } - diff --git a/src/plugindata.h b/src/plugindata.h index aa18a310e..185043c66 100644 --- a/src/plugindata.h +++ b/src/plugindata.h @@ -50,7 +50,7 @@ enum { /** The Application Programming Interface (API) version, incremented * whenever any plugin data types are modified or appended to. */ - GEANY_API_VERSION = 175, + GEANY_API_VERSION = 176, /** The Application Binary Interface (ABI) version, incremented whenever * existing fields in the plugin data types have to be changed or reordered. */ diff --git a/src/prefs.c b/src/prefs.c index 908ed5abe..03c351b46 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -399,13 +399,15 @@ static void prefs_init_dialog(void) gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), interface_prefs.editor_font); widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_long_line"); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), editor_prefs.long_line_column); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), editor_prefs.long_line_global_column); - switch (editor_prefs.long_line_type) + widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_long_line"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.long_line_global_enabled); + + switch (editor_prefs.long_line_global_type) { case 0: widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_long_line_line"); break; case 1: widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_long_line_background"); break; - default: widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_long_line_disabled"); break; } gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE); @@ -806,18 +808,18 @@ on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_data) widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_list_openfiles"); interface_prefs.sidebar_openfiles_visible = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); + widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_long_line"); + editor_prefs.long_line_global_enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); + widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_long_line_line"); - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) editor_prefs.long_line_type = 0; + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) + editor_prefs.long_line_global_type = 0; else - { - widget = ui_lookup_widget(ui_widgets.prefs_dialog, "radio_long_line_background"); - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) editor_prefs.long_line_type = 1; - else - { /* now only the disabled radio remains, so disable it */ - editor_prefs.long_line_type = 2; - } - } - if (editor_prefs.long_line_column == 0) editor_prefs.long_line_type = 2; + /* now only the "background" radio remains */ + editor_prefs.long_line_global_type = 1; + + if (editor_prefs.long_line_global_column == 0) + editor_prefs.long_line_global_enabled = FALSE; widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_show_notebook_tabs"); interface_prefs.show_notebook_tabs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); @@ -907,7 +909,7 @@ on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_data) widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_long_line"); /* note: use stash for new code - it updates spin buttons itself */ gtk_spin_button_update(GTK_SPIN_BUTTON(widget)); - editor_prefs.long_line_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); + editor_prefs.long_line_global_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_folding"); editor_prefs.folding = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); @@ -1716,4 +1718,3 @@ void prefs_show_dialog(void) prefs_init_dialog(); gtk_window_present(GTK_WINDOW(ui_widgets.prefs_dialog)); } - diff --git a/src/project.c b/src/project.c index 7a52d7581..f3814561f 100644 --- a/src/project.c +++ b/src/project.c @@ -88,6 +88,8 @@ static gboolean load_config(const gchar *filename); static gboolean write_config(gboolean emit_signal); static void on_name_entry_changed(GtkEditable *editable, PropertyDialogElements *e); static void on_entries_changed(GtkEditable *editable, PropertyDialogElements *e); +static void on_radio_long_line_custom_toggled(GtkToggleButton *radio, GtkWidget *spin_long_line); +static void apply_editor_prefs(); #define SHOW_ERR(args) dialogs_show_msgbox(GTK_MESSAGE_ERROR, args) @@ -367,6 +369,8 @@ void project_close(gboolean open_default) g_free(app->project); app->project = NULL; + apply_editor_prefs(); /* ensure that global settings are restored */ + if (project_prefs.project_session) { /* close all existing tabs first */ @@ -500,6 +504,9 @@ static void create_properties_dialog(PropertyDialogElements *e) (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), (GtkAttachOptions) (GTK_FILL), 0, 0); + g_signal_connect(ui_lookup_widget(e->dialog, "radio_long_line_custom"), "toggled", + G_CALLBACK(on_radio_long_line_custom_toggled), ui_lookup_widget(e->dialog, "spin_long_line")); + #if 0 label = gtk_label_new(_("File patterns:")); /* Separate multiple patterns by a new line */ @@ -531,6 +538,8 @@ void project_properties(void) PropertyDialogElements *e = g_new(PropertyDialogElements, 1); GeanyProject *p = app->project; gint response; + GtkWidget *widget = NULL; + GtkWidget *radio_long_line_custom; g_return_if_fail(app->project != NULL); @@ -542,6 +551,21 @@ void project_properties(void) /* fill the elements with the appropriate data */ gtk_entry_set_text(GTK_ENTRY(e->name), p->name); + gtk_entry_set_text(GTK_ENTRY(e->file_name), p->file_name); + gtk_entry_set_text(GTK_ENTRY(e->base_path), p->base_path); + + radio_long_line_custom = ui_lookup_widget(e->dialog, "radio_long_line_custom"); + switch (p->long_line_behaviour) + { + case 0: widget = ui_lookup_widget(e->dialog, "radio_long_line_disabled"); break; + case 1: widget = ui_lookup_widget(e->dialog, "radio_long_line_default"); break; + case 2: widget = radio_long_line_custom; break; + } + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE); + + widget = ui_lookup_widget(e->dialog, "spin_long_line"); + gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), (gdouble)p->long_line_column); + on_radio_long_line_custom_toggled(GTK_TOGGLE_BUTTON(radio_long_line_custom), widget); if (p->description != NULL) { /* set text */ @@ -570,8 +594,6 @@ void project_properties(void) } #endif - gtk_entry_set_text(GTK_ENTRY(e->file_name), p->file_name); - gtk_entry_set_text(GTK_ENTRY(e->base_path), p->base_path); gtk_widget_show_all(e->dialog); retry: @@ -621,6 +643,9 @@ static GeanyProject *create_project(void) priv.indentation = &indentation; project->priv = &priv; + project->long_line_behaviour = 1 /* use global settings */; + project->long_line_column = editor_prefs.long_line_global_column; + app->project = project; return project; } @@ -729,6 +754,7 @@ static gboolean update_config(const PropertyDialogElements *e) BuildDestination menu_dst; GeanyBuildCommand *oldvalue; GeanyFiletype *ft = NULL; + GtkWidget *widget; /* get and set the project description */ buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e->description)); @@ -764,6 +790,23 @@ static gboolean update_config(const PropertyDialogElements *e) } build_menu_update(doc); + widget = ui_lookup_widget(e->dialog, "radio_long_line_disabled"); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) + p->long_line_behaviour = 0; + else + { + widget = ui_lookup_widget(e->dialog, "radio_long_line_default"); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) + p->long_line_behaviour = 1; + else + /* "Custom" radio button must be checked */ + p->long_line_behaviour = 2; + } + + widget = ui_lookup_widget(e->dialog, "spin_long_line"); + p->long_line_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); + apply_editor_prefs(); + #if 0 /* get and set the project file patterns */ buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e->patterns)); @@ -916,6 +959,12 @@ static void on_entries_changed(GtkEditable *editable, PropertyDialogElements *e) } +static void on_radio_long_line_custom_toggled(GtkToggleButton *radio, GtkWidget *spin_long_line) +{ + gtk_widget_set_sensitive(spin_long_line, gtk_toggle_button_get_active(radio)); +} + + gboolean project_load_file(const gchar *locale_file_name) { g_return_val_if_fail(locale_file_name != NULL, FALSE); @@ -970,6 +1019,10 @@ static gboolean load_config(const gchar *filename) p->base_path = utils_get_setting_string(config, "project", "base_path", ""); p->file_patterns = g_key_file_get_string_list(config, "project", "file_patterns", NULL, NULL); + p->long_line_behaviour = g_key_file_get_integer(config, "long line marker", "long_line_behaviour", NULL); + p->long_line_column = g_key_file_get_integer(config, "long line marker", "long_line_column", NULL); + apply_editor_prefs(); + build_load_menu(config, GEANY_BCS_PROJ, (gpointer)p); if (project_prefs.project_session) { @@ -988,6 +1041,15 @@ static gboolean load_config(const gchar *filename) } +static void apply_editor_prefs() +{ + guint i; + + foreach_document(i) + editor_apply_update_prefs(documents[i]->editor); +} + + /* Write the project settings as well as the project session files into its configuration files. * emit_signal defines whether the project-save signal should be emitted. When write_config() * is called while closing a project, this is used to skip emitting the signal because @@ -1021,6 +1083,9 @@ static gboolean write_config(gboolean emit_signal) g_key_file_set_string_list(config, "project", "file_patterns", (const gchar**) p->file_patterns, g_strv_length(p->file_patterns)); + g_key_file_set_integer(config, "long line marker", "long_line_behaviour", p->long_line_behaviour); + g_key_file_set_integer(config, "long line marker", "long_line_column", p->long_line_column); + /* store the session files into the project too */ if (project_prefs.project_session) configuration_save_session_files(config); @@ -1165,4 +1230,3 @@ void project_finalize(void) { stash_group_free(indent_group); } - diff --git a/src/project.h b/src/project.h index 67c04fb55..508ae290a 100644 --- a/src/project.h +++ b/src/project.h @@ -43,7 +43,9 @@ typedef struct GeanyProject struct GeanyProjectPrivate *priv; /* must be last, append fields before this item */ #ifdef GEANY_PRIVATE /* Do not use following fields in plugins */ - GPtrArray *build_filetypes_list; /* *< Project has custom filetype builds for these. */ + GPtrArray *build_filetypes_list; /* Project has custom filetype builds for these. */ + gint long_line_behaviour; /* 0 - disabled, 1 - follow global settings, 2 - enabled (custom) */ + gint long_line_column; /* Long line marker position. */ #endif } GeanyProject; -- 2.11.4.GIT