Compare commits
No commits in common. "69f3e28f2c49664f9ad6f6c581ebb9c70e3838cf" and "1176e64a7c490eae4aca7b00aabdbdb2a83900a2" have entirely different histories.
69f3e28f2c
...
1176e64a7c
@ -98,6 +98,24 @@ Result<ui::EventResult> EditorWidget::handle_key_event(const ui::KeyEventRequest
|
||||
return ui::EventResult::DidHandle;
|
||||
}
|
||||
|
||||
if (request.modifiers & ui::Mod_Ctrl)
|
||||
{
|
||||
switch (request.key)
|
||||
{
|
||||
case 's': {
|
||||
auto result = save_file();
|
||||
if (result.has_error())
|
||||
{
|
||||
os::eprintln("editor: failed to save file: %s", result.error_string());
|
||||
return ui::EventResult::DidNotHandle;
|
||||
}
|
||||
os::println("editor: buffer saved to %s successfully", m_path.name().chars());
|
||||
return ui::EventResult::DidNotHandle;
|
||||
}
|
||||
default: return ui::EventResult::DidNotHandle;
|
||||
}
|
||||
}
|
||||
|
||||
if (request.code == moon::K_Backspace)
|
||||
{
|
||||
if (m_cursor == 0) return ui::EventResult::DidNotHandle;
|
||||
|
@ -26,11 +26,6 @@ class EditorWidget : public ui::TextInput
|
||||
|
||||
Result<void> draw(ui::Canvas& canvas) override;
|
||||
|
||||
os::Path& path()
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
|
||||
private:
|
||||
SharedPtr<ui::Font> m_font;
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
|
||||
#include "EditorWidget.h"
|
||||
#include <os/ArgumentParser.h>
|
||||
#include <os/File.h>
|
||||
#include <ui/App.h>
|
||||
|
||||
Result<int> luna_main(int argc, char** argv)
|
||||
@ -34,13 +33,6 @@ Result<int> luna_main(int argc, char** argv)
|
||||
window->set_main_widget(*editor);
|
||||
if (!path.is_empty()) TRY(editor->load_file(path));
|
||||
|
||||
TRY(window->add_keyboard_shortcut({ moon::K_CH26, ui::Mod_Ctrl }, true, [&](ui::Shortcut) {
|
||||
auto result = editor->save_file();
|
||||
if (result.has_error()) os::eprintln("editor: failed to save file: %s", result.error_string());
|
||||
else
|
||||
os::println("editor: buffer saved to %s successfully", editor->path().name().chars());
|
||||
}));
|
||||
|
||||
window->draw();
|
||||
|
||||
return app.run();
|
||||
|
@ -26,17 +26,6 @@ namespace ui
|
||||
System,
|
||||
};
|
||||
|
||||
struct [[gnu::packed]] Shortcut
|
||||
{
|
||||
moon::KeyCode key;
|
||||
int modifiers;
|
||||
|
||||
bool operator==(const Shortcut& other) const
|
||||
{
|
||||
return key == other.key && modifiers == other.modifiers;
|
||||
}
|
||||
};
|
||||
|
||||
class Window
|
||||
{
|
||||
public:
|
||||
@ -73,8 +62,6 @@ namespace ui
|
||||
Result<ui::EventResult> handle_mouse_buttons(ui::Point position, int buttons);
|
||||
Result<ui::EventResult> handle_key_event(const ui::KeyEventRequest& request);
|
||||
|
||||
Result<void> add_keyboard_shortcut(ui::Shortcut shortcut, bool intercept, os::Function<ui::Shortcut>&& action);
|
||||
|
||||
int id() const
|
||||
{
|
||||
return m_id;
|
||||
@ -93,14 +80,6 @@ namespace ui
|
||||
Option<int> m_old_mouse_buttons;
|
||||
bool m_decorated { false };
|
||||
|
||||
struct ShortcutAction
|
||||
{
|
||||
bool intercept;
|
||||
os::Function<Shortcut> action;
|
||||
};
|
||||
|
||||
HashMap<Shortcut, ShortcutAction> m_shortcuts;
|
||||
|
||||
Result<void> draw_titlebar();
|
||||
};
|
||||
}
|
||||
|
@ -212,25 +212,7 @@ namespace ui
|
||||
|
||||
Result<ui::EventResult> Window::handle_key_event(const ui::KeyEventRequest& request)
|
||||
{
|
||||
if (request.pressed)
|
||||
{
|
||||
auto* shortcut = m_shortcuts.try_get_ref({ request.code, request.modifiers });
|
||||
if (shortcut)
|
||||
{
|
||||
shortcut->action({ request.code, request.modifiers });
|
||||
if (shortcut->intercept) return ui::EventResult::DidHandle;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_main_widget) return ui::EventResult::DidNotHandle;
|
||||
return m_main_widget->handle_key_event(request);
|
||||
}
|
||||
|
||||
Result<void> Window::add_keyboard_shortcut(ui::Shortcut shortcut, bool intercept,
|
||||
os::Function<ui::Shortcut>&& action)
|
||||
{
|
||||
TRY(m_shortcuts.try_set(shortcut, { intercept, move(action) }));
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user