handle most of InsetText::dispatch() to LyXText::dispatch

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8095 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-11-17 14:51:36 +00:00
parent 6c38a862ab
commit 2ff4eaba84
2 changed files with 12 additions and 215 deletions

View File

@ -431,171 +431,6 @@ DispatchResult InsetText::priv_dispatch(FuncRequest const & cmd,
result = DispatchResult(true, true);
break;
case LFUN_SELFINSERT:
if (bv->buffer()->isReadonly()) {
// setErrorMessage(N_("Document is read only"));
break;
}
if (!cmd.argument.empty()) {
/* Automatically delete the currently selected
* text and replace it with what is being
* typed in now. Depends on lyxrc settings
* "auto_region_delete", which defaults to
* true (on). */
#if 0
// This should not be needed here and is also WRONG!
recordUndo(bv, Undo::INSERT, text_.cursorPar());
#endif
bv->switchKeyMap();
if (lyxrc.auto_region_delete && text_.selection.set())
text_.cutSelection(false, false);
text_.clearSelection();
for (string::size_type i = 0; i < cmd.argument.length(); ++i)
bv->owner()->getIntl().getTransManager().
TranslateAndInsert(cmd.argument[i], &text_);
}
text_.selection.cursor = text_.cursor;
result.dispatched(true);
result.update(true);
break;
case LFUN_RIGHT:
result = text_.moveRight();
finishUndo();
break;
case LFUN_LEFT:
finishUndo();
result = text_.moveLeft();
break;
case LFUN_DOWN:
finishUndo();
result = text_.moveDown();
break;
case LFUN_UP:
finishUndo();
result = text_.moveUp();
break;
case LFUN_PRIOR:
if (crow() == text_.firstRow()) {
result.val(FINISHED_UP);
} else {
text_.cursorPrevious();
text_.clearSelection();
result.dispatched(true);
}
break;
case LFUN_NEXT:
if (crow() == text_.lastRow()) {
result.val(FINISHED_DOWN);
} else {
text_.cursorNext();
text_.clearSelection();
result.dispatched(true);
}
break;
case LFUN_BACKSPACE:
if (text_.selection.set())
text_.cutSelection(true, false);
else
text_.backspace();
#warning should be also set dispatched here?
result.update(true);
break;
case LFUN_DELETE:
if (text_.selection.set())
text_.cutSelection(true, false);
else
text_.Delete();
#warning should be also set dispatched here?
result.update(true);
break;
case LFUN_BREAKPARAGRAPH:
if (!autoBreakRows_) {
result.dispatched(true);
result.update(true);
} else {
replaceSelection(bv->getLyXText());
text_.breakParagraph(paragraphs, 0);
#warning should be also set dispatched here?
result.update(true);
}
break;
case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
if (!autoBreakRows_) {
result.dispatched(true);
result.update(true);
} else {
replaceSelection(bv->getLyXText());
text_.breakParagraph(paragraphs, 1);
#warning should be also set dispatched here?
result.update(true);
}
break;
case LFUN_BREAKLINE: {
if (!autoBreakRows_) {
result.dispatched(true);
result.update(true);
} else {
replaceSelection(bv->getLyXText());
auto_ptr<InsetNewline> ins(new InsetNewline);
text_.insertInset(ins.release());
#warning should be also set dispatched here?
result.update(true);
}
break;
}
case LFUN_LAYOUT:
// do not set layouts on non breakable textinsets
if (autoBreakRows_) {
string cur_layout = cpar()->layout()->name();
// Derive layout number from given argument (string)
// and current buffer's textclass (number).
LyXTextClass const & tclass =
bv->buffer()->params().getLyXTextClass();
string layout = cmd.argument;
bool hasLayout = tclass.hasLayout(layout);
// If the entry is obsolete, use the new one instead.
if (hasLayout) {
string const & obs = tclass[layout]->obsoleted_by();
if (!obs.empty())
layout = obs;
}
// see if we found the layout number:
if (!hasLayout) {
FuncRequest lf(LFUN_MESSAGE, N_("Layout ") + cmd.argument + N_(" not known"));
bv->owner()->dispatch(lf);
break;
}
if (cur_layout != layout) {
cur_layout = layout;
text_.setLayout(layout);
bv->owner()->setLayout(cpar()->layout()->name());
#warning should be also set dispatched here?
result.update(true);
}
} else {
// reset the layout box
bv->owner()->setLayout(cpar()->layout()->name());
}
break;
default:
result = text_.dispatch(cmd);
break;

View File

@ -707,63 +707,21 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
break;
}
case LFUN_RIGHT: {
bool is_rtl = rtl();
if (!selection.mark())
clearSelection();
if (is_rtl)
cursorLeft(false);
if (cursor.pos() < cursorPar()->size()
&& cursorPar()->isInset(cursor.pos())
&& isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
cmd.message(tmpinset->editMessage());
tmpinset->edit(bv, !is_rtl);
break;
}
if (!is_rtl)
cursorRight(false);
case LFUN_RIGHT:
finishChange(bv);
break;
}
return moveRight();
case LFUN_LEFT: {
// This is soooo ugly. Isn't it possible to make
// it simpler? (Lgb)
bool const is_rtl = rtl();
if (!selection.mark())
clearSelection();
LyXCursor const cur = cursor;
if (!is_rtl)
cursorLeft(false);
if ((is_rtl || cur != cursor) && // only if really moved!
cursor.pos() < cursorPar()->size() &&
cursorPar()->isInset(cursor.pos()) &&
isHighlyEditableInset(cursorPar()->getInset(cursor.pos()))) {
InsetOld * tmpinset = cursorPar()->getInset(cursor.pos());
cmd.message(tmpinset->editMessage());
tmpinset->edit(bv, is_rtl);
break;
}
if (is_rtl)
cursorRight(false);
case LFUN_LEFT:
finishChange(bv);
break;
}
return moveLeft();
case LFUN_UP:
if (!selection.mark())
clearSelection();
cursorUp(false);
finishChange(bv);
break;
return moveUp();
case LFUN_DOWN:
if (!selection.mark())
clearSelection();
cursorDown(false);
finishChange(bv);
break;
return moveDown();
case LFUN_UP_PARAGRAPH:
if (!selection.mark())
@ -782,15 +740,19 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
case LFUN_PRIOR:
if (!selection.mark())
clearSelection();
cursorPrevious();
finishChange(bv, false);
if (cursorRow() == firstRow())
return DispatchResult(false, FINISHED_UP);
cursorPrevious();
break;
case LFUN_NEXT:
if (!selection.mark())
clearSelection();
cursorNext();
finishChange(bv, false);
if (cursorRow() == lastRow())
return DispatchResult(false, FINISHED_DOWN);
cursorNext();
break;
case LFUN_HOME: