Changeset View
Changeset View
Standalone View
Standalone View
src/search/katesearchbar.cpp
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
43 | #include <KLocalizedString> | 43 | #include <KLocalizedString> | ||
44 | 44 | | |||
45 | #include <QVBoxLayout> | 45 | #include <QVBoxLayout> | ||
46 | #include <QCheckBox> | 46 | #include <QCheckBox> | ||
47 | #include <QComboBox> | 47 | #include <QComboBox> | ||
48 | #include <QCompleter> | 48 | #include <QCompleter> | ||
49 | #include <QShortcut> | 49 | #include <QShortcut> | ||
50 | #include <QStringListModel> | 50 | #include <QStringListModel> | ||
51 | #include <QTime> | ||||
51 | 52 | | |||
52 | #include <memory> | | |||
53 | #include <vector> | 53 | #include <vector> | ||
54 | 54 | | |||
55 | // Turn debug messages on/off here | 55 | // Turn debug messages on/off here | ||
56 | // #define FAST_DEBUG_ENABLE | 56 | // #define FAST_DEBUG_ENABLE | ||
57 | 57 | | |||
58 | #ifdef FAST_DEBUG_ENABLE | 58 | #ifdef FAST_DEBUG_ENABLE | ||
59 | # define FAST_DEBUG(x) qCDebug(LOG_KTE) << x | 59 | # define FAST_DEBUG(x) qCDebug(LOG_KTE) << x | ||
60 | #else | 60 | #else | ||
Show All 14 Lines | 72 | private: | |||
75 | QSet<QAction *> m_actionPointers; | 75 | QSet<QAction *> m_actionPointers; | ||
76 | uint m_indexWalker; | 76 | uint m_indexWalker; | ||
77 | QMenu *m_menu; | 77 | QMenu *m_menu; | ||
78 | 78 | | |||
79 | public: | 79 | public: | ||
80 | AddMenuManager(QMenu *parent, int expectedItemCount) | 80 | AddMenuManager(QMenu *parent, int expectedItemCount) | ||
81 | : m_insertBefore(QVector<QString>(expectedItemCount)), | 81 | : m_insertBefore(QVector<QString>(expectedItemCount)), | ||
82 | m_insertAfter(QVector<QString>(expectedItemCount)), | 82 | m_insertAfter(QVector<QString>(expectedItemCount)), | ||
83 | m_indexWalker(0), | 83 | m_indexWalker(0), | ||
anthonyfieroni: It's not needed, right? | |||||
84 | m_menu(nullptr) | 84 | m_menu(nullptr) | ||
85 | { | 85 | { | ||
86 | Q_ASSERT(parent != nullptr); | 86 | Q_ASSERT(parent != nullptr); | ||
87 | m_menu = parent->addMenu(i18n("Add...")); | 87 | m_menu = parent->addMenu(i18n("Add...")); | ||
88 | if (m_menu == nullptr) { | 88 | if (m_menu == nullptr) { | ||
89 | return; | 89 | return; | ||
You can take another approach connect(foo, &Qobject::destroyed, d_func, [foo]() { delete d_func()->take(foo); }); anthonyfieroni: You can take another approach
```
connect(foo, &Qobject::destroyed, d_func, [foo]() { delete… | |||||
90 | } | 90 | } | ||
91 | m_menu->setIcon(QIcon::fromTheme(QStringLiteral("list-add"))); | 91 | m_menu->setIcon(QIcon::fromTheme(QStringLiteral("list-add"))); | ||
92 | } | 92 | } | ||
93 | 93 | | |||
94 | void enableMenu(bool enabled) | 94 | void enableMenu(bool enabled) | ||
95 | { | 95 | { | ||
96 | if (m_menu == nullptr) { | 96 | if (m_menu == nullptr) { | ||
97 | return; | 97 | return; | ||
anthonyfieroni: Remove. | |||||
98 | } | 98 | } | ||
99 | m_menu->setEnabled(enabled); | 99 | m_menu->setEnabled(enabled); | ||
anthonyfieroni: Use directly
```
delete d_func()->take(foo);
``` | |||||
100 | } | 100 | } | ||
101 | 101 | | |||
102 | void addEntry(const QString &before, const QString after, | 102 | void addEntry(const QString &before, const QString after, | ||
103 | const QString description, const QString &realBefore = QString(), | 103 | const QString description, const QString &realBefore = QString(), | ||
104 | const QString &realAfter = QString()) | 104 | const QString &realAfter = QString()) | ||
105 | { | 105 | { | ||
106 | if (m_menu == nullptr) { | 106 | if (m_menu == nullptr) { | ||
107 | return; | 107 | return; | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 143 | : KateViewBarWidget(true, view), | |||
156 | m_powerMatchCase(true), | 156 | m_powerMatchCase(true), | ||
157 | m_powerFromCursor(false), | 157 | m_powerFromCursor(false), | ||
158 | m_powerHighlightAll(false), | 158 | m_powerHighlightAll(false), | ||
159 | m_powerMode(0) | 159 | m_powerMode(0) | ||
160 | { | 160 | { | ||
161 | 161 | | |||
162 | connect(view, SIGNAL(cursorPositionChanged(KTextEditor::View*,KTextEditor::Cursor)), | 162 | connect(view, SIGNAL(cursorPositionChanged(KTextEditor::View*,KTextEditor::Cursor)), | ||
163 | this, SLOT(updateIncInitCursor())); | 163 | this, SLOT(updateIncInitCursor())); | ||
164 | connect(this, &KateSearchBar::findOrReplaceAllFinished, this, &KateSearchBar::endFindOrReplaceAll); | ||||
164 | 165 | | |||
165 | // init match attribute | 166 | // init match attribute | ||
166 | Attribute::Ptr mouseInAttribute(new Attribute()); | 167 | Attribute::Ptr mouseInAttribute(new Attribute()); | ||
167 | mouseInAttribute->setFontBold(true); | 168 | mouseInAttribute->setFontBold(true); | ||
168 | highlightMatchAttribute->setDynamicAttribute(Attribute::ActivateMouseIn, mouseInAttribute); | 169 | highlightMatchAttribute->setDynamicAttribute(Attribute::ActivateMouseIn, mouseInAttribute); | ||
169 | 170 | | |||
170 | Attribute::Ptr caretInAttribute(new Attribute()); | 171 | Attribute::Ptr caretInAttribute(new Attribute()); | ||
171 | caretInAttribute->setFontItalic(true); | 172 | caretInAttribute->setFontItalic(true); | ||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Line(s) | 511 | } else { | |||
512 | findNext(); | 513 | findNext(); | ||
513 | } | 514 | } | ||
514 | 515 | | |||
515 | if (controlDown) { | 516 | if (controlDown) { | ||
516 | emit hideMe(); | 517 | emit hideMe(); | ||
517 | } | 518 | } | ||
518 | } | 519 | } | ||
519 | 520 | | |||
520 | bool KateSearchBar::find(SearchDirection searchDirection, const QString *replacement) | 521 | bool KateSearchBar::findOrReplace(SearchDirection searchDirection, const QString *replacement) | ||
521 | { | 522 | { | ||
522 | // What to find? | 523 | // What to find? | ||
523 | if (searchPattern().isEmpty()) { | 524 | if (searchPattern().isEmpty()) { | ||
524 | return false; // == Pattern error | 525 | return false; // == Pattern error | ||
525 | } | 526 | } | ||
526 | 527 | | |||
527 | // don't let selectionChanged signal mess around in this routine | 528 | // don't let selectionChanged signal mess around in this routine | ||
528 | disconnect(m_view, SIGNAL(selectionChanged(KTextEditor::View*)), this, SLOT(updateSelectionOnly())); | 529 | disconnect(m_view, SIGNAL(selectionChanged(KTextEditor::View*)), this, SLOT(updateSelectionOnly())); | ||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Line(s) | |||||
660 | void KateSearchBar::findAll() | 661 | void KateSearchBar::findAll() | ||
661 | { | 662 | { | ||
662 | // clear highlightings of prior search&replace action | 663 | // clear highlightings of prior search&replace action | ||
663 | clearHighlights(); | 664 | clearHighlights(); | ||
664 | 665 | | |||
665 | Range inputRange = (m_view->selection() && selectionOnly()) | 666 | Range inputRange = (m_view->selection() && selectionOnly()) | ||
666 | ? m_view->selectionRange() | 667 | ? m_view->selectionRange() | ||
667 | : m_view->document()->documentRange(); | 668 | : m_view->document()->documentRange(); | ||
668 | const int occurrences = findAll(inputRange, nullptr); | | |||
669 | 669 | | |||
670 | // send passive notification to view | 670 | beginFindAll(inputRange); | ||
671 | showInfoMessage(i18ncp("short translation", "1 match found", "%1 matches found", occurrences)); | | |||
672 | | ||||
673 | indicateMatch(occurrences > 0 ? MatchFound : MatchMismatch); | | |||
674 | } | 671 | } | ||
675 | 672 | | |||
676 | void KateSearchBar::onPowerPatternChanged(const QString & /*pattern*/) | 673 | void KateSearchBar::onPowerPatternChanged(const QString & /*pattern*/) | ||
677 | { | 674 | { | ||
678 | givePatternFeedback(); | 675 | givePatternFeedback(); | ||
679 | indicateMatch(MatchNothing); | 676 | indicateMatch(MatchNothing); | ||
680 | } | 677 | } | ||
681 | 678 | | |||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | 728 | { | |||
777 | // Adjust global config | 774 | // Adjust global config | ||
778 | m_config->setSearchFlags(futureFlags); | 775 | m_config->setSearchFlags(futureFlags); | ||
779 | } | 776 | } | ||
780 | 777 | | |||
781 | void KateSearchBar::replaceNext() | 778 | void KateSearchBar::replaceNext() | ||
782 | { | 779 | { | ||
783 | const QString replacement = m_powerUi->replacement->currentText(); | 780 | const QString replacement = m_powerUi->replacement->currentText(); | ||
784 | 781 | | |||
785 | if (find(SearchForward, &replacement)) { | 782 | if (findOrReplace(SearchForward, &replacement)) { | ||
786 | // Never merge replace actions with other replace actions/user actions | 783 | // Never merge replace actions with other replace actions/user actions | ||
787 | m_view->doc()->undoManager()->undoSafePoint(); | 784 | m_view->doc()->undoManager()->undoSafePoint(); | ||
788 | 785 | | |||
789 | // Add to search history | 786 | // Add to search history | ||
790 | addCurrentTextToHistory(m_powerUi->pattern); | 787 | addCurrentTextToHistory(m_powerUi->pattern); | ||
791 | 788 | | |||
792 | // Add to replace history | 789 | // Add to replace history | ||
793 | addCurrentTextToHistory(m_powerUi->replacement); | 790 | addCurrentTextToHistory(m_powerUi->replacement); | ||
794 | } | 791 | } | ||
795 | } | 792 | } | ||
796 | 793 | | |||
797 | // replacement == NULL --> Highlight all matches | 794 | // replacement == NULL --> Only highlight all matches | ||
798 | // replacement != NULL --> Replace and highlight all matches | 795 | // replacement != NULL --> Replace and highlight all matches | ||
799 | int KateSearchBar::findAll(Range inputRange, const QString *replacement) | 796 | void KateSearchBar::beginFindOrReplaceAll(Range inputRange, const QString &replacement, bool replaceMode/* = true*/) | ||
800 | { | 797 | { | ||
801 | // don't let selectionChanged signal mess around in this routine | 798 | // don't let selectionChanged signal mess around in this routine | ||
802 | disconnect(m_view, SIGNAL(selectionChanged(KTextEditor::View*)), this, SLOT(updateSelectionOnly())); | 799 | disconnect(m_view, SIGNAL(selectionChanged(KTextEditor::View*)), this, SLOT(updateSelectionOnly())); | ||
803 | 800 | | |||
801 | // Offer Cancel button and disable not useful buttons | ||||
802 | m_powerUi->searchCancelStacked->setCurrentIndex(m_powerUi->searchCancelStacked->indexOf(m_powerUi->cancelPage)); | ||||
803 | m_powerUi->findNext->setEnabled(false); | ||||
804 | m_powerUi->findPrev->setEnabled(false); | ||||
805 | m_powerUi->replaceNext->setEnabled(false); | ||||
806 | | ||||
807 | m_inputRange = inputRange; | ||||
808 | m_workingRange = m_view->doc()->newMovingRange(m_inputRange); | ||||
809 | m_replacement = replacement; | ||||
810 | m_replaceMode = replaceMode; | ||||
811 | m_matchCounter = 0; | ||||
812 | m_cancelFindOrReplace = false; // Ensure we have a GO! | ||||
813 | | ||||
814 | findOrReplaceAll(); | ||||
815 | } | ||||
816 | | ||||
817 | void KateSearchBar::findOrReplaceAll() | ||||
818 | { | ||||
804 | const SearchOptions enabledOptions = searchOptions(SearchForward); | 819 | const SearchOptions enabledOptions = searchOptions(SearchForward); | ||
805 | 820 | | |||
806 | const bool regexMode = enabledOptions.testFlag(Regex); | 821 | const bool regexMode = enabledOptions.testFlag(Regex); | ||
807 | const bool multiLinePattern = regexMode ? KateRegExp(searchPattern()).isMultiLine() : false; | 822 | const bool multiLinePattern = regexMode ? KateRegExp(searchPattern()).isMultiLine() : false; | ||
808 | 823 | | |||
809 | std::unique_ptr<KTextEditor::MovingRange> workingRange(m_view->doc()->newMovingRange(inputRange)); | | |||
810 | int matchCounter = 0; | | |||
811 | | ||||
812 | // we highlight all ranges of a replace, up to some hard limit | 824 | // we highlight all ranges of a replace, up to some hard limit | ||
813 | // e.g. if you replace 100000 things, rendering will break down otherwise ;=) | 825 | // e.g. if you replace 100000 things, rendering will break down otherwise ;=) | ||
814 | const int maxHighlightings = 65536; | 826 | const int maxHighlightings = 65536; | ||
815 | std::vector<Range> highlightRanges; | | |||
816 | 827 | | |||
817 | // reuse match object to avoid massive moving range creation | 828 | // reuse match object to avoid massive moving range creation | ||
818 | KateMatch match(m_view->doc(), enabledOptions); | 829 | KateMatch match(m_view->doc(), enabledOptions); | ||
819 | 830 | | |||
820 | bool block = m_view->selection() && m_view->blockSelection(); | 831 | bool block = m_view->selection() && m_view->blockSelection(); | ||
821 | int line = inputRange.start().line(); | 832 | int line = m_inputRange.start().line(); | ||
833 | | ||||
834 | QTime rolex; // Watchog to suspend the work after some time | ||||
835 | rolex.start(); | ||||
836 | bool timeOut = false; | ||||
837 | bool done = false; | ||||
822 | do { | 838 | do { | ||
823 | if (block) { | 839 | if (block) { | ||
824 | workingRange.reset(m_view->doc()->newMovingRange(m_view->doc()->rangeOnLine(inputRange, line))); | 840 | m_workingRange = m_view->doc()->newMovingRange(m_view->doc()->rangeOnLine(m_inputRange, line)); | ||
825 | } | 841 | } | ||
826 | 842 | | |||
827 | for (;;) { | 843 | do { | ||
828 | match.searchText(*workingRange, searchPattern()); | 844 | match.searchText(*m_workingRange, searchPattern()); | ||
829 | if (!match.isValid()) { | 845 | if (!match.isValid()) { | ||
846 | done = true; | ||||
830 | break; | 847 | break; | ||
831 | } | 848 | } | ||
832 | bool const originalMatchEmpty = match.isEmpty(); | 849 | bool const originalMatchEmpty = match.isEmpty(); | ||
833 | 850 | | |||
834 | // Work with the match | 851 | // Work with the match | ||
835 | Range lastRange; | 852 | Range lastRange; | ||
836 | if (replacement != nullptr) { | 853 | if (m_replaceMode) { | ||
837 | if (matchCounter == 0) { | 854 | if (m_matchCounter == 0) { | ||
838 | static_cast<KTextEditor::DocumentPrivate *>(m_view->document())->startEditing(); | 855 | static_cast<KTextEditor::DocumentPrivate *>(m_view->document())->startEditing(); | ||
839 | } | 856 | } | ||
840 | 857 | | |||
841 | // Replace | 858 | // Replace | ||
842 | lastRange = match.replace(*replacement, false, ++matchCounter); | 859 | lastRange = match.replace(m_replacement, false, ++m_matchCounter); | ||
843 | } else { | 860 | } else { | ||
844 | lastRange = match.range(); | 861 | lastRange = match.range(); | ||
845 | ++matchCounter; | 862 | ++m_matchCounter; | ||
846 | } | 863 | } | ||
847 | 864 | | |||
848 | // remember ranges if limit not reached | 865 | // remember ranges if limit not reached | ||
Maybe not an issue, but you can try to cache value preventing unwanted lookup auto dd = d(this); dd->... anthonyfieroni: Maybe not an issue, but you can try to cache value preventing unwanted lookup
```
auto dd = d… | |||||
Only here or everywhere? loh.tar: Only here or everywhere?
At this particular place may that optimized by the compiler(?)
| |||||
849 | if (matchCounter < maxHighlightings) { | 866 | if (m_matchCounter < maxHighlightings) { | ||
850 | highlightRanges.push_back(lastRange); | 867 | m_highlightRanges.push_back(lastRange); | ||
851 | } else { | 868 | } else { | ||
852 | highlightRanges.clear(); | 869 | m_highlightRanges.clear(); | ||
870 | // TODO Info user that highlighting is disabled | ||||
853 | } | 871 | } | ||
854 | 872 | | |||
855 | // Continue after match | 873 | // Continue after match | ||
856 | if (lastRange.end() >= workingRange->end()) { | 874 | if (lastRange.end() >= m_workingRange->end()) { | ||
875 | done = true; | ||||
857 | break; | 876 | break; | ||
858 | } | 877 | } | ||
859 | 878 | | |||
860 | KTextEditor::DocumentCursor workingStart(m_view->doc(), lastRange.end()); | 879 | KTextEditor::DocumentCursor workingStart(m_view->doc(), lastRange.end()); | ||
880 | | ||||
861 | if (originalMatchEmpty) { | 881 | if (originalMatchEmpty) { | ||
862 | // Can happen for regex patterns like "^". | 882 | // Can happen for regex patterns like "^". | ||
863 | // If we don't advance here we will loop forever... | 883 | // If we don't advance here we will loop forever... | ||
864 | workingStart.move(1); | 884 | workingStart.move(1); | ||
865 | } else if (regexMode && !multiLinePattern && workingStart.atEndOfLine()) { | 885 | } else if (regexMode && !multiLinePattern && workingStart.atEndOfLine()) { | ||
866 | // single-line regexps might match the naked line end | 886 | // single-line regexps might match the naked line end | ||
867 | // therefore we better advance to the next line | 887 | // therefore we better advance to the next line | ||
868 | workingStart.move(1); | 888 | workingStart.move(1); | ||
869 | } | 889 | } | ||
870 | workingRange->setRange(workingStart.toCursor(), workingRange->end()); | 890 | m_workingRange->setRange(workingStart.toCursor(), m_workingRange->end()); | ||
871 | 891 | | |||
872 | // Are we done? | 892 | // Are we done? | ||
873 | if (!workingRange->toRange().isValid() || workingStart.atEndOfDocument()) { | 893 | if (!m_workingRange->toRange().isValid() || workingStart.atEndOfDocument()) { | ||
894 | done = true; | ||||
874 | break; | 895 | break; | ||
875 | } | 896 | } | ||
876 | } | | |||
877 | 897 | | |||
878 | } while (block && ++line <= inputRange.end().line()); | 898 | timeOut = rolex.elapsed() > 150; | ||
899 | | ||||
900 | } while (!m_cancelFindOrReplace && !timeOut); | ||||
879 | 901 | | |||
902 | } while (!m_cancelFindOrReplace && !timeOut && block && ++line <= m_inputRange.end().line()); | ||||
903 | | ||||
904 | if (done || m_cancelFindOrReplace) { | ||||
905 | emit findOrReplaceAllFinished(); | ||||
906 | } else if (timeOut) { | ||||
907 | QTimer::singleShot(0, this, &KateSearchBar::findOrReplaceAll); | ||||
908 | } | ||||
909 | } | ||||
910 | | ||||
911 | void KateSearchBar::endFindOrReplaceAll() | ||||
912 | { | ||||
880 | // After last match | 913 | // After last match | ||
881 | if (matchCounter > 0) { | 914 | if (m_matchCounter > 0) { | ||
882 | if (replacement != nullptr) { | 915 | if (m_replaceMode) { | ||
883 | static_cast<KTextEditor::DocumentPrivate *>(m_view->document())->finishEditing(); | 916 | static_cast<KTextEditor::DocumentPrivate *>(m_view->document())->finishEditing(); | ||
884 | } | 917 | } | ||
885 | } | 918 | } | ||
886 | 919 | | |||
887 | // Add ScrollBarMarks | 920 | // Add ScrollBarMarks | ||
888 | if (!highlightRanges.empty()) { | 921 | if (!m_highlightRanges.empty()) { | ||
889 | KTextEditor::MarkInterface* iface = qobject_cast<KTextEditor::MarkInterface*>(m_view->document()); | 922 | KTextEditor::MarkInterface* iface = qobject_cast<KTextEditor::MarkInterface*>(m_view->document()); | ||
890 | if (iface) { | 923 | if (iface) { | ||
891 | iface->setMarkDescription(KTextEditor::MarkInterface::SearchMatch, i18n("SearchHighLight")); | 924 | iface->setMarkDescription(KTextEditor::MarkInterface::SearchMatch, i18n("SearchHighLight")); | ||
892 | iface->setMarkPixmap(KTextEditor::MarkInterface::SearchMatch, QIcon().pixmap(0,0)); | 925 | iface->setMarkPixmap(KTextEditor::MarkInterface::SearchMatch, QIcon().pixmap(0,0)); | ||
893 | for (const Range &r : highlightRanges) { | 926 | for (const Range &r : m_highlightRanges) { | ||
894 | iface->addMark(r.start().line(), KTextEditor::MarkInterface::SearchMatch); | 927 | iface->addMark(r.start().line(), KTextEditor::MarkInterface::SearchMatch); | ||
895 | } | 928 | } | ||
896 | } | 929 | } | ||
897 | } | 930 | } | ||
898 | 931 | | |||
899 | // Add highlights | 932 | // Add highlights | ||
900 | if (replacement == nullptr) { | 933 | if (m_replaceMode) { | ||
901 | for (const Range &r : highlightRanges) { | 934 | for (const Range &r : qAsConst(m_highlightRanges)) { | ||
902 | highlightMatch(r); | 935 | highlightReplacement(r); | ||
903 | } | 936 | } | ||
937 | // send passive notification to view | ||||
938 | showInfoMessage(i18ncp("short translation", "1 replacement made", "%1 replacements made", m_matchCounter)); | ||||
939 | | ||||
940 | // Never merge replace actions with other replace actions/user actions | ||||
941 | m_view->doc()->undoManager()->undoSafePoint(); | ||||
942 | | ||||
904 | } else { | 943 | } else { | ||
905 | for (const Range &r : highlightRanges) { | 944 | for (const Range &r : qAsConst(m_highlightRanges)) { | ||
906 | highlightReplacement(r); | 945 | highlightMatch(r); | ||
907 | } | 946 | } | ||
947 | // send passive notification to view | ||||
948 | showInfoMessage(i18ncp("short translation", "1 match found", "%1 matches found", m_matchCounter)); | ||||
949 | // indicateMatch(m_matchCounter > 0 ? MatchFound : MatchMismatch); TODO | ||||
908 | } | 950 | } | ||
909 | 951 | | |||
910 | // restore connection | 952 | // restore connection | ||
911 | connect(m_view, SIGNAL(selectionChanged(KTextEditor::View*)), this, SLOT(updateSelectionOnly())); | 953 | connect(m_view, SIGNAL(selectionChanged(KTextEditor::View*)), this, SLOT(updateSelectionOnly())); | ||
912 | 954 | | |||
913 | return matchCounter; | 955 | // Offer Find and Replace buttons and enable again useful buttons | ||
956 | m_powerUi->searchCancelStacked->setCurrentIndex(m_powerUi->searchCancelStacked->indexOf(m_powerUi->searchPage)); | ||||
957 | m_powerUi->findNext->setEnabled(true); | ||||
958 | m_powerUi->findPrev->setEnabled(true); | ||||
959 | m_powerUi->replaceNext->setEnabled(true); | ||||
960 | | ||||
961 | // Add to search history | ||||
962 | addCurrentTextToHistory(m_powerUi->pattern); | ||||
963 | | ||||
964 | // Add to replace history | ||||
965 | addCurrentTextToHistory(m_powerUi->replacement); | ||||
914 | } | 966 | } | ||
915 | 967 | | |||
916 | void KateSearchBar::replaceAll() | 968 | void KateSearchBar::replaceAll() | ||
917 | { | 969 | { | ||
918 | // clear prior highlightings (deletes info message if present) | 970 | // clear prior highlightings (deletes info message if present) | ||
919 | clearHighlights(); | 971 | clearHighlights(); | ||
920 | 972 | | |||
921 | // What to find/replace? | 973 | // What to find/replace? | ||
922 | const QString replacement = m_powerUi->replacement->currentText(); | 974 | const QString replacement = m_powerUi->replacement->currentText(); | ||
923 | 975 | | |||
924 | // Where to replace? | 976 | // Where to replace? | ||
925 | const bool selected = m_view->selection(); | 977 | const bool selected = m_view->selection(); | ||
926 | Range inputRange = (selected && selectionOnly()) | 978 | Range inputRange = (selected && selectionOnly()) | ||
927 | ? m_view->selectionRange() | 979 | ? m_view->selectionRange() | ||
928 | : m_view->document()->documentRange(); | 980 | : m_view->document()->documentRange(); | ||
929 | 981 | | |||
930 | // Pass on the hard work | 982 | beginFindOrReplaceAll(inputRange, replacement); | ||
931 | int replacementsDone = findAll(inputRange, &replacement); | | |||
932 | | ||||
933 | // send passive notification to view | | |||
934 | showInfoMessage(i18ncp("short translation", "1 replacement made", "%1 replacements made", replacementsDone)); | | |||
935 | | ||||
936 | // Never merge replace actions with other replace actions/user actions | | |||
937 | m_view->doc()->undoManager()->undoSafePoint(); | | |||
938 | | ||||
939 | // Add to search history | | |||
940 | addCurrentTextToHistory(m_powerUi->pattern); | | |||
941 | | ||||
942 | // Add to replace history | | |||
943 | addCurrentTextToHistory(m_powerUi->replacement); | | |||
944 | } | 983 | } | ||
945 | 984 | | |||
946 | void KateSearchBar::setSearchPattern(const QString &searchPattern) | 985 | void KateSearchBar::setSearchPattern(const QString &searchPattern) | ||
947 | { | 986 | { | ||
948 | if (searchPattern == this->searchPattern()) { | 987 | if (searchPattern == this->searchPattern()) { | ||
949 | return; | 988 | return; | ||
950 | } | 989 | } | ||
951 | 990 | | |||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Line(s) | 1424 | if (create) { | |||
1388 | connect(patternLineEdit, SIGNAL(textChanged(QString)), this, SLOT(onPowerPatternChanged(QString))); | 1427 | connect(patternLineEdit, SIGNAL(textChanged(QString)), this, SLOT(onPowerPatternChanged(QString))); | ||
1389 | connect(m_powerUi->findNext, SIGNAL(clicked()), this, SLOT(findNext())); | 1428 | connect(m_powerUi->findNext, SIGNAL(clicked()), this, SLOT(findNext())); | ||
1390 | connect(m_powerUi->findPrev, SIGNAL(clicked()), this, SLOT(findPrevious())); | 1429 | connect(m_powerUi->findPrev, SIGNAL(clicked()), this, SLOT(findPrevious())); | ||
1391 | connect(m_powerUi->replaceNext, SIGNAL(clicked()), this, SLOT(replaceNext())); | 1430 | connect(m_powerUi->replaceNext, SIGNAL(clicked()), this, SLOT(replaceNext())); | ||
1392 | connect(m_powerUi->replaceAll, SIGNAL(clicked()), this, SLOT(replaceAll())); | 1431 | connect(m_powerUi->replaceAll, SIGNAL(clicked()), this, SLOT(replaceAll())); | ||
1393 | connect(m_powerUi->searchMode, SIGNAL(currentIndexChanged(int)), this, SLOT(onPowerModeChanged(int))); | 1432 | connect(m_powerUi->searchMode, SIGNAL(currentIndexChanged(int)), this, SLOT(onPowerModeChanged(int))); | ||
1394 | connect(m_powerUi->matchCase, SIGNAL(toggled(bool)), this, SLOT(onMatchCaseToggled(bool))); | 1433 | connect(m_powerUi->matchCase, SIGNAL(toggled(bool)), this, SLOT(onMatchCaseToggled(bool))); | ||
1395 | connect(m_powerUi->findAll, SIGNAL(clicked()), this, SLOT(findAll())); | 1434 | connect(m_powerUi->findAll, SIGNAL(clicked()), this, SLOT(findAll())); | ||
1435 | connect(m_powerUi->cancel, &QPushButton::clicked, this, &KateSearchBar::onPowerCancelFindOrReplace); | ||||
1396 | 1436 | | |||
1397 | // Make [return] in pattern line edit trigger <find next> action | 1437 | // Make [return] in pattern line edit trigger <find next> action | ||
1398 | connect(patternLineEdit, SIGNAL(returnPressed()), this, SLOT(onReturnPressed())); | 1438 | connect(patternLineEdit, SIGNAL(returnPressed()), this, SLOT(onReturnPressed())); | ||
1399 | connect(replacementLineEdit, SIGNAL(returnPressed()), this, SLOT(replaceNext())); | 1439 | connect(replacementLineEdit, SIGNAL(returnPressed()), this, SLOT(replaceNext())); | ||
1400 | 1440 | | |||
1401 | // Hook into line edit context menus | 1441 | // Hook into line edit context menus | ||
1402 | m_powerUi->pattern->setContextMenuPolicy(Qt::CustomContextMenu); | 1442 | m_powerUi->pattern->setContextMenuPolicy(Qt::CustomContextMenu); | ||
1403 | connect(m_powerUi->pattern, SIGNAL(customContextMenuRequested(QPoint)), this, | 1443 | connect(m_powerUi->pattern, SIGNAL(customContextMenuRequested(QPoint)), this, | ||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Line(s) | 1681 | { | |||
1643 | showExtendedContextMenu(FOR_REPLACEMENT, pos); | 1683 | showExtendedContextMenu(FOR_REPLACEMENT, pos); | ||
1644 | } | 1684 | } | ||
1645 | 1685 | | |||
1646 | void KateSearchBar::onPowerReplacmentContextMenuRequest() | 1686 | void KateSearchBar::onPowerReplacmentContextMenuRequest() | ||
1647 | { | 1687 | { | ||
1648 | onPowerReplacmentContextMenuRequest(m_powerUi->replacement->mapFromGlobal(QCursor::pos())); | 1688 | onPowerReplacmentContextMenuRequest(m_powerUi->replacement->mapFromGlobal(QCursor::pos())); | ||
1649 | } | 1689 | } | ||
1650 | 1690 | | |||
1691 | void KateSearchBar::onPowerCancelFindOrReplace() | ||||
1692 | { | ||||
1693 | m_cancelFindOrReplace = true; | ||||
1694 | } | ||||
1695 | | ||||
1651 | bool KateSearchBar::isPower() const | 1696 | bool KateSearchBar::isPower() const | ||
1652 | { | 1697 | { | ||
1653 | return m_powerUi != nullptr; | 1698 | return m_powerUi != nullptr; | ||
1654 | } | 1699 | } | ||
1655 | 1700 | | |||
1656 | void KateSearchBar::slotReadWriteChanged() | 1701 | void KateSearchBar::slotReadWriteChanged() | ||
1657 | { | 1702 | { | ||
1658 | if (!KateSearchBar::isPower()) { | 1703 | if (!KateSearchBar::isPower()) { | ||
1659 | return; | 1704 | return; | ||
1660 | } | 1705 | } | ||
1661 | 1706 | | |||
1662 | // perhaps disable/enable | 1707 | // perhaps disable/enable | ||
1663 | m_powerUi->replaceNext->setEnabled(m_view->doc()->isReadWrite() && isPatternValid()); | 1708 | m_powerUi->replaceNext->setEnabled(m_view->doc()->isReadWrite() && isPatternValid()); | ||
1664 | m_powerUi->replaceAll->setEnabled(m_view->doc()->isReadWrite() && isPatternValid()); | 1709 | m_powerUi->replaceAll->setEnabled(m_view->doc()->isReadWrite() && isPatternValid()); | ||
1665 | } | 1710 | } | ||
1666 | 1711 | | |||
Context not available. |
It's not needed, right?