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 gsv.SourceCompletionContext; 26 27 private import glib.ListG; 28 private import gobject.ObjectG; 29 private import gobject.Signals; 30 private import gsv.SourceCompletionProposalIF; 31 private import gsv.SourceCompletionProviderIF; 32 private import gsvc.gsv; 33 public import gsvc.gsvtypes; 34 private import gtk.TextIter; 35 private import std.algorithm; 36 37 38 /** */ 39 public class SourceCompletionContext : ObjectG 40 { 41 /** the main Gtk struct */ 42 protected GtkSourceCompletionContext* gtkSourceCompletionContext; 43 44 /** Get the main Gtk struct */ 45 public GtkSourceCompletionContext* getSourceCompletionContextStruct() 46 { 47 return gtkSourceCompletionContext; 48 } 49 50 /** the main Gtk struct as a void* */ 51 protected override void* getStruct() 52 { 53 return cast(void*)gtkSourceCompletionContext; 54 } 55 56 protected override void setStruct(GObject* obj) 57 { 58 gtkSourceCompletionContext = cast(GtkSourceCompletionContext*)obj; 59 super.setStruct(obj); 60 } 61 62 /** 63 * Sets our main struct and passes it to the parent class. 64 */ 65 public this (GtkSourceCompletionContext* gtkSourceCompletionContext, bool ownedRef = false) 66 { 67 this.gtkSourceCompletionContext = gtkSourceCompletionContext; 68 super(cast(GObject*)gtkSourceCompletionContext, ownedRef); 69 } 70 71 72 /** */ 73 public static GType getType() 74 { 75 return gtk_source_completion_context_get_type(); 76 } 77 78 /** 79 * Providers can use this function to add proposals to the completion. They 80 * can do so asynchronously by means of the @finished argument. Providers must 81 * ensure that they always call this function with @finished set to %TRUE 82 * once each population (even if no proposals need to be added). 83 * Population occurs when the gtk_source_completion_provider_populate() 84 * function is called. 85 * 86 * Params: 87 * provider = a #GtkSourceCompletionProvider. 88 * proposals = The list of proposals to add. 89 * finished = Whether the provider is finished adding proposals. 90 */ 91 public void addProposals(SourceCompletionProviderIF provider, ListG proposals, bool finished) 92 { 93 gtk_source_completion_context_add_proposals(gtkSourceCompletionContext, (provider is null) ? null : provider.getSourceCompletionProviderStruct(), (proposals is null) ? null : proposals.getListGStruct(), finished); 94 } 95 96 /** 97 * Get the context activation. 98 * 99 * Returns: The context activation. 100 */ 101 public GtkSourceCompletionActivation getActivation() 102 { 103 return gtk_source_completion_context_get_activation(gtkSourceCompletionContext); 104 } 105 106 /** 107 * Get the iter at which the completion was invoked. Providers can use this 108 * to determine how and if to match proposals. 109 * 110 * Params: 111 * iter = a #GtkTextIter. 112 * 113 * Returns: %TRUE if @iter is correctly set, %FALSE otherwise. 114 */ 115 public bool getIter(out TextIter iter) 116 { 117 GtkTextIter* outiter = gMalloc!GtkTextIter(); 118 119 auto p = gtk_source_completion_context_get_iter(gtkSourceCompletionContext, outiter) != 0; 120 121 iter = ObjectG.getDObject!(TextIter)(outiter, true); 122 123 return p; 124 } 125 126 protected class OnCancelledDelegateWrapper 127 { 128 static OnCancelledDelegateWrapper[] listeners; 129 void delegate(SourceCompletionContext) dlg; 130 gulong handlerId; 131 132 this(void delegate(SourceCompletionContext) dlg) 133 { 134 this.dlg = dlg; 135 this.listeners ~= this; 136 } 137 138 void remove(OnCancelledDelegateWrapper source) 139 { 140 foreach(index, wrapper; listeners) 141 { 142 if (wrapper.handlerId == source.handlerId) 143 { 144 listeners[index] = null; 145 listeners = std.algorithm.remove(listeners, index); 146 break; 147 } 148 } 149 } 150 } 151 152 /** 153 * Emitted when the current population of proposals has been cancelled. 154 * Providers adding proposals asynchronously should connect to this signal 155 * to know when to cancel running proposal queries. 156 */ 157 gulong addOnCancelled(void delegate(SourceCompletionContext) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 158 { 159 auto wrapper = new OnCancelledDelegateWrapper(dlg); 160 wrapper.handlerId = Signals.connectData( 161 this, 162 "cancelled", 163 cast(GCallback)&callBackCancelled, 164 cast(void*)wrapper, 165 cast(GClosureNotify)&callBackCancelledDestroy, 166 connectFlags); 167 return wrapper.handlerId; 168 } 169 170 extern(C) static void callBackCancelled(GtkSourceCompletionContext* sourcecompletioncontextStruct, OnCancelledDelegateWrapper wrapper) 171 { 172 wrapper.dlg(wrapper.outer); 173 } 174 175 extern(C) static void callBackCancelledDestroy(OnCancelledDelegateWrapper wrapper, GClosure* closure) 176 { 177 wrapper.remove(wrapper); 178 } 179 }