diff --git a/src/core/OSTreeTUI.cpp b/src/core/OSTreeTUI.cpp index 8e01ec0..0c41973 100644 --- a/src/core/OSTreeTUI.cpp +++ b/src/core/OSTreeTUI.cpp @@ -230,10 +230,41 @@ int OSTreeTUI::main(const std::string& repo, const std::vector& 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(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 diff --git a/src/core/commitComponent.cpp b/src/core/commitComponent.cpp index a81b08c..50076e9 100644 --- a/src/core/commitComponent.cpp +++ b/src/core/commitComponent.cpp @@ -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; @@ -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; } @@ -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; } @@ -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; @@ -302,6 +320,30 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { "", "oof", "foo", "fo/of/x86_64" }; std::unordered_map& 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