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.SourceCompletion; 26 27 private import glib.ErrorG; 28 private import glib.GException; 29 private import glib.ListG; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 private import gsv.SourceCompletionContext; 33 private import gsv.SourceCompletionInfo; 34 private import gsv.SourceCompletionProviderIF; 35 private import gsv.SourceView; 36 private import gsv.c.functions; 37 public import gsv.c.types; 38 public import gsvc.gsvtypes; 39 private import gtk.BuildableIF; 40 private import gtk.BuildableT; 41 private import gtk.TextIter; 42 private import std.algorithm; 43 44 45 /** */ 46 public class SourceCompletion : ObjectG, BuildableIF 47 { 48 /** the main Gtk struct */ 49 protected GtkSourceCompletion* gtkSourceCompletion; 50 51 /** Get the main Gtk struct */ 52 public GtkSourceCompletion* getSourceCompletionStruct(bool transferOwnership = false) 53 { 54 if (transferOwnership) 55 ownedRef = false; 56 return gtkSourceCompletion; 57 } 58 59 /** the main Gtk struct as a void* */ 60 protected override void* getStruct() 61 { 62 return cast(void*)gtkSourceCompletion; 63 } 64 65 /** 66 * Sets our main struct and passes it to the parent class. 67 */ 68 public this (GtkSourceCompletion* gtkSourceCompletion, bool ownedRef = false) 69 { 70 this.gtkSourceCompletion = gtkSourceCompletion; 71 super(cast(GObject*)gtkSourceCompletion, ownedRef); 72 } 73 74 // add the Buildable capabilities 75 mixin BuildableT!(GtkSourceCompletion); 76 77 78 /** */ 79 public static GType getType() 80 { 81 return gtk_source_completion_get_type(); 82 } 83 84 /** 85 * Add a new #GtkSourceCompletionProvider to the completion object. This will 86 * add a reference @provider, so make sure to unref your own copy when you 87 * no longer need it. 88 * 89 * Params: 90 * provider = a #GtkSourceCompletionProvider. 91 * 92 * Returns: %TRUE if @provider was successfully added, otherwise if @error 93 * is provided, it will be set with the error and %FALSE is returned. 94 * 95 * Throws: GException on failure. 96 */ 97 public bool addProvider(SourceCompletionProviderIF provider) 98 { 99 GError* err = null; 100 101 auto p = gtk_source_completion_add_provider(gtkSourceCompletion, (provider is null) ? null : provider.getSourceCompletionProviderStruct(), &err) != 0; 102 103 if (err !is null) 104 { 105 throw new GException( new ErrorG(err) ); 106 } 107 108 return p; 109 } 110 111 /** 112 * Block interactive completion. This can be used to disable interactive 113 * completion when inserting or deleting text from the buffer associated with 114 * the completion. Use gtk_source_completion_unblock_interactive() to enable 115 * interactive completion again. 116 * 117 * This function may be called multiple times. It will continue to block 118 * interactive completion until gtk_source_completion_unblock_interactive() 119 * has been called the same number of times. 120 */ 121 public void blockInteractive() 122 { 123 gtk_source_completion_block_interactive(gtkSourceCompletion); 124 } 125 126 /** 127 * Create a new #GtkSourceCompletionContext for @completion. The position where 128 * the completion occurs can be specified by @position. If @position is %NULL, 129 * the current cursor position will be used. 130 * 131 * Params: 132 * position = a #GtkTextIter, or %NULL. 133 * 134 * Returns: a new #GtkSourceCompletionContext. 135 * The reference being returned is a 'floating' reference, 136 * so if you invoke gtk_source_completion_show() with this context 137 * you don't need to unref it. 138 */ 139 public SourceCompletionContext createContext(TextIter position) 140 { 141 auto p = gtk_source_completion_create_context(gtkSourceCompletion, (position is null) ? null : position.getTextIterStruct()); 142 143 if(p is null) 144 { 145 return null; 146 } 147 148 return ObjectG.getDObject!(SourceCompletionContext)(cast(GtkSourceCompletionContext*) p); 149 } 150 151 /** 152 * The info widget is the window where the completion displays optional extra 153 * information of the proposal. 154 * 155 * Returns: The #GtkSourceCompletionInfo window 156 * associated with @completion. 157 */ 158 public SourceCompletionInfo getInfoWindow() 159 { 160 auto p = gtk_source_completion_get_info_window(gtkSourceCompletion); 161 162 if(p is null) 163 { 164 return null; 165 } 166 167 return ObjectG.getDObject!(SourceCompletionInfo)(cast(GtkSourceCompletionInfo*) p); 168 } 169 170 /** 171 * Get list of providers registered on @completion. The returned list is owned 172 * by the completion and should not be freed. 173 * 174 * Returns: list of #GtkSourceCompletionProvider. 175 */ 176 public ListG getProviders() 177 { 178 auto p = gtk_source_completion_get_providers(gtkSourceCompletion); 179 180 if(p is null) 181 { 182 return null; 183 } 184 185 return new ListG(cast(GList*) p); 186 } 187 188 /** 189 * The #GtkSourceView associated with @completion, or %NULL if the view has been 190 * destroyed. 191 * 192 * Returns: The #GtkSourceView associated with 193 * @completion, or %NULL. 194 */ 195 public SourceView getView() 196 { 197 auto p = gtk_source_completion_get_view(gtkSourceCompletion); 198 199 if(p is null) 200 { 201 return null; 202 } 203 204 return ObjectG.getDObject!(SourceView)(cast(GtkSourceView*) p); 205 } 206 207 /** 208 * Hides the completion if it is active (visible). 209 */ 210 public void hide() 211 { 212 gtk_source_completion_hide(gtkSourceCompletion); 213 } 214 215 /** 216 * Move the completion window to a specific iter. 217 * 218 * Deprecated: Use gtk_source_completion_provider_get_start_iter() instead. 219 * 220 * Params: 221 * iter = a #GtkTextIter. 222 */ 223 public void moveWindow(TextIter iter) 224 { 225 gtk_source_completion_move_window(gtkSourceCompletion, (iter is null) ? null : iter.getTextIterStruct()); 226 } 227 228 /** 229 * Remove @provider from the completion. 230 * 231 * Params: 232 * provider = a #GtkSourceCompletionProvider. 233 * 234 * Returns: %TRUE if @provider was successfully removed, otherwise if @error 235 * is provided, it will be set with the error and %FALSE is returned. 236 * 237 * Throws: GException on failure. 238 */ 239 public bool removeProvider(SourceCompletionProviderIF provider) 240 { 241 GError* err = null; 242 243 auto p = gtk_source_completion_remove_provider(gtkSourceCompletion, (provider is null) ? null : provider.getSourceCompletionProviderStruct(), &err) != 0; 244 245 if (err !is null) 246 { 247 throw new GException( new ErrorG(err) ); 248 } 249 250 return p; 251 } 252 253 /** 254 * Starts a new completion with the specified #GtkSourceCompletionContext and 255 * a list of potential candidate providers for completion. 256 * 257 * It can be convenient for showing a completion on-the-fly, without the need to 258 * add or remove providers to the #GtkSourceCompletion. 259 * 260 * Another solution is to add providers with 261 * gtk_source_completion_add_provider(), and implement 262 * gtk_source_completion_provider_match() for each provider. 263 * 264 * Params: 265 * providers = a list of #GtkSourceCompletionProvider, or %NULL. 266 * context = The #GtkSourceCompletionContext 267 * with which to start the completion. 268 * 269 * Returns: %TRUE if it was possible to the show completion window. 270 */ 271 public bool show(ListG providers, SourceCompletionContext context) 272 { 273 return gtk_source_completion_show(gtkSourceCompletion, (providers is null) ? null : providers.getListGStruct(), (context is null) ? null : context.getSourceCompletionContextStruct()) != 0; 274 } 275 276 /** 277 * Unblock interactive completion. This can be used after using 278 * gtk_source_completion_block_interactive() to enable interactive completion 279 * again. 280 */ 281 public void unblockInteractive() 282 { 283 gtk_source_completion_unblock_interactive(gtkSourceCompletion); 284 } 285 286 protected class OnActivateProposalDelegateWrapper 287 { 288 void delegate(SourceCompletion) dlg; 289 gulong handlerId; 290 291 this(void delegate(SourceCompletion) dlg) 292 { 293 this.dlg = dlg; 294 onActivateProposalListeners ~= this; 295 } 296 297 void remove(OnActivateProposalDelegateWrapper source) 298 { 299 foreach(index, wrapper; onActivateProposalListeners) 300 { 301 if (wrapper.handlerId == source.handlerId) 302 { 303 onActivateProposalListeners[index] = null; 304 onActivateProposalListeners = std.algorithm.remove(onActivateProposalListeners, index); 305 break; 306 } 307 } 308 } 309 } 310 OnActivateProposalDelegateWrapper[] onActivateProposalListeners; 311 312 /** 313 * The #GtkSourceCompletion::activate-proposal signal is a 314 * keybinding signal which gets emitted when the user initiates 315 * a proposal activation. 316 * 317 * Applications should not connect to it, but may emit it with 318 * g_signal_emit_by_name() if they need to control the proposal 319 * activation programmatically. 320 */ 321 gulong addOnActivateProposal(void delegate(SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 322 { 323 auto wrapper = new OnActivateProposalDelegateWrapper(dlg); 324 wrapper.handlerId = Signals.connectData( 325 this, 326 "activate-proposal", 327 cast(GCallback)&callBackActivateProposal, 328 cast(void*)wrapper, 329 cast(GClosureNotify)&callBackActivateProposalDestroy, 330 connectFlags); 331 return wrapper.handlerId; 332 } 333 334 extern(C) static void callBackActivateProposal(GtkSourceCompletion* sourcecompletionStruct, OnActivateProposalDelegateWrapper wrapper) 335 { 336 wrapper.dlg(wrapper.outer); 337 } 338 339 extern(C) static void callBackActivateProposalDestroy(OnActivateProposalDelegateWrapper wrapper, GClosure* closure) 340 { 341 wrapper.remove(wrapper); 342 } 343 344 protected class OnHideDelegateWrapper 345 { 346 void delegate(SourceCompletion) dlg; 347 gulong handlerId; 348 349 this(void delegate(SourceCompletion) dlg) 350 { 351 this.dlg = dlg; 352 onHideListeners ~= this; 353 } 354 355 void remove(OnHideDelegateWrapper source) 356 { 357 foreach(index, wrapper; onHideListeners) 358 { 359 if (wrapper.handlerId == source.handlerId) 360 { 361 onHideListeners[index] = null; 362 onHideListeners = std.algorithm.remove(onHideListeners, index); 363 break; 364 } 365 } 366 } 367 } 368 OnHideDelegateWrapper[] onHideListeners; 369 370 /** 371 * Emitted when the completion window is hidden. The default handler 372 * will actually hide the window. 373 */ 374 gulong addOnHide(void delegate(SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 375 { 376 auto wrapper = new OnHideDelegateWrapper(dlg); 377 wrapper.handlerId = Signals.connectData( 378 this, 379 "hide", 380 cast(GCallback)&callBackHide, 381 cast(void*)wrapper, 382 cast(GClosureNotify)&callBackHideDestroy, 383 connectFlags); 384 return wrapper.handlerId; 385 } 386 387 extern(C) static void callBackHide(GtkSourceCompletion* sourcecompletionStruct, OnHideDelegateWrapper wrapper) 388 { 389 wrapper.dlg(wrapper.outer); 390 } 391 392 extern(C) static void callBackHideDestroy(OnHideDelegateWrapper wrapper, GClosure* closure) 393 { 394 wrapper.remove(wrapper); 395 } 396 397 protected class OnMoveCursorDelegateWrapper 398 { 399 void delegate(GtkScrollStep, int, SourceCompletion) dlg; 400 gulong handlerId; 401 402 this(void delegate(GtkScrollStep, int, SourceCompletion) dlg) 403 { 404 this.dlg = dlg; 405 onMoveCursorListeners ~= this; 406 } 407 408 void remove(OnMoveCursorDelegateWrapper source) 409 { 410 foreach(index, wrapper; onMoveCursorListeners) 411 { 412 if (wrapper.handlerId == source.handlerId) 413 { 414 onMoveCursorListeners[index] = null; 415 onMoveCursorListeners = std.algorithm.remove(onMoveCursorListeners, index); 416 break; 417 } 418 } 419 } 420 } 421 OnMoveCursorDelegateWrapper[] onMoveCursorListeners; 422 423 /** 424 * The #GtkSourceCompletion::move-cursor signal is a keybinding 425 * signal which gets emitted when the user initiates a cursor 426 * movement. 427 * 428 * The <keycap>Up</keycap>, <keycap>Down</keycap>, 429 * <keycap>PageUp</keycap>, <keycap>PageDown</keycap>, 430 * <keycap>Home</keycap> and <keycap>End</keycap> keys are bound to the 431 * normal behavior expected by those keys. 432 * 433 * When @step is equal to %GTK_SCROLL_PAGES, the page size is defined by 434 * the #GtkSourceCompletion:proposal-page-size property. It is used for 435 * the <keycap>PageDown</keycap> and <keycap>PageUp</keycap> keys. 436 * 437 * Applications should not connect to it, but may emit it with 438 * g_signal_emit_by_name() if they need to control the cursor 439 * programmatically. 440 * 441 * Params: 442 * step = The #GtkScrollStep by which to move the cursor 443 * num = The amount of steps to move the cursor 444 */ 445 gulong addOnMoveCursor(void delegate(GtkScrollStep, int, SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 446 { 447 auto wrapper = new OnMoveCursorDelegateWrapper(dlg); 448 wrapper.handlerId = Signals.connectData( 449 this, 450 "move-cursor", 451 cast(GCallback)&callBackMoveCursor, 452 cast(void*)wrapper, 453 cast(GClosureNotify)&callBackMoveCursorDestroy, 454 connectFlags); 455 return wrapper.handlerId; 456 } 457 458 extern(C) static void callBackMoveCursor(GtkSourceCompletion* sourcecompletionStruct, GtkScrollStep step, int num, OnMoveCursorDelegateWrapper wrapper) 459 { 460 wrapper.dlg(step, num, wrapper.outer); 461 } 462 463 extern(C) static void callBackMoveCursorDestroy(OnMoveCursorDelegateWrapper wrapper, GClosure* closure) 464 { 465 wrapper.remove(wrapper); 466 } 467 468 protected class OnMovePageDelegateWrapper 469 { 470 void delegate(GtkScrollStep, int, SourceCompletion) dlg; 471 gulong handlerId; 472 473 this(void delegate(GtkScrollStep, int, SourceCompletion) dlg) 474 { 475 this.dlg = dlg; 476 onMovePageListeners ~= this; 477 } 478 479 void remove(OnMovePageDelegateWrapper source) 480 { 481 foreach(index, wrapper; onMovePageListeners) 482 { 483 if (wrapper.handlerId == source.handlerId) 484 { 485 onMovePageListeners[index] = null; 486 onMovePageListeners = std.algorithm.remove(onMovePageListeners, index); 487 break; 488 } 489 } 490 } 491 } 492 OnMovePageDelegateWrapper[] onMovePageListeners; 493 494 /** 495 * The #GtkSourceCompletion::move-page signal is a keybinding 496 * signal which gets emitted when the user initiates a page 497 * movement (i.e. switches between provider pages). 498 * 499 * <keycombo><keycap>Control</keycap><keycap>Left</keycap></keycombo> 500 * is for going to the previous provider. 501 * <keycombo><keycap>Control</keycap><keycap>Right</keycap></keycombo> 502 * is for going to the next provider. 503 * <keycombo><keycap>Control</keycap><keycap>Home</keycap></keycombo> 504 * is for displaying all the providers. 505 * <keycombo><keycap>Control</keycap><keycap>End</keycap></keycombo> 506 * is for going to the last provider. 507 * 508 * When @step is equal to #GTK_SCROLL_PAGES, the page size is defined by 509 * the #GtkSourceCompletion:provider-page-size property. 510 * 511 * Applications should not connect to it, but may emit it with 512 * g_signal_emit_by_name() if they need to control the page selection 513 * programmatically. 514 * 515 * Params: 516 * step = The #GtkScrollStep by which to move the page 517 * num = The amount of steps to move the page 518 */ 519 gulong addOnMovePage(void delegate(GtkScrollStep, int, SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 520 { 521 auto wrapper = new OnMovePageDelegateWrapper(dlg); 522 wrapper.handlerId = Signals.connectData( 523 this, 524 "move-page", 525 cast(GCallback)&callBackMovePage, 526 cast(void*)wrapper, 527 cast(GClosureNotify)&callBackMovePageDestroy, 528 connectFlags); 529 return wrapper.handlerId; 530 } 531 532 extern(C) static void callBackMovePage(GtkSourceCompletion* sourcecompletionStruct, GtkScrollStep step, int num, OnMovePageDelegateWrapper wrapper) 533 { 534 wrapper.dlg(step, num, wrapper.outer); 535 } 536 537 extern(C) static void callBackMovePageDestroy(OnMovePageDelegateWrapper wrapper, GClosure* closure) 538 { 539 wrapper.remove(wrapper); 540 } 541 542 protected class OnPopulateContextDelegateWrapper 543 { 544 void delegate(SourceCompletionContext, SourceCompletion) dlg; 545 gulong handlerId; 546 547 this(void delegate(SourceCompletionContext, SourceCompletion) dlg) 548 { 549 this.dlg = dlg; 550 onPopulateContextListeners ~= this; 551 } 552 553 void remove(OnPopulateContextDelegateWrapper source) 554 { 555 foreach(index, wrapper; onPopulateContextListeners) 556 { 557 if (wrapper.handlerId == source.handlerId) 558 { 559 onPopulateContextListeners[index] = null; 560 onPopulateContextListeners = std.algorithm.remove(onPopulateContextListeners, index); 561 break; 562 } 563 } 564 } 565 } 566 OnPopulateContextDelegateWrapper[] onPopulateContextListeners; 567 568 /** 569 * Emitted just before starting to populate the completion with providers. 570 * You can use this signal to add additional attributes in the context. 571 * 572 * Params: 573 * context = The #GtkSourceCompletionContext for the current completion 574 */ 575 gulong addOnPopulateContext(void delegate(SourceCompletionContext, SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 576 { 577 auto wrapper = new OnPopulateContextDelegateWrapper(dlg); 578 wrapper.handlerId = Signals.connectData( 579 this, 580 "populate-context", 581 cast(GCallback)&callBackPopulateContext, 582 cast(void*)wrapper, 583 cast(GClosureNotify)&callBackPopulateContextDestroy, 584 connectFlags); 585 return wrapper.handlerId; 586 } 587 588 extern(C) static void callBackPopulateContext(GtkSourceCompletion* sourcecompletionStruct, GtkSourceCompletionContext* context, OnPopulateContextDelegateWrapper wrapper) 589 { 590 wrapper.dlg(ObjectG.getDObject!(SourceCompletionContext)(context), wrapper.outer); 591 } 592 593 extern(C) static void callBackPopulateContextDestroy(OnPopulateContextDelegateWrapper wrapper, GClosure* closure) 594 { 595 wrapper.remove(wrapper); 596 } 597 598 protected class OnShowDelegateWrapper 599 { 600 void delegate(SourceCompletion) dlg; 601 gulong handlerId; 602 603 this(void delegate(SourceCompletion) dlg) 604 { 605 this.dlg = dlg; 606 onShowListeners ~= this; 607 } 608 609 void remove(OnShowDelegateWrapper source) 610 { 611 foreach(index, wrapper; onShowListeners) 612 { 613 if (wrapper.handlerId == source.handlerId) 614 { 615 onShowListeners[index] = null; 616 onShowListeners = std.algorithm.remove(onShowListeners, index); 617 break; 618 } 619 } 620 } 621 } 622 OnShowDelegateWrapper[] onShowListeners; 623 624 /** 625 * Emitted when the completion window is shown. The default handler 626 * will actually show the window. 627 */ 628 gulong addOnShow(void delegate(SourceCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 629 { 630 auto wrapper = new OnShowDelegateWrapper(dlg); 631 wrapper.handlerId = Signals.connectData( 632 this, 633 "show", 634 cast(GCallback)&callBackShow, 635 cast(void*)wrapper, 636 cast(GClosureNotify)&callBackShowDestroy, 637 connectFlags); 638 return wrapper.handlerId; 639 } 640 641 extern(C) static void callBackShow(GtkSourceCompletion* sourcecompletionStruct, OnShowDelegateWrapper wrapper) 642 { 643 wrapper.dlg(wrapper.outer); 644 } 645 646 extern(C) static void callBackShowDestroy(OnShowDelegateWrapper wrapper, GClosure* closure) 647 { 648 wrapper.remove(wrapper); 649 } 650 }