Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Naming Consistent #29

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ add_library(ostree-tui_core commit.cpp
footer.hpp
manager.cpp
manager.hpp
OSTreeTUI.cpp
OSTreeTUI.hpp
trashBin.cpp
trashBin.hpp)
ostreetui.cpp
ostreetui.hpp
trashbin.cpp
trashbin.hpp)

target_link_libraries(ostree-tui_core
PRIVATE clip
Expand Down
75 changes: 37 additions & 38 deletions src/core/commit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "../util/cpplibostree.hpp"

#include "OSTreeTUI.hpp"
#include "ostreetui.hpp"

namespace CommitRender {

Expand Down Expand Up @@ -76,8 +76,8 @@ Element DefaultRenderState(const WindowRenderState& state,
class CommitComponentImpl : public ComponentBase, public WindowOptions {
public:
explicit CommitComponentImpl(size_t position, std::string commit, OSTreeTUI& ostreetui)
: drag_initial_x(1),
drag_initial_y(static_cast<int>(position) * COMMIT_WINDOW_HEIGHT),
: defaultX(1),
defaultY(static_cast<int>(position) * COMMIT_WINDOW_HEIGHT),
commitPosition(position),
hash(std::move(commit)),
ostreetui(ostreetui),
Expand All @@ -96,20 +96,20 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
Add(inner);

title = hash.substr(0, 8);
top = drag_initial_y;
left = drag_initial_x;
top = defaultY;
left = defaultX;
width = COMMIT_WINDOW_WIDTH;
height = COMMIT_WINDOW_HEIGHT;
}

private:
void resetWindow(bool positionReset = true) {
if (positionReset) {
left() = drag_initial_x;
top() = drag_initial_y;
left() = defaultX;
top() = defaultY;
}
width() = width_initial;
height() = height_initial;
width() = defaultWidth;
height() = defaultHeight;
// reset window contents
DetachAllChildren();
Add(simpleCommit);
Expand Down Expand Up @@ -202,7 +202,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
}

// Position and record the drawn area of the window.
element |= reflect(box_window_);
element |= reflect(boxWindow_);
element |= PositionAndSize(left(), top() + ostreetui.GetScrollOffset(), width(), height());
element |= reflect(box_);

Expand Down Expand Up @@ -253,22 +253,22 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
return true;
}

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

if (mouse_hover_ && event.mouse().button == Mouse::Left) {
if (mouseHover_ && event.mouse().button == Mouse::Left) {
ostreetui.SetSelectedCommit(commitPosition);
}

if (captured_mouse_) {
if (capturedMouse_) {
if (event.mouse().motion == Mouse::Released) {
// reset mouse
captured_mouse_ = nullptr;
capturedMouse_ = nullptr;
// drop commit
if (event.mouse().y > ostreetui.GetScreen().dimy() - 8) {
ostreetui.SetViewMode(ViewMode::COMMIT_DROP, hash);
ostreetui.SetModeBranch(
ostreetui.GetOstreeRepo().GetCommitList().at(hash).branch);
top() = drag_initial_y;
top() = defaultY;
}
// check if position matches branch & do something if it does
else if (ostreetui.GetModeBranch().empty()) {
Expand All @@ -281,8 +281,8 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
}

if (drag_) {
left() = event.mouse().x - drag_start_x - box_.x_min;
top() = event.mouse().y - drag_start_y - box_.y_min;
left() = event.mouse().x - dragStartX - box_.x_min;
top() = event.mouse().y - dragStartY - box_.y_min;
ostreetui.SetViewMode(ViewMode::COMMIT_DRAGGING, hash);
// check if potential commit deletion
if (event.mouse().y > ostreetui.GetScreen().dimy() - 8) {
Expand Down Expand Up @@ -318,7 +318,7 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {
return true;
}

if (!mouse_hover_) {
if (!mouseHover_) {
return false;
}

Expand All @@ -335,38 +335,37 @@ class CommitComponentImpl : public ComponentBase, public WindowOptions {

TakeFocus();

captured_mouse_ = CaptureMouse(event);
if (!captured_mouse_) {
capturedMouse_ = CaptureMouse(event);
if (!capturedMouse_) {
return true;
}

drag_start_x = event.mouse().x - left() - box_.x_min;
drag_start_y = event.mouse().y - top() - box_.y_min;
dragStartX = event.mouse().x - left() - box_.x_min;
dragStartY = event.mouse().y - top() - box_.y_min;

const bool drag_old = drag_;
const bool dragOld = drag_;
drag_ = true;
if (!drag_old && drag_) { // if we start dragging
drag_initial_x = left();
drag_initial_y = top();
if (!dragOld && drag_) { // if we start dragging
defaultX = left();
defaultY = top();
}
return true;
}

// window specific members
Box box_;
Box box_window_;
Box boxWindow_;

CapturedMouse captured_mouse_;
int drag_start_x = 0;
int drag_start_y = 0;

int drag_initial_x;
int drag_initial_y;
int width_initial = COMMIT_WINDOW_WIDTH;
int height_initial = COMMIT_WINDOW_HEIGHT;

bool mouse_hover_ = false;
bool mouseHover_ = false;
bool drag_ = false;
CapturedMouse capturedMouse_;
int dragStartX = 0;
int dragStartY = 0;

int defaultX;
int defaultY;
int defaultWidth = COMMIT_WINDOW_WIDTH;
int defaultHeight = COMMIT_WINDOW_HEIGHT;

// ostree-tui specific members
size_t commitPosition;
Expand Down Expand Up @@ -447,7 +446,7 @@ ftxui::Component CommitComponent(size_t position, const std::string& commit, OST
return ftxui::Make<CommitComponentImpl>(position, commit, ostreetui);
}

ftxui::Element commitRender(OSTreeTUI& ostreetui,
ftxui::Element CommitRender(OSTreeTUI& ostreetui,
const std::unordered_map<std::string, ftxui::Color>& branchColorMap) {
using namespace ftxui;

Expand Down
2 changes: 1 addition & 1 deletion src/core/commit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ enum RenderTree : uint8_t {
* @param selectedCommit Commit that should be marked as selected.
* @return UI Element
*/
[[nodiscard]] ftxui::Element commitRender(
[[nodiscard]] ftxui::Element CommitRender(
OSTreeTUI& ostreetui,
const std::unordered_map<std::string, ftxui::Color>& branchColorMap);

Expand Down
2 changes: 1 addition & 1 deletion src/core/footer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Footer {
void ResetContent();

/// @brief Creates a Renderer for the footer section.
ftxui::Element FooterRender();
[[nodiscard]] ftxui::Element FooterRender();

// Setter
void SetContent(std::string content);
Expand Down
20 changes: 10 additions & 10 deletions src/core/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "../util/cpplibostree.hpp"

#include "OSTreeTUI.hpp"
#include "ostreetui.hpp"

// Manager

Expand All @@ -20,9 +20,9 @@ Manager::Manager(OSTreeTUI& ostreetui,
: ostreetui(ostreetui) {
using namespace ftxui;

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

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

managerRenderer = Container::Vertical(
{tabSelection, tabContent,
Expand All @@ -38,12 +38,12 @@ Manager::Manager(OSTreeTUI& ostreetui,
})});
}

ftxui::Component Manager::getManagerRenderer() {
ftxui::Component Manager::GetManagerRenderer() {
return managerRenderer;
}

int Manager::getTabIndex() const {
return tab_index;
int Manager::GetTabIndex() const {
return tabIndex;
}

// BranchBoxManager
Expand All @@ -63,21 +63,21 @@ BranchBoxManager::BranchBoxManager(OSTreeTUI& ostreetui,
}
}

ftxui::Element BranchBoxManager::branchBoxRender() {
ftxui::Element BranchBoxManager::BranchBoxRender() {
using namespace ftxui;

// branch filter
Elements bfb_elements = {
Elements bfbElements = {
text(L"branches:") | bold,
filler(),
branchBoxes->Render() | vscroll_indicator | frame | size(HEIGHT, LESS_THAN, 10),
};
return vbox(bfb_elements);
return vbox(bfbElements);
}

// CommitInfoManager

ftxui::Element CommitInfoManager::renderInfoView(const cpplibostree::Commit& displayCommit) {
ftxui::Element CommitInfoManager::RenderInfoView(const cpplibostree::Commit& displayCommit) {
using namespace ftxui;

// selected commit info
Expand Down
16 changes: 8 additions & 8 deletions src/core/manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ class Manager {
const ftxui::Component& infoView,
const ftxui::Component& filterView);

public:
[[nodiscard]] ftxui::Component GetManagerRenderer();
[[nodiscard]] int GetTabIndex() const;

private:
OSTreeTUI& ostreetui;

int tab_index{0};
std::vector<std::string> tab_entries = {" Info ", " Filter "};
int tabIndex{0};
std::vector<std::string> tabEntries = {" Info ", " Filter "};

// because the combination of all interchangeable views is very simple,
// we can (in contrast to the other ones) render this one here
ftxui::Component managerRenderer;
ftxui::Component tabSelection;
ftxui::Component tabContent;

public:
ftxui::Component getManagerRenderer();
int getTabIndex() const;
};

class CommitInfoManager {
Expand All @@ -46,7 +46,7 @@ class CommitInfoManager {
* @param displayCommit Commit to display the information of.
* @return ftxui::Element
*/
[[nodiscard]] static ftxui::Element renderInfoView(const cpplibostree::Commit& displayCommit);
[[nodiscard]] static ftxui::Element RenderInfoView(const cpplibostree::Commit& displayCommit);
};

class BranchBoxManager {
Expand All @@ -60,7 +60,7 @@ class BranchBoxManager {
*
* @return ftxui::Element
*/
[[nodiscard]] ftxui::Element branchBoxRender();
[[nodiscard]] ftxui::Element BranchBoxRender();

public:
ftxui::Component branchBoxes = ftxui::Container::Vertical({});
Expand Down
18 changes: 9 additions & 9 deletions src/core/OSTreeTUI.cpp → src/core/ostreetui.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "OSTreeTUI.hpp"
#include "ostreetui.hpp"

#include <fcntl.h>
#include <algorithm>
Expand Down Expand Up @@ -55,9 +55,9 @@ OSTreeTUI::OSTreeTUI(const std::string& repo, const std::vector<std::string>& st
promotionBranchColorMap.insert({str, Color::GrayDark});
}
}
return CommitRender::commitRender(*this, promotionBranchColorMap);
return CommitRender::CommitRender(*this, promotionBranchColorMap);
}
return CommitRender::commitRender(*this, branchColorMap);
return CommitRender::CommitRender(*this, branchColorMap);
});

commitListComponent = Container::Horizontal({tree, commitList});
Expand Down Expand Up @@ -87,19 +87,19 @@ OSTreeTUI::OSTreeTUI(const std::string& repo, const std::vector<std::string>& st
if (visibleCommitViewMap.size() <= 0) {
return text(" no commit info available ") | color(Color::RedLight) | bold | center;
}
return CommitInfoManager::renderInfoView(
return CommitInfoManager::RenderInfoView(
ostreeRepo.GetCommitList().at(visibleCommitViewMap.at(selectedCommit)));
});

// filter
filterManager =
std::unique_ptr<BranchBoxManager>(new BranchBoxManager(*this, ostreeRepo, visibleBranches));
filterView =
Renderer(filterManager->branchBoxes, [&] { return filterManager->branchBoxRender(); });
Renderer(filterManager->branchBoxes, [&] { return filterManager->BranchBoxRender(); });

// interchangeable view (composed)
manager = std::unique_ptr<Manager>(new Manager(*this, infoView, filterView));
managerRenderer = manager->getManagerRenderer();
managerRenderer = manager->GetManagerRenderer();

// FOOTER
FooterRenderer = Renderer([&] { return footer.FooterRender(); });
Expand Down Expand Up @@ -143,7 +143,7 @@ OSTreeTUI::OSTreeTUI(const std::string& repo, const std::vector<std::string>& st
}
// make commit list focussable
if (event == Event::ArrowLeft && managerRenderer->Focused() &&
manager->getTabIndex() == 0) {
manager->GetTabIndex() == 0) {
commitListComponent->TakeFocus();
return true;
}
Expand Down Expand Up @@ -380,7 +380,7 @@ int OSTreeTUI::showHelp(const std::string& caller, const std::string& errorMessa
using namespace ftxui;

// define command line options
std::vector<std::vector<std::string>> command_options{
std::vector<std::vector<std::string>> commandOptions{
// option, arguments, meaning
{"-h, --help", "", "Show help options. The REPOSITORY_PATH can be omitted"},
{"-r, --refs", "REF [REF...]",
Expand All @@ -390,7 +390,7 @@ int OSTreeTUI::showHelp(const std::string& caller, const std::string& errorMessa
Elements options{text("Options:")};
Elements arguments{text("Arguments:")};
Elements meanings{text("Meaning:")};
for (const auto& command : command_options) {
for (const auto& command : commandOptions) {
options.push_back(text(command.at(0) + " ") | color(Color::GrayLight));
arguments.push_back(text(command.at(1) + " ") | color(Color::GrayLight));
meanings.push_back(text(command.at(2) + " "));
Expand Down
2 changes: 1 addition & 1 deletion src/core/OSTreeTUI.hpp → src/core/ostreetui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "commit.hpp"
#include "footer.hpp"
#include "manager.hpp"
#include "trashBin.hpp"
#include "trashbin.hpp"

#include "../util/cpplibostree.hpp"

Expand Down
Loading
Loading