Permalink
Browse files

New History

The following improvements have be made to the history management:

* Redos are now visable and appear as blue, italic text.
* The ListStore in now managed
* Only a single click is required to move between states in the history list.
  • Loading branch information...
joehillen committed Mar 4, 2010
1 parent eaba6dc commit 90cd954ac439cbed2d89a45b0cdf3fd232cf11c4
@@ -0,0 +1,40 @@
//
// HistoryItemSelectedEventArgs.cs
//
// Author:
// Anirudh Sanjeev <anirudh@anirudhsanjeev.org>
//
// Copyright (c) 2010 Anirudh Sanjeev
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using Gtk;
namespace Pinta.Core
{
public sealed class HistoryItemHighlightEventArgs : EventArgs
{
public TreeIter Iter { get; set; }
public HistoryItemHighlightEventArgs (TreeIter iter)
{
Iter = iter;
}
}
}
@@ -25,46 +25,32 @@
// THE SOFTWARE.
using System;
using Gtk;
namespace Pinta.Core
{
public enum HistoryItemState { Undo, Redo }
public static class HistoryID {
private static int id = 0;
public static int ID {
get {
return id++;
}
set {
id = value;
}
}
}
public class BaseHistoryItem : IDisposable
{
public int ID { get; set; }
public string Icon { get; set; }
public string Text { get; set; }
public HistoryItemState State { get; set; }
public TreeIter Id;
public BaseHistoryItem ()
{
}
public BaseHistoryItem (string icon, string text)
{
this.ID = HistoryID.ID;
Icon = icon;
Text = text;
State = HistoryItemState.Undo;
}
public BaseHistoryItem (string icon, string text, HistoryItemState state)
{
this.ID = HistoryID.ID;
Icon = icon;
Text = text;
State = state;
@@ -1,8 +1,9 @@
//
// HistoryManager.cs
//
// Author:
// Authors:
// Jonathan Pobst <monkey@jpobst.com>
// Joe Hillenbrand <joehillen@gmail.com>
//
// Copyright (c) 2010 Jonathan Pobst
//
@@ -28,112 +29,129 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gtk;
namespace Pinta.Core
{
public class HistoryManager
{
List<BaseHistoryItem> history = new List<BaseHistoryItem> ();
int stack_pointer = -1;
int historyPointer = -1;
public void PushNewItem (BaseHistoryItem item)
public int Pointer {
get { return historyPointer; }
}
public BaseHistoryItem Current {
get { return history[historyPointer]; }
}
public void PushNewItem (BaseHistoryItem new_item)
{
// If we have un-did items on the history stack, they
// all get destroyed before we add a new item
while (history.Count - 1 > stack_pointer) {
BaseHistoryItem base_item = history[history.Count - 1];
history.RemoveAt (history.Count - 1);
base_item.Dispose ();
PintaCore.Actions.Edit.Redo.Sensitive = false;
// TODO: Delete from ListStore
//Remove all old redos starting from the end of the list
for (int i = history.Count - 1; i >= 0; i--) {
BaseHistoryItem item = history[i];
if (item.State == HistoryItemState.Redo) {
history.RemoveAt(i);
item.Dispose();
//Remove from ListStore
PintaCore.HistoryListStore.Remove (ref item.Id);
} else if (item.State == HistoryItemState.Undo) {
break;
}
}
//Add new undo to ListStore
new_item.Id = PintaCore.HistoryListStore.AppendValues (new_item);
history.Add (new_item);
historyPointer = history.Count - 1;
history.Add (item);
stack_pointer++;
PintaCore.Workspace.IsDirty = true;
PintaCore.Actions.Edit.Undo.Sensitive = true;
OnHistoryItemAdded (item);
PintaCore.Actions.Edit.Redo.Sensitive = false;
OnHistoryItemAdded (new_item);
}
public void Undo ()
{
if (stack_pointer < 0)
if (historyPointer < 0) {
throw new InvalidOperationException ("Undo stack is empty");
} else {
BaseHistoryItem item = history[historyPointer];
item.Undo ();
item.State = HistoryItemState.Redo;
PintaCore.HistoryListStore.SetValue (item.Id, 0, item);
history[historyPointer] = item;
historyPointer--;
}
BaseHistoryItem item = history[stack_pointer--];
item.Undo ();
if (stack_pointer == -1)
if (historyPointer == -1)
PintaCore.Actions.Edit.Undo.Sensitive = false;
PintaCore.Actions.Edit.Redo.Sensitive = true;
OnActionUndone ();
OnHistoryItemRemoved (item);
}
public void Redo ()
{
if (stack_pointer == history.Count - 1)
if (historyPointer >= history.Count - 1) {
throw new InvalidOperationException ("Redo stack is empty");
} else {
historyPointer++;
BaseHistoryItem item = history[historyPointer];
item.Redo ();
item.State = HistoryItemState.Undo;
PintaCore.HistoryListStore.SetValue (item.Id, 0, item);
history[historyPointer] = item;
}
BaseHistoryItem item = history[++stack_pointer];
item.Redo ();
if (stack_pointer == history.Count - 1)
if (historyPointer == history.Count - 1)
PintaCore.Actions.Edit.Redo.Sensitive = false;
PintaCore.Actions.Edit.Undo.Sensitive = true;
OnActionUndone ();
OnHistoryItemAdded (item);
}
public void Clear ()
{
while (history.Count > 0) {
BaseHistoryItem base_item = history[history.Count - 1];
history.RemoveAt (history.Count - 1);
base_item.Dispose ();
// TODO: Delete from ListStore
}
stack_pointer = -1;
history.ForEach (delegate(BaseHistoryItem item) { item.Dispose (); } );
history.Clear();
PintaCore.HistoryListStore.Clear ();
historyPointer = -1;
PintaCore.Actions.Edit.Redo.Sensitive = false;
PintaCore.Actions.Edit.Undo.Sensitive = false;
}
#region Protected Methods
protected void OnHistoryItemAdded (BaseHistoryItem item)
{
if (HistoryItemAdded != null)
HistoryItemAdded (this, new HistoryItemAddedEventArgs (item));
}
protected void OnHistoryItemRemoved (BaseHistoryItem item)
{
if (HistoryItemRemoved != null)
{
HistoryItemRemoved (this, new HistoryItemRemovedEventArgs (item));
}
}
protected void OnActionUndone ()
{
if (ActionUndone != null)
ActionUndone (this, EventArgs.Empty);
}
protected void OnActionRedone ()
{
if (ActionRedone != null)
ActionRedone (this, EventArgs.Empty);
}
#endregion
#region Events
public event EventHandler<HistoryItemAddedEventArgs> HistoryItemAdded;
public event EventHandler<HistoryItemRemovedEventArgs> HistoryItemRemoved;
@@ -64,6 +64,7 @@
<Compile Include="Effects\UserBlendOps.Generated.cs" />
<Compile Include="EventArgs\CanvasInvalidatedEventArgs.cs" />
<Compile Include="EventArgs\HistoryItemAddedEventArgs.cs" />
<Compile Include="EventArgs\HistoryItemRemovedEventArgs.cs" />
<Compile Include="EventArgs\TextChangedEventArgs.cs" />
<Compile Include="Extensions\ToolBarSlider.cs" />
<Compile Include="HistoryItems\ResizeHistoryItem.cs" />
@@ -132,7 +133,6 @@
<Compile Include="Tools\ShapeTool.cs" />
<Compile Include="Tools\UnimplementedTools.cs" />
<Compile Include="Tools\ZoomTool.cs" />
<Compile Include="EventArgs\HistoryItemRemovedEventArgs.cs" />
<Compile Include="HistoryItems\UpdateLayerPropertiesHistoryItem.cs" />
<Compile Include="Classes\ObservableObject.cs" />
<Compile Include="Classes\PropertyChangedEventArgs.cs" />
@@ -148,4 +148,4 @@
<Name>Pinta.Resources</Name>
</ProjectReference>
</ItemGroup>
</Project>
</Project>
@@ -40,6 +40,7 @@ public static class PintaCore
public static ActionManager Actions { get; private set; }
public static WorkspaceManager Workspace { get; private set; }
public static HistoryManager History { get; private set; }
public static Gtk.ListStore HistoryListStore { get; private set; }
public static SystemManager System { get; private set; }
static PintaCore ()
@@ -50,6 +51,7 @@ static PintaCore ()
Layers = new LayerManager ();
Tools = new ToolManager ();
History = new HistoryManager ();
HistoryListStore = new ListStore (typeof (BaseHistoryItem));
System = new SystemManager ();
}
Oops, something went wrong.

0 comments on commit 90cd954

Please sign in to comment.