From 2bf7abcb283c250781fa4fe9e255c5dbfd9b7b04 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 11 Jan 2022 20:52:03 +0000 Subject: [PATCH] CharacterMap: Add previous, next, and go-to glyph buttons These work the same as in FontEditor, where I shamelessly stole them from. :^) --- .../CharacterMap/CharacterMapWidget.cpp | 31 +++++++++++++++++++ .../CharacterMap/CharacterMapWidget.h | 3 ++ 2 files changed, 34 insertions(+) diff --git a/Userland/Applications/CharacterMap/CharacterMapWidget.cpp b/Userland/Applications/CharacterMap/CharacterMapWidget.cpp index c35e9162f2..553b1326e1 100644 --- a/Userland/Applications/CharacterMap/CharacterMapWidget.cpp +++ b/Userland/Applications/CharacterMap/CharacterMapWidget.cpp @@ -5,6 +5,7 @@ */ #include "CharacterMapWidget.h" +#include #include #include #include @@ -12,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -48,10 +50,39 @@ CharacterMapWidget::CharacterMapWidget() } GUI::Clipboard::the().set_plain_text(builder.to_string()); }); + m_copy_selection_action->set_status_tip("Copy the highlighted characters to the clipboard"); + + m_previous_glyph_action = GUI::Action::create("Previous character", { Mod_Alt, Key_Left }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-back.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) { + m_glyph_map->select_previous_existing_glyph(); + }); + m_previous_glyph_action->set_status_tip("Seek the previous visible glyph"); + + m_next_glyph_action = GUI::Action::create("&Next Glyph", { Mod_Alt, Key_Right }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-forward.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) { + m_glyph_map->select_next_existing_glyph(); + }); + m_next_glyph_action->set_status_tip("Seek the next visible glyph"); + + m_go_to_glyph_action = GUI::Action::create("Go to glyph...", { Mod_Ctrl, Key_G }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/go-to.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) { + String input; + if (GUI::InputBox::show(window(), input, "Hexadecimal:", "Go to glyph") == GUI::InputBox::ExecOK && !input.is_empty()) { + auto maybe_code_point = AK::StringUtils::convert_to_uint_from_hex(input); + if (!maybe_code_point.has_value()) + return; + auto code_point = clamp(maybe_code_point.value(), 0x0000, 0x10FFFF); + m_glyph_map->set_focus(true); + m_glyph_map->set_active_glyph(code_point); + m_glyph_map->scroll_to_glyph(code_point); + } + }); + m_go_to_glyph_action->set_status_tip("Go to the specified code point"); m_toolbar->add_action(*m_choose_font_action); m_toolbar->add_separator(); m_toolbar->add_action(*m_copy_selection_action); + m_toolbar->add_separator(); + m_toolbar->add_action(*m_previous_glyph_action); + m_toolbar->add_action(*m_next_glyph_action); + m_toolbar->add_action(*m_go_to_glyph_action); m_glyph_map->on_active_glyph_changed = [&](int) { update_statusbar(); diff --git a/Userland/Applications/CharacterMap/CharacterMapWidget.h b/Userland/Applications/CharacterMap/CharacterMapWidget.h index 2af5f93c5d..0b57a35a01 100644 --- a/Userland/Applications/CharacterMap/CharacterMapWidget.h +++ b/Userland/Applications/CharacterMap/CharacterMapWidget.h @@ -33,4 +33,7 @@ private: RefPtr m_choose_font_action; RefPtr m_copy_selection_action; + RefPtr m_previous_glyph_action; + RefPtr m_next_glyph_action; + RefPtr m_go_to_glyph_action; };