Commit 21c0cdee authored by hjk's avatar hjk
Browse files

Core::Filemanager: make some methods static



This follows suit to the ICore changes.

Change-Id: Iba2de1b1e3f2574fd1459892eae702e6af1cc7dc
Reviewed-by: default avatarDaniel Teske <daniel.teske@nokia.com>
parent 828139a7
...@@ -641,7 +641,7 @@ bool BazaarPlugin::submitEditorAboutToClose(VcsBase::VcsBaseSubmitEditor *submit ...@@ -641,7 +641,7 @@ bool BazaarPlugin::submitEditorAboutToClose(VcsBase::VcsBaseSubmitEditor *submit
QStringList files = commitEditor->checkedFiles(); QStringList files = commitEditor->checkedFiles();
if (!files.empty()) { if (!files.empty()) {
//save the commit message //save the commit message
if (!Core::ICore::fileManager()->saveFile(editorFile)) if (!Core::FileManager::saveFile(editorFile))
return false; return false;
//rewrite entries of the form 'file => newfile' to 'newfile' because //rewrite entries of the form 'file => newfile' to 'newfile' because
......
...@@ -266,7 +266,7 @@ void ShortcutSettings::defaultAction() ...@@ -266,7 +266,7 @@ void ShortcutSettings::defaultAction()
void ShortcutSettings::exportAction() void ShortcutSettings::exportAction()
{ {
QString fileName = FileManager::instance()->getSaveFileNameWithExtension( QString fileName = FileManager::getSaveFileNameWithExtension(
tr("Export Keyboard Mapping Scheme"), tr("Export Keyboard Mapping Scheme"),
ICore::resourcePath() + QLatin1String("/schemes/"), ICore::resourcePath() + QLatin1String("/schemes/"),
tr("Keyboard Mapping Scheme (*.kms)")); tr("Keyboard Mapping Scheme (*.kms)"));
......
...@@ -536,7 +536,7 @@ void EditorManager::removeEditor(IEditor *editor) ...@@ -536,7 +536,7 @@ void EditorManager::removeEditor(IEditor *editor)
bool isDuplicate = d->m_editorModel->isDuplicate(editor); bool isDuplicate = d->m_editorModel->isDuplicate(editor);
d->m_editorModel->removeEditor(editor); d->m_editorModel->removeEditor(editor);
if (!isDuplicate) if (!isDuplicate)
FileManager::instance()->removeFile(editor->file()); FileManager::removeFile(editor->file());
ICore::removeContextObject(editor); ICore::removeContextObject(editor);
} }
...@@ -870,8 +870,7 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask ...@@ -870,8 +870,7 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
//ask whether to save modified files //ask whether to save modified files
if (askAboutModifiedEditors) { if (askAboutModifiedEditors) {
bool cancelled = false; bool cancelled = false;
QList<IFile*> list = ICore::fileManager()-> QList<IFile*> list = FileManager::saveModifiedFiles(filesForEditors(acceptedEditors), &cancelled);
saveModifiedFiles(filesForEditors(acceptedEditors), &cancelled);
if (cancelled) if (cancelled)
return false; return false;
if (!list.isEmpty()) { if (!list.isEmpty()) {
...@@ -1206,10 +1205,9 @@ void EditorManager::addEditor(IEditor *editor, bool isDuplicate) ...@@ -1206,10 +1205,9 @@ void EditorManager::addEditor(IEditor *editor, bool isDuplicate)
if (!isDuplicate) { if (!isDuplicate) {
const bool isTemporary = editor->isTemporary(); const bool isTemporary = editor->isTemporary();
const bool addWatcher = !isTemporary; const bool addWatcher = !isTemporary;
ICore::fileManager()->addFile(editor->file(), addWatcher); FileManager::addFile(editor->file(), addWatcher);
if (!isTemporary) if (!isTemporary)
ICore::fileManager()->addToRecentFiles(editor->file()->fileName(), FileManager::addToRecentFiles(editor->file()->fileName(), editor->id());
editor->id());
} }
emit editorOpened(editor); emit editorOpened(editor);
} }
...@@ -1367,8 +1365,7 @@ QStringList EditorManager::getOpenFileNames() const ...@@ -1367,8 +1365,7 @@ QStringList EditorManager::getOpenFileNames() const
{ {
QString selectedFilter; QString selectedFilter;
const QString &fileFilters = ICore::mimeDatabase()->allFiltersString(&selectedFilter); const QString &fileFilters = ICore::mimeDatabase()->allFiltersString(&selectedFilter);
return ICore::fileManager()->getOpenFileNames(fileFilters, return FileManager::getOpenFileNames(fileFilters, QString(), &selectedFilter);
QString(), &selectedFilter);
} }
...@@ -1485,7 +1482,7 @@ bool EditorManager::saveFile(IFile *fileParam) ...@@ -1485,7 +1482,7 @@ bool EditorManager::saveFile(IFile *fileParam)
bool isReadOnly; bool isReadOnly;
// try saving, no matter what isReadOnly tells us // try saving, no matter what isReadOnly tells us
success = ICore::fileManager()->saveFile(file, QString(), &isReadOnly); success = FileManager::saveFile(file, QString(), &isReadOnly);
if (!success && isReadOnly) { if (!success && isReadOnly) {
MakeWritableResult answer = MakeWritableResult answer =
...@@ -1497,7 +1494,7 @@ bool EditorManager::saveFile(IFile *fileParam) ...@@ -1497,7 +1494,7 @@ bool EditorManager::saveFile(IFile *fileParam)
file->checkPermissions(); file->checkPermissions();
success = ICore::fileManager()->saveFile(file); success = FileManager::saveFile(file);
} }
if (success) { if (success) {
...@@ -1571,7 +1568,7 @@ bool EditorManager::saveFileAs(IFile *fileParam) ...@@ -1571,7 +1568,7 @@ bool EditorManager::saveFileAs(IFile *fileParam)
QString selectedFilter = QString selectedFilter =
ICore::mimeDatabase()->findByFile(QFileInfo(file->fileName())).filterString(); ICore::mimeDatabase()->findByFile(QFileInfo(file->fileName())).filterString();
const QString &absoluteFilePath = const QString &absoluteFilePath =
ICore::fileManager()->getSaveAsFileName(file, filter, &selectedFilter); FileManager::getSaveAsFileName(file, filter, &selectedFilter);
if (absoluteFilePath.isEmpty()) if (absoluteFilePath.isEmpty())
return false; return false;
...@@ -1584,7 +1581,7 @@ bool EditorManager::saveFileAs(IFile *fileParam) ...@@ -1584,7 +1581,7 @@ bool EditorManager::saveFileAs(IFile *fileParam)
} }
} }
const bool success = ICore::fileManager()->saveFile(file, absoluteFilePath); const bool success = FileManager::saveFile(file, absoluteFilePath);
file->checkPermissions(); file->checkPermissions();
// @todo: There is an issue to be treated here. The new file might be of a different mime // @todo: There is an issue to be treated here. The new file might be of a different mime
...@@ -1614,7 +1611,7 @@ void EditorManager::addFileToRecentFiles(IFile *file) ...@@ -1614,7 +1611,7 @@ void EditorManager::addFileToRecentFiles(IFile *file)
} }
} }
if (!isTemporary) if (!isTemporary)
ICore::fileManager()->addToRecentFiles(file->fileName(), editorId); FileManager::addToRecentFiles(file->fileName(), editorId);
} }
void EditorManager::gotoNextDocHistory() void EditorManager::gotoNextDocHistory()
......
...@@ -603,12 +603,12 @@ void ExternalToolRunner::run() ...@@ -603,12 +603,12 @@ void ExternalToolRunner::run()
if (IEditor *editor = EditorManager::instance()->currentEditor()) { if (IEditor *editor = EditorManager::instance()->currentEditor()) {
m_expectedFileName = editor->file()->fileName(); m_expectedFileName = editor->file()->fileName();
bool cancelled = false; bool cancelled = false;
FileManager::instance()->saveModifiedFiles(QList<IFile *>() << editor->file(), &cancelled); FileManager::saveModifiedFiles(QList<IFile *>() << editor->file(), &cancelled);
if (cancelled) { if (cancelled) {
deleteLater(); deleteLater();
return; return;
} }
FileManager::instance()->expectFileChange(m_expectedFileName); FileManager::expectFileChange(m_expectedFileName);
} }
} }
m_process = new Utils::QtcProcess(this); m_process = new Utils::QtcProcess(this);
...@@ -641,7 +641,7 @@ void ExternalToolRunner::finished(int exitCode, QProcess::ExitStatus status) ...@@ -641,7 +641,7 @@ void ExternalToolRunner::finished(int exitCode, QProcess::ExitStatus status)
emit ExternalToolManager::instance()->replaceSelectionRequested(m_processOutput); emit ExternalToolManager::instance()->replaceSelectionRequested(m_processOutput);
} }
if (m_tool->modifiesCurrentDocument()) { if (m_tool->modifiesCurrentDocument()) {
FileManager::instance()->unexpectFileChange(m_expectedFileName); FileManager::unexpectFileChange(m_expectedFileName);
} }
} }
ICore::messageManager()->printToOutputPane( ICore::messageManager()->printToOutputPane(
...@@ -651,9 +651,8 @@ void ExternalToolRunner::finished(int exitCode, QProcess::ExitStatus status) ...@@ -651,9 +651,8 @@ void ExternalToolRunner::finished(int exitCode, QProcess::ExitStatus status)
void ExternalToolRunner::error(QProcess::ProcessError error) void ExternalToolRunner::error(QProcess::ProcessError error)
{ {
if (m_tool->modifiesCurrentDocument()) { if (m_tool->modifiesCurrentDocument())
FileManager::instance()->unexpectFileChange(m_expectedFileName); FileManager::unexpectFileChange(m_expectedFileName);
}
// TODO inform about errors // TODO inform about errors
Q_UNUSED(error); Q_UNUSED(error);
deleteLater(); deleteLater();
......
This diff is collapsed.
...@@ -48,15 +48,10 @@ QT_END_NAMESPACE ...@@ -48,15 +48,10 @@ QT_END_NAMESPACE
namespace Core { namespace Core {
class ICore;
class IContext; class IContext;
class IFile; class IFile;
class IVersionControl; class IVersionControl;
namespace Internal {
struct FileManagerPrivate;
}
class CORE_EXPORT FileManager : public QObject class CORE_EXPORT FileManager : public QObject
{ {
Q_OBJECT Q_OBJECT
...@@ -74,44 +69,44 @@ public: ...@@ -74,44 +69,44 @@ public:
static FileManager *instance(); static FileManager *instance();
// file pool to monitor // file pool to monitor
void addFiles(const QList<IFile *> &files, bool addWatcher = true); static void addFiles(const QList<IFile *> &files, bool addWatcher = true);
void addFile(IFile *file, bool addWatcher = true); static void addFile(IFile *file, bool addWatcher = true);
bool removeFile(IFile *file); static bool removeFile(IFile *file);
QList<IFile *> modifiedFiles() const; static QList<IFile *> modifiedFiles();
void renamedFile(const QString &from, const QString &to); static void renamedFile(const QString &from, const QString &to);
void expectFileChange(const QString &fileName); static void expectFileChange(const QString &fileName);
void unexpectFileChange(const QString &fileName); static void unexpectFileChange(const QString &fileName);
// recent files // recent files
void addToRecentFiles(const QString &fileName, const Id &editorId = Id()); static void addToRecentFiles(const QString &fileName, const Id &editorId = Id());
Q_SLOT void clearRecentFiles(); Q_SLOT void clearRecentFiles();
QList<RecentFile> recentFiles() const; static QList<RecentFile> recentFiles();
void saveSettings(); static void saveSettings();
// current file // current file
void setCurrentFile(const QString &filePath); static void setCurrentFile(const QString &filePath);
QString currentFile() const; static QString currentFile();
// helper methods // helper methods
static QString fixFileName(const QString &fileName, FixMode fixmode); static QString fixFileName(const QString &fileName, FixMode fixmode);
bool saveFile(IFile *file, const QString &fileName = QString(), bool *isReadOnly = 0); static bool saveFile(IFile *file, const QString &fileName = QString(), bool *isReadOnly = 0);
QStringList getOpenFileNames(const QString &filters, static QStringList getOpenFileNames(const QString &filters,
const QString path = QString(), const QString path = QString(),
QString *selectedFilter = 0); QString *selectedFilter = 0);
QString getSaveFileName(const QString &title, const QString &pathIn, static QString getSaveFileName(const QString &title, const QString &pathIn,
const QString &filter = QString(), QString *selectedFilter = 0); const QString &filter = QString(), QString *selectedFilter = 0);
QString getSaveFileNameWithExtension(const QString &title, const QString &pathIn, static QString getSaveFileNameWithExtension(const QString &title, const QString &pathIn,
const QString &filter); const QString &filter);
QString getSaveAsFileName(IFile *file, const QString &filter = QString(), static QString getSaveAsFileName(IFile *file, const QString &filter = QString(),
QString *selectedFilter = 0); QString *selectedFilter = 0);
QList<IFile *> saveModifiedFilesSilently(const QList<IFile *> &files, bool *cancelled = 0); static QList<IFile *> saveModifiedFilesSilently(const QList<IFile *> &files, bool *cancelled = 0);
QList<IFile *> saveModifiedFiles(const QList<IFile *> &files, static QList<IFile *> saveModifiedFiles(const QList<IFile *> &files,
bool *cancelled = 0, bool *cancelled = 0,
const QString &message = QString(), const QString &message = QString(),
const QString &alwaysSaveMessage = QString(), const QString &alwaysSaveMessage = QString(),
...@@ -126,25 +121,27 @@ public: ...@@ -126,25 +121,27 @@ public:
QWidget *parent, QWidget *parent,
bool displaySaveAsButton = false); bool displaySaveAsButton = false);
QString fileDialogLastVisitedDirectory() const; static QString fileDialogLastVisitedDirectory();
void setFileDialogLastVisitedDirectory(const QString &); static void setFileDialogLastVisitedDirectory(const QString &);
QString fileDialogInitialDirectory() const; static QString fileDialogInitialDirectory();
bool useProjectsDirectory() const; static bool useProjectsDirectory();
void setUseProjectsDirectory(bool); static void setUseProjectsDirectory(bool);
QString projectsDirectory() const; static QString projectsDirectory();
void setProjectsDirectory(const QString &); static void setProjectsDirectory(const QString &);
static void populateOpenWithMenu(QMenu *menu, const QString &fileName); static void populateOpenWithMenu(QMenu *menu, const QString &fileName);
public slots:
/* Used to notify e.g. the code model to update the given files. Does *not* /* Used to notify e.g. the code model to update the given files. Does *not*
lead to any editors to reload or any other editor manager actions. */ lead to any editors to reload or any other editor manager actions. */
void notifyFilesChangedInternally(const QStringList &files); static void notifyFilesChangedInternally(const QStringList &files);
void executeOpenWithMenuAction(QAction *action); static void executeOpenWithMenuAction(QAction *action);
public slots:
void slotExecuteOpenWithMenuAction(QAction *action);
signals: signals:
void currentFileChanged(const QString &filePath); void currentFileChanged(const QString &filePath);
...@@ -159,23 +156,6 @@ private slots: ...@@ -159,23 +156,6 @@ private slots:
void changedFile(const QString &file); void changedFile(const QString &file);
void mainWindowActivated(); void mainWindowActivated();
void syncWithEditor(Core::IContext *context); void syncWithEditor(Core::IContext *context);
private:
void readSettings();
void dump();
void addFileInfo(IFile *file);
void addFileInfo(const QString &fileName, IFile *file, bool isLink);
void removeFileInfo(IFile *file);
void updateExpectedState(const QString &fileName);
QList<IFile *> saveModifiedFiles(const QList<IFile *> &files,
bool *cancelled, bool silently,
const QString &message,
const QString &alwaysSaveMessage = QString(),
bool *alwaysSave = 0);
Internal::FileManagerPrivate *d;
}; };
/*! The FileChangeBlocker blocks all change notifications to all IFile * that /*! The FileChangeBlocker blocks all change notifications to all IFile * that
......
...@@ -94,7 +94,7 @@ public: ...@@ -94,7 +94,7 @@ public:
QWidget *parent = 0); QWidget *parent = 0);
static ActionManager *actionManager(); static ActionManager *actionManager();
static FileManager *fileManager(); static QT_DEPRECATED FileManager *fileManager(); // Use FileManager::... directly.
static MessageManager *messageManager(); static MessageManager *messageManager();
static EditorManager *editorManager(); static EditorManager *editorManager();
static ProgressManager *progressManager(); static ProgressManager *progressManager();
......
...@@ -138,7 +138,6 @@ MainWindow::MainWindow() : ...@@ -138,7 +138,6 @@ MainWindow::MainWindow() :
m_actionManager(new ActionManagerPrivate(this)), m_actionManager(new ActionManagerPrivate(this)),
m_editorManager(0), m_editorManager(0),
m_externalToolManager(0), m_externalToolManager(0),
m_fileManager(new FileManager(this)),
m_progressManager(new ProgressManagerPrivate()), m_progressManager(new ProgressManagerPrivate()),
m_scriptManager(new ScriptManagerPrivate(this)), m_scriptManager(new ScriptManagerPrivate(this)),
m_variableManager(new VariableManager), m_variableManager(new VariableManager),
...@@ -171,6 +170,7 @@ MainWindow::MainWindow() : ...@@ -171,6 +170,7 @@ MainWindow::MainWindow() :
#endif #endif
m_toggleSideBarButton(new QToolButton) m_toggleSideBarButton(new QToolButton)
{ {
(void) new FileManager(this);
OutputPaneManager::create(); OutputPaneManager::create();
setWindowTitle(tr("Qt Creator")); setWindowTitle(tr("Qt Creator"));
...@@ -376,7 +376,7 @@ void MainWindow::closeEvent(QCloseEvent *event) ...@@ -376,7 +376,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
// Save opened files // Save opened files
bool cancelled; bool cancelled;
QList<IFile*> notSaved = fileManager()->saveModifiedFiles(fileManager()->modifiedFiles(), &cancelled); QList<IFile*> notSaved = FileManager::saveModifiedFiles(FileManager::modifiedFiles(), &cancelled);
if (cancelled || !notSaved.isEmpty()) { if (cancelled || !notSaved.isEmpty()) {
event->ignore(); event->ignore();
return; return;
...@@ -962,18 +962,17 @@ void MainWindow::showNewItemDialog(const QString &title, ...@@ -962,18 +962,17 @@ void MainWindow::showNewItemDialog(const QString &title,
QString path = defaultLocation; QString path = defaultLocation;
if (path.isEmpty()) { if (path.isEmpty()) {
const FileManager *fm = m_coreImpl->fileManager();
switch (wizard->kind()) { switch (wizard->kind()) {
case IWizard::ProjectWizard: case IWizard::ProjectWizard:
// Project wizards: Check for projects directory or // Project wizards: Check for projects directory or
// use last visited directory of file dialog. Never start // use last visited directory of file dialog. Never start
// at current. // at current.
path = fm->useProjectsDirectory() ? path = FileManager::useProjectsDirectory() ?
fm->projectsDirectory() : FileManager::projectsDirectory() :
fm->fileDialogLastVisitedDirectory(); FileManager::fileDialogLastVisitedDirectory();
break; break;
default: default:
path = fm->fileDialogInitialDirectory(); path = FileManager::fileDialogInitialDirectory();
break; break;
} }
} }
...@@ -993,7 +992,7 @@ bool MainWindow::showOptionsDialog(const QString &category, ...@@ -993,7 +992,7 @@ bool MainWindow::showOptionsDialog(const QString &category,
void MainWindow::saveAll() void MainWindow::saveAll()
{ {
m_fileManager->saveModifiedFilesSilently(m_fileManager->modifiedFiles()); FileManager::saveModifiedFilesSilently(FileManager::modifiedFiles());
emit m_coreImpl->saveSettingsRequested(); emit m_coreImpl->saveSettingsRequested();
} }
...@@ -1030,7 +1029,7 @@ ActionManager *MainWindow::actionManager() const ...@@ -1030,7 +1029,7 @@ ActionManager *MainWindow::actionManager() const
FileManager *MainWindow::fileManager() const FileManager *MainWindow::fileManager() const
{ {
return m_fileManager; return FileManager::instance();
} }
MessageManager *MainWindow::messageManager() const MessageManager *MainWindow::messageManager() const
...@@ -1236,7 +1235,7 @@ void MainWindow::writeSettings() ...@@ -1236,7 +1235,7 @@ void MainWindow::writeSettings()
m_settings->endGroup(); m_settings->endGroup();
m_fileManager->saveSettings(); FileManager::saveSettings();
m_actionManager->saveSettings(m_settings); m_actionManager->saveSettings(m_settings);
m_editorManager->saveSettings(); m_editorManager->saveSettings();
m_navigationWidget->saveSettings(m_settings); m_navigationWidget->saveSettings(m_settings);
...@@ -1296,7 +1295,7 @@ void MainWindow::aboutToShowRecentFiles() ...@@ -1296,7 +1295,7 @@ void MainWindow::aboutToShowRecentFiles()
aci->menu()->clear(); aci->menu()->clear();
bool hasRecentFiles = false; bool hasRecentFiles = false;
foreach (const FileManager::RecentFile &file, m_fileManager->recentFiles()) { foreach (const FileManager::RecentFile &file, FileManager::recentFiles()) {
hasRecentFiles = true; hasRecentFiles = true;
QAction *action = aci->menu()->addAction( QAction *action = aci->menu()->addAction(
QDir::toNativeSeparators(Utils::withTildeHomePath(file.first))); QDir::toNativeSeparators(Utils::withTildeHomePath(file.first)));
...@@ -1310,7 +1309,7 @@ void MainWindow::aboutToShowRecentFiles() ...@@ -1310,7 +1309,7 @@ void MainWindow::aboutToShowRecentFiles()
aci->menu()->addSeparator(); aci->menu()->addSeparator();
QAction *action = aci->menu()->addAction(QCoreApplication::translate( QAction *action = aci->menu()->addAction(QCoreApplication::translate(
"Core", Core::Constants::TR_CLEAR_MENU)); "Core", Core::Constants::TR_CLEAR_MENU));
connect(action, SIGNAL(triggered()), m_fileManager, SLOT(clearRecentFiles())); connect(action, SIGNAL(triggered()), FileManager::instance(), SLOT(clearRecentFiles()));
} }
} }
......
...@@ -188,7 +188,6 @@ private: ...@@ -188,7 +188,6 @@ private:
ActionManagerPrivate *m_actionManager; ActionManagerPrivate *m_actionManager;
EditorManager *m_editorManager; EditorManager *m_editorManager;
ExternalToolManager *m_externalToolManager; ExternalToolManager *m_externalToolManager;
FileManager *m_fileManager;
MessageManager *m_messageManager; MessageManager *m_messageManager;
ProgressManagerPrivate *m_progressManager; ProgressManagerPrivate *m_progressManager;
ScriptManager *m_scriptManager; ScriptManager *m_scriptManager;
......
...@@ -179,10 +179,9 @@ VcsManager::~VcsManager() ...@@ -179,10 +179,9 @@ VcsManager::~VcsManager()
void VcsManager::extensionsInitialized() void VcsManager::extensionsInitialized()
{ {
// Change signal connections // Change signal connections
FileManager *fileManager = ICore::fileManager();
foreach (IVersionControl *versionControl, allVersionControls()) { foreach (IVersionControl *versionControl, allVersionControls()) {
connect(versionControl, SIGNAL(filesChanged(QStringList)), connect(versionControl, SIGNAL(filesChanged(QStringList)),
fileManager, SIGNAL(filesChangedInternally(QStringList))); FileManager::instance(), SIGNAL(filesChangedInternally(QStringList)));
connect(versionControl, SIGNAL(repositoryChanged(QString)), connect(versionControl, SIGNAL(repositoryChanged(QString)),
this, SIGNAL(repositoryChanged(QString))); this, SIGNAL(repositoryChanged(QString)));
} }
......
...@@ -110,10 +110,9 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error) ...@@ -110,10 +110,9 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
// Objects // Objects
m_modelManager = new CppModelManager(this); m_modelManager = new CppModelManager(this);
Core::VcsManager *vcsManager = Core::ICore::vcsManager(); Core::VcsManager *vcsManager = Core::ICore::vcsManager();
Core::FileManager *fileManager = Core::ICore::fileManager();
connect(vcsManager, SIGNAL(repositoryChanged(QString)),