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