~paolorotolo/pinta/fix-for-1093971

« back to all changes in this revision

Viewing changes to Pinta.Core/Managers/ToolManager.cs

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2011-11-16 15:34:43 UTC
  • mfrom: (8.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20111116153443-5b3d3nqoc82a3pnv
Tags: 1.1-1
* [a2af0ce] Imported Upstream version 1.1
* [6b57160] Wrap too-long changelog line — silence, Lintian!
* [1e6d30f] Update copyright to newer DEP5ness
* [3879389] Update watch file for new upstream download location
* Remove upstreamed patches
  + [16a2b1b] remove-targetversion patch
  + [0114794] unversion-lib-references
* Add new build dependencies required by this release
  + [1cc97d9] mono-addins
  + [b698368] intltool
* [b698368] Remove references to other programs in long description
* [bd76c1d] BD on intltool for required by upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
using System;
28
28
using System.Collections.Generic;
 
29
using System.Linq;
29
30
using Gtk;
30
31
 
31
32
namespace Pinta.Core
37
38
                
38
39
                private List<BaseTool> Tools;
39
40
 
 
41
                public event EventHandler<ToolEventArgs> ToolAdded;
 
42
 
40
43
                public ToolManager ()
41
44
                {
42
45
                        Tools = new List<BaseTool> ();
47
50
                        tool.ToolItem.Clicked += HandlePbToolItemClicked;
48
51
                        tool.ToolItem.Sensitive = tool.Enabled;
49
52
                        
50
 
                        Tools.Add (tool);       
 
53
                        Tools.Add (tool);
 
54
                        Tools.Sort (new ToolSorter ());
 
55
 
 
56
                        OnToolAdded (tool);
 
57
 
 
58
                        if (CurrentTool == null)
 
59
                                SetCurrentTool (tool);
51
60
                }
52
61
                
53
62
                void HandlePbToolItemClicked (object sender, EventArgs e)
57
66
                        BaseTool t = FindTool (tb.Label);
58
67
 
59
68
                        // Don't let the user unselect the current tool 
60
 
                        if (t.Name == CurrentTool.Name) {
 
69
                        if (CurrentTool != null && t.Name == CurrentTool.Name) {
61
70
                                if (prev_index != index)
62
71
                                        tb.Active = true;
63
72
                                return;
80
89
                }
81
90
                
82
91
                public BaseTool CurrentTool {
83
 
                        get { return Tools[index]; }
 
92
                        get { if (index >= 0) return Tools[index]; return null; }
84
93
                }
85
94
                
86
95
                public BaseTool PreviousTool {
89
98
 
90
99
                public void Commit ()
91
100
                {
92
 
                        CurrentTool.DoCommit ();
 
101
                        if (CurrentTool != null)
 
102
                                CurrentTool.DoCommit ();
93
103
                }
94
104
 
95
105
                public void SetCurrentTool (BaseTool tool)
156
166
                        return null;
157
167
                }
158
168
                
 
169
                private void OnToolAdded (BaseTool tool)
 
170
                {
 
171
                        if (ToolAdded != null)
 
172
                                ToolAdded (this, new ToolEventArgs (tool));
 
173
                }
 
174
 
159
175
                #region IEnumerable<BaseTool> implementation
160
176
                public IEnumerator<BaseTool> GetEnumerator ()
161
177
                {
169
185
                        return Tools.GetEnumerator ();
170
186
                }
171
187
                #endregion
 
188
 
 
189
                class ToolSorter : Comparer<BaseTool>
 
190
                {
 
191
                        public override int Compare (BaseTool x, BaseTool y)
 
192
                        {
 
193
                                return x.Priority - y.Priority;
 
194
                        }
 
195
                }
172
196
        }
173
197
}