* LyX, The Document Processor
*
* Copyright 1995 Matthias Ettrich
- * Copyright 1995-1999 The LyX Team.
+ * Copyright 1995-2000 The LyX Team.
*
* This file is Copyright 1996-1999
* Lars Gullik Bjønnes
#include <fstream>
#include <iomanip>
-using std::ofstream;
-using std::ifstream;
-using std::fstream;
-using std::ios;
-using std::setw;
-
#include <cstdlib>
#include <unistd.h>
#include "insets/insetspecialchar.h"
#include "insets/figinset.h"
#include "insets/insettext.h"
+//#include "insets/insetnumber.h"
#include "insets/insetert.h"
#include "insets/insetgraphics.h"
#include "insets/insetfoot.h"
#include "support/FileInfo.h"
#include "lyxtext.h"
#include "gettext.h"
+#include "language.h"
+
+using std::ostream;
+using std::ofstream;
+using std::ifstream;
+using std::fstream;
+using std::ios;
+using std::setw;
+using std::endl;
+using std::pair;
// Uncomment this line to enable a workaround for the weird behaviour
// of the cursor between a displayed inset and last character
extern LyXAction lyxaction;
-static const float LYX_FORMAT = 2.15;
+static const float LYX_FORMAT = 2.16;
extern int tex_code_break_column;
}
+string Buffer::getLatexName(bool no_path /* = true */) const
+{
+ return ChangeExtension(MakeLatexName(filename),
+ ".tex", no_path);
+}
+
+
+void Buffer::setReadonly(bool flag /* = true */)
+{
+ if (read_only != flag) {
+ read_only = flag;
+ updateTitles();
+ updateAllVisibleBufferRelatedPopups();
+ }
+ if (read_only) {
+ WarnReadonly(filename);
+ }
+}
+
+
bool Buffer::saveParamsAsDefaults()
{
string fname = AddName(AddPath(user_lyxdir, "templates/"),
bool the_end_read = false;
LyXParagraph * return_par = 0;
- LyXFont font(LyXFont::ALL_INHERIT);
+ LyXFont font(LyXFont::ALL_INHERIT,params.language_info);
+ if (format < 2.16 && params.language == "hebrew")
+ font.setLanguage(default_language);
// If we are inserting, we cheat and get a token in advance
bool has_token = false;
if (!return_par)
return_par = par;
else {
- par->text.resize(par->text.size());
+ par->fitToSize();
par = new LyXParagraph(par);
}
pos = 0;
par->footnoteflag = footnoteflag;
par->footnotekind = footnotekind;
par->depth = depth;
- font = LyXFont(LyXFont::ALL_INHERIT);
+ font = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
+ if (format < 2.16 && params.language == "hebrew")
+ font.setLanguage(default_language);
} else if (token == "\\end_float") {
if (!return_par)
return_par = par;
else {
- par->text.resize(par->text.size());
+ par->fitToSize();
par = new LyXParagraph(par);
}
footnotekind = LyXParagraph::FOOTNOTE;
pos = 0;
lex.EatLine();
par->layout = LYX_DUMMY_LAYOUT;
- font = LyXFont(LyXFont::ALL_INHERIT);
+ font = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
+ if (format < 2.16 && params.language == "hebrew")
+ font.setLanguage(default_language);
} else if (token == "\\begin_float") {
tmpret = lex.FindToken(string_footnotekinds);
if (tmpret == -1) ++tmpret;
else
lex.printError("Unknown LaTeX font flag "
"`$$Token'");
- } else if (token == "\\direction") {
+ } else if (token == "\\lang") {
lex.next();
string tok = lex.GetString();
- if (tok == "ltr")
- font.setDirection(LyXFont::LTR_DIR);
- else if (tok == "rtl")
- font.setDirection(LyXFont::RTL_DIR);
+ Languages::iterator lit = languages.find(tok);
+ if (lit != languages.end()) {
+ font.setLanguage(&(*lit).second);
+ } else {
+ font.setLanguage(params.language_info);
+ lex.printError("Unknown language `$$Token'");
+ }
+ } else if (token == "\\direction") { // obsolete
+ if (format >= 2.16)
+ lex.printError("Command \\direction is obsolete");
+ lex.next();
+ string tok = lex.GetString();
+ if (tok == "rtl")
+ font.setLanguage(&languages["hebrew"]);
else if (tok == "default")
- font.setDirection(LyXFont::INHERIT_DIR);
+ if (params.language == "hebrew")
+ font.setLanguage(default_language);
+ else
+ font.setLanguage(params.language_info);
else
- lex.printError("Unknown font flag "
- "`$$Token'");
+ lex.printError("Unknown direction `$$Token'");
} else if (token == "\\emph") {
lex.next();
font.setEmph(font.setLyXMisc(lex.GetString()));
}
} else if (token == "\\added_space_top") {
lex.nextToken();
- par->added_space_top = lex.GetString();
+ par->added_space_top = VSpace(lex.GetString());
} else if (token == "\\added_space_bottom") {
lex.nextToken();
- par->added_space_bottom = lex.GetString();
+ par->added_space_bottom = VSpace(lex.GetString());
} else if (token == "\\pextra_type") {
lex.nextToken();
par->pextra_type = lex.GetInteger();
par->InsertInset(pos, inset);
par->SetFont(pos, font);
++pos;
+#if 0
+ } else if (tmptok == "Number") {
+ inset = new InsetNumber(this);
+ inset->Read(lex);
+ par->InsertChar(pos, LyXParagraph::META_INSET);
+ par->InsertInset(pos, inset);
+ par->SetFont(pos, font);
+ ++pos;
+#endif
} else if (tmptok == "Foot") {
inset = new InsetFoot(this);
inset->Read(lex);
if (!inscmd.getOptions().empty() || !inscmd.getContents().empty()) {
inset = new InsetRef(inscmd, this);
}
-#warning Verify that this else clause is still needed. (Lgb)
+#warning Check if this else clause is still needed. (Lgb)
#if 0
// This condition comes from a
// temporary solution to the latexdel
// Should probably be moved to somewhere else: BufferView? LyXView?
-bool Buffer::save(bool makeBackup) const
+bool Buffer::save() const
{
// We don't need autosaves in the immediate future. (Asger)
resetAutosaveTimers();
// make a backup
- if (makeBackup) {
- string s = fileName() + '~';
+ string s;
+ if (lyxrc.make_backup) {
+ s = fileName() + '~';
+ if (!lyxrc.backupdir_path.empty())
+ s = AddName(lyxrc.backupdir_path,
+ subst(CleanupPath(s),'/','!'));
+
// Rename is the wrong way of making a backup,
// this is the correct way.
/* truss cp fil fil2:
FileInfo finfo(fileName());
if (finfo.exist()) {
mode_t fmode = finfo.getMode();
- struct utimbuf * times = new struct utimbuf;
+ struct utimbuf times = {
+ finfo.getAccessTime(),
+ finfo.getModificationTime() };
- times->actime = finfo.getAccessTime();
- times->modtime = finfo.getModificationTime();
ifstream ifs(fileName().c_str());
ofstream ofs(s.c_str(), ios::out|ios::trunc);
if (ifs && ofs) {
ofs.close();
::chmod(s.c_str(), fmode);
- if (::utime(s.c_str(), times)) {
+ if (::utime(s.c_str(), ×)) {
lyxerr << "utime error." << endl;
}
} else {
lyxerr << "LyX was not able to make "
"backupcopy. Beware." << endl;
}
- delete times;
}
}
}
} else {
// Saving failed, so backup is not backup
- if (makeBackup) {
- string s = fileName() + '~';
+ if (lyxrc.make_backup) {
::rename(s.c_str(), fileName().c_str());
}
return false;
if ((inset = par->GetInset(i))) {
#if 1
#ifdef HAVE_SSTREAM
- ostringstream ost;
+ std::ostringstream ost;
inset->Latex(ost, -1, free_spc);
h += ost.str().length();
#else
clen[j] = h;
}
- font1 = LyXFont(LyXFont::ALL_INHERIT);
+ font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
actcell = 0;
for (i = 0, actpos = 1; i < par->size(); ++i, ++actpos) {
if (!i && !footnoteflag && !noparbreak){
// validate the buffer.
lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
- LaTeXFeatures features(tclass.numLayouts());
+ LaTeXFeatures features(params, tclass.numLayouts());
validate(features);
lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
&& params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
options += "landscape,";
- // language should be a parameter to \documentclass
- if (params.language != "default") {
- if (params.language == "hebrew")
- options += "english,";
- else if (lyxrc.rtl_support)
- options += "hebrew,";
- options += params.language + ',';
+ // language should be a parameter to \documentclass
+ bool use_babel = false;
+ if (params.language != "default" ||
+ !features.UsedLanguages.empty() ) {
+ use_babel = true;
+ for (LaTeXFeatures::LanguageList::const_iterator cit =
+ features.UsedLanguages.begin();
+ cit != features.UsedLanguages.end(); ++cit) {
+ options += (*cit)->lang + ",";
+ }
+ if (default_language != params.language_info)
+ options += default_language ->lang + ',';
+ options += params.language_info->lang + ',';
}
// the user-defined options
// We try to load babel late, in case it interferes
// with other packages.
- if (params.language != "default") {
- ofs << lyxrc.language_package;
+ if (use_babel) {
+ ofs << lyxrc.language_package << endl;
texrow.newline();
}
string preamble, tmppreamble;
// The optional packages;
- preamble = features.getPackages(params);
+ preamble = features.getPackages();
// this might be useful...
preamble += "\n\\makeatletter\n\n";
// Some macros LyX will need
- tmppreamble = features.getMacros(params);
+ tmppreamble = features.getMacros();
if (!tmppreamble.empty()) {
preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
}
// the text class specific preamble
- tmppreamble = features.getTClassPreamble(params);
+ tmppreamble = features.getTClassPreamble();
if (!tmppreamble.empty()) {
preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
"Textclass specific LaTeX commands.\n"
texrow.newline();
} // only_body
lyxerr.debug() << "preamble finished, now the body." << endl;
- if (lyxrc.language_command_begin &&
- params.getDocumentDirection() == LYX_DIR_RIGHT_TO_LEFT)
- ofs << lyxrc.language_command_rtl;
+ if (!lyxrc.language_auto_begin && params.language != "default") {
+ ofs << subst(lyxrc.language_command_begin, "$$lang",
+ params.language)
+ << endl;
+ texrow.newline();
+ }
bool was_title = false;
bool already_title = false;
#ifdef HAVE_SSTREAM
- ostringstream ftnote;
+ std::ostringstream ftnote;
#else
char * tmpholder = 0;
#endif
texrow.newline();
}
- if (lyxrc.language_command_end &&
- params.getDocumentDirection() == LYX_DIR_RIGHT_TO_LEFT)
- ofs << lyxrc.language_command_ltr;
+ if (!lyxrc.language_auto_end && params.language != "default") {
+ ofs << subst(lyxrc.language_command_end, "$$lang",
+ params.language)
+ << endl;
+ texrow.newline();
+ }
if (!only_body) {
ofs << "\\end{document}\n";
.NumberOfLayout(params.textclass,
"Caption").second) {
#ifdef HAVE_SSTREAM
- ostringstream ost;
+ std::ostringstream ost;
#else
ostrstream ost;
#endif
os << "<" << stack[i] << ">";
}
+
void Buffer::pop_tag(ostream & os, char const * tag,
int & pos, char stack[5][3])
{
font1 = font2;
}
- if (lyxrc.language_command_end &&
- params.getDocumentDirection() == LYX_DIR_RIGHT_TO_LEFT)
- os << lyxrc.language_command_ltr;
-
/* needed if there is an optional argument but no contents */
if (main_body > 0 && main_body == par->size()) {
font1 = style.font;
if (c == LyXParagraph::META_INSET) {
Inset * inset = par->GetInset(i);
#ifdef HAVE_SSTREAM
- ostringstream ost;
+ std::ostringstream ost;
inset->DocBook(ost);
string tmp_out = ost.str().c_str();
#else
#if 0
void Buffer::RoffAsciiTable(ostream & os, LyXParagraph * par)
{
- LyXFont font1(LyXFont::ALL_INHERIT);
+ LyXFont font1(LyXFont::ALL_INHERIT,params.language_info);
LyXFont font2;
Inset * inset;
LyXParagraph::size_type i;
}
if (lyxerr.debugging(Debug::LATEX)) {
- features.showStruct(params);
+ features.showStruct();
}
}
} // end of switch
}
+
+void Buffer::ChangeLanguage(Language const * from, Language const * to)
+{
+
+ LyXParagraph * par = paragraph;
+ while (par) {
+ par->ChangeLanguage(from,to);
+ par = par->next;
+ }
+}
+
+bool Buffer::isMultiLingual()
+{
+
+ LyXParagraph * par = paragraph;
+ while (par) {
+ if (par->isMultiLingual())
+ return true;
+ par = par->next;
+ }
+ return false;
+}