feat: multitab and basic file saving
This commit is contained in:
57
tabwidget.h
Normal file
57
tabwidget.h
Normal file
@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <QTabWidget>
|
||||
#include <QHash>
|
||||
|
||||
class SciEdit;
|
||||
class DocumentManager;
|
||||
|
||||
class TabWidget : public QTabWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TabWidget(DocumentManager *documentManager, QWidget *parent = nullptr);
|
||||
~TabWidget();
|
||||
|
||||
// 标签页管理
|
||||
int newDocument();
|
||||
int openDocument(const QString &filePath);
|
||||
bool saveCurrentDocument();
|
||||
bool saveCurrentDocumentAs();
|
||||
void closeCurrentTab();
|
||||
bool closeTab(int index);
|
||||
void closeAllTabs();
|
||||
|
||||
// 获取当前编辑器和文档信息
|
||||
SciEdit *currentEditor() const;
|
||||
SciEdit *editorAt(int index) const;
|
||||
int currentDocumentId() const;
|
||||
int documentIdAt(int index) const;
|
||||
|
||||
// 标签页操作
|
||||
void setCurrentTab(int index);
|
||||
int findTabByDocumentId(int docId) const;
|
||||
|
||||
signals:
|
||||
void currentEditorChanged(SciEdit *editor);
|
||||
void tabCloseRequested(int index);
|
||||
|
||||
private slots:
|
||||
void onCurrentChanged(int index);
|
||||
void onTabCloseRequested(int index);
|
||||
void onDocumentModified(int docId, bool modified);
|
||||
void onDocumentTitleChanged(int docId, const QString &title);
|
||||
void onEditorTextChanged();
|
||||
|
||||
private:
|
||||
DocumentManager *m_documentManager;
|
||||
QHash<int, int> m_tabToDocumentId; // tab index -> document id
|
||||
QHash<int, int> m_documentIdToTab; // document id -> tab index
|
||||
QHash<int, SciEdit*> m_editors; // document id -> editor
|
||||
|
||||
SciEdit *createEditor();
|
||||
void updateTabTitle(int tabIndex);
|
||||
void connectEditorSignals(SciEdit *editor);
|
||||
void disconnectEditorSignals(SciEdit *editor);
|
||||
};
|
Reference in New Issue
Block a user