[dasher: 161/217] Control box move and delete to the beginning or end or by one character are synchronized.
- From: Patrick Welche <pwelche src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dasher: 161/217] Control box move and delete to the beginning or end or by one character are synchronized.
- Date: Sat, 27 Feb 2016 12:13:51 +0000 (UTC)
commit feb93896ae58da5d8f0c92c1781a895468534dc8
Author: Ada Majorek <amajorek google com>
Date: Sun Jan 3 22:49:09 2016 -0800
Control box move and delete to the beginning or end or by one character are synchronized.
https://github.com/ipomoena/dasher/issues/13
Moving deleting by word, sentence, line and rest still not implemented.
Src/DasherCore/Alphabet/AlphIO.cpp | 10 +++---
Src/DasherCore/ControlManager.cpp | 55 +++++++++++++++++++++++++++-----
Src/DasherCore/ControlManager.h | 4 ++-
Src/DasherCore/DasherInterfaceBase.cpp | 1 +
4 files changed, 56 insertions(+), 14 deletions(-)
---
diff --git a/Src/DasherCore/Alphabet/AlphIO.cpp b/Src/DasherCore/Alphabet/AlphIO.cpp
index 9c17b81..2d089f0 100644
--- a/Src/DasherCore/Alphabet/AlphIO.cpp
+++ b/Src/DasherCore/Alphabet/AlphIO.cpp
@@ -66,8 +66,8 @@ CAlphIO::CAlphIO(CMessageDisplay *pMsgs) : AbstractXMLParser(pMsgs) {
void CAlphIO::GetAlphabets(std::vector <std::string >*AlphabetList) const {
AlphabetList->clear();
- for(auto Cur = Alphabets.begin(); Cur != Alphabets.end(); Cur++)
- AlphabetList->push_back(Cur->second->AlphID);
+ for (auto alphabet : Alphabets)
+ AlphabetList->push_back(alphabet.second->AlphID);
}
std::string CAlphIO::GetDefault() {
@@ -80,7 +80,7 @@ std::string CAlphIO::GetDefault() {
}
const CAlphInfo *CAlphIO::GetInfo(const std::string &AlphID) const {
- map<string, const CAlphInfo*>::const_iterator it = Alphabets.find(AlphID);
+ auto it = Alphabets.find(AlphID);
if (it == Alphabets.end()) //if we don't have the alphabet they ask for,
it = Alphabets.find("Default"); //give them default - it's better than nothing
return it->second;
@@ -431,7 +431,7 @@ void CAlphIO::XmlCData(const XML_Char *s, int len) {
}
CAlphIO::~CAlphIO() {
- for (std::map<std::string, const CAlphInfo* >::iterator it = Alphabets.begin(); it != Alphabets.end();
++it) {
- delete it->second;
+ for (auto it : Alphabets) {
+ delete it.second;
}
}
diff --git a/Src/DasherCore/ControlManager.cpp b/Src/DasherCore/ControlManager.cpp
index 09fae54..93ee234 100644
--- a/Src/DasherCore/ControlManager.cpp
+++ b/Src/DasherCore/ControlManager.cpp
@@ -105,6 +105,7 @@ void CControlBase::CContNode::PopulateChildren() {
const unsigned int iNChildren( m_pTemplate->successors.size() );
unsigned int iLbnd(0), iIdx(0);
+ int newOffset = m_pTemplate->calculateNewOffset(this, offset());
for (vector<NodeTemplate *>::iterator it = m_pTemplate->successors.begin();
it!=m_pTemplate->successors.end(); it++) {
@@ -113,11 +114,10 @@ void CControlBase::CContNode::PopulateChildren() {
if( *it == NULL ) {
// Escape back to alphabet
- pNewNode = m_pMgr->m_pNCManager->GetAlphabetManager()->GetRoot(this, false, offset()+1);
+ pNewNode = m_pMgr->m_pNCManager->GetAlphabetManager()->GetRoot(this, false, newOffset + 1);
}
else {
-
- pNewNode = new CContNode(offset(), m_pMgr->getColour(*it, this), *it, m_pMgr);
+ pNewNode = new CContNode(newOffset, m_pMgr->getColour(*it, this), *it, m_pMgr);
}
pNewNode->Reparent(this, iLbnd, iHbnd);
iLbnd=iHbnd;
@@ -144,14 +144,21 @@ public:
XMLNodeTemplate(const string &label, int color) : NodeTemplate(label, color) {
}
- void happen(CControlBase::CContNode *pNode) {
- for (vector<Action*>::iterator it=actions.begin(); it!=actions.end(); it++)
- (*it)->happen(pNode);
+ int calculateNewOffset(CControlBase::CContNode *pNode, int offsetBefore) override {
+ int newOffset = offsetBefore;
+ for (auto pAction : actions)
+ newOffset = pAction->calculateNewOffset(pNode, newOffset);
+ return newOffset;
+ }
+
+ void happen(CControlBase::CContNode *pNode) override {
+ for (auto pAction : actions)
+ pAction->happen(pNode);
}
~XMLNodeTemplate() {
- for (vector<Action*>::iterator it=actions.begin(); it!=actions.end(); it++)
- delete *it;
+ for (auto pAction : actions)
+ delete pAction;
}
vector<CControlBase::Action*> actions;
@@ -298,6 +305,19 @@ class Delete : public CControlBase::Action {
const CControlManager::EditDistance m_dist;
public:
Delete(bool bForwards, CControlManager::EditDistance dist) : m_bForwards(bForwards), m_dist(dist) {
+ }
+ int calculateNewOffset(CControlBase::CContNode *pNode, int offsetBefore) override {
+ if (m_bForwards)
+ return offsetBefore;
+ switch (m_dist) {
+ case CControlManager::EDIT_FILE:
+ return -1;
+ case CControlManager::EDIT_CHAR: {
+ return max(-1, offsetBefore - 1);
+ }
+ default:
+ return offsetBefore;
+ }
}
virtual void happen(CControlBase::CContNode *pNode) {
pNode->mgr()->GetDasherInterface()->ctrlDelete(m_bForwards, m_dist);
@@ -310,6 +330,23 @@ class Move : public CControlBase::Action {
public:
Move(bool bForwards, CControlManager::EditDistance dist) : m_bForwards(bForwards), m_dist(dist) {
}
+ int calculateNewOffset(CControlBase::CContNode *pNode, int offsetBefore) override {
+ switch (m_dist) {
+ case CControlManager::EDIT_FILE:
+ return m_bForwards ? pNode->mgr()->GetDasherInterface()->GetAllContextLenght() - 1 : -1;
+
+ case CControlManager::EDIT_CHAR: {
+ if (m_bForwards) {
+ int maxPos = pNode->mgr()->GetDasherInterface()->GetAllContextLenght() - 1;
+ return min(maxPos, offsetBefore + 1);
+ }
+ else
+ return max(-1, offsetBefore - 1);
+ }
+ default:
+ return offsetBefore;
+ }
+ }
virtual void happen(CControlBase::CContNode *pNode) {
pNode->mgr()->GetDasherInterface()->ctrlMove(m_bForwards, m_dist);
}
@@ -385,6 +422,7 @@ CControlManager::CControlManager(CSettingsUser *pCreateFrom, CNodeCreationManage
if (!id.empty())
fileName = "control." + id + ".xml";
m_pInterface->ScanFiles(this, fileName);
+
updateActions();
}
@@ -439,6 +477,7 @@ void CControlManager::updateActions() {
// If nothing was read from control.xml, add alphabet and control box
if (GetRootTemplate()->successors.empty())
{
+ m_pMsgs->Message("Control box is empty.", false);
GetRootTemplate()->successors.push_back(NULL);
GetRootTemplate()->successors.push_back(GetRootTemplate());
}
diff --git a/Src/DasherCore/ControlManager.h b/Src/DasherCore/ControlManager.h
index 3e8feb7..d12f368 100644
--- a/Src/DasherCore/ControlManager.h
+++ b/Src/DasherCore/ControlManager.h
@@ -84,7 +84,8 @@ namespace Dasher {
class Action {
public:
virtual ~Action() = default;
- virtual void happen(CContNode *pNode) {}
+ virtual int calculateNewOffset(CControlBase::CContNode *pNode, int offsetBefore) { return
offsetBefore; }
+ virtual void happen(CContNode *pNode) {}
};
class NodeTemplate : public Action {
public:
@@ -93,6 +94,7 @@ namespace Dasher {
const std::string m_strLabel;
const int m_iColour;
std::vector<NodeTemplate *> successors;
+
private:
friend class CControlBase;
CDasherScreen::Label *m_pLabel;
diff --git a/Src/DasherCore/DasherInterfaceBase.cpp b/Src/DasherCore/DasherInterfaceBase.cpp
index c3781b9..0ad4041 100644
--- a/Src/DasherCore/DasherInterfaceBase.cpp
+++ b/Src/DasherCore/DasherInterfaceBase.cpp
@@ -274,6 +274,7 @@ void CDasherInterfaceBase::HandleEvent(int iParameter) {
m_pWordSpeaker = GetBoolParameter(BP_SPEAK_WORDS) ? new WordSpeaker(this) : NULL;
break;
case BP_CONTROL_MODE:
+ case SP_CONTROL_BOX_ID:
// force rebuilding every node. If not control box is accessed after delete.
CreateNCManager();
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]