~ubuntu-branches/ubuntu/natty/monodevelop/natty

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Components/MonoDevelop.Components/FolderListSelector.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-07-05 13:00:05 UTC
  • mfrom: (1.2.8 upstream) (1.3.9 experimental)
  • Revision ID: james.westby@ubuntu.com-20100705130005-d6hp4k5gcn1xkj8c
Tags: 2.4+dfsg-1ubuntu1
* debian/patches/remove_support_for_moonlight.patch,
  debian/patches/dont_add_moonlight_to_core_addins.patch,
  debian/control:
  + Enable support for Moonlight
* debian/rules:
  + Ensure Moonlight addin isn't shipped in main MonoDevelop package by
    mistake

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// 
2
 
// FolderListSelector.cs
3
 
//  
4
 
// Author:
5
 
//       Lluis Sanchez Gual <lluis@novell.com>
6
 
// 
7
 
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
8
 
// 
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:
15
 
// 
16
 
// The above copyright notice and this permission notice shall be included in
17
 
// all copies or substantial portions of the Software.
18
 
// 
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
25
 
// THE SOFTWARE.
26
 
 
27
 
using System;
28
 
using System.Collections.Generic;
29
 
using Gtk;
30
 
 
31
 
namespace MonoDevelop.Components
32
 
{
33
 
        [System.ComponentModel.ToolboxItem(true)]
34
 
        public partial class FolderListSelector : Gtk.Bin
35
 
        {
36
 
                ListStore store;
37
 
                List<string> directories = new List<string> ();
38
 
                
39
 
                public FolderListSelector ()
40
 
                {
41
 
                        this.Build ();
42
 
                        
43
 
                        store = new ListStore (typeof(String));
44
 
                        dirList.Model = store;
45
 
                        dirList.AppendColumn ("", new CellRendererText (), "text", 0);
46
 
                        dirList.Selection.Changed += delegate {
47
 
                                UpdateStatus ();
48
 
                        };
49
 
                }
50
 
                
51
 
                public List<string> Directories {
52
 
                        get {
53
 
                                return directories;
54
 
                        }
55
 
                        set {
56
 
                                directories = value;
57
 
                                UpdateList ();
58
 
                        }
59
 
                }
60
 
                
61
 
                void UpdateList ()
62
 
                {
63
 
                        store.Clear ();
64
 
                        foreach (string dir in directories)
65
 
                                store.AppendValues (dir);
66
 
                }
67
 
                
68
 
                void UpdateStatus ()
69
 
                {
70
 
                        buttonAdd.Sensitive = !string.IsNullOrEmpty (folderentry.Path);
71
 
                        TreeIter it;
72
 
                        if (dirList.Selection.GetSelected (out it)) {
73
 
                                buttonUpdate.Sensitive = !string.IsNullOrEmpty (folderentry.Path);
74
 
                                buttonRemove.Sensitive = true;
75
 
                                TreeIter fi;
76
 
                                store.GetIterFirst (out fi);
77
 
                                buttonUp.Sensitive = !(store.GetPath (it).Equals (store.GetPath (fi)));
78
 
                                buttonDown.Sensitive = store.IterNext (ref it);
79
 
                        } else {
80
 
                                buttonUpdate.Sensitive = buttonRemove.Sensitive = buttonUp.Sensitive = buttonDown.Sensitive = false;
81
 
                        }
82
 
                }
83
 
 
84
 
                void OnButtonAddClicked (object sender, System.EventArgs e)
85
 
                {
86
 
                        string path = folderentry.Path;
87
 
                        directories.Add (path);
88
 
                        TreeIter it = store.AppendValues (path);
89
 
                        FocusRow (it);
90
 
                }
91
 
                
92
 
                void FocusRow (TreeIter it)
93
 
                {
94
 
                        dirList.Selection.SelectIter (it);
95
 
                        dirList.ScrollToCell (store.GetPath (it), dirList.Columns[0], false, 0, 0);
96
 
                        UpdateStatus ();
97
 
                }
98
 
 
99
 
                void OnFolderentryPathChanged (object sender, System.EventArgs e)
100
 
                {
101
 
                        UpdateStatus ();
102
 
                }
103
 
 
104
 
                void OnButtonRemoveClicked (object sender, System.EventArgs e)
105
 
                {
106
 
                        TreeIter it;
107
 
                        if (dirList.Selection.GetSelected (out it)) {
108
 
                                string dir = (string) store.GetValue (it, 0);
109
 
                                directories.Remove (dir);
110
 
                                store.Remove (ref it);
111
 
                                if (!it.Equals (TreeIter.Zero))
112
 
                                        FocusRow (it);
113
 
                                else
114
 
                                        UpdateStatus ();
115
 
                        }
116
 
                }
117
 
 
118
 
                void OnButtonUpdateClicked (object sender, System.EventArgs e)
119
 
                {
120
 
                        TreeIter it;
121
 
                        if (dirList.Selection.GetSelected (out it)) {
122
 
                                string dir = (string) store.GetValue (it, 0);
123
 
                                int i = directories.IndexOf (dir);
124
 
                                directories [i] = folderentry.Path;
125
 
                                store.SetValue (it, 0, folderentry.Path);
126
 
                                UpdateStatus ();
127
 
                        }
128
 
                }
129
 
 
130
 
                void OnButtonUpClicked (object sender, System.EventArgs e)
131
 
                {
132
 
                        TreeIter it;
133
 
                        dirList.Selection.GetSelected (out it);
134
 
                        string dir = (string) store.GetValue (it, 0);
135
 
                        int i = directories.IndexOf (dir);
136
 
                        string prevDir = directories [i - 1];
137
 
                        TreeIter pi;
138
 
                        store.IterNthChild (out pi, i - 1);
139
 
                        store.SetValue (pi, 0, dir);
140
 
                        store.SetValue (it, 0, prevDir);
141
 
                        directories [i - 1] = dir;
142
 
                        directories [i] = prevDir;
143
 
                        FocusRow (pi);
144
 
                }
145
 
 
146
 
                void OnButtonDownClicked (object sender, System.EventArgs e)
147
 
                {
148
 
                        TreeIter it;
149
 
                        dirList.Selection.GetSelected (out it);
150
 
                        string prevDir = (string) store.GetValue (it, 0);
151
 
                        int i = directories.IndexOf (prevDir);
152
 
                        string dir = directories [++i];
153
 
                        TreeIter pi = it;
154
 
                        store.IterNext (ref it);
155
 
                        store.SetValue (pi, 0, dir);
156
 
                        store.SetValue (it, 0, prevDir);
157
 
                        directories [i - 1] = dir;
158
 
                        directories [i] = prevDir;
159
 
                        FocusRow (it);
160
 
                }
161
 
        }
162
 
}