4
// Lluis Sanchez Gual <lluis@novell.com>
6
// Copyright (c) 2008 Novell, Inc (http://www.novell.com)
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
9
// of this software and associated documentation files (the "Software"), to deal
10
// in the Software without restriction, including without limitation the rights
11
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
// copies of the Software, and to permit persons to whom the Software is
13
// furnished to do so, subject to the following conditions:
15
// The above copyright notice and this permission notice shall be included in
16
// all copies or substantial portions of the Software.
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29
using System.Collections.Generic;
31
using MonoDevelop.Core;
33
namespace MonoDevelop.Projects.Gui.Dialogs.OptionPanels
35
[System.ComponentModel.Category("MonoDevelop.Projects.Gui")]
36
[System.ComponentModel.ToolboxItem(true)]
37
public class EnvVarList: ScrolledWindow
45
list = new TreeView ();
46
store = new ListStore (typeof(string), typeof(string), typeof(bool), typeof(string));
50
CellRendererText crt = new CellRendererText ();
52
TreeViewColumn col = list.AppendColumn (GettextCatalog.GetString ("Variable"), crt, "text", 0, "foreground", 3);
55
CellRendererText crv = new CellRendererText ();
56
col = list.AppendColumn (GettextCatalog.GetString ("Value"), crv, "text", 1, "editable", 2);
59
crt.Edited += OnExpEdited;
60
crt.EditingStarted += OnExpEditing;
61
crv.Edited += OnValEdited;
63
createMsg = GettextCatalog.GetString ("Click here to add a new variable");
69
public void LoadValues (IDictionary<string, string> values)
72
foreach (KeyValuePair<string,string> val in values)
73
store.AppendValues (val.Key, val.Value, true, null);
77
public void StoreValues (IDictionary<string, string> values)
80
if (!store.GetIterFirst (out it))
83
bool inserter = !(bool) store.GetValue (it, 2);
85
string var = (string) store.GetValue (it, 0);
86
string val = (string) store.GetValue (it, 1);
89
} while (store.IterNext (ref it));
92
void OnExpEditing (object s, Gtk.EditingStartedArgs args)
95
if (!store.GetIterFromString (out it, args.Path))
97
Gtk.Entry e = (Gtk.Entry) args.Editable;
98
if (e.Text == createMsg)
99
e.Text = string.Empty;
102
void OnExpEdited (object s, Gtk.EditedArgs args)
105
if (!store.GetIterFromString (out it, args.Path))
108
bool isInserter = !(bool) store.GetValue (it, 2);
110
if (args.NewText.Length == 0) {
112
store.Remove (ref it);
116
store.SetValue (it, 0, args.NewText);
117
store.SetValue (it, 2, true);
118
store.SetValue (it, 3, null);
124
void OnValEdited (object s, Gtk.EditedArgs args)
127
if (!store.GetIterFromString (out it, args.Path))
129
store.SetValue (it, 1, args.NewText);
132
void AppendInserter ()
134
store.AppendValues (createMsg, "", false, "gray");