Jump to content
Sign in to follow this  
Champak

Recent Menu Update

Recommended Posts

Champak

I have a menu item that loads files and also updates a recent file menu, but it isn't working correctly. It will load and update, but after it updates once, the function doesn't work at all again...I can't even load a file.

Case $msg2 = $loadprogram
            ConsoleWrite(@CRLF & "Menu Clicked")
            If FileExists(@ScriptDir & "\Program") Then
                ;
            Else
                DirCreate(@ScriptDir & "\Program")
            EndIf
            $SaveProgram = FileOpenDialog("Program Loader", @ScriptDir & "\Program", "Program File (*.txt)")
            IniWrite($Where, 'Options', 'ProgramFile', $SaveProgram)
            MRUUpdate("HKEY_CURRENT_USER\SOFTWARE\H-Program", $SaveProgram, 10)
            ConsoleWrite($SaveProgram & @CRLF & $Where)
            $RemovePath = StringTrimRight(StringReplace($SaveProgram, @ScriptDir & "\Program\", ""), 4)
            GUICtrlSetData($ActiveProgram, $RemovePath)
            ConsoleWrite(@CRLF & $RemovePath & @CRLF)

            GUICtrlDelete($recentfilesmenu)
            
            $NFileLink1 = RegRead("HKEY_CURRENT_USER\SOFTWARE\IGNavProgram", "MRUList")


            $split = StringSplit($NFileLink1, "")
            Dim $log[UBound($split) ]
            For $logcount = 1 To UBound($split) - 1
                $log[$logcount] = RegRead("HKEY_CURRENT_USER\SOFTWARE\IGNavProgram", $split[$logcount])
            Next
            Dim $recent[UBound($split) ]
            $recentfilesmenu = GUICtrlCreateMenu("Recent Program", $programprogrammenu)
            For $recentcount = 1 To UBound($split) - 1
                $recent[$recentcount] = GUICtrlCreateMenuitem($log[$recentcount], $recentfilesmenu)
            Next        
            ConsoleWrite(@CRLF & "Success")

Any ideas?

Edited by Champak

Share this post


Link to post
Share on other sites
Champak

OK, I know that

GUICtrlDelete($recentfilesmenu)

is causing the main load function not to work anymore, although I don't understand why because I can still load files from the recent file list. But since it is causing the problem, how else would I accomplish what I want to do? At least this way, I totally get rid of the recent menu and then put in the new menu. What now anyone?

Thanks.

Share this post


Link to post
Share on other sites
Champak

Figured it out. I had to change the original array into a 2D array to insert the menu item number, and then add the rest of the stuff seen.

Global $RecentMenuLimit=3;If increases/decreases, must do the same with the Select Case load custom recent menus    
Global $count = RegRead("HKEY_CURRENT_USER\SOFTWARE\IGNavPOI\", "Count")
Global $lastindexcount = RegRead("HKEY_CURRENT_USER\SOFTWARE\IGNavPOI\", "LastIndexCount")  


$menu = GUICtrlCreateMenu("Menu")
    $Menu_LoadCustomPOI = GUICtrlCreateMenuItem("Load Custom POI", $Menu_POI)
    $NFileLink1 = RegRead("HKEY_CURRENT_USER\SOFTWARE\IGNavPOI", "MRUList")
    $split = StringSplit($NFileLink1, "")
    Dim $log[UBound($split)][2]
    For $logcount = 1 To UBound($split) - 1
        $log[$logcount][1] = RegRead("HKEY_CURRENT_USER\SOFTWARE\IGNavPOI", $split[$logcount])
    Next
    Dim $recent[UBound($split)][2]
    $recentfilesmenu = GUICtrlCreateMenu("Recent Items", $menu)
    For $i = 1 To UBound($split) - 1
        $recent[$i][0] = GUICtrlCreateMenuItem($log[$i][1], $recentfilesmenu, 0)
        $recent[$i][1] = $log[$i][1]
    Next
    If $recent[1][1] = "" Then Dim $recent[$RecentMenuLimit][2]


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;The following is In the loop Select Case
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


        Case $msg1[0] = $Menu_LoadCustomPOI
            If FileExists(@ScriptDir & "\POI") Then
                ;
            Else
                MsgBox(0, "Error", "POI Folder does not exist. One will be created now.")
                DirCreate(@ScriptDir & "\POI")
            EndIf
            $SavePOI = FileOpenDialog("POI Loader", @ScriptDir & "\POI", "POI File (*.txt;*.csv)")
            If @error = 0 Then
                $found = 0      
                For $i = 1 To $RecentMenuLimit - 1
                    If $SavePOI = $recent[$i][1] Then
                        $found = 1
                        ExitLoop
                    EndIf
                Next
                If $found = 0 Then
                    $RecentMenuItem = GUICtrlCreateMenuitem ($SavePOI, $recentfilesmenu, 0)
                    If $count > $RecentMenuLimit - 1 Then
                        GUICtrlDelete($recent[$lastindexcount][0])                      
                    EndIf
                   
                    $recent[$lastindexcount][0] = $RecentMenuItem
                    $recent[$lastindexcount][1] = $SavePOI
                   
                    $lastindexcount = $lastindexcount + 1
                
                    If $lastindexcount >= $RecentMenuLimit + 1 Then 
                        $lastindexcount = 1
                    EndIf
                    $count = $count + 1
                    IniWrite($Where, 'Settings', 'File', $SavePOI)
                    MRUUpdate("HKEY_CURRENT_USER\SOFTWARE\POI", $SavePOI, $RecentMenuLimit)
                    RegWrite("HKEY_CURRENT_USER\SOFTWARE\POI\", "Count", "REG_SZ", $count)
                    RegWrite("HKEY_CURRENT_USER\SOFTWARE\POI\", "LastIndexCount", "REG_SZ", $lastindexcount)
                    
                EndIf

                $RemovePath = StringTrimRight(StringReplace($SavePOI, @ScriptDir & "\POI\", ""), 4)
                GUICtrlSetData($ActivePOI, $RemovePath)
            EndIf

        ;Menu-Load recent custom POI
        Case $msg1[0] = $recent[1][0]
            IniWrite($Where, 'Settings', 'File', $recent[1][1])
            $RemovePath = StringTrimRight(StringReplace($recent[1][1], @ScriptDir & "\POI\", ""), 4)
            GUICtrlSetData($ActivePOI, $RemovePath)
        Case $msg1[0] = $recent[2][0]
            IniWrite($Where, 'Settings', 'File', $recent[2][1])
            $RemovePath = StringTrimRight(StringReplace($recent[2][1], @ScriptDir & "\POI\", ""), 4)
            GUICtrlSetData($ActivePOI, $RemovePath)
        Case $msg1[0] = $recent[3][0]
            IniWrite($Where, 'Settings', 'File', $recent[3][1])
            $RemovePath = StringTrimRight(StringReplace($recent[3][1], @ScriptDir & "\POI\", ""), 4)
            GUICtrlSetData($ActivePOI, $RemovePath)
Edited by Champak

Share this post


Link to post
Share on other sites
Champak

OK, so a new problem has raised its ugly head with this recent menu thing. The way the recent menu items are selected is causing a problem with the GUICtrlSetData. For whatever reason the GUICtrlSetData is setting regardless if the menu item is clicked, which is causing problems elsewhere in the app; because it is basically constantly setting nothing and erasing what should be there. Any ideas? ...for now I had to comment out the GUICtrlSetData.

EDIT: The case is being activated every loop without being clicked.

Case $msg1[0] = $recent[1][0]
            IniWrite($Where, 'Settings', 'File', $recent[1][1])
            $RemovePath = StringTrimRight(StringReplace($recent[1][1], @ScriptDir & "\POI\", ""), 4)
            GUICtrlSetData($ActivePOI, $RemovePath)
        Case $msg1[0] = $recent[2][0]
            IniWrite($Where, 'Settings', 'File', $recent[2][1])
            $RemovePath = StringTrimRight(StringReplace($recent[2][1], @ScriptDir & "\POI\", ""), 4)
            GUICtrlSetData($ActivePOI, $RemovePath)
        Case $msg1[0] = $recent[3][0]
            IniWrite($Where, 'Settings', 'File', $recent[3][1])
            $RemovePath = StringTrimRight(StringReplace($recent[3][1], @ScriptDir & "\POI\", ""), 4)
            GUICtrlSetData($ActivePOI, $RemovePath)oÝ÷ Ø l¢+-êÞi·­µêðk+hvayú%"(uæÚ²'¢~Ø^­çÙè¬zjmÊØb²f¤zÆ©äjºÚÊØ^²,Þ¡ûaz·z{fz{¥Ëm¢Þ½éízºè®Â¢Øb±¼ç$x"^­è¬jÇ¢wk£§v'ç¢×+y«^¶©äjºÚÉ«­¢+Ù±½°I¹Ñ5¹Õ1¥µ¥ÐôÐ)}ÉÉåMÉ É ÀÌØíɹаÅÕ½ÐìÅÕ½Ðì°Ä°´Ä°´Ä°´Ä°À°±Í¤íMÉ ¥Ñ¡É¥Ìͽ¹É½Ü)%ÉɽÈôÐQ¡¸¥´ÀÌØíɹÑlÀÌØíI¹Ñ5¹Õ1¥µ¥Ð¬ÅulÉt

If you look at post 4 you'll see where this part fits in; is there a better way to accomplish what I want here?

Edited by Champak

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.