Revision: 1977 http://geany.svn.sourceforge.net/geany/?rev=1977&view=rev Author: frlan Date: 2007-10-25 10:38:35 -0700 (Thu, 25 Oct 2007)
Log Message: ----------- Added feature to make a diff from an open project or a current directory
Modified Paths: -------------- trunk/ChangeLog trunk/plugins/svndiff.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-10-25 07:21:31 UTC (rev 1976) +++ trunk/ChangeLog 2007-10-25 17:38:35 UTC (rev 1977) @@ -1,3 +1,10 @@ +2007-10-25 Frank Lanitz <frank(at)frank(dot)uvena(dot)de> + + * plugins/svndiff.c: + Added feature to make a diff from an open project or a + current directory. + + 2007-10-24 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* src/build.c, src/ui_utils.h, src/tools.c, src/project.c, src/geany.h,
Modified: trunk/plugins/svndiff.c =================================================================== --- trunk/plugins/svndiff.c 2007-10-25 07:21:31 UTC (rev 1976) +++ trunk/plugins/svndiff.c 2007-10-25 17:38:35 UTC (rev 1977) @@ -2,6 +2,8 @@ * svndiff.c - this file is part of Geany, a fast and lightweight IDE * * Copyright 2007 Frank Lanitz <frank(at)frank(dot)uvena(dot)de> + * Copyright 2007 Enrico Tröger enrico.troeger@uvena.de + * Copyright 2007 Nick Treleaven nick.treleaven@btinternet.com * * 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 @@ -27,8 +29,9 @@ #include "plugindata.h" #include "document.h" #include "filetypes.h" +#include "utils.h" +#include "project.h"
- PluginFields *plugin_fields; GeanyData *geany_data;
@@ -39,11 +42,106 @@
VERSION_CHECK(25)
-PLUGIN_INFO(_("SVNdiff"), _("Plugin to create a patch of a file against svn"), "0.0.3") +PLUGIN_INFO(_("SVNdiff"), _("Plugin to create a patch of a file against svn"), "0.0.4")
+/* Callback if menu item for the current procet or directory was acitvated */ +static void svndirectory_activated(GtkMenuItem *menuitem, gpointer gdata) +{ + guint idx, new_idx; + gchar *base_name = NULL; + gchar *command = NULL; + gchar *project_name = NULL; + gchar *std_output = NULL; + gchar *std_err = NULL; + gint exit_code; + GError *error = NULL; + gchar *filename = NULL; + gchar *locale_filename = NULL; + gchar *text = NULL; + gchar *dir_enc = NULL;
-/* Callback if menu item was acitvated */ -static void item_activated(GtkMenuItem *menuitem, gpointer gdata) + GeanyProject *geany_project = geany_data->app->project; + + idx = geany_data->document->get_cur_idx(); + + if (geany_project != NULL && NZV(geany_project->base_path)) + { + if (doc_list[idx].file_name != NULL) + { + geany_data->document->save_file(idx, FALSE); + } + base_name = geany_project->base_path; + project_name = geany_project->name; + } + else if (doc_list[idx].file_name != NULL) + { + if (doc_list[idx].changed) + { + geany_data->document->save_file(idx, FALSE); + } + locale_filename = utils->get_locale_from_utf8(doc_list[idx].file_name); + base_name = g_path_get_dirname(locale_filename); + } + else if (doc_list[idx].file_name == NULL) + { + if ( geany_data->dialogs->show_save_as() ) + { + locale_filename = utils->get_locale_from_utf8(doc_list[idx].file_name); + base_name = g_path_get_dirname(locale_filename); + } + } + + if (base_name != NULL) + { + command = g_strconcat("svn diff ", base_name, NULL); + + if (project_name != NULL) + { + filename = g_strconcat(project_name,".diff", NULL); + } + else + { + filename = g_strdup("dir.diff"); + } + + if (g_spawn_command_line_sync(command, &std_output, &std_err, &exit_code, &error)) + { + if (! exit_code) + { + if (std_output == NULL || std_output[0] != '\0') + { + if (filename != NULL) + // Be carefull with mixed up encodings + { + text = geany_data->encoding->convert_to_utf8(std_output, -1, &dir_enc); + new_idx = geany_data->document->new_file(filename, NULL, std_output); + geany_data->document->set_encoding(new_idx, dir_enc); + g_free(text); + g_free(dir_enc); + g_free(filename); + } + + } + else + { + ui->set_statusbar(FALSE, _("No changes were made.")); + } + } + else + { // SVN returns some error + ui->set_statusbar(FALSE, + _("Something went really wrong. Is there any svn-binary in your path?")); + } + } + } + else + { + ui->set_statusbar(FALSE, _("Could not determinate a path working in")); + } +} + +/* Callback if menu item for a single file was acitvated */ +static void svnfile_activated(GtkMenuItem *menuitem, gpointer gdata) { gchar *command; gint idx; @@ -145,16 +243,50 @@ /* Called by Geany to initialize the plugin */ void init(GeanyData *data) { - GtkWidget *svndiff_item; + GtkWidget *menu_svndiff = NULL; + GtkWidget *menu_svndiff_menu = NULL; + GtkWidget *menu_svndiff_dir = NULL; + GtkWidget *menu_svndiff_file = NULL; + GtkTooltips *tooltips = NULL;
- // Add an item to the Tools menu - svndiff_item = gtk_menu_item_new_with_mnemonic(_("_SVNdiff")); - gtk_widget_show(svndiff_item); - gtk_container_add(GTK_CONTAINER(geany_data->tools_menu), svndiff_item); - g_signal_connect(G_OBJECT(svndiff_item), "activate", G_CALLBACK(item_activated), NULL); + tooltips = gtk_tooltips_new(); + //// Add an item to the Tools menu + //svndiff_item = gtk_menu_item_new_with_mnemonic(_("_SVNdiff")); + //gtk_widget_show(svndiff_item); + //gtk_container_add(GTK_CONTAINER(geany_data->tools_menu), svndiff_item); + //g_signal_connect(G_OBJECT(svndiff_item), "activate", G_CALLBACK(svnfile_activated), NULL);
- plugin_fields->menu_item = svndiff_item; + plugin_fields->flags = PLUGIN_IS_DOCUMENT_SENSITIVE; + + menu_svndiff = gtk_image_menu_item_new_with_mnemonic(_("_SVNdiff")); + gtk_container_add(GTK_CONTAINER(data->tools_menu), menu_svndiff); + + menu_svndiff_menu = gtk_menu_new (); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_svndiff), menu_svndiff_menu); + + // Directory + menu_svndiff_dir = gtk_menu_item_new_with_mnemonic(_("From current _project")); + gtk_container_add(GTK_CONTAINER (menu_svndiff_menu), menu_svndiff_dir); + gtk_tooltips_set_tip (tooltips, menu_svndiff_dir, + _("Makes a svn diff from the a complete projekt or if there is no " + "project avaible of the directory of current activeted file"), NULL); + + g_signal_connect((gpointer) menu_svndiff_dir, "activate", + G_CALLBACK(svndirectory_activated), NULL); + + // Singe file + menu_svndiff_file = gtk_menu_item_new_with_mnemonic(_("From single _file")); + gtk_container_add(GTK_CONTAINER (menu_svndiff_menu), menu_svndiff_file); + gtk_tooltips_set_tip (tooltips, menu_svndiff_file, + _("Makes a svn diff from the of current activeted file"), NULL); + + g_signal_connect((gpointer) menu_svndiff_file, "activate", + G_CALLBACK(svnfile_activated), NULL); + + gtk_widget_show_all(menu_svndiff); + + plugin_fields->menu_item = menu_svndiff; }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.