source: appstream-generator/build/girepo/gio/FilenameCompleter.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 5.0 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module gio.FilenameCompleter;
22
23private import gi.gio;
24public  import gi.giotypes;
25private import glib.ConstructionException;
26private import glib.Str;
27private import gobject.ObjectG;
28private import gobject.Signals;
29private import std.algorithm;
30
31
32/**
33 * Completes partial file and directory names given a partial string by
34 * looking in the file system for clues. Can return a list of possible
35 * completion strings for widget implementations.
36 */
37public class FilenameCompleter : ObjectG
38{
39        /** the main Gtk struct */
40        protected GFilenameCompleter* gFilenameCompleter;
41
42        /** Get the main Gtk struct */
43        public GFilenameCompleter* getFilenameCompleterStruct()
44        {
45                return gFilenameCompleter;
46        }
47
48        /** the main Gtk struct as a void* */
49        protected override void* getStruct()
50        {
51                return cast(void*)gFilenameCompleter;
52        }
53
54        protected override void setStruct(GObject* obj)
55        {
56                gFilenameCompleter = cast(GFilenameCompleter*)obj;
57                super.setStruct(obj);
58        }
59
60        /**
61         * Sets our main struct and passes it to the parent class.
62         */
63        public this (GFilenameCompleter* gFilenameCompleter, bool ownedRef = false)
64        {
65                this.gFilenameCompleter = gFilenameCompleter;
66                super(cast(GObject*)gFilenameCompleter, ownedRef);
67        }
68
69
70        /** */
71        public static GType getType()
72        {
73                return g_filename_completer_get_type();
74        }
75
76        /**
77         * Creates a new filename completer.
78         *
79         * Returns: a #GFilenameCompleter.
80         *
81         * Throws: ConstructionException GTK+ fails to create the object.
82         */
83        public this()
84        {
85                auto p = g_filename_completer_new();
86               
87                if(p is null)
88                {
89                        throw new ConstructionException("null returned by new");
90                }
91               
92                this(cast(GFilenameCompleter*) p, true);
93        }
94
95        /**
96         * Obtains a completion for @initial_text from @completer.
97         *
98         * Params:
99         *     initialText = text to be completed.
100         *
101         * Returns: a completed string, or %NULL if no completion exists.
102         *     This string is not owned by GIO, so remember to g_free() it
103         *     when finished.
104         */
105        public string getCompletionSuffix(string initialText)
106        {
107                auto retStr = g_filename_completer_get_completion_suffix(gFilenameCompleter, Str.toStringz(initialText));
108               
109                scope(exit) Str.freeString(retStr);
110                return Str.toString(retStr);
111        }
112
113        /**
114         * Gets an array of completion strings for a given initial text.
115         *
116         * Params:
117         *     initialText = text to be completed.
118         *
119         * Returns: array of strings with possible completions for @initial_text.
120         *     This array must be freed by g_strfreev() when finished.
121         */
122        public string[] getCompletions(string initialText)
123        {
124                auto retStr = g_filename_completer_get_completions(gFilenameCompleter, Str.toStringz(initialText));
125               
126                scope(exit) Str.freeStringArray(retStr);
127                return Str.toStringArray(retStr);
128        }
129
130        /**
131         * If @dirs_only is %TRUE, @completer will only
132         * complete directory names, and not file names.
133         *
134         * Params:
135         *     dirsOnly = a #gboolean.
136         */
137        public void setDirsOnly(bool dirsOnly)
138        {
139                g_filename_completer_set_dirs_only(gFilenameCompleter, dirsOnly);
140        }
141
142        protected class OnGotCompletionDataDelegateWrapper
143        {
144                static OnGotCompletionDataDelegateWrapper[] listeners;
145                void delegate(FilenameCompleter) dlg;
146                gulong handlerId;
147               
148                this(void delegate(FilenameCompleter) dlg)
149                {
150                        this.dlg = dlg;
151                        this.listeners ~= this;
152                }
153               
154                void remove(OnGotCompletionDataDelegateWrapper source)
155                {
156                        foreach(index, wrapper; listeners)
157                        {
158                                if (wrapper.handlerId == source.handlerId)
159                                {
160                                        listeners[index] = null;
161                                        listeners = std.algorithm.remove(listeners, index);
162                                        break;
163                                }
164                        }
165                }
166        }
167
168        /**
169         * Emitted when the file name completion information comes available.
170         */
171        gulong addOnGotCompletionData(void delegate(FilenameCompleter) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
172        {
173                auto wrapper = new OnGotCompletionDataDelegateWrapper(dlg);
174                wrapper.handlerId = Signals.connectData(
175                        this,
176                        "got-completion-data",
177                        cast(GCallback)&callBackGotCompletionData,
178                        cast(void*)wrapper,
179                        cast(GClosureNotify)&callBackGotCompletionDataDestroy,
180                        connectFlags);
181                return wrapper.handlerId;
182        }
183       
184        extern(C) static void callBackGotCompletionData(GFilenameCompleter* filenamecompleterStruct, OnGotCompletionDataDelegateWrapper wrapper)
185        {
186                wrapper.dlg(wrapper.outer);
187        }
188       
189        extern(C) static void callBackGotCompletionDataDestroy(OnGotCompletionDataDelegateWrapper wrapper, GClosure* closure)
190        {
191                wrapper.remove(wrapper);
192        }
193}
Note: See TracBrowser for help on using the repository browser.