gflow-dock.vala 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /********************************************************************
  2. # Copyright 2014-2019 Daniel 'grindhold' Brendle, 2015 Daniel Espinosa <esodan@gmail.com>
  3. #
  4. # This file is part of libgflow.
  5. #
  6. # libgflow is free software: you can redistribute it and/or
  7. # modify it under the terms of the GNU Lesser General Public License
  8. # as published by the Free Software Foundation, either
  9. # version 3 of the License, or (at your option) any later
  10. # version.
  11. #
  12. # libgtkflow is distributed in the hope that it will be
  13. # useful, but WITHOUT ANY WARRANTY; without even the implied
  14. # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. # PURPOSE. See the GNU Lesser General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public
  18. # License along with libgtkflow.
  19. # If not, see http://www.gnu.org/licenses/.
  20. *********************************************************************/
  21. namespace GFlow {
  22. /**
  23. * This class represents an endpoint of a node. These endpoints can be
  24. * connected in order to let them exchange data. The data contained
  25. * in this endpoint is stored as GLib.Value. Only Docks that contain
  26. * data with the same VariantType can be interconnected.
  27. */
  28. public interface Dock : Object {
  29. /**
  30. * The name that will be rendered for this dock
  31. */
  32. public abstract string? name { get; set; }
  33. /**
  34. * The string rendered as typehint for this dock.
  35. * If this string is "" and the show_type is set to true
  36. * libgflow will attempt to determine the type of this
  37. * dock and display it, but it produces nicer results to set
  38. * them manually.
  39. */
  40. public abstract string? typename { get; set; }
  41. /**
  42. * Determines whether this dock is highlighted
  43. * this is usually triggered when the mouse hovers over it
  44. */
  45. public abstract bool highlight { get; set; }
  46. /**
  47. * Determines whether this dock is active
  48. */
  49. public abstract bool active { get; set; }
  50. /**
  51. * A reference to the node this Dock resides in
  52. */
  53. public abstract weak Node? node { get; set; }
  54. /**
  55. * The initial value that has been set to this dock
  56. * The dock will be set to this value when it is rendered
  57. * invalid
  58. */
  59. public abstract GLib.Value? initial { get; }
  60. /**
  61. * This signal is being triggered, when there is a connection being established
  62. * from or to this Dock.
  63. */
  64. public signal void linked (Dock d);
  65. /**
  66. * This signal is being triggered, before a connection is made
  67. * between two docks. If the implementor returns false, the
  68. * connection is not being made.
  69. * IMPORTANT: Connect to this signal with connect_after
  70. * otherwise this default handler will be called after the
  71. * signal you implemented, thus always returning true,
  72. * rendering your code ineffective.
  73. */
  74. public virtual signal bool before_linking (Dock self, Dock other){
  75. return true;
  76. }
  77. /**
  78. * This signal is being triggered, when there is a connection being removed
  79. * from or to this Dock. If this the last connection of the dock, the
  80. * boolean parameter last will be set to true.
  81. */
  82. public signal void unlinked (Dock d, bool last);
  83. /**
  84. * Triggers when the value of this dock changes
  85. */
  86. public signal void changed ();
  87. /**
  88. * Implementations should return true if this dock has at least one
  89. * connection to another dock
  90. */
  91. public abstract bool is_linked ();
  92. /**
  93. * Implementations should return true if this dock is connected
  94. * to the supplied dock
  95. */
  96. public abstract bool is_linked_to (Dock dock);
  97. /**
  98. * Connect this {@link Dock} to other {@link Dock}
  99. */
  100. public abstract void link (Dock dock) throws GLib.Error;
  101. /**
  102. * Disconnect this {@link Dock} from other {@link Dock}
  103. */
  104. public abstract void unlink (Dock dock) throws GLib.Error;
  105. /**
  106. * Disconnect this {@link Dock} from all {@link Dock}s it is connected to
  107. */
  108. public abstract void unlink_all () throws GLib.Error;
  109. /**
  110. * Tries to resolve this Dock's value-type to a displayable string
  111. */
  112. public virtual string determine_typestring () {
  113. if (this.initial != null)
  114. return this.initial.type().name();
  115. else
  116. return "";
  117. }
  118. /**
  119. * Returs true if this and the supplied dock have
  120. * same type
  121. */
  122. public virtual bool has_same_type (Dock other) {
  123. return this.initial.type_name() == other.initial.type_name();
  124. }
  125. }
  126. }