@@ -20,23 +20,22 @@ Attribute VB_Exposed = False
2020'Last update: Trimmed fileName in MRU_AddNewFile, and deleted old XML file if Max limit changed.
2121'
2222'This class is responsible for the creation and maintenance of MRU or "Most Recently Used" lists.
23- ' It contains functionality for saving and loading MRU lists to files, and updating a single
24- ' menu array. The functionality can be further specialized if required.
23+ ' It contains functionality for saving and loading MRU lists to files, and updating a single
24+ ' menu array. The functionality can be further specialized if required.
2525'
26- 'Many thanks to Raj Chaudhuri for rewriting this class as a generic manager, so PD can now support recent file lists
27- ' in multiple places throughout the program.
26+ 'Many thanks to Raj Chaudhuri for rewriting this class as a generic manager, so PD can now support
27+ 'crecent file lists in multiple places throughout the program.
2828'
2929'Unless otherwise noted, all source code in this file is shared under a simplified BSD license.
3030' Full license details are available in the LICENSE.md file, or at https://photodemon.org/license/
3131'
3232'***************************************************************************
33- Option Explicit
34-
3533
36- 'These functions are used to shrink long path entries to a max number of characters. PhotoDemon exposes a global preference
37- ' for Recent File menus, and this API is used to shrink full-length paths as necessary to fit them within a menu.
34+ Option Explicit
3835
39- Private Const maxMRULength As Long = 64
36+ 'Long filenames (and/or paths, if the user selects that option in Tools > Preference) are automatically
37+ ' shrunk using PathCompact; this constant controls the maximum length, in characters.
38+ Private Const MAX_MRU_LENGTH_IN_CHARS As Long = 64
4039
4140'MRUlist will contain string entries of all the most recently used files
4241Private m_FileList() As String
@@ -47,8 +46,8 @@ Private m_NumEntries As Long
4746'PD's standard XML engine is used to write the recent file lists out to file
4847Private m_XMLEngine As pdXML
4948
50- 'The file where this class persistently stores its data. In PD, the path of this file is controlled by the global
51- ' preferences object (UserPrefs)
49+ 'The file where this class persistently stores its data. In PD, the path of this file is controlled by
50+ ' the preferences manager (UserPrefs)
5251Private m_XMLFilename As String
5352
5453'This class relies on a child class that implements that the IMRUList interface.
@@ -69,35 +68,31 @@ Private Function GetMRUCaption(ByRef newFile As String) As String
6968 If (UserPrefs.GetPref_Long("Core" , "MRU Caption Length" , 0 ) = 0 ) Then
7069 GetMRUCaption = Files.FileGetName(newFile)
7170 Else
72- GetMRUCaption = Files.PathCompact(newFile, maxMRULength )
71+ GetMRUCaption = Files.PathCompact(newFile, MAX_MRU_LENGTH_IN_CHARS )
7372 End If
7473
7574End Function
7675
7776'Return the actual file path at a given index
7877Public Function GetSpecificMRU (ByVal mIndex As Long ) As String
79-
80- If (mIndex <= m_NumEntries) And (mIndex >= 0 ) Then
78+ If (mIndex >= 0 ) And (mIndex <= m_NumEntries) Then
8179 GetSpecificMRU = m_FileList(mIndex)
8280 Else
8381 GetSpecificMRU = vbNullString
8482 End If
85-
8683End Function
8784
8885'Return a menu-friendly caption of a given index
89- Public Function GetSpecificMRUCaption (ByVal Index As Long ) As String
90-
91- If (Index <= m_NumEntries) And (Index >= 0 ) Then
92- GetSpecificMRUCaption = GetMRUCaption(m_FileList(Index))
86+ Public Function GetSpecificMRUCaption (ByVal mIndex As Long ) As String
87+ If (mIndex >= 0 ) And (mIndex <= m_NumEntries) Then
88+ GetSpecificMRUCaption = GetMRUCaption(m_FileList(mIndex))
9389 Else
9490 GetSpecificMRUCaption = vbNullString
9591 End If
96-
9792End Function
9893
99- 'Return the path to an MRU thumbnail file. (PD uses PNGs only, but any valid image format should technically work. )
100- Public Function GetMRUThumbnailPath (ByVal Index As Long ) As String
94+ 'Return the path to an MRU thumbnail file (if one exists; PD does not currently support this for macros )
95+ Public Function GetMRUThumbnailPath (ByVal mIndex As Long ) As String
10196
10297 GetMRUThumbnailPath = vbNullString
10398
@@ -106,7 +101,7 @@ Public Function GetMRUThumbnailPath(ByVal Index As Long) As String
106101
107102 'Ignore thumbnail requests if the current list is empty
108103 If (m_NumEntries > 0 ) Then
109- If (Index >= 0 ) And (Index <= m_NumEntries) Then GetMRUThumbnailPath = m_MRUList.GetThumbnailPath(Me, Index )
104+ If (mIndex >= 0 ) And (mIndex <= m_NumEntries) Then GetMRUThumbnailPath = m_MRUList.GetThumbnailPath(Me, mIndex )
110105 End If
111106
112107 End If
@@ -130,12 +125,12 @@ Public Sub MRU_LoadFromFile()
130125 End If
131126
132127 'Allow the child to run any required initialization steps
133- Dim Cancel As Boolean
134- Cancel = False
135- m_MRUList.BeforeListLoad Me, Cancel
128+ Dim childCanceled As Boolean
129+ childCanceled = False
130+ m_MRUList.BeforeListLoad Me, childCanceled
136131
137132 'If something goes wrong, the child is allowed to abort the load process. Do not proceed if cancellation was requested.
138- If Cancel Then Exit Sub
133+ If childCanceled Then Exit Sub
139134
140135 'We are now ready to load the actual MRU data from file.
141136
@@ -186,16 +181,13 @@ End Sub
186181'Save the current MRU list to file (currently done at program close)
187182Public Sub MRU_SaveToFile ()
188183
189- Dim Cancel As Boolean
190- Cancel = False
184+ Dim saveCancel As Boolean
185+ saveCancel = False
191186
192187 'Allow the child to do any necessary prep work. They can cancel this operation; if they do, the file will not be saved.
193- m_MRUList.BeforeListSave Me, Cancel
194- If Cancel Then Exit Sub
188+ m_MRUList.BeforeListSave Me, saveCancel
189+ If saveCancel Then Exit Sub
195190
196- 'Since the switch to pdFSO for file operations, we should no longer experience write errors, but better safe than sorry
197- On Error GoTo MRUSaveFailure
198-
199191 'Reset whatever XML data we may have stored at present - we will be rewriting the full MRU file from scratch.
200192 ResetXMLData
201193
@@ -222,9 +214,6 @@ Public Sub MRU_SaveToFile()
222214 'Allow the child to perform any post-save cleanup
223215 m_MRUList.AfterListSave Me
224216
225-
226- MRUSaveFailure:
227-
228217End Sub
229218
230219'Add another file to the MRU list
@@ -234,10 +223,10 @@ Public Sub MRU_AddNewFile(ByVal newFile As String, Optional ByRef srcImage As pd
234223 newFile = Strings.TrimNull(newFile)
235224
236225 'Allow the child to perform any necessary UI prep work. The child also has the option to cancel this operation.
237- Dim Cancel As Boolean
238- Cancel = False
239- m_MRUList.BeforeFileAdded Me, newFile, Cancel
240- If Cancel Then Exit Sub
226+ Dim childCancel As Boolean
227+ childCancel = False
228+ m_MRUList.BeforeFileAdded Me, newFile, childCancel
229+ If childCancel Then Exit Sub
241230
242231 'Locators are used to determine if this file already exists in the recent files list.
243232 ' If it does, we will simply shuffle its position instead of adding it as a new entry.
@@ -376,4 +365,3 @@ Public Sub InitList(specificList As IMRUList)
376365 'If an XML file exists, it will be loaded separately, by the MRU_LoadFromFile() function
377366
378367End Sub
379-
0 commit comments