"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Pinta.Core/Managers/ToolManager.cs" between
pinta-1.7.tar.gz and pinta-1.7.1.tar.gz

About: Pinta is a powerful image drawing and editing program (modeled after Paint.NET).

ToolManager.cs  (pinta-1.7):ToolManager.cs  (pinta-1.7.1)
skipping to change at line 40 skipping to change at line 40
using Gtk; using Gtk;
namespace Pinta.Core namespace Pinta.Core
{ {
public class ToolManager : IEnumerable<BaseTool> public class ToolManager : IEnumerable<BaseTool>
{ {
int index = -1; int index = -1;
int prev_index = -1; int prev_index = -1;
private List<BaseTool> Tools; private List<BaseTool> Tools;
private Dictionary<Gdk.Key, List<BaseTool>> groupedTools;
private Gdk.Key LastUsedKey;
private int PressedShortcutCounter;
public event EventHandler<ToolEventArgs> ToolAdded; public event EventHandler<ToolEventArgs> ToolAdded;
public event EventHandler<ToolEventArgs> ToolRemoved; public event EventHandler<ToolEventArgs> ToolRemoved;
public ToolManager () public ToolManager ()
{ {
Tools = new List<BaseTool> (); Tools = new List<BaseTool> ();
groupedTools = new Dictionary<Gdk.Key, List<BaseTool>>();
PressedShortcutCounter = 0;
} }
public void AddTool (BaseTool tool) public void AddTool (BaseTool tool)
{ {
tool.ToolItem.Clicked += HandlePbToolItemClicked; tool.ToolItem.Clicked += HandlePbToolItemClicked;
tool.ToolItem.Sensitive = tool.Enabled; tool.ToolItem.Sensitive = tool.Enabled;
Tools.Add (tool); Tools.Add (tool);
Tools.Sort (new ToolSorter ()); Tools.Sort (new ToolSorter ());
OnToolAdded (tool); OnToolAdded (tool);
if (CurrentTool == null) if (CurrentTool == null)
SetCurrentTool (tool); SetCurrentTool (tool);
if (!groupedTools.ContainsKey(tool.ShortcutKey))
groupedTools.Add(tool.ShortcutKey, new List<BaseT
ool>());
groupedTools[tool.ShortcutKey].Add(tool);
} }
public void RemoveInstanceOfTool (System.Type tool_type) public void RemoveInstanceOfTool (System.Type tool_type)
{ {
foreach (BaseTool tool in Tools) { foreach (BaseTool tool in Tools) {
if (tool.GetType () == tool_type) { if (tool.GetType () == tool_type) {
tool.ToolItem.Clicked -= HandlePbToolItem Clicked; tool.ToolItem.Clicked -= HandlePbToolItem Clicked;
tool.ToolItem.Active = false; tool.ToolItem.Active = false;
tool.ToolItem.Sensitive = false; tool.ToolItem.Sensitive = false;
Tools.Remove (tool); Tools.Remove (tool);
Tools.Sort (new ToolSorter ()); Tools.Sort (new ToolSorter ());
SetCurrentTool(new DummyTool()); SetCurrentTool(new DummyTool());
OnToolRemoved (tool); OnToolRemoved (tool);
if (groupedTools[tool.ShortcutKey].Count
> 1)
groupedTools[tool.ShortcutKey].Re
move(tool);
else
groupedTools.Remove(tool.Shortcut
Key);
return; return;
} }
} }
} }
void HandlePbToolItemClicked (object sender, EventArgs e) void HandlePbToolItemClicked (object sender, EventArgs e)
{ {
ToggleToolButton tb = (ToggleToolButton)sender; ToggleToolButton tb = (ToggleToolButton)sender;
BaseTool t = FindTool (tb.Label); BaseTool t = FindTool (tb.Label);
skipping to change at line 178 skipping to change at line 194
public void SetCurrentTool (Gdk.Key shortcut) public void SetCurrentTool (Gdk.Key shortcut)
{ {
BaseTool tool = FindNextTool (shortcut); BaseTool tool = FindNextTool (shortcut);
if (tool != null) if (tool != null)
SetCurrentTool(tool); SetCurrentTool(tool);
} }
private BaseTool FindNextTool (Gdk.Key shortcut) private BaseTool FindNextTool (Gdk.Key shortcut)
{ {
string key = shortcut.ToString ().ToUpperInvariant (); shortcut = shortcut.ToUpper();
// Begin looking at the tool after the current one if (groupedTools.ContainsKey(shortcut))
for (int i = index + 1; i < Tools.Count; i++) { {
if (Tools[i].ShortcutKey.ToString ().ToUpperInvar for (int i = 0; i < groupedTools[shortcut].Count;
iant () == key) i++)
return Tools[i]; {
} if (LastUsedKey != shortcut)
{
// Begin at the beginning and look up to the current tool // Return first tool in group.
for (int i = 0; i < index; i++) { PressedShortcutCounter = (1 % gro
if (Tools[i].ShortcutKey.ToString ().ToUpperInvar upedTools[shortcut].Count);
iant () == key) LastUsedKey = shortcut;
return Tools[i]; return groupedTools[shortcut][0];
}
else if(i == PressedShortcutCounter)
{
var tool = groupedTools[shortcut]
[PressedShortcutCounter];
PressedShortcutCounter = (i + 1)
% groupedTools[shortcut].Count;
return tool;
}
}
} }
return null; return null;
} }
private void OnToolAdded (BaseTool tool) private void OnToolAdded (BaseTool tool)
{ {
if (ToolAdded != null) if (ToolAdded != null)
ToolAdded (this, new ToolEventArgs (tool)); ToolAdded (this, new ToolEventArgs (tool));
} }
private void OnToolRemoved (BaseTool tool) private void OnToolRemoved (BaseTool tool)
{ {
skipping to change at line 245 skipping to change at line 269
public override string Icon { get { return Gtk.Stock.MissingImage ; } } public override string Icon { get { return Gtk.Stock.MissingImage ; } }
public override string StatusBarText { get { return Mono.Unix.Cat alog.GetString ("No tool selected."); } } public override string StatusBarText { get { return Mono.Unix.Cat alog.GetString ("No tool selected."); } }
protected override void OnBuildToolBar (Toolbar tb) protected override void OnBuildToolBar (Toolbar tb)
{ {
tool_label = null; tool_label = null;
tool_image = null; tool_image = null;
tool_sep = null; tool_sep = null;
} }
} }
//Key extensions for more convenient usage of Gdk key enumerator
public static class KeyExtensions
{
public static Gdk.Key ToUpper(this Gdk.Key k1)
{
try
{
return (Gdk.Key)Enum.Parse(typeof(Gdk.Key), k1.To
String().ToUpperInvariant());
}
catch (ArgumentException)
{
//there is a need to catch argument exception bec
ause some buttons have not its UpperCase variant
return k1;
}
}
}
} }
 End of changes. 8 change blocks. 
14 lines changed or deleted 63 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)