GitCommitDialog.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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_title("Commit");
  15. set_icon(parent->icon());
  16. auto& widget = set_main_widget<GUI::Widget>();
  17. widget.load_from_gml(git_commit_dialog_gml);
  18. m_message_editor = widget.find_descendant_of_type_named<GUI::TextEditor>("message_editor");
  19. m_cancel_button = widget.find_descendant_of_type_named<GUI::Button>("cancel_button");
  20. m_commit_button = widget.find_descendant_of_type_named<GUI::Button>("commit_button");
  21. m_line_and_col_label = widget.find_descendant_of_type_named<GUI::Label>("line_and_col_label");
  22. m_message_editor->on_change = [this]() {
  23. m_commit_button->set_enabled(!m_message_editor->text().is_empty() && on_commit);
  24. };
  25. m_message_editor->on_cursor_change = [this]() {
  26. auto line = m_message_editor->cursor().line() + 1;
  27. auto col = m_message_editor->cursor().column();
  28. m_line_and_col_label->set_text(String::formatted("Line: {}, Col: {}", line, col));
  29. };
  30. m_commit_button->set_enabled(!m_message_editor->text().is_empty() && on_commit);
  31. m_commit_button->on_click = [this](auto) {
  32. on_commit(m_message_editor->text());
  33. done(ExecResult::OK);
  34. };
  35. m_cancel_button->on_click = [this](auto) {
  36. done(ExecResult::Cancel);
  37. };
  38. }
  39. }