Hello,
Is there a way to make a button to toggle "Show only modified files within 1 hour" for example?
Regards,
Atalay TAN
Hello,
Is there a way to make a button to toggle "Show only modified files within 1 hour" for example?
Regards,
Atalay TAN
To make the current filedisplay show only items that were modified within the last hour, you can use these commands:
The first tree lines are to be joined into one, I needed to break the command into separate lines for posting.
SelectEx SIMILARMETAJS="if (((new Date().valueOf()-new Date(item.modify).valueOf())/1000)<3600) return true;" DESELECTNOMATCH
Select NOPATTERN HIDEUNSEL
You need to install the SelectEx script add-in for the first command to work:
Toggling is another story, if you need help on this too, tell us.
Dear tbone,
Thank you, your code is working successfully. But I created a filter for files modified in 1 hour and I can get the same result with the below command:
Select Modifiedwithin1h FILTER FILTERFLAGS=hidenomatch
The problem is that I can't make it toggle. I would like it to come to the previous state with a second click.
Regards,
Atalay TAN
Using a filter is also a nice solution! Good find! o)
That seems to do the trick, just replace the SelectEx call with your Select FILTER statement.
@ifset:$src:HiddenItems
@set src:HiddenItems
Select NOPATTERN SHOWHIDDEN
@ifset:else
@set src:HiddenItems=1
SelectEx SIMILARMETAJS="if (((new Date().valueOf()-new Date(item.modify).valueOf())/1000)<3600) return true;" DESELECTNOMATCH
Select NOPATTERN HIDEUNSEL
I just don't know how to remove the src:HiddenItems indicator-variable when the folder is changed (without making use of some heavier scripting logic). It seems a temporary variable scope would be useful, that lasts as long as the path is not changed/refreshed. Leo, Jon? Listening? Here is something for a new beta-version! o))
Yes, exactly, thank you. We need a temporary variable. Your code meets my needs for now thank you very much.
I could't think to use local variable. I have made it toggle by using SORTBY argument but it was pointless to always change file sorting behaviour
@ifset:SORTBY=name
Select Modifiedwithin1h FILTER FILTERFLAGS=hidenomatch
Set SORTBY=modified
@ifset:else
Select NOPATTERN SHOWHIDDEN
Set SORTBY=name
From a script, one way you could do it without using a variable or event handlers, is to loop through the visible files and see if any do not match the filter.
If any visible file doesn't match the filter, you know the filter isn't being applied (or needs updating for new files), in which case the script can apply the filter.
If all visible files match the filter, you know that either the filter won't change anything (so it doesn't matter what happens), or the filter is already in effect, in which case the script should clear the filter.
Note that the item collections only return the visible items. (Visible as in they are in the file display. They may be scrolled out of view and not strictly visible on the screen.) So this would print out the names of currently visible files:
Option Explicit
Function OnClick(ByRef ClickData)
Dim fileItem
For Each fileItem In ClickData.Func.sourcetab.files
DOpus.Output fileItem.realpath
Next
End Function
I think that idea, combined with the things TBone already has in his script and above, should provide a route to making a toggle button for this kind of advanced filter.
(It's also worth noting that simple wildcard filters do not need all this complex stuff, and can act as toggles from a single-line command. This extra stuff is only needed for complex filters that do more than apply wildcards to the filenames.)
How can a script check if files match a predefined filter? You mean the "real" filters DO manages, don't you?
I was thinking of it for use with your SelectEx SIMILARMETAJS mode.
The word "filter" is a bit overloaded around here, I should've been more specific.
Ah ok, I just wondered if I missed something essential! o)
Well, I don't know what 0xt1n's opinion is, but I find suggested logic a bit too heavy and very specific for a good working toggle. I guess I would lean more towards that mentioned event-based approach, you also wouldn't loose the @toggle functionality. Because I had spare time at hands, I did AutoVars: Event: AutoVars (event-handling for variables)
@0xt1n
Maybe you like to try the add-in, install it and then just insert the lines using "src:HiddenItems.bfc.drop" like shown below.
This will result in a button that indicates your current filtering with a "pressed" button-look, which will magically dissapear once you leave/change the folder. o)
@toggle:if $src:HiddenItems
@ifset:$src:HiddenItems
@set src:HiddenItems
@set src:HiddenItems.bfc.drop
Select NOPATTERN SHOWHIDDEN
@ifset:else
@set src:HiddenItems=1
@set src:HiddenItems.bfc.drop=always
SelectEx SIMILARMETAJS="if (((new Date().valueOf()-new Date(item.modify).valueOf())/1000)<3600) return true;" DESELECTNOMATCH
Select NOPATTERN HIDEUNSEL
I installed your add-in and used the code above. It works perfectly. It shows the pressed and unpressed state of the filter in each folder tab. I put it on my file display toolbar for everyday use, thank you.
Thanks for your feedback and glad it works for you! o)