Skip to content

Commit

Permalink
Add basic file menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
albin-johansson committed May 23, 2024
1 parent 1c45ec1 commit 4f32e8d
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 3 deletions.
16 changes: 16 additions & 0 deletions source/core/inc/tactile/core/event/file_events.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ struct SaveAsEvent final
Path path;
};

/**
* Event for reopening the last closed file.
*
* \ingroup Event
*/
struct ReopenLastClosedFileEvent final
{};

/**
* Event for clearing the file history.
*
* \ingroup Event
*/
struct ClearFileHistoryEvent final
{};

/**
* Event for closing the current document.
*
Expand Down
72 changes: 72 additions & 0 deletions source/core/src/tactile/core/ui/menu/file_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,41 @@

#include <imgui.h>

#include "tactile/core/event/dialog_events.hpp"
#include "tactile/core/event/event_dispatcher.hpp"
#include "tactile/core/event/file_events.hpp"
#include "tactile/core/model/model.hpp"
#include "tactile/core/ui/common/menus.hpp"
#include "tactile/core/ui/i18n/language.hpp"
#include "tactile/core/ui/shortcuts.hpp"

namespace tactile::ui {
inline namespace file_menu {

void _push_recent_files_menu(const Language& language,
EventDispatcher& dispatcher)
{
const MenuScope menu {language.get(StringID::kRecentFilesMenu)};
if (menu.is_open()) {
if (ImGui::MenuItem(language.get(StringID::kReopenLastClosedFile),
nullptr,
false,
false)) {
dispatcher.push<ReopenLastClosedFileEvent>();
}

ImGui::Separator();

if (ImGui::MenuItem(language.get(StringID::kClearFileHistory),
nullptr,
false,
false)) {
dispatcher.push<ClearFileHistoryEvent>();
}
}
}

} // namespace file_menu

void FileMenu::push(const Model& model, EventDispatcher& dispatcher)
{
Expand All @@ -18,6 +47,49 @@ void FileMenu::push(const Model& model, EventDispatcher& dispatcher)

const MenuScope menu {language.get(StringID::kFileMenu)};
if (menu.is_open()) {
if (ImGui::MenuItem(language.get(StringID::kCreateMap),
kCreateMapShortcut.hint)) {
dispatcher.push<ShowNewMapDialogEvent>();
}

ImGui::Separator();

if (ImGui::MenuItem(language.get(StringID::kOpen), kOpenShortcut.hint)) {
dispatcher.push<ShowOpenMapDialogEvent>();
}

_push_recent_files_menu(language, dispatcher);

ImGui::Separator();

if (ImGui::MenuItem(language.get(StringID::kSave),
kSaveShortcut.hint,
false,
false)) {
dispatcher.push<SaveEvent>();
}

if (ImGui::MenuItem(language.get(StringID::kSaveAs),
kSaveAsShortcut.hint,
false,
current_document != nullptr)) {
dispatcher.push<ShowSaveAsDialogEvent>();
}

ImGui::Separator();

if (ImGui::MenuItem(language.get(StringID::kClose),
nullptr,
false,
current_document != nullptr)) {
dispatcher.push<CloseEvent>();
}

ImGui::Separator();

if (ImGui::MenuItem(language.get(StringID::kQuit))) {
dispatcher.push<QuitEvent>();
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions source/core/src/tactile/core/ui/shortcuts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

#include <imgui_internal.h>

#include "tactile/core/event/dialog_events.hpp"
#include "tactile/core/event/event_dispatcher.hpp"
#include "tactile/core/event/file_events.hpp"
#include "tactile/core/event/map_events.hpp"

namespace tactile::ui {

Expand All @@ -18,7 +17,7 @@ void push_global_shortcuts(const Model& model, EventDispatcher& dispatcher)
dispatcher.push<ShowNewMapDialogEvent>();
}

if (ImGui::Shortcut(kOpenMapShortcut.chord,
if (ImGui::Shortcut(kOpenShortcut.chord,
ImGuiKeyOwner_Any,
ImGuiInputFlags_RouteGlobalLow)) {
dispatcher.push<ShowOpenMapDialogEvent>();
Expand Down

0 comments on commit 4f32e8d

Please sign in to comment.