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

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Projects.Gui/MonoDevelop.Projects.Gui.Dialogs.OptionPanels/EnvVarList.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
 
// EnvVarList.cs
2
 
//
3
 
// Author:
4
 
//   Lluis Sanchez Gual <lluis@novell.com>
5
 
//
6
 
// Copyright (c) 2008 Novell, Inc (http://www.novell.com)
7
 
//
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:
14
 
//
15
 
// The above copyright notice and this permission notice shall be included in
16
 
// all copies or substantial portions of the Software.
17
 
//
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
24
 
// THE SOFTWARE.
25
 
//
26
 
//
27
 
 
28
 
using System;
29
 
using System.Collections.Generic;
30
 
using Gtk;
31
 
using MonoDevelop.Core;
32
 
 
33
 
namespace MonoDevelop.Projects.Gui.Dialogs.OptionPanels
34
 
{
35
 
        [System.ComponentModel.Category("MonoDevelop.Projects.Gui")]
36
 
        [System.ComponentModel.ToolboxItem(true)]
37
 
        public class EnvVarList: ScrolledWindow
38
 
        {
39
 
                TreeView list;
40
 
                ListStore store;
41
 
                string createMsg;
42
 
                
43
 
                public EnvVarList()
44
 
                {
45
 
                        list = new TreeView ();
46
 
                        store = new ListStore (typeof(string), typeof(string), typeof(bool), typeof(string));
47
 
                        list.Model = store;
48
 
                        Add (list);
49
 
                        
50
 
                        CellRendererText crt = new CellRendererText ();
51
 
                        crt.Editable = true;
52
 
                        TreeViewColumn col = list.AppendColumn (GettextCatalog.GetString ("Variable"), crt, "text", 0, "foreground", 3);
53
 
                        col.Resizable = true;
54
 
                        
55
 
                        CellRendererText crv = new CellRendererText ();
56
 
                        col = list.AppendColumn (GettextCatalog.GetString ("Value"), crv, "text", 1, "editable", 2);
57
 
                        col.Resizable = true;
58
 
                        
59
 
                        crt.Edited += OnExpEdited;
60
 
                        crt.EditingStarted += OnExpEditing;
61
 
                        crv.Edited += OnValEdited;
62
 
                        
63
 
                        createMsg = GettextCatalog.GetString ("Click here to add a new variable");
64
 
                        AppendInserter ();
65
 
                        
66
 
                        ShowAll ();
67
 
                }
68
 
                
69
 
                public void LoadValues (IDictionary<string, string> values)
70
 
                {
71
 
                        store.Clear ();
72
 
                        foreach (KeyValuePair<string,string> val in values)
73
 
                                store.AppendValues (val.Key, val.Value, true, null);
74
 
                        AppendInserter ();
75
 
                }
76
 
                
77
 
                public void StoreValues (IDictionary<string, string> values)
78
 
                {
79
 
                        TreeIter it;
80
 
                        if (!store.GetIterFirst (out it))
81
 
                                return;
82
 
                        do {
83
 
                                bool inserter = !(bool) store.GetValue (it, 2);
84
 
                                if (!inserter) {
85
 
                                        string var = (string) store.GetValue (it, 0);
86
 
                                        string val = (string) store.GetValue (it, 1);
87
 
                                        values [var] = val;
88
 
                                }
89
 
                        } while (store.IterNext (ref it));
90
 
                }
91
 
                
92
 
                void OnExpEditing (object s, Gtk.EditingStartedArgs args)
93
 
                {
94
 
                        TreeIter it;
95
 
                        if (!store.GetIterFromString (out it, args.Path))
96
 
                                return;
97
 
                        Gtk.Entry e = (Gtk.Entry) args.Editable;
98
 
                        if (e.Text == createMsg)
99
 
                                e.Text = string.Empty;
100
 
                }
101
 
                
102
 
                void OnExpEdited (object s, Gtk.EditedArgs args)
103
 
                {
104
 
                        TreeIter it;
105
 
                        if (!store.GetIterFromString (out it, args.Path))
106
 
                                return;
107
 
                        
108
 
                        bool isInserter = !(bool) store.GetValue (it, 2);
109
 
                        
110
 
                        if (args.NewText.Length == 0) {
111
 
                                if (!isInserter)
112
 
                                        store.Remove (ref it);
113
 
                                return;
114
 
                        }
115
 
                        
116
 
                        store.SetValue (it, 0, args.NewText);
117
 
                        store.SetValue (it, 2, true);
118
 
                        store.SetValue (it, 3, null);
119
 
                        
120
 
                        if (isInserter)
121
 
                                AppendInserter ();
122
 
                }
123
 
                
124
 
                void OnValEdited (object s, Gtk.EditedArgs args)
125
 
                {
126
 
                        TreeIter it;
127
 
                        if (!store.GetIterFromString (out it, args.Path))
128
 
                                return;
129
 
                        store.SetValue (it, 1, args.NewText);
130
 
                }
131
 
                
132
 
                void AppendInserter ()
133
 
                {
134
 
                        store.AppendValues (createMsg, "", false, "gray");
135
 
                }
136
 
        }
137
 
}