mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
GDirectoryModel: Automagically update on filesystem changes.
Use the new watch_file() mechanism to monitor the currently open directory for changes and refresh the model when notified. This makes FileManager automagically show newly added files. :^)
This commit is contained in:
parent
c8e2bb5605
commit
1511cac715
Notes:
sideshowbarker
2024-07-19 13:05:25 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/1511cac715c
2 changed files with 14 additions and 0 deletions
|
@ -308,7 +308,18 @@ void GDirectoryModel::open(const StringView& a_path)
|
|||
if (!dirp)
|
||||
return;
|
||||
closedir(dirp);
|
||||
if (m_notifier)
|
||||
close(m_notifier->fd());
|
||||
m_path = path;
|
||||
int watch_fd = watch_file(path.characters(), path.length());
|
||||
if (watch_fd < 0) {
|
||||
perror("watch_file");
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
m_notifier = make<CNotifier>(watch_fd, CNotifier::Event::Read);
|
||||
m_notifier->on_ready_to_read = [this] {
|
||||
update();
|
||||
};
|
||||
update();
|
||||
set_selected_index(index(0, 0));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/HashMap.h>
|
||||
#include <LibCore/CNotifier.h>
|
||||
#include <LibGUI/GModel.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
@ -77,4 +78,6 @@ private:
|
|||
|
||||
HashMap<uid_t, String> m_user_names;
|
||||
HashMap<gid_t, String> m_group_names;
|
||||
|
||||
OwnPtr<CNotifier> m_notifier;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue