diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2011-01-31 22:07:58 +0100 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2011-02-01 14:52:27 +0100 |
commit | c091f71f9ac15dd4b5eb29beb233c9715420d75a (patch) | |
tree | bd4f4ebc75167b4ea264978db3e7efe1dfa56da8 | |
parent | 18f5da95291ec99192d1b594cd3939a75328273d (diff) | |
download | logdiag-c091f71f9ac15dd4b5eb29beb233c9715420d75a.tar.gz logdiag-c091f71f9ac15dd4b5eb29beb233c9715420d75a.tar.xz logdiag-c091f71f9ac15dd4b5eb29beb233c9715420d75a.zip |
Offer the undo functionality in LdWindowMain.
Kill the "Export" action for now.
-rw-r--r-- | share/gui/window-main.ui | 7 | ||||
-rw-r--r-- | src/ld-window-main.c | 64 |
2 files changed, 60 insertions, 11 deletions
diff --git a/share/gui/window-main.ui b/share/gui/window-main.ui index ad8037c..5ab82e9 100644 --- a/share/gui/window-main.ui +++ b/share/gui/window-main.ui @@ -6,11 +6,16 @@ <menuitem action="Save" /> <menuitem action="SaveAs" /> <separator /> +<!-- <menuitem action="Export" /> <separator /> +--> <menuitem action="Quit" /> </menu> <menu name="EditMenu" action="EditMenu"> + <menuitem action="Undo" /> + <menuitem action="Redo" /> + <separator /> <!-- <menuitem action="Cut" /> <menuitem action="Copy" /> @@ -34,6 +39,8 @@ <toolitem action="Open" /> <toolitem action="Save" /> <separator /> + <toolitem action="Undo" /> + <toolitem action="Redo" /> </toolbar> </ui> diff --git a/src/ld-window-main.c b/src/ld-window-main.c index 4f3e603..69b8fb2 100644 --- a/src/ld-window-main.c +++ b/src/ld-window-main.c @@ -59,6 +59,9 @@ static void update_title (LdWindowMain *self); static void action_set_sensitive (LdWindowMain *self, const gchar *name, gboolean sensitive); +static void on_diagram_changed (LdDiagram *diagram, LdWindowMain *self); +static void on_diagram_history_changed (LdDiagram *diagram, + GParamSpec *pspec, LdWindowMain *self); static void on_diagram_selection_changed (LdDiagram *diagram, LdWindowMain *self); @@ -89,6 +92,8 @@ static void on_action_save_as (GtkAction *action, LdWindowMain *self); static void on_action_quit (GtkAction *action, LdWindowMain *self); static void on_action_about (GtkAction *action, LdWindowMain *self); +static void on_action_undo (GtkAction *action, LdWindowMain *self); +static void on_action_redo (GtkAction *action, LdWindowMain *self); static void on_action_delete (GtkAction *action, LdWindowMain *self); static void on_action_select_all (GtkAction *action, LdWindowMain *self); @@ -111,19 +116,26 @@ static GtkActionEntry wm_action_entries[] = {"SaveAs", GTK_STOCK_SAVE_AS, Q_("Save _As..."), "<Shift><Ctrl>S", Q_("Save the current diagram with another name"), G_CALLBACK (on_action_save_as)}, - {"Export", NULL, Q_("_Export"), NULL, - Q_("Export the diagram"), - NULL}, +/* + * {"Export", NULL, Q_("_Export"), NULL, + * Q_("Export the diagram"), + * NULL}, + */ {"Quit", GTK_STOCK_QUIT, Q_("_Quit"), "<Ctrl>Q", Q_("Quit the application"), G_CALLBACK (on_action_quit)}, {"EditMenu", NULL, Q_("_Edit"), NULL, NULL, NULL}, - /* XXX: Don't implement these yet: */ + {"Undo", GTK_STOCK_UNDO, Q_("_Undo"), "<Ctrl>Z", + Q_("Undo the last action"), + G_CALLBACK (on_action_undo)}, + {"Redo", GTK_STOCK_REDO, Q_("_Redo"), "<Shift><Ctrl>Z", + Q_("Redo the last undone action"), + G_CALLBACK (on_action_redo)}, /* - {"Cut", GTK_STOCK_CUT, Q_("Cu_t"), "<Ctrl>X", NULL, NULL}, - {"Copy", GTK_STOCK_COPY, Q_("_Copy"), "<Ctrl>C", NULL, NULL}, - {"Paste", GTK_STOCK_PASTE, Q_("_Paste"), "<Ctrl>V", NULL, NULL}, + * {"Cut", GTK_STOCK_CUT, Q_("Cu_t"), "<Ctrl>X", NULL, NULL}, + * {"Copy", GTK_STOCK_COPY, Q_("_Copy"), "<Ctrl>C", NULL, NULL}, + * {"Paste", GTK_STOCK_PASTE, Q_("_Paste"), "<Ctrl>V", NULL, NULL}, */ {"Delete", GTK_STOCK_DELETE, Q_("_Delete"), "Delete", Q_("Delete the contents of the selection"), @@ -258,9 +270,12 @@ ld_window_main_init (LdWindowMain *self) /* Initialize the backend. */ priv->diagram = ld_diagram_new (); - g_signal_connect_data (priv->diagram, "changed", - G_CALLBACK (update_title), self, - NULL, G_CONNECT_AFTER | G_CONNECT_SWAPPED); + g_signal_connect_after (priv->diagram, "changed", + G_CALLBACK (on_diagram_changed), self); + g_signal_connect (priv->diagram, "notify::can-undo", + G_CALLBACK (on_diagram_history_changed), self); + g_signal_connect (priv->diagram, "notify::can-redo", + G_CALLBACK (on_diagram_history_changed), self); g_signal_connect_after (priv->diagram, "selection-changed", G_CALLBACK (on_diagram_selection_changed), self); @@ -284,7 +299,8 @@ ld_window_main_init (LdWindowMain *self) diagram_set_filename (self, NULL); - action_set_sensitive (self, "Export", FALSE); + action_set_sensitive (self, "Undo", FALSE); + action_set_sensitive (self, "Redo", FALSE); action_set_sensitive (self, "Delete", FALSE); action_set_sensitive (self, "ZoomIn", FALSE); action_set_sensitive (self, "ZoomOut", FALSE); @@ -428,6 +444,20 @@ on_menu_item_deselected (GtkItem *item, LdWindowMain *window) /* ===== Diagram handling ================================================== */ static void +on_diagram_changed (LdDiagram *diagram, LdWindowMain *self) +{ + update_title (self); +} + +static void +on_diagram_history_changed (LdDiagram *diagram, + GParamSpec *pspec, LdWindowMain *self) +{ + action_set_sensitive (self, "Undo", ld_diagram_can_undo (diagram)); + action_set_sensitive (self, "Redo", ld_diagram_can_redo (diagram)); +} + +static void on_diagram_selection_changed (LdDiagram *diagram, LdWindowMain *self) { gboolean selection_empty; @@ -796,6 +826,18 @@ on_action_about (GtkAction *action, LdWindowMain *self) } static void +on_action_undo (GtkAction *action, LdWindowMain *self) +{ + ld_diagram_undo (self->priv->diagram); +} + +static void +on_action_redo (GtkAction *action, LdWindowMain *self) +{ + ld_diagram_redo (self->priv->diagram); +} + +static void on_action_delete (GtkAction *action, LdWindowMain *self) { ld_diagram_remove_selection (self->priv->diagram); |