Revision: 406 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=406&view=rev Author: kugel- Date: 2009-01-26 22:51:55 +0000 (Mon, 26 Jan 2009)
Log Message: ----------- Use flags in command_with_question_activated (and remove the ask flag). Commands can set FLAG_DIR, so that the dir instead of the filename will passed to that command. Remove code which is only needed to reload the file after an action, and use command_with_question_activated for the reload (with FLAG_RELOAD). Some other cleanup. Run that rediculous indent-all.sh script.
Modified Paths: -------------- branches/GeanyVC_menu_redesign/geanyvc.c branches/GeanyVC_menu_redesign/geanyvc.h
Modified: branches/GeanyVC_menu_redesign/geanyvc.c =================================================================== --- branches/GeanyVC_menu_redesign/geanyvc.c 2009-01-26 18:52:40 UTC (rev 405) +++ branches/GeanyVC_menu_redesign/geanyvc.c 2009-01-26 22:51:55 UTC (rev 406) @@ -131,9 +131,7 @@ };
PLUGIN_KEY_GROUP(geanyvc, COUNT_KB) - -GSList * -get_commit_files_null(G_GNUC_UNUSED const gchar * dir) +GSList *get_commit_files_null(G_GNUC_UNUSED const gchar * dir) { return NULL; } @@ -446,23 +444,23 @@ if (cur != g_slist_last(largv)) { utils_spawn_sync(dir, cur->data, (gchar **) env, - G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL | - G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, NULL, NULL, - &exit_code, &error); + G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL | + G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL, NULL, NULL, + &exit_code, &error); } else { utils_spawn_sync(dir, cur->data, (gchar **) env, - G_SPAWN_SEARCH_PATH | (std_out ? 0 : - G_SPAWN_STDOUT_TO_DEV_NULL) | - (std_err ? 0 : G_SPAWN_STDERR_TO_DEV_NULL), NULL, NULL, - std_out, std_err, &exit_code, &error); + G_SPAWN_SEARCH_PATH | (std_out ? 0 : + G_SPAWN_STDOUT_TO_DEV_NULL) | + (std_err ? 0 : G_SPAWN_STDERR_TO_DEV_NULL), NULL, NULL, + std_out, std_err, &exit_code, &error); } if (error) { g_warning("geanyvc: s_spawn_sync error: %s", error->message); ui_set_statusbar(FALSE, _("geanyvc: s_spawn_sync error: %s"), - error->message); + error->message); g_error_free(error); }
@@ -478,8 +476,7 @@ if (!g_utf8_validate(*std_out, -1, NULL)) { setptr(*std_out, encodings_convert_to_utf8(*std_out, - strlen(*std_out), - NULL)); + strlen(*std_out), NULL)); } if (!NZV(*std_out)) { @@ -497,8 +494,7 @@ if (!g_utf8_validate(*std_err, -1, NULL)) { setptr(*std_err, encodings_convert_to_utf8(*std_err, - strlen(*std_err), - NULL)); + strlen(*std_err), NULL)); } if (!NZV(*std_err)) { @@ -850,7 +846,7 @@ }
static gboolean -command_with_question_activated(gchar ** text, gint cmd, const gchar * question, gboolean ask) +command_with_question_activated(gchar ** text, gint cmd, const gchar * question, gint flags) { GtkWidget *dialog; gint result; @@ -861,17 +857,22 @@ doc = document_get_current(); g_return_val_if_fail(doc != NULL && doc->file_name != NULL, FALSE);
+ dir = g_path_get_dirname(doc->file_name); + vc = find_vc(dir); + g_return_val_if_fail(vc, FALSE); + if (doc->changed) { document_save_file(doc, FALSE); }
- if (ask) + if ((flags & FLAG_FORCE_ASK) || set_add_confirmation) { dialog = gtk_message_dialog_new(GTK_WINDOW(geany->main_widgets->window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, - GTK_BUTTONS_YES_NO, question, doc->file_name); + GTK_BUTTONS_YES_NO, question, + (flags & FLAG_DIR ? dir : doc->file_name)); result = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } @@ -882,52 +883,40 @@
if (result == GTK_RESPONSE_YES) { - dir = g_path_get_dirname(doc->file_name); - vc = find_vc(dir); - g_return_val_if_fail(vc, FALSE); - - execute_command(vc, text, NULL, doc->file_name, cmd, NULL, NULL); - g_free(dir); + if (flags & FLAG_FILE) + execute_command(vc, text, NULL, doc->file_name, cmd, NULL, NULL); + if (flags & FLAG_DIR) + execute_command(vc, text, NULL, dir, cmd, NULL, NULL); + if (flags & FLAG_RELOAD) + document_reload_file(doc, NULL); } - return (result == GTK_RESPONSE_YES) ? TRUE : FALSE; + return (result == GTK_RESPONSE_YES); }
static void vcrevert_activated(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer gdata) { - gboolean ret; - GeanyDocument *doc; - - doc = document_get_current(); - g_return_if_fail(doc != NULL && doc->file_name != NULL); - - ret = command_with_question_activated(NULL, VC_COMMAND_REVERT_FILE, - _("Do you really want to revert: %s?"), TRUE); - if (ret) - { - document_reload_file(doc, NULL); - } + command_with_question_activated(NULL, VC_COMMAND_REVERT_FILE, + _("Do you really want to revert: %s?"), + FLAG_RELOAD | FLAG_FILE | FLAG_FORCE_ASK); }
- static void vcadd_activated(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer gdata) { command_with_question_activated(NULL, VC_COMMAND_ADD, - _("Do you really want to add: %s?"), set_add_confirmation); + _("Do you really want to add: %s?"), FLAG_FILE); }
static void vcremove_activated(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer gdata) { - gboolean ret; - - ret = command_with_question_activated(NULL, VC_COMMAND_REMOVE, - _("Do you really want to remove: %s?"), TRUE); - if (ret) + if (command_with_question_activated(NULL, VC_COMMAND_REMOVE, + _("Do you really want to remove: %s?"), + FLAG_FORCE_ASK | FLAG_FILE)) { document_remove_page(gtk_notebook_get_current_page - (GTK_NOTEBOOK(geany->main_widgets->notebook))); + (GTK_NOTEBOOK(geany->main_widgets->notebook))); } }
@@ -946,17 +935,14 @@ document_save_file(doc, FALSE); }
- ret = command_with_question_activated(&text, VC_COMMAND_UPDATE, - _("Do you really want to update?"), - set_add_confirmation); - if (ret) + if (command_with_question_activated(&text, VC_COMMAND_UPDATE, + _("Do you really want to update?"), FLAG_FILE)) { document_reload_file(doc, NULL);
if (NZV(text)) show_output(text, "*VC-UPDATE*", NULL); - if (text) - g_free(text); + g_free(text); } }
@@ -1430,7 +1416,7 @@ if (speller == NULL) { ui_set_statusbar(FALSE, _("Error initializing spell checking: %s"), - spellcheck_error->message); + spellcheck_error->message); g_error_free(spellcheck_error); spellcheck_error = NULL; } @@ -1440,9 +1426,9 @@ if (spellcheck_error != NULL) { ui_set_statusbar(TRUE, - _ - ("Error while setting up language for spellchecking. Please check configuration. Error message was: %s"), - spellcheck_error->message); + _ + ("Error while setting up language for spellchecking. Please check configuration. Error message was: %s"), + spellcheck_error->message); g_error_free(spellcheck_error); spellcheck_error = NULL; } @@ -1536,37 +1522,44 @@ }
-static void kbdiff_file(G_GNUC_UNUSED guint key_id) +static void +kbdiff_file(G_GNUC_UNUSED guint key_id) { vcdiff_file_activated(NULL, NULL); }
-static void kbdiff_dir(G_GNUC_UNUSED guint key_id) +static void +kbdiff_dir(G_GNUC_UNUSED guint key_id) { vcdiff_dir_activated(NULL, NULL); }
-static void kbdiff_basedir(G_GNUC_UNUSED guint key_id) +static void +kbdiff_basedir(G_GNUC_UNUSED guint key_id) { vcdiff_basedir_activated(NULL, NULL); }
-static void kbstatus(G_GNUC_UNUSED guint key_id) +static void +kbstatus(G_GNUC_UNUSED guint key_id) { vcstatus_activated(NULL, NULL); }
-static void kbcommit(G_GNUC_UNUSED guint key_id) +static void +kbcommit(G_GNUC_UNUSED guint key_id) { vccommit_activated(NULL, NULL); }
-static void kbrevert(G_GNUC_UNUSED guint key_id) +static void +kbrevert(G_GNUC_UNUSED guint key_id) { vcrevert_activated(NULL, NULL); }
-static void kbupdate(G_GNUC_UNUSED guint key_id) +static void +kbupdate(G_GNUC_UNUSED guint key_id) { vcupdate_activated(NULL, NULL); } @@ -1645,8 +1638,8 @@ && utils_mkdir(config_dir, TRUE) != 0) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, - _ - ("Plugin configuration directory could not be created.")); + _ + ("Plugin configuration directory could not be created.")); } else { @@ -1890,16 +1883,16 @@ }
static void -do_current_file_menu(GtkWidget **parent_menu, GtkTooltips **tooltips) +do_current_file_menu(GtkWidget ** parent_menu, GtkTooltips ** tooltips) { GtkWidget *cur_file_menu = NULL; - /* Menu which will hold the items in the current file menu */ + /* Menu which will hold the items in the current file menu */ cur_file_menu = gtk_menu_new();
*parent_menu = gtk_image_menu_item_new_with_mnemonic(_("Current _File")); - g_signal_connect((gpointer) *parent_menu, "activate", G_CALLBACK(update_menu_items), NULL); + g_signal_connect((gpointer) * parent_menu, "activate", G_CALLBACK(update_menu_items), NULL);
- /* Diff of current file */ + /* Diff of current file */ menu_vc_diff_file = gtk_menu_item_new_with_mnemonic(_("_Diff")); gtk_container_add(GTK_CONTAINER(cur_file_menu), menu_vc_diff_file); gtk_tooltips_set_tip(*tooltips, menu_vc_diff_file, @@ -1961,19 +1954,19 @@ g_signal_connect((gpointer) menu_vc_remove_file, "activate", G_CALLBACK(vcremove_activated), NULL);
- /* connect to parent menu */ + /* connect to parent menu */ gtk_menu_item_set_submenu(GTK_MENU_ITEM(*parent_menu), cur_file_menu); }
static void -do_current_dir_menu(GtkWidget **parent_menu, GtkTooltips **tooltips) +do_current_dir_menu(GtkWidget ** parent_menu, GtkTooltips ** tooltips) { - GtkWidget *cur_dir_menu = NULL; - /* Menu which will hold the items in the current file menu */ + GtkWidget *cur_dir_menu = NULL; + /* Menu which will hold the items in the current file menu */ cur_dir_menu = gtk_menu_new();
*parent_menu = gtk_image_menu_item_new_with_mnemonic(_("Current _Directory")); - g_signal_connect((gpointer) *parent_menu, "activate", G_CALLBACK(update_menu_items), NULL); + g_signal_connect((gpointer) * parent_menu, "activate", G_CALLBACK(update_menu_items), NULL); /* Diff of the current dir */ menu_vc_diff_dir = gtk_menu_item_new_with_mnemonic(_("_Diff")); gtk_container_add(GTK_CONTAINER(cur_dir_menu), menu_vc_diff_dir); @@ -1984,26 +1977,26 @@ G_CALLBACK(vcdiff_dir_activated), NULL);
gtk_container_add(GTK_CONTAINER(cur_dir_menu), gtk_separator_menu_item_new()); - /* History/log of the current dir */ + /* History/log of the current dir */ menu_vc_log_dir = gtk_menu_item_new_with_mnemonic(_("_History")); gtk_container_add(GTK_CONTAINER(cur_dir_menu), menu_vc_log_dir); gtk_tooltips_set_tip(*tooltips, menu_vc_log_dir, _("Shows the log of the current directory"), NULL);
- /* connect to parent menu */ + /* connect to parent menu */ gtk_menu_item_set_submenu(GTK_MENU_ITEM(*parent_menu), cur_dir_menu); }
static void -do_basedir_menu(GtkWidget **parent_menu, GtkTooltips **tooltips) +do_basedir_menu(GtkWidget ** parent_menu, GtkTooltips ** tooltips) { - GtkWidget *basedir_menu = NULL; - /* Menu which will hold the items in the current file menu */ + GtkWidget *basedir_menu = NULL; + /* Menu which will hold the items in the current file menu */ basedir_menu = gtk_menu_new();
*parent_menu = gtk_image_menu_item_new_with_mnemonic(_("Current _Basedirectory")); - g_signal_connect((gpointer) *parent_menu, "activate", G_CALLBACK(update_menu_items), NULL); + g_signal_connect((gpointer) * parent_menu, "activate", G_CALLBACK(update_menu_items), NULL);
/* Complete diff of base directory */ menu_vc_diff_basedir = gtk_menu_item_new_with_mnemonic(_("_Diff")); @@ -2018,7 +2011,7 @@ g_signal_connect((gpointer) menu_vc_log_dir, "activate", G_CALLBACK(vclog_dir_activated), NULL);
- /* Complete History/Log of base directory */ + /* Complete History/Log of base directory */ menu_vc_log_basedir = gtk_menu_item_new_with_mnemonic(_("_History")); gtk_container_add(GTK_CONTAINER(basedir_menu), menu_vc_log_basedir); gtk_tooltips_set_tip(*tooltips, menu_vc_log_basedir, @@ -2027,7 +2020,7 @@ g_signal_connect((gpointer) menu_vc_log_basedir, "activate", G_CALLBACK(vclog_basedir_activated), NULL);
- /* connect to parent menu */ + /* connect to parent menu */ gtk_menu_item_set_submenu(GTK_MENU_ITEM(*parent_menu), basedir_menu); }
@@ -2036,19 +2029,21 @@ { /* init keybindins */ keybindings_set_item(plugin_key_group, VC_DIFF_FILE, kbdiff_file, - 0, 0, "vc_show_diff_of_file", _("Show diff of file"), menu_vc_diff_file); - keybindings_set_item(plugin_key_group, VC_DIFF_DIR, kbdiff_dir, - 0, 0, "vc_show_diff_of_dir", _("Show diff of diretory"), menu_vc_diff_dir); - keybindings_set_item(plugin_key_group, VC_DIFF_BASEDIR, kbdiff_basedir, - 0, 0, "vc_show_diff_of_basedir", _("Show diff of basedir"), menu_vc_diff_basedir); - keybindings_set_item(plugin_key_group, VC_COMMIT, kbcommit, - 0, 0, "vc_commit", _("Commit changes"), menu_vc_commit); - keybindings_set_item(plugin_key_group, VC_STATUS, kbstatus, - 0, 0, "vc_status", _("Show status") , menu_vc_status); - keybindings_set_item(plugin_key_group, VC_REVERT, kbrevert, - 0, 0, "vc_revert", _("Revert changes"), menu_vc_revert_file); - keybindings_set_item(plugin_key_group, VC_UPDATE, kbupdate, - 0, 0, "vc_update", _("Update file"), menu_vc_update); + 0, 0, "vc_show_diff_of_file", _("Show diff of file"), + menu_vc_diff_file); + keybindings_set_item(plugin_key_group, VC_DIFF_DIR, kbdiff_dir, 0, 0, "vc_show_diff_of_dir", + _("Show diff of diretory"), menu_vc_diff_dir); + keybindings_set_item(plugin_key_group, VC_DIFF_BASEDIR, kbdiff_basedir, 0, 0, + "vc_show_diff_of_basedir", _("Show diff of basedir"), + menu_vc_diff_basedir); + keybindings_set_item(plugin_key_group, VC_COMMIT, kbcommit, 0, 0, "vc_commit", + _("Commit changes"), menu_vc_commit); + keybindings_set_item(plugin_key_group, VC_STATUS, kbstatus, 0, 0, "vc_status", + _("Show status"), menu_vc_status); + keybindings_set_item(plugin_key_group, VC_REVERT, kbrevert, 0, 0, "vc_revert", + _("Revert changes"), menu_vc_revert_file); + keybindings_set_item(plugin_key_group, VC_UPDATE, kbupdate, 0, 0, "vc_update", + _("Update file"), menu_vc_update); }
/* Called by Geany to initialize the plugin */ @@ -2081,18 +2076,18 @@ menu_vc_menu = gtk_menu_new(); gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_vc), menu_vc_menu);
- /* Create the current file Submenu */ + /* Create the current file Submenu */ do_current_file_menu(&menu_vc_file, &tooltips); gtk_container_add(GTK_CONTAINER(menu_vc_menu), menu_vc_file); - /* Create the current directory Submenu */ - do_current_dir_menu(&menu_vc_dir, &tooltips); + /* Create the current directory Submenu */ + do_current_dir_menu(&menu_vc_dir, &tooltips); gtk_container_add(GTK_CONTAINER(menu_vc_menu), menu_vc_dir); - /* Create the current base directory Submenu */ - do_basedir_menu(&menu_vc_basedir, &tooltips); + /* Create the current base directory Submenu */ + do_basedir_menu(&menu_vc_basedir, &tooltips); gtk_container_add(GTK_CONTAINER(menu_vc_menu), menu_vc_basedir);
gtk_container_add(GTK_CONTAINER(menu_vc_menu), gtk_separator_menu_item_new()); - /* Status of basedir */ + /* Status of basedir */ menu_vc_status = gtk_menu_item_new_with_mnemonic(_("_Status")); gtk_container_add(GTK_CONTAINER(menu_vc_menu), menu_vc_status); gtk_tooltips_set_tip(tooltips, menu_vc_status, _("Show status."), NULL); @@ -2124,8 +2119,8 @@ gtk_widget_show_all(menu_vc_dir); gtk_widget_show_all(menu_vc_basedir);
- /* initialize keybindings */ - init_keybindings(); + /* initialize keybindings */ + init_keybindings();
plugin_fields->menu_item = menu_vc; plugin_fields->flags = PLUGIN_IS_DOCUMENT_SENSITIVE;
Modified: branches/GeanyVC_menu_redesign/geanyvc.h =================================================================== --- branches/GeanyVC_menu_redesign/geanyvc.h 2009-01-26 18:52:40 UTC (rev 405) +++ branches/GeanyVC_menu_redesign/geanyvc.h 2009-01-26 22:51:55 UTC (rev 406) @@ -51,10 +51,15 @@ VC_COMMAND_STARTDIR_FILE };
-#define P_ABS_DIRNAME "*<?geanyvcDIRNAME>*" -#define P_ABS_FILENAME "*<?geanyvcFILENAME>*" -#define P_BASENAME "*<?geanyvcBASE_FILENAME>*" +#define FLAG_RELOAD (1<<0) +#define FLAG_FORCE_ASK (1<<1) +#define FLAG_FILE (1<<2) +#define FLAG_DIR (1<<3)
+#define P_ABS_DIRNAME "*<?geanyvcDIRNAME>*" +#define P_ABS_FILENAME "*<?geanyvcFILENAME>*" +#define P_BASENAME "*<?geanyvcBASE_FILENAME>*" + /* The addresses of these strings act as enums, their contents are not used. */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.