Make DialogSpellChecker operate on a context rather than going through FrameMain

Originally committed to SVN as r5203.
This commit is contained in:
Thomas Goyne 2011-01-16 07:16:13 +00:00
parent 1aeded1a29
commit bee57ccad3
3 changed files with 12 additions and 21 deletions

View file

@ -355,9 +355,8 @@ struct subtitle_spellcheck : public Command {
STR_HELP("Open spell checker.") STR_HELP("Open spell checker.")
void operator()(agi::Context *c) { void operator()(agi::Context *c) {
//XXX: This is obscene, requires refactoring the spellchecker.
c->videoContext->Stop(); c->videoContext->Stop();
new DialogSpellChecker(wxGetApp().frame); new DialogSpellChecker(c);
} }
}; };

View file

@ -34,8 +34,6 @@
/// @ingroup unused spelling /// @ingroup unused spelling
/// ///
///////////
// Headers
#include "config.h" #include "config.h"
#ifndef AGI_PRE #ifndef AGI_PRE
@ -46,10 +44,10 @@
#include "ass_file.h" #include "ass_file.h"
#include "compat.h" #include "compat.h"
#include "dialog_spellchecker.h" #include "dialog_spellchecker.h"
#include "frame_main.h"
#include "help_button.h" #include "help_button.h"
#include "libresrc/libresrc.h" #include "libresrc/libresrc.h"
#include "main.h" #include "main.h"
#include "include/aegisub/context.h"
#include "include/aegisub/spellchecker.h" #include "include/aegisub/spellchecker.h"
#include "selection_controller.h" #include "selection_controller.h"
#include "subs_edit_box.h" #include "subs_edit_box.h"
@ -90,8 +88,9 @@ enum {
/// @param parent /// @param parent
/// @return /// @return
/// ///
DialogSpellChecker::DialogSpellChecker(wxFrame *parent) DialogSpellChecker::DialogSpellChecker(agi::Context *context)
: wxDialog(parent, -1, _("Spell Checker"), wxDefaultPosition, wxDefaultSize) : wxDialog(context->parent, -1, _("Spell Checker"), wxDefaultPosition, wxDefaultSize)
, context(context)
{ {
// Set icon // Set icon
SetIcon(BitmapToIcon(GETIMAGE(spellcheck_toolbutton_24))); SetIcon(BitmapToIcon(GETIMAGE(spellcheck_toolbutton_24)));
@ -197,7 +196,7 @@ bool DialogSpellChecker::FindNext(int startLine,int startPos) {
if (startPos != -1) lastPos = 0; if (startPos != -1) lastPos = 0;
// Get grid // Get grid
SubtitlesGrid *grid = ((FrameMain*)GetParent())->SubsGrid; SubtitlesGrid *grid = context->SubsGrid;
int rows = grid->GetRows(); int rows = grid->GetRows();
// Loop through lines // Loop through lines
@ -270,7 +269,7 @@ void DialogSpellChecker::SetWord(wxString word) {
for (size_t i=0;i<sugs.Count();i++) suggestList->Append(sugs[i]); for (size_t i=0;i<sugs.Count();i++) suggestList->Append(sugs[i]);
// Show word on the main program interface // Show word on the main program interface
SubtitlesGrid *grid = ((FrameMain*)GetParent())->SubsGrid; SubtitlesGrid *grid = context->SubsGrid;
int line = lastLine % grid->GetRows(); int line = lastLine % grid->GetRows();
grid->SelectRow(line,false); grid->SelectRow(line,false);
grid->MakeCellVisible(line,0); grid->MakeCellVisible(line,0);
@ -383,7 +382,7 @@ bool DialogSpellChecker::FindOrDie() {
/// ///
void DialogSpellChecker::Replace() { void DialogSpellChecker::Replace() {
// Get dialog // Get dialog
SubtitlesGrid *grid = ((FrameMain*)GetParent())->SubsGrid; SubtitlesGrid *grid = context->SubsGrid;
AssDialogue *diag = grid->GetDialogue(lastLine % grid->GetRows()); AssDialogue *diag = grid->GetDialogue(lastLine % grid->GetRows());
// Replace // Replace
@ -436,7 +435,7 @@ void DialogSpellChecker::OnTakeSuggestion(wxCommandEvent &event) {
/// ///
bool DialogSpellChecker::GetFirstMatch() { bool DialogSpellChecker::GetFirstMatch() {
// Get selection // Get selection
SubtitlesGrid *grid = ((FrameMain*)GetParent())->SubsGrid; SubtitlesGrid *grid = context->SubsGrid;
wxArrayInt sel = grid->GetSelection(); wxArrayInt sel = grid->GetSelection();
firstLine = (sel.Count()>0) ? sel[0] : 0; firstLine = (sel.Count()>0) ? sel[0] : 0;
bool hasTypos = FindNext(firstLine,0); bool hasTypos = FindNext(firstLine,0);

View file

@ -34,9 +34,6 @@
/// @ingroup unused spelling /// @ingroup unused spelling
/// ///
///////////
// Headers
#ifndef AGI_PRE #ifndef AGI_PRE
#include <map> #include <map>
@ -46,20 +43,16 @@
#include <wx/textctrl.h> #include <wx/textctrl.h>
#endif #endif
namespace agi { struct Context; }
//////////////
// Prototypes
class SpellChecker; class SpellChecker;
/// DOCME /// DOCME
/// @class DialogSpellChecker /// @class DialogSpellChecker
/// @brief DOCME /// @brief DOCME
/// ///
/// DOCME /// DOCME
class DialogSpellChecker : public wxDialog { class DialogSpellChecker : public wxDialog {
private: agi::Context *context;
/// DOCME /// DOCME
SpellChecker *spellchecker; SpellChecker *spellchecker;
@ -121,7 +114,7 @@ private:
void OnAdd(wxCommandEvent &event); void OnAdd(wxCommandEvent &event);
public: public:
DialogSpellChecker(wxFrame *parent); DialogSpellChecker(agi::Context *context);
~DialogSpellChecker(); ~DialogSpellChecker();
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()