[Volunteers welcome] Refactoring the keyboard shortcuts

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
TheMarkster
Posts: 1727
Joined: Thu Apr 05, 2018 1:53 am

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby TheMarkster » Sat Aug 01, 2020 8:52 pm

Offtopic, sort of, but I have to say I loathe vi with a passion. I'm okay with shortcuts, but the most basic of operations -- editing your document -- should be a bit more intuitive. This is coming from somebody who once took great pride in learning the shortcuts for wordperfect for DOS and not needing the keyboard template. Even further offtopic, how grossly mismanaged do you have to be to let your software go from *the* dominant leader in the marketplace to one now nobody who never used a rotary phone ever heard of? Word for DOS was almost as bad as vi back in those days, almost.

On to the topic at hand, if we are to disable workbench shortcuts after leaving the workbench this is something that users should be able to opt out of with a preference. As an example, a shortcut for creating a new spreadsheet or a new sketch could be useful even if you're in another workbench.

I've added some shortcuts to DynamicData, which should not conflict:

D,D,C -- create new dd object
D,D,A -- add new property
D,D,R -- remove property
D,D,S -- open settings

New PR:
https://github.com/FreeCAD/FreeCAD/pull/3768

This will add a new Gui command:

Gui.listCommandsByShortcut(shortcut)

Example:

Gui.listCommandsByShortcut('a,c')
['Std_AxisCross']

Gui.listCommandsByShortcut('')
[all commands without shortcuts as a list of strings]

This can already be done in python, but it's a nice convenience to have, I think.
My FreeCAD video series on youtube: https://www.youtube.com/c/mwganson
catman
Posts: 230
Joined: Fri Jan 11, 2019 10:42 pm

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby catman » Sat Aug 01, 2020 9:51 pm

TheMarkster wrote:
Sat Aug 01, 2020 8:52 pm
Offtopic, sort of, but I have to say I loathe vi with a passion.
I know its picking up off-topic, but maybe I should have mentioned that I really dislike both vi and emacs :lol: .
Its just that I have looked into them enough to understand why some people are fanatic about them.
catman
Posts: 230
Joined: Fri Jan 11, 2019 10:42 pm

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby catman » Sat Aug 01, 2020 9:54 pm

TheMarkster wrote:
Sat Aug 01, 2020 8:52 pm
D,D,C -- create new dd object
D,D,A -- add new property
D,D,R -- remove property
D,D,S -- open settings
This is D,D for "Dynamic Data", right? Do all your WB shortcuts start with D,D ?
chrisb
Posts: 25699
Joined: Tue Mar 17, 2015 9:14 am

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby chrisb » Sat Aug 01, 2020 10:01 pm

TheMarkster wrote:
Sat Aug 01, 2020 8:52 pm
On to the topic at hand, if we are to disable workbench shortcuts after leaving the workbench this is something that users should be able to opt out of with a preference. As an example, a shortcut for creating a new spreadsheet or a new sketch could be useful even if you're in another workbench.
It would be sufficient, if the current workbench just sets its own shortcuts. If they aren't overwritten they can still be used. So it's a good idea to use multiple key shortcuts, preferably the first one with a modifier, because a simple D key - perhaps for some "Delete" - would make the D,Something keys unavailable.
TheMarkster
Posts: 1727
Joined: Thu Apr 05, 2018 1:53 am

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby TheMarkster » Sat Aug 01, 2020 10:07 pm

catman wrote:
Sat Aug 01, 2020 9:54 pm
TheMarkster wrote:
Sat Aug 01, 2020 8:52 pm
D,D,C -- create new dd object
D,D,A -- add new property
D,D,R -- remove property
D,D,S -- open settings
This is D,D for "Dynamic Data", right? Do all your WB shortcuts start with D,D ?
Yes, that's the idea. Start them all with d,d.
My FreeCAD video series on youtube: https://www.youtube.com/c/mwganson
TheMarkster
Posts: 1727
Joined: Thu Apr 05, 2018 1:53 am

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby TheMarkster » Sat Aug 01, 2020 10:12 pm

chrisb wrote:
Sat Aug 01, 2020 10:01 pm

It would be sufficient, if the current workbench just sets its own shortcuts. If they aren't overwritten they can still be used. So it's a good idea to use multiple key shortcuts, preferably the first one with a modifier, because a simple D key - perhaps for some "Delete" - would make the D,Something keys unavailable.
Maybe you're right. I'll need to test if there is a conflict in such cases.

