-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMainWindow.LeftPanel.vb
More file actions
executable file
·340 lines (281 loc) · 13.7 KB
/
Copy pathMainWindow.LeftPanel.vb
File metadata and controls
executable file
·340 lines (281 loc) · 13.7 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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
' MainWindow.LeftPanel.vb
' Created: 2025-08-04 22:27:38
' MainWindow.LeftPanel.vb - Left panel management with Notebook for ProjectExplorer and ObjectExplorer
Imports Gtk
Imports System
Imports SimpleIDE.Widgets
Imports SimpleIDE.Interfaces
Imports SimpleIDE.Editors
Imports SimpleIDE.Syntax
Imports SimpleIDE.Models
Imports SimpleIDE.Utilities
Partial Public Class MainWindow
Inherits Window
' ===== Private Fields =====
Private pLeftNotebook As CustomDrawNotebook
Private pObjectExplorer As CustomDrawObjectExplorer
Private Const LEFT_PANEL_MINIMUM_WIDTH = 310
Private pLastLeftPanelWidth As Integer = LEFT_PANEL_MINIMUM_WIDTH
' ===== Left Panel Initialization =====
''' <summary>
''' Initializes the left panel with proper shrink settings to prevent hiding on resize
''' </summary>
Private Sub InitializeLeftPanel()
Try
#If DEBUG Then
Console.WriteLine("InitializeLeftPanel: Starting initialization")
#End If
' Create the CustomDrawNotebook for the left panel
pLeftNotebook = New CustomDrawNotebook(pThemeManager)
' IMPORTANT: Set minimum width ONLY, not both parameters
' This ensures minimum width but allows GTK to manage visibility properly
pLeftNotebook.SetSizeRequest(LEFT_PANEL_MINIMUM_WIDTH, -1)
#If DEBUG Then
Console.WriteLine($"Set left notebook minimum width to {LEFT_PANEL_MINIMUM_WIDTH}")
#End If
' Configure the notebook
Dim lCustomNotebook As CustomDrawNotebook = DirectCast(pLeftNotebook, CustomDrawNotebook)
'lCustomNotebook.SetThemeManager(pThemeManager)
' The hide-panel button's own handler (OnLeftPanelHideRequested below) doesn't
' actually do anything (ToggleLeftPanel() call is commented out) - James wants
' it hidden for this tab group regardless
lCustomNotebook.ShowHidePanelButton = False
lCustomNotebook.ShowDropdownButton = False ' Left panel needs this hidden
lCustomNotebook.ShowScrollButtons = False
lCustomNotebook.ShowTabCloseButtons = False ' Project/Object Explorer tabs aren't individually closable
' Wire up events for the left notebook
AddHandler lCustomNotebook.CurrentTabChanged, AddressOf OnLeftNotebookPageChanged
AddHandler lCustomNotebook.HidePanelRequested, AddressOf OnLeftPanelHideRequested
' Add Project Explorer tab
If pProjectExplorer IsNot Nothing Then
#If DEBUG Then
Console.WriteLine(" Adding Project Explorer tab")
#End If
Dim lProjectIndex As Integer = lCustomNotebook.AppendPage(pProjectExplorer, "Project", "folder-open")
#If DEBUG Then
Console.WriteLine($" Project Explorer added at index {lProjectIndex}")
#End If
End If
' Create and add Object Explorer tab with ThemeManager
#If DEBUG Then
Console.WriteLine(" Creating Object Explorer")
#End If
pObjectExplorer = New CustomDrawObjectExplorer(pSettingsManager, pThemeManager)
AddHandler pObjectExplorer.NodeDoubleClicked, AddressOf OnObjectExplorerNodeDoubleClicked
AddHandler pObjectExplorer.CloseRequested, AddressOf OnObjectExplorerCloseRequested
' CRITICAL: Initialize Object Explorer with ProjectManager for parsing integration
If pProjectManager IsNot Nothing Then
#If DEBUG Then
Console.WriteLine(" Initializing Object Explorer with ProjectManager")
#End If
pObjectExplorer.InitializeWithProjectManager(pProjectManager)
Else
#If DEBUG Then
Console.WriteLine(" WARNING: ProjectManager not available for Object Explorer")
#End If
End If
#If DEBUG Then
Console.WriteLine(" Adding Object Explorer tab")
#End If
' "file-code" is not a real icon name in most system icon themes (including the
' active KDE theme this was tested against), so it silently fell back to a
' generic blank-document icon - "view-list-tree" is a standard freedesktop icon
' name present in Breeze, Papirus, and other common themes, and fits a class/
' member hierarchy browser better anyway
Dim lObjectIndex As Integer = lCustomNotebook.AppendPage(pObjectExplorer, "Objects", "view-list-tree")
#If DEBUG Then
Console.WriteLine($" Object Explorer added at index {lObjectIndex}")
#End If
' CRITICAL FIX: Pack the notebook with shrink:=False to prevent it from disappearing
' resize:=False means it won't grow when window grows (keeps its set width)
' shrink:=False means it won't shrink below its minimum size when window shrinks
pMainHPaned.Pack1(pLeftNotebook, resize:=False, shrink:=False)
' CRITICAL: Ensure the left notebook is visible
pLeftNotebook.ShowAll()
' Set the first tab as active
If lCustomNotebook.NPages > 0 Then
#If DEBUG Then
Console.WriteLine($" Setting tab 0 as current (Project Explorer)")
#End If
lCustomNotebook.CurrentPage = 0
End If
#If DEBUG Then
Console.WriteLine($"InitializeLeftPanel: Completed with {lCustomNotebook.NPages} tabs")
#End If
Catch ex As Exception
Console.WriteLine($"InitializeLeftPanel error: {ex.Message}")
End Try
End Sub
' ===== Object Explorer Event Handlers =====
''' <summary>
''' Handle left panel resize and save to settings
''' </summary>
Private Sub OnLeftPanelResized(vSender As Object, vArgs As EventArgs)
Try
If pMainHPaned Is Nothing OrElse pSettingsManager Is Nothing Then Return
' Get current position (width)
Dim lCurrentWidth As Integer = pMainHPaned.Position
' Only save if it's a reasonable width
If lCurrentWidth >= LEFT_PANEL_MINIMUM_WIDTH AndAlso lCurrentWidth <= 800 Then
pSettingsManager.SetInteger("LeftPanelWidth", lCurrentWidth)
' Don't save immediately on every pixel change, settings will save on app close
End If
Catch ex As Exception
Console.WriteLine($"OnLeftPanelResized error: {ex.Message}")
End Try
End Sub
Private Sub OnObjectExplorerNodeDoubleClicked(vNode As SyntaxNode)
Try
If vNode Is Nothing Then Return
' Get the current editor
Dim lCurrentTab As TabInfo = GetCurrentTabInfo()
If lCurrentTab Is Nothing OrElse lCurrentTab.Editor Is Nothing Then Return
' Navigate to the node's location
If vNode.StartLine >= 0 Then
lCurrentTab.Editor.GoToPosition(New EditorPosition(vNode.StartLine + 1, vNode.StartColumn + 1))
lCurrentTab.Editor.EnsureCursorVisible()
End If
Catch ex As Exception
Console.WriteLine($"OnObjectExplorerNodeDoubleClicked error: {ex.Message}")
End Try
End Sub
Private Sub OnObjectExplorerCloseRequested()
Try
' Hide the Object Explorer by switching to Project Explorer tab
If pLeftNotebook IsNot Nothing AndAlso pLeftNotebook.NPages > 0 Then
pLeftNotebook.SetCurrentTab(0) ' Switch to project Explorer
End If
Catch ex As Exception
Console.WriteLine($"OnObjectExplorerCloseRequested error: {ex.Message}")
End Try
End Sub
' ===== Editor Focus Changed Handler Update =====
Private Sub OnEditorFocusChanged(vSender As Object, vArgs As EventArgs)
Try
' Get the focused editor
Dim lEditor As IEditor = TryCast(vSender, IEditor)
If lEditor Is Nothing Then Return
' Update the object explorer with the current editor
If pObjectExplorer IsNot Nothing Then
pObjectExplorer.SetCurrentEditor(lEditor)
End If
' Update status bar
UpdateStatusBar()
Catch ex As Exception
Console.WriteLine($"OnEditorFocusChanged error: {ex.Message}")
End Try
End Sub
''' <summary>
''' Prevent auto-resize when nodes are expanded
''' </summary>
''' <remarks>
''' This should be called from object explorer/project explorer when nodes expand
''' to prevent the panel from auto-resizing
''' </remarks>
Public Sub PreventAutoResize()
Try
If pMainHPaned Is Nothing Then Return
' Store current position
Dim lCurrentPosition As Integer = pMainHPaned.Position
' Ensure it doesn't change
' Note: GTK# doesn't auto-resize paned widgets, but this is defensive
pMainHPaned.Position = lCurrentPosition
Catch ex As Exception
Console.WriteLine($"PreventAutoResize error: {ex.Message}")
End Try
End Sub
''' <summary>
''' Handles the hide panel request from the left CustomDrawNotebook
''' </summary>
Private Sub OnLeftPanelHideRequested()
Try
'ToggleLeftPanel()
#If DEBUG Then
Console.WriteLine("Left panel hide requested from CustomDrawNotebook")
#End If
Catch ex As Exception
Console.WriteLine($"OnLeftPanelHideRequested error: {ex.Message}")
End Try
End Sub
''' <summary>
''' Handles page changes in the left notebook (CustomDrawNotebook version)
''' </summary>
''' <param name="vOldIndex">Previous tab index</param>
''' <param name="vNewIndex">New tab index</param>
Private Sub OnLeftNotebookPageChanged(vOldIndex As Integer, vNewIndex As Integer)
Try
#If DEBUG Then
Console.WriteLine($"Left notebook page changed from {vOldIndex} to {vNewIndex}")
#End If
' If switching to Object Explorer tab (index 1)
If vNewIndex = 1 Then
' Update Object Explorer for current editor
UpdateObjectExplorerForActiveTab()
End If
Catch ex As Exception
Console.WriteLine($"OnLeftNotebookPageChanged error: {ex.Message}")
End Try
End Sub
Private Sub EnsureLeftPanelWidth()
Try
If pMainHPaned Is Nothing Then Return
Dim lSavedWidth As Integer = LEFT_PANEL_MINIMUM_WIDTH
If pSettingsManager IsNot Nothing Then
lSavedWidth = pSettingsManager.GetInteger("leftpanelwidth", LEFT_PANEL_MINIMUM_WIDTH)
If lSavedWidth < LEFT_PANEL_MINIMUM_WIDTH Then lSavedWidth = LEFT_PANEL_MINIMUM_WIDTH
If lSavedWidth > 500 Then lSavedWidth = 500
End If
pMainHPaned.Position = lSavedWidth
#If DEBUG Then
Console.WriteLine($"EnsureLeftPanelWidth: Set position to {lSavedWidth}")
#End If
Catch ex As Exception
Console.WriteLine($"EnsureLeftPanelWidth error: {ex.Message}")
End Try
End Sub
' Add: SimpleIDE.MainWindow.ForceShowLeftPanel
' To: MainWindow.LeftPanel.vb
''' <summary>
''' Force the left panel to be visible with proper width
''' </summary>
Public Sub ForceShowLeftPanel()
Try
#If DEBUG Then
Console.WriteLine("ForceShowLeftPanel: Starting...")
#End If
' Check if notebook exists
If pLeftNotebook Is Nothing Then
#If DEBUG Then
Console.WriteLine("ERROR: Left notebook doesn't exist - attempting to recreate")
#End If
InitializeLeftPanel()
End If
' Ensure notebook is visible
If pLeftNotebook IsNot Nothing Then
pLeftNotebook.ShowAll()
pLeftNotebook.Visible = True
' Set minimum size
pLeftNotebook.SetSizeRequest(LEFT_PANEL_MINIMUM_WIDTH, -1)
#If DEBUG Then
Console.WriteLine($"Left notebook forced visible with {pLeftNotebook.NPages} pages")
#End If
End If
' Ensure HPaned position
If pMainHPaned IsNot Nothing Then
If pMainHPaned.Position < LEFT_PANEL_MINIMUM_WIDTH Then
pMainHPaned.Position = LEFT_PANEL_MINIMUM_WIDTH
#If DEBUG Then
Console.WriteLine($"Set HPaned position To {LEFT_PANEL_MINIMUM_WIDTH}")
#End If
End If
' Force redraw
pMainHPaned.QueueDraw()
End If
#If DEBUG Then
Console.WriteLine("ForceShowLeftPanel: Complete")
#End If
Catch ex As Exception
Console.WriteLine($"ForceShowLeftPanel error: {ex.Message}")
End Try
End Sub
End Class