RedPanda-CPP/RedPandaIDE/editorlist.h

108 lines
3.1 KiB
C
Raw Normal View History

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
class Project;
2021-04-07 21:13:15 +08:00
class Editor;
class EditorList : public QObject
2021-04-06 23:10:57 +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,
QWidget* panel, QObject* parent = nullptr);
2021-04-06 23:10:57 +08:00
Editor* newEditor(const QString& filename, const QByteArray& encoding,
Project *pProject, bool newFile,
QTabWidget* page=nullptr);
2021-04-07 21:13:15 +08:00
Editor* getEditor(int index=-1, QTabWidget* tabsWidget=nullptr) const;
2021-04-07 22:44:08 +08:00
bool closeEditor(Editor* editor, bool transferFocus=true, bool force=false);
2021-04-07 22:44:08 +08:00
bool swapEditor(Editor* editor);
void saveAll();
bool saveAllForProject();
bool projectEditorsModified();
void clearProjectEditorsModified();
2021-04-09 10:08:05 +08:00
bool closeAll(bool force = false);
bool closeOthers(Editor* editor);
2021-04-09 10:08:05 +08:00
2021-09-07 16:49:35 +08:00
void forceCloseEditor(Editor* editor);
Editor* getOpenedEditorByFilename(QString filename) const;
2021-04-29 20:54:44 +08:00
bool getContentFromOpenedEditor(const QString& filename, QStringList& buffer) const;
2021-08-23 10:16:06 +08:00
void getVisibleEditors(Editor*& left, Editor*& right) const;
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);
bool isFileOpened(const QString& fullfilepath) const;
bool hasFilename(const QString& filename) const;
int pageCount() const;
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;
signals:
void editorClosed();
void editorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave);
void editorOpenned();
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);
void doRemoveEditor(Editor* e);
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