이 페이지에서

Core::ActionManager Class

class Core::ActionManager

ActionManager 클래스는 메뉴와 메뉴 항목, 키보드 단축키의 등록을 담당합니다. 더 보기...

Header: #include <coreplugin/actionmanager/actionmanager.h>
Inherits: QObject

신호

void commandAdded(Utils::Id id)
void commandListChanged()

정적 공용 멤버

Core::ActionContainer *actionContainer(Utils::Id id)
Core::Command *command(Utils::Id id)
QList<Core::Command *> commands()
Core::Command *createCommand(Utils::Id id)
Core::ActionContainer *createMenu(Utils::Id id)
Core::ActionContainer *createMenuBar(Utils::Id id)
Core::ActionContainer *createTouchBar(Utils::Id id, const QIcon &icon, const QString &text = QString())
Core::ActionManager *instance()
bool isPresentationModeEnabled()
Core::Command *registerAction(QAction *action, Utils::Id id, const Core::Context &context = Context(Constants::C_GLOBAL), bool scriptable = false)
void unregisterAction(QAction *action, Utils::Id id)
QString withNumberAccelerator(const QString &text, const int number)

상세 설명

액션 매니저는 액션과 해당 단축키 및 레이아웃을 관리하는 중심적인 관리자 역할을 합니다. 이 클래스는 대부분 정적 함수를 포함하는 싱글톤입니다. 예를 들어 시그널에 연결하기 위해 인스턴스에 접근해야 하는 경우, ActionManager::instance() 함수를 호출하십시오.

액션 매니저를 통해 사용자가 모든 키보드 단축키를 지정할 수 있는 중앙 집중식 장소를 제공할 수 있으며, 상황에 따라 다르게 동작해야 하는 액션(예: 복사/바꾸기/실행 취소/다시 실행 액션)에 대한 해결책을 제공합니다.

Core::ActionManager, Core::Command, Core::Context 간의 상호 작용에 대한 개요는 「액션 매니저와 명령어 」를 참조하십시오.

플러그인의 ` ExtensionSystem::IPlugin::initialize()` 함수에 다음 코드를 추가하여 전역적으로 활성화된 "My Action" 액션을 등록하십시오.

QAction *myAction = new QAction(Tr::tr("My Action"), this);
Command *cmd = ActionManager::registerAction(myAction, "myplugin.myaction", Context(C_GLOBAL));
cmd->setDefaultKeySequence(QKeySequence(Tr::tr("Ctrl+Alt+u")));
connect(myAction, &QAction::triggered, this, &MyPlugin::performMyAction);

connect 는 사용자 정의 QAction 인스턴스에 수행됩니다. 예를 들어, 해당 액션을 나타낼 도구 버튼을 생성하는 경우, Command::action()에서 반환된 액션을 해당 버튼에 추가하십시오.

QToolButton *myButton = new QToolButton(someParentWidget);
myButton->setDefaultAction(cmd->action());

또한 액션 매니저를 사용하여 애플리케이션의 메뉴 바나 해당 메뉴 바 내의 메뉴와 같이 등록된 액션 컨테이너에 항목을 추가할 수 있습니다. Core::ActionManager::registerAction() 함수를 통해 액션을 등록하고, Core::ActionManager::actionContainer()를 사용하여 특정 ID(예: Core::Constants 네임스페이스에 지정된 ID)에 해당하는 액션 컨테이너를 가져온 다음, 이 컨테이너에 명령을 추가하면 됩니다.

이 예제를 바탕으로, “Tools” 메뉴에 “My Action”을 추가하려면 다음과 같이 하면 됩니다.

ActionManager::actionContainer(Core::Constants::M_TOOLS)->addAction(cmd);

Core::ICore, Core::Command, Core::ActionContainer, Core::IContext 및 ‘액션 관리자 및 명령’항목도 참조하십시오 .

멤버 함수 문서

[static] Core::ActionContainer *ActionManager::actionContainer(Utils::Id id)

지정된 id 에 대해 createMenu(), createMenuBar(), createTouchBar()을 사용하여 생성된 ActionContainer 인스턴스를 반환합니다.

ID Core::Constants::MENU_BAR 을 사용하여 메인 메뉴 바를 가져옵니다.

Core::Constants::M_FILE, Core::Constants::M_EDIT 등의 ID 및 유사한 상수를 사용하여 다양한 기본 메뉴를 가져옵니다.

ID Core::Constants::TOUCH_BAR 를 사용하여 메인 터치 바를 가져옵니다.

ActionManager::createMenu() 및 ActionManager::createMenuBar()도 참조하십시오 .

[static] Core::Command *ActionManager::command(Utils::Id id)

지정된 ` id`에 대해 ` registerAction()`를 사용하여 생성된 `Command` 인스턴스를 반환합니다.

registerAction()도 참조하십시오 .

