[nostalgia/studio] Add Copy/Paste hooks
This commit is contained in:
parent
b6c82c42f0
commit
fdda3bd82d
@ -13,6 +13,12 @@ namespace nostalgia::studio {
|
||||
Editor::Editor(QWidget *parent): QWidget(parent) {
|
||||
}
|
||||
|
||||
void Editor::copy() {
|
||||
}
|
||||
|
||||
void Editor::paste() {
|
||||
}
|
||||
|
||||
void Editor::exportFile() {
|
||||
}
|
||||
|
||||
@ -26,7 +32,7 @@ void Editor::setUnsavedChanges(bool uc) {
|
||||
emit unsavedChangesChanged(uc);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool Editor::unsavedChanges() noexcept {
|
||||
bool Editor::unsavedChanges() noexcept {
|
||||
return m_unsavedChanges;
|
||||
}
|
||||
|
||||
@ -43,6 +49,24 @@ bool Editor::exportable() const {
|
||||
return m_exportable;
|
||||
}
|
||||
|
||||
void Editor::setCopyEnabled(bool v) {
|
||||
m_copyEnabled = v;
|
||||
emit copyEnabledChanged(v);
|
||||
}
|
||||
|
||||
bool Editor::copyEnabled() const {
|
||||
return m_copyEnabled;
|
||||
}
|
||||
|
||||
void Editor::setPasteEnabled(bool v) {
|
||||
m_pasteEnabled = v;
|
||||
emit pasteEnabledChanged(v);
|
||||
}
|
||||
|
||||
bool Editor::pasteEnabled() const {
|
||||
return m_pasteEnabled;
|
||||
}
|
||||
|
||||
void Editor::saveItem() {
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,8 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget {
|
||||
QUndoStack m_cmdStack;
|
||||
bool m_unsavedChanges = false;
|
||||
bool m_exportable = false;
|
||||
bool m_copyEnabled = false;
|
||||
bool m_pasteEnabled = false;
|
||||
|
||||
public:
|
||||
Editor(QWidget *parent);
|
||||
@ -33,6 +35,10 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget {
|
||||
*/
|
||||
virtual QString itemName() const = 0;
|
||||
|
||||
virtual void copy();
|
||||
|
||||
virtual void paste();
|
||||
|
||||
virtual void exportFile();
|
||||
|
||||
/**
|
||||
@ -51,11 +57,19 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget {
|
||||
/**
|
||||
* Returns the undo stack holding changes to the item being edited.
|
||||
*/
|
||||
QUndoStack *undoStack();
|
||||
[[nodiscard]] QUndoStack *undoStack();
|
||||
|
||||
void setExportable(bool);
|
||||
|
||||
bool exportable() const;
|
||||
[[nodiscard]] bool exportable() const;
|
||||
|
||||
void setCopyEnabled(bool);
|
||||
|
||||
[[nodiscard]] bool copyEnabled() const;
|
||||
|
||||
void setPasteEnabled(bool);
|
||||
|
||||
[[nodiscard]] bool pasteEnabled() const;
|
||||
|
||||
protected:
|
||||
/**
|
||||
@ -68,6 +82,10 @@ class NOSTALGIASTUDIO_EXPORT Editor: public QWidget {
|
||||
|
||||
void exportableChanged(bool);
|
||||
|
||||
void copyEnabledChanged(bool);
|
||||
|
||||
void pasteEnabledChanged(bool);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -191,6 +191,30 @@ void MainWindow::setupMenu() {
|
||||
auto redoAction = m_undoGroup.createRedoAction(this, tr("&Redo"));
|
||||
editMenu->addAction(redoAction);
|
||||
redoAction->setShortcuts(QKeySequence::Redo);
|
||||
|
||||
editMenu->addSeparator();
|
||||
|
||||
// Copy
|
||||
m_copyAction = addAction(
|
||||
editMenu,
|
||||
tr("&Copy"),
|
||||
tr(""),
|
||||
QKeySequence::Copy,
|
||||
this,
|
||||
SLOT(copyAction())
|
||||
);
|
||||
m_copyAction->setEnabled(false);
|
||||
|
||||
// Paste
|
||||
m_pasteAction = addAction(
|
||||
editMenu,
|
||||
tr("&Paste"),
|
||||
tr(""),
|
||||
QKeySequence::Paste,
|
||||
this,
|
||||
SLOT(pasteAction())
|
||||
);
|
||||
m_pasteAction->setEnabled(false);
|
||||
}
|
||||
|
||||
void MainWindow::setupProjectExplorer() {
|
||||
@ -476,6 +500,14 @@ void MainWindow::exportFile() {
|
||||
m_currentEditor->exportFile();
|
||||
}
|
||||
|
||||
void MainWindow::copyAction() {
|
||||
m_currentEditor->copy();
|
||||
}
|
||||
|
||||
void MainWindow::pasteAction() {
|
||||
m_currentEditor->paste();
|
||||
}
|
||||
|
||||
void MainWindow::closeTab(int idx) {
|
||||
auto tab = static_cast<studio::Editor*>(m_tabs->widget(idx));
|
||||
m_undoGroup.removeStack(tab->undoStack());
|
||||
@ -501,12 +533,16 @@ void MainWindow::changeTab(int idx) {
|
||||
disconnect(m_currentEditor, &Editor::unsavedChangesChanged, m_saveAction, &QAction::setEnabled);
|
||||
disconnect(m_currentEditor, &Editor::unsavedChangesChanged, this, &MainWindow::markUnsavedChanges);
|
||||
disconnect(m_currentEditor, &Editor::exportableChanged, m_exportAction, &QAction::setEnabled);
|
||||
disconnect(m_currentEditor, &Editor::copyEnabledChanged, m_copyAction, &QAction::setEnabled);
|
||||
disconnect(m_currentEditor, &Editor::pasteEnabledChanged, m_pasteAction, &QAction::setEnabled);
|
||||
}
|
||||
m_currentEditor = tab;
|
||||
if (m_currentEditor) {
|
||||
m_saveAction->setEnabled(m_currentEditor->unsavedChanges());
|
||||
connect(m_currentEditor, &Editor::unsavedChangesChanged, m_saveAction, &QAction::setEnabled);
|
||||
connect(m_currentEditor, &Editor::unsavedChangesChanged, this, &MainWindow::markUnsavedChanges);
|
||||
connect(m_currentEditor, &Editor::copyEnabledChanged, m_copyAction, &QAction::setEnabled);
|
||||
connect(m_currentEditor, &Editor::pasteEnabledChanged, m_pasteAction, &QAction::setEnabled);
|
||||
m_exportAction->setEnabled(m_currentEditor->exportable());
|
||||
connect(m_currentEditor, &Editor::exportableChanged, m_exportAction, &QAction::setEnabled);
|
||||
m_undoGroup.setActiveStack(tab->undoStack());
|
||||
|
@ -75,6 +75,8 @@ class MainWindow: public QMainWindow {
|
||||
QAction *m_importAction = nullptr;
|
||||
QAction *m_saveAction = nullptr;
|
||||
QAction *m_exportAction = nullptr;
|
||||
QAction *m_copyAction = nullptr;
|
||||
QAction *m_pasteAction = nullptr;
|
||||
Context m_ctx;
|
||||
QPointer<QMenu> m_viewMenu;
|
||||
QVector<QPointer<QDockWidget>> m_dockWidgets;
|
||||
@ -84,7 +86,7 @@ class MainWindow: public QMainWindow {
|
||||
QPointer<OxFSModel> m_oxfsView = nullptr;
|
||||
QTabWidget *m_tabs = nullptr;
|
||||
QUndoGroup m_undoGroup;
|
||||
Editor* m_currentEditor = nullptr;
|
||||
Editor *m_currentEditor = nullptr;
|
||||
|
||||
public:
|
||||
MainWindow(QString profilePath);
|
||||
@ -147,6 +149,10 @@ class MainWindow: public QMainWindow {
|
||||
|
||||
void exportFile();
|
||||
|
||||
void copyAction();
|
||||
|
||||
void pasteAction();
|
||||
|
||||
void closeTab(int idx);
|
||||
|
||||
void moveTab(int from, int to);
|
||||
|
Loading…
Reference in New Issue
Block a user