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

List:       kde-commits
Subject:    =?utf-8?q?=5Bkile=5D_src=3A_Correct_a_few_problems_related_to_th?=
From:       Michel Ludwig <michel.ludwig () kdemail ! net>
Date:       2011-04-30 17:24:24
Message-ID: 20110430172424.F38D0A60A4 () git ! kde ! org
[Download RAW message or body]

Git commit 83e1dc1f7419f5aa378337c6f66520b776cec57e by Michel Ludwig.
Committed on 30/04/2011 at 19:18.
Pushed by mludwig into branch 'master'.

Correct a few problems related to the ManageCompletionFilesDialog.

These problems were introduced while rewriting the patch sent by Libor Bukata.
Thanks to Libor for pointing this out!

M  +2    -2    src/kiledocmanager.cpp     
M  +16   -11   src/kilelistselector.cpp     
M  +3    -1    src/kilelistselector.h     
M  +3    -3    src/widgets/codecompletionconfigwidget.cpp     

http://commits.kde.org/kile/83e1dc1f7419f5aa378337c6f66520b776cec57e

diff --git a/src/kiledocmanager.cpp b/src/kiledocmanager.cpp
index aa4aaa9..9614139 100644
--- a/src/kiledocmanager.cpp
+++ b/src/kiledocmanager.cpp
@@ -2150,7 +2150,7 @@ QList<KileProjectItem*> Manager::selectProjectFileItems(const \
QString &label)  return QList<KileProjectItem*>();
 	}
 
-	QStringList filelist, selectedfiles;
+	QStringList filelist;
 	QMap<QString,KileProjectItem *> map;
 
 	QList<KileProjectItem*> list = project->items();
