Skip to content

Commit

Permalink
Create Promotion Window
Browse files Browse the repository at this point in the history
  • Loading branch information
forgottosave committed Oct 28, 2024
1 parent 6975a1b commit d88d117
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 5 deletions.
33 changes: 32 additions & 1 deletion src/core/OSTreeTUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,41 @@ int OSTreeTUI::main(const std::string& repo, const std::vector<std::string>& sta
}
return CommitRender::commitRender(ostreeRepo, visibleCommitViewMap, visibleBranches, promotionBranchColorMap, selectedCommit);
}
//if (promotionHash.size() != 0) {
// // open commit promotion window
// commitComponents.push_back(
// Window({
// .inner = Renderer([&] {
// return vbox({
// text("Promote Commit?"),
// text(""),
// text("commit: " + promotionHash),
// text(" " + ostreeRepo.getCommitList().at(promotionHash).subject),
// text(" " + std::format("{:%Y-%m-%d %T %Ez}", std::chrono::time_point_cast<std::chrono::seconds>(ostreeRepo.getCommitList().at(promotionHash).timestamp))),
// text(""),
// text("onto branch " + promotionBranch),
// text(""),
// text("Yes / No")
// });
// }),
// .title = "",
// .left = 1,
// .top = 1,
// .width = 40,
// .height = 40,
// .resize_left = false,
// .resize_right = false,
// .resize_top = false,
// .resize_down = false,
// })
// );
//}
return CommitRender::commitRender(ostreeRepo, visibleCommitViewMap, visibleBranches, branchColorMap, selectedCommit);
}),
// commit list
commitComponents.size() == 0 ? Renderer([&] { return text(" no commits to be shown ") | color(Color::Red); }) : Container::Stacked(commitComponents)
commitComponents.size() == 0
? Renderer([&] { return text(" no commits to be shown ") | color(Color::Red); })
: Container::Stacked(commitComponents)
});

// window specific shortcuts
Expand Down
50 changes: 46 additions & 4 deletions src/core/commitComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
return false;
}

//if (inPromotionSelection && ! drag_) {
// return true;
//}

mouse_hover_ = box_window_.Contain(event.mouse().x, event.mouse().y);

resize_down_hover_ = false;
Expand All @@ -155,16 +159,27 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
if (event.mouse().motion == Mouse::Released) {
// reset mouse
captured_mouse_ = nullptr;
// reset window position
left() = drag_initial_x;
top() = drag_initial_y;
// TODO check if position matches branch & do something if it does
if (false) {
if (promotionBranch.size() != 0) {
// initiate promotion
// TODO do not hardcode
inPromotionSelection = true;
promotionHash = "49febbd98626719cf10b36e6c859a5132e2163f4752c10d841bc8ac596f9d0f7";
// take this commit window and resize it. Add buttons to .inner to confirm promotion
//title = "Promote commit " + promotionHash.substr(0, 8);
left() = std::max(left(),-2);
width() += 8;
height() += 20;
// TODO change inner to promotion layout
DetachAllChildren();
Add(promotionView);
} else {
// not promotion
inPromotionSelection = false;
promotionBranch = "";
// reset window position
left() = drag_initial_x;
top() = drag_initial_y;
}
return true;
}
Expand Down Expand Up @@ -201,6 +216,8 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
++count;
}
if (count == branch_pos) {
// problem -> branch sorting not stored anywhere...
// promotionBranch = branch;
promotionBranch = branch_mapping.at(event.mouse().x / 2);
break;
}
Expand Down Expand Up @@ -293,6 +310,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
int& scroll_offset;

// ostree-tui specific members
// TODO store commit data
// common / shared variables to set the promotion state
bool& inPromotionSelection;
std::string& promotionHash;
Expand All @@ -302,6 +320,30 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
"", "oof", "foo", "fo/of/x86_64"
};
std::unordered_map<std::string, bool>& visibleBranches;

// promotion view
bool promoting{false};
Component promotionView = Container::Vertical({
Renderer([&] {
return vbox({
text(""),
text(" Promote Commit...") | bold,
text(""),
text(" ☐ todocommithash") | bold,
text(" ┆ subject: TODO add commit subject"),
text(" ┆ time: T0.D0.2024 to:do"),
text(""),
text(" ┆ to branch:"),
text("" + promotionBranch) | bold,
text("") | bold,
text("")
});
}),
Container::Horizontal({
Button(" Cancel [n]", [&] { promoting = false; }) | color(Color::Red) | flex,
Button(" Promote [y]", [&] { promoting = true; }) | color(Color::Green) | flex,
})
});
};

} // namespace
Expand Down

0 comments on commit d88d117

Please sign in to comment.