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