Jump to content

Recent File List in Menu


GEOSoft
 Share

Recommended Posts

I want to create a recent file list in a menu. I have one now but It's limited to the last 2 files.

With the existing function;

Selecting the second item in the Menu will reverse the two items and write the new order to an INI file.

A new File will remove the second Item, move the first tho second and then add the new file at the beginning

This all works fine.

What I want is to be able to have more than the two files in the list.

If a new file is opened then that file gets placed first and the rest shift down one and if the last is over the limit then remove it. No problem there.

If a previously opened file is selected then that item has to move to the the top of the list and the files the previously preceeded it in the list have to shift down as far as where the file used to be in the list. That shouldn't take much work.

Now it gets tougher.

I want to do this without having a lot of empty spaces in the menu in the event that the list is not full.

I have to add a menu item for each new file up to the maximum file limit (set in the INI)

Because of another function that dynamically creates controls I can't dynamically create these ones. When the other function is called it deletes any dynamically created controls and refreshes its own list. (perhaps I could also recrete the MenuItems at that point but that would be a clumsy workaround)

As far as I know MenuItems can be disabled but not hidden (which would be the way to go) so I'm looking for ideas.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

GEOSoft

Hi, i don't quite understand what yo trying to do - you want to create a list with recent files, but what are these recent files? like from windows's recent files?

And it will be much more efective to help you if you post some code (what you are have so far, and where you cab't do something).

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

GEOSoft

Hi, i don't quite understand what yo trying to do - you want to create a list with recent files, but what are these recent files? like from windows's recent files?

And it will be much more efective to help you if you post some code (what you are have so far, and where you cab't do something).

They could be files of several types but for the sake of discussion we'll say they are all au3 files.

I just need to Have a Menu called Recent Files and then separate menuItems for each file opened in the order that they were last opened starting with the most recent.. The number of files is variable depending on the user settings in the INI file although I'm setting a maximum of 10. It's easy to do using 10 Menu items and then GUICtrlSetData for each item but if there are 10 menuitems and only 3 file have been opened then you will end up with 7 menuitems with a blank string. That creates a menu with 3 items and a large empty space below. I'm trying to avoid that. GUICtrlSetState($I, $GUI_Hide) would would be good but I don't think that works on a menuitem.

To see what I want just take a look at the File menu of any MS Office product (and thousands of other apps).

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Credits - Holger

#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()
   
    Switch $msg
        Case $fileitem
            $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

        Case $viewstatusitem
            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
   
        Case $GUI_EVENT_CLOSE, $cancelbutton, $exititem
            ExitLoop
           
        Case $infoitem
            Msgbox(0, "Info", "Only a test...")
           
        Case Else
            For $i = 0 To $maxrecentfiles - 1
                If $msg > 0 And $msg = $recentfiles[$i][0] Then
                    $file = $recentfiles[$i][1] ; now you have the file that was clicked
                    Msgbox(0, "Open File", $file)
                    ExitLoop
                EndIf               
            Next
    EndSwitch
WEnd

GUIDelete()

Exit

8)

NEWHeader1.png

Link to comment
Share on other sites

Credits - Holger

8)

That looks promising. I'll play with it a bit. Thanks @Valuater

I think my other option was to go ahead and create them dynamicly. and then delete and re-create them as necessary. And without testing I'm not positive that they would have to be re-created when I called my other function because of the way I refresh those dynamic controls.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...