[signal] void ActionManager::commandAdded(Utils::Id id)

( id 가 포함된) 명령어가 추가될 때 발생합니다.

[signal] void ActionManager::commandListChanged()

명령 목록이 변경되었을 때 발생합니다.

[static] QList<Core::Command *> ActionManager::commands()

등록된 모든 명령을 반환합니다.

[static] Core::Command *ActionManager::createCommand(Utils::Id id)

지정된 명령어 설명( id)을 사용하여 명령어를 생성하거나 기존 명령어를 반환합니다.

생성된 명령에는 아직 어떤 동작도 연결되어 있지 않으므로 실제로 실행할 수는 없습니다. 하지만 시스템은 이 명령을 인식하고 있으며, 키보드 단축키 설정에 표시되며, 나중에 QActions를 등록할 수 있습니다. 등록하려는 QAction, ID 및 Context가 이미 있다면 이 메서드를 호출할 필요가 없습니다. registerAction()를 직접 호출하기만 하면 됩니다.

[static] Core::ActionContainer *ActionManager::createMenu(Utils::Id id)

지정된 id 를 사용하여 새로운 메뉴 액션 컨테이너를 생성하거나 기존 컨테이너를 반환합니다. ActionManager 는 반환된 ActionContainer 를 소유합니다. actionContainer() 및 ActionContainer::addMenu() 함수를 사용하여 메뉴를 다른 메뉴나 메뉴 바에 추가하십시오.

actionContainer() 및 ActionContainer::addMenu()함수도 참조하십시오 .

[static] Core::ActionContainer *ActionManager::createMenuBar(Utils::Id id)

지정된 id 를 사용하여 새로운 메뉴 막대 액션 컨테이너를 생성하거나, 기존 컨테이너를 반환합니다. ActionManager 는 반환된 ActionContainer 를 소유합니다.

createMenu() 및 ActionContainer::addMenu()도 참조하십시오 .

[static] Core::ActionContainer *ActionManager::createTouchBar(Utils::Id id, const QIcon &icon, const QString &text = QString())

새로운 (하위) 터치 바 액션 컨테이너를 생성하거나, 지정된 id 를 가진 기존 컨테이너를 반환합니다. ActionManager 는 반환된 ActionContainer 를 소유합니다.

하위 터치 바는 단 한 단계만 생성할 수 있다는 점에 유의하십시오. 하위 터치 바는 icon 및 text (둘 중 하나는 비워둘 수 있음)를 가진 버튼으로 표시되며, 이 버튼을 터치하면 하위 터치 바가 열립니다.

actionContainer() 및 ActionContainer::addMenu()도 참조하십시오 .

[static] Core::ActionManager *ActionManager::instance()

인스턴스에 대한 포인터를 반환합니다. 신호 연결용으로만 사용하십시오.

[static] bool ActionManager::isPresentationModeEnabled()

프레젠테이션 모드가 활성화되어 있는지 여부를 반환합니다.

Qt Creator 를 명령줄 인수 -presentationMode 와 함께 시작하면 프레젠테이션 모드가 활성화됩니다. 프레젠테이션 모드에서는 Qt Creator 가 누른 단축키를 오버레이 상자에 표시합니다.

[static] Core::Command *ActionManager::registerAction(QAction *action, Utils::Id id, const Core::Context &context = Context(Constants::C_GLOBAL), bool scriptable = false)

지정된 id 하에서 시스템에 action 를 등록합니다.

애플리케이션 내의 액션을 나타내며 ActionManager 가 소유하는 Command 인스턴스를 반환합니다. context 가 서로 다른 한, 동일한 id 에 여러 액션을 등록할 수 있습니다. 이 경우 액션 트리거는 현재 활성화된 컨텍스트( QAction )에 대해 등록된 컨텍스트로 전달됩니다. 선택적 컨텍스트 매개변수( context )가 지정되지 않으면 전역 컨텍스트로 간주됩니다. scriptable 액션은 사용자의 상호작용 없이 스크립트에서 호출할 수 있습니다.

[static] void ActionManager::unregisterAction(QAction *action, Utils::Id id)

지정된 id 하위의 action 에 대한 정보를 제거합니다.

일반적으로 액션을 등록 해제할 필요는 없습니다. 액션 등록 해제의 유일한 유효한 사용 사례는 사용자 정의 가능한 액션을 나타내는 경우, 예를 들어 사용자 정의 로케이터 필터와 같은 경우입니다. 사용자가 이러한 액션을 제거하면, 단축키 설정 등에서 해당 액션이 사라지도록 하기 위해 액션 관리자에서도 등록을 해제해야 합니다.

[static] QString ActionManager::withNumberAccelerator(const QString &text, const int number)

지정된 text 에 Recent Files 메뉴의 스타일과 같이 번호가 매겨진 단축키 number 를 적용합니다.

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.