[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kdevelop-devel
Subject:    RE: Project file list support for the grepview part
From:       "Kris Wong" <wongk () seapine ! com>
Date:       2006-10-20 13:26:19
Message-ID: D1EF2A02037CA74CBC1C6AF3F5E0F7310120C767 () ex3 ! seapine ! com
[Download RAW message or body]

>> If it is desired I can also re-enable the exclude_combo.

> Well /I/ desire it, but (as the one responsible for that particular 
> feature) I'm biased. :-) Though it does seem silly (to me) to disable
a 
> potentially useful feature. Again, any tie breakers?

You are right, it doesn't make sense to disable a potentially useful
feature.  Now that I consider it a little more I can see why a user
would want to use this.

Attached is a patch that re-enables this functionality.

Kris Wong
Seapine Software, Inc.

["grepview_with_project_support.patch" (application/octet-stream)]

diff -urN kdevelop-svn-clean/parts/grepview/grepdlg.cpp \
                kdevelop-svn-patched/parts/grepview/grepdlg.cpp
--- kdevelop-svn-clean/parts/grepview/grepdlg.cpp	2006-10-16 14:40:08.000000000 -0400
+++ kdevelop-svn-patched/parts/grepview/grepdlg.cpp	2006-10-20 08:47:50.000000000 \
-0400 @@ -169,6 +169,11 @@
     QBoxLayout *dir_checks_layout = new QHBoxLayout(5);
     layout->addLayout(dir_checks_layout, 5, 1);
 
+    use_project_box = new QCheckBox(i18n("Search files in &project"), this);
+    use_project_box->setChecked(config->readBoolEntry("search_project_files", \
false)); +    dir_checks_layout->addSpacing(10);
+    dir_checks_layout->addWidget(use_project_box);
+
     regexp_box = new QCheckBox(i18n("Regular &Expression"), this);
     regexp_box->setChecked(true);
     dir_checks_layout->addSpacing(10);
@@ -247,7 +252,9 @@
     connect( pattern_combo->lineEdit(), SIGNAL( textChanged ( const QString & ) ),
              SLOT( slotPatternChanged( const QString & ) ) );
 	connect( synch_button, SIGNAL(clicked()), this, SLOT(slotSynchDirectory()) );
+	connect( use_project_box, SIGNAL(toggled(bool)), \
SLOT(slotUseProjectToggled(bool)));  slotPatternChanged( pattern_combo->currentText() \
); +    slotUseProjectToggled( use_project_box->isChecked() );
 }
 
 // Returns the contents of a QComboBox as a QStringList
@@ -268,6 +275,7 @@
     // memorize the last patterns and paths
     config->writeEntry("LastSearchItems", qCombo2StringList(pattern_combo));
     config->writePathEntry("LastSearchPaths", qCombo2StringList(dir_combo));
+    config->writeEntry("search_project_files", use_project_box->isChecked());
 	config->writeEntry("recursive", recursive_box->isChecked());
 	config->writeEntry("case_sens", case_sens_box->isChecked());
 	config->writeEntry("new_view", keep_output_box->isChecked());
@@ -352,4 +360,22 @@
 	}
 }
 
+void GrepDialog::setEnableProjectBox(bool enable)
+{
+    if (use_project_box)
+    {
+	use_project_box->setEnabled(enable);
+	if (!enable && use_project_box->isChecked())
+	    use_project_box->setChecked(false);
+    }
+}
+
+void GrepDialog::slotUseProjectToggled(bool on)
+{
+    files_combo->setDisabled(on);
+    dir_combo->setDisabled(on);
+    recursive_box->setDisabled(on);
+    no_find_err_box->setDisabled(on);
+}
+
 #include "grepdlg.moc"
diff -urN kdevelop-svn-clean/parts/grepview/grepdlg.h \
                kdevelop-svn-patched/parts/grepview/grepdlg.h
--- kdevelop-svn-clean/parts/grepview/grepdlg.h	2006-10-16 14:40:08.000000000 -0400
+++ kdevelop-svn-patched/parts/grepview/grepdlg.h	2006-10-20 08:47:56.000000000 -0400
@@ -37,6 +37,7 @@
 	{ pattern_combo->setEditText(pattern); }
     void setDirectory(const QString &dir)
 	{ dir_combo->setEditText(dir); }
+    void setEnableProjectBox(bool enable);
 
     QString patternString() const
 	{ return pattern_combo->currentText(); }
@@ -49,6 +50,8 @@
     QString directoryString() const
 	{ return dir_combo->currentText(); }
 
