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 private import std.algorithm; 35 36 37 /** 38 * Completes partial file and directory names given a partial string by 39 * looking in the file system for clues. Can return a list of possible 40 * completion strings for widget implementations. 41 */ 42 public class FilenameCompleter : ObjectG 43 { 44 /** the main Gtk struct */ 45 protected GFilenameCompleter* gFilenameCompleter; 46 47 /** Get the main Gtk struct */ 48 public GFilenameCompleter* getFilenameCompleterStruct() 49 { 50 return gFilenameCompleter; 51 } 52 53 /** the main Gtk struct as a void* */ 54 protected override void* getStruct() 55 { 56 return cast(void*)gFilenameCompleter; 57 } 58 59 protected override void setStruct(GObject* obj) 60 { 61 gFilenameCompleter = cast(GFilenameCompleter*)obj; 62 super.setStruct(obj); 63 } 64 65 /** 66 * Sets our main struct and passes it to the parent class. 67 */ 68 public this (GFilenameCompleter* gFilenameCompleter, bool ownedRef = false) 69 { 70 this.gFilenameCompleter = gFilenameCompleter; 71 super(cast(GObject*)gFilenameCompleter, ownedRef); 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 auto retStr = g_filename_completer_get_completion_suffix(gFilenameCompleter, Str.toStringz(initialText)); 113 114 scope(exit) Str.freeString(retStr); 115 return Str.toString(retStr); 116 } 117 118 /** 119 * Gets an array of completion strings for a given initial text. 120 * 121 * Params: 122 * initialText = text to be completed. 123 * 124 * Return: array of strings with possible completions for @initial_text. 125 * This array must be freed by g_strfreev() when finished. 126 */ 127 public string[] getCompletions(string initialText) 128 { 129 auto retStr = g_filename_completer_get_completions(gFilenameCompleter, Str.toStringz(initialText)); 130 131 scope(exit) Str.freeStringArray(retStr); 132 return Str.toStringArray(retStr); 133 } 134 135 /** 136 * If @dirs_only is %TRUE, @completer will only 137 * complete directory names, and not file names. 138 * 139 * Params: 140 * dirsOnly = a #gboolean. 141 */ 142 public void setDirsOnly(bool dirsOnly) 143 { 144 g_filename_completer_set_dirs_only(gFilenameCompleter, dirsOnly); 145 } 146 147 protected class OnGotCompletionDataDelegateWrapper 148 { 149 void delegate(FilenameCompleter) dlg; 150 gulong handlerId; 151 ConnectFlags flags; 152 this(void delegate(FilenameCompleter) dlg, gulong handlerId, ConnectFlags flags) 153 { 154 this.dlg = dlg; 155 this.handlerId = handlerId; 156 this.flags = flags; 157 } 158 } 159 protected OnGotCompletionDataDelegateWrapper[] onGotCompletionDataListeners; 160 161 /** 162 * Emitted when the file name completion information comes available. 163 */ 164 gulong addOnGotCompletionData(void delegate(FilenameCompleter) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 165 { 166 onGotCompletionDataListeners ~= new OnGotCompletionDataDelegateWrapper(dlg, 0, connectFlags); 167 onGotCompletionDataListeners[onGotCompletionDataListeners.length - 1].handlerId = Signals.connectData( 168 this, 169 "got-completion-data", 170 cast(GCallback)&callBackGotCompletionData, 171 cast(void*)onGotCompletionDataListeners[onGotCompletionDataListeners.length - 1], 172 cast(GClosureNotify)&callBackGotCompletionDataDestroy, 173 connectFlags); 174 return onGotCompletionDataListeners[onGotCompletionDataListeners.length - 1].handlerId; 175 } 176 177 extern(C) static void callBackGotCompletionData(GFilenameCompleter* filenamecompleterStruct,OnGotCompletionDataDelegateWrapper wrapper) 178 { 179 wrapper.dlg(wrapper.outer); 180 } 181 182 extern(C) static void callBackGotCompletionDataDestroy(OnGotCompletionDataDelegateWrapper wrapper, GClosure* closure) 183 { 184 wrapper.outer.internalRemoveOnGotCompletionData(wrapper); 185 } 186 187 protected void internalRemoveOnGotCompletionData(OnGotCompletionDataDelegateWrapper source) 188 { 189 foreach(index, wrapper; onGotCompletionDataListeners) 190 { 191 if (wrapper.dlg == source.dlg && wrapper.flags == source.flags && wrapper.handlerId == source.handlerId) 192 { 193 onGotCompletionDataListeners[index] = null; 194 onGotCompletionDataListeners = std.algorithm.remove(onGotCompletionDataListeners, index); 195 break; 196 } 197 } 198 } 199 200 }