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
QStringList files = commitEditor->checkedFiles();
if (!files.empty()) {
//save the commit message
if (!Core::ICore::fileManager()->saveFile(editorFile))
if (!Core::FileManager::saveFile(editorFile))
return false;
//rewrite entries of the form 'file => newfile' to 'newfile' because
......
......@@ -266,7 +266,7 @@ void ShortcutSettings::defaultAction()
void ShortcutSettings::exportAction()
{
QString fileName = FileManager::instance()->getSaveFileNameWithExtension(
QString fileName = FileManager::getSaveFileNameWithExtension(
tr("Export Keyboard Mapping Scheme"),
ICore::resourcePath() + QLatin1String("/schemes/"),
tr("Keyboard Mapping Scheme (*.kms)"));
......
......@@ -536,7 +536,7 @@ void EditorManager::removeEditor(IEditor *editor)
bool isDuplicate = d->m_editorModel->isDuplicate(editor);
d->m_editorModel->removeEditor(editor);
if (!isDuplicate)
FileManager::instance()->removeFile(editor->file());
FileManager::removeFile(editor->file());
ICore::removeContextObject(editor);
}
......@@ -870,8 +870,7 @@ bool EditorManager::closeEditors(const QList<IEditor*> &editorsToClose, bool ask
//ask whether to save modified files
if (askAboutModifiedEditors) {
bool cancelled = false;
QList<IFile*> list = ICore::fileManager()->
saveModifiedFiles(filesForEditors(acceptedEditors), &cancelled);
QList<IFile*> list = FileManager::saveModifiedFiles(filesForEditors(acceptedEditors), &cancelled);
if (cancelled)
return false;
if (!list.isEmpty()) {
......@@ -1206,10 +1205,9 @@ void EditorManager::addEditor(IEditor *editor, bool isDuplicate)
if (!isDuplicate) {
const bool isTemporary = editor->isTemporary();
const bool addWatcher = !isTemporary;
ICore::fileManager()->addFile(editor->file(), addWatcher);
FileManager::addFile(editor->file(), addWatcher);
if (!isTemporary)
ICore::fileManager()->addToRecentFiles(editor->file()->fileName(),
editor->id());
FileManager::addToRecentFiles(editor->file()->fileName(), editor->id());
}
emit editorOpened(editor);
}
......@@ -1367,8 +1365,7 @@ QStringList EditorManager::getOpenFileNames() const
{
QString selectedFilter;
const QString &fileFilters = ICore::mimeDatabase()->allFiltersString(&selectedFilter);
return ICore::fileManager()->getOpenFileNames(fileFilters,
QString(), &selectedFilter);
return FileManager::getOpenFileNames(fileFilters, QString(), &selectedFilter);
}
......@@ -1485,7 +1482,7 @@ bool EditorManager::saveFile(IFile *fileParam)
bool isReadOnly;
// try saving, no matter what isReadOnly tells us
success = ICore::fileManager()->saveFile(file, QString(), &isReadOnly);
success = FileManager::saveFile(file, QString(), &isReadOnly);
if (!success && isReadOnly) {
MakeWritableResult answer =
......@@ -1497,7 +1494,7 @@ bool EditorManager::saveFile(IFile *fileParam)
file->checkPermissions();
success = ICore::fileManager()->saveFile(file);
success = FileManager::saveFile(file);
}
if (success) {
......@@ -1571,7 +1568,7 @@ bool EditorManager::saveFileAs(IFile *fileParam)
QString selectedFilter =
ICore::mimeDatabase()->findByFile(QFileInfo(file->fileName())).filterString();
const QString &absoluteFilePath =
ICore::fileManager()->getSaveAsFileName(file, filter, &selectedFilter);
FileManager::getSaveAsFileName(file, filter, &selectedFilter);
if (absoluteFilePath.isEmpty())
return false;
......@@ -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();
// @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)
}
}
if (!isTemporary)
ICore::fileManager()->addToRecentFiles(file->fileName(), editorId);
FileManager::addToRecentFiles(file->fileName(), editorId);
}
void EditorManager::gotoNextDocHistory()
......
......@@ -603,12 +603,12 @@ void ExternalToolRunner::run()
if (IEditor *editor = EditorManager::instance()->currentEditor()) {
m_expectedFileName = editor->file()->fileName();
bool cancelled = false;
FileManager::instance()->saveModifiedFiles(QList<IFile *>() << editor->file(), &cancelled);
FileManager::saveModifiedFiles(QList<IFile *>() << editor->file(), &cancelled);
if (cancelled) {
deleteLater();
return;
}
FileManager::instance()->expectFileChange(m_expectedFileName);
FileManager::expectFileChange(m_expectedFileName);
}
}
m_process = new Utils::QtcProcess(this);
......@@ -641,7 +641,7 @@ void ExternalToolRunner::finished(int exitCode, QProcess::ExitStatus status)
emit ExternalToolManager::instance()->replaceSelectionRequested(m_processOutput);
}
if (m_tool->modifiesCurrentDocument()) {
FileManager::instance()->unexpectFileChange(m_expectedFileName);
FileManager::unexpectFileChange(m_expectedFileName);
}
}
ICore::messageManager()->printToOutputPane(
......@@ -651,9 +651,8 @@ void ExternalToolRunner::finished(int exitCode, QProcess::ExitStatus status)
void ExternalToolRunner::error(QProcess::ProcessError error)
{
if (m_tool->modifiesCurrentDocument()) {
FileManager::instance()->unexpectFileChange(m_expectedFileName);
}
if (m_tool->modifiesCurrentDocument())
FileManager::unexpectFileChange(m_expectedFileName);
// TODO inform about errors
Q_UNUSED(error);
deleteLater();
......
This diff is collapsed.
......@@ -48,15 +48,10 @@ QT_END_NAMESPACE
namespace Core {
class ICore;
class IContext;
class IFile;
class IVersionControl;
namespace Internal {
struct FileManagerPrivate;
}
class CORE_EXPORT FileManager : public QObject
{
Q_OBJECT
......@@ -74,44 +69,44 @@ public:
static FileManager *instance();
// file pool to monitor
void addFiles(const QList<IFile *> &files, bool addWatcher = true);
void addFile(IFile *file, bool addWatcher = true);
bool removeFile(IFile *file);
QList<IFile *> modifiedFiles() const;
static void addFiles(const QList<IFile *> &files, bool addWatcher = true);
static void addFile(IFile *file, bool addWatcher = true);
static bool removeFile(IFile *file);
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);
void unexpectFileChange(const QString &fileName);
static void expectFileChange(const QString &fileName);
static void unexpectFileChange(const QString &fileName);
// 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();
QList<RecentFile> recentFiles() const;
static QList<RecentFile> recentFiles();
void saveSettings();
static void saveSettings();
// current file
void setCurrentFile(const QString &filePath);
QString currentFile() const;
static void setCurrentFile(const QString &filePath);
static QString currentFile();
// helper methods
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(),
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);
QString getSaveFileNameWithExtension(const QString &title, const QString &pathIn,
static QString getSaveFileNameWithExtension(const QString &title, const QString &pathIn,
const QString &filter);
QString getSaveAsFileName(IFile *file, const QString &filter = QString(),
static QString getSaveAsFileName(IFile *file, const QString &filter = QString(),
QString *selectedFilter = 0);
QList<IFile *> saveModifiedFilesSilently(const QList<IFile *> &files, bool *cancelled = 0);
QList<IFile *> saveModifiedFiles(const QList<IFile *> &files,
static QList<IFile *> saveModifiedFilesSilently(const QList<IFile *> &files, bool *cancelled = 0);
static QList<IFile *> saveModifiedFiles(const QList<IFile *> &files,
bool *cancelled = 0,
const QString &message = QString(),
const QString &alwaysSaveMessage = QString(),
......@@ -126,25 +121,27 @@ public:
QWidget *parent,
bool displaySaveAsButton = false);
QString fileDialogLastVisitedDirectory() const;
void setFileDialogLastVisitedDirectory(const QString &);
static QString fileDialogLastVisitedDirectory();
static void setFileDialogLastVisitedDirectory(const QString &);
QString fileDialogInitialDirectory() const;
static QString fileDialogInitialDirectory();
bool useProjectsDirectory() const;
void setUseProjectsDirectory(bool);
static bool useProjectsDirectory();
static void setUseProjectsDirectory(bool);
QString projectsDirectory() const;
void setProjectsDirectory(const QString &);
static QString projectsDirectory();
static void setProjectsDirectory(const QString &);
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*
lead to any editors to reload or any other editor manager actions. */
void notifyFilesChangedInternally(const QStringList &files);
static void notifyFilesChangedInternally(const QStringList &files);
static void executeOpenWithMenuAction(QAction *action);
void executeOpenWithMenuAction(QAction *action);
public slots:
void slotExecuteOpenWithMenuAction(QAction *action);
signals:
void currentFileChanged(const QString &filePath);
......@@ -159,23 +156,6 @@ private slots:
void changedFile(const QString &file);
void mainWindowActivated();
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
......
......@@ -94,7 +94,7 @@ public:
QWidget *parent = 0);
static ActionManager *actionManager();
static FileManager *fileManager();
static QT_DEPRECATED FileManager *fileManager(); // Use FileManager::... directly.
static MessageManager *messageManager();
static EditorManager *editorManager();
static ProgressManager *progressManager();
......
......@@ -138,7 +138,6 @@ MainWindow::MainWindow() :
m_actionManager(new ActionManagerPrivate(this)),
m_editorManager(0),
m_externalToolManager(0),
m_fileManager(new FileManager(this)),
m_progressManager(new ProgressManagerPrivate()),
m_scriptManager(new ScriptManagerPrivate(this)),
m_variableManager(new VariableManager),
......@@ -171,6 +170,7 @@ MainWindow::MainWindow() :
#endif
m_toggleSideBarButton(new QToolButton)
{
(void) new FileManager(this);
OutputPaneManager::create();
setWindowTitle(tr("Qt Creator"));
......@@ -376,7 +376,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
// Save opened files
bool cancelled;
QList<IFile*> notSaved = fileManager()->saveModifiedFiles(fileManager()->modifiedFiles(), &cancelled);
QList<IFile*> notSaved = FileManager::saveModifiedFiles(FileManager::modifiedFiles(), &cancelled);
if (cancelled || !notSaved.isEmpty()) {
event->ignore();
return;
......@@ -962,18 +962,17 @@ void MainWindow::showNewItemDialog(const QString &title,
QString path = defaultLocation;
if (path.isEmpty()) {
const FileManager *fm = m_coreImpl->fileManager();
switch (wizard->kind()) {
case IWizard::ProjectWizard:
// Project wizards: Check for projects directory or
// use last visited directory of file dialog. Never start
// at current.
path = fm->useProjectsDirectory() ?
fm->projectsDirectory() :
fm->fileDialogLastVisitedDirectory();
path = FileManager::useProjectsDirectory() ?
FileManager::projectsDirectory() :
FileManager::fileDialogLastVisitedDirectory();
break;
default:
path = fm->fileDialogInitialDirectory();
path = FileManager::fileDialogInitialDirectory();
break;
}
}
......@@ -993,7 +992,7 @@ bool MainWindow::showOptionsDialog(const QString &category,
void MainWindow::saveAll()
{
m_fileManager->saveModifiedFilesSilently(m_fileManager->modifiedFiles());
FileManager::saveModifiedFilesSilently(FileManager::modifiedFiles());
emit m_coreImpl->saveSettingsRequested();
}
......@@ -1030,7 +1029,7 @@ ActionManager *MainWindow::actionManager() const
FileManager *MainWindow::fileManager() const
{
return m_fileManager;
return FileManager::instance();
}
MessageManager *MainWindow::messageManager() const
......@@ -1236,7 +1235,7 @@ void MainWindow::writeSettings()
m_settings->endGroup();
m_fileManager->saveSettings();
FileManager::saveSettings();
m_actionManager->saveSettings(m_settings);
m_editorManager->saveSettings();
m_navigationWidget->saveSettings(m_settings);
......@@ -1296,7 +1295,7 @@ void MainWindow::aboutToShowRecentFiles()
aci->menu()->clear();
bool hasRecentFiles = false;
foreach (const FileManager::RecentFile &file, m_fileManager->recentFiles()) {
foreach (const FileManager::RecentFile &file, FileManager::recentFiles()) {
hasRecentFiles = true;
QAction *action = aci->menu()->addAction(
QDir::toNativeSeparators(Utils::withTildeHomePath(file.first)));
......@@ -1310,7 +1309,7 @@ void MainWindow::aboutToShowRecentFiles()
aci->menu()->addSeparator();
QAction *action = aci->menu()->addAction(QCoreApplication::translate(
"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:
ActionManagerPrivate *m_actionManager;
EditorManager *m_editorManager;
ExternalToolManager *m_externalToolManager;
FileManager *m_fileManager;
MessageManager *m_messageManager;
ProgressManagerPrivate *m_progressManager;
ScriptManager *m_scriptManager;
......
......@@ -179,10 +179,9 @@ VcsManager::~VcsManager()
void VcsManager::extensionsInitialized()
{
// Change signal connections
FileManager *fileManager = ICore::fileManager();
foreach (IVersionControl *versionControl, allVersionControls()) {
connect(versionControl, SIGNAL(filesChanged(QStringList)),
fileManager, SIGNAL(filesChangedInternally(QStringList)));
FileManager::instance(), SIGNAL(filesChangedInternally(QStringList)));
connect(versionControl, SIGNAL(repositoryChanged(QString)),
this, SIGNAL(repositoryChanged(QString)));
}
......
......@@ -110,10 +110,9 @@ bool CppToolsPlugin::initialize(const QStringList &arguments, QString *error)
// Objects
m_modelManager = new CppModelManager(this);
Core::VcsManager *vcsManager = Core::ICore::vcsManager();
Core::FileManager *fileManager = Core::ICore::fileManager();
connect(vcsManager, SIGNAL(repositoryChanged(QString)),
m_modelManager, SLOT(updateModifiedSourceFiles()));
connect(fileManager, SIGNAL(filesChangedInternally(QStringList)),
connect(Core::FileManager::instance(), SIGNAL(filesChangedInternally(QStringList)),
m_modelManager, SLOT(updateSourceFiles(QStringList)));
addAutoReleasedObject(m_modelManager);
......
......@@ -504,7 +504,7 @@ bool CvsPlugin::submitEditorAboutToClose(VcsBaseSubmitEditor *submitEditor)
bool closeEditor = true;
if (!fileList.empty()) {
// get message & commit
closeEditor = ICore::fileManager()->saveFile(fileIFace);
closeEditor = FileManager::saveFile(fileIFace);
if (closeEditor)
closeEditor = commit(m_commitMessageFileName, fileList);
}
......
......@@ -1497,7 +1497,7 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
const QString fileName = handler->currentFileName();
if (editor && editor->file()->fileName() == fileName) {
// Handle that as a special case for nicer interaction with core
ICore::fileManager()->saveFile(editor->file());
FileManager::saveFile(editor->file());
// Check result by reading back.
QFile file3(fileName);
file3.open(QIODevice::ReadOnly);
......@@ -1512,9 +1512,8 @@ void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
}
} else if (cmd.matches("wa", "wall")) {
// :w[all]
FileManager *fm = ICore::fileManager();
QList<IFile *> toSave = fm->modifiedFiles();
QList<IFile *> failed = fm->saveModifiedFilesSilently(toSave);
QList<IFile *> toSave = FileManager::modifiedFiles();
QList<IFile *> failed = FileManager::saveModifiedFilesSilently(toSave);
if (failed.isEmpty())
handler->showBlackMessage(tr("Saving succeeded"));
else
......
......@@ -91,11 +91,10 @@ GenericProject::GenericProject(Manager *manager, const QString &fileName)
m_includesIFile = new GenericProjectFile(this, m_includesFileName, GenericProject::Configuration);
m_configIFile = new GenericProjectFile(this, m_configFileName, GenericProject::Configuration);
Core::FileManager *fm = Core::FileManager::instance();
fm->addFile(m_creatorIFile);
fm->addFile(m_filesIFile);
fm->addFile(m_includesIFile);
fm->addFile(m_configIFile);
Core::FileManager::addFile(m_creatorIFile);
Core::FileManager::addFile(m_filesIFile);
Core::FileManager::addFile(m_includesIFile);
Core::FileManager::addFile(m_configIFile);
m_rootNode = new GenericProjectNode(this, m_creatorIFile);
......
......@@ -774,7 +774,7 @@ bool GitPlugin::submitEditorAboutToClose(VcsBase::VcsBaseSubmitEditor *submitEdi
bool closeEditor = true;
if (model->hasCheckedFiles() || !m_commitAmendSHA1.isEmpty()) {
// get message & commit
if (!Core::ICore::fileManager()->saveFile(fileIFace))
if (!Core::FileManager::saveFile(fileIFace))
return false;
closeEditor = m_gitClient->addAndCommit(m_submitRepository, editor->panelData(),
......@@ -891,11 +891,10 @@ static bool ensureFileSaved(const QString &fileName)
Core::IFile *file = editors.front()->file();
if (!file || !file->isModified())
return true;
Core::FileManager *fm = Core::ICore::fileManager();
bool canceled;
QList<Core::IFile *> files;
files << file;
fm->saveModifiedFiles(files, &canceled);
Core::FileManager::saveModifiedFiles(files, &canceled);
return !canceled;
}
......
......@@ -718,7 +718,7 @@ void AbstractDebBasedQt4MaemoTarget::handleTargetAddedSpecial()
connect(m_controlFile, SIGNAL(modified()), SIGNAL(controlChanged()));
m_changeLogFile = new WatchableFile(changeLogFilePath(), this);
connect(m_changeLogFile, SIGNAL(modified()), SIGNAL(changeLogChanged()));
Core::FileManager::instance()->addFiles(QList<Core::IFile *>()
Core::FileManager::addFiles(QList<Core::IFile *>()
<< m_controlFile << m_changeLogFile);
connect(m_filesWatcher, SIGNAL(directoryChanged(QString)), this,
SLOT(handleDebianDirContentsChanged()));
......@@ -1067,7 +1067,7 @@ void AbstractRpmBasedQt4MaemoTarget::handleTargetAddedSpecial()
{
m_specFile = new WatchableFile(specFilePath(), this);
connect(m_specFile, SIGNAL(modified()), SIGNAL(specFileChanged()));
Core::FileManager::instance()->addFile(m_specFile);
Core::FileManager::addFile(m_specFile);
emit specFileChanged();
}
......
......@@ -651,7 +651,7 @@ bool MercurialPlugin::submitEditorAboutToClose(VcsBaseSubmitEditor *submitEditor
const QStringList files = commitEditor->checkedFiles();
if (!files.empty()) {
//save the commit message
if (!core->fileManager()->saveFile(editorFile))
if (!Core::FileManager::saveFile(editorFile))
return false;
QStringList extraOptions;
......
......@@ -1371,7 +1371,7 @@ bool PerforcePlugin::submitEditorAboutToClose(VcsBase::VcsBaseSubmitEditor *subm
m_settings.setPromptToSubmit(wantsPrompt);
m_settings.toSettings(Core::ICore::settings());
}
if (!Core::ICore::fileManager()->saveFile(fileIFace))
if (!Core::FileManager::saveFile(fileIFace))
return false;
if (answer == VcsBase::VcsBaseSubmitEditor::SubmitDiscarded) {
cleanCommitMessageFile();
......
......@@ -129,9 +129,8 @@ void BaseProjectWizardDialog::slotAccepted()
{
if (d->introPage->useAsDefaultPath()) {
// Store the path as default path for new projects if desired.
Core::FileManager *fm = Core::ICore::fileManager();
fm->setProjectsDirectory(path());
fm->setUseProjectsDirectory(true);
Core::FileManager::setProjectsDirectory(path());
Core::FileManager::setUseProjectsDirectory(true);
}
}
......
......@@ -187,13 +187,12 @@ void FolderNavigationWidget::setAutoSynchronization(bool sync)
m_autoSync = sync;
Core::FileManager *fileManager = Core::ICore::fileManager();
if (m_autoSync) {
connect(fileManager, SIGNAL(currentFileChanged(QString)),
connect(Core::FileManager::instance(), SIGNAL(currentFileChanged(QString)),
this, SLOT(setCurrentFile(QString)));
setCurrentFile(fileManager->currentFile());
setCurrentFile(Core::FileManager::currentFile());
} else {
disconnect(fileManager, SIGNAL(currentFileChanged(QString)),
disconnect(Core::FileManager::instance(), SIGNAL(currentFileChanged(QString)),
this, SLOT(setCurrentFile(QString)));
}
}
......@@ -361,7 +360,7 @@ void FolderNavigationWidget::contextMenuEvent(QContextMenuEvent *ev)
findOnFileSystem(info.absolutePath());
return;
}
Core::FileManager::instance()->executeOpenWithMenuAction(action);
Core::FileManager::executeOpenWithMenuAction(action);
}
QString FolderNavigationWidget::msgFindOnFileSystem()
......
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