3
// Copyright (C) 2008 GNOME Do
5
// This program is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21
using System.Collections.Generic;
27
namespace Do.Interface
30
public class InterfaceManager
33
public static void Initialize ()
35
if (!AddinManager.IsInitialized)
36
throw new Exception ("Addin manager was not initialized before initializing user interfaces");
37
AddinManager.AddExtensionNodeHandler ("/Do/InterfaceWindow", OnInterfaceChanged);
40
static void OnInterfaceChanged (object sender, ExtensionNodeEventArgs e)
42
TypeExtensionNode node = e.ExtensionNode as TypeExtensionNode;
43
InterfaceDescription desc = new InterfaceDescription (node);
45
case ExtensionChange.Add:
46
Log<InterfaceManager>.Debug ("\"{0}\" interface was loaded", desc.Name);
48
case ExtensionChange.Remove:
49
Log<InterfaceManager>.Debug ("\"{0}\" interface was unloaded", desc.Name);
54
public static IEnumerable<InterfaceDescription> GetInterfaceDescriptions ()
56
return AddinManager.GetExtensionNodes ("/Do/InterfaceWindow")
57
.Cast<TypeExtensionNode> ()
58
.Select (node => new InterfaceDescription (node));
61
public static IDoWindow MaybeGetInterfaceNamed (string name)
63
return GetInterfaceDescriptions ()
64
.Where (d => d.Name == name)
65
.Select (d => d.GetNewInstance ())