Make hotkey::check take a project context and make FrameMain::context private

Originally committed to SVN as r5532.
This commit is contained in:
Thomas Goyne 2011-07-29 23:16:55 +00:00
parent ef26170214
commit 561216d4c8
15 changed files with 53 additions and 77 deletions

View File

@ -95,7 +95,7 @@ static void add_option(wxWindow *parent, wxSizer *sizer, int border, const char
/// ///
AudioBox::AudioBox(wxWindow *parent, agi::Context *context) AudioBox::AudioBox(wxWindow *parent, agi::Context *context)
: wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxBORDER_RAISED) : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL|wxBORDER_RAISED)
, audioDisplay(new AudioDisplay(this, context->audioController)) , audioDisplay(new AudioDisplay(this, context->audioController, context))
, controller(context->audioController) , controller(context->audioController)
, timing_controller_dialogue(CreateDialogueTimingController(controller, context->selectionController, context->ass)) , timing_controller_dialogue(CreateDialogueTimingController(controller, context->selectionController, context->ass))
, context(context) , context(context)

View File

@ -54,7 +54,6 @@
#include "audio_renderer_waveform.h" #include "audio_renderer_waveform.h"
#include "audio_timing.h" #include "audio_timing.h"
#include "block_cache.h" #include "block_cache.h"
#include "include/aegisub/audio_player.h"
#include "include/aegisub/audio_provider.h" #include "include/aegisub/audio_provider.h"
#include "include/aegisub/hotkey.h" #include "include/aegisub/hotkey.h"
#include "main.h" #include "main.h"
@ -529,8 +528,9 @@ public:
AudioDisplay::AudioDisplay(wxWindow *parent, AudioController *controller) AudioDisplay::AudioDisplay(wxWindow *parent, AudioController *controller, agi::Context *context)
: wxWindow(parent, -1, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS|wxBORDER_SIMPLE) : wxWindow(parent, -1, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS|wxBORDER_SIMPLE)
, context(context)
, audio_renderer(new AudioRenderer) , audio_renderer(new AudioRenderer)
, audio_spectrum_renderer(new AudioSpectrumRenderer) , audio_spectrum_renderer(new AudioSpectrumRenderer)
, audio_waveform_renderer(new AudioWaveformRenderer) , audio_waveform_renderer(new AudioWaveformRenderer)
@ -1154,7 +1154,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& event)
void AudioDisplay::OnKeyDown(wxKeyEvent& event) void AudioDisplay::OnKeyDown(wxKeyEvent& event)
{ {
if (!hotkey::check("Audio", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) if (!hotkey::check("Audio", context, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
event.Skip(); event.Skip();
event.StopPropagation(); event.StopPropagation();
} }

View File

@ -35,43 +35,31 @@
/// @ingroup audio_ui /// @ingroup audio_ui
/// ///
#pragma once
#ifndef AGI_PRE #ifndef AGI_PRE
#include <list> #include <list>
#include <stdint.h> #include <stdint.h>
#include <wx/bitmap.h> #include <wx/gdicmn.h>
#include <wx/scrolbar.h> #include <wx/string.h>
#include <wx/timer.h>
#include <wx/window.h> #include <wx/window.h>
#endif #endif
#include <libaegisub/scoped_ptr.h> #include <libaegisub/scoped_ptr.h>
#include <libaegisub/signal.h> #include <libaegisub/signal.h>
namespace agi { struct Context; }
class AudioRenderer; class AudioRenderer;
class AudioSpectrumRenderer; class AudioSpectrumRenderer;
class AudioWaveformRenderer; class AudioWaveformRenderer;
class AudioKaraoke; class AudioKaraoke;
class AudioProvider; class AudioProvider;
class AudioPlayer;
class SubtitlesGrid;
class VideoProvider;
class AudioBox;
class SubtitlesGrid;
class AssDialogue;
class wxScrollBar;
// Helper classes used in implementation of the audio display // Helper classes used in implementation of the audio display
class AudioDisplayScrollbar; class AudioDisplayScrollbar;
class AudioDisplayTimeline; class AudioDisplayTimeline;
class AudioDisplaySelection; class AudioDisplaySelection;
/// @class AudioDisplayInteractionObject /// @class AudioDisplayInteractionObject
/// @brief Interface for objects on the audio display that can respond to mouse events /// @brief Interface for objects on the audio display that can respond to mouse events
class AudioDisplayInteractionObject { class AudioDisplayInteractionObject {
@ -113,6 +101,7 @@ public:
class AudioDisplay: public wxWindow { class AudioDisplay: public wxWindow {
private: private:
std::list<agi::signal::Connection> slots; std::list<agi::signal::Connection> slots;
agi::Context *context;
/// The audio renderer manager /// The audio renderer manager
agi::scoped_ptr<AudioRenderer> audio_renderer; agi::scoped_ptr<AudioRenderer> audio_renderer;
@ -209,7 +198,7 @@ private:
public: public:
AudioDisplay(wxWindow *parent, AudioController *controller); AudioDisplay(wxWindow *parent, AudioController *controller, agi::Context *context);
~AudioDisplay(); ~AudioDisplay();

View File

@ -909,7 +909,7 @@ bool BaseGrid::IsDisplayed(const AssDialogue *line) const {
void BaseGrid::OnKeyDown(wxKeyEvent &event) { void BaseGrid::OnKeyDown(wxKeyEvent &event) {
event.StopPropagation(); event.StopPropagation();
if (hotkey::check("Subtitle Grid", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) if (hotkey::check("Subtitle Grid", context, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
return; return;
int w,h; int w,h;
@ -983,7 +983,7 @@ void BaseGrid::OnKeyDown(wxKeyEvent &event) {
return; return;
} }
} }
else if (!hotkey::check("Audio", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) { else if (!hotkey::check("Audio", context, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) {
event.Skip(); event.Skip();
} }
} }

View File

@ -119,7 +119,7 @@ void DialogDetachedVideo::OnMinimize(wxIconizeEvent &event) {
void DialogDetachedVideo::OnKeyDown(wxKeyEvent &evt) { void DialogDetachedVideo::OnKeyDown(wxKeyEvent &evt) {
evt.StopPropagation(); evt.StopPropagation();
hotkey::check("Video Display", evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers()); hotkey::check("Video Display", context, evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers());
} }
void DialogDetachedVideo::OnVideoOpen() { void DialogDetachedVideo::OnVideoOpen() {

View File

@ -256,7 +256,7 @@ void DialogStyling::OnPlayAudioButton(wxCommandEvent &) {
} }
void DialogStyling::OnKeyDown(wxKeyEvent &evt) { void DialogStyling::OnKeyDown(wxKeyEvent &evt) {
if (!hotkey::check("Styling Assistant", evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers())) { if (!hotkey::check("Styling Assistant", c, evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers())) {
// Move the beginning of the selection back one character so that backspace // Move the beginning of the selection back one character so that backspace
// actually does something // actually does something
if (evt.GetKeyCode() == WXK_BACK && !evt.GetModifiers()) { if (evt.GetKeyCode() == WXK_BACK && !evt.GetModifiers()) {

View File

@ -254,7 +254,7 @@ void DialogTranslation::InsertOriginal() {
void DialogTranslation::OnKeyDown(wxKeyEvent &evt) { void DialogTranslation::OnKeyDown(wxKeyEvent &evt) {
if (!hotkey::check("Translation Assistant", evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers())) if (!hotkey::check("Translation Assistant", c, evt.GetKeyCode(), evt.GetUnicodeKey(), evt.GetModifiers()))
evt.Skip(); evt.Skip();
evt.StopPropagation(); evt.StopPropagation();
} }

View File

@ -1048,6 +1048,6 @@ void FrameMain::OnSubtitlesSave() {
} }
void FrameMain::OnKeyDown(wxKeyEvent &event) { void FrameMain::OnKeyDown(wxKeyEvent &event) {
if (!hotkey::check("Main Frame", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) if (!hotkey::check("Main Frame", context.get(), event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
event.Skip(); event.Skip();
} }

View File

@ -74,20 +74,8 @@ namespace Automation4 { class FeatureMacro; class ScriptManager; }
class FrameMain: public wxFrame { class FrameMain: public wxFrame {
friend class AegisubFileDropTarget; friend class AegisubFileDropTarget;
public:
/// Set the status bar text
/// @param text New status bar text
/// @param ms Time in milliseconds that the message should be visible
void StatusTimeout(wxString text,int ms=10000);
/// @brief Set the video and audio display visibility
/// @param video -1: leave unchanged; 0: hide; 1: show
/// @param audio -1: leave unchanged; 0: hide; 1: show
void SetDisplayMode(int showVid, int showAudio);
void LoadSubtitles(wxString filename,wxString charset="");
agi::scoped_ptr<agi::Context> context; agi::scoped_ptr<agi::Context> context;
private:
// XXX: Make Freeze()/Thaw() noops on GTK, this seems to be buggy // XXX: Make Freeze()/Thaw() noops on GTK, this seems to be buggy
#ifdef __WXGTK__ #ifdef __WXGTK__
void Freeze(void) {} void Freeze(void) {}
@ -160,5 +148,15 @@ public:
bool HasASSDraw(); bool HasASSDraw();
/// Set the status bar text
/// @param text New status bar text
/// @param ms Time in milliseconds that the message should be visible
void StatusTimeout(wxString text,int ms=10000);
/// @brief Set the video and audio display visibility
/// @param video -1: leave unchanged; 0: hide; 1: show
/// @param audio -1: leave unchanged; 0: hide; 1: show
void SetDisplayMode(int showVid,int showAudio);
void LoadSubtitles(wxString filename,wxString charset="");
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View File

@ -20,22 +20,12 @@
#include "config.h" #include "config.h"
#ifndef AGI_PRE
#include <math.h>
#include <memory>
#include <vector>
#endif
#include <libaegisub/log.h>
#include <libaegisub/hotkey.h> #include <libaegisub/hotkey.h>
#include "include/aegisub/hotkey.h" #include "include/aegisub/hotkey.h"
#include "include/aegisub/toolbar.h"
#include "libresrc/libresrc.h" #include "libresrc/libresrc.h"
#include "command/command.h" #include "command/command.h"
#include "frame_main.h"
#include "main.h" #include "main.h"
namespace hotkey { namespace hotkey {
@ -57,7 +47,7 @@ static std::string const& keycode_name(int code) {
return keycode_names[code]; return keycode_names[code];
} }
bool check(std::string const& context, int key_code, wchar_t key_char, int modifier) { bool check(std::string const& context, agi::Context *c, int key_code, wchar_t key_char, int modifier) {
std::string combo; std::string combo;
if ((modifier != wxMOD_NONE)) { if ((modifier != wxMOD_NONE)) {
if ((modifier & wxMOD_CMD) != 0) combo.append("Ctrl-"); if ((modifier & wxMOD_CMD) != 0) combo.append("Ctrl-");
@ -73,7 +63,7 @@ bool check(std::string const& context, int key_code, wchar_t key_char, int modif
/// The bottom line should be removed after all the hotkey commands are fixed. /// The bottom line should be removed after all the hotkey commands are fixed.
/// This is to avoid pointless exceptions. /// This is to avoid pointless exceptions.
if (command.find("/") != std::string::npos) { if (command.find("/") != std::string::npos) {
(*cmd::get(command))(wxGetApp().frame->context.get()); (*cmd::get(command))(c);
return true; return true;
} }
} }
@ -187,5 +177,5 @@ static void init_keycode_names() {
} }
} // namespace toolbar } // namespace hotkey

View File

@ -19,16 +19,15 @@
/// @ingroup hotkey menu event window /// @ingroup hotkey menu event window
#ifndef AGI_PRE #ifndef AGI_PRE
#include <math.h>
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#endif #endif
namespace agi { struct Context; }
namespace hotkey { namespace hotkey {
bool check(std::string const& context, int key_code, wchar_t key_char, int modifier); bool check(std::string const& context, agi::Context *c, int key_code, wchar_t key_char, int modifier);
std::string get_hotkey_str_first(std::string const& context, std::string const& command); std::string get_hotkey_str_first(std::string const& context, std::string const& command);
std::vector<std::string> get_hotkey_strs(std::string const& context, std::string const& command); std::vector<std::string> get_hotkey_strs(std::string const& context, std::string const& command);

View File

@ -424,7 +424,7 @@ void SubsEditBox::UpdateFrameTiming(agi::vfr::Framerate const& fps) {
void SubsEditBox::OnKeyDown(wxKeyEvent &event) { void SubsEditBox::OnKeyDown(wxKeyEvent &event) {
event.StopPropagation(); event.StopPropagation();
if (hotkey::check("Subtitle Edit Box", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) if (hotkey::check("Subtitle Edit Box", c, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
return; return;
int key = event.GetKeyCode(); int key = event.GetKeyCode();

View File

@ -464,7 +464,7 @@ void VideoDisplay::OnKeyDown(wxKeyEvent &event) {
else if (kc == 'J') SetMode(Video_Mode_Vector_Clip); else if (kc == 'J') SetMode(Video_Mode_Vector_Clip);
else { else {
event.StopPropagation(); event.StopPropagation();
if (hotkey::check("Video Display", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) if (hotkey::check("Video Display", con, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
return; return;
} }
} }

View File

@ -50,19 +50,18 @@
VideoSlider::VideoSlider (wxWindow* parent, agi::Context *c) VideoSlider::VideoSlider (wxWindow* parent, agi::Context *c)
: wxWindow(parent, -1, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS | wxFULL_REPAINT_ON_RESIZE) : wxWindow(parent, -1, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS | wxFULL_REPAINT_ON_RESIZE)
, vc(c->videoController) , c(c)
, grid(c->subsGrid)
, val(0) , val(0)
, max(1) , max(1)
{ {
SetClientSize(20,25); SetClientSize(20,25);
SetMinSize(wxSize(20, 25)); SetMinSize(wxSize(20, 25));
slots.push_back(OPT_SUB("Video/Slider/Show Keyframes", &wxWindow::Refresh, this, false, (wxRect*)NULL)); slots.push_back(OPT_SUB("Video/Slider/Show Keyframes", &wxWindow::Refresh, this, false, (wxRect*)NULL));
slots.push_back(vc->AddSeekListener(&VideoSlider::SetValue, this)); slots.push_back(c->videoController->AddSeekListener(&VideoSlider::SetValue, this));
slots.push_back(vc->AddVideoOpenListener(&VideoSlider::VideoOpened, this)); slots.push_back(c->videoController->AddVideoOpenListener(&VideoSlider::VideoOpened, this));
slots.push_back(vc->AddKeyframesListener(&VideoSlider::KeyframesChanged, this)); slots.push_back(c->videoController->AddKeyframesListener(&VideoSlider::KeyframesChanged, this));
if (vc->IsLoaded()) { if (c->videoController->IsLoaded()) {
VideoOpened(); VideoOpened();
} }
} }
@ -74,8 +73,8 @@ void VideoSlider::SetValue(int value) {
} }
void VideoSlider::VideoOpened() { void VideoSlider::VideoOpened() {
max = vc->GetLength() - 1; max = c->videoController->GetLength() - 1;
keyframes = vc->GetKeyFrames(); keyframes = c->videoController->GetKeyFrames();
Refresh(false); Refresh(false);
} }
@ -143,13 +142,13 @@ void VideoSlider::OnMouse(wxMouseEvent &event) {
SetValue(go); SetValue(go);
} }
if (vc->IsPlaying()) { if (c->videoController->IsPlaying()) {
vc->Stop(); c->videoController->Stop();
vc->JumpToFrame(val); c->videoController->JumpToFrame(val);
vc->Play(); c->videoController->Play();
} }
else else
vc->JumpToFrame(val); c->videoController->JumpToFrame(val);
SetFocus(); SetFocus();
return; return;
} }
@ -158,20 +157,20 @@ void VideoSlider::OnMouse(wxMouseEvent &event) {
SetFocus(); SetFocus();
} }
else if (!vc->IsPlaying()) else if (!c->videoController->IsPlaying())
event.Skip(); event.Skip();
} }
void VideoSlider::OnKeyDown(wxKeyEvent &event) { void VideoSlider::OnKeyDown(wxKeyEvent &event) {
if (vc->IsPlaying()) return; if (c->videoController->IsPlaying()) return;
if (hotkey::check("Video", event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers())) if (hotkey::check("Video", c, event.GetKeyCode(), event.GetUnicodeKey(), event.GetModifiers()))
return; return;
// Forward up/down to grid // Forward up/down to grid
if (event.GetKeyCode() == WXK_UP || event.GetKeyCode() == WXK_DOWN) { if (event.GetKeyCode() == WXK_UP || event.GetKeyCode() == WXK_DOWN) {
grid->GetEventHandler()->ProcessEvent(event); c->subsGrid->GetEventHandler()->ProcessEvent(event);
grid->SetFocus(); c->subsGrid->SetFocus();
return; return;
} }

View File

@ -42,6 +42,8 @@
#include <libaegisub/signal.h> #include <libaegisub/signal.h>
namespace agi { struct Context; }
class VideoContext; class VideoContext;
class SubtitlesGrid; class SubtitlesGrid;
@ -51,8 +53,7 @@ class SubtitlesGrid;
/// ///
/// DOCME /// DOCME
class VideoSlider: public wxWindow { class VideoSlider: public wxWindow {
VideoContext *vc; ///< Video controller agi::Context *c;
SubtitlesGrid *grid; ///< temp hack; remove this once event forwarding is killed
std::vector<int> keyframes; ///< Currently loaded keyframes std::vector<int> keyframes; ///< Currently loaded keyframes
std::vector<agi::signal::Connection> slots; std::vector<agi::signal::Connection> slots;