1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "texteditoractionhandler.h"
36 #include "basetexteditor.h"
37 #include "displaysettings.h"
38 #include "linenumberfilter.h"
39 #include "texteditorconstants.h"
40 #include "texteditorplugin.h"
42 #include <locator/locatormanager.h>
43 #include <coreplugin/icore.h>
44 #include <coreplugin/coreconstants.h>
45 #include <coreplugin/actionmanager/actionmanager.h>
46 #include <coreplugin/actionmanager/actioncontainer.h>
47 #include <coreplugin/actionmanager/command.h>
48 #include <coreplugin/editormanager/editormanager.h>
49 #include <coreplugin/uniqueidmanager.h>
50 #include <utils/qtcassert.h>
52 #include <QtCore/QSet>
53 #include <QtCore/QtDebug>
54 #include <QtGui/QAction>
55 #include <QtGui/QTextCursor>
57 using namespace TextEditor;
58 using namespace TextEditor::Internal;
60 TextEditorActionHandler::TextEditorActionHandler(const char *context,
62 : QObject(Core::ICore::instance()),
72 m_visualizeWhitespaceAction(0),
73 m_cleanWhitespaceAction(0),
74 m_textWrappingAction(0),
75 m_unCommentSelectionAction(0),
80 m_deleteLineAction(0),
81 m_selectEncodingAction(0),
82 m_increaseFontSizeAction(0),
83 m_decreaseFontSizeAction(0),
84 m_resetFontSizeAction(0),
85 m_gotoBlockStartAction(0),
86 m_gotoBlockEndAction(0),
87 m_gotoBlockStartWithSelectionAction(0),
88 m_gotoBlockEndWithSelectionAction(0),
89 m_selectBlockUpAction(0),
90 m_selectBlockDownAction(0),
91 m_moveLineUpAction(0),
92 m_moveLineDownAction(0),
93 m_copyLineUpAction(0),
94 m_copyLineDownAction(0),
96 m_optionalActions(optionalActions),
101 connect(Core::ICore::instance()->editorManager(), SIGNAL(currentEditorChanged(Core::IEditor*)),
102 this, SLOT(updateCurrentEditor(Core::IEditor*)));
105 void TextEditorActionHandler::setupActions(BaseTextEditor *editor)
108 editor->setActionHack(this);
109 QObject::connect(editor, SIGNAL(undoAvailable(bool)), this, SLOT(updateUndoAction()));
110 QObject::connect(editor, SIGNAL(redoAvailable(bool)), this, SLOT(updateRedoAction()));
111 QObject::connect(editor, SIGNAL(copyAvailable(bool)), this, SLOT(updateCopyAction()));
115 void TextEditorActionHandler::initializeActions()
117 if (!m_initialized) {
119 m_initialized = true;
123 void TextEditorActionHandler::createActions()
125 m_undoAction = registerNewAction(QLatin1String(Core::Constants::UNDO), this, SLOT(undoAction()),
127 m_redoAction = registerNewAction(QLatin1String(Core::Constants::REDO), this, SLOT(redoAction()),
129 m_copyAction = registerNewAction(QLatin1String(Core::Constants::COPY), this, SLOT(copyAction()), true);
130 m_cutAction = registerNewAction(QLatin1String(Core::Constants::CUT), this, SLOT(cutAction()), true);
131 m_pasteAction = registerNewAction(QLatin1String(Core::Constants::PASTE), this, SLOT(pasteAction()), true);
132 m_selectAllAction = registerNewAction(QLatin1String(Core::Constants::SELECTALL), this, SLOT(selectAllAction()), true);
133 m_gotoAction = registerNewAction(QLatin1String(Core::Constants::GOTO), this, SLOT(gotoAction()));
134 m_printAction = registerNewAction(QLatin1String(Core::Constants::PRINT), this, SLOT(printAction()));
136 Core::ActionManager *am = Core::ICore::instance()->actionManager();
138 Core::ActionContainer *medit = am->actionContainer(Core::Constants::M_EDIT);
139 Core::ActionContainer *advancedMenu = am->actionContainer(Core::Constants::M_EDIT_ADVANCED);
141 m_selectEncodingAction = new QAction(tr("Select Encoding..."), this);
142 Core::Command *command = am->registerAction(m_selectEncodingAction, Constants::SELECT_ENCODING, m_contextId);
143 connect(m_selectEncodingAction, SIGNAL(triggered()), this, SLOT(selectEncoding()));
144 medit->addAction(command, Core::Constants::G_EDIT_OTHER);
147 m_formatAction = new QAction(tr("Auto-&indent Selection"), this);
148 command = am->registerAction(m_formatAction, TextEditor::Constants::AUTO_INDENT_SELECTION, m_contextId, true);
149 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+I")));
150 advancedMenu->addAction(command, Core::Constants::G_EDIT_FORMAT);
151 connect(m_formatAction, SIGNAL(triggered(bool)), this, SLOT(formatAction()));
154 QString modifier = tr("Meta");
156 QString modifier = tr("Ctrl");
159 m_rewrapParagraphAction = new QAction(tr("&Rewrap Paragraph"), this);
160 command = am->registerAction(m_rewrapParagraphAction, TextEditor::Constants::REWRAP_PARAGRAPH, m_contextId, true);
161 command->setDefaultKeySequence(QKeySequence(tr("%1+E, R").arg(modifier)));
162 advancedMenu->addAction(command, Core::Constants::G_EDIT_FORMAT);
163 connect(m_rewrapParagraphAction, SIGNAL(triggered(bool)), this, SLOT(rewrapParagraphAction()));
166 m_visualizeWhitespaceAction = new QAction(tr("&Visualize Whitespace"), this);
167 m_visualizeWhitespaceAction->setCheckable(true);
168 command = am->registerAction(m_visualizeWhitespaceAction,
169 TextEditor::Constants::VISUALIZE_WHITESPACE, m_contextId);
170 command->setDefaultKeySequence(QKeySequence(tr("%1+E, %2+V").arg(modifier, modifier)));
171 advancedMenu->addAction(command, Core::Constants::G_EDIT_FORMAT);
172 connect(m_visualizeWhitespaceAction, SIGNAL(triggered(bool)), this, SLOT(setVisualizeWhitespace(bool)));
174 m_cleanWhitespaceAction = new QAction(tr("Clean Whitespace"), this);
175 command = am->registerAction(m_cleanWhitespaceAction,
176 TextEditor::Constants::CLEAN_WHITESPACE, m_contextId, true);
178 advancedMenu->addAction(command, Core::Constants::G_EDIT_FORMAT);
179 connect(m_cleanWhitespaceAction, SIGNAL(triggered()), this, SLOT(cleanWhitespace()));
181 m_textWrappingAction = new QAction(tr("Enable Text &Wrapping"), this);
182 m_textWrappingAction->setCheckable(true);
183 command = am->registerAction(m_textWrappingAction, TextEditor::Constants::TEXT_WRAPPING, m_contextId);
184 command->setDefaultKeySequence(QKeySequence(tr("%1+E, %2+W").arg(modifier, modifier)));
185 advancedMenu->addAction(command, Core::Constants::G_EDIT_FORMAT);
186 connect(m_textWrappingAction, SIGNAL(triggered(bool)), this, SLOT(setTextWrapping(bool)));
189 m_unCommentSelectionAction = new QAction(tr("(Un)Comment &Selection"), this);
190 command = am->registerAction(m_unCommentSelectionAction, Constants::UN_COMMENT_SELECTION, m_contextId, true);
191 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+/")));
192 connect(m_unCommentSelectionAction, SIGNAL(triggered()), this, SLOT(unCommentSelection()));
193 advancedMenu->addAction(command, Core::Constants::G_EDIT_FORMAT);
195 m_cutLineAction = new QAction(tr("Cut &Line"), this);
196 command = am->registerAction(m_cutLineAction, Constants::CUT_LINE, m_contextId, true);
197 command->setDefaultKeySequence(QKeySequence(tr("Shift+Del")));
198 connect(m_cutLineAction, SIGNAL(triggered()), this, SLOT(cutLine()));
200 m_deleteLineAction = new QAction(tr("Delete &Line"), this);
201 command = am->registerAction(m_deleteLineAction, Constants::DELETE_LINE, m_contextId, true);
202 connect(m_deleteLineAction, SIGNAL(triggered()), this, SLOT(deleteLine()));
204 m_foldAction = new QAction(tr("Fold"), this);
205 command = am->registerAction(m_foldAction, Constants::FOLD, m_contextId, true);
206 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+<")));
207 connect(m_foldAction, SIGNAL(triggered()), this, SLOT(fold()));
208 advancedMenu->addAction(command, Core::Constants::G_EDIT_COLLAPSING);
210 m_unfoldAction = new QAction(tr("Unfold"), this);
211 command = am->registerAction(m_unfoldAction, Constants::UNFOLD, m_contextId, true);
212 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+>")));
213 connect(m_unfoldAction, SIGNAL(triggered()), this, SLOT(unfold()));
214 advancedMenu->addAction(command, Core::Constants::G_EDIT_COLLAPSING);
216 m_unfoldAllAction = new QAction(tr("(Un)&Fold All"), this);
217 command = am->registerAction(m_unfoldAllAction, Constants::UNFOLD_ALL, m_contextId, true);
218 connect(m_unfoldAllAction, SIGNAL(triggered()), this, SLOT(unfoldAll()));
219 advancedMenu->addAction(command, Core::Constants::G_EDIT_COLLAPSING);
221 m_increaseFontSizeAction = new QAction(tr("Increase Font Size"), this);
222 command = am->registerAction(m_increaseFontSizeAction, Constants::INCREASE_FONT_SIZE, m_contextId);
223 command->setDefaultKeySequence(QKeySequence(tr("Ctrl++")));
224 connect(m_increaseFontSizeAction, SIGNAL(triggered()), this, SLOT(increaseFontSize()));
225 advancedMenu->addAction(command, Core::Constants::G_EDIT_FONT);
227 m_decreaseFontSizeAction = new QAction(tr("Decrease Font Size"), this);
228 command = am->registerAction(m_decreaseFontSizeAction, Constants::DECREASE_FONT_SIZE, m_contextId);
229 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+-")));
230 connect(m_decreaseFontSizeAction, SIGNAL(triggered()), this, SLOT(decreaseFontSize()));
231 advancedMenu->addAction(command, Core::Constants::G_EDIT_FONT);
233 m_resetFontSizeAction = new QAction(tr("Reset Font Size"), this);
234 command = am->registerAction(m_resetFontSizeAction, Constants::RESET_FONT_SIZE, m_contextId);
236 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+0")));
238 connect(m_resetFontSizeAction, SIGNAL(triggered()), this, SLOT(resetFontSize()));
239 advancedMenu->addAction(command, Core::Constants::G_EDIT_FONT);
241 m_gotoBlockStartAction = new QAction(tr("Go to Block Start"), this);
242 command = am->registerAction(m_gotoBlockStartAction, Constants::GOTO_BLOCK_START, m_contextId, true);
243 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+[")));
244 connect(m_gotoBlockStartAction, SIGNAL(triggered()), this, SLOT(gotoBlockStart()));
245 advancedMenu->addAction(command, Core::Constants::G_EDIT_BLOCKS);
247 m_gotoBlockEndAction = new QAction(tr("Go to Block End"), this);
248 command = am->registerAction(m_gotoBlockEndAction, Constants::GOTO_BLOCK_END, m_contextId, true);
249 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+]")));
250 connect(m_gotoBlockEndAction, SIGNAL(triggered()), this, SLOT(gotoBlockEnd()));
251 advancedMenu->addAction(command, Core::Constants::G_EDIT_BLOCKS);
253 m_gotoBlockStartWithSelectionAction = new QAction(tr("Go to Block Start With Selection"), this);
254 command = am->registerAction(m_gotoBlockStartWithSelectionAction, Constants::GOTO_BLOCK_START_WITH_SELECTION, m_contextId, true);
255 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+{")));
256 connect(m_gotoBlockStartWithSelectionAction, SIGNAL(triggered()), this, SLOT(gotoBlockStartWithSelection()));
258 m_gotoBlockEndWithSelectionAction = new QAction(tr("Go to Block End With Selection"), this);
259 command = am->registerAction(m_gotoBlockEndWithSelectionAction, Constants::GOTO_BLOCK_END_WITH_SELECTION, m_contextId, true);
260 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+}")));
261 connect(m_gotoBlockEndWithSelectionAction, SIGNAL(triggered()), this, SLOT(gotoBlockEndWithSelection()));
263 m_selectBlockUpAction = new QAction(tr("Select Block Up"), this);
264 command = am->registerAction(m_selectBlockUpAction, Constants::SELECT_BLOCK_UP, m_contextId, true);
265 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+U")));
266 connect(m_selectBlockUpAction, SIGNAL(triggered()), this, SLOT(selectBlockUp()));
267 advancedMenu->addAction(command, Core::Constants::G_EDIT_BLOCKS);
269 m_selectBlockDownAction = new QAction(tr("Select Block Down"), this);
270 command = am->registerAction(m_selectBlockDownAction, Constants::SELECT_BLOCK_DOWN, m_contextId, true);
271 connect(m_selectBlockDownAction, SIGNAL(triggered()), this, SLOT(selectBlockDown()));
272 advancedMenu->addAction(command, Core::Constants::G_EDIT_BLOCKS);
274 m_moveLineUpAction = new QAction(tr("Move Line Up"), this);
275 command = am->registerAction(m_moveLineUpAction, Constants::MOVE_LINE_UP, m_contextId, true);
276 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+Up")));
277 connect(m_moveLineUpAction, SIGNAL(triggered()), this, SLOT(moveLineUp()));
279 m_moveLineDownAction = new QAction(tr("Move Line Down"), this);
280 command = am->registerAction(m_moveLineDownAction, Constants::MOVE_LINE_DOWN, m_contextId, true);
281 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+Down")));
282 connect(m_moveLineDownAction, SIGNAL(triggered()), this, SLOT(moveLineDown()));
284 m_copyLineUpAction = new QAction(tr("Copy Line Up"), this);
285 command = am->registerAction(m_copyLineUpAction, Constants::COPY_LINE_UP, m_contextId, true);
286 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Up")));
287 connect(m_copyLineUpAction, SIGNAL(triggered()), this, SLOT(copyLineUp()));
289 m_copyLineDownAction = new QAction(tr("Copy Line Down"), this);
290 command = am->registerAction(m_copyLineDownAction, Constants::COPY_LINE_DOWN, m_contextId, true);
291 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Down")));
292 connect(m_copyLineDownAction, SIGNAL(triggered()), this, SLOT(copyLineDown()));
294 m_joinLinesAction = new QAction(tr("Join Lines"), this);
295 command = am->registerAction(m_joinLinesAction, Constants::JOIN_LINES, m_contextId, true);
296 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+J")));
297 connect(m_joinLinesAction, SIGNAL(triggered()), this, SLOT(joinLines()));
299 m_insertLineAboveAction = new QAction(tr("Insert Line Above Current Line"), this);
300 command = am->registerAction(m_insertLineAboveAction, Constants::INSERT_LINE_ABOVE, m_contextId, true);
301 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+Return")));
302 connect(m_insertLineAboveAction, SIGNAL(triggered()), this, SLOT(insertLineAbove()));
304 m_insertLineBelowAction = new QAction(tr("Insert Line Below Current Line"), this);
305 command = am->registerAction(m_insertLineBelowAction, Constants::INSERT_LINE_BELOW, m_contextId, true);
306 command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Return")));
307 connect(m_insertLineBelowAction, SIGNAL(triggered()), this, SLOT(insertLineBelow()));
310 a = new QAction(tr("Goto Line Start"), this);
311 command = am->registerAction(a, Constants::GOTO_LINE_START, m_contextId, true);
312 connect(a, SIGNAL(triggered()), this, SLOT(gotoLineStart()));
313 a = new QAction(tr("Goto Line End"), this);
314 command = am->registerAction(a, Constants::GOTO_LINE_END, m_contextId, true);
315 connect(a, SIGNAL(triggered()), this, SLOT(gotoLineEnd()));
316 a = new QAction(tr("Goto Next Line"), this);
317 command = am->registerAction(a, Constants::GOTO_NEXT_LINE, m_contextId, true);
318 connect(a, SIGNAL(triggered()), this, SLOT(gotoNextLine()));
319 a = new QAction(tr("Goto Previous Line"), this);
320 command = am->registerAction(a, Constants::GOTO_PREVIOUS_LINE, m_contextId, true);
321 connect(a, SIGNAL(triggered()), this, SLOT(gotoPreviousLine()));
322 a = new QAction(tr("Goto Previous Character"), this);
323 command = am->registerAction(a, Constants::GOTO_PREVIOUS_CHARACTER, m_contextId, true);
324 connect(a, SIGNAL(triggered()), this, SLOT(gotoPreviousCharacter()));
325 a = new QAction(tr("Goto Next Character"), this);
326 command = am->registerAction(a, Constants::GOTO_NEXT_CHARACTER, m_contextId, true);
327 connect(a, SIGNAL(triggered()), this, SLOT(gotoNextCharacter()));
328 a = new QAction(tr("Goto Previous Word"), this);
329 command = am->registerAction(a, Constants::GOTO_PREVIOUS_WORD, m_contextId, true);
330 connect(a, SIGNAL(triggered()), this, SLOT(gotoPreviousWord()));
331 a = new QAction(tr("Goto Next Word"), this);
332 command = am->registerAction(a, Constants::GOTO_NEXT_WORD, m_contextId, true);
333 connect(a, SIGNAL(triggered()), this, SLOT(gotoNextWord()));
334 a = new QAction(tr("Goto Previous Word Camel Case"), this);
335 command = am->registerAction(a, Constants::GOTO_PREVIOUS_WORD_CAMEL_CASE, m_contextId);
336 connect(a, SIGNAL(triggered()), this, SLOT(gotoPreviousWordCamelCase()));
337 a = new QAction(tr("Goto Next Word Camel Case"), this);
338 command = am->registerAction(a, Constants::GOTO_NEXT_WORD_CAMEL_CASE, m_contextId);
339 connect(a, SIGNAL(triggered()), this, SLOT(gotoNextWordCamelCase()));
341 a = new QAction(tr("Goto Line Start With Selection"), this);
342 command = am->registerAction(a, Constants::GOTO_LINE_START_WITH_SELECTION, m_contextId, true);
343 connect(a, SIGNAL(triggered()), this, SLOT(gotoLineStartWithSelection()));
344 a = new QAction(tr("Goto Line End With Selection"), this);
345 command = am->registerAction(a, Constants::GOTO_LINE_END_WITH_SELECTION, m_contextId, true);
346 connect(a, SIGNAL(triggered()), this, SLOT(gotoLineEndWithSelection()));
347 a = new QAction(tr("Goto Next Line With Selection"), this);
348 command = am->registerAction(a, Constants::GOTO_NEXT_LINE_WITH_SELECTION, m_contextId, true);
349 connect(a, SIGNAL(triggered()), this, SLOT(gotoNextLineWithSelection()));
350 a = new QAction(tr("Goto Previous Line With Selection"), this);
351 command = am->registerAction(a, Constants::GOTO_PREVIOUS_LINE_WITH_SELECTION, m_contextId, true);
352 connect(a, SIGNAL(triggered()), this, SLOT(gotoPreviousLineWithSelection()));
353 a = new QAction(tr("Goto Previous Character With Selection"), this);
354 command = am->registerAction(a, Constants::GOTO_PREVIOUS_CHARACTER_WITH_SELECTION, m_contextId, true);
355 connect(a, SIGNAL(triggered()), this, SLOT(gotoPreviousCharacterWithSelection()));
356 a = new QAction(tr("Goto Next Character With Selection"), this);
357 command = am->registerAction(a, Constants::GOTO_NEXT_CHARACTER_WITH_SELECTION, m_contextId, true);
358 connect(a, SIGNAL(triggered()), this, SLOT(gotoNextCharacterWithSelection()));
359 a = new QAction(tr("Goto Previous Word With Selection"), this);
360 command = am->registerAction(a, Constants::GOTO_PREVIOUS_WORD_WITH_SELECTION, m_contextId, true);
361 connect(a, SIGNAL(triggered()), this, SLOT(gotoPreviousWordWithSelection()));
362 a = new QAction(tr("Goto Next Word With Selection"), this);
363 command = am->registerAction(a, Constants::GOTO_NEXT_WORD_WITH_SELECTION, m_contextId, true);
364 connect(a, SIGNAL(triggered()), this, SLOT(gotoNextWordWithSelection()));
365 a = new QAction(tr("Goto Previous Word Camel Case With Selection"), this);
366 command = am->registerAction(a, Constants::GOTO_PREVIOUS_WORD_CAMEL_CASE_WITH_SELECTION, m_contextId);
367 connect(a, SIGNAL(triggered()), this, SLOT(gotoPreviousWordCamelCaseWithSelection()));
368 a = new QAction(tr("Goto Next Word Camel Case With Selection"), this);
369 command = am->registerAction(a, Constants::GOTO_NEXT_WORD_CAMEL_CASE_WITH_SELECTION, m_contextId);
370 connect(a, SIGNAL(triggered()), this, SLOT(gotoNextWordCamelCaseWithSelection()));
374 bool TextEditorActionHandler::supportsAction(const QString & /*id */) const
379 QAction *TextEditorActionHandler::registerNewAction(const QString &id, bool scriptable, const QString &title)
381 if (!supportsAction(id))
384 QAction *result = new QAction(title, this);
385 Core::ICore::instance()->actionManager()->registerAction(result, id, m_contextId, scriptable);
389 QAction *TextEditorActionHandler::registerNewAction(const QString &id,
393 const QString &title)
395 QAction *rc = registerNewAction(id, scriptable, title);
399 connect(rc, SIGNAL(triggered()), receiver, slot);
403 TextEditorActionHandler::UpdateMode TextEditorActionHandler::updateMode() const
405 Q_ASSERT(m_currentEditor != 0);
406 return m_currentEditor->file()->isReadOnly() ? ReadOnlyMode : WriteMode;
409 void TextEditorActionHandler::updateActions()
411 if (!m_currentEditor || !m_initialized)
413 updateActions(updateMode());
416 void TextEditorActionHandler::updateActions(UpdateMode um)
418 m_pasteAction->setEnabled(um != ReadOnlyMode);
419 m_formatAction->setEnabled((m_optionalActions & Format) && um != ReadOnlyMode);
420 m_unCommentSelectionAction->setEnabled((m_optionalActions & UnCommentSelection) && um != ReadOnlyMode);
421 m_moveLineUpAction->setEnabled(um != ReadOnlyMode);
422 m_moveLineDownAction->setEnabled(um != ReadOnlyMode);
424 m_formatAction->setEnabled((m_optionalActions & Format));
425 m_unfoldAllAction->setEnabled((m_optionalActions & UnCollapseAll));
426 m_visualizeWhitespaceAction->setChecked(m_currentEditor->displaySettings().m_visualizeWhitespace);
427 if (m_textWrappingAction) {
428 m_textWrappingAction->setChecked(m_currentEditor->displaySettings().m_textWrapping);
436 void TextEditorActionHandler::updateRedoAction()
439 m_redoAction->setEnabled(m_currentEditor && m_currentEditor->document()->isRedoAvailable());
442 void TextEditorActionHandler::updateUndoAction()
445 m_undoAction->setEnabled(m_currentEditor && m_currentEditor->document()->isUndoAvailable());
448 void TextEditorActionHandler::updateCopyAction()
450 const bool hasCopyableText = m_currentEditor && m_currentEditor->textCursor().hasSelection();
452 m_cutAction->setEnabled(hasCopyableText && updateMode() == WriteMode);
454 m_copyAction->setEnabled(hasCopyableText);
458 void TextEditorActionHandler::gotoAction()
460 Locator::LocatorManager *locatorManager = Locator::LocatorManager::instance();
461 QTC_ASSERT(locatorManager, return);
462 QString locatorString = TextEditorPlugin::instance()->lineNumberFilter()->shortcutString();
463 locatorString += QLatin1Char(' ');
464 const int selectionStart = locatorString.size();
465 locatorString += tr("<line number>");
466 locatorManager->show(locatorString, selectionStart, locatorString.size() - selectionStart);
469 void TextEditorActionHandler::printAction()
472 m_currentEditor->print(Core::ICore::instance()->printer());
475 void TextEditorActionHandler::setVisualizeWhitespace(bool checked)
477 if (m_currentEditor) {
478 DisplaySettings ds = m_currentEditor->displaySettings();
479 ds.m_visualizeWhitespace = checked;
480 m_currentEditor->setDisplaySettings(ds);
484 void TextEditorActionHandler::setTextWrapping(bool checked)
486 if (m_currentEditor) {
487 DisplaySettings ds = m_currentEditor->displaySettings();
488 ds.m_textWrapping = checked;
489 m_currentEditor->setDisplaySettings(ds);
493 #define FUNCTION(funcname) void TextEditorActionHandler::funcname ()\
495 if (m_currentEditor)\
496 m_currentEditor->funcname ();\
498 #define FUNCTION2(funcname, funcname2) void TextEditorActionHandler::funcname ()\
500 if (m_currentEditor)\
501 m_currentEditor->funcname2 ();\
505 FUNCTION2(undoAction, undo)
506 FUNCTION2(redoAction, redo)
507 FUNCTION2(copyAction, copy)
508 FUNCTION2(cutAction, cut)
509 FUNCTION2(pasteAction, paste)
510 FUNCTION2(formatAction, format)
511 FUNCTION2(rewrapParagraphAction, rewrapParagraph)
512 FUNCTION2(selectAllAction, selectAll)
513 FUNCTION(cleanWhitespace)
514 FUNCTION(unCommentSelection)
520 FUNCTION2(increaseFontSize, zoomIn)
521 FUNCTION2(decreaseFontSize, zoomOut)
522 FUNCTION2(resetFontSize, zoomReset)
523 FUNCTION(selectEncoding)
524 FUNCTION(gotoBlockStart)
525 FUNCTION(gotoBlockEnd)
526 FUNCTION(gotoBlockStartWithSelection)
527 FUNCTION(gotoBlockEndWithSelection)
528 FUNCTION(selectBlockUp)
529 FUNCTION(selectBlockDown)
531 FUNCTION(moveLineDown)
533 FUNCTION(copyLineDown)
535 FUNCTION(insertLineAbove)
536 FUNCTION(insertLineBelow)
538 FUNCTION(gotoLineStart)
539 FUNCTION(gotoLineStartWithSelection)
540 FUNCTION(gotoLineEnd)
541 FUNCTION(gotoLineEndWithSelection)
542 FUNCTION(gotoNextLine)
543 FUNCTION(gotoNextLineWithSelection)
544 FUNCTION(gotoPreviousLine)
545 FUNCTION(gotoPreviousLineWithSelection)
546 FUNCTION(gotoPreviousCharacter)
547 FUNCTION(gotoPreviousCharacterWithSelection)
548 FUNCTION(gotoNextCharacter)
549 FUNCTION(gotoNextCharacterWithSelection)
550 FUNCTION(gotoPreviousWord)
551 FUNCTION(gotoPreviousWordWithSelection)
552 FUNCTION(gotoPreviousWordCamelCase)
553 FUNCTION(gotoPreviousWordCamelCaseWithSelection)
554 FUNCTION(gotoNextWord)
555 FUNCTION(gotoNextWordWithSelection)
556 FUNCTION(gotoNextWordCamelCase)
557 FUNCTION(gotoNextWordCamelCaseWithSelection)
560 void TextEditorActionHandler::updateCurrentEditor(Core::IEditor *editor)
567 BaseTextEditor *baseEditor = qobject_cast<BaseTextEditor *>(editor->widget());
569 if (baseEditor && baseEditor->actionHack() == this) {
570 m_currentEditor = baseEditor;
575 const QPointer<BaseTextEditor> &TextEditorActionHandler::currentEditor() const
577 return m_currentEditor;