Add a TextSelectionController interface to avoid exposing the wxSTC edit directly in the context

This commit is contained in:
Thomas Goyne 2012-10-08 07:32:51 -07:00
parent 1c2ec34cb1
commit a948924850
11 changed files with 142 additions and 12 deletions

View file

@ -1831,10 +1831,22 @@
RelativePath="..\..\src\audio_timing.h"
>
</File>
<File
RelativePath="..\..\src\scintilla_text_selection_controller.cpp"
>
</File>
<File
RelativePath="..\..\src\scintilla_text_selection_controller.h"
>
</File>
<File
RelativePath="..\..\src\selection_controller.h"
>
</File>
<File
RelativePath="..\..\src\text_selection_controller.h"
>
</File>
</Filter>
<Filter
Name="Commands"

View file

@ -212,6 +212,7 @@ SRC += \
preferences.cpp \
preferences_base.cpp \
scintilla_text_ctrl.cpp \
scintilla_text_selection_controller.cpp \
spellchecker.cpp \
spline.cpp \
spline_curve.cpp \

View file

@ -51,6 +51,7 @@
#include "include/aegisub/context.h"
#include "main.h"
#include "selection_controller.h"
#include "text_selection_controller.h"
#include "subs_edit_ctrl.h"
#include "subs_grid.h"
#include "video_context.h"
@ -334,8 +335,8 @@ void SearchReplaceEngine::ReplaceNext(bool DoReplace) {
context->subsGrid->SelectRow(curLine,false);
context->subsGrid->MakeCellVisible(curLine,0);
if (field == 0) {
context->subsGrid->SetActiveLine(context->subsGrid->GetDialogue(curLine));
context->editBox->SetSelectionU(pos,pos+replaceLen);
context->selectionController->SetActiveLine(context->subsGrid->GetDialogue(curLine));
context->textSelectionController->SetSelection(pos, pos + replaceLen);
}
// Update video

View file

@ -45,6 +45,7 @@
#include "libresrc/libresrc.h"
#include "main.h"
#include "selection_controller.h"
#include "text_selection_controller.h"
#include "subs_edit_ctrl.h"
#include "utils.h"
@ -208,7 +209,7 @@ bool DialogSpellChecker::FindNext() {
start_line = active_line;
}
int start_pos = context->editBox->GetReverseUnicodePosition(context->editBox->GetCurrentPos());
int start_pos = context->textSelectionController->GetInsertionPoint();
int commit_id = -1;
if (CheckLine(active_line, start_pos, &commit_id))
@ -288,7 +289,7 @@ void DialogSpellChecker::Replace() {
if (active_line->Text.Mid(word_start, word_end - word_start) == orig_word->GetValue()) {
active_line->Text = active_line->Text.Left(word_start) + replace_word->GetValue() + active_line->Text.Mid(word_end);
context->ass->Commit(_("spell check replace"), AssFile::COMMIT_DIAG_TEXT);
context->editBox->SetCurrentPos(context->editBox->GetUnicodePosition(word_start + replace_word->GetValue().size()));
context->textSelectionController->SetInsertionPoint(word_start + replace_word->GetValue().size());
}
}
@ -300,8 +301,8 @@ void DialogSpellChecker::SetWord(wxString const& word) {
suggest_list->Clear();
suggest_list->Append(suggestions);
context->editBox->SetSelectionU(word_start, word_end);
context->editBox->SetCurrentPos(context->editBox->GetUnicodePosition(word_end));
context->textSelectionController->SetSelection(word_start, word_end);
context->textSelectionController->SetInsertionPoint(word_end);
add_button->Enable(spellchecker->CanAddWord(word));
}

View file

@ -389,7 +389,6 @@ void FrameMain::InitContents() {
StartupLog("Create subtitle editing box");
SubsEditBox *EditBox = new SubsEditBox(Panel, context.get());
context->editBox = EditBox->TextEdit;
StartupLog("Arrange main sizers");
ToolsSizer = new wxBoxSizer(wxVERTICAL);
@ -406,8 +405,6 @@ void FrameMain::InitContents() {
StartupLog("Perform layout");
Layout();
StartupLog("Set focus to edting box");
EditBox->TextEdit->SetFocus();
StartupLog("Leaving InitContents");
}

View file

@ -7,6 +7,7 @@ class DialogManager;
template<class T> class SelectionController;
class SubsTextEditCtrl;
class SubtitlesGrid;
class TextSelectionController;
class VideoContext;
class VideoDisplay;
class wxWindow;
@ -22,6 +23,7 @@ struct Context {
// Controllers
AudioController *audioController;
SelectionController<AssDialogue *> *selectionController;
TextSelectionController *textSelectionController;
VideoContext *videoController;
// Things that should probably be in some sort of UI-context-model
@ -33,7 +35,6 @@ struct Context {
AudioBox *audioBox;
AudioKaraoke *karaoke;
DialogManager *dialog;
SubsTextEditCtrl *editBox;
SubtitlesGrid *subsGrid;
VideoDisplay *videoDisplay;
};

View file

@ -0,0 +1,46 @@
// Copyright (c) 2012, Thomas Goyne <plorkyeran@aegisub.org>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// Aegisub Project http://www.aegisub.org/
#include "config.h"
#include "scintilla_text_selection_controller.h"
#include "scintilla_text_ctrl.h"
ScintillaTextSelectionController::ScintillaTextSelectionController(ScintillaTextCtrl *ctrl)
: ctrl(ctrl)
{
}
void ScintillaTextSelectionController::SetInsertionPoint(int position) {
ctrl->SetInsertionPoint(ctrl->GetUnicodePosition(position));
}
int ScintillaTextSelectionController::GetInsertionPoint() const {
return ctrl->GetReverseUnicodePosition(ctrl->GetInsertionPoint());
}
void ScintillaTextSelectionController::SetSelection(int start, int end) {
ctrl->SetSelectionU(start, end);
}
int ScintillaTextSelectionController::GetSelectionStart() const {
return ctrl->GetReverseUnicodePosition(ctrl->GetSelectionStart());
}
int ScintillaTextSelectionController::GetSelectionEnd() const {
return ctrl->GetReverseUnicodePosition(ctrl->GetSelectionEnd());
}

View file

@ -0,0 +1,33 @@
// Copyright (c) 2012, Thomas Goyne <plorkyeran@aegisub.org>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// Aegisub Project http://www.aegisub.org/
#include "text_selection_controller.h"
class ScintillaTextCtrl;
class ScintillaTextSelectionController : public TextSelectionController {
ScintillaTextCtrl *ctrl;
public:
void SetSelection(int start, int end);
void SetInsertionPoint(int point);
int GetSelectionStart() const;
int GetSelectionEnd() const;
int GetInsertionPoint() const;
ScintillaTextSelectionController(ScintillaTextCtrl *ctrl);
};

View file

@ -64,6 +64,7 @@
#include "libresrc/libresrc.h"
#include "main.h"
#include "placeholder_ctrl.h"
#include "scintilla_text_selection_controller.h"
#include "subs_edit_ctrl.h"
#include "subs_grid.h"
#include "timeedit_ctrl.h"
@ -250,6 +251,10 @@ SubsEditBox::SubsEditBox(wxWindow *parent, agi::Context *context)
connections.push_back(context->videoController->AddTimecodesListener(&SubsEditBox::UpdateFrameTiming, this));
connections.push_back(context->selectionController->AddActiveLineListener(&SubsEditBox::OnActiveLineChanged, this));
connections.push_back(context->selectionController->AddSelectionListener(&SubsEditBox::OnSelectedSetChanged, this));
textSelectionController.reset(new ScintillaTextSelectionController(TextEdit));
context->textSelectionController = textSelectionController.get();
TextEdit->SetFocus();
}
SubsEditBox::~SubsEditBox() {

View file

@ -43,6 +43,7 @@
#include <wx/timer.h>
#endif
#include <libaegisub/scoped_ptr.h>
#include <libaegisub/signal.h>
#include "selection_controller.h"
@ -54,6 +55,7 @@ class AssDialogue;
class AssStyle;
class AssTime;
class SubsTextEditCtrl;
class TextSelectionController;
class TimeEdit;
class wxButton;
class wxCheckBox;
@ -216,9 +218,11 @@ class SubsEditBox : public wxPanel {
/// @brief Enable or disable frame timing mode
void UpdateFrameTiming(agi::vfr::Framerate const& fps);
public:
SubsTextEditCtrl *TextEdit;
SubsTextEditCtrl *TextEdit;
agi::scoped_ptr<TextSelectionController> textSelectionController;
public:
/// @brief Constructor
/// @param parent Parent window
SubsEditBox(wxWindow *parent, agi::Context *context);

View file

@ -0,0 +1,29 @@
// Copyright (c) 2012, Thomas Goyne <plorkyeran@aegisub.org>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// Aegisub Project http://www.aegisub.org/
#pragma once
class TextSelectionController {
public:
virtual ~TextSelectionController() { }
virtual void SetSelection(int start, int end) = 0;
virtual void SetInsertionPoint(int point) = 0;
virtual int GetSelectionStart() const = 0;
virtual int GetSelectionEnd() const = 0;
virtual int GetInsertionPoint() const = 0;
};