GitCommitDialog.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2021, Conor Byrne <conor@cbyrne.dev>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "GitCommitDialog.h"
  7. #include <DevTools/HackStudio/Dialogs/Git/GitCommitDialogGML.h>
  8. namespace HackStudio {
  9. GitCommitDialog::GitCommitDialog(GUI::Window* parent)
  10. : Dialog(parent)
  11. {
  12. resize(400, 260);
  13. center_within(*parent);
  14. set_modal(true);
  15. set_title("Commit");
  16. set_icon(parent->icon());
  17. auto& widget = set_main_widget<GUI::Widget>();
  18. widget.load_from_gml(git_commit_dialog_gml);
  19. m_message_editor = widget.find_descendant_of_type_named<GUI::TextEditor>("message_editor");
  20. m_cancel_button = widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
  21. m_commit_button = widget.find_descendant_of_type_named<GUI::Button>("commit_button");
  22. m_line_and_col_label = widget.find_descendant_of_type_named<GUI::Label>("line_and_col_label");
  23. m_message_editor->on_change = [this]() {
  24. m_commit_button->set_enabled(!m_message_editor->text().is_empty() && on_commit);
  25. };
  26. m_message_editor->on_cursor_change = [this]() {
  27. auto line = m_message_editor->cursor().line() + 1;
  28. auto col = m_message_editor->cursor().column();
  29. m_line_and_col_label->set_text(String::formatted("Line: {}, Col: {}", line, col));
  30. };
  31. m_commit_button->set_enabled(!m_message_editor->text().is_empty() && on_commit);
  32. m_commit_button->on_click = [this](auto) {
  33. on_commit(m_message_editor->text());
  34. done(ExecResult::OK);
  35. };
  36. m_cancel_button->on_click = [this](auto) {
  37. done(ExecResult::Cancel);
  38. };
  39. }
  40. }