1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of Qt Creator. 7 ** 8 ** Commercial License Usage 9 ** Licensees holding valid commercial Qt licenses may use this file in 10 ** accordance with the commercial license agreement provided with the 11 ** Software or, alternatively, in accordance with the terms contained in 12 ** a written agreement between you and The Qt Company. For licensing terms 13 ** and conditions see https://www.qt.io/terms-conditions. For further 14 ** information use the contact form at https://www.qt.io/contact-us. 15 ** 16 ** GNU General Public License Usage 17 ** Alternatively, this file may be used under the terms of the GNU 18 ** General Public License version 3 as published by the Free Software 19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 20 ** included in the packaging of this file. Please review the following 21 ** information to ensure the GNU General Public License requirements will 22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 23 ** 24 ****************************************************************************/ 25 26 #pragma once 27 28 #include "../core_global.h" 29 30 #include <utils/fileutils.h> 31 #include <utils/id.h> 32 #include <utils/optional.h> 33 34 QT_BEGIN_NAMESPACE 35 class QAbstractItemModel; 36 class QIcon; 37 QT_END_NAMESPACE 38 39 namespace Core { 40 41 class IEditor; 42 class IDocument; 43 44 class CORE_EXPORT DocumentModel 45 { 46 public: 47 static void init(); 48 static void destroy(); 49 50 static QIcon lockedIcon(); 51 static QAbstractItemModel *model(); 52 53 struct CORE_EXPORT Entry { 54 Entry(); 55 ~Entry(); 56 Utils::FilePath fileName() const; 57 QString displayName() const; 58 QString plainDisplayName() const; 59 QString uniqueDisplayName() const; 60 Utils::Id id() const; 61 62 IDocument *document; 63 // When an entry is suspended, it means that it is not in memory, 64 // and there is no IEditor for it and only a dummy IDocument. 65 // This is typically the case for files that have not been opened yet, 66 // but can also happen later after they have been opened. 67 // The related setting for this is found in: 68 // Options > Environment > System > Auto-suspend unmodified files 69 bool isSuspended; 70 // The entry has been pinned, which means that it should stick to 71 // the top of any lists of open files, and that any actions that close 72 // files in bulk should not close this one. 73 bool pinned; 74 }; 75 76 static Entry *entryAtRow(int row); 77 static Utils::optional<int> rowOfDocument(IDocument *document); 78 79 static int entryCount(); 80 static QList<Entry *> entries(); 81 static Utils::optional<int> indexOfDocument(IDocument *document); 82 static Utils::optional<int> indexOfFilePath(const Utils::FilePath &filePath); 83 static Entry *entryForDocument(IDocument *document); 84 static Entry *entryForFilePath(const Utils::FilePath &filePath); 85 static QList<IDocument *> openedDocuments(); 86 87 static IDocument *documentForFilePath(const Utils::FilePath &filePath); 88 static QList<IEditor *> editorsForFilePath(const Utils::FilePath &filePath); 89 static QList<IEditor *> editorsForDocument(IDocument *document); 90 static QList<IEditor *> editorsForDocuments(const QList<IDocument *> &entries); 91 static QList<IEditor *> editorsForOpenedDocuments(); 92 93 private: 94 DocumentModel(); 95 }; 96 97 } // namespace Core 98 99 Q_DECLARE_METATYPE(Core::DocumentModel::Entry *) 100