add nf7::File::RequestFocus()
This commit is contained in:
parent
5d796635b7
commit
c5d46f37d6
@ -22,7 +22,7 @@ void FileMenuItems(nf7::File& f) noexcept {
|
||||
auto config = f.interface<nf7::Config>();
|
||||
|
||||
if (ImGui::MenuItem("request focus")) {
|
||||
f.env().Handle({.id = f.id(), .type = nf7::File::Event::kReqFocus});
|
||||
f.RequestFocus();
|
||||
}
|
||||
if (ImGui::MenuItem("copy path")) {
|
||||
ImGui::SetClipboardText(f.abspath().Stringify().c_str());
|
||||
|
@ -149,7 +149,7 @@ void Dir::UpdateTree() noexcept {
|
||||
|
||||
// send nf7::File::Event::kReqFocus on double click
|
||||
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
|
||||
env().Handle({.id = file.id(), .type = nf7::File::Event::kReqFocus});
|
||||
file.RequestFocus();
|
||||
}
|
||||
|
||||
// context menu
|
||||
|
3
nf7.cc
3
nf7.cc
@ -114,6 +114,9 @@ void File::Touch() noexcept {
|
||||
}
|
||||
});
|
||||
}
|
||||
void File::RequestFocus() noexcept {
|
||||
env().Handle({ .id = id_, .type = nf7::File::Event::kReqFocus });
|
||||
}
|
||||
File& File::FindOrThrow(std::string_view name) const {
|
||||
if (auto ret = Find(name)) return *ret;
|
||||
throw NotFoundException("missing child: "+std::string(name));
|
||||
|
6
nf7.hh
6
nf7.hh
@ -95,6 +95,7 @@ class File {
|
||||
void Isolate() noexcept;
|
||||
|
||||
void Touch() noexcept;
|
||||
void RequestFocus() noexcept;
|
||||
|
||||
virtual void Update() noexcept { }
|
||||
virtual void Handle(const Event&) noexcept { }
|
||||
@ -137,14 +138,9 @@ class File {
|
||||
struct File::Event final {
|
||||
public:
|
||||
enum Type {
|
||||
// emitted by system (do not emit manually)
|
||||
kAdd,
|
||||
kRemove,
|
||||
|
||||
// can be emitted from inside of File
|
||||
kUpdate,
|
||||
|
||||
// can be emitted from outside of File
|
||||
kReqFocus,
|
||||
};
|
||||
Id id;
|
||||
|
Loading…
x
Reference in New Issue
Block a user