[nostalgia/studio] Add Copy/Paste hooks

This commit is contained in:
2020-10-19 19:36:23 -05:00
parent b6c82c42f0
commit fdda3bd82d
4 changed files with 88 additions and 4 deletions
+36
View File
@@ -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());