diff options
| author | Vlad Voicu <vladv@rosedu.org> | 2012-03-06 16:47:28 (GMT) | 
|---|---|---|
| committer | vlad <vlad@tyrion.(none)> | 2012-10-13 13:55:45 (GMT) | 
| commit | 9a4873e153ae16ef68e7c60de376ade7882874f0 (patch) | |
| tree | 9ebeb47da15d9813aa6a99881b9c5b508776a80c | |
| parent | 2267554fcf1a73dc761d3a15b152192d3f420d7f (diff) | |
| download | swift-contrib-9a4873e153ae16ef68e7c60de376ade7882874f0.zip swift-contrib-9a4873e153ae16ef68e7c60de376ade7882874f0.tar.bz2 | |
Fixed some bugs with language selection
| -rw-r--r-- | Swift/QtUI/QtSpellCheckerWindow.cpp | 15 | ||||
| -rw-r--r-- | Swift/QtUI/QtTextEdit.cpp | 19 | 
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();  } | 
 Swift
 Swift