[ease] [general] Document, Slide, and Element are now UndoSources
- From: Nate Stedman <natesm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ease] [general] Document, Slide, and Element are now UndoSources
- Date: Mon, 26 Jul 2010 23:43:11 +0000 (UTC)
commit 8ad67820a01b65676137e5c0181fcfc73ad89bfc
Author: Nate Stedman <natesm gmail com>
Date: Mon Jul 26 19:41:59 2010 -0400
[general] Document, Slide, and Element are now UndoSources
Added some convenience methods to UndoSource:
- forward: passes along an UndoAction
- listen: starts forwarding from an UndoSource
- silence: stops listening
src/ease-document.vala | 4 +++-
src/ease-editor-window.vala | 6 +++---
src/ease-element.vala | 2 +-
src/ease-image-element.vala | 2 +-
src/ease-inspector.vala | 2 +-
src/ease-slide.vala | 7 +++++--
src/ease-text-element.vala | 6 +++---
src/ease-undo-source.vala | 26 ++++++++++++++++++++++++++
8 files changed, 43 insertions(+), 12 deletions(-)
---
diff --git a/src/ease-document.vala b/src/ease-document.vala
index 37ebf04..2384bdd 100644
--- a/src/ease-document.vala
+++ b/src/ease-document.vala
@@ -235,6 +235,7 @@ public class Ease.Document : GLib.Object, UndoSource
slides.insert(out itr, index);
slides.set(itr, COL_SLIDE, s);
slide_added(s, index);
+ listen(s);
}
/**
@@ -262,10 +263,11 @@ public class Ease.Document : GLib.Object, UndoSource
{
slides.remove(itr);
slide_deleted(s, index);
+ silence(s);
break;
}
index++;
- }
+ }
Slide ret;
Gtk.TreeIter itr;
diff --git a/src/ease-editor-window.vala b/src/ease-editor-window.vala
index bd4fab8..959468b 100644
--- a/src/ease-editor-window.vala
+++ b/src/ease-editor-window.vala
@@ -127,6 +127,7 @@ public class Ease.EditorWindow : Gtk.Window
set_default_size(1024, 768);
document = doc;
+ document.undo.connect(add_undo_action);
var builder = new Gtk.Builder();
try
@@ -152,18 +153,17 @@ public class Ease.EditorWindow : Gtk.Window
// main editor
embed = new EditorEmbed(document, this);
(builder.get_object("Embed Align") as Gtk.Alignment).add(embed);
- embed.undo.connect((action) => add_undo_action(action));
+ embed.undo.connect(add_undo_action);
// the inspector
inspector = new Inspector();
(builder.get_object("Inspector Align") as Gtk.Alignment).add(inspector);
- inspector.undo.connect((action) => add_undo_action(action));
+ inspector.undo.connect(add_undo_action);
embed.element_selected.connect(
inspector.element_pane.on_element_selected);
embed.element_deselected.connect(
inspector.element_pane.on_element_deselected);
-
// zoom slider
(builder.get_object("Zoom Slider Item") as Gtk.ToolItem).
add(create_zoom_slider());
diff --git a/src/ease-element.vala b/src/ease-element.vala
index c4ab1c3..9c7dc0a 100644
--- a/src/ease-element.vala
+++ b/src/ease-element.vala
@@ -22,7 +22,7 @@
* abstract, so each type of element is represented by a subclass. The Element
* base class contains properties common to all types of element.
*/
-public abstract class Ease.Element : GLib.Object
+public abstract class Ease.Element : GLib.Object, UndoSource
{
/**
* The default width of { link Theme} master slides.
diff --git a/src/ease-image-element.vala b/src/ease-image-element.vala
index 8560fc9..edacf44 100644
--- a/src/ease-image-element.vala
+++ b/src/ease-image-element.vala
@@ -68,7 +68,7 @@ public class Ease.ImageElement : MediaElement
{
filename = parent.parent.add_media_file(file_b.get_filename());
source_filename = file_b.get_filename();
- (widget_window(button) as EditorWindow).add_undo_action(action);
+ undo(action);
}
catch (Error e)
{
diff --git a/src/ease-inspector.vala b/src/ease-inspector.vala
index 0ac9ea7..fa5048c 100644
--- a/src/ease-inspector.vala
+++ b/src/ease-inspector.vala
@@ -64,7 +64,7 @@ public class Ease.Inspector : Gtk.Notebook, UndoSource
{
append_page(i, new Gtk.Image.from_stock(stock_id,
Gtk.IconSize.SMALL_TOOLBAR));
- i.undo.connect((action) => undo(action));
+ listen(i);
}
}
diff --git a/src/ease-slide.vala b/src/ease-slide.vala
index 9c74e0d..87916a5 100644
--- a/src/ease-slide.vala
+++ b/src/ease-slide.vala
@@ -22,7 +22,7 @@
* children. The currently selected Slide is often acted upon by an
* { link EditorWindow}.
*/
-public class Ease.Slide : GLib.Object
+public class Ease.Slide : GLib.Object, UndoSource
{
public const string IMAGE_TYPE = "EaseImageElement";
@@ -371,6 +371,7 @@ public class Ease.Slide : GLib.Object
e.parent = this;
elements.insert(index, e);
element_added(this, e, index);
+ listen(e);
}
/**
@@ -390,7 +391,8 @@ public class Ease.Slide : GLib.Object
{
var index = index_of(e);
elements.remove(e);
- element_removed(this, e, index);
+ element_removed(this, e, index);
+ silence(e);
}
/**
@@ -401,6 +403,7 @@ public class Ease.Slide : GLib.Object
var e = elements.get(index);
elements.remove_at(index);
element_removed(this, e, index);
+ silence(e);
}
/**
diff --git a/src/ease-text-element.vala b/src/ease-text-element.vala
index b8de459..83b5ce4 100644
--- a/src/ease-text-element.vala
+++ b/src/ease-text-element.vala
@@ -148,7 +148,7 @@ public class Ease.TextElement : Element
font.font_set.connect((button) => {
var action = new UndoAction(this, "font-description");
- (widget_window(button) as EditorWindow).add_undo_action(action);
+ undo(action);
font_description =
Pango.FontDescription.from_string(font.font_name);
});
@@ -163,7 +163,7 @@ public class Ease.TextElement : Element
color_b.color_set.connect((button) => {
var action = new UndoAction(this, "color");
- (widget_window(button) as EditorWindow).add_undo_action(action);
+ undo(action);
color = new Color.from_gdk(color_b.color);
});
@@ -192,7 +192,7 @@ public class Ease.TextElement : Element
if (text_align != old)
{
- (widget_window(sender) as EditorWindow).add_undo_action(action);
+ undo(action);
}
}
diff --git a/src/ease-undo-source.vala b/src/ease-undo-source.vala
index fcace0a..4cffb98 100644
--- a/src/ease-undo-source.vala
+++ b/src/ease-undo-source.vala
@@ -26,4 +26,30 @@ public interface Ease.UndoSource : GLib.Object
* UndoAction.
*/
public signal void undo(UndoItem action);
+
+ /**
+ * Forwards an { link UndoItem} downwards, to any object listening to this
+ * UndoSource's "undo" signal".
+ */
+ protected void forward(UndoItem action)
+ {
+ undo(action);
+ }
+
+ /**
+ * Listens for incoming UndoItems from the specified UndoSource, and
+ * { link forward}s them downwards.
+ */
+ protected void listen(UndoSource source)
+ {
+ source.undo.connect(forward);
+ }
+
+ /**
+ * Stops listening to an UndoSource.
+ */
+ protected void silence(UndoSource source)
+ {
+ source.undo.disconnect(forward);
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]