[feat] optimize certificate selection table

This commit is contained in:
dijunkun
2025-10-24 17:39:25 +08:00
parent 9f80d4f69d
commit 911dce2e71
2 changed files with 63 additions and 49 deletions

View File

@@ -458,6 +458,7 @@ class Render {
bool self_hosted_server_config_window_pos_reset_ = true; bool self_hosted_server_config_window_pos_reset_ = true;
std::string selected_current_file_path_ = ""; std::string selected_current_file_path_ = "";
std::string selected_file_ = ""; std::string selected_file_ = "";
bool show_file_browser_ = true;
/* ------ main window property end ------ */ /* ------ main window property end ------ */
/* ------ sub stream window property start ------ */ /* ------ sub stream window property start ------ */

View File

@@ -28,6 +28,11 @@ std::vector<std::string> GetRootEntries() {
int Render::ShowSimpleFileBrowser() { int Render::ShowSimpleFileBrowser() {
std::string display_text; std::string display_text;
if (selected_current_file_path_.empty()) {
selected_current_file_path_ = std::filesystem::current_path().string();
}
if (!selected_file_.empty()) { if (!selected_file_.empty()) {
display_text = std::filesystem::path(selected_file_).filename().string(); display_text = std::filesystem::path(selected_file_).filename().string();
} else if (selected_current_file_path_ != "Root") { } else if (selected_current_file_path_ != "Root") {
@@ -43,16 +48,21 @@ int Render::ShowSimpleFileBrowser() {
localization::select_a_file[localization_language_index_].c_str(); localization::select_a_file[localization_language_index_].c_str();
} }
// 设置固定宽度 if (show_file_browser_) {
// ImGui::SetNextItemWidth(SELF_HOSTED_SERVER_INPUT_WINDOW_WIDTH); ImGui::PushItemFlag(ImGuiItemFlags_AutoClosePopups, false);
ImGui::PushItemFlag(ImGuiItemFlags_AutoClosePopups, false); // 禁用自动关闭 float fixed_width = 130.0f;
if (ImGui::BeginCombo("##select_a_file", display_text.c_str())) { ImGui::SetNextItemWidth(fixed_width);
ImGui::SetNextWindowSizeConstraints(ImVec2(fixed_width, 0),
ImVec2(fixed_width, 100.0f));
if (ImGui::BeginCombo("##select_a_file", display_text.c_str(), 0)) {
bool file_selected = false; bool file_selected = false;
auto roots = GetRootEntries();
if (selected_current_file_path_ == "Root" || if (selected_current_file_path_ == "Root" ||
!std::filesystem::exists(selected_current_file_path_) || !std::filesystem::exists(selected_current_file_path_) ||
!std::filesystem::is_directory(selected_current_file_path_)) { !std::filesystem::is_directory(selected_current_file_path_)) {
auto roots = GetRootEntries();
for (const auto& root : roots) { for (const auto& root : roots) {
if (ImGui::Selectable(root.c_str())) { if (ImGui::Selectable(root.c_str())) {
selected_current_file_path_ = root; selected_current_file_path_ = root;
@@ -63,16 +73,20 @@ int Render::ShowSimpleFileBrowser() {
std::filesystem::path p(selected_current_file_path_); std::filesystem::path p(selected_current_file_path_);
if (ImGui::Selectable("..")) { if (ImGui::Selectable("..")) {
if (p.has_parent_path() && p != p.root_path()) if (std::find(roots.begin(), roots.end(),
selected_current_file_path_ = p.parent_path().string(); selected_current_file_path_) != roots.end()) {
else
selected_current_file_path_ = "Root"; selected_current_file_path_ = "Root";
} else if (p.has_parent_path()) {
selected_current_file_path_ = p.parent_path().string();
} else {
selected_current_file_path_ = "Root";
}
selected_file_.clear(); selected_file_.clear();
} }
try { try {
for (const auto& entry : for (const auto& entry : std::filesystem::directory_iterator(
std::filesystem::directory_iterator(selected_current_file_path_)) { selected_current_file_path_)) {
std::string name = entry.path().filename().string(); std::string name = entry.path().filename().string();
if (entry.is_directory()) { if (entry.is_directory()) {
if (ImGui::Selectable(name.c_str())) { if (ImGui::Selectable(name.c_str())) {
@@ -82,7 +96,8 @@ int Render::ShowSimpleFileBrowser() {
} else { } else {
if (ImGui::Selectable(name.c_str())) { if (ImGui::Selectable(name.c_str())) {
selected_file_ = entry.path().string(); selected_file_ = entry.path().string();
file_selected = true; // 记录选中文件 file_selected = true;
show_file_browser_ = false;
} }
} }
} }
@@ -91,14 +106,12 @@ int Render::ShowSimpleFileBrowser() {
} }
} }
// 如果选中了文件,则自动关闭下拉框 ImGui::EndCombo();
if (file_selected) { }
ImGui::EndCombo(); // 关闭下拉框 ImGui::PopItemFlag();
} else { } else {
ImGui::EndCombo(); // 保持下拉框开启 show_file_browser_ = true;
} }
}
ImGui::PopItemFlag(); // 恢复默认行为
return 0; return 0;
} }