From 361654e33cc0bf8f9aed2d1ff5607da29decdfc5 Mon Sep 17 00:00:00 2001 From: Timon Ensel Date: Fri, 8 Nov 2024 17:38:15 +0100 Subject: [PATCH] Add keyboard functionality --- src/core/OSTreeTUI.cpp | 37 +++++++++++++------------------------ src/core/commit.cpp | 18 +++++++++++++++++- src/core/footer.hpp | 2 +- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/core/OSTreeTUI.cpp b/src/core/OSTreeTUI.cpp index 193670d..53a402b 100644 --- a/src/core/OSTreeTUI.cpp +++ b/src/core/OSTreeTUI.cpp @@ -44,24 +44,13 @@ OSTreeTUI::OSTreeTUI (const std::string& repo, const std::vector st visibleCommitViewMap = parseVisibleCommitMap(ostreeRepo, visibleBranches); // TODO This update shouldn't be made here... // COMMIT TREE -/* The commit-tree is currentrly under a heavy rebuild, see implementation To-Dos below. - * For a general list of To-Dos refer to https://github.com/AP-Sensing/ostree-tui/pull/21 - * - * TODO extend with keyboard functionality: - * normal scrolling through commits (should also highlight selected commit) - * if 'p' is pressed: start promotion - * if 'd' is pressed: open deletion window - */ - // commit promotion state - // TODO especially needed for keyboard shortcuts - // store shared information about which commit is in which state - // each commit can then display itself the way it should - // * is promotion action active? - // * keyboard or mouse? - // * which commit? - // * is deletion action active? - // * keyboard or mouse? - // * which commit? + /* The commit-tree is currentrly under a heavy rebuild, see implementation To-Dos below. + * For a general list of To-Dos refer to https://github.com/AP-Sensing/ostree-tui/pull/21 + * + * TODO bug fixes: + * > updates (update commit-list when promoting) + * > keyboard functionality (especially in-app navigation) + */ // parse all commits refresh_commitComponents(); @@ -158,11 +147,11 @@ OSTreeTUI::OSTreeTUI (const std::string& repo, const std::vector st // add application shortcuts mainContainer = CatchEvent(container | border, [&](const Event& event) { - //if (event == Event::Character('p')) { - // inPromotionSelection = true; - // promotionHash = visibleCommitViewMap.at(selectedCommit); - // promotionBranch = columnToBranchMap.at(0); - //} + if (event == Event::AltP) { + inPromotionSelection = true; + promotionHash = visibleCommitViewMap.at(selectedCommit); + promotionBranch = columnToBranchMap.at(0); + } // copy commit id if (event == Event::AltC) { std::string hash = visibleCommitViewMap.at(selectedCommit); @@ -178,7 +167,7 @@ OSTreeTUI::OSTreeTUI (const std::string& repo, const std::vector st return true; } // exit - if (event == Event::AltQ || event == Event::Escape) { + if (event == Event::AltQ) { screen.ExitLoopClosure()(); return true; } diff --git a/src/core/commit.cpp b/src/core/commit.cpp index 9ea9ae8..a2133ee 100644 --- a/src/core/commit.cpp +++ b/src/core/commit.cpp @@ -78,7 +78,9 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { title = hash.substr(0, 8); top = position * 4; - left = 1; + drag_initial_y = top(); + left = 1; + drag_initial_x = left(); width = 30; height = 4; } @@ -102,9 +104,15 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { simpleCommit = inner; DetachAllChildren(); Add(promotionView); + TakeFocus(); } Element Render() final { + // check if promotion was started not from drag & drop, but from ostreetui + if (ostreetui.inPromotionSelection && ostreetui.promotionHash == hash) { + startPromotionWindow(); + } + auto element = ComponentBase::Render(); const WindowRenderState state = { @@ -130,6 +138,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { } if (ostreetui.inPromotionSelection) { + // navigate promotion branches if (event == Event::ArrowLeft) { int it = std::find(ostreetui.columnToBranchMap.begin(), ostreetui.columnToBranchMap.end(), ostreetui.promotionBranch) - ostreetui.columnToBranchMap.begin(); ostreetui.promotionBranch = ostreetui.columnToBranchMap.at((it - 1) % ostreetui.columnToBranchMap.size()); @@ -140,6 +149,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { ostreetui.promotionBranch = ostreetui.columnToBranchMap.at((it + 1) % ostreetui.columnToBranchMap.size()); return true; } + // promote if (event == Event::Return) { ostreetui.ostreeRepo.promoteCommit(hash, ostreetui.promotionBranch, {}, newSubject, true); resetWindow(); @@ -147,6 +157,12 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions { ostreetui.refresh = true; return true; } + // cancel + if (event == Event::Escape) { + ostreetui.inPromotionSelection = false; + resetWindow(); + return true; + } } if (!event.is_mouse()) { diff --git a/src/core/footer.hpp b/src/core/footer.hpp index 289467d..801df3f 100644 --- a/src/core/footer.hpp +++ b/src/core/footer.hpp @@ -7,7 +7,7 @@ class Footer { public: - const std::string DEFAULT_CONTENT {" || Alt+Q / Esc : Quit || Alt+R : Refresh || Alt+C : Copy commit hash || "}; + const std::string DEFAULT_CONTENT {" || Alt+Q : Quit || Alt+R : Refresh || Alt+C : Copy commit hash || Alt+P : Promote Commit "}; std::string content {DEFAULT_CONTENT}; public: