Revision: 857 http://svn.sourceforge.net/geany/?rev=857&view=rev Author: ntrel Date: 2006-10-01 09:14:45 -0700 (Sun, 01 Oct 2006)
Log Message: ----------- Save the build includes and arguments on quitting.
Modified Paths: -------------- trunk/ChangeLog trunk/TODO trunk/src/callbacks.c trunk/src/filetypes.c trunk/src/filetypes.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2006-09-30 16:15:45 UTC (rev 856) +++ trunk/ChangeLog 2006-10-01 16:14:45 UTC (rev 857) @@ -1,3 +1,9 @@ +2006-10-01 Nick Treleaven nick.treleaven@btinternet.com + + * src/callbacks.c, src/filetypes.c, src/filetypes.h, TODO: + Save the build includes and arguments on quitting. + + 2006-09-30 Nick Treleaven nick.treleaven@btinternet.com
* src/highlighting.c, src/highlighting.h:
Modified: trunk/TODO =================================================================== --- trunk/TODO 2006-09-30 16:15:45 UTC (rev 856) +++ trunk/TODO 2006-10-01 16:14:45 UTC (rev 857) @@ -3,7 +3,7 @@ (features included in () have lower priority)
- Geany 0.8 or later: + Next version or later:
o fix problems when loading global.tags and other tags files are already loaded @@ -11,7 +11,6 @@ o documentation: list and explain filetype modes o documentation: preferences o user-definable auto completion structs - o save build includes & arguments (->project management) o don't override Scintilla keybindings by default o allow use of custom global tags files o common default highlighting all in one config file @@ -19,6 +18,5 @@ o (DBUS) o (startup notification) o (indent wrapped lines - Scintilla issue) - o (inverting highlighting by selection - Scintilla issue) o (folder tree in the sidebar) o (improved Windows support)
Modified: trunk/src/callbacks.c =================================================================== --- trunk/src/callbacks.c 2006-09-30 16:15:45 UTC (rev 856) +++ trunk/src/callbacks.c 2006-10-01 16:14:45 UTC (rev 857) @@ -161,7 +161,11 @@ on_exit_clicked (GtkWidget *widget, gpointer gdata) { app->quitting = TRUE; + + // TODO: only save config if definitely quitting configuration_save(); + filetypes_save_commands(); + if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(app->notebook)) > 0) { gint i; @@ -2258,23 +2262,41 @@ if (response == GTK_RESPONSE_ACCEPT) { + const gchar *newstr; + struct build_programs *programs = ft->programs; + if (ft->menu_items->can_compile) { - if (ft->programs->compiler) g_free(ft->programs->compiler); - ft->programs->compiler = g_strdup(gtk_entry_get_text( - GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "includes_entry1")))); + newstr = gtk_entry_get_text( + GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "includes_entry1"))); + if (! utils_strcmp(newstr, programs->compiler)) + { + if (programs->compiler) g_free(programs->compiler); + programs->compiler = g_strdup(newstr); + programs->modified = TRUE; + } } if (ft->menu_items->can_link) { - if (ft->programs->linker) g_free(ft->programs->linker); - ft->programs->linker = g_strdup(gtk_entry_get_text( - GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "includes_entry2")))); + newstr = gtk_entry_get_text( + GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "includes_entry2"))); + if (! utils_strcmp(newstr, programs->linker)) + { + if (programs->linker) g_free(programs->linker); + programs->linker = g_strdup(newstr); + programs->modified = TRUE; + } } if (ft->menu_items->can_exec) { - if (ft->programs->run_cmd) g_free(ft->programs->run_cmd); - ft->programs->run_cmd = g_strdup(gtk_entry_get_text( - GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "includes_entry3")))); + newstr = gtk_entry_get_text( + GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "includes_entry3"))); + if (! utils_strcmp(newstr, programs->run_cmd)) + { + if (programs->run_cmd) g_free(programs->run_cmd); + programs->run_cmd = g_strdup(newstr); + programs->modified = TRUE; + } } } } @@ -2290,18 +2312,41 @@
if (response == GTK_RESPONSE_ACCEPT) { - if (ft->programs->compiler) g_free(ft->programs->compiler); - ft->programs->compiler = g_strdup(gtk_entry_get_text( - GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "tex_entry1")))); - if (ft->programs->linker) g_free(ft->programs->linker); - ft->programs->linker = g_strdup(gtk_entry_get_text( - GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "tex_entry2")))); - if (ft->programs->run_cmd) g_free(ft->programs->run_cmd); - ft->programs->run_cmd = g_strdup(gtk_entry_get_text( - GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "tex_entry3")))); - if (ft->programs->run_cmd2) g_free(ft->programs->run_cmd2); - ft->programs->run_cmd2 = g_strdup(gtk_entry_get_text( - GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "tex_entry4")))); + const gchar *newstr; + struct build_programs *programs = ft->programs; + + newstr = gtk_entry_get_text( + GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "tex_entry1"))); + if (! utils_strcmp(newstr, programs->compiler)) + { + if (programs->compiler) g_free(programs->compiler); + programs->compiler = g_strdup(newstr); + programs->modified = TRUE; + } + newstr = gtk_entry_get_text( + GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "tex_entry2"))); + if (! utils_strcmp(newstr, programs->linker)) + { + if (programs->linker) g_free(programs->linker); + programs->linker = g_strdup(newstr); + programs->modified = TRUE; + } + newstr = gtk_entry_get_text( + GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "tex_entry3"))); + if (! utils_strcmp(newstr, programs->run_cmd)) + { + if (programs->run_cmd) g_free(programs->run_cmd); + programs->run_cmd = g_strdup(newstr); + programs->modified = TRUE; + } + newstr = gtk_entry_get_text( + GTK_ENTRY(lookup_widget(GTK_WIDGET(dialog), "tex_entry4"))); + if (! utils_strcmp(newstr, programs->run_cmd2)) + { + if (programs->run_cmd2) g_free(programs->run_cmd2); + programs->run_cmd2 = g_strdup(newstr); + programs->modified = TRUE; + } } gtk_widget_destroy(GTK_WIDGET(dialog)); }
Modified: trunk/src/filetypes.c =================================================================== --- trunk/src/filetypes.c 2006-09-30 16:15:45 UTC (rev 856) +++ trunk/src/filetypes.c 2006-10-01 16:14:45 UTC (rev 857) @@ -30,6 +30,7 @@ #include "callbacks.h" #include "templates.h" #include "msgwindow.h" +#include "utils.h"
/* This is the order of unique ids used in the config file. @@ -683,7 +684,7 @@ }
-/* convenient function to save code size */ +/* convenience function - NULLs and zeros struct members */ static void filetypes_init_build_programs(filetype *ftype) { ftype->programs = g_new0(struct build_programs, 1); @@ -911,6 +912,62 @@ }
+static gchar *get_conf_extension(gint filetype_idx) +{ + gchar *result, *tmp = g_strdup(filetypes[filetype_idx]->name); + + switch (filetype_idx) + { + case GEANY_FILETYPES_CPP: result = g_strdup("cpp"); break; + case GEANY_FILETYPES_MAKE: result = g_strdup("makefile"); break; + case GEANY_FILETYPES_OMS: result = g_strdup("oms"); break; + default: result = g_ascii_strdown(tmp, -1); break; + } + g_free(tmp); + return result; +} + + +void filetypes_save_commands() +{ + gchar *conf_prefix = g_strconcat(app->configdir, + G_DIR_SEPARATOR_S GEANY_FILEDEFS_SUBDIR G_DIR_SEPARATOR_S "filetypes.", NULL); + gint i; + + for (i = 0; i < GEANY_FILETYPES_ALL; i++) + { + struct build_programs *bp = filetypes[i]->programs; + GKeyFile *config_home; + gchar *fname, *ext, *data; + + if (! bp->modified) continue; + + ext = get_conf_extension(i); + fname = g_strconcat(conf_prefix, ext, NULL); + g_free(ext); + + config_home = g_key_file_new(); + g_key_file_load_from_file(config_home, fname, G_KEY_FILE_KEEP_COMMENTS, NULL); + + if (bp->compiler && *bp->compiler) + g_key_file_set_string(config_home, "build_settings", "compiler", bp->compiler); + if (bp->linker && *bp->linker) + g_key_file_set_string(config_home, "build_settings", "linker", bp->linker); + if (bp->run_cmd && *bp->run_cmd) + g_key_file_set_string(config_home, "build_settings", "run_cmd", bp->run_cmd); + if (bp->run_cmd2 && *bp->run_cmd2) + g_key_file_set_string(config_home, "build_settings", "run_cmd2", bp->run_cmd2); + + data = g_key_file_to_data(config_home, NULL, NULL); + utils_write_file(fname, data); + g_free(data); + g_key_file_free(config_home); + g_free(fname); + } + g_free(conf_prefix); +} + + GtkFileFilter *filetypes_create_file_filter(filetype *ft) { GtkFileFilter *new_filter;
Modified: trunk/src/filetypes.h =================================================================== --- trunk/src/filetypes.h 2006-09-30 16:15:45 UTC (rev 856) +++ trunk/src/filetypes.h 2006-10-01 16:14:45 UTC (rev 857) @@ -59,7 +59,7 @@ GEANY_FILETYPES_OMS, GEANY_FILETYPES_DIFF, GEANY_FILETYPES_CONF, - GEANY_FILETYPES_ALL, + GEANY_FILETYPES_ALL, // must be last filetype GEANY_MAX_FILE_TYPES };
@@ -81,6 +81,7 @@ gchar *linker; gchar *run_cmd; gchar *run_cmd2; + gboolean modified; };
typedef struct filetype @@ -123,6 +124,8 @@
void filetypes_get_config(GKeyFile *config, GKeyFile *configh, gint ft);
+void filetypes_save_commands(); + void filetypes_select_radio_item(const filetype *ft);
GtkFileFilter *filetypes_create_file_filter(filetype *ft);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.