2
// FolderListSelector.cs
5
// Lluis Sanchez Gual <lluis@novell.com>
7
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
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;
31
namespace MonoDevelop.Components
33
[System.ComponentModel.ToolboxItem(true)]
34
public partial class FolderListSelector : Gtk.Bin
37
List<string> directories = new List<string> ();
39
public FolderListSelector ()
43
store = new ListStore (typeof(String));
44
dirList.Model = store;
45
dirList.AppendColumn ("", new CellRendererText (), "text", 0);
46
dirList.Selection.Changed += delegate {
51
public List<string> Directories {
64
foreach (string dir in directories)
65
store.AppendValues (dir);
70
buttonAdd.Sensitive = !string.IsNullOrEmpty (folderentry.Path);
72
if (dirList.Selection.GetSelected (out it)) {
73
buttonUpdate.Sensitive = !string.IsNullOrEmpty (folderentry.Path);
74
buttonRemove.Sensitive = true;
76
store.GetIterFirst (out fi);
77
buttonUp.Sensitive = !(store.GetPath (it).Equals (store.GetPath (fi)));
78
buttonDown.Sensitive = store.IterNext (ref it);
80
buttonUpdate.Sensitive = buttonRemove.Sensitive = buttonUp.Sensitive = buttonDown.Sensitive = false;
84
void OnButtonAddClicked (object sender, System.EventArgs e)
86
string path = folderentry.Path;
87
directories.Add (path);
88
TreeIter it = store.AppendValues (path);
92
void FocusRow (TreeIter it)
94
dirList.Selection.SelectIter (it);
95
dirList.ScrollToCell (store.GetPath (it), dirList.Columns[0], false, 0, 0);
99
void OnFolderentryPathChanged (object sender, System.EventArgs e)
104
void OnButtonRemoveClicked (object sender, System.EventArgs e)
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))
118
void OnButtonUpdateClicked (object sender, System.EventArgs e)
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);
130
void OnButtonUpClicked (object sender, System.EventArgs e)
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];
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;
146
void OnButtonDownClicked (object sender, System.EventArgs e)
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];
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;