[nostalgia,studio] Cleanup string handling

This commit is contained in:
Gary Talent 2023-12-03 22:01:38 -06:00
parent 6b7c002a10
commit 348193ae9e
5 changed files with 20 additions and 20 deletions

View File

@ -16,5 +16,5 @@ int main(int argc, const char **argv) {
#endif #endif
nostalgia::registerKeelModules(); nostalgia::registerKeelModules();
nostalgia::registerStudioModules(); nostalgia::registerStudioModules();
return studio::main("Nostalgia Studio", ox::String(".nostalgia"), argc, argv); return studio::main("Nostalgia Studio", ".nostalgia", argc, argv);
} }

View File

@ -21,7 +21,7 @@ int main(StudioOptions&&);
int main( int main(
ox::CRStringView appName, ox::CRStringView appName,
ox::String projectDataDir, ox::CRStringView projectDataDir,
int argc, int argc,
const char **argv); const char **argv);

View File

@ -19,13 +19,13 @@ namespace studio {
class StudioUIDrawer: public turbine::gl::Drawer { class StudioUIDrawer: public turbine::gl::Drawer {
private: private:
StudioUI *m_ui = nullptr; StudioUI &m_ui;
public: public:
explicit StudioUIDrawer(StudioUI *ui) noexcept: m_ui(ui) { explicit StudioUIDrawer(StudioUI &ui) noexcept: m_ui(ui) {
} }
protected: protected:
void draw(turbine::Context&) noexcept final { void draw(turbine::Context&) noexcept final {
m_ui->draw(); m_ui.draw();
} }
}; };
@ -44,7 +44,7 @@ static void keyEventHandler(turbine::Context &ctx, turbine::Key key, bool down)
static ox::Error runApp( static ox::Error runApp(
ox::CRStringView appName, ox::CRStringView appName,
ox::String projectDataDir, ox::CRStringView projectDataDir,
ox::UniquePtr<ox::FileSystem> fs) noexcept { ox::UniquePtr<ox::FileSystem> fs) noexcept {
oxRequireM(ctx, turbine::init(std::move(fs), appName)); oxRequireM(ctx, turbine::init(std::move(fs), appName));
turbine::setWindowTitle(*ctx, ctx->keelCtx.appName); turbine::setWindowTitle(*ctx, ctx->keelCtx.appName);
@ -53,9 +53,9 @@ static ox::Error runApp(
turbine::setConstantRefresh(*ctx, false); turbine::setConstantRefresh(*ctx, false);
studio::StudioContext studioCtx; studio::StudioContext studioCtx;
turbine::setApplicationData(*ctx, &studioCtx); turbine::setApplicationData(*ctx, &studioCtx);
StudioUI ui(ctx.get(), std::move(projectDataDir)); StudioUI ui(ctx.get(), projectDataDir);
studioCtx.ui = &ui; studioCtx.ui = &ui;
StudioUIDrawer drawer(&ui); StudioUIDrawer drawer(ui);
turbine::gl::addDrawer(*ctx, &drawer); turbine::gl::addDrawer(*ctx, &drawer);
const auto err = turbine::run(*ctx); const auto err = turbine::run(*ctx);
turbine::gl::removeDrawer(*ctx, &drawer); turbine::gl::removeDrawer(*ctx, &drawer);
@ -64,7 +64,7 @@ static ox::Error runApp(
int main( int main(
ox::CRStringView appName, ox::CRStringView appName,
ox::String projectDataDir, ox::CRStringView projectDataDir,
int, int,
const char**) { const char**) {
OX_INIT_DEBUG_LOGGER(loggerConn, appName) OX_INIT_DEBUG_LOGGER(loggerConn, appName)
@ -75,13 +75,13 @@ int main(
static_cast<uint64_t>(time << 1) static_cast<uint64_t>(time << 1)
}); });
// run app // run app
const auto err = runApp(appName, std::move(projectDataDir), ox::UniquePtr<ox::FileSystem>(nullptr)); const auto err = runApp(appName, projectDataDir, ox::UniquePtr<ox::FileSystem>(nullptr));
oxAssert(err, "Something went wrong..."); oxAssert(err, "Something went wrong...");
return static_cast<int>(err); return static_cast<int>(err);
} }
int main(StudioOptions &&opts, int argc = 0, const char **argv = nullptr) { int main(StudioOptions &&opts, int argc = 0, const char **argv = nullptr) {
return main(opts.appName, std::move(opts.projectDataDir), argc, argv); return main(opts.appName, opts.projectDataDir, argc, argv);
} }
} }

