2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
**
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
#ifndef DOCUMENTMANAGER_H
|
|
|
|
#define DOCUMENTMANAGER_H
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-11-10 11:36:51 +01:00
|
|
|
#include <coreplugin/id.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QObject>
|
|
|
|
#include <QStringList>
|
|
|
|
#include <QPair>
|
|
|
|
#include <QVariant>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
2011-12-09 10:45:17 +01:00
|
|
|
class QAction;
|
2009-11-25 10:09:45 +01:00
|
|
|
class QMainWindow;
|
2011-12-09 10:45:17 +01:00
|
|
|
class QMenu;
|
2008-12-02 12:01:29 +01:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
class IContext;
|
2012-02-14 16:43:51 +01:00
|
|
|
class IDocument;
|
2010-11-26 16:01:34 +01:00
|
|
|
class IVersionControl;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
class CORE_EXPORT DocumentManager : public QObject
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2010-11-23 12:47:45 +01:00
|
|
|
enum FixMode {
|
|
|
|
ResolveLinks,
|
|
|
|
KeepLinks
|
|
|
|
};
|
|
|
|
|
2011-11-10 11:36:51 +01:00
|
|
|
typedef QPair<QString, Id> RecentFile;
|
2010-12-09 11:37:58 +01:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
explicit DocumentManager(QMainWindow *ew);
|
|
|
|
virtual ~DocumentManager();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
static DocumentManager *instance();
|
2010-11-26 16:01:34 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// file pool to monitor
|
2012-02-14 16:43:51 +01:00
|
|
|
static void addDocuments(const QList<IDocument *> &documents, bool addWatcher = true);
|
|
|
|
static void addDocument(IDocument *document, bool addWatcher = true);
|
|
|
|
static bool removeDocument(IDocument *document);
|
|
|
|
static QList<IDocument *> modifiedDocuments();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-01-19 23:23:43 +01:00
|
|
|
static void renamedFile(const QString &from, const QString &to);
|
2010-05-11 14:13:38 +02:00
|
|
|
|
2012-01-19 23:23:43 +01:00
|
|
|
static void expectFileChange(const QString &fileName);
|
|
|
|
static void unexpectFileChange(const QString &fileName);
|
2010-01-22 16:49:57 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// recent files
|
2012-01-19 23:23:43 +01:00
|
|
|
static void addToRecentFiles(const QString &fileName, const Id &editorId = Id());
|
2011-06-20 11:01:23 +02:00
|
|
|
Q_SLOT void clearRecentFiles();
|
2012-01-19 23:23:43 +01:00
|
|
|
static QList<RecentFile> recentFiles();
|
2011-06-20 11:01:23 +02:00
|
|
|
|
2012-01-19 23:23:43 +01:00
|
|
|
static void saveSettings();
|
2010-05-11 14:13:38 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// current file
|
2012-01-19 23:23:43 +01:00
|
|
|
static void setCurrentFile(const QString &filePath);
|
|
|
|
static QString currentFile();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
// helper methods
|
2010-11-23 12:47:45 +01:00
|
|
|
static QString fixFileName(const QString &fileName, FixMode fixmode);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
static bool saveDocument(IDocument *document, const QString &fileName = QString(), bool *isReadOnly = 0);
|
2011-03-30 12:38:12 +02:00
|
|
|
|
2012-01-19 23:23:43 +01:00
|
|
|
static QStringList getOpenFileNames(const QString &filters,
|
2009-11-26 18:03:16 +01:00
|
|
|
const QString path = QString(),
|
|
|
|
QString *selectedFilter = 0);
|
2012-01-19 23:23:43 +01:00
|
|
|
static QString getSaveFileName(const QString &title, const QString &pathIn,
|
2010-09-07 11:55:52 +02:00
|
|
|
const QString &filter = QString(), QString *selectedFilter = 0);
|
2012-01-19 23:23:43 +01:00
|
|
|
static QString getSaveFileNameWithExtension(const QString &title, const QString &pathIn,
|
2010-09-07 11:55:52 +02:00
|
|
|
const QString &filter);
|
2012-02-14 16:43:51 +01:00
|
|
|
static QString getSaveAsFileName(IDocument *document, const QString &filter = QString(),
|
2010-09-07 11:55:52 +02:00
|
|
|
QString *selectedFilter = 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
static QList<IDocument *> saveModifiedDocumentsSilently(const QList<IDocument *> &documents, bool *cancelled = 0);
|
|
|
|
static QList<IDocument *> saveModifiedDocuments(const QList<IDocument *> &documents,
|
2009-01-20 17:14:00 +01:00
|
|
|
bool *cancelled = 0,
|
2009-05-06 11:55:21 +02:00
|
|
|
const QString &message = QString(),
|
2011-02-25 15:27:13 +01:00
|
|
|
const QString &alwaysSaveMessage = QString(),
|
2009-05-06 11:55:21 +02:00
|
|
|
bool *alwaysSave = 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-11-26 18:03:16 +01:00
|
|
|
|
2010-11-26 16:01:34 +01:00
|
|
|
// Helper to display a message dialog when encountering a read-only
|
|
|
|
// file, prompting the user about how to make it writeable.
|
|
|
|
enum ReadOnlyAction { RO_Cancel, RO_OpenVCS, RO_MakeWriteable, RO_SaveAs };
|
|
|
|
static ReadOnlyAction promptReadOnlyFile(const QString &fileName,
|
|
|
|
const IVersionControl *versionControl,
|
|
|
|
QWidget *parent,
|
|
|
|
bool displaySaveAsButton = false);
|
|
|
|
|
2012-01-19 23:23:43 +01:00
|
|
|
static QString fileDialogLastVisitedDirectory();
|
|
|
|
static void setFileDialogLastVisitedDirectory(const QString &);
|
2009-11-26 18:03:16 +01:00
|
|
|
|
2012-01-19 23:23:43 +01:00
|
|
|
static QString fileDialogInitialDirectory();
|
2009-11-26 18:03:16 +01:00
|
|
|
|
2012-01-19 23:23:43 +01:00
|
|
|
static bool useProjectsDirectory();
|
|
|
|
static void setUseProjectsDirectory(bool);
|
2009-11-26 18:03:16 +01:00
|
|
|
|
2012-01-19 23:23:43 +01:00
|
|
|
static QString projectsDirectory();
|
|
|
|
static void setProjectsDirectory(const QString &);
|
2009-11-26 18:03:16 +01:00
|
|
|
|
2011-12-09 10:45:17 +01:00
|
|
|
static void populateOpenWithMenu(QMenu *menu, const QString &fileName);
|
|
|
|
|
2009-12-21 11:08:20 +01:00
|
|
|
/* 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. */
|
2012-01-19 23:23:43 +01:00
|
|
|
static void notifyFilesChangedInternally(const QStringList &files);
|
2009-12-21 11:08:20 +01:00
|
|
|
|
2012-01-19 23:23:43 +01:00
|
|
|
static void executeOpenWithMenuAction(QAction *action);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void slotExecuteOpenWithMenuAction(QAction *action);
|
2011-12-09 12:23:46 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
signals:
|
|
|
|
void currentFileChanged(const QString &filePath);
|
2009-12-21 11:08:20 +01:00
|
|
|
/* 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 filesChangedInternally(const QStringList &files);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
private slots:
|
2012-02-14 16:43:51 +01:00
|
|
|
void documentDestroyed(QObject *obj);
|
2008-12-02 12:01:29 +01:00
|
|
|
void checkForNewFileName();
|
|
|
|
void checkForReload();
|
|
|
|
void changedFile(const QString &file);
|
|
|
|
void mainWindowActivated();
|
|
|
|
void syncWithEditor(Core::IContext *context);
|
|
|
|
};
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
/*! The FileChangeBlocker blocks all change notifications to all IDocument * that
|
2009-06-18 14:30:04 +02:00
|
|
|
match the given filename. And unblocks in the destructor.
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
To also reload the IDocument in the destructor class set modifiedReload to true
|
2009-06-18 14:30:04 +02:00
|
|
|
|
|
|
|
*/
|
|
|
|
class CORE_EXPORT FileChangeBlocker
|
|
|
|
{
|
|
|
|
public:
|
2010-09-16 14:59:05 +02:00
|
|
|
explicit FileChangeBlocker(const QString &fileName);
|
2009-06-18 14:30:04 +02:00
|
|
|
~FileChangeBlocker();
|
|
|
|
private:
|
2010-09-16 14:59:05 +02:00
|
|
|
const QString m_fileName;
|
2009-07-28 11:37:16 +02:00
|
|
|
Q_DISABLE_COPY(FileChangeBlocker)
|
2009-06-18 14:30:04 +02:00
|
|
|
};
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
} // namespace Core
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
Q_DECLARE_METATYPE(Core::DocumentManager::RecentFile)
|
2010-12-09 11:37:58 +01:00
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
#endif // DOCUMENTMANAGER_H
|