From c066305125d92d92353937c5ac1284274044bd3a Mon Sep 17 00:00:00 2001 From: Guillaume Chereau Date: Wed, 8 Mar 2017 22:36:04 +0800 Subject: [PATCH] Some cleanup of menus and actions --- src/goxel.h | 8 ++++---- src/gui.cpp | 25 +++++-------------------- src/save.c | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/goxel.h b/src/goxel.h index 643a85471..b24cacb19 100644 --- a/src/goxel.h +++ b/src/goxel.h @@ -400,10 +400,10 @@ void actions_iter(int (*f)(const action_t *action)); // Convenience macro to register an action from anywere in a c file. #define ACTION_REGISTER(id_, ...) \ - static const action_t action_##id_ = {.id = #id_, __VA_ARGS__}; \ - static void register_action_##id_() __attribute__((constructor)); \ - static void register_action_##id_() { \ - action_register(&action_##id_); \ + static const action_t GOX_action_##id_ = {.id = #id_, __VA_ARGS__}; \ + static void GOX_register_action_##id_() __attribute__((constructor)); \ + static void GOX_register_action_##id_() { \ + action_register(&GOX_action_##id_); \ } // ############################# diff --git a/src/gui.cpp b/src/gui.cpp index e75e16670..a0f9c0886 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -1032,15 +1032,6 @@ static void export_as(goxel_t *goxel, const char *filter) action_exec2("export_as", "pp", filter, path); } -static void load(goxel_t *goxel) -{ - const char *path; - path = noc_file_dialog_open(NOC_FILE_DIALOG_OPEN, "gox\0*.gox\0", - NULL, NULL); - if (!path) return; - load_from_file(goxel, path); -} - static void shift_alpha_popup(goxel_t *goxel, bool just_open) { static int v = 0; @@ -1152,15 +1143,9 @@ void gui_iter(goxel_t *goxel, const inputs_t *inputs) if (ImGui::BeginMenuBar()) { if (ImGui::BeginMenu("File")) { - if (ImGui::MenuItem("Save", "Ctrl+S")) { - action_exec2("save", ""); - } - if (ImGui::MenuItem("Save as")) { - action_exec2("save_as", ""); - } - if (ImGui::MenuItem("Load", "Ctrl+O")) { - load(goxel); - } + ImGui::GoxMenuItem("save", "Save"); + ImGui::GoxMenuItem("save_as", "Save as"); + ImGui::GoxMenuItem("open", "Open"); if (ImGui::BeginMenu("Import...")) { if (ImGui::MenuItem("image plane")) import_image_plane(goxel); if (ImGui::MenuItem("qubicle")) import_qubicle(goxel); @@ -1184,8 +1169,8 @@ void gui_iter(goxel_t *goxel, const inputs_t *inputs) if (ImGui::BeginMenu("Edit")) { if (ImGui::MenuItem("Clear", "Delete")) action_exec2("layer_clear", ""); - if (ImGui::MenuItem("Undo", "Ctrl+Z")) goxel_undo(goxel); - if (ImGui::MenuItem("Redo", "Ctrl+Y")) goxel_redo(goxel); + if (ImGui::MenuItem("Undo", "Ctrl Z")) goxel_undo(goxel); + if (ImGui::MenuItem("Redo", "Ctrl Y")) goxel_redo(goxel); if (ImGui::MenuItem("Shift Alpha")) open_shift_alpha = true; ImGui::EndMenu(); diff --git a/src/save.c b/src/save.c index 42abf64a9..e9c466c6d 100644 --- a/src/save.c +++ b/src/save.c @@ -375,6 +375,23 @@ void load_from_file(goxel_t *goxel, const char *path) gzclose(in); } +static void action_open(const char *path) +{ + + if (!path) + path = noc_file_dialog_open(NOC_FILE_DIALOG_OPEN, "gox\0*.gox\0", + NULL, NULL); + if (!path) return; + load_from_file(goxel, path); +} + +ACTION_REGISTER(open, + .help = "Open an image", + .cfunc = action_open, + .csig = "vp", + .shortcut = "Ctrl O", +) + static void save_as(const char *path) { if (!path) {