mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:57:44 +00:00
LibWeb: Require parent window argument for MessageBox
Since the vast majority of message boxes should be modal, require the parent window to be passed in, which can be nullptr for the rare case that they don't. By it being the first argument, the default arguments also don't need to be explicitly stated in most cases, and it encourages passing in a parent window handle. Fix up several message boxes that should have been modal.
This commit is contained in:
parent
6568765e8f
commit
27bd2eab22
30 changed files with 109 additions and 135 deletions
|
@ -153,12 +153,10 @@ void VariablesModel::set_variable_value(const GUI::ModelIndex& index, const Stri
|
|||
return;
|
||||
}
|
||||
|
||||
GUI::MessageBox::show(
|
||||
GUI::MessageBox::show(parent_window,
|
||||
String::format("String value \"%s\" could not be converted to a value of type %s.", string_value.to_string().characters(), variable->type_name.characters()),
|
||||
"Set value failed",
|
||||
GUI::MessageBox::Type::Error,
|
||||
GUI::MessageBox::InputType::OK,
|
||||
parent_window);
|
||||
GUI::MessageBox::Type::Error);
|
||||
}
|
||||
|
||||
GUI::Variant VariablesModel::data(const GUI::ModelIndex& index, Role role) const
|
||||
|
|
|
@ -44,12 +44,10 @@
|
|||
void TerminalWrapper::run_command(const String& command)
|
||||
{
|
||||
if (m_pid != -1) {
|
||||
GUI::MessageBox::show(
|
||||
GUI::MessageBox::show(window(),
|
||||
"A command is already running in this TerminalWrapper",
|
||||
"Can't run command",
|
||||
GUI::MessageBox::Type::Error,
|
||||
GUI::MessageBox::InputType::OK,
|
||||
window());
|
||||
GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -187,7 +187,7 @@ int main(int argc, char** argv)
|
|||
setenv("PATH", path.to_string().characters(), true);
|
||||
|
||||
if (!make_is_available())
|
||||
GUI::MessageBox::show("The 'make' command is not available. You probably want to install the binutils, gcc, and make ports from the root of the Serenity repository.", "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, g_window);
|
||||
GUI::MessageBox::show(g_window, "The 'make' command is not available. You probably want to install the binutils, gcc, and make ports from the root of the Serenity repository.", "Error", GUI::MessageBox::Type::Error);
|
||||
|
||||
open_project("/home/anon/little/little.files");
|
||||
|
||||
|
@ -209,11 +209,11 @@ int main(int argc, char** argv)
|
|||
auto filename = input_box->text_value();
|
||||
auto file = Core::File::construct(filename);
|
||||
if (!file->open((Core::IODevice::OpenMode)(Core::IODevice::WriteOnly | Core::IODevice::MustBeNew))) {
|
||||
GUI::MessageBox::show(String::format("Failed to create '%s'", filename.characters()), "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, g_window);
|
||||
GUI::MessageBox::show(g_window, String::format("Failed to create '%s'", filename.characters()), "Error", GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
if (!g_project->add_file(filename)) {
|
||||
GUI::MessageBox::show(String::format("Failed to add '%s' to project", filename.characters()), "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, g_window);
|
||||
GUI::MessageBox::show(g_window, String::format("Failed to add '%s' to project", filename.characters()), "Error", GUI::MessageBox::Type::Error);
|
||||
// FIXME: Should we unlink the file here maybe?
|
||||
return;
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ int main(int argc, char** argv)
|
|||
return;
|
||||
auto& filename = result.value();
|
||||
if (!g_project->add_file(filename)) {
|
||||
GUI::MessageBox::show(String::format("Failed to add '%s' to project", filename.characters()), "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, g_window);
|
||||
GUI::MessageBox::show(g_window, String::format("Failed to add '%s' to project", filename.characters()), "Error", GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
g_project_tree_view->toggle_index(g_project_tree_view->model()->index(0, 0));
|
||||
|
@ -248,23 +248,20 @@ int main(int argc, char** argv)
|
|||
message = String::format("Really remove %d files from the project?", files.size());
|
||||
}
|
||||
|
||||
auto result = GUI::MessageBox::show(
|
||||
auto result = GUI::MessageBox::show(g_window,
|
||||
message,
|
||||
"Confirm deletion",
|
||||
GUI::MessageBox::Type::Warning,
|
||||
GUI::MessageBox::InputType::OKCancel,
|
||||
g_window);
|
||||
GUI::MessageBox::InputType::OKCancel);
|
||||
if (result == GUI::MessageBox::ExecCancel)
|
||||
return;
|
||||
|
||||
for (auto& file : files) {
|
||||
if (!g_project->remove_file(file)) {
|
||||
GUI::MessageBox::show(
|
||||
GUI::MessageBox::show(g_window,
|
||||
String::format("Removing file %s from the project failed.", file.characters()),
|
||||
"Removal failed",
|
||||
GUI::MessageBox::Type::Error,
|
||||
GUI::MessageBox::InputType::OK,
|
||||
g_window);
|
||||
GUI::MessageBox::Type::Error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -564,15 +561,15 @@ int main(int argc, char** argv)
|
|||
RefPtr<LibThread::Thread> debugger_thread;
|
||||
auto debug_action = GUI::Action::create("Debug", Gfx::Bitmap::load_from_file("/res/icons/16x16/debug-run.png"), [&](auto&) {
|
||||
if (g_project->type() != ProjectType::Cpp) {
|
||||
GUI::MessageBox::show(String::format("Cannot debug current project type", get_project_executable_path().characters()), "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, g_window);
|
||||
GUI::MessageBox::show(g_window, String::format("Cannot debug current project type", get_project_executable_path().characters()), "Error", GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
if (!GUI::FilePicker::file_exists(get_project_executable_path())) {
|
||||
GUI::MessageBox::show(String::format("Could not find file: %s. (did you build the project?)", get_project_executable_path().characters()), "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, g_window);
|
||||
GUI::MessageBox::show(g_window, String::format("Could not find file: %s. (did you build the project?)", get_project_executable_path().characters()), "Error", GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
if (Debugger::the().session()) {
|
||||
GUI::MessageBox::show("Debugger is already running", "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, g_window);
|
||||
GUI::MessageBox::show(g_window, "Debugger is already running", "Error", GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
Debugger::the().set_executable_path(get_project_executable_path());
|
||||
|
@ -637,7 +634,7 @@ int main(int argc, char** argv)
|
|||
debug_info_widget.program_stopped();
|
||||
hide_action_tabs();
|
||||
Core::EventLoop::main().post_event(*g_window, make<Core::DeferredInvocationEvent>([=](auto&) {
|
||||
GUI::MessageBox::show("Program Exited", "Debugger", GUI::MessageBox::Type::Information, GUI::MessageBox::InputType::OK, g_window);
|
||||
GUI::MessageBox::show(g_window, "Program Exited", "Debugger", GUI::MessageBox::Type::Information);
|
||||
}));
|
||||
Core::EventLoop::wake();
|
||||
});
|
||||
|
|
|
@ -63,7 +63,7 @@ void ProcessChooser::build()
|
|||
auto& profile_button = button_container.add<GUI::Button>("Profile");
|
||||
profile_button.on_click = [&](auto) {
|
||||
if (table_view.selection().is_empty()) {
|
||||
GUI::MessageBox::show("No process selected!", "Profiler", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, this);
|
||||
GUI::MessageBox::show(this, "No process selected!", "Profiler", GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
auto index = table_view.selection().first();
|
||||
|
|
|
@ -162,7 +162,7 @@ bool generate_profile(pid_t pid)
|
|||
|
||||
if (profiling_enable(pid) < 0) {
|
||||
int saved_errno = errno;
|
||||
GUI::MessageBox::show(String::format("Unable to profile PID %d: %s", pid, strerror(saved_errno)), "Profiler", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK);
|
||||
GUI::MessageBox::show(nullptr, String::format("Unable to profile PID %d: %s", pid, strerror(saved_errno)), "Profiler", GUI::MessageBox::Type::Error);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -383,7 +383,7 @@ void VBForm::load_from_file(const String& path)
|
|||
{
|
||||
auto file = Core::File::construct(path);
|
||||
if (!file->open(Core::IODevice::ReadOnly)) {
|
||||
GUI::MessageBox::show(String::format("Could not open '%s' for reading", path.characters()), "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window());
|
||||
GUI::MessageBox::show(window(), String::format("Could not open '%s' for reading", path.characters()), "Error", GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -392,7 +392,7 @@ void VBForm::load_from_file(const String& path)
|
|||
ASSERT(form_json.has_value());
|
||||
|
||||
if (!form_json.value().is_object()) {
|
||||
GUI::MessageBox::show(String::format("Could not parse '%s'", path.characters()), "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window());
|
||||
GUI::MessageBox::show(window(), String::format("Could not parse '%s'", path.characters()), "Error", GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -420,7 +420,7 @@ void VBForm::write_to_file(const String& path)
|
|||
{
|
||||
auto file = Core::File::construct(path);
|
||||
if (!file->open(Core::IODevice::WriteOnly)) {
|
||||
GUI::MessageBox::show(String::format("Could not open '%s' for writing", path.characters()), "Error", GUI::MessageBox::Type::Error, GUI::MessageBox::InputType::OK, window());
|
||||
GUI::MessageBox::show(window(), String::format("Could not open '%s' for writing", path.characters()), "Error", GUI::MessageBox::Type::Error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue