extend the cut/paste system through the undo/redo system.

* extend the cut/paste system through the undo/redo system.
This commit is contained in:
Archit Baweja 2003-04-23 02:42:12 +00:00
parent 9d07445d12
commit f94fb6d2cc
7 changed files with 157 additions and 9 deletions

View File

@ -68,6 +68,20 @@
* config.h.win: config file for win32. Rename it to config.h before
trying to compile on windows.
2003-04-04 Archit Baweja <bighead@users.sourceforge.net>
* src/glade-project-window.c (gpw_cut_cb): use glade_command_cut().
(gpw_paste_cb): use glade_command_paste().
* src/glade-placeholder.c (glade_placeholder_paste_cb): likewise.
* src/glade-widget.c (glade_widget_cut): likewise.
2002-05-26 Archit Baweja <bighead@users.sourceforge.net>
* src/glade-command.c (glade_command_cut_paste_*): cut/paste through
the undo/redo system.
2003-04-02 Joaquin Cuenca Abela <e98cuenc@yahoo.com>
* src/glade-menu-editor.c: Fix the segfault when adding a new menu item.

View File

@ -4,7 +4,7 @@
* Copyright (C) 2001 The GNOME Foundation.
*
* Author(s):
* Archit Baweja <bighead@crosswinds.net>
* Archit Baweja <bighead@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License

View File

@ -18,6 +18,7 @@
*
* Authors:
* Joaquín Cuenca Abela <e98cuenc@yahoo.com>
* Archit Baweja <bighead@users.sourceforge.net>
*/
#include <gtk/gtk.h>
#include <string.h>
@ -31,6 +32,7 @@
#include "glade-property.h"
#include "glade-debug.h"
#include "glade-placeholder.h"
#include "glade-clipboard.h"
#include "glade.h"
#define GLADE_COMMAND_TYPE (glade_command_get_type ())
@ -607,3 +609,131 @@ glade_command_create (GladeWidget *widget)
{
glade_command_create_delete_common (widget, TRUE);
}
/**
* Cut/Paste
*
* Following is the code to extend the GladeCommand Undo/Redo system to
* Clipboard functions.
**/
typedef struct {
GladeCommand parent;
GladeClipboard *clipboard;
GladeWidget *widget;
GladePlaceholder *placeholder;
gboolean cut;
} GladeCommandCutPaste;
GLADE_MAKE_COMMAND (GladeCommandCutPaste, glade_command_cut_paste);
#define GLADE_COMMAND_CUT_PASTE_TYPE (glade_command_cut_paste_get_type ())
#define GLADE_COMMAND_CUT_PASTE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GLADE_COMMAND_CUT_PASTE_TYPE, GladeCommandCutPaste))
#define GLADE_COMMAND_CUT_PASTE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GLADE_COMMAND_CUT_PASTE_TYPE, GladeCommandCutPasteClass))
#define IS_GLADE_COMMAND_CUT_PASTE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GLADE_COMMAND_CUT_PASTE_TYPE))
#define IS_GLADE_COMMAND_CUT_PASTE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GLADE_COMMAND_CREATE_DELETE_TYPE))
static gboolean
glade_command_cut_paste_undo (GladeCommand *cmd)
{
return glade_command_cut_paste_execute (cmd);
}
static gboolean
glade_command_paste_execute (GladeCommandCutPaste *me)
{
glade_clipboard_paste (me->clipboard, me->placeholder);
return TRUE;
}
static gboolean
glade_command_cut_execute (GladeCommandCutPaste *me)
{
glade_clipboard_cut (me->clipboard, me->widget);
return TRUE;
}
/**
* Execute the cmd and revert it. Ie, after the execution of this
* function cmd will point to the undo action
*/
static gboolean
glade_command_cut_paste_execute (GladeCommand *cmd)
{
GladeCommandCutPaste *me = (GladeCommandCutPaste *) cmd;
gboolean retval;
if (me->cut)
retval = glade_command_cut_execute (me);
else
retval = glade_command_paste_execute (me);
me->cut = !me->cut;
return retval;
}
static void
glade_command_cut_paste_finalize (GObject *obj)
{
GladeCommandCutPaste *cmd = GLADE_COMMAND_CUT_PASTE (obj);
g_object_unref (cmd->widget);
glade_command_finalize (obj);
}
static gboolean
glade_command_cut_paste_unifies (GladeCommand *this, GladeCommand *other)
{
return FALSE;
}
static void
glade_command_cut_paste_collapse (GladeCommand *this, GladeCommand *other)
{
g_return_if_reached ();
}
static void
glade_command_cut_paste_common (GladeWidget *widget,
GladePlaceholder *placeholder,
gboolean cut)
{
GladeCommandCutPaste *me;
GladeCommand *cmd;
GladeProject *project;
GladeProjectWindow *gpw;
me = (GladeCommandCutPaste *) g_object_new (GLADE_COMMAND_CUT_PASTE_TYPE, NULL);
cmd = (GladeCommand *) me;
project = glade_project_window_get_project ();
gpw = glade_project_window_get ();
me->cut = cut;
me->widget = widget;
me->placeholder = placeholder;
me->clipboard = gpw->clipboard;
cmd->description = g_strdup_printf (_("%s %s"), cut ? "Cut" : "Paste", widget->name);
g_debug(("Pushing: %s\n", cmd->description));
/*
* Push it onto the undo stack only on success
*/
if (glade_command_cut_paste_execute (GLADE_COMMAND (me)))
glade_command_push_undo (project, GLADE_COMMAND (me));
}
void
glade_command_paste (GladeWidget *widget, GladePlaceholder *placeholder)
{
glade_command_cut_paste_common (widget, placeholder, FALSE);
}
void
glade_command_cut (GladeWidget *widget)
{
glade_command_cut_paste_common (widget, NULL, TRUE);
}

