Skip to content

Commit

Permalink
Hackstudio: Add a window title when diff is opened
Browse files Browse the repository at this point in the history
Set window title when a diff is opened from Git
widget in HackStudio.
  • Loading branch information
asan-sanitizer authored and nico committed Jun 9, 2024
1 parent 9597403 commit ceec7cd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Userland/DevTools/HackStudio/Git/GitWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ void GitWidget::show_diff(ByteString const& file_path)
if (!m_git_repo->is_tracked(file_path)) {
auto file = Core::File::open(file_path, Core::File::OpenMode::Read).release_value_but_fixme_should_propagate_errors();
auto content = file->read_until_eof().release_value_but_fixme_should_propagate_errors();
m_view_diff_callback("", Diff::generate_only_additions(content));
m_view_diff_callback("", Diff::generate_only_additions(content), file_path);
return;
}
auto const& original_content = m_git_repo->original_file_content(file_path);
auto const& diff = m_git_repo->unstaged_diff(file_path);
VERIFY(original_content.has_value() && diff.has_value());
m_view_diff_callback(original_content.value(), diff.value());
m_view_diff_callback(original_content.value(), diff.value(), file_path);
}

void GitWidget::change_repo(ByteString const& repo_root)
Expand Down
2 changes: 1 addition & 1 deletion Userland/DevTools/HackStudio/Git/GitWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace HackStudio {

using ViewDiffCallback = Function<void(ByteString const& original_content, ByteString const& diff)>;
using ViewDiffCallback = Function<void(ByteString const& original_content, ByteString const& diff, ByteString const& file_path)>;

class GitWidget final : public GUI::Widget {
C_OBJECT(GitWidget)
Expand Down
6 changes: 5 additions & 1 deletion Userland/DevTools/HackStudio/HackStudioWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1363,9 +1363,13 @@ ErrorOr<void> HackStudioWidget::create_action_tab(GUI::Widget& parent)

m_disassembly_widget = m_action_tab_widget->add_tab<DisassemblyWidget>("Disassembly"_string);
m_git_widget = m_action_tab_widget->add_tab<GitWidget>("Git"_string);
m_git_widget->set_view_diff_callback([this](auto const& original_content, auto const& diff) {
m_git_widget->set_view_diff_callback([this](auto const& original_content, auto const& diff, auto const& file_path) {
m_diff_viewer->set_content(original_content, diff);
set_edit_mode(EditMode::Diff);
StringBuilder diff_title;
diff_title.append("Diff:", 5);
diff_title.append(file_path.view());
m_diff_viewer->window()->set_title(diff_title.to_byte_string());
});
m_gml_preview_widget = m_action_tab_widget->add_tab<GMLPreviewWidget>("GML Preview"_string, "");

Expand Down

0 comments on commit ceec7cd

Please sign in to comment.