mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 08:32:43 +00:00 
			
		
		
		
	LibGUI: Don't create GMessageBox and GInputBox on the stack
We need to get rid of all instances of widgets-on-the-stack since that will no longer work in the ref-counting world.
This commit is contained in:
		
							parent
							
								
									defafd72bc
								
							
						
					
					
						commit
						31b38ed88f
					
				
					 7 changed files with 30 additions and 33 deletions
				
			
		|  | @ -92,12 +92,12 @@ int main(int argc, char** argv) | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     auto mkdir_action = GAction::create("New directory...", GraphicsBitmap::load_from_file("/res/icons/16x16/mkdir.png"), [&](const GAction&) { |     auto mkdir_action = GAction::create("New directory...", GraphicsBitmap::load_from_file("/res/icons/16x16/mkdir.png"), [&](const GAction&) { | ||||||
|         GInputBox input_box("Enter name:", "New directory", window); |         auto input_box = GInputBox::construct("Enter name:", "New directory", window); | ||||||
|         if (input_box.exec() == GInputBox::ExecOK && !input_box.text_value().is_empty()) { |         if (input_box->exec() == GInputBox::ExecOK && !input_box->text_value().is_empty()) { | ||||||
|             auto new_dir_path = canonicalized_path( |             auto new_dir_path = canonicalized_path( | ||||||
|                 String::format("%s/%s", |                 String::format("%s/%s", | ||||||
|                     directory_view->path().characters(), |                     directory_view->path().characters(), | ||||||
|                     input_box.text_value().characters())); |                     input_box->text_value().characters())); | ||||||
|             int rc = mkdir(new_dir_path.characters(), 0777); |             int rc = mkdir(new_dir_path.characters(), 0777); | ||||||
|             if (rc < 0) { |             if (rc < 0) { | ||||||
|                 GMessageBox::show(String::format("mkdir(\"%s\") failed: %s", new_dir_path.characters(), strerror(errno)), "Error", GMessageBox::Type::Error, GMessageBox::InputType::OK, window); |                 GMessageBox::show(String::format("mkdir(\"%s\") failed: %s", new_dir_path.characters(), strerror(errno)), "Error", GMessageBox::Type::Error, GMessageBox::InputType::OK, window); | ||||||
|  | @ -216,13 +216,12 @@ int main(int argc, char** argv) | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             if (confirm == ConfirmBeforeDelete::Yes) { |             if (confirm == ConfirmBeforeDelete::Yes) { | ||||||
|                 GMessageBox box( |                 auto result = GMessageBox::show( | ||||||
|                     message, |                     message, | ||||||
|                     "Confirm deletion", |                     "Confirm deletion", | ||||||
|                     GMessageBox::Type::Warning, |                     GMessageBox::Type::Warning, | ||||||
|                     GMessageBox::InputType::OKCancel, |                     GMessageBox::InputType::OKCancel, | ||||||
|                     window); |                     window); | ||||||
|                 auto result = box.exec(); |  | ||||||
|                 if (result == GMessageBox::ExecCancel) |                 if (result == GMessageBox::ExecCancel) | ||||||
|                     return; |                     return; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  | @ -68,12 +68,12 @@ void IRCAppWindow::setup_client() | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     if (m_client.hostname().is_empty()) { |     if (m_client.hostname().is_empty()) { | ||||||
|         GInputBox input_box("Enter server:", "Connect to server", this); |         auto input_box = GInputBox::construct("Enter server:", "Connect to server", this); | ||||||
|         auto result = input_box.exec(); |         auto result = input_box->exec(); | ||||||
|         if (result == GInputBox::ExecCancel) |         if (result == GInputBox::ExecCancel) | ||||||
|             ::exit(0); |             ::exit(0); | ||||||
| 
 | 
 | ||||||
|         m_client.set_server(input_box.text_value(), 6667); |         m_client.set_server(input_box->text_value(), 6667); | ||||||
|     } |     } | ||||||
|     update_title(); |     update_title(); | ||||||
|     bool success = m_client.connect(); |     bool success = m_client.connect(); | ||||||
|  | @ -83,9 +83,9 @@ void IRCAppWindow::setup_client() | ||||||
| void IRCAppWindow::setup_actions() | void IRCAppWindow::setup_actions() | ||||||
| { | { | ||||||
|     m_join_action = GAction::create("Join channel", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-join.png"), [&](auto&) { |     m_join_action = GAction::create("Join channel", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-join.png"), [&](auto&) { | ||||||
|         GInputBox input_box("Enter channel name:", "Join channel", this); |         auto input_box = GInputBox::construct("Enter channel name:", "Join channel", this); | ||||||
|         if (input_box.exec() == GInputBox::ExecOK && !input_box.text_value().is_empty()) |         if (input_box->exec() == GInputBox::ExecOK && !input_box->text_value().is_empty()) | ||||||
|             m_client.handle_join_action(input_box.text_value()); |             m_client.handle_join_action(input_box->text_value()); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     m_part_action = GAction::create("Part from channel", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-part.png"), [this](auto&) { |     m_part_action = GAction::create("Part from channel", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-part.png"), [this](auto&) { | ||||||
|  | @ -98,15 +98,15 @@ void IRCAppWindow::setup_actions() | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     m_whois_action = GAction::create("Whois user", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-whois.png"), [&](auto&) { |     m_whois_action = GAction::create("Whois user", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-whois.png"), [&](auto&) { | ||||||
|         GInputBox input_box("Enter nickname:", "IRC WHOIS lookup", this); |         auto input_box = GInputBox::construct("Enter nickname:", "IRC WHOIS lookup", this); | ||||||
|         if (input_box.exec() == GInputBox::ExecOK && !input_box.text_value().is_empty()) |         if (input_box->exec() == GInputBox::ExecOK && !input_box->text_value().is_empty()) | ||||||
|             m_client.handle_whois_action(input_box.text_value()); |             m_client.handle_whois_action(input_box->text_value()); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     m_open_query_action = GAction::create("Open query", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-open-query.png"), [&](auto&) { |     m_open_query_action = GAction::create("Open query", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-open-query.png"), [&](auto&) { | ||||||
|         GInputBox input_box("Enter nickname:", "Open IRC query with...", this); |         auto input_box = GInputBox::construct("Enter nickname:", "Open IRC query with...", this); | ||||||
|         if (input_box.exec() == GInputBox::ExecOK && !input_box.text_value().is_empty()) |         if (input_box->exec() == GInputBox::ExecOK && !input_box->text_value().is_empty()) | ||||||
|             m_client.handle_open_query_action(input_box.text_value()); |             m_client.handle_open_query_action(input_box->text_value()); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     m_close_query_action = GAction::create("Close query", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-close-query.png"), [](auto&) { |     m_close_query_action = GAction::create("Close query", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-close-query.png"), [](auto&) { | ||||||
|  | @ -114,9 +114,9 @@ void IRCAppWindow::setup_actions() | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     m_change_nick_action = GAction::create("Change nickname", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-nick.png"), [this](auto&) { |     m_change_nick_action = GAction::create("Change nickname", GraphicsBitmap::load_from_file("/res/icons/16x16/irc-nick.png"), [this](auto&) { | ||||||
|         GInputBox input_box("Enter nickname:", "Change nickname", this); |         auto input_box = GInputBox::construct("Enter nickname:", "Change nickname", this); | ||||||
|         if (input_box.exec() == GInputBox::ExecOK && !input_box.text_value().is_empty()) |         if (input_box->exec() == GInputBox::ExecOK && !input_box->text_value().is_empty()) | ||||||
|             m_client.handle_change_nick_action(input_box.text_value()); |             m_client.handle_change_nick_action(input_box->text_value()); | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -29,8 +29,7 @@ int run_shutdown_dialog(int argc, char** argv) | ||||||
|     GApplication app(argc, argv); |     GApplication app(argc, argv); | ||||||
| 
 | 
 | ||||||
|     { |     { | ||||||
|         GMessageBox box("Shut down Serenity?", "Confirm Shutdown", GMessageBox::Type::Warning, GMessageBox::InputType::OKCancel); |         auto result = GMessageBox::show("Shut down Serenity?", "Confirm Shutdown", GMessageBox::Type::Warning, GMessageBox::InputType::OKCancel); | ||||||
|         auto result = box.exec(); |  | ||||||
| 
 | 
 | ||||||
|         if (result == GMessageBox::ExecOK) { |         if (result == GMessageBox::ExecOK) { | ||||||
|             dbg() << "OK"; |             dbg() << "OK"; | ||||||
|  |  | ||||||
|  | @ -285,7 +285,6 @@ bool TextEditorWidget::request_close() | ||||||
| { | { | ||||||
|     if (!m_document_dirty) |     if (!m_document_dirty) | ||||||
|         return true; |         return true; | ||||||
|     GMessageBox box("The document has been modified. Quit without saving?", "Quit without saving?", GMessageBox::Type::Warning, GMessageBox::InputType::OKCancel, window()); |     auto result = GMessageBox::show("The document has been modified. Quit without saving?", "Quit without saving?", GMessageBox::Type::Warning, GMessageBox::InputType::OKCancel, window()); | ||||||
|     auto result = box.exec(); |  | ||||||
|     return result == GMessageBox::ExecOK; |     return result == GMessageBox::ExecOK; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -102,11 +102,11 @@ GFilePicker::GFilePicker(Mode mode, const StringView& file_name, const StringVie | ||||||
|     toolbar->add_separator(); |     toolbar->add_separator(); | ||||||
| 
 | 
 | ||||||
|     auto mkdir_action = GAction::create("New directory...", GraphicsBitmap::load_from_file("/res/icons/16x16/mkdir.png"), [this](const GAction&) { |     auto mkdir_action = GAction::create("New directory...", GraphicsBitmap::load_from_file("/res/icons/16x16/mkdir.png"), [this](const GAction&) { | ||||||
|         GInputBox input_box("Enter name:", "New directory", this); |         auto input_box = GInputBox::construct("Enter name:", "New directory", this); | ||||||
|         if (input_box.exec() == GInputBox::ExecOK && !input_box.text_value().is_empty()) { |         if (input_box->exec() == GInputBox::ExecOK && !input_box->text_value().is_empty()) { | ||||||
|             auto new_dir_path = FileSystemPath(String::format("%s/%s", |             auto new_dir_path = FileSystemPath(String::format("%s/%s", | ||||||
|                                                    m_model->path().characters(), |                                                    m_model->path().characters(), | ||||||
|                                                    input_box.text_value().characters())) |                                                    input_box->text_value().characters())) | ||||||
|                                     .string(); |                                     .string(); | ||||||
|             int rc = mkdir(new_dir_path.characters(), 0777); |             int rc = mkdir(new_dir_path.characters(), 0777); | ||||||
|             if (rc < 0) { |             if (rc < 0) { | ||||||
|  | @ -248,8 +248,8 @@ void GFilePicker::on_file_return() | ||||||
|     FileSystemPath path(String::format("%s/%s", m_model->path().characters(), m_filename_textbox->text().characters())); |     FileSystemPath path(String::format("%s/%s", m_model->path().characters(), m_filename_textbox->text().characters())); | ||||||
| 
 | 
 | ||||||
|     if (GFilePicker::file_exists(path.string()) && m_mode == Mode::Save) { |     if (GFilePicker::file_exists(path.string()) && m_mode == Mode::Save) { | ||||||
|         GMessageBox box("File already exists, overwrite?", "Existing File", GMessageBox::Type::Warning, GMessageBox::InputType::OKCancel); |         auto result = GMessageBox::show("File already exists, overwrite?", "Existing File", GMessageBox::Type::Warning, GMessageBox::InputType::OKCancel); | ||||||
|         if (box.exec() == GMessageBox::ExecCancel) |         if (result == GMessageBox::ExecCancel) | ||||||
|             return; |             return; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -4,10 +4,10 @@ | ||||||
| #include <LibGUI/GMessageBox.h> | #include <LibGUI/GMessageBox.h> | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| 
 | 
 | ||||||
| void GMessageBox::show(const StringView& text, const StringView& title, Type type, InputType input_type, CObject* parent) | int GMessageBox::show(const StringView& text, const StringView& title, Type type, InputType input_type, CObject* parent) | ||||||
| { | { | ||||||
|     GMessageBox box(text, title, type, input_type, parent); |     auto box = GMessageBox::construct(text, title, type, input_type, parent); | ||||||
|     box.exec(); |     return box->exec(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| GMessageBox::GMessageBox(const StringView& text, const StringView& title, Type type, InputType input_type, CObject* parent) | GMessageBox::GMessageBox(const StringView& text, const StringView& title, Type type, InputType input_type, CObject* parent) | ||||||
|  |  | ||||||
|  | @ -20,7 +20,7 @@ public: | ||||||
|     explicit GMessageBox(const StringView& text, const StringView& title, Type type = Type::None, InputType = InputType::OK, CObject* parent = nullptr); |     explicit GMessageBox(const StringView& text, const StringView& title, Type type = Type::None, InputType = InputType::OK, CObject* parent = nullptr); | ||||||
|     virtual ~GMessageBox() override; |     virtual ~GMessageBox() override; | ||||||
| 
 | 
 | ||||||
|     static void show(const StringView& text, const StringView& title, Type type = Type::None, InputType = InputType::OK, CObject* parent = nullptr); |     static int show(const StringView& text, const StringView& title, Type type = Type::None, InputType = InputType::OK, CObject* parent = nullptr); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|     bool should_include_ok_button() const; |     bool should_include_ok_button() const; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling