X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fbuffer.C;h=e0953cf145bdde710a6fad6f78f0acb7232a5fe5;hb=53b464c5e95ed708e9464db0499826894be450fd;hp=155949a5668157a4f31da27d67f41b44b3c11e63;hpb=c32b845a5350bf1b683c4590221135903a177685;p=features.git diff --git a/src/buffer.C b/src/buffer.C index 155949a566..e0953cf145 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -101,9 +101,6 @@ using std::setw; // 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; @@ -122,17 +119,12 @@ Buffer::Buffer(string const & file, LyXRC * lyxrc, bool ronly) filename = file; filepath = OnlyPath(file); paragraph = 0; -#ifndef MOVE_TEXT - text = 0; -#endif - 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)) { @@ -164,9 +156,6 @@ Buffer::~Buffer() par = tmppar; } paragraph = 0; -#ifndef MOVE_TEXT - delete text; -#endif } @@ -211,25 +200,8 @@ void Buffer::fileName(string const & newfile) } -// candidate for move to BufferView -void Buffer::InsetUnlock() -{ - if (the_locking_inset) { - if (!inset_slept) the_locking_inset->InsetUnlock(); - the_locking_inset = 0; -#ifdef MOVE_TEXT - users->text->FinishUndo(); -#else - text->FinishUndo(); -#endif - 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 @@ -240,51 +212,42 @@ bool Buffer::insertLyXFile(string const & filen) { if (filen.empty()) return false; - string filename = MakeAbsPath(filen); + string fname = MakeAbsPath(filen); // check if file exist - FileInfo fi(filename); + FileInfo fi(fname); if (!fi.readable()) { WriteAlert(_("Error!"), _("Specified file is unreadable: "), - MakeDisplayPath(filename, 50)); + MakeDisplayPath(fname, 50)); return false; } - BeforeChange(); + beforeChange(); - FilePtr myfile(filename, FilePtr::read); - if (!myfile()) { + ifstream ifs(fname.c_str()); + if (!ifs) { WriteAlert(_("Error!"), _("Cannot open specified file: "), - MakeDisplayPath(filename, 50)); + 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; -#ifdef MOVE_TEXT 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); } -#else - if (c == '#') { - lyxerr.debug() << "Will insert file with header" << endl; - res = readFile(lex, text->cursor.par); - } else { - lyxerr.debug() << "Will insert file without header" << endl; - res = readLyXformat2(lex, text->cursor.par); - } -#endif + resize(); return res; } @@ -319,13 +282,8 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) if(!par) { par = new LyXParagraph; } else { -#ifdef MOVE_TEXT users->text->BreakParagraph(); return_par = users->text->FirstParagraph(); -#else - text->BreakParagraph(); - return_par = text->FirstParagraph(); -#endif pos = 0; markDirty(); // We don't want to adopt the parameters from the @@ -355,10 +313,10 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) 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; @@ -413,7 +371,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) 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(tmpret); // bad if (footnotekind == LyXParagraph::FOOTNOTE @@ -422,19 +380,19 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) 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 pp = + pair pp = textclasslist.NumberOfClass(lex.GetString()); if (pp.first) { params.textclass = pp.second; @@ -458,7 +416,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) 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") { @@ -494,11 +452,11 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) } 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 @@ -666,7 +624,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) } 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 @@ -691,7 +649,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) } 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") { @@ -744,13 +702,13 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) } 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") { @@ -924,6 +882,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) 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()) { @@ -936,6 +895,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) par->SetFont(pos, font); pos++; } +#endif } else if (tmptok == "Info") { inset = new InsetInfo; inset->Read(lex); @@ -974,9 +934,11 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) 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(); @@ -1037,7 +999,10 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) 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); @@ -1047,12 +1012,13 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) 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") { @@ -1061,7 +1027,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) 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; @@ -1069,7 +1035,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) 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 @@ -1079,35 +1045,35 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) 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; @@ -1115,7 +1081,7 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) }else if (token == "\\backslash") { par->InsertChar(pos, '\\'); par->SetFont(pos, font); - pos++; + ++pos; }else if (token == "\\the_end") { the_end_read = true; } else { @@ -1123,10 +1089,10 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) 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; } } } @@ -1198,45 +1164,45 @@ bool Buffer::readFile(LyXLex & lex, LyXParagraph * par) // Returns false if unsuccesful -bool Buffer::writeFile(string const & filename, bool flag) +bool Buffer::writeFile(string const & fname, bool flag) { // if flag is false writeFile will not create any GUI // warnings, only cerr. // Needed for autosave in background or panic save (Matthias 120496) - if (read_only && (filename == this->filename)) { + if (read_only && (fname == filename)) { // Here we should come with a question if we should // perform the write anyway. if (flag) lyxerr << _("Error! Document is read-only: ") - << filename << endl; + << fname << endl; else WriteAlert(_("Error! Document is read-only: "), - filename); + fname); return false; } - FileInfo finfo(filename); + FileInfo finfo(fname); if (finfo.exist() && !finfo.writable()) { // Here we should come with a question if we should // try to do the save anyway. (i.e. do a chmod first) if (flag) lyxerr << _("Error! Cannot write file: ") - << filename << endl; + << fname << endl; else WriteFSAlert(_("Error! Cannot write file: "), - filename); + fname); return false; } - ofstream ofs(filename.c_str()); + ofstream ofs(fname.c_str()); if (!ofs) { if (flag) lyxerr << _("Error! Cannot open file: ") - << filename << endl; + << fname << endl; else WriteFSAlert(_("Error! Cannot open file: "), - filename); + fname); return false; } // The top of the file should not be written by params. @@ -1266,7 +1232,7 @@ bool Buffer::writeFile(string const & filename, bool flag) } -void Buffer::writeFileAscii(string const & filename, int linelen) +void Buffer::writeFileAscii(string const & fname, int linelen) { LyXFont font1, font2; Inset * inset; @@ -1279,9 +1245,9 @@ void Buffer::writeFileAscii(string const & filename, int linelen) long fpos = 0; bool ref_printed = false; - ofstream ofs(filename.c_str()); + ofstream ofs(fname.c_str()); if (!ofs) { - WriteFSAlert(_("Error: Cannot write file:"), filename); + WriteFSAlert(_("Error: Cannot write file:"), fname); return; } @@ -1589,12 +1555,15 @@ void Buffer::writeFileAscii(string const & filename, int linelen) } -void Buffer::makeLaTeXFile(string const & filename, +void Buffer::makeLaTeXFile(string const & fname, string const & original_path, 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; @@ -1602,9 +1571,9 @@ void Buffer::makeLaTeXFile(string const & filename, LyXTextClass const & tclass = textclasslist.TextClass(params.textclass); - ofstream ofs(filename.c_str()); + ofstream ofs(fname.c_str()); if (!ofs) { - WriteFSAlert(_("Error: Cannot open file: "), filename); + WriteFSAlert(_("Error: Cannot open file: "), fname); return; } @@ -1623,18 +1592,15 @@ void Buffer::makeLaTeXFile(string const & filename, string LFile; if (!only_body && nice) { - LFile += "%% This LaTeX-file was created by <"; - LFile += userName + "> " + date(); - LFile += "%% LyX 1.0 (C) 1995-1999 by Matthias Ettrich and the LyX Team\n"; - LFile += "\n%% Do not edit this file unless you know what you are doing.\n"; - texrow.newline(); - texrow.newline(); + LFile += "%% " LYX_DOCVERSION " created this file. " + "For more info, see http://www.lyx.org/.\n"; + LFile += "%% Do not edit unless you really know what you are doing.\n"; texrow.newline(); texrow.newline(); } 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. @@ -1648,9 +1614,6 @@ void Buffer::makeLaTeXFile(string const & filename, 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"; @@ -2144,27 +2107,18 @@ bool Buffer::isSGML() const void Buffer::sgmlOpenTag(ostream & os, int depth, string const & latexname) const { - static char * space[] = {" "," ", " ", " ", " ", " ", - " ", - " ", " ", " ", - " "}; - - os << space[depth] << "<" << latexname << ">\n"; + os << string(depth, ' ') << "<" << latexname << ">\n"; } void Buffer::sgmlCloseTag(ostream & os, int depth, string const & latexname) const { - static char * space[] = {" ", " ", " ", " ", " ", - " ", " ", " ", - " ", " ", " "}; - - os << space[depth] << "\n"; + os << string(depth, ' ') << "\n"; } -void Buffer::makeLinuxDocFile(string const & filename, int column) +void Buffer::makeLinuxDocFile(string const & fname, int column) { LyXParagraph * par = paragraph; @@ -2174,10 +2128,10 @@ void Buffer::makeLinuxDocFile(string const & filename, int column) int depth = 0; /* paragraph depth */ - ofstream ofs(filename.c_str()); + ofstream ofs(fname.c_str()); if (!ofs) { - WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename); + WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname); return; } @@ -2208,7 +2162,7 @@ void Buffer::makeLinuxDocFile(string const & filename, int column) while (par) { int desc_on = 0; /* description mode*/ LyXLayout const & style = - textclasslist.Style(GetCurrentTextClass(), + textclasslist.Style(users->buffer()->params.textclass, par->layout); par->AutoDeleteInsets(); @@ -2226,13 +2180,13 @@ void Buffer::makeLinuxDocFile(string const & filename, int column) } } - /* 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 @@ -2473,18 +2427,16 @@ void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par, 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 << ""; /* 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] << ">"; } @@ -2492,19 +2444,17 @@ void Buffer::push_tag(ostream & os, char const * tag, 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 << ""; // closes the tag os << ""; // 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; } @@ -2747,7 +2697,7 @@ void Buffer::LinuxDocError(LyXParagraph * par, int pos, enum { MAX_NEST_LEVEL = 25}; -void Buffer::makeDocBookFile(string const & filename, int column) +void Buffer::makeDocBookFile(string const & fname, int column) { LyXParagraph * par = paragraph; @@ -2765,13 +2715,12 @@ void Buffer::makeDocBookFile(string const & filename, int column) tex_code_break_column = column; - ofstream ofs(filename.c_str()); + ofstream ofs(fname.c_str()); if (!ofs) { - WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), filename); + WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname); return; } - //ResetTexRow(); texrow.reset(); ofs << "buffer()->params.textclass, par->layout); par->AutoDeleteInsets(); @@ -3157,16 +3106,11 @@ void Buffer::SimpleDocBookOnePar(string & file, string & extra, } -// candidate for move to BufferView -bool Buffer::removeAutoInsets() +bool BufferView::removeAutoInsets() { - LyXParagraph *par = paragraph; + LyXParagraph * par = buffer()->paragraph; -#ifdef MOVE_TEXT - LyXCursor cursor = users->text->cursor; -#else LyXCursor cursor = text->cursor; -#endif LyXCursor tmpcursor = cursor; cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos); cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos); @@ -3176,31 +3120,20 @@ bool Buffer::removeAutoInsets() if (par->AutoDeleteInsets()){ a = true; if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){ -#ifdef MOVE_TEXT - /* 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(); -#else - /* this is possible now, since SetCursor takes - care about footnotes */ + // this is possible now, since SetCursor takes + // care about footnotes text->SetCursorIntern(par, 0); - text->RedoParagraphs(text->cursor, text->cursor.par->Next()); + text->RedoParagraphs(text->cursor, + text->cursor.par->Next()); text->FullRebreak(); -#endif } } 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(); -#ifdef MOVE_TEXT - users->text->SetCursorIntern(cursor.par, cursor.pos); -#else text->SetCursorIntern(cursor.par, cursor.pos); -#endif return a; } @@ -3208,11 +3141,7 @@ bool Buffer::removeAutoInsets() int Buffer::runLaTeX() { -#ifdef MOVE_TEXT if (!users->text) return 0; -#else - if (!text) return 0; -#endif ProhibitInput(); @@ -3230,7 +3159,7 @@ int Buffer::runLaTeX() 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); @@ -3249,7 +3178,7 @@ int Buffer::runLaTeX() } 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 @@ -3275,11 +3204,7 @@ int Buffer::runLaTeX() int Buffer::runLiterate() { -#ifdef MOVE_TEXT if (!users->text) return 0; -#else - if (!text) return 0; -#endif ProhibitInput(); @@ -3300,7 +3225,7 @@ int Buffer::runLiterate() 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) { @@ -3322,7 +3247,7 @@ int Buffer::runLiterate() } 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 @@ -3348,11 +3273,7 @@ int Buffer::runLiterate() int Buffer::buildProgram() { -#ifdef MOVE_TEXT if (!users->text) return 0; -#else - if (!text) return 0; -#endif ProhibitInput(); @@ -3373,7 +3294,7 @@ int Buffer::buildProgram() 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) { @@ -3395,7 +3316,7 @@ int Buffer::buildProgram() } 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. @@ -3423,11 +3344,7 @@ int Buffer::buildProgram() // Other flags: -wall -v0 -x int Buffer::runChktex() { -#ifdef MOVE_TEXT if (!users->text) return 0; -#else - if (!text) return 0; -#endif ProhibitInput(); @@ -3444,7 +3361,7 @@ int Buffer::runChktex() 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) { @@ -3461,7 +3378,7 @@ int Buffer::runChktex() _("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 @@ -3477,23 +3394,14 @@ int Buffer::runChktex() } -extern void AllFloats(char, char); - - -// candidate for move to BufferView -void Buffer::insertErrors(TeXErrors & terr) +void BufferView::insertErrors(TeXErrors & terr) { -#ifdef MOVE_TEXT - // Save the cursor position - LyXCursor cursor = users->text->cursor; -#else // Save the cursor position LyXCursor cursor = text->cursor; -#endif // 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(); @@ -3507,67 +3415,39 @@ void Buffer::insertErrors(TeXErrors & terr) int tmpid = -1; int tmppos = -1; - texrow.getIdFromRow(errorrow, tmpid, tmppos); + buffer()->texrow.getIdFromRow(errorrow, tmpid, tmppos); LyXParagraph * texrowpar = 0; -#ifdef MOVE_TEXT - if (tmpid == -1) { - texrowpar = users->text->FirstParagraph(); - tmppos = 0; - } else { - texrowpar = users->text->GetParFromID(tmpid); - } -#else if (tmpid == -1) { texrowpar = text->FirstParagraph(); tmppos = 0; } else { texrowpar = text->GetParFromID(tmpid); } -#endif if (texrowpar == 0) continue; InsetError * new_inset = new InsetError(msgtxt); -#ifdef MOVE_TEXT - users->text->SetCursorIntern(texrowpar, tmppos); - users->text->InsertInset(new_inset); - users->text->FullRebreak(); - } - // Restore the cursor position - users->text->SetCursorIntern(cursor.par, cursor.pos); -#else text->SetCursorIntern(texrowpar, tmppos); text->InsertInset(new_inset); text->FullRebreak(); } // Restore the cursor position text->SetCursorIntern(cursor.par, cursor.pos); -#endif } -// 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; -#ifdef MOVE_TEXT - if (tmpid == -1) { - texrowpar = users->text->FirstParagraph(); - tmppos = 0; - } else { - texrowpar = users->text->GetParFromID(tmpid); - } - users->text->SetCursor(texrowpar, tmppos); -#else if (tmpid == -1) { texrowpar = text->FirstParagraph(); tmppos = 0; @@ -3575,7 +3455,6 @@ void Buffer::setCursorFromRow (int row) texrowpar = text->GetParFromID(tmpid); } text->SetCursor(texrowpar, tmppos); -#endif } @@ -3726,37 +3605,6 @@ void Buffer::markDviDirty() } -#ifndef MOVE_TEXT -// candidate for move to BufferView -void Buffer::update(signed char f) -{ - if (!users) return; - - users->owner()->updateLayoutChoice(); - if (!text->selection && f > -3) - text->sel_cursor = text->cursor; - - FreeUpdateTimer(); - text->FullRebreak(); - - users->update(); - - if (f != 3 && f != -3) { - users->fitCursor(); - users->updateScrollbar(); - } - - if (f == 1 || f == -1) { - if (isLyxClean()) { - markDirty(); - users->owner()->getMiniBuffer()->setTimer(4); - } else { - markDirty(); - } - } -} -#endif - void Buffer::validate(LaTeXFeatures & features) { LyXParagraph * par = paragraph; @@ -3868,61 +3716,8 @@ void Buffer::setOldPaperStuff() } #endif -#ifdef MOVE_TEXT -// candidate for move to BufferView -void Buffer::insertInset(Inset * inset, string const & lout, - bool no_table) -{ - // check for table/list in tables - if (no_table && users->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(); - - BeforeChange(); - if (!lout.empty()) { - users->update(-2); - users->text->BreakParagraph(); - users->update(-1); - - if (users->text->cursor.par->Last()) { - users->text->CursorLeft(); - - users->text->BreakParagraph(); - users->update(-1); - } - - int lay = textclasslist.NumberOfLayout(params.textclass, - lout).second; - if (lay == -1) // layout not found - // use default layout "Standard" (0) - lay = 0; - - users->text->SetLayout(lay); - - users->text->SetParagraph(0, 0, - 0, 0, - VSpace(VSpace::NONE), VSpace(VSpace::NONE), - LYX_ALIGN_LAYOUT, - string(), - 0); - users->update(-1); - - users->text->current_font.setLatex(LyXFont::OFF); - } - - users->text->InsertInset(inset); - users->update(-1); - users->text->UnFreezeUndo(); -} -#else -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 @@ -3936,7 +3731,7 @@ void Buffer::insertInset(Inset * inset, string const & lout, text->SetCursorParUndo(); text->FreezeUndo(); - BeforeChange(); + beforeChange(); if (!lout.empty()) { update(-2); text->BreakParagraph(); @@ -3949,7 +3744,7 @@ void Buffer::insertInset(Inset * inset, string const & lout, 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) @@ -3973,31 +3768,21 @@ void Buffer::insertInset(Inset * inset, string const & lout, text->UnFreezeUndo(); } -#endif + // 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) { -#ifdef MOVE_TEXT - BeforeChange(); - users->text->FinishUndo(); - insertInset(new_inset); - users->text->CursorLeft(); - users->update(1); - new_inset->Edit(0, 0); -#else - BeforeChange(); + beforeChange(); text->FinishUndo(); insertInset(new_inset); text->CursorLeft(); update(1); new_inset->Edit(0, 0); -#endif } -/* 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; @@ -4026,7 +3811,7 @@ string Buffer::getIncludeonlyList(char delim) } -/* 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 @@ -4058,7 +3843,7 @@ string Buffer::getReferenceList(char delim) } -/* 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 @@ -4092,9 +3877,9 @@ string Buffer::getBibkeyList(char delim) if (inset-> LyxCode() == Inset::BIBTEX_CODE) { if (!bibkeys.empty()) bibkeys += delim; - bibkeys += static_cast(inset)->getKeys(); + bibkeys += static_cast(inset)->getKeys(delim); } else if (inset-> LyxCode() == Inset::INCLUDE_CODE) { - string bk = static_cast(inset)->getKeys(); + string bk = static_cast(inset)->getKeys(delim); if (!bk.empty()) { if (!bibkeys.empty()) bibkeys += delim; @@ -4112,16 +3897,15 @@ string Buffer::getBibkeyList(char delim) } -// 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) { @@ -4129,19 +3913,11 @@ bool Buffer::gotoLabel(string const & label) while ((inset = par->ReturnNextInsetPointer(pos))){ for (int i = 0; i < inset->GetNumberOfLabels(); i++) { if (label == inset->getLabel(i)) { -#ifdef MOVE_TEXT - BeforeChange(); - users->text->SetCursor(par, pos); - users->text->sel_cursor = users->text->cursor; - users->update(0); - return true; -#else - BeforeChange(); + beforeChange(); text->SetCursor(par, pos); text->sel_cursor = text->cursor; update(0); return true; -#endif } } pos++; @@ -4184,7 +3960,8 @@ void Buffer::markDepClean(string const & name) } } -void Buffer::Dispatch(const string & command) + +void Buffer::Dispatch(string const & command) { // Split command string into command and argument string cmd, line = frontStrip(command); @@ -4193,18 +3970,17 @@ void Buffer::Dispatch(const string & 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: MenuExport(this, argument); break; - break; default: lyxerr << "A truly unknown func!" << endl; break; } // end of switch - }