summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI')
-rw-r--r--Swift/QtUI/QtSpellCheckerWindow.cpp15
-rw-r--r--Swift/QtUI/QtTextEdit.cpp19
2 files changed, 22 insertions, 12 deletions
diff --git a/Swift/QtUI/QtSpellCheckerWindow.cpp b/Swift/QtUI/QtSpellCheckerWindow.cpp
index f955668..ff6ef39 100644
--- a/Swift/QtUI/QtSpellCheckerWindow.cpp
+++ b/Swift/QtUI/QtSpellCheckerWindow.cpp
@@ -31,8 +31,8 @@ QtSpellCheckerWindow::QtSpellCheckerWindow(SettingsProvider* settings, QWidget*
void QtSpellCheckerWindow::setFromSettings() {
ui_.spellChecker->setChecked(settings_->getSetting(SettingConstants::SPELL_CHECKER));
- ui_.personalPathContent->insert(P2QSTRING(settings_->getSetting(SettingConstants::PERSONAL_DICT_PATH)));
- ui_.pathContent->insert(P2QSTRING(settings_->getSetting(SettingConstants::DICT_PATH)));
+ ui_.personalPathContent->setText(P2QSTRING(settings_->getSetting(SettingConstants::PERSONAL_DICT_PATH)));
+ ui_.pathContent->setText(P2QSTRING(settings_->getSetting(SettingConstants::DICT_PATH)));
ui_.currentLanguageValue->setText(P2QSTRING(settings_->getSetting(SettingConstants::DICT_FILE)));
std::string currentPath = settings_->getSetting(SettingConstants::DICT_PATH);
QString filename = "*.dic";
@@ -63,7 +63,7 @@ void QtSpellCheckerWindow::handleApply() {
settings_->storeSetting(SettingConstants::SPELL_CHECKER, ui_.spellChecker->isChecked());
QList<QListWidgetItem* > selectedLanguage = ui_.languageView->selectedItems();
if (!selectedLanguage.empty()) {
- settings_->storeSetting(SettingConstants::DICT_FILE, Q2PSTRING(selectedLanguage[0]->text()));
+ settings_->storeSetting(SettingConstants::DICT_FILE, Q2PSTRING((selectedLanguage.first())->text()));
}
emit settingsChanged();
this->done(0);
@@ -76,13 +76,18 @@ void QtSpellCheckerWindow::handleCancel() {
void QtSpellCheckerWindow::handlePathButton() {
std::string currentPath = settings_->getSetting(SettingConstants::DICT_PATH);
QString dirpath = QFileDialog::getExistingDirectory(this, tr("Dictionary Path"), P2QSTRING(currentPath));
+ if (dirpath.compare(P2QSTRING(currentPath))) {
+ ui_.languageView->clear();
+ settings_->storeSetting(SettingConstants::DICT_FILE, "");
+ ui_.currentLanguageValue->setText(" ");
+ }
if (!dirpath.isEmpty()) {
if (!dirpath.endsWith("/")) {
dirpath.append("/");
}
settings_->storeSetting(SettingConstants::DICT_PATH, Q2PSTRING(dirpath));
QDir dictDirectory = QDir(dirpath);
- ui_.pathContent->insert(dirpath);
+ ui_.pathContent->setText(dirpath);
QString filename = "*.dic";
QStringList files = dictDirectory.entryList(QStringList(filename), QDir::Files);
showFiles(files);
@@ -92,9 +97,11 @@ void QtSpellCheckerWindow::handlePathButton() {
void QtSpellCheckerWindow::handlePersonalPathButton() {
std::string currentPath = settings_->getSetting(SettingConstants::PERSONAL_DICT_PATH);
QString filename = QFileDialog::getOpenFileName(this, tr("Select Personal Dictionary"), P2QSTRING(currentPath), tr("(*.dic"));
+ settings_->storeSetting(SettingConstants::PERSONAL_DICT_PATH, Q2PSTRING(filename));
}
void QtSpellCheckerWindow::showFiles(const QStringList& files) {
+ ui_.languageView->clear();
for (int i = 0; i < files.size(); ++i) {
ui_.languageView->insertItem(i, files[i]);
}
diff --git a/Swift/QtUI/QtTextEdit.cpp b/Swift/QtUI/QtTextEdit.cpp
index f115d1c..75bc292 100644
--- a/Swift/QtUI/QtTextEdit.cpp
+++ b/Swift/QtUI/QtTextEdit.cpp
@@ -6,6 +6,7 @@
#include <boost/tuple/tuple.hpp>
#include <boost/algorithm/string.hpp>
+#include <boost/filesystem/operations.hpp>
#include <SwifTools/SpellCheckerFactory.h>
#include <SwifTools/SpellChecker.h>
@@ -24,6 +25,7 @@ namespace Swift {
QtTextEdit::QtTextEdit(SettingsProvider* settings, QWidget* parent) : QTextEdit(parent) {
connect(this, SIGNAL(textChanged()), this, SLOT(handleTextChanged()));
+ checker_ = NULL;
settings_ = settings;
setUpSpellChecker();
handleTextChanged();
@@ -184,19 +186,19 @@ void QtTextEdit::addSuggestions(QMenu* menu, QContextMenuEvent* event)
void QtTextEdit::setUpSpellChecker()
{
SpellCheckerFactory *checkerFactory = new SpellCheckerFactory();
- std::string dictFile = settings_->getSetting(SettingConstants::DICT_FILE);
- if (dictFile.empty()) {
- // Disable the dictionary to force the user to select a dictionary
- settings_->storeSetting(SettingConstants::SPELL_CHECKER, false);
- }
+ delete checker_;
if (settings_->getSetting(SettingConstants::SPELL_CHECKER)) {
std::string dictPath = settings_->getSetting(SettingConstants::DICT_PATH);
+ std::string dictFile = settings_->getSetting(SettingConstants::DICT_FILE);
std::string affixFile(dictFile);
boost::replace_all(affixFile, ".dic", ".aff");
- if (checker_ != NULL) {
- delete checker_;
+ if ((boost::filesystem::exists(dictPath + dictFile)) && (boost::filesystem::exists(dictPath + affixFile))) {
+ checker_ = checkerFactory->createSpellChecker((dictPath + affixFile).c_str(), (dictPath + dictFile).c_str());
+ }
+ else {
+ // If dictionaries don't exist disable the checker
+ checker_ = NULL;
}
- checker_ = checkerFactory->createSpellChecker((dictPath + affixFile).c_str(), (dictPath + dictFile).c_str());
delete checkerFactory;
}
else {
@@ -219,6 +221,7 @@ void QtTextEdit::spellCheckerSettingsWindow() {
void QtTextEdit::handleModifiedSettings() {
delete checker_;
+ checker_ = NULL;
setUpSpellChecker();
underlineMisspells();
}