feat(toolbar): add configurable pull actions
This commit is contained in:
@@ -31,8 +31,10 @@ void UserData::load() {
|
||||
std::string key;
|
||||
while (settings >> key) {
|
||||
if (key == "sidebar_width") settings >> sidebar_width_;
|
||||
else if (key == "pull_mode") settings >> pull_mode_;
|
||||
}
|
||||
sidebar_width_ = std::clamp(sidebar_width_, 180.0f, 520.0f);
|
||||
pull_mode_ = std::clamp(pull_mode_, 0, 3);
|
||||
|
||||
std::ifstream history(directory_ / "history.txt");
|
||||
std::string path;
|
||||
@@ -54,6 +56,7 @@ void UserData::save() const {
|
||||
std::filesystem::create_directories(directory_);
|
||||
std::ofstream settings(directory_ / "settings.ini", std::ios::trunc);
|
||||
settings << "sidebar_width " << sidebar_width_ << '\n';
|
||||
settings << "pull_mode " << pull_mode_ << '\n';
|
||||
|
||||
std::ofstream history(directory_ / "history.txt", std::ios::trunc);
|
||||
for (const auto& path : recently_closed_) history << std::quoted(path) << '\n';
|
||||
|
||||
@@ -13,8 +13,10 @@ public:
|
||||
[[nodiscard]] const std::string& imguiIniPath() const { return imgui_ini_path_; }
|
||||
[[nodiscard]] const std::vector<std::string>& recentlyClosed() const { return recently_closed_; }
|
||||
[[nodiscard]] float sidebarWidth() const { return sidebar_width_; }
|
||||
[[nodiscard]] int pullMode() const { return pull_mode_; }
|
||||
|
||||
void setSidebarWidth(float width) { sidebar_width_ = width; }
|
||||
void setPullMode(int mode) { pull_mode_ = mode; save(); }
|
||||
void addRecentlyClosed(const std::string& path);
|
||||
void save() const;
|
||||
|
||||
@@ -25,4 +27,5 @@ private:
|
||||
std::string imgui_ini_path_;
|
||||
std::vector<std::string> recently_closed_;
|
||||
float sidebar_width_ = 230.0f;
|
||||
int pull_mode_ = 1;
|
||||
};
|
||||
|
||||
@@ -593,12 +593,17 @@ void draw_details() {
|
||||
}
|
||||
|
||||
bool toolbar_action(const char* id, const char* label, const char* icon, const char* tooltip,
|
||||
bool enabled = true, bool dropdown = false, float logical_width = 58.0f) {
|
||||
bool enabled = true, bool dropdown = false, float logical_width = 58.0f,
|
||||
bool* dropdown_clicked = nullptr) {
|
||||
ImGui::PushID(id);
|
||||
if (!enabled) ImGui::BeginDisabled();
|
||||
const bool clicked = ImGui::InvisibleButton("##action", {ui(logical_width), ui(58.0f)});
|
||||
const bool raw_clicked = ImGui::InvisibleButton("##action", {ui(logical_width), ui(58.0f)});
|
||||
const ImVec2 minimum = ImGui::GetItemRectMin();
|
||||
const ImVec2 maximum = ImGui::GetItemRectMax();
|
||||
const bool clicked_dropdown = raw_clicked && dropdown &&
|
||||
ImGui::GetIO().MousePos.x >= maximum.x - ui(20.0f);
|
||||
if (dropdown_clicked) *dropdown_clicked = clicked_dropdown;
|
||||
const bool clicked = raw_clicked && !clicked_dropdown;
|
||||
ImDrawList* draw = ImGui::GetWindowDrawList();
|
||||
if (enabled && ImGui::IsItemHovered())
|
||||
draw->AddRectFilled(minimum, maximum, IM_COL32(55, 62, 74, 180), ui(3.0f));
|
||||
@@ -621,6 +626,38 @@ bool toolbar_action(const char* id, const char* label, const char* icon, const c
|
||||
return clicked;
|
||||
}
|
||||
|
||||
const char* pull_mode_name(int mode) {
|
||||
constexpr const char* names[] = {
|
||||
"Fetch All",
|
||||
"Pull (fast-forward if possible)",
|
||||
"Pull (fast-forward only)",
|
||||
"Pull (rebase)",
|
||||
};
|
||||
return names[std::clamp(mode, 0, 3)];
|
||||
}
|
||||
|
||||
void draw_pull_options() {
|
||||
ImGui::SetNextWindowSize({ui(270), 0});
|
||||
if (!ImGui::BeginPopup("pull_options")) return;
|
||||
|
||||
ImGui::PushTextWrapPos(ImGui::GetCursorPosX() + ui(245));
|
||||
ImGui::TextDisabled("Select a default pull/fetch operation to execute when clicking this button");
|
||||
ImGui::PopTextWrapPos();
|
||||
ImGui::Separator();
|
||||
|
||||
int selected = g_user_data->pullMode();
|
||||
for (int mode = 0; mode < 4; ++mode) {
|
||||
ImGui::PushID(mode);
|
||||
if (ImGui::RadioButton(pull_mode_name(mode), selected == mode)) {
|
||||
g_user_data->setPullMode(mode);
|
||||
g_notice = std::string("Default action: ") + pull_mode_name(mode);
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
bool toolbar_selector(const char* id, const char* label, const std::string& value,
|
||||
float logical_width, bool trailing_arrow = false) {
|
||||
ImGui::PushID(id);
|
||||
@@ -880,8 +917,12 @@ void draw_app() {
|
||||
ImGui::SameLine(0, action_spacing);
|
||||
toolbar_action("redo", "Redo", ICON_FA_ROTATE_RIGHT, "Redo last Git action", false, false, 54);
|
||||
ImGui::SameLine(0, action_spacing);
|
||||
if (toolbar_action("pull", "Pull", ICON_FA_DOWNLOAD, "Pull from remote", true, true, 58))
|
||||
g_notice = "Pull is not wired yet";
|
||||
bool pull_dropdown_clicked = false;
|
||||
if (toolbar_action("pull", "Pull", ICON_FA_DOWNLOAD, pull_mode_name(g_user_data->pullMode()),
|
||||
true, true, 58, &pull_dropdown_clicked))
|
||||
g_notice = std::string(pull_mode_name(g_user_data->pullMode())) + " is not wired yet";
|
||||
if (pull_dropdown_clicked) ImGui::OpenPopup("pull_options");
|
||||
draw_pull_options();
|
||||
ImGui::SameLine(0, action_spacing);
|
||||
if (toolbar_action("push", "Push", ICON_FA_UPLOAD, "Push to remote", true, false, 58))
|
||||
g_notice = "Push is not wired yet";
|
||||
|
||||
Reference in New Issue
Block a user