3
// Copyright (C) 2009 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/>.
20
using System.Collections.Generic;
27
public static class DockServices
29
static List<IDockService> services = new List<IDockService> ();
31
static IItemsService items_service;
32
static IDrawingService drawing_service;
33
static IDoInteropService do_interop_service;
34
static IPainterService painter_service;
35
static IDockletService docklet_service;
37
public static IDockletService DockletService {
39
if (docklet_service == null)
40
docklet_service = new Default.DockletService () as IDockletService;
41
return docklet_service;
45
public static IItemsService ItemsService {
47
if (items_service == null)
48
items_service = new Default.ItemsService () as IItemsService;
53
public static IDrawingService DrawingService {
55
if (drawing_service == null)
56
drawing_service = LoadService<IDrawingService, Default.DrawingService> ();
57
return drawing_service;
61
public static IDoInteropService DoInteropService {
63
if (do_interop_service == null)
64
do_interop_service = LoadService<IDoInteropService, Default.DoInteropService> ();
65
return do_interop_service;
69
public static IPainterService PainterService {
71
if (painter_service == null)
72
painter_service = LoadService<IPainterService, Default.PainterService> ();
73
return painter_service;
77
public static void Clean ()
79
if (items_service != null) {
80
items_service.Dispose ();
84
if (drawing_service != null) {
85
drawing_service.Dispose ();
86
drawing_service = null;
89
if (painter_service != null) {
90
painter_service.Dispose ();
91
painter_service = null;
94
if (docklet_service != null) {
95
docklet_service.Dispose ();
96
docklet_service = null;
99
if (do_interop_service != null) {
100
do_interop_service.Dispose ();
101
do_interop_service = null;
107
public static void RegisterService (IDockService service)
109
services.Add (service);
112
public static IDockService UnregisterService (IDockService service)
114
if (!services.Contains (service))
117
if (do_interop_service == service)
118
do_interop_service = null;
120
if (painter_service == service)
121
painter_service = null;
123
if (drawing_service == service)
124
drawing_service = null;
126
if (items_service == service)
127
items_service = null;
129
if (docklet_service == service)
130
docklet_service = null;
132
services.Remove (service);
137
static TService LoadService<TService, TElse> ()
138
where TService : class, IDockService
139
where TElse : TService
141
if (services.OfType<TService> ().Any ()) {
142
return services.OfType<TService> ().First () as TService;
144
return Activator.CreateInstance<TElse> () as TService;