Skip to content

Commit

Permalink
Code for handling new behaviour in file browsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mls-m5 committed Nov 15, 2023
1 parent 33556e5 commit 34065eb
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/script/fileviewinteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,20 @@ void handleFileViewResponse(std::shared_ptr<IEnvironment> env,
return result;
};

auto rootPath = std::filesystem::path(lineAt(1));
auto result = rootPath / lineAt(i.cursorPosition.y());
if (i.text.empty()) {
return;
}

auto result = std::string{};

/// Filesystem mode
if (i.text.front() == '/') {
auto rootPath = std::filesystem::path(lineAt(1));
result = rootPath / lineAt(i.cursorPosition.y());
}
else { /// Project mode
result = lineAt(i.cursorPosition.y());
}

if (result.empty()) {
env->statusMessage(FString{"no file selected"});
Expand All @@ -47,7 +59,6 @@ void handleFileViewResponse(std::shared_ptr<IEnvironment> env,
}

FString formatPath(std::filesystem::path path) {

auto str = FString{};

if (path.has_parent_path()) {
Expand All @@ -71,7 +82,7 @@ void internalBeginFileViewInteraction(std::shared_ptr<IEnvironment> env,

auto &editor = env->editor();

size_t currentLine = 1;
size_t currentLine = 0;

const auto hideHiddenFiles = true;

Expand All @@ -86,13 +97,6 @@ void internalBeginFileViewInteraction(std::shared_ptr<IEnvironment> env,
root = std::filesystem::current_path();
}

if (std::filesystem::absolute(root).has_parent_path()) {
interaction.text +=
std::filesystem::absolute(root).parent_path().string() + "\n";
++currentLine;
}
interaction.text += std::filesystem::absolute(root).string() + "\n";

auto addFile = [&](std::filesystem::path file, std::filesystem::path root) {
if (hideHiddenFiles && file.has_filename() &&
file.filename().string().starts_with(".")) {
Expand All @@ -118,6 +122,13 @@ void internalBeginFileViewInteraction(std::shared_ptr<IEnvironment> env,

// If project had no files. Just brows the current directory
if (env->project().files().empty()) {
if (std::filesystem::absolute(root).has_parent_path()) {
interaction.text +=
std::filesystem::absolute(root).parent_path().string() + "\n";
++currentLine;
}
interaction.text += std::filesystem::absolute(root).string() + "\n";
++currentLine;
for (auto &it : std::filesystem::directory_iterator{
std::filesystem::absolute(root)}) {
addFile(it.path(), root);
Expand Down

0 comments on commit 34065eb

Please sign in to comment.