Button to toggle sort by

Hi, is there a way to create a button that toggles between sorting by date modified and name, so I don't have to create 2 separate buttons for each

something that toggles between these 2 commands automatically so I can assign it to a single hotkey:

Set SORTBY=modified
Set SORTBY=name

Thanks!

This is very simple:

<?xml version="1.0"?>
<button backcol="none" display="label" textcol="none" type="three_button">
	<label>Neuer Schalter</label>
	<icon1>#newcommand</icon1>
	<button backcol="none" display="label" textcol="none">
		<label>Sortby Modified</label>
		<tip>Sort by Modified</tip>
		<icon1>#newcommand</icon1>
		<function type="normal">
			<instruction>Set Sortby=Modified</instruction>
			<instruction>Set Sortreverse=On </instruction>
		</function>
	</button>
	<button backcol="none" display="label" textcol="none">
		<label>Sortby Name</label>
		<tip>Sort by Name</tip>
		<icon1>#newcommand</icon1>
		<function type="normal">
			<instruction>Set Sortby=name</instruction>
			<instruction>set Sortreverse=On</instruction>
		</function>
	</button>
</button>

Abr's XML is for a three-button where left-click sorts by Modified and right-click sorts by Name.

If you want a single toggle button (or hotkey), use this command instead (requires Opus 10):

@ifset:SORTBY=name
Set SORTBY=modified
@ifset:else
Set SORTBY=name

I'm been using this as a custom command for the double-click on file display background which saves me lot of time and clicks. They only issue I have is knowing which sort is in effect while in thumbnail mode. I'm making a feature request to add "currently sorted field" to the status bar code list, along with possibly an up/down arrow to indicate sort order.

1 Like

You can see what sort is in effect in thumbnail mode and you can also click on a field to change the sort mode.


Regards, AB

Wow--thanks. How did I not notice that?

In my experience Opus is full of useful things that are easy to miss simply because there are so many of them. There's probably a term for this condition.... Feature Blindness!

Regards, AB :smiley:

Hi guys. I made my two sort-buttons working BUT they stop working as soon as I disable the Type/Modified columns as you can see in this GIF:

The whole idea of having these buttons was, to save some space because I actually don't need to see the modified date and/or the type. I just want to be able to quickly sort.

Do you guys know, how I can sort without having to show the type/modified columns?

The columns need to be visible to sort by them. You can make it so the buttons add and remove the columns so you only have them there when sorting by them, if that would solve things.

That would help a lot! I've problems finding the command to show/hide problems with Google and I'm not sure if this is the correct way to go: https://www.gpsoft.com.au/help/opus12/index.html#!Documents/Scripting/ScriptColumn.htm

It looks a bit too complex. Looking at the sort-command "Set Sortby=Modified" I expected something like "Show Column=Type" or similar?

Do you know how I can show/hide the type/modified-columns?

The function you need depends on exactly how you want it to work; here are two options:

The first version assumes you will be removing the type column by right-clicking on it as shown in your animation, rather than using the button. The button adds the column if it's not there, and then sorts by it.

  • If type column is visible, sort by type column
  • If type column isn't visible, display and sort by type column
@toggle:if set SORTBY=type
@if:set COLUMNSTOGGLE=type 
set SORTBY=type 
@if:else
set COLUMNSADD=type SORTBY=type

The second version will toggle the column on and off entirely from the button.

  • If type column is visible, remove it and sort by name
  • If type column isn't visible, display and sort by type column
@toggle:if set COLUMNSTOGGLE=type
@if:set COLUMNSTOGGLE=type
set COLUMNSREMOVE=type SORTBY=name
@if:else
set COLUMNSADD=type SORTBY=type

Thank you very much! Here is my little snippet based on your code. Unfortunately it doesnt work. It seems to always sort by name again (I guess removing the column is something which DO doesn't like) :smiley:

set COLUMNSADD=type
Set Sortby=Type
Set Sortreverse=On
set COLUMNSREMOVE=type

You're adding the column and then removing it again. All those @if:set things in my code were there for a reason :slight_smile:

But actually that's what I want. I want to sort, but I don't want to see the columns since they occlude a lot of space. That's why a added them again only so that the sort-algorithm can do its work and after that I hoped to be able to remove them again - with the sfiles stay sorted and not more space needed that necessary.

But it seems, that DO is not able to keep the sorting if the column isn't shown. Thanks for your help! It helped me a lot!

The columns need to be visible while you are sorting by them. They can be removed when you aren't sorting by them, but need to be there when you are.

Sorting isn't a one-off operation; it's a state. It happens when files are added or changed as well.

1 Like

I had exactly this idea today, this seems like the ideal setting for the double click feature. Could somebody tell what exactly I would to write into the field in the settings for the double click action?

I.e., I am thinking, double clicking in file area -> toggling between sort by name (a....z) and sort by modified date (latest modified date .... oldest modified date).

I am too unskilled to know why
@ifset:SORTBY=name Set SORTBY=modified @ifset:else Set SORTBY=name
does not work.

The forum messed up the old post and put everything on one line. I’ve fixed it above.

To use a multi-line command in a field that only takes a single line, first create a User-Defined Command out of it, then specify that as the thing to run.

(Not at my PC currently but can help more later if you need it.)

I have created a user-defined command:

@ifset:SORTBY=name 
Set SORTBY=modified SortReverse=Off
@ifset:else 
Set SORTBY=name SortReverse=Off

and I labeled it "sort_columns_toggle"

I then entered "sort_columns_toggle" into settings and it seems to work!

Did I do that correctly?

Thank you!

1 Like