Changeset View
Changeset View
Standalone View
Standalone View
src/view/kateview.cpp
Show First 20 Lines • Show All 493 Lines • ▼ Show 20 Line(s) | 485 | if (!doc()->readOnly()) { | |||
---|---|---|---|---|---|
494 | 494 | | |||
495 | // Tools > Scripts | 495 | // Tools > Scripts | ||
496 | // stored inside scoped pointer to ensure we destruct it early enough as it does internal cleanups of other child objects | 496 | // stored inside scoped pointer to ensure we destruct it early enough as it does internal cleanups of other child objects | ||
497 | m_scriptActionMenu.reset(new KateScriptActionMenu(this, i18n("&Scripts"))); | 497 | m_scriptActionMenu.reset(new KateScriptActionMenu(this, i18n("&Scripts"))); | ||
498 | ac->addAction(QStringLiteral("tools_scripts"), m_scriptActionMenu.data()); | 498 | ac->addAction(QStringLiteral("tools_scripts"), m_scriptActionMenu.data()); | ||
499 | 499 | | |||
500 | a = ac->addAction(QStringLiteral("tools_apply_wordwrap")); | 500 | a = ac->addAction(QStringLiteral("tools_apply_wordwrap")); | ||
501 | a->setText(i18n("Apply &Word Wrap")); | 501 | a->setText(i18n("Apply &Word Wrap")); | ||
502 | a->setWhatsThis(i18n("Use this command to wrap all lines of the current document which are longer than the width of the" | 502 | a->setWhatsThis(i18n("Use this to wrap the current line, or to reformat the selected lines as paragraph, " | ||
503 | " current view, to fit into this view.<br /><br /> This is a static word wrap, meaning it is not updated" | 503 | "to fit the 'Wrap words at' setting in the configuration dialog.<br /><br />" | ||
504 | " when the view is resized.")); | 504 | "This is a static word wrap, meaning the document is changed.")); | ||
505 | connect(a, SIGNAL(triggered(bool)), SLOT(applyWordWrap())); | 505 | connect(a, SIGNAL(triggered(bool)), SLOT(applyWordWrap())); | ||
506 | 506 | | |||
507 | a = ac->addAction(QStringLiteral("tools_cleanIndent")); | 507 | a = ac->addAction(QStringLiteral("tools_cleanIndent")); | ||
508 | a->setText(i18n("&Clean Indentation")); | 508 | a->setText(i18n("&Clean Indentation")); | ||
509 | a->setWhatsThis(i18n("Use this to clean the indentation of a selected block of text (only tabs/only spaces).<br /><br />" | 509 | a->setWhatsThis(i18n("Use this to clean the indentation of a selected block of text (only tabs/only spaces).<br /><br />" | ||
510 | "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog.")); | 510 | "You can configure whether tabs should be honored and used or replaced with spaces, in the configuration dialog.")); | ||
511 | connect(a, SIGNAL(triggered(bool)), SLOT(cleanIndent())); | 511 | connect(a, SIGNAL(triggered(bool)), SLOT(cleanIndent())); | ||
512 | 512 | | |||
▲ Show 20 Lines • Show All 179 Lines • ▼ Show 20 Line(s) | |||||
692 | ac->setDefaultShortcut(a, QKeySequence(Qt::Key_Insert)); | 692 | ac->setDefaultShortcut(a, QKeySequence(Qt::Key_Insert)); | ||
693 | a->setWhatsThis(i18n("Choose whether you want the text you type to be inserted or to overwrite existing text.")); | 693 | a->setWhatsThis(i18n("Choose whether you want the text you type to be inserted or to overwrite existing text.")); | ||
694 | connect(a, SIGNAL(triggered(bool)), SLOT(toggleInsert())); | 694 | connect(a, SIGNAL(triggered(bool)), SLOT(toggleInsert())); | ||
695 | 695 | | |||
696 | KToggleAction *toggleAction; | 696 | KToggleAction *toggleAction; | ||
697 | a = m_toggleDynWrap = toggleAction = new KToggleAction(i18n("&Dynamic Word Wrap"), this); | 697 | a = m_toggleDynWrap = toggleAction = new KToggleAction(i18n("&Dynamic Word Wrap"), this); | ||
698 | ac->addAction(QStringLiteral("view_dynamic_word_wrap"), a); | 698 | ac->addAction(QStringLiteral("view_dynamic_word_wrap"), a); | ||
699 | ac->setDefaultShortcut(a, QKeySequence(Qt::Key_F10)); | 699 | ac->setDefaultShortcut(a, QKeySequence(Qt::Key_F10)); | ||
700 | a->setWhatsThis(i18n("If this option is checked, the text lines will be wrapped at the view border on the screen.")); | 700 | a->setWhatsThis(i18n("If this option is checked, the text lines will be wrapped at the view border on the screen.<br /><br />" | ||
701 | "This is only a view option, meaning the document will not changed.")); | ||||
701 | connect(a, SIGNAL(triggered(bool)), SLOT(toggleDynWordWrap())); | 702 | connect(a, SIGNAL(triggered(bool)), SLOT(toggleDynWordWrap())); | ||
702 | 703 | | |||
703 | a = m_setDynWrapIndicators = new KSelectAction(i18n("Dynamic Word Wrap Indicators"), this); | 704 | a = m_setDynWrapIndicators = new KSelectAction(i18n("Dynamic Word Wrap Indicators"), this); | ||
704 | ac->addAction(QStringLiteral("dynamic_word_wrap_indicators"), a); | 705 | ac->addAction(QStringLiteral("dynamic_word_wrap_indicators"), a); | ||
705 | a->setWhatsThis(i18n("Choose when the Dynamic Word Wrap Indicators should be displayed")); | 706 | a->setWhatsThis(i18n("Choose when the Dynamic Word Wrap Indicators should be displayed")); | ||
706 | connect(m_setDynWrapIndicators, SIGNAL(triggered(int)), this, SLOT(setDynWrapIndicators(int))); | 707 | connect(m_setDynWrapIndicators, SIGNAL(triggered(int)), this, SLOT(setDynWrapIndicators(int))); | ||
707 | const QStringList list2{ i18n("&Off"), i18n("Follow &Line Numbers"), i18n("&Always On") }; | 708 | const QStringList list2{ i18n("&Off"), i18n("Follow &Line Numbers"), i18n("&Always On") }; | ||
708 | m_setDynWrapIndicators->setItems(list2); | 709 | m_setDynWrapIndicators->setItems(list2); | ||
▲ Show 20 Lines • Show All 1624 Lines • ▼ Show 20 Line(s) | 2323 | { | |||
2333 | } | 2334 | } | ||
2334 | 2335 | | |||
2335 | // copy to clipboard and our history! | 2336 | // copy to clipboard and our history! | ||
2336 | KTextEditor::EditorPrivate::self()->copyToClipboard(text); | 2337 | KTextEditor::EditorPrivate::self()->copyToClipboard(text); | ||
2337 | } | 2338 | } | ||
2338 | 2339 | | |||
2339 | void KTextEditor::ViewPrivate::applyWordWrap() | 2340 | void KTextEditor::ViewPrivate::applyWordWrap() | ||
2340 | { | 2341 | { | ||
2341 | if (selection()) { | 2342 | int first = selectionRange().start().line(); | ||
2342 | doc()->wrapText(selectionRange().start().line(), selectionRange().end().line()); | 2343 | int last = selectionRange().end().line(); | ||
2343 | } else { | 2344 | | ||
2344 | doc()->wrapText(0, doc()->lastLine()); | 2345 | if (first == last) { | ||
2346 | // Either no selection or only one line selected, wrap only the current line | ||||
mwolff: all of this functionality needs to go into the document, it shouldn't depend on the view. | |||||
2347 | first = cursorPosition().line(); | ||||
2348 | last = first; | ||||
2345 | } | 2349 | } | ||
2350 | | ||||
2351 | doc()->wrapParagraph(first, last); | ||||
2346 | } | 2352 | } | ||
2347 | 2353 | | |||
2348 | //END | 2354 | //END | ||
2349 | 2355 | | |||
mwolff: store in a std::unique_ptr and remove the manual `delete` further down below | |||||
loh.tar: fine, will do it | |||||
2350 | //BEGIN KTextEditor::BlockSelectionInterface stuff | 2356 | //BEGIN KTextEditor::BlockSelectionInterface stuff | ||
2351 | 2357 | | |||
2352 | bool KTextEditor::ViewPrivate::blockSelection() const | 2358 | bool KTextEditor::ViewPrivate::blockSelection() const | ||
2353 | { | 2359 | { | ||
mwolff: bool shouldWrap = true; | |||||
loh.tar: I dislike that. I hope someone else like my goto way | |||||
2354 | return blockSelect; | 2360 | return blockSelect; | ||
2355 | } | 2361 | } | ||
2356 | 2362 | | |||
2357 | bool KTextEditor::ViewPrivate::setBlockSelection(bool on) | 2363 | bool KTextEditor::ViewPrivate::setBlockSelection(bool on) | ||
2358 | { | 2364 | { | ||
2359 | if (on != blockSelect) { | 2365 | if (on != blockSelect) { | ||
2360 | blockSelect = on; | 2366 | blockSelect = on; | ||
mwolff: shouldWrap = false;
break; | |||||
2361 | 2367 | | |||
2362 | KTextEditor::Range oldSelection = m_selection; | 2368 | KTextEditor::Range oldSelection = m_selection; | ||
2363 | 2369 | | |||
2364 | const bool hadSelection = clearSelection(false, false); | 2370 | const bool hadSelection = clearSelection(false, false); | ||
mwolff: if (!shouldWrap) {
continue;
}
| |||||
2365 | 2371 | | |||
2366 | setSelection(oldSelection); | 2372 | setSelection(oldSelection); | ||
2367 | 2373 | | |||
2368 | m_toggleBlockSelection->setChecked(blockSelection()); | 2374 | m_toggleBlockSelection->setChecked(blockSelection()); | ||
2369 | 2375 | | |||
2370 | // when leaving block selection mode, if cursor is at an invalid position or past the end of the | 2376 | // when leaving block selection mode, if cursor is at an invalid position or past the end of the | ||
2371 | // line, move the cursor to the last column of the current line unless cursor wrapping is off | 2377 | // line, move the cursor to the last column of the current line unless cursor wrapping is off | ||
2372 | ensureCursorColumnValid(); | 2378 | ensureCursorColumnValid(); | ||
▲ Show 20 Lines • Show All 1443 Lines • Show Last 20 Lines |
all of this functionality needs to go into the document, it shouldn't depend on the view.