Revision: 2217 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=2217&view=re... Author: cesspit Date: 2011-09-29 11:05:32 +0000 (Thu, 29 Sep 2011) Log Message: ----------- debugger: debug session is stored in a debugger config, added option to store debug session in a project file
Modified Paths: -------------- trunk/geany-plugins/debugger/src/Makefile.am trunk/geany-plugins/debugger/src/breakpoints.c trunk/geany-plugins/debugger/src/btnpanel.c trunk/geany-plugins/debugger/src/btnpanel.h trunk/geany-plugins/debugger/src/callbacks.c trunk/geany-plugins/debugger/src/callbacks.h trunk/geany-plugins/debugger/src/dconfig.c trunk/geany-plugins/debugger/src/dconfig.h trunk/geany-plugins/debugger/src/debug.c trunk/geany-plugins/debugger/src/debug.h trunk/geany-plugins/debugger/src/dpaned.c trunk/geany-plugins/debugger/src/dpaned.h trunk/geany-plugins/debugger/src/envtree.c trunk/geany-plugins/debugger/src/plugin.c trunk/geany-plugins/debugger/src/tpage.c
Removed Paths: ------------- trunk/geany-plugins/debugger/src/pconfig.c trunk/geany-plugins/debugger/src/pconfig.h
Modified: trunk/geany-plugins/debugger/src/Makefile.am =================================================================== --- trunk/geany-plugins/debugger/src/Makefile.am 2011-09-25 20:08:05 UTC (rev 2216) +++ trunk/geany-plugins/debugger/src/Makefile.am 2011-09-29 11:05:32 UTC (rev 2217) @@ -25,8 +25,8 @@ calltip.c \ calltip.h \ dbm_gdb.c \ - dconfig.h \ dconfig.c \ + dconfig.h \ debug.c \ debug.h \ debug_module.c \ @@ -45,8 +45,6 @@ markers.h \ pixbuf.c \ pixbuf.h \ - pconfig.c \ - pconfig.h \ plugin.c \ stree.c \ stree.h \
Modified: trunk/geany-plugins/debugger/src/breakpoints.c =================================================================== --- trunk/geany-plugins/debugger/src/breakpoints.c 2011-09-25 20:08:05 UTC (rev 2216) +++ trunk/geany-plugins/debugger/src/breakpoints.c 2011-09-29 11:05:32 UTC (rev 2217) @@ -185,7 +185,7 @@ /* add markers, update treeview */ on_add(bp); /* mark config for saving */ - dconfig_set_changed(); + config_set_debug_changed(); } else dialogs_show_msgbox(GTK_MESSAGE_ERROR, "%s", debug_error_message()); @@ -197,7 +197,7 @@ /* remove markers, update treeview */ on_remove(bp); /* mark config for saving */ - dconfig_set_changed(); + config_set_debug_changed(); } else dialogs_show_msgbox(GTK_MESSAGE_ERROR, "%s", debug_error_message()); @@ -208,7 +208,7 @@ { on_set_hits_count(bp); /* mark config for saving */ - dconfig_set_changed(); + config_set_debug_changed(); } else dialogs_show_msgbox(GTK_MESSAGE_ERROR, "%s", debug_error_message()); @@ -219,7 +219,7 @@ { on_set_condition(bp); /* mark config for saving */ - dconfig_set_changed(); + config_set_debug_changed(); } else { @@ -237,7 +237,7 @@ { on_switch(bp); /* mark config for saving */ - dconfig_set_changed(); + config_set_debug_changed(); } else { @@ -266,7 +266,7 @@ } g_list_free(list);
- dconfig_set_changed(TRUE); + config_set_debug_changed(); } static void breaks_set_enabled_list_debug(GList *list) { @@ -289,7 +289,7 @@ } g_list_free(list);
- dconfig_set_changed(TRUE); + config_set_debug_changed(); } static void breaks_remove_list_debug(GList *list) { @@ -304,7 +304,7 @@ } g_list_free(list);
- dconfig_set_changed(TRUE); + config_set_debug_changed(); }
/* @@ -386,7 +386,7 @@ if (DBS_IDLE == state) { on_add(bp); - dconfig_set_changed(TRUE); + config_set_debug_changed(); } else if (DBS_STOPPED == state) breaks_add_debug(bp); @@ -418,7 +418,7 @@ if (DBS_IDLE == state) { on_remove(bp); - dconfig_set_changed(TRUE); + config_set_debug_changed(); } else if (DBS_STOPPED == state) breaks_remove_debug(bp); @@ -446,7 +446,7 @@ on_remove_list(list); g_list_free(list); - dconfig_set_changed(TRUE); + config_set_debug_changed(); } else if (DBS_STOPPED == state) breaks_remove_list_debug(list); @@ -486,7 +486,7 @@ { on_set_enabled_list(breaks, enabled); g_list_free(breaks); - dconfig_set_changed(TRUE); + config_set_debug_changed(); } else if (DBS_STOPPED == state) enabled ? breaks_set_enabled_list_debug(breaks) : breaks_set_disabled_list_debug(breaks); @@ -521,7 +521,7 @@ if (DBS_IDLE == state) { on_switch(bp); - dconfig_set_changed(TRUE); + config_set_debug_changed(); } else if (DBS_STOPPED == state) breaks_switch_debug(bp); @@ -557,7 +557,7 @@ if (state == DBS_IDLE) { on_set_hits_count(bp); - dconfig_set_changed(TRUE); + config_set_debug_changed(); } else if(state == DBS_STOPPED) breaks_set_hits_count_debug(bp); @@ -593,7 +593,7 @@ if (state == DBS_IDLE) { on_set_condition(bp); - dconfig_set_changed(TRUE); + config_set_debug_changed(); } else if (state == DBS_STOPPED) breaks_set_condition_debug(bp); @@ -623,7 +623,7 @@ g_tree_insert(tree, GINT_TO_POINTER(line_to), bp);
/* mark config for saving */ - dconfig_set_changed(); + config_set_debug_changed(); } } }
Modified: trunk/geany-plugins/debugger/src/btnpanel.c =================================================================== --- trunk/geany-plugins/debugger/src/btnpanel.c 2011-09-25 20:08:05 UTC (rev 2216) +++ trunk/geany-plugins/debugger/src/btnpanel.c 2011-09-29 11:05:32 UTC (rev 2217) @@ -40,10 +40,7 @@ #include "btnpanel.h"
#define CP_BUTTONS_PAD 5 -#define CONFIG_NAME ".debugger"
-static GtkWidget *loadbtn = NULL; - static GtkWidget *runbtn = NULL; static GtkWidget *restartbtn = NULL; static GtkWidget *stopbtn = NULL; @@ -56,45 +53,7 @@ static GtkWidget *tabbtn = NULL; static GtkWidget *optbtn = NULL;
-static gboolean debugging = FALSE; - /* - * load config button handler - */ -void on_config_load(GtkButton *button, gpointer user_data) -{ - GeanyDocument *doc = document_get_current(); - if (!doc && !doc->real_path) - { - dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Error reading config file")); - } - else - { - gchar *folder = g_path_get_dirname(DOC_FILENAME(doc)); - if (!dconfig_load(folder)) - { - dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Error reading config file")); - } - g_free(folder); - } -} - -/* - * clear config values button handler - */ -void on_config_clear(GtkButton *button, gpointer user_data) -{ - /* target page */ - tpage_clear(); - - /* breakpoints */ - breaks_remove_all(); - - /* watches */ - wtree_remove_all(); -} - -/* * calls settings dialog */ void on_settings(GtkButton *button, gpointer user_data) @@ -121,7 +80,6 @@ GtkWidget* btnpanel_create(on_toggle cb) { GtkWidget *vbox = gtk_vbox_new(FALSE, CP_BUTTONS_PAD); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 7);
GtkWidget *hbutton_box = gtk_hbox_new(FALSE, CP_BUTTONS_PAD);
@@ -167,78 +125,25 @@ gtk_box_pack_start(GTK_BOX(hbutton_box), runcursorbtn, FALSE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox), hbutton_box, FALSE, TRUE, 0);
- GtkWidget *vbox_panels_buttons = gtk_vbox_new(FALSE, 0); - GtkWidget *vbutton_box = gtk_vbox_new(TRUE, CP_BUTTONS_PAD); + optbtn = create_stock_button(GTK_STOCK_PREFERENCES, _("Settings")); + g_signal_connect(G_OBJECT(optbtn), "clicked", G_CALLBACK (on_settings), NULL); + gtk_box_pack_end(GTK_BOX(vbox), optbtn, FALSE, FALSE, 0);
- loadbtn = create_stock_button(GTK_STOCK_OPEN, _("Load settings")); - g_signal_connect(G_OBJECT(loadbtn), "clicked", G_CALLBACK (on_config_load), (gpointer)TRUE); - gtk_box_pack_start(GTK_BOX(vbutton_box), loadbtn, FALSE, TRUE, 0); - - gtk_box_pack_start(GTK_BOX(vbox_panels_buttons), vbutton_box, TRUE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(vbox), vbox_panels_buttons, TRUE, FALSE, 0); - - vbutton_box = gtk_vbox_new(TRUE, CP_BUTTONS_PAD); - tabbtn = create_toggle_button("tabs.gif", _("Tabs")); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tabbtn), dpaned_get_tabbed()); + tabbtn = create_toggle_button("tabs.gif", _("Two panel mode")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(tabbtn), config_get_tabbed()); g_signal_connect(G_OBJECT(tabbtn), "toggled", G_CALLBACK(cb), NULL); - gtk_box_pack_start(GTK_BOX(vbox), tabbtn, FALSE, FALSE, 0); + gtk_box_pack_end(GTK_BOX(vbox), tabbtn, FALSE, FALSE, 0);
- optbtn = create_stock_button(GTK_STOCK_PREFERENCES, "Настройки"); - g_signal_connect(G_OBJECT(optbtn), "clicked", G_CALLBACK (on_settings), NULL); - gtk_box_pack_start(GTK_BOX(vbox), optbtn, FALSE, FALSE, 0); - btnpanel_set_debug_state(DBS_IDLE);
return vbox; }
/* - * disable load/save config buttons on document close - */ -void btnpanel_on_document_close() -{ - gtk_widget_set_sensitive(loadbtn, FALSE); -} - -/* - * enable load/save config buttons on document activate - * if page is not readonly and have config - */ -void btnpanel_on_document_activate(GeanyDocument *doc) -{ - if (debugging) - return; - - if (!doc || !doc->real_path) - { - btnpanel_on_document_close(); - return; - } - - gchar *dirname = g_path_get_dirname(DOC_FILENAME(doc)); - gchar *config = g_build_path(G_DIR_SEPARATOR_S, dirname, CONFIG_NAME, NULL); - struct stat st; - gtk_widget_set_sensitive(loadbtn, !stat(config, &st)); - - g_free(config); -} - -/* - * set buttons sensitive based on whether it is a config file - * in the current folder - */ -void btnpanel_set_have_config(gboolean haveconfig) -{ - gtk_widget_set_sensitive(loadbtn, haveconfig); -} - -/* * set buttons sensitive based on debugger state */ void btnpanel_set_debug_state(enum dbs state) { - debugging = (DBS_IDLE != state); - if (DBS_STOPPED == state) { set_button_image(runbtn, "continue.png"); @@ -258,13 +163,4 @@ gtk_widget_set_sensitive(stepinbtn, DBS_STOPPED == state); gtk_widget_set_sensitive(stepoutbtn, DBS_STOPPED == state); gtk_widget_set_sensitive(runcursorbtn, DBS_STOPPED == state); - - if (DBS_IDLE == state) - { - btnpanel_on_document_activate(document_get_current()); - } - else - { - gtk_widget_set_sensitive(loadbtn, FALSE); - } }
Modified: trunk/geany-plugins/debugger/src/btnpanel.h =================================================================== --- trunk/geany-plugins/debugger/src/btnpanel.h 2011-09-25 20:08:05 UTC (rev 2216) +++ trunk/geany-plugins/debugger/src/btnpanel.h 2011-09-29 11:05:32 UTC (rev 2217) @@ -22,8 +22,4 @@ typedef void (*on_toggle)(GtkToggleButton *button, gpointer user_data);
GtkWidget* btnpanel_create(on_toggle cb); -void btnpanel_on_document_close(); -void btnpanel_on_document_activate(GeanyDocument *doc); - -void btnpanel_set_have_config(gboolean haveconfig); void btnpanel_set_debug_state(enum dbs state);
Modified: trunk/geany-plugins/debugger/src/callbacks.c =================================================================== --- trunk/geany-plugins/debugger/src/callbacks.c 2011-09-25 20:08:05 UTC (rev 2216) +++ trunk/geany-plugins/debugger/src/callbacks.c 2011-09-29 11:05:32 UTC (rev 2217) @@ -108,14 +108,6 @@ }
/* - * Occures on closing document - */ -void on_document_close(GObject *obj, GeanyDocument *doc, gpointer user_data) -{ - btnpanel_on_document_close(); -} - -/* * Occures on saving document */ void on_document_save(GObject *obj, GeanyDocument *doc, gpointer user_data) @@ -134,8 +126,6 @@ _unexisting_file = FALSE; } - - btnpanel_on_document_activate(doc); }
/* @@ -146,14 +136,6 @@ }
/* - * Occures on document activating - */ -void on_document_activate(GObject *obj, GeanyDocument *doc, gpointer user_data) -{ - btnpanel_on_document_activate(doc); -} - -/* * Occures on document opening. * Used to set breaks markers */ @@ -172,11 +154,6 @@ /* set breakpoint and frame markers */ set_markers_for_file(file);
- /* check if current path contains config file */ - gchar *folder = g_path_get_dirname(DOC_FILENAME(doc)); - btnpanel_set_have_config(dconfig_is_found_at(folder)); - g_free(folder); - /* if debug is active - tell the debug module that a file was opened */ if (DBS_IDLE != debug_get_state()) debug_on_file_open(doc); @@ -286,7 +263,7 @@ iter = iter->next; } - dconfig_set_changed(); + config_set_debug_changed();
g_list_free(breaks); }
Modified: trunk/geany-plugins/debugger/src/callbacks.h =================================================================== --- trunk/geany-plugins/debugger/src/callbacks.h 2011-09-25 20:08:05 UTC (rev 2216) +++ trunk/geany-plugins/debugger/src/callbacks.h 2011-09-29 11:05:32 UTC (rev 2217) @@ -20,8 +20,6 @@ */
void on_document_open(GObject *obj, GeanyDocument *doc, gpointer user_data); -void on_document_activate(GObject *obj, GeanyDocument *doc, gpointer user_data); -void on_document_close(GObject *obj, GeanyDocument *doc, gpointer user_data); void on_document_save(GObject *obj, GeanyDocument *doc, gpointer user_data); void on_document_before_save(GObject *obj, GeanyDocument *doc, gpointer user_data); void on_document_new(GObject *obj, GeanyDocument *doc, gpointer user_data);
Modified: trunk/geany-plugins/debugger/src/dconfig.c =================================================================== --- trunk/geany-plugins/debugger/src/dconfig.c 2011-09-25 20:08:05 UTC (rev 2216) +++ trunk/geany-plugins/debugger/src/dconfig.c 2011-09-29 11:05:32 UTC (rev 2217) @@ -2,7 +2,7 @@ * * dconfig.c * - * Copyright 2010 Alexander Petukhov <devel(at)apetukhov.ru> + * Copyright 2011 Alexander Petukhov <devel(at)apetukhov.ru> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,18 +20,20 @@ * MA 02110-1301, USA. */
- /* - * Working with debugger configs. +/* + * Plugin panel and debug session configs */ - + +#include <unistd.h> #include <sys/stat.h> -#include <memory.h>
+#include <glib/gstdio.h> + #include "geanyplugin.h" -extern GeanyFunctions *geany_functions; -extern GeanyPlugin *geany_plugin; +extern GeanyData *geany_data;
#include "dconfig.h" +#include "tabs.h" #include "breakpoints.h" #include "debug.h" #include "watch_model.h" @@ -39,52 +41,233 @@ #include "tpage.h" #include "bptree.h"
-#define CONFIG_NAME ".debugger" +/* keyfile debug group name */ +#define DEBUGGER_GROUP "debugger" +/* saving interval */ +#define SAVING_INTERVAL 2000000
-/* config file markers */ -#define ENVIRONMENT_MARKER "[ENV]" -#define BREAKPOINTS_MARKER "[BREAK]" -#define WATCH_MARKER "[WATCH]" +/* check button for a configure dialog */ +static GtkWidget *save_to_project_btn = NULL;
-/* maximus config file line length */ -#define MAXLINE 1000 +/* plugin config file path */ +static gchar *plugin_config_path = NULL;
-/* saving interval */ -#define SAVING_INTERVAL 2000000 +/* current debug session store */ +static debug_store dstore = DEBUG_STORE_PLUGIN;
+/* GKeyFile's for a project and plugin config */ +static GKeyFile *keyfile_plugin = NULL; +static GKeyFile *keyfile_project = NULL; + +/* flag that indicates that debug session is being loaded to controls + * to prevent change state to modified from GUI callbacks */ +static gboolean debug_config_loading = FALSE; + /* saving thread staff */ static GMutex *change_config_mutex; static GCond *cond; static GThread *saving_thread; -static gboolean config_changed = FALSE; -static gboolean modifyable = FALSE;
-/* the folder, config has been loaded from */ -static gchar *current_folder = NULL; +/* flags that indicate that part of a config has been changed and + * is going to be saved on the savng thread */ +static gboolean debug_config_changed = FALSE; +static gboolean panel_config_changed = FALSE;
-/* forward declaration */ -gboolean dconfig_save(gchar *folder); +/* + * creates a copy of a specified keyfile + */ +GKeyFile *create_copy_keyfile(GKeyFile *keyfile) +{ + gchar *path; + close(g_file_open_tmp(NULL, &path, NULL)); + + gchar *config_data = g_key_file_to_data(keyfile, NULL, NULL); + g_file_set_contents(path, config_data, -1, NULL); + g_free(config_data); + + GKeyFile *copy = g_key_file_new(); + g_key_file_load_from_file(copy, path, G_KEY_FILE_NONE, NULL);
+ g_remove(path); + g_free(path); + + return copy; +} + /* - * reads line from a file + * loads debug session from a keyfile and updates GUI */ -int readline(FILE *file, gchar *buffer, int buffersize) +void debug_load_from_keyfile(GKeyFile *keyfile) { - gchar c; - int read_count = 0; - while (buffersize && fread(&c, 1, 1, file) && '\n' != c) + debug_config_loading = TRUE; + + gchar *value; + /* target */ + tpage_set_target(value = g_key_file_get_string(keyfile, DEBUGGER_GROUP, "target", NULL)); + g_free(value); + /* debugger */ + tpage_set_debugger(value = g_key_file_get_string(keyfile, DEBUGGER_GROUP, "debugger", NULL)); + g_free(value); + /* arguments */ + tpage_set_commandline(value = g_key_file_get_string(keyfile, DEBUGGER_GROUP, "arguments", NULL)); + g_free(value); + + int i; + + /* environment */ + int envcount = g_key_file_get_integer(keyfile, DEBUGGER_GROUP, "envvar_count", NULL); + for (i = 0; i < envcount; i++) { - buffer[read_count++] = c; - buffersize--; + gchar *env_name_id = g_strdup_printf("envvar_%i_name", i); + gchar *env_value_id = g_strdup_printf("envvar_%i_value", i); + + gchar *name = g_key_file_get_string(keyfile, DEBUGGER_GROUP, env_name_id, NULL); + value = g_key_file_get_string(keyfile, DEBUGGER_GROUP, env_value_id, NULL); + + tpage_add_environment(name, value); + + g_free(name); + g_free(value); + + g_free(env_name_id); + g_free(env_value_id); } - buffer[read_count] = '\0';
- return read_count; + /* watches */ + int wcount = g_key_file_get_integer(keyfile, DEBUGGER_GROUP, "watches_count", NULL); + for (i = 0; i < wcount; i++) + { + gchar *watch_id = g_strdup_printf("watch_%i", i); + wtree_add_watch(value = g_key_file_get_string(keyfile, DEBUGGER_GROUP, watch_id, NULL)); + g_free(value); + g_free(watch_id); + } + + /* breakpoints */ + int bcount = g_key_file_get_integer(keyfile, DEBUGGER_GROUP, "breaks_count", NULL); + for (i = 0; i < bcount; i++) + { + gchar *break_file_id = g_strdup_printf("break_%i_file", i); + gchar *break_line_id = g_strdup_printf("break_%i_line", i); + gchar *break_condition_id = g_strdup_printf("break_%i_condition", i); + gchar *break_hits_id = g_strdup_printf("break_%i_hits_count", i); + gchar *break_enabled_id = g_strdup_printf("break_%i_enabled", i); + + gchar *file = g_key_file_get_string(keyfile, DEBUGGER_GROUP, break_file_id, NULL); + int line = g_key_file_get_integer(keyfile, DEBUGGER_GROUP, break_line_id, NULL); + gchar *condition = g_key_file_get_string(keyfile, DEBUGGER_GROUP, break_condition_id, NULL); + int hits_count = g_key_file_get_integer(keyfile, DEBUGGER_GROUP, break_hits_id, NULL); + gboolean enabled = g_key_file_get_boolean(keyfile, DEBUGGER_GROUP, break_enabled_id, NULL); + + breaks_add(file, line, condition, enabled, hits_count); + + g_free(break_file_id); + g_free(break_line_id); + g_free(break_condition_id); + g_free(break_hits_id); + g_free(break_enabled_id); + + g_free(file); + g_free(condition); + } + bptree_update_file_nodes(); + + debug_config_loading = FALSE; }
/* - * function for a config file background saving if changed + * saves debug session to a keyfile using values from GUI */ +void save_to_keyfile(GKeyFile *keyfile) +{ + g_key_file_remove_group(keyfile, DEBUGGER_GROUP, NULL); + + g_key_file_set_string(keyfile, DEBUGGER_GROUP, "target", tpage_get_target()); + g_key_file_set_string(keyfile, DEBUGGER_GROUP, "debugger", tpage_get_debugger()); + g_key_file_set_string(keyfile, DEBUGGER_GROUP, "arguments", tpage_get_commandline()); + + /* environment */ + GList *_env = tpage_get_environment(); + g_key_file_set_integer(keyfile, DEBUGGER_GROUP, "envvar_count", g_list_length(_env) / 2); + GList *iter = _env; + int env_index = 0; + while(iter) + { + gchar *name = (gchar*)iter->data; + iter = iter->next; + gchar *value = (gchar*)iter->data; + + gchar *env_name_id = g_strdup_printf("envvar_%i_name", env_index); + gchar *env_value_id = g_strdup_printf("envvar_%i_value", env_index); + + g_key_file_set_string(keyfile, DEBUGGER_GROUP, env_name_id, name); + g_key_file_set_string(keyfile, DEBUGGER_GROUP, env_value_id, value); + + g_free(env_name_id); + g_free(env_value_id); + + env_index++; + iter = iter->next; + } + g_list_foreach(_env, (GFunc)g_free, NULL); + g_list_free(_env); + + /* watches */ + GList *watches = wtree_get_watches(); + g_key_file_set_integer(keyfile, DEBUGGER_GROUP, "watches_count", g_list_length(watches)); + int watch_index = 0; + GList *biter = watches; + while (biter) + { + gchar *watch = (gchar*)biter->data; + gchar *watch_id = g_strdup_printf("watch_%i", watch_index); + + g_key_file_set_string(keyfile, DEBUGGER_GROUP, watch_id, watch); + + g_free(watch_id); + + watch_index++; + biter = biter->next; + } + g_list_foreach(watches, (GFunc)g_free, NULL); + g_list_free(watches); + + /* breakpoints */ + GList *_breaks = breaks_get_all(); + g_key_file_set_integer(keyfile, DEBUGGER_GROUP, "breaks_count", g_list_length(_breaks)); + int bp_index = 0; + biter = _breaks; + while (biter) + { + breakpoint *bp = (breakpoint*)biter->data; + + gchar *break_file_id = g_strdup_printf("break_%i_file", bp_index); + gchar *break_line_id = g_strdup_printf("break_%i_line", bp_index); + gchar *break_condition_id = g_strdup_printf("break_%i_condition", bp_index); + gchar *break_hits_id = g_strdup_printf("break_%i_hits_count", bp_index); + gchar *break_enabled_id = g_strdup_printf("break_%i_enabled", bp_index); + + g_key_file_set_string(keyfile, DEBUGGER_GROUP, break_file_id, bp->file); + g_key_file_set_integer(keyfile, DEBUGGER_GROUP, break_line_id, bp->line); + g_key_file_set_string(keyfile, DEBUGGER_GROUP, break_condition_id, bp->condition); + g_key_file_set_integer(keyfile, DEBUGGER_GROUP, break_hits_id, bp->hitscount); + g_key_file_set_boolean(keyfile, DEBUGGER_GROUP, break_enabled_id, bp->enabled); + + g_free(break_file_id); + g_free(break_line_id); + g_free(break_condition_id); + g_free(break_hits_id); + g_free(break_enabled_id); + + bp_index++; + biter = biter->next; + } + g_list_free(_breaks); +} + +/* + * function for config files background saving + */ static gpointer saving_thread_func(gpointer data) { GTimeVal interval; @@ -92,11 +275,38 @@ do { g_mutex_lock(change_config_mutex); - if (config_changed && current_folder) + + if ( + panel_config_changed || + (debug_config_changed && DEBUG_STORE_PLUGIN == dstore) + ) { - dconfig_save(current_folder); - config_changed = FALSE; + /* if all saving is going to be done to a plugin keyfile */ + if (debug_config_changed) + { + save_to_keyfile(keyfile_plugin); + debug_config_changed = FALSE; + } + + gchar *config_data = g_key_file_to_data(keyfile_plugin, NULL, NULL); + g_file_set_contents(plugin_config_path, config_data, -1, NULL); + g_free(config_data); + + panel_config_changed = FALSE; } + + if (debug_config_changed && DEBUG_STORE_PROJECT == dstore) + { + /* if debug is saved into a project and has been changed */ + save_to_keyfile(keyfile_project); + + gchar *config_data = g_key_file_to_data(keyfile_project, NULL, NULL); + g_file_set_contents(geany_data->app->project->file_name, config_data, -1, NULL); + g_free(config_data); + + debug_config_changed = FALSE; + } + g_mutex_unlock(change_config_mutex);
g_get_current_time(&interval); @@ -109,249 +319,357 @@ }
/* - * set "changed" flag to save it on "saving_thread" thread + * set "debug changed" flag to save it on "saving_thread" thread */ -void dconfig_set_changed() +void config_set_debug_changed() { - if (!modifyable) + if (!debug_config_loading) { g_mutex_lock(change_config_mutex); - config_changed = TRUE; + debug_config_changed = TRUE; g_mutex_unlock(change_config_mutex); } }
/* - * init config + * set one or several panel config values */ -void dconfig_init() +void config_set_panel(int config_part, gpointer config_value, ...) { + g_mutex_lock(change_config_mutex); + + va_list ap; + va_start(ap, config_value); + + while(config_part) + { + switch (config_part) + { + case CP_TABBED_MODE: + { + g_key_file_set_boolean(keyfile_plugin, "tabbed_mode", "enabled", (gboolean)config_value); + break; + } + case CP_OT_TABS: + { + int *array = (int*)config_value; + g_key_file_set_integer_list(keyfile_plugin, "one_panel_mode", "tabs", array + 1, array[0]); + break; + } + case CP_OT_SELECTED: + { + g_key_file_set_integer(keyfile_plugin, "one_panel_mode", "selected_tab_index", (int)config_value); + break; + } + case CP_TT_LTABS: + { + int *array = (int*)config_value; + g_key_file_set_integer_list(keyfile_plugin, "two_panels_mode", "left_tabs", array + 1, array[0]); + break; + } + case CP_TT_LSELECTED: + { + g_key_file_set_integer(keyfile_plugin, "two_panels_mode", "left_selected_tab_index", (int)config_value); + break; + } + case CP_TT_RTABS: + { + int *array = (int*)config_value; + g_key_file_set_integer_list(keyfile_plugin, "two_panels_mode", "right_tabs", array + 1, array[0]); + break; + } + case CP_TT_RSELECTED: + { + g_key_file_set_integer(keyfile_plugin, "two_panels_mode", "right_selected_tab_index", (int)config_value); + break; + } + } + + config_part = va_arg(ap, int); + if (config_part) + { + config_value = va_arg(ap, gpointer); + } + } + + panel_config_changed = TRUE; + g_mutex_unlock(change_config_mutex); +} + +/* + * set default debug session values to a keyfile + */ +void config_set_debug_defaults(GKeyFile *keyfile) +{ + g_key_file_set_string(keyfile, DEBUGGER_GROUP, "target", ""); + g_key_file_set_string(keyfile, DEBUGGER_GROUP, "debugger", ""); + g_key_file_set_string(keyfile, DEBUGGER_GROUP, "arguments", ""); + + g_key_file_set_integer(keyfile, DEBUGGER_GROUP, "envvar_count", 0); + g_key_file_set_integer(keyfile, DEBUGGER_GROUP, "watches_count", 0); + g_key_file_set_integer(keyfile, DEBUGGER_GROUP, "breaks_count", 0); +} + +/* + * set default panel config values in a GKeyFile + */ +void config_set_panel_defaults(GKeyFile *keyfile) +{ + g_key_file_set_boolean(keyfile_plugin, "tabbed_mode", "enabled", FALSE); + + int all_tabs[] = { TID_TARGET, TID_BREAKS, TID_AUTOS, TID_WATCH, TID_STACK, TID_TERMINAL, TID_MESSAGES }; + g_key_file_set_integer_list(keyfile, "one_panel_mode", "tabs", all_tabs, sizeof(all_tabs) / sizeof(int)); + g_key_file_set_integer(keyfile, "one_panel_mode", "selected_tab_index", 0); + + int left_tabs[] = { TID_TARGET, TID_BREAKS, TID_AUTOS, TID_WATCH }; + g_key_file_set_integer_list(keyfile, "two_panels_mode", "left_tabs", left_tabs, sizeof(left_tabs) / sizeof(int)); + g_key_file_set_integer(keyfile, "two_panels_mode", "left_selected_tab_index", 0); + int right_tabs[] = { TID_STACK, TID_TERMINAL, TID_MESSAGES }; + g_key_file_set_integer_list(keyfile, "two_panels_mode", "right_tabs", right_tabs, sizeof(right_tabs) / sizeof(int)); + g_key_file_set_integer(keyfile, "two_panels_mode", "right_selected_tab_index", 0); + + g_key_file_set_boolean(keyfile, "saving_settings", "save_to_project", FALSE); +} + +/* + * initialize + */ +void config_init() +{ + /* read config */ + gchar *config_dir = g_build_path(G_DIR_SEPARATOR_S, geany_data->app->configdir, "plugins", "debugger", NULL); + plugin_config_path = g_build_path(G_DIR_SEPARATOR_S, config_dir, "debugger.conf", NULL); + + g_mkdir_with_parents(config_dir, S_IRUSR | S_IWUSR | S_IXUSR); + g_free(config_dir); + + keyfile_plugin = g_key_file_new(); + if (!g_key_file_load_from_file(keyfile_plugin, plugin_config_path, G_KEY_FILE_NONE, NULL)) + { + config_set_panel_defaults(keyfile_plugin); + gchar *data = g_key_file_to_data(keyfile_plugin, NULL, NULL); + g_file_set_contents(plugin_config_path, data, -1, NULL); + g_free(data); + } + change_config_mutex = g_mutex_new(); cond = g_cond_new(); - saving_thread = g_thread_create(saving_thread_func, NULL, TRUE, NULL); -} +}
/* - * destroys config + * destroy */ -void dconfig_destroy() +void config_destroy() { g_cond_signal(cond); /* ??? g_thread_join(saving_thread); */ g_mutex_free(change_config_mutex); g_cond_free(cond); + + g_free(plugin_config_path); - if (current_folder) + g_key_file_free(keyfile_plugin); + if(keyfile_project) { - g_free(current_folder); - current_folder = NULL; + g_key_file_free(keyfile_project); } }
/* - * checks whether a config file is founs in the folder + * config parts getters */ -gboolean dconfig_is_found_at(gchar *folder) +/* saving option */ +gboolean config_get_save_to_project() { - gchar *config = g_build_path(G_DIR_SEPARATOR_S, folder, CONFIG_NAME, NULL); - gboolean res = g_file_test(config, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR); - g_free(config); - - return res; + return g_key_file_get_boolean(keyfile_plugin, "saving_settings", "save_to_project", NULL); } +/* panel config */ +gboolean config_get_tabbed() +{ + return g_key_file_get_boolean(keyfile_plugin, "tabbed_mode", "enabled", NULL); +} +int* config_get_tabs(gsize *length) +{ + return g_key_file_get_integer_list(keyfile_plugin, "one_panel_mode", "tabs", length, NULL); +} +int config_get_selected_tab_index() +{ + return g_key_file_get_integer(keyfile_plugin, "one_panel_mode", "selected_tab_index", NULL); +} +int* config_get_left_tabs(gsize *length) +{ + return g_key_file_get_integer_list(keyfile_plugin, "two_panels_mode", "left_tabs", length, NULL); +} +int config_get_left_selected_tab_index() +{ + return g_key_file_get_integer(keyfile_plugin, "two_panels_mode", "left_selected_tab_index", NULL); +} +int* config_get_right_tabs(gsize *length) +{ + return g_key_file_get_integer_list(keyfile_plugin, "two_panels_mode", "right_tabs", length, NULL); +} +int config_get_right_selected_tab_index() +{ + return g_key_file_get_integer(keyfile_plugin, "two_panels_mode", "right_selected_tab_index", NULL); +}
/* - * loads config from a folder + * update GUI fron the store specified + * also handles default values insertion in a keyfile if debug section doesn't exist */ -gboolean dconfig_load(gchar *folder) +void config_set_debug_store(debug_store store) { - modifyable = TRUE; - g_mutex_lock(change_config_mutex); + dstore = store;
tpage_clear(); wtree_remove_all(); breaks_remove_all(); + + GKeyFile *keyfile = DEBUG_STORE_PROJECT == dstore ? keyfile_project : keyfile_plugin; - if (current_folder) + if (!g_key_file_has_group(keyfile, DEBUGGER_GROUP)) { - g_free(current_folder); - } - current_folder = g_strdup(folder); - - gchar *path = g_build_path(G_DIR_SEPARATOR_S, folder, CONFIG_NAME, NULL); - FILE *file = fopen(path, "r"); - if (!file) - { - config_changed = FALSE; + config_set_debug_defaults(keyfile); + gchar *data = g_key_file_to_data(keyfile, NULL, NULL);
- modifyable = FALSE; - g_mutex_unlock(change_config_mutex); + gchar *file = DEBUG_STORE_PROJECT == dstore ? geany_data->app->project->file_name : plugin_config_path; + g_file_set_contents(file, data, -1, NULL);
- return FALSE; + g_free(data); } + + debug_load_from_keyfile(keyfile); +}
- /* target */ - gchar buffer[FILENAME_MAX]; - if(readline(file, buffer, FILENAME_MAX - 1)) +/* + * updates keyfile_project from a current geany project path + */ +void config_update_project_keyfile() +{ + if (keyfile_project) { - tpage_set_target(buffer); + g_key_file_free(keyfile_project); } + keyfile_project = g_key_file_new(); + g_key_file_load_from_file(keyfile_project, geany_data->app->project->file_name, G_KEY_FILE_NONE, NULL); +}
- /* debugger */ - gchar debugger[FILENAME_MAX]; - if(readline(file, debugger, FILENAME_MAX - 1)) +/* + * project open handler + */ +void config_on_project_open(GObject *obj, GKeyFile *config, gpointer user_data) +{ + config_update_project_keyfile(); + + if (config_get_save_to_project()) { - tpage_set_debugger(debugger); + config_set_debug_store(DEBUG_STORE_PROJECT); } - - /* arguments */ - if(readline(file, buffer, FILENAME_MAX - 1)) - { - tpage_set_commandline(buffer); - } +}
- /* breakpoints and environment variables */ - gchar line[MAXLINE]; - while (readline(file, line, MAXLINE)) +/* + * project close handler + */ +void config_on_project_close(GObject *obj, gpointer user_data) +{ + if (config_get_save_to_project()) { - if (!strcmp(line, BREAKPOINTS_MARKER)) + if (DBS_IDLE != debug_get_state()) { - /* file */ - gchar _path[FILENAME_MAX]; - readline(file, _path, MAXLINE); + /* stop a debugger and ait for it to be stopped */ + debug_stop(); - /* line */ - int nline; - readline(file, line, MAXLINE); - sscanf(line, "%i", &nline); - - /* hitscount */ - int hitscount; - readline(file, line, MAXLINE); - sscanf(line, "%d", &hitscount); - - /* condition */ - gchar condition[MAXLINE]; - readline(file, condition, MAXLINE); - - /* enabled */ - gboolean enabled; - readline(file, line, MAXLINE); - sscanf(line, "%d", &enabled); - - /* check whether file is available */ - struct stat st; - if(!stat(_path, &st)) + while (DBS_IDLE != debug_get_state()) { - breaks_add(_path, nline, condition, enabled, hitscount); + g_main_context_iteration(NULL, FALSE); } } - else if (!strcmp(line, ENVIRONMENT_MARKER)) + + config_set_debug_store(DEBUG_STORE_PLUGIN); + } +} + +/* + * project save handler + * handles ne project creation and updatng a project using project properties dialog + */ +void config_on_project_save(GObject *obj, GKeyFile *config, gpointer user_data) +{ + if (config_get_save_to_project()) + { + if (!g_key_file_has_group(config, DEBUGGER_GROUP)) { - gchar name[MAXLINE], value[1000]; - if(readline(file, name, MAXLINE) && readline(file, value, MAXLINE)) - { - tpage_add_environment(name, value); - } + /* no debug group, creating a new project */ + dstore = DEBUG_STORE_PROJECT; + + /* clear values taken from a plugin */ + tpage_clear(); + wtree_remove_all(); + breaks_remove_all(); + + /* set default debug values */ + config_set_debug_defaults(config); } - else if (!strcmp(line, WATCH_MARKER)) + + /* update local keyfile */ + if (keyfile_project) { - gchar watch[MAXLINE]; - if(readline(file, watch, MAXLINE)) - { - wtree_add_watch(watch); - } + g_key_file_free(keyfile_project); } + keyfile_project = create_copy_keyfile(config); } - - bptree_update_file_nodes(); - - config_changed = FALSE; - - modifyable = FALSE; - g_mutex_unlock(change_config_mutex); - - return TRUE; }
/* - * saves config to a folder + * a configure dialog has been closed */ -gboolean dconfig_save(gchar *folder) +static void on_configure_response(GtkDialog* dialog, gint response, gpointer user_data) { - /* open config file */ - gchar *config_file = g_build_path(G_DIR_SEPARATOR_S, folder, CONFIG_NAME, NULL); - - FILE *config = fopen(config_file, "w"); - if (config) + gboolean newvalue = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(save_to_project_btn)); + if (newvalue ^ config_get_save_to_project()) { - /* get target */ - const gchar *_target = tpage_get_target(); - fprintf(config, "%s\n", _target); - - /* debugger type */ - gchar *debugger = tpage_get_debugger(); - fprintf(config, "%s\n", debugger); - - /* get command line arguments */ - gchar *_args = tpage_get_commandline(); - fprintf(config, "%s\n", _args); - g_free(_args); + g_key_file_set_boolean(keyfile_plugin, "saving_settings", "save_to_project", newvalue);
- /* environment */ - GList *_env = tpage_get_environment(); - GList *iter = _env; - - while(iter) + g_mutex_lock(change_config_mutex); + panel_config_changed = TRUE; + g_mutex_unlock(change_config_mutex); + + if (geany_data->app->project) { - gchar *name = (gchar*)iter->data; - iter = iter->next; - gchar *value = (gchar*)iter->data; + if (DBS_IDLE != debug_get_state()) + { + debug_stop(); + + while (DBS_IDLE != debug_get_state()) + { + g_main_context_iteration(NULL, FALSE); + } + }
- fprintf(config, "%s\n", ENVIRONMENT_MARKER); - fprintf(config, "%s\n%s\n", name, value); - - iter = iter->next; + config_set_debug_store(newvalue ? DEBUG_STORE_PROJECT : DEBUG_STORE_PLUGIN); } - - /* breakpoints */ - GList *_breaks = breaks_get_all(); - GList *biter = _breaks; - while (biter) - { - breakpoint *bp = (breakpoint*)biter->data; - - fprintf(config, "%s\n", BREAKPOINTS_MARKER); - fprintf(config, "%s\n%i\n%i\n%s\n%i\n", - bp->file, bp->line, bp->hitscount, bp->condition, bp->enabled); - - biter = biter->next; - } - g_list_free(_breaks); - _breaks = NULL; - - /* watches */ - GList *cur_watches = wtree_get_watches(); - biter = cur_watches; - while (biter) - { - gchar *watch = (gchar*)biter->data; - - fprintf(config, "%s\n", WATCH_MARKER); - fprintf(config, "%s\n", watch); - - biter = biter->next; - } - g_list_foreach(cur_watches, (GFunc)g_free, NULL); - g_list_free(cur_watches); - cur_watches = NULL; - - fclose(config); } +}
- g_free(config_file); +/* + * "plugin_configure" signal handler + */ +GtkWidget *config_plugin_configure(GtkDialog *dialog) +{ + GtkWidget *vbox = gtk_vbox_new(FALSE, 6); + GtkWidget *_hbox = gtk_hbox_new(FALSE, 6); + + save_to_project_btn = gtk_check_button_new_with_label(_("Save debug session data to a project")); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(save_to_project_btn), config_get_save_to_project());
- return config ? TRUE : FALSE; + gtk_box_pack_start(GTK_BOX(_hbox), save_to_project_btn, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(vbox), _hbox, FALSE, FALSE, 0); + + gtk_widget_show_all(vbox); + + g_signal_connect(dialog, "response", G_CALLBACK(on_configure_response), NULL); + + return vbox; }
Modified: trunk/geany-plugins/debugger/src/dconfig.h =================================================================== --- trunk/geany-plugins/debugger/src/dconfig.h 2011-09-25 20:08:05 UTC (rev 2216) +++ trunk/geany-plugins/debugger/src/dconfig.h 2011-09-29 11:05:32 UTC (rev 2217) @@ -1,7 +1,7 @@ /* * dconfig.h * - * Copyright 2010 Alexander Petukhov <devel(at)apetukhov.ru> + * Copyright 2011 Alexander Petukhov <devel(at)apetukhov.ru> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,12 +19,49 @@ * MA 02110-1301, USA. */
-void dconfig_init(); -void dconfig_destroy(); +#include <stdarg.h>
-gboolean dconfig_is_found_at(gchar *folder); -gboolean dconfig_load(gchar *folder); +/* panel config parts */ +#define CP_TABBED_MODE 1 +#define CP_OT_TABS 2 +#define CP_OT_SELECTED 3 +#define CP_TT_LTABS 4 +#define CP_TT_LSELECTED 5 +#define CP_TT_RTABS 6 +#define CP_TT_RSELECTED 7
-void dconfig_set_changed();
+typedef enum _debug_store { + DEBUG_STORE_PLUGIN, + DEBUG_STORE_PROJECT +} debug_store;
+ +void config_init(); +void config_destroy(); + +void config_set_panel(int config_part, gpointer config_value, ...); + +gboolean config_get_save_to_project(); + +gboolean config_get_tabbed(); + +int* config_get_tabs(gsize *length); +int config_get_selected_tab_index(); + +int* config_get_left_tabs(gsize *length); +int config_get_left_selected_tab_index(); + +int* config_get_right_tabs(gsize *length); +int config_get_right_selected_tab_index(); + +void config_set_debug_changed(); +void config_set_debug_store(debug_store store); + +void config_on_project_open(GObject *obj, GKeyFile *config, gpointer user_data); +void config_on_project_close(GObject *obj, gpointer user_data); +void config_on_project_save(GObject *obj, GKeyFile *config, gpointer user_data); + +void config_update_project_keyfile(); + +GtkWidget *config_plugin_configure(GtkDialog *dialog);
Modified: trunk/geany-plugins/debugger/src/debug.c =================================================================== --- trunk/geany-plugins/debugger/src/debug.c 2011-09-25 20:08:05 UTC (rev 2216) +++ trunk/geany-plugins/debugger/src/debug.c 2011-09-29 11:05:32 UTC (rev 2217) @@ -242,7 +242,7 @@ if (DBS_STOPPED == debug_state) active_module->remove_watch(internal);
- dconfig_set_changed(); + config_set_debug_changed(); } else if (strcmp(oldvalue, striped)) { @@ -274,7 +274,7 @@ gtk_tree_path_free(_path); }
- dconfig_set_changed(); + config_set_debug_changed(); } /* free resources */ @@ -341,7 +341,7 @@ else variable_set_name_only(wstore, &newvar, expression);
- dconfig_set_changed(); + config_set_debug_changed(); }
/* @@ -457,7 +457,7 @@ g_list_foreach (references, (GFunc)gtk_tree_row_reference_free, NULL); g_list_free (references);
- dconfig_set_changed(); + config_set_debug_changed(); }
/* free rows list */ @@ -504,7 +504,7 @@ else variable_set_name_only(wstore, &newvar, expression);
- dconfig_set_changed(); + config_set_debug_changed(); }
g_free(expression); @@ -804,11 +804,11 @@ /* enable widgets */ enable_sensitive_widgets(TRUE);
+ /* update buttons panel state */ + btnpanel_set_debug_state(DBS_IDLE); + /* update debug state */ debug_state = DBS_IDLE; - - /* update buttons panel state */ - btnpanel_set_debug_state(debug_state); }
/*
Modified: trunk/geany-plugins/debugger/src/debug.h =================================================================== --- trunk/geany-plugins/debugger/src/debug.h 2011-09-25 20:08:05 UTC (rev 2216) +++ trunk/geany-plugins/debugger/src/debug.h 2011-09-29 11:05:32 UTC (rev 2217) @@ -50,11 +50,11 @@ int debug_get_module_index(const gchar *modulename); gboolean debug_supports_async_breaks(); void debug_destroy(); -gchar* debug_evaluate_expression(gchar *expression); +gchar* debug_evaluate_expression(gchar *expression); gboolean debug_current_instruction_have_sources(); void debug_jump_to_current_instruction(); void debug_on_file_open(GeanyDocument *doc); -gchar* debug_get_calltip_for_expression(gchar* expression); +gchar* debug_get_calltip_for_expression(gchar* expression); GList* debug_get_stack(); void debug_restart();
Modified: trunk/geany-plugins/debugger/src/dpaned.c =================================================================== --- trunk/geany-plugins/debugger/src/dpaned.c 2011-09-25 20:08:05 UTC (rev 2216) +++ trunk/geany-plugins/debugger/src/dpaned.c 2011-09-29 11:05:32 UTC (rev 2217) @@ -38,7 +38,7 @@ #include "debug.h" #include "btnpanel.h" #include "stree.h" -#include "pconfig.h" +#include "dconfig.h"
#define NOTEBOOK_GROUP 438948394 #define HPANED_BORDER_WIDTH 4 @@ -104,17 +104,17 @@ static void on_page_added(GtkNotebook *notebook, GtkWidget *child, guint page_num, gpointer user_data) { gboolean is_left = (GTK_NOTEBOOK(debug_notebook_left) == notebook); - gboolean is_tabbed = pconfig_get_tabbed(); + gboolean is_tabbed = config_get_tabbed(); int *tabs = NULL; gsize length;
if (!is_tabbed) - tabs = pconfig_get_tabs(&length); + tabs = config_get_tabs(&length); else if (is_left) - tabs = pconfig_get_left_tabs(&length); + tabs = config_get_left_tabs(&length); else - tabs = pconfig_get_right_tabs(&length); + tabs = config_get_right_tabs(&length); int *array = g_malloc((length + 2) * sizeof(int)); int *new_tabs = array + 1; @@ -135,7 +135,7 @@
array[0] = length + 1; memcpy(array + 1, new_tabs, length + 1); - pconfig_set(config_part, array, 0); + config_set_panel(config_part, array, 0);
g_free(tabs); g_free(array); @@ -147,17 +147,17 @@ static void on_page_reordered(GtkNotebook *notebook, GtkWidget *child, guint page_num, gpointer user_data) { gboolean is_left = (GTK_NOTEBOOK(debug_notebook_left) == notebook); - gboolean is_tabbed = pconfig_get_tabbed(); + gboolean is_tabbed = config_get_tabbed();
int *tabs = NULL; gsize length;
if (!is_tabbed) - tabs = pconfig_get_tabs(&length); + tabs = config_get_tabs(&length); else if (is_left) - tabs = pconfig_get_left_tabs(&length); + tabs = config_get_left_tabs(&length); else - tabs = pconfig_get_right_tabs(&length); + tabs = config_get_right_tabs(&length);
int prev_index; GtkWidget *page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(is_left ? debug_notebook_left : debug_notebook_right), page_num); @@ -200,7 +200,7 @@ array[0] = length; memcpy(array + 1, tabs, length * sizeof(int)); - pconfig_set( + config_set_panel( config_part_tabs, array, config_part_selected_index, page_num, 0 @@ -216,17 +216,17 @@ static void on_page_removed(GtkNotebook *notebook, GtkWidget *child, guint page_num, gpointer user_data) { gboolean is_left = (GTK_NOTEBOOK(debug_notebook_left) == notebook); - gboolean is_tabbed = pconfig_get_tabbed(); + gboolean is_tabbed = config_get_tabbed();
int *tabs = NULL; gsize length;
if (!is_tabbed) - tabs = pconfig_get_tabs(&length); + tabs = config_get_tabs(&length); else if (is_left) - tabs = pconfig_get_left_tabs(&length); + tabs = config_get_left_tabs(&length); else - tabs = pconfig_get_right_tabs(&length); + tabs = config_get_right_tabs(&length);
memmove(tabs + page_num, tabs + page_num + 1, (length - page_num - 1) * sizeof(int)); memmove(tabs + 1, tabs, (length - 1) * sizeof(int)); @@ -240,7 +240,7 @@ else config_part = CP_TT_RTABS; - pconfig_set(config_part, tabs, 0); + config_set_panel(config_part, tabs, 0);
g_free(tabs); } @@ -251,7 +251,7 @@ static gboolean on_change_current_page(GtkNotebook *notebook, gpointer arg1, guint arg2, gpointer user_data) { gboolean is_left = (GTK_NOTEBOOK(debug_notebook_left) == notebook); - gboolean is_tabbed = pconfig_get_tabbed(); + gboolean is_tabbed = config_get_tabbed();
int config_part; if (!is_tabbed) @@ -261,7 +261,7 @@ else config_part = CP_TT_RSELECTED; - pconfig_set(config_part, (gpointer)arg2, 0); + config_set_panel(config_part, (gpointer)arg2, 0);
return TRUE; } @@ -273,7 +273,6 @@ { /* create paned */ hpaned = gtk_hpaned_new(); - gtk_container_set_border_width(GTK_CONTAINER(hpaned), HPANED_BORDER_WIDTH); /* create notebooks */ debug_notebook_left = gtk_notebook_new(); @@ -291,17 +290,14 @@ gtk_paned_add1(GTK_PANED(hpaned), debug_notebook_left); gtk_paned_add2(GTK_PANED(hpaned), debug_notebook_right);
- /* load config */ - pconfig_init(); - - gboolean is_tabbed = pconfig_get_tabbed(); + gboolean is_tabbed = config_get_tabbed(); if (is_tabbed) { gsize length; int *tab_ids, i;
/* left */ - tab_ids = pconfig_get_left_tabs(&length); + tab_ids = config_get_left_tabs(&length); for (i = 0; i < length; i++) { GtkWidget *tab = tabs_get_tab((tab_id)tab_ids[i]); @@ -314,7 +310,7 @@ g_free(tab_ids);
/* right */ - tab_ids = pconfig_get_right_tabs(&length); + tab_ids = config_get_right_tabs(&length); for (i = 0; i < length; i++) { GtkWidget *tab = tabs_get_tab((tab_id)tab_ids[i]); @@ -328,8 +324,8 @@
gtk_widget_show_all(hpaned);
- gtk_notebook_set_current_page(GTK_NOTEBOOK(debug_notebook_left), pconfig_get_left_selected_tab_index()); - gtk_notebook_set_current_page(GTK_NOTEBOOK(debug_notebook_right),pconfig_get_right_selected_tab_index()); + gtk_notebook_set_current_page(GTK_NOTEBOOK(debug_notebook_left), config_get_left_selected_tab_index()); + gtk_notebook_set_current_page(GTK_NOTEBOOK(debug_notebook_right),config_get_right_selected_tab_index()); } else { @@ -337,7 +333,7 @@ gtk_container_remove(GTK_CONTAINER(hpaned), debug_notebook_right); gsize length; - int *tab_ids = pconfig_get_tabs(&length); + int *tab_ids = config_get_tabs(&length); int i; for (i = 0; i < length; i++) { @@ -350,7 +346,7 @@ }
gtk_widget_show_all(hpaned); - gtk_notebook_set_current_page(GTK_NOTEBOOK(debug_notebook_left), pconfig_get_selected_tab_index()); + gtk_notebook_set_current_page(GTK_NOTEBOOK(debug_notebook_left), config_get_selected_tab_index()); } CONNECT_PAGE_SIGNALS(); @@ -363,8 +359,6 @@ void dpaned_destroy() { DISCONNECT_PAGE_SIGNALS(); - - pconfig_destroy(); }
/* @@ -388,7 +382,7 @@ gtk_container_remove(GTK_CONTAINER(hpaned), debug_notebook_right); gsize length; - int *tab_ids = pconfig_get_tabs(&length); + int *tab_ids = config_get_tabs(&length); int i; for (i = 0; i < length; i++) { @@ -404,7 +398,7 @@ } }
- gtk_notebook_set_current_page(GTK_NOTEBOOK(debug_notebook_left), pconfig_get_selected_tab_index()); + gtk_notebook_set_current_page(GTK_NOTEBOOK(debug_notebook_left), config_get_selected_tab_index());
gtk_widget_show_all(hpaned); } @@ -414,7 +408,7 @@ g_object_unref(debug_notebook_right);
gsize length; - int *tab_ids = pconfig_get_right_tabs(&length); + int *tab_ids = config_get_right_tabs(&length); int i; for (i = 0; i < length; i++) { @@ -427,21 +421,13 @@ gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(debug_notebook_right), tab, TRUE); }
- gtk_notebook_set_current_page(GTK_NOTEBOOK(debug_notebook_left), pconfig_get_left_selected_tab_index()); - gtk_notebook_set_current_page(GTK_NOTEBOOK(debug_notebook_right), pconfig_get_right_selected_tab_index()); + gtk_notebook_set_current_page(GTK_NOTEBOOK(debug_notebook_left), config_get_left_selected_tab_index()); + gtk_notebook_set_current_page(GTK_NOTEBOOK(debug_notebook_right), config_get_right_selected_tab_index());
gtk_widget_show_all(hpaned); } CONNECT_PAGE_SIGNALS();
- pconfig_set(CP_TABBED_MODE, (gpointer)tabbed, 0); + config_set_panel(CP_TABBED_MODE, (gpointer)tabbed, 0); } - -/* - * gets tabbed mode state - */ -gboolean dpaned_get_tabbed() -{ - return pconfig_get_tabbed(); -}
Modified: trunk/geany-plugins/debugger/src/dpaned.h =================================================================== --- trunk/geany-plugins/debugger/src/dpaned.h 2011-09-25 20:08:05 UTC (rev 2216) +++ trunk/geany-plugins/debugger/src/dpaned.h 2011-09-29 11:05:32 UTC (rev 2217) @@ -24,4 +24,3 @@ void dpaned_destroy(); GtkWidget* dpaned_get_paned(); void dpaned_set_tabbed(gboolean paned); -gboolean dpaned_get_tabbed();
Modified: trunk/geany-plugins/debugger/src/envtree.c =================================================================== --- trunk/geany-plugins/debugger/src/envtree.c 2011-09-25 20:08:05 UTC (rev 2216) +++ trunk/geany-plugins/debugger/src/envtree.c 2011-09-29 11:05:32 UTC (rev 2217) @@ -185,7 +185,7 @@ if (GDK_Delete == keyval) { delete_selected_rows(); - dconfig_set_changed(); + config_set_debug_changed(); }
return GDK_Tab == keyval; @@ -243,7 +243,7 @@ if (dialogs_show_question(_("Delete variable?"))) { delete_selected_rows(); - dconfig_set_changed(); + config_set_debug_changed();
gtk_widget_grab_focus(tree); } @@ -266,7 +266,7 @@ add_empty_row(); g_object_set (renderer_value, "editable", FALSE, NULL); - dconfig_set_changed(); + config_set_debug_changed(); } g_free(oldvalue); @@ -346,7 +346,7 @@ if (!empty && dialogs_show_question(_("Delete variable?"))) { delete_selected_rows(); - dconfig_set_changed(); + config_set_debug_changed();
gtk_widget_grab_focus(tree); } @@ -362,7 +362,7 @@ } if (!empty) { - dconfig_set_changed(); + config_set_debug_changed(); } }
Deleted: trunk/geany-plugins/debugger/src/pconfig.c =================================================================== --- trunk/geany-plugins/debugger/src/pconfig.c 2011-09-25 20:08:05 UTC (rev 2216) +++ trunk/geany-plugins/debugger/src/pconfig.c 2011-09-29 11:05:32 UTC (rev 2217) @@ -1,235 +0,0 @@ -/* - * - * pconfig.c - * - * Copyright 2011 Alexander Petukhov <devel(at)apetukhov.ru> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -/* - * Debug paned config. - */ - -#include <sys/stat.h> - -#include "geanyplugin.h" -extern GeanyFunctions *geany_functions; -extern GeanyData *geany_data; - -#include "pconfig.h" -#include "tabs.h" - -/* config file path */ -static gchar *config_path = NULL; - -/* config GKeyFile */ -static GKeyFile *key_file = NULL; - -/* saving interval */ -#define SAVING_INTERVAL 2000000 - -/* saving thread staff */ -static GMutex *change_config_mutex; -static GCond *cond; -static GThread *saving_thread; -static gboolean config_changed = FALSE; - -/* - * function for a config file background saving if changed - */ -static gpointer saving_thread_func(gpointer data) -{ - GTimeVal interval; - GMutex *m = g_mutex_new(); - do - { - g_mutex_lock(change_config_mutex); - if (config_changed) - { - gchar *config_data = g_key_file_to_data(key_file, NULL, NULL); - g_file_set_contents(config_path, config_data, -1, NULL); - g_free(config_data); - - config_changed = FALSE; - } - g_mutex_unlock(change_config_mutex); - - g_get_current_time(&interval); - g_time_val_add(&interval, SAVING_INTERVAL); - } - while (!g_cond_timed_wait(cond, m, &interval)); - g_mutex_free(m); - - return NULL; -} - -/* - * set default values in the GKeyFile - */ -void pconfig_set_defaults(GKeyFile *kf) -{ - g_key_file_set_boolean(key_file, "tabbed_mode", "enabled", FALSE); - - int all_tabs[] = { TID_TARGET, TID_BREAKS, TID_AUTOS, TID_WATCH, TID_STACK, TID_TERMINAL, TID_MESSAGES }; - g_key_file_set_integer_list(key_file, "one_panel_mode", "tabs", all_tabs, sizeof(all_tabs) / sizeof(int)); - g_key_file_set_integer(key_file, "one_panel_mode", "selected_tab_index", 0); - - int left_tabs[] = { TID_TARGET, TID_BREAKS, TID_AUTOS, TID_WATCH }; - g_key_file_set_integer_list(key_file, "two_panels_mode", "left_tabs", left_tabs, sizeof(left_tabs) / sizeof(int)); - g_key_file_set_integer(key_file, "two_panels_mode", "left_selected_tab_index", 0); - int right_tabs[] = { TID_STACK, TID_TERMINAL, TID_MESSAGES }; - g_key_file_set_integer_list(key_file, "two_panels_mode", "right_tabs", right_tabs, sizeof(right_tabs) / sizeof(int)); - g_key_file_set_integer(key_file, "two_panels_mode", "right_selected_tab_index", 0); -} - -/* - * initialize - */ -void pconfig_init() -{ - /* read config */ - gchar *config_dir = g_build_path(G_DIR_SEPARATOR_S, geany_data->app->configdir, "plugins", "debugger", NULL); - config_path = g_build_path(G_DIR_SEPARATOR_S, config_dir, "debugger.conf", NULL); - - g_mkdir_with_parents(config_dir, S_IRUSR | S_IWUSR | S_IXUSR); - g_free(config_dir); - - key_file = g_key_file_new(); - if (!g_key_file_load_from_file(key_file, config_path, G_KEY_FILE_NONE, NULL)) - { - pconfig_set_defaults(key_file); - gchar *data = g_key_file_to_data(key_file, NULL, NULL); - g_file_set_contents(config_path, data, -1, NULL); - g_free(data); - } - - change_config_mutex = g_mutex_new(); - cond = g_cond_new(); - saving_thread = g_thread_create(saving_thread_func, NULL, TRUE, NULL); -} - -/* - * destroy - */ -void pconfig_destroy() -{ - g_cond_signal(cond); - /* ??? g_thread_join(saving_thread); */ - - g_mutex_free(change_config_mutex); - g_cond_free(cond); - - g_free(config_path); -} - -/* - * set one or several config values - */ -void pconfig_set(int config_part, gpointer config_value, ...) -{ - g_mutex_lock(change_config_mutex); - - va_list ap; - va_start(ap, config_value); - - while(config_part) - { - switch (config_part) - { - case CP_TABBED_MODE: - { - g_key_file_set_boolean(key_file, "tabbed_mode", "enabled", (gboolean)config_value); - break; - } - case CP_OT_TABS: - { - int *array = (int*)config_value; - g_key_file_set_integer_list(key_file, "one_panel_mode", "tabs", array + 1, array[0]); - break; - } - case CP_OT_SELECTED: - { - g_key_file_set_integer(key_file, "one_panel_mode", "selected_tab_index", (int)config_value); - break; - } - case CP_TT_LTABS: - { - int *array = (int*)config_value; - g_key_file_set_integer_list(key_file, "two_panels_mode", "left_tabs", array + 1, array[0]); - break; - } - case CP_TT_LSELECTED: - { - g_key_file_set_integer(key_file, "two_panels_mode", "left_selected_tab_index", (int)config_value); - break; - } - case CP_TT_RTABS: - { - int *array = (int*)config_value; - g_key_file_set_integer_list(key_file, "two_panels_mode", "right_tabs", array + 1, array[0]); - break; - } - case CP_TT_RSELECTED: - { - g_key_file_set_integer(key_file, "two_panels_mode", "right_selected_tab_index", (int)config_value); - break; - } - } - - config_part = va_arg(ap, int); - if (config_part) - { - config_value = va_arg(ap, gpointer); - } - } - - config_changed = TRUE; - g_mutex_unlock(change_config_mutex); -} - -/* - * config parts getters - */ - -gboolean pconfig_get_tabbed() -{ - return g_key_file_get_boolean(key_file, "tabbed_mode", "enabled", NULL); -} -int* pconfig_get_tabs(gsize *length) -{ - return g_key_file_get_integer_list(key_file, "one_panel_mode", "tabs", length, NULL); -} -int pconfig_get_selected_tab_index() -{ - return g_key_file_get_integer(key_file, "one_panel_mode", "selected_tab_index", NULL); -} -int* pconfig_get_left_tabs(gsize *length) -{ - return g_key_file_get_integer_list(key_file, "two_panels_mode", "left_tabs", length, NULL); -} -int pconfig_get_left_selected_tab_index() -{ - return g_key_file_get_integer(key_file, "two_panels_mode", "left_selected_tab_index", NULL); -} -int* pconfig_get_right_tabs(gsize *length) -{ - return g_key_file_get_integer_list(key_file, "two_panels_mode", "right_tabs", length, NULL); -} -int pconfig_get_right_selected_tab_index() -{ - return g_key_file_get_integer(key_file, "two_panels_mode", "right_selected_tab_index", NULL); -}
Deleted: trunk/geany-plugins/debugger/src/pconfig.h =================================================================== --- trunk/geany-plugins/debugger/src/pconfig.h 2011-09-25 20:08:05 UTC (rev 2216) +++ trunk/geany-plugins/debugger/src/pconfig.h 2011-09-29 11:05:32 UTC (rev 2217) @@ -1,47 +0,0 @@ -/* - * pconfig.h - * - * Copyright 2011 Alexander Petukhov <devel(at)apetukhov.ru> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301, USA. - */ - -#include <stdarg.h> - -/* config parts */ -#define CP_TABBED_MODE 1 -#define CP_OT_TABS 2 -#define CP_OT_SELECTED 3 -#define CP_TT_LTABS 4 -#define CP_TT_LSELECTED 5 -#define CP_TT_RTABS 6 -#define CP_TT_RSELECTED 7 - -void pconfig_init(); -void pconfig_destroy(); - -void pconfig_set(int config_part, gpointer config_value, ...); - -gboolean pconfig_get_tabbed(); - -int* pconfig_get_tabs(gsize *length); -int pconfig_get_selected_tab_index(); - -int* pconfig_get_left_tabs(gsize *length); -int pconfig_get_left_selected_tab_index(); - -int* pconfig_get_right_tabs(gsize *length); -int pconfig_get_right_selected_tab_index();
Modified: trunk/geany-plugins/debugger/src/plugin.c =================================================================== --- trunk/geany-plugins/debugger/src/plugin.c 2011-09-25 20:08:05 UTC (rev 2216) +++ trunk/geany-plugins/debugger/src/plugin.c 2011-09-29 11:05:32 UTC (rev 2217) @@ -68,11 +68,12 @@ * can prevent Geany from processing the notification. Use this with care. */ { "editor-notify", (GCallback) &on_editor_notify, FALSE, NULL }, { "document_open", (GCallback) &on_document_open, FALSE, NULL }, - { "document_activate", (GCallback) &on_document_activate, FALSE, NULL }, - { "document_close", (GCallback) &on_document_close, FALSE, NULL }, { "document_save", (GCallback) &on_document_save, FALSE, NULL }, { "document_before_save", (GCallback) &on_document_before_save, FALSE, NULL }, { "document_new", (GCallback) &on_document_new, FALSE, NULL }, + { "project_open", (GCallback) &config_on_project_open, FALSE, NULL }, + { "project_close", (GCallback) &config_on_project_close, FALSE, NULL }, + { "project_save", (GCallback) &config_on_project_save, FALSE, NULL }, { NULL, NULL, FALSE, NULL } }; @@ -84,6 +85,7 @@ tpage_pack_widgets(state); }
+extern void config_on_project_open(GObject *obj, GKeyFile *config, gpointer user_data); /* Called by Geany to initialize the plugin. * Note: data is the same as geany_data. */ void plugin_init(GeanyData *data) @@ -95,7 +97,8 @@ pixbufs_init();
/* main box */ - hbox = gtk_hbox_new(FALSE, 0); + hbox = gtk_hbox_new(FALSE, 7); + gtk_container_set_border_width(GTK_CONTAINER(hbox), 6);
/* add target page */ tpage_init(); @@ -109,9 +112,12 @@ /* init debug */ debug_init();
+ /* load config */ + config_init(); + /* init paned */ dpaned_init(); - tpage_pack_widgets(dpaned_get_tabbed()); + tpage_pack_widgets(config_get_tabbed());
GtkWidget* vbox = btnpanel_create(on_paned_mode_changed);
@@ -125,11 +131,15 @@ hbox, gtk_label_new(_("Debug")));
- /* init config */ - dconfig_init(); + if (geany_data->app->project) + { + config_update_project_keyfile(); + } + config_set_debug_store( + config_get_save_to_project() && geany_data->app->project ? DEBUG_STORE_PROJECT : DEBUG_STORE_PLUGIN + ); }
- /* Called by Geany to show the plugin's configure dialog. This function is always called after * plugin_init() was called. * You can omit this function if the plugin doesn't need to be configured. @@ -137,11 +147,7 @@ * dialog. */ GtkWidget *plugin_configure(GtkDialog *dialog) { - /* configuration dialog */ - GtkWidget *vbox = gtk_vbox_new(FALSE, 6); - - gtk_widget_show_all(vbox); - return vbox; + return config_plugin_configure(dialog); }
@@ -158,21 +164,11 @@ g_main_context_iteration(NULL,FALSE); }
+ config_destroy(); pixbufs_destroy(); - - /* destroy debug-related stuff */ debug_destroy(); - - /* destroy breaks */ breaks_destroy(); - - /* clears config */ - dconfig_destroy(); - - /* clears debug paned data */ dpaned_destroy(); - - /* clears anv tree data */ envtree_destroy(); /* release other allocated strings and objects */
Modified: trunk/geany-plugins/debugger/src/tpage.c =================================================================== --- trunk/geany-plugins/debugger/src/tpage.c 2011-09-25 20:08:05 UTC (rev 2216) +++ trunk/geany-plugins/debugger/src/tpage.c 2011-09-29 11:05:32 UTC (rev 2217) @@ -85,7 +85,7 @@ */ static void on_arguments_changed(GtkTextBuffer *textbuffer, gpointer user_data) { - dconfig_set_changed(); + config_set_debug_changed(); }
/* @@ -120,7 +120,7 @@ gtk_entry_set_text(GTK_ENTRY(target_name), filename); g_free (filename); - dconfig_set_changed(); + config_set_debug_changed(); } gtk_widget_destroy (dialog); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
plugins-commits@lists.geany.org