Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
forgottosave committed Nov 11, 2024
1 parent e482979 commit aef9889
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
8 changes: 6 additions & 2 deletions src/core/OSTreeTUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ OSTreeTUI::OSTreeTUI (const std::string& repo, const std::vector<std::string> st

// interchangeable view (composed)
manager = std::unique_ptr<Manager>(new Manager(*this, infoView, filterView));
managerRenderer = manager->managerRenderer;
managerRenderer = manager->getManagerRenderer();

// FOOTER
footerRenderer = Renderer([&] {
Expand Down Expand Up @@ -145,7 +145,7 @@ OSTreeTUI::OSTreeTUI (const std::string& repo, const std::vector<std::string> st
return true;
}
// make commit list focussable
if (event == Event::ArrowLeft && managerRenderer->Focused() && manager->tab_index == 0) {
if (event == Event::ArrowLeft && managerRenderer->Focused() && manager->getTabIndex() == 0) {
commitListComponent->TakeFocus();
return true;
}
Expand Down Expand Up @@ -298,6 +298,10 @@ std::vector<std::string>& OSTreeTUI::getColumnToBranchMap() {
return columnToBranchMap;
}

ftxui::ScreenInteractive& OSTreeTUI::getScreen() {
return screen;
}

// GETTER
const cpplibostree::OSTreeRepo& OSTreeTUI::getOstreeRepo() const {
return ostreeRepo;
Expand Down
6 changes: 4 additions & 2 deletions src/core/OSTreeTUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ class OSTreeTUI {
void adjustScrollToSelectedCommit();

public:
// "SETTER" & non-const GETTER
// SETTER
void setPromotionBranch(std::string promotionBranch);
void setSelectedCommit(size_t selectedCommit);

// non-const GETTER
std::vector<std::string>& getColumnToBranchMap();
ftxui::ScreenInteractive& getScreen();

// GETTER
const cpplibostree::OSTreeRepo& getOstreeRepo() const;
Expand Down Expand Up @@ -120,7 +123,6 @@ class OSTreeTUI {
Footer footer;
std::unique_ptr<BranchBoxManager> filterManager{nullptr};
std::unique_ptr<Manager> manager{nullptr};
public:
ftxui::ScreenInteractive screen;
ftxui::Component mainContainer;
ftxui::Components commitComponents;
Expand Down
10 changes: 5 additions & 5 deletions src/core/commit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
TakeFocus();
// manually fix focus issues
// change to proper control layout if possible...
ostreetui.screen.Post(Event::ArrowDown);
ostreetui.screen.Post(Event::ArrowRight);
ostreetui.screen.Post(Event::ArrowDown);
ostreetui.screen.Post(Event::ArrowRight);
ostreetui.screen.Post(Event::ArrowUp);
ostreetui.getScreen().Post(Event::ArrowDown);
ostreetui.getScreen().Post(Event::ArrowRight);
ostreetui.getScreen().Post(Event::ArrowDown);
ostreetui.getScreen().Post(Event::ArrowRight);
ostreetui.getScreen().Post(Event::ArrowUp);
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/core/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ Manager::Manager(OSTreeTUI& ostreetui, const ftxui::Component& infoView, const f
});
}

ftxui::Component Manager::getManagerRenderer() {
return managerRenderer;
}

const int& Manager::getTabIndex() const {
return tab_index;
}

// BranchBoxManager

BranchBoxManager::BranchBoxManager(cpplibostree::OSTreeRepo& repo, std::unordered_map<std::string, bool>& visibleBranches) {
Expand Down
10 changes: 6 additions & 4 deletions src/core/manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ class Manager {
private:
OSTreeTUI& ostreetui;

int tab_index{0};
std::vector<std::string> tab_entries = {
" Info ", " Filter "
};

// because the combination of all interchangeable views is very simple,
// we can (in contrast to the other ones) render this one here
ftxui::Component managerRenderer;
ftxui::Component tabSelection;
ftxui::Component tabContent;

public:
int tab_index{0};
// because the combination of all interchangeable views is very simple,
// we can (in contrast to the other ones) render this one immediately
ftxui::Component managerRenderer;
ftxui::Component getManagerRenderer();
const int& getTabIndex() const;
};

class CommitInfoManager {
Expand Down

0 comments on commit aef9889

Please sign in to comment.