Jump to content

ChooseFileFolder - Interim Version 11 Mar 21


Melba23
 Share

Recommended Posts

1 hour ago, Melba23 said:

No need for BitOR when setting the $iDisplay parameter - simple addition will suffice.

Well, i prefer to code properly to avoid as much as possible those simple mistakes, because we have other places in code where things get complicated.

BTW, i would use User Constant in the UDF:

Global Enum Step *2 _
    $CFF_FLDRTREE = 0, $CFF_FLDRTREENOSUBFLDRS = 1, $CFF_FLDRTREENOFILES = 2, $CFF_NOHIDFILES, _
    $CFF_NOSYSFILES, $CFF_SELECTABLE, $CFF_DUPSEL, $CFF_NOFILEEXT, $CFF_SCRLTOFRSTFILE, _
    $CFF_SHOWSPLASH, $CFF_RETDEEPONLY, $CFF_DRVLSTRFRSH, $CFF_SHOWICONS

And also i suggest to use real constants instead of "magic numbers" inside UDF.

 

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

  • Moderators

MrCreator,

Using simple addition when the author has set suitable values for the various constants is not, IMO, "improper coding", but there we can perhaps agree to differ. And having some "magic numbers" in the UDF follows my long established practice of keeping required include files to a minimum, especially when only a few of the values within them are needed.

However, I do like your suggestion of naming the various $iDisplay values - thanks for the suggestion.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Hi all,

Another Beta version with (I think) all of the recent suggestions incorporated - well, at least the ones I accepted! I would be grateful for any testing and comments:

 

M23

Edited by Melba23
Beta code removed

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

It works perfect for me. (I did not test too much. just $hParent stuff)

 

Saludos

Link to comment
Share on other sites

Thanks for a great library Melba23!

I have started writing a few little tools to automate some repetitive tasks for staff at work. But I got a bit stuck on something...

One of the scripts I've written has a treeview embedded in a GUI using _cff_embed - the same GUI also has a couple of other controls for inputting data (just a text input and a checkbox in this case). 

Ideally I'd like to validate those fields before going on and performing the actions on the folders the user selected in the treeview; problem is that as soon as those folders are returned the GUI closes - so I can validate the data and if it fails validation, my only option seems to be to to MsgBox an alert to say why the validation failed, then exit the script and make the user run it again. Is there a simple way to validate the data and then leave the GUI open if it fails?

The other minor quibble I have is that by default, in a GUI using _cff_embed the 'x' button doesn't actually work to close the GUI and the normal method of polling the GUI for events and catching the $GUI_EVENT_CLOSE event doesn't work. I dug into the au3 and can see that this is already being done there so it seems like I have to extend that function somehow. My googling made me think think I might need to write my own WM_NOTIFY function but I could be completely off base?

Sorry for the silly questions. I have been using AutoIT on and off for years and have always been able to cobble things together and make it do what I need, but this one's over my head right now. 

Edited by CrshOverride
Link to comment
Share on other sites

  • Moderators

CrshOverride,

Welcome to the AutoIt forums.

I am delighted that you find my UDF useful - and sorry that you appear to have run into some problems using it. But I do not understand the problem that you have with the GUI closing when you return from the _CFF_Embed call - the UDF does nothing to close the main GUI at that point, all it does is delete the TreeView content which can be restored without problem. In fact the Example_3 script in the UDF zip shows 3 embedded TreeViews operating within the main GUI which remains open until it is deliberately closed by the user. I attach a simple example showing how I would use the function, check the results and the GUI content and loop until everything is good ( which means: a file selected + some content in the input + checkbox NOT checked).

And you are correct that when the _CFF_Embed function is running the main GUI [X] is ignored - you need to end the function using {ESC} before the main GUI becomes active again. I can easily add something to the function to look for that event and return immediately setting a suitable @error value which will allow the user to exit the script. I have added some suggested code in the example script - but of course it does not work at the moment as the current UDF does not return the @error value!

Here is the example script:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