@@ -2166,7 +2166,7 @@ QList<KileProjectItem*> Manager::selectProjectFileItems(const \
QString &label)  KileListSelectorMultiple *dlg  = new \
KileListSelectorMultiple(filelist, i18n("Project Files"), label, m_ki->mainWindow()); \
if(dlg->exec()) {  if(dlg->currentItem() >= 0) {
-			selectedfiles = dlg->selected();
+			QStringList selectedfiles = dlg->selected();
 			for(QStringList::Iterator it = selectedfiles.begin(); it != selectedfiles.end(); \
++it ){  if(map.contains(*it)) {
 					itemsList.append(map[(*it)]);
diff --git a/src/kilelistselector.cpp b/src/kilelistselector.cpp
index b50b52c..211e37a 100644
--- a/src/kilelistselector.cpp
+++ b/src/kilelistselector.cpp
@@ -157,12 +157,6 @@ ManageCompletionFilesDialog::ManageCompletionFilesDialog(const \
QString& caption,  connect(this, SIGNAL(user1Clicked()), this, \
SLOT(addCustomCompletionFiles()));  connect(this, SIGNAL(user2Clicked()), this, \
SLOT(openLocalCompletionDirectoryInFileManager()));  
-	// Create local path if it doesn't exist.
-	QDir workPath(m_localCompletionDirectory);
-	if (!workPath.isReadable()) {
-		workPath.mkpath(m_localCompletionDirectory);
-	}
-
 	fillTreeView();
 	setMainWidget(m_listView);
 }
@@ -172,6 +166,8 @@ ManageCompletionFilesDialog::~ManageCompletionFilesDialog()
 }
 
 void ManageCompletionFilesDialog::fillTreeView() {
+	// we want to keep selected items still selected after refreshing
+	QSet<QString> previouslySelectedItems = selected();
 	QStringList list = \
KileCodeCompletion::Manager::getAllCwlFiles(m_localCompletionDirectory, \
m_globalCompletionDirectory).uniqueKeys();  qSort(list);
 	m_listView->clear();
@@ -180,11 +176,11 @@ void ManageCompletionFilesDialog::fillTreeView() {
 		QString expectedGlobalPath = m_globalCompletionDirectory + "/" + filename;
 		if (QFileInfo(expectedLocalPath).exists() && \
QFileInfo(expectedLocalPath).isReadable()) {  QTreeWidgetItem* item = new \
                QTreeWidgetItem(m_listView, QStringList() << filename << \
                i18n("yes"));
-			item->setCheckState(2, Qt::Unchecked);
+			item->setCheckState(2, previouslySelectedItems.contains(filename) ? Qt::Checked : \
Qt::Unchecked);  }
 		else if (QFileInfo(expectedGlobalPath).exists() && \
QFileInfo(expectedGlobalPath).isReadable()) {  QTreeWidgetItem* item = new \
                QTreeWidgetItem(m_listView, QStringList() << filename << i18n("no"));
-			item->setCheckState(2, Qt::Unchecked);
+			item->setCheckState(2, previouslySelectedItems.contains(filename) ? Qt::Checked : \
Qt::Unchecked);  }
 		else {
 			KILE_DEBUG() << "Cannot load file" << filename << "!";
@@ -200,6 +196,15 @@ void ManageCompletionFilesDialog::addCustomCompletionFiles()
 	bool someFileAdded = false;
 	QStringList files = KFileDialog::getOpenFileNames(KUrl(), i18n("*.cwl|Completion \
files (*.cwl)"), this, i18n("Select Completion Files to Install Locally"));  
+	if(files.isEmpty()) {
+		return;
+	}
+	// Create local path if it doesn't exist or has been deleted in the mean time
+	QDir workPath(m_localCompletionDirectory);
+	if (!workPath.isReadable()) {
+		workPath.mkpath(m_localCompletionDirectory);
+	}
+
 	foreach (QString file, files) {
 		QFileInfo fileInf(file);
 		QFileInfo localFile(m_localCompletionDirectory + "/" + fileInf.fileName());
@@ -252,13 +257,13 @@ void \
ManageCompletionFilesDialog::openLocalCompletionDirectoryInFileManager()  new \
KRun(KUrl(m_localCompletionDirectory), QApplication::activeWindow());  }
 
-const QStringList ManageCompletionFilesDialog::selected() const
+const QSet<QString> ManageCompletionFilesDialog::selected() const
 {
-	QStringList checked_files;
+	QSet<QString> checked_files;
 	for (int i = 0; i < m_listView->topLevelItemCount(); ++i) {
 		QTreeWidgetItem* item = m_listView->topLevelItem(i);
 		if (item->checkState(2) == Qt::Checked) {
-			checked_files.push_back(item->text(0));
+			checked_files.insert(item->text(0));
 		}
 	}
 
diff --git a/src/kilelistselector.h b/src/kilelistselector.h
index cefb066..5d2b7fd 100644
--- a/src/kilelistselector.h
+++ b/src/kilelistselector.h
@@ -16,6 +16,8 @@
 #ifndef KILELISTSELECTOR_H
 #define KILELISTSELECTOR_H
 
+#include <QSet>
+
 #include <KDialog>
 
 class QTreeWidget;
@@ -63,7 +65,7 @@ class ManageCompletionFilesDialog : public KDialog
 		                            const QString &localCompletionDir, const QString \
&globalCompletionDir, QWidget* parent = NULL, const char *name = NULL);  \
~ManageCompletionFilesDialog();  
-		const QStringList selected() const;
+		const QSet<QString> selected() const;
 
 	protected Q_SLOTS:
 		void addCustomCompletionFiles();
diff --git a/src/widgets/codecompletionconfigwidget.cpp \
b/src/widgets/codecompletionconfigwidget.cpp index 6c91fe4..8f3d13a 100644
--- a/src/widgets/codecompletionconfigwidget.cpp
+++ b/src/widgets/codecompletionconfigwidget.cpp
@@ -325,10 +325,10 @@ void CodeCompletionConfigWidget::addClicked()
 	ManageCompletionFilesDialog dlg(i18n("Completion Files"), localPath, globalPath, \
this);  
 	if (dlg.exec()) {
-		QStringList filenames = dlg.selected();
-		if (!filenames.empty()) {
+		QSet<QString> filenames = dlg.selected();
+		if (!filenames.isEmpty()) {
 			QTreeWidget *listview = getListview(m_tabWidget->currentWidget());     // get \
                current page
-			for (QStringList::ConstIterator it = filenames.constBegin(); it != \
filenames.constEnd(); ++it) { +			for (QSet<QString>::ConstIterator it = \
filenames.constBegin(); it != filenames.constEnd(); ++it) {  QString filename = *it;
 				// Reload map of files.
 				QMap<QString, QString> filemap = \
KileCodeCompletion::Manager::getAllCwlFiles(localPath, globalPath);


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

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