瀏覽代碼

LibGUI: Add clear_selection helper for ComboBox

This patch adds a helper to ComboBox allowing it to clear the current
selection and show a blank editor.
networkException 3 年之前
父節點
當前提交
84780f3ed5
共有 2 個文件被更改,包括 8 次插入0 次删除
  1. 7 0
      Userland/Libraries/LibGUI/ComboBox.cpp
  2. 1 0
      Userland/Libraries/LibGUI/ComboBox.h

+ 7 - 0
Userland/Libraries/LibGUI/ComboBox.cpp

@@ -200,6 +200,13 @@ void ComboBox::set_model(NonnullRefPtr<Model> model)
     m_list_view->set_model(move(model));
 }
 
+void ComboBox::clear_selection()
+{
+    m_selected_index.clear();
+    m_editor->clear_selection();
+    m_editor->clear();
+}
+
 void ComboBox::set_selected_index(size_t index, AllowCallback allow_callback)
 {
     if (!m_list_view->model())

+ 1 - 0
Userland/Libraries/LibGUI/ComboBox.h

@@ -33,6 +33,7 @@ public:
 
     size_t selected_index() const;
     void set_selected_index(size_t index, AllowCallback = AllowCallback::Yes);
+    void clear_selection();
 
     bool only_allow_values_from_model() const { return m_only_allow_values_from_model; }
     void set_only_allow_values_from_model(bool);