1 /*
2  * This file is part of d-dazzle.
3  *
4  * d-dazzle 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  * d-dazzle 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 d-dazzle; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 module dazzle.PathBar;
20 
21 private import dazzle.Path;
22 private import dazzle.PathElement;
23 private import dazzle.c.functions;
24 public  import dazzle.c.types;
25 private import gio.Menu;
26 private import glib.ConstructionException;
27 private import gobject.ObjectG;
28 private import gobject.Signals;
29 private import gtk.Box;
30 private import gtk.BuildableIF;
31 private import gtk.BuildableT;
32 private import gtk.OrientableIF;
33 private import gtk.OrientableT;
34 private import gtk.Widget;
35 private import std.algorithm;
36 
37 
38 /** */
39 public class PathBar : Box
40 {
41 	/** the main Gtk struct */
42 	protected DzlPathBar* dzlPathBar;
43 
44 	/** Get the main Gtk struct */
45 	public DzlPathBar* getPathBarStruct(bool transferOwnership = false)
46 	{
47 		if (transferOwnership)
48 			ownedRef = false;
49 		return dzlPathBar;
50 	}
51 
52 	/** the main Gtk struct as a void* */
53 	protected override void* getStruct()
54 	{
55 		return cast(void*)dzlPathBar;
56 	}
57 
58 	/**
59 	 * Sets our main struct and passes it to the parent class.
60 	 */
61 	public this (DzlPathBar* dzlPathBar, bool ownedRef = false)
62 	{
63 		this.dzlPathBar = dzlPathBar;
64 		super(cast(GtkBox*)dzlPathBar, ownedRef);
65 	}
66 
67 	alias getPath = Widget.getPath;
68 
69 	/**
70 	 * Gets the path for the view.
71 	 *
72 	 * Returns: A #DzlPath.
73 	 */
74 	public Path getPath()
75 	{
76 		auto p = dzl_path_bar_get_path(dzlPathBar);
77 
78 		if(p is null)
79 		{
80 			return null;
81 		}
82 
83 		return ObjectG.getDObject!(Path)(cast(DzlPath*) p);
84 	}
85 
86 	/**
87 	 */
88 
89 	/** */
90 	public static GType getType()
91 	{
92 		return dzl_path_bar_get_type();
93 	}
94 
95 	/** */
96 	public this()
97 	{
98 		auto p = dzl_path_bar_new();
99 
100 		if(p is null)
101 		{
102 			throw new ConstructionException("null returned by new");
103 		}
104 
105 		this(cast(DzlPathBar*) p);
106 	}
107 
108 	/** */
109 	public void setPath(Path path)
110 	{
111 		dzl_path_bar_set_path(dzlPathBar, (path is null) ? null : path.getPathStruct());
112 	}
113 
114 	/** */
115 	public void setSelectedIndex(uint index)
116 	{
117 		dzl_path_bar_set_selected_index(dzlPathBar, index);
118 	}
119 
120 	/** */
121 	gulong addOnElementSelected(void delegate(Path, PathElement, PathBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
122 	{
123 		return Signals.connect(this, "element-selected", dlg, connectFlags ^ ConnectFlags.SWAPPED);
124 	}
125 
126 	/** */
127 	gulong addOnPopulateMenu(void delegate(Path, PathElement, Menu, PathBar) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
128 	{
129 		return Signals.connect(this, "populate-menu", dlg, connectFlags ^ ConnectFlags.SWAPPED);
130 	}
131 }