1: Private Const _btnName As String = "LaunchDocument"
2: Private Const _toolTip As String = "Enable/Disable Open external document"
3: Private _bOpenDoc As Boolean
5: <CLSCompliant(False)> _
6: Public Sub Initialize(ByVal MapWin As MapWindow.Interfaces.IMapWin, ByVal ParentHandle As Integer) Implements MapWindow.Interfaces.IPlugin.Initialize
7: 'This event is fired when the user loads your plug-in either through the plug-in dialog
8: 'box, or by checkmarking it in the plug-ins menu. This is where you would add buttons to the
9: 'tool bar or menu items to the menu.
11: 'It is also standard to set a global reference to the IMapWin that is passed through here so that
12: 'you can access it elsewhere in your project to act on MapWindow.
13: g_MapWin = MapWin
15: ' Create a new toolbar and a new button with an icon attached on it
16: ' Added 04/01/2008 by Earljon Hidalgo
18: Dim tbr As MapWindow.Interfaces.Toolbar = MapWin.Toolbar
21: Dim btn As MapWindow.Interfaces.ToolbarButton = tbr.AddButton(_btnName, _toolbarName, "", "")
23: btn.BeginsGroup = True
24: ' if we like icon + text to appear, uncomment this
25: 'btn.Text = "OpenDoc"
26: btn.Tooltip = _toolTip
27: btn.Category = _toolbarName
28: btn.Picture = New System.Drawing.Icon(My.Resources.Resource.AppIcon, New System.Drawing.Size(16, 16))
30: ' initialized to not selected
31: _bOpenDoc = False
32: tbr = Nothing
33: btn = Nothing
34: Catch ex As Exception
36: End Try
37: End Sub
39: Public Sub Terminate() Implements MapWindow.Interfaces.IPlugin.Terminate
40: 'This event is fired when the user unloads your plug-in either through the plug-in dialog
41: 'box, or by un-checkmarking it in the plug-ins menu. This is where you would remove any
42: 'buttons from the tool bar tool bar or menu items from the menu that you may have added.
43: 'If you don't do this, then you will leave dangling menus and buttons that don't do anything.
45: ' Remove button and the toolbar if plugin is unloaded
46: ' Added 04/01/2008 by Earljon Hidalgo
49: End Sub
51: Public Sub ItemClicked(ByVal ItemName As String, ByRef Handled As Boolean) Implements MapWindow.Interfaces.IPlugin.ItemClicked
52: 'This event fires when a menu item or toolbar button is clicked. So if you added a button or menu
53: 'on the Initialize event, then this is where you would handle it.
55: ' Check and save the state of the button
56: ' Added 04/01/2008 by Earljon Hidalgo
57: Dim bToggle As Boolean = IIf(Not _bOpenDoc, True, False)
59: If ItemName = _btnName Then
60: g_MapWin.Toolbar.ButtonItem(_btnName).Pressed = bToggle
61: _bOpenDoc = bToggle
62: Handled = True
63: End If
64: Catch ex As System.Exception
66: End Try
67: End Sub
69: <CLSCompliant(False)> _
70: Public Sub ShapesSelected(ByVal Handle As Integer, ByVal SelectInfo As MapWindow.Interfaces.SelectInfo) Implements MapWindow.Interfaces.IPlugin.ShapesSelected
71: 'This event fires when the user selects one or more shapes using the select tool in MapWindow. Handle is the
72: 'Layer handle for the shapefile on which shapes were selected. SelectInfo holds information abou the
73: 'shapes that were selected.
74: Dim i As Integer
75: Dim sf As MapWinGIS.Shapefile
76: Dim FileOrURL As String = ""
77: Dim newProcess As New Process
79: 'make sure something was returned in SelectInfo
80: If SelectInfo Is Nothing Then Exit Sub
82: ' Check the state of the button if we need to open external document
83: ' or ignore it
84: ' Added 04/01/2008 by Earljon Hidalgo
85: If Not _bOpenDoc Then Exit Sub
87: 'get the shapefile object on which a shape was selected
88: sf = g_MapWin.Layers(Handle).GetObject
89: 'Check to see if this shapefile has an attribute field "FileOrURL"
90: For i = 0 To sf.NumFields - 1
91: If LCase(sf.Field(i).Name) = "fileorurl" Then
92: 'This shapefile has the needed attribute field.
93: 'We will only be launching one document, so if they selected more than one shape
94: 'then we will just launch the document associated with the first selected shape.
95: 'Also, i is the index of the field that has the FileOrURL that we are going to
97: FileOrURL = sf.CellValue(i, SelectInfo(0).ShapeIndex)
98: Exit For
99: End If
101: If FileOrURL <> "" Then
102: 'Use a .NET process() to launch the file or URL
103: MapWinUtility.Logger.Dbg("DocLauncher: Launched File or URL: " + FileOrURL)
104: newProcess.StartInfo.FileName = FileOrURL
106: End If
107: Catch ex As System.Exception
109: End Try
110: End Sub