+ //lyxerr << BOOST_CURRENT_FUNCTION
+ // << [ cmd = " << cmd << "]" << endl;
+
+ // Make sure that the cached BufferView is correct.
+ lyxerr[Debug::ACTION] << BOOST_CURRENT_FUNCTION
+ << " action[" << cmd.action << ']'
+ << " arg[" << to_utf8(cmd.argument()) << ']'
+ << " x[" << cmd.x << ']'
+ << " y[" << cmd.y << ']'
+ << " button[" << cmd.button() << ']'
+ << endl;
+
+ LCursor & cur = cursor_;
+
+ switch (cmd.action) {
+
+ case LFUN_UNDO:
+ if (buffer_) {
+ cur.message(_("Undo"));
+ cur.clearSelection();
+ if (!textUndo(*this))
+ cur.message(_("No further undo information"));
+ update();
+ switchKeyMap();
+ }
+ break;
+
+ case LFUN_REDO:
+ if (buffer_) {
+ cur.message(_("Redo"));
+ cur.clearSelection();
+ if (!textRedo(*this))
+ cur.message(_("No further redo information"));
+ update();
+ switchKeyMap();
+ }
+ break;
+
+ case LFUN_FILE_INSERT:
+ // FIXME: We don't know the encoding of filenames
+ menuInsertLyXFile(to_utf8(cmd.argument()));
+ break;
+
+ case LFUN_FILE_INSERT_ASCII_PARA:
+ // FIXME: We don't know the encoding of filenames
+ insertAsciiFile(this, to_utf8(cmd.argument()), true);
+ break;
+
+ case LFUN_FILE_INSERT_ASCII:
+ // FIXME: We don't know the encoding of filenames
+ insertAsciiFile(this, to_utf8(cmd.argument()), false);
+ break;
+
+ case LFUN_FONT_STATE:
+ cur.message(from_utf8(cur.currentState()));
+ break;
+
+ case LFUN_BOOKMARK_SAVE:
+ saveBookmark(convert<unsigned int>(to_utf8(cmd.argument())));
+ break;
+
+ case LFUN_LABEL_GOTO: {
+ docstring label = cmd.argument();
+ if (label.empty()) {
+ InsetRef * inset =
+ getInsetByCode<InsetRef>(cursor_,
+ InsetBase::REF_CODE);
+ if (inset) {
+ label = inset->getParam("reference");
+ // persistent=false: use temp_bookmark
+ saveBookmark(false);
+ }
+ }
+
+ if (!label.empty())
+ gotoLabel(label);
+ break;
+ }
+
+ case LFUN_PARAGRAPH_GOTO: {
+ int const id = convert<int>(to_utf8(cmd.argument()));
+ int i = 0;
+ for (Buffer * b = buffer_; i == 0 || b != buffer_; b = theBufferList().next(b)) {
+ ParIterator par = b->getParFromID(id);
+ if (par == b->par_iterator_end()) {
+ lyxerr[Debug::INFO]
+ << "No matching paragraph found! ["
+ << id << "]." << endl;
+ } else {
+ lyxerr[Debug::INFO]
+ << "Paragraph " << par->id()
+ << " found in buffer `"
+ << b->fileName() << "'." << endl;
+
+ if (b == buffer_) {
+ // Set the cursor
+ setCursor(makeDocIterator(par, 0));
+ update();
+ switchKeyMap();
+ } else {
+ // Switch to other buffer view and resend cmd
+ theLyXFunc().dispatch(FuncRequest(
+ LFUN_BUFFER_SWITCH, b->fileName()));
+ theLyXFunc().dispatch(cmd);
+ }
+ break;
+ }
+ ++i;
+ }
+ break;
+ }
+
+ case LFUN_OUTLINE_UP:
+ toc::outline(toc::Up, cursor_);
+ cursor_.text()->setCursor(cursor_, cursor_.pit(), 0);
+ updateLabels(*buffer_);
+ break;
+ case LFUN_OUTLINE_DOWN:
+ toc::outline(toc::Down, cursor_);
+ cursor_.text()->setCursor(cursor_, cursor_.pit(), 0);
+ updateLabels(*buffer_);
+ break;
+ case LFUN_OUTLINE_IN:
+ toc::outline(toc::In, cursor_);
+ updateLabels(*buffer_);
+ break;
+ case LFUN_OUTLINE_OUT:
+ toc::outline(toc::Out, cursor_);
+ updateLabels(*buffer_);
+ break;
+
+ case LFUN_NOTE_NEXT:
+ bv_funcs::gotoInset(this, InsetBase::NOTE_CODE, false);
+ break;
+
+ case LFUN_REFERENCE_NEXT: {
+ vector<InsetBase_code> tmp;
+ tmp.push_back(InsetBase::LABEL_CODE);
+ tmp.push_back(InsetBase::REF_CODE);
+ bv_funcs::gotoInset(this, tmp, true);
+ break;
+ }
+
+ case LFUN_CHANGES_TRACK:
+ buffer_->params().trackChanges = !buffer_->params().trackChanges;
+ break;
+
+ case LFUN_CHANGES_OUTPUT: {
+ buffer_->params().outputChanges = !buffer_->params().outputChanges;
+ break;
+ }
+
+ case LFUN_CHANGE_NEXT:
+ findNextChange(this);
+ break;
+
+ case LFUN_CHANGES_MERGE:
+ if (findNextChange(this))
+ showDialog("changes");
+ break;
+
+ case LFUN_ALL_CHANGES_ACCEPT: {
+ cursor_.reset(buffer_->inset());
+#ifdef WITH_WARNINGS
+#warning FIXME changes
+#endif
+ while (findNextChange(this))
+ getLyXText()->acceptChange(cursor_);
+ update();
+ break;
+ }
+
+ case LFUN_ALL_CHANGES_REJECT: {
+ cursor_.reset(buffer_->inset());
+#ifdef WITH_WARNINGS
+#warning FIXME changes
+#endif
+ while (findNextChange(this))
+ getLyXText()->rejectChange(cursor_);
+ break;
+ }
+
+ case LFUN_WORD_FIND:
+ find(this, cmd);
+ break;
+
+ case LFUN_WORD_REPLACE:
+ replace(this, cmd);
+ break;
+
+ case LFUN_MARK_OFF:
+ cur.clearSelection();
+ cur.resetAnchor();
+ cur.message(from_utf8(N_("Mark off")));
+ break;
+
+ case LFUN_MARK_ON:
+ cur.clearSelection();
+ cur.mark() = true;
+ cur.resetAnchor();
+ cur.message(from_utf8(N_("Mark on")));
+ break;
+
+ case LFUN_MARK_TOGGLE:
+ cur.clearSelection();
+ if (cur.mark()) {
+ cur.mark() = false;
+ cur.message(from_utf8(N_("Mark removed")));
+ } else {
+ cur.mark() = true;
+ cur.message(from_utf8(N_("Mark set")));
+ }
+ cur.resetAnchor();
+ break;
+
+ case LFUN_SCREEN_RECENTER:
+ center();
+ break;
+
+ case LFUN_BIBTEX_DATABASE_ADD: {
+ LCursor tmpcur = cursor_;
+ bv_funcs::findInset(tmpcur, InsetBase::BIBTEX_CODE, false);
+ InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
+ InsetBase::BIBTEX_CODE);
+ if (inset) {
+ if (inset->addDatabase(to_utf8(cmd.argument())))
+ buffer_->updateBibfilesCache();
+ }
+ break;
+ }
+
+ case LFUN_BIBTEX_DATABASE_DEL: {
+ LCursor tmpcur = cursor_;
+ bv_funcs::findInset(tmpcur, InsetBase::BIBTEX_CODE, false);
+ InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
+ InsetBase::BIBTEX_CODE);
+ if (inset) {
+ if (inset->delDatabase(to_utf8(cmd.argument())))
+ buffer_->updateBibfilesCache();
+ }
+ break;
+ }
+
+ case LFUN_WORDS_COUNT: {
+ DocIterator from, to;
+ if (cur.selection()) {
+ from = cur.selectionBegin();
+ to = cur.selectionEnd();
+ } else {
+ from = doc_iterator_begin(buffer_->inset());
+ to = doc_iterator_end(buffer_->inset());
+ }
+ int const count = countWords(from, to);
+ docstring message;
+ if (count != 1) {
+ if (cur.selection())
+ message = bformat(_("%1$d words in selection."),
+ count);
+ else
+ message = bformat(_("%1$d words in document."),
+ count);
+ }
+ else {
+ if (cur.selection())
+ message = _("One word in selection.");
+ else
+ message = _("One word in document.");
+ }
+
+ Alert::information(_("Count words"), message);
+ }
+ break;
+
+ case LFUN_BUFFER_TOGGLE_COMPRESSION:
+ // turn compression on/off
+ buffer_->params().compressed = !buffer_->params().compressed;
+ break;
+
+ case LFUN_NEXT_INSET_TOGGLE: {
+ // this is the real function we want to invoke
+ FuncRequest tmpcmd = FuncRequest(LFUN_INSET_TOGGLE, cmd.origin);
+ // if there is an inset at cursor, see whether it
+ // wants to toggle.
+ InsetBase * inset = cur.nextInset();
+ if (inset && inset->isActive()) {
+ LCursor tmpcur = cur;
+ tmpcur.pushLeft(*inset);
+ inset->dispatch(tmpcur, tmpcmd);
+ if (tmpcur.result().dispatched()) {
+ cur.dispatched();
+ }
+ }
+ // if it did not work, try the underlying inset.
+ if (!cur.result().dispatched())
+ cur.dispatch(tmpcmd);
+
+ if (cur.result().dispatched())
+ cur.clearSelection();
+
+ break;
+ }
+
+ default:
+ return false;
+ }
+
+ return true;