#include <ChooseFileFolder.au3>

$hGUI = GUICreate("Test", 500, 500)
GUISetBkColor(0xC4C4C4)

$cTV = GUICtrlCreateTreeView(250, 10, 200, 400)

$cInput = GUICtrlCreateInput("", 10, 10, 200, 20)

$cCheckbox = GUICtrlCreateCheckbox("Test", 10, 100, 200, 20)

$cLoad = GUICtrlCreateButton("Load Tree", 10, 190, 80, 30)

GUISetState()

; Register UDF message handler
_CFF_RegMsg()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cLoad

            While 1

                $sRet = _CFF_Embed($cTV)

                ; THIS DOES NOT WORK WITH THE CURRENT UDF - IT IS A SUGGESTION FOR HOW IT MIGHT BE INCORPORATED
                ; Check for $GUI_EVENT_CLOSE detected by the function
                If @error = 99 Then
                    ; Specific error code detected- so the user can exit directly
                    Exit
                EndIf
                ; END OF SUGGESTION

                ; Now do your validation
                If $sRet = "" Then
                    MsgBox($MB_SYSTEMMODAL, "Ooops!", "No file selected!")
                    ; In each of these fail cases the tree reopens
                ElseIf GUICtrlRead($cInput) = "" Then
                    MsgBox($MB_SYSTEMMODAL, "Ooops!", "No base input selected!")
                ElseIf GUICtrlRead($cCheckbox) = $GUI_CHECKED Then
                    MsgBox($MB_SYSTEMMODAL, "Ooops!", "Checkbox was checked!")
                Else
                    ; All good so carry on
                    ExitLoop
                EndIf

            WEnd

            If MsgBox($MB_SYSTEMMODAL + $MB_YESNO, "All good!", "Close GUI?") = $IDYES Then
                Exit
            EndIf

    EndSwitch

WEnd

I hope this helps - if not then I have to assume there is something in your code which is closing your GUI - so can you please post your script, or a simplified version of it so that I can take a look.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thankyou so much for that @Melba23 - and you have absolutely no need to be sorry, it's not a problem with your UDF at all, just with my implementation of it :)

So I wasn't actually firing _CFF_Embed from within a loop... which now seems painfully obvious that was why it was just exiting as soon as some folders had been selected, so I feel pretty silly for that, but there it is. That's kinda what I get for copying and pasting from the example scripts without really understanding properly. As soon as I started firing it from within a loop, that fixed the issue with it closing if the validation failed. 

 

The only problem that I then had was that the treeview didn't retain the preselected items after a refresh. In my use case, it's a treeview for a user to select folders (using checkboxes) to archive into a zip file, and by default I have all the folders in the script directory selected using _CFF_SetPreCheck - but if I deselected a few, and deliberately failed a validation check, the treeview refreshed with nothing selected/checked. I racked my brains for a while and tried a bunch of stuff to figure out why this was the case, as it looks from the au3 that when the GUI returns $cReturn it is supposed to be repopulating the precheck list, but it didn't seem to work? After a while I gave up troubleshooting it, got hacky and just added another call to _CFF_SetPreCheck at the end of that section of the au3 - which seems to work. So now around line 1370 it's 

; Reset precheck array as required
$g_aCFF_PreCheck = $g_aCFF_PreCheckRetain
_CFF_SetPreCheck(StringSplit(StringTrimRight($sAddFile_List, 1), "|", 2)) ; My addition
; Return list of files selected
Return SetError(0, $iRet_Pressed, StringTrimRight($sAddFile_List, 1))

Maybe there was a better way to fix it, I don't know.... I'm not sure why it wasn't working - your example script above seems to behave in exactly the same way (the only thing I changed was adding the checkbox flag to the treeview).

As far as the X button stuff goes, that works perfectly, thankyou. I just added a section to the au3 to return an error code of 999 when the X was pressed, and caught it in my script. I figured out that I could've just as easily just exited the GUI from within the .au3 too - although I guess your way is probably neater because it lets the user decide if they want to enable that X or not. In my case these scripts I've been writing are aimed at automating some repetitive tasks for some pretty non-tech savvy users so I need to give them a way to back out of it if they open the app by mistake or something.

