]> 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 975c51f4973557a381f13b2fad601a90ea2b62ad..3bc8c6d426aec2dda78001ce07e57b998cce066d 100644 (file)
@@ -54,6 +54,7 @@
 #include "gettext.h"
 #include "layout.h"
 #include "language.h"
+#include "CutAndPaste.h"
 
 using std::ifstream;
 using std::copy;
@@ -202,10 +203,10 @@ void ShowMessage(Buffer * buf,
 // 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;
@@ -217,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,
@@ -248,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);
@@ -263,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();
@@ -324,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);
 
@@ -335,7 +336,7 @@ void MenuWriteAs(Buffer * buffer)
                               OnlyPath(fname),
                               "*.lyx", 
                               OnlyFilename(fname));
-       AllowInput();
+       AllowInput(current_view);
 
        if (fname.empty()) {
                return;
@@ -586,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
@@ -662,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;
 }
 
@@ -681,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 
@@ -691,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;
 }
 
@@ -1095,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
@@ -1130,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;
@@ -1145,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...
@@ -1157,8 +1158,8 @@ void AutoSave()
                }
        }
        
-       current_view->buffer()->markBakClean();
-       current_view->owner()->resetAutosaveTimer();
+       bv->buffer()->markBakClean();
+       bv->owner()->resetAutosaveTimer();
 }
 
 
@@ -1204,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;
        }
 
@@ -1270,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:"));
@@ -1283,7 +1284,7 @@ void MenuInsertLabel(char const * arg)
                new_inset->setContents(label);
                current_view->insertInset(new_inset);
        }
-       AllowInput();
+       AllowInput(current_view);
 }
 
 
@@ -1377,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";
@@ -1388,7 +1390,7 @@ int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
        default: /* nothing to be done yet ;-) */     break; 
        }
        
-       ProhibitInput();
+       ProhibitInput(bv);
        
        Systemcalls one;
        switch (flag) {
@@ -1410,7 +1412,7 @@ int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
                break;
        }
        
-       AllowInput();
+       AllowInput(bv);
 
         bv->buffer()->redraw();
        return errorcode;
@@ -1445,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;
@@ -1464,7 +1466,7 @@ int RunDocBook(int flag, string const & filename)
                break;
        }
        
-       AllowInput();
+       AllowInput(current_view);
 
         current_view->buffer()->redraw();
        return errorcode;
@@ -1875,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
@@ -2076,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, ignore_language);
-       ToggleAndShow(current_view, font);
+       ToggleAndShow(bv, font);
 }
 
 
@@ -2170,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.
@@ -2370,9 +2400,9 @@ LyXFont UserFreeFont()
 }
 
 
-void Free()
+void Free(BufferView * bv)
 {
-       ToggleAndShow(current_view, UserFreeFont());
+       ToggleAndShow(bv, UserFreeFont());
 }
 
 
@@ -2585,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),
@@ -2604,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);
 }
 
 
@@ -2664,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.
@@ -2698,9 +2741,10 @@ extern "C" void DocumentApplyCB(FL_OBJECT *, long)
    
        if (!current_view->available())
                return;
-       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;
@@ -2710,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;