GitWidget.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include "GitFilesView.h"
  8. #include "GitRepo.h"
  9. #include <AK/Function.h>
  10. #include <LibGUI/Forward.h>
  11. #include <LibGUI/Widget.h>
  12. namespace HackStudio {
  13. using ViewDiffCallback = Function<void(DeprecatedString const& original_content, DeprecatedString const& diff)>;
  14. class GitWidget final : public GUI::Widget {
  15. C_OBJECT(GitWidget)
  16. public:
  17. virtual ~GitWidget() override { }
  18. void refresh();
  19. void set_view_diff_callback(ViewDiffCallback callback);
  20. bool initialized() const { return !m_git_repo.is_null(); }
  21. void change_repo(DeprecatedString const& repo_root);
  22. private:
  23. explicit GitWidget();
  24. bool initialize();
  25. bool initialize_if_needed();
  26. void stage_file(DeprecatedString const&);
  27. void unstage_file(DeprecatedString const&);
  28. void commit();
  29. void show_diff(DeprecatedString const&);
  30. DeprecatedString m_repo_root;
  31. RefPtr<GitFilesView> m_unstaged_files;
  32. RefPtr<GitFilesView> m_staged_files;
  33. RefPtr<GitRepo> m_git_repo;
  34. ViewDiffCallback m_view_diff_callback;
  35. };
  36. }