Просмотр исходного кода

LibGUI: Get rid of GWindow's destroy-on-close mechanism

Since we're moving to a world of ref-counting, we can't have weird
behaviors like "windows delete themselves when you close them."

The "close app when there are no more windows" mechanism is moved
to GWindow::hide(). Now, we close the app when it has no more
windows on screen.
Andreas Kling 5 лет назад
Родитель
Сommit
870bc2a4d1
3 измененных файлов с 11 добавлено и 10 удалено
  1. 0 1
      Libraries/LibGUI/GComboBox.cpp
  2. 11 5
      Libraries/LibGUI/GWindow.cpp
  3. 0 4
      Libraries/LibGUI/GWindow.h

+ 0 - 1
Libraries/LibGUI/GComboBox.cpp

@@ -31,7 +31,6 @@ GComboBox::GComboBox(GWidget* parent)
     m_list_window = GWindow::construct(this);
     // FIXME: This is obviously not a tooltip window, but it's the closest thing to what we want atm.
     m_list_window->set_window_type(GWindowType::Tooltip);
-    m_list_window->set_should_destroy_on_close(false);
 
     m_list_view = GListView::construct(nullptr);
     m_list_view->horizontal_scrollbar().set_visible(false);

+ 11 - 5
Libraries/LibGUI/GWindow.cpp

@@ -38,15 +38,11 @@ GWindow::~GWindow()
 {
     all_windows.remove(this);
     hide();
-    if (all_windows.is_empty()) {
-        GApplication::the().did_delete_last_window({});
-    }
 }
 
 void GWindow::close()
 {
-    if (should_destroy_on_close())
-        delete_later();
+    hide();
 }
 
 void GWindow::move_to_front()
@@ -104,6 +100,16 @@ void GWindow::hide()
     m_pending_paint_event_rects.clear();
     m_back_bitmap = nullptr;
     m_front_bitmap = nullptr;
+
+    bool app_has_visible_windows = false;
+    for (auto& window : all_windows) {
+        if (window->is_visible()) {
+            app_has_visible_windows = true;
+            break;
+        }
+    }
+    if (!app_has_visible_windows)
+        GApplication::the().did_delete_last_window({});
 }
 
 void GWindow::set_title(const StringView& title)

+ 0 - 4
Libraries/LibGUI/GWindow.h

@@ -53,9 +53,6 @@ public:
     Color background_color() const { return m_background_color; }
     void set_background_color(Color color) { m_background_color = color; }
 
-    bool should_destroy_on_close() { return m_destroy_on_close; }
-    void set_should_destroy_on_close(bool b) { m_destroy_on_close = b; }
-
     enum class CloseRequestDecision {
         StayOpen,
         Close,
@@ -167,7 +164,6 @@ private:
     Color m_background_color { Color::WarmGray };
     GWindowType m_window_type { GWindowType::Normal };
     bool m_is_active { false };
-    bool m_destroy_on_close { true };
     bool m_has_alpha_channel { false };
     bool m_double_buffering_enabled { true };
     bool m_modal { false };