// all these externs should eventually be removed.
extern BufferList bufferlist;
-extern void SmallUpdate(signed char);
-extern unsigned char GetCurrentTextClass();
-extern void BeforeChange();
extern void MenuExport(Buffer *, string const &);
extern LyXAction lyxaction;
filename = file;
filepath = OnlyPath(file);
paragraph = 0;
- the_locking_inset = 0;
lyx_clean = true;
bak_clean = true;
dvi_clean_orgd = false; // Heinrich Bauer, 23/03/98
dvi_clean_tmpd = false; // Heinrich Bauer, 23/03/98
dep_clean = 0;
read_only = ronly;
- inset_slept = false;
users = 0;
lyxvc.buffer(this);
if (read_only || (lyxrc && lyxrc->use_tempdir)) {
}
-// candidate for move to BufferView
-void Buffer::InsetUnlock()
-{
- if (the_locking_inset) {
- if (!inset_slept) the_locking_inset->InsetUnlock();
- the_locking_inset = 0;
- users->text->FinishUndo();
- inset_slept = false;
- }
-}
-
-
-// candidate for move to BufferView
// Inserts a file into current document
-bool Buffer::insertLyXFile(string const & filen)
+bool BufferView::insertLyXFile(string const & filen)
//
// (c) CHT Software Service GmbH
// Uwe C. Schroeder
return false;
}
- BeforeChange();
+ beforeChange();
- FilePtr myfile(fname, FilePtr::read);
- if (!myfile()) {
+ ifstream ifs(fname.c_str());
+ if (!ifs) {
WriteAlert(_("Error!"),
_("Cannot open specified file: "),
MakeDisplayPath(fname, 50));
return false;
}
LyXLex lex(0, 0);
- lex.setFile(myfile);
- int c = fgetc(myfile());
- ungetc(c, myfile);
+ lex.setStream(ifs);
+ char c; ifs.get(c);
+ ifs.putback(c);
bool res = true;
if (c == '#') {
lyxerr.debug() << "Will insert file with header" << endl;
- res = readFile(lex, users->text->cursor.par);
+ res = buffer()->readFile(lex, text->cursor.par);
} else {
lyxerr.debug() << "Will insert file without header" << endl;
- res = readLyXformat2(lex, users->text->cursor.par);
+ res = buffer()->readLyXformat2(lex, text->cursor.par);
}
resize();
continue;
else if (token[0] != '\\') {
int n = token.length();
- for (int i = 0; i < n; i++) {
+ for (int i = 0; i < n; ++i) {
par->InsertChar(pos, token[i]);
par->SetFont(pos, font);
- pos++;
+ ++pos;
}
} else if (token == "\\i") {
inset = new InsetLatexAccent;
font = LyXFont(LyXFont::ALL_INHERIT);
} else if (token == "\\begin_float") {
tmpret = lex.FindToken(string_footnotekinds);
- if (tmpret == -1) tmpret++;
+ if (tmpret == -1) ++tmpret;
if (tmpret != LYX_LAYOUT_DEFAULT)
footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
if (footnotekind == LyXParagraph::FOOTNOTE
else
footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
} else if (token == "\\begin_deeper") {
- depth++;
+ ++depth;
} else if (token == "\\end_deeper") {
if (!depth) {
lex.printError("\\end_deeper: "
"depth is already null");
}
else
- depth--;
+ --depth;
} else if (token == "\\begin_preamble") {
params.readPreamble(lex);
} else if (token == "\\textclass") {
lex.EatLine();
- pair<bool, LyXTextClassList::ClassList::size_type> pp =
+ pair<bool, LyXTextClassList::size_type> pp =
textclasslist.NumberOfClass(lex.GetString());
if (pp.first) {
params.textclass = pp.second;
lex.EatLine();
params.options = lex.GetString();
} else if (token == "\\language") {
- params.readLanguage(lex);
+ params.readLanguage(lex);
} else if (token == "\\fontencoding") {
lex.EatLine();
} else if (token == "\\inputencoding") {
} else if (token == "\\defskip") {
lex.nextToken();
params.defskip = VSpace(lex.GetString());
- } else if (token == "\\no_isolatin1") {
+ } else if (token == "\\no_isolatin1") { // obsolete
lex.nextToken();
- } else if (token == "\\no_babel") {
+ } else if (token == "\\no_babel") { // obsolete
lex.nextToken();
- } else if (token == "\\no_epsfig") {
+ } else if (token == "\\no_epsfig") { // obsolete
lex.nextToken();
} else if (token == "\\epsfig") { // obsolete
// Indeed it is obsolete, but we HAVE to be backwards
} else if (token == "\\tocdepth") {
lex.nextToken();
params.tocdepth = lex.GetInteger();
- } else if (token == "\\baselinestretch") { // now obsolete
+ } else if (token == "\\baselinestretch") { // obsolete
lex.nextToken(); // should not be used directly
// anymore.
// Will probably keep a kind of support just for
} else if (token == "\\float_placement") {
lex.nextToken();
params.float_placement = lex.GetString();
- } else if (token == "\\cursor") {
+ } else if (token == "\\cursor") { // obsolete
// this is obsolete, so we just skip it.
lex.nextToken();
} else if (token == "\\family") {
} else if (token == "\\align") {
tmpret = lex.FindToken(string_align);
if (tmpret == -1) tmpret++;
- if (tmpret != LYX_LAYOUT_DEFAULT) {
+ if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
tmpret2 = 1;
- for (; tmpret>0; tmpret--)
+ for (; tmpret > 0; --tmpret)
tmpret2 = tmpret2 * 2;
par->align = LyXAlignment(tmpret2);
}
- } else if (token == "\\added_space_top"){
+ } else if (token == "\\added_space_top") {
lex.nextToken();
par->added_space_top = lex.GetString();
} else if (token == "\\added_space_bottom") {
par->InsertInset(pos, inset);
par->SetFont(pos, font);
pos++;
+#if 0
} else if (tmptok == "Label") {
// Kept for compability. Remove in 0.13.
if (lex.EatLine()) {
par->SetFont(pos, font);
pos++;
}
+#endif
} else if (tmptok == "Info") {
inset = new InsetInfo;
inset->Read(lex);
if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
inset = new InsetRef(inscmd, this);
}
- /* This condition comes from a temporary solution
- to the latexdel ref inset that was transformed to an empty ref
- inset plus the body surronded by latexdel insets */
+ // This condition comes from a
+ // temporary solution to the latexdel
+ // ref inset that was transformed to
+ // an empty ref inset plus the body
+ // surronded by latexdel insets
else {
string cont, opt, tmptmptok, cmdname;
lex.next();
inset = new InsetPrintIndex(this);
} else if (inscmd.getCmdName() == "lyxparent") {
inset = new InsetParent(inscmd.getContents(), this);
- } else
+ }
+#if 0
+ // Do we need this at all now?
+ else
// The following three are only for compatibility
if (inscmd.getCmdName() == "-") {
inset = new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
inset = new InsetSpecialChar(InsetSpecialChar::LDOTS);
} else
inset = inscmd.Clone();
+#endif
if (inset) {
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
- pos++;
+ ++pos;
}
}
} else if (token == "\\InsetQuotes") {
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
- pos++;
+ ++pos;
#if 0
} else if (token == "\\InsetLatex") {
inset = new InsetLatex;
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
- pos++;
+ ++pos;
} else if (token == "\\InsetLatexDel") {
lex.printError(_("Warning: Ignoring Old Inset"));
#endif
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
- pos++;
+ ++pos;
} else if (token == "\\SpecialChar") {
inset = new InsetSpecialChar;
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
- pos++;
+ ++pos;
} else if (token == "\\Figure") {
inset = new InsetFig(100, 100, this);
inset->Read(lex);
par->InsertChar(pos, LyXParagraph::META_INSET);
par->InsertInset(pos, inset);
par->SetFont(pos, font);
- pos++;
+ ++pos;
} else if (token == "\\newline") {
par->InsertChar(pos, LyXParagraph::META_NEWLINE);
par->SetFont(pos, font);
- pos++;
+ ++pos;
} else if (token == "\\LyXTable") {
par->table = new LyXTable(lex);
} else if (token == "\\hfill") {
par->InsertChar(pos, LyXParagraph::META_HFILL);
par->SetFont(pos, font);
- pos++;
+ ++pos;
} else if (token == "\\protected_separator") {
par->InsertChar(pos, LyXParagraph::META_PROTECTED_SEPARATOR);
par->SetFont(pos, font);
- pos++;
+ ++pos;
} else if (token == "\\bibitem") { // ale970302
if (!par->bibkey)
par->bibkey = new InsetBibKey;
}else if (token == "\\backslash") {
par->InsertChar(pos, '\\');
par->SetFont(pos, font);
- pos++;
+ ++pos;
}else if (token == "\\the_end") {
the_end_read = true;
} else {
lex.printError("Unknown token `$$Token'. "
"Inserting as text.");
int n = token.length();
- for (int i = 0; i < n; i++) {
+ for (int i = 0; i < n; ++i) {
par->InsertChar(pos, token[i]);
par->SetFont(pos, font);
- pos++;
+ ++pos;
}
}
}
bool nice, bool only_body)
{
lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
- params.textclass = GetCurrentTextClass();
+
+ // How the **** can this be needed?
+ //params.textclass = current_view->buffer()->params.textclass;
+
niceFile = nice; // this will be used by Insetincludes.
tex_code_break_column = lyxrc->ascii_linelen;
}
lyxerr.debug() << "lyx header finished" << endl;
// There are a few differences between nice LaTeX and usual files:
- // usual is \batchmode, uses \listfiles and has a
+ // usual is \batchmode and has a
// special input@path to allow the including of figures
// with either \input or \includegraphics (what figinsets do).
// batchmode is not set if there is a tex_code_break_column.
LFile += "\\batchmode\n"; // changed
// from \nonstopmode
texrow.newline();
- // We don't need listfiles anymore
- //LFile += "\\listfiles\n";
- //texrow.newline();
}
if (!original_path.empty()) {
LFile += "\\makeatletter\n";
void Buffer::sgmlOpenTag(ostream & os, int depth,
string const & latexname) const
{
-#if 0
- static char const * space[] = {
- " "," ", " ", " ", " ", " ",
- " ",
- " ", " ", " ",
- " "};
- os << space[depth] << "<" << latexname << ">\n";
-#endif
os << string(depth, ' ') << "<" << latexname << ">\n";
}
void Buffer::sgmlCloseTag(ostream & os, int depth,
string const & latexname) const
{
-#if 0
- static char * space[] = {" ", " ", " ", " ", " ",
- " ", " ", " ",
- " ", " ", " "};
-
- os << space[depth] << "</" << latexname << ">\n";
-#endif
os << string(depth, ' ') << "</" << latexname << ">\n";
}
while (par) {
int desc_on = 0; /* description mode*/
LyXLayout const & style =
- textclasslist.Style(GetCurrentTextClass(),
+ textclasslist.Style(users->buffer()->params.textclass,
par->layout);
par->AutoDeleteInsets();
}
}
- /* environment tag closing */
+ // environment tag closing
for( ; depth > par->depth; --depth) {
sgmlCloseTag(ofs, depth, environment_stack[depth]);
environment_stack[depth].clear();
}
- /* write opening SGML tags */
+ // write opening SGML tags
switch(style.latextype) {
case LATEX_PARAGRAPH:
if(depth == par->depth
void Buffer::push_tag(ostream & os, char const * tag,
int & pos, char stack[5][3])
{
- int j;
-
/* pop all previous tags */
- for (j = pos; j >= 0; --j)
+ for (int j = pos; j >= 0; --j)
os << "</" << stack[j] << ">";
/* add new tag */
sprintf(stack[++pos], "%s", tag);
/* push all tags */
- for (j = 0; j <= pos; ++j)
- os << "<" << stack[j] << ">";
+ for (int i = 0; i <= pos; ++i)
+ os << "<" << stack[i] << ">";
}
void Buffer::pop_tag(ostream & os, char const * tag,
int & pos, char stack[5][3])
{
- int j;
-
// pop all tags till specified one
- for (j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
+ for (int j = pos; (j >= 0) && (strcmp(stack[j], tag)); --j)
os << "</" << stack[j] << ">";
// closes the tag
os << "</" << tag << ">";
// push all tags, but the specified one
- for (j = j + 1; j <= pos; ++j) {
- os << "<" << stack[j] << ">";
- strcpy(stack[j-1], stack[j]);
+ for (int i = 0; i <= pos; ++i) {
+ os << "<" << stack[i] << ">";
+ strcpy(stack[i - 1], stack[i]);
}
--pos;
}
return;
}
- //ResetTexRow();
texrow.reset();
ofs << "<!doctype " << top_element
while (par) {
int desc_on= 0; /* description mode*/
- LyXLayout const & style = textclasslist.Style(GetCurrentTextClass(),
+ LyXLayout const & style = textclasslist.Style(users->buffer()->params.textclass,
par->layout);
par->AutoDeleteInsets();
}
-// candidate for move to BufferView
-bool Buffer::removeAutoInsets()
+bool BufferView::removeAutoInsets()
{
- LyXParagraph * par = paragraph;
+ LyXParagraph * par = buffer()->paragraph;
- LyXCursor cursor = users->text->cursor;
+ LyXCursor cursor = text->cursor;
LyXCursor tmpcursor = cursor;
cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
if (par->AutoDeleteInsets()){
a = true;
if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){
- /* this is possible now, since SetCursor takes
- care about footnotes */
- users->text->SetCursorIntern(par, 0);
- users->text->RedoParagraphs(users->text->cursor, users->text->cursor.par->Next());
- users->text->FullRebreak();
+ // this is possible now, since SetCursor takes
+ // care about footnotes
+ text->SetCursorIntern(par, 0);
+ text->RedoParagraphs(text->cursor,
+ text->cursor.par->Next());
+ text->FullRebreak();
}
}
par = par->next;
}
- /* avoid forbidden cursor positions caused by error removing */
+ // avoid forbidden cursor positions caused by error removing
if (cursor.pos > cursor.par->Last())
cursor.pos = cursor.par->Last();
- users->text->SetCursorIntern(cursor.par, cursor.pos);
+ text->SetCursorIntern(cursor.par, cursor.pos);
return a;
}
users->owner()->getMiniBuffer()->Set(_("Running LaTeX..."));
// Remove all error insets
- bool a = removeAutoInsets();
+ bool a = users->removeAutoInsets();
// Always generate the LaTeX file
makeLaTeXFile(name, org_path, false);
} else if ((res & LaTeX::ERRORS)) {
users->owner()->getMiniBuffer()->Set(_("Done"));
// Insert all errors as errors boxes
- insertErrors(terr);
+ users->insertErrors(terr);
// Dvi should also be kept dirty if the latex run
// ends up with errors. However it should be possible
users->owner()->getMiniBuffer()->Set(_("Running Literate..."));
// Remove all error insets
- bool a = removeAutoInsets();
+ bool a = users->removeAutoInsets();
// generate the Literate file if necessary
if (!isDviClean() || a) {
} else if ((res & Literate::ERRORS)) {
users->owner()->getMiniBuffer()->Set(_("Done"));
// Insert all errors as errors boxes
- insertErrors(terr);
+ users->insertErrors(terr);
// Dvi should also be kept dirty if the latex run
// ends up with errors. However it should be possible
users->owner()->getMiniBuffer()->Set(_("Building Program..."));
// Remove all error insets
- bool a = removeAutoInsets();
+ bool a = users->removeAutoInsets();
// generate the LaTeX file if necessary
if (!isNwClean() || a) {
} else if ((res & Literate::ERRORS)) {
users->owner()->getMiniBuffer()->Set(_("Done"));
// Insert all errors as errors boxes
- insertErrors(terr);
+ users->insertErrors(terr);
// Literate files should also be kept dirty if the literate
// command run ends up with errors.
users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
// Remove all error insets
- bool a = removeAutoInsets();
+ bool a = users->removeAutoInsets();
// Generate the LaTeX file if neccessary
if (!isDviClean() || a) {
_("Could not run with file:"), name);
} else if (res > 0) {
// Insert all errors as errors boxes
- insertErrors(terr);
+ users->insertErrors(terr);
}
// if we removed error insets before we ran chktex or if we inserted
}
-extern void AllFloats(char, char);
-
-
-// candidate for move to BufferView
-void Buffer::insertErrors(TeXErrors & terr)
+void BufferView::insertErrors(TeXErrors & terr)
{
// Save the cursor position
- LyXCursor cursor = users->text->cursor;
+ LyXCursor cursor = text->cursor;
// This is drastic, but it's the only fix, I could find. (Asger)
- AllFloats(1, 0);
- AllFloats(1, 1);
+ allFloats(1, 0);
+ allFloats(1, 1);
for (TeXErrors::Errors::const_iterator cit = terr.begin();
cit != terr.end();
int tmpid = -1;
int tmppos = -1;
- texrow.getIdFromRow(errorrow, tmpid, tmppos);
+ buffer()->texrow.getIdFromRow(errorrow, tmpid, tmppos);
LyXParagraph * texrowpar = 0;
if (tmpid == -1) {
- texrowpar = users->text->FirstParagraph();
+ texrowpar = text->FirstParagraph();
tmppos = 0;
} else {
- texrowpar = users->text->GetParFromID(tmpid);
+ texrowpar = text->GetParFromID(tmpid);
}
if (texrowpar == 0)
continue;
InsetError * new_inset = new InsetError(msgtxt);
- users->text->SetCursorIntern(texrowpar, tmppos);
- users->text->InsertInset(new_inset);
- users->text->FullRebreak();
+ text->SetCursorIntern(texrowpar, tmppos);
+ text->InsertInset(new_inset);
+ text->FullRebreak();
}
// Restore the cursor position
- users->text->SetCursorIntern(cursor.par, cursor.pos);
+ text->SetCursorIntern(cursor.par, cursor.pos);
}
-// candidate for move to BufferView
-void Buffer::setCursorFromRow (int row)
+void BufferView::setCursorFromRow(int row)
{
int tmpid = -1;
int tmppos = -1;
- texrow.getIdFromRow(row, tmpid, tmppos);
+ buffer()->texrow.getIdFromRow(row, tmpid, tmppos);
LyXParagraph * texrowpar;
if (tmpid == -1) {
- texrowpar = users->text->FirstParagraph();
+ texrowpar = text->FirstParagraph();
tmppos = 0;
} else {
- texrowpar = users->text->GetParFromID(tmpid);
+ texrowpar = text->GetParFromID(tmpid);
}
- users->text->SetCursor(texrowpar, tmppos);
+ text->SetCursor(texrowpar, tmppos);
}
#endif
-// candidate for move to BufferView
-void Buffer::insertInset(Inset * inset, string const & lout,
+void BufferView::insertInset(Inset * inset, string const & lout,
bool no_table)
{
// check for table/list in tables
- if (no_table && users->text->cursor.par->table){
+ if (no_table && text->cursor.par->table){
WriteAlert(_("Impossible Operation!"),
_("Cannot insert table/list in table."),
_("Sorry."));
return;
}
// not quite sure if we want this...
- users->text->SetCursorParUndo();
- users->text->FreezeUndo();
+ text->SetCursorParUndo();
+ text->FreezeUndo();
- BeforeChange();
+ beforeChange();
if (!lout.empty()) {
- users->update(-2);
- users->text->BreakParagraph();
- users->update(-1);
+ update(-2);
+ text->BreakParagraph();
+ update(-1);
- if (users->text->cursor.par->Last()) {
- users->text->CursorLeft();
+ if (text->cursor.par->Last()) {
+ text->CursorLeft();
- users->text->BreakParagraph();
- users->update(-1);
+ text->BreakParagraph();
+ update(-1);
}
- int lay = textclasslist.NumberOfLayout(params.textclass,
+ int lay = textclasslist.NumberOfLayout(buffer()->params.textclass,
lout).second;
if (lay == -1) // layout not found
// use default layout "Standard" (0)
lay = 0;
- users->text->SetLayout(lay);
+ text->SetLayout(lay);
- users->text->SetParagraph(0, 0,
+ text->SetParagraph(0, 0,
0, 0,
VSpace(VSpace::NONE), VSpace(VSpace::NONE),
LYX_ALIGN_LAYOUT,
string(),
0);
- users->update(-1);
+ update(-1);
- users->text->current_font.setLatex(LyXFont::OFF);
+ text->current_font.setLatex(LyXFont::OFF);
}
- users->text->InsertInset(inset);
- users->update(-1);
+ text->InsertInset(inset);
+ update(-1);
- users->text->UnFreezeUndo();
+ text->UnFreezeUndo();
}
// Open and lock an updatable inset
-// candidate for move to BufferView
-void Buffer::open_new_inset(UpdatableInset * new_inset)
+void BufferView::open_new_inset(UpdatableInset * new_inset)
{
- BeforeChange();
- users->text->FinishUndo();
+ beforeChange();
+ text->FinishUndo();
insertInset(new_inset);
- users->text->CursorLeft();
- users->update(1);
+ text->CursorLeft();
+ update(1);
new_inset->Edit(0, 0);
}
-/* This function should be in Buffer because it's a buffer's property (ale) */
+// This function should be in Buffer because it's a buffer's property (ale)
string Buffer::getIncludeonlyList(char delim)
{
string lst;
}
-/* This is also a buffer property (ale) */
+// This is also a buffer property (ale)
string Buffer::getReferenceList(char delim)
{
/// if this is a child document and the parent is already loaded
}
-/* This is also a buffer property (ale) */
+// This is also a buffer property (ale)
string Buffer::getBibkeyList(char delim)
{
/// if this is a child document and the parent is already loaded
}
-// candidate for move to BufferView
/* 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 Buffer::gotoLabel(string const & label)
+bool BufferView::gotoLabel(string const & label)
{
- LyXParagraph * par = paragraph;
+ LyXParagraph * par = buffer()->paragraph;
LyXParagraph::size_type pos;
Inset * inset;
while (par) {
while ((inset = par->ReturnNextInsetPointer(pos))){
for (int i = 0; i < inset->GetNumberOfLabels(); i++) {
if (label == inset->getLabel(i)) {
- BeforeChange();
- users->text->SetCursor(par, pos);
- users->text->sel_cursor = users->text->cursor;
- users->update(0);
+ beforeChange();
+ text->SetCursor(par, pos);
+ text->sel_cursor = text->cursor;
+ update(0);
return true;
}
}
}
}
-void Buffer::Dispatch(const string & command)
+
+void Buffer::Dispatch(string const & command)
{
// Split command string into command and argument
string cmd, line = frontStrip(command);
Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
}
-void Buffer::Dispatch(int action, const string & argument)
+
+void Buffer::Dispatch(int action, string const & argument)
{
switch (action) {
case LFUN_EXPORT:
break;
} // end of switch
-
}