Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be less restrictive when saving users selection. #41

Merged
merged 1 commit into from
Jun 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@
}
}
],
"version": 3
"version": 4
}
2 changes: 1 addition & 1 deletion src/engine/ibus/ibus_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void ibus_commit() {
std::string candidate = suggestions.candidates[candidateSel];
IBusText *txt = ibus_text_new_from_string((gchar*)candidate.c_str());
ibus_engine_commit_text(engine,txt);
gLayout->candidateCommited(candidate);
gLayout->candidateCommited(candidateSel);
}
ibus_reset();
candidateSel = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/engine/libengine/Layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ bool Layout::handledKeyPress() {
return mth->handledKeyPress();
}

void Layout::candidateCommited(std::string commited) {
mth->candidateCommited(commited);
void Layout::candidateCommited(int index) {
mth->candidateCommited(index);
}

bool Layout::isCandidateWinHorizontal() {
Expand Down
12 changes: 6 additions & 6 deletions src/engine/libengine/Layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ class LayoutMth {
virtual Suggestion getCandidates() = 0;
/* Is the last key was processed? */
virtual bool handledKeyPress() = 0;
/* Confirms that one of the sended candidates has been commited
* @commited the string that was commited */
virtual void candidateCommited(std::string commited) = 0;
/* Confirms that one of the send candidates has been commited
* @index index of the candidate string that was commited */
virtual void candidateCommited(int index) = 0;
/* Update internal suggestion making mechanism */
virtual void updateEngine() = 0;
};
Expand Down Expand Up @@ -123,9 +123,9 @@ class Layout {
IMCommand handleSpecialKey(int key);
/* Is the last key was processed? */
bool handledKeyPress();
/* Confirms that one of the sended candidates has been commited
* @lcommited the string that was commited */
void candidateCommited(std::string commited);
/* Confirms that one of the send candidates has been commited
* @index index of the candidate string that was commited */
void candidateCommited(int index);
/* Checks is the candidate window horizontal */
bool isCandidateWinHorizontal();
/* Update internal suggestion making mechanism */
Expand Down
2 changes: 1 addition & 1 deletion src/engine/libengine/MethodFixedLayoutModern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ bool MethodFixedLayoutModern::handledKeyPress() {
return handledKey;
}

void MethodFixedLayoutModern::candidateCommited(std::string commited) {
void MethodFixedLayoutModern::candidateCommited(int index) {
// Clear cache & stored suggestion
BengaliT = "";
suggest = {};
Expand Down
2 changes: 1 addition & 1 deletion src/engine/libengine/MethodFixedLayoutModern.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MethodFixedLayoutModern : public LayoutMth {
IMCommand handleSpecialKey(int key);
Suggestion getCandidates();
bool handledKeyPress();
void candidateCommited(std::string commited);
void candidateCommited(int index);

void updateEngine() {
// Nothing to do :)
Expand Down
15 changes: 5 additions & 10 deletions src/engine/libengine/MethodPhonetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

//#include "im.h"
#include "log.h"
#include "keycode.h"
#include "MethodPhonetic.h"
#include "Settings.h"
Expand All @@ -39,12 +37,9 @@ Suggestion MethodPhonetic::createSuggestion() {
if(EnglishT == "") {
// If there is no text available, don't do anything
return {};
} else {/*
if(changedCandidateSelection) {
// User selected other candidate, save current selection
suggest.saveSelection(QString::fromStdString(im_get_selection(im_get_selection_id())));
changedCandidateSelection = false;
}*/
} else {
// Reset
changedCandidateSelection = false;

// Build the suggestions
list = suggest.Suggest(EnglishT).toVector();
Expand Down Expand Up @@ -690,10 +685,10 @@ bool MethodPhonetic::handledKeyPress() {
return handledKey;
}

void MethodPhonetic::candidateCommited(std::string commited) {
void MethodPhonetic::candidateCommited(int index) {
if(changedCandidateSelection) {
// User selected other candidates
suggest.saveSelection(QString::fromStdString(commited));
suggest.saveSelection(index);
changedCandidateSelection = false;
}
// Clear cache & stored suggestions
Expand Down
2 changes: 1 addition & 1 deletion src/engine/libengine/MethodPhonetic.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class MethodPhonetic : public LayoutMth {
IMCommand handleSpecialKey(int key);
Suggestion getCandidates();
bool handledKeyPress();
void candidateCommited(std::string commited);
void candidateCommited(int index);
void updateEngine();
};

Expand Down
19 changes: 8 additions & 11 deletions src/engine/libengine/PhoneticSuggestion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ void PhoneticSuggestion::appendIfNotContains(QStringList &array, QString item) {

void PhoneticSuggestion::addToTempCache(QString full, QString base, QString eng) {
if (!tempCache.contains(full)) {
tempCache[full].base = base;
tempCache[full].eng = eng;
tempCache[full] = {base, eng};
}
}

Expand Down Expand Up @@ -240,6 +239,8 @@ QStringList PhoneticSuggestion::joinSuggestion(QString writtenWord, QString auto

appendIfNotContains(words, phonetic);

prevSuggestion << words;

for (auto& word : words) {
// smiley rule
if (autoCorrect == writtenWord) {
Expand All @@ -254,24 +255,20 @@ QStringList PhoneticSuggestion::joinSuggestion(QString writtenWord, QString auto
return words;
}

void PhoneticSuggestion::saveSelection(QString selected) {
if (tempCache.contains(selected)) {
QString base = tempCache[selected].base;
QString eng = tempCache[selected].eng;
if(cacheMan.getCandidateSelection(eng) == "") {
cacheMan.writeCandidateSelection(eng, base);
}
}
void PhoneticSuggestion::saveSelection(int index) {
cacheMan.writeCandidateSelection(PadMap["middle"], prevSuggestion[index]);
}

QStringList PhoneticSuggestion::Suggest(QString word) {
QStringList suggestion;
QMap<QString, QString> splitWord = separatePadding(word);
PadMap = splitWord;
prevSuggestion.clear();

splitWord["begin"] = parser.parse(splitWord["begin"]);
splitWord["end"] = parser.parse(splitWord["end"]);

PadMap = splitWord;

QString phonetic = parser.parse(splitWord["middle"]);

if(!gSettings->getShowCWPhonetic()) {
Expand Down
3 changes: 2 additions & 1 deletion src/engine/libengine/PhoneticSuggestion.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class PhoneticSuggestion {
QMap<QString, QString> PadMap;
QMap<QString, QStringList> phoneticCache;
QMap<QString, Cache> tempCache;
QStringList prevSuggestion;

QMap<QString, QString> separatePadding(QString word);
bool isKar(QString word);
Expand All @@ -50,7 +51,7 @@ class PhoneticSuggestion {
void setLayout(QJsonObject lay);

QString getPrevSelected();
void saveSelection(QString selected);
void saveSelection(int index);

QStringList Suggest(QString word);
void updateEngine();
Expand Down
2 changes: 1 addition & 1 deletion src/engine/libengine/cachemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ QString CacheManager::getCandidateSelection(QString word) {
}

void CacheManager::writeCandidateSelection(QString word, QString sel) {
candidateSel[word] = sel;
candidateSel.insert(word, sel);
saveCandidateSelection();
}

Expand Down
13 changes: 0 additions & 13 deletions src/engine/libengine/cachemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,6 @@ class CacheManager {
void setTempCache(QString key, QVector<QString> suggestions);
QVector<QString> getTempCache(QString key);

/* TODO: Add Suffix implementation
void removeAllBase() {
base.clear();
}

QVector<QString> baseForKey(QString key) {
return base[key];
}

void setBase(QVector<QString> aBase, QString aKey) {
base[aKey] = aBase;
}*/

void loadCandidateSelection();
QString getCandidateSelection(QString word);
void writeCandidateSelection(QString word, QString sel);
Expand Down