Fix awkwardness of Enter key in string picker
Search field starts out hidden. When the button is clicked, the field and other controls appear, and the button takes over the enter key. Ctrl+Enter clicks okay (so if search is not opened, either Enter OR Ctrl+Enter will click okay)
This commit is contained in:
@@ -54,5 +54,5 @@
|
|||||||
<button name='left' type='left' def-key='left' relative='pos-in pos-in' anchor='led20' top='19' left='0'/>
|
<button name='left' type='left' def-key='left' relative='pos-in pos-in' anchor='led20' top='19' left='0'/>
|
||||||
<button name='right' type='right' def-key='right' relative='pos-in pos-in' rel-anchor='prev' top='0' left='63'/>
|
<button name='right' type='right' def-key='right' relative='pos-in pos-in' rel-anchor='prev' top='0' left='63'/>
|
||||||
<button name='cancel' type='regular' def-key='esc' relative='pos-in pos-in' rel-anchor='prev' top='0' left='201'>Cancel</button>
|
<button name='cancel' type='regular' def-key='esc' relative='pos-in pos-in' rel-anchor='prev' top='0' left='201'>Cancel</button>
|
||||||
<button name='done' type='regular' relative='pos-in pos-in' rel-anchor='prev' top='0' left='66'>OK</button>
|
<button name='done' type='regular' def-key='ctrl enter' relative='pos-in pos-in' rel-anchor='prev' top='0' left='66'>OK</button>
|
||||||
</dialog>
|
</dialog>
|
||||||
|
@@ -158,7 +158,7 @@ void cDialog::loadFromFile(const DialogDefn& file){
|
|||||||
|
|
||||||
Iterator<Attribute> attr;
|
Iterator<Attribute> attr;
|
||||||
Iterator<Element> node;
|
Iterator<Element> node;
|
||||||
string type, name, val, defaultButton;
|
string type, name, val, defbtn;
|
||||||
|
|
||||||
xml.FirstChildElement()->GetValue(&type);
|
xml.FirstChildElement()->GetValue(&type);
|
||||||
if(type != "dialog") throw xBadNode(type,xml.FirstChildElement()->Row(),xml.FirstChildElement()->Column(),fname);
|
if(type != "dialog") throw xBadNode(type,xml.FirstChildElement()->Row(),xml.FirstChildElement()->Column(),fname);
|
||||||
@@ -182,7 +182,7 @@ void cDialog::loadFromFile(const DialogDefn& file){
|
|||||||
}
|
}
|
||||||
defTextClr = clr;
|
defTextClr = clr;
|
||||||
} else if(name == "defbtn") {
|
} else if(name == "defbtn") {
|
||||||
defaultButton = val;
|
defbtn = val;
|
||||||
}else if(name != "debug")
|
}else if(name != "debug")
|
||||||
throw xBadAttr(type,name,attr->Row(),attr->Column(),fname);
|
throw xBadAttr(type,name,attr->Row(),attr->Column(),fname);
|
||||||
}
|
}
|
||||||
@@ -336,8 +336,7 @@ void cDialog::loadFromFile(const DialogDefn& file){
|
|||||||
} while(!all_resolved);
|
} while(!all_resolved);
|
||||||
|
|
||||||
// Set the default button.
|
// Set the default button.
|
||||||
if(hasControl(defaultButton))
|
setDefaultButton(defbtn);
|
||||||
getControl(defaultButton).setDefault(true);
|
|
||||||
|
|
||||||
// Sort by tab order
|
// Sort by tab order
|
||||||
// First, fill any gaps that might have been left, using ones that had no specific tab order
|
// First, fill any gaps that might have been left, using ones that had no specific tab order
|
||||||
@@ -1158,6 +1157,19 @@ bool cDialog::hasControl(std::string id) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cDialog::setDefaultButton(std::string defbtn) {
|
||||||
|
if(!hasControl(defbtn)){
|
||||||
|
// this is likely because the dialogxml is malformed. maybe the linter already checks this,
|
||||||
|
// but the engine might as well also.
|
||||||
|
throw std::string { "Requested default button does not exist: " } + defbtn;
|
||||||
|
}
|
||||||
|
if(!defaultButton.empty()){
|
||||||
|
getControl(defaultButton).setDefault(false);
|
||||||
|
}
|
||||||
|
defaultButton = defbtn;
|
||||||
|
getControl(defaultButton).setDefault(true);
|
||||||
|
}
|
||||||
|
|
||||||
const char*const xBadVal::CONTENT = "$content$";
|
const char*const xBadVal::CONTENT = "$content$";
|
||||||
|
|
||||||
cDialogIterator::cDialogIterator() : parent(nullptr) {}
|
cDialogIterator::cDialogIterator() : parent(nullptr) {}
|
||||||
|
@@ -265,6 +265,7 @@ public:
|
|||||||
cDialog(cDialog& other) = delete;
|
cDialog(cDialog& other) = delete;
|
||||||
inline void setAnimPictFPS(int fps) { if(fps == -1) fps = 2; anim_pict_fps = fps; }
|
inline void setAnimPictFPS(int fps) { if(fps == -1) fps = 2; anim_pict_fps = fps; }
|
||||||
inline void setDoAnimations(bool value) { doAnimations = value; }
|
inline void setDoAnimations(bool value) { doAnimations = value; }
|
||||||
|
void setDefaultButton(std::string defbtn);
|
||||||
private:
|
private:
|
||||||
void draw();
|
void draw();
|
||||||
void handle_events();
|
void handle_events();
|
||||||
@@ -275,6 +276,7 @@ private:
|
|||||||
rectangle winRect;
|
rectangle winRect;
|
||||||
boost::any result;
|
boost::any result;
|
||||||
std::string fname;
|
std::string fname;
|
||||||
|
std::string defaultButton;
|
||||||
sf::Clock animTimer, paintTimer;
|
sf::Clock animTimer, paintTimer;
|
||||||
friend class cControl;
|
friend class cControl;
|
||||||
friend class cContainer;
|
friend class cContainer;
|
||||||
|
@@ -66,6 +66,11 @@ cDialog* cStringChoice::operator->() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t cStringChoice::show(size_t selectedIndex) {
|
size_t cStringChoice::show(size_t selectedIndex) {
|
||||||
|
// Hide most of the search ui until Ctrl+f or clicking the search button
|
||||||
|
dlg["search-field"].hide();
|
||||||
|
dlg["search-label"].hide();
|
||||||
|
dlg["reverse"].hide();
|
||||||
|
|
||||||
cur = selectedIndex;
|
cur = selectedIndex;
|
||||||
if(cur >= strings.size()) {
|
if(cur >= strings.size()) {
|
||||||
if(editable) {
|
if(editable) {
|
||||||
@@ -162,6 +167,15 @@ bool cStringChoice::onOkay(cDialog& me){
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool cStringChoice::onSearch(cDialog& me){
|
bool cStringChoice::onSearch(cDialog& me){
|
||||||
|
if(!search_open){
|
||||||
|
me["search-field"].show();
|
||||||
|
me["search-label"].show();
|
||||||
|
me["reverse"].show();
|
||||||
|
me.setDefaultButton("search");
|
||||||
|
search_open = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
cLed& reverse_led = dynamic_cast<cLed&>(me["reverse"]);
|
cLed& reverse_led = dynamic_cast<cLed&>(me["reverse"]);
|
||||||
bool reversed = reverse_led.getState() == led_red;
|
bool reversed = reverse_led.getState() == led_red;
|
||||||
size_t page_delta = reversed ? -1 : 1;
|
size_t page_delta = reversed ? -1 : 1;
|
||||||
|
@@ -37,6 +37,7 @@ class cStringChoice {
|
|||||||
std::vector<std::string> strings;
|
std::vector<std::string> strings;
|
||||||
size_t page, cur;
|
size_t page, cur;
|
||||||
std::string search_str;
|
std::string search_str;
|
||||||
|
bool search_open = false;
|
||||||
cLedGroup* leds;
|
cLedGroup* leds;
|
||||||
std::function<void(cStringChoice&,int)> select_handler;
|
std::function<void(cStringChoice&,int)> select_handler;
|
||||||
cStringChoice(cDialog* parent, bool editable = false);
|
cStringChoice(cDialog* parent, bool editable = false);
|
||||||
|
Reference in New Issue
Block a user