View File

@ -33,9 +33,9 @@ oxModelBegin(StudioConfig)
oxModelFieldRename(show_project_explorer, showProjectExplorer) oxModelFieldRename(show_project_explorer, showProjectExplorer)
oxModelEnd() oxModelEnd()
StudioUI::StudioUI(turbine::Context *ctx, ox::String projectDir) noexcept: StudioUI::StudioUI(turbine::Context *ctx, ox::StringView projectDir) noexcept:
m_ctx(ctx), m_ctx(ctx),
m_projectDir(std::move(projectDir)), m_projectDir(projectDir),
m_projectExplorer(ox::make_unique<ProjectExplorer>(m_ctx)), m_projectExplorer(ox::make_unique<ProjectExplorer>(m_ctx)),
m_aboutPopup(*ctx) { m_aboutPopup(*ctx) {
m_projectExplorer->fileChosen.connect(this, &StudioUI::openFile); m_projectExplorer->fileChosen.connect(this, &StudioUI::openFile);
@ -253,8 +253,8 @@ void StudioUI::drawTabs() noexcept {
} }
} }
void StudioUI::loadEditorMaker(const studio::EditorMaker &editorMaker) noexcept { void StudioUI::loadEditorMaker(studio::EditorMaker const&editorMaker) noexcept {
for (const auto &ext : editorMaker.fileTypes) { for (auto const&ext : editorMaker.fileTypes) {
m_editorMakers[ext] = editorMaker.make; m_editorMakers[ext] = editorMaker.make;
} }
} }
@ -370,7 +370,7 @@ ox::Error StudioUI::openFileActiveTab(ox::CRStringView path, bool makeActiveTab)
return {}; return {};
} }
ox::Error StudioUI::closeFile(const ox::String &path) noexcept { ox::Error StudioUI::closeFile(ox::CRStringView path) noexcept {
if (!m_openFiles.contains(path)) { if (!m_openFiles.contains(path)) {
return OxError(0); return OxError(0);
} }

View File

@ -44,14 +44,14 @@ class StudioUI: public ox::SignalHandler {
bool m_showProjectExplorer = true; bool m_showProjectExplorer = true;
public: public:
explicit StudioUI(turbine::Context *ctx, ox::String projectDir) noexcept; explicit StudioUI(turbine::Context *ctx, ox::StringView projectDir) noexcept;
void update() noexcept; void update() noexcept;
void handleKeyEvent(turbine::Key, bool down) noexcept; void handleKeyEvent(turbine::Key, bool down) noexcept;
[[nodiscard]] [[nodiscard]]
constexpr auto project() noexcept { constexpr studio::Project *project() noexcept {
return m_project.get(); return m_project.get();
} }
@ -65,7 +65,7 @@ class StudioUI: public ox::SignalHandler {
void drawTabs() noexcept; void drawTabs() noexcept;
void loadEditorMaker(const studio::EditorMaker &editorMaker) noexcept; void loadEditorMaker(studio::EditorMaker const&editorMaker) noexcept;
void loadModule(const studio::Module *mod) noexcept; void loadModule(const studio::Module *mod) noexcept;
@ -85,7 +85,7 @@ class StudioUI: public ox::SignalHandler {
ox::Error openFileActiveTab(ox::CRStringView path, bool makeActiveTab) noexcept; ox::Error openFileActiveTab(ox::CRStringView path, bool makeActiveTab) noexcept;
ox::Error closeFile(const ox::String &path) noexcept; ox::Error closeFile(ox::CRStringView path) noexcept;
}; };
} }