Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Recent.bin editor
#1
I got bored so I wrote this simple utility to edit the qb64 file menu recent filename list:


Code: (Select All)
Rem Utility to edit recent history list in QB64.

Rem $dynamic

DefInt A-Z

Dim Shared RecentList(1) As String

ReDim RecentList(1024) As String

File$ = "c:\qb64pe\internal\temp\recent.bin"
Close
If _FileExists(File$) = 0 Then
    Open File$ For Output As #1
    Print #1, "": Print #1, ""
    Print "Recent.bin init."
End If
Close
Open File$ For Input As #1
Do
    If EOF(1) Then Exit Do
    Line Input #1, Line$
    Line$ = LTrim$(RTrim$(Line$))
    If Len(Line$) Then
        LineNum = LineNum + 1
        RecentList(LineNum) = Line$
    End If
Loop

Color 15
Print "Recent.bin loaded."

Do
    Color 15
    Print "Recent editor"
    Color 14
    Print "(A)dd to list"
    Print "(C)lear list"
    Print "(E)dit value"
    Print "(L)ist values"
    Print "(R)emove value"
    Print "(Q)uit and save"
    Color 15
    Print "Enter option?";
    Do
        _Limit 100
        Inp$ = InKey$
        If Len(Inp$) Then
            Inp$ = UCase$(Inp$)
            Select Case Inp$
                Case "A"
                    Print "A"
                    Print "Enter filename to add:"
                    Print "?";
                    Line Input Line$
                    If Len(Line$) Then
                        If _FileExists(Line$) Then
                            LineNum = LineNum + 1
                            RecentList(LineNum) = Line$
                            Print "Value added."
                        Else
                            Print "File not found."
                        End If
                    Else
                        Print "File not found."
                    End If
                    Exit Do
                Case "C"
                    Print "C"
                    LineNum = 0
                    Print "List Cleared."
                Case "L"
                    Print "L"
                    Found = 0
                    For Linen = 1 To LineNum
                        Count$ = LTrim$(Str$(Linen))
                        Print "("; Count$; ")"; RecentList(Linen)
                        Found = -1
                    Next
                    If Found = 0 Then
                        Print "No values found."
                    End If
                    Exit Do
                Case "E"
                    Print "E"
                    If LineNum > 0 Then
                        Count$ = LTrim$(Str$(Linen))
                        Print "Enter line to edit(1-"; Count$; ")";
                        Input Linen
                        If Linen > 0 And Linen <= LineNum Then
                            Print "Enter filename:"
                            Print "?";
                            Line Input Line$
                            If Len(Line$) Then
                                If _FileExists(Line$) Then
                                    RecentList(Linen) = Line$
                                    Print "Value edited."
                                Else
                                    Print "File not found."
                                End If
                            Else
                                Print "File not found."
                            End If
                        Else
                            Print "Value not found."
                        End If
                    Else
                        Print "No values found."
                    End If
                    Exit Do
                Case "R"
                    Print "R"
                    If LineNum > 0 Then
                        Count$ = LTrim$(Str$(LineNum))
                        Print "Enter line to remove(1-"; Count$; ")";
                        Input Linen
                        If Linen > 0 And Linen <= LineNum Then
                            For Linex = Linen To LineNum - 1
                                RecentList(Linex) = RecentList(Linex + 1)
                            Next
                            LineNum = LineNum - 1
                            Print "Value removed."
                        Else
                            Print "Value not found."
                        End If
                    Else
                        Print "No values found."
                    End If
                    Exit Do
                Case "Q"
                    Print "Q"
                    Print "Write recent.bin(y/n)? ";
                    Do
                        _Limit 100
                        Write$ = InKey$
                        If Len(Write$) Then
                            Print
                            Write$ = UCase$(Write$)
                            Exit Do
                        End If
                    Loop
                    If Write$ = "Y" Then
                        If LineNum = 0 Then
                            Print "No values written."
                        Else
                            Close
                            Open File$ For Output As #1
                            For Linen = 1 To LineNum
                                Print #1, ""
                                Print #1, RecentList(Linen)
                            Next
                            Print "Recent.bin written."
                        End If
                    End If
                    Color 7
                    End
            End Select
        End If
    Loop
