mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 21:15:09 +00:00
HackStudio: Only refresh Git widget on save if initialized
This commit is contained in:
parent
e46b4e0865
commit
b82a254da0
3 changed files with 35 additions and 7 deletions
|
@ -95,19 +95,41 @@ GitWidget::GitWidget(const LexicalPath& repo_root)
|
||||||
Gfx::Bitmap::load_from_file("/res/icons/16x16/minus.png").release_nonnull());
|
Gfx::Bitmap::load_from_file("/res/icons/16x16/minus.png").release_nonnull());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitWidget::refresh()
|
bool GitWidget::initialize()
|
||||||
{
|
{
|
||||||
auto result = GitRepo::try_to_create(m_repo_root);
|
auto result = GitRepo::try_to_create(m_repo_root);
|
||||||
if (result.type == GitRepo::CreateResult::Type::Success) {
|
switch (result.type) {
|
||||||
|
case GitRepo::CreateResult::Type::Success:
|
||||||
m_git_repo = result.repo;
|
m_git_repo = result.repo;
|
||||||
} else if (result.type == GitRepo::CreateResult::Type::GitProgramNotFound) {
|
return true;
|
||||||
|
case GitRepo::CreateResult::Type::GitProgramNotFound:
|
||||||
GUI::MessageBox::show(window(), "Please install the Git port", "Error", GUI::MessageBox::Type::Error);
|
GUI::MessageBox::show(window(), "Please install the Git port", "Error", GUI::MessageBox::Type::Error);
|
||||||
return;
|
return false;
|
||||||
} else if (result.type == GitRepo::CreateResult::Type::NoGitRepo) {
|
case GitRepo::CreateResult::Type::NoGitRepo: {
|
||||||
auto decision = GUI::MessageBox::show(window(), "Create git repository?", "Git", GUI::MessageBox::Type::Question, GUI::MessageBox::InputType::YesNo);
|
auto decision = GUI::MessageBox::show(window(), "Create git repository?", "Git", GUI::MessageBox::Type::Question, GUI::MessageBox::InputType::YesNo);
|
||||||
if (decision != GUI::Dialog::ExecResult::ExecYes)
|
if (decision != GUI::Dialog::ExecResult::ExecYes)
|
||||||
return;
|
return false;
|
||||||
m_git_repo = GitRepo::initialize_repository(m_repo_root);
|
m_git_repo = GitRepo::initialize_repository(m_repo_root);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
ASSERT_NOT_REACHED();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GitWidget::initialize_if_needed()
|
||||||
|
{
|
||||||
|
if (initialized())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GitWidget::refresh()
|
||||||
|
{
|
||||||
|
if (!initialize_if_needed()) {
|
||||||
|
dbg() << "GitWidget initialization failed";
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(!m_git_repo.is_null());
|
ASSERT(!m_git_repo.is_null());
|
||||||
|
|
|
@ -43,10 +43,13 @@ public:
|
||||||
|
|
||||||
void refresh();
|
void refresh();
|
||||||
void set_view_diff_callback(ViewDiffCallback callback);
|
void set_view_diff_callback(ViewDiffCallback callback);
|
||||||
|
bool initialized() const { return !m_git_repo.is_null(); };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit GitWidget(const LexicalPath& repo_root);
|
explicit GitWidget(const LexicalPath& repo_root);
|
||||||
|
|
||||||
|
bool initialize();
|
||||||
|
bool initialize_if_needed();
|
||||||
void stage_file(const LexicalPath&);
|
void stage_file(const LexicalPath&);
|
||||||
void unstage_file(const LexicalPath&);
|
void unstage_file(const LexicalPath&);
|
||||||
void commit();
|
void commit();
|
||||||
|
|
|
@ -489,8 +489,11 @@ static int main_impl(int argc, char** argv)
|
||||||
auto save_action = GUI::Action::create("Save", { Mod_Ctrl, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [&](auto&) {
|
auto save_action = GUI::Action::create("Save", { Mod_Ctrl, Key_S }, Gfx::Bitmap::load_from_file("/res/icons/16x16/save.png"), [&](auto&) {
|
||||||
if (g_currently_open_file.is_empty())
|
if (g_currently_open_file.is_empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
current_editor().write_to_file(g_currently_open_file);
|
current_editor().write_to_file(g_currently_open_file);
|
||||||
g_git_widget->refresh();
|
|
||||||
|
if (g_git_widget->initialized())
|
||||||
|
g_git_widget->refresh();
|
||||||
});
|
});
|
||||||
|
|
||||||
toolbar.add_action(new_action);
|
toolbar.add_action(new_action);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue