action_ptr highlighter::get_delete_target() { if(action_ptr locked = selected_action_.lock()) { return *side_actions_->find_last_action_of(*(locked->get_unit())); } else { return action_ptr(); } }
void MyShareData::AddLastOpenAction(QString path, bool front) { QString action_path; QFileInfo file_info(path); QAction* act = new QAction(file_info.fileName(), nullptr); act->setData(path); MySimpleList<QActionPtr>::iterator iter = MyShareData::m_files_history.first(); for(;iter != MyShareData::m_files_history.end(); iter++) { action_path = (*iter)->data().toString(); if(action_path == path) MyShareData::m_files_history.remove(iter); } QActionPtr action_ptr(act); if(front) MyShareData::m_files_history.addAtFront(action_ptr); else MyShareData::m_files_history.addAtEnd(action_ptr); }
/* static */ action_ptr action::from_config(config const& cfg, bool hidden) { std::string type = cfg["type"]; try { if(type=="move") return action_ptr(new move(cfg,hidden)); else if(type=="attack") return action_ptr(new attack(cfg,hidden)); else if(type=="recruit") return action_ptr(new recruit(cfg,hidden)); else if(type=="recall") return action_ptr(new recall(cfg,hidden)); else if(type=="suppose_dead") return action_ptr(new suppose_dead(cfg,hidden)); } catch(action::ctor_err const&) {} return action_ptr(); }
void cTextField::handleInput(cKey key) { changeMade = true; bool select = mod_contains(key.mod, mod_shift); bool haveSelection = insertionPoint != selectionPoint; key = divineFunction(key); TextStyle style; style.font = FONT_PLAIN; style.pointSize = 12; size_t new_ip; std::string contents = getText(); if(current_action && hist_timer.getElapsedTime().asSeconds() > 5.0f) history.add(current_action), current_action.reset(); hist_timer.restart(); if(!key.spec) { if(haveSelection) { cKey deleteKey = key; deleteKey.spec = true; deleteKey.k = key_bsp; handleInput(deleteKey); contents = getText(); } if(aTextInsert* ins = dynamic_cast<aTextInsert*>(current_action.get())) ins->append(key.c); else { if(current_action) history.add(current_action); aTextInsert* new_ins = new aTextInsert(*this, insertionPoint); new_ins->append(key.c); current_action.reset(new_ins); } contents.insert(contents.begin() + insertionPoint, char(key.c)); selectionPoint = ++insertionPoint; } else switch(key.k) { case key_enter: break; // Shouldn't be receiving this anyway // TODO: Implement all the other special keys case key_left: case key_word_left: if(current_action) history.add(current_action), current_action.reset(); if(haveSelection && !select) { selectionPoint = insertionPoint = std::min(selectionPoint,insertionPoint); break; } new_ip = select ? selectionPoint : insertionPoint; if(new_ip == 0) break; if(key.k == key_word_left) { new_ip--; while(new_ip > 0 && contents[new_ip - 1] != ' ') new_ip--; } else new_ip--; (select ? selectionPoint : insertionPoint) = new_ip; if(!select) selectionPoint = insertionPoint; break; case key_right: case key_word_right: if(current_action) history.add(current_action), current_action.reset(); if(haveSelection && !select) { selectionPoint = insertionPoint = std::max(selectionPoint,insertionPoint); break; } new_ip = select ? selectionPoint : insertionPoint; if(new_ip == contents.length()) break; if(key.k == key_word_right) { new_ip++; while(new_ip < contents.length() && contents[new_ip] != ' ') new_ip++; } else new_ip++; (select ? selectionPoint : insertionPoint) = new_ip; if(!select) selectionPoint = insertionPoint; break; case key_up: if(current_action) history.add(current_action), current_action.reset(); if(haveSelection && !select) selectionPoint = insertionPoint = std::min(selectionPoint,insertionPoint); if(snippets[ip_row].at.y == snippets[0].at.y) { key.k = key_top; if(select) key.mod += mod_shift; handleInput(key); } else { int x = snippets[ip_row].at.x + ip_col, y = snippets[ip_row].at.y - 10; set_ip(loc(x,y), select ? &cTextField::selectionPoint : &cTextField::insertionPoint); if(!select) selectionPoint = insertionPoint; } break; case key_down: if(current_action) history.add(current_action), current_action.reset(); if(haveSelection && !select) selectionPoint = insertionPoint = std::max(selectionPoint,insertionPoint); if(snippets[ip_row].at.y == snippets.back().at.y) { key.k = key_bottom; if(select) key.mod += mod_shift; handleInput(key); } else { int x = snippets[ip_row].at.x + ip_col, y = snippets[ip_row].at.y + 20; set_ip(loc(x,y), select ? &cTextField::selectionPoint : &cTextField::insertionPoint); if(!select) selectionPoint = insertionPoint; } break; case key_bsp: case key_word_bsp: case key_del: case key_word_del: if(haveSelection) { if(key.k == key_word_bsp) handleInput({true, key_word_left, mod_shift}); else if(key.k == key_word_del) handleInput({true, key_word_right, mod_shift}); auto begin = contents.begin() + std::min(selectionPoint, insertionPoint); auto end = contents.begin() + std::max(selectionPoint, insertionPoint); std::string removed(begin, end); auto result = contents.erase(begin, end); bool dir = insertionPoint < selectionPoint; selectionPoint = insertionPoint = result - contents.begin(); if(current_action) history.add(current_action), current_action.reset(); history.add(action_ptr(new aTextDelete(*this, std::min(selectionPoint, insertionPoint), removed, dir))); } else if(key.k == key_word_bsp) { cKey selectKey = key; selectKey.k = key_word_left; selectKey.mod = mod_shift; key.k = key_bsp; handleInput(selectKey); if(selectionPoint != insertionPoint) handleInput(key); return; } else if(key.k == key_bsp) { if(insertionPoint == 0) break; char c = contents[insertionPoint - 1]; contents.erase(insertionPoint - 1,1); selectionPoint = --insertionPoint; if(aTextDelete* del = dynamic_cast<aTextDelete*>(current_action.get())) del->append_front(c); else { if(current_action) history.add(current_action); aTextDelete* new_del = new aTextDelete(*this, insertionPoint + 1, insertionPoint + 1); new_del->append_front(c); current_action.reset(new_del); } } else if(key.k == key_word_del) { cKey selectKey = key; selectKey.k = key_word_right; selectKey.mod = mod_shift; key.k = key_del; handleInput(selectKey); if(selectionPoint != insertionPoint) handleInput(key); return; } else if(key.k == key_del) { if(insertionPoint == contents.length()) break; char c = contents[insertionPoint]; contents.erase(insertionPoint,1); if(aTextDelete* del = dynamic_cast<aTextDelete*>(current_action.get())) del->append_back(c); else { if(current_action) history.add(current_action); aTextDelete* new_del = new aTextDelete(*this, insertionPoint, insertionPoint); new_del->append_back(c); current_action.reset(new_del); } } break; case key_top: if(current_action) history.add(current_action), current_action.reset(); if(!select) insertionPoint = 0; selectionPoint = 0; break; case key_bottom: if(current_action) history.add(current_action), current_action.reset(); if(!select) insertionPoint = contents.length(); selectionPoint = contents.length(); break; case key_end: if(current_action) history.add(current_action), current_action.reset(); new_ip = snippets[ip_row].at.x + string_length(snippets[ip_row].text, style); set_ip(loc(new_ip, snippets[ip_row].at.y), select ? &cTextField::selectionPoint : &cTextField::insertionPoint); if(!select) selectionPoint = insertionPoint; break; case key_home: if(current_action) history.add(current_action), current_action.reset(); set_ip(snippets[ip_row].at, select ? &cTextField::selectionPoint : &cTextField::insertionPoint); if(!select) selectionPoint = insertionPoint; break; case key_pgup: if(current_action) history.add(current_action), current_action.reset(); if(snippets[ip_row].at.y != snippets[0].at.y) { int x = snippets[ip_row].at.x + ip_col, y = frame.top + 2; set_ip(loc(x,y), select ? &cTextField::selectionPoint : &cTextField::insertionPoint); if(!select) selectionPoint = insertionPoint; } break; case key_pgdn: if(current_action) history.add(current_action), current_action.reset(); if(snippets[ip_row].at.y != snippets.back().at.y) { int x = snippets[ip_row].at.x + ip_col, y = frame.bottom - 2; set_ip(loc(x,y), select ? &cTextField::selectionPoint : &cTextField::insertionPoint); if(!select) selectionPoint = insertionPoint; } break; case key_copy: case key_cut: if(current_action) history.add(current_action), current_action.reset(); set_clipboard(contents.substr(std::min(insertionPoint,selectionPoint), abs(insertionPoint - selectionPoint))); if(key.k == key_cut) { cKey deleteKey = key; deleteKey.k = key_bsp; handleInput(deleteKey); contents = getText(); } break; case key_paste: if(current_action) history.add(current_action), current_action.reset(); if(!get_clipboard().empty()) { if(haveSelection) { cKey deleteKey = {true, key_bsp, mod_none}; handleInput(deleteKey); } contents = getText(); std::string toInsert = get_clipboard(); contents.insert(insertionPoint, toInsert); history.add(action_ptr(new aTextInsert(*this, insertionPoint, toInsert))); insertionPoint += toInsert.length(); selectionPoint = insertionPoint; } break; case key_undo: if(current_action) history.add(current_action), current_action.reset(); history.undo(); return; case key_redo: if(current_action) history.add(current_action), current_action.reset(); history.redo(); return; case key_selectall: if(current_action) history.add(current_action), current_action.reset(); selectionPoint = 0; insertionPoint = contents.length(); break; // These keys have no function in this context. case key_esc: case key_tab: case key_help: case key_insert: break; } // Setting the text normally resets insertion/selection point, but we don't want that here. int ip = insertionPoint, sp = selectionPoint; setText(contents); insertionPoint = ip; selectionPoint = sp; }