Loop
End


Attached Files
.zip   Recent10.zip (Size: 5.32 KB / Downloads: 40)
Reply
#2
This looks like a job for VS GUI and the new Dialog Box for navigating and getting a filename so you don't have to type pathed file names.

Have you checked out this thread?
https://qb64phoenix.com/forum/showthread.php?tid=689
b = b + ...
Reply
#3
OK what a good way to screw up recent.bin!

For some reason all the "C:" are getting dropped, even when I add them back in when lost by _OpenFileDialog. IDE is doing something to lines with C: and they are getting dropped in the IDE's recent listing. Must be some special formatting.
b = b + ...
Reply
#4
btw: I found the array can be extended to almost any element but the recent list only displays the first 6 items.
maybe the QB64 editor crew could extend the list to some larger value such as 128 items!?

Erik.

(could not find "recent.bin" in qb64pe.bas)

Find attached the recent.bas with:
 New menu options:
  (S)ort list
  (U)pload list

-end-


Attached Files
.zip   Recent10.zip (Size: 5.32 KB / Downloads: 31)
Reply
#5
(03-31-2023, 01:18 PM)bplus Wrote: This looks like a job for VS GUI and the new Dialog Box for navigating and getting a filename so you don't have to type pathed file names.

Have you checked out this thread?
https://qb64phoenix.com/forum/showthread.php?tid=689

Actually I could add a DialogBox input filename but it is beyond the scope of this program.

Hope you like it!!

Erik.
Reply
#6
(04-01-2023, 02:03 AM)eoredson Wrote: btw: I found the array can be extended to almost any element but the recent list only displays the first 6 items.
maybe the QB64 editor crew could extend the list to some larger value such as 128 items!?

Erik.

(could not find "recent.bin" in qb64pe.bas)

Find attached the recent.bas with:
 New menu options:
  (S)ort list
  (U)pload list

-end-

With <= 6 entries in the recent list, the menu will show the entries and an additional "Clear recent" entry. As soon as the list get > 6 files the additional "Clear recent" will change into just "Recent..." and when you select that, an Dialogbox will pop up listing all files in the current recent list and give some editing options too.
Reply
#7
Well I think I have my GUI version working but for Windows only mainly due to fact I have to add C: to pathed files to match the IDE's pathed files so duplicate entries are avoided.

Apparently recent.bin requires a blank line before each pathed file entry ?? Thanks to reading over Eric's code I discovered this, so thanks Eric for idea to try this little exercise and figuring out recent.bin's format.

Here is code for the GUI (version GUIb) for the Editor:
Code: (Select All)
Option _Explicit '
_Title "Edit QB64 Recent Files GUIb" '  b+ started 2023-03-31

'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

' Windows only, mainly because GetBas$ adds a C: to the beginning of what _OpenFileDialog returns
' This matches the C: needed in the other IDE recent list to avoid duplicate listing.

' Edit the following path for recent.bin your QB64pe setup
Const RecentF$ = "C:\Users\Mark\Desktop\3_6 qb64pe_win-x64-3.6.0\qb64pe\internal\temp\recent.bin"

'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

'$include:'GUIb.BI'
ReDim Shared fList$(1 To 1024)
Dim Shared nLines
Dim Shared lstRecent$ '                  this is the long ~ delimited string for lstRecent control
Dim Shared Saved

'   Set Globals from BI
Xmax = 1220: Ymax = 680: GuiTitle$ = "Edit QB64 Recent Files GUIb"
OpenWindow Xmax, Ymax, GuiTitle$, "arial.ttf" ' before drawing anything from NewControl()

