[ease] [editor] Changes made to text can be reverted
- From: Nate Stedman <natesm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ease] [editor] Changes made to text can be reverted
- Date: Mon, 26 Jul 2010 23:58:45 +0000 (UTC)
commit 05cdedba8c4720a27a22d2e8033b4d4566484fcc
Author: Nate Stedman <natesm gmail com>
Date: Mon Jul 26 19:58:12 2010 -0400
[editor] Changes made to text can be reverted
Ties into UndoSource, as usual.
src/ease-text-actor.vala | 44 +++++++++++++++++++++++++++++++++++++-------
src/ease-undo-action.vala | 1 +
src/ease-undo-item.vala | 5 +++++
3 files changed, 43 insertions(+), 7 deletions(-)
---
diff --git a/src/ease-text-actor.vala b/src/ease-text-actor.vala
index a54998b..6beb144 100644
--- a/src/ease-text-actor.vala
+++ b/src/ease-text-actor.vala
@@ -31,6 +31,16 @@ public class Ease.TextActor : Actor
* The opacity of the selection highlight.
*/
private const uchar SELECTION_ALPHA = 200;
+
+ /**
+ * { link UndoAction} for an edit.
+ */
+ private UndoAction undo_action;
+
+ /**
+ * Text at the start of an edit.
+ */
+ private string original_text;
/**
* Instantiates a new TextActor from an Element.
@@ -53,7 +63,7 @@ public class Ease.TextActor : Actor
text.line_wrap_mode = Pango.WrapMode.WORD_CHAR;
text.color = e.color.clutter;
text.line_alignment = e.text_align;
- format(e);
+ text.font_name = e.font_description.to_string();
text.set_markup(e.has_been_edited ? e.text : DEFAULT_TEXT);
add_actor(contents);
@@ -68,7 +78,7 @@ public class Ease.TextActor : Actor
});
e.notify["font-description"].connect((sender, spec) => {
- format(element as TextElement);
+ text.font_name = e.font_description.to_string();
});
e.notify["text-align"].connect((sender, spec) => {
@@ -78,11 +88,13 @@ public class Ease.TextActor : Actor
e.notify["color"].connect((sender, spec) => {
text.color = e.color.clutter;
});
- }
-
- private void format(TextElement e)
- {
- (contents as Clutter.Text).font_name = e.font_description.to_string();
+
+ e.notify["text"].connect((sender, spec) => {
+ if (!text.editable)
+ {
+ text.set_markup(e.has_been_edited ? e.text : DEFAULT_TEXT);
+ }
+ });
}
/**
@@ -113,6 +125,18 @@ public class Ease.TextActor : Actor
{
text.text = "";
}
+
+ // create an UndoAction for the element
+ undo_action = new UndoAction(element, "has-been-edited");
+
+ // order is IMPORTANT here because of notify lambda
+ undo_action.add(element, "text");
+ original_text = (element as TextElement).text;
+
+ // if the text is being edited when the action is applied, stop editing
+ undo_action.pre_apply.connect((action) => {
+ if (text.editable) end_edit(sender);
+ });
}
/**
@@ -140,6 +164,12 @@ public class Ease.TextActor : Actor
{
element.has_been_edited = true;
}
+
+ // if changes were made to the text, report an UndoAction
+ if (original_text != (element as TextElement).text)
+ {
+ element.undo(undo_action);
+ }
}
/**
diff --git a/src/ease-undo-action.vala b/src/ease-undo-action.vala
index 747051b..9b56cf7 100644
--- a/src/ease-undo-action.vala
+++ b/src/ease-undo-action.vala
@@ -64,6 +64,7 @@ public class Ease.UndoAction : UndoItem
*/
public override UndoItem apply()
{
+ pre_apply(this);
foreach (var pair in pairs) pair.apply();
applied(this);
return this;
diff --git a/src/ease-undo-item.vala b/src/ease-undo-item.vala
index d5faf4a..9d6b49e 100644
--- a/src/ease-undo-item.vala
+++ b/src/ease-undo-item.vala
@@ -29,6 +29,11 @@ public abstract class Ease.UndoItem : GLib.Object
public signal void applied(UndoAction sender);
/**
+ * Emitted befor the item is applied.
+ */
+ public signal void pre_apply(UndoAction sender);
+
+ /**
* Applies the { link UndoItem}, restoring previous state.
*
* Returns an UndoItem that will redo the undo action.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]