From 422b61e55786253ecf951ca0508f0f6fce8381c6 Mon Sep 17 00:00:00 2001 From: nakst <> Date: Sun, 26 Sep 2021 13:33:23 +0100 Subject: [PATCH] require command title --- apps/file_manager/commands.cpp | 18 +++++++++--------- apps/image_editor.cpp | 10 +++++----- apps/system_monitor.cpp | 2 +- apps/text_editor.cpp | 8 ++++---- desktop/api.cpp | 34 +++++++++++++++++++--------------- desktop/gui.cpp | 4 ++-- desktop/os.header | 5 +++-- shared/strings.cpp | 3 +++ 8 files changed, 46 insertions(+), 38 deletions(-) diff --git a/apps/file_manager/commands.cpp b/apps/file_manager/commands.cpp index ce8dd96..56c33e9 100644 --- a/apps/file_manager/commands.cpp +++ b/apps/file_manager/commands.cpp @@ -464,7 +464,7 @@ void CommandPaste(Instance *instance, EsElement *, EsCommand *) { void InstanceRegisterCommands(Instance *instance) { uint32_t stableCommandID = 1; - EsCommandRegister(&instance->commandGoBackwards, instance, [] (Instance *instance, EsElement *, EsCommand *) { + EsCommandRegister(&instance->commandGoBackwards, instance, INTERFACE_STRING(FileManagerGoBack), [] (Instance *instance, EsElement *, EsCommand *) { EsAssert(instance->pathBackwardHistory.Length()); HistoryEntry entry = instance->pathBackwardHistory.Pop(); StringDestroy(&instance->delayedFocusItem); @@ -472,7 +472,7 @@ void InstanceRegisterCommands(Instance *instance) { InstanceLoadFolder(instance, entry.path, LOAD_FOLDER_BACK); }, stableCommandID++, "Backspace|Alt+Left"); - EsCommandRegister(&instance->commandGoForwards, instance, [] (Instance *instance, EsElement *, EsCommand *) { + EsCommandRegister(&instance->commandGoForwards, instance, INTERFACE_STRING(FileManagerGoForwards), [] (Instance *instance, EsElement *, EsCommand *) { EsAssert(instance->pathForwardHistory.Length()); HistoryEntry entry = instance->pathForwardHistory.Pop(); StringDestroy(&instance->delayedFocusItem); @@ -480,31 +480,31 @@ void InstanceRegisterCommands(Instance *instance) { InstanceLoadFolder(instance, entry.path, LOAD_FOLDER_FORWARD); }, stableCommandID++, "Alt+Right"); - EsCommandRegister(&instance->commandGoParent, instance, [] (Instance *instance, EsElement *, EsCommand *) { + EsCommandRegister(&instance->commandGoParent, instance, INTERFACE_STRING(FileManagerGoUp), [] (Instance *instance, EsElement *, EsCommand *) { String parent = PathGetParent(instance->folder->path); InstanceLoadFolder(instance, StringDuplicate(parent)); }, stableCommandID++, "Alt+Up"); - EsCommandRegister(&instance->commandRefresh, instance, [] (Instance *instance, EsElement *, EsCommand *) { + EsCommandRegister(&instance->commandRefresh, instance, INTERFACE_STRING(FileManagerRefresh), [] (Instance *instance, EsElement *, EsCommand *) { FolderRefresh(instance->folder); }, stableCommandID++, "F5"); - EsCommandRegister(&instance->commandNewFolder, instance, CommandNewFolder, stableCommandID++, "Ctrl+Shift+N"); - EsCommandRegister(&instance->commandRename, instance, CommandRename, stableCommandID++, "F2"); + EsCommandRegister(&instance->commandNewFolder, instance, INTERFACE_STRING(FileManagerNewFolderToolbarItem), CommandNewFolder, stableCommandID++, "Ctrl+Shift+N"); + EsCommandRegister(&instance->commandRename, instance, INTERFACE_STRING(FileManagerRenameAction), CommandRename, stableCommandID++, "F2"); - EsCommandRegister(&instance->commandViewDetails, instance, [] (Instance *instance, EsElement *, EsCommand *) { + EsCommandRegister(&instance->commandViewDetails, instance, INTERFACE_STRING(CommonListViewTypeDetails), [] (Instance *instance, EsElement *, EsCommand *) { instance->viewSettings.viewType = VIEW_DETAILS; InstanceRefreshViewType(instance); InstanceViewSettingsUpdated(instance); }, stableCommandID++); - EsCommandRegister(&instance->commandViewTiles, instance, [] (Instance *instance, EsElement *, EsCommand *) { + EsCommandRegister(&instance->commandViewTiles, instance, INTERFACE_STRING(CommonListViewTypeTiles), [] (Instance *instance, EsElement *, EsCommand *) { instance->viewSettings.viewType = VIEW_TILES; InstanceRefreshViewType(instance); InstanceViewSettingsUpdated(instance); }, stableCommandID++); - EsCommandRegister(&instance->commandViewThumbnails, instance, [] (Instance *instance, EsElement *, EsCommand *) { + EsCommandRegister(&instance->commandViewThumbnails, instance, INTERFACE_STRING(CommonListViewTypeThumbnails), [] (Instance *instance, EsElement *, EsCommand *) { instance->viewSettings.viewType = VIEW_THUMBNAILS; InstanceRefreshViewType(instance); InstanceViewSettingsUpdated(instance); diff --git a/apps/image_editor.cpp b/apps/image_editor.cpp index 704f8ea..72d3216 100644 --- a/apps/image_editor.cpp +++ b/apps/image_editor.cpp @@ -704,11 +704,11 @@ void InstanceCreate(EsMessage *message) { // Register commands. - EsCommandRegister(&instance->commandBrush, instance, CommandSelectTool, 1, "N", true); - EsCommandRegister(&instance->commandFill, instance, CommandSelectTool, 2, "Shift+B", true); - EsCommandRegister(&instance->commandRectangle, instance, CommandSelectTool, 3, "Shift+R", true); - EsCommandRegister(&instance->commandSelect, instance, CommandSelectTool, 4, "R", false); - EsCommandRegister(&instance->commandText, instance, CommandSelectTool, 5, "T", false); + EsCommandRegister(&instance->commandBrush, instance, INTERFACE_STRING(ImageEditorToolBrush), CommandSelectTool, 1, "N", true); + EsCommandRegister(&instance->commandFill, instance, INTERFACE_STRING(ImageEditorToolFill), CommandSelectTool, 2, "Shift+B", true); + EsCommandRegister(&instance->commandRectangle, instance, INTERFACE_STRING(ImageEditorToolRectangle), CommandSelectTool, 3, "Shift+R", true); + EsCommandRegister(&instance->commandSelect, instance, INTERFACE_STRING(ImageEditorToolSelect), CommandSelectTool, 4, "R", false); + EsCommandRegister(&instance->commandText, instance, INTERFACE_STRING(ImageEditorToolText), CommandSelectTool, 5, "T", false); EsCommandSetCheck(&instance->commandBrush, ES_CHECK_CHECKED, false); diff --git a/apps/system_monitor.cpp b/apps/system_monitor.cpp index 22a986d..1ee7801 100644 --- a/apps/system_monitor.cpp +++ b/apps/system_monitor.cpp @@ -372,7 +372,7 @@ void ProcessApplicationMessage(EsMessage *message) { if (message->type == ES_MSG_INSTANCE_CREATE) { Instance *instance = EsInstanceCreate(message, "System Monitor"); - EsCommandRegister(&instance->commandTerminateProcess, instance, TerminateProcess, 1, "Del", false); + EsCommandRegister(&instance->commandTerminateProcess, instance, EsLiteral("Terminate process"), TerminateProcess, 1, "Del", false); EsWindow *window = instance->window; EsWindowSetIcon(window, ES_ICON_UTILITIES_SYSTEM_MONITOR); diff --git a/apps/text_editor.cpp b/apps/text_editor.cpp index bde33f2..1fd827a 100644 --- a/apps/text_editor.cpp +++ b/apps/text_editor.cpp @@ -202,20 +202,20 @@ void ProcessApplicationMessage(EsMessage *message) { uint32_t stableID = 1; - EsCommandRegister(&instance->commandFindNext, instance, [] (Instance *instance, EsElement *, EsCommand *) { + EsCommandRegister(&instance->commandFindNext, instance, INTERFACE_STRING(CommonSearchNext), [] (Instance *instance, EsElement *, EsCommand *) { Find(instance, false); }, stableID++, "F3"); - EsCommandRegister(&instance->commandFindPrevious, instance, [] (Instance *instance, EsElement *, EsCommand *) { + EsCommandRegister(&instance->commandFindPrevious, instance, INTERFACE_STRING(CommonSearchPrevious), [] (Instance *instance, EsElement *, EsCommand *) { Find(instance, true); }, stableID++, "Shift+F3"); - EsCommandRegister(&instance->commandFind, instance, [] (Instance *instance, EsElement *, EsCommand *) { + EsCommandRegister(&instance->commandFind, instance, INTERFACE_STRING(CommonSearchOpen), [] (Instance *instance, EsElement *, EsCommand *) { EsWindowSwitchToolbar(instance->window, instance->toolbarSearch, ES_TRANSITION_ZOOM_OUT); EsElementFocus(instance->textboxSearch); }, stableID++, "Ctrl+F"); - EsCommandRegister(&instance->commandFormat, instance, [] (Instance *instance, EsElement *, EsCommand *) { + EsCommandRegister(&instance->commandFormat, instance, INTERFACE_STRING(CommonFormatPopup), [] (Instance *instance, EsElement *, EsCommand *) { FormatPopupCreate(instance); }, stableID++, "Ctrl+Alt+T"); diff --git a/desktop/api.cpp b/desktop/api.cpp index 65d2c47..ada47d0 100644 --- a/desktop/api.cpp +++ b/desktop/api.cpp @@ -656,7 +656,7 @@ void InstanceSave(EsInstance *_instance) { } void InstanceClose(EsInstance *instance) { - if (EsCommandByID(instance, ES_COMMAND_SAVE)->disabled) { + if (!EsCommandByID(instance, ES_COMMAND_SAVE)->enabled) { EsInstanceDestroy(instance); return; } @@ -803,15 +803,15 @@ APIInstance *InstanceSetup(EsInstance *instance) { instance->undoManager->instance = instance; apiInstance->activeUndoManager = instance->undoManager; - EsCommandRegister(&apiInstance->commandDelete, instance, nullptr, ES_COMMAND_DELETE, "Del"); - EsCommandRegister(&apiInstance->commandSelectAll, instance, nullptr, ES_COMMAND_SELECT_ALL, "Ctrl+A"); - EsCommandRegister(&apiInstance->commandCopy, instance, nullptr, ES_COMMAND_COPY, "Ctrl+C|Ctrl+Ins"); - EsCommandRegister(&apiInstance->commandCut, instance, nullptr, ES_COMMAND_CUT, "Ctrl+X|Shift+Del"); - EsCommandRegister(&apiInstance->commandPaste, instance, nullptr, ES_COMMAND_PASTE, "Ctrl+V|Shift+Ins"); - EsCommandRegister(&apiInstance->commandUndo, instance, nullptr, ES_COMMAND_UNDO, "Ctrl+Z"); - EsCommandRegister(&apiInstance->commandRedo, instance, nullptr, ES_COMMAND_REDO, "Ctrl+Y"); - EsCommandRegister(&apiInstance->commandSave, instance, nullptr, ES_COMMAND_SAVE, "Ctrl+S"); - EsCommandRegister(&apiInstance->commandShowInFileManager, instance, nullptr, ES_COMMAND_SHOW_IN_FILE_MANAGER, "Ctrl+Shift+O"); + EsCommandRegister(&apiInstance->commandDelete, instance, INTERFACE_STRING(CommonSelectionDelete), nullptr, ES_COMMAND_DELETE, "Del"); + EsCommandRegister(&apiInstance->commandSelectAll, instance, INTERFACE_STRING(CommonSelectionSelectAll), nullptr, ES_COMMAND_SELECT_ALL, "Ctrl+A"); + EsCommandRegister(&apiInstance->commandCopy, instance, INTERFACE_STRING(CommonClipboardCopy), nullptr, ES_COMMAND_COPY, "Ctrl+C|Ctrl+Ins"); + EsCommandRegister(&apiInstance->commandCut, instance, INTERFACE_STRING(CommonClipboardCut), nullptr, ES_COMMAND_CUT, "Ctrl+X|Shift+Del"); + EsCommandRegister(&apiInstance->commandPaste, instance, INTERFACE_STRING(CommonClipboardPaste), nullptr, ES_COMMAND_PASTE, "Ctrl+V|Shift+Ins"); + EsCommandRegister(&apiInstance->commandUndo, instance, INTERFACE_STRING(CommonUndo), nullptr, ES_COMMAND_UNDO, "Ctrl+Z"); + EsCommandRegister(&apiInstance->commandRedo, instance, INTERFACE_STRING(CommonRedo), nullptr, ES_COMMAND_REDO, "Ctrl+Y"); + EsCommandRegister(&apiInstance->commandSave, instance, INTERFACE_STRING(CommonFileSave), nullptr, ES_COMMAND_SAVE, "Ctrl+S"); + EsCommandRegister(&apiInstance->commandShowInFileManager, instance, INTERFACE_STRING(CommonFileShowInFileManager), nullptr, ES_COMMAND_SHOW_IN_FILE_MANAGER, "Ctrl+Shift+O"); EsCommandSetCallback(&apiInstance->commandUndo, [] (EsInstance *instance, EsElement *, EsCommand *) { EsUndoInvokeGroup(((APIInstance *) instance->_private)->activeUndoManager, false); @@ -1566,11 +1566,13 @@ void EsCommandAddButton(EsCommand *command, EsButton *button) { command->elements = elements.array; EsButtonOnCommand(button, command->callback, command); button->state |= UI_STATE_COMMAND_BUTTON; - EsElementSetDisabled(button, command->disabled); + EsElementSetEnabled(button, command->enabled); EsButtonSetCheck(button, command->check); } -EsCommand *EsCommandRegister(EsCommand *command, EsInstance *_instance, EsCommandCallback callback, uint32_t stableID, +EsCommand *EsCommandRegister(EsCommand *command, EsInstance *_instance, + const char *title, ptrdiff_t titleBytes, + EsCommandCallback callback, uint32_t stableID, const char *cDefaultKeyboardShortcut, bool enabled) { if (!command) { command = (EsCommand *) EsHeapAllocate(sizeof(EsCommand), true); @@ -1583,7 +1585,9 @@ EsCommand *EsCommandRegister(EsCommand *command, EsInstance *_instance, EsComman command->registered = true; command->stableID = stableID; command->cKeyboardShortcut = cDefaultKeyboardShortcut; - command->disabled = !enabled; + command->enabled = enabled; + command->title = title; + command->titleBytes = titleBytes == -1 ? EsCStringLength(title) : titleBytes; EsAssert(!instance->commands.Get(&stableID)); // Command already registered. *instance->commands.Put(&stableID) = command; return command; @@ -1592,8 +1596,8 @@ EsCommand *EsCommandRegister(EsCommand *command, EsInstance *_instance, EsComman void EsCommandSetDisabled(EsCommand *command, bool disabled) { EsAssert(command->registered); // Command has not been registered. - if (disabled != command->disabled) { - command->disabled = disabled; + if (command->enabled != !disabled) { + command->enabled = !disabled; for (uintptr_t i = 0; i < ArrayLength(command->elements); i++) { EsElementSetDisabled(command->elements[i], disabled); diff --git a/desktop/gui.cpp b/desktop/gui.cpp index f084f06..4951c36 100644 --- a/desktop/gui.cpp +++ b/desktop/gui.cpp @@ -5550,7 +5550,7 @@ void FileMenuCreate(EsInstance *_instance, EsElement *element, EsCommand *) { if (instance->instanceClass == ES_INSTANCE_CLASS_EDITOR) { EsMenuAddSeparator(menu); - if (instance->commandSave.disabled && !newDocument) { + if (!instance->commandSave.enabled && !newDocument) { EsMenuAddItem(menu, ES_ELEMENT_DISABLED, INTERFACE_STRING(CommonFileUnchanged)); } else { EsMenuAddCommand(menu, ES_FLAGS_DEFAULT, INTERFACE_STRING(CommonFileSave), &instance->commandSave); @@ -6905,7 +6905,7 @@ bool UIHandleKeyMessage(EsWindow *window, EsMessage *message) { for (uintptr_t i = 0; i < instance->commands.Count(); i++) { EsCommand *command = instance->commands[i]; - if (!command->cKeyboardShortcut || command->disabled) continue; + if (!command->cKeyboardShortcut || !command->enabled) continue; const char *position = EsCRTstrstr(command->cKeyboardShortcut, keyboardShortcutString); if (!position) continue; diff --git a/desktop/os.header b/desktop/os.header index 1f4ae6b..383e091 100644 --- a/desktop/os.header +++ b/desktop/os.header @@ -1393,11 +1393,12 @@ function_pointer void EsCommandCallback(ES_INSTANCE_TYPE *instance, EsElement *e struct EsCommand { EsElement **elements; EsCommandCallback callback; - bool disabled, registered, allocated; + bool enabled, registered, allocated; EsCheckState check; uint32_t stableID; EsCString cKeyboardShortcut; EsGeneric data; + STRING title; }; struct EsListViewColumn { @@ -2298,7 +2299,7 @@ function ES_INSTANCE_TYPE *EsUndoGetInstance(EsUndoManager *manager); function void EsCommandAddButton(EsCommand *command, EsButton *button); function EsCommand *EsCommandByID(EsInstance *instance, uint32_t stableID); -function EsCommand *EsCommandRegister(EsCommand *command, EsInstance *instance, EsCommandCallback callback, uint32_t stableID, EsCString cDefaultKeyboardShortcut = ES_NULL, bool enabled = false); // IDs >= 0xF0000000 reserved by the system. +function EsCommand *EsCommandRegister(EsCommand *command, EsInstance *instance, STRING title, EsCommandCallback callback, uint32_t stableID, EsCString cDefaultKeyboardShortcut = ES_NULL, bool enabled = false); // IDs >= 0xF0000000 reserved by the system. function void EsCommandSetCallback(EsCommand *command, EsCommandCallback callback); function void EsCommandSetDisabled(EsCommand *command, bool disabled); function void EsCommandSetCheck(EsCommand *command, EsCheckState check, bool sendUpdatedMessage); diff --git a/shared/strings.cpp b/shared/strings.cpp index 8847da6..0b832b8 100644 --- a/shared/strings.cpp +++ b/shared/strings.cpp @@ -298,6 +298,9 @@ DEFINE_INTERFACE_STRING(FileManagerRefresh, "Refresh"); DEFINE_INTERFACE_STRING(FileManagerListContextActions, "Actions"); DEFINE_INTERFACE_STRING(FileManagerCopyTask, "Copying" ELLIPSIS); DEFINE_INTERFACE_STRING(FileManagerMoveTask, "Moving" ELLIPSIS); +DEFINE_INTERFACE_STRING(FileManagerGoBack, "Go back"); +DEFINE_INTERFACE_STRING(FileManagerGoForwards, "Go forwards"); +DEFINE_INTERFACE_STRING(FileManagerGoUp, "Go to containing folder"); // 2048.