1 module webkit2webextension.ContextMenuItem;
2 
3 private import gio.ActionIF;
4 private import glib.ConstructionException;
5 private import glib.Str;
6 private import glib.Variant;
7 private import gobject.ObjectG;
8 private import gtk.Action;
9 private import webkit2webextension.ContextMenu;
10 private import webkit2webextension.c.functions;
11 public  import webkit2webextension.c.types;
12 
13 
14 /**
15  * The #WebKitContextMenu is composed of #WebKitContextMenuItem<!--
16  * -->s. These items can be created from a #GtkAction, from a
17  * #WebKitContextMenuAction or from a #WebKitContextMenuAction and a
18  * label. These #WebKitContextMenuAction<!-- -->s denote stock actions
19  * for the items. You can also create separators and submenus.
20  */
21 public class ContextMenuItem : ObjectG
22 {
23 	/** the main Gtk struct */
24 	protected WebKitContextMenuItem* webKitContextMenuItem;
25 
26 	/** Get the main Gtk struct */
27 	public WebKitContextMenuItem* getContextMenuItemStruct(bool transferOwnership = false)
28 	{
29 		if (transferOwnership)
30 			ownedRef = false;
31 		return webKitContextMenuItem;
32 	}
33 
34 	/** the main Gtk struct as a void* */
35 	protected override void* getStruct()
36 	{
37 		return cast(void*)webKitContextMenuItem;
38 	}
39 
40 	/**
41 	 * Sets our main struct and passes it to the parent class.
42 	 */
43 	public this (WebKitContextMenuItem* webKitContextMenuItem, bool ownedRef = false)
44 	{
45 		this.webKitContextMenuItem = webKitContextMenuItem;
46 		super(cast(GObject*)webKitContextMenuItem, ownedRef);
47 	}
48 
49 
50 	/** */
51 	public static GType getType()
52 	{
53 		return webkit_context_menu_item_get_type();
54 	}
55 
56 	/**
57 	 * Creates a new #WebKitContextMenuItem for the given @action.
58 	 *
59 	 * Deprecated: Use webkit_context_menu_item_new_from_gaction() instead.
60 	 *
61 	 * Params:
62 	 *     action = a #GtkAction
63 	 *
64 	 * Returns: the newly created #WebKitContextMenuItem object.
65 	 *
66 	 * Throws: ConstructionException GTK+ fails to create the object.
67 	 */
68 	public this(Action action)
69 	{
70 		auto __p = webkit_context_menu_item_new((action is null) ? null : action.getActionStruct());
71 
72 		if(__p is null)
73 		{
74 			throw new ConstructionException("null returned by new");
75 		}
76 
77 		this(cast(WebKitContextMenuItem*) __p);
78 	}
79 
80 	/**
81 	 * Creates a new #WebKitContextMenuItem for the given @action and @label. On activation
82 	 * @target will be passed as parameter to the callback.
83 	 *
84 	 * Params:
85 	 *     action = a #GAction
86 	 *     label = the menu item label text
87 	 *     target = a #GVariant to use as the action target
88 	 *
89 	 * Returns: the newly created #WebKitContextMenuItem object.
90 	 *
91 	 * Since: 2.18
92 	 *
93 	 * Throws: ConstructionException GTK+ fails to create the object.
94 	 */
95 	public this(ActionIF action, string label, Variant target)
96 	{
97 		auto __p = webkit_context_menu_item_new_from_gaction((action is null) ? null : action.getActionStruct(), Str.toStringz(label), (target is null) ? null : target.getVariantStruct());
98 
99 		if(__p is null)
100 		{
101 			throw new ConstructionException("null returned by new_from_gaction");
102 		}
103 
104 		this(cast(WebKitContextMenuItem*) __p);
105 	}
106 
107 	/**
108 	 * Creates a new #WebKitContextMenuItem for the given stock action.
109 	 * Stock actions are handled automatically by WebKit so that, for example,
110 	 * when a menu item created with a %WEBKIT_CONTEXT_MENU_ACTION_STOP is
111 	 * activated the action associated will be handled by WebKit and the current
112 	 * load operation will be stopped. You can get the #GAction of a
113 	 * #WebKitContextMenuItem created with a #WebKitContextMenuAction with
114 	 * webkit_context_menu_item_get_gaction() and connect to the #GSimpleAction::activate signal
115 	 * to be notified when the item is activated, but you can't prevent the associated
116 	 * action from being performed.
117 	 *
118 	 * Params:
119 	 *     action = a #WebKitContextMenuAction stock action
120 	 *
121 	 * Returns: the newly created #WebKitContextMenuItem object.
122 	 *
123 	 * Throws: ConstructionException GTK+ fails to create the object.
124 	 */
125 	public this(WebKitContextMenuAction action)
126 	{
127 		auto __p = webkit_context_menu_item_new_from_stock_action(action);
128 
129 		if(__p is null)
130 		{
131 			throw new ConstructionException("null returned by new_from_stock_action");
132 		}
133 
134 		this(cast(WebKitContextMenuItem*) __p);
135 	}
136 
137 	/**
138 	 * Creates a new #WebKitContextMenuItem for the given stock action using the given @label.
139 	 * Stock actions have a predefined label, this method can be used to create a
140 	 * #WebKitContextMenuItem for a #WebKitContextMenuAction but using a custom label.
141 	 *
142 	 * Params:
143 	 *     action = a #WebKitContextMenuAction stock action
144 	 *     label = a custom label text to use instead of the predefined one
145 	 *
146 	 * Returns: the newly created #WebKitContextMenuItem object.
147 	 *
148 	 * Throws: ConstructionException GTK+ fails to create the object.
149 	 */
150 	public this(WebKitContextMenuAction action, string label)
151 	{
152 		auto __p = webkit_context_menu_item_new_from_stock_action_with_label(action, Str.toStringz(label));
153 
154 		if(__p is null)
155 		{
156 			throw new ConstructionException("null returned by new_from_stock_action_with_label");
157 		}
158 
159 		this(cast(WebKitContextMenuItem*) __p);
160 	}
161 
162 	/**
163 	 * Creates a new #WebKitContextMenuItem representing a separator.
164 	 *
165 	 * Returns: the newly created #WebKitContextMenuItem object.
166 	 *
167 	 * Throws: ConstructionException GTK+ fails to create the object.
168 	 */
169 	public this()
170 	{
171 		auto __p = webkit_context_menu_item_new_separator();
172 
173 		if(__p is null)
174 		{
175 			throw new ConstructionException("null returned by new_separator");
176 		}
177 
178 		this(cast(WebKitContextMenuItem*) __p);
179 	}
180 
181 	/**
182 	 * Creates a new #WebKitContextMenuItem using the given @label with a submenu.
183 	 *
184 	 * Params:
185 	 *     label = the menu item label text
186 	 *     submenu = a #WebKitContextMenu to set
187 	 *
188 	 * Returns: the newly created #WebKitContextMenuItem object.
189 	 *
190 	 * Throws: ConstructionException GTK+ fails to create the object.
191 	 */
192 	public this(string label, ContextMenu submenu)
193 	{
194 		auto __p = webkit_context_menu_item_new_with_submenu(Str.toStringz(label), (submenu is null) ? null : submenu.getContextMenuStruct());
195 
196 		if(__p is null)
197 		{
198 			throw new ConstructionException("null returned by new_with_submenu");
199 		}
200 
201 		this(cast(WebKitContextMenuItem*) __p);
202 	}
203 
204 	/**
205 	 * Gets the action associated to @item as a #GtkAction.
206 	 *
207 	 * Deprecated: Use webkit_context_menu_item_get_gaction() instead.
208 	 *
209 	 * Returns: the #GtkAction associated to the #WebKitContextMenuItem,
210 	 *     or %NULL if @item is a separator.
211 	 */
212 	public Action getAction()
213 	{
214 		auto __p = webkit_context_menu_item_get_action(webKitContextMenuItem);
215 
216 		if(__p is null)
217 		{
218 			return null;
219 		}
220 
221 		return ObjectG.getDObject!(Action)(cast(GtkAction*) __p);
222 	}
223 
224 	/**
225 	 * Gets the action associated to @item as a #GAction.
226 	 *
227 	 * Returns: the #GAction associated to the #WebKitContextMenuItem,
228 	 *     or %NULL if @item is a separator.
229 	 *
230 	 * Since: 2.18
231 	 */
232 	public ActionIF getGaction()
233 	{
234 		auto __p = webkit_context_menu_item_get_gaction(webKitContextMenuItem);
235 
236 		if(__p is null)
237 		{
238 			return null;
239 		}
240 
241 		return ObjectG.getDObject!(ActionIF)(cast(GAction*) __p);
242 	}
243 
244 	/**
245 	 * Gets the #WebKitContextMenuAction of @item. If the #WebKitContextMenuItem was not
246 	 * created for a stock action %WEBKIT_CONTEXT_MENU_ACTION_CUSTOM will be
247 	 * returned. If the #WebKitContextMenuItem is a separator %WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION
248 	 * will be returned.
249 	 *
250 	 * Returns: the #WebKitContextMenuAction of @item
251 	 */
252 	public WebKitContextMenuAction getStockAction()
253 	{
254 		return webkit_context_menu_item_get_stock_action(webKitContextMenuItem);
255 	}
256 
257 	/**
258 	 * Gets the submenu of @item.
259 	 *
260 	 * Returns: the #WebKitContextMenu representing the submenu of
261 	 *     @item or %NULL if @item doesn't have a submenu.
262 	 */
263 	public ContextMenu getSubmenu()
264 	{
265 		auto __p = webkit_context_menu_item_get_submenu(webKitContextMenuItem);
266 
267 		if(__p is null)
268 		{
269 			return null;
270 		}
271 
272 		return ObjectG.getDObject!(ContextMenu)(cast(WebKitContextMenu*) __p);
273 	}
274 
275 	/**
276 	 * Checks whether @item is a separator.
277 	 *
278 	 * Returns: %TRUE is @item is a separator or %FALSE otherwise
279 	 */
280 	public bool isSeparator()
281 	{
282 		return webkit_context_menu_item_is_separator(webKitContextMenuItem) != 0;
283 	}
284 
285 	/**
286 	 * Sets or replaces the @item submenu. If @submenu is %NULL the current
287 	 * submenu of @item is removed.
288 	 *
289 	 * Params:
290 	 *     submenu = a #WebKitContextMenu
291 	 */
292 	public void setSubmenu(ContextMenu submenu)
293 	{
294 		webkit_context_menu_item_set_submenu(webKitContextMenuItem, (submenu is null) ? null : submenu.getContextMenuStruct());
295 	}
296 }