2021-12-26 23:18:28 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-04-06 23:10:57 +08:00
|
|
|
#ifndef EDITORLIST_H
|
|
|
|
#define EDITORLIST_H
|
|
|
|
|
|
|
|
#include <QTabWidget>
|
|
|
|
#include <QSplitter>
|
|
|
|
#include <QWidget>
|
2021-04-07 21:13:15 +08:00
|
|
|
#include "utils.h"
|
2021-04-06 23:10:57 +08:00
|
|
|
|
2022-10-09 22:19:18 +08:00
|
|
|
class Project;
|
2021-04-07 21:13:15 +08:00
|
|
|
class Editor;
|
2021-11-02 23:47:51 +08:00
|
|
|
class EditorList : public QObject
|
2021-04-06 23:10:57 +08:00
|
|
|
{
|
2021-11-02 23:47:51 +08:00
|
|
|
Q_OBJECT
|
2021-04-06 23:10:57 +08:00
|
|
|
public:
|
2021-09-07 16:49:35 +08:00
|
|
|
enum class LayoutShowType{
|
2021-04-06 23:10:57 +08:00
|
|
|
lstLeft,
|
|
|
|
lstRight,
|
|
|
|
lstBoth
|
|
|
|
};
|
|
|
|
|
2021-04-07 21:13:15 +08:00
|
|
|
explicit EditorList(QTabWidget* leftPageWidget,
|
|
|
|
QTabWidget* rightPageWidget,
|
|
|
|
QSplitter* splitter,
|
2021-11-02 23:47:51 +08:00
|
|
|
QWidget* panel, QObject* parent = nullptr);
|
2021-04-06 23:10:57 +08:00
|
|
|
|
2021-04-08 10:29:21 +08:00
|
|
|
Editor* newEditor(const QString& filename, const QByteArray& encoding,
|
2022-10-09 22:19:18 +08:00
|
|
|
Project *pProject, bool newFile,
|
2021-10-13 11:32:59 +08:00
|
|
|
QTabWidget* page=nullptr);
|
2021-04-07 21:13:15 +08:00
|
|
|
|
2021-10-13 11:32:59 +08:00
|
|
|
Editor* getEditor(int index=-1, QTabWidget* tabsWidget=nullptr) const;
|
2021-04-07 22:44:08 +08:00
|
|
|
|
2021-04-08 10:29:21 +08:00
|
|
|
bool closeEditor(Editor* editor, bool transferFocus=true, bool force=false);
|
2021-04-07 22:44:08 +08:00
|
|
|
|
2021-10-13 11:32:59 +08:00
|
|
|
bool swapEditor(Editor* editor);
|
|
|
|
|
2022-10-21 12:43:02 +08:00
|
|
|
void saveAll();
|
|
|
|
bool saveAllForProject();
|
|
|
|
|
|
|
|
bool projectEditorsModified();
|
|
|
|
void clearProjectEditorsModified();
|
|
|
|
|
2021-04-09 10:08:05 +08:00
|
|
|
bool closeAll(bool force = false);
|
|
|
|
|
2021-09-07 16:49:35 +08:00
|
|
|
void forceCloseEditor(Editor* editor);
|
|
|
|
|
2021-10-22 16:43:53 +08:00
|
|
|
Editor* getOpenedEditorByFilename(QString filename);
|
2021-04-29 20:54:44 +08:00
|
|
|
|
2021-08-23 10:16:06 +08:00
|
|
|
bool getContentFromOpenedEditor(const QString& filename, QStringList& buffer);
|
|
|
|
|
2021-09-11 09:21:44 +08:00
|
|
|
void getVisibleEditors(Editor*& left, Editor*& right);
|
2021-09-07 16:49:35 +08:00
|
|
|
void updateLayout();
|
|
|
|
|
2021-04-09 10:08:05 +08:00
|
|
|
void beginUpdate();
|
|
|
|
void endUpdate();
|
2021-06-07 11:02:03 +08:00
|
|
|
void applySettings();
|
2021-06-20 14:30:47 +08:00
|
|
|
void applyColorSchemes(const QString& name);
|
2021-06-23 22:38:02 +08:00
|
|
|
bool isFileOpened(const QString& name);
|
2021-07-26 00:22:08 +08:00
|
|
|
int pageCount();
|
2021-09-03 00:26:49 +08:00
|
|
|
void selectNextPage();
|
|
|
|
void selectPreviousPage();
|
2021-07-26 00:22:08 +08:00
|
|
|
|
|
|
|
Editor* operator[](int index);
|
2021-04-09 10:08:05 +08:00
|
|
|
|
2021-10-20 18:05:43 +08:00
|
|
|
QTabWidget *leftPageWidget() const;
|
|
|
|
|
|
|
|
QTabWidget *rightPageWidget() const;
|
|
|
|
|
2021-11-02 23:47:51 +08:00
|
|
|
signals:
|
|
|
|
void editorClosed();
|
2022-01-02 10:37:00 +08:00
|
|
|
void editorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave);
|
2021-11-02 23:47:51 +08:00
|
|
|
|
2021-04-07 21:13:15 +08:00
|
|
|
private:
|
2021-04-09 10:08:05 +08:00
|
|
|
QTabWidget* getNewEditorPageControl() const;
|
|
|
|
QTabWidget* getFocusedPageControl() const;
|
2021-09-07 16:49:35 +08:00
|
|
|
void showLayout(LayoutShowType layout);
|
2022-01-02 10:37:00 +08:00
|
|
|
private slots:
|
|
|
|
void onEditorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave);
|
2021-04-06 23:10:57 +08:00
|
|
|
private:
|
2021-09-07 16:49:35 +08:00
|
|
|
LayoutShowType mLayout;
|
2021-04-06 23:10:57 +08:00
|
|
|
QTabWidget *mLeftPageWidget;
|
|
|
|
QTabWidget *mRightPageWidget;
|
|
|
|
QSplitter *mSplitter;
|
|
|
|
QWidget *mPanel;
|
|
|
|
int mUpdateCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // EDITORLIST_H
|