Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
big refactor
Browse files Browse the repository at this point in the history
refactored most of the history / favorite code to now be "bookkeeping".
this now uses a common struct to hold the required paths and the record type (to open up future work for emus).
thegouldfish committed Dec 6, 2024
1 parent c2be0c2 commit 1fecd26
Showing 18 changed files with 438 additions and 309 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@ SRCS = \
menu/ui_components/common.c \
menu/ui_components/context_menu.c \
menu/ui_components/file_list.c \
menu/ui_components/tabs.c \
menu/usb_comm.c \
menu/views/browser.c \
menu/views/credits.c \
Empty file added New Text Document.txt
Empty file.
8 changes: 4 additions & 4 deletions src/menu/actions.c
Original file line number Diff line number Diff line change
@@ -22,8 +22,8 @@ static void actions_clear (menu_t *menu) {
menu->actions.options = false;
menu->actions.settings = false;
menu->actions.lz_context = false;
menu->actions.favorite = false;
menu->actions.load_last = false;
menu->actions.previous_tab = false;
menu->actions.next_tab = false;
}

static void actions_update_direction (menu_t *menu) {
@@ -112,9 +112,9 @@ static void actions_update_buttons (menu_t *menu) {
} else if (pressed.l || pressed.z) {
menu->actions.lz_context = true;
} else if (pressed.c_left) {
menu->actions.load_last = true;
menu->actions.previous_tab = true;
} else if (pressed.c_right) {
menu->actions.favorite = true;
menu->actions.next_tab = true;
}
}

9 changes: 5 additions & 4 deletions src/menu/menu.c
Original file line number Diff line number Diff line change
@@ -72,9 +72,9 @@ static void menu_init (boot_params_t *boot_params) {
path_pop(path);

path_push(path, MENU_HISTORY_FILE);
history_init(path_get(path));
history_load(&menu->history);
menu->load.load_last = false;
bookkeeping_init(path_get(path));
bookkeeping_load(&menu->history);
menu->load.load_history = -1;
menu->load.load_favorite = -1;
path_pop(path);

@@ -158,7 +158,8 @@ static view_t menu_views[] = {
{ MENU_MODE_LOAD_EMULATOR, view_load_emulator_init, view_load_emulator_display },
{ MENU_MODE_ERROR, view_error_init, view_error_display },
{ MENU_MODE_FAULT, view_fault_init, view_fault_display },
{ MENU_MODE_FAVORITE, view_favorite_init, view_favorite_display }
{ MENU_MODE_FAVORITE, view_favorite_init, view_favorite_display },
{ MENU_MODE_HISTORY, view_history_init, view_history_display }
};

static view_t *menu_get_view (menu_mode_t id) {
11 changes: 6 additions & 5 deletions src/menu/menu_state.h
Original file line number Diff line number Diff line change
@@ -39,7 +39,8 @@ typedef enum {
MENU_MODE_ERROR,
MENU_MODE_FAULT,
MENU_MODE_BOOT,
MENU_MODE_FAVORITE
MENU_MODE_FAVORITE,
MENU_MODE_HISTORY
} menu_mode_t;

/** @brief File entry type enumeration */
@@ -69,7 +70,7 @@ typedef struct {

const char *storage_prefix;
settings_t settings;
history_t history;
bookkeeping_t history;
boot_params_t *boot_params;

char *error_message;
@@ -89,8 +90,8 @@ typedef struct {
bool options;
bool settings;
bool lz_context;
bool favorite;
bool load_last;
bool previous_tab;
bool next_tab;
} actions;

struct {
@@ -108,7 +109,7 @@ typedef struct {
rom_info_t rom_info;
path_t *disk_path;
disk_info_t disk_info;
bool load_last;
int load_history;
int load_favorite;
} load;

10 changes: 10 additions & 0 deletions src/menu/path.c
Original file line number Diff line number Diff line change
@@ -149,4 +149,14 @@ bool path_has_value(path_t *path) {
}
}
return false;
}

bool path_are_match(path_t *left, path_t *right) {
if(!path_has_value(left) && !path_has_value(right)) {
return true;
} else if(path_has_value(left) && path_has_value(right)) {
return (strcmp(path_get(left), path_get(right)) == 0);
} else {
return false;
}
}
1 change: 1 addition & 0 deletions src/menu/path.h
Original file line number Diff line number Diff line change
@@ -34,5 +34,6 @@ char *path_ext_get (path_t *path);
void path_ext_remove (path_t *path);
void path_ext_replace (path_t *path, char *ext);
bool path_has_value(path_t *path);
bool path_are_match(path_t *left, path_t *right);

#endif
Loading

0 comments on commit 1fecd26

Please sign in to comment.