#include "bufferlist.h"
#include "lyx_main.h"
#include "lyx_gui_misc.h"
+#include "LyXAction.h"
#include "lyxrc.h"
#include "lyxlex.h"
#include "tex-strings.h"
extern unsigned char GetCurrentTextClass();
extern void BeforeChange();
+extern void MenuMakeLaTeX(Buffer *);
+extern void MenuMakeLinuxDoc(Buffer *);
+extern void MenuMakeDocBook(Buffer *);
+extern void MenuRunLaTeX(Buffer *);
+extern void MenuPrint(Buffer *);
+extern void MenuMakeAscii(Buffer *);
+extern void MenuSendto();
+extern LyXAction lyxaction;
+
+
static const float LYX_FORMAT = 2.15;
extern int tex_code_break_column;
filename = file;
filepath = OnlyPath(file);
paragraph = 0;
+#ifndef MOVE_TEXT
text = 0;
+#endif
the_locking_inset = 0;
lyx_clean = true;
bak_clean = true;
par = tmppar;
}
paragraph = 0;
+#ifndef MOVE_TEXT
delete text;
+#endif
}
}
-void Buffer::setFileName(string const & newfile)
+void Buffer::fileName(string const & newfile)
{
filename = MakeAbsPath(newfile);
filepath = OnlyPath(filename);
updateTitles();
}
+
+// 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 res = true;
+#ifdef MOVE_TEXT
+ if (c == '#') {
+ lyxerr.debug() << "Will insert file with header" << endl;
+ res = readFile(lex, users->text->cursor.par);
+ } else {
+ lyxerr.debug() << "Will insert file without header" << endl;
+ res = readLyXformat2(lex, users->text->cursor.par);
+ }
+#else
if (c == '#') {
lyxerr.debug() << "Will insert file with header" << endl;
res = readFile(lex, text->cursor.par);
lyxerr.debug() << "Will insert file without header" << endl;
res = readLyXformat2(lex, text->cursor.par);
}
+#endif
resize();
return res;
}
+// candidate for move to BufferView
+// (at least some parts in the beginning of the func)
//
// Uwe C. Schroeder
// changed to be public and have one parameter
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
break;
}
if (ltype_depth > depth) {
- for(j = ltype_depth-1; j>depth; j--)
+ for(j = ltype_depth - 1; j > depth; --j)
ofs << " ";
currlinelen += (ltype_depth-depth)*2;
}
if (par->table) {
- for(j = 0;j<cells;j++) {
+ for(j = 0; j < cells; ++j) {
ofs << '+';
- for(h = 0; h < (clen[j]+1); h++)
+ for(h = 0; h < (clen[j] + 1);
+ ++h)
ofs << '-';
}
ofs << "+\n";
- for(j = 0; j<depth; j++)
+ for(j = 0; j < depth; ++j)
ofs << " ";
- currlinelen = depth*2;
+ currlinelen = depth * 2;
if (ltype_depth > depth) {
- for(j = ltype_depth; j>depth; j--)
+ for(j = ltype_depth;
+ j > depth; --j)
ofs << " ";
currlinelen += (ltype_depth-depth)*2;
}
for(j = actpos; j < clen[cell-1];j++)
ofs << ' ';
ofs << " |\n";
- for(j = 0; j<depth; j++)
+ for(j = 0; j < depth; ++j)
ofs << " ";
currlinelen = depth*2;
if (ltype_depth > depth) {
- for(j = ltype_depth; j>depth; j--)
+ for(j = ltype_depth; j > depth; --j)
ofs << " ";
- currlinelen += (ltype_depth-depth)*2;
+ currlinelen += (ltype_depth-depth) * 2;
}
- for(j = 0;j<cells;j++) {
+ for(j = 0; j < cells; ++j) {
ofs << '+';
- for(h = 0; h < (clen[j]+1); ++h)
+ for(h = 0; h < (clen[j] + 1); ++h)
ofs << '-';
}
ofs << "+\n";
- for(j = 0; j<depth; j++)
+ for(j = 0; j < depth; ++j)
ofs << " ";
- currlinelen = depth*2;
+ currlinelen = depth * 2;
if (ltype_depth > depth) {
- for(j = ltype_depth; j>depth; j--)
+ for(j = ltype_depth;
+ j > depth; --j)
ofs << " ";
currlinelen += (ltype_depth-depth)*2;
}
ofs << "| ";
cell = 1;
} else {
- for(j = actpos; j<clen[cell-1]; j++)
+ for(j = actpos;
+ j < clen[cell - 1]; ++j)
ofs << ' ';
ofs << " | ";
++cell;
currlinelen = actpos = 0;
} else {
ofs << "\n";
- for(j = 0; j<depth; j++)
+ for(j = 0; j < depth; ++j)
ofs << " ";
currlinelen = depth * 2;
if (ltype_depth > depth) {
- for(j = ltype_depth; j>depth; j--)
+ for(j = ltype_depth;
+ j > depth; --j)
ofs << " ";
- currlinelen += (ltype_depth-depth)*2;
+ currlinelen += (ltype_depth - depth) * 2;
}
}
break;
for(j = actpos; j < clen[cell - 1]; ++j)
ofs << ' ';
ofs << " |\n";
- for(j = 0; j<depth; j++)
+ for(j = 0; j < depth; ++j)
ofs << " ";
currlinelen = depth * 2;
if (ltype_depth > depth) {
for(j = ltype_depth; j > depth; --j)
ofs << " ";
- currlinelen += (ltype_depth-depth)*2;
+ currlinelen += (ltype_depth - depth) * 2;
}
- for(j = 0;j<cells; ++j) {
+ for(j = 0; j < cells; ++j) {
ofs << '+';
for(h = 0; h < (clen[j] + 1); ++h)
ofs << '-';
options += "onecolumn,";
}
- if (!params.use_geometry && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
+ if (!params.use_geometry
+ && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
options += "landscape,";
// language should be a parameter to \documentclass
}
+// candidate for move to BufferView
bool Buffer::removeAutoInsets()
{
LyXParagraph *par = 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);
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 */
text->SetCursorIntern(par, 0);
text->RedoParagraphs(text->cursor, text->cursor.par->Next());
text->FullRebreak();
+#endif
}
}
par = par->next;
/* 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;
}
int Buffer::runLaTeX()
{
+#ifdef MOVE_TEXT
+ if (!users->text) return 0;
+#else
if (!text) return 0;
+#endif
ProhibitInput();
int Buffer::runLiterate()
{
+#ifdef MOVE_TEXT
+ if (!users->text) return 0;
+#else
if (!text) return 0;
+#endif
ProhibitInput();
int Buffer::buildProgram()
{
+#ifdef MOVE_TEXT
+ if (!users->text) return 0;
+#else
if (!text) return 0;
+#endif
ProhibitInput();
// Other flags: -wall -v0 -x
int Buffer::runChktex()
{
+#ifdef MOVE_TEXT
+ if (!users->text) return 0;
+#else
if (!text) return 0;
+#endif
ProhibitInput();
extern void AllFloats(char, char);
+// candidate for move to BufferView
void Buffer::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);
texrow.getIdFromRow(errorrow, tmpid, tmppos);
- LyXParagraph* texrowpar;
+ 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)
{
int tmpid = -1;
texrow.getIdFromRow(row, tmpid, tmppos);
- LyXParagraph* texrowpar;
+ 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;
texrowpar = text->GetParFromID(tmpid);
}
text->SetCursor(texrowpar, tmppos);
+#endif
}
}
+#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) {
}
}
}
-
+#endif
void Buffer::validate(LaTeXFeatures & features)
{
}
#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,
bool no_table)
{
text->UnFreezeUndo();
}
-
+#endif
// Open and lock an updatable inset
+// candidate for move to BufferView
void Buffer::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();
text->FinishUndo();
insertInset(new_inset);
text->CursorLeft();
update(1);
new_inset->Edit(0, 0);
+#endif
}
/// if this is a child document and the parent is already loaded
/// Use the parent's list instead [ale990407]
if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
- Buffer *tmp = bufferlist.getBuffer(params.parentname);
+ Buffer * tmp = bufferlist.getBuffer(params.parentname);
if (tmp)
return tmp->getReferenceList(delim);
}
- LyXParagraph *par = paragraph;
+ LyXParagraph * par = paragraph;
LyXParagraph::size_type pos;
Inset * inset;
string lst;
/// if this is a child document and the parent is already loaded
/// Use the parent's list instead [ale990412]
if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
- Buffer *tmp = bufferlist.getBuffer(params.parentname);
+ Buffer * tmp = bufferlist.getBuffer(params.parentname);
if (tmp)
return tmp->getBibkeyList(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
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();
text->SetCursor(par, pos);
text->sel_cursor = text->cursor;
update(0);
return true;
+#endif
}
}
pos++;
}
}
}
+
+void Buffer::Dispatch(const string & command)
+{
+ // Split command string into command and argument
+ string cmd, line = frontStrip(command);
+ string arg = strip(frontStrip(split(line, cmd, ' ')));
+
+ Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str());
+}
+
+void Buffer::Dispatch(int action, const string & argument)
+{
+ switch (action) {
+ case LFUN_EXPORT: {
+ // latex
+ if (argument == "latex") {
+ // make sure that this buffer is not linuxdoc
+ MenuMakeLaTeX(this);
+ }
+ // linuxdoc
+ else if (argument == "linuxdoc") {
+ // make sure that this buffer is not latex
+ MenuMakeLinuxDoc(this);
+ }
+ // docbook
+ else if (argument == "docbook") {
+ // make sure that this buffer is not latex or linuxdoc
+ MenuMakeDocBook(this);
+ }
+ // dvi
+ else if (argument == "dvi") {
+ // Run LaTeX as "Update dvi..." Bernhard.
+ // We want the dvi in the current directory. This
+ // is achieved by temporarily disabling use of
+ // temp directory. As a side-effect, we get
+ // *.log and *.aux files also. (Asger)
+ bool flag = lyxrc->use_tempdir;
+ lyxrc->use_tempdir = false;
+ MenuRunLaTeX(this);
+ lyxrc->use_tempdir = flag;
+ }
+ // postscript
+ else if (argument == "postscript") {
+ // Start Print-dialog. Not as good as dvi... Bernhard.
+ MenuPrint(this);
+ // Since the MenuPrint is a pop-up, we can't use
+ // the same trick as above. (Asger)
+ // MISSING: Move of ps-file :-|
+ }
+ // ascii
+ else if (argument == "ascii") {
+ MenuMakeAscii(this);
+ }
+ else if (argument == "custom") {
+ MenuSendto();
+ break;
+ }
+ // HTML
+ else if (argument == "html" && lyxrc->html_command != "none") {
+ // First, create LaTeX file
+ MenuMakeLaTeX(this);
+
+ // And now, run the converter
+ string file = fileName();
+ Path path(OnlyPath(file));
+ // the tex file name has to be correct for
+ // latex, but the html file name can be
+ // anything.
+ string result = ChangeExtension(file, ".html", false);
+ file = ChangeExtension(MakeLatexName(file), ".tex", false);
+ string tmp = lyxrc->html_command;
+ tmp = subst(tmp, "$$FName", file);
+ tmp = subst(tmp, "$$OutName", result);
+ Systemcalls one;
+ /*int res = */ one.startscript(Systemcalls::System, tmp);
+ //
+ // Hi, Asger. This time I plead guilty and I promise to clean it up
+ //
+ // if (res == 0) {
+ // setMessage(N_("Document exported as HTML to file `")
+ // + MakeDisplayPath(result) +'\ '');
+ // } else {
+ // setErrorMessage(N_("Unable to convert to HTML the file `")
+ // + MakeDisplayPath(file)
+ // + '\'');
+ // }
+ }
+ else {
+ // setErrorMessage(N_("Unknown export type: ")
+ // + argument);
+ }
+ }
+ break;
+
+ default:
+ lyxerr << "A truly unknown func!" << endl;
+ break;
+
+ } // end of switch
+
+}