2000-02-04 09:38:32 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
|
|
|
* Copyright 1995-2000 The LyX Team.
|
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
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
|
|
|
|
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 "insets/insetinfo.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"
|
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 == '#') {
|
|
|
|
lyxerr.debug() << "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 {
|
|
|
|
lyxerr.debug() << "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()
|
|
|
|
{
|
|
|
|
LyXParagraph * par = buffer()->paragraph;
|
|
|
|
|
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
|
|
|
|
text->SetCursor(this, cursor, par, 0);
|
|
|
|
if (par->AutoDeleteInsets()){
|
|
|
|
a = true;
|
|
|
|
text->RedoParagraphs(this, cursor,
|
|
|
|
cursor.par()->next());
|
|
|
|
text->FullRebreak(this);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2000-06-12 11:27:15 +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) {
|
2000-12-29 12:48:02 +00:00
|
|
|
string const desctext((*cit).error_desc);
|
|
|
|
string const errortext((*cit).error_text);
|
|
|
|
string const msgtxt = desctext + '\n' + errortext;
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
LyXParagraph * texrowpar = 0;
|
|
|
|
|
|
|
|
if (tmpid == -1) {
|
|
|
|
texrowpar = text->FirstParagraph();
|
|
|
|
tmppos = 0;
|
|
|
|
} else {
|
|
|
|
texrowpar = text->GetParFromID(tmpid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (texrowpar == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
InsetError * new_inset = new InsetError(msgtxt);
|
2000-06-12 11:27:15 +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
|
2000-06-12 11:27:15 +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);
|
|
|
|
|
|
|
|
LyXParagraph * texrowpar;
|
|
|
|
|
|
|
|
if (tmpid == -1) {
|
|
|
|
texrowpar = text->FirstParagraph();
|
|
|
|
tmppos = 0;
|
|
|
|
} else {
|
|
|
|
texrowpar = text->GetParFromID(tmpid);
|
|
|
|
}
|
2000-06-12 11:27:15 +00:00
|
|
|
text->SetCursor(this, texrowpar, tmppos);
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
2000-10-03 18:38:10 +00:00
|
|
|
|
2000-05-15 14:49:36 +00:00
|
|
|
bool BufferView::insertInset(Inset * inset, string const & lout,
|
2000-10-03 18:38:10 +00:00
|
|
|
bool /*no_table*/)
|
2000-02-04 09:38:32 +00:00
|
|
|
{
|
2000-05-15 14:49:36 +00:00
|
|
|
// if we are in a locking inset we should try to insert the
|
|
|
|
// inset there otherwise this is a illegal function now
|
2000-10-03 13:55:48 +00:00
|
|
|
if (theLockingInset()) {
|
|
|
|
if (theLockingInset()->InsertInsetAllowed(inset))
|
|
|
|
return theLockingInset()->InsertInset(this, inset);
|
2000-05-15 14:49:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
// not quite sure if we want this...
|
2000-06-12 11:27:15 +00:00
|
|
|
text->SetCursorParUndo(buffer());
|
2000-02-04 09:38:32 +00:00
|
|
|
text->FreezeUndo();
|
|
|
|
|
2001-02-14 10:11:22 +00:00
|
|
|
beforeChange(text);
|
2000-02-04 09:38:32 +00:00
|
|
|
if (!lout.empty()) {
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR);
|
2000-06-12 11:27:15 +00:00
|
|
|
text->BreakParagraph(this);
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
|
2001-03-11 00:21:13 +00:00
|
|
|
|
|
|
|
if (text->cursor.par()->size()) {
|
2000-06-12 11:27:15 +00:00
|
|
|
text->CursorLeft(this);
|
2000-02-04 09:38:32 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
text->BreakParagraph(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
|
|
|
}
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
pair<bool, LyXTextClass::size_type> lres =
|
|
|
|
textclasslist.NumberOfLayout(buffer()->params
|
|
|
|
.textclass, lout);
|
|
|
|
LyXTextClass::size_type lay;
|
|
|
|
if (lres.first != false) {
|
|
|
|
// layout found
|
|
|
|
lay = lres.second;
|
|
|
|
} else {
|
|
|
|
// layout not fount using default "Standard" (0)
|
2000-02-04 09:38:32 +00:00
|
|
|
lay = 0;
|
2000-02-29 02:19:17 +00:00
|
|
|
}
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
text->SetLayout(this, lay);
|
2000-02-04 09:38:32 +00:00
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
text->SetParagraph(this, 0, 0,
|
2000-02-04 09:38:32 +00:00
|
|
|
0, 0,
|
|
|
|
VSpace(VSpace::NONE), VSpace(VSpace::NONE),
|
|
|
|
LYX_ALIGN_LAYOUT,
|
|
|
|
string(),
|
|
|
|
0);
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
text->current_font.setLatex(LyXFont::OFF);
|
|
|
|
}
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
text->InsertInset(this, inset);
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
|
2000-02-04 09:38:32 +00:00
|
|
|
|
2000-05-15 14:49:36 +00:00
|
|
|
text->UnFreezeUndo();
|
|
|
|
return true;
|
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);
|
2000-06-12 11:27:15 +00:00
|
|
|
text->SetCursor(this, it.getPar(), it.getPos());
|
2000-05-19 16:46:01 +00:00
|
|
|
text->sel_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);
|
2000-06-12 11:27:15 +00:00
|
|
|
if (!text->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);
|
2000-06-12 11:27:15 +00:00
|
|
|
if (!text->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-02-22 14:09:20 +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()) {
|
2000-06-15 15:44:39 +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-02-22 14:09:20 +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);
|
2000-06-12 11:27:15 +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-02-22 14:09:20 +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
|
2000-06-12 11:27:15 +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-02-22 14:09:20 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-15 18:54:31 +00:00
|
|
|
void BufferView::gotoInset(std::vector<Inset::Code> const & codes,
|
|
|
|
bool same_content)
|
2000-02-04 09:38:32 +00:00
|
|
|
{
|
2000-02-17 19:59:08 +00:00
|
|
|
if (!available()) return;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
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-01-15 18:54:31 +00:00
|
|
|
|
|
|
|
string contents;
|
|
|
|
if (same_content &&
|
|
|
|
text->cursor.par()->GetChar(text->cursor.pos()) == LyXParagraph::META_INSET) {
|
|
|
|
Inset const * inset = text->cursor.par()->GetInset(text->cursor.pos());
|
|
|
|
if (find(codes.begin(), codes.end(), inset->LyxCode())
|
|
|
|
!= codes.end())
|
|
|
|
contents =
|
|
|
|
static_cast<InsetCommand const *>(inset)->getContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!text->GotoNextInset(this, codes, contents)) {
|
2000-06-08 23:16:16 +00:00
|
|
|
if (text->cursor.pos()
|
|
|
|
|| text->cursor.par() != text->FirstParagraph()) {
|
2001-01-15 18:54:31 +00:00
|
|
|
LyXCursor tmp = text->cursor;
|
2000-06-08 23:16:16 +00:00
|
|
|
text->cursor.par(text->FirstParagraph());
|
|
|
|
text->cursor.pos(0);
|
2001-01-15 18:54:31 +00:00
|
|
|
if (!text->GotoNextInset(this, codes, contents)) {
|
2000-02-04 09:38:32 +00:00
|
|
|
text->cursor = tmp;
|
2001-04-24 17:33:01 +00:00
|
|
|
owner()->message(_("No more insets"));
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
} else {
|
2001-04-24 17:33:01 +00:00
|
|
|
owner()->message(_("No more insets"));
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR);
|
2000-02-04 09:38:32 +00:00
|
|
|
text->sel_cursor = text->cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-15 18:54:31 +00:00
|
|
|
void BufferView::gotoInset(Inset::Code code, bool same_content)
|
|
|
|
{
|
|
|
|
gotoInset(vector<Inset::Code>(1, code), same_content);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
void BufferView::insertCorrectQuote()
|
|
|
|
{
|
|
|
|
char c;
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
if (text->cursor.pos())
|
|
|
|
c = text->cursor.par()->GetChar(text->cursor.pos() - 1);
|
2000-02-04 09:38:32 +00:00
|
|
|
else
|
|
|
|
c = ' ';
|
|
|
|
|
|
|
|
insertInset(new InsetQuotes(c, buffer()->params));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
}
|
|
|
|
|
2000-09-14 17:53:12 +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);
|
2000-06-12 11:27:15 +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);
|
2000-06-12 11:27:15 +00:00
|
|
|
text->SelectSelectedWord(this);
|
2001-02-22 14:09:20 +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
|
|
|
}
|
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
|
|
|
|
2000-02-17 19:59:08 +00:00
|
|
|
hideCursor();
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, 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-02-14 08:38:21 +00:00
|
|
|
update(text, 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);
|
2000-09-26 13:54:57 +00:00
|
|
|
text->ReplaceSelectionWithString(this, replacestring);
|
2000-02-04 09:38:32 +00:00
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
text->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) {
|
2000-09-26 13:54:57 +00:00
|
|
|
text->CursorLeft(this);
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, 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) {
|
2000-10-03 13:55:48 +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) &&
|
|
|
|
(cursor.par()->GetChar(cursor.pos() - 1) ==
|
2000-04-19 14:42:19 +00:00
|
|
|
LyXParagraph::META_INSET) &&
|
2000-06-08 23:16:16 +00:00
|
|
|
(cursor.par()->GetInset(cursor.pos() - 1) ==
|
2000-10-03 13:55:48 +00:00
|
|
|
theLockingInset()->GetLockingInset()))
|
2000-06-12 11:27:15 +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();
|
|
|
|
if (theLockingInset()->GetLockingInset()->LyxCode() ==
|
|
|
|
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;
|
2000-10-03 13:55:48 +00:00
|
|
|
y += cursor.y() + theLockingInset()->InsetInInsetY();
|
2000-06-22 14:55:46 +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()) {
|
2000-06-19 15:33:58 +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()) {
|
2000-10-03 13:55:48 +00:00
|
|
|
y += text->cursor.y() + theLockingInset()->InsetInInsetY();
|
2001-01-02 16:06:14 +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) {
|
2000-02-22 00:36:17 +00:00
|
|
|
inset->InsetUnlock(this);
|
2000-10-03 13:55:48 +00:00
|
|
|
theLockingInset(0);
|
2000-02-04 09:38:32 +00:00
|
|
|
text->FinishUndo();
|
|
|
|
return 0;
|
2000-10-03 13:55:48 +00:00
|
|
|
} else if (inset && theLockingInset() &&
|
|
|
|
theLockingInset()->UnlockInsetInInset(this, inset)) {
|
2000-04-10 14:29:05 +00:00
|
|
|
text->FinishUndo();
|
|
|
|
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-03-09 00:56:42 +00:00
|
|
|
text->SetUndo(buffer(), kind,
|
|
|
|
text->cursor.par()->previous(),
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (!inset)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// first check for locking insets
|
2000-10-03 13:55:48 +00:00
|
|
|
if (theLockingInset()) {
|
|
|
|
if (theLockingInset() == inset) {
|
2000-12-29 12:48:02 +00:00
|
|
|
if (text->UpdateInset(this, inset)) {
|
2000-02-25 12:06:15 +00:00
|
|
|
update();
|
2000-12-29 12:48:02 +00:00
|
|
|
if (mark_dirty) {
|
2000-02-25 12:06:15 +00:00
|
|
|
buffer()->markDirty();
|
|
|
|
}
|
|
|
|
updateScrollbar();
|
|
|
|
return;
|
|
|
|
}
|
2000-10-03 13:55:48 +00:00
|
|
|
} else if (theLockingInset()->UpdateInsetInInset(this,inset)) {
|
|
|
|
if (text->UpdateInset(this, theLockingInset())) {
|
2000-02-25 12:06:15 +00:00
|
|
|
update();
|
|
|
|
if (mark_dirty){
|
|
|
|
buffer()->markDirty();
|
|
|
|
}
|
|
|
|
updateScrollbar();
|
|
|
|
return;
|
2000-02-23 16:39:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// then check the current buffer
|
|
|
|
if (available()) {
|
|
|
|
hideCursor();
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::UPDATE);
|
2000-12-29 12:48:02 +00:00
|
|
|
if (text->UpdateInset(this, inset)) {
|
2000-02-23 16:39:03 +00:00
|
|
|
if (mark_dirty)
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
|
2000-02-23 16:39:03 +00:00
|
|
|
else
|
2001-02-14 08:38:21 +00:00
|
|
|
update(text, SELECT);
|
2000-02-23 16:39:03 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
LyXParagraph * par = buffer()->paragraph;
|
|
|
|
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;
|
|
|
|
for (LyXParagraph::inset_iterator it = par->inset_iterator_begin();
|
|
|
|
it != par->inset_iterator_end(); ++it) {
|
2001-01-31 20:39:53 +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
|
|
|
|
text->SetCursorIntern(this, par, 0);
|
|
|
|
text->RedoParagraphs(this, text->cursor,
|
|
|
|
text->cursor.par()->next());
|
|
|
|
text->FullRebreak(this);
|
|
|
|
}
|
|
|
|
par = par->next();
|
2000-05-19 16:46:01 +00:00
|
|
|
}
|
2000-06-12 11:27:15 +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);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
return text->cursor.par()->GetFontSettings(buffer()->params,
|
|
|
|
text->cursor.pos()).language();
|
|
|
|
}
|