[nostalgia/studio] Add keyboard shortcuts
This commit is contained in:
parent
ea318bb6c8
commit
d76d525054
@ -23,17 +23,24 @@ class StudioUIDrawer: public core::Drawer {
|
||||
}
|
||||
};
|
||||
|
||||
static int eventHandler(core::Context *ctx) noexcept {
|
||||
static int updateHandler(core::Context *ctx) noexcept {
|
||||
auto sctx = core::applicationData<studio::StudioContext>(ctx);
|
||||
auto ui = dynamic_cast<StudioUI*>(sctx->ui);
|
||||
ui->update();
|
||||
return 16;
|
||||
}
|
||||
|
||||
static void keyEventHandler(core::Context *ctx, core::Key key, bool down) noexcept {
|
||||
auto sctx = core::applicationData<studio::StudioContext>(ctx);
|
||||
auto ui = dynamic_cast<StudioUI*>(sctx->ui);
|
||||
ui->handleKeyEvent(key, down);
|
||||
}
|
||||
|
||||
static ox::Error run(ox::UniquePtr<ox::FileSystem> fs) noexcept {
|
||||
oxRequireM(ctx, core::init(std::move(fs), "NostalgiaStudio"));
|
||||
core::setWindowTitle(ctx.get(), "Nostalgia Studio");
|
||||
core::setUpdateHandler(ctx.get(), eventHandler);
|
||||
core::setUpdateHandler(ctx.get(), updateHandler);
|
||||
core::setKeyEventHandler(ctx.get(), keyEventHandler);
|
||||
core::setConstantRefresh(ctx.get(), false);
|
||||
studio::StudioContext studioCtx;
|
||||
core::setApplicationData(ctx.get(), &studioCtx);
|
||||
|
@ -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);
|
||||
|
@ -39,6 +39,8 @@ class StudioUI: public ox::SignalHandler {
|
||||
|
||||
void update() noexcept;
|
||||
|
||||
void handleKeyEvent(core::Key, bool down) noexcept;
|
||||
|
||||
constexpr auto project() noexcept {
|
||||
return m_project.get();
|
||||
}
|
||||
@ -63,6 +65,14 @@ class StudioUI: public ox::SignalHandler {
|
||||
|
||||
void loadModules() noexcept;
|
||||
|
||||
void toggleProjectExplorer() noexcept;
|
||||
|
||||
void redo() noexcept;
|
||||
|
||||
void undo() noexcept;
|
||||
|
||||
void save() noexcept;
|
||||
|
||||
ox::Error openProject(const ox::String &path) noexcept;
|
||||
|
||||
ox::Error openFile(const ox::String &path) noexcept;
|
||||
|
Loading…
Reference in New Issue
Block a user