Explorar el Código

LibGUI: Allow blocking CommandPalette/EmojiInput on a per Window basis

Instead of having to negate every focusable widget or textbox, let
windows override all their widgets. These two Dialogs now block
themselves and each other.
thankyouverycool hace 2 años
padre
commit
f8e65d24cf

+ 2 - 0
Userland/Libraries/LibGUI/CommandPalette.cpp

@@ -176,6 +176,8 @@ CommandPalette::CommandPalette(GUI::Window& parent_window, ScreenPosition screen
     : GUI::Dialog(&parent_window, screen_position)
     : GUI::Dialog(&parent_window, screen_position)
 {
 {
     set_frameless(true);
     set_frameless(true);
+    set_blocks_command_palette(true);
+    set_blocks_emoji_input(true);
     resize(450, 300);
     resize(450, 300);
 
 
     collect_actions(parent_window);
     collect_actions(parent_window);

+ 3 - 3
Userland/Libraries/LibGUI/ConnectionToWindowServer.cpp

@@ -193,7 +193,7 @@ void ConnectionToWindowServer::key_down(i32 window_id, u32 code_point, u32 key,
     }
     }
 
 
     bool focused_widget_accepts_emoji_input = window->focused_widget() && window->focused_widget()->accepts_emoji_input();
     bool focused_widget_accepts_emoji_input = window->focused_widget() && window->focused_widget()->accepts_emoji_input();
-    if (focused_widget_accepts_emoji_input && (modifiers == (Mod_Ctrl | Mod_Alt)) && key == Key_Space) {
+    if (!window->blocks_emoji_input() && focused_widget_accepts_emoji_input && (modifiers == (Mod_Ctrl | Mod_Alt)) && key == Key_Space) {
         auto emoji_input_dialog = EmojiInputDialog::construct(window);
         auto emoji_input_dialog = EmojiInputDialog::construct(window);
         emoji_input_dialog->set_window_mode(GUI::WindowMode::Passive);
         emoji_input_dialog->set_window_mode(GUI::WindowMode::Passive);
         if (emoji_input_dialog->exec() != EmojiInputDialog::ExecResult::OK)
         if (emoji_input_dialog->exec() != EmojiInputDialog::ExecResult::OK)
@@ -207,8 +207,8 @@ void ConnectionToWindowServer::key_down(i32 window_id, u32 code_point, u32 key,
         key_event->m_code_point = emoji_code_point;
         key_event->m_code_point = emoji_code_point;
     }
     }
 
 
-    bool accepts_command_palette = true;
-    if (window->focused_widget())
+    bool accepts_command_palette = !window->blocks_command_palette();
+    if (accepts_command_palette && window->focused_widget())
         accepts_command_palette = window->focused_widget()->accepts_command_palette();
         accepts_command_palette = window->focused_widget()->accepts_command_palette();
 
 
     // FIXME: This shortcut should be configurable.
     // FIXME: This shortcut should be configurable.

+ 2 - 0
Userland/Libraries/LibGUI/EmojiInputDialog.cpp

@@ -53,6 +53,8 @@ EmojiInputDialog::EmojiInputDialog(Window* parent_window)
         VERIFY_NOT_REACHED();
         VERIFY_NOT_REACHED();
 
 
     set_frameless(true);
     set_frameless(true);
+    set_blocks_command_palette(true);
+    set_blocks_emoji_input(true);
     resize(400, 300);
     resize(400, 300);
 
 
     auto& scrollable_container = *main_widget.find_descendant_of_type_named<GUI::ScrollableContainerWidget>("scrollable_container"sv);
     auto& scrollable_container = *main_widget.find_descendant_of_type_named<GUI::ScrollableContainerWidget>("scrollable_container"sv);

+ 5 - 0
Userland/Libraries/LibGUI/TextEditor.cpp

@@ -775,6 +775,9 @@ void TextEditor::select_all()
 
 
 void TextEditor::insert_emoji()
 void TextEditor::insert_emoji()
 {
 {
+    if (!accepts_emoji_input() || window()->blocks_emoji_input())
+        return;
+
     auto emoji_input_dialog = EmojiInputDialog::construct(window());
     auto emoji_input_dialog = EmojiInputDialog::construct(window());
     emoji_input_dialog->set_window_mode(GUI::WindowMode::Passive);
     emoji_input_dialog->set_window_mode(GUI::WindowMode::Passive);
     if (emoji_input_dialog->exec() != EmojiInputDialog::ExecResult::OK)
     if (emoji_input_dialog->exec() != EmojiInputDialog::ExecResult::OK)
@@ -1722,6 +1725,8 @@ void TextEditor::context_menu_event(ContextMenuEvent& event)
     if (is_displayonly())
     if (is_displayonly())
         return;
         return;
 
 
+    m_insert_emoji_action->set_enabled(accepts_emoji_input() && !window()->blocks_emoji_input());
+
     if (!m_context_menu) {
     if (!m_context_menu) {
         m_context_menu = Menu::construct();
         m_context_menu = Menu::construct();
         m_context_menu->add_action(undo_action());
         m_context_menu->add_action(undo_action());

+ 8 - 0
Userland/Libraries/LibGUI/Window.h

@@ -225,6 +225,12 @@ public:
     Menubar& menubar() { return *m_menubar; }
     Menubar& menubar() { return *m_menubar; }
     Menubar const& menubar() const { return *m_menubar; }
     Menubar const& menubar() const { return *m_menubar; }
 
 
+    void set_blocks_command_palette(bool b) { m_blocks_command_palette = b; }
+    bool blocks_command_palette() const { return m_blocks_command_palette; }
+
+    void set_blocks_emoji_input(bool b) { m_blocks_emoji_input = b; }
+    bool blocks_emoji_input() const { return m_blocks_emoji_input; }
+
 protected:
 protected:
     Window(Core::Object* parent = nullptr);
     Window(Core::Object* parent = nullptr);
     virtual void wm_event(WMEvent&);
     virtual void wm_event(WMEvent&);
@@ -307,6 +313,8 @@ private:
     bool m_visible_for_timer_purposes { true };
     bool m_visible_for_timer_purposes { true };
     bool m_visible { false };
     bool m_visible { false };
     bool m_moved_by_client { false };
     bool m_moved_by_client { false };
+    bool m_blocks_command_palette { false };
+    bool m_blocks_emoji_input { false };
 };
 };
 
 
 }
 }