-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMainWindow.ObjectExplorerIntegration.vb
More file actions
executable file
·323 lines (264 loc) · 13.8 KB
/
Copy pathMainWindow.ObjectExplorerIntegration.vb
File metadata and controls
executable file
·323 lines (264 loc) · 13.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
' MainWindow.ObjectExplorerIntegration.vb - Complete Object Explorer integration
Imports Gtk
Imports System
Imports System.Collections.Generic
Imports SimpleIDE.Widgets
Imports SimpleIDE.Interfaces
Imports SimpleIDE.Editors
Imports SimpleIDE.Models
Imports SimpleIDE.Syntax
Imports SimpleIDE.Utilities
Partial Public Class MainWindow
Inherits Window
' ===== Object Explorer Integration Methods =====
' Object Explorer related fields
'Private pObjectExplorer As ObjectExplorer
Private pObjectExplorerScrolled As ScrolledWindow
' Store reference to root node for Object Explorer
Private pRootNode As SyntaxNode
' Replace: SimpleIDE.MainWindow.SetupObjectExplorerForEditor
''' <summary>
''' Set up Object Explorer with current active editor
''' </summary>
Private Sub SetupObjectExplorerForEditor(vEditor As IEditor)
Try
If pObjectExplorer Is Nothing OrElse vEditor Is Nothing Then Return
' Set the current editor in Object Explorer
pObjectExplorer.SetCurrentEditor(vEditor)
' Hook up the DocumentParsed event if not already connected
RemoveHandler vEditor.DocumentParsed, AddressOf OnEditorDocumentParsed
AddHandler vEditor.DocumentParsed, AddressOf OnEditorDocumentParsed
' Get initial document structure if available
Dim lStructure As SyntaxNode = vEditor.GetDocumentStructure()
If lStructure IsNot Nothing Then
pObjectExplorer.UpdateStructure(lStructure)
' ADDED: Also update navigation dropdowns if this is the current tab
Dim lCurrentTab As TabInfo = GetCurrentTabInfo()
If lCurrentTab IsNot Nothing AndAlso lCurrentTab.Editor Is vEditor Then
Console.WriteLine("SetupObjectExplorerForEditor: Initial structure available, updating navigation dropdowns")
UpdateNavigationDropdowns()
End If
Else
' ADDED: Schedule a parse if no structure available yet
If TypeOf vEditor Is CustomDrawingEditor Then
Dim lCustomEditor As CustomDrawingEditor = DirectCast(vEditor, CustomDrawingEditor)
End If
End If
Catch ex As Exception
Console.WriteLine($"SetupObjectExplorerForEditor error: {ex.Message}")
End Try
End Sub
''' <summary>
''' Enhanced document parsed handler with navigation dropdown support
''' </summary>
''' <param name="vRootNode">The root node of the parsed syntax tree</param>
''' <remarks>
''' This method updates both the Object Explorer and navigation dropdowns
''' when a document is parsed. The signature matches IEditor.DocumentParsedEventHandler.
''' </remarks>
Private Sub OnEditorDocumentParsed(vRootNode As SyntaxNode)
Try
Console.WriteLine($"OnEditorDocumentParsed: Document parsed, root node = {If(vRootNode IsNot Nothing, vRootNode.Name, "Nothing")}")
' Update Object Explorer (existing functionality)
UpdateObjectExplorerForActiveTab()
UpdateNavigationDropdowns
' Update navigation dropdowns for current tab (new functionality)
Dim lCurrentTab As TabInfo = GetCurrentTabInfo()
If lCurrentTab IsNot Nothing Then
Console.WriteLine("OnEditorDocumentParsed: Updating navigation dropdowns for current tab")
UpdateNavigationDropdowns()
' Also update the position to reflect current cursor location
If lCurrentTab.NavigationDropdowns IsNot Nothing AndAlso lCurrentTab.Editor IsNot Nothing Then
Dim lLine As Integer = lCurrentTab.Editor.CurrentLine
Console.WriteLine($"OnEditorDocumentParsed: Updating position to line {lLine}")
lCurrentTab.NavigationDropdowns.UpdatePosition(lLine)
End If
End If
' Note: ProjectManager already has the parse info through SourceFileInfo
' No need to call UpdateFileParseInfo as it doesn't exist
' The parsing is already handled by ProjectManager.ParseFile
Catch ex As Exception
Console.WriteLine($"OnEditorDocumentParsed error: {ex.Message}")
End Try
End Sub
Private Sub OnGetThemeManager(vGTMEA As CustomDrawObjectExplorer.GetThemeManagerEventArgs)
vGTMEA.ThemeManager = pThemeManager
End Sub
''' <summary>
''' Update Object Explorer for the currently active tab
''' </summary>
Private Sub UpdateObjectExplorerForActiveTab()
Try
If pObjectExplorer Is Nothing Then Return
' Skip rebuild when the tab switch was initiated by the Object Explorer itself —
' there's no need to rebuild and it would lose the expanded node state
If pIsObjectExplorerNavigating Then Return
' Get current tab
Dim lCurrentTab As TabInfo = GetCurrentTabInfo()
If lCurrentTab Is Nothing OrElse lCurrentTab.Editor Is Nothing Then Return
' Set the current editor
pObjectExplorer.SetCurrentEditor(lCurrentTab.Editor)
' FIXED: If a project is open, always show the full project structure
If pProjectManager IsNot Nothing AndAlso pProjectManager.IsProjectOpen Then
' Get and display the full project structure
Dim lProjectTree As SyntaxNode = pProjectManager.GetProjectSyntaxTree()
If lProjectTree IsNot Nothing Then
pObjectExplorer.UpdateStructure(lProjectTree)
Console.WriteLine("Object Explorer updated with project structure for active tab")
Else
' Fall back to file structure if project tree not available
Dim lStructure As SyntaxNode = lCurrentTab.Editor.GetDocumentStructure()
If lStructure IsNot Nothing Then
pObjectExplorer.UpdateStructure(lStructure)
Console.WriteLine("Object Explorer updated with file structure (project tree unavailable)")
End If
End If
Else
' No project open, show just the current file's structure
Dim lStructure As SyntaxNode = lCurrentTab.Editor.GetDocumentStructure()
If lStructure IsNot Nothing Then
pObjectExplorer.UpdateStructure(lStructure)
Console.WriteLine("Object Explorer updated with file structure (no project)")
End If
End If
' Update toolbar state
UpdateObjectExplorerToolbarState()
Catch ex As Exception
Console.WriteLine($"UpdateObjectExplorerForActiveTab error: {ex.Message}")
End Try
End Sub
''' <summary>
''' Object Explorer toolbar integration
''' </summary>
Private Sub UpdateObjectExplorerToolbarState()
Try
If pObjectExplorer Is Nothing Then Return
Dim lCurrentTab As TabInfo = GetCurrentTabInfo()
Dim lHasActiveEditor As Boolean = (lCurrentTab IsNot Nothing AndAlso lCurrentTab.Editor IsNot Nothing)
' Enable/disable Object Explorer refresh button based on active editor
pObjectExplorer.SetRefreshEnabled(lHasActiveEditor)
Catch ex As Exception
Console.WriteLine($"UpdateObjectExplorerToolbarState error: {ex.Message}")
End Try
End Sub
' Replace: SimpleIDE.MainWindow.OnObjectExplorerNavigateToFile
Private Sub OnObjectExplorerNavigateToFile(vFilePath As String, vPosition As EditorPosition)
Try
Console.WriteLine($"NavigateToFile: {vFilePath} at line {vPosition.Line + 1}")
' Suppress tree rebuild triggered by the tab switch we are about to make
pIsObjectExplorerNavigating = True
' Check if the file is already open in any tab
Dim lCurrentTab As TabInfo = GetCurrentTabInfo()
Dim lNeedToOpenFile As Boolean = True
If pOpenTabs.ContainsKey(vFilePath) Then
lNeedToOpenFile = False
' Switch to the existing tab if it isn't already active
If lCurrentTab Is Nothing OrElse
Not vFilePath.Equals(lCurrentTab.FilePath, StringComparison.OrdinalIgnoreCase) Then
SwitchToTab(vFilePath)
lCurrentTab = GetCurrentTabInfo()
End If
End If
Dim lFileName As String = System.IO.Path.GetFileName(vFilePath)
' Show loading status ONLY if we need to open the file
If lNeedToOpenFile Then
UpdateStatusBar($"Loading {lFileName}...")
' Force immediate update and add tiny delay to ensure visibility
While Gtk.Application.EventsPending()
Gtk.Application.RunIteration()
End While
System.Threading.Thread.Sleep(50) ' 50ms delay to ensure status is visible
End If
' Open the file if needed
If lNeedToOpenFile Then
OpenFileWithProjectIntegration(vFilePath)
lCurrentTab = GetCurrentTabInfo()
End If
' Navigate to the position
If lCurrentTab IsNot Nothing AndAlso lCurrentTab.Editor IsNot Nothing Then
' vPosition is already 0-based from EditorPosition
lCurrentTab.Editor.NavigateToLineNumberForPresentment(vPosition.Line)
lCurrentTab.Editor.SelectLine(vPosition.Line + 1) ' SelectLine expects 1-based
lCurrentTab.Editor.GrabFocus()
UpdateStatusBar($"Ready - {lFileName} at line {vPosition.Line + 1}")
End If
Catch ex As Exception
Console.WriteLine($"OnObjectExplorerNavigateToFile error: {ex.Message}")
UpdateStatusBar("Ready")
Finally
pIsObjectExplorerNavigating = False
End Try
End Sub
''' <summary>
''' Handle file opened from Project Explorer
''' </summary>
Private Sub OnFileOpenedFromProjectExplorer(vEditor As IEditor)
Try
If pObjectExplorer Is Nothing OrElse vEditor Is Nothing Then Return
Console.WriteLine("File opened from Project Explorer")
' Set the current editor
pObjectExplorer.SetCurrentEditor(vEditor)
Catch ex As Exception
Console.WriteLine($"OnFileOpenedFromProjectExplorer error: {ex.Message}")
End Try
End Sub
''' <summary>
''' Parse all project files and build complete project structure
''' </summary>
Public Sub ParseProjectStructure(vProjectPath As String)
Try
Console.WriteLine($"ParseProjectStructure: {vProjectPath}")
pProjectManager.LoadProjectWithParsing(vProjectPath)
' Get the combined project structure
Dim lProjectStructure As SyntaxNode = pProjectManager.GetProjectSyntaxTree()
If lProjectStructure IsNot Nothing Then
Console.WriteLine($" Project has {lProjectStructure.Children.Count} top-level nodes")
' Update Object Explorer with complete project structure
If pObjectExplorer IsNot Nothing Then
pObjectExplorer.UpdateStructure(lProjectStructure)
End If
Else
Console.WriteLine(" No project structure available")
End If
Catch ex As Exception
Console.WriteLine($"ParseProjectStructure error: {ex.Message}")
End Try
End Sub
' Replace: SimpleIDE.MainWindow.OnObjectExplorerNodeActivated
''' <summary>
''' Handle node selection in Object Explorer (single-click)
''' </summary>
Private Sub OnObjectExplorerNodeSelected(vNode As SyntaxNode)
Try
If vNode Is Nothing Then Return
' Could highlight the node in editor or show info in status bar
Console.WriteLine($"Object Explorer node selected: {vNode.Name}")
Catch ex As Exception
Console.WriteLine($"OnObjectExplorerNodeSelected error: {ex.Message}")
End Try
End Sub
''' <summary>
''' Updated method to switch to the Object Explorer tab with proper activation
''' </summary>
Private Sub SwitchToObjectExplorerTab()
Try
If pLeftNotebook IsNot Nothing AndAlso pObjectExplorer IsNot Nothing Then
' Find the Object Explorer page index
for i As Integer = 0 To pLeftNotebook.NPages - 1
Dim lPage As Widget = pLeftNotebook.GetNthPage(i)
If lPage Is pObjectExplorer Then
pLeftNotebook.CurrentPage = i
Console.WriteLine($"Switched To Object Explorer tab (page {i})")
' Ensure it's visible and activated
lPage.ShowAll()
' Call OnPageActivated to ensure proper initialization
pObjectExplorer.OnPageActivated()
Exit for
End If
Next
End If
Catch ex As Exception
Console.WriteLine($"SwitchToObjectExplorerTab error: {ex.Message}")
End Try
End Sub
End Class