#include "BufferView.h"
#include "cursor.h"
#include "debug.h"
+#include "dispatchresult.h"
#include "encoding.h"
#include "exporter.h"
#include "format.h"
#include "lyxvc.h"
#include "paragraph.h"
#include "ParagraphParameters.h"
-#include "TextCache.h"
-#include "undo_funcs.h"
+#include "undo.h"
#include "insets/insetcommand.h"
#include "insets/insetexternal.h"
if (ev.action == LFUN_NOACTION) {
setStatusMessage(N_("Nothing to do"));
- return flag.disabled(true);
+ flag.disabled(true);
+ return flag;
}
switch (ev.action) {
case LFUN_THESAURUS_ENTRY:
#endif
flag.unknown(true);
+ flag.disabled(true);
break;
default:
flag |= lyx_gui::getStatus(ev);
} else {
// no
setStatusMessage(N_("Command not allowed with"
- "out any document open"));
- return flag.disabled(true);
+ "out any document open"));
+ flag.disabled(true);
+ return flag;
}
}
disable = true;
}
} else {
- static InsetTabular inset(*owner->buffer(), 1, 1);
- FuncStatus ret;
-
+ static InsetTabular inset(*buf, 1, 1);
disable = true;
- ret = inset.getStatus(ev.argument);
+ FuncStatus ret = inset.getStatus(ev.argument);
if (ret.onoff(true) || ret.onoff(false))
flag.setOnOff(false);
}
disable = buf->isUnnamed() || buf->isClean();
break;
case LFUN_BOOKMARK_GOTO:
- disable = !view()->
+ disable = !view()->
isSavedPosition(strToUnsignedInt(ev.argument));
break;
+
case LFUN_MERGE_CHANGES:
case LFUN_ACCEPT_CHANGE:
case LFUN_REJECT_CHANGE:
case LFUN_REJECT_ALL_CHANGES:
disable = !buf->params().tracking_changes;
break;
+
case LFUN_INSET_TOGGLE: {
LyXText * lt = view()->getLyXText();
disable = !(isEditableInset(lt->getInset())
code = InsetOld::SPACE_CODE;
break;
case LFUN_INSET_DIALOG_SHOW: {
- LyXText * lt = view()->getLyXText();
- InsetOld * inset = lt->getInset();
- disable = !inset;
- if (!disable) {
- code = inset->lyxCode();
- if (!(code == InsetOld::INCLUDE_CODE
- || code == InsetOld::BIBTEX_CODE
- || code == InsetOld::FLOAT_LIST_CODE
- || code == InsetOld::TOC_CODE))
- disable = true;
- }
+ InsetOld * inset = view()->getLyXText()->getInset();
+ disable = !inset;
+ if (!disable) {
+ code = inset->lyxCode();
+ if (!(code == InsetOld::INCLUDE_CODE
+ || code == InsetOld::BIBTEX_CODE
+ || code == InsetOld::FLOAT_LIST_CODE
+ || code == InsetOld::TOC_CODE))
+ disable = true;
}
break;
+ }
default:
break;
}
// solution, we consider only the first action of the sequence
if (ev.action == LFUN_SEQUENCE) {
// argument contains ';'-terminated commands
-#warning LyXAction arguements not handled here.
+#warning LyXAction arguments not handled here.
flag = getStatus(FuncRequest(lyxaction.lookupFunc(token(ev.argument, ';', 0))));
}
if (view()->available())
view()->hideCursor();
-#if 0
+#if 1
{
Cursor cursor;
buildCursor(cursor, *view());
- if (cursor.dispatch(FuncRequest(func, view())) == DISPATCHED) {
+ DispatchResult result =
+ cursor.dispatch(FuncRequest(func, view()));
+
+ if (result.dispatched()) {
+ if (result.update()) {
+ view()->update();
+ }
lyxerr << "dispatched by Cursor::dispatch()\n";
goto exit_with_message;
}
+ lyxerr << "### NOT DispatchResult(true, true) BY Cursor::dispatch() ###\n";
}
#endif
if (view()->available() && view()->theLockingInset()) {
- dispatch_result result;
+ DispatchResult result;
if (action > 1 || (action == LFUN_UNKNOWN_ACTION &&
!keyseq.deleted()))
{
int dummy_y;
inset->getCursorPos(view(), inset_x, dummy_y);
#endif
- if (action == LFUN_UNKNOWN_ACTION
- && argument.empty()) {
+ if (action == LFUN_UNKNOWN_ACTION && argument.empty())
argument = encoded_last_key;
- }
// the insets can't try to handle this,
// a table cell in the dummy position will
}
// Hand-over to inset's own dispatch:
- result = inset->localDispatch(FuncRequest(view(), action, argument));
- if (result == DISPATCHED || result == DISPATCHED_NOUPDATE) {
+ result = inset->dispatch(FuncRequest(view(), action, argument));
+ if (result.dispatched()) {
+ if (result.update())
+ view()->update();
+
goto exit_with_message;
}
- // If UNDISPATCHED, just soldier on
- if (result == FINISHED) {
+ // If DispatchResult(false), just soldier on
+ if (result.val() == FINISHED) {
owner->clearMessage();
goto exit_with_message;
// We do not need special RTL handling here:
// one position after the inset.
}
- if (result == FINISHED_RIGHT) {
+ if (result.val() == FINISHED_RIGHT) {
view()->text->cursorRight(view());
moveCursorUpdate();
owner->clearMessage();
goto exit_with_message;
}
- if (result == FINISHED_UP) {
- RowList::iterator const irow = view()->text->cursorIRow();
- if (irow != view()->text->firstRow()) {
+ if (result.val() == FINISHED_UP) {
+ LyXText * text = view()->text;
+ ParagraphList::iterator pit = text->cursorPar();
+ Row const & row = *pit->getRow(text->cursor.pos());
+ if (text->isFirstRow(pit, row)) {
#if 1
- view()->text->setCursorFromCoordinates(
- view()->text->cursor.x() + inset_x,
- view()->text->cursor.y() -
- irow->baseline() - 1);
- view()->text->cursor.x_fix(view()->text->cursor.x());
+ text->setCursorFromCoordinates(
+ text->cursor.x() + inset_x,
+ text->cursor.y() -
+ row.baseline() - 1);
+ view()->x_target(text->cursor.x());
#else
- view()->text->cursorUp(view());
+ text->cursorUp(view());
#endif
moveCursorUpdate();
} else {
goto exit_with_message;
}
- if (result == FINISHED_DOWN) {
- RowList::iterator const irow = view()->text->cursorIRow();
- if (irow != view()->text->lastRow()) {
+ if (result.val() == FINISHED_DOWN) {
+ LyXText * text = view()->text;
+ ParagraphList::iterator pit = text->cursorPar();
+ Row const & row = *pit->getRow(text->cursor.pos());
+ if (text->isLastRow(pit, row)) {
#if 1
- view()->text->setCursorFromCoordinates(
- view()->text->cursor.x() + inset_x,
- view()->text->cursor.y() -
- irow->baseline() +
- irow->height() + 1);
- view()->text->cursor.x_fix(view()->text->cursor.x());
+ text->setCursorFromCoordinates(
+ text->cursor.x() + inset_x,
+ text->cursor.y() -
+ row.baseline() +
+ row.height() + 1);
+ view()->x_target(text->cursor.x());
#else
- view()->text->cursorDown(view());
+ text->cursorDown(view());
#endif
} else {
- view()->text->cursorRight(view());
+ text->cursorRight(view());
}
moveCursorUpdate();
owner->clearMessage();
}
#warning I am not sure this is still right, please have a look! (Jug 20020417)
- // result == UNDISPATCHED
+ // result == DispatchResult()
//setMessage(N_("Text mode"));
switch (action) {
case LFUN_UNKNOWN_ACTION:
owner->view_state_changed();
}
goto exit_with_message;
- case LFUN_DOWN:
- if (view()->text->cursorRow() != view()->text->lastRow())
+ case LFUN_DOWN: {
+ LyXText * text = view()->text;
+ ParagraphList::iterator pit = text->cursorPar();
+ if (text->isLastRow(pit, *pit->getRow(text->cursor.pos())))
view()->text->cursorDown(view());
else
view()->text->cursorRight(view());
moveCursorUpdate();
owner->view_state_changed();
goto exit_with_message;
+ }
default:
break;
}
}
bool fw = (action == LFUN_WORDFINDFORWARD);
if (!searched_string.empty())
- lyx::find::find(view(), searched_string, fw);
+ lyx::find::find(view(), searched_string,
+ true, false, fw);
break;
}
QuitLyX();
break;
- case LFUN_TOCVIEW:
- {
+ case LFUN_TOCVIEW: {
InsetCommandParams p("tableofcontents");
string const data = InsetCommandMailer::params2string("toc", p);
owner->getDialogs().show("toc", data, 0);
//#warning Find another implementation here (or another lyxfunc)!
#endif
#endif
- case LFUN_HELP_OPEN:
- {
+
+ case LFUN_HELP_OPEN: {
string const arg = argument;
if (arg.empty()) {
setErrorMessage(N_("Missing argument"));
// --- version control -------------------------------
case LFUN_VC_REGISTER:
- {
if (!ensureBufferClean(view()))
break;
if (!owner->buffer()->lyxvc().inUse()) {
owner->buffer()->lyxvc().registrer();
view()->reload();
}
- }
- break;
+ break;
case LFUN_VC_CHECKIN:
- {
if (!ensureBufferClean(view()))
break;
if (owner->buffer()->lyxvc().inUse()
owner->buffer()->lyxvc().checkIn();
view()->reload();
}
- }
- break;
+ break;
case LFUN_VC_CHECKOUT:
- {
if (!ensureBufferClean(view()))
break;
if (owner->buffer()->lyxvc().inUse()
owner->buffer()->lyxvc().checkOut();
view()->reload();
}
- }
- break;
+ break;
case LFUN_VC_REVERT:
- {
owner->buffer()->lyxvc().revert();
view()->reload();
- }
- break;
+ break;
case LFUN_VC_UNDO:
- {
owner->buffer()->lyxvc().undoLast();
view()->reload();
- }
- break;
+ break;
// --- buffers ----------------------------------------
open(argument);
break;
- case LFUN_LAYOUT_TABULAR:
- if (view()->theLockingInset()) {
- if (view()->theLockingInset()->lyxCode()== InsetOld::TABULAR_CODE) {
- InsetTabular * inset = static_cast<InsetTabular *>
- (view()->theLockingInset());
- inset->openLayoutDialog(view());
- } else if (view()->theLockingInset()->
- getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)!=0) {
- InsetTabular * inset = static_cast<InsetTabular *>(
- view()->theLockingInset()->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE));
- inset->openLayoutDialog(view());
+ case LFUN_LAYOUT_TABULAR: {
+ UpdatableInset * tli = view()->theLockingInset();
+ if (tli) {
+ if (tli->lyxCode() == InsetOld::TABULAR_CODE) {
+ static_cast<InsetTabular *>(tli)->openLayoutDialog(view());
+ } else if (tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE)) {
+ static_cast<InsetTabular *>(
+ tli->getFirstLockingInsetOfType(InsetOld::TABULAR_CODE))
+ ->openLayoutDialog(view());
+ }
}
- }
- break;
+ break;
+ }
case LFUN_DROP_LAYOUTS_CHOICE:
owner->getToolbar().openLayoutList();
break;
case LFUN_NOTIFY:
- {
dispatch_buffer = keyseq.print();
lyxserver->notifyClient(dispatch_buffer);
- }
- break;
+ break;
- case LFUN_GOTOFILEROW:
- {
+ case LFUN_GOTOFILEROW: {
string file_name;
int row;
- istringstream istr(argument.c_str());
- istr >> file_name >> row;
+ istringstream is(argument);
+ is >> file_name >> row;
if (prefixIs(file_name, getTmpDir())) {
// Needed by inverse dvi search. If it is a file
// in tmpdir, call the apropriated function
} else {
// Must replace extension of the file to be .lyx
// and get full path
- string const s(ChangeExtension(file_name, ".lyx"));
+ string const s = ChangeExtension(file_name, ".lyx");
// Either change buffer or load the file
if (bufferlist.exists(s)) {
view()->buffer(bufferlist.getBuffer(s));
view()->center();
// see BufferView_pimpl::center()
view()->updateScrollbar();
+ break;
}
- break;
-
- case LFUN_GOTO_PARAGRAPH:
- {
- istringstream istr(argument.c_str());
+ case LFUN_GOTO_PARAGRAPH: {
+ istringstream is(argument);
int id;
- istr >> id;
+ is >> id;
ParIterator par = owner->buffer()->getParFromID(id);
if (par == owner->buffer()->par_iterator_end()) {
lyxerr[Debug::INFO] << "No matching paragraph found! ["
if (view()->theLockingInset())
view()->unlockInset(view()->theLockingInset());
+
+ LyXText * lt = view()->getLyXText();
if (par->inInset()) {
FuncRequest cmd(view(), LFUN_INSET_EDIT, "left");
- par->inInset()->localDispatch(cmd);
+ par.inset()->dispatch(cmd);
+ lt = par->inInset()->getLyXText(view());
}
+
// Set the cursor
- view()->getLyXText()->setCursor(par.pit(), 0);
+ lt->setCursor(par.pit(), 0);
view()->switchKeyMap();
owner->view_state_changed();
case LFUN_MATH_NUMBER:
case LFUN_MATH_NONUMBER:
case LFUN_MATH_LIMITS:
- {
setErrorMessage(N_("This is only allowed in math mode!"));
- }
- break;
+ break;
// passthrough hat and underscore outside mathed:
case LFUN_SUBSCRIPT:
dispatch(FuncRequest(view(), LFUN_SELFINSERT, "_"));
break;
+
case LFUN_SUPERSCRIPT:
dispatch(FuncRequest(view(), LFUN_SELFINSERT, "^"));
break;
data = InsetCommandMailer::params2string(name, p);
}
owner->getDialogs().show(name, data, 0);
+ break;
}
- break;
- case LFUN_DIALOG_SHOW_NEXT_INSET: {
- }
- break;
+ case LFUN_DIALOG_SHOW_NEXT_INSET:
+ break;
case LFUN_INSET_DIALOG_SHOW: {
- LyXText * lt = view()->getLyXText();
- InsetOld * inset = lt->getInset();
- if (inset) {
- FuncRequest cmd(view(), LFUN_INSET_DIALOG_SHOW);
- inset->localDispatch(cmd);
- }
+ InsetOld * inset = view()->getLyXText()->getInset();
+ if (inset)
+ inset->dispatch(FuncRequest(view(), LFUN_INSET_DIALOG_SHOW));
+ break;
}
- break;
case LFUN_DIALOG_UPDATE: {
string const & name = argument;
if (inset) {
FuncRequest fr(view(), LFUN_INSET_DIALOG_UPDATE,
func.argument);
- inset->localDispatch(fr);
+ inset->dispatch(fr);
} else if (name == "paragraph") {
dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
}
+ break;
}
- break;
case LFUN_DIALOG_HIDE:
Dialogs::hide(argument, 0);
owner->getDialogs().disconnect(argument);
break;
- case LFUN_CHILDOPEN:
- {
+ case LFUN_CHILDOPEN: {
string const filename =
MakeAbsPath(argument, owner->buffer()->filePath());
setMessage(N_("Opening child document ") +
view()->buffer(bufferlist.getBuffer(filename));
else
view()->loadLyXFile(filename);
+ break;
}
- break;
case LFUN_TOGGLECURSORFOLLOW:
lyxrc.cursor_follows_scrollbar = !lyxrc.cursor_follows_scrollbar;
owner->getIntl().ToggleKeyMap();
break;
+ case LFUN_REPEAT: {
+ // repeat command
+ string countstr;
+ argument = split(argument, countstr, ' ');
+ istringstream is(countstr);
+ int count = 0;
+ is >> count;
+ lyxerr << "repeat: count: " << count << " cmd: " << argument << endl;
+ for (int i = 0; i < count; ++i)
+ dispatch(lyxaction.lookupFunc(argument));
+ break;
+ }
+
case LFUN_SEQUENCE:
- {
// argument contains ';'-terminated commands
while (!argument.empty()) {
string first;
argument = split(argument, first, ';');
dispatch(lyxaction.lookupFunc(first));
}
- }
- break;
+ break;
- case LFUN_SAVEPREFERENCES:
- {
+ case LFUN_SAVEPREFERENCES: {
Path p(user_lyxdir());
lyxrc.write("preferences");
+ break;
}
- break;
case LFUN_SCREEN_FONT_UPDATE:
- {
// handle the screen font changes.
lyxrc.set_font_norm_type();
lyx_gui::update_fonts();
- // We also need to empty the textcache so that
- // the buffer will be formatted correctly after
- // a zoom change.
- textcache.clear();
- // Of course we should only do the resize and the textcache.clear
- // if values really changed...but not very important right now. (Lgb)
// All visible buffers will need resize
view()->resize();
view()->update();
- }
- break;
+ break;
- case LFUN_SET_COLOR:
- {
+ case LFUN_SET_COLOR: {
string lyx_name;
string const x11_name = split(argument, lyx_name, ' ');
if (lyx_name.empty() || x11_name.empty()) {
setErrorMessage(N_("Syntax: set-color <lyx_name>"
" <x11_name>"));
break;
- }
+ }
bool const graphicsbg_changed =
(lyx_name == lcolor.getLyXName(LColor::graphicsbg) &&
#warning FIXME!! The graphics cache no longer has a changeDisplay method.
#endif
#if 0
- lyx::graphics::GCache & gc =
- lyx::graphics::GCache::get();
- gc.changeDisplay(true);
+ lyx::graphics::GCache::get().changeDisplay(true);
#endif
}
break;
case LFUN_FORKS_KILL:
- {
- if (!isStrInt(argument))
- break;
-
- pid_t const pid = strToInt(argument);
- ForkedcallsController & fcc = ForkedcallsController::get();
- fcc.kill(pid);
+ if (isStrInt(argument)) {
+ pid_t const pid = strToInt(argument);
+ ForkedcallsController & fcc = ForkedcallsController::get();
+ fcc.kill(pid);
+ }
break;
- }
case LFUN_TOOLTIPS_TOGGLE:
owner->getDialogs().toggleTooltips();
break;
- case LFUN_EXTERNAL_EDIT: {
- InsetExternal().localDispatch(FuncRequest(view(), action, argument));
+ case LFUN_EXTERNAL_EDIT:
+ InsetExternal().dispatch(FuncRequest(view(), action, argument));
break;
- }
default:
// Then if it was none of the above