forked from qt-creator/qt-creator
Move some API around and make some IFile based instead of IEditor.
promptReadOnlyFile: EditorManager-->FileManager fileFilters: EditorManager-->MimeDataBase saveFile & saveFileAs --> IFile based
This commit is contained in:
@@ -1161,30 +1161,6 @@ QString EditorManager::getOpenWithEditorId(const QString &fileName,
|
|||||||
return selectedId;
|
return selectedId;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QString formatFileFilters(const Core::ICore *core, QString *selectedFilter = 0)
|
|
||||||
{
|
|
||||||
if (selectedFilter)
|
|
||||||
selectedFilter->clear();
|
|
||||||
|
|
||||||
// Compile list of filter strings, sort, and remove duplicates (different mime types might
|
|
||||||
// generate the same filter).
|
|
||||||
QStringList filters = core->mimeDatabase()->filterStrings();
|
|
||||||
if (filters.empty())
|
|
||||||
return QString();
|
|
||||||
filters.sort();
|
|
||||||
filters.erase(std::unique(filters.begin(), filters.end()), filters.end());
|
|
||||||
|
|
||||||
static const QString allFilesFilter =
|
|
||||||
QCoreApplication::translate("Core", Constants::ALL_FILES_FILTER);
|
|
||||||
if (selectedFilter)
|
|
||||||
*selectedFilter = allFilesFilter;
|
|
||||||
|
|
||||||
// Prepend all files filter (instead of appending to work around a bug in Qt/Mac).
|
|
||||||
filters.prepend(allFilesFilter);
|
|
||||||
|
|
||||||
return filters.join(QLatin1String(";;"));
|
|
||||||
}
|
|
||||||
|
|
||||||
IEditor *EditorManager::openEditor(const QString &fileName, const QString &editorId,
|
IEditor *EditorManager::openEditor(const QString &fileName, const QString &editorId,
|
||||||
OpenEditorFlags flags, bool *newEditor)
|
OpenEditorFlags flags, bool *newEditor)
|
||||||
{
|
{
|
||||||
@@ -1279,7 +1255,7 @@ bool EditorManager::openExternalEditor(const QString &fileName, const QString &e
|
|||||||
QStringList EditorManager::getOpenFileNames() const
|
QStringList EditorManager::getOpenFileNames() const
|
||||||
{
|
{
|
||||||
QString selectedFilter;
|
QString selectedFilter;
|
||||||
const QString &fileFilters = formatFileFilters(m_d->m_core, &selectedFilter);
|
const QString &fileFilters = m_d->m_core->mimeDatabase()->allFiltersString(&selectedFilter);
|
||||||
return ICore::instance()->fileManager()->getOpenFileNames(fileFilters,
|
return ICore::instance()->fileManager()->getOpenFileNames(fileFilters,
|
||||||
QString(), &selectedFilter);
|
QString(), &selectedFilter);
|
||||||
}
|
}
|
||||||
@@ -1379,23 +1355,23 @@ void EditorManager::restoreEditorState(IEditor *editor)
|
|||||||
|
|
||||||
bool EditorManager::saveEditor(IEditor *editor)
|
bool EditorManager::saveEditor(IEditor *editor)
|
||||||
{
|
{
|
||||||
return saveFile(editor);
|
return saveFile(editor->file());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EditorManager::saveFile(IEditor *editor)
|
bool EditorManager::saveFile(IFile *fileParam)
|
||||||
{
|
{
|
||||||
if (!editor)
|
IFile *file = fileParam;
|
||||||
editor = currentEditor();
|
if (!file && currentEditor())
|
||||||
if (!editor)
|
file = currentEditor()->file();
|
||||||
|
if (!file)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
IFile *file = editor->file();
|
|
||||||
file->checkPermissions();
|
file->checkPermissions();
|
||||||
|
|
||||||
const QString &fileName = file->fileName();
|
const QString &fileName = file->fileName();
|
||||||
|
|
||||||
if (fileName.isEmpty())
|
if (fileName.isEmpty())
|
||||||
return saveFileAs(editor);
|
return saveFileAs(file);
|
||||||
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
||||||
@@ -1406,7 +1382,7 @@ bool EditorManager::saveFile(IEditor *editor)
|
|||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
MakeWritableResult answer =
|
MakeWritableResult answer =
|
||||||
makeEditorWritable(editor);
|
makeFileWritable(file);
|
||||||
if (answer == Failed)
|
if (answer == Failed)
|
||||||
return false;
|
return false;
|
||||||
if (answer == SavedAs)
|
if (answer == SavedAs)
|
||||||
@@ -1419,74 +1395,31 @@ bool EditorManager::saveFile(IEditor *editor)
|
|||||||
m_d->m_core->fileManager()->unblockFileChange(file);
|
m_d->m_core->fileManager()->unblockFileChange(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success && !editor->isTemporary())
|
if (success) {
|
||||||
m_d->m_core->fileManager()->addToRecentFiles(editor->file()->fileName());
|
addFileToRecentFiles(file);
|
||||||
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorManager::ReadOnlyAction
|
|
||||||
EditorManager::promptReadOnlyFile(const QString &fileName,
|
|
||||||
const IVersionControl *versionControl,
|
|
||||||
QWidget *parent,
|
|
||||||
bool displaySaveAsButton)
|
|
||||||
{
|
|
||||||
// Version Control: If automatic open is desired, open right away.
|
|
||||||
bool promptVCS = false;
|
|
||||||
if (versionControl && versionControl->supportsOperation(IVersionControl::OpenOperation)) {
|
|
||||||
if (versionControl->settingsFlags() & IVersionControl::AutoOpen)
|
|
||||||
return RO_OpenVCS;
|
|
||||||
promptVCS = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create message box.
|
|
||||||
QMessageBox msgBox(QMessageBox::Question, tr("File is Read Only"),
|
|
||||||
tr("The file <i>%1</i> is read only.").arg(QDir::toNativeSeparators(fileName)),
|
|
||||||
QMessageBox::Cancel, parent);
|
|
||||||
|
|
||||||
QPushButton *vcsButton = 0;
|
|
||||||
if (promptVCS)
|
|
||||||
vcsButton = msgBox.addButton(tr("Open with VCS (%1)").arg(versionControl->displayName()), QMessageBox::AcceptRole);
|
|
||||||
|
|
||||||
QPushButton *makeWritableButton = msgBox.addButton(tr("Make writable"), QMessageBox::AcceptRole);
|
|
||||||
|
|
||||||
QPushButton *saveAsButton = 0;
|
|
||||||
if (displaySaveAsButton)
|
|
||||||
saveAsButton = msgBox.addButton(tr("Save as ..."), QMessageBox::ActionRole);
|
|
||||||
|
|
||||||
msgBox.setDefaultButton(vcsButton ? vcsButton : makeWritableButton);
|
|
||||||
msgBox.exec();
|
|
||||||
|
|
||||||
QAbstractButton *clickedButton = msgBox.clickedButton();
|
|
||||||
if (clickedButton == vcsButton)
|
|
||||||
return RO_OpenVCS;
|
|
||||||
if (clickedButton == makeWritableButton)
|
|
||||||
return RO_MakeWriteable;
|
|
||||||
if (clickedButton == saveAsButton)
|
|
||||||
return RO_SaveAs;
|
|
||||||
return RO_Cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
MakeWritableResult
|
MakeWritableResult
|
||||||
EditorManager::makeEditorWritable(IEditor *editor)
|
EditorManager::makeFileWritable(IFile *file)
|
||||||
{
|
{
|
||||||
if (!editor || !editor->file())
|
if (!file)
|
||||||
return Failed;
|
return Failed;
|
||||||
QString directory = QFileInfo(editor->file()->fileName()).absolutePath();
|
QString directory = QFileInfo(file->fileName()).absolutePath();
|
||||||
IVersionControl *versionControl = m_d->m_core->vcsManager()->findVersionControlForDirectory(directory);
|
IVersionControl *versionControl = m_d->m_core->vcsManager()->findVersionControlForDirectory(directory);
|
||||||
IFile *file = editor->file();
|
|
||||||
const QString &fileName = file->fileName();
|
const QString &fileName = file->fileName();
|
||||||
|
|
||||||
switch (promptReadOnlyFile(fileName, versionControl, m_d->m_core->mainWindow(), true)) {
|
switch (FileManager::promptReadOnlyFile(fileName, versionControl, m_d->m_core->mainWindow(), true)) {
|
||||||
case RO_OpenVCS:
|
case FileManager::RO_OpenVCS:
|
||||||
if (!versionControl->vcsOpen(fileName)) {
|
if (!versionControl->vcsOpen(fileName)) {
|
||||||
QMessageBox::warning(m_d->m_core->mainWindow(), tr("Failed!"), tr("Could not open the file for editing with SCC."));
|
QMessageBox::warning(m_d->m_core->mainWindow(), tr("Failed!"), tr("Could not open the file for editing with SCC."));
|
||||||
return Failed;
|
return Failed;
|
||||||
}
|
}
|
||||||
file->checkPermissions();
|
file->checkPermissions();
|
||||||
return OpenedWithVersionControl;
|
return OpenedWithVersionControl;
|
||||||
case RO_MakeWriteable: {
|
case FileManager::RO_MakeWriteable: {
|
||||||
const bool permsOk = QFile::setPermissions(fileName, QFile::permissions(fileName) | QFile::WriteUser);
|
const bool permsOk = QFile::setPermissions(fileName, QFile::permissions(fileName) | QFile::WriteUser);
|
||||||
if (!permsOk) {
|
if (!permsOk) {
|
||||||
QMessageBox::warning(m_d->m_core->mainWindow(), tr("Failed!"), tr("Could not set permissions to writable."));
|
QMessageBox::warning(m_d->m_core->mainWindow(), tr("Failed!"), tr("Could not set permissions to writable."));
|
||||||
@@ -1495,23 +1428,23 @@ EditorManager::makeEditorWritable(IEditor *editor)
|
|||||||
}
|
}
|
||||||
file->checkPermissions();
|
file->checkPermissions();
|
||||||
return MadeWritable;
|
return MadeWritable;
|
||||||
case RO_SaveAs :
|
case FileManager::RO_SaveAs :
|
||||||
return saveFileAs(editor) ? SavedAs : Failed;
|
return saveFileAs(file) ? SavedAs : Failed;
|
||||||
case RO_Cancel:
|
case FileManager::RO_Cancel:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return Failed;
|
return Failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EditorManager::saveFileAs(IEditor *editor)
|
bool EditorManager::saveFileAs(IFile *fileParam)
|
||||||
{
|
{
|
||||||
if (!editor)
|
IFile *file = fileParam;
|
||||||
editor = currentEditor();
|
if (!file && currentEditor())
|
||||||
if (!editor)
|
file = currentEditor()->file();
|
||||||
|
if (!file)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
IFile *file = editor->file();
|
const QString &filter = m_d->m_core->mimeDatabase()->allFiltersString();
|
||||||
const QString &filter = formatFileFilters(m_d->m_core);
|
|
||||||
QString selectedFilter =
|
QString selectedFilter =
|
||||||
m_d->m_core->mimeDatabase()->findByFile(QFileInfo(file->fileName())).filterString();
|
m_d->m_core->mimeDatabase()->findByFile(QFileInfo(file->fileName())).filterString();
|
||||||
const QString &absoluteFilePath =
|
const QString &absoluteFilePath =
|
||||||
@@ -1519,7 +1452,9 @@ bool EditorManager::saveFileAs(IEditor *editor)
|
|||||||
|
|
||||||
if (absoluteFilePath.isEmpty())
|
if (absoluteFilePath.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (absoluteFilePath != file->fileName()) {
|
if (absoluteFilePath != file->fileName()) {
|
||||||
|
// close existing editors for the new file name
|
||||||
const QList<IEditor *> existList = editorsForFileName(absoluteFilePath);
|
const QList<IEditor *> existList = editorsForFileName(absoluteFilePath);
|
||||||
if (!existList.isEmpty()) {
|
if (!existList.isEmpty()) {
|
||||||
closeEditors(existList, false);
|
closeEditors(existList, false);
|
||||||
@@ -1537,13 +1472,27 @@ bool EditorManager::saveFileAs(IEditor *editor)
|
|||||||
// a good way out either (also the undo stack would be lost). Perhaps the best is to
|
// a good way out either (also the undo stack would be lost). Perhaps the best is to
|
||||||
// re-think part of the editors design.
|
// re-think part of the editors design.
|
||||||
|
|
||||||
if (success && !editor->isTemporary())
|
if (success) {
|
||||||
m_d->m_core->fileManager()->addToRecentFiles(file->fileName());
|
addFileToRecentFiles(file);
|
||||||
|
}
|
||||||
updateActions();
|
updateActions();
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorManager::addFileToRecentFiles(IFile *file)
|
||||||
|
{
|
||||||
|
bool isTemporary = true;
|
||||||
|
QList<IEditor *> editors = editorsForFile(file);
|
||||||
|
foreach (IEditor *editor, editors) {
|
||||||
|
if (!editor->isTemporary()) {
|
||||||
|
isTemporary = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isTemporary)
|
||||||
|
m_d->m_core->fileManager()->addToRecentFiles(file->fileName());
|
||||||
|
}
|
||||||
|
|
||||||
void EditorManager::gotoNextDocHistory()
|
void EditorManager::gotoNextDocHistory()
|
||||||
{
|
{
|
||||||
OpenEditorsWindow *dialog = windowPopup();
|
OpenEditorsWindow *dialog = windowPopup();
|
||||||
@@ -1573,7 +1522,7 @@ void EditorManager::gotoPreviousDocHistory()
|
|||||||
void EditorManager::makeCurrentEditorWritable()
|
void EditorManager::makeCurrentEditorWritable()
|
||||||
{
|
{
|
||||||
if (IEditor* curEditor = currentEditor())
|
if (IEditor* curEditor = currentEditor())
|
||||||
makeEditorWritable(curEditor);
|
makeFileWritable(curEditor->file());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorManager::updateWindowTitle()
|
void EditorManager::updateWindowTitle()
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ public:
|
|||||||
|
|
||||||
bool closeEditors(const QList<IEditor *> &editorsToClose, bool askAboutModifiedEditors = true);
|
bool closeEditors(const QList<IEditor *> &editorsToClose, bool askAboutModifiedEditors = true);
|
||||||
|
|
||||||
MakeWritableResult makeEditorWritable(IEditor *editor);
|
MakeWritableResult makeFileWritable(IFile *file);
|
||||||
|
|
||||||
QByteArray saveState() const;
|
QByteArray saveState() const;
|
||||||
bool restoreState(const QByteArray &state);
|
bool restoreState(const QByteArray &state);
|
||||||
@@ -197,15 +197,6 @@ public:
|
|||||||
|
|
||||||
QTextCodec *defaultTextEncoding() const;
|
QTextCodec *defaultTextEncoding() const;
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
static qint64 maxTextFileSize();
|
static qint64 maxTextFileSize();
|
||||||
|
|
||||||
void setWindowTitleAddition(const QString &addition);
|
void setWindowTitleAddition(const QString &addition);
|
||||||
@@ -222,8 +213,8 @@ public slots:
|
|||||||
bool closeAllEditors(bool askAboutModifiedEditors = true);
|
bool closeAllEditors(bool askAboutModifiedEditors = true);
|
||||||
void openInExternalEditor();
|
void openInExternalEditor();
|
||||||
|
|
||||||
bool saveFile(Core::IEditor *editor = 0);
|
bool saveFile(Core::IFile *file = 0);
|
||||||
bool saveFileAs(Core::IEditor *editor = 0);
|
bool saveFileAs(Core::IFile *file = 0);
|
||||||
void revertToSaved();
|
void revertToSaved();
|
||||||
void closeEditor();
|
void closeEditor();
|
||||||
void closeOtherEditors();
|
void closeOtherEditors();
|
||||||
@@ -272,6 +263,7 @@ private:
|
|||||||
void emptyView(Core::Internal::EditorView *view);
|
void emptyView(Core::Internal::EditorView *view);
|
||||||
Core::Internal::EditorView *currentEditorView() const;
|
Core::Internal::EditorView *currentEditorView() const;
|
||||||
IEditor *pickUnusedEditor() const;
|
IEditor *pickUnusedEditor() const;
|
||||||
|
void addFileToRecentFiles(IFile *file);
|
||||||
|
|
||||||
static EditorManager *m_instance;
|
static EditorManager *m_instance;
|
||||||
EditorManagerPrivate *m_d;
|
EditorManagerPrivate *m_d;
|
||||||
|
|||||||
@@ -311,7 +311,7 @@ void EditorToolBar::listContextMenu(QPoint pos)
|
|||||||
void EditorToolBar::makeEditorWritable()
|
void EditorToolBar::makeEditorWritable()
|
||||||
{
|
{
|
||||||
if (currentEditor())
|
if (currentEditor())
|
||||||
ICore::instance()->editorManager()->makeEditorWritable(currentEditor());
|
ICore::instance()->editorManager()->makeFileWritable(currentEditor()->file());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorToolBar::setCanGoBack(bool canGoBack)
|
void EditorToolBar::setCanGoBack(bool canGoBack)
|
||||||
|
|||||||
@@ -53,6 +53,7 @@
|
|||||||
#include <QtGui/QFileDialog>
|
#include <QtGui/QFileDialog>
|
||||||
#include <QtGui/QMessageBox>
|
#include <QtGui/QMessageBox>
|
||||||
#include <QtGui/QMainWindow>
|
#include <QtGui/QMainWindow>
|
||||||
|
#include <QtGui/QPushButton>
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class Core::FileManager
|
\class Core::FileManager
|
||||||
@@ -107,8 +108,9 @@ struct FileState
|
|||||||
|
|
||||||
|
|
||||||
struct FileManagerPrivate {
|
struct FileManagerPrivate {
|
||||||
explicit FileManagerPrivate(QObject *q, QMainWindow *mw);
|
explicit FileManagerPrivate(FileManager *q, QMainWindow *mw);
|
||||||
|
|
||||||
|
static FileManager *m_instance;
|
||||||
QMap<QString, FileState> m_states;
|
QMap<QString, FileState> m_states;
|
||||||
QStringList m_changedFiles;
|
QStringList m_changedFiles;
|
||||||
QList<IFile *> m_filesWithoutWatch;
|
QList<IFile *> m_filesWithoutWatch;
|
||||||
@@ -133,7 +135,9 @@ struct FileManagerPrivate {
|
|||||||
IFile *m_blockedIFile;
|
IFile *m_blockedIFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
FileManagerPrivate::FileManagerPrivate(QObject *q, QMainWindow *mw) :
|
FileManager *FileManagerPrivate::m_instance = 0;
|
||||||
|
|
||||||
|
FileManagerPrivate::FileManagerPrivate(FileManager *q, QMainWindow *mw) :
|
||||||
m_mainWindow(mw),
|
m_mainWindow(mw),
|
||||||
m_fileWatcher(new QFileSystemWatcher(q)),
|
m_fileWatcher(new QFileSystemWatcher(q)),
|
||||||
m_blockActivated(false),
|
m_blockActivated(false),
|
||||||
@@ -145,6 +149,7 @@ FileManagerPrivate::FileManagerPrivate(QObject *q, QMainWindow *mw) :
|
|||||||
#endif
|
#endif
|
||||||
m_blockedIFile(0)
|
m_blockedIFile(0)
|
||||||
{
|
{
|
||||||
|
m_instance = q;
|
||||||
q->connect(m_fileWatcher, SIGNAL(fileChanged(QString)),
|
q->connect(m_fileWatcher, SIGNAL(fileChanged(QString)),
|
||||||
q, SLOT(changedFile(QString)));
|
q, SLOT(changedFile(QString)));
|
||||||
#ifdef Q_OS_UNIX
|
#ifdef Q_OS_UNIX
|
||||||
@@ -177,6 +182,11 @@ FileManager::~FileManager()
|
|||||||
delete d;
|
delete d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileManager *FileManager::instance()
|
||||||
|
{
|
||||||
|
return Internal::FileManagerPrivate::m_instance;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn bool FileManager::addFiles(const QList<IFile *> &files, bool addWatcher)
|
\fn bool FileManager::addFiles(const QList<IFile *> &files, bool addWatcher)
|
||||||
|
|
||||||
@@ -300,7 +310,7 @@ void FileManager::dump()
|
|||||||
information to avoid annoying the user with "file has been removed"
|
information to avoid annoying the user with "file has been removed"
|
||||||
popups.
|
popups.
|
||||||
*/
|
*/
|
||||||
void FileManager::renamedFile(const QString &from, QString &to)
|
void FileManager::renamedFile(const QString &from, const QString &to)
|
||||||
{
|
{
|
||||||
const QString &fixedFrom = fixFileName(from, KeepLinks);
|
const QString &fixedFrom = fixFileName(from, KeepLinks);
|
||||||
|
|
||||||
@@ -793,6 +803,47 @@ QStringList FileManager::getOpenFileNames(const QString &filters,
|
|||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileManager::ReadOnlyAction
|
||||||
|
FileManager::promptReadOnlyFile(const QString &fileName,
|
||||||
|
const IVersionControl *versionControl,
|
||||||
|
QWidget *parent,
|
||||||
|
bool displaySaveAsButton)
|
||||||
|
{
|
||||||
|
// Version Control: If automatic open is desired, open right away.
|
||||||
|
bool promptVCS = false;
|
||||||
|
if (versionControl && versionControl->supportsOperation(IVersionControl::OpenOperation)) {
|
||||||
|
if (versionControl->settingsFlags() & IVersionControl::AutoOpen)
|
||||||
|
return RO_OpenVCS;
|
||||||
|
promptVCS = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create message box.
|
||||||
|
QMessageBox msgBox(QMessageBox::Question, tr("File is Read Only"),
|
||||||
|
tr("The file <i>%1</i> is read only.").arg(QDir::toNativeSeparators(fileName)),
|
||||||
|
QMessageBox::Cancel, parent);
|
||||||
|
|
||||||
|
QPushButton *vcsButton = 0;
|
||||||
|
if (promptVCS)
|
||||||
|
vcsButton = msgBox.addButton(tr("Open with VCS (%1)").arg(versionControl->displayName()), QMessageBox::AcceptRole);
|
||||||
|
|
||||||
|
QPushButton *makeWritableButton = msgBox.addButton(tr("Make writable"), QMessageBox::AcceptRole);
|
||||||
|
|
||||||
|
QPushButton *saveAsButton = 0;
|
||||||
|
if (displaySaveAsButton)
|
||||||
|
saveAsButton = msgBox.addButton(tr("Save as ..."), QMessageBox::ActionRole);
|
||||||
|
|
||||||
|
msgBox.setDefaultButton(vcsButton ? vcsButton : makeWritableButton);
|
||||||
|
msgBox.exec();
|
||||||
|
|
||||||
|
QAbstractButton *clickedButton = msgBox.clickedButton();
|
||||||
|
if (clickedButton == vcsButton)
|
||||||
|
return RO_OpenVCS;
|
||||||
|
if (clickedButton == makeWritableButton)
|
||||||
|
return RO_MakeWriteable;
|
||||||
|
if (clickedButton == saveAsButton)
|
||||||
|
return RO_SaveAs;
|
||||||
|
return RO_Cancel;
|
||||||
|
}
|
||||||
|
|
||||||
void FileManager::changedFile(const QString &fileName)
|
void FileManager::changedFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ namespace Core {
|
|||||||
class ICore;
|
class ICore;
|
||||||
class IContext;
|
class IContext;
|
||||||
class IFile;
|
class IFile;
|
||||||
|
class IVersionControl;
|
||||||
|
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
struct FileManagerPrivate;
|
struct FileManagerPrivate;
|
||||||
@@ -61,13 +62,15 @@ public:
|
|||||||
explicit FileManager(QMainWindow *ew);
|
explicit FileManager(QMainWindow *ew);
|
||||||
virtual ~FileManager();
|
virtual ~FileManager();
|
||||||
|
|
||||||
|
static FileManager *instance();
|
||||||
|
|
||||||
// file pool to monitor
|
// file pool to monitor
|
||||||
void addFiles(const QList<IFile *> &files, bool addWatcher = true);
|
void addFiles(const QList<IFile *> &files, bool addWatcher = true);
|
||||||
void addFile(IFile *file, bool addWatcher = true);
|
void addFile(IFile *file, bool addWatcher = true);
|
||||||
void removeFile(IFile *file);
|
void removeFile(IFile *file);
|
||||||
QList<IFile *> modifiedFiles() const;
|
QList<IFile *> modifiedFiles() const;
|
||||||
|
|
||||||
void renamedFile(const QString &from, QString &to);
|
void renamedFile(const QString &from, const QString &to);
|
||||||
|
|
||||||
void blockFileChange(IFile *file);
|
void blockFileChange(IFile *file);
|
||||||
void unblockFileChange(IFile *file);
|
void unblockFileChange(IFile *file);
|
||||||
@@ -105,6 +108,14 @@ public:
|
|||||||
bool *alwaysSave = 0);
|
bool *alwaysSave = 0);
|
||||||
|
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
QString fileDialogLastVisitedDirectory() const;
|
QString fileDialogLastVisitedDirectory() const;
|
||||||
void setFileDialogLastVisitedDirectory(const QString &);
|
void setFileDialogLastVisitedDirectory(const QString &);
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
#include "mimedatabase.h"
|
#include "mimedatabase.h"
|
||||||
|
#include "coreconstants.h"
|
||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
@@ -1303,6 +1304,29 @@ QStringList MimeDatabase::filterStrings() const
|
|||||||
m_mutex.unlock();
|
m_mutex.unlock();
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
QString MimeDatabase::allFiltersString(QString *allFilesFilter) const
|
||||||
|
{
|
||||||
|
if (allFilesFilter)
|
||||||
|
allFilesFilter->clear();
|
||||||
|
|
||||||
|
// Compile list of filter strings, sort, and remove duplicates (different mime types might
|
||||||
|
// generate the same filter).
|
||||||
|
QStringList filters = filterStrings();
|
||||||
|
if (filters.empty())
|
||||||
|
return QString();
|
||||||
|
filters.sort();
|
||||||
|
filters.erase(std::unique(filters.begin(), filters.end()), filters.end());
|
||||||
|
|
||||||
|
static const QString allFiles =
|
||||||
|
QCoreApplication::translate("Core", Constants::ALL_FILES_FILTER);
|
||||||
|
if (allFilesFilter)
|
||||||
|
*allFilesFilter = allFiles;
|
||||||
|
|
||||||
|
// Prepend all files filter (instead of appending to work around a bug in Qt/Mac).
|
||||||
|
filters.prepend(allFiles);
|
||||||
|
|
||||||
|
return filters.join(QLatin1String(";;"));
|
||||||
|
}
|
||||||
|
|
||||||
QString MimeDatabase::preferredSuffixByType(const QString &type) const
|
QString MimeDatabase::preferredSuffixByType(const QString &type) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -271,6 +271,8 @@ public:
|
|||||||
|
|
||||||
friend QDebug operator<<(QDebug d, const MimeDatabase &mt);
|
friend QDebug operator<<(QDebug d, const MimeDatabase &mt);
|
||||||
|
|
||||||
|
// returns a string with all the possible file filters, for use with file dialogs
|
||||||
|
QString allFiltersString(QString *allFilesFilter = 0) const;
|
||||||
private:
|
private:
|
||||||
MimeType findByFileUnlocked(const QFileInfo &f) const;
|
MimeType findByFileUnlocked(const QFileInfo &f) const;
|
||||||
|
|
||||||
|
|||||||
@@ -937,14 +937,14 @@ bool Qt4PriFileNode::priFileWritable(const QString &path)
|
|||||||
const QString dir = QFileInfo(path).dir().path();
|
const QString dir = QFileInfo(path).dir().path();
|
||||||
Core::ICore *core = Core::ICore::instance();
|
Core::ICore *core = Core::ICore::instance();
|
||||||
Core::IVersionControl *versionControl = core->vcsManager()->findVersionControlForDirectory(dir);
|
Core::IVersionControl *versionControl = core->vcsManager()->findVersionControlForDirectory(dir);
|
||||||
switch (Core::EditorManager::promptReadOnlyFile(path, versionControl, core->mainWindow(), false)) {
|
switch (Core::FileManager::promptReadOnlyFile(path, versionControl, core->mainWindow(), false)) {
|
||||||
case Core::EditorManager::RO_OpenVCS:
|
case Core::FileManager::RO_OpenVCS:
|
||||||
if (!versionControl->vcsOpen(path)) {
|
if (!versionControl->vcsOpen(path)) {
|
||||||
QMessageBox::warning(core->mainWindow(), tr("Failed!"), tr("Could not open the file for edit with VCS."));
|
QMessageBox::warning(core->mainWindow(), tr("Failed!"), tr("Could not open the file for edit with VCS."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Core::EditorManager::RO_MakeWriteable: {
|
case Core::FileManager::RO_MakeWriteable: {
|
||||||
const bool permsOk = QFile::setPermissions(path, QFile::permissions(path) | QFile::WriteUser);
|
const bool permsOk = QFile::setPermissions(path, QFile::permissions(path) | QFile::WriteUser);
|
||||||
if (!permsOk) {
|
if (!permsOk) {
|
||||||
QMessageBox::warning(core->mainWindow(), tr("Failed!"), tr("Could not set permissions to writable."));
|
QMessageBox::warning(core->mainWindow(), tr("Failed!"), tr("Could not set permissions to writable."));
|
||||||
@@ -952,8 +952,8 @@ bool Qt4PriFileNode::priFileWritable(const QString &path)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Core::EditorManager::RO_SaveAs:
|
case Core::FileManager::RO_SaveAs:
|
||||||
case Core::EditorManager::RO_Cancel:
|
case Core::FileManager::RO_Cancel:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user