GitWidget.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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(const String& original_content, const String& 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. private:
  22. explicit GitWidget(const LexicalPath& repo_root);
  23. bool initialize();
  24. bool initialize_if_needed();
  25. void stage_file(const LexicalPath&);
  26. void unstage_file(const LexicalPath&);
  27. void commit();
  28. void show_diff(const LexicalPath&);
  29. LexicalPath m_repo_root;
  30. RefPtr<GitFilesView> m_unstaged_files;
  31. RefPtr<GitFilesView> m_staged_files;
  32. RefPtr<GitRepo> m_git_repo;
  33. ViewDiffCallback m_view_diff_callback;
  34. };
  35. }