2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "texteditoractionhandler.h"
|
2009-12-08 17:43:01 +01:00
|
|
|
|
2014-09-26 09:14:03 +02:00
|
|
|
#include "texteditor.h"
|
2009-12-08 17:43:01 +01:00
|
|
|
#include "displaysettings.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "linenumberfilter.h"
|
2009-12-08 17:43:01 +01:00
|
|
|
#include "texteditorconstants.h"
|
|
|
|
|
#include "texteditorplugin.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-02-11 14:00:09 +01:00
|
|
|
#include <aggregation/aggregate.h>
|
|
|
|
|
|
2014-01-13 16:17:34 +01:00
|
|
|
#include <coreplugin/locator/locatormanager.h>
|
2009-01-20 15:31:33 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2015-02-26 13:22:35 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2009-01-13 13:39:31 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
2015-02-26 13:38:54 +01:00
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2013-04-25 20:24:06 +02:00
|
|
|
#include <utils/hostosinfo.h>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-08-06 13:42:46 +02:00
|
|
|
#include <QDebug>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QAction>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-08-19 16:00:58 +02:00
|
|
|
#include <functional>
|
|
|
|
|
|
2014-07-01 14:26:55 +02:00
|
|
|
namespace TextEditor {
|
|
|
|
|
namespace Internal {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-07-01 14:26:55 +02:00
|
|
|
class TextEditorActionHandlerPrivate : public QObject
|
|
|
|
|
{
|
2015-03-23 12:41:06 +03:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(TextEditor::Internal::TextEditorActionHandler)
|
2020-02-05 14:13:28 +01:00
|
|
|
|
2014-07-01 14:26:55 +02:00
|
|
|
public:
|
2020-06-26 13:59:38 +02:00
|
|
|
TextEditorActionHandlerPrivate(Utils::Id editorId, Utils::Id contextId, uint optionalActions);
|
2014-07-01 14:26:55 +02:00
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
QAction *registerActionHelper(Utils::Id id, bool scriptable, const QString &title,
|
|
|
|
|
const QKeySequence &keySequence, Utils::Id menueGroup,
|
2014-08-19 16:00:58 +02:00
|
|
|
Core::ActionContainer *container,
|
|
|
|
|
std::function<void(bool)> slot)
|
|
|
|
|
{
|
2018-09-20 01:16:01 +03:00
|
|
|
auto result = new QAction(title, this);
|
2014-08-19 16:00:58 +02:00
|
|
|
Core::Command *command = Core::ActionManager::registerAction(result, id, Core::Context(m_contextId), scriptable);
|
|
|
|
|
if (!keySequence.isEmpty())
|
|
|
|
|
command->setDefaultKeySequence(keySequence);
|
|
|
|
|
|
2015-06-25 12:52:16 +02:00
|
|
|
if (container && menueGroup.isValid())
|
2014-08-19 16:00:58 +02:00
|
|
|
container->addAction(command, menueGroup);
|
|
|
|
|
|
|
|
|
|
connect(result, &QAction::triggered, slot);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
QAction *registerAction(Utils::Id id,
|
2014-09-26 11:37:54 +02:00
|
|
|
std::function<void(TextEditorWidget *)> slot,
|
2014-08-19 16:00:58 +02:00
|
|
|
bool scriptable = false,
|
|
|
|
|
const QString &title = QString(),
|
|
|
|
|
const QKeySequence &keySequence = QKeySequence(),
|
2020-06-26 13:59:38 +02:00
|
|
|
Utils::Id menueGroup = Utils::Id(),
|
2018-09-20 01:16:01 +03:00
|
|
|
Core::ActionContainer *container = nullptr)
|
2014-08-19 16:00:58 +02:00
|
|
|
{
|
|
|
|
|
return registerActionHelper(id, scriptable, title, keySequence, menueGroup, container,
|
|
|
|
|
[this, slot](bool) { if (m_currentEditorWidget) slot(m_currentEditorWidget); });
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
QAction *registerBoolAction(Utils::Id id,
|
2014-09-26 11:37:54 +02:00
|
|
|
std::function<void(TextEditorWidget *, bool)> slot,
|
2014-08-19 16:00:58 +02:00
|
|
|
bool scriptable = false,
|
|
|
|
|
const QString &title = QString(),
|
|
|
|
|
const QKeySequence &keySequence = QKeySequence(),
|
2020-06-26 13:59:38 +02:00
|
|
|
Utils::Id menueGroup = Utils::Id(),
|
2018-09-20 01:16:01 +03:00
|
|
|
Core::ActionContainer *container = nullptr)
|
2014-08-19 16:00:58 +02:00
|
|
|
{
|
|
|
|
|
return registerActionHelper(id, scriptable, title, keySequence, menueGroup, container,
|
|
|
|
|
[this, slot](bool on) { if (m_currentEditorWidget) slot(m_currentEditorWidget, on); });
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
QAction *registerIntAction(Utils::Id id,
|
2014-09-26 11:37:54 +02:00
|
|
|
std::function<void(TextEditorWidget *, int)> slot,
|
2014-07-01 14:26:55 +02:00
|
|
|
bool scriptable = false,
|
|
|
|
|
const QString &title = QString(),
|
|
|
|
|
const QKeySequence &keySequence = QKeySequence(),
|
2020-06-26 13:59:38 +02:00
|
|
|
Utils::Id menueGroup = Utils::Id(),
|
2018-09-20 01:16:01 +03:00
|
|
|
Core::ActionContainer *container = nullptr)
|
2014-08-19 16:00:58 +02:00
|
|
|
{
|
|
|
|
|
return registerActionHelper(id, scriptable, title, keySequence, menueGroup, container,
|
|
|
|
|
[this, slot](bool on) { if (m_currentEditorWidget) slot(m_currentEditorWidget, on); });
|
|
|
|
|
}
|
2014-07-01 14:26:55 +02:00
|
|
|
|
|
|
|
|
void createActions();
|
|
|
|
|
|
|
|
|
|
void updateActions();
|
2020-06-15 10:14:35 +02:00
|
|
|
void updateOptionalActions();
|
2014-08-19 16:00:58 +02:00
|
|
|
void updateRedoAction(bool on);
|
|
|
|
|
void updateUndoAction(bool on);
|
|
|
|
|
void updateCopyAction(bool on);
|
|
|
|
|
|
2014-07-01 14:26:55 +02:00
|
|
|
void updateCurrentEditor(Core::IEditor *editor);
|
|
|
|
|
|
|
|
|
|
public:
|
2017-05-08 13:52:34 +02:00
|
|
|
TextEditorActionHandler::TextEditorWidgetResolver m_findTextWidget;
|
2017-01-24 14:25:11 +01:00
|
|
|
QAction *m_undoAction = nullptr;
|
|
|
|
|
QAction *m_redoAction = nullptr;
|
|
|
|
|
QAction *m_copyAction = nullptr;
|
|
|
|
|
QAction *m_cutAction = nullptr;
|
|
|
|
|
QAction *m_pasteAction = nullptr;
|
|
|
|
|
QAction *m_circularPasteAction = nullptr;
|
|
|
|
|
QAction *m_switchUtf8bomAction = nullptr;
|
|
|
|
|
QAction *m_selectAllAction = nullptr;
|
|
|
|
|
QAction *m_gotoAction = nullptr;
|
|
|
|
|
QAction *m_printAction = nullptr;
|
2019-11-18 10:38:35 +01:00
|
|
|
QAction *m_autoIndentAction = nullptr;
|
|
|
|
|
QAction *m_autoFormatAction = nullptr;
|
2017-01-24 14:25:11 +01:00
|
|
|
QAction *m_rewrapParagraphAction = nullptr;
|
|
|
|
|
QAction *m_visualizeWhitespaceAction = nullptr;
|
|
|
|
|
QAction *m_cleanWhitespaceAction = nullptr;
|
|
|
|
|
QAction *m_textWrappingAction = nullptr;
|
|
|
|
|
QAction *m_unCommentSelectionAction = nullptr;
|
|
|
|
|
QAction *m_unfoldAllAction = nullptr;
|
|
|
|
|
QAction *m_foldAction = nullptr;
|
|
|
|
|
QAction *m_unfoldAction = nullptr;
|
|
|
|
|
QAction *m_cutLineAction = nullptr;
|
|
|
|
|
QAction *m_copyLineAction = nullptr;
|
|
|
|
|
QAction *m_duplicateSelectionAction = nullptr;
|
|
|
|
|
QAction *m_duplicateSelectionAndCommentAction = nullptr;
|
|
|
|
|
QAction *m_deleteLineAction = nullptr;
|
2017-04-26 10:48:48 +02:00
|
|
|
QAction *m_deleteEndOfLineAction = nullptr;
|
2017-01-24 14:25:11 +01:00
|
|
|
QAction *m_deleteEndOfWordAction = nullptr;
|
|
|
|
|
QAction *m_deleteEndOfWordCamelCaseAction = nullptr;
|
2017-04-26 10:48:48 +02:00
|
|
|
QAction *m_deleteStartOfLineAction = nullptr;
|
2017-01-24 14:25:11 +01:00
|
|
|
QAction *m_deleteStartOfWordAction = nullptr;
|
|
|
|
|
QAction *m_deleteStartOfWordCamelCaseAction = nullptr;
|
|
|
|
|
QAction *m_selectEncodingAction = nullptr;
|
|
|
|
|
QAction *m_increaseFontSizeAction = nullptr;
|
|
|
|
|
QAction *m_decreaseFontSizeAction = nullptr;
|
|
|
|
|
QAction *m_resetFontSizeAction = nullptr;
|
|
|
|
|
QAction *m_gotoBlockStartAction = nullptr;
|
|
|
|
|
QAction *m_gotoBlockEndAction = nullptr;
|
|
|
|
|
QAction *m_gotoBlockStartWithSelectionAction = nullptr;
|
|
|
|
|
QAction *m_gotoBlockEndWithSelectionAction = nullptr;
|
|
|
|
|
QAction *m_selectBlockUpAction = nullptr;
|
|
|
|
|
QAction *m_selectBlockDownAction = nullptr;
|
|
|
|
|
QAction *m_viewPageUpAction = nullptr;
|
|
|
|
|
QAction *m_viewPageDownAction = nullptr;
|
|
|
|
|
QAction *m_viewLineUpAction = nullptr;
|
|
|
|
|
QAction *m_viewLineDownAction = nullptr;
|
|
|
|
|
QAction *m_moveLineUpAction = nullptr;
|
|
|
|
|
QAction *m_moveLineDownAction = nullptr;
|
|
|
|
|
QAction *m_copyLineUpAction = nullptr;
|
|
|
|
|
QAction *m_copyLineDownAction = nullptr;
|
|
|
|
|
QAction *m_joinLinesAction = nullptr;
|
|
|
|
|
QAction *m_insertLineAboveAction = nullptr;
|
|
|
|
|
QAction *m_insertLineBelowAction = nullptr;
|
|
|
|
|
QAction *m_upperCaseSelectionAction = nullptr;
|
|
|
|
|
QAction *m_lowerCaseSelectionAction = nullptr;
|
2017-08-13 20:38:08 +03:00
|
|
|
QAction *m_sortSelectedLinesAction = nullptr;
|
2017-01-24 14:25:11 +01:00
|
|
|
QAction *m_indentAction = nullptr;
|
|
|
|
|
QAction *m_unindentAction = nullptr;
|
|
|
|
|
QAction *m_followSymbolAction = nullptr;
|
|
|
|
|
QAction *m_followSymbolInNextSplitAction = nullptr;
|
2018-11-28 07:26:14 +01:00
|
|
|
QAction *m_findUsageAction = nullptr;
|
2020-05-06 07:30:33 +02:00
|
|
|
QAction *m_renameSymbolAction = nullptr;
|
2017-01-24 14:25:11 +01:00
|
|
|
QAction *m_jumpToFileAction = nullptr;
|
|
|
|
|
QAction *m_jumpToFileInNextSplitAction = nullptr;
|
2014-07-01 14:26:55 +02:00
|
|
|
QList<QAction *> m_modifyingActions;
|
|
|
|
|
|
2017-01-24 14:25:11 +01:00
|
|
|
uint m_optionalActions = TextEditorActionHandler::None;
|
2014-09-26 11:37:54 +02:00
|
|
|
QPointer<TextEditorWidget> m_currentEditorWidget;
|
2020-06-26 13:59:38 +02:00
|
|
|
Utils::Id m_editorId;
|
|
|
|
|
Utils::Id m_contextId;
|
2014-07-01 14:26:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TextEditorActionHandlerPrivate::TextEditorActionHandlerPrivate
|
2020-06-26 13:59:38 +02:00
|
|
|
(Utils::Id editorId, Utils::Id contextId, uint optionalActions)
|
2020-02-05 17:51:41 +01:00
|
|
|
: m_optionalActions(optionalActions)
|
2017-05-08 16:06:35 +02:00
|
|
|
, m_editorId(editorId)
|
2017-01-24 14:25:11 +01:00
|
|
|
, m_contextId(contextId)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-12-10 15:54:20 +01:00
|
|
|
createActions();
|
2014-08-19 16:00:58 +02:00
|
|
|
connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged,
|
|
|
|
|
this, &TextEditorActionHandlerPrivate::updateCurrentEditor);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-01 14:26:55 +02:00
|
|
|
void TextEditorActionHandlerPrivate::createActions()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-05-17 16:32:57 +02:00
|
|
|
using namespace Core::Constants;
|
|
|
|
|
using namespace TextEditor::Constants;
|
|
|
|
|
|
|
|
|
|
m_undoAction = registerAction(UNDO,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->undo(); }, true, tr("&Undo"));
|
2013-05-17 16:32:57 +02:00
|
|
|
m_redoAction = registerAction(REDO,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->redo(); }, true, tr("&Redo"));
|
2013-05-17 16:32:57 +02:00
|
|
|
m_copyAction = registerAction(COPY,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->copy(); }, true);
|
2013-05-17 16:32:57 +02:00
|
|
|
m_cutAction = registerAction(CUT,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->cut(); }, true);
|
2013-05-17 16:32:57 +02:00
|
|
|
m_pasteAction = registerAction(PASTE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->paste(); }, true);
|
2013-05-17 16:32:57 +02:00
|
|
|
m_selectAllAction = registerAction(SELECTALL,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->selectAll(); }, true);
|
|
|
|
|
m_gotoAction = registerAction(GOTO, [] (TextEditorWidget *) {
|
2014-08-19 16:00:58 +02:00
|
|
|
QString locatorString = TextEditorPlugin::lineNumberFilter()->shortcutString();
|
|
|
|
|
locatorString += QLatin1Char(' ');
|
|
|
|
|
const int selectionStart = locatorString.size();
|
2020-02-05 17:51:41 +01:00
|
|
|
locatorString += tr("<line>:<column>");
|
2014-08-19 16:00:58 +02:00
|
|
|
Core::LocatorManager::show(locatorString, selectionStart, locatorString.size() - selectionStart);
|
|
|
|
|
});
|
2014-08-27 18:22:04 +02:00
|
|
|
m_printAction = registerAction(PRINT,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *widget) { widget->print(Core::ICore::printer()); });
|
2013-05-17 16:32:57 +02:00
|
|
|
m_deleteLineAction = registerAction(DELETE_LINE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->deleteLine(); }, true, tr("Delete &Line"));
|
2017-04-26 10:48:48 +02:00
|
|
|
m_deleteEndOfLineAction = registerAction(DELETE_END_OF_LINE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->deleteEndOfLine(); }, true, tr("Delete Line from Cursor On"));
|
2013-05-17 16:32:57 +02:00
|
|
|
m_deleteEndOfWordAction = registerAction(DELETE_END_OF_WORD,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->deleteEndOfWord(); }, true, tr("Delete Word from Cursor On"));
|
2013-05-17 16:32:57 +02:00
|
|
|
m_deleteEndOfWordCamelCaseAction = registerAction(DELETE_END_OF_WORD_CAMEL_CASE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->deleteEndOfWordCamelCase(); }, true, tr("Delete Word Camel Case from Cursor On"));
|
2017-04-26 10:48:48 +02:00
|
|
|
m_deleteStartOfLineAction = registerAction(DELETE_START_OF_LINE,
|
2020-09-17 10:51:05 +02:00
|
|
|
[] (TextEditorWidget *w) { w->deleteStartOfLine(); }, true, tr("Delete Line up to Cursor"),
|
|
|
|
|
Core::useMacShortcuts ? QKeySequence(tr("Ctrl+Backspace")) : QKeySequence());
|
2013-05-17 16:32:57 +02:00
|
|
|
m_deleteStartOfWordAction = registerAction(DELETE_START_OF_WORD,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->deleteStartOfWord(); }, true, tr("Delete Word up to Cursor"));
|
2013-05-17 16:32:57 +02:00
|
|
|
m_deleteStartOfWordCamelCaseAction = registerAction(DELETE_START_OF_WORD_CAMEL_CASE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->deleteStartOfWordCamelCase(); }, true, tr("Delete Word Camel Case up to Cursor"));
|
2013-05-17 16:32:57 +02:00
|
|
|
m_gotoBlockStartWithSelectionAction = registerAction(GOTO_BLOCK_START_WITH_SELECTION,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoBlockStartWithSelection(); }, true, tr("Go to Block Start with Selection"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+{")));
|
|
|
|
|
m_gotoBlockEndWithSelectionAction = registerAction(GOTO_BLOCK_END_WITH_SELECTION,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoBlockEndWithSelection(); }, true, tr("Go to Block End with Selection"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+}")));
|
|
|
|
|
m_moveLineUpAction = registerAction(MOVE_LINE_UP,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->moveLineUp(); }, true, tr("Move Line Up"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+Shift+Up")));
|
|
|
|
|
m_moveLineDownAction = registerAction(MOVE_LINE_DOWN,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->moveLineDown(); }, true, tr("Move Line Down"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+Shift+Down")));
|
|
|
|
|
m_copyLineUpAction = registerAction(COPY_LINE_UP,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->copyLineUp(); }, true, tr("Copy Line Up"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+Alt+Up")));
|
|
|
|
|
m_copyLineDownAction = registerAction(COPY_LINE_DOWN,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->copyLineDown(); }, true, tr("Copy Line Down"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+Alt+Down")));
|
|
|
|
|
m_joinLinesAction = registerAction(JOIN_LINES,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->joinLines(); }, true, tr("Join Lines"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+J")));
|
|
|
|
|
m_insertLineAboveAction = registerAction(INSERT_LINE_ABOVE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->insertLineAbove(); }, true, tr("Insert Line Above Current Line"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+Shift+Return")));
|
|
|
|
|
m_insertLineBelowAction = registerAction(INSERT_LINE_BELOW,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->insertLineBelow(); }, true, tr("Insert Line Below Current Line"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+Return")));
|
|
|
|
|
m_switchUtf8bomAction = registerAction(SWITCH_UTF8BOM,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->switchUtf8bom(); }, true, tr("Toggle UTF-8 BOM"));
|
2013-05-17 16:32:57 +02:00
|
|
|
m_indentAction = registerAction(INDENT,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->indent(); }, true, tr("Indent"));
|
2013-05-17 16:32:57 +02:00
|
|
|
m_unindentAction = registerAction(UNINDENT,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->unindent(); }, true, tr("Unindent"));
|
2013-05-17 16:32:57 +02:00
|
|
|
m_followSymbolAction = registerAction(FOLLOW_SYMBOL_UNDER_CURSOR,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->openLinkUnderCursor(); }, true, tr("Follow Symbol Under Cursor"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(Qt::Key_F2));
|
|
|
|
|
m_followSymbolInNextSplitAction = registerAction(FOLLOW_SYMBOL_UNDER_CURSOR_IN_NEXT_SPLIT,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->openLinkUnderCursorInNextSplit(); }, true, tr("Follow Symbol Under Cursor in Next Split"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(Utils::HostOsInfo::isMacHost() ? tr("Meta+E, F2") : tr("Ctrl+E, F2")));
|
2018-11-28 07:26:14 +01:00
|
|
|
m_findUsageAction = registerAction(FIND_USAGES,
|
|
|
|
|
[] (TextEditorWidget *w) { w->findUsages(); }, true, tr("Find References to Symbol Under Cursor"),
|
|
|
|
|
QKeySequence(tr("Ctrl+Shift+U")));
|
2020-05-06 07:30:33 +02:00
|
|
|
m_renameSymbolAction = registerAction(RENAME_SYMBOL,
|
|
|
|
|
[] (TextEditorWidget *w) { w->renameSymbolUnderCursor(); }, true, tr("Rename Symbol Under Cursor"),
|
|
|
|
|
QKeySequence(tr("Ctrl+Shift+R")));
|
2013-05-17 16:32:57 +02:00
|
|
|
m_jumpToFileAction = registerAction(JUMP_TO_FILE_UNDER_CURSOR,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->openLinkUnderCursor(); }, true, tr("Jump to File Under Cursor"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(Qt::Key_F2));
|
|
|
|
|
m_jumpToFileInNextSplitAction = registerAction(JUMP_TO_FILE_UNDER_CURSOR_IN_NEXT_SPLIT,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->openLinkUnderCursorInNextSplit(); }, true, tr("Jump to File Under Cursor in Next Split"),
|
2014-08-28 17:33:47 +02:00
|
|
|
QKeySequence(Utils::HostOsInfo::isMacHost() ? tr("Meta+E, F2") : tr("Ctrl+E, F2")).toString());
|
2013-05-17 16:32:57 +02:00
|
|
|
|
2014-06-02 14:21:46 +02:00
|
|
|
m_viewPageUpAction = registerAction(VIEW_PAGE_UP,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->viewPageUp(); }, true, tr("Move the View a Page Up and Keep the Cursor Position"),
|
2014-06-02 14:21:46 +02:00
|
|
|
QKeySequence(tr("Ctrl+PgUp")));
|
|
|
|
|
m_viewPageDownAction = registerAction(VIEW_PAGE_DOWN,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->viewPageDown(); }, true, tr("Move the View a Page Down and Keep the Cursor Position"),
|
2014-06-02 14:21:46 +02:00
|
|
|
QKeySequence(tr("Ctrl+PgDown")));
|
|
|
|
|
m_viewLineUpAction = registerAction(VIEW_LINE_UP,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->viewLineUp(); }, true, tr("Move the View a Line Up and Keep the Cursor Position"),
|
2014-06-02 14:21:46 +02:00
|
|
|
QKeySequence(tr("Ctrl+Up")));
|
|
|
|
|
m_viewLineDownAction = registerAction(VIEW_LINE_DOWN,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->viewLineDown(); }, true, tr("Move the View a Line Down and Keep the Cursor Position"),
|
2014-06-02 14:21:46 +02:00
|
|
|
QKeySequence(tr("Ctrl+Down")));
|
|
|
|
|
|
2013-05-17 16:32:57 +02:00
|
|
|
// register "Edit" Menu Actions
|
|
|
|
|
Core::ActionContainer *editMenu = Core::ActionManager::actionContainer(M_EDIT);
|
|
|
|
|
m_selectEncodingAction = registerAction(SELECT_ENCODING,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->selectEncoding(); }, false, tr("Select Encoding..."),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(), G_EDIT_OTHER, editMenu);
|
|
|
|
|
m_circularPasteAction = registerAction(CIRCULAR_PASTE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->circularPaste(); }, false, tr("Paste from Clipboard History"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+Shift+V")), G_EDIT_COPYPASTE, editMenu);
|
|
|
|
|
|
|
|
|
|
// register "Edit -> Advanced" Menu Actions
|
|
|
|
|
Core::ActionContainer *advancedEditMenu = Core::ActionManager::actionContainer(M_EDIT_ADVANCED);
|
2019-11-18 10:38:35 +01:00
|
|
|
m_autoIndentAction = registerAction(AUTO_INDENT_SELECTION,
|
2019-11-12 12:43:16 +01:00
|
|
|
[] (TextEditorWidget *w) { w->autoIndent(); }, true, tr("Auto-&indent Selection"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+I")),
|
|
|
|
|
G_EDIT_FORMAT, advancedEditMenu);
|
2019-11-18 10:38:35 +01:00
|
|
|
m_autoFormatAction = registerAction(AUTO_FORMAT_SELECTION,
|
|
|
|
|
[] (TextEditorWidget *w) { w->autoFormat(); }, true, tr("Auto-&format Selection"),
|
|
|
|
|
QKeySequence(tr("Ctrl+;")),
|
|
|
|
|
G_EDIT_FORMAT, advancedEditMenu);
|
2013-05-17 16:32:57 +02:00
|
|
|
m_rewrapParagraphAction = registerAction(REWRAP_PARAGRAPH,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->rewrapParagraph(); }, true, tr("&Rewrap Paragraph"),
|
2018-02-02 13:39:18 +01:00
|
|
|
QKeySequence(Core::useMacShortcuts ? tr("Meta+E, R") : tr("Ctrl+E, R")),
|
2013-05-17 16:32:57 +02:00
|
|
|
G_EDIT_FORMAT, advancedEditMenu);
|
2014-08-19 16:00:58 +02:00
|
|
|
m_visualizeWhitespaceAction = registerBoolAction(VISUALIZE_WHITESPACE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *widget, bool checked) {
|
2014-08-19 16:00:58 +02:00
|
|
|
if (widget) {
|
|
|
|
|
DisplaySettings ds = widget->displaySettings();
|
|
|
|
|
ds.m_visualizeWhitespace = checked;
|
|
|
|
|
widget->setDisplaySettings(ds);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
false, tr("&Visualize Whitespace"),
|
2018-02-02 13:39:18 +01:00
|
|
|
QKeySequence(Core::useMacShortcuts ? tr("Meta+E, Meta+V") : tr("Ctrl+E, Ctrl+V")),
|
2013-05-17 16:32:57 +02:00
|
|
|
G_EDIT_FORMAT, advancedEditMenu);
|
2013-09-16 08:45:07 +02:00
|
|
|
m_visualizeWhitespaceAction->setCheckable(true);
|
2013-05-17 16:32:57 +02:00
|
|
|
m_cleanWhitespaceAction = registerAction(CLEAN_WHITESPACE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->cleanWhitespace(); }, true, tr("Clean Whitespace"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(),
|
2013-09-03 18:48:02 +02:00
|
|
|
G_EDIT_FORMAT, advancedEditMenu);
|
2014-08-19 16:00:58 +02:00
|
|
|
m_textWrappingAction = registerBoolAction(TEXT_WRAPPING,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *widget, bool checked) {
|
2014-08-19 16:00:58 +02:00
|
|
|
if (widget) {
|
|
|
|
|
DisplaySettings ds = widget->displaySettings();
|
|
|
|
|
ds.m_textWrapping = checked;
|
|
|
|
|
widget->setDisplaySettings(ds);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
false, tr("Enable Text &Wrapping"),
|
2018-02-02 13:39:18 +01:00
|
|
|
QKeySequence(Core::useMacShortcuts ? tr("Meta+E, Meta+W") : tr("Ctrl+E, Ctrl+W")),
|
2013-05-17 16:32:57 +02:00
|
|
|
G_EDIT_FORMAT, advancedEditMenu);
|
|
|
|
|
m_textWrappingAction->setCheckable(true);
|
|
|
|
|
m_unCommentSelectionAction = registerAction(UN_COMMENT_SELECTION,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->unCommentSelection(); }, true, tr("Toggle Comment &Selection"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+/")),
|
|
|
|
|
G_EDIT_FORMAT, advancedEditMenu);
|
2014-02-24 12:08:39 +01:00
|
|
|
m_cutLineAction = registerAction(CUT_LINE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->cutLine(); }, true, tr("Cut &Line"),
|
2014-02-24 12:08:39 +01:00
|
|
|
QKeySequence(tr("Shift+Del")),
|
|
|
|
|
G_EDIT_TEXT, advancedEditMenu);
|
|
|
|
|
m_copyLineAction = registerAction(COPY_LINE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->copyLine(); }, false, tr("Copy &Line"),
|
2014-02-24 12:08:39 +01:00
|
|
|
QKeySequence(tr("Ctrl+Ins")),
|
|
|
|
|
G_EDIT_TEXT, advancedEditMenu);
|
2016-09-26 15:55:04 +02:00
|
|
|
m_duplicateSelectionAction = registerAction(DUPLICATE_SELECTION,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->duplicateSelection(); }, false, tr("&Duplicate Selection"),
|
2016-09-26 15:55:04 +02:00
|
|
|
QKeySequence(),
|
|
|
|
|
G_EDIT_TEXT, advancedEditMenu);
|
|
|
|
|
m_duplicateSelectionAndCommentAction = registerAction(DUPLICATE_SELECTION_AND_COMMENT,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->duplicateSelectionAndComment(); }, false, tr("&Duplicate Selection and Comment"),
|
2016-09-26 15:55:04 +02:00
|
|
|
QKeySequence(),
|
|
|
|
|
G_EDIT_TEXT, advancedEditMenu);
|
2014-05-18 11:43:22 +03:00
|
|
|
m_upperCaseSelectionAction = registerAction(UPPERCASE_SELECTION,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->uppercaseSelection(); }, true, tr("Uppercase Selection"),
|
2018-02-02 13:39:18 +01:00
|
|
|
QKeySequence(Core::useMacShortcuts ? tr("Meta+Shift+U") : tr("Alt+Shift+U")),
|
2014-05-18 11:43:22 +03:00
|
|
|
G_EDIT_TEXT, advancedEditMenu);
|
|
|
|
|
m_lowerCaseSelectionAction = registerAction(LOWERCASE_SELECTION,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->lowercaseSelection(); }, true, tr("Lowercase Selection"),
|
2018-02-02 13:39:18 +01:00
|
|
|
QKeySequence(Core::useMacShortcuts ? tr("Meta+U") : tr("Alt+U")),
|
2014-05-18 11:43:22 +03:00
|
|
|
G_EDIT_TEXT, advancedEditMenu);
|
2017-08-13 20:38:08 +03:00
|
|
|
m_sortSelectedLinesAction = registerAction(SORT_SELECTED_LINES,
|
2017-09-19 11:32:21 +02:00
|
|
|
[] (TextEditorWidget *w) { w->sortSelectedLines(); }, false, tr("&Sort Selected Lines"),
|
2018-02-02 13:39:18 +01:00
|
|
|
QKeySequence(Core::useMacShortcuts ? tr("Meta+Shift+S") : tr("Alt+Shift+S")),
|
2017-08-13 20:38:08 +03:00
|
|
|
G_EDIT_TEXT, advancedEditMenu);
|
2013-05-17 16:32:57 +02:00
|
|
|
m_foldAction = registerAction(FOLD,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->fold(); }, true, tr("Fold"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+<")),
|
|
|
|
|
G_EDIT_COLLAPSING, advancedEditMenu);
|
|
|
|
|
m_unfoldAction = registerAction(UNFOLD,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->unfold(); }, true, tr("Unfold"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+>")),
|
|
|
|
|
G_EDIT_COLLAPSING, advancedEditMenu);
|
|
|
|
|
m_unfoldAllAction = registerAction(UNFOLD_ALL,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->unfoldAll(); }, true, tr("Toggle &Fold All"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(),
|
|
|
|
|
G_EDIT_COLLAPSING, advancedEditMenu);
|
|
|
|
|
m_increaseFontSizeAction = registerAction(INCREASE_FONT_SIZE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->zoomF(1.f); }, false, tr("Increase Font Size"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl++")),
|
|
|
|
|
G_EDIT_FONT, advancedEditMenu);
|
|
|
|
|
m_decreaseFontSizeAction = registerAction(DECREASE_FONT_SIZE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->zoomF(-1.f); }, false, tr("Decrease Font Size"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+-")),
|
|
|
|
|
G_EDIT_FONT, advancedEditMenu);
|
|
|
|
|
m_resetFontSizeAction = registerAction(RESET_FONT_SIZE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->zoomReset(); }, false, tr("Reset Font Size"),
|
2018-02-02 13:39:18 +01:00
|
|
|
QKeySequence(Core::useMacShortcuts ? tr("Meta+0") : tr("Ctrl+0")),
|
2013-05-17 16:32:57 +02:00
|
|
|
G_EDIT_FONT, advancedEditMenu);
|
|
|
|
|
m_gotoBlockStartAction = registerAction(GOTO_BLOCK_START,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoBlockStart(); }, true, tr("Go to Block Start"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+[")),
|
|
|
|
|
G_EDIT_BLOCKS, advancedEditMenu);
|
|
|
|
|
m_gotoBlockEndAction = registerAction(GOTO_BLOCK_END,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoBlockEnd(); }, true, tr("Go to Block End"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+]")),
|
|
|
|
|
G_EDIT_BLOCKS, advancedEditMenu);
|
|
|
|
|
m_selectBlockUpAction = registerAction(SELECT_BLOCK_UP,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->selectBlockUp(); }, true, tr("Select Block Up"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+U")),
|
|
|
|
|
G_EDIT_BLOCKS, advancedEditMenu);
|
|
|
|
|
m_selectBlockDownAction = registerAction(SELECT_BLOCK_DOWN,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->selectBlockDown(); }, true, tr("Select Block Down"),
|
2015-12-20 19:59:00 +01:00
|
|
|
QKeySequence(tr("Ctrl+Shift+Alt+U")),
|
2013-05-17 16:32:57 +02:00
|
|
|
G_EDIT_BLOCKS, advancedEditMenu);
|
2016-08-02 08:17:35 +02:00
|
|
|
registerAction(SELECT_WORD_UNDER_CURSOR,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->selectWordUnderCursor(); }, true,
|
2016-08-02 08:17:35 +02:00
|
|
|
tr("Select Word Under Cursor"));
|
2013-05-17 16:32:57 +02:00
|
|
|
|
|
|
|
|
// register GOTO Actions
|
2018-02-12 15:07:45 +01:00
|
|
|
registerAction(GOTO_DOCUMENT_START,
|
|
|
|
|
[] (TextEditorWidget *w) { w->gotoDocumentStart(); }, true, tr("Go to Document Start"));
|
|
|
|
|
registerAction(GOTO_DOCUMENT_END,
|
|
|
|
|
[] (TextEditorWidget *w) { w->gotoDocumentEnd(); }, true, tr("Go to Document End"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_LINE_START,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoLineStart(); }, true, tr("Go to Line Start"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_LINE_END,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoLineEnd(); }, true, tr("Go to Line End"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_NEXT_LINE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoNextLine(); }, true, tr("Go to Next Line"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_PREVIOUS_LINE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoPreviousLine(); }, true, tr("Go to Previous Line"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_PREVIOUS_CHARACTER,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoPreviousCharacter(); }, true, tr("Go to Previous Character"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_NEXT_CHARACTER,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoNextCharacter(); }, true, tr("Go to Next Character"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_PREVIOUS_WORD,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoPreviousWord(); }, true, tr("Go to Previous Word"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_NEXT_WORD,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoNextWord(); }, true, tr("Go to Next Word"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_PREVIOUS_WORD_CAMEL_CASE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoPreviousWordCamelCase(); }, false, tr("Go to Previous Word Camel Case"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_NEXT_WORD_CAMEL_CASE,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoNextWordCamelCase(); }, false, tr("Go to Next Word Camel Case"));
|
2013-05-17 16:32:57 +02:00
|
|
|
|
|
|
|
|
// register GOTO actions with selection
|
|
|
|
|
registerAction(GOTO_LINE_START_WITH_SELECTION,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoLineStartWithSelection(); }, true, tr("Go to Line Start with Selection"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_LINE_END_WITH_SELECTION,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoLineEndWithSelection(); }, true, tr("Go to Line End with Selection"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_NEXT_LINE_WITH_SELECTION,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoNextLineWithSelection(); }, true, tr("Go to Next Line with Selection"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_PREVIOUS_LINE_WITH_SELECTION,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoPreviousLineWithSelection(); }, true, tr("Go to Previous Line with Selection"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_PREVIOUS_CHARACTER_WITH_SELECTION,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoPreviousCharacterWithSelection(); }, true, tr("Go to Previous Character with Selection"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_NEXT_CHARACTER_WITH_SELECTION,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoNextCharacterWithSelection(); }, true, tr("Go to Next Character with Selection"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_PREVIOUS_WORD_WITH_SELECTION,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoPreviousWordWithSelection(); }, true, tr("Go to Previous Word with Selection"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_NEXT_WORD_WITH_SELECTION,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoNextWordWithSelection(); }, true, tr("Go to Next Word with Selection"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_PREVIOUS_WORD_CAMEL_CASE_WITH_SELECTION,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoPreviousWordCamelCaseWithSelection(); }, false, tr("Go to Previous Word Camel Case with Selection"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_NEXT_WORD_CAMEL_CASE_WITH_SELECTION,
|
2017-09-07 17:05:47 +02:00
|
|
|
[] (TextEditorWidget *w) { w->gotoNextWordCamelCaseWithSelection(); }, false, tr("Go to Next Word Camel Case with Selection"));
|
2013-05-17 16:32:57 +02:00
|
|
|
|
|
|
|
|
// Collect all modifying actions so we can check for them inside a readonly file
|
|
|
|
|
// and disable them
|
2017-05-08 11:56:21 +02:00
|
|
|
m_modifyingActions << m_circularPasteAction;
|
2011-05-19 12:25:27 +02:00
|
|
|
m_modifyingActions << m_cleanWhitespaceAction;
|
2017-05-08 11:56:21 +02:00
|
|
|
m_modifyingActions << m_copyLineDownAction;
|
|
|
|
|
m_modifyingActions << m_copyLineUpAction;
|
2011-05-19 12:25:27 +02:00
|
|
|
m_modifyingActions << m_cutLineAction;
|
2017-04-26 10:48:48 +02:00
|
|
|
m_modifyingActions << m_deleteEndOfLineAction;
|
2011-09-26 14:21:19 +02:00
|
|
|
m_modifyingActions << m_deleteEndOfWordAction;
|
|
|
|
|
m_modifyingActions << m_deleteEndOfWordCamelCaseAction;
|
2017-05-08 11:56:21 +02:00
|
|
|
m_modifyingActions << m_deleteLineAction;
|
2017-04-26 10:48:48 +02:00
|
|
|
m_modifyingActions << m_deleteStartOfLineAction;
|
2011-09-26 14:21:19 +02:00
|
|
|
m_modifyingActions << m_deleteStartOfWordAction;
|
|
|
|
|
m_modifyingActions << m_deleteStartOfWordCamelCaseAction;
|
2017-05-08 11:59:33 +02:00
|
|
|
m_modifyingActions << m_duplicateSelectionAction;
|
|
|
|
|
m_modifyingActions << m_duplicateSelectionAndCommentAction;
|
2019-11-18 10:38:35 +01:00
|
|
|
m_modifyingActions << m_autoIndentAction;
|
|
|
|
|
m_modifyingActions << m_autoFormatAction;
|
2017-05-08 11:56:21 +02:00
|
|
|
m_modifyingActions << m_indentAction;
|
2011-05-19 12:25:27 +02:00
|
|
|
m_modifyingActions << m_insertLineAboveAction;
|
|
|
|
|
m_modifyingActions << m_insertLineBelowAction;
|
2017-05-08 11:56:21 +02:00
|
|
|
m_modifyingActions << m_joinLinesAction;
|
2011-05-19 12:25:27 +02:00
|
|
|
m_modifyingActions << m_lowerCaseSelectionAction;
|
2017-05-08 11:56:21 +02:00
|
|
|
m_modifyingActions << m_moveLineDownAction;
|
|
|
|
|
m_modifyingActions << m_moveLineUpAction;
|
|
|
|
|
m_modifyingActions << m_pasteAction;
|
|
|
|
|
m_modifyingActions << m_rewrapParagraphAction;
|
2012-03-02 08:16:23 +08:00
|
|
|
m_modifyingActions << m_switchUtf8bomAction;
|
2017-05-08 11:56:21 +02:00
|
|
|
m_modifyingActions << m_unCommentSelectionAction;
|
2012-01-22 17:05:02 -05:00
|
|
|
m_modifyingActions << m_unindentAction;
|
2017-05-08 11:56:21 +02:00
|
|
|
m_modifyingActions << m_upperCaseSelectionAction;
|
2017-08-13 20:38:08 +03:00
|
|
|
m_modifyingActions << m_sortSelectedLinesAction;
|
2013-12-10 15:54:20 +01:00
|
|
|
|
2020-06-15 10:14:35 +02:00
|
|
|
updateOptionalActions();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-01 14:26:55 +02:00
|
|
|
void TextEditorActionHandlerPrivate::updateActions()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2017-05-08 16:06:35 +02:00
|
|
|
bool isWritable = m_currentEditorWidget && !m_currentEditorWidget->isReadOnly();
|
2011-05-19 12:25:27 +02:00
|
|
|
foreach (QAction *a, m_modifyingActions)
|
2013-12-10 15:54:20 +01:00
|
|
|
a->setEnabled(isWritable);
|
2014-07-01 14:26:55 +02:00
|
|
|
m_unCommentSelectionAction->setEnabled((m_optionalActions & TextEditorActionHandler::UnCommentSelection) && isWritable);
|
2017-05-08 16:06:35 +02:00
|
|
|
m_visualizeWhitespaceAction->setEnabled(m_currentEditorWidget);
|
|
|
|
|
m_textWrappingAction->setEnabled(m_currentEditorWidget);
|
|
|
|
|
if (m_currentEditorWidget) {
|
|
|
|
|
m_visualizeWhitespaceAction->setChecked(
|
|
|
|
|
m_currentEditorWidget->displaySettings().m_visualizeWhitespace);
|
|
|
|
|
m_textWrappingAction->setChecked(m_currentEditorWidget->displaySettings().m_textWrapping);
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2017-05-08 16:06:35 +02:00
|
|
|
updateRedoAction(m_currentEditorWidget && m_currentEditorWidget->document()->isRedoAvailable());
|
|
|
|
|
updateUndoAction(m_currentEditorWidget && m_currentEditorWidget->document()->isUndoAvailable());
|
|
|
|
|
updateCopyAction(m_currentEditorWidget && m_currentEditorWidget->textCursor().hasSelection());
|
2020-06-15 10:14:35 +02:00
|
|
|
updateOptionalActions();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TextEditorActionHandlerPrivate::updateOptionalActions()
|
|
|
|
|
{
|
2020-06-17 10:28:27 +02:00
|
|
|
const uint optionalActions = m_currentEditorWidget ? m_currentEditorWidget->optionalActions()
|
|
|
|
|
: m_optionalActions;
|
2020-06-15 10:14:35 +02:00
|
|
|
m_followSymbolAction->setEnabled(
|
2020-06-15 12:40:08 +02:00
|
|
|
optionalActions & TextEditorActionHandler::FollowSymbolUnderCursor);
|
2020-06-15 10:14:35 +02:00
|
|
|
m_followSymbolInNextSplitAction->setEnabled(
|
2020-06-15 12:40:08 +02:00
|
|
|
optionalActions & TextEditorActionHandler::FollowSymbolUnderCursor);
|
2020-06-15 10:14:35 +02:00
|
|
|
m_jumpToFileAction->setEnabled(
|
2020-06-15 12:40:08 +02:00
|
|
|
optionalActions & TextEditorActionHandler::JumpToFileUnderCursor);
|
2020-06-15 10:14:35 +02:00
|
|
|
m_jumpToFileInNextSplitAction->setEnabled(
|
2020-06-15 12:40:08 +02:00
|
|
|
optionalActions & TextEditorActionHandler::JumpToFileUnderCursor);
|
2020-06-15 10:14:35 +02:00
|
|
|
m_unfoldAllAction->setEnabled(
|
2020-06-15 12:40:08 +02:00
|
|
|
optionalActions & TextEditorActionHandler::UnCollapseAll);
|
2020-06-15 10:14:35 +02:00
|
|
|
m_renameSymbolAction->setEnabled(
|
2020-06-15 12:40:08 +02:00
|
|
|
optionalActions & TextEditorActionHandler::RenameSymbol);
|
2020-06-15 10:14:35 +02:00
|
|
|
|
2020-06-15 12:40:08 +02:00
|
|
|
bool formatEnabled = (optionalActions & TextEditorActionHandler::Format)
|
2020-06-15 10:14:35 +02:00
|
|
|
&& m_currentEditorWidget && !m_currentEditorWidget->isReadOnly();
|
|
|
|
|
m_autoIndentAction->setEnabled(formatEnabled);
|
|
|
|
|
m_autoFormatAction->setEnabled(formatEnabled);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-08-19 16:00:58 +02:00
|
|
|
void TextEditorActionHandlerPrivate::updateRedoAction(bool on)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-08-19 16:00:58 +02:00
|
|
|
m_redoAction->setEnabled(on);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-08-19 16:00:58 +02:00
|
|
|
void TextEditorActionHandlerPrivate::updateUndoAction(bool on)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2014-08-19 16:00:58 +02:00
|
|
|
m_undoAction->setEnabled(on);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2014-08-19 16:00:58 +02:00
|
|
|
void TextEditorActionHandlerPrivate::updateCopyAction(bool hasCopyableText)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
if (m_cutAction)
|
2017-05-08 16:06:35 +02:00
|
|
|
m_cutAction->setEnabled(hasCopyableText && m_currentEditorWidget
|
|
|
|
|
&& !m_currentEditorWidget->isReadOnly());
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (m_copyAction)
|
2008-12-02 12:01:29 +01:00
|
|
|
m_copyAction->setEnabled(hasCopyableText);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-01 14:26:55 +02:00
|
|
|
void TextEditorActionHandlerPrivate::updateCurrentEditor(Core::IEditor *editor)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-12-10 15:54:20 +01:00
|
|
|
if (m_currentEditorWidget)
|
|
|
|
|
m_currentEditorWidget->disconnect(this);
|
2018-09-20 01:16:01 +03:00
|
|
|
m_currentEditorWidget = nullptr;
|
2009-02-16 12:50:15 +01:00
|
|
|
|
2017-05-08 16:06:35 +02:00
|
|
|
if (editor && editor->document()->id() == m_editorId) {
|
2017-05-08 13:52:34 +02:00
|
|
|
TextEditorWidget *editorWidget = m_findTextWidget(editor);
|
2017-05-08 16:06:35 +02:00
|
|
|
QTC_ASSERT(editorWidget, return); // editor has our id, so shouldn't happen
|
|
|
|
|
m_currentEditorWidget = editorWidget;
|
|
|
|
|
connect(editorWidget, &QPlainTextEdit::undoAvailable,
|
|
|
|
|
this, &TextEditorActionHandlerPrivate::updateUndoAction);
|
|
|
|
|
connect(editorWidget, &QPlainTextEdit::redoAvailable,
|
|
|
|
|
this, &TextEditorActionHandlerPrivate::updateRedoAction);
|
|
|
|
|
connect(editorWidget, &QPlainTextEdit::copyAvailable,
|
|
|
|
|
this, &TextEditorActionHandlerPrivate::updateCopyAction);
|
|
|
|
|
connect(editorWidget, &TextEditorWidget::readOnlyChanged,
|
|
|
|
|
this, &TextEditorActionHandlerPrivate::updateActions);
|
2020-06-15 12:40:08 +02:00
|
|
|
connect(editorWidget, &TextEditorWidget::optionalActionMaskChanged,
|
|
|
|
|
this, &TextEditorActionHandlerPrivate::updateOptionalActions);
|
2017-05-08 16:06:35 +02:00
|
|
|
}
|
2013-12-10 12:36:15 +01:00
|
|
|
updateActions();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2014-07-01 14:26:55 +02:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
|
2020-06-26 13:59:38 +02:00
|
|
|
TextEditorActionHandler::TextEditorActionHandler(Utils::Id editorId,
|
|
|
|
|
Utils::Id contextId,
|
2020-02-05 17:51:41 +01:00
|
|
|
uint optionalActions,
|
|
|
|
|
const TextEditorWidgetResolver &resolver)
|
|
|
|
|
: d(new Internal::TextEditorActionHandlerPrivate(editorId, contextId, optionalActions))
|
2014-07-01 14:26:55 +02:00
|
|
|
{
|
2020-02-05 17:51:41 +01:00
|
|
|
if (resolver)
|
|
|
|
|
d->m_findTextWidget = resolver;
|
|
|
|
|
else
|
2020-02-11 14:00:09 +01:00
|
|
|
d->m_findTextWidget = TextEditorWidget::fromEditor;
|
2014-07-01 14:26:55 +02:00
|
|
|
}
|
|
|
|
|
|
2020-06-17 10:28:27 +02:00
|
|
|
uint TextEditorActionHandler::optionalActions() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_optionalActions;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-01 14:26:55 +02:00
|
|
|
TextEditorActionHandler::~TextEditorActionHandler()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace TextEditor
|