diff options
author | Thomas Hartmann <thomas.hartmann@qt.io> | 2017-01-05 17:44:10 +0100 |
---|---|---|
committer | Thomas Hartmann <thomas.hartmann@qt.io> | 2017-01-05 16:44:32 +0000 |
commit | e575f054dbe2f07d537db6e13e9ee729788f7cb1 (patch) | |
tree | 6bbbedb6d3aad63135f90bf5f52e5a0247014478 /src/plugins/qmldesigner/shortcutmanager.cpp | |
parent | a8c14b558afda35607c93bbbc34e7e33b005815c (diff) |
QmlDesigner: Adding a toolbar
* Icons are not the final ones.
* I fixed a couple of glitches and cleaned up the code.
- Action for copy and paste/delete were not properly updated
- Delete had no icon
- Using std::function for action predicates and operations
- The context menu has no icons. This way we avoid having to define 2
icons.
Change-Id: Ic23cbc78ba299c19e07e8de775eb813aae55db9b
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'src/plugins/qmldesigner/shortcutmanager.cpp')
-rw-r--r-- | src/plugins/qmldesigner/shortcutmanager.cpp | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/src/plugins/qmldesigner/shortcutmanager.cpp b/src/plugins/qmldesigner/shortcutmanager.cpp index 0dde203732..bf44d8ab21 100644 --- a/src/plugins/qmldesigner/shortcutmanager.cpp +++ b/src/plugins/qmldesigner/shortcutmanager.cpp @@ -27,6 +27,10 @@ #include "designersettings.h" +#include <viewmanager.h> +#include <designeractionmanagerview.h> +#include <componentcore_constants.h> + #include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/actionmanager/actioncontainer.h> #include <coreplugin/actionmanager/command.h> @@ -39,6 +43,8 @@ #include <qmljseditor/qmljseditordocument.h> #include <utils/hostosinfo.h> +#include <utils/proxyaction.h> +#include <utils/utilsicons.h> #include <utils/qtcassert.h> #include <qmljs/qmljsreformatter.h> @@ -47,6 +53,14 @@ #include "qmldesignerplugin.h" #include "designmodewidget.h" +#include <QApplication> +#include <QClipboard> + +static void updateClipboard(QAction *action) +{ + const bool dataInClipboard = !QApplication::clipboard()->text().isEmpty(); + action->setEnabled(dataInClipboard); +} namespace QmlDesigner { @@ -139,6 +153,8 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex + Core::Command *command = nullptr; + //Save As Core::ActionManager::registerAction(&m_saveAsAction, Core::Constants::SAVEAS, qmlDesignerMainContext); connect(&m_saveAsAction, SIGNAL(triggered()), em, SLOT(saveDocumentAs())); @@ -147,6 +163,8 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex Core::ActionManager::registerAction(&m_closeCurrentEditorAction, Core::Constants::CLOSE, qmlDesignerMainContext); connect(&m_closeCurrentEditorAction, SIGNAL(triggered()), em, SLOT(slotCloseCurrentEditorOrDocument())); + DesignerActionManager &designerActionManager = QmlDesignerPlugin::instance()->viewManager().designerActionManager(); + //Close All Core::ActionManager::registerAction(&m_closeAllEditorsAction, Core::Constants::CLOSEALL, qmlDesignerMainContext); connect(&m_closeAllEditorsAction, SIGNAL(triggered()), em, SLOT(closeAllEditors())); @@ -156,10 +174,11 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex connect(&m_closeOtherEditorsAction, SIGNAL(triggered()), em, SLOT(closeOtherDocuments())); // Undo / Redo - Core::ActionManager::registerAction(&m_undoAction, Core::Constants::UNDO, qmlDesignerMainContext); - Core::ActionManager::registerAction(&m_redoAction, Core::Constants::REDO, qmlDesignerMainContext); + command = Core::ActionManager::registerAction(&m_undoAction, Core::Constants::UNDO, qmlDesignerMainContext); + designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 310, Utils::Icons::UNDO_TOOLBAR.icon()); + command = Core::ActionManager::registerAction(&m_redoAction, Core::Constants::REDO, qmlDesignerMainContext); + designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 300, Utils::Icons::REDO_TOOLBAR.icon()); - Core::Command *command; //GoIntoComponent command = Core::ActionManager::registerAction(&m_goIntoComponentAction, @@ -168,6 +187,8 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex //Edit Menu + m_deleteAction.setIcon(QIcon::fromTheme(QLatin1String("edit-cut"), Utils::Icons::EDIT_CLEAR_TOOLBAR.icon())); + Core::ActionManager::registerAction(&m_deleteAction, QmlDesigner::Constants::C_BACKSPACE, qmlDesignerFormEditorContext); command = Core::ActionManager::registerAction(&m_deleteAction, QmlDesigner::Constants::C_BACKSPACE, qmlDesignerNavigatorContext); command->setDefaultKeySequence(QKeySequence(Qt::Key_Backspace)); @@ -181,21 +202,25 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex command->setAttribute(Core::Command::CA_Hide); // don't show delete in other modes if (!Utils::HostOsInfo::isMacHost()) editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE); + designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 280); Core::ActionManager::registerAction(&m_cutAction, Core::Constants::CUT, qmlDesignerFormEditorContext); command = Core::ActionManager::registerAction(&m_cutAction, Core::Constants::CUT, qmlDesignerNavigatorContext); command->setDefaultKeySequence(QKeySequence::Cut); editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE); + designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 260, Utils::Icons::CUT_TOOLBAR.icon()); Core::ActionManager::registerAction(&m_copyAction, Core::Constants::COPY, qmlDesignerFormEditorContext); command = Core::ActionManager::registerAction(&m_copyAction, Core::Constants::COPY, qmlDesignerNavigatorContext); command->setDefaultKeySequence(QKeySequence::Copy); editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE); + designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 250, Utils::Icons::COPY_TOOLBAR.icon()); Core::ActionManager::registerAction(&m_pasteAction, Core::Constants::PASTE, qmlDesignerFormEditorContext); command = Core::ActionManager::registerAction(&m_pasteAction, Core::Constants::PASTE, qmlDesignerNavigatorContext); command->setDefaultKeySequence(QKeySequence::Paste); editMenu->addAction(command, Core::Constants::G_EDIT_COPYPASTE); + designerActionManager.addCreatorCommand(command, ComponentCoreConstants::editCategory, 240, Utils::Icons::PASTE_TOOLBAR.icon()); Core::ActionManager::registerAction(&m_selectAllAction, Core::Constants::SELECTALL, qmlDesignerFormEditorContext); command = Core::ActionManager::registerAction(&m_selectAllAction, Core::Constants::SELECTALL, qmlDesignerNavigatorContext); @@ -225,6 +250,17 @@ void ShortCutManager::registerActions(const Core::Context &qmlDesignerMainContex m_escapeAction.setEnabled(false); Core::ActionManager::registerAction(&m_hideSidebarsAction, Core::Constants::TOGGLE_SIDEBAR, qmlDesignerMainContext); + + connect(designerActionManager.view(), &DesignerActionManagerView::selectionChanged, this, [this](bool itemsSelected) { + m_deleteAction.setEnabled(itemsSelected); + m_cutAction.setEnabled(itemsSelected); + m_copyAction.setEnabled(itemsSelected); + }); + + updateClipboard(&m_pasteAction); + connect(QApplication::clipboard(), &QClipboard::QClipboard::changed, this, [this]() { + updateClipboard(&m_pasteAction); + }); } void ShortCutManager::updateActions(Core::IEditor* currentEditor) |