2
// ManageSitesDialog.cs
7
// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
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:
17
// The above copyright notice and this permission notice shall be
18
// included in all copies or substantial portions of the Software.
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.
33
using System.Threading;
35
using Mono.Addins.Setup;
38
namespace Mono.Addins.Gui
40
partial class ManageSitesDialog : Dialog
45
public ManageSitesDialog (Gtk.Window parent, SetupService service)
48
TransientFor = parent;
49
Services.PlaceDialog (this, parent);
50
this.service = service;
51
treeStore = new Gtk.ListStore (typeof (string), typeof (string), typeof(bool));
52
repoTree.Model = treeStore;
53
repoTree.HeadersVisible = false;
54
var crt = new Gtk.CellRendererToggle ();
55
crt.Toggled += HandleRepoToggled;
56
repoTree.AppendColumn ("", crt, "active", 2);
57
repoTree.AppendColumn ("", new Gtk.CellRendererText (), "markup", 1);
58
repoTree.Selection.Changed += new EventHandler(OnSelect);
60
AddinRepository[] reps = service.Repositories.GetRepositories ();
61
foreach (AddinRepository rep in reps)
62
AppendRepository (rep);
64
btnRemove.Sensitive = false;
67
public override void Dispose ()
73
void AppendRepository (AddinRepository rep)
75
string txt = GLib.Markup.EscapeText (rep.Title) + "\n<span color='darkgray'>" + GLib.Markup.EscapeText (rep.Url) + "</span>";
76
treeStore.AppendValues (rep.Url, txt, rep.Enabled);
79
protected void OnAdd (object sender, EventArgs e)
81
NewSiteDialog dlg = new NewSiteDialog (this);
85
if (!url.StartsWith ("http://") && !url.StartsWith ("https://") && !url.StartsWith ("file://")) {
86
url = "http://" + url;
92
Services.ShowError (null, "Invalid url: " + url, null, true);
95
if (!service.Repositories.ContainsRepository (url)) {
96
ProgressDialog pdlg = new ProgressDialog (this);
98
pdlg.SetMessage (AddinManager.CurrentLocalizer.GetString ("Registering repository"));
101
AddinRepository rr = null;
102
Exception error = null;
104
ThreadPool.QueueUserWorkItem (delegate {
106
rr = service.Repositories.RegisterRepository (pdlg, url, true);
107
} catch (System.Exception ex) {
115
if (Gtk.Application.EventsPending ())
116
Gtk.Application.RunIteration ();
125
service.Repositories.RemoveRepository (rr.Url);
130
Services.ShowError (error, "The repository could not be registered", null, true);
134
AppendRepository (rr);
142
protected void OnRemove (object sender, EventArgs e)
146
if (!repoTree.Selection.GetSelected (out foo, out iter))
149
string rep = (string) treeStore.GetValue (iter, 0);
150
service.Repositories.RemoveRepository (rep);
152
treeStore.Remove (ref iter);
155
void HandleRepoToggled (object o, ToggledArgs args)
158
if (!treeStore.GetIterFromString (out iter, args.Path))
161
bool newVal = !(bool) treeStore.GetValue (iter, 2);
162
string rep = (string) treeStore.GetValue (iter, 0);
163
service.Repositories.SetRepositoryEnabled (rep, newVal);
165
treeStore.SetValue (iter, 2, newVal);
168
protected void OnSelect(object sender, EventArgs e)
170
btnRemove.Sensitive = repoTree.Selection.CountSelectedRows() > 0;