Mostly adopt the standard OS X document-based UI model on OS X

This commit is contained in:
Thomas Goyne 2015-08-29 18:18:04 -07:00
parent 0f17784548
commit 84b0f1e043
2 changed files with 37 additions and 10 deletions

View File

@ -31,6 +31,7 @@
#include "../include/aegisub/context.h"
#include "../libresrc/libresrc.h"
#include "../main.h"
#include "../options.h"
#include "../project.h"
#include "../subs_controller.h"
@ -75,8 +76,12 @@ struct recent_subtitle_entry : public Command {
STR_HELP("Open recent subtitles")
void operator()(agi::Context *c, int id) {
#ifdef __APPLE__
wxGetApp().NewProjectContext().project->LoadSubtitles(config::mru->GetEntry("Subtitle", id));
#else
if (c->subsController->TryToClose() == wxCANCEL) return;
c->project->LoadSubtitles(config::mru->GetEntry("Subtitle", id));
c->project->LoadSubtitles();
#endif
}
};

View File

@ -38,6 +38,7 @@
#include "../dialogs.h"
#include "../include/aegisub/context.h"
#include "../libresrc/libresrc.h"
#include "../main.h"
#include "../options.h"
#include "../project.h"
#include "../search_replace_engine.h"
@ -215,6 +216,22 @@ struct subtitle_insert_before_videotime final : public validate_nonempty_selecti
}
};
bool is_okay_to_close_subtitles(agi::Context *c) {
#ifdef __APPLE__
return true;
#else
return c->subsController->TryToClose() != wxCANCEL;
#endif
}
void load_subtitles(agi::Context *c, agi::fs::path const& path, std::string const& encoding="") {
#ifdef __APPLE__
wxGetApp().NewProjectContext().project->LoadSubtitles(path, encoding);
#else
c->project->LoadSubtitles(path, encoding);
#endif
}
struct subtitle_new final : public Command {
CMD_NAME("subtitle/new")
CMD_ICON(new_toolbutton)
@ -223,8 +240,12 @@ struct subtitle_new final : public Command {
STR_HELP("New subtitles")
void operator()(agi::Context *c) override {
if (c->subsController->TryToClose() != wxCANCEL)
#ifdef __APPLE__
wxGetApp().NewProjectContext();
#else
if (is_okay_to_reuse_existing_window(c))
c->project->CloseSubtitles();
#endif
}
};
@ -236,10 +257,11 @@ struct subtitle_open final : public Command {
STR_HELP("Open a subtitles file")
void operator()(agi::Context *c) override {
if (c->subsController->TryToClose() == wxCANCEL) return;
if (!is_okay_to_close_subtitles(c)) return;
auto filename = OpenFileSelector(_("Open subtitles file"), "Path/Last/Subtitles", "","", SubtitleFormat::GetWildcards(0), c->parent);
if (!filename.empty())
c->project->LoadSubtitles(filename);
load_subtitles(c, filename);
}
};
@ -250,10 +272,10 @@ struct subtitle_open_autosave final : public Command {
STR_HELP("Open a previous version of a file which was autosaved by Aegisub")
void operator()(agi::Context *c) override {
if (c->subsController->TryToClose() == wxCANCEL) return;
auto file = PickAutosaveFile(c->parent);
if (!file.empty())
c->project->LoadSubtitles(file);
if (!is_okay_to_close_subtitles(c)) return;
auto filename = PickAutosaveFile(c->parent);
if (!filename.empty())
load_subtitles(c, filename);
}
};
@ -265,7 +287,7 @@ struct subtitle_open_charset final : public Command {
STR_HELP("Open a subtitles file with a specific file encoding")
void operator()(agi::Context *c) override {
if (c->subsController->TryToClose() == wxCANCEL) return;
if (!is_okay_to_close_subtitles(c)) return;
auto filename = OpenFileSelector(_("Open subtitles file"), "Path/Last/Subtitles", "","", SubtitleFormat::GetWildcards(0), c->parent);
if (filename.empty()) return;
@ -273,7 +295,7 @@ struct subtitle_open_charset final : public Command {
wxString charset = wxGetSingleChoice(_("Choose charset code:"), _("Charset"), agi::charset::GetEncodingsList<wxArrayString>(), c->parent, -1, -1, true, 250, 200);
if (charset.empty()) return;
c->project->LoadSubtitles(filename, from_wx(charset));
load_subtitles(c, filename, from_wx(charset));
}
};