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 public  import gtkc.gdktypes;
38 private import peas.Engine;
39 private import peas.PluginInfo;
40 private import peasc.peas;
41 public  import peasc.peastypes;
42 private import std.algorithm;
43 
44 
45 /**
46  * The #PeasGtkPluginManagerView structure contains only private data
47  * and should only be accessed using the provided API.
48  */
49 public class PluginManagerView : TreeView
50 {
51 	/** the main Gtk struct */
52 	protected PeasGtkPluginManagerView* peasGtkPluginManagerView;
53 
54 	/** Get the main Gtk struct */
55 	public PeasGtkPluginManagerView* getPluginManagerViewStruct()
56 	{
57 		return peasGtkPluginManagerView;
58 	}
59 
60 	/** the main Gtk struct as a void* */
61 	protected override void* getStruct()
62 	{
63 		return cast(void*)peasGtkPluginManagerView;
64 	}
65 
66 	protected override void setStruct(GObject* obj)
67 	{
68 		peasGtkPluginManagerView = cast(PeasGtkPluginManagerView*)obj;
69 		super.setStruct(obj);
70 	}
71 
72 	/**
73 	 * Sets our main struct and passes it to the parent class.
74 	 */
75 	public this (PeasGtkPluginManagerView* peasGtkPluginManagerView, bool ownedRef = false)
76 	{
77 		this.peasGtkPluginManagerView = peasGtkPluginManagerView;
78 		super(cast(GtkTreeView*)peasGtkPluginManagerView, ownedRef);
79 	}
80 
81 
82 	/** */
83 	public static GType getType()
84 	{
85 		return peas_gtk_plugin_manager_view_get_type();
86 	}
87 
88 	/**
89 	 * Creates a new plugin manager view for the given #PeasEngine.
90 	 *
91 	 * If @engine is %NULL, then the default engine will be used.
92 	 *
93 	 * Params:
94 	 *     engine = A #PeasEngine, or %NULL.
95 	 *
96 	 * Return: the new #PeasGtkPluginManagerView.
97 	 *
98 	 * Throws: ConstructionException GTK+ fails to create the object.
99 	 */
100 	public this(Engine engine)
101 	{
102 		auto p = peas_gtk_plugin_manager_view_new((engine is null) ? null : engine.getEngineStruct());
103 		
104 		if(p is null)
105 		{
106 			throw new ConstructionException("null returned by new");
107 		}
108 		
109 		this(cast(PeasGtkPluginManagerView*) p);
110 	}
111 
112 	/**
113 	 * Returns the currently selected plugin, or %NULL if a plugin is not selected.
114 	 *
115 	 * Return: the selected plugin.
116 	 */
117 	public PluginInfo getSelectedPlugin()
118 	{
119 		auto p = peas_gtk_plugin_manager_view_get_selected_plugin(peasGtkPluginManagerView);
120 		
121 		if(p is null)
122 		{
123 			return null;
124 		}
125 		
126 		return ObjectG.getDObject!(PluginInfo)(cast(PeasPluginInfo*) p);
127 	}
128 
129 	/**
130 	 * Returns if builtin plugins should be shown.
131 	 *
132 	 * Deprecated: Use hidden plugins instead.
133 	 *
134 	 * Return: if builtin plugins should be shown.
135 	 */
136 	public bool getShowBuiltin()
137 	{
138 		return peas_gtk_plugin_manager_view_get_show_builtin(peasGtkPluginManagerView) != 0;
139 	}
140 
141 	/**
142 	 * Selects the given plugin.
143 	 *
144 	 * Params:
145 	 *     info = A #PeasPluginInfo.
146 	 */
147 	public void setSelectedPlugin(PluginInfo info)
148 	{
149 		peas_gtk_plugin_manager_view_set_selected_plugin(peasGtkPluginManagerView, (info is null) ? null : info.getPluginInfoStruct());
150 	}
151 
152 	/**
153 	 * Sets if builtin plugins should be shown.
154 	 *
155 	 * Deprecated: Use hidden plugins instead.
156 	 *
157 	 * Params:
158 	 *     showBuiltin = If builtin plugins should be shown.
159 	 */
160 	public void setShowBuiltin(bool showBuiltin)
161 	{
162 		peas_gtk_plugin_manager_view_set_show_builtin(peasGtkPluginManagerView, showBuiltin);
163 	}
164 
165 	protected class OnPopulatePopupDelegateWrapper
166 	{
167 		void delegate(Menu, PluginManagerView) dlg;
168 		gulong handlerId;
169 		ConnectFlags flags;
170 		this(void delegate(Menu, PluginManagerView) dlg, gulong handlerId, ConnectFlags flags)
171 		{
172 			this.dlg = dlg;
173 			this.handlerId = handlerId;
174 			this.flags = flags;
175 		}
176 	}
177 	protected OnPopulatePopupDelegateWrapper[] onPopulatePopupListeners;
178 
179 	/**
180 	 * The ::populate-popup signal is emitted before showing the context
181 	 * menu of the view. If you need to add items to the context menu,
182 	 * connect to this signal and add your menuitems to the @menu.
183 	 *
184 	 * Params:
185 	 *     menu = A #GtkMenu.
186 	 */
187 	gulong addOnPopulatePopup(void delegate(Menu, PluginManagerView) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
188 	{
189 		onPopulatePopupListeners ~= new OnPopulatePopupDelegateWrapper(dlg, 0, connectFlags);
190 		onPopulatePopupListeners[onPopulatePopupListeners.length - 1].handlerId = Signals.connectData(
191 			this,
192 			"populate-popup",
193 			cast(GCallback)&callBackPopulatePopup,
194 			cast(void*)onPopulatePopupListeners[onPopulatePopupListeners.length - 1],
195 			cast(GClosureNotify)&callBackPopulatePopupDestroy,
196 			connectFlags);
197 		return onPopulatePopupListeners[onPopulatePopupListeners.length - 1].handlerId;
198 	}
199 	
200 	extern(C) static void callBackPopulatePopup(PeasGtkPluginManagerView* pluginmanagerviewStruct, GtkMenu* menu,OnPopulatePopupDelegateWrapper wrapper)
201 	{
202 		wrapper.dlg(ObjectG.getDObject!(Menu)(menu), wrapper.outer);
203 	}
204 	
205 	extern(C) static void callBackPopulatePopupDestroy(OnPopulatePopupDelegateWrapper wrapper, GClosure* closure)
206 	{
207 		wrapper.outer.internalRemoveOnPopulatePopup(wrapper);
208 	}
209 
210 	protected void internalRemoveOnPopulatePopup(OnPopulatePopupDelegateWrapper source)
211 	{
212 		foreach(index, wrapper; onPopulatePopupListeners)
213 		{
214 			if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId)
215 			{
216 				onPopulatePopupListeners[index] = null;
217 				onPopulatePopupListeners = std.algorithm.remove(onPopulatePopupListeners, index);
218 				break;
219 			}
220 		}
221 	}
222 	
223 }