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 	public static GType getType()
76 	{
77 		return g_filename_completer_get_type();
78 	}
79 
80 	/**
81 	 * Creates a new filename completer.
82 	 *
83 	 * Return: a #GFilenameCompleter.
84 	 *
85 	 * Throws: ConstructionException GTK+ fails to create the object.
86 	 */
87 	public this()
88 	{
89 		auto p = g_filename_completer_new();
90 		
91 		if(p is null)
92 		{
93 			throw new ConstructionException("null returned by new");
94 		}
95 		
96 		this(cast(GFilenameCompleter*) p, true);
97 	}
98 
99 	/**
100 	 * Obtains a completion for @initial_text from @completer.
101 	 *
102 	 * Params:
103 	 *     initialText = text to be completed.
104 	 *
105 	 * Return: a completed string, or %NULL if no completion exists.
106 	 *     This string is not owned by GIO, so remember to g_free() it
107 	 *     when finished.
108 	 */
109 	public string getCompletionSuffix(string initialText)
110 	{
111 		auto retStr = g_filename_completer_get_completion_suffix(gFilenameCompleter, Str.toStringz(initialText));
112 		
113 		scope(exit) Str.freeString(retStr);
114 		return Str.toString(retStr);
115 	}
116 
117 	/**
118 	 * Gets an array of completion strings for a given initial text.
119 	 *
120 	 * Params:
121 	 *     initialText = text to be completed.
122 	 *
123 	 * Return: array of strings with possible completions for @initial_text.
124 	 *     This array must be freed by g_strfreev() when finished.
125 	 */
126 	public string[] getCompletions(string initialText)
127 	{
128 		auto retStr = g_filename_completer_get_completions(gFilenameCompleter, Str.toStringz(initialText));
129 		
130 		scope(exit) Str.freeStringArray(retStr);
131 		return Str.toStringArray(retStr);
132 	}
133 
134 	/**
135 	 * If @dirs_only is %TRUE, @completer will only
136 	 * complete directory names, and not file names.
137 	 *
138 	 * Params:
139 	 *     dirsOnly = a #gboolean.
140 	 */
141 	public void setDirsOnly(bool dirsOnly)
142 	{
143 		g_filename_completer_set_dirs_only(gFilenameCompleter, dirsOnly);
144 	}
145 
146 	int[string] connectedSignals;
147 
148 	void delegate(FilenameCompleter)[] onGotCompletionDataListeners;
149 	/**
150 	 * Emitted when the file name completion information comes available.
151 	 */
152 	void addOnGotCompletionData(void delegate(FilenameCompleter) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
153 	{
154 		if ( "got-completion-data" !in connectedSignals )
155 		{
156 			Signals.connectData(
157 				this,
158 				"got-completion-data",
159 				cast(GCallback)&callBackGotCompletionData,
160 				cast(void*)this,
161 				null,
162 				connectFlags);
163 			connectedSignals["got-completion-data"] = 1;
164 		}
165 		onGotCompletionDataListeners ~= dlg;
166 	}
167 	extern(C) static void callBackGotCompletionData(GFilenameCompleter* filenamecompleterStruct, FilenameCompleter _filenamecompleter)
168 	{
169 		foreach ( void delegate(FilenameCompleter) dlg; _filenamecompleter.onGotCompletionDataListeners )
170 		{
171 			dlg(_filenamecompleter);
172 		}
173 	}
174 }