#include <config.h>
#include <fstream>
-
-using std::ifstream;
-using std::copy;
-using std::back_inserter;
+#include <algorithm>
+#include <iostream>
#include "LString.h"
#include "support/lstrings.h"
#include "gettext.h"
#include "layout.h"
#include "language.h"
+#include "CutAndPaste.h"
+
+using std::ifstream;
+using std::copy;
+using std::back_inserter;
+using std::endl;
+using std::cout;
+using std::ios;
+using std::istream_iterator;
+using std::pair;
extern Combox * combo_language;
extern BufferList bufferlist;
extern void MenuSendto();
extern LyXServer * lyxserver;
-extern FontLoader fontloader;
// this should be static, but I need it in buffer.C
bool quitting; // flag, that we are quitting the program
void MenuLayoutSave();
-void ShowMessage(Buffer * buf, string const & msg1,
- string const & msg2 = string(), string const & msg3 = string(), int delay=6)
+void ShowMessage(Buffer * buf,
+ string const & msg1,
+ string const & msg2 = string(),
+ string const & msg3 = string(), int delay = 6)
{
if (lyxrc.use_gui) {
- buf->getUser()->owner()->getMiniBuffer()->Set(msg1, msg2, msg3, delay);
- }
- else {
+ buf->getUser()->owner()->getMiniBuffer()->Set(msg1, msg2,
+ msg3, delay);
+ } else {
// can somebody think of something more clever? cerr?
cout << msg1 << msg2 << msg3 << endl;
}
// BufferViews. Or is it perhaps just the (input in) BufferViews in the
// current LyxView that should be prohibited (Lgb) (This applies to
// "AllowInput" as well.)
-void ProhibitInput()
+void ProhibitInput(BufferView * bv)
{
input_prohibited = true;
- current_view->hideCursor();
+ bv->hideCursor();
static Cursor cursor;
static bool cursor_undefined = true;
}
/* set the cursor to the watch for all forms and the canvas */
- XDefineCursor(fl_display, current_view->owner()->getForm()->window,
+ XDefineCursor(fl_display, bv->owner()->getForm()->window,
cursor);
if (fd_form_paragraph->form_paragraph->visible)
XDefineCursor(fl_display,
}
-void AllowInput()
+void AllowInput(BufferView * bv)
{
input_prohibited = false;
/* reset the cursor from the watch for all forms and the canvas */
- XUndefineCursor(fl_display, current_view->owner()->getForm()->window);
+ XUndefineCursor(fl_display, bv->owner()->getForm()->window);
if (fd_form_paragraph->form_paragraph->visible)
XUndefineCursor(fl_display,
fd_form_paragraph->form_paragraph->window);
fd_form_character->form_character->window);
// What to do about this? (Lgb)
- if (current_view->belowMouse())
- SetXtermCursor(current_view->owner()->getForm()->window);
+ if (bv->belowMouse())
+ SetXtermCursor(bv->owner()->getForm()->window);
XFlush(fl_display);
fl_activate_all_forms();
string oldname = fname;
LyXFileDlg fileDlg;
- ProhibitInput();
+ ProhibitInput(current_view);
fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
OnlyPath(fname),
"*.lyx",
OnlyFilename(fname));
- AllowInput();
+ AllowInput(current_view);
if (fname.empty()) {
return;
// substitute the real file name otherwise the filename is
// simply appended. rokrau 1/12/00
cmd = command;
- std::string::size_type i;
- if ( (i=command.find("$$FName")) != std::string::npos)
+ string::size_type i;
+ if ( (i=command.find("$$FName")) != string::npos)
{
cmd.replace(i,7,QuoteName(name));
}
//if (!bv->text)
// return false;
- ProhibitInput();
+ ProhibitInput(current_view);
// Generate dvi file
if (MakeLaTeXOutput(buffer) > 0) {
- AllowInput();
+ AllowInput(current_view);
return false;
}
// Generate postscript file
}
Path p(path);
bool ret = RunScript(buffer, wait, command);
- AllowInput();
+ AllowInput(current_view);
return ret;
}
}
// Start postscript viewer
- ProhibitInput();
+ ProhibitInput(current_view);
string ps = ChangeExtension (buffer->fileName(),
".ps_tmp", true);
// push directorypath, if necessary
}
Path p(path);
bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
- AllowInput();
+ AllowInput(current_view);
return ret;
}
}
+void MenuMakeHTML_LinuxDoc(Buffer * buffer)
+{
+ // First, create LinuxDoc file
+ MenuMakeLinuxDoc(buffer);
+
+ // And now, run the converter
+ string file = buffer->fileName();
+
+ string result = ChangeExtension(file, ".html", false);
+ string infile = ChangeExtension(file, ".sgml", false);
+ string tmp = lyxrc.linuxdoc_to_html_command;
+ tmp = subst(tmp, "$$FName", infile);
+ tmp = subst(tmp, "$$OutName", result);
+ Systemcalls one;
+ int res = one.startscript(Systemcalls::System, tmp);
+ if (res == 0) {
+ ShowMessage(buffer,_("Document exported as HTML to file `")
+ + MakeDisplayPath(result) +'\'');
+ } else {
+ ShowMessage(buffer,_("Unable to convert to HTML the file `")
+ + MakeDisplayPath(infile)
+ + '\'');
+ }
+
+}
+
+void MenuMakeHTML_DocBook(Buffer * buffer)
+{
+ // First, create LaTeX file
+ MenuMakeDocBook(buffer);
+
+ // And now, run the converter
+ string file = buffer->fileName();
+ string result = ChangeExtension(file, ".html", false);
+ string infile = ChangeExtension(file, ".sgml", false);
+ string tmp = lyxrc.docbook_to_html_command;
+ tmp = subst(tmp, "$$FName", infile);
+ tmp = subst(tmp, "$$OutName", result);
+ Systemcalls one;
+ int res = one.startscript(Systemcalls::System, tmp);
+ if (res == 0) {
+ ShowMessage(buffer,_("Document exported as HTML to file `")
+ + MakeDisplayPath(result) +'\'');
+ } else {
+ ShowMessage(buffer,_("Unable to convert to HTML the file `")
+ + MakeDisplayPath(infile)
+ + '\'');
+ }
+
+}
+
void MenuExport(Buffer * buffer, string const & extyp)
{
// latex
else if (extyp == "html") {
MenuMakeHTML(buffer);
}
+ // HTML from linuxdoc
+ else if (extyp == "html-linuxdoc") {
+ MenuMakeHTML_LinuxDoc(buffer);
+ }
+ // HTML from docbook
+ else if (extyp == "html-docbook") {
+ MenuMakeHTML_DocBook(buffer);
+ }
else {
ShowMessage(buffer, _("Unknown export type: ") + extyp);
}
-void AutoSave()
+void AutoSave(BufferView * bv)
// should probably be moved into BufferList (Lgb)
// Perfect target for a thread...
{
- if (!current_view->available())
+ if (!bv->available())
return;
- if (current_view->buffer()->isBakClean()
- || current_view->buffer()->isReadonly()) {
+ if (bv->buffer()->isBakClean()
+ || bv->buffer()->isReadonly()) {
// We don't save now, but we'll try again later
- current_view->owner()->resetAutosaveTimer();
+ bv->owner()->resetAutosaveTimer();
return;
}
- current_view->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
+ bv->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
// create autosave filename
- string fname = OnlyPath(current_view->buffer()->fileName());
+ string fname = OnlyPath(bv->buffer()->fileName());
fname += "#";
- fname += OnlyFilename(current_view->buffer()->fileName());
+ fname += OnlyFilename(bv->buffer()->fileName());
fname += "#";
// tmp_ret will be located (usually) in /tmp
// anyway.
bool failed = false;
if (!tmp_ret.empty()) {
- current_view->buffer()->writeFile(tmp_ret, 1);
+ bv->buffer()->writeFile(tmp_ret, 1);
// assume successful write of tmp_ret
if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
failed = true;
if (failed) {
// failed to write/rename tmp_ret so try writing direct
- if (!current_view->buffer()->writeFile(fname, 1)) {
+ if (!bv->buffer()->writeFile(fname, 1)) {
// It is dangerous to do this in the child,
// but safe in the parent, so...
if (pid == -1)
- current_view->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
+ bv->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
}
}
if (pid == 0) { // we are the child so...
}
}
- current_view->buffer()->markBakClean();
- current_view->owner()->resetAutosaveTimer();
+ bv->buffer()->markBakClean();
+ bv->owner()->resetAutosaveTimer();
}
if (!bv->available()) return;
if (fname.empty()) {
- ProhibitInput();
+ ProhibitInput(bv);
fname = fileDlg.Select(_("File to Insert"),
bv->owner()->buffer()->filepath,
"*");
- AllowInput();
+ AllowInput(bv);
if (fname.empty()) return;
}
return;
}
- ifs.unsetf(std::ios::skipws);
- std::istream_iterator<char> ii(ifs);
- std::istream_iterator<char> end;
+ ifs.unsetf(ios::skipws);
+ istream_iterator<char> ii(ifs);
+ istream_iterator<char> end;
//string tmpstr(ii, end); // yet a reason for using std::string
// alternate approach to get the file into a string:
string tmpstr;
void MenuInsertLabel(char const * arg)
{
string label = arg;
- ProhibitInput();
+ ProhibitInput(current_view);
if (label.empty()) {
pair<bool, string>
result = askForText(_("Enter new label to insert:"));
new_inset->setContents(label);
current_view->insertInset(new_inset);
}
- AllowInput();
+ AllowInput(current_view);
}
#ifdef WITH_WARNINGS
#warning remove this once we have a proper geometry class
#endif
- BufferParams::PAPER_SIZE ps = static_cast<BufferParams::PAPER_SIZE>(bv->buffer()->params.papersize);
+ BufferParams::PAPER_SIZE ps =
+ static_cast<BufferParams::PAPER_SIZE>(bv->buffer()->params.papersize);
switch (ps) {
case BufferParams::PAPER_A4PAPER:
add_flags = "-p a4";
default: /* nothing to be done yet ;-) */ break;
}
- ProhibitInput();
+ ProhibitInput(bv);
Systemcalls one;
switch (flag) {
case 0: /* TeX output asked */
bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
- s2 = "sgml2latex " + add_flags + " -o tex "
- + lyxrc.sgml_extra_options + ' ' + name;
+ s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o tex " + ' ' + name;
if (one.startscript(Systemcalls::System, s2))
errorcode = 1;
break;
case 1: /* dvi output asked */
bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
- s2 = "sgml2latex " + add_flags + " -o dvi "
- + lyxrc.sgml_extra_options + ' ' + name;
+ s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o dvi " + ' ' + name;
if (one.startscript(Systemcalls::System, s2)) {
errorcode = 1;
} else
break;
}
- AllowInput();
+ AllowInput(bv);
bv->buffer()->redraw();
return errorcode;
current_view->buffer()->makeDocBookFile(name, 0);
// Shall this code go or should it stay? (Lgb)
+ // This code is a placeholder for future implementation. (Jose')
// string add_flags;
// LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
// switch (ps) {
// case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
// default: /* nothing to be done yet ;-) */ break;
// }
- ProhibitInput();
+ ProhibitInput(current_view);
int errorcode = 0;
Systemcalls one;
case 1: /* dvi output asked */
{
current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
- string s2 = "sgmltools --backend dvi " + name;
+ string s2 = lyxrc.docbook_to_dvi_command + ' ' + name;
if (one.startscript(Systemcalls::System, s2)) {
errorcode = 1;
} else
break;
}
- AllowInput();
+ AllowInput(current_view);
current_view->buffer()->redraw();
return errorcode;
fl_set_input(fd_form_document->input_spacing, "");
switch (params->spacing.getSpace()) {
+ case Spacing::Default: // nothing bad should happen with this
case Spacing::Single:
{
// \singlespacing
//char sval[20];
//sprintf(sval, "%g", params->spacing.getValue());
#ifdef HAVE_SSTREAM
- ostringstream sval;
+ std::ostringstream sval;
sval << params->spacing.getValue(); // setw?
fl_set_input(fd_form_document->input_spacing,
sval.str().c_str());
void ToggleAndShow(BufferView *, LyXFont const &);
-void FontSize(string const & size)
+void FontSize(BufferView * bv, string const & size)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setGUISize(size);
- ToggleAndShow(current_view, font);
+ ToggleAndShow(bv, font);
}
-void Emph()
+void Emph(BufferView * bv)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setEmph(LyXFont::TOGGLE);
- ToggleAndShow(current_view, font);
+ ToggleAndShow(bv, font);
}
-void Noun()
+void Noun(BufferView * bv)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setNoun(LyXFont::TOGGLE);
- ToggleAndShow(current_view, font);
+ ToggleAndShow(bv, font);
}
-void Bold()
+void Bold(BufferView * bv)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setSeries(LyXFont::BOLD_SERIES);
- ToggleAndShow(current_view, font);
+ ToggleAndShow(bv, font);
}
-void Underline()
+void Underline(BufferView * bv)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setUnderbar(LyXFont::TOGGLE);
- ToggleAndShow(current_view, font);
+ ToggleAndShow(bv, font);
}
-void Code()
+void Code(BufferView * bv)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
- ToggleAndShow(current_view, font);
+ ToggleAndShow(bv, font);
}
-void Sans()
+void Sans(BufferView * bv)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setFamily(LyXFont::SANS_FAMILY);
- ToggleAndShow(current_view, font);
+ ToggleAndShow(bv, font);
}
-void Roman()
+void Roman(BufferView * bv)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setFamily(LyXFont::ROMAN_FAMILY);
- ToggleAndShow(current_view, font);
+ ToggleAndShow(bv, font);
}
-void Tex()
+void Tex(BufferView * bv)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setLatex (LyXFont::TOGGLE);
- ToggleAndShow(current_view, font);
+ ToggleAndShow(bv, font);
}
-void LangCB(string const & l)
+void Lang(BufferView * bv, string const & l)
{
LyXFont font(LyXFont::ALL_IGNORE);
Languages::iterator lit = languages.find(l);
if (lit != languages.end()) {
font.setLanguage(&(*lit).second);
- ToggleAndShow(current_view, font);
+ ToggleAndShow(bv, font);
} else
WriteAlert(_("Error! unknown language"),l);
}
-void StyleReset()
+void StyleReset(BufferView * bv)
{
- LyXFont font(LyXFont::ALL_INHERIT);
- ToggleAndShow(current_view, font);
+ LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
+ ToggleAndShow(bv, font);
}
* future perhaps we could try to implement a callback to the button-bar.
* That is, `light' the bold button when the font is currently bold, etc.
*/
-string CurrentState()
+string CurrentState(BufferView * bv)
{
string state;
- if (current_view->available()) {
+ if (bv->available()) {
// I think we should only show changes from the default
// font. (Asger)
- Buffer * buffer = current_view->buffer();
- LyXFont font = current_view->text->real_current_font;
+ Buffer * buffer = bv->buffer();
+ LyXFont font = bv->text->real_current_font;
LyXFont defaultfont = textclasslist.TextClass(buffer->
params.textclass).defaultfont();
font.reduce(defaultfont);
state = _("Font: ") + font.stateText();
-
- int depth = current_view->text->GetDepth();
+ // The paragraph depth
+ int depth = bv->text->GetDepth();
if (depth > 0)
state += string(_(", Depth: ")) + tostr(depth);
+ // The paragraph spacing, but only if different from
+ // buffer spacing.
+ if (!bv->text->cursor.par->spacing.isDefault()) {
+ Spacing::Space cur_space =
+ bv->text->cursor.par->spacing.getSpace();
+ state += _(", Spacing: ");
+ switch (cur_space) {
+ case Spacing::Single:
+ state += _("Single");
+ break;
+ case Spacing::Onehalf:
+ state += _("Onehalf");
+ break;
+ case Spacing::Double:
+ state += _("Double");
+ break;
+ case Spacing::Other:
+ state += _("Other (");
+ state += tostr(bv->text->cursor.par->spacing.getValue());
+ state += ")";
+ break;
+ case Spacing::Default:
+ // should never happen, do nothing
+ break;
+ }
+ }
}
return state;
}
+
// candidate for move to BufferView
/* -------> Does the actual toggle job of the XxxCB() calls above.
* Also shows the current font state.
}
-void Free()
+void Free(BufferView * bv)
{
- ToggleAndShow(current_view, UserFreeFont());
+ ToggleAndShow(bv, UserFreeFont());
}
extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
{
- ProhibitInput();
+ ProhibitInput(current_view);
if (textclasslist.Load(fl_get_choice(ob)-1)) {
if (AskQuestion(_("Should I set some parameters to"),
fl_get_choice_text(ob),
fl_set_choice(fd_form_document->choice_class,
current_view->buffer()->params.textclass + 1);
}
- AllowInput();
+ AllowInput(current_view);
}
bool redo = false;
BufferParams * params = &(current_view->buffer()->params);
+ Language const * old_language = params->language_info;
+ Language const * new_language;
params->language = combo_language->getline();
Languages::iterator lit = languages.find(params->language);
if (lit != languages.end())
- params->language_info = &(*lit).second;
+ new_language = &(*lit).second;
else
- params->language_info = default_language;
+ new_language = default_language;
+
+ if (current_view->available()) {
+ if (old_language != new_language &&
+ old_language->RightToLeft == new_language->RightToLeft &&
+ ! current_view->buffer()->isMultiLingual() ) {
+ current_view->buffer()->ChangeLanguage(old_language,
+ new_language);
+ current_view->buffer()->redraw();
+ }
+ }
+ params->language_info = new_language;
// If default skip is a "Length" but there's no text in the
// input field, reset the kind to "Medskip", which is the default.
if (!current_view->available())
return;
- if (lyxrc.rtl_support) {
- current_view->text->SetCursor(current_view->text->cursor.par,
- current_view->text->cursor.pos);
- current_view->setState();
- }
+
+ current_view->text->SetCursor(current_view->text->cursor.par,
+ current_view->text->cursor.pos);
+ current_view->setState();
LyXTextClassList::ClassList::size_type new_class =
fl_get_choice(fd_form_document->choice_class) - 1;
if (textclasslist.Load(new_class)) {
// successfully loaded
redo = true;
- current_view->owner()->getMiniBuffer()->Set(_("Converting document to new document class..."));
- int ret = current_view->text->
- SwitchLayoutsBetweenClasses(current_view->buffer()->
- params.textclass,
- new_class,
- current_view->buffer()->
- paragraph);
+ current_view->owner()->getMiniBuffer()->
+ Set(_("Converting document to new document class..."));
+ CutAndPaste cap;
+ int ret = cap.SwitchLayoutsBetweenClasses(
+ current_view->buffer()->params.textclass,
+ new_class,
+ current_view->buffer()->paragraph);
if (ret) {
string s;
static
bool stringOnlyContains (string const & LStr, char const * cset)
{
- char const * cstr = LStr.c_str() ;
+#if 0
+ char const * cstr = LStr.c_str();
- return strspn(cstr, cset) == strlen(cstr) ;
+ return strspn(cstr, cset) == strlen(cstr);
+#else
+ return LStr.find_first_not_of(cset) == string::npos;
+#endif
}