Skip to content

Commit c7a4266

Browse files
committed
Remove old promotion manager
1 parent c97f4cc commit c7a4266

File tree

3 files changed

+7
-195
lines changed

3 files changed

+7
-195
lines changed

src/core/OSTreeTUI.cpp

+3-23
Original file line numberDiff line numberDiff line change
@@ -100,27 +100,8 @@ int OSTreeTUI::main(const std::string& repo, const std::vector<std::string>& sta
100100
return filterManager.branchBoxRender();
101101
});
102102

103-
// promotion
104-
ContentPromotionManager promotionManager(showTooltips);
105-
promotionManager.setBranchRadiobox(Radiobox(&allBranches, &promotionManager.selectedBranch));
106-
promotionManager.setApplyButton(Button(" Apply ", [&] {
107-
ostreeRepo.promoteCommit(visibleCommitViewMap.at(selectedCommit),
108-
ostreeRepo.getBranches().at(static_cast<size_t>(promotionManager.selectedBranch)),
109-
{}, promotionManager.newSubject,
110-
true);
111-
//refresh_repository();
112-
notificationText = " Applied content promotion. ";
113-
}, ButtonOption::Simple()));
114-
Component promotionView = Renderer(promotionManager.composePromotionComponent(), [&] {
115-
if (visibleCommitViewMap.size() <= 0) {
116-
return text(" please select a commit to continue commit-promotion... ") | color(Color::RedLight) | bold | center;
117-
}
118-
return promotionManager.renderPromotionView(ostreeRepo, screen.dimy(),
119-
ostreeRepo.getCommitList().at(visibleCommitViewMap.at(selectedCommit)));
120-
});
121-
122103
// interchangeable view (composed)
123-
Manager manager(infoView, filterView, promotionView);
104+
Manager manager(infoView, filterView);
124105
Component managerRenderer = manager.managerRenderer;
125106

