Added support for svn revert and a little patch from Yura Siamashka to re-use an already created tab for a new diff on the same file.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@2018 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Frank Lanitz 2007-11-05 14:21:46 +00:00
parent f819bde65a
commit 293bba1692
2 changed files with 116 additions and 4 deletions

View File

@ -1,3 +1,12 @@
2007-11-05 Frank Lanitz <frank(at)frank(dot)uvena(dot)de>
* plugins/svndiff.c:
Added function for svn revert and check before complete loading of
then plugin if svn is inside $PATH.
Added patch from Yura Siamashka to re-use an already created tab
for a new diff on the same file. Thanks.
2007-11-04 Enrico Tröger <enrico.troeger@uvena.de> 2007-11-04 Enrico Tröger <enrico.troeger@uvena.de>
* src/build.c: * src/build.c:

View File

@ -37,17 +37,29 @@ PluginFields *plugin_fields;
GeanyData *geany_data; GeanyData *geany_data;
VERSION_CHECK(25) VERSION_CHECK(27)
PLUGIN_INFO(_("SVNdiff"), _("Plugin to create a patch of a file against svn"), VERSION) PLUGIN_INFO(_("SVNdiff"), _("Plugin to create a patch of a file against svn"), VERSION)
static int find_by_filename(const gchar* filename)
{
guint i;
for (i = 0; i < doc_array->len; i++)
{
if ( DOC_IDX_VALID(i) && doc_list[i].file_name &&
strcmp(doc_list[i].file_name, filename) == 0)
return i;
}
return -1;
}
/* name_prefix should be in UTF-8, and can have a path. */ /* name_prefix should be in UTF-8, and can have a path. */
static void show_output(const gchar *std_output, const gchar *name_prefix, static void show_output(const gchar *std_output, const gchar *name_prefix,
const gchar *force_encoding) const gchar *force_encoding)
{ {
gchar *text, *detect_enc = NULL; gchar *text, *detect_enc = NULL;
gint new_idx; gint idx, page;
GtkNotebook *book;
gchar *filename; gchar *filename;
filename = g_path_get_basename(name_prefix); filename = g_path_get_basename(name_prefix);
@ -66,10 +78,23 @@ static void show_output(const gchar *std_output, const gchar *name_prefix,
} }
if (text) if (text)
{ {
new_idx = geany_data->document->new_file(filename, idx = find_by_filename(filename);
if ( idx == -1)
{
idx = geany_data->document->new_file(filename,
geany_data->filetypes[GEANY_FILETYPES_DIFF], text); geany_data->filetypes[GEANY_FILETYPES_DIFF], text);
}
else
{
scintilla->set_text(doc_list[idx].sci, text);
book = GTK_NOTEBOOK(app->notebook);
page = gtk_notebook_page_num(book, GTK_WIDGET(doc_list[idx].sci));
gtk_notebook_set_current_page(book, page);
doc_list[idx].changed = FALSE;
documents->set_text_changed(idx);
}
geany_data->document->set_encoding(new_idx, geany_data->document->set_encoding(idx,
force_encoding ? force_encoding : detect_enc); force_encoding ? force_encoding : detect_enc);
} }
else else
@ -81,6 +106,46 @@ static void show_output(const gchar *std_output, const gchar *name_prefix,
g_free(filename); g_free(filename);
} }
static gboolean make_revert(const gchar *svn_file)
{
gchar *std_output = NULL;
gchar *std_error = NULL;
gint exit_code;
gchar *command = NULL;
// use '' quotation for Windows compatibility
command = g_strdup_printf("svn revert '%s'", svn_file);
if (g_spawn_command_line_sync(command, &std_output, &std_error, &exit_code, NULL))
{
if (! exit_code)
{
if (NZV(std_output))
{
ui->set_statusbar(FALSE, std_output);
}
else
{
ui->set_statusbar(FALSE, _("No changes were made."));
return FALSE;
}
}
else
{ // SVN returns some error
dialogs->show_msgbox(1,
_("SVN exited with an error: \n%s."), g_strstrip(std_error));
return FALSE;
}
}
else
{
ui->set_statusbar(FALSE,
_("Something went really wrong. Is there any svn-binary in your path?"));
return FALSE;
}
return TRUE;
}
static gchar *make_diff(const gchar *svn_file) static gchar *make_diff(const gchar *svn_file)
{ {
@ -201,10 +266,32 @@ static void svnfile_activated(GtkMenuItem *menuitem, gpointer gdata)
g_free(locale_filename); g_free(locale_filename);
} }
/* Callback if menu item for a single file was activated */
static void svnrevert_activated(GtkMenuItem *menuitem, gpointer gdata)
{
gint idx;
gchar *locale_filename;
idx = documents->get_cur_idx();
g_return_if_fail(DOC_IDX_VALID(idx) && doc_list[idx].file_name != NULL);
if (dialogs->show_question(_("Do you realy want to revert '%s'?"), doc_list[idx].file_name))
{
locale_filename = utils->get_locale_from_utf8(doc_list[idx].file_name);
if (make_revert(locale_filename))
{
documents->reload_file(idx, NULL);
}
g_free(locale_filename);
}
}
static GtkWidget *menu_svndiff_file = NULL; static GtkWidget *menu_svndiff_file = NULL;
static GtkWidget *menu_svndiff_dir = NULL; static GtkWidget *menu_svndiff_dir = NULL;
static GtkWidget *menu_svndiff_project = NULL; static GtkWidget *menu_svndiff_project = NULL;
static GtkWidget *menu_svndiff_revert = NULL;
static void update_menu_items() static void update_menu_items()
{ {
@ -216,6 +303,7 @@ static void update_menu_items()
gtk_widget_set_sensitive(menu_svndiff_file, have_file); gtk_widget_set_sensitive(menu_svndiff_file, have_file);
gtk_widget_set_sensitive(menu_svndiff_dir, have_file); gtk_widget_set_sensitive(menu_svndiff_dir, have_file);
gtk_widget_set_sensitive(menu_svndiff_revert, have_file);
gtk_widget_set_sensitive(menu_svndiff_project, gtk_widget_set_sensitive(menu_svndiff_project,
project != NULL && NZV(project->base_path)); project != NULL && NZV(project->base_path));
} }
@ -227,6 +315,15 @@ void init(GeanyData *data)
GtkWidget *menu_svndiff = NULL; GtkWidget *menu_svndiff = NULL;
GtkWidget *menu_svndiff_menu = NULL; GtkWidget *menu_svndiff_menu = NULL;
GtkTooltips *tooltips = NULL; GtkTooltips *tooltips = NULL;
gchar *tmp = NULL;
gboolean have_svn = FALSE;
// Check for svn inside $PATH. Thanks to Yura Siamashka <yurand2@gmail.com>
tmp = g_find_program_in_path("svn");
if (!tmp)
return;
have_svn = TRUE;
g_free(tmp);
tooltips = gtk_tooltips_new(); tooltips = gtk_tooltips_new();
@ -268,6 +365,12 @@ void init(GeanyData *data)
g_signal_connect((gpointer) menu_svndiff_project, "activate", g_signal_connect((gpointer) menu_svndiff_project, "activate",
G_CALLBACK(svnproject_activated), NULL); G_CALLBACK(svnproject_activated), NULL);
// SVN revert
menu_svndiff_revert = gtk_menu_item_new_with_mnemonic(_("Revert changes"));
gtk_container_add(GTK_CONTAINER (menu_svndiff_menu), menu_svndiff_revert);
gtk_tooltips_set_tip(tooltips, menu_svndiff_revert, _("Revert all made changes at this file"), NULL);
g_signal_connect((gpointer) menu_svndiff_revert, "activate", G_CALLBACK(svnrevert_activated), NULL);
gtk_widget_show_all(menu_svndiff); gtk_widget_show_all(menu_svndiff);
plugin_fields->menu_item = menu_svndiff; plugin_fields->menu_item = menu_svndiff;