[nostalgia/studio] Add keyboard shortcuts

This commit is contained in:
2022-03-20 02:08:54 -05:00
parent ea318bb6c8
commit d76d525054
3 changed files with 84 additions and 6 deletions
+65 -4
View File
@@ -9,6 +9,7 @@
#include "lib/configio.hpp"
#include "builtinmodules.hpp"
#include "filedialogmanager.hpp"
#include "nostalgia/core/input.hpp"
#include "studioapp.hpp"
namespace nostalgia {
@@ -56,6 +57,42 @@ void StudioUI::update() noexcept {
m_taskRunner.update(m_ctx);
}
void StudioUI::handleKeyEvent(core::Key key, bool down) noexcept {
if (down && core::buttonDown(m_ctx, core::Key::Mod_Ctrl)) {
switch (key) {
case core::Key::Num_1:
toggleProjectExplorer();
break;
case core::Key::Alpha_C:
m_acitveEditor->copy();
break;
case core::Key::Alpha_O:
m_taskRunner.add(new FileDialogManager(this, &StudioUI::openProject));
break;
case core::Key::Alpha_Q:
oxIgnoreError(core::shutdown(m_ctx));
break;
case core::Key::Alpha_S:
save();
break;
case core::Key::Alpha_V:
m_acitveEditor->paste();
break;
case core::Key::Alpha_X:
m_acitveEditor->cut();
break;
case core::Key::Alpha_Y:
redo();
break;
case core::Key::Alpha_Z:
undo();
break;
default:
break;
}
}
}
void StudioUI::draw() noexcept {
drawMenu();
drawToolbar();
@@ -110,10 +147,7 @@ void StudioUI::drawMenu() noexcept {
}
if (ImGui::BeginMenu("View")) {
if (ImGui::MenuItem("Project Explorer", "Ctrl+1", m_showProjectExplorer)) {
m_showProjectExplorer = !m_showProjectExplorer;
studio::editConfig<StudioConfig>(m_ctx, [&](StudioConfig *config) {
config->showProjectExplorer = m_showProjectExplorer;
});
toggleProjectExplorer();
}
ImGui::EndMenu();
}
@@ -230,6 +264,33 @@ void StudioUI::loadModules() noexcept {
}
}
void StudioUI::toggleProjectExplorer() noexcept {
m_showProjectExplorer = !m_showProjectExplorer;
studio::editConfig<StudioConfig>(m_ctx, [&](StudioConfig *config) {
config->showProjectExplorer = m_showProjectExplorer;
});
}
void StudioUI::redo() noexcept {
auto undoStack = m_acitveEditor ? m_acitveEditor->undoStack() : nullptr;
if (undoStack && undoStack->canRedo()) {
m_acitveEditor->undoStack()->redo();
}
}
void StudioUI::undo() noexcept {
auto undoStack = m_acitveEditor ? m_acitveEditor->undoStack() : nullptr;
if (undoStack && undoStack->canUndo()) {
m_acitveEditor->undoStack()->undo();
}
}
void StudioUI::save() noexcept {
if (m_acitveEditor && m_acitveEditor->unsavedChanges()) {
m_acitveEditor->save();
}
}
ox::Error StudioUI::openProject(const ox::String &path) noexcept {
oxRequireM(fs, core::loadRomFs(path.c_str()));
m_ctx->rom = std::move(fs);