bug + spped fixes + small stuff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8421 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2004-02-11 14:45:44 +00:00
parent fcc19bf137
commit 2a5bc90633
22 changed files with 260 additions and 393 deletions

View File

@ -322,34 +322,6 @@ void BufferView::gotoLabel(string const & label)
}
void BufferView::undo()
{
if (!available())
return;
owner()->message(_("Undo"));
cursor().clearSelection();
if (!textUndo(*this))
owner()->message(_("No further undo information"));
update();
switchKeyMap();
}
void BufferView::redo()
{
if (!available())
return;
owner()->message(_("Redo"));
cursor().clearSelection();
if (!textRedo(*this))
owner()->message(_("No further redo information"));
update();
switchKeyMap();
}
void BufferView::replaceWord(string const & replacestring)
{
if (!available())

View File

@ -125,11 +125,6 @@ public:
/// move cursor to the named label
void gotoLabel(std::string const & label);
/// undo last action
void undo();
/// redo last action
void redo();
/// get the stored error list
ErrorList const & getErrorList() const;
/// show the error list to the user

View File

@ -549,7 +549,7 @@ void BufferView::Pimpl::selectionRequested()
xsel_cache_.cursor = cur.cursor_.back();
xsel_cache_.anchor = cur.anchor_.back();
xsel_cache_.set = cur.selection();
sel = bv_->getLyXText()->selectionAsString(*bv_->buffer(), false);
sel = cur.selectionAsString(false);
if (!sel.empty())
workarea().putClipboard(sel);
}
@ -578,11 +578,9 @@ void BufferView::Pimpl::workAreaResize()
work_area_width = workarea().workWidth();
work_area_height = workarea().workHeight();
if (buffer_ != 0) {
if (widthChange) {
// The visible LyXView need a resize
resizeCurrentBuffer();
}
if (buffer_ && widthChange) {
// The visible LyXView need a resize
resizeCurrentBuffer();
}
if (widthChange || heightChange)
@ -907,7 +905,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
}
if (fitCursor() || res.update()) {
bv_->update();
update();
cur.updatePos();
}
return true;
@ -950,7 +948,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
DispatchResult res = cur.dispatch(cmd);
if (fitCursor() || res.update())
bv_->update();
update();
// see workAreaKeyPress
cursor_timeout.restart();
@ -993,10 +991,26 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
switch (cmd.action) {
case LFUN_SCROLL_INSET:
// this is not handled here as this function is only active
// if we have a locking_inset and that one is (or contains)
// a tabular-inset
case LFUN_UNDO:
if (available()) {
cur.message(_("Undo"));
cur.clearSelection();
if (!textUndo(*bv_))
cur.message(_("No further undo information"));
update();
switchKeyMap();
}
break;
case LFUN_REDO:
if (available()) {
cur.message(_("Redo"));
cur.clearSelection();
if (!textRedo(*bv_))
cur.message(_("No further redo information"));
update();
switchKeyMap();
}
break;
case LFUN_FILE_INSERT:
@ -1083,14 +1097,12 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
string arg = cmd.argument;
if (arg.empty()) {
arg = bv_->getLyXText()->selectionAsString(*buffer_,
false);
arg = cur.selectionAsString(false);
// FIXME
if (arg.size() > 100 || arg.empty()) {
// Get word or selection
bv_->getLyXText()->selectWordWhenUnderCursor(lyx::WHOLE_WORD);
arg = bv_->getLyXText()->selectionAsString(*buffer_, false);
arg = cur.selectionAsString(false);
// FIXME: where is getLyXText()->unselect(bv_) ?
}
}
@ -1147,7 +1159,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
case LFUN_MARK_OFF:
cur.clearSelection();
bv_->update();
update();
cur.resetAnchor();
cur.message(N_("Mark off"));
break;
@ -1155,7 +1167,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
case LFUN_MARK_ON:
cur.clearSelection();
cur.mark() = true;
bv_->update();
update();
cur.resetAnchor();
cur.message(N_("Mark on"));
break;
@ -1169,7 +1181,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
cur.message(N_("Mark set"));
}
cur.resetAnchor();
bv_->update();
update();
break;
case LFUN_UNKNOWN_ACTION:

View File