126107
// FOOTER
@@ -141,9 +122,8 @@ int OSTreeTUI::main(const std::string& repo, const std::vector<std::string>& sta
141122
* add deletion button & ask for confirmation (also add keyboard functionality)
142123
* TODO maybe re-arrange the manager window to remove the tabs again
143124
* now that promotion and deletion is gone / changed, we have enough rooom to fit both the info and the filter
144-
* TODO update the ostree-tui after promotion
145-
* the new, promoted (or deleted) commit doesn't get updated
146-
* might need a new component for that, as Component::Stacked seems like a fixed component (not modifyable)
125+
* TODO update the ostree-tui
126+
* after promotion & after filtering branches
147127
* TOOD code cleanup:
148128
* snake_case to camelCase (consistent)
149129
* make const& where applicable

src/core/manager.cpp

+2-112
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212

1313
// Manager
1414

15-
Manager::Manager(const ftxui::Component& infoView, const ftxui::Component& filterView, const ftxui::Component& promotionView) {
15+
Manager::Manager(const ftxui::Component& infoView, const ftxui::Component& filterView) {
1616
using namespace ftxui;
1717

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

2020
tabContent = Container::Tab({
2121
infoView,
22-
filterView,
23-
promotionView
22+
filterView
2423
},
2524
&tab_index);
2625

@@ -102,112 +101,3 @@ ftxui::Element CommitInfoManager::renderInfoView(const cpplibostree::Commit& dis
102101
filler()
103102
});
104103
}
105-
106-
// ContentPromotionManager
107-
108-
ContentPromotionManager::ContentPromotionManager(bool show_tooltips): show_tooltips(show_tooltips) {
109-
using namespace ftxui;
110-
111-
subjectComponent = Input(&newSubject, "subject");
112-
}
113-
114-
void ContentPromotionManager::setBranchRadiobox(ftxui::Component radiobox) {
115-
using namespace ftxui;
116-
117-
branchSelection = CatchEvent(radiobox, [&](const Event& event) {
118-
// copy commit id
119-
if (event == Event::Return) {
120-
subjectComponent->TakeFocus();
121-
}
122-
return false;
123-
});
124-
}
125-
126-
void ContentPromotionManager::setApplyButton(ftxui::Component button) {
127-
applyButton = button;
128-
}
129-
130-
ftxui::Elements ContentPromotionManager::renderPromotionCommand(cpplibostree::OSTreeRepo& ostreeRepo, const std::string& selectedCommitHash) {
131-
using namespace ftxui;
132-
133-
assert(branchSelection);
134-
assert(applyButton);
135-
136-
Elements line;
137-
line.push_back(text("ostree commit") | bold);
138-
line.push_back(text(" --repo=" + ostreeRepo.getRepoPath()) | bold);
139-
line.push_back(text(" -b " + ostreeRepo.getBranches().at(static_cast<size_t>(selectedBranch))) | bold);
140-
line.push_back(text(" --keep-metadata") | bold);
141-
// optional subject
142-
if (!newSubject.empty()) {
143-
line.push_back(text(" -s \"") | bold);
144-
line.push_back(text(newSubject) | color(Color::BlueLight) | bold);
145-
line.push_back(text("\"") | bold);
146-
}
147-
// commit
148-
line.push_back(text(" --tree=ref=" + selectedCommitHash) | bold);
149-
150-
return line;
151-
}
152-
153-
ftxui::Component ContentPromotionManager::composePromotionComponent() {
154-
using namespace ftxui;
155-
156-
return Container::Vertical({
157-
branchSelection,
158-
Container::Vertical({
159-
subjectComponent,
160-
applyButton,
161-
}),
162-
});
163-
}
164-
165-
ftxui::Element ContentPromotionManager::renderPromotionView(cpplibostree::OSTreeRepo& ostreeRepo, int screenHeight, const cpplibostree::Commit& displayCommit) {
166-
using namespace ftxui;
167-
168-
assert(branchSelection);
169-
assert(applyButton);
170-
171-
// compute screen element sizes
172-
int screenOverhead {8}; // borders, footer, etc.
173-
int commitWinHeight {3};
174-
int apsectWinHeight {8};
175-
int tooltipsWinHeight {2};
176-
int branchSelectWinHeight = screenHeight - screenOverhead - commitWinHeight - apsectWinHeight - tooltipsWinHeight;
177-
// tooltips only get shown, if the window is sufficiently large
178-
if (branchSelectWinHeight < 4) {
179-
tooltipsWinHeight = 0;
180-
branchSelectWinHeight = 4;
181-
}
182-
183-
// build elements
184-
auto commitHashElem = vbox({text(" Commit: ") | bold | color(Color::Green), text(" " + displayCommit.hash)}) | flex;
185-
auto branchWin = window(text("New Branch"), branchSelection->Render() | vscroll_indicator | frame);
186-
auto subjectWin = window(text("Subject"), subjectComponent->Render()) | flex;
187-
auto applyButtonWin = applyButton->Render() | color(Color::Green) | size(WIDTH, GREATER_THAN, 9) | flex;
188-
189-
auto toolTipContent = [&](size_t tip) {
190-
return vbox({
191-
separatorCharacter(""),
192-
text(" 🛈 " + tool_tip_strings.at(tip)),
193-
});
194-
};
195-
auto toolTipsWin = !show_tooltips || tooltipsWinHeight < 2 ? filler() : // only show if screen is reasonable size
196-
branchSelection->Focused() ? toolTipContent(0) :
197-
subjectComponent->Focused() ? toolTipContent(1) :
198-
applyButton->Focused() ? toolTipContent(2) :
199-
filler();
200-
201-
// build element composition
202-
return vbox({
203-
commitHashElem | size(HEIGHT, EQUAL, commitWinHeight),
204-
branchWin | size(HEIGHT, LESS_THAN, branchSelectWinHeight),
205-
vbox({
206-
subjectWin,
207-
applyButtonWin,
208-
}) | flex | size(HEIGHT, LESS_THAN, apsectWinHeight),
209-
hflow(renderPromotionCommand(ostreeRepo, displayCommit.hash)) | flex_grow,
210-
filler(),
211-
toolTipsWin,
212-
}) | flex_grow;
213-
}

src/core/manager.hpp

+2-60
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Manager {
1919
int tab_index{0};
2020

2121
std::vector<std::string> tab_entries = {
22-
" Info ", " Filter ", " Promote "
22+
" Info ", " Filter "
2323
};
2424

2525
ftxui::Component tabSelection;
@@ -30,7 +30,7 @@ class Manager {
3030
ftxui::Component managerRenderer;
3131

3232
public:
33-
Manager(const ftxui::Component& infoView, const ftxui::Component& filterView, const ftxui::Component& promotionView);
33+
Manager(const ftxui::Component& infoView, const ftxui::Component& filterView);
3434
};
3535

3636
class CommitInfoManager {
@@ -58,61 +58,3 @@ class BranchBoxManager {
5858
*/
5959
ftxui::Element branchBoxRender();
6060
};
61-
62-
class ContentPromotionManager {
63-
public:
64-
// branch selection
65-
ftxui::Component branchSelection; // must be set from OSTreeTUI
66-
int selectedBranch{0};
67-
68-
// subject
69-
ftxui::Component subjectComponent;
70-
71-
std::string newSubject{""};
72-
73-
// apply button
74-
ftxui::Component applyButton; // must be set from OSTreeTUI
75-
76-
// tool-tips
77-
bool show_tooltips{true};
78-
ftxui::Component tool_tips_comp;
79-
const std::vector<std::string> tool_tip_strings = {
80-
"Branch to promote the Commit to.",
81-
"New subject for promoted Commit (optional).",
82-
"Apply the Commit Promotion (write to repository).",
83-
};
84-
85-
public:
86-
/**
87-
* @brief Constructor for the Promotion Manager.
88-
*
89-
* @warning The branchSelection and applyButton have to be set
90-
* using the respective set-methods AFTER construction, as they
91-
* have to be constructed in the OSTreeTUI::main
92-
*/
93-
ContentPromotionManager(bool show_tooltips = true);
94-
95-
/// Setter
96-
void setBranchRadiobox(ftxui::Component radiobox);
97-
/// Setter
98-
void setApplyButton(ftxui::Component button);
99-
100-
/**
101-
* @brief Build the promotion view Component
102-
*
103-
* @warning branchSelection & applyButton have to be set first (checked through assert)
104-
* @return ftxui::Component
105-
*/
106-
ftxui::Component composePromotionComponent();
107-
108-
/// renders the promotion command resulting from the current user settings (ostree commit ...)
109-
ftxui::Elements renderPromotionCommand(cpplibostree::OSTreeRepo& ostreeRepo, const std::string& selectedCommitHash);
110-
111-
/**
112-
* @brief Build the promotion view Element
113-
*
114-
* @warning branchSelection & applyButton have to be set first (checked through assert)
115-
* @return ftxui::Element
116-
*/
117-
ftxui::Element renderPromotionView(cpplibostree::OSTreeRepo& ostreeRepo, int screenHeight, const cpplibostree::Commit& displayCommit);
118-
};

0 commit comments

Comments
 (0)