Commit 3a82e229 authored by con's avatar con

Opening recent files wasn't opening with right encoding (Windows)

Confusion between native and internal path representation (i.e.
backslashes). File names should always be "portable" internally.

Reviewed-by: Robert Loehning
parent 8f647ca9
......@@ -159,25 +159,7 @@ FileManager::FileManager(QMainWindow *mw)
connect(core, SIGNAL(contextChanged(Core::IContext*,Core::Context)),
this, SLOT(syncWithEditor(Core::IContext*)));
const QSettings *s = core->settings();
d->m_recentFiles = s->value(QLatin1String(settingsGroupC) + QLatin1Char('/') + QLatin1String(filesKeyC), QStringList()).toStringList();
for (QStringList::iterator it = d->m_recentFiles.begin(); it != d->m_recentFiles.end(); ) {
if (QFileInfo(*it).isFile()) {
++it;
} else {
it = d->m_recentFiles.erase(it);
}
}
const QString directoryGroup = QLatin1String(directoryGroupC) + QLatin1Char('/');
const QString settingsProjectDir = s->value(directoryGroup + QLatin1String(projectDirectoryKeyC),
QString()).toString();
if (!settingsProjectDir.isEmpty() && QFileInfo(settingsProjectDir).isDir()) {
d->m_projectsDirectory = settingsProjectDir;
} else {
d->m_projectsDirectory = Utils::PathChooser::homePath();
}
d->m_useProjectsDirectory = s->value(directoryGroup + QLatin1String(useProjectDirectoryKeyC),
d->m_useProjectsDirectory).toBool();
readSettings();
}
FileManager::~FileManager()
......@@ -994,11 +976,16 @@ void FileManager::addToRecentFiles(const QString &fileName)
{
if (fileName.isEmpty())
return;
QString prettyFileName(QDir::toNativeSeparators(fileName));
d->m_recentFiles.removeAll(prettyFileName);
QString unifiedForm(fixFileName(fileName));
QMutableStringListIterator it(d->m_recentFiles);
while (it.hasNext()) {
QString recentUnifiedForm(fixFileName(it.next()));
if (unifiedForm == recentUnifiedForm)
it.remove();
}
if (d->m_recentFiles.count() > d->m_maxRecentFiles)
d->m_recentFiles.removeLast();
d->m_recentFiles.prepend(prettyFileName);
d->m_recentFiles.prepend(fileName);
}
/*!
......@@ -1011,7 +998,7 @@ QStringList FileManager::recentFiles() const
return d->m_recentFiles;
}
void FileManager::saveRecentFiles()
void FileManager::saveSettings()
{
QSettings *s = Core::ICore::instance()->settings();
s->beginGroup(QLatin1String(settingsGroupC));
......@@ -1023,6 +1010,29 @@ void FileManager::saveRecentFiles()
s->endGroup();
}
void FileManager::readSettings()
{
const QSettings *s = Core::ICore::instance()->settings();
d->m_recentFiles.clear();
QStringList recentFiles = s->value(QLatin1String(settingsGroupC) + QLatin1Char('/') + QLatin1String(filesKeyC), QStringList()).toStringList();
// clean non-existing files
foreach (const QString &file, recentFiles) {
if (QFileInfo(file).isFile())
d->m_recentFiles.append(QDir::fromNativeSeparators(file)); // from native to guard against old settings
}
const QString directoryGroup = QLatin1String(directoryGroupC) + QLatin1Char('/');
const QString settingsProjectDir = s->value(directoryGroup + QLatin1String(projectDirectoryKeyC),
QString()).toString();
if (!settingsProjectDir.isEmpty() && QFileInfo(settingsProjectDir).isDir()) {
d->m_projectsDirectory = settingsProjectDir;
} else {
d->m_projectsDirectory = Utils::PathChooser::homePath();
}
d->m_useProjectsDirectory = s->value(directoryGroup + QLatin1String(useProjectDirectoryKeyC),
d->m_useProjectsDirectory).toBool();
}
/*!
The current file is e.g. the file currently opened when an editor is active,
......
......@@ -74,8 +74,7 @@ public:
// recent files
void addToRecentFiles(const QString &fileName);
QStringList recentFiles() const;
void saveRecentFiles();
void saveSettings();
// current file
void setCurrentFile(const QString &filePath);
......@@ -133,6 +132,7 @@ private slots:
void syncWithEditor(Core::IContext *context);
private:
void readSettings();
void dump();
void addFileInfo(IFile *file);
void removeFileInfo(IFile *file);
......
......@@ -82,6 +82,7 @@
#include <QtCore/QTimer>
#include <QtCore/QtPlugin>
#include <QtCore/QUrl>
#include <QtCore/QDir>
#include <QtGui/QApplication>
#include <QtGui/QCloseEvent>
......@@ -1208,7 +1209,7 @@ void MainWindow::writeSettings()
m_settings->endGroup();
m_fileManager->saveRecentFiles();
m_fileManager->saveSettings();
m_actionManager->saveSettings(m_settings);
m_editorManager->saveSettings();
m_navigationWidget->saveSettings(m_settings);
......@@ -1271,7 +1272,7 @@ void MainWindow::aboutToShowRecentFiles()
foreach (const QString &fileName, m_fileManager->recentFiles()) {
hasRecentFiles = true;
QAction *action = aci->menu()->addAction(
Utils::withTildeHomePath(fileName));
QDir::toNativeSeparators(Utils::withTildeHomePath(fileName)));
action->setData(fileName);
connect(action, SIGNAL(triggered()), this, SLOT(openRecentFile()));
}
......
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