23 #include "katesearchbar.moc"
37 #include "ui_searchbarincremental.h"
38 #include "ui_searchbarpower.h"
44 #include <QtGui/QVBoxLayout>
45 #include <QtGui/QComboBox>
46 #include <QtGui/QCheckBox>
47 #include <QtGui/QShortcut>
52 #ifdef FAST_DEBUG_ENABLE
53 # define FAST_DEBUG(x) kDebug() << x
55 # define FAST_DEBUG(x)
58 using namespace KTextEditor;
62 class AddMenuManager {
65 QVector<QString> m_insertBefore;
66 QVector<QString> m_insertAfter;
72 AddMenuManager(
QMenu * parent,
int expectedItemCount)
73 : m_insertBefore(QVector<QString>(expectedItemCount)),
74 m_insertAfter(QVector<QString>(expectedItemCount)),
77 Q_ASSERT(parent != NULL);
78 m_menu = parent->addMenu(
i18n(
"Add..."));
82 m_menu->setIcon(
KIcon(
"list-add"));
85 void enableMenu(
bool enabled) {
89 m_menu->setEnabled(enabled);
98 QAction *
const action = m_menu->addAction(before + after +
'\t' + description);
99 m_insertBefore[m_indexWalker] =
QString(realBefore.isEmpty() ? before : realBefore);
100 m_insertAfter[m_indexWalker] =
QString(realAfter.isEmpty() ? after : realAfter);
101 action->setData(
QVariant(m_indexWalker++));
102 m_actionPointers.insert(action);
105 void addSeparator() {
106 if (m_menu == NULL) {
109 m_menu->addSeparator();
113 if (!m_actionPointers.contains(action)) {
117 const int cursorPos = lineEdit->cursorPosition();
118 const int index = action->data().toUInt();
119 const QString & before = m_insertBefore[index];
120 const QString & after = m_insertAfter[index];
121 lineEdit->insert(before + after);
122 lineEdit->setCursorPosition(cursorPos + before.count());
123 lineEdit->setFocus();
135 m_layout(new QVBoxLayout()),
138 m_incInitCursor(view->cursorPosition()),
140 highlightMatchAttribute (new
Attribute()),
141 highlightReplacementAttribute (new
Attribute()),
142 m_incHighlightAll(false),
143 m_incFromCursor(true),
144 m_incMatchCase(false),
145 m_powerMatchCase(true),
146 m_powerFromCursor(false),
147 m_powerHighlightAll(false),
149 m_unitTestMode(false)
153 this, SLOT(updateIncInitCursor()));
158 highlightMatchAttribute->
setDynamicAttribute (Attribute::ActivateMouseIn, mouseInAttribute);
161 caretInAttribute->setFontItalic(
true);
162 highlightMatchAttribute->
setDynamicAttribute (Attribute::ActivateCaretIn, caretInAttribute);
168 widget->setLayout(m_layout);
169 m_layout->setMargin(0);
172 setMinimumWidth (100);
198 updateSelectionOnly();
200 this, SLOT(updateSelectionOnly()));
232 m_powerUi->replacement->setEditText(replacementPattern);
241 return m_powerUi->replacement->currentText();
250 m_powerUi->searchMode->setCurrentIndex(mode);
257 const bool found = find();
260 QComboBox *combo = m_powerUi != 0 ? m_powerUi->pattern : m_incUi->pattern;
263 addCurrentTextToHistory(combo);
273 QComboBox *combo = m_powerUi != 0 ? m_powerUi->pattern : m_incUi->pattern;
276 addCurrentTextToHistory(combo);
280 void KateSearchBar::showInfoMessage(
const QString& text)
282 delete m_infoMessage;
286 m_infoMessage->setAutoHide(3000);
287 m_infoMessage->setView(m_view);
292 void KateSearchBar::highlightMatch(
const Range & range) {
299 m_hlRanges.append(highlight);
302 void KateSearchBar::highlightReplacement(
const Range & range) {
309 m_hlRanges.append(highlight);
312 void KateSearchBar::indicateMatch(MatchResult matchResult) {
314 : m_incUi->pattern->lineEdit();
315 QPalette background(lineEdit->palette());
317 switch (matchResult) {
330 background = QPalette();
338 if (m_incUi != NULL) {
339 QPalette foreground(m_incUi->status->palette());
340 switch (matchResult) {
344 m_incUi->status->clear();
350 m_incUi->status->setText(
i18n(
"Reached top, continued from bottom"));
352 m_incUi->status->setText(
i18n(
"Reached bottom, continued from top"));
357 m_incUi->status->setText(
i18n(
"Not found"));
363 m_incUi->status->setPalette(foreground);
366 lineEdit->setPalette(background);
382 disconnect(m_view, SIGNAL(selectionChanged(
KTextEditor::View*)),
this, SLOT(updateSelectionOnly()));
383 selectRange(m_view, range);
384 connect(m_view, SIGNAL(selectionChanged(
KTextEditor::View*)),
this, SLOT(updateSelectionOnly()));
389 void KateSearchBar::onIncPatternChanged(
const QString & pattern)
397 m_incUi->next->setDisabled(pattern.isEmpty());
398 m_incUi->prev->setDisabled(pattern.isEmpty());
402 if (!pattern.isEmpty()) {
405 match.searchText(inputRange, pattern);
408 const bool wrap = !match.
isValid() && !pattern.isEmpty();
413 match.searchText(inputRange, pattern);
420 const Range selectionRange = pattern.isEmpty() ?
Range(m_incInitCursor, m_incInitCursor) :
421 match.isValid() ? match.range() :
426 this, SLOT(updateIncInitCursor()));
427 selectRange2(selectionRange);
429 this, SLOT(updateIncInitCursor()));
431 indicateMatch(matchResult);
441 m_powerUi->matchCase->setChecked(matchCase);
443 m_incUi->matchCase->setChecked(matchCase);
448 void KateSearchBar::onMatchCaseToggled(
bool ) {
453 const QString pattern = m_incUi->pattern->currentText();
454 onIncPatternChanged(pattern);
464 return isPower() ? m_powerUi->matchCase->isChecked()
465 : m_incUi->matchCase->isChecked();
470 void KateSearchBar::fixForSingleLine(
Range & range, SearchDirection searchDirection) {
471 FAST_DEBUG(
"Single-line workaround checking BEFORE" << range);
476 if (col == maxColWithNewline) {
479 if (line < maxLine) {
481 FAST_DEBUG(
"Search range fixed to " << range);
484 range = Range::invalid();
490 FAST_DEBUG(
"Ending after a newline" << range);
491 const int line = range.
end().
line();
495 FAST_DEBUG(
"Search range fixed to " << range);
498 range = Range::invalid();
502 FAST_DEBUG(
"Single-line workaround checking AFTER" << range);
507 void KateSearchBar::onReturnPressed() {
508 const Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers();
509 const bool shiftDown = (modifiers & Qt::ShiftModifier) != 0;
510 const bool controlDown = (modifiers & Qt::ControlModifier) != 0;
533 bool KateSearchBar::find(SearchDirection searchDirection,
const QString * replacement) {
540 disconnect(m_view, SIGNAL(selectionChanged(
KTextEditor::View*)),
this, SLOT(updateSelectionOnly()));
545 const Search::SearchOptions enabledOptions = searchOptions(searchDirection);
553 inputRange = selection;
581 const bool regexMode = enabledOptions.testFlag(Search::Regex);
585 if (regexMode && !multiLinePattern) {
586 fixForSingleLine(inputRange, searchDirection);
591 Range afterReplace = Range::invalid();
595 if (match.isValid() && match.range() == selection) {
597 if (replacement != 0) {
600 afterReplace = match.replace(*replacement, m_view->
blockSelection());
601 inputRange = *smartInputRange;
602 delete smartInputRange;
608 const Cursor start = (replacement != 0) ? afterReplace.end() : selection.
end();
611 const Cursor end = (replacement != 0) ? afterReplace.start() : selection.
start();
617 fixForSingleLine(inputRange, searchDirection);
625 if (m_unitTestMode && askWrap)
633 : i18n(
"Top of file reached. Continue from bottom ?");
643 if (match.isValid()) {
644 selectRange2(match.range());
651 indicateMatch(matchResult);
654 if (afterReplace.isValid()) {
655 highlightReplacement(afterReplace);
659 connect(m_view, SIGNAL(selectionChanged(
KTextEditor::View*)),
this, SLOT(updateSelectionOnly()));
675 const int occurrences =
findAll(inputRange, NULL);
678 showInfoMessage(
i18ncp(
"short translation",
"1 match found",
"%1 matches found", occurrences));
685 void KateSearchBar::onPowerPatternChanged(
const QString & ) {
686 givePatternFeedback();
692 bool KateSearchBar::isPatternValid()
const {
703 void KateSearchBar::givePatternFeedback() {
705 m_powerUi->findNext->setEnabled(isPatternValid());
706 m_powerUi->findPrev->setEnabled(isPatternValid());
707 m_powerUi->replaceNext->setEnabled(isPatternValid());
708 m_powerUi->replaceAll->setEnabled(isPatternValid());
713 void KateSearchBar::addCurrentTextToHistory(
QComboBox * combo) {
714 const QString text = combo->currentText();
715 const int index = combo->findText(text);
718 combo->removeItem(index);
720 combo->insertItem(0, text);
721 combo->setCurrentIndex(0);
727 void KateSearchBar::backupConfig(
bool ofPower) {
729 m_powerMatchCase = m_powerUi->matchCase->isChecked();
730 m_powerMode = m_powerUi->searchMode->currentIndex();
732 m_incMatchCase = m_incUi->matchCase->isChecked();
738 void KateSearchBar::sendConfig() {
740 long futureFlags = pastFlags;
742 if (m_powerUi != NULL) {
743 const bool OF_POWER =
true;
744 backupConfig(OF_POWER);
747 const long incFlagsOnly = pastFlags
752 futureFlags = incFlagsOnly
764 }
else if (m_incUi != NULL) {
765 const bool OF_INCREMENTAL =
false;
766 backupConfig(OF_INCREMENTAL);
769 const long powerFlagsOnly = pastFlags
771 | KateViewConfig::PowerFromCursor
778 futureFlags = powerFlagsOnly
791 const QString replacement = m_powerUi->replacement->currentText();
798 addCurrentTextToHistory(m_powerUi->pattern);
801 addCurrentTextToHistory(m_powerUi->replacement);
812 disconnect(m_view, SIGNAL(selectionChanged(
KTextEditor::View*)),
this, SLOT(updateSelectionOnly()));
814 const Search::SearchOptions enabledOptions = searchOptions(
SearchForward);
816 const bool regexMode = enabledOptions.testFlag(Search::Regex);
821 int matchCounter = 0;
832 if (!match.isValid()) {
835 bool const originalMatchEmpty = match.
isEmpty();
838 if (replacement != NULL) {
839 if (matchCounter == 0) {
844 const Range afterReplace = match.replace(*replacement,
false, ++matchCounter);
848 highlightRanges << afterReplace;
852 highlightRanges << match.range();
857 if (highlightRanges.last().end() >= workingRange->
end())
861 if (originalMatchEmpty) {
864 workingStart->
move(1);
865 }
else if (regexMode && !multiLinePattern && workingStart->
atEndOfLine()) {
868 workingStart->
move(1);
870 workingRange->
setRange(*workingStart, workingRange->
end());
880 }
while (block && ++line <= inputRange.
end().
line());
883 if (matchCounter > 0) {
884 if (replacement != NULL) {
889 if (replacement == NULL)
890 foreach (
const Range &r, highlightRanges) {
894 foreach (
const Range &r, highlightRanges) {
895 highlightReplacement(r);
901 connect(m_view, SIGNAL(selectionChanged(
KTextEditor::View*)),
this, SLOT(updateSelectionOnly()));
914 const QString replacement = m_powerUi->replacement->currentText();
918 const bool selected = m_view->
selection();
925 int replacementsDone=
findAll(inputRange, &replacement);
928 showInfoMessage(
i18ncp(
"short translation",
"1 replacement made",
"%1 replacements made", replacementsDone));
934 addCurrentTextToHistory(m_powerUi->pattern);
937 addCurrentTextToHistory(m_powerUi->replacement);
948 m_powerUi->pattern->setEditText(searchPattern);
950 m_incUi->pattern->setEditText(searchPattern);
956 return (m_powerUi != 0) ? m_powerUi->pattern->currentText()
957 : m_incUi->pattern->currentText();
968 m_powerUi->selectionOnly->setChecked(selectionOnly);
975 return isPower() ? m_powerUi->selectionOnly->isChecked()
981 KTextEditor::Search::SearchOptions KateSearchBar::searchOptions(SearchDirection searchDirection)
const {
985 enabledOptions |= Search::CaseInsensitive;
989 enabledOptions |= Search::Backwards;
992 if (m_powerUi != NULL) {
993 switch (m_powerUi->searchMode->currentIndex()) {
995 enabledOptions |= Search::WholeWords;
999 enabledOptions |= Search::EscapeSequences;
1003 enabledOptions |= Search::Regex;
1013 return enabledOptions;
1027 QVector<QString> KateSearchBar::getCapturePatterns(
const QString & pattern)
const {
1028 QVector<QString> capturePatterns;
1029 capturePatterns.reserve(9);
1030 QStack<ParInfo> parInfos;
1032 const int inputLen = pattern.length();
1034 bool insideClass =
false;
1035 int captureCount = 0;
1037 while (input < inputLen) {
1040 if (pattern[input].unicode() == L
']') {
1041 insideClass =
false;
1047 switch (pattern[input].unicode())
1056 curInfo.openIndex = input;
1057 curInfo.capturing = (input + 1 >= inputLen) || (pattern[input + 1].unicode() !=
'?');
1058 if (curInfo.capturing) {
1061 curInfo.captureNumber = captureCount;
1062 parInfos.push(curInfo);
1068 if (!parInfos.empty()) {
1069 ParInfo & top = parInfos.top();
1070 if (top.capturing && (top.captureNumber <= 9)) {
1071 const int start = top.openIndex + 1;
1072 const int len = input - start;
1073 if (capturePatterns.size() < top.captureNumber) {
1074 capturePatterns.resize(top.captureNumber);
1076 capturePatterns[top.captureNumber - 1] = pattern.mid(start, len);
1097 return capturePatterns;
1102 void KateSearchBar::showExtendedContextMenu(
bool forPattern,
const QPoint& pos) {
1104 QComboBox* comboBox = forPattern ? m_powerUi->pattern : m_powerUi->replacement;
1105 QMenu*
const contextMenu = comboBox->lineEdit()->createStandardContextMenu();
1107 if (contextMenu == NULL) {
1111 bool extendMenu =
false;
1112 bool regexMode =
false;
1113 switch (m_powerUi->searchMode->currentIndex()) {
1126 AddMenuManager addMenuManager(contextMenu, 37);
1128 addMenuManager.enableMenu(extendMenu);
1133 addMenuManager.addEntry(
"^",
"",
i18n(
"Beginning of line"));
1134 addMenuManager.addEntry(
"$",
"",
i18n(
"End of line"));
1135 addMenuManager.addSeparator();
1136 addMenuManager.addEntry(
".",
"",
i18n(
"Any single character (excluding line breaks)"));
1137 addMenuManager.addSeparator();
1138 addMenuManager.addEntry(
"+",
"",
i18n(
"One or more occurrences"));
1139 addMenuManager.addEntry(
"*",
"",
i18n(
"Zero or more occurrences"));
1140 addMenuManager.addEntry(
"?",
"",
i18n(
"Zero or one occurrences"));
1141 addMenuManager.addEntry(
"{a",
",b}",
i18n(
"<a> through <b> occurrences"),
"{",
",}");
1142 addMenuManager.addSeparator();
1143 addMenuManager.addEntry(
"(",
")",
i18n(
"Group, capturing"));
1144 addMenuManager.addEntry(
"|",
"",
i18n(
"Or"));
1145 addMenuManager.addEntry(
"[",
"]",
i18n(
"Set of characters"));
1146 addMenuManager.addEntry(
"[^",
"]",
i18n(
"Negative set of characters"));
1147 addMenuManager.addSeparator();
1150 addMenuManager.addEntry(
"\\0",
"",
i18n(
"Whole match reference"));
1151 addMenuManager.addSeparator();
1153 const QString pattern = m_powerUi->pattern->currentText();
1154 const QVector<QString> capturePatterns = getCapturePatterns(pattern);
1156 const int captureCount = capturePatterns.count();
1157 for (
int i = 1; i <= 9; i++) {
1159 const QString & captureDetails = (i <= captureCount)
1160 ? (
QString(
" = (") + capturePatterns[i - 1].left(30)) +
QString(
")")
1162 addMenuManager.addEntry(
"\\" + number,
"",
1163 i18n(
"Reference") +
' ' + number + captureDetails);
1166 addMenuManager.addSeparator();
1170 addMenuManager.addEntry(
"\\n",
"",
i18n(
"Line break"));
1171 addMenuManager.addEntry(
"\\t",
"",
i18n(
"Tab"));
1173 if (forPattern && regexMode) {
1174 addMenuManager.addEntry(
"\\b",
"",
i18n(
"Word boundary"));
1175 addMenuManager.addEntry(
"\\B",
"",
i18n(
"Not word boundary"));
1176 addMenuManager.addEntry(
"\\d",
"",
i18n(
"Digit"));
1177 addMenuManager.addEntry(
"\\D",
"",
i18n(
"Non-digit"));
1178 addMenuManager.addEntry(
"\\s",
"",
i18n(
"Whitespace (excluding line breaks)"));
1179 addMenuManager.addEntry(
"\\S",
"",
i18n(
"Non-whitespace (excluding line breaks)"));
1180 addMenuManager.addEntry(
"\\w",
"",
i18n(
"Word character (alphanumerics plus '_')"));
1181 addMenuManager.addEntry(
"\\W",
"",
i18n(
"Non-word character"));
1184 addMenuManager.addEntry(
"\\0???",
"",
i18n(
"Octal character 000 to 377 (2^8-1)"),
"\\0");
1185 addMenuManager.addEntry(
"\\x????",
"",
i18n(
"Hex character 0000 to FFFF (2^16-1)"),
"\\x");
1186 addMenuManager.addEntry(
"\\\\",
"",
i18n(
"Backslash"));
1188 if (forPattern && regexMode) {
1189 addMenuManager.addSeparator();
1190 addMenuManager.addEntry(
"(?:E",
")",
i18n(
"Group, non-capturing"),
"(?:");
1191 addMenuManager.addEntry(
"(?=E",
")",
i18n(
"Lookahead"),
"(?=");
1192 addMenuManager.addEntry(
"(?!E",
")",
i18n(
"Negative lookahead"),
"(?!");
1196 addMenuManager.addSeparator();
1197 addMenuManager.addEntry(
"\\L",
"",
i18n(
"Begin lowercase conversion"));
1198 addMenuManager.addEntry(
"\\U",
"",
i18n(
"Begin uppercase conversion"));
1199 addMenuManager.addEntry(
"\\E",
"",
i18n(
"End case conversion"));
1200 addMenuManager.addEntry(
"\\l",
"",
i18n(
"Lowercase first character conversion"));
1201 addMenuManager.addEntry(
"\\u",
"",
i18n(
"Uppercase first character conversion"));
1202 addMenuManager.addEntry(
"\\#[#..]",
"",
i18n(
"Replacement counter (for Replace All)"),
"\\#");
1207 QAction *
const result = contextMenu->exec(comboBox->mapToGlobal(pos));
1208 if (result != NULL) {
1209 addMenuManager.handle(result, comboBox->lineEdit());
1215 void KateSearchBar::onPowerModeChanged(
int ) {
1216 if (m_powerUi->searchMode->currentIndex() ==
MODE_REGEX) {
1217 m_powerUi->matchCase->setChecked(
true);
1223 givePatternFeedback();
1229 const bool selected = view->
selection();
1236 enabledOptions |= Search::Backwards;
1252 if (match.isValid()) {
1253 selectRange(view, match.range());
1263 if (match2.isValid()) {
1264 selectRange(view, match2.range());
1281 const bool selected = m_view->
selection();
1289 selectionOnly =
true;
1294 if (initialPattern.isNull()) {
1296 const bool fromReplace = (m_powerUi != NULL) && (m_widget->isVisible());
1298 QLineEdit *
const patternLineEdit = m_powerUi->pattern->lineEdit();
1299 Q_ASSERT(patternLineEdit != NULL);
1300 patternLineEdit->selectAll();
1301 m_powerUi->pattern->setFocus(Qt::MouseFocusReason);
1306 const bool fromIncremental = (m_incUi != NULL) && (m_widget->isVisible());
1307 if (fromIncremental) {
1308 initialPattern = m_incUi->pattern->currentText();
1313 const bool create = (m_powerUi == NULL);
1316 if (m_incUi != NULL) {
1318 const bool OF_INCREMENTAL =
false;
1319 backupConfig(OF_INCREMENTAL);
1324 m_layout->removeWidget(m_widget);
1325 m_widget->deleteLater();
1330 m_powerUi =
new Ui::PowerSearchBar;
1331 m_powerUi->setupUi(m_widget);
1332 m_layout->addWidget(m_widget);
1335 m_powerUi->pattern->setDuplicatesEnabled(
false);
1336 m_powerUi->pattern->setInsertPolicy(QComboBox::InsertAtTop);
1339 m_powerUi->replacement->setDuplicatesEnabled(
false);
1340 m_powerUi->replacement->setInsertPolicy(QComboBox::InsertAtTop);
1345 m_powerUi->mutate->setIcon(
KIcon(
"arrow-down-double"));
1346 m_powerUi->findNext->setIcon(
KIcon(
"go-down-search"));
1347 m_powerUi->findPrev->setIcon(
KIcon(
"go-up-search"));
1348 m_powerUi->findAll->setIcon(
KIcon(
"edit-find"));
1354 m_powerUi->pattern->completionObject()->setIgnoreCase(
false);
1355 m_powerUi->replacement->completionObject()->setIgnoreCase(
false);
1358 m_powerUi->selectionOnly->setChecked(selectionOnly);
1362 m_powerUi->matchCase->setChecked(m_powerMatchCase);
1363 m_powerUi->searchMode->setCurrentIndex(m_powerMode);
1367 m_powerUi->pattern->setCurrentIndex(-1);
1368 m_powerUi->replacement->setCurrentIndex(-1);
1371 QLineEdit *
const patternLineEdit = m_powerUi->pattern->lineEdit();
1372 Q_ASSERT(patternLineEdit != NULL);
1373 patternLineEdit->setText(initialPattern);
1374 patternLineEdit->selectAll();
1377 QLineEdit *
const replacementLineEdit = m_powerUi->replacement->lineEdit();
1378 Q_ASSERT(replacementLineEdit != NULL);
1379 replacementLineEdit->setText(
"");
1382 onPowerPatternChanged(initialPattern);
1383 givePatternFeedback();
1388 connect(patternLineEdit, SIGNAL(textChanged(
QString)),
this, SLOT(onPowerPatternChanged(
QString)));
1389 connect(m_powerUi->findNext, SIGNAL(clicked()),
this, SLOT(
findNext()));
1390 connect(m_powerUi->findPrev, SIGNAL(clicked()),
this, SLOT(
findPrevious()));
1391 connect(m_powerUi->replaceNext, SIGNAL(clicked()),
this, SLOT(
replaceNext()));
1392 connect(m_powerUi->replaceAll, SIGNAL(clicked()),
this, SLOT(
replaceAll()));
1393 connect(m_powerUi->searchMode, SIGNAL(currentIndexChanged(
int)),
this, SLOT(onPowerModeChanged(
int)));
1394 connect(m_powerUi->matchCase, SIGNAL(toggled(
bool)),
this, SLOT(onMatchCaseToggled(
bool)));
1395 connect(m_powerUi->findAll, SIGNAL(clicked()),
this, SLOT(
findAll()));
1398 connect(patternLineEdit, SIGNAL(returnPressed()),
this, SLOT(onReturnPressed()));
1399 connect(replacementLineEdit, SIGNAL(returnPressed()),
this, SLOT(
replaceNext()));
1402 m_powerUi->pattern->setContextMenuPolicy(Qt::CustomContextMenu);
1403 connect(m_powerUi->pattern, SIGNAL(customContextMenuRequested(
QPoint)),
this,
1404 SLOT(onPowerPatternContextMenuRequest(
QPoint)));
1405 m_powerUi->replacement->setContextMenuPolicy(Qt::CustomContextMenu);
1406 connect(m_powerUi->replacement, SIGNAL(customContextMenuRequested(
QPoint)),
this,
1407 SLOT(onPowerReplacmentContextMenuRequest(
QPoint)));
1411 if (m_widget->isVisible()) {
1412 m_powerUi->pattern->setFocus(Qt::MouseFocusReason);
1422 const bool selected = m_view->
selection();
1432 if (initialPattern.isNull()) {
1434 const bool fromIncremental = (m_incUi != NULL) && (m_widget->isVisible());
1435 if (fromIncremental) {
1436 m_incUi->pattern->lineEdit()->selectAll();
1437 m_incUi->pattern->setFocus(Qt::MouseFocusReason);
1442 const bool fromReplace = (m_powerUi != NULL) && (m_widget->isVisible());
1444 initialPattern = m_powerUi->pattern->currentText();
1449 if (initialPattern.isNull()) {
1451 initialPattern = m_view->
doc()->
getWord( cursorPosition );
1455 const bool create = (m_incUi == NULL);
1458 if (m_powerUi != NULL) {
1460 const bool OF_POWER =
true;
1461 backupConfig(OF_POWER);
1466 m_layout->removeWidget(m_widget);
1467 m_widget->deleteLater();
1472 m_incUi =
new Ui::IncrementalSearchBar;
1473 m_incUi->setupUi(m_widget);
1474 m_layout->addWidget(m_widget);
1482 m_incUi->mutate->setIcon(
KIcon(
"arrow-up-double"));
1483 m_incUi->next->setIcon(
KIcon(
"go-down-search"));
1484 m_incUi->prev->setIcon(
KIcon(
"go-up-search"));
1487 m_incUi->pattern->setMinimumWidth(12 * m_incUi->pattern->fontMetrics().height());
1490 m_incUi->status->setTextElideMode(Qt::ElideLeft);
1495 m_incUi->pattern->setDuplicatesEnabled(
false);
1496 m_incUi->pattern->setInsertPolicy(QComboBox::InsertAtTop);
1499 m_incUi->pattern->setAutoCompletion(
false);
1504 m_incUi->matchCase->setChecked(m_incMatchCase);
1508 m_incUi->pattern->setCurrentIndex(-1);
1512 disconnect(m_incUi->pattern, SIGNAL(editTextChanged(
QString)),
this, SLOT(onIncPatternChanged(
QString)));
1513 m_incUi->pattern->setEditText(initialPattern);
1514 connect(m_incUi->pattern, SIGNAL(editTextChanged(
QString)),
this, SLOT(onIncPatternChanged(
QString)));
1515 m_incUi->pattern->lineEdit()->selectAll();
1518 if (initialPattern.isEmpty()) {
1524 m_incUi->next->setDisabled(initialPattern.isEmpty());
1525 m_incUi->prev->setDisabled(initialPattern.isEmpty());
1529 connect(m_incUi->mutate, SIGNAL(clicked()),
this, SLOT(
enterPowerMode()));
1530 connect(m_incUi->pattern->lineEdit(), SIGNAL(returnPressed()),
this, SLOT(onReturnPressed()));
1531 connect(m_incUi->next, SIGNAL(clicked()),
this, SLOT(
findNext()));
1532 connect(m_incUi->prev, SIGNAL(clicked()),
this, SLOT(
findPrevious()));
1533 connect(m_incUi->matchCase, SIGNAL(toggled(
bool)),
this, SLOT(onMatchCaseToggled(
bool)));
1537 if (m_widget->isVisible()) {
1538 m_incUi->pattern->setFocus(Qt::MouseFocusReason);
1544 if (m_infoMessage) {
1545 delete m_infoMessage;
1548 if (m_hlRanges.isEmpty()) {
1551 qDeleteAll(m_hlRanges);
1562 highlightMatchAttribute->setBackground(searchColor);
1563 highlightMatchAttribute->
dynamicAttribute (Attribute::ActivateMouseIn)->setBackground(searchColor);
1564 highlightMatchAttribute->
dynamicAttribute (Attribute::ActivateCaretIn)->setBackground(searchColor);
1567 highlightReplacementAttribute->setBackground(replaceColor);
1573 if (m_incUi != NULL) {
1577 updateSelectionOnly();
1578 KateViewBarWidget::showEvent(event);
1582 void KateSearchBar::updateSelectionOnly() {
1583 if (m_powerUi == NULL) {
1588 const bool selected = m_view->
selection();
1594 m_powerUi->selectionOnly->setChecked(selectionOnly);
1598 void KateSearchBar::updateIncInitCursor() {
1599 if (m_incUi == NULL) {
1608 void KateSearchBar::onPowerPatternContextMenuRequest(
const QPoint& pos) {
1609 const bool FOR_PATTERN =
true;
1610 showExtendedContextMenu(FOR_PATTERN, pos);
1613 void KateSearchBar::onPowerPatternContextMenuRequest() {
1614 onPowerPatternContextMenuRequest(m_powerUi->pattern->mapFromGlobal(QCursor::pos()));
1618 void KateSearchBar::onPowerReplacmentContextMenuRequest(
const QPoint& pos) {
1619 const bool FOR_REPLACEMENT =
false;
1620 showExtendedContextMenu(FOR_REPLACEMENT, pos);
1623 void KateSearchBar::onPowerReplacmentContextMenuRequest() {
1624 onPowerReplacmentContextMenuRequest(m_powerUi->replacement->mapFromGlobal(QCursor::pos()));
1629 return m_powerUi != 0;
1638 m_powerUi->replaceNext->setEnabled (m_view->
doc()->
isReadWrite() && isPatternValid());
1639 m_powerUi->replaceAll->setEnabled (m_view->
doc()->
isReadWrite() && isPatternValid());
void setReplacementPattern(const QString &replacementPattern)
Set the current replacement pattern.
QScriptValue i18n(QScriptContext *context, QScriptEngine *engine)
i18n("text", arguments [optional])
void setSearchPattern(const QString &searchPattern)
Set the current search pattern.
virtual KTextEditor::MovingRange * newMovingRange(const KTextEditor::Range &range, KTextEditor::MovingRange::InsertBehaviors insertBehaviors=KTextEditor::MovingRange::DoNotExpand, KTextEditor::MovingRange::EmptyBehavior emptyBehavior=KTextEditor::MovingRange::AllowEmpty)
Create a new moving range for this document.
void selectWord(const KTextEditor::Cursor &cursor)
KateRenderer * renderer()
KTextEditor::Document * document() const
void setSelectionOnly(bool selectionOnly)
virtual bool isValid() const
const QColor & replaceHighlightColor() const
QString searchPattern() const
virtual Cursor documentEnd() const =0
const Range toRange() const
KateUndoManager * undoManager()
virtual void setRange(const Range &range)
void enterIncrementalMode()
static void adjustForeground(QPalette &, ForegroundRole newRole=NormalText, QPalette::ColorRole color=QPalette::Text, ColorSet set=View, KSharedConfigPtr=KSharedConfigPtr())
QScriptValue i18ncp(QScriptContext *context, QScriptEngine *engine)
i18ncp("context", "singular", "plural", number, arguments [optional])
virtual void setAttributeOnlyForViews(bool onlyForViews)=0
virtual const KTextEditor::Range & selectionRange() const
virtual void showEvent(QShowEvent *event)
virtual bool startEditing()=0
void removeBarWidget(KateViewBarWidget *barWidget)
Removes a widget from this viewbar.
bool atEndOfDocument() const
bool selectionOnly() const
KateRendererConfig * config() const
Configuration.
virtual bool setSelection(const KTextEditor::Range &selection)
void updateHighlightColors()
void setMatchCase(bool matchCase)
void setFontBold(bool bold=true)
void slotReadWriteChanged()
virtual KTextEditor::Cursor documentEnd() const
QStringListModel * replacementHistoryModel()
KTextEditor::Range rangeOnLine(KTextEditor::Range range, int line) const
virtual void setAttribute(Attribute::Ptr attribute)=0
virtual bool blockSelection() const
bool isMultiLine() const
States, whether the pattern matches multiple lines, even if it was repaired using repairPattern()...
KateSearchBar(bool initAsPower, KateView *view, KateViewConfig *config)
QString replacementPattern() const
virtual void setRange(const KTextEditor::Range &range)=0
Range documentRange() const
virtual bool selection() const
static int questionYesNo(QWidget *parent, const QString &text, const QString &caption=QString(), const KGuiItem &buttonYes=KStandardGuiItem::yes(), const KGuiItem &buttonNo=KStandardGuiItem::no(), const QString &dontAskAgainName=QString(), Options options=Notify)
bool onSingleLine() const
virtual void setView(View *view)=0
static void nextMatchForSelection(KateView *view, SearchDirection searchDirection)
void undoSafePoint()
Prevent latest KateUndoGroup from being merged with the next one.
KTextEditor::Cursor cursorPosition() const
void setDynamicAttribute(ActivationType type, Attribute::Ptr attribute)
QString getWord(const KTextEditor::Cursor &cursor)
static void adjustBackground(QPalette &, BackgroundRole newRole=NormalBackground, QPalette::ColorRole color=QPalette::Base, ColorSet set=View, KSharedConfigPtr=KSharedConfigPtr())
virtual bool endEditing()=0
virtual int lineLength(int line) const =0
KAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)
virtual void setZDepth(qreal zDepth)=0
const QColor & searchHighlightColor() const
virtual QString selectionText() const
bool move(int chars, WrapBehavior wrapBehavior=Wrap)
KateDocument * doc()
accessor to katedocument pointer
virtual const MovingCursor & end() const =0
virtual bool postMessage(KTextEditor::Message *message)
int maxHistorySize() const
bool setCursorPositionInternal(const KTextEditor::Cursor &position, uint tabwidth=1, bool calledExternally=false)
QStringListModel * patternHistoryModel()
void setSearchFlags(long flags)
QString number(KIO::filesize_t size)
virtual int lines() const =0
KTextEditor::Range searchText(const KTextEditor::Range &range, const QString &pattern)
void setSearchMode(SearchMode mode)
Attribute::Ptr dynamicAttribute(ActivationType type) const