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)
: 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)
, timing_controller_dialogue(CreateDialogueTimingController(controller, context->selectionController, context->ass))
, context(context)

View file

@ -54,7 +54,6 @@
#include "audio_renderer_waveform.h"
#include "audio_timing.h"
#include "block_cache.h"
#include "include/aegisub/audio_player.h"
#include "include/aegisub/audio_provider.h"
#include "include/aegisub/hotkey.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)
, context(context)
, audio_renderer(new AudioRenderer)
, audio_spectrum_renderer(new AudioSpectrumRenderer)
, audio_waveform_renderer(new AudioWaveformRenderer)
@ -1154,7 +1154,7 @@ void AudioDisplay::OnMouseEvent(wxMouseEvent& 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.StopPropagation();
}

View file

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

View file

@ -909,7 +909,7 @@ bool BaseGrid::IsDisplayed(const AssDialogue *line) const {
void BaseGrid::OnKeyDown(wxKeyEvent &event) {
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;
int w,h;
@ -983,7 +983,7 @@ void BaseGrid::OnKeyDown(wxKeyEvent &event) {
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();
}
}

View file

@ -119,7 +119,7 @@ void DialogDetachedVideo::OnMinimize(wxIconizeEvent &event) {
void DialogDetachedVideo::OnKeyDown(wxKeyEvent &evt) {
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() {

View file

@ -256,7 +256,7 @@ void DialogStyling::OnPlayAudioButton(wxCommandEvent &) {
}
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
// actually does something
if (evt.GetKeyCode() == WXK_BACK && !evt.GetModifiers()) {

View file

@ -254,7 +254,7 @@ void DialogTranslation::InsertOriginal() {
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.StopPropagation();
}

View file

@ -1048,6 +1048,6 @@ void FrameMain::OnSubtitlesSave() {
}
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();
}

View file

@ -74,20 +74,8 @@ namespace Automation4 { class FeatureMacro; class ScriptManager; }
class FrameMain: public wxFrame {
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;
private:
// XXX: Make Freeze()/Thaw() noops on GTK, this seems to be buggy
#ifdef __WXGTK__
void Freeze(void) {}
@ -160,5 +148,15 @@ public:
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()
};

View file

@ -20,22 +20,12 @@
#include "config.h"
#ifndef AGI_PRE
#include <math.h>
#include <memory>
#include <vector>
#endif
#include <libaegisub/log.h>
#include <libaegisub/hotkey.h>
#include "include/aegisub/hotkey.h"
#include "include/aegisub/toolbar.h"
#include "libresrc/libresrc.h"
#include "command/command.h"
#include "frame_main.h"
#include "main.h"
namespace hotkey {
@ -57,7 +47,7 @@ static std::string const& keycode_name(int 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;
if ((modifier != wxMOD_NONE)) {
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.
/// This is to avoid pointless exceptions.
if (command.find("/") != std::string::npos) {
(*cmd::get(command))(wxGetApp().frame->context.get());
(*cmd::get(command))(c);
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
#ifndef AGI_PRE
#include <math.h>
#include <memory>
#include <string>
#include <vector>
#endif
namespace agi { struct Context; }
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::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) {
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;
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 {
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;
}
}

View file

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

View file

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