2000-02-04 09:38:32 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
2000-02-04 09:38:32 +00:00
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
#include <fstream>
|
2000-05-19 16:46:01 +00:00
|
|
|
#include <algorithm>
|
2000-04-08 17:02:02 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
#include "BufferView.h"
|
|
|
|
#include "buffer.h"
|
|
|
|
#include "lyxcursor.h"
|
|
|
|
#include "lyxtext.h"
|
|
|
|
#include "insets/inseterror.h"
|
|
|
|
#include "LyXView.h"
|
|
|
|
#include "bufferlist.h"
|
|
|
|
#include "support/FileInfo.h"
|
2000-02-17 19:59:08 +00:00
|
|
|
#include "lyxscreen.h"
|
2000-04-08 17:02:02 +00:00
|
|
|
#include "support/filetools.h"
|
|
|
|
#include "lyx_gui_misc.h"
|
|
|
|
#include "LaTeX.h"
|
|
|
|
#include "BufferView_pimpl.h"
|
2000-05-19 16:46:01 +00:00
|
|
|
#include "insets/insetcommand.h" //ChangeRefs
|
2001-01-31 20:39:53 +00:00
|
|
|
#include "support/lyxfunctional.h" //equal_1st_in_pair
|
2001-04-05 12:26:41 +00:00
|
|
|
#include "language.h"
|
2001-04-17 15:15:59 +00:00
|
|
|
#include "gettext.h"
|
2001-07-06 15:57:54 +00:00
|
|
|
#include "undo_funcs.h"
|
2001-07-29 15:34:18 +00:00
|
|
|
#include "debug.h"
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
extern BufferList bufferlist;
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::pair;
|
2000-03-28 02:18:55 +00:00
|
|
|
using std::endl;
|
2000-02-08 15:13:01 +00:00
|
|
|
using std::ifstream;
|
2000-05-19 16:46:01 +00:00
|
|
|
using std::vector;
|
|
|
|
using std::find;
|
2000-12-11 09:46:09 +00:00
|
|
|
using std::count;
|
2001-01-31 20:39:53 +00:00
|
|
|
using std::count_if;
|
2000-02-08 15:13:01 +00:00
|
|
|
|
2001-05-29 09:50:02 +00:00
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
// Inserts a file into current document
|
|
|
|
bool BufferView::insertLyXFile(string const & filen)
|
|
|
|
//
|
2000-03-09 03:36:48 +00:00
|
|
|
// Copyright CHT Software Service GmbH
|
2000-02-04 09:38:32 +00:00
|
|
|
// Uwe C. Schroeder
|
|
|
|
//
|
|
|
|
// Insert a Lyxformat - file into current buffer
|
|
|
|
//
|
|
|
|
// Moved from lyx_cb.C (Lgb)
|
|
|
|
{
|
|
|
|
if (filen.empty()) return false;
|
|
|
|
|
2000-12-29 12:48:02 +00:00
|
|
|
string const fname = MakeAbsPath(filen);
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
// check if file exist
|
2000-12-29 12:48:02 +00:00
|
|
|
FileInfo const fi(fname);
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
if (!fi.readable()) {
|
|
|
|
WriteAlert(_("Error!"),
|
|
|
|
_("Specified file is unreadable: "),
|
|
|
|
MakeDisplayPath(fname, 50));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-02-14 10:11:22 +00:00
|
|
|
beforeChange(text);
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
ifstream ifs(fname.c_str());
|
|
|
|
if (!ifs) {
|
|
|
|
WriteAlert(_("Error!"),
|
|
|
|
_("Cannot open specified file: "),
|
|
|
|
MakeDisplayPath(fname, 50));
|
|
|
|
return false;
|
|
|
|
}
|
2000-07-31 16:39:50 +00:00
|
|
|
|
2000-12-29 12:48:02 +00:00
|
|
|
char const c = ifs.peek();
|
2000-07-31 16:39:50 +00:00
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
LyXLex lex(0, 0);
|
|
|
|
lex.setStream(ifs);
|
|
|
|
|
|
|
|
bool res = true;
|
|
|
|
|
|
|
|
if (c == '#') {
|
2001-06-27 14:10:35 +00:00
|
|
|
lyxerr[Debug::INFO] << "Will insert file with header" << endl;
|
2000-06-08 23:16:16 +00:00
|
|
|
res = buffer()->readFile(lex, text->cursor.par());
|
2000-02-04 09:38:32 +00:00
|
|
|
} else {
|
2001-06-27 14:10:35 +00:00
|
|
|
lyxerr[Debug::INFO] << "Will insert file without header"
|
|
|
|
<< endl;
|
2000-06-08 23:16:16 +00:00
|
|
|
res = buffer()->readLyXformat2(lex, text->cursor.par());
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resize();
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-12-29 12:48:02 +00:00
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
bool BufferView::removeAutoInsets()
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph * par = buffer()->paragraph;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
2000-05-17 14:43:09 +00:00
|
|
|
LyXCursor tmpcursor = text->cursor;
|
|
|
|
LyXCursor cursor;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
bool a = false;
|
2001-03-11 00:21:13 +00:00
|
|
|
|
2001-03-09 00:56:42 +00:00
|
|
|
while (par) {
|
|
|
|
// this has to be done before the delete
|
2001-06-25 00:06:33 +00:00
|
|
|
text->setCursor(this, cursor, par, 0);
|
|
|
|
if (par->autoDeleteInsets()){
|
2001-03-09 00:56:42 +00:00
|
|
|
a = true;
|
2001-06-25 00:06:33 +00:00
|
|
|
text->redoParagraphs(this, cursor,
|
2001-03-09 00:56:42 +00:00
|
|
|
cursor.par()->next());
|
2001-06-25 00:06:33 +00:00
|
|
|
text->fullRebreak(this);
|
2001-03-09 00:56:42 +00:00
|
|
|
}
|
|
|
|
par = par->next();
|
|
|
|
}
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
// avoid forbidden cursor positions caused by error removing
|
2001-03-11 00:21:13 +00:00
|
|
|
if (tmpcursor.pos() > tmpcursor.par()->size())
|
|
|
|
tmpcursor.pos(tmpcursor.par()->size());
|
2001-05-03 14:31:33 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
text->setCursorIntern(this, tmpcursor.par(), tmpcursor.pos());
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::insertErrors(TeXErrors & terr)
|
|
|
|
{
|
|
|
|
// Save the cursor position
|
|
|
|
LyXCursor cursor = text->cursor;
|
|
|
|
|
|
|
|
for (TeXErrors::Errors::const_iterator cit = terr.begin();
|
|
|
|
cit != terr.end();
|
|
|
|
++cit) {
|
2001-07-12 11:11:10 +00:00
|
|
|
string const desctext(cit->error_desc);
|
|
|
|
string const errortext(cit->error_text);
|
2000-12-29 12:48:02 +00:00
|
|
|
string const msgtxt = desctext + '\n' + errortext;
|
2001-07-12 11:11:10 +00:00
|
|
|
int const errorrow = cit->error_in_line;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
// Insert error string for row number
|
|
|
|
int tmpid = -1;
|
|
|
|
int tmppos = -1;
|
|
|
|
|
2000-08-05 05:17:18 +00:00
|
|
|
if (buffer()->texrow.getIdFromRow(errorrow, tmpid, tmppos)) {
|
|
|
|
buffer()->texrow.increasePos(tmpid, tmppos);
|
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph * texrowpar = 0;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
if (tmpid == -1) {
|
2001-06-25 00:06:33 +00:00
|
|
|
texrowpar = text->firstParagraph();
|
2000-02-04 09:38:32 +00:00
|
|
|
tmppos = 0;
|
|
|
|
} else {
|
2001-07-09 09:16:00 +00:00
|
|
|
texrowpar = buffer()->getParFromID(tmpid);
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (texrowpar == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
InsetError * new_inset = new InsetError(msgtxt);
|
2001-06-25 00:06:33 +00:00
|
|
|
text->setCursorIntern(this, texrowpar, tmppos);
|
|
|
|
text->insertInset(this, new_inset);
|
|
|
|
text->fullRebreak(this);
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
// Restore the cursor position
|
2001-06-25 00:06:33 +00:00
|
|
|
text->setCursorIntern(this, cursor.par(), cursor.pos());
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::setCursorFromRow(int row)
|
|
|
|
{
|
|
|
|
int tmpid = -1;
|
|
|
|
int tmppos = -1;
|
|
|
|
|
|
|
|
buffer()->texrow.getIdFromRow(row, tmpid, tmppos);
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph * texrowpar;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
if (tmpid == -1) {
|
2001-06-25 00:06:33 +00:00
|
|
|
texrowpar = text->firstParagraph();
|
2000-02-04 09:38:32 +00:00
|
|
|
tmppos = 0;
|
|
|
|
} else {
|
2001-07-09 09:16:00 +00:00
|
|
|
texrowpar = buffer()->getParFromID(tmpid);
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
text->setCursor(this, texrowpar, tmppos);
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
2000-10-03 18:38:10 +00:00
|
|
|
|
2001-06-04 23:57:32 +00:00
|
|
|
bool BufferView::insertInset(Inset * inset, string const & lout)
|
2000-02-04 09:38:32 +00:00
|
|
|
{
|
2001-06-04 23:57:32 +00:00
|
|
|
return pimpl_->insertInset(inset, lout);
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* This is also a buffer property (ale) */
|
|
|
|
// Not so sure about that. a goto Label function can not be buffer local, just
|
|
|
|
// think how this will work in a multiwindo/buffer environment, all the
|
|
|
|
// cursors in all the views showing this buffer will move. (Lgb)
|
|
|
|
// OK, then no cursor action should be allowed in buffer. (ale)
|
|
|
|
bool BufferView::gotoLabel(string const & label)
|
|
|
|
|
|
|
|
{
|
2000-05-19 16:46:01 +00:00
|
|
|
for (Buffer::inset_iterator it = buffer()->inset_iterator_begin();
|
|
|
|
it != buffer()->inset_iterator_end(); ++it) {
|
|
|
|
vector<string> labels = (*it)->getLabelList();
|
2000-11-04 10:00:12 +00:00
|
|
|
if (find(labels.begin(),labels.end(),label)
|
2000-05-19 16:46:01 +00:00
|
|
|
!= labels.end()) {
|
2001-02-14 10:11:22 +00:00
|
|
|
beforeChange(text);
|
2001-06-25 00:06:33 +00:00
|
|
|
text->setCursor(this, it.getPar(), it.getPos());
|
2001-05-31 02:23:46 +00:00
|
|
|
text->selection.cursor = text->cursor;
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR);
|
2000-05-19 16:46:01 +00:00
|
|
|
return true;
|
|
|
|
}
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2000-07-19 17:16:27 +00:00
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
void BufferView::menuUndo()
|
|
|
|
{
|
|
|
|
if (available()) {
|
2001-04-24 17:33:01 +00:00
|
|
|
owner()->message(_("Undo"));
|
2000-02-17 19:59:08 +00:00
|
|
|
hideCursor();
|
2001-02-14 10:11:22 +00:00
|
|
|
beforeChange(text);
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR);
|
2001-07-06 15:57:54 +00:00
|
|
|
if (!textUndo(this))
|
2001-04-24 17:33:01 +00:00
|
|
|
owner()->message(_("No forther undo information"));
|
2000-02-04 09:38:32 +00:00
|
|
|
else
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
|
2000-02-17 19:59:08 +00:00
|
|
|
setState();
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::menuRedo()
|
|
|
|
{
|
2000-10-03 13:55:48 +00:00
|
|
|
if (theLockingInset()) {
|
2001-04-24 17:33:01 +00:00
|
|
|
owner()->message(_("Redo not yet supported in math mode"));
|
2000-02-04 09:38:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (available()) {
|
2001-04-24 17:33:01 +00:00
|
|
|
owner()->message(_("Redo"));
|
2000-02-17 19:59:08 +00:00
|
|
|
hideCursor();
|
2001-02-14 10:11:22 +00:00
|
|
|
beforeChange(text);
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR);
|
2001-07-06 15:57:54 +00:00
|
|
|
if (!textRedo(this))
|
2001-04-24 17:33:01 +00:00
|
|
|
owner()->message(_("No further redo information"));
|
2000-02-04 09:38:32 +00:00
|
|
|
else
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
|
2000-02-17 19:59:08 +00:00
|
|
|
setState();
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::copyEnvironment()
|
|
|
|
{
|
|
|
|
if (available()) {
|
|
|
|
text->copyEnvironmentType();
|
|
|
|
// clear the selection, even if mark_set
|
2000-02-17 19:59:08 +00:00
|
|
|
toggleSelection();
|
2001-06-25 00:06:33 +00:00
|
|
|
text->clearSelection(this);
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR);
|
2001-04-24 17:33:01 +00:00
|
|
|
owner()->message(_("Paragraph environment type copied"));
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::pasteEnvironment()
|
|
|
|
{
|
|
|
|
if (available()) {
|
2000-06-12 11:27:15 +00:00
|
|
|
text->pasteEnvironmentType(this);
|
2001-04-24 17:33:01 +00:00
|
|
|
owner()->message(_("Paragraph environment type set"));
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::copy()
|
|
|
|
{
|
|
|
|
if (available()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
text->copySelection(this);
|
2000-02-04 09:38:32 +00:00
|
|
|
// clear the selection, even if mark_set
|
2000-02-17 19:59:08 +00:00
|
|
|
toggleSelection();
|
2001-06-25 00:06:33 +00:00
|
|
|
text->clearSelection(this);
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR);
|
2001-04-24 17:33:01 +00:00
|
|
|
owner()->message(_("Copy"));
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-29 09:50:02 +00:00
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
void BufferView::cut()
|
|
|
|
{
|
|
|
|
if (available()) {
|
2000-02-17 19:59:08 +00:00
|
|
|
hideCursor();
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR);
|
2001-06-25 00:06:33 +00:00
|
|
|
text->cutSelection(this);
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
|
2001-04-24 17:33:01 +00:00
|
|
|
owner()->message(_("Cut"));
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::paste()
|
|
|
|
{
|
|
|
|
if (!available()) return;
|
2001-04-17 15:15:59 +00:00
|
|
|
|
2001-04-24 17:33:01 +00:00
|
|
|
owner()->message(_("Paste"));
|
2001-04-17 15:15:59 +00:00
|
|
|
|
2000-02-17 19:59:08 +00:00
|
|
|
hideCursor();
|
2000-02-04 09:38:32 +00:00
|
|
|
// clear the selection
|
2000-02-17 19:59:08 +00:00
|
|
|
toggleSelection();
|
2001-06-25 00:06:33 +00:00
|
|
|
text->clearSelection(this);
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR);
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
// paste
|
2001-06-25 00:06:33 +00:00
|
|
|
text->pasteSelection(this);
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
// clear the selection
|
2000-02-17 19:59:08 +00:00
|
|
|
toggleSelection();
|
2001-06-25 00:06:33 +00:00
|
|
|
text->clearSelection(this);
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR);
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* these functions are for the spellchecker */
|
2000-09-14 17:53:12 +00:00
|
|
|
string const BufferView::nextWord(float & value)
|
2000-02-04 09:38:32 +00:00
|
|
|
{
|
|
|
|
if (!available()) {
|
|
|
|
value = 1;
|
2000-10-23 22:36:52 +00:00
|
|
|
return string();
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
return text->selectNextWord(this, value);
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::selectLastWord()
|
|
|
|
{
|
|
|
|
if (!available()) return;
|
|
|
|
|
2000-02-17 19:59:08 +00:00
|
|
|
hideCursor();
|
2001-02-14 10:11:22 +00:00
|
|
|
beforeChange(text);
|
2001-06-25 00:06:33 +00:00
|
|
|
text->selectSelectedWord(this);
|
2000-02-17 19:59:08 +00:00
|
|
|
toggleSelection(false);
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR);
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::endOfSpellCheck()
|
|
|
|
{
|
|
|
|
if (!available()) return;
|
|
|
|
|
2000-02-17 19:59:08 +00:00
|
|
|
hideCursor();
|
2001-02-14 10:11:22 +00:00
|
|
|
beforeChange(text);
|
2001-06-25 00:06:33 +00:00
|
|
|
text->selectSelectedWord(this);
|
|
|
|
text->clearSelection(this);
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR);
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
2000-02-17 19:59:08 +00:00
|
|
|
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
void BufferView::replaceWord(string const & replacestring)
|
|
|
|
{
|
2000-02-17 19:59:08 +00:00
|
|
|
if (!available()) return;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
2001-07-17 15:39:12 +00:00
|
|
|
LyXText * tt = getLyXText();
|
2000-02-17 19:59:08 +00:00
|
|
|
hideCursor();
|
2001-07-17 15:39:12 +00:00
|
|
|
update(tt, BufferView::SELECT|BufferView::FITCUR);
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
/* clear the selection (if there is any) */
|
2000-02-17 19:59:08 +00:00
|
|
|
toggleSelection(false);
|
2001-07-17 15:39:12 +00:00
|
|
|
update(tt, BufferView::SELECT|BufferView::FITCUR);
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
/* clear the selection (if there is any) */
|
2000-02-17 19:59:08 +00:00
|
|
|
toggleSelection(false);
|
2001-07-17 15:39:12 +00:00
|
|
|
tt->replaceSelectionWithString(this, replacestring);
|
2000-02-04 09:38:32 +00:00
|
|
|
|
2001-07-17 15:39:12 +00:00
|
|
|
tt->setSelectionOverString(this, replacestring);
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
// Go back so that replacement string is also spellchecked
|
|
|
|
for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
|
2001-07-17 15:39:12 +00:00
|
|
|
tt->cursorLeft(this);
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
2001-07-17 15:39:12 +00:00
|
|
|
update(tt, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
// End of spellchecker stuff
|
|
|
|
|
|
|
|
|
2000-04-19 14:42:19 +00:00
|
|
|
bool BufferView::lockInset(UpdatableInset * inset)
|
2000-02-04 09:38:32 +00:00
|
|
|
{
|
2000-10-03 13:55:48 +00:00
|
|
|
if (!theLockingInset() && inset) {
|
|
|
|
theLockingInset(inset);
|
2000-04-19 14:42:19 +00:00
|
|
|
return true;
|
|
|
|
} else if (inset) {
|
2001-06-28 10:25:20 +00:00
|
|
|
return theLockingInset()->lockInsetInInset(this, inset);
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
2000-04-19 14:42:19 +00:00
|
|
|
return false;
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-29 18:44:07 +00:00
|
|
|
void BufferView::showLockedInsetCursor(int x, int y, int asc, int desc)
|
2000-02-04 09:38:32 +00:00
|
|
|
{
|
2000-10-03 13:55:48 +00:00
|
|
|
if (theLockingInset() && available()) {
|
2000-04-19 14:42:19 +00:00
|
|
|
LyXCursor cursor = text->cursor;
|
2000-06-08 23:16:16 +00:00
|
|
|
if ((cursor.pos() - 1 >= 0) &&
|
2001-06-25 00:06:33 +00:00
|
|
|
(cursor.par()->getChar(cursor.pos() - 1) ==
|
|
|
|
Paragraph::META_INSET) &&
|
|
|
|
(cursor.par()->getInset(cursor.pos() - 1) ==
|
2001-06-28 10:25:20 +00:00
|
|
|
theLockingInset()->getLockingInset()))
|
2001-06-25 00:06:33 +00:00
|
|
|
text->setCursor(this, cursor,
|
2000-06-08 23:16:16 +00:00
|
|
|
cursor.par(), cursor.pos() - 1);
|
2000-12-17 06:09:35 +00:00
|
|
|
LyXScreen::Cursor_Shape shape = LyXScreen::BAR_SHAPE;
|
|
|
|
LyXText * txt = getLyXText();
|
2001-06-28 10:25:20 +00:00
|
|
|
if (theLockingInset()->getLockingInset()->lyxCode() ==
|
2000-12-17 06:09:35 +00:00
|
|
|
Inset::TEXT_CODE &&
|
|
|
|
(txt->real_current_font.language() !=
|
|
|
|
buffer()->params.language
|
|
|
|
|| txt->real_current_font.isVisibleRightToLeft()
|
|
|
|
!= buffer()->params.language->RightToLeft()))
|
|
|
|
shape = (txt->real_current_font.isVisibleRightToLeft())
|
|
|
|
? LyXScreen::REVERSED_L_SHAPE
|
|
|
|
: LyXScreen::L_SHAPE;
|
2001-06-28 10:25:20 +00:00
|
|
|
y += cursor.y() + theLockingInset()->insetInInsetY();
|
2001-07-04 07:19:09 +00:00
|
|
|
pimpl_->screen_->showManualCursor(text, x, y, asc, desc,
|
2000-12-17 06:09:35 +00:00
|
|
|
shape);
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-17 19:59:08 +00:00
|
|
|
void BufferView::hideLockedInsetCursor()
|
2000-02-04 09:38:32 +00:00
|
|
|
{
|
2000-10-03 13:55:48 +00:00
|
|
|
if (theLockingInset() && available()) {
|
2001-07-04 07:19:09 +00:00
|
|
|
pimpl_->screen_->hideCursor();
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-29 18:44:07 +00:00
|
|
|
void BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc)
|
2000-02-04 09:38:32 +00:00
|
|
|
{
|
2000-12-29 12:48:02 +00:00
|
|
|
if (theLockingInset() && available()) {
|
2001-06-28 10:25:20 +00:00
|
|
|
y += text->cursor.y() + theLockingInset()->insetInInsetY();
|
2001-07-04 07:19:09 +00:00
|
|
|
if (pimpl_->screen_->fitManualCursor(text, this, x, y, asc, desc))
|
2000-02-04 09:38:32 +00:00
|
|
|
updateScrollbar();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int BufferView::unlockInset(UpdatableInset * inset)
|
|
|
|
{
|
2000-10-03 13:55:48 +00:00
|
|
|
if (inset && theLockingInset() == inset) {
|
2001-06-28 10:25:20 +00:00
|
|
|
inset->insetUnlock(this);
|
2000-10-03 13:55:48 +00:00
|
|
|
theLockingInset(0);
|
2001-07-06 15:57:54 +00:00
|
|
|
finishUndo();
|
2000-02-04 09:38:32 +00:00
|
|
|
return 0;
|
2000-10-03 13:55:48 +00:00
|
|
|
} else if (inset && theLockingInset() &&
|
2001-06-28 10:25:20 +00:00
|
|
|
theLockingInset()->unlockInsetInInset(this, inset)) {
|
2001-07-06 15:57:54 +00:00
|
|
|
finishUndo();
|
2000-04-10 14:29:05 +00:00
|
|
|
return 0;
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
return bufferlist.unlockInset(inset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BufferView::lockedInsetStoreUndo(Undo::undo_kind kind)
|
|
|
|
{
|
2000-10-03 13:55:48 +00:00
|
|
|
if (!theLockingInset())
|
2000-02-04 09:38:32 +00:00
|
|
|
return; // shouldn't happen
|
|
|
|
if (kind == Undo::EDIT) // in this case insets would not be stored!
|
|
|
|
kind = Undo::FINISH;
|
2001-07-06 15:57:54 +00:00
|
|
|
setUndo(this, kind,
|
|
|
|
text->cursor.par(),
|
|
|
|
text->cursor.par()->next());
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
2000-02-23 16:39:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
void BufferView::updateInset(Inset * inset, bool mark_dirty)
|
|
|
|
{
|
2001-06-04 23:57:32 +00:00
|
|
|
pimpl_->updateInset(inset, mark_dirty);
|
2000-02-23 16:39:03 +00:00
|
|
|
}
|
2000-05-19 16:46:01 +00:00
|
|
|
|
2000-12-29 12:48:02 +00:00
|
|
|
|
2001-04-17 15:15:59 +00:00
|
|
|
bool BufferView::ChangeInsets(Inset::Code code,
|
|
|
|
string const & from, string const & to)
|
2000-05-19 16:46:01 +00:00
|
|
|
{
|
|
|
|
bool flag = false;
|
2001-06-25 00:06:33 +00:00
|
|
|
Paragraph * par = buffer()->paragraph;
|
2000-05-19 16:46:01 +00:00
|
|
|
LyXCursor cursor = text->cursor;
|
|
|
|
LyXCursor tmpcursor = cursor;
|
2000-07-24 21:49:58 +00:00
|
|
|
cursor.par(tmpcursor.par());
|
|
|
|
cursor.pos(tmpcursor.pos());
|
2000-05-19 16:46:01 +00:00
|
|
|
|
|
|
|
while (par) {
|
|
|
|
bool flag2 = false;
|
2001-06-25 00:06:33 +00:00
|
|
|
for (Paragraph::inset_iterator it = par->inset_iterator_begin();
|
2000-05-19 16:46:01 +00:00
|
|
|
it != par->inset_iterator_end(); ++it) {
|
2001-06-28 10:25:20 +00:00
|
|
|
if ((*it)->lyxCode() == code) {
|
2000-05-19 16:46:01 +00:00
|
|
|
InsetCommand * inset = static_cast<InsetCommand *>(*it);
|
|
|
|
if (inset->getContents() == from) {
|
|
|
|
inset->setContents(to);
|
|
|
|
flag2 = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-03-09 00:56:42 +00:00
|
|
|
if (flag2) {
|
|
|
|
flag = true;
|
|
|
|
// this is possible now, since SetCursor takes
|
|
|
|
// care about footnotes
|
2001-06-25 00:06:33 +00:00
|
|
|
text->setCursorIntern(this, par, 0);
|
|
|
|
text->redoParagraphs(this, text->cursor,
|
2001-03-09 00:56:42 +00:00
|
|
|
text->cursor.par()->next());
|
2001-06-25 00:06:33 +00:00
|
|
|
text->fullRebreak(this);
|
2001-03-09 00:56:42 +00:00
|
|
|
}
|
|
|
|
par = par->next();
|
2000-05-19 16:46:01 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
text->setCursorIntern(this, cursor.par(), cursor.pos());
|
2000-05-19 16:46:01 +00:00
|
|
|
return flag;
|
|
|
|
}
|
2000-10-03 13:55:48 +00:00
|
|
|
|
|
|
|
|
2000-12-11 09:46:09 +00:00
|
|
|
bool BufferView::ChangeRefsIfUnique(string const & from, string const & to)
|
|
|
|
{
|
|
|
|
// Check if the label 'from' appears more than once
|
|
|
|
vector<string> labels = buffer()->getLabelList();
|
|
|
|
if (count(labels.begin(), labels.end(), from) > 1)
|
|
|
|
return false;
|
|
|
|
|
2001-01-31 20:39:53 +00:00
|
|
|
return ChangeInsets(Inset::REF_CODE, from, to);
|
2000-12-11 09:46:09 +00:00
|
|
|
}
|
|
|
|
|
2000-12-29 12:48:02 +00:00
|
|
|
|
2001-01-31 20:39:53 +00:00
|
|
|
bool BufferView::ChangeCitationsIfUnique(string const & from, string const & to)
|
|
|
|
{
|
|
|
|
|
|
|
|
vector<pair<string,string> > keys = buffer()->getBibkeyList();
|
|
|
|
if (count_if(keys.begin(), keys.end(),
|
2001-04-24 15:25:26 +00:00
|
|
|
lyx::equal_1st_in_pair<string,string>(from))
|
2001-01-31 20:39:53 +00:00
|
|
|
> 1)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return ChangeInsets(Inset::CITE_CODE, from, to);
|
|
|
|
}
|
|
|
|
|
2001-06-04 23:57:32 +00:00
|
|
|
|
2000-10-03 13:55:48 +00:00
|
|
|
UpdatableInset * BufferView::theLockingInset() const
|
|
|
|
{
|
2000-12-17 06:09:35 +00:00
|
|
|
// If NULL is not allowed we should put an Assert here. (Lgb)
|
|
|
|
if (text)
|
|
|
|
return text->the_locking_inset;
|
|
|
|
return 0;
|
2000-10-03 13:55:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-03 15:31:35 +00:00
|
|
|
void BufferView::theLockingInset(UpdatableInset * inset)
|
2000-10-03 13:55:48 +00:00
|
|
|
{
|
2001-04-26 19:17:50 +00:00
|
|
|
text->the_locking_inset = inset;
|
2000-10-03 13:55:48 +00:00
|
|
|
}
|
2000-12-17 06:09:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
LyXText * BufferView::getLyXText() const
|
|
|
|
{
|
|
|
|
if (theLockingInset()) {
|
2001-02-22 14:09:20 +00:00
|
|
|
LyXText * txt = theLockingInset()->getLyXText(this, true);
|
2000-12-17 06:09:35 +00:00
|
|
|
if (txt)
|
|
|
|
return txt;
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2001-01-08 16:14:09 +00:00
|
|
|
|
|
|
|
LyXText * BufferView::getParentText(Inset * inset) const
|
|
|
|
{
|
|
|
|
if (inset->owner()) {
|
|
|
|
LyXText * txt = inset->getLyXText(this);
|
|
|
|
inset = inset->owner();
|
|
|
|
while (inset && inset->getLyXText(this) == txt)
|
|
|
|
inset = inset->owner();
|
|
|
|
if (inset)
|
|
|
|
return inset->getLyXText(this);
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2001-04-04 21:37:14 +00:00
|
|
|
|
2001-01-08 16:14:09 +00:00
|
|
|
Language const * BufferView::getParentLanguage(Inset * inset) const
|
|
|
|
{
|
|
|
|
LyXText * text = getParentText(inset);
|
2001-06-25 00:06:33 +00:00
|
|
|
return text->cursor.par()->getFontSettings(buffer()->params,
|
2001-01-08 16:14:09 +00:00
|
|
|
text->cursor.pos()).language();
|
|
|
|
}
|