main.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "TextEditorWidget.h"
  2. #include <LibDraw/PNGLoader.h>
  3. #include <stdio.h>
  4. int main(int argc, char** argv)
  5. {
  6. if (pledge("stdio rpath cpath wpath shared_buffer unix fattr", nullptr) < 0) {
  7. perror("pledge");
  8. return 1;
  9. }
  10. GApplication app(argc, argv);
  11. if (pledge("stdio rpath cpath wpath shared_buffer unix", nullptr) < 0) {
  12. perror("pledge");
  13. return 1;
  14. }
  15. auto window = GWindow::construct();
  16. window->set_title("Text Editor");
  17. window->set_rect(20, 200, 640, 400);
  18. auto text_widget = TextEditorWidget::construct();
  19. window->set_main_widget(text_widget);
  20. text_widget->editor().set_focus(true);
  21. window->on_close_request = [&]() -> GWindow::CloseRequestDecision {
  22. if (text_widget->request_close())
  23. return GWindow::CloseRequestDecision::Close;
  24. return GWindow::CloseRequestDecision::StayOpen;
  25. };
  26. if (argc >= 2)
  27. text_widget->open_sesame(argv[1]);
  28. window->show();
  29. window->set_icon(load_png("/res/icons/TextEditor16.png"));
  30. return app.exec();
  31. }