1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD 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 Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module peas.PluginManagerView;
26 
27 private import glib.ConstructionException;
28 private import gobject.ObjectG;
29 private import gobject.Signals;
30 private import gtk.BuildableIF;
31 private import gtk.BuildableT;
32 private import gtk.Menu;
33 private import gtk.ScrollableIF;
34 private import gtk.ScrollableT;
35 private import gtk.TreeView;
36 private import gtk.Widget;
37 private import peas.Engine;
38 private import peas.PluginInfo;
39 private import peas.c.functions;
40 public  import peas.c.types;
41 private import std.algorithm;
42 
43 
44 /**
45  * The #PeasGtkPluginManagerView structure contains only private data
46  * and should only be accessed using the provided API.
47  */
48 public class PluginManagerView : TreeView
49 {
50 	/** the main Gtk struct */
51 	protected PeasGtkPluginManagerView* peasGtkPluginManagerView;
52 
53 	/** Get the main Gtk struct */
54 	public PeasGtkPluginManagerView* getPluginManagerViewStruct(bool transferOwnership = false)
55 	{
56 		if (transferOwnership)
57 			ownedRef = false;
58 		return peasGtkPluginManagerView;
59 	}
60 
61 	/** the main Gtk struct as a void* */
62 	protected override void* getStruct()
63 	{
64 		return cast(void*)peasGtkPluginManagerView;
65 	}
66 
67 	protected override void setStruct(GObject* obj)
68 	{
69 		peasGtkPluginManagerView = cast(PeasGtkPluginManagerView*)obj;
70 		super.setStruct(obj);
71 	}
72 
73 	/**
74 	 * Sets our main struct and passes it to the parent class.
75 	 */
76 	public this (PeasGtkPluginManagerView* peasGtkPluginManagerView, bool ownedRef = false)
77 	{
78 		this.peasGtkPluginManagerView = peasGtkPluginManagerView;
79 		super(cast(GtkTreeView*)peasGtkPluginManagerView, ownedRef);
80 	}
81 
82 
83 	/** */
84 	public static GType getType()
85 	{
86 		return peas_gtk_plugin_manager_view_get_type();
87 	}
88 
89 	/**
90 	 * Creates a new plugin manager view for the given #PeasEngine.
91 	 *
92 	 * If @engine is %NULL, then the default engine will be used.
93 	 *
94 	 * Params:
95 	 *     engine = A #PeasEngine, or %NULL.
96 	 *
97 	 * Returns: the new #PeasGtkPluginManagerView.
98 	 *
99 	 * Throws: ConstructionException GTK+ fails to create the object.
100 	 */
101 	public this(Engine engine)
102 	{
103 		auto p = peas_gtk_plugin_manager_view_new((engine is null) ? null : engine.getEngineStruct());
104 
105 		if(p is null)
106 		{
107 			throw new ConstructionException("null returned by new");
108 		}
109 
110 		this(cast(PeasGtkPluginManagerView*) p);
111 	}
112 
113 	/**
114 	 * Returns the currently selected plugin, or %NULL if a plugin is not selected.
115 	 *
116 	 * Returns: the selected plugin.
117 	 */
118 	public PluginInfo getSelectedPlugin()
119 	{
120 		auto p = peas_gtk_plugin_manager_view_get_selected_plugin(peasGtkPluginManagerView);
121 
122 		if(p is null)
123 		{
124 			return null;
125 		}
126 
127 		return ObjectG.getDObject!(PluginInfo)(cast(PeasPluginInfo*) p);
128 	}
129 
130 	/**
131 	 * Returns if builtin plugins should be shown.
132 	 *
133 	 * Deprecated: Use hidden plugins instead.
134 	 *
135 	 * Returns: if builtin plugins should be shown.
136 	 */
137 	public bool getShowBuiltin()
138 	{
139 		return peas_gtk_plugin_manager_view_get_show_builtin(peasGtkPluginManagerView) != 0;
140 	}
141 
142 	/**
143 	 * Selects the given plugin.
144 	 *
145 	 * Params:
146 	 *     info = A #PeasPluginInfo.
147 	 */
148 	public void setSelectedPlugin(PluginInfo info)
149 	{
150 		peas_gtk_plugin_manager_view_set_selected_plugin(peasGtkPluginManagerView, (info is null) ? null : info.getPluginInfoStruct());
151 	}
152 
153 	/**
154 	 * Sets if builtin plugins should be shown.
155 	 *
156 	 * Deprecated: Use hidden plugins instead.
157 	 *
158 	 * Params:
159 	 *     showBuiltin = If builtin plugins should be shown.
160 	 */
161 	public void setShowBuiltin(bool showBuiltin)
162 	{
163 		peas_gtk_plugin_manager_view_set_show_builtin(peasGtkPluginManagerView, showBuiltin);
164 	}
165 
166 	protected class OnPopulatePopupDelegateWrapper
167 	{
168 		void delegate(Menu, PluginManagerView) dlg;
169 		gulong handlerId;
170 
171 		this(void delegate(Menu, PluginManagerView) dlg)
172 		{
173 			this.dlg = dlg;
174 			onPopulatePopupListeners ~= this;
175 		}
176 
177 		void remove(OnPopulatePopupDelegateWrapper source)
178 		{
179 			foreach(index, wrapper; onPopulatePopupListeners)
180 			{
181 				if (wrapper.handlerId == source.handlerId)
182 				{
183 					onPopulatePopupListeners[index] = null;
184 					onPopulatePopupListeners = std.algorithm.remove(onPopulatePopupListeners, index);
185 					break;
186 				}
187 			}
188 		}
189 	}
190 	OnPopulatePopupDelegateWrapper[] onPopulatePopupListeners;
191 
192 	/**
193 	 * The ::populate-popup signal is emitted before showing the context
194 	 * menu of the view. If you need to add items to the context menu,
195 	 * connect to this signal and add your menuitems to the @menu.
196 	 *
197 	 * Params:
198 	 *     menu = A #GtkMenu.
199 	 */
200 	gulong addOnPopulatePopup(void delegate(Menu, PluginManagerView) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
201 	{
202 		auto wrapper = new OnPopulatePopupDelegateWrapper(dlg);
203 		wrapper.handlerId = Signals.connectData(
204 			this,
205 			"populate-popup",
206 			cast(GCallback)&callBackPopulatePopup,
207 			cast(void*)wrapper,
208 			cast(GClosureNotify)&callBackPopulatePopupDestroy,
209 			connectFlags);
210 		return wrapper.handlerId;
211 	}
212 
213 	extern(C) static void callBackPopulatePopup(PeasGtkPluginManagerView* pluginmanagerviewStruct, GtkMenu* menu, OnPopulatePopupDelegateWrapper wrapper)
214 	{
215 		wrapper.dlg(ObjectG.getDObject!(Menu)(menu), wrapper.outer);
216 	}
217 
218 	extern(C) static void callBackPopulatePopupDestroy(OnPopulatePopupDelegateWrapper wrapper, GClosure* closure)
219 	{
220 		wrapper.remove(wrapper);
221 	}
222 }