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