-
Notifications
You must be signed in to change notification settings - Fork 32
/
IndentControl.bas
387 lines (316 loc) · 12.5 KB
/
IndentControl.bas
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
Attribute VB_Name = "IndentControl_Module"
' #VBIDEUtils#************************************************************
' * Programmer Name : removed
' * Web Site : http://www.ppreview.net
' * E-Mail : removed
' * Date : 04/05/97
' * Time : 17:25
' * Module Name : IndentControl_Module
' * Module Filename : IndentControl.bas
' **********************************************************************
' * Comments :
' *
' **********************************************************************
Option Explicit
Dim m_sIndentType As String
Dim m_sIndentName As String
Dim m_vbProjectObj As VBProject
Dim m_vbCodemoduleObj As CodeModule
Dim m_nStart As Long
Dim m_nEnd As Long
Public Sub IndentProcedure()
' #VBIDEUtils#************************************************************
' * Programmer Name : removed
' * Web Site : http://www.ppreview.net
' * E-Mail : removed
' * Date : 04/05/97
' * Time : 17:26
' * Module Name : IndentControl_Module
' * Module Filename : IndentControl.bas
' * Procedure Name : IndentProcedure
' * Parameters :
' **********************************************************************
' * Comments :
' *
' *
' **********************************************************************
Dim prjProject As VBProject
Dim cpCodePane As CodePane
Dim nStartLine As Long
Dim nStartCol As Long
Dim nEndline As Long
Dim nEndCol As Long
Dim sProc As String
Dim vaTypes As Variant
Dim nI As Integer
Dim nTmp As Long
On Error Resume Next
Dim cHourglass As class_Hourglass
Set cHourglass = New class_Hourglass
Set prjProject = VBInstance.ActiveVBProject
If prjProject Is Nothing Then Exit Sub
Set cpCodePane = VBInstance.ActiveCodePane
If cpCodePane Is Nothing Then Exit Sub
If Not IsThereCode(cpCodePane.CodeModule) Then Exit Sub
' *** Get where the current selection is in the module
cpCodePane.GetSelection nStartLine, nStartCol, nEndline, nEndCol
' *** Create an array of procedure types to check for
vaTypes = Array(vbext_pk_Proc, vbext_pk_Get, vbext_pk_Let, vbext_pk_Set)
sProc = ""
' *** Loop through the procedure type
For nI = 0 To 3
' *** Try to get the procedure name
sProc = cpCodePane.CodeModule.ProcOfLine(nStartLine, CLng(vaTypes(nI)))
If sProc <> "" Then
' *** If we got a procedure name, find its start and end lines and quit the loop
nTmp = cpCodePane.CodeModule.ProcStartLine(sProc, CLng(vaTypes(nI)))
nEndline = cpCodePane.CodeModule.ProcCountLines(sProc, CLng(vaTypes(nI))) + nTmp - 1
If err Then err.Clear
If nTmp > 0 Then Exit For
sProc = ""
End If
Next
If sProc = "" Then Exit Sub
nStartLine = nTmp
' *** Store the currently active pane
RecoveActiveState "Store"
' *** Set some module-level variables to specify what to rebuild
m_sIndentType = "Procedure"
m_sIndentName = sProc
Set m_vbProjectObj = prjProject
Set m_vbCodemoduleObj = cpCodePane.CodeModule
m_nStart = nStartLine
m_nEnd = nEndline
Load frmProgress
frmProgress.Show
frmProgress.ZOrder
frmProgress.MessageText = "Indenting " & Chr$(13) & m_sIndentName
Call RebuildIndents
Unload frmProgress
Set frmProgress = Nothing
' *** Restore the currently active pane
RecoveActiveState "Restore"
End Sub
Public Sub IndentModule()
' #VBIDEUtils#************************************************************
' * Programmer Name : removed
' * Web Site : http://www.ppreview.net
' * E-Mail : removed
' * Date : 04/05/97
' * Time : 17:26
' * Module Name : IndentControl_Module
' * Module Filename : IndentControl.bas
' * Procedure Name : IndentModule
' * Parameters :
' **********************************************************************
' * Comments :
' * Locates the active module, checks it for code and indents it
' *
' *
' **********************************************************************
Dim prjProject As VBProject
Dim cpCodePane As CodePane
On Error Resume Next
Dim cHourglass As class_Hourglass
Set cHourglass = New class_Hourglass
Set prjProject = VBInstance.ActiveVBProject
If prjProject Is Nothing Then Exit Sub
Set cpCodePane = VBInstance.ActiveCodePane
If cpCodePane Is Nothing Then Exit Sub
If Not IsThereCode(cpCodePane.CodeModule) Then
Call MsgBox("The current module does not contain any code to indent!", vbExclamation + vbOKOnly + vbDefaultButton1, "No Code")
Exit Sub
End If
' *** Store the currently active pane
RecoveActiveState "Store"
' *** Set some module-level variables to specify what to rebuild
m_sIndentType = "Module"
m_sIndentName = cpCodePane.CodeModule.Parent.Name
Set m_vbProjectObj = prjProject
Set m_vbCodemoduleObj = cpCodePane.CodeModule
Load frmProgress
frmProgress.Show
frmProgress.ZOrder
frmProgress.MessageText = "Indenting " & Chr$(13) & m_sIndentName
Call RebuildIndents
Unload frmProgress
Set frmProgress = Nothing
' *** Restore the currently active pane
RecoveActiveState "Restore"
End Sub
Public Sub IndentProject()
' #VBIDEUtils#************************************************************
' * Programmer Name : removed
' * Web Site : http://www.ppreview.net
' * E-Mail : removed
' * Date : 04/05/97
' * Time : 17:26
' * Module Name : IndentControl_Module
' * Module Filename : IndentControl.bas
' * Procedure Name : IndentProject
' * Parameters :
' **********************************************************************
' * Comments :
' * Locates the active project, checks it for code and indents it
' *
' *
' **********************************************************************
Dim prjProject As VBProject
Dim cmpObj As VBComponent
Dim bSomeCode As Boolean
On Error Resume Next
Dim cHourglass As class_Hourglass
Set cHourglass = New class_Hourglass
Set prjProject = VBInstance.ActiveVBProject
If prjProject Is Nothing Then Exit Sub
bSomeCode = False
For Each cmpObj In prjProject.VBComponents
If (cmpObj.Type <> vbext_ct_RelatedDocument) And (cmpObj.Type <> vbext_ct_ResFile) Then
If IsThereCode(cmpObj.CodeModule) Then
bSomeCode = True
Exit For
End If
End If
Next
' *** If we didn't find any code, display a message and quit
If Not bSomeCode Then
MsgBox "The current project, " & prjProject.Name & ", does not contain any code"
Exit Sub
End If
' *** Store the currently active pane
RecoveActiveState "Store"
' *** Set some module-level variables to specify what to rebuild
m_sIndentType = "Project"
Set m_vbProjectObj = prjProject
Set m_vbCodemoduleObj = Nothing
Load frmProgress
frmProgress.Show
frmProgress.ZOrder
frmProgress.MessageText = "Indenting " & Chr$(13) & prjProject.Name
Call RebuildIndents
Unload frmProgress
Set frmProgress = Nothing
' *** Restore the currently active pane
RecoveActiveState "Restore"
End Sub
Public Function IsThereCode(vbCodemoduleObj As CodeModule) As Boolean
' #VBIDEUtils#************************************************************
' * Programmer Name : removed
' * Web Site : http://www.ppreview.net
' * E-Mail : removed
' * Date : 13/10/99
' * Time : 16:38
' * Module Name : IndentControl_Module
' * Module Filename : IndentControl.bas
' * Procedure Name : IsThereCode
' * Parameters :
' * vbCodemoduleObj As CodeModule
' **********************************************************************
' * Comments :
' *
' *
' **********************************************************************
Dim nI As Long
For nI = 1 To vbCodemoduleObj.CountOfLines
If Len(Trim$(vbCodemoduleObj.Lines(nI, 1))) > 0 Then
IsThereCode = True
Exit Function
End If
Next
IsThereCode = False
End Function
Private Sub RecoveActiveState(sType As String)
' #VBIDEUtils#************************************************************
' * Programmer Name : removed
' * Web Site : http://www.ppreview.net
' * E-Mail : removed
' * Date : 04/05/97
' * Time : 17:28
' * Module Name : IndentControl_Module
' * Module Filename : IndentControl.bas
' * Procedure Name : RecoveActiveState
' * Parameters :
' * sType As String
' **********************************************************************
' * Comments :
' *
' **********************************************************************
Static nStartLine As Long
Static nStartCol As Long
Static nEndline As Long
Static nEndCol As Long
Static nTop As Long
On Error GoTo ErrorHandler
With VBInstance.ActiveCodePane
If sType = "Store" Then
nTop = VBInstance.ActiveCodePane.TopLine
.GetSelection nStartLine, nStartCol, nEndline, nEndCol
Else
.TopLine = nTop
.SetSelection nStartLine, nStartCol, nEndline, nEndCol
End If
End With
Exit Sub
ErrorHandler:
Exit Sub
End Sub
Private Sub RebuildIndents()
' #VBIDEUtils#************************************************************
' * Programmer Name : removed
' * Web Site : http://www.ppreview.net
' * E-Mail : removed
' * Date : 04/05/97
' * Time : 17:29
' * Module Name : IndentControl_Module
' * Module Filename : IndentControl.bas
' * Procedure Name : RebuildIndents
' * Parameters :
' **********************************************************************
' * Comments :
' *
' *
' **********************************************************************
Dim cmp As VBComponent
Dim lLineCount As Long
Dim lLinesDone As Long
' *** Work out what needs to be done
Select Case m_sIndentType
Case "Procedure"
' *** Just rebuilding a procedure, so pass the procedure name and line boundaries
frmProgress.MessageText = "Indenting " & Chr$(13) & m_sIndentName
DoEvents
RebuildCodePanel m_vbCodemoduleObj, m_sIndentName, m_nStart, m_nEnd, 0, m_nEnd - m_nStart
Case "Module"
' *** Rebuilding a module, so pass the module name and number of lines therein
frmProgress.MessageText = "Indenting " & Chr$(13) & m_sIndentName
DoEvents
RebuildCodePanel m_vbCodemoduleObj, m_sIndentName, 1, m_vbCodemoduleObj.CountOfLines, 0, m_vbCodemoduleObj.CountOfLines - 1
Case "Project"
' *** Rebuilding a project, so we need to work out how many lines there are before doing the indenting
' *** Loop through the components, totalling their lines
On Error GoTo Exit_1
For Each cmp In m_vbProjectObj.VBComponents
If (cmp.Type <> vbext_ct_RelatedDocument) And (cmp.Type <> vbext_ct_ResFile) Then
If IsThereCode(cmp.CodeModule) Then ' *** removed, 05/11/1999 13:21:59 :
lLineCount = lLineCount + cmp.CodeModule.CountOfLines
End If
End If
Next
Exit_1:
' *** Now loop through the components to rebuild their indenting
On Error GoTo Exit_2
For Each cmp In m_vbProjectObj.VBComponents
If (cmp.Type <> vbext_ct_RelatedDocument) And (cmp.Type <> vbext_ct_ResFile) Then
If IsThereCode(cmp.CodeModule) Then
frmProgress.MessageText = "Indenting " & Chr$(13) & cmp.CodeModule.Parent.Name
DoEvents
' *** Pass the module name, number of lines, how many have been done already and how many are there in total
RebuildCodePanel cmp.CodeModule, cmp.CodeModule.Parent.Name, 1, cmp.CodeModule.CountOfLines, lLinesDone, lLineCount - 1
' *** Increment the number of lines done for next time round
lLinesDone = lLinesDone + cmp.CodeModule.CountOfLines
End If
End If
Next
Exit_2:
End Select
End Sub