void GuiSearch::wrap_dispatch(const FuncRequest & func, bool forward) { dispatch(func); BufferView * bv = const_cast<BufferView *>(bufferview()); if (!bv->cursor().result().dispatched()) { GuiView & lv = *const_cast<GuiView *>(&lyxview()); DocIterator cur_orig(bv->cursor()); docstring q; if (forward) q = _("End of file reached while searching forward.\n" "Continue searching from the beginning?"); else q = _("Beginning of file reached while searching backward.\n" "Continue searching from the end?"); int wrap_answer = frontend::Alert::prompt(_("Wrap search?"), q, 0, 1, _("&Yes"), _("&No")); if (wrap_answer == 0) { if (forward) { bv->cursor().clear(); bv->cursor().push_back(CursorSlice(bv->buffer().inset())); } else { bv->cursor().setCursor(doc_iterator_end(&bv->buffer())); bv->cursor().backwardPos(); } bv->clearSelection(); dispatch(func); if (bv->cursor().result().dispatched()) return; } bv->cursor().setCursor(cur_orig); lv.message(_("String not found.")); } }
/** Copy selected elements from bv's BufferParams to the dest_bv's one ** We don't want to copy'em all, e.g., not the default master **/ static void copy_params(BufferView const & bv, BufferView & dest_bv) { Buffer const & doc_buf = bv.buffer(); BufferParams const & doc_bp = doc_buf.params(); string const & lang = doc_bp.language->lang(); string const & doc_class = doc_bp.documentClass().name(); Buffer & dest_buf = dest_bv.buffer(); dest_buf.params().setLanguage(lang); dest_buf.params().setBaseClass(doc_class); dest_buf.params().makeDocumentClass(); dest_bv.cursor().current_font.setLanguage(doc_bp.language); }
docstring InsetCitation::toolTip(BufferView const & bv, int, int) const { Buffer const & buf = bv.buffer(); // Only after the buffer is loaded from file... if (!buf.isFullyLoaded()) return docstring(); BiblioInfo const & bi = buf.masterBibInfo(); if (bi.empty()) return _("No bibliography defined!"); docstring const & key = getParam("key"); if (key.empty()) return _("No citations selected!"); vector<docstring> keys = getVectorFromString(key); vector<docstring>::const_iterator it = keys.begin(); vector<docstring>::const_iterator en = keys.end(); docstring tip; for (; it != en; ++it) { docstring const key_info = bi.getInfo(*it, buffer()); if (key_info.empty()) continue; if (!tip.empty()) tip += "\n"; tip += wrap(key_info, -4); } return tip; }
int VSpace::inPixels(BufferView const & bv) const { // Height of a normal line in pixels (zoom factor considered) int const default_height = defaultRowHeight(); switch (kind_) { case DEFSKIP: return bv.buffer().params().getDefSkip().inPixels(bv); // This is how the skips are normally defined by LateX. // But there should be some way to change this per document. case SMALLSKIP: return default_height / 4; case MEDSKIP: return default_height / 2; case BIGSKIP: return default_height; case VFILL: // leave space for the vfill symbol return 3 * default_height; case LENGTH: return len_.len().inPixels(bv.workWidth()); default: LATTEST(false); // fall through in release mode } return 0; }
int ParagraphMetrics::rightMargin(BufferView const & bv) const { BufferParams const & params = bv.buffer().params(); DocumentClass const & tclass = params.documentClass(); frontend::FontMetrics const & fm = theFontMetrics(params.getFont()); int const r_margin = bv.rightMargin() + fm.signedWidth(tclass.rightmargin()) + fm.signedWidth(par_->layout().rightmargin) * 4 / (par_->getDepth() + 4); return r_margin; }
bool SpellcheckerWidget::initialiseParams(std::string const &) { BufferView * bv = d->gv_->documentBufferView(); if (bv == 0) return false; std::set<Language const *> languages = bv->buffer().masterBuffer()->getLanguages(); if (!languages.empty()) d->setLanguage(*languages.begin()); d->start_ = DocIterator(); d->wrapAround(false); d->canCheck(); return true; }
int HSpace::inPixels(BufferView const & bv) const { switch (kind_) { case DEFAULT: // FIXME: replace by correct length return bv.buffer().params().getIndentation().inPixels(bv); case LENGTH: return len_.len().inPixels(bv.workWidth()); default: LATTEST(false); // fall through in release mode } return 0; }
/// Return true if a match was found bool FindAndReplaceWidget::findAndReplaceScope(FindAndReplaceOptions & opt, bool replace_all) { BufferView * bv = view_.documentBufferView(); if (!bv) return false; Buffer * buf = &bv->buffer(); Buffer * buf_orig = &bv->buffer(); DocIterator cur_orig(bv->cursor()); int wrap_answer = -1; ostringstream oss; oss << opt; FuncRequest cmd(LFUN_WORD_FINDADV, from_utf8(oss.str())); view_.setBusy(true); if (opt.scope == FindAndReplaceOptions::S_ALL_MANUALS) { vector<string> const & v = allManualsFiles(); if (std::find(v.begin(), v.end(), buf->absFileName()) == v.end()) { FileName const & fname = FileName(*v.begin()); if (!theBufferList().exists(fname)) { guiApp->currentView()->setBusy(false); guiApp->currentView()->loadDocument(fname, false); guiApp->currentView()->setBusy(true); } buf = theBufferList().getBuffer(fname); lyx::dispatch(FuncRequest(LFUN_BUFFER_SWITCH, buf->absFileName())); bv = view_.documentBufferView(); bv->cursor().clear(); bv->cursor().push_back(CursorSlice(buf->inset())); } } do { LYXERR(Debug::FIND, "Dispatching LFUN_WORD_FINDADV"); dispatch(cmd); LYXERR(Debug::FIND, "dispatched"); if (bv->cursor().result().dispatched()) { // New match found and selected (old selection replaced if needed) if (replace_all) continue; view_.setBusy(false); return true; } // No match found in current buffer (however old selection might have been replaced) // select next buffer in scope, if any bool prompt = nextPrevBuffer(buf, opt); if (prompt) { if (wrap_answer != -1) break; docstring q = getQuestionString(opt); view_.setBusy(false); wrap_answer = frontend::Alert::prompt( _("Wrap search?"), q, 0, 1, _("&Yes"), _("&No")); view_.setBusy(true); if (wrap_answer == 1) break; } if (buf != &view_.documentBufferView()->buffer()) lyx::dispatch(FuncRequest(LFUN_BUFFER_SWITCH, buf->absFileName())); bv = view_.documentBufferView(); if (opt.forward) { bv->cursor().clear(); bv->cursor().push_back(CursorSlice(buf->inset())); } else { //lyx::dispatch(FuncRequest(LFUN_BUFFER_END)); bv->cursor().setCursor(doc_iterator_end(buf)); bv->cursor().backwardPos(); LYXERR(Debug::FIND, "findBackAdv5: cur: " << bv->cursor()); } bv->clearSelection(); } while (wrap_answer != 1); if (buf_orig != &view_.documentBufferView()->buffer()) lyx::dispatch(FuncRequest(LFUN_BUFFER_SWITCH, buf_orig->absFileName())); bv = view_.documentBufferView(); // This may happen after a replace occurred if (cur_orig.pos() > cur_orig.lastpos()) cur_orig.pos() = cur_orig.lastpos(); bv->cursor().setCursor(cur_orig); view_.setBusy(false); return false; }
void SpellcheckerWidget::Private::check() { BufferView * bv = gv_->documentBufferView(); if (!bv || bv->buffer().text().empty()) return; fixPositionsIfBroken(); SpellChecker * speller = theSpellChecker(); if (speller && !speller->hasDictionary(bv->buffer().language())) { int dsize = speller->numDictionaries(); if (0 == dsize) { hide(); QMessageBox::information(p, qt_("Spell Checker"), qt_("Spell checker has no dictionaries.")); return; } } DocIterator from = bv->cursor(); DocIterator to = isCurrentBuffer(from) ? end_ : doc_iterator_end(&bv->buffer()); WordLangTuple word_lang; docstring_list suggestions; LYXERR(Debug::GUI, "Spellchecker: start check at " << from); try { bv->buffer().spellCheck(from, to, word_lang, suggestions); } catch (ExceptionMessage const & message) { if (message.type_ == WarningException) { Alert::warning(message.title_, message.details_); return; } throw message; } // end of document or selection? if (atLastPos(from)) { if (isWrapAround()) { hide(); return; } if (continueFromBeginning()) check(); return; } if (isWrapAround(from)) { hide(); return; } word_ = word_lang; // set suggestions updateSuggestions(suggestions); // set language if (!word_lang.lang()) return; setLanguage(word_lang.lang()); // mark misspelled word setSelection(from, to); }