' GUI Controls
'                     Dim and set Globals for GUI app
Dim Shared As Long lstRecent, BInsert, BReplace, BAdd, BDelete, BSav, BExit
lstRecent = NewControl(3, 20, 40, 1180, 580, "", "Recent Files List")
BInsert = NewControl(1, 20, 640, 180, 24, "Insert at Highlight", "")
BReplace = NewControl(1, 220, 640, 180, 24, "Replace at Highlight", "")
BAdd = NewControl(1, 420, 640, 180, 24, "Add (to end)", "")
BDelete = NewControl(1, 620, 640, 180, 24, "Delete Highlighted", "")
BSav = NewControl(1, 820, 640, 180, 24, "Save", "")
BExit = NewControl(1, 1020, 640, 180, 24, "Exit", "")
' End GUI Controls

Saved = -1

Dim fl$
'          join array to long string delimited by ~ for lst control

Open RecentF$ For Input As #1 '            load the file into buf$
While Not EOF(1)
    Line Input #1, fl$
    fl$ = _Trim$(fl$)
    If fl$ <> "" Then
        nLines = nLines + 1
        fList$(nLines) = fl$
    End If
Wend
Close #1
lstRecent$ = Join$(fList$(), "~") '        join to long string
con(lstRecent).Text = lstRecent$ '         for lstRecent control
drwLst lstRecent '                         update the control with new list

' ready to edit
MainRouter ' _exit will exit mainRouter but now you must handle ending the program
checkSaved
System

Sub BtnClickEvent (i As Long)
    Dim As Long hiNum, j
    Dim f$, b$

    Select Case i
        Case BInsert
            f$ = GetBas$
            If f$ <> "" Then
                hiNum = LstHighliteNum&(lstRecent)
                If hiNum = 0 Then
                    lstRecent$ = f$ + "~" + lstRecent$
                Else
                    ReDim temp$(1 To 1)
                    Split lstRecent$, "~", temp$()
                    For j = LBound(temp$) To UBound(temp$)
                        If j = hiNum Then
                            If Len(b$) Then b$ = b$ + "~" + f$ Else b$ = f$
                        End If
                        If temp$(j) <> f$ Then ' don't add duplicates
                            If Len(b$) Then b$ = b$ + "~" + temp$(j) Else b$ = temp$(j)
                        End If
                    Next
                    lstRecent$ = b$
                End If
                con(lstRecent).Text = lstRecent$ '         for lstRecent control
                drwLst lstRecent '                         update the control with new list
                Saved = 0
            End If

        Case BReplace
            f$ = GetBas$
            If f$ <> "" Then
                hiNum = LstHighliteNum&(lstRecent)
                If hiNum = 0 Then ' just add it to top of list
                    lstRecent$ = f$ + "~" + lstRecent$
                Else
                    ReDim temp$(1 To 1)
                    Split lstRecent$, "~", temp$()
                    For j = LBound(temp$) To UBound(temp$)
                        If j = hiNum Then
                            If Len(b$) Then b$ = b$ + "~" + f$ Else b$ = f$
                        Else
                            If temp$(j) <> f$ Then
                                If Len(b$) Then b$ = b$ + "~" + temp$(j) Else b$ = temp$(j)
                            End If
                        End If
                    Next
                    lstRecent$ = b$
                End If
                con(lstRecent).Text = lstRecent$ '         for lstRecent control
                drwLst lstRecent '                         update the control with new list
                Saved = 0
            End If

        Case BAdd
            f$ = GetBas$
            If f$ <> "" Then
                ReDim temp$(1 To 1)
                Split lstRecent$, "~", temp$()
                For j = LBound(temp$) To UBound(temp$)
                    If temp$(j) <> f$ Then
                        If Len(b$) Then b$ = b$ + "~" + temp$(j) Else b$ = temp$(j)
                    End If
                Next
                lstRecent$ = b$
                lstRecent$ = lstRecent$ + "~" + f$
                con(lstRecent).Text = lstRecent$ '         for lstRecent control
                drwLst lstRecent '                         update the control with new list
                Saved = 0
            End If

        Case BDelete
            hiNum = LstHighliteNum&(lstRecent)
            If hiNum <> 0 Then
                ReDim temp$(1 To 1)
                Split lstRecent$, "~", temp$()
                For j = LBound(temp$) To UBound(temp$)
                    If j <> hiNum Then
                        If Len(b$) Then b$ = b$ + "~" + temp$(j) Else b$ = temp$(j)
                    End If
                Next
                lstRecent$ = b$
                con(lstRecent).Text = lstRecent$ '         for lstRecent control
                drwLst lstRecent '                         update the control with new list
                Saved = 0
            End If

        Case BSav
            saveWork

        Case BExit
            checkSaved
            System

    End Select
