~ubuntu-branches/ubuntu/feisty/monodevelop/feisty

« back to all changes in this revision

Viewing changes to Core/src/MonoDevelop.Projects.Gui/MonoDevelop.Projects.Gui.Dialogs.OptionPanels/DeploymentOptionsPanel.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-08-18 00:51:23 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060818005123-5iit07y0j7wjg55f
Tags: 0.11+svn20060818-0ubuntu1
* New SVN snapshot
  + Works with Gtk# 2.9.0
* debian/control:
  + Updated Build-Depends
* debian/patches/use_nunit2.2.dpatch,
  debian/patches/use_real_libs.dpatch:
  + Updated
* debian/patches/versioncontrol_buildfix.dpatch:
  + Fix build failure in the version control addin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// DeploymentOptionsPanel.cs
 
3
//
 
4
// Author:
 
5
//   Lluis Sanchez Gual
 
6
//
 
7
// Copyright (C) 2006 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.Generic;
 
31
using Gtk;
 
32
using Gdk;
 
33
using MonoDevelop.Core;
 
34
using MonoDevelop.Core.Properties;
 
35
using MonoDevelop.Core.Gui.Dialogs;
 
36
using MonoDevelop.Projects.Deployment;
 
37
using MonoDevelop.Components;
 
38
using MonoDevelop.Projects.Gui.Deployment;
 
39
 
 
40
namespace MonoDevelop.Projects.Gui.Dialogs.OptionPanels
 
