~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Projects.Gui/MonoDevelop.Projects.Gui.Dialogs.OptionPanels/CombineEntryConfigurationsPanel.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// CombineEntryConfigurationsPanel.cs
3
 
//
4
 
// Author:
5
 
//   Lluis Sanchez Gual
6
 
//
7
 
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
8
 
//
9
 
// Permission is hereby granted, free of charge, to any person obtaining
10
 
// a copy of this software and associated documentation files (the
11
 
// "Software"), to deal in the Software without restriction, including
12
 
// without limitation the rights to use, copy, modify, merge, publish,
13
 
// distribute, sublicense, and/or sell copies of the Software, and to
14
 
// permit persons to whom the Software is furnished to do so, subject to
15
 
// the following conditions:
16
 
// 
17
 
// The above copyright notice and this permission notice shall be
18
 
// included in all copies or substantial portions of the Software.
19
 
// 
20
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
 
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
 
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
 
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
 
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
 
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
 
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
 
//
28
 
 
29
 
using System;
30
 
using System.Collections;
31
 
using System.Reflection;
32
 
 
33
 
using MonoDevelop.Projects;
34
 
using MonoDevelop.Core;
35
 
using MonoDevelop.Components;
36
 
using MonoDevelop.Core.Gui;
37
 
using MonoDevelop.Core.Gui.Dialogs;
38
 
using Gtk;
39
 
 
40
 
namespace MonoDevelop.Projects.Gui.Dialogs.OptionPanels
41
 
