Skip to content

Commit 371bf36

Browse files
committed
First of two modifications to this PR.
1 parent 4657d19 commit 371bf36

File tree

4 files changed

+12
-138
lines changed

4 files changed

+12
-138
lines changed

ui/xui/actions.cc

Lines changed: 3 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "../xemu-notifications.h"
2525
#include "snapshot-manager.hh"
2626

27-
#define MAX_RECENT_DISCS 15
27+
#define MAX_RECENT_DISCS 11
2828

2929
void ActionEjectDisc(void)
3030
{
@@ -90,8 +90,8 @@ void ActionLoadDiscFile(const char *file_path)
9090
g_config.general.recent.discs_count++;
9191
}
9292

93-
for (int i = g_config.general.recent.discs_count - 1; i > 0; i--) {
94-
g_config.general.recent.discs[i] = g_config.general.recent.discs[i-1];
93+
for (int i = g_config.general.recent.discs_count - 1; j > 0; j--) {
94+
g_config.general.recent.discs[i] = g_config.general.recent.discs[j-1];
9595
}
9696
g_config.general.recent.discs[0] = g_strdup(file_path);
9797
}
@@ -152,46 +152,6 @@ void ActionLoadSnapshotChecked(const char *name)
152152
g_snapshot_mgr.LoadSnapshotChecked(name);
153153
}
154154

155-
void ActionLoadDiscFromRecent(unsigned int index)
156-
{
157-
g_assert(index < g_config.general.recent.discs_count);
158-
if (index >= g_config.general.recent.discs_count) return;
159-
160-
const char *file_path = g_config.general.recent.discs[index];
161-
if (!file_path || !file_path[0]) return;
162-
163-
if (qemu_access(file_path, F_OK) == -1) {
164-
g_free((void*)g_config.general.recent.discs[index]);
165-
for (int j = index; j < g_config.general.recent.discs_count - 1; j++) {
166-
g_config.general.recent.discs[j] = g_config.general.recent.discs[j + 1];
167-
}
168-
g_config.general.recent.discs_count--;
169-
if (g_config.general.recent.discs_count == 0) {
170-
g_free(g_config.general.recent.discs);
171-
g_config.general.recent.discs = NULL;
172-
}
173-
return;
174-
}
175-
176-
ActionLoadDiscFile(file_path);
177-
}
178-
179-
void ActionRemoveDiscFromRecent(unsigned int index)
180-
{
181-
g_assert(index < g_config.general.recent.discs_count);
182-
if (index >= g_config.general.recent.discs_count) return;
183-
184-
g_free((void*)g_config.general.recent.discs[index]);
185-
for (int j = index; j < g_config.general.recent.discs_count - 1; j++) {
186-
g_config.general.recent.discs[j] = g_config.general.recent.discs[j + 1];
187-
}
188-
g_config.general.recent.discs_count--;
189-
if (g_config.general.recent.discs_count == 0) {
190-
g_free(g_config.general.recent.discs);
191-
g_config.general.recent.discs = NULL;
192-
}
193-
}
194-
195155
void ActionClearDiscRecent(void)
196156
{
197157
for (int i = 0; i < g_config.general.recent.discs_count; i++) {
@@ -201,35 +161,3 @@ void ActionClearDiscRecent(void)
201161
g_config.general.recent.discs = NULL;
202162
g_config.general.recent.discs_count = 0;
203163
}
204-
205-
void ActionClearMissingRecentDiscs(void)
206-
{
207-
int valid_count = 0;
208-
for (int i = 0; i < g_config.general.recent.discs_count; i++) {
209-
const char *disc_path = g_config.general.recent.discs[i];
210-
if (!disc_path) continue;
211-
if (qemu_access(disc_path, F_OK) != -1) {
212-
valid_count++;
213-
}
214-
}
215-
216-
const char **valid_discs = NULL;
217-
if (valid_count > 0) {
218-
valid_discs = (const char **)g_new0(const char *, valid_count);
219-
220-
int valid_index = 0;
221-
for (int i = 0; i < g_config.general.recent.discs_count; i++) {
222-
const char *disc_path = g_config.general.recent.discs[i];
223-
if (!disc_path) continue;
224-
if (qemu_access(disc_path, F_OK) != -1) {
225-
valid_discs[valid_index++] = disc_path;
226-
} else {
227-
g_free((void*)disc_path);
228-
}
229-
}
230-
}
231-
232-
g_free(g_config.general.recent.discs);
233-
g_config.general.recent.discs = valid_discs;
234-
g_config.general.recent.discs_count = valid_count;
235-
}

ui/xui/actions.hh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,4 @@ void ActionShutdown();
2727
void ActionScreenshot();
2828
void ActionActivateBoundSnapshot(int slot, bool save);
2929
void ActionLoadSnapshotChecked(const char *name);
30-
void ActionLoadDiscFromRecent(unsigned int index);
31-
void ActionRemoveDiscFromRecent(unsigned int index);
3230
void ActionClearDiscRecent(void);
33-
void ActionClearMissingRecentDiscs(void);

ui/xui/main.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ void xemu_hud_init(SDL_Window* window, void* sdl_gl_context)
159159
InitializeStyle();
160160
g_main_menu.SetNextViewIndex(g_config.general.last_viewed_menu_index);
161161
first_boot_window.is_open = g_config.general.show_welcome;
162+
// g_menubar_recent_list = RecentList::create(&g_config.recent);
162163
}
163164

