separate an implementation from interface declaration

This commit is contained in:
falsycat 2022-05-28 11:41:21 +09:00
parent 29430a8a6c
commit ec74a35dfc
8 changed files with 54 additions and 42 deletions

View File

@ -45,11 +45,15 @@ target_sources(nf7
nf7.hh
common/dir.hh
common/dir_item.hh
common/file_ref.hh
common/generic_context.hh
common/generic_type_info.hh
common/gui_window.hh
common/logger.hh
common/logger_pool.hh
common/ptr_selector.hh
common/queue.hh
common/type_info.hh
common/yas.hh
file/system_dir.cc

View File

@ -26,32 +26,4 @@ class Dir::DuplicateException : public Exception {
using Exception::Exception;
};
class DirItem : public File::Interface {
public:
enum Flag : uint8_t {
kNone = 0,
kTree = 1 << 0,
kMenu = 1 << 1,
kTooltip = 1 << 2,
};
using Flags = uint8_t;
DirItem() = delete;
DirItem(Flags flags) noexcept : flags_(flags) {
}
DirItem(const DirItem&) = delete;
DirItem(DirItem&&) = delete;
DirItem& operator=(const DirItem&) = delete;
DirItem& operator=(DirItem&&) = delete;
virtual void UpdateTree() noexcept { }
virtual void UpdateMenu() noexcept { }
virtual void UpdateTooltip() noexcept { }
Flags flags() const noexcept { return flags_; }
private:
Flags flags_;
};
} // namespace nf7

38
common/dir_item.hh Normal file
View File

@ -0,0 +1,38 @@
#pragma once
#include <cstdint>
#include "nf7.hh"
namespace nf7 {
class DirItem : public File::Interface {
public:
enum Flag : uint8_t {
kNone = 0,
kTree = 1 << 0,
kMenu = 1 << 1,
kTooltip = 1 << 2,
};
using Flags = uint8_t;
DirItem() = delete;
DirItem(Flags flags) noexcept : flags_(flags) {
}
DirItem(const DirItem&) = delete;
DirItem(DirItem&&) = delete;
DirItem& operator=(const DirItem&) = delete;
DirItem& operator=(DirItem&&) = delete;
virtual void UpdateTree() noexcept { }
virtual void UpdateMenu() noexcept { }
virtual void UpdateTooltip() noexcept { }
Flags flags() const noexcept { return flags_; }
private:
Flags flags_;
};
} // namespace nf7

View File

@ -10,7 +10,7 @@
namespace nf7 {
class SimpleContext : public Context {
class GenericContext : public Context {
public:
using Context::Context;

View File

@ -11,11 +11,12 @@
#include "nf7.hh"
#include "common/context.hh"
#include "common/dir.hh"
#include "common/dir_item.hh"
#include "common/generic_context.hh"
#include "common/generic_type_info.hh"
#include "common/gui_window.hh"
#include "common/ptr_selector.hh"
#include "common/type_info.hh"
#include "common/yas.hh"
@ -199,7 +200,7 @@ void Dir::Update() noexcept {
if (ImGui::Button("ok")) {
ImGui::CloseCurrentPopup();
auto ctx = std::make_shared<SimpleContext>(env(), id());
auto ctx = std::make_shared<GenericContext>(env(), id());
ctx->description() = "adding new file on "+abspath().Stringify();
auto task = [this, name = std::move(name), type = selecting]() {
@ -240,7 +241,7 @@ void Dir::Update() noexcept {
if (submit) {
ImGui::CloseCurrentPopup();
auto ctx = std::make_shared<SimpleContext>(env(), id());
auto ctx = std::make_shared<GenericContext>(env(), id());
ctx->description() = "renaming an item on "+abspath().Stringify();
auto task = [this, before = std::move(rename_target_), after = std::move(new_name)]() {
@ -309,16 +310,13 @@ void Dir::UpdateTree() noexcept {
}
ImGui::Separator();
if (ImGui::MenuItem("remove")) {
auto ctx = std::make_shared<SimpleContext>(env(), id());
auto ctx = std::make_shared<GenericContext>(env(), id());
ctx->description() = "removing file on "+abspath().Stringify();
env().ExecMain(ctx, [this, name]() { Remove(name); });
}
if (ImGui::MenuItem("rename")) {
rename_target_ = name;
popup_ = "RenamePopup";
// auto ctx = std::make_shared<SimpleContext>(env(), id());
// ctx->description() = "renaming file on "+abspath().Stringify();
// env().ExecMain(ctx, []() { throw Exception("not implemented"); });
}
if (ditem && (ditem->flags() & DirItem::kMenu)) {
ImGui::Separator();

View File

@ -11,9 +11,9 @@
#include "nf7.hh"
#include "common/dir.hh"
#include "common/dir_item.hh"
#include "common/generic_type_info.hh"
#include "common/ptr_selector.hh"
#include "common/type_info.hh"
using namespace std::literals;

View File

@ -7,12 +7,12 @@
#include "nf7.hh"
#include "common/dir.hh"
#include "common/dir_item.hh"
#include "common/generic_type_info.hh"
#include "common/gui_window.hh"
#include "common/logger.hh"
#include "common/logger_pool.hh"
#include "common/ptr_selector.hh"
#include "common/type_info.hh"
using namespace std::literals;