+	bool useProjectFilesFlag() const
+		{ return use_project_box->isChecked(); }
 	bool regexpFlag() const
 		{ return regexp_box->isChecked(); }
 	bool recursiveFlag() const
@@ -70,6 +73,7 @@
     void slotSearchClicked();
     void slotPatternChanged( const QString &);
 	void slotSynchDirectory();
+	void slotUseProjectToggled(bool on);
 
 private:
     KLineEdit *template_edit;
@@ -77,6 +81,7 @@
     KComboBox * dir_combo;
     KURLRequester * url_requester;
 
+    QCheckBox *use_project_box;
     QCheckBox *regexp_box;
     QCheckBox *recursive_box;
     QCheckBox *no_find_err_box;
diff -urN kdevelop-svn-clean/parts/grepview/grepviewwidget.cpp \
                kdevelop-svn-patched/parts/grepview/grepviewwidget.cpp
--- kdevelop-svn-clean/parts/grepview/grepviewwidget.cpp	2006-10-16 \
                14:40:08.000000000 -0400
+++ kdevelop-svn-patched/parts/grepview/grepviewwidget.cpp	2006-10-20 \
08:48:05.000000000 -0400 @@ -152,6 +152,17 @@
 			}
 		}
 	}
+	// Determine if we have a list of project files
+	KDevProject *openProject = m_part->project();
+	if (openProject)
+	{
+		QStringList projectFiles = openProject->allFiles();
+		grepdlg->setEnableProjectBox(projectFiles.count() > 0);
+	}
+	else
+	{
+		grepdlg->setEnableProjectBox(false);
+	}
 	grepdlg->show();
 }
 
@@ -185,6 +196,18 @@
 	if (len > 0 && pattern[len-1] == '\n')
 		pattern.truncate(len-1);
 	grepdlg->setPattern( pattern );
+
+	// Determine if we have a list of project files
+	KDevProject *openProject = m_part->project();
+	if (openProject)
+	{
+		QStringList projectFiles = openProject->allFiles();
+		grepdlg->setEnableProjectBox(projectFiles.count() > 0);
+	}
+	else
+	{
+		grepdlg->setEnableProjectBox(false);
+	}
 	grepdlg->show();
 }
 
@@ -199,36 +222,71 @@
 	m_curOutput->setLastFileName("");
 	m_curOutput->setMatchCount( 0 );
 
-	QString files;
-	// waba: code below breaks on filenames containing a ',' !!!
-	QStringList filelist = QStringList::split(",", grepdlg->filesString());
-	if (!filelist.isEmpty())
-	{
-		QStringList::Iterator it(filelist.begin());
-		files = KShellProcess::quote(*it);
-		++it;
-		for (; it != filelist.end(); ++it)
-			files += " -o -name " + KShellProcess::quote(*it);
+	QString command, files, tmpFilePath;
+
+	if (grepdlg->useProjectFilesFlag())
+	{
+		KDevProject *openProject = m_part->project();
+		if (openProject)
+		{
+			QStringList projectFiles = openProject->allFiles();
+			if (!projectFiles.isEmpty())
+			{
+				tmpFilePath = openProject->projectDirectory() + QChar(QDir::separator()) + \
".grep.tmp"; +
+				m_tempFile.setName(tmpFilePath);
+				if (m_tempFile.open(IO_WriteOnly))
+				{
+					QTextStream out(&m_tempFile);
+
+					QStringList::Iterator it(projectFiles.begin());
+					for (; it != projectFiles.end(); ++it)
+					{
+						if ((*it).startsWith(QChar(QDir::separator())))
+						   out << KShellProcess::quote(QDir::cleanDirPath(openProject->projectDirectory() \
+ *it)) + "\n"; +						else
+						   out << KShellProcess::quote(QDir::cleanDirPath(openProject->projectDirectory() \
+ QChar(QDir::separator()) + *it)) + "\n"; +					}
+
+					m_tempFile.close();
+				}
+				else
+				{
+					// Ruh-roh raggy, if we can't open a temporary file, we can't proceed!
+					KMessageBox::error(this, i18n("Unable to create temp file for search."));
+					return;
+				}
+			}
+
+			command = "cat ";
+			command += tmpFilePath.replace(' ', "\\ ");
+		}
 	}
+	else
+	{
+		// waba: code below breaks on filenames containing a ',' !!!
+		QStringList filelist = QStringList::split(",", grepdlg->filesString());
+		if (!filelist.isEmpty())
+		{
+			QStringList::Iterator it(filelist.begin());
+			files = KShellProcess::quote(*it);
+			++it;
+			for (; it != filelist.end(); ++it)
+				files += " -o -name " + KShellProcess::quote(*it);
+		}
 
-	m_lastPattern = grepdlg->patternString();
-	QString pattern = grepdlg->templateString();
-	if (grepdlg->regexpFlag())
-	    pattern.replace(QRegExp("%s"), grepdlg->patternString());
-        else
-	    pattern.replace(QRegExp("%s"), escape( grepdlg->patternString() ) );
-
-	QString filepattern = "find ";
-	filepattern += KShellProcess::quote(grepdlg->directoryString());
-	if (!grepdlg->recursiveFlag())
-		filepattern += " -maxdepth 1";
-	filepattern += " \\( -name ";
-	filepattern += files;
-	filepattern += " \\) -print -follow";
-	if (grepdlg->noFindErrorsFlag())
-		filepattern += " 2>/dev/null";
+		QString filepattern = "find ";
+		filepattern += KShellProcess::quote(grepdlg->directoryString());
+		if (!grepdlg->recursiveFlag())
+			filepattern += " -maxdepth 1";
+		filepattern += " \\( -name ";
+		filepattern += files;
+		filepattern += " \\) -print -follow";
+		if (grepdlg->noFindErrorsFlag())
+			filepattern += " 2>/dev/null";
 
-	QString command = filepattern + " " ;
+		command = filepattern + " " ;
+	}
 
 	QStringList excludelist = QStringList::split(",", grepdlg->excludeString());
 	if (!excludelist.isEmpty())
@@ -239,13 +297,16 @@
 			command += "-e " + KShellProcess::quote(*it) + " ";
 	}
 
