aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-11-16 12:14:47 +0800
committerYuqian Yang <crupest@crupest.life>2025-11-16 12:14:47 +0800
commitfaf73c4af74bdae1abf394a33b573149b98ec2b1 (patch)
treeaa985593c35a256e7190eddf47e023962a717ade /src
parent4e0b7d82cd64ef8016dcb49247a8a5e4de8a0b3d (diff)
downloadcru-faf73c4af74bdae1abf394a33b573149b98ec2b1.tar.gz
cru-faf73c4af74bdae1abf394a33b573149b98ec2b1.tar.bz2
cru-faf73c4af74bdae1abf394a33b573149b98ec2b1.zip
Clean DeleteLater.
Diffstat (limited to 'src')
-rw-r--r--src/ThemeBuilder/components/StyleRuleSetEditor.cpp2
-rw-r--r--src/ThemeBuilder/components/conditions/CompoundConditionEditor.cpp8
-rw-r--r--src/ThemeBuilder/components/stylers/CompoundStylerEditor.cpp5
-rw-r--r--src/ui/DeleteLater.cpp8
-rw-r--r--src/ui/controls/TextHostControlService.cpp4
-rw-r--r--src/ui/host/WindowHost.cpp1
6 files changed, 16 insertions, 12 deletions
diff --git a/src/ThemeBuilder/components/StyleRuleSetEditor.cpp b/src/ThemeBuilder/components/StyleRuleSetEditor.cpp
index a2dd3177..f2509f4f 100644
--- a/src/ThemeBuilder/components/StyleRuleSetEditor.cpp
+++ b/src/ThemeBuilder/components/StyleRuleSetEditor.cpp
@@ -66,7 +66,7 @@ void StyleRuleSetEditor::UpdateView(
for (auto i = change->position; i < change->position + change->count;
++i) {
const auto& rule = style_rule_set->GetStyleRule(i);
- auto style_rule_editor = ui::MakeDeleteLaterPtr<StyleRuleEditor>();
+ auto style_rule_editor = ui::MakeDeleteLater<StyleRuleEditor>();
style_rule_editor->SetValue(rule, false);
style_rule_editor->RemoveEvent()->AddSpyOnlyHandler(
[this, editor = style_rule_editor.get()] {
diff --git a/src/ThemeBuilder/components/conditions/CompoundConditionEditor.cpp b/src/ThemeBuilder/components/conditions/CompoundConditionEditor.cpp
index d01ceca0..b9b1fdef 100644
--- a/src/ThemeBuilder/components/conditions/CompoundConditionEditor.cpp
+++ b/src/ThemeBuilder/components/conditions/CompoundConditionEditor.cpp
@@ -7,6 +7,7 @@
#include "cru/base/ClonePtr.h"
#include "cru/platform/Color.h"
#include "cru/ui/Base.h"
+#include "cru/ui/DeleteLater.h"
#include "cru/ui/ThemeManager.h"
#include "cru/ui/controls/FlexLayout.h"
#include "cru/ui/style/Condition.h"
@@ -67,7 +68,7 @@ CompoundConditionEditor::CompoundConditionEditor() {
this->children_container_.RemoveChildAt(index);
RaiseChangeEvent();
});
- children_.push_back(std::move(editor));
+ children_.push_back(ui::ToDeleteLaterPtr(std::move(editor)));
children_container_.AddChild(children_.back()->GetRootControl());
RaiseChangeEvent();
}
@@ -86,8 +87,7 @@ CompoundConditionEditor::GetChildren() {
}
void CompoundConditionEditor::SetChildren(
- std::vector<ClonePtr<ui::style::Condition>> children,
- bool trigger_change) {
+ std::vector<ClonePtr<ui::style::Condition>> children, bool trigger_change) {
children_container_.ClearChildren();
children_.clear();
for (const auto& condition : children) {
@@ -99,7 +99,7 @@ void CompoundConditionEditor::SetChildren(
this->children_container_.RemoveChildAt(index);
RaiseChangeEvent();
});
- children_.push_back(std::move(editor));
+ children_.push_back(ui::ToDeleteLaterPtr(std::move(editor)));
children_container_.AddChild(children_.back()->GetRootControl());
}
if (trigger_change) {
diff --git a/src/ThemeBuilder/components/stylers/CompoundStylerEditor.cpp b/src/ThemeBuilder/components/stylers/CompoundStylerEditor.cpp
index 15f4e912..1a20bf70 100644
--- a/src/ThemeBuilder/components/stylers/CompoundStylerEditor.cpp
+++ b/src/ThemeBuilder/components/stylers/CompoundStylerEditor.cpp
@@ -7,6 +7,7 @@
#include "PaddingStylerEditor.h"
#include "PreferredSizeStylerEditor.h"
#include "cru/base/ClonePtr.h"
+#include "cru/ui/DeleteLater.h"
#include "cru/ui/ThemeManager.h"
#include "cru/ui/style/Styler.h"
@@ -69,7 +70,7 @@ CompoundStylerEditor::CompoundStylerEditor() {
this->children_container_.RemoveChildAt(index);
RaiseChangeEvent();
});
- children_.push_back(std::move(editor));
+ children_.push_back(ui::ToDeleteLaterPtr(std::move(editor)));
children_container_.AddChild(editor->GetRootControl());
RaiseChangeEvent();
}
@@ -98,7 +99,7 @@ void CompoundStylerEditor::SetValue(ui::style::CompoundStyler* value,
this->children_container_.RemoveChildAt(index);
RaiseChangeEvent();
});
- children_.push_back(std::move(editor));
+ children_.push_back(ui::ToDeleteLaterPtr(std::move(editor)));
children_container_.AddChild(children_.back()->GetRootControl());
}
}
diff --git a/src/ui/DeleteLater.cpp b/src/ui/DeleteLater.cpp
index f8911ae1..499b9b34 100644
--- a/src/ui/DeleteLater.cpp
+++ b/src/ui/DeleteLater.cpp
@@ -4,10 +4,16 @@
#include "cru/platform/gui/UiApplication.h"
namespace cru::ui {
+
+DeleteLaterImpl::DeleteLaterImpl() : delete_later_scheduled_(false) {}
+
DeleteLaterImpl::~DeleteLaterImpl() {}
void DeleteLaterImpl::DeleteLater() {
- GetUiApplication()->SetImmediate([this] { delete this; });
+ if (!delete_later_scheduled_) {
+ GetUiApplication()->SetImmediate([this] { delete this; });
+ delete_later_scheduled_ = true;
+ }
}
void DeleteLaterImpl::OnPrepareDelete() {}
diff --git a/src/ui/controls/TextHostControlService.cpp b/src/ui/controls/TextHostControlService.cpp
index 3c38c454..235e6e6a 100644
--- a/src/ui/controls/TextHostControlService.cpp
+++ b/src/ui/controls/TextHostControlService.cpp
@@ -150,8 +150,6 @@ std::vector<TextControlMovePattern> TextControlMovePattern::kDefaultPatterns = {
TextHostControlService::TextHostControlService(Control* control)
: control_(control),
text_host_control_(dynamic_cast<ITextHostControl*>(control)) {
- context_menu_ = MakeDeleteLaterPtr<components::PopupMenu>();
-
SetUpShortcuts();
SetupOneHandler(&Control::MouseMoveEvent,
@@ -701,7 +699,7 @@ void TextHostControlService::SetUpShortcuts() {
void TextHostControlService::OpenContextMenu(const Point& position,
ContextMenuItem items) {
- context_menu_ = MakeDeleteLaterPtr<components::PopupMenu>();
+ context_menu_ = MakeDeleteLater<components::PopupMenu>();
auto menu = context_menu_->GetMenu();
if (items & ContextMenuItem::kSelectAll) {
menu->AddTextItem("Select All", [this] { this->SelectAll(); });
diff --git a/src/ui/host/WindowHost.cpp b/src/ui/host/WindowHost.cpp
index 7417740d..ec956bb4 100644
--- a/src/ui/host/WindowHost.cpp
+++ b/src/ui/host/WindowHost.cpp
@@ -4,7 +4,6 @@
#include "cru/base/Base.h"
#include "cru/base/log/Logger.h"
#include "cru/platform/graphics/Painter.h"
-#include "cru/platform/gui/InputMethod.h"
#include "cru/platform/gui/UiApplication.h"
#include "cru/platform/gui/Window.h"
#include "cru/ui/Base.h"