5
// Jonathan Pobst <monkey@jpobst.com>
7
// Copyright (c) 2010 Jonathan Pobst
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
using System.Collections.Generic;
33
public class ToolManager : IEnumerable<BaseTool>
38
private List<BaseTool> Tools;
42
Tools = new List<BaseTool> ();
45
public void AddTool (BaseTool tool)
47
tool.ToolItem.Clicked += HandlePbToolItemClicked;
48
tool.ToolItem.Sensitive = tool.Enabled;
53
void HandlePbToolItemClicked (object sender, EventArgs e)
55
ToggleToolButton tb = (ToggleToolButton)sender;
57
BaseTool t = FindTool (tb.Label);
59
// Don't let the user unselect the current tool
60
if (t.Name == CurrentTool.Name) {
68
private BaseTool FindTool (string name)
70
name = name.ToLowerInvariant ();
72
foreach (BaseTool tool in Tools) {
73
if (tool.Name.ToLowerInvariant () == name) {
81
public BaseTool CurrentTool {
82
get { return Tools[index]; }
85
public BaseTool PreviousTool {
86
get { return Tools[prev_index]; }
89
public void SetCurrentTool (BaseTool tool)
91
int i = Tools.IndexOf (tool);
96
// Unload previous tool if needed
98
Tools[index].DoClearToolBar (PintaCore.Chrome.ToolToolBar);
99
Tools[index].DoDeactivated ();
100
Tools[index].ToolItem.Active = false;
106
tool.DoBuildToolBar (PintaCore.Chrome.ToolToolBar);
107
tool.ToolItem.Active = true;
109
PintaCore.Workspace.Invalidate ();
110
PintaCore.Chrome.SetStatusBarText (string.Format (" {0}: {1}", tool.Name, tool.StatusBarText));
113
public void SetCurrentTool (string tool)
115
BaseTool t = FindTool (tool);
121
#region IEnumerable<BaseTool> implementation
122
public IEnumerator<BaseTool> GetEnumerator ()
124
return Tools.GetEnumerator ();
128
#region IEnumerable implementation
129
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
131
return Tools.GetEnumerator ();