{
42
 
        internal class CombineEntryConfigurationsPanel : AbstractOptionPanel
43
 
        {
44
 
                CombineEntryConfigurationsPanelWidget widget;
45
 
                
46
 
                public override void LoadPanelContents()
47
 
                {
48
 
                        Add (widget = new CombineEntryConfigurationsPanelWidget ((Properties) CustomizationObject));
49
 
                }
50
 
 
51
 
                public override bool StorePanelContents()
52
 
                {
53
 
                bool success = widget.Store ();
54
 
                        return success;                 
55
 
        }
56
 
        }
57
 
 
58
 
        partial class CombineEntryConfigurationsPanelWidget : Gtk.Bin 
59
 
        {
60
 
                TreeStore store;
61
 
                ConfigurationData configData;
62
 
                
63
 
                public CombineEntryConfigurationsPanelWidget (Properties CustomizationObject)
64
 
                {
65
 
                        Build ();
66
 
                        
67
 
//                      combine = (Combine)((Properties)CustomizationObject).Get("Combine");
68
 
                        configData = ((Properties)CustomizationObject).Get<ConfigurationData>("CombineConfigData");
69
 
                        
70
 
                        store = new TreeStore (typeof(object), typeof(string));
71
 
                        configsList.Model = store;
72
 
                        configsList.HeadersVisible = true;
73
 
                        
74
 
                        TreeViewColumn col = new TreeViewColumn ();
75
 
                        CellRendererText sr = new CellRendererText ();
76
 
                        col.PackStart (sr, true);
77
 
                        col.AddAttribute (sr, "text", 1);
78
 
                        col.Title = GettextCatalog.GetString ("Configuration");
79
 
                        configsList.AppendColumn (col);
80
 
                        
81
 
                        foreach (CombineConfiguration cc in configData.Configurations)
82
 
                                store.AppendValues (cc, cc.Name);
83
 
 
84
 
                        addButton.Clicked += new EventHandler (OnAddConfiguration);
85
 
                        removeButton.Clicked += new EventHandler (OnRemoveConfiguration);
86
 
                        renameButton.Clicked += new EventHandler (OnRenameConfiguration);
87
 
                        copyButton.Clicked += new EventHandler (OnCopyConfiguration);
88
 
                }
89
 
                
90
 
                void OnAddConfiguration (object sender, EventArgs args)
91
 
                {
92
 
                        AddConfiguration (null);
93
 
                }
94
 
 
95
 
                void OnCopyConfiguration (object sender, EventArgs args)
96
 
                {
97
 
                        Gtk.TreeModel foo;
98
 
                        Gtk.TreeIter iter;
99
 
                        if (!configsList.Selection.GetSelected (out foo, out iter))
100
 
                                return;
101
 
                                
102
 
                        CombineConfiguration cc = (CombineConfiguration) store.GetValue (iter, 0);
103
 
                        AddConfiguration (cc.Name);
104
 
                }
105
 
 
106
 
                void AddConfiguration (string copyFrom)
107
 
                {
108
 
                        NewConfigurationDialog dlg = new NewConfigurationDialog ();
109
 
                        try {
110
 
                                bool done = false;
111
 
                                do {
112
 
                                        if (dlg.Run () == (int) Gtk.ResponseType.Ok) {
113
 
                                                if (dlg.ConfigName.Length == 0) {
114
 
                                                        Services.MessageService.ShowWarning (GettextCatalog.GetString ("Please enter a valid configuration name."));
115
 
                                                } else if (configData.Configurations [dlg.ConfigName] != null) {
116
 
                                                        Services.MessageService.ShowWarning (GettextCatalog.GetString ("A configuration with the name '{0}' already exists.", dlg.ConfigName));
117
 
                                                } else {
118
 
                                                        CombineConfiguration cc = (CombineConfiguration) configData.AddConfiguration (dlg.ConfigName, copyFrom, dlg.CreateChildren);
119
 
                                                        store.AppendValues (cc, cc.Name);
120
 
                                                        done = true;
121
 
                                                }
122
 
                                        } else
123
 
                                                done = true;
124
 
                                } while (!done);
125
 
                        } finally {
126
 
                                dlg.Destroy ();
127
 
                        }
128
 
                }
129
 
 
130
 
                void OnRemoveConfiguration (object sender, EventArgs args)
131
 
                {
132
 
                        Gtk.TreeModel foo;
133
 
                        Gtk.TreeIter iter;
134
 
                        if (!configsList.Selection.GetSelected (out foo, out iter))
135
 
                                return;
136
 
                        
137
 
                        if (configData.Configurations.Count == 1) {
138
 
                                Services.MessageService.ShowWarning (GettextCatalog.GetString ("There must be at least one configuration."));
139
 
                                return;
140
 
                        }
141
 
                        
142
 
                        CombineConfiguration cc = (CombineConfiguration) store.GetValue (iter, 0);
143
 
                        DeleteConfigDialog dlg = new DeleteConfigDialog ();
144
 
                        
145
 
                        try {
146
 
                                if (dlg.Run () == (int) Gtk.ResponseType.Yes) {
147
 
                                        configData.RemoveConfiguration (cc.Name, dlg.DeleteChildren);
148
 
                                        store.Remove (ref iter);
149
 
                                }
150
 
                        } finally {
151
 
                                dlg.Destroy ();
152
 
                        }
153
 
                }
154
 
                
155
 
                void OnRenameConfiguration (object sender, EventArgs args)
156
 
                {
157
 
                        Gtk.TreeModel foo;
158
 
                        Gtk.TreeIter iter;
159
 
                        if (!configsList.Selection.GetSelected (out foo, out iter))
160
 
                                return;
161
 
                                
162
 
                        CombineConfiguration cc = (CombineConfiguration) store.GetValue (iter, 0);
163
 
                        RenameConfigDialog dlg = new RenameConfigDialog ();
164
 
                        dlg.ConfigName = cc.Name;
165
 
                        
166
 
                        try {
167
 
                                bool done = false;
168
 
                                do {
169
 
                                        if (dlg.Run () == (int) Gtk.ResponseType.Ok) {
170
 
                                                if (dlg.ConfigName.Length == 0) {
171
 
                                                        Services.MessageService.ShowWarning (GettextCatalog.GetString ("Please enter a valid configuration name."));
172
 
                                                } else if (configData.Configurations [dlg.ConfigName] != null) {
173
 
                                                        Services.MessageService.ShowWarning (GettextCatalog.GetString ("A configuration with the name '{0}' already exists.", dlg.ConfigName));
174
 
                                                } else {
175
 
                                                        configData.RenameConfiguration (cc.Name, dlg.ConfigName, dlg.RenameChildren);
176
 
                                                        store.SetValue (iter, 1, cc.Name);
177
 
                                                        done = true;
178
 
                                                }
179
 
                                        } else
180
 
                                                done = true;
181
 
                                } while (!done);
182
 
                        } finally {
183
 
                                dlg.Destroy ();
184
 
                        }
185
 
                }
186
 
 
187
 
                public bool Store()
188
 
                {
189
 
                        // Data stored at dialog level
190
 
                        return true;
191
 
                }
192
 
        }
193
 
}
194