guiObjectInspector.ed.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. // The "Object Inspector" is a useful little window for browsing and editing SimObject
  23. // hierarchies. Be aware that there is no undo in the inspector.
  24. //---------------------------------------------------------------------------------------------
  25. /// Bring up a new inspector window on the given object.
  26. function inspectObject( %object )
  27. {
  28. if( !isObject( %object ) )
  29. {
  30. error( "inspectObject: no object '" @ %object @ "'" );
  31. return;
  32. }
  33. // Create a new object inspector window.
  34. exec( "./guiObjectInspector.ed.gui" );
  35. if( !isObject( %guiContent) )
  36. {
  37. error( "InspectObject: failed to create GUI from 'guiObjectInspector.ed.gui'" );
  38. return;
  39. }
  40. // Initialize the inspector.
  41. %guiContent.init( %object );
  42. Canvas.getContent().add( %guiContent );
  43. }
  44. //=============================================================================================
  45. // GuiObjectInspector
  46. //=============================================================================================
  47. //---------------------------------------------------------------------------------------------
  48. function GuiObjectInspector::init( %this, %object )
  49. {
  50. if( !%object.isMemberOfClass( "SimSet" ) )
  51. {
  52. // Complete deletely the splitter and the left-side part of the inspector
  53. // leaving only the field inspector.
  54. %this.add( %this-->panel2 );
  55. %this-->splitter.delete();
  56. %this-->inspector.inspect( %object );
  57. %this-->methodList.init( %object );
  58. }
  59. else
  60. {
  61. %treeView = %this-->treeView;
  62. %treeView.inspectorCtrl = %this-->inspector;
  63. %treeView.methodList = %this-->methodList;
  64. %treeView.open( %object );
  65. }
  66. // Set window caption.
  67. %caption = "Object Inspector - " @ %object.getId() @ " : " @ %object.getClassName();
  68. %name = %object.getName();
  69. if( %name !$= "" )
  70. %caption = %caption @ " - " @ %name;
  71. %this.text = %caption;
  72. }
  73. //---------------------------------------------------------------------------------------------
  74. function GuiObjectInspector::onClose( %this )
  75. {
  76. // Delete us.
  77. %this.schedule( 1, "delete" );
  78. }
  79. //=============================================================================================
  80. // GuiObjectInspectorTree
  81. //=============================================================================================
  82. //---------------------------------------------------------------------------------------------
  83. function GuiObjectInspectorTree::onSelect( %this, %object )
  84. {
  85. if( isObject( %object ) )
  86. {
  87. %this.inspectorCtrl.inspect( %object );
  88. %this.methodList.init( %object );
  89. }
  90. }
  91. //---------------------------------------------------------------------------------------------
  92. function GuiObjectInspectorTree::onRightMouseUp( %this, %itemId, %mousePos, %object )
  93. {
  94. if( !isObject( GuiObjectInspectorTreePopup ) )
  95. new PopupMenu( GuiObjectInspectorTreePopup )
  96. {
  97. superClass = "MenuBuilder";
  98. isPopup = true;
  99. item[ 0 ] = "Jump to Definition in Torsion" TAB "" TAB "EditorOpenDeclarationInTorsion( %this.object );";
  100. object = "";
  101. };
  102. GuiObjectInspectorTreePopup.object = %object;
  103. GuiObjectInspectorTreePopup.showPopup( Canvas );
  104. }
  105. //=============================================================================================
  106. // GuiObjectInspectorMethodList
  107. //=============================================================================================
  108. //---------------------------------------------------------------------------------------------
  109. function GuiObjectInspectorMethodList::init( %this, %object )
  110. {
  111. %this.clear();
  112. %methods = %object.dumpMethods();
  113. %count = %methods.count();
  114. %methodsGroup = %this.insertItem( 0, "Methods" );
  115. %parentScripted = %this.insertItem( %methodsGroup, "Scripted" );
  116. %parentNative = %this.insertItem( %methodsGroup, "Native" );
  117. for( %i = 0; %i < %count; %i ++ )
  118. {
  119. %name = %methods.getKey( %i );
  120. %value = %methods.getValue( %i );
  121. %prototype = getRecord( %value, 2 );
  122. %fileName = getRecord( %value, 3 );
  123. %lineNumber = getRecord( %value, 4 );
  124. %usage = getRecords( %value, 5 );
  125. %tooltip = %prototype;
  126. if( isFile( %fileName ) )
  127. {
  128. %parent = %parentScripted;
  129. %tooltip = %tooltip NL "Declared in: " @ %fileName @ ":" @ %lineNumber;
  130. }
  131. else
  132. %parent = %parentNative;
  133. %tooltip = %tooltip @ "\n\n" @ %usage;
  134. %id = %this.insertItem( %parent, %prototype, %fileName NL %lineNumber );
  135. %this.setItemTooltip( %id, %tooltip );
  136. }
  137. %methods.delete();
  138. if( %object.isMethod( "getDebugInfo" ) )
  139. {
  140. %debugInfo = %object.getDebugInfo();
  141. %count = %debugInfo.count();
  142. %parent = %this.insertItem( 0, "Debug Info" );
  143. for( %i = 0; %i < %count; %i ++ )
  144. %id = %this.insertItem( %parent, %debugInfo.getKey( %i ) @ ": " @ %debugInfo.getValue( %i ) );
  145. %debugInfo.delete();
  146. }
  147. %this.sort( 0, true );
  148. }
  149. //---------------------------------------------------------------------------------------------
  150. function GuiObjectInspectorMethodList::onRightMouseUp( %this, %item, %mousePos )
  151. {
  152. %value = %this.getItemValue( %item );
  153. if( %value $= "" )
  154. return;
  155. %fileName = getRecord( %value, 0 );
  156. %lineNumber = getRecord( %value, 1 );
  157. if( isFile( %fileName ) )
  158. {
  159. if( !isObject( GuiInspectorMethodListPopup ) )
  160. new PopupMenu( GuiInspectorMethodListPopup )
  161. {
  162. superClass = "MenuBuilder";
  163. isPopup = true;
  164. item[ 0 ] = "Jump to Definition in Torsion" TAB "" TAB "EditorOpenFileInTorsion( %this.jumpFileName, %this.jumpLineNumber );";
  165. jumpFileName = "";
  166. jumpLineNumber = "";
  167. };
  168. GuiInspectorMethodListPopup.jumpFileName = %fileName;
  169. GuiInspectorMethodListPopup.jumpLineNumber = %lineNumber;
  170. GuiInspectorMethodListPopup.showPopup( Canvas );
  171. }
  172. }
  173. //=============================================================================================
  174. // GuiObjectInspectorTreeFilter
  175. //=============================================================================================
  176. //---------------------------------------------------------------------------------------------
  177. function GuiObjectInspectorTreeFilter::onWake( %this )
  178. {
  179. %treeView = %this.getParent()-->TreeView;
  180. if( isObject( %treeView ) )
  181. %this.treeView = %treeView;
  182. Parent::onWake( %this );
  183. }
  184. //=============================================================================================
  185. // GuiObjectInspectorTreeFilter
  186. //=============================================================================================
  187. //---------------------------------------------------------------------------------------------
  188. function GuiObjectInspectorTreeFilterClearButton::onWake( %this )
  189. {
  190. %filterText = %this.getParent()-->FilterText;
  191. if( isObject( %filterText ) )
  192. %this.textCtrl = %filterText;
  193. }