Commit b7fbc945 authored by Kåre Särs's avatar Kåre Särs

S&R: Fix searching in never saved files + multiplex using roles

The match data is now saved in column 0 with custom roles in stead of
using UserRole in many columns. The custom roles also have enums for
better readability.

BUG: 324924
parent c8fdcc23
......@@ -103,7 +103,7 @@ void SearchDiskFiles::searchSingleLineRegExp(const QString &fileName)
if (m_regExp.cap().isEmpty()) break;
// limit line length
if (line.length() > 512) line = line.left(512);
emit matchFound(fileName, i, column, line, m_regExp.matchedLength());
emit matchFound(fileName, fileName, i, column, line, m_regExp.matchedLength());
column = m_regExp.indexIn(line, column + m_regExp.cap().size());
m_matchCount++;
// NOTE: This sleep is here so that the main thread will get a chance to
......@@ -161,7 +161,7 @@ void SearchDiskFiles::searchMultiLineRegExp(const QString &fileName)
if (line == -1) {
break;
}
emit matchFound(fileName,
emit matchFound(fileName,fileName,
line,
(column - lineStart[line]),
fullDoc.mid(lineStart[line], column - lineStart[line])+tmpRegExp.cap(),
......
......@@ -51,7 +51,7 @@ public Q_SLOTS:
void cancelSearch();
Q_SIGNALS:
void matchFound(const QString &url, int line, int column,
void matchFound(const QString &url, const QString &docName, int line, int column,
const QString &lineContent, int matchLen);
void searchDone();
void searching(const QString &file);
......
This diff is collapsed.
......@@ -119,7 +119,7 @@ private Q_SLOTS:
void folderFileListChanged();
void matchFound(const QString &fileName, int line, int column,
void matchFound(const QString &url, const QString &fileName, int line, int column,
const QString &lineContent, int matchLen);
void addMatchMark(KTextEditor::Document* doc, int line, int column, int len);
......@@ -157,7 +157,7 @@ protected:
void addHeaderItem();
private:
QTreeWidgetItem *rootFileItem(const QString &url);
QTreeWidgetItem *rootFileItem(const QString &url, const QString &fName);
QStringList filterFiles(const QStringList& files) const;
QString currentWord(const KTextEditor::Document& document, const KTextEditor::Cursor& cursor) const;
......
......@@ -55,6 +55,19 @@ void ReplaceMatches::cancelReplace()
m_cancelReplace = true;
}
KTextEditor::Document *ReplaceMatches::findNamed(const QString &name)
{
QList<KTextEditor::Document*> docs = m_manager->documents();
foreach (KTextEditor::Document* it, docs) {
if ( it->documentName() == name) {
return it;
}
}
return 0;
}
void ReplaceMatches::doReplaceNextMatch()
{
if ((!m_manager) || (m_cancelReplace) || (m_tree->topLevelItemCount() != 1)) {
......@@ -74,7 +87,7 @@ void ReplaceMatches::doReplaceNextMatch()
return;
}
if (!rootItem->data(2, Qt::UserRole).toString().isEmpty()) {
if (!rootItem->data(0, ColumnRole).toString().isEmpty()) {
// this is a search as you type replace
rootItem = m_tree->topLevelItem(0);
m_cancelReplace = true; // only one document...
......@@ -86,9 +99,17 @@ void ReplaceMatches::doReplaceNextMatch()
return;
}
KTextEditor::Document *doc = m_manager->findUrl(rootItem->data(0, Qt::UserRole).toString());
if (!doc) {
doc = m_manager->openUrl(rootItem->data(0, Qt::UserRole).toString());
KTextEditor::Document *doc;
QString docUrl = rootItem->data(0, FileUrlRole).toString();
QString docName = rootItem->data(0, FileNameRole).toString();
if (docUrl.isEmpty()) {
doc = findNamed(rootItem->data(0, FileNameRole).toString());
}
else {
doc = m_manager->findUrl(docUrl);
if (!doc) {
doc = m_manager->openUrl(rootItem->data(0, FileUrlRole).toString());
}
}
if (!doc) {
......@@ -113,9 +134,9 @@ void ReplaceMatches::doReplaceNextMatch()
item = rootItem->child(i);
if (item->checkState(0) == Qt::Unchecked) continue;
line = endLine= item->data(1, Qt::UserRole).toInt();
column = item->data(2, Qt::UserRole).toInt();
matchLen = item->data(3, Qt::UserRole).toInt();
line = endLine= item->data(0, LineRole).toInt();
column = item->data(0, ColumnRole).toInt();
matchLen = item->data(0, MatchLenRole).toInt();
matchLines = doc->line(line).mid(column);
while (matchLines.size() < matchLen) {
if (endLine+1 >= doc->lines()) break;
......@@ -138,10 +159,10 @@ void ReplaceMatches::doReplaceNextMatch()
rTexts << replaceText;
replaceText.replace('\n', "\\n");
QString html = item->data(1, Qt::ToolTipRole).toString();
html += "<i><s>" + item->data(2, Qt::ToolTipRole).toString() + "</s></i> ";
QString html = item->data(0, PreMatchRole).toString();
html += "<i><s>" + item->data(0, MatchRole).toString() + "</s></i> ";
html += "<b>" + replaceText + "</b>";
html += item->data(3, Qt::ToolTipRole).toString();
html += item->data(0, PostMatchRole).toString();
item->setData(0, Qt::DisplayRole, i18n("Line: <b>%1</b>: %2",line+1, html));
endLine = line;
......
......@@ -32,11 +32,24 @@ class ReplaceMatches: public QObject
Q_OBJECT
public:
enum MatchData {
FileUrlRole = Qt::UserRole,
FileNameRole,
LineRole,
ColumnRole,
MatchLenRole,
PreMatchRole,
MatchRole,
PostMatchRole
};
ReplaceMatches(QObject *parent = 0);
void setDocumentManager(Kate::DocumentManager *manager);
void replaceChecked(QTreeWidget *tree, const QRegExp &regexp, const QString &replace);
KTextEditor::Document *findNamed(const QString &name);
public Q_SLOTS:
void cancelReplace();
......
......@@ -104,7 +104,7 @@ int SearchOpenFiles::searchSingleLineRegExp(KTextEditor::Document *doc, const QR
column = regExp.indexIn(doc->line(line));
while (column != -1) {
if (regExp.cap().isEmpty()) break;
emit matchFound(doc->url().pathOrUrl(), line, column,
emit matchFound(doc->url().pathOrUrl(), doc->documentName(), line, column,
doc->line(line), regExp.matchedLength());
column = regExp.indexIn(doc->line(line), column + regExp.cap().size());
}
......@@ -166,7 +166,7 @@ int SearchOpenFiles::searchMultiLineRegExp(KTextEditor::Document *doc, const QRe
if (line == -1) {
break;
}
emit matchFound(doc->url().pathOrUrl(),
emit matchFound(doc->url().pathOrUrl(), doc->documentName(),
line,
(column - m_lineStart[line]),
doc->line(line).left(column - m_lineStart[line])+tmpRegExp.cap(),
......
......@@ -51,7 +51,7 @@ private:
Q_SIGNALS:
void searchNextFile(int startLine);
void matchFound(const QString &url, int line, int column, const QString &lineContent, int matchLen);
void matchFound(const QString &url, const QString &fileName, int line, int column, const QString &lineContent, int matchLen);
void searchDone();
void searching(const QString &file);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment