activate sort list with keyboard hotkey ?

is it possible to assign a keyboard shortcut to active this custom sort order? E.g. I’d like to assign ctrl+y and it’l activate this custom sort order https://i.imgur.com/ZARwA0R.png

Always attach example documents.
An image is rarely useful. Actually that’s only the case if the question is explicitly about an issue with the view.

I feel sure you can’t do what you want without user code (“macro”), and if you (or somebody) created such a macro, it’s wasted time if only developed and used for the one sapecial case for which you assign the macro to a shortcut. Shortcuts are very poor, because they can’t accept modifiers. In addition they tend to create conflicts, and to be called now and then inadvertently -sometimes with desastrous consequences if complex tasks are performed…

Passing parameters to subroutines, on the other hand, isn’t exactly simple.

If you are specifically interested in the ways the LibO API can be used for related purposes, please tell.

t71258.ods (14.3 KB)

1 Like

You may also check the attached example. It contains some user code allowing to (internally) create and apply temporary user sortlists.
There are also some explanations concerning limitations of the concept. For testing you need to understand the usage of J8:J10. Column F may serve as an example of entries needing to be sorted.

customSortByUserCode.ods (16.8 KB)
The example can only work if the execution of document macros is pertmitted. Chack in advance.
(I didn’t post the example originally, because there are lots of expectable issues.)

If you have a moment, could you speak to the “magic constants” 7,8,3 in

soDe(7).Value = True
soDe(8).Value = uIndMax + 1
Dim sortFields(0) As New com.sun.star.util.SortField
sortFields(0).SortAscending = pAscending
soDe(3).Value = sortFields
workRg.sort(soDe)

Simply inspect variable soDe

Cool. I didn’t know XRay (and I assume MRI) would reflect Property names like that. Very useful. To expand on @Villeroy for any other lookers-on, have the MRI library or XRay activated in the macro after soDe is set with something like

XRay soDe

or

Mri soDe

and presto, you get a list like (from XRay):

  • (0) | Structure : com.sun.star.beans.PropertyValue → IsSortColumns False
  • (1) | Structure : com.sun.star.beans.PropertyValue → ContainsHeader False
  • (2) | Structure : com.sun.star.beans.PropertyValue → MaxFieldCount 3
  • (3) | Structure : com.sun.star.beans.PropertyValue → SortFields
  • (4) | Structure : com.sun.star.beans.PropertyValue → BindFormatsToContent True
  • (5) | Structure : com.sun.star.beans.PropertyValue → CopyOutputData False
  • (6) | Structure : com.sun.star.beans.PropertyValue → OutputPosition
  • (7) | Structure : com.sun.star.beans.PropertyValue → IsUserListEnabled False
  • (8) | Structure : com.sun.star.beans.PropertyValue → UserListIndex 0

If you like XRay, you will love MRI. [Tutorial] Introduction into object inspection with MRI

In this particular case the normal IDE watch window would be sufficient.
Unbenannt

You touched a strange inconsistency probably going back to the times of dinosaurs:
A sortable object can create.SearchDescriptor, but the returned “thing” isn’t an object as expected. It neither supports any service, nor does it export any interface, nor is it an UnoStruct.
It’s simply a sequence (funtionally a 1D-array) of com.sun.star.beans.PropertyValue elements - and I don’t even know a specification telling which property is assigned to what index.
Funny in a truely fascinating way now is, that the .sort method invoked by a sortable object does not identify the properties by index, but by name.

===
You actually can replace the magic part of the code by

Dim sortFields(0) As New com.sun.star.util.SortField
sortFields(0).SortAscending = pAscending

Dim soDe(2) As New com.sun.star.beans.PropertyValue
soDe(0).Name  = "SortFields"
soDe(0).Value = sortFields
soDe(1).Name  = "UserListEnabled"
soDe(1).Value = True
soDe(2).Name  = "UserListIndex"
soDe(2).Value = uIndMax + 1  

===
and get the same effect. No magic left. Sorry!
(Please note that property names are case sensitive.)

Another remark: The .createFilterDescriptor() method called by (e.g.) the same range object actually returns an interface. You may need some theological skills to understand this.

1 Like