]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_cb.C
paragraph-spacing, redoparagraph in deleteemptyparagraphmechanism, got rid of some...
[lyx.git] / src / lyx_cb.C
index a52d5fbd7ebe2981e49a85175f1282decc36415a..3bc8c6d426aec2dda78001ce07e57b998cce066d 100644 (file)
 #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"
@@ -56,6 +54,16 @@ using std::back_inserter;
 #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;
@@ -83,7 +91,6 @@ extern bool send_fax(string const & fname, string const & sendcmd);
 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
@@ -175,13 +182,15 @@ void MenuReload(Buffer * buf);
 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;
        }
@@ -194,10 +203,10 @@ void ShowMessage(Buffer * buf, string const & msg1,
 // 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;
@@ -209,7 +218,7 @@ void ProhibitInput()
        }
    
        /* 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,
@@ -240,13 +249,13 @@ void SetXtermCursor(Window win)
 }
 
 
-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);
@@ -255,8 +264,8 @@ void AllowInput()
                                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();
@@ -316,7 +325,7 @@ void MenuWriteAs(Buffer * buffer)
        string oldname = fname;
        LyXFileDlg fileDlg;
 
-       ProhibitInput();
+       ProhibitInput(current_view);
        fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
        fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
 
@@ -327,7 +336,7 @@ void MenuWriteAs(Buffer * buffer)
                               OnlyPath(fname),
                               "*.lyx", 
                               OnlyFilename(fname));
-       AllowInput();
+       AllowInput(current_view);
 
        if (fname.empty()) {
                return;
@@ -520,8 +529,8 @@ bool RunScript(Buffer * buffer, bool wait,
        // 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));
        }
@@ -578,11 +587,11 @@ bool CreatePostscript(Buffer * buffer, bool wait = false)
        //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
@@ -654,7 +663,7 @@ bool CreatePostscript(Buffer * buffer, bool wait = false)
         }
         Path p(path);
        bool ret = RunScript(buffer, wait, command);
-       AllowInput();
+       AllowInput(current_view);
        return ret;
 }
 
@@ -673,7 +682,7 @@ bool PreviewPostscript(Buffer * buffer)
        }
 
        // Start postscript viewer
-       ProhibitInput();
+       ProhibitInput(current_view);
        string ps = ChangeExtension (buffer->fileName(),
                                     ".ps_tmp", true);
        // push directorypath, if necessary 
@@ -683,7 +692,7 @@ bool PreviewPostscript(Buffer * buffer)
         }
         Path p(path);
        bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
-       AllowInput();
+       AllowInput(current_view);
        return ret;
 }
 
@@ -947,6 +956,57 @@ void MenuMakeHTML(Buffer * buffer)
 
 }
 
+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
@@ -996,6 +1056,14 @@ void MenuExport(Buffer * buffer, string const & extyp)
        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);
        }
@@ -1028,26 +1096,26 @@ void QuitLyX()
 
 
 
-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
@@ -1063,7 +1131,7 @@ void AutoSave()
                // 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;
@@ -1078,11 +1146,11 @@ void AutoSave()
                
                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...
@@ -1090,8 +1158,8 @@ void AutoSave()
                }
        }
        
-       current_view->buffer()->markBakClean();
-       current_view->owner()->resetAutosaveTimer();
+       bv->buffer()->markBakClean();
+       bv->owner()->resetAutosaveTimer();
 }
 
 
@@ -1137,11 +1205,11 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
        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;
        }
 
@@ -1160,9 +1228,9 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
                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;
@@ -1203,7 +1271,7 @@ void MenuShowTableOfContents()
 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:"));
@@ -1216,7 +1284,7 @@ void MenuInsertLabel(char const * arg)
                new_inset->setContents(label);
                current_view->insertInset(new_inset);
        }
-       AllowInput();
+       AllowInput(current_view);
 }
 
 
@@ -1310,7 +1378,8 @@ int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
 #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";
@@ -1321,21 +1390,19 @@ int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
        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
@@ -1345,7 +1412,7 @@ int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
                break;
        }
        
-       AllowInput();
+       AllowInput(bv);
 
         bv->buffer()->redraw();
        return errorcode;
@@ -1372,6 +1439,7 @@ int RunDocBook(int flag, string const & filename)
        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) {
@@ -1379,7 +1447,7 @@ int RunDocBook(int flag, string const & filename)
 //     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;
@@ -1387,7 +1455,7 @@ int RunDocBook(int flag, string const & filename)
        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
@@ -1398,7 +1466,7 @@ int RunDocBook(int flag, string const & filename)
                break;
        }
        
-       AllowInput();
+       AllowInput(current_view);
 
         current_view->buffer()->redraw();
        return errorcode;
@@ -1809,6 +1877,7 @@ bool UpdateLayoutDocument(BufferParams * params)
    
        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
@@ -1833,7 +1902,7 @@ bool UpdateLayoutDocument(BufferParams * params)
                //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());
@@ -2010,93 +2079,93 @@ static
 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);
 }
 
 
@@ -2104,27 +2173,54 @@ void StyleReset()
  * 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.
@@ -2304,9 +2400,9 @@ LyXFont UserFreeFont()
 }
 
 
-void Free()
+void Free(BufferView * bv)
 {
-       ToggleAndShow(current_view, UserFreeFont());
+       ToggleAndShow(bv, UserFreeFont());
 }
 
 
@@ -2519,7 +2615,7 @@ void UpdateDocumentButtons(BufferParams const & params)
 
 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),
@@ -2538,7 +2634,7 @@ extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
                fl_set_choice(fd_form_document->choice_class, 
                              current_view->buffer()->params.textclass + 1);
        }
-       AllowInput();
+       AllowInput(current_view);
 }
 
 
@@ -2598,12 +2694,25 @@ extern "C" void DocumentApplyCB(FL_OBJECT *, long)
        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.
@@ -2632,11 +2741,10 @@ extern "C" void DocumentApplyCB(FL_OBJECT *, long)
    
        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;
@@ -2646,13 +2754,13 @@ extern "C" void DocumentApplyCB(FL_OBJECT *, long)
                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;
@@ -2969,9 +3077,13 @@ extern "C" void PrintCancelCB(FL_OBJECT *, long)
 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
 }