Branch: refs/heads/document-messages Author: Nick Treleaven nick.treleaven@btinternet.com Committer: Nick Treleaven nick.treleaven@btinternet.com Date: Thu, 19 Jan 2012 18:17:12 Commit: 21cd7bb2139fd67644e5777bb8e6387d34473d09 https://github.com/geany/geany/commit/21cd7bb2139fd67644e5777bb8e6387d34473d...
Log Message: ----------- Add Project overrides for 'Saving files' checkbox options
Modified Paths: -------------- data/geany.glade src/document.c src/project.c src/project.h src/projectprivate.h
Modified: data/geany.glade 9071 files changed, 4597 insertions(+), 4474 deletions(-) =================================================================== No diff available, check online
Modified: src/document.c 11 files changed, 7 insertions(+), 4 deletions(-) =================================================================== @@ -71,6 +71,7 @@ #include "win32.h" #include "search.h" #include "filetypesprivate.h" +#include "project.h"
#include "SciLexer.h"
@@ -1687,6 +1688,7 @@ gboolean document_save_file(GeanyDocument *doc, gboolean force) gchar *data; gsize len; gchar *locale_filename; + const GeanyFilePrefs *fp;
g_return_val_if_fail(doc != NULL, FALSE);
@@ -1701,17 +1703,18 @@ gboolean document_save_file(GeanyDocument *doc, gboolean force) if (! force && ! ui_prefs.allow_always_save && (! doc->changed || doc->readonly)) return FALSE;
+ fp = project_get_file_prefs(); /* replaces tabs by spaces but only if the current file is not a Makefile */ - if (file_prefs.replace_tabs && doc->file_type->id != GEANY_FILETYPES_MAKE) + if (fp->replace_tabs && doc->file_type->id != GEANY_FILETYPES_MAKE) editor_replace_tabs(doc->editor); /* strip trailing spaces */ - if (file_prefs.strip_trailing_spaces) + if (fp->strip_trailing_spaces) editor_strip_trailing_spaces(doc->editor); /* ensure the file has a newline at the end */ - if (file_prefs.final_new_line) + if (fp->final_new_line) editor_ensure_final_newline(doc->editor); /* ensure newlines are consistent */ - if (file_prefs.ensure_convert_new_lines) + if (fp->ensure_convert_new_lines) sci_convert_eols(doc->editor->sci, sci_get_eol_mode(doc->editor->sci));
/* notify plugins which may wish to modify the document before it's saved */
Modified: src/project.c 97 files changed, 77 insertions(+), 20 deletions(-) =================================================================== @@ -54,14 +54,13 @@ static GeanyProjectPrivate priv; static GeanyIndentPrefs indentation;
-static StashGroup *indent_group = NULL; +static GSList *stash_groups = NULL;
static struct { gchar *project_file_path; /* in UTF-8 */ } local_prefs = { NULL };
- static gboolean entries_modified;
/* simple struct to keep references to the elements of the properties dialog */ @@ -87,6 +86,7 @@ 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(void); +static void init_stash_prefs(void);
#define SHOW_ERR(args) dialogs_show_msgbox(GTK_MESSAGE_ERROR, args) @@ -344,6 +344,8 @@ static void remove_foreach_project_filetype(gpointer data, gpointer user_data) /* open_default will make function reload default session files on close */ void project_close(gboolean open_default) { + GSList *node; + g_return_if_fail(app->project != NULL);
ui_set_statusbar(TRUE, _("Project "%s" closed."), app->project->name); @@ -371,6 +373,12 @@ void project_close(gboolean open_default) g_free(app->project); app->project = NULL;
+ foreach_slist(node, stash_groups) + stash_group_free(node->data); + + g_slist_free(stash_groups); + stash_groups = NULL; + apply_editor_prefs(); /* ensure that global settings are restored */
if (project_prefs.project_session) @@ -424,15 +432,9 @@ void project_close(gboolean open_default)
static void insert_build_page(PropertyDialogElements *e) { - GtkWidget *build_table, *label, *editor_tab; + GtkWidget *build_table, *label; GeanyDocument *doc = document_get_current(); GeanyFiletype *ft = NULL; - gint page_num; - - /* lookup the "Editor" tab page so the "Build" tab can be inserted - * right after it. */ - editor_tab = ui_lookup_widget(e->dialog, "vbox_project_dialog_editor"); - page_num = gtk_notebook_page_num(GTK_NOTEBOOK(e->notebook), editor_tab);
if (doc != NULL) ft = doc->file_type; @@ -440,8 +442,8 @@ static void insert_build_page(PropertyDialogElements *e) build_table = build_commands_table(doc, GEANY_BCS_PROJ, &(e->build_properties), ft); gtk_container_set_border_width(GTK_CONTAINER(build_table), 6); label = gtk_label_new(_("Build")); - e->build_page_num = gtk_notebook_insert_page(GTK_NOTEBOOK(e->notebook), - build_table, label, ++page_num); + e->build_page_num = gtk_notebook_append_page(GTK_NOTEBOOK(e->notebook), + build_table, label); }
@@ -493,6 +495,7 @@ static void show_project_properties(gboolean show_build) GtkWidget *widget = NULL; GtkWidget *radio_long_line_custom; static PropertyDialogElements e; + GSList *node;
g_return_if_fail(app->project != NULL);
@@ -503,7 +506,8 @@ static void show_project_properties(gboolean show_build)
insert_build_page(&e);
- stash_group_display(indent_group, e.dialog); + foreach_slist(node, stash_groups) + stash_group_display(node->data, e.dialog);
/* fill the elements with the appropriate data */ gtk_entry_set_text(GTK_ENTRY(e.name), p->name); @@ -607,10 +611,11 @@ static GeanyProject *create_project(void) GeanyProject *project = g_new0(GeanyProject, 1);
memset(&priv, 0, sizeof priv); - indentation = *editor_get_indent_prefs(NULL); priv.indentation = &indentation; project->priv = &priv;
+ init_stash_prefs(); + project->file_patterns = NULL;
project->long_line_behaviour = 1 /* use global settings */; @@ -730,6 +735,7 @@ static gboolean update_config(const PropertyDialogElements *e, gboolean new_proj GtkWidget *widget; gchar *tmp; GString *str; + GSList *node;
/* get and set the project description */ buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e->description)); @@ -737,7 +743,8 @@ static gboolean update_config(const PropertyDialogElements *e, gboolean new_proj gtk_text_buffer_get_end_iter(buffer, &end); setptr(p->description, g_strdup(gtk_text_buffer_get_text(buffer, &start, &end, FALSE)));
- stash_group_update(indent_group, e->dialog); + foreach_slist(node, stash_groups) + stash_group_update(node->data, e->dialog);
/* read the project build menu */ oldvalue = ft ? ft->projfilecmds : NULL; @@ -954,6 +961,7 @@ static gboolean load_config(const gchar *filename) { GKeyFile *config; GeanyProject *p; + GSList *node;
/* there should not be an open project */ g_return_val_if_fail(app->project == NULL && filename != NULL, FALSE); @@ -967,7 +975,8 @@ static gboolean load_config(const gchar *filename)
p = create_project();
- stash_group_load_from_key_file(indent_group, config); + foreach_slist(node, stash_groups) + stash_group_load_from_key_file(node->data, config);
p->name = utils_get_setting_string(config, "project", "name", GEANY_STRING_UNTITLED); p->description = utils_get_setting_string(config, "project", "description", ""); @@ -1021,6 +1030,7 @@ static gboolean write_config(gboolean emit_signal) gchar *filename; gchar *data; gboolean ret = FALSE; + GSList *node;
g_return_val_if_fail(app->project != NULL, FALSE);
@@ -1031,7 +1041,8 @@ static gboolean write_config(gboolean emit_signal) filename = utils_get_locale_from_utf8(p->file_name); g_key_file_load_from_file(config, filename, G_KEY_FILE_NONE, NULL);
- stash_group_save_to_key_file(indent_group, config); + foreach_slist(node, stash_groups) + stash_group_save_to_key_file(node->data, config);
g_key_file_set_string(config, "project", "name", p->name); g_key_file_set_string(config, "project", "base_path", p->base_path); @@ -1159,14 +1170,22 @@ void project_apply_prefs(void) }
-void project_init(void) +static void add_stash_group(StashGroup *group) +{ + stash_groups = g_slist_prepend(stash_groups, group); +} + + +static void init_stash_prefs(void) { StashGroup *group; + GKeyFile *kf;
group = stash_group_new("indentation"); - /* defaults are copied from editor indent prefs */ + /* copy global defaults */ + indentation = *editor_get_indent_prefs(NULL); stash_group_set_use_defaults(group, FALSE); - indent_group = group; + add_stash_group(group);
stash_group_add_spin_button_integer(group, &indentation.width, "indent_width", 4, "spin_indent_width_project"); @@ -1185,10 +1204,48 @@ void project_init(void) "detect_indent_width", FALSE, "check_detect_indent_width_project"); stash_group_add_combo_box(group, (gint*)(gpointer)&indentation.auto_indent_mode, "indent_mode", GEANY_AUTOINDENT_CURRENTCHARS, "combo_auto_indent_mode_project"); + + group = stash_group_new("file_prefs"); + stash_group_add_toggle_button(group, &priv.final_new_line, + "final_new_line", file_prefs.final_new_line, "check_new_line1"); + stash_group_add_toggle_button(group, &priv.ensure_convert_new_lines, + "ensure_convert_new_lines", file_prefs.ensure_convert_new_lines, "check_ensure_convert_new_lines1"); + stash_group_add_toggle_button(group, &priv.strip_trailing_spaces, + "strip_trailing_spaces", file_prefs.strip_trailing_spaces, "check_trailing_spaces1"); + stash_group_add_toggle_button(group, &priv.replace_tabs, + "replace_tabs", file_prefs.replace_tabs, "check_replace_tabs1"); + add_stash_group(group); + /* apply defaults */ + kf = g_key_file_new(); + stash_group_load_from_key_file(group, kf); + g_key_file_free(kf); +} + + +#define COPY_PREF(dest, prefname)\ + (dest.prefname = priv.prefname) + +const GeanyFilePrefs *project_get_file_prefs(void) +{ + static GeanyFilePrefs fp; + + if (!app->project) + return &file_prefs; + + fp = file_prefs; + COPY_PREF(fp, final_new_line); + COPY_PREF(fp, ensure_convert_new_lines); + COPY_PREF(fp, strip_trailing_spaces); + COPY_PREF(fp, replace_tabs); + return &fp; +} + + +void project_init(void) +{ }
void project_finalize(void) { - stash_group_free(indent_group); }
Modified: src/project.h 2 files changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -84,6 +84,8 @@ gchar *project_get_base_path(void);
+const struct GeanyFilePrefs *project_get_file_prefs(void); + void project_save_prefs(GKeyFile *config);
void project_load_prefs(GKeyFile *config);
Modified: src/projectprivate.h 4 files changed, 4 insertions(+), 0 deletions(-) =================================================================== @@ -28,6 +28,10 @@ typedef struct GeanyProjectPrivate { struct GeanyIndentPrefs *indentation; + gboolean final_new_line; + gboolean strip_trailing_spaces; + gboolean replace_tabs; + gboolean ensure_convert_new_lines; } GeanyProjectPrivate;
@@ Diff output truncated at 100000 characters. @@
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: TBD).