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.SourceCompletionProposalT; 26 27 public import gdkpixbuf.Pixbuf; 28 public import gio.Icon; 29 public import gio.IconIF; 30 public import glib.Str; 31 public import gobject.ObjectG; 32 public import gobject.Signals; 33 public import gsvc.gsv; 34 public import gsvc.gsvtypes; 35 public import std.algorithm; 36 37 38 /** */ 39 public template SourceCompletionProposalT(TStruct) 40 { 41 /** Get the main Gtk struct */ 42 public GtkSourceCompletionProposal* getSourceCompletionProposalStruct() 43 { 44 return cast(GtkSourceCompletionProposal*)getStruct(); 45 } 46 47 48 /** 49 * Emits the "changed" signal on @proposal. This should be called by 50 * implementations whenever the name, icon or info of the proposal has 51 * changed. 52 */ 53 public void changed() 54 { 55 gtk_source_completion_proposal_changed(getSourceCompletionProposalStruct()); 56 } 57 58 /** 59 * Get whether two proposal objects are the same. This is used to (together 60 * with gtk_source_completion_proposal_hash()) to match proposals in the 61 * completion model. By default, it uses direct equality (g_direct_equal()). 62 * 63 * Params: 64 * other = a #GtkSourceCompletionProposal. 65 * 66 * Returns: %TRUE if @proposal and @object are the same proposal 67 */ 68 public bool equal(SourceCompletionProposalIF other) 69 { 70 return gtk_source_completion_proposal_equal(getSourceCompletionProposalStruct(), (other is null) ? null : other.getSourceCompletionProposalStruct()) != 0; 71 } 72 73 /** 74 * Gets the #GIcon for the icon of @proposal. 75 * 76 * Returns: A #GIcon with the icon of @proposal. 77 * 78 * Since: 3.18 79 */ 80 public IconIF getGicon() 81 { 82 auto p = gtk_source_completion_proposal_get_gicon(getSourceCompletionProposalStruct()); 83 84 if(p is null) 85 { 86 return null; 87 } 88 89 return ObjectG.getDObject!(Icon, IconIF)(cast(GIcon*) p); 90 } 91 92 /** 93 * Gets the #GdkPixbuf for the icon of @proposal. 94 * 95 * Returns: A #GdkPixbuf with the icon of @proposal. 96 */ 97 public Pixbuf getIcon() 98 { 99 auto p = gtk_source_completion_proposal_get_icon(getSourceCompletionProposalStruct()); 100 101 if(p is null) 102 { 103 return null; 104 } 105 106 return ObjectG.getDObject!(Pixbuf)(cast(GdkPixbuf*) p); 107 } 108 109 /** 110 * Gets the icon name of @proposal. 111 * 112 * Returns: The icon name of @proposal. 113 * 114 * Since: 3.18 115 */ 116 public string getIconName() 117 { 118 return Str.toString(gtk_source_completion_proposal_get_icon_name(getSourceCompletionProposalStruct())); 119 } 120 121 /** 122 * Gets extra information associated to the proposal. This information will be 123 * used to present the user with extra, detailed information about the 124 * selected proposal. The returned string must be freed with g_free(). 125 * 126 * Returns: a newly-allocated string containing 127 * extra information of @proposal or %NULL if no extra information is associated 128 * to @proposal. 129 */ 130 public string getInfo() 131 { 132 auto retStr = gtk_source_completion_proposal_get_info(getSourceCompletionProposalStruct()); 133 134 scope(exit) Str.freeString(retStr); 135 return Str.toString(retStr); 136 } 137 138 /** 139 * Gets the label of @proposal. The label is shown in the list of proposals as 140 * plain text. If you need any markup (such as bold or italic text), you have 141 * to implement gtk_source_completion_proposal_get_markup(). The returned string 142 * must be freed with g_free(). 143 * 144 * Returns: a new string containing the label of @proposal. 145 */ 146 public string getLabel() 147 { 148 auto retStr = gtk_source_completion_proposal_get_label(getSourceCompletionProposalStruct()); 149 150 scope(exit) Str.freeString(retStr); 151 return Str.toString(retStr); 152 } 153 154 /** 155 * Gets the label of @proposal with markup. The label is shown in the list of 156 * proposals and may contain markup. This will be used instead of 157 * gtk_source_completion_proposal_get_label() if implemented. The returned string 158 * must be freed with g_free(). 159 * 160 * Returns: a new string containing the label of @proposal with markup. 161 */ 162 public string getMarkup() 163 { 164 auto retStr = gtk_source_completion_proposal_get_markup(getSourceCompletionProposalStruct()); 165 166 scope(exit) Str.freeString(retStr); 167 return Str.toString(retStr); 168 } 169 170 /** 171 * Gets the text of @proposal. The text that is inserted into 172 * the text buffer when the proposal is activated by the default activation. 173 * You are free to implement a custom activation handler in the provider and 174 * not implement this function. For more information, see 175 * gtk_source_completion_provider_activate_proposal(). The returned string must 176 * be freed with g_free(). 177 * 178 * Returns: a new string containing the text of @proposal. 179 */ 180 public string getText() 181 { 182 auto retStr = gtk_source_completion_proposal_get_text(getSourceCompletionProposalStruct()); 183 184 scope(exit) Str.freeString(retStr); 185 return Str.toString(retStr); 186 } 187 188 /** 189 * Get the hash value of @proposal. This is used to (together with 190 * gtk_source_completion_proposal_equal()) to match proposals in the completion 191 * model. By default, it uses a direct hash (g_direct_hash()). 192 * 193 * Returns: The hash value of @proposal. 194 */ 195 public uint hash() 196 { 197 return gtk_source_completion_proposal_hash(getSourceCompletionProposalStruct()); 198 } 199 200 protected class OnChangedDelegateWrapper 201 { 202 static OnChangedDelegateWrapper[] listeners; 203 void delegate(SourceCompletionProposalIF) dlg; 204 gulong handlerId; 205 206 this(void delegate(SourceCompletionProposalIF) dlg) 207 { 208 this.dlg = dlg; 209 this.listeners ~= this; 210 } 211 212 void remove(OnChangedDelegateWrapper source) 213 { 214 foreach(index, wrapper; listeners) 215 { 216 if (wrapper.handlerId == source.handlerId) 217 { 218 listeners[index] = null; 219 listeners = std.algorithm.remove(listeners, index); 220 break; 221 } 222 } 223 } 224 } 225 226 /** 227 * Emitted when the proposal has changed. The completion popup 228 * will react to this by updating the shown information. 229 */ 230 gulong addOnChanged(void delegate(SourceCompletionProposalIF) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 231 { 232 auto wrapper = new OnChangedDelegateWrapper(dlg); 233 wrapper.handlerId = Signals.connectData( 234 this, 235 "changed", 236 cast(GCallback)&callBackChanged, 237 cast(void*)wrapper, 238 cast(GClosureNotify)&callBackChangedDestroy, 239 connectFlags); 240 return wrapper.handlerId; 241 } 242 243 extern(C) static void callBackChanged(GtkSourceCompletionProposal* sourcecompletionproposalStruct, OnChangedDelegateWrapper wrapper) 244 { 245 wrapper.dlg(wrapper.outer); 246 } 247 248 extern(C) static void callBackChangedDestroy(OnChangedDelegateWrapper wrapper, GClosure* closure) 249 { 250 wrapper.remove(wrapper); 251 } 252 }