Skip to content

Commit

Permalink
Remove old promotion manager
Browse files Browse the repository at this point in the history
  • Loading branch information
forgottosave committed Nov 2, 2024
1 parent c97f4cc commit c7a4266
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 195 deletions.
26 changes: 3 additions & 23 deletions src/core/OSTreeTUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,8 @@ int OSTreeTUI::main(const std::string& repo, const std::vector<std::string>& sta
return filterManager.branchBoxRender();
});

// promotion
ContentPromotionManager promotionManager(showTooltips);
promotionManager.setBranchRadiobox(Radiobox(&allBranches, &promotionManager.selectedBranch));
promotionManager.setApplyButton(Button(" Apply ", [&] {
ostreeRepo.promoteCommit(visibleCommitViewMap.at(selectedCommit),
ostreeRepo.getBranches().at(static_cast<size_t>(promotionManager.selectedBranch)),
{}, promotionManager.newSubject,
true);
//refresh_repository();
notificationText = " Applied content promotion. ";
}, ButtonOption::Simple()));
Component promotionView = Renderer(promotionManager.composePromotionComponent(), [&] {
if (visibleCommitViewMap.size() <= 0) {
return text(" please select a commit to continue commit-promotion... ") | color(Color::RedLight) | bold | center;
}
return promotionManager.renderPromotionView(ostreeRepo, screen.dimy(),
ostreeRepo.getCommitList().at(visibleCommitViewMap.at(selectedCommit)));
});

// interchangeable view (composed)
Manager manager(infoView, filterView, promotionView);
Manager manager(infoView, filterView);
Component managerRenderer = manager.managerRenderer;

