2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
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
|
|
|
|
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>
|
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
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TextEditorActionHandlerPrivate(TextEditorActionHandler *parent,
|
|
|
|
|
Core::Id contextId,
|
|
|
|
|
uint optionalActions);
|
|
|
|
|
|
2014-08-19 16:00:58 +02:00
|
|
|
QAction *registerActionHelper(Core::Id id, bool scriptable, const QString &title,
|
|
|
|
|
const QKeySequence &keySequence, const char *menueGroup,
|
|
|
|
|
Core::ActionContainer *container,
|
|
|
|
|
std::function<void(bool)> slot)
|
|
|
|
|
{
|
|
|
|
|
QAction *result = new QAction(title, this);
|
|
|
|
|
Core::Command *command = Core::ActionManager::registerAction(result, id, Core::Context(m_contextId), scriptable);
|
|
|
|
|
if (!keySequence.isEmpty())
|
|
|
|
|
command->setDefaultKeySequence(keySequence);
|
|
|
|
|
|
|
|
|
|
if (container && menueGroup)
|
|
|
|
|
container->addAction(command, menueGroup);
|
|
|
|
|
|
|
|
|
|
connect(result, &QAction::triggered, slot);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-01 14:26:55 +02:00
|
|
|
QAction *registerAction(Core::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(),
|
|
|
|
|
const char *menueGroup = 0,
|
|
|
|
|
Core::ActionContainer *container = 0)
|
|
|
|
|
{
|
|
|
|
|
return registerActionHelper(id, scriptable, title, keySequence, menueGroup, container,
|
|
|
|
|
[this, slot](bool) { if (m_currentEditorWidget) slot(m_currentEditorWidget); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction *registerBoolAction(Core::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(),
|
|
|
|
|
const char *menueGroup = 0,
|
|
|
|
|
Core::ActionContainer *container = 0)
|
|
|
|
|
{
|
|
|
|
|
return registerActionHelper(id, scriptable, title, keySequence, menueGroup, container,
|
|
|
|
|
[this, slot](bool on) { if (m_currentEditorWidget) slot(m_currentEditorWidget, on); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QAction *registerIntAction(Core::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(),
|
|
|
|
|
const char *menueGroup = 0,
|
2014-08-19 16:00:58 +02:00
|
|
|
Core::ActionContainer *container = 0)
|
|
|
|
|
{
|
|
|
|
|
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();
|
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:
|
|
|
|
|
TextEditorActionHandler *q;
|
|
|
|
|
QAction *m_undoAction;
|
|
|
|
|
QAction *m_redoAction;
|
|
|
|
|
QAction *m_copyAction;
|
|
|
|
|
QAction *m_cutAction;
|
|
|
|
|
QAction *m_pasteAction;
|
|
|
|
|
QAction *m_circularPasteAction;
|
|
|
|
|
QAction *m_switchUtf8bomAction;
|
|
|
|
|
QAction *m_selectAllAction;
|
|
|
|
|
QAction *m_gotoAction;
|
|
|
|
|
QAction *m_printAction;
|
|
|
|
|
QAction *m_formatAction;
|
|
|
|
|
QAction *m_rewrapParagraphAction;
|
|
|
|
|
QAction *m_visualizeWhitespaceAction;
|
|
|
|
|
QAction *m_cleanWhitespaceAction;
|
|
|
|
|
QAction *m_textWrappingAction;
|
|
|
|
|
QAction *m_unCommentSelectionAction;
|
|
|
|
|
QAction *m_unfoldAllAction;
|
|
|
|
|
QAction *m_foldAction;
|
|
|
|
|
QAction *m_unfoldAction;
|
|
|
|
|
QAction *m_cutLineAction;
|
|
|
|
|
QAction *m_copyLineAction;
|
|
|
|
|
QAction *m_deleteLineAction;
|
|
|
|
|
QAction *m_deleteEndOfWordAction;
|
|
|
|
|
QAction *m_deleteEndOfWordCamelCaseAction;
|
|
|
|
|
QAction *m_deleteStartOfWordAction;
|
|
|
|
|
QAction *m_deleteStartOfWordCamelCaseAction;
|
|
|
|
|
QAction *m_selectEncodingAction;
|
|
|
|
|
QAction *m_increaseFontSizeAction;
|
|
|
|
|
QAction *m_decreaseFontSizeAction;
|
|
|
|
|
QAction *m_resetFontSizeAction;
|
|
|
|
|
QAction *m_gotoBlockStartAction;
|
|
|
|
|
QAction *m_gotoBlockEndAction;
|
|
|
|
|
QAction *m_gotoBlockStartWithSelectionAction;
|
|
|
|
|
QAction *m_gotoBlockEndWithSelectionAction;
|
|
|
|
|
QAction *m_selectBlockUpAction;
|
|
|
|
|
QAction *m_selectBlockDownAction;
|
|
|
|
|
QAction *m_viewPageUpAction;
|
|
|
|
|
QAction *m_viewPageDownAction;
|
|
|
|
|
QAction *m_viewLineUpAction;
|
|
|
|
|
QAction *m_viewLineDownAction;
|
|
|
|
|
QAction *m_moveLineUpAction;
|
|
|
|
|
QAction *m_moveLineDownAction;
|
|
|
|
|
QAction *m_copyLineUpAction;
|
|
|
|
|
QAction *m_copyLineDownAction;
|
|
|
|
|
QAction *m_joinLinesAction;
|
|
|
|
|
QAction *m_insertLineAboveAction;
|
|
|
|
|
QAction *m_insertLineBelowAction;
|
|
|
|
|
QAction *m_upperCaseSelectionAction;
|
|
|
|
|
QAction *m_lowerCaseSelectionAction;
|
|
|
|
|
QAction *m_indentAction;
|
|
|
|
|
QAction *m_unindentAction;
|
|
|
|
|
QAction *m_followSymbolAction;
|
|
|
|
|
QAction *m_followSymbolInNextSplitAction;
|
|
|
|
|
QAction *m_jumpToFileAction;
|
|
|
|
|
QAction *m_jumpToFileInNextSplitAction;
|
|
|
|
|
QList<QAction *> m_modifyingActions;
|
|
|
|
|
|
|
|
|
|
uint m_optionalActions;
|
2014-09-26 11:37:54 +02:00
|
|
|
QPointer<TextEditorWidget> m_currentEditorWidget;
|
2014-07-01 14:26:55 +02:00
|
|
|
Core::Id m_contextId;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TextEditorActionHandlerPrivate::TextEditorActionHandlerPrivate
|
|
|
|
|
(TextEditorActionHandler *parent, Core::Id contextId, uint optionalActions)
|
|
|
|
|
: q(parent),
|
2009-05-26 11:11:47 +02:00
|
|
|
m_undoAction(0),
|
|
|
|
|
m_redoAction(0),
|
|
|
|
|
m_copyAction(0),
|
|
|
|
|
m_cutAction(0),
|
|
|
|
|
m_pasteAction(0),
|
2011-12-13 12:15:30 +01:00
|
|
|
m_circularPasteAction(0),
|
2012-03-02 08:16:23 +08:00
|
|
|
m_switchUtf8bomAction(0),
|
2009-05-26 11:11:47 +02:00
|
|
|
m_selectAllAction(0),
|
|
|
|
|
m_gotoAction(0),
|
|
|
|
|
m_printAction(0),
|
|
|
|
|
m_formatAction(0),
|
|
|
|
|
m_visualizeWhitespaceAction(0),
|
|
|
|
|
m_cleanWhitespaceAction(0),
|
|
|
|
|
m_textWrappingAction(0),
|
|
|
|
|
m_unCommentSelectionAction(0),
|
2010-05-20 15:10:26 +02:00
|
|
|
m_unfoldAllAction(0),
|
|
|
|
|
m_foldAction(0),
|
|
|
|
|
m_unfoldAction(0),
|
2009-05-26 11:11:47 +02:00
|
|
|
m_cutLineAction(0),
|
2010-11-27 14:02:20 +09:00
|
|
|
m_copyLineAction(0),
|
2009-05-26 11:11:47 +02:00
|
|
|
m_deleteLineAction(0),
|
2011-09-26 14:21:19 +02:00
|
|
|
m_deleteEndOfWordAction(0),
|
|
|
|
|
m_deleteEndOfWordCamelCaseAction(0),
|
|
|
|
|
m_deleteStartOfWordAction(0),
|
|
|
|
|
m_deleteStartOfWordCamelCaseAction(0),
|
2009-05-26 11:11:47 +02:00
|
|
|
m_selectEncodingAction(0),
|
|
|
|
|
m_increaseFontSizeAction(0),
|
|
|
|
|
m_decreaseFontSizeAction(0),
|
2009-11-30 19:00:36 +01:00
|
|
|
m_resetFontSizeAction(0),
|
2009-05-26 11:11:47 +02:00
|
|
|
m_gotoBlockStartAction(0),
|
|
|
|
|
m_gotoBlockEndAction(0),
|
|
|
|
|
m_gotoBlockStartWithSelectionAction(0),
|
|
|
|
|
m_gotoBlockEndWithSelectionAction(0),
|
|
|
|
|
m_selectBlockUpAction(0),
|
|
|
|
|
m_selectBlockDownAction(0),
|
2014-06-02 14:21:46 +02:00
|
|
|
m_viewPageUpAction(0),
|
|
|
|
|
m_viewPageDownAction(0),
|
|
|
|
|
m_viewLineUpAction(0),
|
|
|
|
|
m_viewLineDownAction(0),
|
2009-05-26 11:11:47 +02:00
|
|
|
m_moveLineUpAction(0),
|
|
|
|
|
m_moveLineDownAction(0),
|
|
|
|
|
m_copyLineUpAction(0),
|
|
|
|
|
m_copyLineDownAction(0),
|
2010-01-20 17:51:05 +01:00
|
|
|
m_joinLinesAction(0),
|
2011-02-25 11:10:42 +01:00
|
|
|
m_insertLineAboveAction(0),
|
|
|
|
|
m_insertLineBelowAction(0),
|
|
|
|
|
m_upperCaseSelectionAction(0),
|
|
|
|
|
m_lowerCaseSelectionAction(0),
|
2012-01-22 17:05:02 -05:00
|
|
|
m_indentAction(0),
|
|
|
|
|
m_unindentAction(0),
|
2012-03-27 23:18:46 +04:00
|
|
|
m_followSymbolAction(0),
|
2013-02-05 14:14:33 +01:00
|
|
|
m_followSymbolInNextSplitAction(0),
|
2012-03-27 23:18:46 +04:00
|
|
|
m_jumpToFileAction(0),
|
2013-02-05 14:14:33 +01:00
|
|
|
m_jumpToFileInNextSplitAction(0),
|
2008-12-02 12:01:29 +01:00
|
|
|
m_optionalActions(optionalActions),
|
2013-12-10 15:54:20 +01:00
|
|
|
m_currentEditorWidget(0),
|
|
|
|
|
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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->undo(); }, true, tr("&Undo"));
|
2013-05-17 16:32:57 +02:00
|
|
|
m_redoAction = registerAction(REDO,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->redo(); }, true, tr("&Redo"));
|
2013-05-17 16:32:57 +02:00
|
|
|
m_copyAction = registerAction(COPY,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->copy(); }, true);
|
2013-05-17 16:32:57 +02:00
|
|
|
m_cutAction = registerAction(CUT,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->cut(); }, true);
|
2013-05-17 16:32:57 +02:00
|
|
|
m_pasteAction = registerAction(PASTE,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->paste(); }, true);
|
2013-05-17 16:32:57 +02:00
|
|
|
m_selectAllAction = registerAction(SELECTALL,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->selectAll(); }, true);
|
|
|
|
|
m_gotoAction = registerAction(GOTO, [this] (TextEditorWidget *) {
|
2014-08-19 16:00:58 +02:00
|
|
|
QString locatorString = TextEditorPlugin::lineNumberFilter()->shortcutString();
|
|
|
|
|
locatorString += QLatin1Char(' ');
|
|
|
|
|
const int selectionStart = locatorString.size();
|
|
|
|
|
locatorString += TextEditorActionHandler::tr("<line>:<column>");
|
|
|
|
|
Core::LocatorManager::show(locatorString, selectionStart, locatorString.size() - selectionStart);
|
|
|
|
|
});
|
2014-08-27 18:22:04 +02:00
|
|
|
m_printAction = registerAction(PRINT,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *widget) { widget->print(Core::ICore::printer()); });
|
2013-05-17 16:32:57 +02:00
|
|
|
m_deleteLineAction = registerAction(DELETE_LINE,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->deleteLine(); }, true, tr("Delete &Line"));
|
2013-05-17 16:32:57 +02:00
|
|
|
m_deleteEndOfWordAction = registerAction(DELETE_END_OF_WORD,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->deleteEndOfWordCamelCase(); }, true, tr("Delete Word Camel Case from Cursor On"));
|
2013-05-17 16:32:57 +02:00
|
|
|
m_deleteStartOfWordAction = registerAction(DELETE_START_OF_WORD,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->switchUtf8bom(); }, true);
|
2013-05-17 16:32:57 +02:00
|
|
|
m_indentAction = registerAction(INDENT,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->indent(); }, true, tr("Indent"));
|
2013-05-17 16:32:57 +02:00
|
|
|
m_unindentAction = registerAction(UNINDENT,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->unindent(); }, true, tr("Unindent"));
|
2013-05-17 16:32:57 +02:00
|
|
|
m_followSymbolAction = registerAction(FOLLOW_SYMBOL_UNDER_CURSOR,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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")));
|
|
|
|
|
m_jumpToFileAction = registerAction(JUMP_TO_FILE_UNDER_CURSOR,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-10-14 15:36:16 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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);
|
|
|
|
|
m_formatAction = registerAction(AUTO_INDENT_SELECTION,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->format(); }, true, tr("Auto-&indent Selection"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(tr("Ctrl+I")),
|
|
|
|
|
G_EDIT_FORMAT, advancedEditMenu);
|
|
|
|
|
m_rewrapParagraphAction = registerAction(REWRAP_PARAGRAPH,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->rewrapParagraph(); }, true, tr("&Rewrap Paragraph"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(Core::UseMacShortcuts ? tr("Meta+E, R") : tr("Ctrl+E, R")),
|
|
|
|
|
G_EDIT_FORMAT, advancedEditMenu);
|
2014-08-19 16:00:58 +02:00
|
|
|
m_visualizeWhitespaceAction = registerBoolAction(VISUALIZE_WHITESPACE,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(Core::UseMacShortcuts ? tr("Meta+E, Meta+V") : tr("Ctrl+E, Ctrl+V")),
|
|
|
|
|
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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(Core::UseMacShortcuts ? tr("Meta+E, Meta+W") : tr("Ctrl+E, Ctrl+W")),
|
|
|
|
|
G_EDIT_FORMAT, advancedEditMenu);
|
|
|
|
|
m_textWrappingAction->setCheckable(true);
|
|
|
|
|
m_unCommentSelectionAction = registerAction(UN_COMMENT_SELECTION,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->copyLine(); }, false, tr("Copy &Line"),
|
2014-02-24 12:08:39 +01:00
|
|
|
QKeySequence(tr("Ctrl+Ins")),
|
|
|
|
|
G_EDIT_TEXT, advancedEditMenu);
|
2014-05-18 11:43:22 +03:00
|
|
|
m_upperCaseSelectionAction = registerAction(UPPERCASE_SELECTION,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->uppercaseSelection(); }, true, tr("Uppercase Selection"),
|
2014-05-18 11:43:22 +03:00
|
|
|
QKeySequence(Core::UseMacShortcuts ? tr("Meta+Shift+U") : tr("Alt+Shift+U")),
|
|
|
|
|
G_EDIT_TEXT, advancedEditMenu);
|
|
|
|
|
m_lowerCaseSelectionAction = registerAction(LOWERCASE_SELECTION,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->lowercaseSelection(); }, true, tr("Lowercase Selection"),
|
2014-05-18 11:43:22 +03:00
|
|
|
QKeySequence(Core::UseMacShortcuts ? tr("Meta+U") : tr("Alt+U")),
|
|
|
|
|
G_EDIT_TEXT, advancedEditMenu);
|
2013-05-17 16:32:57 +02:00
|
|
|
m_foldAction = registerAction(FOLD,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->zoomIn(); }, 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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->zoomOut(); }, 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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->zoomReset(); }, false, tr("Reset Font Size"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(Core::UseMacShortcuts ? tr("Meta+0") : tr("Ctrl+0")),
|
|
|
|
|
G_EDIT_FONT, advancedEditMenu);
|
|
|
|
|
m_gotoBlockStartAction = registerAction(GOTO_BLOCK_START,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->selectBlockDown(); }, true, tr("Select Block Down"),
|
2013-05-17 16:32:57 +02:00
|
|
|
QKeySequence(),
|
|
|
|
|
G_EDIT_BLOCKS, advancedEditMenu);
|
|
|
|
|
|
|
|
|
|
// register GOTO Actions
|
|
|
|
|
registerAction(GOTO_LINE_START,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->gotoLineStart(); }, true, tr("Go to Line Start"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_LINE_END,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->gotoLineEnd(); }, true, tr("Go to Line End"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_NEXT_LINE,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->gotoNextLine(); }, true, tr("Go to Next Line"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_PREVIOUS_LINE,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->gotoPreviousLine(); }, true, tr("Go to Previous Line"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_PREVIOUS_CHARACTER,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->gotoPreviousCharacter(); }, true, tr("Go to Previous Character"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_NEXT_CHARACTER,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->gotoNextCharacter(); }, true, tr("Go to Next Character"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_PREVIOUS_WORD,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->gotoPreviousWord(); }, true, tr("Go to Previous Word"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_NEXT_WORD,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (TextEditorWidget *w) { w->gotoNextWord(); }, true, tr("Go to Next Word"));
|
2013-05-17 16:32:57 +02:00
|
|
|
registerAction(GOTO_PREVIOUS_WORD_CAMEL_CASE,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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,
|
2014-09-26 11:37:54 +02:00
|
|
|
[this] (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
|
2011-05-19 12:25:27 +02:00
|
|
|
m_modifyingActions << m_pasteAction;
|
|
|
|
|
m_modifyingActions << m_formatAction;
|
|
|
|
|
m_modifyingActions << m_rewrapParagraphAction;
|
|
|
|
|
m_modifyingActions << m_cleanWhitespaceAction;
|
|
|
|
|
m_modifyingActions << m_unCommentSelectionAction;
|
|
|
|
|
m_modifyingActions << m_cutLineAction;
|
|
|
|
|
m_modifyingActions << m_deleteLineAction;
|
2011-09-26 14:21:19 +02:00
|
|
|
m_modifyingActions << m_deleteEndOfWordAction;
|
|
|
|
|
m_modifyingActions << m_deleteEndOfWordCamelCaseAction;
|
|
|
|
|
m_modifyingActions << m_deleteStartOfWordAction;
|
|
|
|
|
m_modifyingActions << m_deleteStartOfWordCamelCaseAction;
|
2011-05-19 12:25:27 +02:00
|
|
|
m_modifyingActions << m_moveLineUpAction;
|
|
|
|
|
m_modifyingActions << m_moveLineDownAction;
|
|
|
|
|
m_modifyingActions << m_copyLineUpAction;
|
|
|
|
|
m_modifyingActions << m_copyLineDownAction;
|
|
|
|
|
m_modifyingActions << m_joinLinesAction;
|
|
|
|
|
m_modifyingActions << m_insertLineAboveAction;
|
|
|
|
|
m_modifyingActions << m_insertLineBelowAction;
|
|
|
|
|
m_modifyingActions << m_upperCaseSelectionAction;
|
|
|
|
|
m_modifyingActions << m_lowerCaseSelectionAction;
|
2011-12-13 12:15:30 +01:00
|
|
|
m_modifyingActions << m_circularPasteAction;
|
2012-03-02 08:16:23 +08:00
|
|
|
m_modifyingActions << m_switchUtf8bomAction;
|
2012-01-22 17:05:02 -05:00
|
|
|
m_modifyingActions << m_indentAction;
|
|
|
|
|
m_modifyingActions << m_unindentAction;
|
2013-12-10 15:54:20 +01:00
|
|
|
|
|
|
|
|
// set enabled state of optional actions
|
2014-07-01 14:26:55 +02:00
|
|
|
m_followSymbolAction->setEnabled(m_optionalActions & TextEditorActionHandler::FollowSymbolUnderCursor);
|
|
|
|
|
m_followSymbolInNextSplitAction->setEnabled(m_optionalActions & TextEditorActionHandler::FollowSymbolUnderCursor);
|
|
|
|
|
m_jumpToFileAction->setEnabled(m_optionalActions & TextEditorActionHandler::JumpToFileUnderCursor);
|
|
|
|
|
m_jumpToFileInNextSplitAction->setEnabled(m_optionalActions & TextEditorActionHandler::JumpToFileUnderCursor);
|
|
|
|
|
m_unfoldAllAction->setEnabled(m_optionalActions & TextEditorActionHandler::UnCollapseAll);
|
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
|
|
|
{
|
2013-12-10 15:54:20 +01:00
|
|
|
QTC_ASSERT(m_currentEditorWidget, return);
|
|
|
|
|
bool isWritable = !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_formatAction->setEnabled((m_optionalActions & TextEditorActionHandler::Format) && isWritable);
|
|
|
|
|
m_unCommentSelectionAction->setEnabled((m_optionalActions & TextEditorActionHandler::UnCommentSelection) && isWritable);
|
2013-12-10 15:54:20 +01:00
|
|
|
m_visualizeWhitespaceAction->setChecked(m_currentEditorWidget->displaySettings().m_visualizeWhitespace);
|
|
|
|
|
m_textWrappingAction->setChecked(m_currentEditorWidget->displaySettings().m_textWrapping);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2014-08-19 16:00:58 +02:00
|
|
|
updateRedoAction(m_currentEditorWidget->document()->isRedoAvailable());
|
|
|
|
|
updateUndoAction(m_currentEditorWidget->document()->isUndoAvailable());
|
|
|
|
|
updateCopyAction(m_currentEditorWidget->textCursor().hasSelection());
|
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
|
|
|
{
|
2013-12-10 15:54:20 +01:00
|
|
|
QTC_ASSERT(m_currentEditorWidget, return);
|
2008-12-02 12:01:29 +01:00
|
|
|
if (m_cutAction)
|
2013-12-10 15:54:20 +01:00
|
|
|
m_cutAction->setEnabled(hasCopyableText && !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);
|
|
|
|
|
m_currentEditorWidget = 0;
|
2009-02-16 12:50:15 +01:00
|
|
|
|
2013-12-10 15:54:20 +01:00
|
|
|
// don't need to do anything if the editor's context doesn't match
|
|
|
|
|
// (our actions will be disabled because our context will not be active)
|
2013-12-10 12:36:15 +01:00
|
|
|
if (!editor || !editor->context().contains(m_contextId))
|
2009-02-16 12:50:15 +01:00
|
|
|
return;
|
|
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget *editorWidget = q->resolveTextEditorWidget(editor);
|
2013-12-10 15:54:20 +01:00
|
|
|
QTC_ASSERT(editorWidget, return); // editor has our context id, so shouldn't happen
|
|
|
|
|
m_currentEditorWidget = editorWidget;
|
2014-08-19 16:00:58 +02:00
|
|
|
connect(editorWidget, &QPlainTextEdit::undoAvailable,
|
|
|
|
|
this, &TextEditorActionHandlerPrivate::updateUndoAction);
|
|
|
|
|
connect(editorWidget, &QPlainTextEdit::redoAvailable,
|
|
|
|
|
this, &TextEditorActionHandlerPrivate::updateRedoAction);
|
|
|
|
|
connect(editorWidget, &QPlainTextEdit::copyAvailable,
|
|
|
|
|
this, &TextEditorActionHandlerPrivate::updateCopyAction);
|
2014-09-26 11:37:54 +02:00
|
|
|
connect(editorWidget, &TextEditorWidget::readOnlyChanged,
|
2014-08-19 16:00:58 +02:00
|
|
|
this, &TextEditorActionHandlerPrivate::updateActions);
|
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
|
|
|
|
|
|
|
|
|
|
TextEditorActionHandler::TextEditorActionHandler(QObject *parent, Core::Id contextId, uint optionalActions)
|
|
|
|
|
: QObject(parent), d(new Internal::TextEditorActionHandlerPrivate(this, contextId, optionalActions))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TextEditorActionHandler::~TextEditorActionHandler()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget *TextEditorActionHandler::resolveTextEditorWidget(Core::IEditor *editor) const
|
2014-07-01 14:26:55 +02:00
|
|
|
{
|
2014-09-26 11:37:54 +02:00
|
|
|
return qobject_cast<TextEditorWidget *>(editor->widget());
|
2014-07-01 14:26:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace TextEditor
|