Skip to content

Commit

Permalink
Some cleanup of menus and actions
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumechereau committed Mar 8, 2017
1 parent d5af2f3 commit c066305
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/goxel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_); \
}

// #############################
Expand Down
25 changes: 5 additions & 20 deletions src/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions src/save.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit c066305

Please sign in to comment.