mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 13:37:44 +00:00
LibGUI: Don't use Core::Object::add() to instantiate dialogs
Now that add() returns a WidgetType&, we can't rely on the parent of a GUI::Dialog to still keep it alive after exec() returns. This happens because exec() will call remove_from_parent() on itself before returning. And so we go back to the old idiom for creating a GUI::Dialog centered above a specific window. Just call GUI::Dialog::construct(), passing the "parent" window as the last parameter.
This commit is contained in:
parent
dfa69b82b4
commit
b29ff7b821
18 changed files with 43 additions and 43 deletions
|
@ -36,8 +36,8 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, bool disable_rename, Core::Object* parent)
|
||||
: Dialog(parent)
|
||||
PropertiesDialog::PropertiesDialog(GUI::FileSystemModel& model, String path, bool disable_rename, Window* parent_window)
|
||||
: Dialog(parent_window)
|
||||
, m_model(model)
|
||||
{
|
||||
auto file_path = FileSystemPath(path);
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
virtual ~PropertiesDialog() override;
|
||||
|
||||
private:
|
||||
PropertiesDialog(GUI::FileSystemModel&, String, bool disable_rename, Core::Object* parent = nullptr);
|
||||
PropertiesDialog(GUI::FileSystemModel&, String, bool disable_rename, Window* parent = nullptr);
|
||||
|
||||
struct PropertyValuePair {
|
||||
String property;
|
||||
|
|
|
@ -171,12 +171,12 @@ int main(int argc, char** argv)
|
|||
});
|
||||
|
||||
auto mkdir_action = GUI::Action::create("New directory...", { Mod_Ctrl | Mod_Shift, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/mkdir.png"), [&](const GUI::Action&) {
|
||||
auto& input_box = window->add<GUI::InputBox>("Enter name:", "New directory");
|
||||
if (input_box.exec() == GUI::InputBox::ExecOK && !input_box.text_value().is_empty()) {
|
||||
auto input_box = GUI::InputBox::construct("Enter name:", "New directory", window);
|
||||
if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) {
|
||||
auto new_dir_path = canonicalized_path(
|
||||
String::format("%s/%s",
|
||||
directory_view.path().characters(),
|
||||
input_box.text_value().characters()));
|
||||
input_box->text_value().characters()));
|
||||
int rc = mkdir(new_dir_path.characters(), 0777);
|
||||
if (rc < 0) {
|
||||
GUI::MessageBox::show(String::format("mkdir(\"%s\") failed: %s", new_dir_path.characters(), strerror(errno)), "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window);
|
||||
|
|
|
@ -78,7 +78,7 @@ HexEditorWidget::HexEditorWidget()
|
|||
m_save_action->activate();
|
||||
}
|
||||
|
||||
auto input_box = GUI::InputBox::construct("Enter new file size:", "New file size", this);
|
||||
auto input_box = GUI::InputBox::construct("Enter new file size:", "New file size", window());
|
||||
if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) {
|
||||
auto valid = false;
|
||||
auto file_size = input_box->text_value().to_int(valid);
|
||||
|
@ -154,7 +154,7 @@ HexEditorWidget::HexEditorWidget()
|
|||
}
|
||||
|
||||
m_goto_decimal_offset_action = GUI::Action::create("Go To Offset (Decimal)...", { Mod_Ctrl | Mod_Shift, Key_G }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](const GUI::Action&) {
|
||||
auto input_box = GUI::InputBox::construct("Enter Decimal offset:", "Go To", this);
|
||||
auto input_box = GUI::InputBox::construct("Enter Decimal offset:", "Go To", window());
|
||||
if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) {
|
||||
auto valid = false;
|
||||
auto new_offset = input_box->text_value().to_int(valid);
|
||||
|
@ -165,7 +165,7 @@ HexEditorWidget::HexEditorWidget()
|
|||
});
|
||||
|
||||
m_goto_hex_offset_action = GUI::Action::create("Go To Offset (Hex)...", { Mod_Ctrl, Key_G }, Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"), [this](const GUI::Action&) {
|
||||
auto input_box = GUI::InputBox::construct("Enter Hex offset:", "Go To", this);
|
||||
auto input_box = GUI::InputBox::construct("Enter Hex offset:", "Go To", window());
|
||||
if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) {
|
||||
auto new_offset = strtol(input_box->text_value().characters(), nullptr, 16);
|
||||
m_editor->set_position(new_offset);
|
||||
|
@ -174,7 +174,7 @@ HexEditorWidget::HexEditorWidget()
|
|||
|
||||
auto edit_menu = GUI::Menu::construct("Edit");
|
||||
edit_menu->add_action(GUI::Action::create("Fill selection...", { Mod_Ctrl, Key_B }, [&](const GUI::Action&) {
|
||||
auto input_box = GUI::InputBox::construct("Fill byte (hex):", "Fill Selection", this);
|
||||
auto input_box = GUI::InputBox::construct("Fill byte (hex):", "Fill Selection", window());
|
||||
if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty()) {
|
||||
auto fill_byte = strtol(input_box->text_value().characters(), nullptr, 16);
|
||||
m_editor->fill_selection(fill_byte);
|
||||
|
|
|
@ -94,12 +94,12 @@ void IRCAppWindow::setup_client()
|
|||
};
|
||||
|
||||
if (m_client->hostname().is_empty()) {
|
||||
auto& input_box = add<GUI::InputBox>("Enter server:", "Connect to server");
|
||||
auto result = input_box.exec();
|
||||
auto input_box = GUI::InputBox::construct("Enter server:", "Connect to server", this);
|
||||
auto result = input_box->exec();
|
||||
if (result == GUI::InputBox::ExecCancel)
|
||||
::exit(0);
|
||||
|
||||
m_client->set_server(input_box.text_value(), 6667);
|
||||
m_client->set_server(input_box->text_value(), 6667);
|
||||
}
|
||||
update_title();
|
||||
bool success = m_client->connect();
|
||||
|
@ -109,9 +109,9 @@ void IRCAppWindow::setup_client()
|
|||
void IRCAppWindow::setup_actions()
|
||||
{
|
||||
m_join_action = GUI::Action::create("Join channel", { Mod_Ctrl, Key_J }, Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-join.png"), [&](auto&) {
|
||||
auto& input_box = add<GUI::InputBox>("Enter channel name:", "Join channel");
|
||||
if (input_box.exec() == GUI::InputBox::ExecOK && !input_box.text_value().is_empty())
|
||||
m_client->handle_join_action(input_box.text_value());
|
||||
auto input_box = GUI::InputBox::construct("Enter channel name:", "Join channel", this);
|
||||
if (input_box->exec() == GUI::InputBox::ExecOK && !input_box->text_value().is_empty())
|
||||
m_client->handle_join_action(input_box->text_value());
|
||||
});
|
||||
|
||||
m_part_action = GUI::Action::create("Part from channel", { Mod_Ctrl, Key_P }, Gfx::Bitmap::load_from_file("/res/icons/16x16/irc-part.png"), [this](auto&) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue