~ubuntu-branches/ubuntu/karmic/mono-addins/karmic

« back to all changes in this revision

Viewing changes to Mono.Addins.Gui/Mono.Addins.Gui/AddinManagerDialog.cs

  • Committer: Bazaar Package Importer
  • Author(s): Mirco Bauer
  • Date: 2007-07-14 12:07:48 UTC
  • Revision ID: james.westby@ubuntu.com-20070714120748-2elczfsjlrdsrpms
Tags: upstream-0.2
ImportĀ upstreamĀ versionĀ 0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// AddinManagerDialog.cs
 
3
//
 
4
// Author:
 
5
//   Lluis Sanchez Gual
 
6
//
 
7
// Copyright (C) 2007 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 Gtk;
 
31
using Mono.Addins.Setup;
 
32
using Mono.Addins;
 
33
 
 
34
namespace Mono.Addins.Gui
 
35
{
 
36
        partial class AddinManagerDialog : Dialog, IDisposable
 
37
        {
 
38
                AddinTreeWidget tree;
 
39
                SetupService service = new SetupService ();
 
40
                
 
41
                public AddinManagerDialog (Window parent)
 
42
                {
 
43
                        Build ();
 
44
                        TransientFor = parent;
 
45
                        imageInstall.Stock = "md-software-update";
 
46
                        imageInstall.IconSize = (int)IconSize.Dialog;
 
47
 
 
48
                        tree = new AddinTreeWidget (addinTree);
 
49
                        LoadAddins ();
 
50
                        UpdateButtons ();
 
51
                }
 
52
                
 
53
                public override void Dispose ()
 
54
                {
 
55
                        base.Dispose ();
 
56
                        Destroy ();
 
57
                }
 
58
                
 
59
                internal void OnSelectionChanged (object sender, EventArgs args)
 
60
                {
 
61
                        UpdateButtons ();
 
62
                }
 
63
                
 
64
                internal void OnInstall (object sender, EventArgs e)
 
65
                {
 
66
                        AddinInstallDialog dlg = new AddinInstallDialog (service);
 
67
                        try {
 
68
                                dlg.Run ();
 
69
                                LoadAddins ();
 
70
                        } finally {
 
71
                                dlg.Destroy ();
 
72
                        }
 
73
                }
 
74
                
 
75
                internal void OnUpdate (object sender, EventArgs e)
 
76
                {
 
77
                }
 
78
                
 
79
                internal void OnUninstall (object sender, EventArgs e)
 
80
                {
 
81
                        AddinHeader info = (AddinHeader) tree.ActiveAddin;
 
82
                        AddinInstallDialog dlg = new AddinInstallDialog (service);
 
83
                        try {
 
84
                                dlg.SetUninstallMode (info);
 
85
                                dlg.Run ();
 
86
                                LoadAddins ();
 
87
                        } finally {
 
88
                                dlg.Destroy ();
 
89
                        }
 
90
                }
 
91
                
 
92
                internal void OnEnable (object sender, EventArgs e)
 
93
                {
 
94
                        try {
 
95
                                Addin sinfo = (Addin) tree.ActiveAddinData;
 
96
                                if (sinfo == null)
 
97
                                        return;
 
98
                                sinfo.Enabled = true;
 
99
                                LoadAddins ();
 
100
                        }
 
101
                        catch (Exception ex) {
 
102
                                Services.ShowError (ex, null, this, true);
 
103
                        }
 
104
                }
 
105
                
 
106
                internal void OnDisable (object sender, EventArgs e)
 
107
                {
 
108
                        try {
 
109
                                Addin sinfo = (Addin) tree.ActiveAddinData;
 
110
                                if (sinfo == null)
 
111
                                        return;
 
112
                                sinfo.Enabled = false;
 
113
                                LoadAddins ();
 
114
                        }
 
115
                        catch (Exception ex) {
 
116
                                Services.ShowError (ex, null, this, true);
 
117
                        }
 
118
                }
 
119
                
 
120
                internal void OnShowInfo (object sender, EventArgs e)
 
121
                {
 
122
                        Addin sinfo = (Addin) tree.ActiveAddinData;
 
123
                        if (sinfo == null)
 
124
                                return;
 
125
 
 
126
                        AddinInfoDialog dlg = new AddinInfoDialog (SetupService.GetAddinHeader (sinfo));
 
127
                        try {
 
128
                                dlg.Run ();
 
129
                        } finally {
 
130
                                dlg.Destroy ();
 
131
                        }
 
132
                }
 
133
                
 
134
                internal void OnManageRepos (object sender, EventArgs e)
 
135
                {
 
136
                        ManageSitesDialog dlg = new ManageSitesDialog (service);
 
137
                        try {
 
138
                                dlg.Run ();
 
139
                        } finally {
 
140
                                dlg.Destroy ();
 
141
                        }
 
142
                }
 
143
                
 
144
                void LoadAddins ()
 
145
                {
 
146
                        object s = tree.SaveStatus ();
 
147
                        
 
148
                        tree.Clear ();
 
149
                        foreach (Addin ainfo in AddinManager.Registry.GetAddins ()) {
 
150
                                if (Services.InApplicationNamespace (service, ainfo.Id))
 
151
                                        tree.AddAddin (SetupService.GetAddinHeader (ainfo), ainfo, ainfo.Enabled, ainfo.IsUserAddin);
 
152
                        }
 
153
                        
 
154
                        tree.RestoreStatus (s);
 
155
                        UpdateButtons ();
 
156
                }
 
157
                
 
158
                void UpdateButtons ()
 
159
                {
 
160
                        Addin sinfo = (Addin) tree.ActiveAddinData;
 
161
                        if (sinfo == null) {
 
162
                                btnEnable.Sensitive = false;
 
163
                                btnDisable.Sensitive = false;
 
164
                                btnUninstall.Sensitive = false;
 
165
                                btnInfo.Sensitive = false;
 
166
                        } else {
 
167
                                btnEnable.Sensitive = !sinfo.Enabled;
 
168
                                btnDisable.Sensitive = sinfo.Enabled;
 
169
                                btnUninstall.Sensitive = true;
 
170
                                btnInfo.Sensitive = true;
 
171
                        }
 
172
                }
 
173
        }
 
174
}