Skip to content

Commit

Permalink
expand and collapse all folders toolbar button added
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Dec 30, 2023
1 parent 2832ad5 commit 2b22eb4
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 24 deletions.
70 changes: 59 additions & 11 deletions source/Gui/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ void _BrowserWindow::registerCyclicReferences(LoginDialogWeakPtr const& loginDia
auto firstStart = GlobalSettings::getInstance().getBoolState("windows.browser.first start", true);
refreshIntern(firstStart);

auto initialCollapsedSimulationFolders = NetworkResourceService::convertFolderNamesToSettings(NetworkResourceService::calcInitialCollapsedFolderNames(_simulations.rawTOs));
auto initialCollapsedSimulationFolders = NetworkResourceService::convertFolderNamesToSettings(NetworkResourceService::getAllFolderNames(_simulations.rawTOs));
auto collapsedSimulationFolders = GlobalSettings::getInstance().getStringState("windows.browser.simulations.collapsed folders", initialCollapsedSimulationFolders);
_simulations.collapsedFolderNames = NetworkResourceService::convertSettingsToFolderNames(collapsedSimulationFolders);

auto initialCollapsedGenomeFolders =
NetworkResourceService::convertFolderNamesToSettings(NetworkResourceService::calcInitialCollapsedFolderNames(_simulations.rawTOs));
NetworkResourceService::convertFolderNamesToSettings(NetworkResourceService::getAllFolderNames(_simulations.rawTOs));
auto collapsedGenomeFolders =
GlobalSettings::getInstance().getStringState("windows.browser.genomes.collapsed folders", initialCollapsedGenomeFolders);
_genomes.collapsedFolderNames = NetworkResourceService::convertSettingsToFolderNames(collapsedGenomeFolders);
Expand Down Expand Up @@ -226,13 +226,15 @@ void _BrowserWindow::processBackground()
void _BrowserWindow::processToolbar()
{
auto& networkService = NetworkService::getInstance();
std::string resourceTypeString = _selectedDataType == NetworkResourceType_Simulation ? "simulation" : "genome";
std::string resourceTypeString = _visibleResourceType == NetworkResourceType_Simulation ? "simulation" : "genome";

//refresh button
if (AlienImGui::ToolbarButton(ICON_FA_SYNC)) {
onRefresh();
}
AlienImGui::Tooltip("Refresh");

//login button
ImGui::SameLine();
ImGui::BeginDisabled(networkService.getLoggedInUserName().has_value());
if (AlienImGui::ToolbarButton(ICON_FA_SIGN_IN_ALT)) {
Expand All @@ -243,6 +245,7 @@ void _BrowserWindow::processToolbar()
ImGui::EndDisabled();
AlienImGui::Tooltip("Login or register");

//logout button
ImGui::SameLine();
ImGui::BeginDisabled(!networkService.getLoggedInUserName());
if (AlienImGui::ToolbarButton(ICON_FA_SIGN_OUT_ALT)) {
Expand All @@ -254,9 +257,11 @@ void _BrowserWindow::processToolbar()
ImGui::EndDisabled();
AlienImGui::Tooltip("Logout");

//separator
ImGui::SameLine();
AlienImGui::ToolbarSeparator();

//upload button
ImGui::SameLine();
if (AlienImGui::ToolbarButton(ICON_FA_UPLOAD)) {
std::string prefix = [&] {
Expand All @@ -265,13 +270,14 @@ void _BrowserWindow::processToolbar()
}
return NetworkResourceService::concatenateFolderNames(_selectedResource->folderNames, true);
}();
_uploadSimulationDialog.lock()->open(_selectedDataType, prefix);
_uploadSimulationDialog.lock()->open(_visibleResourceType, prefix);
}
AlienImGui::Tooltip(
"Share your current " + resourceTypeString + " with other users:\nThe " + resourceTypeString
+ " will be uploaded to the server and made visible in the browser.\nIf you have already selected a folder, your " + resourceTypeString
+ " will be uploaded there.");

//delete button
ImGui::SameLine();
ImGui::BeginDisabled(
_selectedResource == nullptr || !_selectedResource->isLeaf()
Expand All @@ -283,10 +289,30 @@ void _BrowserWindow::processToolbar()
ImGui::EndDisabled();
AlienImGui::Tooltip("Delete selected " + resourceTypeString);

//separator
ImGui::SameLine();
AlienImGui::ToolbarSeparator();

//expand button
ImGui::SameLine();
if (AlienImGui::ToolbarButton(ICON_FA_EXPAND_ARROWS_ALT)) {
onExpandFolders();
}
AlienImGui::Tooltip("Expand all folders");

//collapse button
ImGui::SameLine();
if (AlienImGui::ToolbarButton(ICON_FA_COMPRESS_ARROWS_ALT)) {
onCollapseFolders();
}
AlienImGui::Tooltip("Collapse all folders");

#ifdef _WIN32
//separator
ImGui::SameLine();
AlienImGui::ToolbarSeparator();

//Discord button
ImGui::SameLine();
if (AlienImGui::ToolbarButton(ICON_FA_COMMENTS)) {
openWeblink(Const::DiscordLink);
Expand All @@ -300,7 +326,7 @@ void _BrowserWindow::processToolbar()
void _BrowserWindow::processSimulationList()
{
ImGui::PushID("SimulationList");
_selectedDataType = NetworkResourceType_Simulation;
_visibleResourceType = NetworkResourceType_Simulation;
static ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Sortable
| ImGuiTableFlags_SortMulti | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_NoBordersInBody
| ImGuiTableFlags_ScrollY | ImGuiTableFlags_ScrollX;
Expand Down Expand Up @@ -390,7 +416,7 @@ void _BrowserWindow::processSimulationList()
void _BrowserWindow::processGenomeList()
{
ImGui::PushID("GenomeList");
_selectedDataType = NetworkResourceType_Genome;
_visibleResourceType = NetworkResourceType_Genome;
auto& styleRepository = StyleRepository::getInstance();
static ImGuiTableFlags flags = ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Sortable
| ImGuiTableFlags_SortMulti | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter | ImGuiTableFlags_BordersV | ImGuiTableFlags_NoBordersInBody
Expand Down Expand Up @@ -420,7 +446,7 @@ void _BrowserWindow::processGenomeList()
sortSpecs->SpecsDirty = false;
_scheduleCreateGenomeTreeTOs = false;

_genomes.treeTOs = NetworkResourceService::createTreeTOs(_genomes.rawTOs, _simulations.collapsedFolderNames);
_genomes.treeTOs = NetworkResourceService::createTreeTOs(_genomes.rawTOs, _genomes.collapsedFolderNames);
}
}
ImGuiListClipper clipper;
Expand Down Expand Up @@ -607,14 +633,14 @@ void _BrowserWindow::processResourceNameField(NetworkResourceTreeTO const& treeT
if (treeTO->isLeaf()) {
auto& leaf = treeTO->getLeaf();

processFolderTreeSymbols(treeTO, _simulations.collapsedFolderNames);
processFolderTreeSymbols(treeTO, collapsedFolderNames);
processDownloadButton(leaf);
ImGui::SameLine();
processShortenedText(leaf.leafName, true);
} else {
auto& folder = treeTO->getFolder();

processFolderTreeSymbols(treeTO, _simulations.collapsedFolderNames);
processFolderTreeSymbols(treeTO, collapsedFolderNames);
processShortenedText(treeTO->folderNames.back());
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_Text, (ImU32)Const::BrowserFolderPropertiesTextColor);
Expand Down Expand Up @@ -1049,14 +1075,14 @@ void _BrowserWindow::onDownloadItem(BrowserLeaf const& leaf)

delayedExecution([=, this] {
auto& networkService = NetworkService::getInstance();
std::string dataTypeString = _selectedDataType == NetworkResourceType_Simulation ? "simulation" : "genome";
std::string dataTypeString = _visibleResourceType == NetworkResourceType_Simulation ? "simulation" : "genome";
SerializedSimulation serializedSim;
if (!networkService.downloadSimulation(serializedSim.mainData, serializedSim.auxiliaryData, serializedSim.statistics, leaf.rawTO->id)) {
MessageDialog::getInstance().information("Error", "Failed to download " + dataTypeString + ".");
return;
}

if (_selectedDataType == NetworkResourceType_Simulation) {
if (_visibleResourceType == NetworkResourceType_Simulation) {
DeserializedSimulation deserializedSim;
if (!SerializerService::deserializeSimulationFromStrings(deserializedSim, serializedSim)) {
MessageDialog::getInstance().information("Error", "Failed to load simulation. Your program version may not match.");
Expand Down Expand Up @@ -1160,6 +1186,28 @@ void _BrowserWindow::onToggleLike(NetworkResourceTreeTO const& to, int emojiType
}
}

void _BrowserWindow::onExpandFolders()
{
if (_visibleResourceType == NetworkResourceType_Simulation) {
_simulations.collapsedFolderNames.clear();
} else {
_genomes.collapsedFolderNames.clear();
}
scheduleCreateTreeTOs();
}

void _BrowserWindow::onCollapseFolders()
{
if (_visibleResourceType == NetworkResourceType_Simulation) {
auto folderNames = NetworkResourceService::getAllFolderNames(_simulations.rawTOs, 1);
_simulations.collapsedFolderNames.insert(folderNames.begin(), folderNames.end());
} else {
auto folderNames = NetworkResourceService::getAllFolderNames(_genomes.rawTOs, 1);
_genomes.collapsedFolderNames.insert(folderNames.begin(), folderNames.end());
}
scheduleCreateTreeTOs();
}

void _BrowserWindow::openWeblink(std::string const& link)
{
#ifdef _WIN32
Expand Down
18 changes: 10 additions & 8 deletions source/Gui/BrowserWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ class _BrowserWindow : public _AlienWindow
void onDownloadItem(BrowserLeaf const& leaf);
void onDeleteItem(BrowserLeaf const& leaf);
void onToggleLike(NetworkResourceTreeTO const& to, int emojiType);
void onExpandFolders();
void onCollapseFolders();
void openWeblink(std::string const& link);

bool isLiked(std::string const& simId);
Expand All @@ -90,10 +92,16 @@ class _BrowserWindow : public _AlienWindow
void pushTextColor(NetworkResourceTreeTO const& to);
void popTextColor();

NetworkResourceType _selectedDataType = NetworkResourceType_Simulation;
bool _scheduleRefresh = false;
bool _scheduleCreateSimulationTreeTOs = false;
bool _scheduleCreateGenomeTreeTOs = false;
bool _activateEmojiPopup = false;
bool _showAllEmojis = false;
NetworkResourceTreeTO _emojiPopupTO;
std::optional<std::chrono::steady_clock::time_point> _lastRefreshTime;

NetworkResourceType _visibleResourceType = NetworkResourceType_Simulation;
NetworkResourceTreeTO _selectedResource;

std::string _filter;
bool _showCommunityCreations = false;
Expand All @@ -103,19 +111,13 @@ class _BrowserWindow : public _AlienWindow
std::unordered_map<std::pair<std::string, int>, std::set<std::string>> _userNamesByEmojiTypeBySimIdCache;

std::vector<NetworkResourceRawTO> _unfilteredRawTOs;
NetworkResourceTreeTO _selectedResource;
ResourceData _genomes;
ResourceData _simulations;

std::vector<UserTO> _userTOs;

std::vector<TextureData> _emojis;

bool _activateEmojiPopup = false;
bool _showAllEmojis = false;
NetworkResourceTreeTO _emojiPopupTO;

std::optional<std::chrono::steady_clock::time_point> _lastRefreshTime;
std::vector<TextureData> _emojis;

SimulationController _simController;
StatisticsWindow _statisticsWindow;
Expand Down
7 changes: 4 additions & 3 deletions source/Network/NetworkResourceService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string.hpp>

#include "NetworkResourceRawTO.h"
#include "NetworkResourceTreeTO.h"

namespace
Expand Down Expand Up @@ -218,14 +219,14 @@ std::vector<NetworkResourceTreeTO> NetworkResourceService::createTreeTOs(
return result;
}

std::set<std::vector<std::string>> NetworkResourceService::calcInitialCollapsedFolderNames(std::vector<NetworkResourceRawTO> const& rawTOs)
std::set<std::vector<std::string>> NetworkResourceService::getAllFolderNames(std::vector<NetworkResourceRawTO> const& rawTOs, int minNesting)
{
std::set<std::vector<std::string>> result;
for (auto const& rawTO : rawTOs) {
std::vector<std::string> folderNames;
boost::split(folderNames, rawTO->resourceName, boost::is_any_of("/"));
for (int i = 0; i < toInt(folderNames.size()) - 2; ++i) {
result.insert(std::vector(folderNames.begin(), folderNames.begin() + 2 + i));
for (int i = 0; i < toInt(folderNames.size()) - minNesting; ++i) {
result.insert(std::vector(folderNames.begin(), folderNames.begin() + minNesting + i));
}
}
return result;
Expand Down
3 changes: 1 addition & 2 deletions source/Network/NetworkResourceService.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <vector>

#include "Definitions.h"
#include "NetworkResourceRawTO.h"

class NetworkResourceService
{
Expand All @@ -12,7 +11,7 @@ class NetworkResourceService
std::vector<NetworkResourceRawTO> const& rawTOs,
std::set<std::vector<std::string>> const& collapsedFolderNames);

static std::set<std::vector<std::string>> calcInitialCollapsedFolderNames(std::vector<NetworkResourceRawTO> const& browserData);
static std::set<std::vector<std::string>> getAllFolderNames(std::vector<NetworkResourceRawTO> const& browserData, int minNesting = 2);

static std::string concatenateFolderNames(std::vector<std::string> const& folderNames, bool withSlash);
static std::string convertFolderNamesToSettings(std::set<std::vector<std::string>> const& data);
Expand Down

0 comments on commit 2b22eb4

Please sign in to comment.