Browse Source

LibGUI: Allow widgets to opt-out from showing the command palette

Sam Atkins 3 năm trước cách đây
mục cha
commit
bf4328de52

+ 4 - 0
Userland/Libraries/LibGUI/Widget.h

@@ -283,6 +283,9 @@ public:
     void set_accepts_emoji_input(bool b) { m_accepts_emoji_input = b; }
     bool accepts_emoji_input() const { return m_accepts_emoji_input; }
 
+    void set_accepts_command_palette(bool b) { m_accepts_command_palette = b; }
+    bool accepts_command_palette() const { return m_accepts_command_palette; }
+
     virtual Gfx::IntRect children_clip_rect() const;
 
     AK::Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> override_cursor() const { return m_override_cursor; }
@@ -378,6 +381,7 @@ private:
     bool m_enabled { true };
     bool m_updates_enabled { true };
     bool m_accepts_emoji_input { false };
+    bool m_accepts_command_palette { true };
     bool m_shrink_to_fit { false };
     bool m_default_font { true };
 

+ 2 - 1
Userland/Libraries/LibGUI/WindowServerConnection.cpp

@@ -196,7 +196,8 @@ void WindowServerConnection::key_down(i32 window_id, u32 code_point, u32 key, u3
     }
 
     // FIXME: This shortcut should be configurable.
-    if (!m_in_command_palette && modifiers == (Mod_Ctrl | Mod_Shift) && key == Key_A) {
+    bool focused_widget_accepts_command_palette = window->focused_widget() && window->focused_widget()->accepts_command_palette();
+    if (focused_widget_accepts_command_palette && !m_in_command_palette && modifiers == (Mod_Ctrl | Mod_Shift) && key == Key_A) {
         auto command_palette = CommandPalette::construct(*window);
         TemporaryChange change { m_in_command_palette, true };
         if (command_palette->exec() != GUI::Dialog::ExecOK)