View File

@ -10,7 +10,11 @@ void glade_command_redo (void);
const gchar* glade_command_get_description (GList *l);
void glade_command_set_property (GObject *obj, const gchar* name, const GValue* value);
void glade_command_delete (GladeWidget *widget);
void glade_command_create (GladeWidget *widget);
void glade_command_cut (GladeWidget *widget);
void glade_command_paste (GladeWidget *widget, GladePlaceholder *placeholder);
#endif /* GLADE_COMMAND_H */

View File

@ -798,12 +798,13 @@ glade_placeholder_fill_empty (GtkWidget *widget)
void
glade_placeholder_paste_cb (GtkWidget *button, gpointer data)
{
GladePlaceholder *placeholder = GTK_WIDGET (data);
GladeProjectWindow *gpw;
GladeClipboard *clipboard;
gpw = glade_project_window_get ();
clipboard = gpw->clipboard;
glade_clipboard_paste (clipboard, placeholder);
/*
* The data parameter is the placeholder we have to replace with the
* widget.
*/
glade_command_paste (gpw->active_widget, GTK_WIDGET (data));
}

View File

@ -275,7 +275,7 @@ gpw_cut_cb (void)
widget = gpw->active_widget;
if (widget)
glade_clipboard_cut (gpw->clipboard, widget);
glade_command_cut (widget);
}
static void
@ -284,7 +284,7 @@ gpw_paste_cb (void)
GladeProjectWindow *gpw;
gpw = glade_project_window_get ();
glade_clipboard_paste (gpw->clipboard, gpw->active_placeholder);
glade_command_paste (gpw->active_widget, gpw->active_placeholder);
}
static void

View File

@ -1243,8 +1243,7 @@ glade_widget_cut (GladeWidget *widget)
gpw = glade_project_window_get ();
clipboard = gpw->clipboard;
glade_clipboard_cut (clipboard, widget);
glade_command_cut (widget);
}
void