2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, 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.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02: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 <QPair>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
2013-03-27 08:29:38 +01:00
|
|
|
class QStringList;
|
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;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-06-25 13:37:21 +02:00
|
|
|
namespace Internal { class MainWindow; }
|
|
|
|
|
|
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
|
|
|
|
2013-08-29 17:56:28 +02:00
|
|
|
static QObject *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
|
|
|
|
2013-10-07 13:34:40 +02:00
|
|
|
// helper functions
|
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-10-15 11:53:22 +02:00
|
|
|
static QString getSaveAsFileName(const 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
|
|
|
|
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
|
|
|
|
2012-10-05 21:34:09 +10:00
|
|
|
static QString buildDirectory();
|
|
|
|
|
static void setBuildDirectory(const QString &directory);
|
|
|
|
|
|
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);
|
2012-03-12 16:56:25 +01:00
|
|
|
/// emitted if all documents changed their name e.g. due to the file changing on disk
|
|
|
|
|
void allDocumentsRenamed(const QString &from, const QString &to);
|
|
|
|
|
/// emitted if one document changed its name e.g. due to save as
|
|
|
|
|
void documentRenamed(Core::IDocument *document, const QString &from, const QString &to);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-06-10 15:28:26 +02:00
|
|
|
protected:
|
|
|
|
|
bool eventFilter(QObject *obj, QEvent *e);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
private slots:
|
2012-02-14 16:43:51 +01:00
|
|
|
void documentDestroyed(QObject *obj);
|
2013-07-04 13:30:26 +02:00
|
|
|
void filePathChanged(const QString &oldName, const QString &newName);
|
2008-12-02 12:01:29 +01:00
|
|
|
void checkForNewFileName();
|
|
|
|
|
void checkForReload();
|
|
|
|
|
void changedFile(const QString &file);
|
2013-05-07 19:03:22 +02:00
|
|
|
void syncWithEditor(const QList<Core::IContext *> &context);
|
2013-06-25 13:37:21 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
explicit DocumentManager(QMainWindow *ew);
|
2013-08-29 17:56:28 +02:00
|
|
|
~DocumentManager();
|
2013-06-25 13:37:21 +02:00
|
|
|
|
|
|
|
|
friend class Core::Internal::MainWindow;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
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
|