From d8e6d9475430c42f90de903f39509bd31eb57cfb Mon Sep 17 00:00:00 2001 From: harukalover Date: Thu, 14 May 2009 07:02:01 +0000 Subject: [PATCH] Made the styling assistant modeless so the user can access other controls within aegisub without having to close the styling assistant, fixes #397 Originally committed to SVN as r2921. --- aegisub/src/dialog_styling_assistant.cpp | 44 ++++++++++++++++++++---- aegisub/src/dialog_styling_assistant.h | 3 ++ aegisub/src/frame_main.cpp | 3 ++ aegisub/src/frame_main.h | 2 ++ aegisub/src/frame_main_events.cpp | 4 +-- 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/aegisub/src/dialog_styling_assistant.cpp b/aegisub/src/dialog_styling_assistant.cpp index acbc363f5..715754e20 100644 --- a/aegisub/src/dialog_styling_assistant.cpp +++ b/aegisub/src/dialog_styling_assistant.cpp @@ -59,7 +59,7 @@ /////////////// // Constructor DialogStyling::DialogStyling (wxWindow *parent,SubtitlesGrid *_grid) : -wxDialog (parent, -1, _("Styling assistant"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxRESIZE_BORDER) +wxDialog (parent, -1, _("Styling assistant"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMINIMIZE_BOX) { // Set icon SetIcon(BitmapToIcon(wxBITMAP(styling_toolbutton))); @@ -115,10 +115,8 @@ wxDialog (parent, -1, _("Styling assistant"), wxDefaultPosition, wxDefaultSize, RightMiddle->AddStretchSpacer(1); // Rest of right sizer - wxButton *PlayVideoButton = new wxButton(this,BUTTON_PLAY_VIDEO,_("Play Video")); - wxButton *PlayAudioButton = new wxButton(this,BUTTON_PLAY_AUDIO,_("Play Audio")); - PlayVideoButton->Enable(video->IsLoaded()); - PlayAudioButton->Enable(audio->loaded); + PlayVideoButton = new wxButton(this,BUTTON_PLAY_VIDEO,_("Play Video")); + PlayAudioButton = new wxButton(this,BUTTON_PLAY_AUDIO,_("Play Audio")); RightBottom->AddStretchSpacer(1); RightBottom->Add(PlayAudioButton,0,wxLEFT | wxRIGHT | wxBOTTOM,5); RightBottom->Add(PlayVideoButton,0,wxBOTTOM | wxRIGHT,5); @@ -179,7 +177,6 @@ DialogStyling::~DialogStyling () { // Jump to line void DialogStyling::JumpToLine(int n) { // Check stuff - if (linen == n) return; if (n == -1) return; // Get line @@ -195,7 +192,14 @@ void DialogStyling::JumpToLine(int n) { // Set focus TypeBox->SetFocus(); - if (TypeBox->GetValue().IsEmpty()) TypeBox->SetValue(Styles->GetString(0)); + bool matched = false; + for (size_t i = 0; i < Styles->GetCount(); i++) { + if (TypeBox->GetValue().IsSameAs(Styles->GetString(i),true)) { + matched = true; + break; + } + } + if (!matched || TypeBox->GetValue().IsEmpty()) TypeBox->SetValue(Styles->GetString(0)); TypeBox->SetSelection(0,TypeBox->GetValue().Length()); // Update grid @@ -234,6 +238,7 @@ void DialogStyling::SetStyle (wxString curName, bool jump) { /////////////// // Event table BEGIN_EVENT_TABLE(DialogStyling,wxDialog) + EVT_ACTIVATE(DialogStyling::OnActivate) EVT_BUTTON(BUTTON_PLAY_VIDEO, DialogStyling::OnPlayVideoButton) EVT_BUTTON(BUTTON_PLAY_AUDIO, DialogStyling::OnPlayAudioButton) //EVT_TEXT_ENTER(ENTER_STYLE_BOX, DialogStyling::OnStyleBoxEnter) @@ -243,6 +248,31 @@ BEGIN_EVENT_TABLE(DialogStyling,wxDialog) END_EVENT_TABLE() +/////////////////////////// +// Dialog was De/Activated +void DialogStyling::OnActivate(wxActivateEvent &event) { + // Dialog lost focus + if (!event.GetActive()) { + if (!PreviewCheck->IsChecked()) { + grid->ass->FlagAsModified(_("styling assistant")); + grid->CommitChanges(); + } + return; + } + // Enable/disable play video/audio buttons + PlayVideoButton->Enable(video->IsLoaded()); + PlayAudioButton->Enable(audio->loaded); + // Update grid + if (grid->ass != AssFile::top) + grid->LoadFromAss(AssFile::top,false,true); + // Fix style list + Styles->Set(grid->ass->GetStyles()); + // Fix line selection + linen = grid->GetFirstSelRow(); + JumpToLine(linen); +} + + /////////////// // Key pressed void DialogStyling::OnKeyDown(wxKeyEvent &event) { diff --git a/aegisub/src/dialog_styling_assistant.h b/aegisub/src/dialog_styling_assistant.h index 1c974dd36..a486d888c 100644 --- a/aegisub/src/dialog_styling_assistant.h +++ b/aegisub/src/dialog_styling_assistant.h @@ -86,6 +86,8 @@ private: wxListBox *Styles; StyleEditBox *TypeBox; wxCheckBox *PreviewCheck; + wxButton *PlayVideoButton; + wxButton *PlayAudioButton; void OnStyleBoxModified (wxCommandEvent &event); void OnStyleBoxEnter (wxCommandEvent &event); @@ -93,6 +95,7 @@ private: void OnKeyDown(wxKeyEvent &event); void OnPlayVideoButton(wxCommandEvent &event); void OnPlayAudioButton(wxCommandEvent &event); + void OnActivate(wxActivateEvent &event); void SetStyle (wxString curName,bool jump=true); diff --git a/aegisub/src/frame_main.cpp b/aegisub/src/frame_main.cpp index deffc5738..ff4f6817a 100644 --- a/aegisub/src/frame_main.cpp +++ b/aegisub/src/frame_main.cpp @@ -76,6 +76,7 @@ #include "standard_paths.h" #include "keyframe.h" #include "help_button.h" +#include "dialog_styling_assistant.h" #ifdef WITH_AUTOMATION #include "auto4_base.h" #endif @@ -133,6 +134,7 @@ FrameMain::FrameMain (wxArrayString args) showVideo = true; showAudio = true; detachedVideo = NULL; + stylingAssistant = NULL; InitContents(); Show(); @@ -578,6 +580,7 @@ void FrameMain::InitContents() { // Deinitialize controls void FrameMain::DeInitContents() { if (detachedVideo) detachedVideo->Destroy(); + if (stylingAssistant) stylingAssistant->Destroy(); AssFile::StackReset(); delete AssFile::top; delete EditBox; diff --git a/aegisub/src/frame_main.h b/aegisub/src/frame_main.h index 04101742e..4be911566 100644 --- a/aegisub/src/frame_main.h +++ b/aegisub/src/frame_main.h @@ -62,6 +62,7 @@ class SubsEditBox; class AudioBox; class VideoBox; class DialogDetachedVideo; +class DialogStyling; class AegisubFileDropTarget; namespace Automation4 { class FeatureMacro; class ScriptManager; }; @@ -268,6 +269,7 @@ public: AudioBox *audioBox; VideoBox *videoBox; DialogDetachedVideo *detachedVideo; + DialogStyling *stylingAssistant; wxBoxSizer *MainSizer; wxBoxSizer *TopSizer; diff --git a/aegisub/src/frame_main_events.cpp b/aegisub/src/frame_main_events.cpp index da065072c..838212035 100644 --- a/aegisub/src/frame_main_events.cpp +++ b/aegisub/src/frame_main_events.cpp @@ -1491,8 +1491,8 @@ void FrameMain::OnSort (wxCommandEvent &event) { // Open styling assistant void FrameMain::OnOpenStylingAssistant (wxCommandEvent &event) { VideoContext::Get()->Stop(); - DialogStyling styling(this,SubsBox); - styling.ShowModal(); + if (!stylingAssistant) stylingAssistant = new DialogStyling(this,SubsBox); + stylingAssistant->Show(true); }