I'm trying to build an Entity Viewer Plugin but I can't detect when a file is opened in order to update my plugin internal entity listbox and refresh the Pad. Here's what I got so far...
Code: Select all
USING Xide.PluginSystem
USING System.Drawing
USING System.Windows.Forms
CLASS EntityViewerPad INHERIT ToolPad
PRIVATE oService AS PluginService
PRIVATE oList AS ListBox
CONSTRUCTOR(toService AS PluginService)
SUPER("Entity Viewer", Size{300, 400})
SELF:oService := toService
SELF:oList := ListBox{}
SELF:oList:Dock := DockStyle.Fill
SELF:oList:SelectedIndexChanged += SELF:OnEntitySelected
SELF:Controls:Add(SELF:oList)
SELF:DockTo(ToolPadDock.Left)
// try to subscribe to the activated event (IT'S DOESN'T WORK)
SELF:oService:IdeForm:Activated += OnEditorActivated
SELF:UpdateEntityList()
END CONSTRUCTOR
METHOD UpdateEntityList AS VOID
LOCAL loFilePad := SELF:oService:GetActiveFilePad() AS FilePad
IF loFilePad == NULL
RETURN
ENDIF
LOCAL loEditor := loFilePad:Editor AS Editor
LOCAL laEntities AS Entity[]
laEntities := loEditor:GetEntities()
SELF:oList:Items:Clear()
FOREACH loEntity AS Entity IN laEntities
SELF:oList:Items:Add(loEntity:Name + " (" + loEntity:Type:ToString() + ")")
NEXT
END METHOD
METHOD OnEntitySelected(o AS OBJECT, e AS EventArgs) AS VOID
LOCAL loFilePad := SELF:oService:GetActiveFilePad() AS FilePad
IF loFilePad == NULL || SELF:oList:SelectedIndex == -1
RETURN
ENDIF
LOCAL loEditor := loFilePad:Editor AS Editor
LOCAL laEntities AS Entity[]
laEntities := loEditor:GetEntities()
LOCAL loSelectedEntity AS Entity
loSelectedEntity := laEntities[SELF:oList:SelectedIndex+1]
// Move the cursor to the selected entity line
loEditor:MoveCaretTo(loSelectedEntity:GetStartLine(), 1)
END METHOD
METHOD OnEditorActivated(sender AS OBJECT, e AS EventArgs) AS VOID
SELF:UpdateEntityList()
END METHOD
END CLASS
BTW: should we have a "XIDE" forum for posting stuffs like this one?
thanks!