このページでは

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 名前空間で指定されているもの)に対応するアクションコンテナを取得し、そのコンテナにコマンドを追加します。

先ほどの例を基に、「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 インスタンスを返します。

IDCore::Constants::MENU_BAR を使用して、メインメニューバーを取得します。

IDCore::Constants::M_FILE 、Core::Constants::M_EDIT 、および同様の定数を使用して、さまざまなデフォルトメニューを取得します。

IDCore::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 を持つコマンドを作成するか、既存のコマンドを返します。

作成されたコマンドにはまだアクションが関連付けられていないため、実際には実行することはできません。しかし、システムはこのコマンドを認識しており、キーボードショートカットの設定に表示され、後で QAction を登録することができます。登録したい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 を所有します。

サブタッチバーは1階層のみ作成できることに注意してください。サブタッチバーは、icon およびtext (いずれも空のままにできます)を持つボタンとして表現され、これをタップするとサブタッチバーが開きます。

actionContainer() およびActionContainer::addMenu()も参照してください 。

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

インスタンスへのポインタを返します。シグナルへの接続にのみ使用してください。

[static] bool ActionManager::isPresentationModeEnabled()

プレゼンテーションモードが有効かどうかを返します。

プレゼンテーションモードは、コマンドライン引数 `-presentationMode` を指定して `Qt Creator ` を起動したときに有効になります。プレゼンテーションモードでは、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.