Commit e5d1490b authored by Hamish Rodda's avatar Hamish Rodda

When activating a hit in the grep dialog, re-grep the line to determine the...

When activating a hit in the grep dialog, re-grep the line to determine the position of the hit and then select the hit.
parent 278a9878
......@@ -61,7 +61,7 @@ QString GrepJob::patternString() const
void GrepJob::setPatternString(const QString& patternString)
{
m_patternString = patternString;
setObjectName(i18n("Grep: %1", m_patternString));
}
......@@ -237,10 +237,13 @@ void GrepJob::start()
setTitle(patternString());
setBehaviours( KDevelop::IOutputView::AutoScroll | KDevelop::IOutputView::AllowUserClose );
setModel(new GrepOutputModel(plugin()), KDevelop::IOutputView::TakeOwnership);
GrepOutputModel* grepModel = new GrepOutputModel(plugin());
grepModel->setRegExp(pattern);
setModel(grepModel, KDevelop::IOutputView::TakeOwnership);
setDelegate(plugin()->delegate());
startOutput();
m_lineMaker = new KDevelop::ProcessLineMaker( xargsProc );
// Delete the tempfile when xargs process is destroyed
......@@ -292,7 +295,7 @@ void GrepJob::slotFinished()
{
m_lineMaker->flushBuffers();
model()->slotCompleted();
emitResult();
}
......@@ -305,7 +308,7 @@ void GrepJob::slotError(QProcess::ProcessError error)
{
proc->kill();
}
setError(UserDefinedError);
// TODO more informative error codes
switch (error) {
......@@ -328,7 +331,7 @@ void GrepJob::slotError(QProcess::ProcessError error)
setErrorText(i18n("Unknown process error."));
break;
}
emitResult();
}
......@@ -346,7 +349,7 @@ bool GrepJob::doKill()
{
foreach (KProcess* p, m_processes)
p->close();
return true;
}
......
......@@ -15,6 +15,7 @@
#include <QModelIndex>
#include <kcolorscheme.h>
#include <ktexteditor/cursor.h>
#include <ktexteditor/document.h>
#include <icore.h>
#include <idocumentcontroller.h>
......@@ -55,8 +56,28 @@ void GrepOutputModel::activate( const QModelIndex &idx )
if( !grepitem )
return;
KTextEditor::Cursor range( grepitem->m_lineNumber.toInt() - 1, 0 );
ICore::self()->documentController()->openDocument( KUrl(grepitem->m_fileName), range );
KUrl url(grepitem->m_fileName);
int line = grepitem->m_lineNumber.toInt() - 1;
KTextEditor::Range range( line, 0, line+1, 0);
// Try to find the actual text range we found during the grep
if (IDocument* doc = ICore::self()->documentController()->documentForUrl( url )) {
KTextEditor::Range currentSelection = doc->textSelection();
if (KTextEditor::Document* tdoc = doc->textDocument()) {
QString text = tdoc->text( range );
if (m_regExp.isEmpty())
m_regExp.setPattern(m_pattern);
int index = m_regExp.indexIn(text);
if (index != -1)
range = KTextEditor::Range(line, index, line, index + m_regExp.matchedLength());
}
ICore::self()->documentController()->activateDocument( doc, range );
} else {
ICore::self()->documentController()->openDocument( url, range );
}
}
QModelIndex GrepOutputModel::nextHighlightIndex( const QModelIndex& currentIndex )
......@@ -158,5 +179,10 @@ void GrepOutputModel::slotFailed()
appendRow( new QStandardItem( "Failed" ) );
}
void GrepOutputModel::setRegExp(const QString& regExp)
{
m_pattern = regExp;
}
#include "grepoutputmodel.moc"
......@@ -14,6 +14,7 @@
#define GREPOUTPUTMODEL_H
#include <QStandardItemModel>
#include <QRegExp>
#include <ioutputviewmodel.h>
class QModelIndex;
......@@ -43,6 +44,8 @@ public:
explicit GrepOutputModel( QObject *parent );
~GrepOutputModel();
void setRegExp(const QString& regExp);
void activate( const QModelIndex &idx );
QModelIndex nextHighlightIndex( const QModelIndex& currentIndex );
QModelIndex previousHighlightIndex( const QModelIndex& currentIndex );
......@@ -56,6 +59,8 @@ public Q_SLOTS:
private:
// int m_matchCount;
QString _lastfilename;
QRegExp m_regExp;
QString m_pattern;
};
#endif
......@@ -194,6 +194,10 @@ void QtDesignerDocument::setCursorPosition(const KTextEditor::Cursor&)
return;
}
void QtDesignerDocument::setTextSelection(const KTextEditor::Range &)
{
}
void QtDesignerDocument::activate(Sublime::View* view, KParts::MainWindow*)
{
m_designerPlugin->designer()->formWindowManager()->setActiveFormWindow( m_form );
......
......@@ -52,6 +52,7 @@ public:
virtual bool isActive() const;
virtual DocumentState state() const;
virtual void setCursorPosition(const KTextEditor::Cursor&);
virtual void setTextSelection(const KTextEditor::Range &range);
virtual void activate(Sublime::View*, KParts::MainWindow*);
virtual KTextEditor::Cursor cursorPosition() const;
void setDesignerPlugin(QtDesignerPlugin*);
......
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