Link to comment
Share on other sites

  • Moderators

CrshOverride,

Glad you got it working, but you have the "retain" problem because you are not clearing the default $bVolatile flag when using the _CFF_SetPreCheck function - so the UDF does not retain the precheck list between runs. I notice that although this parameter exists in the UDF code, the function header syntax was not amended to explain the new functionality - which may be why you missed it. The amended header should have read:

; #FUNCTION# =========================================================================================================
; Name...........: _CFF_SetPreCheck
; Description ...: Sets a list of files/folders which will be checked when expanded
; Syntax.........: _CFF_SetPreCheck ($aPreCheck_List [, $bNoPartial = True [, $bVolatile = True]])
; Parameters ....: $aPreCheck_List - Array holding paths of files/folders to check on expansion (or non-array to clear)
;                  $bNoPartial     - True (default) = partial paths removed from list
;                                    False = List untouched
;                  $bVolatile      - True (default) = List cleared after call to _CFF_Choose/Embed
;                                    False =  List remains active for future calls
; Requirement(s).: v3.3 +
; Return values .: 1 = Precheck list set
;                  0 = Precheck list cleared
;                  @extended = 0 - Precheck list volatile
;                              1 - Precheck list retained
; Author ........: Melba23

So try clearing the flag when calling the function:

_CFF_SetPreCheck(StringSplit(StringTrimRight($sAddFile_List, 1), "|", 2), True, False)

That works for me when I call the function in the main script just the once before entering the idle loop (i.e. not inside the UDF itself) - can you please check it does so for you too. I have amended the function header in the new Beta on which I have been working, so the next release will be up-to-date. 

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Oh, I wish it was that simple... I noticed that flag in the doco and tried it already :)

The relevant snippet looks like this:

; Get list of the subfolders
Global $checked = _FileListToArrayRec(@ScriptDir, "*", $FLTAR_FOLDERS, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_FULLPATH)
;remove the first element
_ArrayDelete($checked, 0)

;Precheck directories
_CFF_SetPreCheck($checked, True, False)

While 1

    $sRet = _CFF_Embed($cTreeView, @ScriptDir, "*", 2 + 4 + 8 + 1024, $cReturn)

    If @error = 999 Then
        Exit
    EndIf
    
    ;Strip illegal characters from filename, check if file already exists
    Local $file = StringRegExpReplace(GUICtrlRead($outfile), '\\|/|:|\*|\?|\"|\<|\>|\|', "_") & ".zip"
    Local $iFileExists = FileExists(@ScriptDir & "\" & $file)

    If $sRet = "" Then
            ;Error out if no folders selected
            MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "No folders selected", "You didn't select any folders to archive.")
        ;Error out if filename is blank
    ElseIf GUICtrlRead($outfile) = "" Then
        MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "No filename", "You must enter a filename")
        ;Error out if the file already exists
    ElseIf $iFileExists Then
        MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "File exists", "A file with the same name already exists.")
    Else
        ArchiveFolders()
        Exit
    EndIf
WEnd

 

With the non-amended au3, if the volatile flag is set to False as above, if any of the validation checks fail it just prechecks all the directories again on each refresh, so the user's selections / deselections are discarded.

Edited by CrshOverride
Link to comment
Share on other sites

  • Moderators

CrshOverride,

Ah, retaining the user selections is a different kettle of fish from retaining the PreCheck list. However, the UDF can already do this when refreshing the drive list using _CFF_Refresh so I hope it will not be too difficult to get it working in this case too - possibly famous last words!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

CrshOverride,

Try using this Beta version and see if it works as you wish. Setting the new $CFF_RETAINUSERSEL (4096) parameter in $iDisplay means that the current user selections will replace any previous list of PreCheck items. So something like this pseudo-code will be needed:

; Set initial PreCheck items

; Start loop

    ; Call _Embed with the $CFF_RETAINUSERSEL parameter
    
    ; Do the checks you need
    
    ; If successful then
    
        ; Reset the intial Precheck items so they will be used for the next new _Embed call
        ; Exit the loop
        
    ; If not then the current user selections will be retained for the _EMBED call in the loop
    
        
; Loop

As you exit the script directly the checks are good, all you should need to do in your script is call the _Embed function like this:

$sRet = _CFF_Embed($cTreeView, @ScriptDir, "*", 2 + 4 + 8 + 1024 + 4096, $cReturn)

and use this Beta UDF: 

I hope it works for you as well as it does for me.

M23

P.S. This Beta now returns "9999" when the main GUI [X] is actioned, so you will also need to change that.

Edited by Melba23
Beta code removed

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

2 hours ago, Melba23 said:

CrshOverride,

Ah, retaining the user selections is a different kettle of fish from retaining the PreCheck list. However, the UDF can already do this when refreshing the drive list using _CFF_Refresh so I hope it will not be too difficult to get it working in this case too - possibly famous last words!

M23


Cool beans - thanks Melba23 - looks like I wasn't very clear in my explanation, sorry about that.

I have got it all working pretty well now using my modifications but I'll try and give the beta UDF a go over the next couple of days. I appreciate you implementing these little additions, hopefully they'll be useful to others in future as well :)

Link to comment
Share on other sites

Well, I tried the beta UDF, and while the returning 9999 to close on X works fine, the user selections still didn't seem to be retained after a refresh.... it still refreshed with either a blank selection (if I hadn't prechecked anything, or had the prechecked items list set to volatile), or refreshed with everything selected (if I had the prechecked items set to non-volatile). I definitely had the $CFF_RETAINUSERSEL (4096) flag enabled. 

Not to worry....

Link to comment
Share on other sites

  • Moderators

CrshOverride,

Oh dear - back to the drawing board then. Thanks for the report.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

CrshOverride,

The "retain user selections" functionality definitely works for me when I test. Could you please post a reproducer script which shows the UDF failing so that I can see if you are doing something different?

If anyone else wants to try out the new functionality then here is my example script - just add some of your own files to the PreCheck list, run the script and select some other files, and then when the MsgBox appears click "Yes" to reload the UDF. I see the user selections reset when the TreeView reloads:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

#include <ChooseFileFolder_Mod.au3>

$hGUI = GUICreate("Test", 500, 500)
GUISetBkColor(0xC4C4C4)

$cTV = GUICtrlCreateTreeView(250, 10, 200, 400, BitOR($GUI_SS_DEFAULT_TREEVIEW, $TVS_CHECKBOXES))

$cLoad = GUICtrlCreateButton("Load Tree", 10, 10, 100, 30)

$cReturn = GUICtrlCreateButton("Return Selection", 10, 110, 100, 30)

GUISetState()

; Register UDF message handler
_CFF_RegMsg()

Global $aPreCheck_List[] = ["Full_File_Path"] ; Add your files here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
_CFF_SetPreCheck ($aPreCheck_List)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cLoad

            While 1

                $sRet = _CFF_Embed($cTV, Default, Default, $CFF_ONLYRETDEEPEST + $CFF_RETAINUSERSEL, $cReturn)
                
                If @error = 9999 Then
                    Exit
                EndIf

                If MsgBox($MB_SYSTEMMODAL + $MB_YESNO, "Ready?", "Reload TreeView?") = $IDNO Then
                    ExitLoop
                EndIf

            WEnd

    EndSwitch

WEnd

And here is the latest UDF Beta: 

Looking forward to any comments.

M23

 

Edited by Melba23
Beta code removed

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Hi Melba23

It still doesn't work... I haven't had a look at the au3 yet but the only thing I'm doing differently is I'm not using a button to trigger the reload of the treeview. All I'm doing is having it fail validation. So for example in the below script, if the filename is not set, or if there's already a zip file with that name in the script directory, it'll avoid triggering the ArchiveFolders() function and go back to allowing the user to select folders. 

Code is below (sans the ArchiveFolders() function, I didn't think that was relevant)....  maybe I'm doing something dumb.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=icons8-clock-128.ico
#AutoIt3Wrapper_Compression=1
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <Array.au3>
#include <File.au3>
#include <Date.au3>
#include "ChooseFileFolder_Mod_2.au3"
#include "_Zip.au3"

Local $sRet, $aRet

; Register handler
_CFF_RegMsg()

; Get the date for the default file name
Local $now = StringReplace(_NowCalcDate(), "/", "-")

; Create GUI
$hGUI = GUICreate("Timesheet Folder Archiver", 250, 440, -1, -1)
GUICtrlCreateLabel("Select folders to archive:", 10, 10)
$cTreeView = GUICtrlCreateTreeView(10, 30, 230, 280, $TVS_CHECKBOXES)
GUICtrlCreateLabel("Choose name for archive: ", 10, 312)
Local $outfile = GUICtrlCreateInput("Timesheets-" & $now, 10, 330, 180, 20)
GUICtrlCreateLabel(".zip", 190, 334)
$cEmpty = GUICtrlCreateCheckbox("Empty directories after archiving? ", 15, 360, $BS_LEFT)
GUICtrlSetState(-1, $GUI_CHECKED)
$cReturn = GUICtrlCreateButton("Go!", 85, 390, 80, 30)
;$cRefresh = GUICtrlCreateDummy()
GUISetState()

; Get list of the subfolders
Global $checked = _FileListToArrayRec(@ScriptDir, "*", $FLTAR_FOLDERS, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_FULLPATH)
;remove the first element
_ArrayDelete($checked, 0)

;Precheck directories
_CFF_SetPreCheck($checked, True)

While 1

    $sRet = _CFF_Embed($cTreeView, @ScriptDir, "*", 2 + 4 + 8 + 4096, $cReturn)

    If @error = 9999 Then
        Exit
    EndIf

    ;Strip illegal characters from filename, check if file already exists
    Local $file = StringRegExpReplace(GUICtrlRead($outfile), '\\|/|:|\*|\?|\"|\<|\>|\|', "_") & ".zip"
    Local $iFileExists = FileExists(@ScriptDir & "\" & $file)

    If $sRet = "" Then
            ;Error out if no folders selected
            MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "No folders selected", "You didn't select any folders to archive.")
        ;Error out if filename is blank
    ElseIf GUICtrlRead($outfile) = "" Then
        MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "No filename", "You must enter a filename")
        ;Error out if the file already exists
    ElseIf $iFileExists Then
        MsgBox($MB_SYSTEMMODAL + $MB_ICONINFORMATION, "File exists", "A file with the same name already exists.")
    Else
        ArchiveFolders()
        Exit
    EndIf
WEnd

 

Link to comment
Share on other sites

  • 2 months later...
  • Moderators

CrshOverride,

My most sincere apologies - i have just noticed that I have not replied to your last post from a month ago!

But as your script works perfectly for me I am not sure quite what benefit an earlier reply would have brought. I can uncheck any number of the boxes that are prechecked in your script and, if the check fails, the TreeView reloads with those same boxes unchecked. So I cannot really help any further as without being able to reproduce your problem I cannot do any debugging. Sorry.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 7 months later...

@Melba23 - Thanks for your UDF. Giving it the once over for the first time, to probably pinch most of it ... feeling too lazy to reinvent the wheel, especially when you have a done a much better job than I ever would. As it is I might need to seek medical attention after studying your code ... my poor simple brain. :lol:

Anyway just noticed this little textual only error.

_CFF_Check_Valid name used for the __CFF_Check_Selection function in the #INTERNAL_USE_ONLY# comments.

EDIT

And another - _CFF_Combo_Fill instead of __CFF_Fill_Combo

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

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...