@ -487,8 +487,8 @@ void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
++pos;
space_inserted = true;
} else {
const pos_type nb = 8 - pos % 8;
for (pos_type a = 0; a < nb ; ++a) {
const pos_type n = 8 - pos % 8;
for (pos_type i = 0; i < n; ++i) {
par->insertChar(pos, ' ', font);
++pos;
}
@ -531,7 +531,6 @@ bool Buffer::readFile(string const & filename, ParagraphList::iterator pit)
{
LyXLex lex(0, 0);
lex.setFile(filename);
return readFile(lex, filename, pit);
}
@ -711,9 +710,8 @@ bool Buffer::save() const
removeAutosaveFile(fileName());
} else {
// Saving failed, so backup is not backup
if (lyxrc.make_backup) {
if (lyxrc.make_backup)
rename(s, fileName());
}
return false;
}
return true;
@ -722,20 +720,17 @@ bool Buffer::save() const
bool Buffer::writeFile(string const & fname) const
{
if (pimpl_->read_only && (fname == fileName())) {
if (pimpl_->read_only && fname == fileName())
return false;
}
FileInfo finfo(fname);
if (finfo.exist() && !finfo.writable()) {
if (finfo.exist() && !finfo.writable())
return false;
}
bool retval;
if (params().compressed) {
gz::ogzstream ofs(fname.c_str());
if (!ofs)
return false;
@ -755,7 +750,6 @@ bool Buffer::writeFile(string const & fname) const
bool Buffer::do_writeFile(ostream & ofs) const
{
#ifdef HAVE_LOCALE
// Use the standard "C" locale for file output.
ofs.imbue(std::locale::classic());
@ -791,16 +785,9 @@ bool Buffer::do_writeFile(ostream & ofs) const
// which should include file system full errors.
bool status = true;
if (!ofs.good()) {
if (!ofs) {
status = false;
#if 0
if (ofs.bad()) {
lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
} else {
lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
<< endl;
}
#endif
lyxerr << "File was not closed properly." << endl;
}
return status;
@ -822,9 +809,8 @@ void Buffer::makeLaTeXFile(string const & fname,
runparams, output_preamble, output_body);
ofs.close();
if (ofs.fail()) {
lyxerr << "File was not closed properly." << endl;
}
if (ofs.fail())
lyxerr << "File '" << fname << "' was not closed properly." << endl;
}
@ -1018,7 +1004,8 @@ void Buffer::makeLinuxDocFile(string const & fname,
}
ofs.close();
// How to check for successful close
if (ofs.fail())
lyxerr << "File '" << fname << "' was not closed properly." << endl;
}
@ -1074,7 +1061,8 @@ void Buffer::makeDocBookFile(string const & fname,
sgml::closeTag(ofs, 0, false, top_element);
ofs.close();
// How to check for successful close
if (ofs.fail())
lyxerr << "File '" << fname << "' was not closed properly." << endl;
}

View File

@ -174,7 +174,7 @@ bool LCursor::popRight()
}
inset()->notifyCursorLeaves(idx());
pop();
posRight();
++pos();
return true;
}
@ -387,7 +387,6 @@ CursorSlice const & LCursor::selBegin() const
{
if (!selection())
return cursor_.back();
// can't use std::min as this creates a new object
return anchor() < cursor_.back() ? anchor() : cursor_.back();
}
@ -396,6 +395,7 @@ CursorSlice & LCursor::selBegin()
{
if (!selection())
return cursor_.back();
// can't use std::min as this returns a const ref
return anchor() < cursor_.back() ? anchor() : cursor_.back();
}
@ -410,8 +410,9 @@ CursorSlice const & LCursor::selEnd() const
CursorSlice & LCursor::selEnd()
{
if (selection())
if (!selection())
return cursor_.back();
// can't use std::min as this returns a const ref
return anchor() > cursor_.back() ? anchor() : cursor_.back();
}
@ -629,8 +630,9 @@ string LCursor::grabSelection()
void LCursor::eraseSelection()
{
CursorSlice i1 = selBegin();
CursorSlice i2 = selEnd();
//lyxerr << "LCursor::eraseSelection" << endl;
CursorSlice const & i1 = selBegin();
CursorSlice const & i2 = selEnd();
#warning FIXME
if (i1.inset()->asMathInset()) {
if (i1.idx_ == i2.idx_) {
@ -648,6 +650,7 @@ void LCursor::eraseSelection()
} else {
lyxerr << "can't erase this selection 1" << endl;
}
//lyxerr << "LCursor::eraseSelection end" << endl;
}
@ -688,6 +691,7 @@ void LCursor::selCut()
void LCursor::selDel()
{
//lyxerr << "LCursor::selDel" << endl;
if (selection()) {
eraseSelection();
selection() = false;
@ -707,6 +711,7 @@ void LCursor::selPaste(size_t n)
void LCursor::selHandle(bool sel)
{
//lyxerr << "LCursor::selHandle" << endl;
if (sel == selection())
return;
resetAnchor();
@ -714,15 +719,9 @@ void LCursor::selHandle(bool sel)
}
void LCursor::selStart()
{
resetAnchor();
selection() = true;
}
void LCursor::selClearOrDel()
{
//lyxerr << "LCursor::selClearOrDel" << endl;
if (lyxrc.auto_region_delete)
selDel();
else
@ -733,9 +732,9 @@ void LCursor::selClearOrDel()
std::ostream & operator<<(std::ostream & os, LCursor const & cur)
{
for (size_t i = 0, n = cur.cursor_.size(); i != n; ++i)
os << " (" << cur.cursor_[i] << " | " << cur.anchor_[i] << "\n";
os << " current: " << cur.current_ << endl;
os << " selection: " << cur.selection_ << endl;
os << " " << cur.cursor_[i] << " | " << cur.anchor_[i] << "\n";
os << " current: " << cur.current_ << endl;
os << " selection: " << cur.selection_ << endl;
return os;
}
@ -983,26 +982,24 @@ void LCursor::plainInsert(MathAtom const & t)
}
void LCursor::insert2(string const & str)
void LCursor::insert(string const & str)
{
lyxerr << "LCursor::insert str '" << str << "'" << endl;
selClearOrDel();
#if 0
for (string::const_iterator it = str.begin(); it != str.end(); ++it)
plainInsert(MathAtom(new MathCharInset(*it)));
#else
MathArray ar;
asArray(str, ar);
insert(ar);
}
void LCursor::insert(string const & str)
{
lyxerr << "inserting '" << str << "'" << endl;
selClearOrDel();
for (string::const_iterator it = str.begin(); it != str.end(); ++it)
plainInsert(MathAtom(new MathCharInset(*it)));
#endif
}
void LCursor::insert(char c)
{
lyxerr << "inserting '" << c << "'" << endl;
//lyxerr << "LCursor::insert char '" << c << "'" << endl;
selClearOrDel();
plainInsert(MathAtom(new MathCharInset(c)));
}
@ -1010,15 +1007,24 @@ void LCursor::insert(char c)
void LCursor::insert(MathAtom const & t)
{
//lyxerr << "LCursor::insert MathAtom: " << endl;
macroModeClose();
selClearOrDel();
plainInsert(t);
}
void LCursor::insert(InsetBase * inset)
{
if (inMathed())
insert(MathAtom(inset));
else
text()->insertInset(inset);
}
void LCursor::niceInsert(string const & t)
{
lyxerr << "*** LCursor::niceInsert 1: " << t << endl;
MathArray ar;
asArray(t, ar);
if (ar.size() == 1)
@ -1030,17 +1036,17 @@ void LCursor::niceInsert(string const & t)
void LCursor::niceInsert(MathAtom const & t)
{
lyxerr << "*** LCursor::niceInsert 2: " << t << endl;
macroModeClose();
string safe = grabAndEraseSelection();
plainInsert(t);
// enter the new inset and move the contents of the selection if possible
if (t->isActive()) {
posLeft();
// be careful here: don't use 'pushLeft(t)' as this we need to
// push the clone, not the original
pushLeft(nextAtom().nucleus());
paste(safe);
}
lyxerr << "*** LCursor::niceInsert 3: " << t << endl;
}
@ -1187,11 +1193,12 @@ string LCursor::macroName()
void LCursor::handleNest(MathAtom const & a, int c)
{
//lyxerr << "LCursor::handleNest: " << c << endl;
MathAtom t = a;
asArray(grabAndEraseSelection(), t.nucleus()->cell(c));
insert(t);
posLeft();
pushLeft(t.nucleus());
pushLeft(nextAtom().nucleus());
}
@ -1268,17 +1275,15 @@ MathGridInset * LCursor::enclosingGrid(idx_type & idx) const
void LCursor::pullArg()
{
#warning look here
#if 0
#warning Look here
MathArray ar = cell();
if (popLeft()) {
if (popLeft() && inMathed()) {
plainErase();
cell().insert(pos(), ar);
resetAnchor();
} else {
formula()->mutateToText();
//formula()->mutateToText();
}
#endif
}
@ -1696,7 +1701,7 @@ void LCursor::lockToggle()
} else if (popLeft() && pos() != lastpos()) {
// ... or enclosing inset if we are in the last inset position
nextAtom().nucleus()->lock(!nextAtom()->lock());
posRight();
++pos();
}
}
@ -1754,6 +1759,7 @@ DispatchResult dispatch(LCursor & cur, FuncRequest const & cmd)
void LCursor::handleFont(string const & font)
{
lyxerr << "LCursor::handleFont: " << font << endl;
string safe;
if (selection()) {
macroModeClose();
@ -1837,3 +1843,40 @@ void LCursor::errorMessage(string const & msg) const
{
bv().owner()->getLyXFunc().setErrorMessage(msg);
}
string LCursor::selectionAsString(bool label) const
{
if (!selection())
return string();
if (inTexted()) {
Buffer const & buffer = *bv().buffer();
// should be const ...
ParagraphList::iterator startpit = text()->getPar(selBegin());
ParagraphList::iterator endpit = text()->getPar(selEnd());
size_t const startpos = selBegin().pos();
size_t const endpos = selEnd().pos();
if (startpit == endpit)
return startpit->asString(buffer, startpos, endpos, label);
// First paragraph in selection
string result =
startpit->asString(buffer, startpos, startpit->size(), label) + "\n\n";
// The paragraphs in between (if any)
ParagraphList::iterator pit = startpit;
for (++pit; pit != endpit; ++pit)
result += pit->asString(buffer, 0, pit->size(), label) + "\n\n";
// Last paragraph in selection
result += endpit->asString(buffer, 0, endpos, label);
return result;
}
#warning an mathed?
return string();
}

View File

@ -144,6 +144,8 @@ public:
void selClear();
/// clears or deletes selection depending on lyxrc setting
void selClearOrDel();
//
std::string selectionAsString(bool label) const;
///
void paste(std::string const & data);
@ -247,6 +249,13 @@ public:
/// move one step to the right
bool posRight();
/// insert an inset
void insert(InsetBase *);
/// insert a single char
void insert(char c);
/// insert a string
void insert(std::string const & str);
/// write acess to target x position of cursor
int & x_target();
/// return target x position of cursor
@ -327,8 +336,6 @@ public:
void insert(MathAtom const &);
///
void insert(MathArray const &);
///
void insert2(std::string const &);
/// return false for empty math insets
bool erase();
/// return false for empty math insets
@ -398,10 +405,6 @@ public:
/// returns the normalized anchor of the selection
CursorSlice normalAnchor();
///
void insert(char c);
///
void insert(std::string const & str);
/// lock/unlock inset
void lockToggle();

View File

@ -236,7 +236,7 @@ std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
os << "inset: " << item.inset_
<< " text: " << item.text()
<< " idx: " << item.idx_
<< " par: " << item.par_
// << " par: " << item.par_
<< " pos: " << item.pos_
// << " x: " << item.inset_->x()
// << " y: " << item.inset_->y()

View File

@ -15,6 +15,7 @@
#include "insettext.h"
#include "lyxlayout_ptr_fwd.h"
class InsetEnvironment : public InsetText {
public:
///

View File

@ -974,6 +974,7 @@ void InsetTabular::getCursorPos(CursorSlice const & cur, int & x, int & y) const
void InsetTabular::setPos(BufferView & bv, int x, int y) const
{
lyxerr << "# InsetTabular::setPos() cursor: " << bv.cursor() << endl;
int const cell = getCell(x + xo_, y + yo_);
lyxerr << "# InsetTabular::setPos() cell: " << cell << endl;
InsetText const & inset = tabular.getCellInset(cell);

View File

@ -223,11 +223,13 @@ public:
string::size_type const size = str.length();
lyx::pos_type i = 0;
lyx::pos_type const parsize = par.size();
while ((pos + i < parsize)
&& (string::size_type(i) < size)
&& (cs ? (str[i] == par.getChar(pos + i))
: (uppercase(str[i]) == uppercase(par.getChar(pos + i))))) {
++i;
for (i = 0; pos + i < parsize; ++i) {
if (string::size_type(i) >= size)
break;
if (cs && str[i] != par.getChar(pos + i))
break;
if (!cs && uppercase(str[i]) != uppercase(par.getChar(pos + i)))
break;
}
if (size != string::size_type(i))
@ -359,16 +361,13 @@ int replaceAll(BufferView * bv,
}
bool stringSelected(BufferView * bv,
string const & searchstr,
bool stringSelected(BufferView * bv, string const & searchstr,
bool cs, bool mw, bool fw)
{
LyXText * text = bv->getLyXText();
// if nothing selected or selection does not equal search
// string search and select next occurance and return
string const & str1 = searchstr;
string const str2 = text->selectionAsString(*bv->buffer(),
false);
string const str2 = bv->cursor().selectionAsString(false);
if ((cs && str1 != str2) || lowercase(str1) != lowercase(str2)) {
find(bv, searchstr, cs, mw, fw);
return false;
@ -378,9 +377,8 @@ bool stringSelected(BufferView * bv,
}
int replace(BufferView * bv,
string const & searchstr, string const & replacestr,
bool cs, bool mw, bool fw)
int replace(BufferView * bv, string const & searchstr,
string const & replacestr, bool cs, bool mw, bool fw)
{
if (!searchAllowed(bv, searchstr) || bv->buffer()->isReadonly())
return 0;

View File

@ -824,7 +824,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
kb_action action = cmd.action;
lyxerr[Debug::ACTION] << "LyXFunc::dispatch: cmd: " << cmd << endl;
//lyxerr << "*** LyXFunc::dispatch: cmd: " << cmd << endl;
lyxerr << "LyXFunc::dispatch: cmd: " << cmd << endl;
// we have not done anything wrong yet.
errorstat = false;
@ -998,14 +998,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
AutoSave(view());
break;
case LFUN_UNDO:
view()->undo();
break;
case LFUN_REDO:
view()->redo();
break;
case LFUN_RECONFIGURE:
Reconfigure(view());
break;
@ -1162,14 +1154,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
break;
}
// --- Mathed stuff. If we are here, there is no locked inset yet.
case LFUN_MATH_EXTERN:
case LFUN_MATH_NUMBER:
case LFUN_MATH_NONUMBER:
case LFUN_MATH_LIMITS:
setErrorMessage(N_("This is only allowed in math mode!"));
break;
case LFUN_DIALOG_SHOW: {
string const name = cmd.getArg(0);
string data = trim(cmd.argument.substr(name.size()));
@ -1431,7 +1415,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
}
}
if (!view()->cursor().inMathed())
if (view()->cursor().inTexted())
view()->owner()->updateLayoutChoice();
if (view()->available()) {
@ -1445,7 +1429,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
view()->buffer()->markDirty();
}
if (!view()->cursor().inMathed())
if (view()->cursor().inTexted())
sendDispatchMessage(getMessage(), cmd, verbose);
}

View File

@ -340,8 +340,6 @@ public:
/// is this row the first in the text?
bool isFirstRow(ParagraphList::iterator pit, Row const & row) const;
///
std::string selectionAsString(Buffer const & buffer, bool label) const;
///
double spacing(Paragraph const &) const;
///

View File

@ -15,7 +15,7 @@
MathDimInset::MathDimInset()
: xo_(-3), yo_(-3)
: xo_(-3), yo_(-3) // some sentinel value for debugging
{}
@ -39,7 +39,7 @@ int MathDimInset::width() const
void MathDimInset::setPosCache(PainterInfo const &, int x, int y) const
{
lyxerr << "MathDimInset:: position cache to " << x << " " << y << std::endl;
//lyxerr << "MathDimInset: cache to " << x << " " << y << std::endl;
xo_ = x;
yo_ = y;
}

View File

@ -34,7 +34,6 @@
#include "support/std_sstream.h"
using lyx::support::trim;
using std::endl;
using std::max;
@ -788,7 +787,7 @@ void MathHullInset::doExtern(LCursor & cur, FuncRequest const & func)
DispatchResult
MathHullInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
lyxerr << "*** MathHullInset: request: " << cmd << endl;
//lyxerr << "*** MathHullInset: request: " << cmd << endl;
switch (cmd.action) {
case LFUN_BREAKLINE:
@ -837,7 +836,7 @@ MathHullInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
: Alert::askForText(_("Enter label:"), old_label);
if (!res.first)
return DispatchResult(false);
new_label = trim(res.second);
new_label = lyx::support::trim(res.second);
}
//if (new_label == old_label)
@ -1183,108 +1182,3 @@ int MathHullInset::docbook(Buffer const & buf, ostream & os,
ms << ETag("equation");
return ms.line() + res;
}
/////////////////////////////////////////////
namespace {
bool openNewInset(LCursor & cur, InsetBase * inset)
{
cur.bv().getLyXText()->insertInset(inset);
inset->edit(cur, true);
return true;
}
void mathDispatchCreation(LCursor & cur, FuncRequest const & cmd,
bool display)
{
// use selection if available..
//string sel;
//if (action == LFUN_MATH_IMPORT_SELECTION)
// sel = "";
//else
string sel =
cur.bv().getLyXText()->selectionAsString(*cur.bv().buffer(), false);
if (sel.empty()) {
InsetBase * f = new MathHullInset;
if (openNewInset(cur, f)) {
cur.inset()->dispatch(cur, FuncRequest(LFUN_MATH_MUTATE, "simple"));
// don't do that also for LFUN_MATH_MODE unless you want end up with
// always changing to mathrm when opening an inlined inset
// -- I really hate "LyXfunc overloading"...
if (display)
f->dispatch(cur, FuncRequest(LFUN_MATH_DISPLAY));
f->dispatch(cur, FuncRequest(LFUN_INSERT_MATH, cmd.argument));
}
} else {
// create a macro if we see "\\newcommand" somewhere, and an ordinary
// formula otherwise
InsetBase * f;
if (sel.find("\\newcommand") == string::npos &&
sel.find("\\def") == string::npos)
f = new MathHullInset(sel);
else
f = new InsetFormulaMacro(sel);
cur.bv().getLyXText()->cutSelection(true, false);
openNewInset(cur, f);
}
cur.message(N_("Math editor mode"));
}
} // namespace anon
void mathDispatch(LCursor & cur, FuncRequest const & cmd)
{
if (!cur.bv().available())
return;
switch (cmd.action) {
case LFUN_MATH_DISPLAY:
mathDispatchCreation(cur, cmd, true);
break;
case LFUN_MATH_MODE:
mathDispatchCreation(cur, cmd, false);
break;
case LFUN_MATH_IMPORT_SELECTION:
mathDispatchCreation(cur, cmd, false);
break;
/*
case LFUN_MATH_MACRO:
if (cmd.argument.empty())
cmd.errorMessage(N_("Missing argument"));
else {
string s = cmd.argument;
string const s1 = token(s, ' ', 1);
int const nargs = s1.empty() ? 0 : atoi(s1);
string const s2 = token(s, ' ', 2);
string const type = s2.empty() ? "newcommand" : s2;
openNewInset(cur, new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
}
break;
case LFUN_INSERT_MATH:
case LFUN_INSERT_MATRIX:
case LFUN_MATH_DELIM: {
MathHullInset * f = new MathHullInset;
if (openNewInset(cur, f)) {
cur.inset()->dispatch(cur, FuncRequest(LFUN_MATH_MUTATE, "simple"));
cur.inset()->dispatch(cur, cmd);
}
break;
}
*/
default:
break;
}
}

View File

@ -207,7 +207,7 @@ void MathNestInset::draw(PainterInfo &, int, int) const
}
void MathNestInset::drawSelection(PainterInfo & pi, int x, int y) const
void MathNestInset::drawSelection(PainterInfo & pi, int, int) const
{
// this should use the x/y values given, not the cached values
LCursor & cur = pi.base.bv->cursor();
@ -218,14 +218,12 @@ void MathNestInset::drawSelection(PainterInfo & pi, int x, int y) const
CursorSlice & s1 = cur.selBegin();
CursorSlice & s2 = cur.selEnd();
if (s1.idx() == s2.idx()) {
MathArray const & c = s1.cell();
lyxerr << "###### c.xo(): " << c.xo() << " c.yo(): " << c.yo() << endl;
MathArray const & c = cell(s1.idx());
int x1 = c.xo() + c.pos2x(s1.pos());
int y1 = c.yo() - c.ascent();
int x2 = c.xo() + c.pos2x(s2.pos());
int y2 = c.yo() + c.descent();
//pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::red);
pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
} else {
for (idx_type i = 0; i < nargs(); ++i) {
if (idxBetween(i, s1.idx(), s2.idx())) {
@ -234,8 +232,7 @@ void MathNestInset::drawSelection(PainterInfo & pi, int x, int y) const
int y1 = c.yo() - c.ascent();
int x2 = c.xo() + c.width();
int y2 = c.yo() + c.descent();
//pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::red);
pi.pain.fillRectangle(x1, y1, x2 - x1, y2 - y1, LColor::selection);
}
}
}
@ -354,12 +351,7 @@ void MathNestInset::handleFont2(LCursor & cur, string const & arg)
DispatchResult
MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
lyxerr << "*** MathNestInset: request: " << cmd << std::endl;
//lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action
// << " arg: '" << cmd.argument
// << "' x: '" << cmd.x
// << " y: '" << cmd.y
// << "' button: " << cmd.button() << endl;
lyxerr << "MathNestInset: request: " << cmd << std::endl;
switch (cmd.action) {
@ -388,48 +380,41 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
return dispatch(cur, FuncRequest(LFUN_PASTE, cur.bv().getClipboard()));
case LFUN_MOUSE_PRESS:
//lyxerr << "Mouse single press" << endl;
return lfunMousePress(cur, cmd);
case LFUN_MOUSE_MOTION:
//lyxerr << "Mouse motion" << endl;
return lfunMouseMotion(cur, cmd);
case LFUN_MOUSE_RELEASE:
//lyxerr << "Mouse single release" << endl;
return lfunMouseRelease(cur, cmd);
case LFUN_MOUSE_DOUBLE:
//lyxerr << "Mouse double" << endl;
return dispatch(cur, FuncRequest(LFUN_WORDSEL));
case LFUN_RIGHTSEL:
cur.selection() = true; // fall through...
case LFUN_RIGHT:
cur.selHandle(cmd.action == LFUN_RIGHTSEL);
return cur.right() ?
DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
//lyxerr << "calling scroll 20" << endl;
//scroll(&cur.bv(), 20);
// write something to the minibuffer
//cur.bv().owner()->message(cur.info());
case LFUN_LEFTSEL:
cur.selection() = true; // fall through
case LFUN_LEFT:
cur.selHandle(cmd.action == LFUN_LEFTSEL);
return cur.left() ?
DispatchResult(true, true) : DispatchResult(false, FINISHED);
case LFUN_UPSEL:
cur.selection() = true; // fall through
case LFUN_UP:
cur.selHandle(cmd.action == LFUN_UPSEL);
return cur.up() ?
DispatchResult(true, true) : DispatchResult(false, FINISHED_UP);
case LFUN_DOWNSEL:
cur.selection() = true; // fall through
case LFUN_DOWN:
cur.selHandle(cmd.action == LFUN_DOWNSEL);
return cur.down() ?
DispatchResult(true, true) : DispatchResult(false, FINISHED_DOWN);
case LFUN_WORDSEL:
cur.home();
cur.resetAnchor();
cur.selection() = true;
cur.end();
return DispatchResult(true, true);
@ -440,19 +425,27 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_DOWN_PARAGRAPH:
return DispatchResult(true, FINISHED);
case LFUN_HOMESEL:
case LFUN_WORDLEFTSEL:
cur.selection() = true; // fall through
case LFUN_HOME:
case LFUN_WORDLEFT:
cur.selHandle(cmd.action == LFUN_WORDLEFTSEL);
return cur.home()
? DispatchResult(true, true) : DispatchResult(true, FINISHED);
case LFUN_WORDRIGHTSEL:
case LFUN_WORDRIGHT:
cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL);
return cur.end()
? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
case LFUN_HOMESEL:
case LFUN_HOME:
cur.selHandle(cmd.action == LFUN_HOMESEL);
return cur.home()
? DispatchResult(true, true) : DispatchResult(true, FINISHED);
case LFUN_ENDSEL:
case LFUN_WORDRIGHTSEL:
cur.selection() = true; // fall through
case LFUN_END:
case LFUN_WORDRIGHT:
cur.selHandle(cmd.action == LFUN_ENDSEL);
return cur.end()
? DispatchResult(true, true) : DispatchResult(false, FINISHED_RIGHT);
@ -516,32 +509,14 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
//
// this needs to be incorporated
//
//lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action
// << " arg: '" << cmd.argument
// << "' x: '" << cmd.x
// << " y: '" << cmd.y
// << "' button: " << cmd.button() << endl;
// delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
bool remove_inset = false;
switch (cmd.action) {
default:
break;
}
DispatchResult result(true);
bool was_macro = cur.inMacroMode();
cur.normalize();
cur.touch();
switch (cmd.action) {
case LFUN_MATH_LIMITS:
//recordUndo(cur, Undo::ATOMIC);
cur.dispatch(cmd);
break;
#endif
// case LFUN_GETXY:
@ -676,7 +651,7 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
}
case LFUN_MATH_DELIM: {
//lyxerr << "formulabase::LFUN_MATH_DELIM, arg: '" << arg << "'" << endl;
lyxerr << "MathNestInset::LFUN_MATH_DELIM" << endl;
string ls;
string rs = lyx::support::split(cmd.argument, ls, ' ');
// Reasonable default values
@ -706,16 +681,6 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
cur.interpret('\\');
return DispatchResult(true, true);
#if 0
case LFUN_BREAKPARAGRAPH:
case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
case LFUN_BREAKPARAGRAPH_SKIP:
cmd.argument = "\n";
//recordUndo(cur, Undo::ATOMIC);
cur.niceInsert(argument);
return DispatchResult(true, true);
#endif
// FIXME: We probably should swap parts of "math-insert" and "self-insert"
// handling such that "self-insert" works on "arbitrary stuff" too, and
// math-insert only handles special math things like "matrix".
@ -767,17 +732,6 @@ MathNestInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
searchForward(&cur.bv(), cmd.getArg(0), false, false)
? DispatchResult(true, true) : DispatchResult(false);
case LFUN_INSERT_MATH:
case LFUN_INSERT_MATRIX:
case LFUN_MATH_DELIM: {
MathHullInset * f = new MathHullInset;
if (openNewInset(cur, f)) {
cur.inset()->dispatch(cur, FuncRequest(LFUN_MATH_MUTATE, "simple"));
cur.inset()->dispatch(cur, cmd);
}
return DispatchResult(true, true);
}
cur.normalize();
cur.touch();

View File

@ -514,8 +514,10 @@ void MathScriptInset::notifyCursorLeaves(idx_type idx)
DispatchResult
MathScriptInset::priv_dispatch(LCursor & bv, FuncRequest const & cmd)
MathScriptInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
lyxerr << "MathScriptInset: request: " << cmd << std::endl;
if (cmd.action == LFUN_MATH_LIMITS) {
if (!cmd.argument.empty()) {
if (cmd.argument == "limits")
@ -531,5 +533,5 @@ MathScriptInset::priv_dispatch(LCursor & bv, FuncRequest const & cmd)
return DispatchResult(true, true);
}
return MathNestInset::priv_dispatch(bv, cmd);
return MathNestInset::priv_dispatch(cur, cmd);
}

View File

@ -428,9 +428,8 @@ TeXOnePar(Buffer const & buf,
} // anon namespace
//
// LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
//
// LaTeX all paragraphs
void latexParagraphs(Buffer const & buf,
ParagraphList const & paragraphs,
ostream & os,
@ -456,7 +455,7 @@ void latexParagraphs(Buffer const & buf,
if (layout->intitle) {
if (already_title) {
lyxerr <<"Error in latexParagraphs: You"
lyxerr << "Error in latexParagraphs: You"
" should not mix title layouts"
" with normal ones." << endl;
} else if (!was_title) {

View File

@ -1385,7 +1385,6 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
}
}
if (isInset(i)) {
InsetBase const * inset = getInset(i);
// don't print the inset in position 0 if desc_on == 3 (label)
@ -1703,7 +1702,6 @@ bool Paragraph::isChangeEdited(pos_type start, pos_type end) const
void Paragraph::setChange(lyx::pos_type pos, Change::Type type)
{
pimpl_->setChange(pos, type);
}
@ -1738,7 +1736,6 @@ Paragraph::value_type Paragraph::getChar(pos_type pos) const
<< id() << " of size " << siz
<< " is a bit silly !" << endl;
BOOST_ASSERT(false);
return '\0';
}
return text_[pos];

View File

@ -888,7 +888,7 @@ int paintText(BufferView const & bv)
{
ParagraphList::iterator pit;
bv.text()->updateParPositions();
bv.text()->getRowNearY(0, pit);
bv.text()->getRowNearY(bv.top_y(), pit);
//lyxerr << "top_y: " << bv.top_y() << " y: " << pit->y << endl;
return paintPars(bv, *bv.text(), pit, 0, 0, pit->y);
}

View File

@ -1499,37 +1499,6 @@ void LyXText::previousRow(ParagraphList::iterator & pit,
}
string LyXText::selectionAsString(Buffer const & buffer, bool label) const
{
LCursor & cur = bv()->cursor();
if (!cur.selection())
return string();
// should be const ...
ParagraphList::iterator startpit = getPar(cur.selBegin());
ParagraphList::iterator endpit = getPar(cur.selEnd());
size_t const startpos = cur.selBegin().pos();
size_t const endpos = cur.selEnd().pos();
if (startpit == endpit)
return startpit->asString(buffer, startpos, endpos, label);
// First paragraph in selection
string result =
startpit->asString(buffer, startpos, startpit->size(), label) + "\n\n";
// The paragraphs in between (if any)
ParagraphList::iterator pit = startpit;
for (++pit; pit != endpit; ++pit)
result += pit->asString(buffer, 0, pit->size(), label) + "\n\n";
// Last paragraph in selection
result += endpit->asString(buffer, 0, endpos, label);
return result;
}
int LyXText::parOffset(ParagraphList::iterator pit) const
{
return distance(paragraphs().begin(), pit);

View File

@ -466,8 +466,7 @@ void LyXText::cursorTop()
void LyXText::cursorBottom()
{
ParagraphList::iterator lastpit =
boost::prior(paragraphs().end());
ParagraphList::iterator lastpit = boost::prior(paragraphs().end());
setCursor(lastpit, lastpit->size());
}
@ -520,7 +519,7 @@ string LyXText::getStringToIndex()
else if (cur.selBegin().par() != cur.selEnd().par())
bv()->owner()->message(_("Cannot index more than one paragraph!"));
else
idxstring = selectionAsString(*bv()->buffer(), false);
idxstring = cur.selectionAsString(false);
// Reset cursors to their original position.
cursor() = reset_cursor;
@ -896,7 +895,7 @@ void LyXText::cutSelection(bool doclear, bool realcut)
// finished. The solution used currently just works, to make it
// faster we need to be more clever and probably also have more
// calls to stuffClipboard. (Lgb)
bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
bv()->stuffClipboard(cur.selectionAsString(true));
// This doesn't make sense, if there is no selection
if (!cur.selection())
@ -947,7 +946,7 @@ void LyXText::copySelection()
{
LCursor & cur = bv()->cursor();
// stuff the selection onto the X clipboard, from an explicit copy request
bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
bv()->stuffClipboard(cur.selectionAsString(true));
// this doesnt make sense, if there is no selection
if (!cur.selection())

View File

@ -46,19 +46,24 @@
#include "insets/insettext.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include "support/tostr.h"
#include "support/std_sstream.h"
#include "mathed/math_hullinset.h"
#include "mathed/formulamacro.h"
#include <clocale>
using bv_funcs::replaceSelection;
using lyx::pos_type;
using lyx::support::isStrUnsignedInt;
using lyx::support::strToUnsignedInt;
using lyx::support::atoi;
using lyx::support::token;
using std::endl;
using std::find;
@ -123,7 +128,43 @@ namespace {
cur.bv().owner()->view_state_changed();
}
} // anon namespace
void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
{
string sel = cur.selectionAsString(false);
lyxerr << "selection is: '" << sel << "'" << endl;
if (sel.empty()) {
cur.insert(new MathHullInset);
cur.dispatch(FuncRequest(LFUN_RIGHT));
cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
// don't do that also for LFUN_MATH_MODE unless you want end up with
// always changing to mathrm when opening an inlined inset
// -- I really hate "LyXfunc overloading"...
if (display)
cur.dispatch(FuncRequest(LFUN_MATH_DISPLAY));
cur.dispatch(FuncRequest(LFUN_INSERT_MATH, cmd.argument));
} else {
// create a macro if we see "\\newcommand" somewhere, and an ordinary
// formula otherwise
cur.bv().getLyXText()->cutSelection(true, true);
if (sel.find("\\newcommand") == string::npos &&
sel.find("\\def") == string::npos)
{
cur.insert(new MathHullInset);
cur.dispatch(FuncRequest(LFUN_RIGHT));
cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
cur.dispatch(FuncRequest(LFUN_INSERT_MATH, sel));
} else {
cur.insert(new InsetFormulaMacro(sel));
cur.dispatch(FuncRequest(LFUN_RIGHT));
}
}
cur.message(N_("Math editor mode"));
}
} // namespace anon
namespace bv_funcs {
@ -1269,22 +1310,39 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
bv->update();
break;
case LFUN_MATH_DELIM:
case LFUN_MATH_DISPLAY:
case LFUN_INSERT_MATH:
case LFUN_MATH_LIMITS:
case LFUN_MATH_MACRO:
case LFUN_MATH_MUTATE:
case LFUN_MATH_SPACE:
mathDispatch(cur, cmd, true);
break;
case LFUN_MATH_IMPORT_SELECTION:
case LFUN_MATH_MODE:
case LFUN_MATH_NONUMBER:
case LFUN_MATH_NUMBER:
case LFUN_MATH_EXTERN:
case LFUN_MATH_SIZE:
mathDispatch(cur, cmd);
mathDispatch(cur, cmd, false);
break;
case LFUN_MATH_MACRO:
if (cmd.argument.empty())
cur.errorMessage(N_("Missing argument"));
else {
string s = cmd.argument;
string const s1 = token(s, ' ', 1);
int const nargs = s1.empty() ? 0 : atoi(s1);
string const s2 = token(s, ' ', 2);
string const type = s2.empty() ? "newcommand" : s2;
cur.insert(new InsetFormulaMacro(token(s, ' ', 0), nargs, s2));
cur.nextInset()->edit(cur, true);
}
break;
case LFUN_INSERT_MATH:
case LFUN_INSERT_MATRIX:
case LFUN_MATH_DELIM: {
cur.insert(new MathHullInset);
cur.dispatch(FuncRequest(LFUN_RIGHT));
cur.dispatch(FuncRequest(LFUN_MATH_MUTATE, "simple"));
cur.dispatch(cmd);
break;
}
case LFUN_EMPH: {
LyXFont font(LyXFont::ALL_IGNORE);
font.setEmph(LyXFont::TOGGLE);