Skip to content

Commit

Permalink
Config option to filter out certain extensions. #156 (#157)
Browse files Browse the repository at this point in the history
* Config option to filter out certain extensions. #156

* Changed default filter. Code formatting. README (#156)
  • Loading branch information
micheldebree committed Sep 20, 2023
1 parent 5756566 commit e42ed27
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 65 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,15 @@ Please report issues in our [issue tracker](https://github.com/Chordian/sidfacto

### Next release

![Commits since last release](https://img.shields.io/github/commits-since/chordian/sidfactory2/release-20221007)

- Changed: Configuration parameter `Window.Scale` now has a range from 1.0 to 10.0, so users can blow up the screen even bigger.
Values below 1.0 were not working correctly.
![Commits since last
release](https://img.shields.io/github/commits-since/chordian/sidfactory2/release-20221007)

- Added: [#156](https://github.com/Chordian/sidfactory2/issues/156)
Configuration option `Disk.Hide.Extensions` to hide files with certain
extensions in the file browser. Default values are `.sid`, `.wav` and `.mp3`
- Changed: Configuration parameter `Window.Scale` now has a range from 1.0 to
10.0, so users can blow up the screen even bigger. Values below 1.0 were not
working correctly.

### Build 20221007

Expand Down
47 changes: 26 additions & 21 deletions SIDFactoryII/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ Key.Track.SetOrderlistLoopPoint = @l:shift:control
Key.OrderListOverview.Copy = @c:control
Key.OrderListOverview.Paste = @v:control

// Hide files with these extensions from the file browser.
// Use += to add to a list, or = to add the first element and disregard previously added elements
Disk.Hide.Extensions = ".sid"
Disk.Hide.Extensions += ".wav"
Disk.Hide.Extensions += ".mp3"

[windows] // Applies to the windows platform only

// Disk.Startup.Folder = "" // Uncomment and enter the absolute path to the folder that should
Expand Down Expand Up @@ -259,27 +265,6 @@ Disk.UserFolders.Aliases += "Desktop"
Disk.UserFolders += "/Volumes"
Disk.UserFolders.Aliases += "External Volumes"

Disk.Startup.Folder = "~" // The folder that should open by default in the file browser.

// Favorite folders to show in the file browser.
// There are two lists;
// Disk.UserFolders for the folders
// Disk.UserFolders.Aliases for corresponding aliases (the name shown in the browser)
// Make sure the number of folders and the number of aliases are equal

Disk.UserFolders += "~"
Disk.UserFolders.Aliases += "Home (~)"
Disk.UserFolders += "~/Music"
Disk.UserFolders.Aliases += "Music"
Disk.UserFolders += "~/Documents"
Disk.UserFolders.Aliases += "Documents"
Disk.UserFolders += "~/Desktop"
Disk.UserFolders.Aliases += "Desktop"
Disk.UserFolders += "/mnt"
Disk.UserFolders.Aliases += "/mnt"
Disk.UserFolders += "/Media"
Disk.UserFolders.Aliases += "/Media"

//
// KEY OVERRIDES FOR MAC VERSION ONLY
//
Expand All @@ -305,6 +290,26 @@ Key.OrderListOverview.Paste = @v:cmd

[linux] // Applies to the linux platform only

Disk.Startup.Folder = "~" // The folder that should open by default in the file browser.
// Favorite folders to show in the file browser.
// There are two lists;
// Disk.UserFolders for the folders
// Disk.UserFolders.Aliases for corresponding aliases (the name shown in the browser)
// Make sure the number of folders and the number of aliases are equal

Disk.UserFolders += "~"
Disk.UserFolders.Aliases += "Home (~)"
Disk.UserFolders += "~/Music"
Disk.UserFolders.Aliases += "Music"
Disk.UserFolders += "~/Documents"
Disk.UserFolders.Aliases += "Documents"
Disk.UserFolders += "~/Desktop"
Disk.UserFolders.Aliases += "Desktop"
Disk.UserFolders += "/mnt"
Disk.UserFolders.Aliases += "/mnt"
Disk.UserFolders += "/Media"
Disk.UserFolders.Aliases += "/Media"

#include "~/.config/sidfactory2/user.ini"

[debug] // Applies to debug builds only
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "datasource_directory.h"
#include "foundation/platform/iplatform.h"
#include "utils/configfile.h"
#include "utils/config/configtypes.h"
#include "utils/configfile.h"
#include <cctype>

using namespace fs;
Expand All @@ -23,19 +23,20 @@ namespace Editor

auto user_folders = GetConfigurationValues<ConfigValueString>(inConfigFile, "Disk.UserFolders", {});
auto user_folders_alias = GetConfigurationValues<ConfigValueString>(inConfigFile, "Disk.UserFolders.Aliases", {});
m_ExtensionFilter = GetConfigurationValues<ConfigValueString>(inConfigFile, "Disk.Hide.Extensions", {});

const size_t user_folder_count = user_folders.size();
const bool has_aliases = user_folders_alias.size() == user_folder_count;

for (size_t i = 0; i<user_folder_count; ++i)
for (size_t i = 0; i < user_folder_count; ++i)
{
const std::string& user_folder = inPlatform->OS_ParsePath(user_folders[i]);
path user_folder_path = path(user_folder);

if (is_directory(user_folder_path))
m_Drives.push_back({ user_folder, has_aliases ? user_folders_alias[i] : "" });
}

GenerateData();
}

Expand All @@ -47,7 +48,7 @@ namespace Editor
FOUNDATION_ASSERT(inIndex < static_cast<int>(m_List.size()));

const DirectoryEntry& entry = (*this)[inIndex];
std::error_code error_code;
std::error_code error_code;

switch (entry.m_Type)
{
Expand All @@ -57,11 +58,11 @@ namespace Editor

case DirectoryEntry::Drive:
case DirectoryEntry::Folder:
if(m_Platform->Storage_SetCurrentPath(entry.m_Path.string()))
{
GenerateData();
return SelectResult::SelectFolderSucceeded;
}
if (m_Platform->Storage_SetCurrentPath(entry.m_Path.string()))
{
GenerateData();
return SelectResult::SelectFolderSucceeded;
}

return SelectResult::SelectFolderFailed;
case DirectoryEntry::File:
Expand All @@ -79,11 +80,11 @@ namespace Editor

bool DataSourceDirectory::Back()
{
std::error_code error_code;
std::error_code error_code;

std::string current_path_string = current_path().string();
if (m_Platform->Storage_SetCurrentPath(current_path().parent_path().string()))
{
{
GenerateData();

for (size_t i = 0; i < m_List.size(); ++i)
Expand Down Expand Up @@ -145,54 +146,70 @@ namespace Editor
fs::path current_path = fs::current_path();

const bool is_root = current_path.parent_path() == current_path;
if(!is_root)
if (!is_root)
m_List.push_back({ DirectoryEntry::Back, ".." });

// Iterate entries in current directory and add folder to the list and cache files for adding afterward
directory_iterator directory_iterator(current_path);
std::vector<path> files;
for (auto& path : directory_iterator)
{
if(!m_Platform->Storage_IsSystemFile(path.path().string()))
{
std::error_code error_code;
if (is_directory(path, error_code))
m_List.push_back({ DirectoryEntry::Folder, path });
if (!m_Platform->Storage_IsSystemFile(path.path().string()))
{
std::error_code error_code;
if (is_directory(path, error_code))
m_List.push_back({ DirectoryEntry::Folder, path });
else if (is_regular_file(path, error_code))
files.push_back(path);
{
std::string extension = fs::path(path).extension();

// filter out files with extensions on the hide list
bool showFile = true;
for (size_t i = 0; i < m_ExtensionFilter.size(); ++i)
{
if (extension.compare(m_ExtensionFilter[i]) == 0)
{
showFile = false;
}
}

if (showFile)
{
files.push_back(path);
}
}
}
}

for (auto& file : files)
m_List.push_back({ DirectoryEntry::File, file });

// Sort the list
std::sort(m_List.begin(), m_List.end(), [](const DirectoryEntry& inEntry1, const DirectoryEntry& inEntry2)
std::sort(m_List.begin(), m_List.end(), [](const DirectoryEntry& inEntry1, const DirectoryEntry& inEntry2) {
// If the types are the same, lets check the filenames against each other (and ignore case .. which means a transformation per comparison, not fast.. but who cares! This is disk operation stuff)
if (inEntry1.m_Type == inEntry2.m_Type)
{
// If the types are the same, lets check the filenames against each other (and ignore case .. which means a transformation per comparasin, not fast.. but who cares! This is disk operation stuff)
if (inEntry1.m_Type == inEntry2.m_Type)
if (!(inEntry1.m_DisplayName.empty() ^ inEntry2.m_DisplayName.empty()))
{
if (!(inEntry1.m_DisplayName.empty() ^ inEntry2.m_DisplayName.empty()))
{
std::string name1 = inEntry1.m_DisplayName.empty() ? inEntry1.m_Path.string() : inEntry1.m_DisplayName;
std::string name2 = inEntry2.m_DisplayName.empty() ? inEntry2.m_Path.string() : inEntry2.m_DisplayName;
std::string name1 = inEntry1.m_DisplayName.empty() ? inEntry1.m_Path.string() : inEntry1.m_DisplayName;
std::string name2 = inEntry2.m_DisplayName.empty() ? inEntry2.m_Path.string() : inEntry2.m_DisplayName;

std::transform(name1.begin(), name1.end(), name1.begin(),
[](char c) { return std::tolower(c); });
std::transform(name2.begin(), name2.end(), name2.begin(),
[](char c) { return std::tolower(c); });
std::transform(name1.begin(), name1.end(), name1.begin(),
[](char c) { return std::tolower(c); });
std::transform(name2.begin(), name2.end(), name2.begin(),
[](char c) { return std::tolower(c); });

return name1 < name2;
}
else
{
// If inEntry2 is not using the display name, entry 1 is and vice versa!
return inEntry2.m_DisplayName.empty();
}
return name1 < name2;
}
else
{
// If inEntry2 is not using the display name, entry 1 is and vice versa!
return inEntry2.m_DisplayName.empty();
}
}

// Otherwise just prefer one type over the other
return inEntry1.m_Type < inEntry2.m_Type;
});
// Otherwise just prefer one type over the other
return inEntry1.m_Type < inEntry2.m_Type;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace Editor
const Utility::ConfigFile& m_ConfigFile;

std::vector<Drive> m_Drives;
std::vector<std::string> m_ExtensionFilter;

bool m_HasFileSelection;
int m_SelectedFileIndex;
Expand Down
6 changes: 6 additions & 0 deletions dist/documentation/user.default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ Window.Scaling.Smooth = 1 // If you set this to 1, scaling
Show.Overlay = 0 // If you set this to 1, the overlay will be shown when starting the editor.
// Note that you can always toggle the overlay on and off with the F12 hotkey.

// Hide files with these extensions from the file browser.
// Use += to add to a list, or = to add the first element and disregard previously added elements
Disk.Hide.Extensions = ".sid"
Disk.Hide.Extensions += ".wav"
Disk.Hide.Extensions += ".mp3"

[windows] // Applies to the windows platform only

Sound.Emulation.SampleFrequency = 48000
Expand Down

0 comments on commit e42ed27

Please sign in to comment.