shift some text related stuff from BufferView::dispatch to LyXText

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8411 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2004-02-06 13:59:26 +00:00
parent 09e11f4d38
commit 3f01b19844
6 changed files with 152 additions and 240 deletions

View File

@ -428,12 +428,6 @@ int BufferView::workHeight() const
} }
void BufferView::updateParagraphDialog()
{
pimpl_->updateParagraphDialog();
}
LyXText * BufferView::text() const LyXText * BufferView::text() const
{ {
return pimpl_->buffer_ ? &pimpl_->buffer_->text() : 0; return pimpl_->buffer_ ? &pimpl_->buffer_->text() : 0;

View File

@ -111,9 +111,6 @@ public:
/// return the lyxtext we are using /// return the lyxtext we are using
LyXText * getLyXText() const; LyXText * getLyXText() const;
/// update paragraph dialogs
void updateParagraphDialog();
/// return the current encoding at the cursor /// return the current encoding at the cursor
Encoding const * getEncoding() const; Encoding const * getEncoding() const;

View File

@ -1046,36 +1046,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
} }
break; break;
// --- accented characters ---------------------------
case LFUN_UMLAUT:
case LFUN_CIRCUMFLEX:
case LFUN_GRAVE:
case LFUN_ACUTE:
case LFUN_TILDE:
case LFUN_CEDILLA:
case LFUN_MACRON:
case LFUN_DOT:
case LFUN_UNDERDOT:
case LFUN_UNDERBAR:
case LFUN_CARON:
case LFUN_SPECIAL_CARON:
case LFUN_BREVE:
case LFUN_TIE:
case LFUN_HUNG_UMLAUT:
case LFUN_CIRCLE:
case LFUN_OGONEK:
if (cmd.argument.empty()) {
// As always...
owner_->getLyXFunc().handleKeyFunc(cmd.action);
} else {
owner_->getLyXFunc().handleKeyFunc(cmd.action);
owner_->getIntl().getTransManager()
.TranslateAndInsert(cmd.argument[0], bv_->getLyXText());
update();
}
break;
case LFUN_FLOAT_LIST: case LFUN_FLOAT_LIST:
if (tclass.floats().typeExist(cmd.argument)) { if (tclass.floats().typeExist(cmd.argument)) {
InsetBase * inset = new InsetFloatList(cmd.argument); InsetBase * inset = new InsetFloatList(cmd.argument);
@ -1102,18 +1072,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
} }
break; break;
case LFUN_LAYOUT_PARAGRAPH: {
string data;
params2string(*bv_->getLyXText()->cursorPar(), data);
data = "show\n" + data;
bv_->owner()->getDialogs().show("paragraph", data);
break;
}
case LFUN_PARAGRAPH_UPDATE:
updateParagraphDialog();
break;
case LFUN_PARAGRAPH_APPLY: case LFUN_PARAGRAPH_APPLY:
setParagraphParams(*bv_, cmd.argument); setParagraphParams(*bv_, cmd.argument);
break; break;
@ -1259,23 +1217,3 @@ bool BufferView::Pimpl::ChangeInsets(InsetBase::Code code,
bv_->text()->setCursorIntern(cur.par(), cur.pos()); bv_->text()->setCursorIntern(cur.par(), cur.pos());
return need_update; return need_update;
} }
void BufferView::Pimpl::updateParagraphDialog()
{
if (!bv_->owner()->getDialogs().visible("paragraph"))
return;
CursorSlice const & cur = bv_->cursor().innerTextSlice();
LyXText * text = bv_->cursor().innerText();
Paragraph const & par = *text->getPar(cur.par());
string data;
params2string(par, data);
// Will the paragraph accept changes from the dialog?
InsetBase * const inset = cur.inset();
bool const accept =
!(inset && inset->forceDefaultParagraphs(inset));
data = "update " + tostr(accept) + '\n' + data;
bv_->owner()->getDialogs().update("paragraph", data);
}

View File

@ -109,8 +109,6 @@ struct BufferView::Pimpl : public boost::signals::trackable {
int top_y() const; int top_y() const;
/// ///
void top_y(int y); void top_y(int y);
/// update paragraph dialogs
void updateParagraphDialog();
private: private:
/// the y coordinate of the top of the screen /// the y coordinate of the top of the screen
int top_y_; int top_y_;

View File

@ -296,7 +296,7 @@ void InsetText::edit(LCursor & cur, bool left)
finishUndo(); finishUndo();
sanitizeEmptyText(cur.bv()); sanitizeEmptyText(cur.bv());
updateLocal(cur); updateLocal(cur);
cur.bv().updateParagraphDialog(); dispatch(cur, FuncRequest(LFUN_PARAGRAPH_UPDATE));
} }

