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 gio.FilenameCompleter;
26 
27 private import glib.ConstructionException;
28 private import glib.Str;
29 private import gobject.ObjectG;
30 private import gobject.Signals;
31 public  import gtkc.gdktypes;
32 private import gtkc.gio;
33 public  import gtkc.giotypes;
34 
35 
36 /**
37  * Completes partial file and directory names given a partial string by
38  * looking in the file system for clues. Can return a list of possible
39  * completion strings for widget implementations.
40  */
41 public class FilenameCompleter : ObjectG
42 {
43 	/** the main Gtk struct */
44 	protected GFilenameCompleter* gFilenameCompleter;
45 
46 	/** Get the main Gtk struct */
47 	public GFilenameCompleter* getFilenameCompleterStruct()
48 	{
49 		return gFilenameCompleter;
50 	}
51 
52 	/** the main Gtk struct as a void* */
53 	protected override void* getStruct()
54 	{
55 		return cast(void*)gFilenameCompleter;
56 	}
57 
58 	protected override void setStruct(GObject* obj)
59 	{
60 		gFilenameCompleter = cast(GFilenameCompleter*)obj;
61 		super.setStruct(obj);
62 	}
63 
64 	/**
65 	 * Sets our main struct and passes it to the parent class.
66 	 */
67 	public this (GFilenameCompleter* gFilenameCompleter, bool ownedRef = false)
68 	{
69 		this.gFilenameCompleter = gFilenameCompleter;
70 		super(cast(GObject*)gFilenameCompleter, ownedRef);
71 	}
72 
73 	/**
74 	 */
75 
76 	public static GType getType()
77 	{
78 		return g_filename_completer_get_type();
79 	}
80 
81 	/**
82 	 * Creates a new filename completer.
83 	 *
84 	 * Return: a #GFilenameCompleter.
85 	 *
86 	 * Throws: ConstructionException GTK+ fails to create the object.
87 	 */
88 	public this()
89 	{
90 		auto p = g_filename_completer_new();
91 		
92 		if(p is null)
93 		{
94 			throw new ConstructionException("null returned by new");
95 		}
96 		
97 		this(cast(GFilenameCompleter*) p, true);
98 	}
99 
100 	/**
101 	 * Obtains a completion for @initial_text from @completer.
102 	 *
103 	 * Params:
104 	 *     initialText = text to be completed.
105 	 *
106 	 * Return: a completed string, or %NULL if no completion exists.
107 	 *     This string is not owned by GIO, so remember to g_free() it
108 	 *     when finished.
109 	 */
110 	public string getCompletionSuffix(string initialText)
111 	{
112 		return Str.toString(g_filename_completer_get_completion_suffix(gFilenameCompleter, Str.toStringz(initialText)));
113 	}
114 
115 	/**
116 	 * Gets an array of completion strings for a given initial text.
117 	 *
118 	 * Params:
119 	 *     initialText = text to be completed.
120 	 *
121 	 * Return: array of strings with possible completions for @initial_text.
122 	 *     This array must be freed by g_strfreev() when finished.
123 	 */
124 	public string[] getCompletions(string initialText)
125 	{
126 		return Str.toStringArray(g_filename_completer_get_completions(gFilenameCompleter, Str.toStringz(initialText)));
127 	}
128 
129 	/**
130 	 * If @dirs_only is %TRUE, @completer will only
131 	 * complete directory names, and not file names.
132 	 *
133 	 * Params:
134 	 *     dirsOnly = a #gboolean.
135 	 */
136 	public void setDirsOnly(bool dirsOnly)
137 	{
138 		g_filename_completer_set_dirs_only(gFilenameCompleter, dirsOnly);
139 	}
140 
141 	int[string] connectedSignals;
142 
143 	void delegate(FilenameCompleter)[] onGotCompletionDataListeners;
144 	/**
145 	 * Emitted when the file name completion information comes available.
146 	 */
147 	void addOnGotCompletionData(void delegate(FilenameCompleter) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
148 	{
149 		if ( "got-completion-data" !in connectedSignals )
150 		{
151 			Signals.connectData(
152 				this,
153 				"got-completion-data",
154 				cast(GCallback)&callBackGotCompletionData,
155 				cast(void*)this,
156 				null,
157 				connectFlags);
158 			connectedSignals["got-completion-data"] = 1;
159 		}
160 		onGotCompletionDataListeners ~= dlg;
161 	}
162 	extern(C) static void callBackGotCompletionData(GFilenameCompleter* filenamecompleterStruct, FilenameCompleter _filenamecompleter)
163 	{
164 		foreach ( void delegate(FilenameCompleter) dlg; _filenamecompleter.onGotCompletionDataListeners )
165 		{
166 			dlg(_filenamecompleter);
167 		}
168 	}
169 }