Skip to content

Commit

Permalink
Enhance fsmodel logic and signaling process
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaMKW committed Oct 21, 2024
1 parent 9662506 commit 7011bec
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 64 deletions.
3 changes: 3 additions & 0 deletions include/model/fsmodel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace Toolbox {
EVENT_FOLDER_MODIFIED = BIT(3),
EVENT_PATH_RENAMED = BIT(4),
EVENT_PATH_REMOVED = BIT(5),
EVENT_IS_VIRTUAL = BIT(6),
EVENT_FILE_ANY =
EVENT_FILE_ADDED | EVENT_FILE_MODIFIED | EVENT_PATH_RENAMED | EVENT_PATH_REMOVED,
EVENT_FOLDER_ANY =
Expand Down Expand Up @@ -214,6 +215,8 @@ namespace Toolbox {

void pathRemoved(const fs_path &path);

void signalEventListeners(const fs_path &path, FileSystemModelEventFlags flags);

private:
UUID64 m_uuid;

Expand Down
14 changes: 9 additions & 5 deletions include/watchdog/fswatchdog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ namespace Toolbox {
ScopePtr<filewatch::FileWatch<fs_path>> m_watch;
};

}


} // namespace Toolbox

namespace std {

Expand Down Expand Up @@ -73,6 +71,9 @@ namespace Toolbox {
void sleep();
void wake();

void ignorePathOnce(const fs_path &path);
void ignorePathOnce(fs_path &&path);

void addPath(const fs_path &path);
void addPath(fs_path &&path);

Expand All @@ -93,8 +94,7 @@ namespace Toolbox {
protected:
void tRun(void *param) override;

void observePath(const fs_path &path);
void observePathF(const fs_path &path);
bool wasSleepingForAlert(const fs_path &path);

struct FileInfo {
Filesystem::file_status m_status;
Expand All @@ -109,6 +109,10 @@ namespace Toolbox {

private:
bool m_asleep = false;
std::chrono::time_point<std::chrono::system_clock> m_sleep_start;
std::chrono::time_point<std::chrono::system_clock> m_sleep_end;

std::unordered_set<fs_path> m_ignore_paths;

std::unordered_map<fs_path, FileInfo> m_path_infos;

Expand Down
12 changes: 10 additions & 2 deletions src/gui/project/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,17 @@ namespace Toolbox::UI {
m_folder_view_context_menu.addDivider();

m_folder_view_context_menu.addOption(
"New Folder", KeyBind({KeyCode::KEY_LEFTCONTROL, KeyCode::KEY_LEFTSHIFT, KeyCode::KEY_N}),
"New Folder",
KeyBind({KeyCode::KEY_LEFTCONTROL, KeyCode::KEY_LEFTSHIFT, KeyCode::KEY_N}),
[this]() { return m_selected_indices_ctx.size() == 0; },
[this](const ModelIndex &view_index) {
std::string folder_name =
m_file_system_model->findUniqueName(view_index, "New Folder");
ModelIndex new_index = m_file_system_model->mkdir(view_index, folder_name);
if (m_file_system_model->validateIndex(new_index)) {
m_selected_indices.clear();
m_selected_indices.push_back(new_index);
m_selected_indices_ctx = m_selected_indices;
actionRenameIndex(new_index);
}
});
Expand Down Expand Up @@ -529,7 +533,11 @@ namespace Toolbox::UI {

void ProjectViewWindow::actionDeleteIndexes(std::vector<ModelIndex> &indices) {
for (auto &item_index : indices) {
m_file_system_model->remove(item_index);
if (m_file_system_model->isDirectory(item_index)) {
m_file_system_model->rmdir(item_index);
} else {
m_file_system_model->remove(item_index);
}
}
indices.clear();
}
Expand Down
Loading

0 comments on commit 7011bec

Please sign in to comment.