Revision: 2172 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=2172&view=re... Author: cesspit Date: 2011-08-27 12:45:36 +0000 (Sat, 27 Aug 2011) Log Message: ----------- debugger: Correcting markers when "savings as", removing or modifying a file from outside geany. Another portion of compiler casting warning removed.
Modified Paths: -------------- trunk/geany-plugins/debugger/src/bptree.c trunk/geany-plugins/debugger/src/breakpoint.c trunk/geany-plugins/debugger/src/breakpoint.h trunk/geany-plugins/debugger/src/breakpoints.c trunk/geany-plugins/debugger/src/breakpoints.h trunk/geany-plugins/debugger/src/callbacks.c trunk/geany-plugins/debugger/src/callbacks.h trunk/geany-plugins/debugger/src/dbm_gdb.c trunk/geany-plugins/debugger/src/debug.c trunk/geany-plugins/debugger/src/debug.h trunk/geany-plugins/debugger/src/debug_module.h trunk/geany-plugins/debugger/src/markers.c trunk/geany-plugins/debugger/src/markers.h trunk/geany-plugins/debugger/src/plugin.c trunk/geany-plugins/debugger/src/stree.c trunk/geany-plugins/debugger/src/tpage.c trunk/geany-plugins/debugger/src/utils.c trunk/geany-plugins/debugger/src/utils.h trunk/geany-plugins/debugger/src/vtree.c
Modified: trunk/geany-plugins/debugger/src/bptree.c =================================================================== --- trunk/geany-plugins/debugger/src/bptree.c 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/bptree.c 2011-08-27 12:45:36 UTC (rev 2172) @@ -343,7 +343,7 @@
/* creating columns */ GtkTreeViewColumn *column; - gchar *header; + const gchar *header; int char_width = get_char_width(tree);
Modified: trunk/geany-plugins/debugger/src/breakpoint.c =================================================================== --- trunk/geany-plugins/debugger/src/breakpoint.c 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/breakpoint.c 2011-08-27 12:45:36 UTC (rev 2172) @@ -47,7 +47,7 @@ * enabled - is new breakpoint enabled * hitscount - breakpoints hitscount */ -breakpoint* break_new_full(char* file, int line, char* condition, int enabled, int hitscount) +breakpoint* break_new_full(const char* file, int line, const char* condition, int enabled, int hitscount) { breakpoint* bp = break_new(); strcpy(bp->file, file);
Modified: trunk/geany-plugins/debugger/src/breakpoint.h =================================================================== --- trunk/geany-plugins/debugger/src/breakpoint.h 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/breakpoint.h 2011-08-27 12:45:36 UTC (rev 2172) @@ -33,4 +33,4 @@ } breakpoint;
breakpoint* break_new(); -breakpoint* break_new_full(char* file, int line, char* condition, int enabled, int hitscount); +breakpoint* break_new_full(const char* file, int line, const char* condition, int enabled, int hitscount);
Modified: trunk/geany-plugins/debugger/src/breakpoints.c =================================================================== --- trunk/geany-plugins/debugger/src/breakpoints.c 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/breakpoints.c 2011-08-27 12:45:36 UTC (rev 2172) @@ -105,7 +105,7 @@ * file - breakpoints filename * line - breakpoints line */ -breakpoint* lookup_breakpoint(gchar* file, int line) +breakpoint* lookup_breakpoint(const gchar* file, int line) { breakpoint* bp = NULL; GTree* tree = NULL; @@ -315,7 +315,7 @@ * enabled - is new breakpoint enabled * hitscount - breakpoints hitscount */ -void breaks_add(char* file, int line, char* condition, int enabled, int hitscount) +void breaks_add(const char* file, int line, char* condition, int enabled, int hitscount) { /* do not process async break manipulation on modules that do not support async interuppt */ @@ -352,7 +352,7 @@ * file - breakpoints filename * line - breakpoints line */ -void breaks_remove(char* file, int line) +void breaks_remove(const char* file, int line) { /* do not process async break manipulation on modules that do not support async interuppt */ @@ -389,7 +389,7 @@ * file - breakpoints filename * line - breakpoints line */ -void breaks_switch(char* file, int line) +void breaks_switch(const char* file, int line) { /* do not process async break manipulation on modules that do not support async interuppt */ @@ -505,7 +505,7 @@ * file - breakpoints filename * line - breakpoints line */ -break_state breaks_get_state(char* file, int line) +break_state breaks_get_state(const char* file, int line) { break_state bs = BS_NOT_SET; @@ -528,7 +528,7 @@ * arguments: * file - file name to get breaks for */ -GList *breaks_get_for_document(char* file) +GList *breaks_get_for_document(const char* file) { GList *breaks = NULL; GTree *tree = g_hash_table_lookup(files, file);
Modified: trunk/geany-plugins/debugger/src/breakpoints.h =================================================================== --- trunk/geany-plugins/debugger/src/breakpoints.h 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/breakpoints.h 2011-08-27 12:45:36 UTC (rev 2172) @@ -29,16 +29,16 @@
gboolean breaks_init(move_to_line_cb callback); void breaks_destroy(); -void breaks_add(char* file, int line, char* condition, int enable, int hitscount); -void breaks_remove(char* file, int line); +void breaks_add(const char* file, int line, char* condition, int enable, int hitscount); +void breaks_remove(const char* file, int line); void breaks_remove_all(); -void breaks_switch(char* file, int line); +void breaks_switch(const char* file, int line); void breaks_set_hits_count(char* file, int line, int count); void breaks_set_condition(char* file, int line, char* condition); void breaks_move_to_line(char* file, int line_from, int line_to); -break_state breaks_get_state(char* file, int line); +break_state breaks_get_state(const char* file, int line); GtkWidget* breaks_get_widget(); -GList* breaks_get_for_document(char* file); +GList* breaks_get_for_document(const char* file); GList* breaks_get_all(); void breaks_read_config();
Modified: trunk/geany-plugins/debugger/src/callbacks.c =================================================================== --- trunk/geany-plugins/debugger/src/callbacks.c 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/callbacks.c 2011-08-27 12:45:36 UTC (rev 2172) @@ -42,12 +42,72 @@ extern GeanyFunctions *geany_functions;
/* + * Set breakpoint and stack markers for a file + */ +void set_markers_for_file(const gchar* file) +{ + GList *breaks; + if ( (breaks = breaks_get_for_document(file)) ) + { + GList *iter = breaks; + while (iter) + { + breakpoint *bp = (breakpoint*)iter->data; + markers_add_breakpoint(bp); + + iter = iter->next; + } + g_list_free(breaks); + } + + /* set frames markers if exists */ + if (DBS_STOPPED == debug_get_state()) + { + GList *iter = debug_get_stack(); + if (iter) + { + frame *f = (frame*)iter->data; + if (f->have_source && !strcmp(f->file, file)) + { + markers_add_current_instruction(f->file, f->line); + } + + iter = iter->next; + while (iter) + { + f = (frame*)iter->data; + if (f->have_source && !strcmp(f->file, file)) + { + markers_add_frame(f->file, f->line); + } + iter = iter->next; + } + } + } +} + +/* * Following group of callbacks are used for * checking of existance of the config file * and changing buttons state in the target page */
/* + * Occures before document is going to be saved + */ +static gboolean _unexisting_file = FALSE; +void on_document_before_save(GObject *obj, GeanyDocument *doc, gpointer user_data) +{ + if (!doc->real_path) + { + /* we can fall here if we are saving new document + (that doesn't exists on a filesystem) or if we're "Saving As" */ + + _unexisting_file = TRUE; + } +} + +/* * Occures on closing document */ void on_document_close(GObject *obj, GeanyDocument *doc, gpointer user_data) @@ -60,6 +120,21 @@ */ void on_document_save(GObject *obj, GeanyDocument *doc, gpointer user_data) { + if (_unexisting_file) + { + /* if we are saving as - remove all markers at first */ + markers_remove_all(doc); + + /* next, lets try to find and insert markers for the file, current document is being saved to*/ + set_markers_for_file(doc->file_name); + + /* if debug is active - tell the debug module that a file was opened */ + if (DBS_IDLE != debug_get_state()) + debug_on_file_open(doc); + + _unexisting_file = FALSE; + } + btnpanel_on_document_activate(doc); }
@@ -84,7 +159,7 @@ */ void on_document_open(GObject *obj, GeanyDocument *doc, gpointer user_data) { - char* file = DOC_FILENAME(doc); + const gchar* file = DOC_FILENAME(doc); /*set markers*/ markers_set_for_document(doc->editor->sci);
@@ -97,50 +172,14 @@ /* set caret policy */ scintilla_send_message(doc->editor->sci, SCI_SETYCARETPOLICY, CARET_SLOP | CARET_JUMPS | CARET_EVEN , 3); + /* 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);
- GList *breaks; - if ( (breaks = breaks_get_for_document(file)) ) - { - GList *iter = breaks; - while (iter) - { - breakpoint *bp = (breakpoint*)iter->data; - markers_add_breakpoint(bp); - - iter = iter->next; - } - g_list_free(breaks); - } - - /* set frames markers if exists */ - if (DBS_STOPPED == debug_get_state()) - { - GList *iter = debug_get_stack(); - if (iter) - { - frame *f = (frame*)iter->data; - if (f->have_source && !strcmp(f->file, file)) - { - markers_add_current_instruction(f->file, f->line); - } - - iter = iter->next; - while (iter) - { - f = (frame*)iter->data; - if (f->have_source && !strcmp(f->file, file)) - { - markers_add_frame(f->file, f->line); - } - iter = iter->next; - } - } - } - /* if debug is active - tell the debug module that a file was opened */ if (DBS_IDLE != debug_get_state()) debug_on_file_open(doc); @@ -154,6 +193,12 @@ GObject *object, GeanyEditor *editor, SCNotification *nt, gpointer data) { + if (!editor->document->real_path) + { + /* no other way to handle removing a file from outside of geany */ + markers_remove_all(editor->document); + } + switch (nt->nmhdr.code) { case SCN_MARGINCLICK:
Modified: trunk/geany-plugins/debugger/src/callbacks.h =================================================================== --- trunk/geany-plugins/debugger/src/callbacks.h 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/callbacks.h 2011-08-27 12:45:36 UTC (rev 2172) @@ -23,6 +23,7 @@ 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); gboolean on_editor_notify(GObject *object, GeanyEditor *editor, SCNotification *nt, gpointer data); gboolean keys_callback(guint key_id);
Modified: trunk/geany-plugins/debugger/src/dbm_gdb.c =================================================================== --- trunk/geany-plugins/debugger/src/dbm_gdb.c 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/dbm_gdb.c 2011-08-27 12:45:36 UTC (rev 2172) @@ -717,7 +717,7 @@ /* * execute until */ -void execute_until(gchar *file, int line) +void execute_until(const gchar *file, int line) { gchar command[1000]; sprintf(command, "-exec-until %s:%i", file, line);
Modified: trunk/geany-plugins/debugger/src/debug.c =================================================================== --- trunk/geany-plugins/debugger/src/debug.c 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/debug.c 2011-08-27 12:45:36 UTC (rev 2172) @@ -837,7 +837,7 @@ /* * called from debugger module to show an error message box */ -static void on_debugger_error (gchar* message) +static void on_debugger_error (const gchar* message) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, "%s", message); } @@ -1209,7 +1209,7 @@ /* * step to position */ -void debug_execute_until(gchar *file, int line) +void debug_execute_until(const gchar *file, int line) { if (DBS_STOPPED == debug_state) active_module->execute_until(file, line); @@ -1355,7 +1355,7 @@ */ void debug_on_file_open(GeanyDocument *doc) { - gchar *file = DOC_FILENAME(doc); + const gchar *file = DOC_FILENAME(doc); if (g_list_find_custom(read_only_pages, (gpointer)file, (GCompareFunc)g_strcmp0)) scintilla_send_message(doc->editor->sci, SCI_SETREADONLY, 1, 0); }
Modified: trunk/geany-plugins/debugger/src/debug.h =================================================================== --- trunk/geany-plugins/debugger/src/debug.h 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/debug.h 2011-08-27 12:45:36 UTC (rev 2172) @@ -41,7 +41,7 @@ void debug_step_over(); void debug_step_into(); void debug_step_out(); -void debug_execute_until(gchar *file, int line); +void debug_execute_until(const gchar *file, int line); gboolean debug_set_break(breakpoint* bp, break_set_activity bsa); gboolean debug_remove_break(breakpoint* bp); void debug_request_interrupt(bs_callback cb, breakpoint* bp, break_set_activity flags);
Modified: trunk/geany-plugins/debugger/src/debug_module.h =================================================================== --- trunk/geany-plugins/debugger/src/debug_module.h 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/debug_module.h 2011-08-27 12:45:36 UTC (rev 2172) @@ -26,7 +26,7 @@ void (*set_exited) (int code); void (*send_message) (const gchar* message, const gchar *color); void (*clear_messages) (); - void (*report_error) (gchar* message); + void (*report_error) (const gchar* message); } dbg_callbacks;
/* type to hold information about a variable */ @@ -84,7 +84,7 @@ void (*step_over) (); void (*step_into) (); void (*step_out) (); - void (*execute_until)(gchar *file, int line); + void (*execute_until)(const gchar *file, int line);
gboolean (*set_break) (breakpoint* bp, break_set_activity bsa); gboolean (*remove_break) (breakpoint* bp);
Modified: trunk/geany-plugins/debugger/src/markers.c =================================================================== --- trunk/geany-plugins/debugger/src/markers.c 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/markers.c 2011-08-27 12:45:36 UTC (rev 2172) @@ -208,3 +208,16 @@ scintilla_send_message(doc->editor->sci, SCI_SETFOCUS, TRUE, 0); } } + +/* + * removes all markers from GeanyDocument + */ +void markers_remove_all(GeanyDocument *doc) +{ + static int markers[] = { M_BP_ENABLED, M_BP_DISABLED, M_BP_CONDITIONAL, M_CI_BACKGROUND, M_CI_ARROW, M_FRAME }; + int i = 0, size = sizeof(markers) / sizeof(int); + for (; i < size; i++) + { + scintilla_send_message(doc->editor->sci, SCI_MARKERDELETEALL, markers[i], 0); + } +}
Modified: trunk/geany-plugins/debugger/src/markers.h =================================================================== --- trunk/geany-plugins/debugger/src/markers.h 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/markers.h 2011-08-27 12:45:36 UTC (rev 2172) @@ -27,5 +27,6 @@ void markers_remove_current_instruction(char* file, int line); void markers_add_frame(char* file, int line); void markers_remove_frame(char* file, int line); +void markers_remove_all(GeanyDocument *doc);
Modified: trunk/geany-plugins/debugger/src/plugin.c =================================================================== --- trunk/geany-plugins/debugger/src/plugin.c 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/plugin.c 2011-08-27 12:45:36 UTC (rev 2172) @@ -68,6 +68,7 @@ { "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 }, { NULL, NULL, FALSE, NULL }
Modified: trunk/geany-plugins/debugger/src/stree.c =================================================================== --- trunk/geany-plugins/debugger/src/stree.c 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/stree.c 2011-08-27 12:45:36 UTC (rev 2172) @@ -134,7 +134,7 @@ /* creating columns */ GtkCellRenderer *renderer; GtkTreeViewColumn *column; - gchar *header; + const gchar *header; int char_width = get_char_width(tree);
Modified: trunk/geany-plugins/debugger/src/tpage.c =================================================================== --- trunk/geany-plugins/debugger/src/tpage.c 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/tpage.c 2011-08-27 12:45:36 UTC (rev 2172) @@ -635,7 +635,7 @@ g_object_set(envtree, "rules-hint", TRUE, NULL); g_signal_connect(G_OBJECT(envtree), "key-press-event", G_CALLBACK (on_envtree_keypressed), NULL);
- gchar *header; + const gchar *header; int char_width = get_char_width(envtree);
header = _("Name");
Modified: trunk/geany-plugins/debugger/src/utils.c =================================================================== --- trunk/geany-plugins/debugger/src/utils.c 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/utils.c 2011-08-27 12:45:36 UTC (rev 2172) @@ -62,7 +62,7 @@ /* * get string width if string length is bigger than minwidth or minwidth * char_width */ -int get_header_string_width(gchar *header, int minchars, int char_width) +int get_header_string_width(const gchar *header, int minchars, int char_width) { return strlen(header) > minchars ? strlen(header) : minchars * char_width; } @@ -70,7 +70,7 @@ /* * create tree view column */ -GtkTreeViewColumn *create_column(gchar *name, GtkCellRenderer *renderer, gboolean expandable, gint minwidth, const char *arg, int value) +GtkTreeViewColumn *create_column(const gchar *name, GtkCellRenderer *renderer, gboolean expandable, gint minwidth, const char *arg, int value) { gtk_cell_renderer_set_padding(renderer, RENDERER_X_PADDING, RENDERER_Y_PADDING); @@ -101,6 +101,10 @@ sci_goto_line(doc->editor->sci, line - 1, TRUE); scintilla_send_message(doc->editor->sci, SCI_SETFOCUS, TRUE, 0); } + else + { + dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Can't find a source file "%s""), file); + } }
/*
Modified: trunk/geany-plugins/debugger/src/utils.h =================================================================== --- trunk/geany-plugins/debugger/src/utils.h 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/utils.h 2011-08-27 12:45:36 UTC (rev 2172) @@ -21,6 +21,6 @@
void editor_open_position(char* file, int line); int get_char_width(GtkWidget *widget); -int get_header_string_width(gchar *header, int minchars, int char_width); -GtkTreeViewColumn* create_column(gchar *name, GtkCellRenderer *renderer, gboolean expandable, gint minwidth, const char *arg, int value); +int get_header_string_width(const gchar *header, int minchars, int char_width); +GtkTreeViewColumn* create_column(const gchar *name, GtkCellRenderer *renderer, gboolean expandable, gint minwidth, const char *arg, int value); GString* get_word_at_position(ScintillaObject *sci, int position);
Modified: trunk/geany-plugins/debugger/src/vtree.c =================================================================== --- trunk/geany-plugins/debugger/src/vtree.c 2011-08-25 19:34:37 UTC (rev 2171) +++ trunk/geany-plugins/debugger/src/vtree.c 2011-08-27 12:45:36 UTC (rev 2172) @@ -128,7 +128,7 @@ /* create columns */ GtkCellRenderer *renderer; GtkTreeViewColumn *column; - gchar *header; + const gchar *header; int char_width = get_char_width(tree);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.