That gives me an idea, to provide a wildcard search capability. Something like listCommandsByShortcut('d*')

That would list all commands with shortcuts starting with a 'd'. I'll need to figure out how to do that, probably with a regular expression.

Edit: regular expression support added.

Usage: Gui.listCommandsByShortcut(expr, bUseRegExp)

where expr is a string, which will be interpreted as a regular expression and bUseRegExp is a boolean.

Example:

Code: Select all

Gui.listCommandsByShortcut('^d,', True)
[all commands that begin with D,]

Code: Select all

Gui.listCommandsByShortcut("Del")
['Std_Delete']
My FreeCAD video series on youtube: https://www.youtube.com/c/mwganson
openBrain
Posts: 4436
Joined: Fri Nov 09, 2018 5:38 pm

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby openBrain » Sun Aug 02, 2020 9:11 am

TheMarkster wrote:
Sat Aug 01, 2020 8:52 pm
I've added some shortcuts to DynamicData, which should not conflict:

D,D,C -- create new dd object
D,D,A -- add new property
D,D,R -- remove property
D,D,S -- open settings
As chrisb already highlighted, I'm afraid this way can actually collide pretty easily (in your example, with a 'd' command in any workbench).
To me, if we want to make all workbench commands accessible, a good strategy would be :
  • Limit the 'native' shortcut sequences to 2 strokes (I say stroke rather than key, because for example 'Ctrl+A' is only 1 stroke in a sequence)
  • Define a global stroke that will mean 'Call foreign command' (and of course that will be forbidden for other commands). As example, let's say 'F'.
  • For each workbench, define a 'foreign ID' stroke that would be unique among workbenches. Ideally this ID is stored as a property of the workbench. As example, let's say Part is 'P', Draft is 'D'
So for example, it Part/Cut native shortcut is 'C', when you are in another workbench you have to call it with 'F, P, C'. If Draft/PolarPattern native shortcut is 'P, P', you can call it from another workbench with 'F, D, P, P'.
Obviously the change between native and foreign shall be handle by FC so it's transparent for the user. IMO ideally, the commands of the activated workbench should be accessible with both their native and foreign sequences.
Does that sound sensible guys ?
chrisb
Posts: 25699
Joined: Tue Mar 17, 2015 9:14 am

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby chrisb » Sun Aug 02, 2020 11:15 am

openBrain wrote:
Sun Aug 02, 2020 9:11 am
Does that sound sensible guys ?
Yes.
TheMarkster
Posts: 1727
Joined: Thu Apr 05, 2018 1:53 am

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby TheMarkster » Sun Aug 02, 2020 6:26 pm

I have changed the DynamicData default shortcuts. With some additional testing I did find some potential conflicts with Draft workbench. New shortcuts all begin with Ctrl+D:

Ctrl+D,C -- create new object
Ctrl+D,A -- add property to object
Ctrl+D,R -- remove property
Ctrl+D,S -- open settings dialog

By the way, Arch_Frame and Draft_Facebinder both use F:

Arch_Frame = F,R
Draft_Facebinder = F,F

No commands (among workbenches installed on the test machine, which aren't that many) begin with Ctrl+F. I'll go through and install as many of the more commonly used workbenches as I can and test again.

Edit: I installed more workbenches. Now with total of 49 installed and 1547 commands. None begin with Ctrl+F. 2 begin with F (arch frame and draft facebinder mentioned above).
My FreeCAD video series on youtube: https://www.youtube.com/c/mwganson
openBrain
Posts: 4436
Joined: Fri Nov 09, 2018 5:38 pm

Re: [Volunteers welcome] Refactoring the keyboard shortcuts

Postby openBrain » Sun Aug 02, 2020 7:09 pm

TheMarkster wrote:
Sun Aug 02, 2020 6:26 pm
No commands (among workbenches installed on the test machine, which aren't that many) begin with Ctrl+F. I'll go through and install as many of the more commonly used workbenches as I can and test again.

Edit: I installed more workbenches. Now with total of 49 installed and 1547 commands. None begin with Ctrl+F. 2 begin with F (arch frame and draft facebinder mentioned above).
Ctrl+F is interesting. It's not used by workbenches, it's nowhere in the 'customize' editor, it's not really documented ... but it is the shortcut used to do a search in the tree view. ;) So yes, you also have to care about not breaking the 'hardcoded-only' shortcuts. ;)