164165
void xemu_hud_cleanup(void)

ui/xui/menubar.cc

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -142,79 +142,27 @@ void ShowMainMenu()
142142
if (ImGui::MenuItem("Eject Disc", SHORTCUT_MENU_TEXT(E))) ActionEjectDisc();
143143
if (ImGui::MenuItem("Load Disc...", SHORTCUT_MENU_TEXT(O))) ActionLoadDisc();
144144

145-
int valid_count = 0;
146-
for (int i = 0; i < g_config.general.recent.discs_count; i++) {
147-
const char *disc_path = g_config.general.recent.discs[i];
148-
if (!disc_path) continue;
149-
150-
const char *filename = g_path_get_basename(disc_path);
151-
bool file_exists = qemu_access(disc_path, F_OK) != -1;
152-
g_free((void *)filename);
153-
154-
if (file_exists) {
155-
valid_count++;
156-
}
157-
}
158-
159-
bool has_valid_entries = (valid_count > 0);
160-
if (ImGui::BeginMenu("Recent Discs", has_valid_entries)) {
161-
for (int i = 0; i < g_config.general.recent.discs_count; i++) {
145+
bool has_any_entries = (g_config.general.recent.discs_count > 0);
146+
if (ImGui::BeginMenu("Recent Discs", has_any_entries)) {
147+
for (size_t i = 0; i < g_config.general.recent.discs_count; i++) {
162148
const char *disc_path = g_config.general.recent.discs[i];
163149
if (!disc_path) continue;
164-
150+
165151
const char *filename = g_path_get_basename(disc_path);
166-
bool file_exists = qemu_access(disc_path, F_OK) != -1;
167-
168-
if (file_exists) {
169-
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 0, 0, 255));
170-
ImGui::PushID(i + 1000);
171-
if (ImGui::Button("X", ImVec2(20.0f, 0))) {
172-
ActionRemoveDiscFromRecent(i);
173-
}
174-
ImGui::PopID();
175-
ImGui::PopStyleColor();
176-
177-
ImGui::SameLine();
178-
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 255, 255, 255));
152+
179153
if (ImGui::MenuItem(filename)) {
180-
ActionLoadDiscFromRecent(i);
181-
}
182-
ImGui::PopStyleColor();
183-
} else {
184-
char *missing_filename = g_strconcat(filename, " (missing)", nullptr);
185-
186-
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 0, 0, 255));
187-
ImGui::PushID(i + 1000);
188-
if (ImGui::Button("X", ImVec2(20.0f, 0))) {
189-
ActionRemoveDiscFromRecent(i);
154+
ActionLoadDiscFile(disc_path);
190155
}
191-
ImGui::PopID();
192-
ImGui::PopStyleColor();
193-
194-
ImGui::SameLine();
195-
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(128, 128, 128, 255));
196-
ImGui::Text("%s", missing_filename);
197-
ImGui::PopStyleColor();
198-
199-
g_free(missing_filename);
200-
}
201-
156+
202157
g_free((void *)filename);
203158
}
204-
205159
if (g_config.general.recent.discs_count > 0) {
206160
ImGui::Separator();
207-
208161
if (ImGui::MenuItem("Clear Recent Discs")) {
209162
ActionClearDiscRecent();
210163
}
211-
212-
if (ImGui::MenuItem("Clear Missing Recent Discs")) {
213-
ActionClearMissingRecentDiscs();
214-
}
215-
}
216-
217164
ImGui::EndMenu();
165+
}
218166
}
219167

220168
ImGui::Separator();

0 commit comments

Comments
 (0)