-	// quote spaces in filenames going to xargs
-	command += "| sed \"s/ /\\\\\\ /g\" ";
+	if (!grepdlg->useProjectFilesFlag())
+	{
+		// quote spaces in filenames going to xargs
+		command += "| sed \"s/ /\\\\\\ /g\" ";
+	}
 
 	command += "| xargs " ;
 
 #ifndef USE_SOLARIS
-	command += "egrep -H -n ";
+	command += "egrep -H -n -s ";
 	if (!grepdlg->caseSensitiveFlag())
 	{
 		command += "-i ";
@@ -262,6 +323,12 @@
 	command += "-e ";
 #endif
 
+	m_lastPattern = grepdlg->patternString();
+	QString pattern = grepdlg->templateString();
+	if (grepdlg->regexpFlag())
+		pattern.replace(QRegExp("%s"), grepdlg->patternString());
+	else
+		pattern.replace(QRegExp("%s"), escape( grepdlg->patternString() ) );
 	command += KShellProcess::quote(pattern);
 	m_curOutput->startJob("", command);
 
@@ -366,6 +433,9 @@
 void GrepViewWidget::killJob( int signo )
 {
 	m_curOutput->killJob( signo );
+
+	if (!m_tempFile.name().isEmpty() && m_tempFile.exists())
+		m_tempFile.remove();
 }
 
 bool GrepViewWidget::isRunning( ) const
@@ -385,6 +455,9 @@
 void GrepViewWidget::slotSearchProcessExited( )
 {
 	m_part->core()->running(m_part, false);
+
+	if (!m_tempFile.name().isEmpty() && m_tempFile.exists())
+		m_tempFile.remove();
 }
 
 void GrepViewProcessWidget::childFinished( bool normal, int status )
diff -urN kdevelop-svn-clean/parts/grepview/grepviewwidget.h \
                kdevelop-svn-patched/parts/grepview/grepviewwidget.h
--- kdevelop-svn-clean/parts/grepview/grepviewwidget.h	2006-10-16 14:40:08.000000000 \
                -0400
+++ kdevelop-svn-patched/parts/grepview/grepviewwidget.h	2006-10-20 \
08:48:10.000000000 -0400 @@ -14,6 +14,7 @@
 
 #include "processwidget.h"
 #include <qwidget.h>
+#include <qfile.h>
 
 class GrepDialog;
 class GrepViewPart;
@@ -102,6 +103,7 @@
 	GrepViewPart *m_part;
 	QToolButton* m_closeButton;
 	QString m_lastPattern;
+	QFile m_tempFile;
 };
 
 #endif



_______________________________________________
KDevelop-devel mailing list
KDevelop-devel@barney.cs.uni-potsdam.de
https://barney.cs.uni-potsdam.de/mailman/listinfo/kdevelop-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic