1 | /* |
2 | * Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com) |
3 | * |
4 | * This program is free software: you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation, either version 3 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | */ |
17 | #ifndef EDITORLIST_H |
18 | #define EDITORLIST_H |
19 | |
20 | #include <QTabWidget> |
21 | #include <QSplitter> |
22 | #include <QWidget> |
23 | #include "utils.h" |
24 | |
25 | class Editor; |
26 | class EditorList : public QObject |
27 | { |
28 | Q_OBJECT |
29 | public: |
30 | enum class LayoutShowType{ |
31 | lstLeft, |
32 | lstRight, |
33 | lstBoth |
34 | }; |
35 | |
36 | explicit EditorList(QTabWidget* leftPageWidget, |
37 | QTabWidget* rightPageWidget, |
38 | QSplitter* splitter, |
39 | QWidget* panel, QObject* parent = nullptr); |
40 | |
41 | Editor* newEditor(const QString& filename, const QByteArray& encoding, |
42 | bool inProject, bool newFile, |
43 | QTabWidget* page=nullptr); |
44 | |
45 | Editor* getEditor(int index=-1, QTabWidget* tabsWidget=nullptr) const; |
46 | |
47 | bool closeEditor(Editor* editor, bool transferFocus=true, bool force=false); |
48 | |
49 | bool swapEditor(Editor* editor); |
50 | |
51 | bool closeAll(bool force = false); |
52 | |
53 | void forceCloseEditor(Editor* editor); |
54 | |
55 | Editor* getOpenedEditorByFilename(QString filename); |
56 | |
57 | Editor* getEditorByFilename(QString filename); |
58 | |
59 | bool getContentFromOpenedEditor(const QString& filename, QStringList& buffer); |
60 | |
61 | void getVisibleEditors(Editor*& left, Editor*& right); |
62 | void updateLayout(); |
63 | |
64 | void beginUpdate(); |
65 | void endUpdate(); |
66 | void applySettings(); |
67 | void applyColorSchemes(const QString& name); |
68 | bool isFileOpened(const QString& name); |
69 | int pageCount(); |
70 | void selectNextPage(); |
71 | void selectPreviousPage(); |
72 | |
73 | Editor* operator[](int index); |
74 | |
75 | QTabWidget *leftPageWidget() const; |
76 | |
77 | QTabWidget *rightPageWidget() const; |
78 | |
79 | signals: |
80 | void editorClosed(); |
81 | void editorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave); |
82 | |
83 | private: |
84 | QTabWidget* getNewEditorPageControl() const; |
85 | QTabWidget* getFocusedPageControl() const; |
86 | void showLayout(LayoutShowType layout); |
87 | private slots: |
88 | void onEditorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave); |
89 | private: |
90 | LayoutShowType mLayout; |
91 | QTabWidget *mLeftPageWidget; |
92 | QTabWidget *mRightPageWidget; |
93 | QSplitter *mSplitter; |
94 | QWidget *mPanel; |
95 | int mUpdateCount; |
96 | |
97 | |
98 | |
99 | }; |
100 | |
101 | #endif // EDITORLIST_H |
102 | |