forked from qt-creator/qt-creator
TextEditorActionHandler: Reduce noise
By using namespace Core Change-Id: I97f4f6c42d5e0e9487b174b6837dc4cbb3452f2b Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -29,6 +29,8 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
using namespace Core;
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -37,13 +39,17 @@ class TextEditorActionHandlerPrivate : public QObject
|
|||||||
public:
|
public:
|
||||||
TextEditorActionHandlerPrivate(Utils::Id editorId, Utils::Id contextId, uint optionalActions);
|
TextEditorActionHandlerPrivate(Utils::Id editorId, Utils::Id contextId, uint optionalActions);
|
||||||
|
|
||||||
QAction *registerActionHelper(Utils::Id id, bool scriptable, const QString &title,
|
QAction *registerActionHelper(Utils::Id id,
|
||||||
const QKeySequence &keySequence, Utils::Id menueGroup,
|
bool scriptable,
|
||||||
Core::ActionContainer *container,
|
const QString &title,
|
||||||
std::function<void(bool)> slot)
|
const QKeySequence &keySequence,
|
||||||
|
Utils::Id menueGroup,
|
||||||
|
ActionContainer *container,
|
||||||
|
std::function<void(bool)> slot)
|
||||||
{
|
{
|
||||||
auto result = new QAction(title, this);
|
auto result = new QAction(title, this);
|
||||||
Core::Command *command = Core::ActionManager::registerAction(result, id, Core::Context(m_contextId), scriptable);
|
Command *command
|
||||||
|
= ActionManager::registerAction(result, id, Context(m_contextId), scriptable);
|
||||||
if (!keySequence.isEmpty())
|
if (!keySequence.isEmpty())
|
||||||
command->setDefaultKeySequence(keySequence);
|
command->setDefaultKeySequence(keySequence);
|
||||||
|
|
||||||
@@ -60,7 +66,7 @@ public:
|
|||||||
const QString &title = QString(),
|
const QString &title = QString(),
|
||||||
const QKeySequence &keySequence = QKeySequence(),
|
const QKeySequence &keySequence = QKeySequence(),
|
||||||
Utils::Id menueGroup = Utils::Id(),
|
Utils::Id menueGroup = Utils::Id(),
|
||||||
Core::ActionContainer *container = nullptr)
|
ActionContainer *container = nullptr)
|
||||||
{
|
{
|
||||||
return registerActionHelper(id,
|
return registerActionHelper(id,
|
||||||
scriptable,
|
scriptable,
|
||||||
@@ -77,24 +83,24 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
QAction *registerBoolAction(Utils::Id id,
|
QAction *registerBoolAction(Utils::Id id,
|
||||||
std::function<void(TextEditorWidget *, bool)> slot,
|
std::function<void(TextEditorWidget *, bool)> slot,
|
||||||
bool scriptable = false,
|
bool scriptable = false,
|
||||||
const QString &title = QString(),
|
const QString &title = QString(),
|
||||||
const QKeySequence &keySequence = QKeySequence(),
|
const QKeySequence &keySequence = QKeySequence(),
|
||||||
Utils::Id menueGroup = Utils::Id(),
|
Utils::Id menueGroup = Utils::Id(),
|
||||||
Core::ActionContainer *container = nullptr)
|
ActionContainer *container = nullptr)
|
||||||
{
|
{
|
||||||
return registerActionHelper(id, scriptable, title, keySequence, menueGroup, container,
|
return registerActionHelper(id, scriptable, title, keySequence, menueGroup, container,
|
||||||
[this, slot](bool on) { if (m_currentEditorWidget) slot(m_currentEditorWidget, on); });
|
[this, slot](bool on) { if (m_currentEditorWidget) slot(m_currentEditorWidget, on); });
|
||||||
}
|
}
|
||||||
|
|
||||||
QAction *registerIntAction(Utils::Id id,
|
QAction *registerIntAction(Utils::Id id,
|
||||||
std::function<void(TextEditorWidget *, int)> slot,
|
std::function<void(TextEditorWidget *, int)> slot,
|
||||||
bool scriptable = false,
|
bool scriptable = false,
|
||||||
const QString &title = QString(),
|
const QString &title = QString(),
|
||||||
const QKeySequence &keySequence = QKeySequence(),
|
const QKeySequence &keySequence = QKeySequence(),
|
||||||
Utils::Id menueGroup = Utils::Id(),
|
Utils::Id menueGroup = Utils::Id(),
|
||||||
Core::ActionContainer *container = nullptr)
|
ActionContainer *container = nullptr)
|
||||||
{
|
{
|
||||||
return registerActionHelper(id, scriptable, title, keySequence, menueGroup, container,
|
return registerActionHelper(id, scriptable, title, keySequence, menueGroup, container,
|
||||||
[this, slot](bool on) { if (m_currentEditorWidget) slot(m_currentEditorWidget, on); });
|
[this, slot](bool on) { if (m_currentEditorWidget) slot(m_currentEditorWidget, on); });
|
||||||
@@ -108,7 +114,7 @@ public:
|
|||||||
void updateUndoAction(bool on);
|
void updateUndoAction(bool on);
|
||||||
void updateCopyAction(bool on);
|
void updateCopyAction(bool on);
|
||||||
|
|
||||||
void updateCurrentEditor(Core::IEditor *editor);
|
void updateCurrentEditor(IEditor *editor);
|
||||||
|
|
||||||
void setCanUndoCallback(const TextEditorActionHandler::Predicate &callback);
|
void setCanUndoCallback(const TextEditorActionHandler::Predicate &callback);
|
||||||
void setCanRedoCallback(const TextEditorActionHandler::Predicate &callback);
|
void setCanRedoCallback(const TextEditorActionHandler::Predicate &callback);
|
||||||
@@ -139,7 +145,7 @@ public:
|
|||||||
|
|
||||||
uint m_optionalActions = TextEditorActionHandler::None;
|
uint m_optionalActions = TextEditorActionHandler::None;
|
||||||
QPointer<TextEditorWidget> m_currentEditorWidget;
|
QPointer<TextEditorWidget> m_currentEditorWidget;
|
||||||
QPointer<Core::IEditor> m_currentEditor;
|
QPointer<IEditor> m_currentEditor;
|
||||||
Utils::Id m_editorId;
|
Utils::Id m_editorId;
|
||||||
Utils::Id m_contextId;
|
Utils::Id m_contextId;
|
||||||
|
|
||||||
@@ -156,8 +162,10 @@ TextEditorActionHandlerPrivate::TextEditorActionHandlerPrivate
|
|||||||
, m_contextId(contextId)
|
, m_contextId(contextId)
|
||||||
{
|
{
|
||||||
createActions();
|
createActions();
|
||||||
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
|
connect(EditorManager::instance(),
|
||||||
this, &TextEditorActionHandlerPrivate::updateCurrentEditor);
|
&EditorManager::currentEditorChanged,
|
||||||
|
this,
|
||||||
|
&TextEditorActionHandlerPrivate::updateCurrentEditor);
|
||||||
connect(TextEditorSettings::instance(), &TextEditorSettings::fontSettingsChanged,
|
connect(TextEditorSettings::instance(), &TextEditorSettings::fontSettingsChanged,
|
||||||
this, &TextEditorActionHandlerPrivate::updateActions);
|
this, &TextEditorActionHandlerPrivate::updateActions);
|
||||||
}
|
}
|
||||||
@@ -179,11 +187,12 @@ void TextEditorActionHandlerPrivate::createActions()
|
|||||||
[] (TextEditorWidget *w) { w->paste(); }, true);
|
[] (TextEditorWidget *w) { w->paste(); }, true);
|
||||||
registerAction(SELECTALL,
|
registerAction(SELECTALL,
|
||||||
[] (TextEditorWidget *w) { w->selectAll(); }, true);
|
[] (TextEditorWidget *w) { w->selectAll(); }, true);
|
||||||
registerAction(GOTO, [] (TextEditorWidget *) {
|
registerAction(GOTO, [](TextEditorWidget *) {
|
||||||
Core::LocatorManager::showFilter(TextEditorPlugin::lineNumberFilter());
|
LocatorManager::showFilter(TextEditorPlugin::lineNumberFilter());
|
||||||
});
|
});
|
||||||
m_modifyingActions << registerAction(PRINT,
|
m_modifyingActions << registerAction(PRINT, [](TextEditorWidget *widget) {
|
||||||
[] (TextEditorWidget *widget) { widget->print(Core::ICore::printer()); });
|
widget->print(ICore::printer());
|
||||||
|
});
|
||||||
m_modifyingActions << registerAction(DELETE_LINE,
|
m_modifyingActions << registerAction(DELETE_LINE,
|
||||||
[] (TextEditorWidget *w) { w->deleteLine(); }, true, Tr::tr("Delete &Line"));
|
[] (TextEditorWidget *w) { w->deleteLine(); }, true, Tr::tr("Delete &Line"));
|
||||||
m_modifyingActions << registerAction(DELETE_END_OF_LINE,
|
m_modifyingActions << registerAction(DELETE_END_OF_LINE,
|
||||||
@@ -192,9 +201,12 @@ void TextEditorActionHandlerPrivate::createActions()
|
|||||||
[] (TextEditorWidget *w) { w->deleteEndOfWord(); }, true, Tr::tr("Delete Word from Cursor On"));
|
[] (TextEditorWidget *w) { w->deleteEndOfWord(); }, true, Tr::tr("Delete Word from Cursor On"));
|
||||||
m_modifyingActions << registerAction(DELETE_END_OF_WORD_CAMEL_CASE,
|
m_modifyingActions << registerAction(DELETE_END_OF_WORD_CAMEL_CASE,
|
||||||
[] (TextEditorWidget *w) { w->deleteEndOfWordCamelCase(); }, true, Tr::tr("Delete Word Camel Case from Cursor On"));
|
[] (TextEditorWidget *w) { w->deleteEndOfWordCamelCase(); }, true, Tr::tr("Delete Word Camel Case from Cursor On"));
|
||||||
m_modifyingActions << registerAction(DELETE_START_OF_LINE,
|
m_modifyingActions << registerAction(
|
||||||
[] (TextEditorWidget *w) { w->deleteStartOfLine(); }, true, Tr::tr("Delete Line up to Cursor"),
|
DELETE_START_OF_LINE,
|
||||||
Core::useMacShortcuts ? QKeySequence(Tr::tr("Ctrl+Backspace")) : QKeySequence());
|
[](TextEditorWidget *w) { w->deleteStartOfLine(); },
|
||||||
|
true,
|
||||||
|
Tr::tr("Delete Line up to Cursor"),
|
||||||
|
Core::useMacShortcuts ? QKeySequence(Tr::tr("Ctrl+Backspace")) : QKeySequence());
|
||||||
m_modifyingActions << registerAction(DELETE_START_OF_WORD,
|
m_modifyingActions << registerAction(DELETE_START_OF_WORD,
|
||||||
[] (TextEditorWidget *w) { w->deleteStartOfWord(); }, true, Tr::tr("Delete Word up to Cursor"));
|
[] (TextEditorWidget *w) { w->deleteStartOfWord(); }, true, Tr::tr("Delete Word up to Cursor"));
|
||||||
m_modifyingActions << registerAction(DELETE_START_OF_WORD_CAMEL_CASE,
|
m_modifyingActions << registerAction(DELETE_START_OF_WORD_CAMEL_CASE,
|
||||||
@@ -273,7 +285,7 @@ void TextEditorActionHandlerPrivate::createActions()
|
|||||||
QKeySequence(Tr::tr("Ctrl+Down")));
|
QKeySequence(Tr::tr("Ctrl+Down")));
|
||||||
|
|
||||||
// register "Edit" Menu Actions
|
// register "Edit" Menu Actions
|
||||||
Core::ActionContainer *editMenu = Core::ActionManager::actionContainer(M_EDIT);
|
ActionContainer *editMenu = ActionManager::actionContainer(M_EDIT);
|
||||||
registerAction(SELECT_ENCODING,
|
registerAction(SELECT_ENCODING,
|
||||||
[] (TextEditorWidget *w) { w->selectEncoding(); }, false, Tr::tr("Select Encoding..."),
|
[] (TextEditorWidget *w) { w->selectEncoding(); }, false, Tr::tr("Select Encoding..."),
|
||||||
QKeySequence(), G_EDIT_OTHER, editMenu);
|
QKeySequence(), G_EDIT_OTHER, editMenu);
|
||||||
@@ -285,7 +297,7 @@ void TextEditorActionHandlerPrivate::createActions()
|
|||||||
QKeySequence(Core::useMacShortcuts ? Tr::tr("Ctrl+Alt+Shift+V") : QString()), G_EDIT_COPYPASTE, editMenu);
|
QKeySequence(Core::useMacShortcuts ? Tr::tr("Ctrl+Alt+Shift+V") : QString()), G_EDIT_COPYPASTE, editMenu);
|
||||||
|
|
||||||
// register "Edit -> Advanced" Menu Actions
|
// register "Edit -> Advanced" Menu Actions
|
||||||
Core::ActionContainer *advancedEditMenu = Core::ActionManager::actionContainer(M_EDIT_ADVANCED);
|
ActionContainer *advancedEditMenu = ActionManager::actionContainer(M_EDIT_ADVANCED);
|
||||||
m_autoIndentAction = registerAction(AUTO_INDENT_SELECTION,
|
m_autoIndentAction = registerAction(AUTO_INDENT_SELECTION,
|
||||||
[] (TextEditorWidget *w) { w->autoIndent(); }, true, Tr::tr("Auto-&indent Selection"),
|
[] (TextEditorWidget *w) { w->autoIndent(); }, true, Tr::tr("Auto-&indent Selection"),
|
||||||
QKeySequence(Tr::tr("Ctrl+I")),
|
QKeySequence(Tr::tr("Ctrl+I")),
|
||||||
@@ -567,7 +579,7 @@ void TextEditorActionHandlerPrivate::updateCopyAction(bool hasCopyableText)
|
|||||||
m_copyHtmlAction->setEnabled(hasCopyableText);
|
m_copyHtmlAction->setEnabled(hasCopyableText);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorActionHandlerPrivate::updateCurrentEditor(Core::IEditor *editor)
|
void TextEditorActionHandlerPrivate::updateCurrentEditor(IEditor *editor)
|
||||||
{
|
{
|
||||||
if (m_currentEditorWidget)
|
if (m_currentEditorWidget)
|
||||||
m_currentEditorWidget->disconnect(this);
|
m_currentEditorWidget->disconnect(this);
|
||||||
@@ -619,7 +631,7 @@ TextEditorActionHandler::~TextEditorActionHandler()
|
|||||||
|
|
||||||
void TextEditorActionHandler::updateCurrentEditor()
|
void TextEditorActionHandler::updateCurrentEditor()
|
||||||
{
|
{
|
||||||
d->updateCurrentEditor(Core::EditorManager::currentEditor());
|
d->updateCurrentEditor(EditorManager::currentEditor());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorActionHandler::updateActions()
|
void TextEditorActionHandler::updateActions()
|
||||||
|
Reference in New Issue
Block a user