End Sub

Sub LstSelectEvent (control As Long)
    control = control
End Sub

Sub SldClickEvent (i As Long)
    i = i
End Sub

Sub PicClickEvent (i As Long, Pmx As Long, Pmy As Long)
    i = i: Pmx = Pmx: Pmy = Pmy
End Sub

Sub PicFrameUpdate (i As Long, MXfracW, MYfracH)
    i = i: MXfracW = MXfracW: MYfracH = MYfracH
End Sub

Sub LblClickEvent (i As Long)
    i = i
End Sub

Sub checkSaved
    Dim As Long ans
    If Saved = 0 Then
        ans = _MessageBox("Save Work?", "Do you want to save your changes to the Recent.Bin file?", "yesno", "question")
        If ans = 1 Then saveWork
    End If
End Sub

Sub saveWork ' assumes workfile <> "" and correct
    Dim As Long i
    ReDim lst(1 To 1) As String
    Split con(lstRecent).Text, "~", lst$()
    Open RecentF$ For Output As #1
    For i = 1 To UBound(lst$)
        Print #1, ""
        Print #1, _Trim$(lst$(i))
    Next
    Close #1
    Saved = -1
    _MessageBox "Saved:", RecentF$
End Sub

Function GetBas$
    Dim bas$
    bas$ = _OpenFileDialog$("Select a .bas file", "*.bas", "*.bas", "Basic file")
    If bas$ <> "" Then
        If Left$(bas$, 2) <> "C:" Then GetBas$ = "C:" + bas$ Else GetBas$ = bas$
    End If
End Function

'$include:'GUIb.BM'

   

BTW, _MessageBox is still screwing up titles in version 3.6, just test code in Windows.

Which is useless without the GUIb.BI and .BM and supplementary Fonts
So zip for this little project is here:


Attached Files
.zip   Edit QB64 Recent List GUIb.zip (Size: 571.28 KB / Downloads: 30)
b = b + ...
Reply
#8
Other files which can be edited are:

  Recent.bin
  Searched.bin
  Bookmarks.bin

where each one has a different file format.

Erik.
Reply
#9
(04-01-2023, 09:11 AM)bplus Wrote: Well I think I have my GUI version working but for Windows only mainly due to fact I have to add C: to pathed files to match the IDE's pathed files so duplicate entries are avoided.

Pretty good. I made it work in Linux by commenting out the last few lines in GetBas$() function (which force "C:" prefix) and just returning the local string variable's value.

Also had to turn RecentF$ into a global variable due to my decision to use ENVIRON$("HOME"), to make sure it works for any regular user on Linux. However still can't do anything about how he/she installs QB64PE...

On Windows could use ENVIRON$("USERPROFILE") to get "C:\Users\(username)", while on Linux the same thing is produced by ENVIRON$("HOME"). The problem is that it's a function which cannot be used with CONST, even though the function is returning a constant value out of another constant value.

One flaw with this system is that it requires fonts installed in a specific place. But which is good because various Linux distros have mind-boggling arrangements and don't neatly establish what the hey is "Monospace". In some configuration files a font is called differently from its filename which wastes time in investigative work and trial and error.
Reply
#10
That's great news that you could get it going in Linux.

When I let that paths thing go, not adding C:, it was taking duplicate files one with C and one without in Windows.
But there may have been a problem with the goofy format of Recent Files.Bin with black lines inserted between the file names.
b = b + ...
Reply




Users browsing this thread: 2 Guest(s)