summaryrefslogtreecommitdiff
path: root/lib/nes/app/ui
diff options
context:
space:
mode:
authorHannes Schulze <haschu0103@outlook.de>2025-02-04 23:11:08 +0100
committerHannes Schulze <haschu0103@outlook.de>2025-02-04 23:11:08 +0100
commit79553ab1fa3d707612e80dd03bf95ca65fa0c411 (patch)
treef44bec41548d569cfca43c44e0e4ffa7b72ed4ed /lib/nes/app/ui
parent9c45e9c7df1efa5bc1c8e73b6eaef4726b828d3e (diff)
refactor file browser
Diffstat (limited to 'lib/nes/app/ui')
-rw-r--r--lib/nes/app/ui/action.hh26
-rw-r--r--lib/nes/app/ui/screen-browser.cc28
2 files changed, 37 insertions, 17 deletions
diff --git a/lib/nes/app/ui/action.hh b/lib/nes/app/ui/action.hh
index b701606..66f77f8 100644
--- a/lib/nes/app/ui/action.hh
+++ b/lib/nes/app/ui/action.hh
@@ -1,5 +1,6 @@
#pragma once
+#include "nes/common/status.hh"
#include <string_view>
namespace nes::app
@@ -16,28 +17,41 @@ namespace nes::app
go_to_settings,
go_to_help,
launch_game,
+ show_error,
};
private:
type type_{ type::none };
std::string_view file_name_;
+ status error_{ status::success };
public:
explicit action() = default;
- static auto go_to_title() -> action { return action{ type::go_to_title, "" }; }
- static auto go_to_browser() -> action { return action{ type::go_to_browser, "" }; }
- static auto go_to_settings() -> action { return action{ type::go_to_settings, "" }; }
- static auto go_to_help() -> action { return action{ type::go_to_help, "" }; }
- static auto launch_game(std::string_view const file_name) -> action { return action{ type::launch_game, file_name }; }
+ static auto go_to_title() -> action { return action{ type::go_to_title, "", status::success }; }
+ static auto go_to_browser() -> action { return action{ type::go_to_browser, "", status::success }; }
+ static auto go_to_settings() -> action { return action{ type::go_to_settings, "", status::success }; }
+ static auto go_to_help() -> action { return action{ type::go_to_help, "", status::success }; }
+
+ static auto launch_game(std::string_view const file_name) -> action
+ {
+ return action{ type::launch_game, file_name, status::success };
+ }
+
+ static auto show_error(status const error)
+ {
+ return action{ type::show_error, "", error };
+ }
auto get_type() const -> type { return type_; }
auto get_file_name() const -> std::string_view { return file_name_; }
+ auto get_error() const -> status { return error_; }
private:
- explicit action(type const type, std::string_view const file_name)
+ explicit action(type const type, std::string_view const file_name, status const error)
: type_{ type }
, file_name_{ file_name }
+ , error_{ error }
{
}
};
diff --git a/lib/nes/app/ui/screen-browser.cc b/lib/nes/app/ui/screen-browser.cc
index 6a18d3c..14ddc23 100644
--- a/lib/nes/app/ui/screen-browser.cc
+++ b/lib/nes/app/ui/screen-browser.cc
@@ -99,7 +99,10 @@ namespace nes::app
{
if (navigation_steps_ > 0)
{
- file_browser_.navigate_up();
+ if (auto const s = file_browser_.navigate_up(); s != status::success)
+ {
+ return action::show_error(s);
+ }
refresh();
navigation_steps_ -= 1;
}
@@ -115,22 +118,25 @@ namespace nes::app
{
if (selected->is_parent)
{
- file_browser_.navigate_up();
+ if (auto const s = file_browser_.navigate_up(); s != status::success)
+ {
+ return action::show_error(s);
+ }
refresh();
if (navigation_steps_ > 0) { navigation_steps_ -= 1; }
}
- else
+ else if (selected->data.get_type() == file_browser::item_type::directory)
{
- switch (selected->data.get_type())
+ if (auto const s = file_browser_.navigate(selected->data.get_name()); s != status::success)
{
- case file_browser::item_type::directory:
- file_browser_.navigate(selected->data.get_name());
- refresh();
- navigation_steps_ += 1;
- break;
- case file_browser::item_type::file:
- return action::launch_game(selected->data.get_name());
+ return action::show_error(s);
}
+ refresh();
+ navigation_steps_ += 1;
+ }
+ else if (selected->data.get_type() == file_browser::item_type::file)
+ {
+ return action::launch_game(selected->data.get_name());
}
}
}