Jump to content
Sign in to follow this  
BPBNA

Recent files menu

Recommended Posts

BPBNA

Hi, I'm trying to make a menu that shows recently opened files and of course displays the most recent at the top of the list. I can do it no problem when the most recent goes at the bottom, but I'm not sure how to make it only display a certain number. I've tried a few things, which I have since deleted so I cant post any code I've tried. Does anyone know how to do this? I tried to search for it but couldnt really find too much.

Even if you point me in the right direction it would be appreciated. All I need it to do it display the last 5 files opened with the most recent at the top.

Thanks!

Edit: I forgot to mention, this isn't just opening any files, its inside my GUI :whistle:

Edited by BPBNA

Share this post


Link to post
Share on other sites
Paulie

Hi, I'm trying to make a menu that shows recently opened files and of course displays the most recent at the top of the list. I can do it no problem when the most recent goes at the bottom, but I'm not sure how to make it only display a certain number. I've tried a few things, which I have since deleted so I cant post any code I've tried. Does anyone know how to do this? I tried to search for it but couldnt really find too much.

Even if you point me in the right direction it would be appreciated. All I need it to do it display the last 5 files opened with the most recent at the top.

Thanks!

Edit: I forgot to mention, this isn't just opening any files, its inside my GUI :whistle:

Well, post the code you have right now so far, and maybe we can make it display more like the way you describe, instead of starting from scratch.

You'll get more help if you do :)

Share this post


Link to post
Share on other sites
BPBNA

Case $msg = $parse
    $fileparse = FileOpenDialog("Choose file...",@ScriptDir & "\searches","INI File (*.ini)")
    If @error <> 1 then
        ParseFile(2)
    EndIf
    GUICtrlDelete($noneparse)
    $slash = StringInStr($fileparse, "\", 0, -1)
    $filerecent = StringTrimLeft($fileparse, $slash)
   ;The next 2 lines are my recent file menu now.  It only shows the last one opened
    If $rparse <> 0 then GUICtrlDelete($rparse)
    $rparse = GUICtrlCreateMenuItem($filerecent, $recentparse)
    GUICtrlSetState($close, $GUI_ENABLE)
    GUICtrlSetState($print, $GUI_ENABLE)
    $record = 1
    Dis_Enable()

Share this post


Link to post
Share on other sites
Holger

Small sample (modified help file sample):

#include <GUIConstants.au3>

GUICreate("My GUI menu",300,200)

Global $defaultstatus = "Ready"
Global $status
Dim $count = 0
Dim $lastindex = 0
Dim $maxrecentfiles = 5 ; max 5 recent files
Dim $recentfiles[$maxrecentfiles][2]

$filemenu = GUICtrlCreateMenu ("&File")
$fileitem = GUICtrlCreateMenuitem ("Open",$filemenu)
GUICtrlSetState(-1,$GUI_DEFBUTTON)
$helpmenu = GUICtrlCreateMenu ("?")
$saveitem = GUICtrlCreateMenuitem ("Save",$filemenu)
GUICtrlSetState(-1,$GUI_DISABLE)
$infoitem = GUICtrlCreateMenuitem ("Info",$helpmenu)
$exititem = GUICtrlCreateMenuitem ("Exit",$filemenu)
$recentfilesmenu = GUICtrlCreateMenu ("Recent Files",$filemenu,1)

$separator1 = GUICtrlCreateMenuitem ("",$filemenu,2)    ; create a separator line

$viewmenu = GUICtrlCreateMenu ("View",-1,1)  ; is created before "?" menu
$viewstatusitem = GUICtrlCreateMenuitem ("Statusbar",$viewmenu)
GUICtrlSetState(-1,$GUI_CHECKED)
$okbutton = GUICtrlCreateButton ("OK",50,130,70,20)
GUICtrlSetState(-1,$GUI_FOCUS)
$cancelbutton = GUICtrlCreateButton ("Cancel",180,130,70,20)

$statuslabel = GUICtrlCreateLabel ($defaultstatus,0,165,300,16,BitOr($SS_SIMPLE,$SS_SUNKEN))

GUISetState ()
While 1
    $msg = GUIGetMsg()
    
    If $msg = $fileitem Then
        $file = FileOpenDialog("Choose file...",@TempDir,"All (*.*)")
        If @error = 0 Then
            $found = 0
            For $i = 0 To $maxrecentfiles - 1
                If $file = $recentfiles[$i][1] Then
                    $found = 1
                    ExitLoop
                EndIf
            Next
            
            If Not $found Then
                $item = GUICtrlCreateMenuitem ($file,$recentfilesmenu,0)
                
                If $count > $maxrecentfiles - 1 Then
                    GUICtrlDelete($recentfiles[$lastindex][0])
                EndIf
                
                $recentfiles[$lastindex][0] = $item
                $recentfiles[$lastindex][1] = $file
                
                $lastindex = $lastindex + 1
                If $lastindex = $maxrecentfiles Then $lastindex = 0
                
                $count = $count + 1
            EndIf
        EndIf
    EndIf
    
    If $msg = $viewstatusitem Then
        If BitAnd(GUICtrlRead($viewstatusitem),$GUI_CHECKED) = $GUI_CHECKED Then
            GUICtrlSetState($viewstatusitem,$GUI_UNCHECKED)
            GUICtrlSetState($statuslabel,$GUI_HIDE)
        Else
            GUICtrlSetState($viewstatusitem,$GUI_CHECKED)
            GUICtrlSetState($statuslabel,$GUI_SHOW)
        EndIf
    EndIf
    
    If $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton Or $msg = $exititem Then ExitLoop
    If $msg = $infoitem Then Msgbox(0,"Info","Only a test...")
WEnd

GUIDelete()

Exit

Last file comes to top with:

GUICtrlCreateMenuItem($file,$recentfilesmenu,0)

If the same file is open (precheck) then no same menu item is created.

Share this post


Link to post
Share on other sites
BPBNA

Thanks! That worked. Now the problem I was alway having before when using an array in my Case structure in a GUI. If I use the following code to open the recent files(only the first one worked when i clicked on it) it just ends the script as soon as it runs through the first loop in the while loop. It for some reason assumes that $msg = $recentfiles[0][0] and trys to run ParseFile and can't because some variables are not set.

Case $msg = $recentfiles[0][0]
    ParseFile($recentfiles[0][1])
    $record = 1
    Dis_Enable()

What am I doing wrong?!

Share this post


Link to post
Share on other sites
BPBNA

^BUMP^

Still trying to get it to correctly open the files when I click on them in the recent files menu. Anyone have any ideas?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.