summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/FontEditor/FontEditor.cpp49
-rw-r--r--Userland/Applications/FontEditor/FontEditor.h5
-rw-r--r--Userland/Libraries/LibGUI/GlyphMapWidget.cpp12
-rw-r--r--Userland/Libraries/LibGUI/GlyphMapWidget.h2
4 files changed, 59 insertions, 9 deletions
diff --git a/Userland/Applications/FontEditor/FontEditor.cpp b/Userland/Applications/FontEditor/FontEditor.cpp
index 3a9167813a..a6a0e1bd4e 100644
--- a/Userland/Applications/FontEditor/FontEditor.cpp
+++ b/Userland/Applications/FontEditor/FontEditor.cpp
@@ -203,6 +203,15 @@ FontEditorWidget::FontEditorWidget()
m_redo_action = GUI::CommonActions::make_redo_action([&](auto&) {
redo();
});
+
+ m_select_all_action = GUI::CommonActions::make_select_all_action([this](auto&) {
+ m_glyph_map_widget->set_selection(m_range.first, m_range.last - m_range.first + 1);
+ m_glyph_map_widget->update();
+ auto selection = m_glyph_map_widget->selection().normalized();
+ m_undo_selection->set_start(selection.start());
+ m_undo_selection->set_size(selection.size());
+ });
+
m_open_preview_action = GUI::Action::create("&Preview Font", { Mod_Ctrl, Key_P }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/find.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
if (!m_font_preview_window)
m_font_preview_window = create_font_preview_window(*this);
@@ -326,11 +335,17 @@ FontEditorWidget::FontEditorWidget()
m_glyph_editor_widget->flip_vertically();
});
- m_copy_character_action = GUI::Action::create("Cop&y as Character", { Mod_Ctrl | Mod_Shift, Key_C }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-copy.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
- StringBuilder glyph_builder;
- glyph_builder.append_code_point(m_glyph_editor_widget->glyph());
- GUI::Clipboard::the().set_plain_text(glyph_builder.build());
+ m_copy_text_action = GUI::Action::create("Copy as Te&xt", { Mod_Ctrl, Key_T }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-copy.png").release_value_but_fixme_should_propagate_errors(), [&](auto&) {
+ StringBuilder builder;
+ auto selection = m_glyph_map_widget->selection().normalized();
+ for (auto code_point = selection.start(); code_point < selection.start() + selection.size(); ++code_point) {
+ if (!m_glyph_map_widget->font().contains_glyph(code_point))
+ continue;
+ builder.append_code_point(code_point);
+ }
+ GUI::Clipboard::the().set_plain_text(builder.to_string());
});
+ m_copy_text_action->set_status_tip("Copy to clipboard as text");
glyph_transform_toolbar.add_action(*m_flip_horizontal_action);
glyph_transform_toolbar.add_action(*m_flip_vertical_action);
@@ -367,6 +382,21 @@ FontEditorWidget::FontEditorWidget()
update_statusbar();
};
+ m_glyph_map_widget->on_context_menu_request = [this](auto& event) {
+ if (!m_context_menu) {
+ m_context_menu = GUI::Menu::construct();
+ m_context_menu->add_action(*m_cut_action);
+ m_context_menu->add_action(*m_copy_action);
+ m_context_menu->add_action(*m_paste_action);
+ m_context_menu->add_action(*m_delete_action);
+ m_context_menu->add_separator();
+ m_context_menu->add_action(*m_select_all_action);
+ m_context_menu->add_separator();
+ m_context_menu->add_action(*m_copy_text_action);
+ }
+ m_context_menu->popup(event.screen_position());
+ };
+
m_name_textbox->on_change = [&] {
m_edited_font->set_name(m_name_textbox->text());
did_modify_font();
@@ -602,11 +632,14 @@ void FontEditorWidget::initialize_menubar(GUI::Window& window)
edit_menu.add_action(*m_paste_action);
edit_menu.add_action(*m_delete_action);
edit_menu.add_separator();
- edit_menu.add_action(*m_copy_character_action);
+ edit_menu.add_action(*m_select_all_action);
edit_menu.add_separator();
- edit_menu.add_action(*m_previous_glyph_action);
- edit_menu.add_action(*m_next_glyph_action);
- edit_menu.add_action(*m_go_to_glyph_action);
+ edit_menu.add_action(*m_copy_text_action);
+
+ auto& go_menu = window.add_menu("&Go");
+ go_menu.add_action(*m_previous_glyph_action);
+ go_menu.add_action(*m_next_glyph_action);
+ go_menu.add_action(*m_go_to_glyph_action);
auto& view_menu = window.add_menu("&View");
view_menu.add_action(*m_open_preview_action);
diff --git a/Userland/Applications/FontEditor/FontEditor.h b/Userland/Applications/FontEditor/FontEditor.h
index d55b2f0980..53c7101fb6 100644
--- a/Userland/Applications/FontEditor/FontEditor.h
+++ b/Userland/Applications/FontEditor/FontEditor.h
@@ -77,6 +77,9 @@ private:
RefPtr<GUI::Action> m_paste_action;
RefPtr<GUI::Action> m_delete_action;
+ RefPtr<GUI::Action> m_copy_text_action;
+ RefPtr<GUI::Action> m_select_all_action;
+
RefPtr<GUI::Action> m_undo_action;
RefPtr<GUI::Action> m_redo_action;
RefPtr<UndoSelection> m_undo_selection;
@@ -103,7 +106,6 @@ private:
RefPtr<GUI::Action> m_flip_vertical_action;
RefPtr<GUI::Action> m_rotate_clockwise_action;
RefPtr<GUI::Action> m_rotate_counterclockwise_action;
- RefPtr<GUI::Action> m_copy_character_action;
RefPtr<GUI::Statusbar> m_statusbar;
RefPtr<GUI::Window> m_font_preview_window;
@@ -126,6 +128,7 @@ private:
RefPtr<GUI::ListView> m_unicode_block_listview;
RefPtr<GUI::Model> m_unicode_block_model;
RefPtr<GUI::FilteringProxyModel> m_filter_model;
+ RefPtr<GUI::Menu> m_context_menu;
String m_path;
Vector<String> m_font_weight_list;
diff --git a/Userland/Libraries/LibGUI/GlyphMapWidget.cpp b/Userland/Libraries/LibGUI/GlyphMapWidget.cpp
index b529f7c7df..2ae04e1325 100644
--- a/Userland/Libraries/LibGUI/GlyphMapWidget.cpp
+++ b/Userland/Libraries/LibGUI/GlyphMapWidget.cpp
@@ -182,8 +182,17 @@ int GlyphMapWidget::glyph_at_position_clamped(Gfx::IntPoint position) const
return glyph;
}
+void GlyphMapWidget::context_menu_event(GUI::ContextMenuEvent& event)
+{
+ if (on_context_menu_request)
+ on_context_menu_request(event);
+}
+
void GlyphMapWidget::mousedown_event(MouseEvent& event)
{
+ if (event.button() == MouseButton::Secondary)
+ return;
+
if (auto maybe_glyph = glyph_at_position(event.position()); maybe_glyph.has_value()) {
auto glyph = maybe_glyph.value();
if (event.shift())
@@ -196,6 +205,9 @@ void GlyphMapWidget::mousedown_event(MouseEvent& event)
void GlyphMapWidget::mouseup_event(GUI::MouseEvent& event)
{
+ if (event.button() == MouseButton::Secondary)
+ return;
+
if (!m_in_drag_select)
return;
auto constrained = event.position().constrained(widget_inner_rect());
diff --git a/Userland/Libraries/LibGUI/GlyphMapWidget.h b/Userland/Libraries/LibGUI/GlyphMapWidget.h
index 66afecf806..d72a2345de 100644
--- a/Userland/Libraries/LibGUI/GlyphMapWidget.h
+++ b/Userland/Libraries/LibGUI/GlyphMapWidget.h
@@ -68,6 +68,7 @@ public:
Function<void(int)> on_active_glyph_changed;
Function<void(int)> on_glyph_double_clicked;
+ Function<void(ContextMenuEvent&)> on_context_menu_request;
private:
GlyphMapWidget();
@@ -79,6 +80,7 @@ private:
virtual void keydown_event(KeyEvent&) override;
virtual void resize_event(ResizeEvent&) override;
virtual void did_change_font() override;
+ virtual void context_menu_event(ContextMenuEvent&) override;
Gfx::IntRect get_outer_rect(int glyph) const;
Optional<int> glyph_at_position(Gfx::IntPoint) const;