// FOOTER
Expand All @@ -141,9 +122,8 @@ int OSTreeTUI::main(const std::string& repo, const std::vector<std::string>& sta
* add deletion button & ask for confirmation (also add keyboard functionality)
* TODO maybe re-arrange the manager window to remove the tabs again
* now that promotion and deletion is gone / changed, we have enough rooom to fit both the info and the filter
* TODO update the ostree-tui after promotion
* the new, promoted (or deleted) commit doesn't get updated
* might need a new component for that, as Component::Stacked seems like a fixed component (not modifyable)
* TODO update the ostree-tui
* after promotion & after filtering branches
* TOOD code cleanup:
* snake_case to camelCase (consistent)
* make const& where applicable
Expand Down
114 changes: 2 additions & 112 deletions src/core/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@

// Manager

Manager::Manager(const ftxui::Component& infoView, const ftxui::Component& filterView, const ftxui::Component& promotionView) {
Manager::Manager(const ftxui::Component& infoView, const ftxui::Component& filterView) {
using namespace ftxui;

tabSelection = Menu(&tab_entries, &tab_index, MenuOption::HorizontalAnimated());

tabContent = Container::Tab({
infoView,
filterView,
promotionView
filterView
},
&tab_index);

Expand Down Expand Up @@ -102,112 +101,3 @@ ftxui::Element CommitInfoManager::renderInfoView(const cpplibostree::Commit& dis
filler()
});
}

// ContentPromotionManager

ContentPromotionManager::ContentPromotionManager(bool show_tooltips): show_tooltips(show_tooltips) {
using namespace ftxui;

subjectComponent = Input(&newSubject, "subject");
}

void ContentPromotionManager::setBranchRadiobox(ftxui::Component radiobox) {
using namespace ftxui;

branchSelection = CatchEvent(radiobox, [&](const Event& event) {
// copy commit id
if (event == Event::Return) {
subjectComponent->TakeFocus();
}
return false;
});
}

void ContentPromotionManager::setApplyButton(ftxui::Component button) {
applyButton = button;
}

ftxui::Elements ContentPromotionManager::renderPromotionCommand(cpplibostree::OSTreeRepo& ostreeRepo, const std::string& selectedCommitHash) {
using namespace ftxui;

assert(branchSelection);
assert(applyButton);

Elements line;
line.push_back(text("ostree commit") | bold);
line.push_back(text(" --repo=" + ostreeRepo.getRepoPath()) | bold);
line.push_back(text(" -b " + ostreeRepo.getBranches().at(static_cast<size_t>(selectedBranch))) | bold);
line.push_back(text(" --keep-metadata") | bold);
// optional subject
if (!newSubject.empty()) {
line.push_back(text(" -s \"") | bold);
line.push_back(text(newSubject) | color(Color::BlueLight) | bold);
line.push_back(text("\"") | bold);
}
// commit
line.push_back(text(" --tree=ref=" + selectedCommitHash) | bold);

return line;
}

ftxui::Component ContentPromotionManager::composePromotionComponent() {
using namespace ftxui;

return Container::Vertical({
branchSelection,
Container::Vertical({
subjectComponent,
applyButton,
}),
});
}

ftxui::Element ContentPromotionManager::renderPromotionView(cpplibostree::OSTreeRepo& ostreeRepo, int screenHeight, const cpplibostree::Commit& displayCommit) {
using namespace ftxui;

assert(branchSelection);
assert(applyButton);

// compute screen element sizes
int screenOverhead {8}; // borders, footer, etc.
int commitWinHeight {3};
int apsectWinHeight {8};
int tooltipsWinHeight {2};
int branchSelectWinHeight = screenHeight - screenOverhead - commitWinHeight - apsectWinHeight - tooltipsWinHeight;
// tooltips only get shown, if the window is sufficiently large
if (branchSelectWinHeight < 4) {
tooltipsWinHeight = 0;
branchSelectWinHeight = 4;
}

// build elements
auto commitHashElem = vbox({text(" Commit: ") | bold | color(Color::Green), text(" " + displayCommit.hash)}) | flex;
auto branchWin = window(text("New Branch"), branchSelection->Render() | vscroll_indicator | frame);
auto subjectWin = window(text("Subject"), subjectComponent->Render()) | flex;
auto applyButtonWin = applyButton->Render() | color(Color::Green) | size(WIDTH, GREATER_THAN, 9) | flex;

auto toolTipContent = [&](size_t tip) {
return vbox({
separatorCharacter(""),
text(" 🛈 " + tool_tip_strings.at(tip)),
});
};
auto toolTipsWin = !show_tooltips || tooltipsWinHeight < 2 ? filler() : // only show if screen is reasonable size
branchSelection->Focused() ? toolTipContent(0) :
subjectComponent->Focused() ? toolTipContent(1) :
applyButton->Focused() ? toolTipContent(2) :
filler();

// build element composition
return vbox({
commitHashElem | size(HEIGHT, EQUAL, commitWinHeight),
branchWin | size(HEIGHT, LESS_THAN, branchSelectWinHeight),
vbox({
subjectWin,
applyButtonWin,
}) | flex | size(HEIGHT, LESS_THAN, apsectWinHeight),
hflow(renderPromotionCommand(ostreeRepo, displayCommit.hash)) | flex_grow,
filler(),
toolTipsWin,
}) | flex_grow;
}
62 changes: 2 additions & 60 deletions src/core/manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Manager {
int tab_index{0};

std::vector<std::string> tab_entries = {
" Info ", " Filter ", " Promote "
" Info ", " Filter "
};

ftxui::Component tabSelection;
Expand All @@ -30,7 +30,7 @@ class Manager {
ftxui::Component managerRenderer;

public:
Manager(const ftxui::Component& infoView, const ftxui::Component& filterView, const ftxui::Component& promotionView);
Manager(const ftxui::Component& infoView, const ftxui::Component& filterView);
};

class CommitInfoManager {
Expand Down Expand Up @@ -58,61 +58,3 @@ class BranchBoxManager {
*/
ftxui::Element branchBoxRender();
};

class ContentPromotionManager {
public:
// branch selection
ftxui::Component branchSelection; // must be set from OSTreeTUI
int selectedBranch{0};

// subject
ftxui::Component subjectComponent;

std::string newSubject{""};

// apply button
ftxui::Component applyButton; // must be set from OSTreeTUI

// tool-tips
bool show_tooltips{true};
ftxui::Component tool_tips_comp;
const std::vector<std::string> tool_tip_strings = {
"Branch to promote the Commit to.",
"New subject for promoted Commit (optional).",
"Apply the Commit Promotion (write to repository).",
};

public:
/**
* @brief Constructor for the Promotion Manager.
*
* @warning The branchSelection and applyButton have to be set
* using the respective set-methods AFTER construction, as they
* have to be constructed in the OSTreeTUI::main
*/
ContentPromotionManager(bool show_tooltips = true);

/// Setter
void setBranchRadiobox(ftxui::Component radiobox);
/// Setter
void setApplyButton(ftxui::Component button);

/**
* @brief Build the promotion view Component
*
* @warning branchSelection & applyButton have to be set first (checked through assert)
* @return ftxui::Component
*/
ftxui::Component composePromotionComponent();

/// renders the promotion command resulting from the current user settings (ostree commit ...)
ftxui::Elements renderPromotionCommand(cpplibostree::OSTreeRepo& ostreeRepo, const std::string& selectedCommitHash);

/**
* @brief Build the promotion view Element
*
* @warning branchSelection & applyButton have to be set first (checked through assert)
* @return ftxui::Element
*/
ftxui::Element renderPromotionView(cpplibostree::OSTreeRepo& ostreeRepo, int screenHeight, const cpplibostree::Commit& displayCommit);
};

0 comments on commit c7a4266

Please sign in to comment.