~do-win/do/test-paths

« back to all changes in this revision

Viewing changes to Do.Interface.Windows/src/Do.Interface/InterfaceManager.cs

  • Committer: Hardeep S
  • Date: 2009-06-23 03:53:12 UTC
  • Revision ID: ootz0rz@gmail.com-20090623035312-it8tb5wkha6nf31p
Added Do.Interface.Windows, and a bunch of cleanup with old MonoDevelop files elsewhere

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// InterfaceManager.cs
 
2
// 
 
3
// Copyright (C) 2008 GNOME Do
 
4
//
 
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.
 
9
//
 
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.
 
14
//
 
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/>.
 
17
//
 
18
 
 
19
using System;
 
20
using System.Linq;
 
21
using System.Collections.Generic;
 
22
 
 
23
using Mono.Addins;
 
24
 
 
25
using Do.Platform;
 
26
 
 
27
namespace Do.Interface
 
28
{
 
29
        
 
30
        public class InterfaceManager
 
31
        {
 
32
 
 
33
                public static void Initialize ()
 
34
                {
 
35
                        if (!AddinManager.IsInitialized)
 
36
                                throw new Exception ("Addin manager was not initialized before initializing user interfaces");
 
37
                        AddinManager.AddExtensionNodeHandler ("/Do/InterfaceWindow", OnInterfaceChanged);
 
38
                }
 
39
                
 
40
                static void OnInterfaceChanged (object sender, ExtensionNodeEventArgs e)
 
41
                {
 
42
                        TypeExtensionNode node = e.ExtensionNode as TypeExtensionNode;
 
43
                        InterfaceDescription desc = new InterfaceDescription (node);
 
44
                        switch (e.Change) {
 
45
                        case ExtensionChange.Add:
 
46
                                Log<InterfaceManager>.Debug ("\"{0}\" interface was loaded", desc.Name);
 
47
                                break;
 
48
                        case ExtensionChange.Remove:
 
49
                                Log<InterfaceManager>.Debug ("\"{0}\" interface was unloaded", desc.Name);
 
50
                                break;
 
51
                        }
 
52
                }
 
53
                
 
54
                public static IEnumerable<InterfaceDescription> GetInterfaceDescriptions ()
 
55
                {
 
56
                        return AddinManager.GetExtensionNodes ("/Do/InterfaceWindow")
 
57
                                .Cast<TypeExtensionNode> ()
 
58
                                .Select (node => new InterfaceDescription (node));
 
59
                }
 
60
 
 
61
                public static IDoWindow MaybeGetInterfaceNamed (string name)
 
62
                {
 
63
                        return GetInterfaceDescriptions ()
 
64
                                .Where (d => d.Name == name)
 
65
                                .Select (d => d.GetNewInstance ())
 
66
                                .FirstOrDefault ();
 
67
                }
 
68
        }
 
69
}