From 9332accc627bbd2e5f65c24b3527f6dc17bc0407 Mon Sep 17 00:00:00 2001 From: James Liggett Date: Tue, 22 Apr 2008 19:55:45 -0700 Subject: [PATCH] Implement add support --- plugins/git/Makefile.am | 6 +- plugins/git/anjuta-git.glade | 139 +++++++++++++++++++++++++++++++++++++++++- plugins/git/anjuta-git.ui | 2 + plugins/git/git-add-command.c | 113 ++++++++++++++++++++++++++++++++++ plugins/git/git-add-command.h | 64 +++++++++++++++++++ plugins/git/git-add-dialog.c | 116 +++++++++++++++++++++++++++++++++++ plugins/git/git-add-dialog.h | 33 ++++++++++ plugins/git/plugin.c | 9 +++ 8 files changed, 480 insertions(+), 2 deletions(-) create mode 100644 plugins/git/git-add-command.c create mode 100644 plugins/git/git-add-command.h create mode 100644 plugins/git/git-add-dialog.c create mode 100644 plugins/git/git-add-dialog.h diff --git a/plugins/git/Makefile.am b/plugins/git/Makefile.am index 4d39b52e..8502b8cd 100644 --- a/plugins/git/Makefile.am +++ b/plugins/git/Makefile.am @@ -59,7 +59,11 @@ libanjuta_git_la_SOURCES = \ git-commit-command.h \ git-commit-command.c \ git-commit-dialog.c \ - git-commit-dialog.h + git-commit-dialog.h \ + git-add-command.h \ + git-add-command.c \ + git-add-dialog.c \ + git-add-dialog.h libanjuta_git_la_LDFLAGS = $(ANJUTA_PLUGIN_LDFLAGS) diff --git a/plugins/git/anjuta-git.glade b/plugins/git/anjuta-git.glade index f2f5b4b3..2b30593c 100644 --- a/plugins/git/anjuta-git.glade +++ b/plugins/git/anjuta-git.glade @@ -1,6 +1,6 @@ - + @@ -206,4 +206,141 @@ + + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 + Add File + GTK_WIN_POS_CENTER_ON_PARENT + GDK_WINDOW_TYPE_HINT_DIALOG + False + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 2 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 2 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 + GTK_SHADOW_NONE + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 12 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + <b>Select file to add:</b> + True + + + label_item + + + + + False + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 + GTK_SHADOW_NONE + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 12 + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Force + 0 + True + + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + <b>Options:</b> + True + + + label_item + + + + + False + 1 + + + + + 1 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + GTK_BUTTONBOX_END + + + True + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + gtk-cancel + True + -6 + + + + + True + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + gtk-ok + True + -5 + + + 1 + + + + + False + GTK_PACK_END + + + + + diff --git a/plugins/git/anjuta-git.ui b/plugins/git/anjuta-git.ui index 53bea9cc..2b1ea6c5 100644 --- a/plugins/git/anjuta-git.ui +++ b/plugins/git/anjuta-git.ui @@ -6,6 +6,8 @@ + + diff --git a/plugins/git/git-add-command.c b/plugins/git/git-add-command.c new file mode 100644 index 00000000..2b0ce884 --- /dev/null +++ b/plugins/git/git-add-command.c @@ -0,0 +1,113 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * anjuta-git + * Copyright (C) James Liggett 2008 + * + * anjuta-git is free software. + * + * You may redistribute it and/or modify it under the terms of the + * GNU General Public License, as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * anjuta-git is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with anjuta-git. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + */ + +#include "git-add-command.h" + +struct _GitAddCommandPriv +{ + GList *paths; + gboolean force; +}; + +G_DEFINE_TYPE (GitAddCommand, git_add_command, GIT_TYPE_COMMAND); + +static void +git_add_command_init (GitAddCommand *self) +{ + self->priv = g_new0 (GitAddCommandPriv, 1); +} + +static void +git_add_command_finalize (GObject *object) +{ + GitAddCommand *self; + + self = GIT_ADD_COMMAND (object); + + git_command_free_path_list (self->priv->paths); + g_free (self->priv); + + G_OBJECT_CLASS (git_add_command_parent_class)->finalize (object); +} + +static guint +git_add_command_run (AnjutaCommand *command) +{ + GitAddCommand *self; + + self = GIT_ADD_COMMAND (command); + + git_command_add_arg (GIT_COMMAND (command), "add"); + + if (self->priv->force) + git_command_add_arg (GIT_COMMAND (command), "-f"); + + git_command_add_list_to_args (GIT_COMMAND (command), self->priv->paths); + + return 0; +} + +static void +git_add_command_class_init (GitAddCommandClass *klass) +{ + GObjectClass* object_class = G_OBJECT_CLASS (klass); + AnjutaCommandClass* command_class = ANJUTA_COMMAND_CLASS (klass); + + object_class->finalize = git_add_command_finalize; + command_class->run = git_add_command_run; +} + + +GitAddCommand * +git_add_command_new_path (const gchar *working_directory, const gchar *path, + gboolean force) +{ + GitAddCommand *self; + + self = g_object_new (GIT_TYPE_ADD_COMMAND, + "working-directory", working_directory, + NULL); + + self->priv->paths = g_list_append (self->priv->paths, g_strdup (path)); + self->priv->force = force; + + return self; +} + + +GitAddCommand * +git_add_command_new_list (const gchar *working_directory, GList *path_list, + gboolean force) +{ + GitAddCommand *self; + + self = g_object_new (GIT_TYPE_ADD_COMMAND, + "working-directory", working_directory, + NULL); + + self->priv->paths = git_command_copy_path_list (path_list); + self->priv->force = force; + + return self; +} diff --git a/plugins/git/git-add-command.h b/plugins/git/git-add-command.h new file mode 100644 index 00000000..b17cb6f5 --- /dev/null +++ b/plugins/git/git-add-command.h @@ -0,0 +1,64 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * anjuta-git + * Copyright (C) James Liggett 2008 + * + * anjuta-git is free software. + * + * You may redistribute it and/or modify it under the terms of the + * GNU General Public License, as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * anjuta-git is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with anjuta-git. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GIT_ADD_COMMAND_H_ +#define _GIT_ADD_COMMAND_H_ + +#include +#include "git-command.h" + +G_BEGIN_DECLS + +#define GIT_TYPE_ADD_COMMAND (git_add_command_get_type ()) +#define GIT_ADD_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIT_TYPE_ADD_COMMAND, GitAddCommand)) +#define GIT_ADD_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIT_TYPE_ADD_COMMAND, GitAddCommandClass)) +#define GIT_IS_ADD_COMMAND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIT_TYPE_ADD_COMMAND)) +#define GIT_IS_ADD_COMMAND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIT_TYPE_ADD_COMMAND)) +#define GIT_ADD_COMMAND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIT_TYPE_ADD_COMMAND, GitAddCommandClass)) + +typedef struct _GitAddCommandClass GitAddCommandClass; +typedef struct _GitAddCommand GitAddCommand; +typedef struct _GitAddCommandPriv GitAddCommandPriv; + +struct _GitAddCommandClass +{ + GitCommandClass parent_class; +}; + +struct _GitAddCommand +{ + GitCommand parent_instance; + + GitAddCommandPriv *priv; +}; + +GType git_add_command_get_type (void) G_GNUC_CONST; +GitAddCommand *git_add_command_new_path (const gchar *working_directory, + const gchar *path, gboolean force); +GitAddCommand *git_add_command_new_list (const gchar *working_directory, + GList *path_list, gboolean force); + +G_END_DECLS + +#endif /* _GIT_ADD_COMMAND_H_ */ diff --git a/plugins/git/git-add-dialog.c b/plugins/git/git-add-dialog.c new file mode 100644 index 00000000..6fa48119 --- /dev/null +++ b/plugins/git/git-add-dialog.c @@ -0,0 +1,116 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * anjuta + * Copyright (C) James Liggett 2008 + * + * anjuta is free software. + * + * You may redistribute it and/or modify it under the terms of the + * GNU General Public License, as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * anjuta is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with anjuta. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + */ + +#include "git-add-dialog.h" + +static void +on_add_command_finished (AnjutaCommand *command, guint return_code, + Git *plugin) +{ + AnjutaStatus *status; + + status = anjuta_shell_get_status (ANJUTA_PLUGIN (plugin)->shell, + NULL); + + anjuta_status (status, _("Git: File staged for add."), 5); + + report_errors (command, return_code); + + g_object_unref (command); +} + + +static void +on_add_dialog_response (GtkDialog *dialog, gint response_id, + GitUIData *data) +{ + GtkWidget *file_chooser_button; + GtkWidget *force_check; + gchar *filename; + const gchar *relative_filename; + GitAddCommand *add_command; + + if (response_id == GTK_RESPONSE_OK) + { + file_chooser_button = glade_xml_get_widget (data->gxml, + "file_chooser_button"); + force_check = glade_xml_get_widget (data->gxml, "force_check"); + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (file_chooser_button)); + + if (check_input (GTK_WIDGET (dialog), file_chooser_button, filename, + _("Please select a file."))) + { + relative_filename = get_relative_path (filename, + data->plugin->project_root_directory); + add_command = git_add_command_new_path (data->plugin->project_root_directory, + relative_filename, + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (force_check))); + + g_free (filename); + + + g_signal_connect (G_OBJECT (add_command), "command-finished", + G_CALLBACK (on_add_command_finished), + data->plugin); + + anjuta_command_start (ANJUTA_COMMAND (add_command)); + } + else + return; + } + + gtk_widget_destroy (GTK_WIDGET (dialog)); + git_ui_data_free (data); +} + +static void +add_dialog (Git *plugin, const gchar *filename) +{ + GladeXML *gxml; + GtkWidget *dialog; + GtkWidget *file_chooser_button; + GitUIData *data; + + gxml = glade_xml_new (GLADE_FILE, "add_dialog", NULL); + + dialog = glade_xml_get_widget (gxml, "add_dialog"); + file_chooser_button = glade_xml_get_widget (gxml, "file_chooser_button"); + + gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (file_chooser_button), + filename); + + data = git_ui_data_new (plugin, gxml); + + g_signal_connect(G_OBJECT (dialog), "response", + G_CALLBACK (on_add_dialog_response), + data); + + gtk_widget_show_all (dialog); +} + +void +on_menu_git_add (GtkAction *action, Git *plugin) +{ + add_dialog (plugin, plugin->current_editor_filename); +} diff --git a/plugins/git/git-add-dialog.h b/plugins/git/git-add-dialog.h new file mode 100644 index 00000000..e3c95685 --- /dev/null +++ b/plugins/git/git-add-dialog.h @@ -0,0 +1,33 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */ +/* + * anjuta + * Copyright (C) James Liggett 2008 + * + * anjuta is free software. + * + * You may redistribute it and/or modify it under the terms of the + * GNU General Public License, as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * anjuta is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with anjuta. If not, write to: + * The Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301, USA. + */ + +#ifndef _GIT_ADD_DIALOG_H +#define _GIT_ADD_DIALOG_H + +#include "git-add-command.h" +#include "git-ui-utils.h" + +void on_menu_git_add (GtkAction *action, Git *plugin); + +#endif diff --git a/plugins/git/plugin.c b/plugins/git/plugin.c index 05460c3a..53941ecc 100644 --- a/plugins/git/plugin.c +++ b/plugins/git/plugin.c @@ -22,6 +22,7 @@ #include "plugin.h" #include "git-diff-dialog.h" #include "git-commit-dialog.h" +#include "git-add-dialog.h" #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-git.ui" @@ -45,6 +46,14 @@ static GtkActionEntry actions_git[] = { G_CALLBACK (on_menu_git_commit) /* action callback */ }, { + "ActionGitAdd", /* Action name */ + GTK_STOCK_ADD, /* Stock icon, if any */ + N_("_Add..."), /* Display label */ + NULL, /* short-cut */ + NULL, /* Tooltip */ + G_CALLBACK (on_menu_git_add) /* action callback */ + }, + { "ActionGitDiffUncommitted", /* Action name */ GTK_STOCK_ZOOM_100, /* Stock icon, if any */ N_("_Diff uncommitted changes"), /* Display label */ -- 2.11.4.GIT