41
{
 
42
        public class DeploymentOptionsPanel : AbstractOptionPanel
 
43
        {
 
44
                DeploymentOptionsWidget widget;
 
45
                
 
46
                class DeploymentOptionsWidget : GladeWidgetExtract 
 
47
                {
 
48
                        // Gtk Controls
 
49
                        [Glade.Widget] Gtk.TreeView targetsTree;
 
50
                        [Glade.Widget] Gtk.HBox targetsBox;
 
51
                        [Glade.Widget] Gtk.Button buttonEdit;
 
52
                        [Glade.Widget] Gtk.Button buttonRemove;
 
53
                        
 
54
                        CombineEntry entry;
 
55
                        List<DeployTarget> targets = new List<DeployTarget> ();
 
56
                        ListStore store;
 
57
                        DeployTarget defaultTarget;
 
58
 
 
59
                        public DeploymentOptionsWidget (IProperties CustomizationObject) : 
 
60
                                base ("Base.glade", "DeployOptionsPanel")
 
61
                        {
 
62
                                entry = ((IProperties)CustomizationObject).GetProperty("Combine") as Combine;
 
63
                                if (entry == null)
 
64
                                        entry = ((IProperties)CustomizationObject).GetProperty("Project") as Project;
 
65
                                        
 
66
                                if (entry == null)
 
67
                                        return;
 
68
                                
 
69
                                if (MonoDevelop.Projects.Services.DeployService.GetDeployHandlers (entry).Length == 0) {
 
70
                                        foreach (Gtk.Widget w in targetsBox.Children)
 
71
                                                targetsBox.Remove (w);
 
72
                                        Gtk.Label lab = new Gtk.Label (GettextCatalog.GetString ("There are no deployment handlers available for this solution item."));
 
73
                                        lab.Xalign = 0;
 
74
                                        targetsBox.PackStart (lab, false, false, 0);
 
75
                                        return;
 
76
                                }
 
77
                                        
 
78
                                store = new ListStore (typeof(Gdk.Pixbuf), typeof(string), typeof(object));
 
79
                                targetsTree.Model = store;
 
80
                                
 
81
                                targetsTree.HeadersVisible = false;
 
82
                                Gtk.CellRendererPixbuf cr = new Gtk.CellRendererPixbuf();
 
83
                                cr.Yalign = 0;
 
84
                                targetsTree.AppendColumn ("", cr, "pixbuf", 0);
 
85
                                targetsTree.AppendColumn ("", new Gtk.CellRendererText(), "markup", 1);
 
86
                                
 
87
                                foreach (DeployTarget target in entry.DeployTargets) {
 
88
                                        if (target is UnknownDeployTarget)
 
89
                                                targets.Add (target);
 
90
                                        else {
 
91
                                                DeployTarget ct = target.DeployHandler.CreateTarget (entry);
 
92
                                                ct.CopyFrom (target);
 
93
                                                targets.Add (ct);
 
94
                                                if (target == entry.DefaultDeployTarget)
 
95
                                                        defaultTarget = ct;
 
96
                                        }
 
97
                                }
 
98
                                
 
99
                                targetsTree.Selection.Changed += delegate (object s, EventArgs a) {
 
100
                                        UpdateButtons ();
 
101
                                };
 
102
                                
 
103
                                FillTargets ();
 
104
                                UpdateButtons ();
 
105
                        }
 
106
                        
 
107
                        void FillTargets ()
 
108
                        {
 
109
                                store.Clear ();
 
110
                                foreach (DeployTarget target in targets) {
 
111
                                        if (target is UnknownDeployTarget) {
 
112
                                                Gdk.Pixbuf pix = MonoDevelop.Core.Gui.Services.Resources.GetIcon ("md-package", Gtk.IconSize.Dialog);
 
113
                                                string desc = "<b>" + target.Name + "</b>\n<small>Unknown target</small>";
 
114
                                                store.AppendValues (pix, desc, target);
 
115
                                        } else {
 
116
                                                Gdk.Pixbuf pix = MonoDevelop.Core.Gui.Services.Resources.GetIcon (target.DeployHandler.Icon, Gtk.IconSize.Dialog);
 
117
                                                string desc = "<b>" + target.Name + "</b>";
 
118
                                                if (target == defaultTarget)
 
119
                                                        desc += " " + GettextCatalog.GetString ("(default target)");
 
120
                                                desc += "\n<small>" + target.DeployHandler.Description + "</small>";
 
121
                                                store.AppendValues (pix, desc, target);
 
122
                                        }
 
123
                                }
 
124
                        }
 
125
                        
 
126
                        void UpdateButtons ()
 
127
                        {
 
128
                                DeployTarget t = GetSelection ();
 
129
                                if (t != null) {
 
130
                                        buttonRemove.Sensitive = true;
 
131
                                        buttonEdit.Sensitive = !(t is UnknownDeployTarget) && DeployTargetEditor.HasEditor (t);
 
132
                                } else {
 
133
                                        buttonRemove.Sensitive = false;
 
134
                                        buttonEdit.Sensitive = false;
 
135
                                }
 
136
                        }
 
137
                        
 
138
                        protected void OnAddTarget (object s, EventArgs args)
 
139
                        {
 
140
                                using (AddDeployTargetDialog dlg = new AddDeployTargetDialog (entry)) {
 
141
                                        if (dlg.Run () == (int) Gtk.ResponseType.Ok) {
 
142
                                                targets.Add (dlg.NewTarget);
 
143
                                                if (targets.Count == 1)
 
144
                                                        defaultTarget = dlg.NewTarget;
 
145
                                                FillTargets ();
 
146
                                        }
 
147
                                }
 
148
                        }
 
149
 
 
150
                        protected void OnRemoveTarget (object s, EventArgs args)
 
151
                        {
 
152
                                DeployTarget t = GetSelection ();
 
153
                                if (t != null) {
 
154
                                        targets.Remove (t);
 
155
                                        FillTargets ();
 
156
                                }
 
157
                        }
 
158
 
 
159
                        protected void OnEditTarget (object s, EventArgs args)
 
160
                        {
 
161
                                DeployTarget t = GetSelection ();
 
162
                                if (t != null) {
 
163
                                        DeployTarget tc = t.DeployHandler.CreateTarget (entry);
 
164
                                        tc.CopyFrom (t);
 
165
                                        using (EditDeployTargetDialog dlg = new EditDeployTargetDialog (tc)) {
 
166
                                                if (dlg.Run () == (int) Gtk.ResponseType.Ok) {
 
167
                                                        targets [targets.IndexOf (t)] = tc;
 
168
                                                        FillTargets ();
 
169
                                                }
 
170
                                        }
 
171
                                }
 
172
                        }
 
173
                        
 
174
                        protected void OnSetDefault (object s, EventArgs args)
 
175
                        {
 
176
                                DeployTarget t = GetSelection ();
 
177
                                if (t != null) {
 
178
                                        defaultTarget = t;
 
179
                                        FillTargets ();
 
180
                                }
 
181
                        }
 
182
                        
 
183
                        DeployTarget GetSelection ()
 
184
                        {
 
185
                                Gtk.TreeModel model;
 
186
                                Gtk.TreeIter iter;
 
187
                                
 
188
                                if (targetsTree.Selection.GetSelected (out model, out iter)) {
 
189
                                        return (DeployTarget) store.GetValue (iter, 2);
 
190
                                } else
 
191
                                        return null;
 
192
                        }
 
193
 
 
194
                        public bool Store()
 
195
                        {
 
196
                                entry.DeployTargets.Clear ();
 
197
                                entry.DeployTargets.AddRange (targets);
 
198
                                entry.DefaultDeployTarget = defaultTarget;
 
199
                                return true;
 
200
                        }
 
201
                }
 
202
 
 
203
                public override void LoadPanelContents()
 
204
                {
 
205
                        try {
 
206
                                Add (widget = new DeploymentOptionsWidget ((IProperties) CustomizationObject));
 
207
                        } catch (Exception ex) {
 
208
                                Console.WriteLine (ex);
 
209
                        }
 
210
                }
 
211
 
 
212
                public override bool StorePanelContents ()
 
213
                {
 
214
                        bool success = widget.Store ();
 
215
                        return success;
 
216
                }                                       
 
217
        }
 
218
}