Skip to content

Commit

Permalink
Layers > Add > from File: now supports multiple files at once
Browse files Browse the repository at this point in the history
Select as many files as you want in the common dialog window, and PD will now add all of them in order above the currently active layer.

This can be used to e.g. create an animation from a list of static image files (first suggested in #487)
  • Loading branch information
tannerhelland committed Nov 14, 2023
1 parent 5b2ef73 commit ad020a5
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 112 deletions.
26 changes: 17 additions & 9 deletions Classes/pdStringStack.cls
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ Friend Function SerializeStackToSingleString() As String
'The first entry in the serialized string is always the string count
Dim finalString As pdString
Set finalString = New pdString
finalString.Append CStr(m_NumOfStrings)
finalString.Append Trim$(Str$(m_NumOfStrings))

Dim tstPipeString As String: tstPipeString = "|"
Dim rplPipeString As String: rplPipeString = "&pipe;"
Expand All @@ -674,7 +674,7 @@ Friend Function SerializeStackToSingleString() As String
For i = 0 To m_NumOfStrings - 1
finalString.Append tstPipeString
If (InStr(1, m_Strings(i), tstPipeString, vbBinaryCompare) <> 0) Then
finalString.Append Replace$(m_Strings(i), tstPipeString, rplPipeString, , , vbBinaryCompare)
finalString.Append Replace$(m_Strings(i), tstPipeString, rplPipeString, Compare:=vbBinaryCompare)
Else
finalString.Append m_Strings(i)
End If
Expand All @@ -698,20 +698,28 @@ Friend Function RecreateStackFromSerializedString(ByRef srcString As String) As
If (InStr(1, srcString, tstPipeString, vbBinaryCompare) <> 0) Then

Dim stringArray() As String
stringArray = Split(srcString, tstPipeString, , vbBinaryCompare)
stringArray = Split(srcString, tstPipeString, -1, vbBinaryCompare)

m_NumOfStrings = CLng(stringArray(LBound(stringArray)))
Dim localNumOfStrings As Long
localNumOfStrings = CLng(stringArray(LBound(stringArray)))

Dim i As Long
For i = 0 To m_NumOfStrings - 1
For i = 0 To localNumOfStrings - 1

If (InStr(1, stringArray(i + 1), rplPipeString, vbBinaryCompare) <> 0) Then
Me.AddString Replace$(stringArray(i + 1), rplPipeString, tstPipeString, , , vbBinaryCompare)
Else
Me.AddString stringArray(i + 1)
'Failsafe check only
If (i < UBound(stringArray)) Then
If (InStr(1, stringArray(i + 1), rplPipeString, vbBinaryCompare) <> 0) Then
Me.AddString Replace$(stringArray(i + 1), rplPipeString, tstPipeString, 1, -1, vbBinaryCompare)
Else
Me.AddString stringArray(i + 1)
End If
End If

Next i

'No pipe chars found! This must just be a single string; dump it into place as-is.
Else
Me.AddString srcString
End If

RecreateStackFromSerializedString = True
Expand Down
15 changes: 4 additions & 11 deletions Modules/FileMenu.bas
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ End Function

'Provide a common dialog that allows the user to retrieve a single image filename, which the calling function can
' then use as it pleases.
Public Function PhotoDemon_OpenImageDialog_Simple(ByRef userImagePath As String, ByVal ownerHwnd As Long) As Boolean
Public Function PhotoDemon_OpenImageDialog_SingleFile(ByRef userImagePath As String, ByVal ownerHwnd As Long) As Boolean

'Disable user input until the dialog closes
Interface.DisableUserInput
Expand All @@ -86,8 +86,9 @@ Public Function PhotoDemon_OpenImageDialog_Simple(ByRef userImagePath As String,
Dim tempPathString As String
tempPathString = UserPrefs.GetPref_String("Paths", "Open Image", vbNullString)

'Use Steve McMahon's excellent Common Dialog class to launch a dialog (this way, no OCX is required)
If openDialog.GetOpenFileName(userImagePath, , True, False, ImageFormats.GetCommonDialogInputFormats, g_LastOpenFilter, tempPathString, g_Language.TranslateMessage("Select an image"), , ownerHwnd) Then
'Launch a common dialog instance, but restrict multi-file selection.
PhotoDemon_OpenImageDialog_SingleFile = openDialog.GetOpenFileName(userImagePath, , True, False, ImageFormats.GetCommonDialogInputFormats, g_LastOpenFilter, tempPathString, g_Language.TranslateMessage("Select an image"), , ownerHwnd)
If PhotoDemon_OpenImageDialog_SingleFile Then

'Save the new directory as the default path for future usage
tempPathString = Files.FileGetPath(userImagePath)
Expand All @@ -96,14 +97,6 @@ Public Function PhotoDemon_OpenImageDialog_Simple(ByRef userImagePath As String,
'Also, remember the file filter for future use (in case the user tends to use the same filter repeatedly)
UserPrefs.SetPref_Long "Core", "Last Open Filter", g_LastOpenFilter

'All done!
PhotoDemon_OpenImageDialog_Simple = True

'If the user cancels the common dialog box, simply exit out
Else

PhotoDemon_OpenImageDialog_Simple = False

End If

'Re-enable user input
Expand Down
Loading

0 comments on commit ad020a5

Please sign in to comment.