[Bug]: Commander Ribbon Elements Reordering on Changes
Opened this issue · 0 comments
Describe the bug
When adding commands via the Commander Ribbon Tab, or when changing icon, color, name, or mode, the elements get reordered. This requires the user to re-reorder the ribbon elements everytime a new command is added or an already existing one is changed.
Relevant errors (if available)
No response
Steps to reproduce
- Open the Commander Ribbon Tab
- Add or modify (icon, color, name, mode) a command
- Observe that the elements are reordered
Expected Behavior
Changes should be applied without reordering the existing elements. Adding a new command should not trigger an additional reorder operation.
Additional context
Proposed fix:
- Implement a new
update()
method inleftRibbonManager.ts
that only adds commands without removing them - Modify the
handleRename
method incommandViewerComponent.tsx
to:
a. First remove the command using themanager.removeCommand()
method
b. Then make the name change
c. Finally, add the command again using themanager.addCommand()
method - Replace
manager.reorder()
calls withmanager.update()
for the following functions insrc/ui/components/commandViewerComponent.tsx
:
- handleNewIcon
- handleModeChange
- handleColorChange
- Modify
addCommand()
andremoveCommand()
method to use the id for finding the native action. - Use
nativeAction.hidden
property to handle mode changes without reordering - Remove the
reorder()
call in "Add command" button click handler
Attachments:
The following attachments contain the fix which allows adding, renaming, and removing commands via the Commander Ribbon tab, or changing icon, color, name, or mode, without the need to reorder all items:
Limitations:
The Plugin.addRibbonIcon(icon, title)
method only permits specifying a name and icon, without an option for specifying a unique identifier. Consequently, changing a name currently causes this element to reorder in ribbon and the Commander Ribbon tab.
Additional notes:
In the current implementation, removing and immediately re-adding the element with a new name results in reordering that command in the ribbon and in the Command Ribbon tab. Another approach would be to assign elements a UID and set the title field of the newly created ribbon item immediately afterward, allowing a name change without reordering. However, this would require changes to the interface and initialization process of the CommandIconPair, affecting multiple files (all instances of CommandIconPair would need to include the UID).
While implementing this field requires changing the initialization process in other parts of the program, as long as this is correctly implemented, it would not impact any of the functionality of the program. In fact, it would be possible to use the UID only on special occasions (e.g., ribbon) where desired.
Operating system
Linux