forked from mia/Aegisub
Implement MRU commands
Originally committed to SVN as r5199.
This commit is contained in:
parent
ecea389e62
commit
08ec92046f
3 changed files with 112 additions and 21 deletions
|
@ -37,12 +37,15 @@
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
|
|
||||||
#ifndef AGI_PRE
|
#ifndef AGI_PRE
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#include <wx/event.h>
|
#include <wx/event.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
|
|
||||||
#include "../include/aegisub/context.h"
|
#include "../include/aegisub/context.h"
|
||||||
|
#include "../audio_controller.h"
|
||||||
#include "../main.h"
|
#include "../main.h"
|
||||||
#include "../frame_main.h"
|
#include "../frame_main.h"
|
||||||
#include "../compat.h"
|
#include "../compat.h"
|
||||||
|
@ -58,6 +61,80 @@ COMMAND_GROUP(recent_subtitle, "recent/subtitle", "Recent", "Recent", "Open rece
|
||||||
COMMAND_GROUP(recent_timecode, "recent/timecode", "Recent", "Recent", "Open recent timecodes.");
|
COMMAND_GROUP(recent_timecode, "recent/timecode", "Recent", "Recent", "Open recent timecodes.");
|
||||||
COMMAND_GROUP(recent_video, "recent/video", "Recent", "Recent", "Open recent video.");
|
COMMAND_GROUP(recent_video, "recent/video", "Recent", "Recent", "Open recent video.");
|
||||||
|
|
||||||
|
struct recent_audio_entry : public Command {
|
||||||
|
CMD_NAME("recent/audio/")
|
||||||
|
STR_MENU("Recent")
|
||||||
|
STR_DISP("Recent")
|
||||||
|
STR_HELP("Open recent audio.")
|
||||||
|
|
||||||
|
void operator()(agi::Context *c, int id) {
|
||||||
|
c->audioController->OpenAudio(lagi_wxString(config::mru->GetEntry("Audio", id)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct recent_keyframe_entry : public Command {
|
||||||
|
CMD_NAME("recent/keyframe/")
|
||||||
|
STR_MENU("Recent")
|
||||||
|
STR_DISP("Recent")
|
||||||
|
STR_HELP("Open recent keyframes.")
|
||||||
|
|
||||||
|
void operator()(agi::Context *c, int id) {
|
||||||
|
c->videoContext->LoadKeyframes(lagi_wxString(config::mru->GetEntry("Keyframes", id)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct recent_subtitle_entry : public Command {
|
||||||
|
CMD_NAME("recent/subtitle/")
|
||||||
|
STR_MENU("Recent")
|
||||||
|
STR_DISP("Recent")
|
||||||
|
STR_HELP("Open recent subtitles.")
|
||||||
|
|
||||||
|
void operator()(agi::Context *c, int id) {
|
||||||
|
wxGetApp().frame->LoadSubtitles(lagi_wxString(config::mru->GetEntry("Subtitle", id)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct recent_timecode_entry : public Command {
|
||||||
|
CMD_NAME("recent/timecode/")
|
||||||
|
STR_MENU("Recent")
|
||||||
|
STR_DISP("Recent")
|
||||||
|
STR_HELP("Open recent timecodes.")
|
||||||
|
|
||||||
|
void operator()(agi::Context *c, int id) {
|
||||||
|
c->videoContext->LoadTimecodes(lagi_wxString(config::mru->GetEntry("Timecodes", id)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct recent_video_entry : public Command {
|
||||||
|
CMD_NAME("recent/video/")
|
||||||
|
STR_MENU("Recent")
|
||||||
|
STR_DISP("Recent")
|
||||||
|
STR_HELP("Open recent videos.")
|
||||||
|
|
||||||
|
void operator()(agi::Context *c, int id) {
|
||||||
|
c->videoContext->SetVideo(lagi_wxString(config::mru->GetEntry("Video", id)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// @class mru_wrapper
|
||||||
|
/// @brief Wrapper class for mru commands to
|
||||||
|
template<class T>
|
||||||
|
class mru_wrapper : public T {
|
||||||
|
int id;
|
||||||
|
std::string full_name;
|
||||||
|
public:
|
||||||
|
const char *name() { return full_name.c_str(); }
|
||||||
|
void operator()(agi::Context *c) {
|
||||||
|
T::operator()(c, id);
|
||||||
|
}
|
||||||
|
mru_wrapper(int id) : id(id) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << T::name();
|
||||||
|
ss << id;
|
||||||
|
full_name = ss.str();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
|
||||||
/// Init recent/ commands.
|
/// Init recent/ commands.
|
||||||
|
@ -67,6 +144,15 @@ void init_recent(CommandManager *cm) {
|
||||||
cm->reg(new recent_subtitle());
|
cm->reg(new recent_subtitle());
|
||||||
cm->reg(new recent_timecode());
|
cm->reg(new recent_timecode());
|
||||||
cm->reg(new recent_video());
|
cm->reg(new recent_video());
|
||||||
|
|
||||||
|
/// @todo 16 is an implementation detail that maybe needs to be exposed
|
||||||
|
for (int i = 0; i < 16; ++i) {
|
||||||
|
cm->reg(new mru_wrapper<recent_audio_entry>(i));
|
||||||
|
cm->reg(new mru_wrapper<recent_keyframe_entry>(i));
|
||||||
|
cm->reg(new mru_wrapper<recent_subtitle_entry>(i));
|
||||||
|
cm->reg(new mru_wrapper<recent_timecode_entry>(i));
|
||||||
|
cm->reg(new mru_wrapper<recent_video_entry>(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace cmd
|
} // namespace cmd
|
||||||
|
|
|
@ -1071,28 +1071,33 @@ void FrameMain::OnGridEvent (wxCommandEvent &event) {
|
||||||
/// @param listName
|
/// @param listName
|
||||||
/// @param menu
|
/// @param menu
|
||||||
/// @param startID
|
/// @param startID
|
||||||
void FrameMain::RebuildRecentList(wxString listName,wxMenu *menu,int startID) {
|
void FrameMain::RebuildRecentList(const char *root_command, const char *mru_name) {
|
||||||
// Wipe previous list
|
wxMenu *menu = menu::menu->GetMenu(root_command);
|
||||||
|
|
||||||
int count = (int)menu->GetMenuItemCount();
|
int count = (int)menu->GetMenuItemCount();
|
||||||
for (int i=count;--i>=0;) {
|
for (int i=count;--i>=0;) {
|
||||||
menu->Destroy(menu->FindItemByPosition(i));
|
menu->Destroy(menu->FindItemByPosition(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rebuild
|
const agi::MRUManager::MRUListMap *map_list = config::mru->Get(mru_name);
|
||||||
int added = 0;
|
if (map_list->empty()) {
|
||||||
wxString n;
|
menu->Append(-1, _("Empty"))->Enable(false);
|
||||||
wxArrayString entries = lagi_MRU_wxAS(listName);
|
return;
|
||||||
for (size_t i=0;i<entries.Count();i++) {
|
|
||||||
n = wxString::Format(_T("%ld"),i+1);
|
|
||||||
if (i < 9) n = _T("&") + n;
|
|
||||||
wxFileName shortname(entries[i]);
|
|
||||||
wxString filename = shortname.GetFullName();
|
|
||||||
menu->Append(startID+i,n + _T(" ") + filename);
|
|
||||||
added++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nothing added, add an empty placeholder
|
int i = 0;
|
||||||
if (added == 0) menu->Append(startID,_("Empty"))->Enable(false);
|
for (agi::MRUManager::MRUListMap::const_iterator it = map_list->begin(); it != map_list->end(); ++it) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << root_command;
|
||||||
|
ss << "/";
|
||||||
|
ss << i;
|
||||||
|
|
||||||
|
wxFileName shortname(lagi_wxString(it->second));
|
||||||
|
|
||||||
|
menu->Append(cmd::id(ss.str()),
|
||||||
|
wxString::Format("%s%d %s", i <= 9 ? "&" : "", i + 1, shortname.GetFullName()));
|
||||||
|
++i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Menu is being opened
|
/// @brief Menu is being opened
|
||||||
|
@ -1107,7 +1112,7 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) {
|
||||||
// File menu
|
// File menu
|
||||||
if (curMenu == menu::menu->GetMenu("main/file")) {
|
if (curMenu == menu::menu->GetMenu("main/file")) {
|
||||||
// Rebuild recent
|
// Rebuild recent
|
||||||
RebuildRecentList(_T("Subtitle"),menu::menu->GetMenu("recent/subtitle"), cmd::id("recent/subtitle"));
|
RebuildRecentList("recent/subtitle", "Subtitle");
|
||||||
|
|
||||||
MenuBar->Enable(cmd::id("subtitle/open/video"),VideoContext::Get()->HasSubtitles());
|
MenuBar->Enable(cmd::id("subtitle/open/video"),VideoContext::Get()->HasSubtitles());
|
||||||
}
|
}
|
||||||
|
@ -1184,9 +1189,9 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) {
|
||||||
MenuBar->Check(cmd::id("video/show_overscan"),OPT_GET("Video/Overscan Mask")->GetBool());
|
MenuBar->Check(cmd::id("video/show_overscan"),OPT_GET("Video/Overscan Mask")->GetBool());
|
||||||
|
|
||||||
// Rebuild recent lists
|
// Rebuild recent lists
|
||||||
RebuildRecentList(_T("Video"),menu::menu->GetMenu("recent/video"), cmd::id("recent/video"));
|
RebuildRecentList("recent/video", "Video");
|
||||||
RebuildRecentList(_T("Timecodes"),menu::menu->GetMenu("recent/timecode"), cmd::id("recent/timecode"));
|
RebuildRecentList("recent/timecode", "Timecodes");
|
||||||
RebuildRecentList(_T("Keyframes"),menu::menu->GetMenu("recent/keyframe"), cmd::id("recent/keyframe"));
|
RebuildRecentList("recent/keyframe", "Keyframes");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Audio menu
|
// Audio menu
|
||||||
|
@ -1198,7 +1203,7 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) {
|
||||||
MenuBar->Enable(cmd::id("audio/close"),state);
|
MenuBar->Enable(cmd::id("audio/close"),state);
|
||||||
|
|
||||||
// Rebuild recent
|
// Rebuild recent
|
||||||
RebuildRecentList(_T("Audio"),menu::menu->GetMenu("recent/audio"), cmd::id("recent/audio"));
|
RebuildRecentList("recent/audio", "Audio");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtitles menu
|
// Subtitles menu
|
||||||
|
|
|
@ -165,7 +165,7 @@ private:
|
||||||
|
|
||||||
int TryToCloseSubs(bool enableCancel=true);
|
int TryToCloseSubs(bool enableCancel=true);
|
||||||
|
|
||||||
void RebuildRecentList(wxString listName,wxMenu *menu,int startID);
|
void RebuildRecentList(const char *root_command, const char *mru_name);
|
||||||
void SynchronizeProject(bool FromSubs=false);
|
void SynchronizeProject(bool FromSubs=false);
|
||||||
|
|
||||||
// AudioControllerAudioEventListener implementation
|
// AudioControllerAudioEventListener implementation
|
||||||
|
|
Loading…
Reference in a new issue