mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 21:38:11 +00:00
DevTools: Introduce SQL Studio
SQL Studio is a graphical SQL manager program that allows the user to create and edit SQL scripts.
This commit is contained in:
parent
0cd5c6bd0f
commit
582539c570
7 changed files with 608 additions and 0 deletions
57
Userland/DevTools/SQLStudio/main.cpp
Normal file
57
Userland/DevTools/SQLStudio/main.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Dylan Katz <dykatz@uw.edu>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/StringUtils.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibGUI/Application.h>
|
||||
#include <LibGUI/Icon.h>
|
||||
#include <LibGUI/Window.h>
|
||||
#include <LibMain/Main.h>
|
||||
|
||||
#include "MainWidget.h"
|
||||
|
||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
{
|
||||
char const* file_to_open = nullptr;
|
||||
|
||||
Core::ArgsParser args_parser;
|
||||
args_parser.add_positional_argument(file_to_open, "Path to SQL script or DB", "file", Core::ArgsParser::Required::No);
|
||||
args_parser.parse(arguments);
|
||||
|
||||
auto app = TRY(GUI::Application::try_create(arguments));
|
||||
|
||||
auto app_icon = GUI::Icon::default_icon("app-sql-studio");
|
||||
|
||||
auto window = TRY(GUI::Window::try_create());
|
||||
window->resize(640, 480);
|
||||
window->set_icon(app_icon.bitmap_for_size(16));
|
||||
window->set_title("SQL Studio");
|
||||
|
||||
auto main_widget = TRY(window->try_set_main_widget<MainWidget>());
|
||||
main_widget->initialize_menu(window);
|
||||
|
||||
window->on_close_request = [&] {
|
||||
if (main_widget->request_close())
|
||||
return GUI::Window::CloseRequestDecision::Close;
|
||||
return GUI::Window::CloseRequestDecision::StayOpen;
|
||||
};
|
||||
|
||||
auto needs_new_script = true;
|
||||
if (file_to_open) {
|
||||
auto path = LexicalPath(file_to_open);
|
||||
if (path.extension().equals_ignoring_case("sql"sv)) {
|
||||
main_widget->open_script_from_file(path);
|
||||
needs_new_script = false;
|
||||
} else if (path.extension().equals_ignoring_case("db"sv)) {
|
||||
main_widget->open_database_from_file(path);
|
||||
}
|
||||
}
|
||||
if (needs_new_script)
|
||||
main_widget->open_new_script();
|
||||
|
||||
window->show();
|
||||
return app->exec();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue