Kaydet (Commit) 634bc6c3 authored tarafından Frank Lanitz's avatar Frank Lanitz

Added feature to make a diff from an open project or a current directory

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1977 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst 8a2d296e
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> 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, * src/build.c, src/ui_utils.h, src/tools.c, src/project.c, src/geany.h,
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
* svndiff.c - this file is part of Geany, a fast and lightweight IDE * 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 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 * 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 * it under the terms of the GNU General Public License as published by
...@@ -27,7 +29,8 @@ ...@@ -27,7 +29,8 @@
#include "plugindata.h" #include "plugindata.h"
#include "document.h" #include "document.h"
#include "filetypes.h" #include "filetypes.h"
#include "utils.h"
#include "project.h"
PluginFields *plugin_fields; PluginFields *plugin_fields;
GeanyData *geany_data; GeanyData *geany_data;
...@@ -39,11 +42,106 @@ GeanyData *geany_data; ...@@ -39,11 +42,106 @@ GeanyData *geany_data;
VERSION_CHECK(25) 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;
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);
}
/* Callback if menu item was acitvated */ }
static void item_activated(GtkMenuItem *menuitem, gpointer gdata) 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; gchar *command;
gint idx; gint idx;
...@@ -145,16 +243,50 @@ static void item_activated(GtkMenuItem *menuitem, gpointer gdata) ...@@ -145,16 +243,50 @@ static void item_activated(GtkMenuItem *menuitem, gpointer gdata)
/* Called by Geany to initialize the plugin */ /* Called by Geany to initialize the plugin */
void init(GeanyData *data) 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;
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);
// 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);
plugin_fields->menu_item = svndiff_item;
plugin_fields->flags = PLUGIN_IS_DOCUMENT_SENSITIVE; 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;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment