[olympic/studio/modlib] East const Studio
This commit is contained in:
@ -23,9 +23,9 @@ ox::String configPath(keel::Context const&ctx) noexcept;
|
||||
template<typename T>
|
||||
ox::Result<T> readConfig(keel::Context &ctx, ox::CRStringView name) noexcept {
|
||||
oxAssert(name != "", "Config type has no TypeName");
|
||||
const auto path = ox::sfmt("/{}.json", name);
|
||||
auto const path = ox::sfmt("/{}.json", name);
|
||||
ox::PassThroughFS fs(configPath(ctx));
|
||||
const auto [buff, err] = fs.read(path);
|
||||
auto const [buff, err] = fs.read(path);
|
||||
if (err) {
|
||||
oxErrf("Could not read config file: {}\n", toStr(err));
|
||||
return err;
|
||||
@ -42,19 +42,19 @@ ox::Result<T> readConfig(keel::Context &ctx) noexcept {
|
||||
template<typename T>
|
||||
ox::Error writeConfig(keel::Context &ctx, ox::CRStringView name, T *data) noexcept {
|
||||
oxAssert(name != "", "Config type has no TypeName");
|
||||
const auto path = ox::sfmt("/{}.json", name);
|
||||
auto const path = ox::sfmt("/{}.json", name);
|
||||
ox::PassThroughFS fs(configPath(ctx));
|
||||
if (const auto err = fs.mkdir("/", true)) {
|
||||
if (auto const err = fs.mkdir("/", true)) {
|
||||
oxErrf("Could not create config directory: {}\n", toStr(err));
|
||||
return err;
|
||||
}
|
||||
oxRequireM(buff, ox::writeOC(*data));
|
||||
*buff.back().value = '\n';
|
||||
if (const auto err = fs.write(path, buff.data(), buff.size())) {
|
||||
if (auto const err = fs.write(path, buff.data(), buff.size())) {
|
||||
oxErrf("Could not read config file: {}\n", toStr(err));
|
||||
return OxError(2, "Could not read config file");
|
||||
}
|
||||
return OxError(0);
|
||||
return {};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@ -66,7 +66,7 @@ ox::Error writeConfig(keel::Context &ctx, T *data) noexcept {
|
||||
template<typename T, typename Func>
|
||||
void openConfig(keel::Context &ctx, ox::CRStringView name, Func f) noexcept {
|
||||
oxAssert(name != "", "Config type has no TypeName");
|
||||
const auto [c, err] = readConfig<T>(ctx, name);
|
||||
auto const [c, err] = readConfig<T>(ctx, name);
|
||||
oxLogError(err);
|
||||
f(&c);
|
||||
}
|
||||
|
@ -15,9 +15,9 @@ namespace studio {
|
||||
|
||||
class ItemMaker {
|
||||
public:
|
||||
const ox::String name;
|
||||
const ox::String parentDir;
|
||||
const ox::String fileExt;
|
||||
ox::String const name;
|
||||
ox::String const parentDir;
|
||||
ox::String const fileExt;
|
||||
constexpr explicit ItemMaker(ox::StringView pName, ox::StringView pParentDir, ox::CRStringView pFileExt) noexcept:
|
||||
name(pName),
|
||||
parentDir(pParentDir),
|
||||
@ -30,8 +30,8 @@ class ItemMaker {
|
||||
template<typename T>
|
||||
class ItemMakerT: public ItemMaker {
|
||||
private:
|
||||
const T item;
|
||||
const ox::ClawFormat fmt;
|
||||
T const item;
|
||||
ox::ClawFormat const fmt;
|
||||
public:
|
||||
constexpr ItemMakerT(
|
||||
ox::StringView pDisplayName,
|
||||
@ -62,7 +62,7 @@ class ItemMakerT: public ItemMaker {
|
||||
fmt(pFmt) {
|
||||
}
|
||||
ox::Error write(turbine::Context &ctx, ox::CRStringView pName) const noexcept override {
|
||||
const auto path = ox::sfmt("/{}/{}.{}", parentDir, pName, fileExt);
|
||||
auto const path = ox::sfmt("/{}/{}.{}", parentDir, pName, fileExt);
|
||||
auto sctx = turbine::applicationData<studio::StudioContext>(ctx);
|
||||
keel::createUuidMapping(keelCtx(ctx), path, ox::UUID::generate().unwrap());
|
||||
return sctx->project->writeObj(path, item, fmt);
|
||||
|
@ -21,7 +21,7 @@ class Popup {
|
||||
ox::String m_title;
|
||||
public:
|
||||
// emits path parameter
|
||||
ox::Signal<ox::Error(const ox::String&)> finished;
|
||||
ox::Signal<ox::Error(ox::String const&)> finished;
|
||||
|
||||
virtual ~Popup() noexcept = default;
|
||||
|
||||
@ -43,7 +43,7 @@ class Popup {
|
||||
m_title = std::move(title);
|
||||
}
|
||||
|
||||
constexpr const ox::String &title() const noexcept {
|
||||
constexpr ox::String const&title() const noexcept {
|
||||
return m_title;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ enum class ProjectEvent {
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ox::Result<ox::StringView> fileExt(ox::CRStringView path) noexcept {
|
||||
const auto extStart = ox::find(path.crbegin(), path.crend(), '.').offset();
|
||||
auto const extStart = ox::find(path.crbegin(), path.crend(), '.').offset();
|
||||
if (!extStart) {
|
||||
return OxError(1, "Cannot open a file without valid extension.");
|
||||
}
|
||||
@ -76,7 +76,7 @@ class Project {
|
||||
ox::Error subscribe(ProjectEvent e, ox::SignalHandler *tgt, Functor &&slot) const noexcept;
|
||||
|
||||
[[nodiscard]]
|
||||
const ox::Vector<ox::String> &fileList(ox::CRStringView ext) noexcept;
|
||||
ox::Vector<ox::String> const&fileList(ox::CRStringView ext) noexcept;
|
||||
|
||||
private:
|
||||
void buildFileIndex() noexcept;
|
||||
@ -114,14 +114,14 @@ ox::Error Project::writeObj(ox::CRStringView path, T const&obj, ox::ClawFormat f
|
||||
oxReturnError(ox::buildTypeDef(&m_typeStore, &obj));
|
||||
}
|
||||
// write out type store
|
||||
const auto descPath = ox::sfmt("/{}/type_descriptors", m_projectDataDir);
|
||||
auto const descPath = ox::sfmt("/{}/type_descriptors", m_projectDataDir);
|
||||
oxReturnError(mkdir(descPath));
|
||||
for (auto const&t : m_typeStore.typeList()) {
|
||||
oxRequireM(typeOut, ox::writeClaw(*t, ox::ClawFormat::Organic));
|
||||
// replace garbage last character with new line
|
||||
*typeOut.back().value = '\n';
|
||||
// write to FS
|
||||
const auto typePath = ox::sfmt("/{}/{}", descPath, buildTypeId(*t));
|
||||
auto const typePath = ox::sfmt("/{}/{}", descPath, buildTypeId(*t));
|
||||
oxReturnError(writeBuff(typePath, typeOut));
|
||||
}
|
||||
oxReturnError(keel::setAsset(m_ctx, path, obj));
|
||||
|
@ -18,7 +18,7 @@ class UndoCommand {
|
||||
virtual void undo() noexcept = 0;
|
||||
[[nodiscard]]
|
||||
virtual int commandId() const noexcept = 0;
|
||||
virtual bool mergeWith(const UndoCommand *cmd) noexcept;
|
||||
virtual bool mergeWith(UndoCommand const*cmd) noexcept;
|
||||
};
|
||||
|
||||
class UndoStack {
|
||||
@ -43,9 +43,9 @@ class UndoStack {
|
||||
return m_stackIdx;
|
||||
}
|
||||
|
||||
ox::Signal<ox::Error(const studio::UndoCommand*)> redoTriggered;
|
||||
ox::Signal<ox::Error(const studio::UndoCommand*)> undoTriggered;
|
||||
ox::Signal<ox::Error(const studio::UndoCommand*)> changeTriggered;
|
||||
ox::Signal<ox::Error(studio::UndoCommand const*)> redoTriggered;
|
||||
ox::Signal<ox::Error(studio::UndoCommand const*)> undoTriggered;
|
||||
ox::Signal<ox::Error(studio::UndoCommand const*)> changeTriggered;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ add_library(
|
||||
project.cpp
|
||||
task.cpp
|
||||
undostack.cpp
|
||||
widget.cpp
|
||||
filedialog_nfd.cpp
|
||||
)
|
||||
|
||||
|
@ -23,8 +23,8 @@ constexpr auto ConfigDir = [] {
|
||||
}
|
||||
}();
|
||||
|
||||
ox::String configPath(const keel::Context &ctx) noexcept {
|
||||
const auto homeDir = std::getenv(ox::defines::OS == ox::OS::Windows ? "USERPROFILE" : "HOME");
|
||||
ox::String configPath(keel::Context const&ctx) noexcept {
|
||||
auto const homeDir = std::getenv(ox::defines::OS == ox::OS::Windows ? "USERPROFILE" : "HOME");
|
||||
return ox::sfmt(ConfigDir, homeDir, ctx.appName);
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ void BaseEditor::close() const {
|
||||
}
|
||||
|
||||
void BaseEditor::save() noexcept {
|
||||
const auto err = saveItem();
|
||||
auto const err = saveItem();
|
||||
if (!err) {
|
||||
setUnsavedChanges(false);
|
||||
} else {
|
||||
|
@ -23,7 +23,7 @@ static ox::Result<ox::String> toResult(nfdresult_t r, NFD::UniquePathN const&pat
|
||||
case NFD_OKAY: {
|
||||
ox::String out;
|
||||
for (auto i = 0u; path.get()[i]; ++i) {
|
||||
const auto c = static_cast<char>(path.get()[i]);
|
||||
auto const c = static_cast<char>(path.get()[i]);
|
||||
oxIgnoreError(out.append(&c, 1));
|
||||
}
|
||||
return out;
|
||||
@ -39,7 +39,7 @@ ox::Result<ox::String> saveFile(ox::Vector<FDFilterItem> const&filters) noexcept
|
||||
NFD::Guard const guard;
|
||||
NFD::UniquePathN path;
|
||||
ox::Vector<nfdnfilteritem_t, 5> filterItems(filters.size());
|
||||
for (auto i = 0u; const auto &f : filters) {
|
||||
for (auto i = 0u; auto const&f : filters) {
|
||||
filterItems[i].name = f.name.data();
|
||||
filterItems[i].spec = f.spec.data();
|
||||
++i;
|
||||
|
@ -9,10 +9,10 @@
|
||||
namespace studio::ig {
|
||||
|
||||
void centerNextWindow(turbine::Context &ctx) noexcept {
|
||||
const auto sz = turbine::getScreenSize(ctx);
|
||||
const auto screenW = static_cast<float>(sz.width);
|
||||
const auto screenH = static_cast<float>(sz.height);
|
||||
const auto mod = ImGui::GetWindowDpiScale() * 2;
|
||||
auto const sz = turbine::getScreenSize(ctx);
|
||||
auto const screenW = static_cast<float>(sz.width);
|
||||
auto const screenH = static_cast<float>(sz.height);
|
||||
auto const mod = ImGui::GetWindowDpiScale() * 2;
|
||||
ImGui::SetNextWindowPos(ImVec2(screenW / mod, screenH / mod), ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
namespace studio {
|
||||
|
||||
static void generateTypes(ox::TypeStore &ts) noexcept {
|
||||
for (const auto mod : keel::modules()) {
|
||||
for (auto const mod : keel::modules()) {
|
||||
for (auto gen : mod->types()) {
|
||||
oxLogError(gen(ts));
|
||||
}
|
||||
@ -56,7 +56,7 @@ bool Project::exists(ox::CRStringView path) const noexcept {
|
||||
return m_fs.stat(path).error == 0;
|
||||
}
|
||||
|
||||
const ox::Vector<ox::String> &Project::fileList(ox::CRStringView ext) noexcept {
|
||||
ox::Vector<ox::String> const&Project::fileList(ox::CRStringView ext) noexcept {
|
||||
return m_fileExtFileMap[ext];
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ void Project::buildFileIndex() noexcept {
|
||||
}
|
||||
m_fileExtFileMap.clear();
|
||||
std::sort(files.begin(), files.end());
|
||||
for (const auto &file : files) {
|
||||
for (auto const&file : files) {
|
||||
if (!beginsWith(file, ox::sfmt("/.{}/", m_projectDataDir))) {
|
||||
indexFile(file);
|
||||
}
|
||||
@ -76,7 +76,7 @@ void Project::buildFileIndex() noexcept {
|
||||
}
|
||||
|
||||
void Project::indexFile(ox::CRStringView path) noexcept {
|
||||
const auto [ext, err] = fileExt(path);
|
||||
auto const [ext, err] = fileExt(path);
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
@ -88,12 +88,12 @@ ox::Error Project::writeBuff(ox::CRStringView path, ox::Buffer const&buff) noexc
|
||||
ox::Buffer outBuff;
|
||||
outBuff.reserve(buff.size() + HdrSz);
|
||||
ox::BufferWriter writer(&outBuff);
|
||||
const auto [uuid, err] = m_ctx.pathToUuid.at(path);
|
||||
auto const [uuid, err] = m_ctx.pathToUuid.at(path);
|
||||
if (!err) {
|
||||
oxReturnError(keel::writeUuidHeader(writer, *uuid));
|
||||
}
|
||||
oxReturnError(writer.write(buff.data(), buff.size()));
|
||||
const auto newFile = m_fs.stat(path).error != 0;
|
||||
auto const newFile = m_fs.stat(path).error != 0;
|
||||
oxReturnError(m_fs.write(path, outBuff.data(), outBuff.size(), ox::FileType::NormalFile));
|
||||
if (newFile) {
|
||||
fileAdded.emit(path);
|
||||
@ -110,7 +110,7 @@ ox::Result<ox::Buffer> Project::loadBuff(ox::CRStringView path) const noexcept {
|
||||
|
||||
ox::Error Project::lsProcDir(ox::Vector<ox::String> *paths, ox::CRStringView path) const noexcept {
|
||||
oxRequire(files, m_fs.ls(path));
|
||||
for (const auto &name : files) {
|
||||
for (auto const&name : files) {
|
||||
auto fullPath = ox::sfmt("{}/{}", path, name);
|
||||
oxRequire(stat, m_fs.stat(ox::StringView(fullPath)));
|
||||
switch (stat.fileType) {
|
||||
|
@ -10,7 +10,7 @@ namespace studio {
|
||||
|
||||
void TaskRunner::update(turbine::Context &ctx) noexcept {
|
||||
oxIgnoreError(m_tasks.erase(std::remove_if(m_tasks.begin(), m_tasks.end(), [&](ox::UPtr<studio::Task> &t) {
|
||||
const auto done = t->update(ctx) == TaskState::Done;
|
||||
auto const done = t->update(ctx) == TaskState::Done;
|
||||
if (done) {
|
||||
t->finished.emit();
|
||||
}
|
||||
|
@ -6,12 +6,12 @@
|
||||
|
||||
namespace studio {
|
||||
|
||||
bool UndoCommand::mergeWith(const UndoCommand*) noexcept {
|
||||
bool UndoCommand::mergeWith(UndoCommand const*) noexcept {
|
||||
return false;
|
||||
}
|
||||
|
||||
void UndoStack::push(ox::UPtr<UndoCommand> &&cmd) noexcept {
|
||||
for (const auto i = m_stackIdx; i < m_stack.size();) {
|
||||
for (auto const i = m_stackIdx; i < m_stack.size();) {
|
||||
oxIgnoreError(m_stack.erase(i));
|
||||
}
|
||||
cmd->redo();
|
||||
|
@ -1,9 +0,0 @@
|
||||
/*
|
||||
* Copyright 2016 - 2023 Gary Talent (gary@drinkingtea.net). All rights reserved.
|
||||
*/
|
||||
|
||||
#include <studio/widget.hpp>
|
||||
|
||||
namespace studio {
|
||||
|
||||
}
|
Reference in New Issue
Block a user