2011-09-15 07:16:41 +02:00
|
|
|
// Copyright (c) 2011, Thomas Goyne <plorkyeran@aegisub.org>
|
2007-04-14 03:02:21 +02:00
|
|
|
//
|
2011-09-15 07:16:41 +02:00
|
|
|
// 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.
|
2007-04-14 03:02:21 +02:00
|
|
|
//
|
2011-09-15 07:16:41 +02:00
|
|
|
// 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.
|
2007-04-14 03:02:21 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2007-04-14 03:02:21 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file dialog_spellchecker.cpp
|
2011-09-15 07:16:41 +02:00
|
|
|
/// @brief Spell checker dialogue box
|
|
|
|
/// @ingroup spelling
|
2009-07-29 07:43:02 +02:00
|
|
|
///
|
2007-04-14 03:02:21 +02:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
2011-09-15 07:16:41 +02:00
|
|
|
#include <wx/combobox.h>
|
2007-04-14 18:08:50 +02:00
|
|
|
#include <wx/intl.h>
|
2011-09-15 07:16:41 +02:00
|
|
|
#include <wx/listbox.h>
|
2011-09-15 08:03:13 +02:00
|
|
|
#include <wx/msgdlg.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/stattext.h>
|
2011-09-15 07:16:41 +02:00
|
|
|
#include <wx/textctrl.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#endif
|
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
#include "dialog_spellchecker.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_dialogue.h"
|
|
|
|
#include "ass_file.h"
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "compat.h"
|
2008-01-13 22:54:31 +01:00
|
|
|
#include "help_button.h"
|
2011-01-16 08:16:13 +01:00
|
|
|
#include "include/aegisub/context.h"
|
2010-08-02 08:31:38 +02:00
|
|
|
#include "include/aegisub/spellchecker.h"
|
2011-09-15 07:17:07 +02:00
|
|
|
#include "libresrc/libresrc.h"
|
|
|
|
#include "main.h"
|
|
|
|
#include "selection_controller.h"
|
2010-07-20 05:11:11 +02:00
|
|
|
#include "subs_edit_ctrl.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "utils.h"
|
2007-04-14 03:02:21 +02:00
|
|
|
|
2011-01-16 08:16:13 +01:00
|
|
|
DialogSpellChecker::DialogSpellChecker(agi::Context *context)
|
2011-09-15 07:16:41 +02:00
|
|
|
: wxDialog(context->parent, -1, _("Spell Checker"))
|
2011-01-16 08:16:13 +01:00
|
|
|
, context(context)
|
2011-09-15 07:16:41 +02:00
|
|
|
, spellchecker(SpellCheckerFactory::GetSpellChecker())
|
2007-04-14 03:02:21 +02:00
|
|
|
{
|
2009-07-25 06:49:59 +02:00
|
|
|
SetIcon(BitmapToIcon(GETIMAGE(spellcheck_toolbutton_24)));
|
2007-07-05 01:09:40 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
wxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
|
2007-04-14 18:08:50 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
wxFlexGridSizer *current_word_sizer = new wxFlexGridSizer(2, 5, 5);
|
|
|
|
main_sizer->Add(current_word_sizer, wxSizerFlags().Expand().Border(wxALL, 5));
|
2007-04-14 18:08:50 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
wxSizer *bottom_sizer = new wxBoxSizer(wxHORIZONTAL);
|
|
|
|
main_sizer->Add(bottom_sizer, wxSizerFlags().Expand().Border(~wxTOP & wxALL, 5));
|
2007-04-14 03:02:21 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
wxSizer *bottom_left_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
bottom_sizer->Add(bottom_left_sizer, wxSizerFlags().Expand().Border(wxRIGHT, 5));
|
2007-04-14 17:26:46 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
wxSizer *actions_sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
bottom_sizer->Add(actions_sizer, wxSizerFlags().Expand());
|
2007-04-14 17:26:46 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
// Misspelled word and currently selected correction
|
|
|
|
current_word_sizer->AddGrowableCol(1, 1);
|
|
|
|
current_word_sizer->Add(new wxStaticText(this, -1, _("Misspelled word:")), 0, wxALIGN_CENTER_VERTICAL);
|
|
|
|
current_word_sizer->Add(orig_word = new wxTextCtrl(this, -1, _("original"), wxDefaultPosition, wxDefaultSize, wxTE_READONLY), wxSizerFlags(1).Expand());
|
|
|
|
current_word_sizer->Add(new wxStaticText(this, -1, _("Replace with:")), 0, wxALIGN_CENTER_VERTICAL);
|
|
|
|
current_word_sizer->Add(replace_word = new wxTextCtrl(this, -1, _("replace with")), wxSizerFlags(1).Expand());
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
// List of suggested corrections
|
|
|
|
suggest_list = new wxListBox(this, -1, wxDefaultPosition, wxSize(300, 150));
|
|
|
|
suggest_list->Bind(wxEVT_COMMAND_LISTBOX_SELECTED, &DialogSpellChecker::OnChangeSuggestion, this);
|
|
|
|
suggest_list->Bind(wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, &DialogSpellChecker::OnReplace, this);
|
|
|
|
bottom_left_sizer->Add(suggest_list, wxSizerFlags(1).Expand());
|
2007-04-14 03:02:21 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
// List of supported spellchecker languages
|
|
|
|
{
|
|
|
|
if (!spellchecker.get()) {
|
|
|
|
wxMessageBox("No spellchecker available.", "Error", wxICON_ERROR);
|
|
|
|
Destroy();
|
|
|
|
return;
|
|
|
|
}
|
2007-04-14 03:02:21 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
dictionary_lang_codes = spellchecker->GetLanguageList();
|
|
|
|
if (dictionary_lang_codes.empty()) {
|
|
|
|
wxMessageBox("No spellchecker dictionaries available.", "Error", wxICON_ERROR);
|
|
|
|
Destroy();
|
|
|
|
return;
|
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
wxArrayString language_names(dictionary_lang_codes);
|
|
|
|
for (size_t i = 0; i < dictionary_lang_codes.size(); ++i) {
|
|
|
|
if (const wxLanguageInfo *info = wxLocale::FindLanguageInfo(dictionary_lang_codes[i]))
|
|
|
|
language_names[i] = info->Description;
|
2007-04-14 17:26:46 +02:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
language = new wxComboBox(this, -1, "", wxDefaultPosition, wxDefaultSize, language_names, wxCB_DROPDOWN | wxCB_READONLY);
|
|
|
|
wxString cur_lang = lagi_wxString(OPT_GET("Tool/Spell Checker/Language")->GetString());
|
|
|
|
int cur_lang_index = dictionary_lang_codes.Index(cur_lang);
|
|
|
|
if (cur_lang_index == wxNOT_FOUND) cur_lang_index = dictionary_lang_codes.Index("en");
|
|
|
|
if (cur_lang_index == wxNOT_FOUND) cur_lang_index = dictionary_lang_codes.Index("en_US");
|
|
|
|
if (cur_lang_index == wxNOT_FOUND) cur_lang_index = 0;
|
|
|
|
language->SetSelection(cur_lang_index);
|
|
|
|
language->Bind(wxEVT_COMMAND_COMBOBOX_SELECTED, &DialogSpellChecker::OnChangeLanguage, this);
|
|
|
|
|
|
|
|
bottom_left_sizer->Add(language, wxSizerFlags().Expand().Border(wxTOP, 5));
|
2007-04-14 17:26:46 +02:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
{
|
|
|
|
wxButton *button;
|
|
|
|
wxSizerFlags button_flags = wxSizerFlags().Expand().Bottom().Border(wxBOTTOM, 5);
|
2007-04-14 17:26:46 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
actions_sizer->Add(button = new wxButton(this, -1, _("Replace")), button_flags);
|
|
|
|
button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogSpellChecker::OnReplace, this);
|
2007-04-14 17:26:46 +02:00
|
|
|
|
2011-11-17 03:21:46 +01:00
|
|
|
actions_sizer->Add(button = new wxButton(this, -1, _("Replace all")), button_flags);
|
2011-09-15 07:16:41 +02:00
|
|
|
button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogSpellChecker::OnReplaceAll, this);
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
actions_sizer->Add(button = new wxButton(this, -1, _("Ignore")), button_flags);
|
|
|
|
button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogSpellChecker::OnIgnore, this);
|
2007-04-14 03:02:21 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
actions_sizer->Add(button = new wxButton(this, -1, _("Ignore all")), button_flags);
|
|
|
|
button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogSpellChecker::OnIgnoreAll, this);
|
2007-04-14 03:02:21 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
actions_sizer->Add(add_button = new wxButton(this, -1, _("Add to dictionary")), button_flags);
|
|
|
|
button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogSpellChecker::OnAdd, this);
|
2007-04-14 18:08:50 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
actions_sizer->Add(new HelpButton(this, "Spell Checker"), button_flags);
|
2007-04-14 03:02:21 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
actions_sizer->Add(new wxButton(this, wxID_CANCEL), button_flags.Border(0));
|
|
|
|
}
|
2007-04-14 03:02:21 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
SetSizerAndFit(main_sizer);
|
|
|
|
CenterOnParent();
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
if (FindNext())
|
|
|
|
Show();
|
2007-04-14 03:02:21 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &DialogSpellChecker::OnClose, this, wxID_CANCEL);
|
|
|
|
}
|
2007-04-14 03:02:21 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
DialogSpellChecker::~DialogSpellChecker() {
|
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
void DialogSpellChecker::OnReplace(wxCommandEvent&) {
|
2007-04-14 17:26:46 +02:00
|
|
|
Replace();
|
2011-09-15 07:16:41 +02:00
|
|
|
FindNext();
|
2007-04-14 03:02:21 +02:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
void DialogSpellChecker::OnReplaceAll(wxCommandEvent&) {
|
|
|
|
auto_replace[orig_word->GetValue()] = replace_word->GetValue();
|
2007-04-14 03:02:21 +02:00
|
|
|
|
2007-04-14 17:26:46 +02:00
|
|
|
Replace();
|
2011-09-15 07:16:41 +02:00
|
|
|
FindNext();
|
2007-04-14 03:02:21 +02:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
void DialogSpellChecker::OnIgnore(wxCommandEvent&) {
|
|
|
|
FindNext();
|
2007-04-14 03:02:21 +02:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
void DialogSpellChecker::OnIgnoreAll(wxCommandEvent&) {
|
|
|
|
auto_ignore.insert(orig_word->GetValue());
|
|
|
|
FindNext();
|
2007-04-14 03:02:21 +02:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
void DialogSpellChecker::OnAdd(wxCommandEvent&) {
|
|
|
|
spellchecker->AddWord(orig_word->GetValue());
|
|
|
|
FindNext();
|
2007-04-14 17:26:46 +02:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
void DialogSpellChecker::OnChangeLanguage(wxCommandEvent&) {
|
|
|
|
wxString code = dictionary_lang_codes[language->GetSelection()];
|
|
|
|
spellchecker->SetLanguage(code);
|
|
|
|
OPT_SET("Tool/Spell Checker/Language")->SetString(STD_STR(code));
|
2007-04-14 17:26:46 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
FindNext();
|
2007-04-14 17:26:46 +02:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
void DialogSpellChecker::OnChangeSuggestion(wxCommandEvent&) {
|
|
|
|
replace_word->SetValue(suggest_list->GetStringSelection());
|
|
|
|
}
|
2007-04-14 17:26:46 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
void DialogSpellChecker::OnClose(wxCommandEvent&) {
|
|
|
|
Destroy();
|
2007-04-14 03:02:21 +02:00
|
|
|
}
|
2007-04-14 18:08:50 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
bool DialogSpellChecker::FindNext() {
|
|
|
|
AssDialogue *active_line = context->selectionController->GetActiveLine();
|
2011-09-15 07:17:07 +02:00
|
|
|
int start_pos = context->editBox->GetReverseUnicodePosition(context->editBox->GetCurrentPos());
|
2011-09-15 07:16:41 +02:00
|
|
|
int commit_id = -1;
|
|
|
|
|
|
|
|
if (CheckLine(active_line, start_pos, &commit_id))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
AssDialogue *start_line = active_line;
|
|
|
|
std::list<AssEntry*>::iterator it = find(context->ass->Line.begin(), context->ass->Line.end(), active_line);
|
|
|
|
bool has_looped = false;
|
|
|
|
|
|
|
|
// Note that it is deliberate that the start line is checked twice, as if
|
|
|
|
// the cursor is past the first misspelled word in the current line, that
|
|
|
|
// word should be hit last
|
|
|
|
while(!has_looped || active_line != start_line) {
|
|
|
|
do {
|
|
|
|
// Wrap around to the beginning if we hit the end
|
|
|
|
if (++it == context->ass->Line.end()) {
|
|
|
|
it = context->ass->Line.begin();
|
|
|
|
has_looped = true;
|
|
|
|
}
|
|
|
|
} while (!(active_line = dynamic_cast<AssDialogue*>(*it)));
|
2007-04-14 18:08:50 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
if (CheckLine(active_line, 0, &commit_id))
|
|
|
|
return true;
|
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
if (IsShown()) {
|
|
|
|
wxMessageBox(_("Aegisub has finished checking spelling of this script."), _("Spell checking complete."));
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
wxMessageBox(_("Aegisub has found no spelling mistakes in this script."), _("Spell checking complete."));
|
|
|
|
Destroy();
|
|
|
|
}
|
2007-04-14 18:08:50 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
return false;
|
2007-04-14 18:08:50 +02:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
bool DialogSpellChecker::CheckLine(AssDialogue *active_line, int start_pos, int *commit_id) {
|
|
|
|
IntPairVector results;
|
|
|
|
GetWordBoundaries(active_line->Text, results);
|
|
|
|
|
|
|
|
int shift = 0;
|
|
|
|
for (size_t j = 0; j < results.size(); ++j) {
|
|
|
|
word_start = results[j].first + shift;
|
|
|
|
if (word_start < start_pos) continue;
|
|
|
|
word_end = results[j].second + shift;
|
|
|
|
wxString word = active_line->Text.Mid(word_start, word_end - word_start);
|
|
|
|
|
|
|
|
if (auto_ignore.count(word) || spellchecker->CheckWord(word)) continue;
|
|
|
|
|
|
|
|
std::map<wxString, wxString>::const_iterator auto_rep = auto_replace.find(word);
|
|
|
|
if (auto_rep == auto_replace.end()) {
|
|
|
|
context->selectionController->SetActiveLine(active_line);
|
|
|
|
SelectionController<AssDialogue>::Selection sel;
|
|
|
|
sel.insert(active_line);
|
|
|
|
context->selectionController->SetSelectedSet(sel);
|
|
|
|
SetWord(word);
|
|
|
|
return true;
|
|
|
|
}
|
2007-04-14 18:08:50 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
active_line->Text = active_line->Text.Left(word_start) + auto_rep->second + active_line->Text.Mid(word_end);
|
|
|
|
*commit_id = context->ass->Commit(_("spell check replace"), AssFile::COMMIT_DIAG_TEXT, *commit_id);
|
|
|
|
shift += auto_rep->second.size() - auto_rep->first.size();
|
|
|
|
}
|
|
|
|
return false;
|
2007-04-14 18:08:50 +02:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
void DialogSpellChecker::Replace() {
|
|
|
|
AssDialogue *active_line = context->selectionController->GetActiveLine();
|
2007-04-14 18:08:50 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
// Only replace if the user hasn't changed the selection to something else
|
|
|
|
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);
|
2011-09-15 07:17:07 +02:00
|
|
|
context->editBox->SetCurrentPos(context->editBox->GetUnicodePosition(word_start + replace_word->GetValue().size()));
|
2011-09-15 07:16:41 +02:00
|
|
|
}
|
2007-04-14 18:08:50 +02:00
|
|
|
}
|
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
void DialogSpellChecker::SetWord(wxString const& word) {
|
|
|
|
orig_word->SetValue(word);
|
2007-04-14 18:08:50 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
wxArrayString suggestions = spellchecker->GetSuggestions(word);
|
|
|
|
replace_word->SetValue(suggestions.size() ? suggestions[0] : word);
|
|
|
|
suggest_list->Clear();
|
|
|
|
suggest_list->Append(suggestions);
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-09-15 07:17:07 +02:00
|
|
|
context->editBox->SetSelectionU(word_start, word_end);
|
|
|
|
context->editBox->SetCurrentPos(context->editBox->GetUnicodePosition(word_end));
|
2007-04-14 18:08:50 +02:00
|
|
|
|
2011-09-15 07:16:41 +02:00
|
|
|
add_button->Enable(spellchecker->CanAddWord(word));
|
2007-04-14 18:08:50 +02:00
|
|
|
}
|
2011-09-28 21:43:11 +02:00
|
|
|
|