View File

@ -28,6 +28,7 @@
#include "gettext.h" #include "gettext.h"
#include "intl.h" #include "intl.h"
#include "language.h" #include "language.h"
#include "lyxfunc.h"
#include "lyxrc.h" #include "lyxrc.h"
#include "lyxrow.h" #include "lyxrow.h"
#include "paragraph.h" #include "paragraph.h"
@ -105,114 +106,6 @@ namespace {
} }
/// Apply the contents of freefont at the current cursor location.
void apply_freefont(BufferView * bv, LyXText * text)
{
toggleAndShow(bv, text, freefont, toggleall);
bv->owner()->view_state_changed();
bv->owner()->message(_("Character set"));
}
/** Set the freefont using the contents of \param data dispatched from
* the frontends and apply it at the current cursor location.
*/
void update_and_apply_freefont(BufferView * bv, LyXText * text,
string const & data)
{
LyXFont font;
bool toggle;
if (bv_funcs::string2font(data, font, toggle)) {
freefont = font;
toggleall = toggle;
apply_freefont(bv, text);
}
}
void emph(BufferView * bv, LyXText * text)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setEmph(LyXFont::TOGGLE);
toggleAndShow(bv, text, font);
}
void bold(BufferView * bv, LyXText * text)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setSeries(LyXFont::BOLD_SERIES);
toggleAndShow(bv, text, font);
}
void noun(BufferView * bv, LyXText * text)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setNoun(LyXFont::TOGGLE);
toggleAndShow(bv, text, font);
}
void lang(BufferView * bv, string const & l, LyXText * text)
{
Language const * lang = languages.getLanguage(l);
if (!lang)
return;
LyXFont font(LyXFont::ALL_IGNORE);
font.setLanguage(lang);
toggleAndShow(bv, text, font);
}
void code(BufferView * bv, LyXText * text)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
toggleAndShow(bv, text, font);
}
void sans(BufferView * bv, LyXText * text)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setFamily(LyXFont::SANS_FAMILY);
toggleAndShow(bv, text, font);
}
void roman(BufferView * bv, LyXText * text)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setFamily(LyXFont::ROMAN_FAMILY);
toggleAndShow(bv, text, font);
}
void styleReset(BufferView * bv, LyXText * text)
{
LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
toggleAndShow(bv, text, font);
}
void underline(BufferView * bv, LyXText * text)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setUnderbar(LyXFont::TOGGLE);
toggleAndShow(bv, text, font);
}
void fontSize(BufferView * bv, string const & size, LyXText * text)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setLyXSize(size);
toggleAndShow(bv, text, font);
}
void moveCursor(LCursor & cur, bool selecting) void moveCursor(LCursor & cur, bool selecting)
{ {
if (selecting || cur.mark()) if (selecting || cur.mark())
@ -223,11 +116,11 @@ namespace {
} }
void finishChange(BufferView * bv, bool selecting = false) void finishChange(LCursor & cur, bool selecting = false)
{ {
finishUndo(); finishUndo();
moveCursor(bv->cursor(), selecting); moveCursor(cur, selecting);
bv->owner()->view_state_changed(); cur.bv().owner()->view_state_changed();
} }
} // anon namespace } // anon namespace
@ -480,19 +373,19 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_DELETE_WORD_FORWARD: case LFUN_DELETE_WORD_FORWARD:
cur.clearSelection(); cur.clearSelection();
deleteWordForward(); deleteWordForward();
finishChange(bv); finishChange(cur);
break; break;
case LFUN_DELETE_WORD_BACKWARD: case LFUN_DELETE_WORD_BACKWARD:
cur.clearSelection(); cur.clearSelection();
deleteWordBackward(); deleteWordBackward();
finishChange(bv); finishChange(cur);
break; break;
case LFUN_DELETE_LINE_FORWARD: case LFUN_DELETE_LINE_FORWARD:
cur.clearSelection(); cur.clearSelection();
deleteLineForward(); deleteLineForward();
finishChange(bv); finishChange(cur);
break; break;
case LFUN_WORDRIGHT: case LFUN_WORDRIGHT:
@ -502,7 +395,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
cursorLeftOneWord(); cursorLeftOneWord();
else else
cursorRightOneWord(); cursorRightOneWord();
finishChange(bv); finishChange(cur);
break; break;
case LFUN_WORDLEFT: case LFUN_WORDLEFT:
@ -512,21 +405,21 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
cursorRightOneWord(); cursorRightOneWord();
else else
cursorLeftOneWord(); cursorLeftOneWord();
finishChange(bv); finishChange(cur);
break; break;
case LFUN_BEGINNINGBUF: case LFUN_BEGINNINGBUF:
if (!cur.mark()) if (!cur.mark())
cur.clearSelection(); cur.clearSelection();
cursorTop(); cursorTop();
finishChange(bv); finishChange(cur);
break; break;
case LFUN_ENDBUF: case LFUN_ENDBUF:
if (!cur.mark()) if (!cur.mark())
cur.clearSelection(); cur.clearSelection();
cursorBottom(); cursorBottom();
finishChange(bv); finishChange(cur);
break; break;
case LFUN_RIGHTSEL: case LFUN_RIGHTSEL:
@ -536,7 +429,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
cursorLeft(true); cursorLeft(true);
else else
cursorRight(true); cursorRight(true);
finishChange(bv, true); finishChange(cur, true);
break; break;
case LFUN_LEFTSEL: case LFUN_LEFTSEL:
@ -546,63 +439,63 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
cursorRight(true); cursorRight(true);
else else
cursorLeft(true); cursorLeft(true);
finishChange(bv, true); finishChange(cur, true);
break; break;
case LFUN_UPSEL: case LFUN_UPSEL:
if (!cur.selection()) if (!cur.selection())
cur.resetAnchor(); cur.resetAnchor();
cursorUp(true); cursorUp(true);
finishChange(bv, true); finishChange(cur, true);
break; break;
case LFUN_DOWNSEL: case LFUN_DOWNSEL:
if (!cur.selection()) if (!cur.selection())
cur.resetAnchor(); cur.resetAnchor();
cursorDown(true); cursorDown(true);
finishChange(bv, true); finishChange(cur, true);
break; break;
case LFUN_UP_PARAGRAPHSEL: case LFUN_UP_PARAGRAPHSEL:
if (!cur.selection()) if (!cur.selection())
cur.resetAnchor(); cur.resetAnchor();
cursorUpParagraph(); cursorUpParagraph();
finishChange(bv, true); finishChange(cur, true);
break; break;
case LFUN_DOWN_PARAGRAPHSEL: case LFUN_DOWN_PARAGRAPHSEL:
if (!cur.selection()) if (!cur.selection())
cur.resetAnchor(); cur.resetAnchor();
cursorDownParagraph(); cursorDownParagraph();
finishChange(bv, true); finishChange(cur, true);
break; break;
case LFUN_PRIORSEL: case LFUN_PRIORSEL:
if (!cur.selection()) if (!cur.selection())
cur.resetAnchor(); cur.resetAnchor();
cursorPrevious(); cursorPrevious();
finishChange(bv, true); finishChange(cur, true);
break; break;
case LFUN_NEXTSEL: case LFUN_NEXTSEL:
if (!cur.selection()) if (!cur.selection())
cur.resetAnchor(); cur.resetAnchor();
cursorNext(); cursorNext();
finishChange(bv, true); finishChange(cur, true);
break; break;
case LFUN_HOMESEL: case LFUN_HOMESEL:
if (!cur.selection()) if (!cur.selection())
cur.resetAnchor(); cur.resetAnchor();
cursorHome(); cursorHome();
finishChange(bv, true); finishChange(cur, true);
break; break;
case LFUN_ENDSEL: case LFUN_ENDSEL:
if (!cur.selection()) if (!cur.selection())
cur.resetAnchor(); cur.resetAnchor();
cursorEnd(); cursorEnd();
finishChange(bv, true); finishChange(cur, true);
break; break;
case LFUN_WORDRIGHTSEL: case LFUN_WORDRIGHTSEL:
@ -612,7 +505,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
cursorLeftOneWord(); cursorLeftOneWord();
else else
cursorRightOneWord(); cursorRightOneWord();
finishChange(bv, true); finishChange(cur, true);
break; break;
case LFUN_WORDLEFTSEL: case LFUN_WORDLEFTSEL:
@ -622,49 +515,49 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
cursorRightOneWord(); cursorRightOneWord();
else else
cursorLeftOneWord(); cursorLeftOneWord();
finishChange(bv, true); finishChange(cur, true);
break; break;
case LFUN_WORDSEL: { case LFUN_WORDSEL: {
selectWord(lyx::WHOLE_WORD); selectWord(lyx::WHOLE_WORD);
finishChange(bv, true); finishChange(cur, true);
break; break;
} }
case LFUN_RIGHT: case LFUN_RIGHT:
finishChange(bv); finishChange(cur);
return moveRight(); return moveRight();
case LFUN_LEFT: case LFUN_LEFT:
finishChange(bv); finishChange(cur);
return moveLeft(); return moveLeft();
case LFUN_UP: case LFUN_UP:
finishChange(bv); finishChange(cur);
return moveUp(); return moveUp();
case LFUN_DOWN: case LFUN_DOWN:
finishChange(bv); finishChange(cur);
return moveDown(); return moveDown();
case LFUN_UP_PARAGRAPH: case LFUN_UP_PARAGRAPH:
if (!cur.mark()) if (!cur.mark())
cur.clearSelection(); cur.clearSelection();
cursorUpParagraph(); cursorUpParagraph();
finishChange(bv); finishChange(cur);
break; break;
case LFUN_DOWN_PARAGRAPH: case LFUN_DOWN_PARAGRAPH:
if (!cur.mark()) if (!cur.mark())
cur.clearSelection(); cur.clearSelection();
cursorDownParagraph(); cursorDownParagraph();
finishChange(bv, false); finishChange(cur, false);
break; break;
case LFUN_PRIOR: case LFUN_PRIOR:
if (!cur.mark()) if (!cur.mark())
cur.clearSelection(); cur.clearSelection();
finishChange(bv, false); finishChange(cur, false);
if (cur.par() == 0 && cursorRow() == firstRow()) if (cur.par() == 0 && cursorRow() == firstRow())
return DispatchResult(false, FINISHED_UP); return DispatchResult(false, FINISHED_UP);
cursorPrevious(); cursorPrevious();
@ -673,7 +566,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_NEXT: case LFUN_NEXT:
if (!cur.mark()) if (!cur.mark())
cur.clearSelection(); cur.clearSelection();
finishChange(bv, false); finishChange(cur, false);
if (cur.par() == cur.lastpar() && cursorRow() == lastRow()) if (cur.par() == cur.lastpar() && cursorRow() == lastRow())
return DispatchResult(false, FINISHED_DOWN); return DispatchResult(false, FINISHED_DOWN);
cursorNext(); cursorNext();
@ -683,14 +576,14 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
if (!cur.mark()) if (!cur.mark())
cur.clearSelection(); cur.clearSelection();
cursorHome(); cursorHome();
finishChange(bv, false); finishChange(cur, false);
break; break;
case LFUN_END: case LFUN_END:
if (!cur.mark()) if (!cur.mark())
cur.clearSelection(); cur.clearSelection();
cursorEnd(); cursorEnd();
finishChange(bv, false); finishChange(cur, false);
break; break;
case LFUN_BREAKLINE: { case LFUN_BREAKLINE: {
@ -960,7 +853,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
if (!cur.selection()) if (!cur.selection())
cur.resetAnchor(); cur.resetAnchor();
cursorTop(); cursorTop();
finishChange(bv, true); finishChange(cur, true);
break; break;
case LFUN_ENDBUFSEL: case LFUN_ENDBUFSEL:
@ -969,7 +862,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
if (!cur.selection()) if (!cur.selection())
cur.resetAnchor(); cur.resetAnchor();
cursorBottom(); cursorBottom();
finishChange(bv, true); finishChange(cur, true);
break; break;
case LFUN_GETXY: case LFUN_GETXY:
@ -1401,64 +1294,109 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
mathDispatch(cur, cmd); mathDispatch(cur, cmd);
break; break;
case LFUN_EMPH: case LFUN_EMPH: {
emph(bv, this); LyXFont font(LyXFont::ALL_IGNORE);
font.setEmph(LyXFont::TOGGLE);
toggleAndShow(bv, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
}
case LFUN_BOLD: case LFUN_BOLD: {
bold(bv, this); LyXFont font(LyXFont::ALL_IGNORE);
font.setSeries(LyXFont::BOLD_SERIES);
toggleAndShow(bv, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
}
case LFUN_NOUN: case LFUN_NOUN: {
noun(bv, this); LyXFont font(LyXFont::ALL_IGNORE);
font.setNoun(LyXFont::TOGGLE);
toggleAndShow(bv, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
}
case LFUN_CODE: case LFUN_CODE: {
code(bv, this); LyXFont font(LyXFont::ALL_IGNORE);
font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
toggleAndShow(bv, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
}
case LFUN_SANS: case LFUN_SANS: {
sans(bv, this); LyXFont font(LyXFont::ALL_IGNORE);
font.setFamily(LyXFont::SANS_FAMILY);
toggleAndShow(bv, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
}
case LFUN_ROMAN: case LFUN_ROMAN: {
roman(bv, this); LyXFont font(LyXFont::ALL_IGNORE);
font.setFamily(LyXFont::ROMAN_FAMILY);
toggleAndShow(bv, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
}
case LFUN_DEFAULT: case LFUN_DEFAULT: {
styleReset(bv, this); LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
toggleAndShow(bv, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
}
case LFUN_UNDERLINE: case LFUN_UNDERLINE: {
underline(bv, this); LyXFont font(LyXFont::ALL_IGNORE);
font.setUnderbar(LyXFont::TOGGLE);
toggleAndShow(bv, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
}
case LFUN_FONT_SIZE: case LFUN_FONT_SIZE: {
fontSize(bv, cmd.argument, this); LyXFont font(LyXFont::ALL_IGNORE);
font.setLyXSize(cmd.argument);
toggleAndShow(bv, this, font);
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
}
case LFUN_LANGUAGE: case LFUN_LANGUAGE: {
lang(bv, cmd.argument, this); Language const * lang = languages.getLanguage(cmd.argument);
if (!lang)
break;
LyXFont font(LyXFont::ALL_IGNORE);
font.setLanguage(lang);
toggleAndShow(bv, this, font);
bv->switchKeyMap(); bv->switchKeyMap();
bv->owner()->view_state_changed(); bv->owner()->view_state_changed();
break; break;
}
case LFUN_FREEFONT_APPLY: case LFUN_FREEFONT_APPLY:
apply_freefont(bv, this); toggleAndShow(bv, this, freefont, toggleall);
bv->owner()->view_state_changed();
bv->owner()->message(_("Character set"));
break; break;
case LFUN_FREEFONT_UPDATE: // Set the freefont using the contents of \param data dispatched from
update_and_apply_freefont(bv, this, cmd.argument); // the frontends and apply it at the current cursor location.
case LFUN_FREEFONT_UPDATE: {
LyXFont font;
bool toggle;
if (bv_funcs::string2font(cmd.argument, font, toggle)) {
freefont = font;
toggleall = toggle;
toggleAndShow(bv, this, freefont, toggleall);
bv->owner()->view_state_changed();
bv->owner()->message(_("Character set"));
}
break; break;
}
case LFUN_FINISHED_LEFT: case LFUN_FINISHED_LEFT:
lyxerr << "handle LFUN_FINISHED_LEFT" << endl; lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
@ -1490,6 +1428,53 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
cursorDown(true); cursorDown(true);
break; break;
case LFUN_LAYOUT_PARAGRAPH: {
string data;
params2string(cur.paragraph(), data);
data = "show\n" + data;
bv->owner()->getDialogs().show("paragraph", data);
break;
}
case LFUN_PARAGRAPH_UPDATE: {
if (!bv->owner()->getDialogs().visible("paragraph"))
break;
string data;
params2string(cur.paragraph(), data);
// Will the paragraph accept changes from the dialog?
InsetBase * const inset = cur.inset();
bool const accept =
!(inset && inset->forceDefaultParagraphs(inset));
data = "update " + tostr(accept) + '\n' + data;
bv->owner()->getDialogs().update("paragraph", data);
break;
}
case LFUN_UMLAUT:
case LFUN_CIRCUMFLEX:
case LFUN_GRAVE:
case LFUN_ACUTE:
case LFUN_TILDE:
case LFUN_CEDILLA:
case LFUN_MACRON:
case LFUN_DOT:
case LFUN_UNDERDOT:
case LFUN_UNDERBAR:
case LFUN_CARON:
case LFUN_SPECIAL_CARON:
case LFUN_BREVE:
case LFUN_TIE:
case LFUN_HUNG_UMLAUT:
case LFUN_CIRCLE:
case LFUN_OGONEK:
bv->owner()->getLyXFunc().handleKeyFunc(cmd.action);
if (!cmd.argument.empty())
bv->owner()->getIntl().getTransManager()
.TranslateAndInsert(cmd.argument[0], this);
break;
default: default:
return DispatchResult(false); return DispatchResult(false);
} }