main.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "HexEditorWidget.h"
  7. #include <LibConfig/Client.h>
  8. #include <LibGUI/Icon.h>
  9. #include <LibGUI/Menubar.h>
  10. #include <stdio.h>
  11. #include <unistd.h>
  12. int main(int argc, char** argv)
  13. {
  14. if (pledge("stdio recvfd sendfd rpath unix cpath wpath thread", nullptr) < 0) {
  15. perror("pledge");
  16. return 1;
  17. }
  18. auto app = GUI::Application::construct(argc, argv);
  19. Config::pledge_domains("HexEditor");
  20. if (pledge("stdio recvfd sendfd rpath cpath wpath thread", nullptr) < 0) {
  21. perror("pledge");
  22. return 1;
  23. }
  24. auto app_icon = GUI::Icon::default_icon("app-hex-editor");
  25. auto window = GUI::Window::construct();
  26. window->set_title("Hex Editor");
  27. window->resize(640, 400);
  28. auto& hex_editor_widget = window->set_main_widget<HexEditorWidget>();
  29. window->on_close_request = [&]() -> GUI::Window::CloseRequestDecision {
  30. if (hex_editor_widget.request_close())
  31. return GUI::Window::CloseRequestDecision::Close;
  32. return GUI::Window::CloseRequestDecision::StayOpen;
  33. };
  34. hex_editor_widget.initialize_menubar(*window);
  35. window->show();
  36. window->set_icon(app_icon.bitmap_for_size(16));
  37. if (argc >= 2)
  38. hex_editor_widget.open_file(argv[1]);
  39. return app->exec();
  40. }