Tutorial 2 - Document selected event

Top  Previous  Next

In this tutorial, we're going to see how to detect when the BLIde user select a document to edit it. Our Plug-in will display a message in the BLIde console whenever the user selects a document to edit it.

 

As always, we're going to create a copy of our empty plugin template, and go directly to the PluginModule.vb file.

 

In this case we're going to change it this way:

 

 

Imports BLIde.SDK

Public Module Plugin

 

   Sub Main()

       AddHandler Events.BLIdeEvents.TabbedDocumentChanged, AddressOf TabDocChanged

   End Sub

 

   Sub TabDocChanged(ByVal sender As Object, ByVal e As System.EventArgs)

       IO.Write("Tabbed document changed!")

   End Sub

End Module

 

 

This example is quite self explanatory, but let's see it step by step.

the only line of code we have on the Plug-in Main procedure is the event handling sentence. In this case, we're handling this event:

 

Events.BLIdeEvents.TabbedDocumentChanged

 

The namespace BLIdeEvents (inside BLIde.SDK.Events) contains event handling structures for some of the actions that are happening while a user is coding in BLIde. for this example we've selected the TabbedDocumentChanged event. This event is fired every time the BLIde user changes the selected tabbed document.

 

So, if we execute this example as it is now, we'll see a message "Tabbed document changed!" every time the user changes the active tabbed document on BLIde.

 

But we can take this a step fordward:

 

Imports BLIde.SDK

Public Module Plugin

   Sub Main()

       AddHandler Events.BLIdeEvents.TabbedDocumentChanged, AddressOf TabDocChanged

   End Sub

   Sub TabDocChanged(ByVal sender As Object, ByVal e As System.EventArgs)

       Dim ED As BLIdeForms.Editor

       ED = BLIdeForms.Editor.GetCurrentEditor()

       If ED IsNot Nothing Then

           If ED.CompletePath = "" Then

               IO.Write("Untitled document selected")

           Else

               IO.Write("New TAB selected: " & ED.CompletePath)

           End If

       Else

           IO.Write("No document selected!")

       End If

   End Sub

End Module

 

In this example, we've added code to identify the selected document filename. Let's see it step by step:

 

...

       Dim ED As BLIdeForms.Editor

...

 

Dim ED As BLIdeForms.Editor

 

This sentence defines a variable ED of the kind BLIde.SDK.BLIdeForms.Editor. This class is the representation of a BLIde document being edited.

Then, we assign this variable the currently selected BLIdeForms Editor control:

 

...

       ED = BLIdeForms.Editor.GetCurrentEditor()

...

 

Then, if there's an active document being edited, the ED variable should 'point' it. Otherwise, the variable ED has the value of nothing, so we act accordingly:

 

...

       If ED IsNot Nothing Then

           If ED.CompletePath = "" Then

               IO.Write("Untitled document selected")

           Else

               IO.Write("New TAB selected: " & ED.CompletePath)

           End If

       Else

           IO.Write("No document selected!")

       End If

...

 

In this example, we're using the CompletePath property of the ED control to see the name in disk of the document.