Changeset View
Changeset View
Standalone View
Standalone View
plugins/grepview/grepjob.cpp
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | 38 | { | |||
---|---|---|---|---|---|
85 | file.close(); | 85 | file.close(); | ||
86 | return res; | 86 | return res; | ||
87 | } | 87 | } | ||
88 | 88 | | |||
89 | GrepJob::GrepJob( QObject* parent ) | 89 | GrepJob::GrepJob( QObject* parent ) | ||
90 | : KJob( parent ) | 90 | : KJob( parent ) | ||
91 | , m_workState(WorkIdle) | 91 | , m_workState(WorkIdle) | ||
92 | , m_fileIndex(0) | 92 | , m_fileIndex(0) | ||
93 | , m_useProjectFilesFlag(false) | | |||
94 | , m_regexpFlag(true) | | |||
95 | , m_caseSensitiveFlag(true) | | |||
96 | , m_depthValue(-1) | | |||
97 | , m_findSomething(false) | 93 | , m_findSomething(false) | ||
98 | { | 94 | { | ||
99 | setCapabilities(Killable); | 95 | setCapabilities(Killable); | ||
100 | KDevelop::ICore::self()->uiController()->registerStatus(this); | 96 | KDevelop::ICore::self()->uiController()->registerStatus(this); | ||
101 | 97 | | |||
102 | connect(this, &GrepJob::result, this, &GrepJob::testFinishState); | 98 | connect(this, &GrepJob::result, this, &GrepJob::testFinishState); | ||
103 | } | 99 | } | ||
104 | 100 | | |||
Show All 24 Lines | 123 | { | |||
129 | emit hideProgress(this); | 125 | emit hideProgress(this); | ||
130 | emit clearMessage(this); | 126 | emit clearMessage(this); | ||
131 | m_errorMessage = i18n("No files found matching the wildcard patterns"); | 127 | m_errorMessage = i18n("No files found matching the wildcard patterns"); | ||
132 | //model()->slotFailed(); | 128 | //model()->slotFailed(); | ||
133 | emitResult(); | 129 | emitResult(); | ||
134 | return; | 130 | return; | ||
135 | } | 131 | } | ||
136 | 132 | | |||
137 | if(!m_regexpFlag) | 133 | if(!m_settings.regexp) | ||
138 | { | 134 | { | ||
139 | m_patternString = QRegExp::escape(m_patternString); | 135 | m_settings.pattern = QRegExp::escape(m_settings.pattern); | ||
140 | } | 136 | } | ||
141 | 137 | | |||
142 | if(m_regexpFlag && QRegExp(m_patternString).captureCount() > 0) | 138 | if(m_settings.regexp && QRegExp(m_settings.pattern).captureCount() > 0) | ||
143 | { | 139 | { | ||
144 | m_workState = WorkIdle; | 140 | m_workState = WorkIdle; | ||
145 | emit hideProgress(this); | 141 | emit hideProgress(this); | ||
146 | emit clearMessage(this); | 142 | emit clearMessage(this); | ||
147 | m_errorMessage = i18nc("Capture is the text which is \"captured\" with () in regular expressions " | 143 | m_errorMessage = i18nc("Capture is the text which is \"captured\" with () in regular expressions " | ||
148 | "see http://doc.trolltech.com/qregexp.html#capturedTexts", | 144 | "see http://doc.trolltech.com/qregexp.html#capturedTexts", | ||
149 | "Captures are not allowed in pattern string"); | 145 | "Captures are not allowed in pattern string"); | ||
150 | emitResult(); | 146 | emitResult(); | ||
151 | return; | 147 | return; | ||
152 | } | 148 | } | ||
153 | 149 | | |||
154 | QString pattern = substitudePattern(m_templateString, m_patternString); | 150 | QString pattern = substitudePattern(m_settings.searchTemplate, m_settings.pattern); | ||
155 | m_regExp.setPattern(pattern); | 151 | m_regExp.setPattern(pattern); | ||
156 | m_regExp.setPatternSyntax(QRegExp::RegExp2); | 152 | m_regExp.setPatternSyntax(QRegExp::RegExp2); | ||
157 | m_regExp.setCaseSensitivity( m_caseSensitiveFlag ? Qt::CaseSensitive : Qt::CaseInsensitive ); | 153 | m_regExp.setCaseSensitivity( m_settings.caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive ); | ||
158 | if(pattern == QRegExp::escape(pattern)) | 154 | if(pattern == QRegExp::escape(pattern)) | ||
159 | { | 155 | { | ||
160 | // enable wildcard mode when possible | 156 | // enable wildcard mode when possible | ||
161 | // if pattern has already been escaped (raw text serch) a second escape will result in a different string anyway | 157 | // if pattern has already been escaped (raw text serch) a second escape will result in a different string anyway | ||
162 | m_regExp.setPatternSyntax(QRegExp::Wildcard); | 158 | m_regExp.setPatternSyntax(QRegExp::Wildcard); | ||
163 | } | 159 | } | ||
164 | 160 | | |||
165 | m_outputModel->setRegExp(m_regExp); | 161 | m_outputModel->setRegExp(m_regExp); | ||
166 | m_outputModel->setReplacementTemplate(m_replacementTemplateString); | 162 | m_outputModel->setReplacementTemplate(m_settings.replacementTemplate); | ||
167 | 163 | | |||
168 | 164 | | |||
169 | emit showMessage(this, i18np("Searching for <b>%2</b> in one file", | 165 | emit showMessage(this, i18np("Searching for <b>%2</b> in one file", | ||
170 | "Searching for <b>%2</b> in %1 files", | 166 | "Searching for <b>%2</b> in %1 files", | ||
171 | m_fileList.length(), | 167 | m_fileList.length(), | ||
172 | m_regExp.pattern().toHtmlEscaped())); | 168 | m_regExp.pattern().toHtmlEscaped())); | ||
173 | 169 | | |||
174 | m_workState = WorkGrep; | 170 | m_workState = WorkGrep; | ||
175 | QMetaObject::invokeMethod( this, "slotWork", Qt::QueuedConnection); | 171 | QMetaObject::invokeMethod( this, "slotWork", Qt::QueuedConnection); | ||
176 | } | 172 | } | ||
177 | 173 | | |||
178 | void GrepJob::slotWork() | 174 | void GrepJob::slotWork() | ||
179 | { | 175 | { | ||
180 | switch(m_workState) | 176 | switch(m_workState) | ||
181 | { | 177 | { | ||
182 | case WorkIdle: | 178 | case WorkIdle: | ||
183 | m_workState = WorkCollectFiles; | 179 | m_workState = WorkCollectFiles; | ||
184 | m_fileIndex = 0; | 180 | m_fileIndex = 0; | ||
185 | emit showProgress(this, 0,0,0); | 181 | emit showProgress(this, 0,0,0); | ||
186 | QMetaObject::invokeMethod(this, "slotWork", Qt::QueuedConnection); | 182 | QMetaObject::invokeMethod(this, "slotWork", Qt::QueuedConnection); | ||
187 | break; | 183 | break; | ||
188 | case WorkCollectFiles: | 184 | case WorkCollectFiles: | ||
189 | m_findThread = new GrepFindFilesThread(this, m_directoryChoice, m_depthValue, m_filesString, m_excludeString, m_useProjectFilesFlag); | 185 | m_findThread = new GrepFindFilesThread(this, m_directoryChoice, m_settings.depth, m_settings.files, m_settings.exclude, m_settings.projectFilesOnly); | ||
190 | emit showMessage(this, i18n("Collecting files...")); | 186 | emit showMessage(this, i18n("Collecting files...")); | ||
191 | connect(m_findThread.data(), &GrepFindFilesThread::finished, this, &GrepJob::slotFindFinished); | 187 | connect(m_findThread.data(), &GrepFindFilesThread::finished, this, &GrepJob::slotFindFinished); | ||
192 | m_findThread->start(); | 188 | m_findThread->start(); | ||
193 | break; | 189 | break; | ||
194 | case WorkGrep: | 190 | case WorkGrep: | ||
195 | if(m_fileIndex < m_fileList.length()) | 191 | if(m_fileIndex < m_fileList.length()) | ||
196 | { | 192 | { | ||
197 | emit showProgress(this, 0, m_fileList.length(), m_fileIndex); | 193 | emit showProgress(this, 0, m_fileList.length(), m_fileIndex); | ||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | 261 | { | |||
274 | } | 270 | } | ||
275 | } | 271 | } | ||
276 | 272 | | |||
277 | void GrepJob::setOutputModel(GrepOutputModel* model) | 273 | void GrepJob::setOutputModel(GrepOutputModel* model) | ||
278 | { | 274 | { | ||
279 | m_outputModel = model; | 275 | m_outputModel = model; | ||
280 | } | 276 | } | ||
281 | 277 | | |||
282 | void GrepJob::setTemplateString(const QString& templateString) | | |||
283 | { | | |||
284 | m_templateString = templateString; | | |||
285 | } | | |||
286 | | ||||
287 | void GrepJob::setReplacementTemplateString(const QString &replTmplString) | | |||
288 | { | | |||
289 | m_replacementTemplateString = replTmplString; | | |||
290 | } | | |||
291 | | ||||
292 | void GrepJob::setFilesString(const QString& filesString) | | |||
293 | { | | |||
294 | m_filesString = filesString; | | |||
295 | } | | |||
296 | | ||||
297 | void GrepJob::setExcludeString(const QString& excludeString) | | |||
298 | { | | |||
299 | m_excludeString = excludeString; | | |||
300 | } | | |||
301 | | ||||
302 | void GrepJob::setDirectoryChoice(const QList<QUrl>& choice) | 278 | void GrepJob::setDirectoryChoice(const QList<QUrl>& choice) | ||
303 | { | 279 | { | ||
304 | m_directoryChoice = choice; | 280 | m_directoryChoice = choice; | ||
305 | } | 281 | } | ||
306 | 282 | | |||
307 | void GrepJob::setCaseSensitive(bool caseSensitive) | 283 | void GrepJob::setSettings(const GrepJobSettings& settings) | ||
308 | { | | |||
309 | m_caseSensitiveFlag = caseSensitive; | | |||
310 | } | | |||
311 | | ||||
312 | void GrepJob::setDepth(int depth) | | |||
313 | { | 284 | { | ||
314 | m_depthValue = depth; | 285 | m_settings = settings; | ||
315 | } | | |||
316 | 286 | | |||
317 | void GrepJob::setRegexpFlag(bool regexpFlag) | 287 | setObjectName(i18n("Grep: %1", m_settings.pattern)); | ||
318 | { | | |||
319 | m_regexpFlag = regexpFlag; | | |||
320 | } | 288 | } | ||
321 | 289 | | |||
322 | void GrepJob::setProjectFilesFlag(bool projectFilesFlag) | 290 | GrepJobSettings GrepJob::settings() const | ||
323 | { | 291 | { | ||
324 | m_useProjectFilesFlag = projectFilesFlag; | 292 | return m_settings; | ||
325 | } | 293 | } | ||
326 | | ||||
327 | void GrepJob::setPatternString(const QString& patternString) | | |||
328 | { | | |||
329 | m_patternString = patternString; | | |||
330 | | ||||
331 | setObjectName(i18n("Grep: %1", m_patternString)); | | |||
332 | } | | |||
333 | |