]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_cb.C
citation patch from Angus
[lyx.git] / src / lyx_cb.C
index dc55aed188a65d794e5c4e21e7b7ad895046f9d8..da971808f2290eac446bc4f23baff9f5d5ca29a9 100644 (file)
@@ -14,7 +14,7 @@
 #include <algorithm>
 #include <iostream>
 
-#include "LString.h"
+//#include "LString.h"
 #include FORMS_H_LOCATION
 #include "lyx.h"
 #include "layout_forms.h"
 #include "support/filetools.h"
 #include "support/path.h"
 #include "lyxserver.h"
-#include "FontLoader.h"
 #include "lyxrc.h"
 #include "lyxtext.h"
 #include "CutAndPaste.h"
-#include "TextCache.h"
+#include "exporter.h"
 
 using std::ifstream;
 using std::copy;
@@ -70,7 +69,6 @@ extern FD_form_quotes * fd_form_quotes;
 extern FD_form_preamble * fd_form_preamble;
 extern FD_form_table * fd_form_table;
 extern FD_form_figure * fd_form_figure;
-extern FD_form_screen * fd_form_screen;
 extern FD_form_bullet * fd_form_bullet;
 
 extern BufferView * current_view; // called too many times in this file...
@@ -157,7 +155,7 @@ void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
 
 int RunLinuxDoc(BufferView *, int, string const &);
 int RunDocBook(int, string const &);
-void MenuWrite(Buffer * buf);
+bool MenuWrite(Buffer * buf);
 bool MenuWriteAs(Buffer * buffer);
 void MenuReload(Buffer * buf);
 void MenuLayoutSave();
@@ -165,8 +163,8 @@ void MenuLayoutSave();
 
 void ShowMessage(Buffer * buf,
                 string const & msg1,
-                string const & msg2 = string(),
-                string const & msg3 = string(), int delay = 6)
+                string const & msg2,
+                string const & msg3, int delay)
 {
        if (lyxrc.use_gui) {
                buf->getUser()->owner()->getMiniBuffer()->Set(msg1, msg2,
@@ -187,7 +185,7 @@ void ShowMessage(Buffer * buf,
 //
 
 // should be moved to lyxfunc.C
-void MenuWrite(Buffer * buffer)
+bool MenuWrite(Buffer * buffer)
 {
        XFlush(fl_display);
        if (!buffer->save()) {
@@ -196,11 +194,13 @@ void MenuWrite(Buffer * buffer)
                if (AskQuestion(_("Save failed. Rename and try again?"),
                                MakeDisplayPath(s, 50),
                                _("(If not, document is not saved.)"))) {
-                       MenuWriteAs(buffer);
+                       return MenuWriteAs(buffer);
                }
+               return false;
        } else {
                lastfiles->newFile(buffer->fileName());
        }
+       return true;
 }
 
 
@@ -280,15 +280,25 @@ bool MenuWriteAs(Buffer * buffer)
        // Ok, change the name of the buffer
        buffer->fileName(s);
        buffer->markDirty();
+       bool unnamed = buffer->isUnnamed();
        buffer->setUnnamed(false);
        // And save
        // Small bug: If the save fails, we have irreversible changed the name
        // of the document.
-       MenuWrite(buffer);
+       // Hope this is fixed this way! (Jug)
+       if (!MenuWrite(buffer)) {
+           buffer->fileName(oldname);
+           buffer->setUnnamed(unnamed);
+           ShowMessage(buffer, _("Document could not be saved!"),
+                       _("Holding the old name."), MakeDisplayPath(oldname));
+           return false;
+       }
+       // now remove the oldname autosave file if existant!
+       removeAutosaveFile(oldname);
        return true;
-}    
-
+}
 
+#ifndef NEW_EXPORT
 int MenuRunLaTeX(Buffer * buffer)
 {
        int ret = 0;
@@ -317,7 +327,7 @@ int MenuRunLaTeX(Buffer * buffer)
        }
        return ret;
 }
-
+#endif
 
 int MenuBuildProg(Buffer * buffer)
 {
@@ -379,7 +389,7 @@ int MenuRunChktex(Buffer * buffer)
        return ret;
 }
 
+#ifndef NEW_EXPORT
 int MakeLaTeXOutput(Buffer * buffer)
 {
        // Who cares?
@@ -592,7 +602,7 @@ bool PreviewPostscript(Buffer * buffer)
        AllowInput(current_view);
        return ret;
 }
-
+#endif
 
 void MenuFax(Buffer * buffer)
 {
@@ -600,6 +610,15 @@ void MenuFax(Buffer * buffer)
        //if (!bv->text)
        //      return;
 
+#ifdef NEW_EXPORT
+       // Generate postscript file
+       if (!Exporter::Export(buffer, "ps", true))
+               return;
+
+       // Send fax
+       string ps = OnlyFilename(ChangeExtension (buffer->fileName(), 
+                                                 ".ps"));
+#else
        // Generate postscript file
        if (!CreatePostscript(buffer, true)) {
                return;
@@ -608,6 +627,7 @@ void MenuFax(Buffer * buffer)
        // Send fax
        string ps = OnlyFilename(ChangeExtension (buffer->fileName(), 
                                                  ".ps_tmp"));
+#endif
        string path = OnlyPath (buffer->fileName());
        if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
                path = buffer->tmppath;
@@ -622,6 +642,7 @@ void MenuFax(Buffer * buffer)
 }
 
 
+#ifndef NEW_EXPORT
 // Returns false if we fail
 bool PreviewDVI(Buffer * buffer)
 {
@@ -943,6 +964,7 @@ void MenuExport(Buffer * buffer, string const & extyp)
                ShowMessage(buffer, _("Unknown export type: ") + extyp);
        }
 }
+#endif
 
 
 void QuitLyX()
@@ -978,8 +1000,7 @@ void AutoSave(BufferView * bv)
        if (!bv->available())
                return;
 
-       if (bv->buffer()->isBakClean() ||
-           bv->buffer()->isReadonly() || bv->buffer()->isUnnamed()) {
+       if (bv->buffer()->isBakClean() || bv->buffer()->isReadonly()) {
                // We don't save now, but we'll try again later
                bv->owner()->resetAutosaveTimer();
                return;
@@ -1161,7 +1182,7 @@ void LayoutsCB(int sel, void *)
                                                      tmp.c_str());
 }
 
-
+#ifndef NEW_EXPORT
 /*
  * SGML Linuxdoc support:
  * (flag == 0) make TeX output
@@ -1279,7 +1300,7 @@ int RunDocBook(int flag, string const & filename)
         current_view->buffer()->redraw();
        return errorcode;
 }
-
+#endif
 
 void MenuLayoutCharacter()
 {
@@ -1554,7 +1575,7 @@ void MenuLayoutParagraph()
        }
 }
 
-
+#ifdef USE_OLD_DOCUMENT_LAYOUT
 inline
 void DeactivateDocumentButtons ()
 {
@@ -1861,6 +1882,7 @@ void MenuLayoutQuotes()
                }
        }
 }
+#endif
 
 
 bool UpdateLayoutPreamble()
@@ -2211,8 +2233,8 @@ extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
 }
 
 
+#ifdef USE_OLD_DOCUMENT_LAYOUT
 /* callbacks for form form_document */
-
 void UpdateDocumentButtons(BufferParams const & params) 
 {
        fl_set_choice(fd_form_document->choice_pagestyle, 1);
@@ -2514,7 +2536,6 @@ extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
        // bullet callbacks etc. in bullet_panel.C -- ARRae
 }
 
-
 /* callbacks for form form_quotes */
 
 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
@@ -2565,7 +2586,19 @@ extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
        QuotesApplyCB(ob, data);
        QuotesCancelCB(ob, data);
 }
-
+#else
+// this is needed for now!
+extern "C" void ChoiceClassCB(FL_OBJECT *, long) {}
+extern "C" void DocumentDefskipCB(FL_OBJECT *, long) {}
+extern "C" void DocumentSpacingCB(FL_OBJECT *, long) {}
+extern "C" void DocumentApplyCB(FL_OBJECT *, long) {}
+extern "C" void DocumentCancelCB(FL_OBJECT *, long) {}
+extern "C" void DocumentOKCB(FL_OBJECT *, long) {}
+extern "C" void DocumentBulletsCB(FL_OBJECT *, long) {}
+extern "C" void QuotesApplyCB(FL_OBJECT *, long) {}
+extern "C" void QuotesCancelCB(FL_OBJECT *, long) {}
+extern "C" void QuotesOKCB(FL_OBJECT *, long) {}
+#endif
 
 
 /* callbacks for form form_preamble */
@@ -2821,43 +2854,6 @@ extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
 }
 
 
-extern "C" void ScreenApplyCB(FL_OBJECT *, long)
-{
-       lyxrc.roman_font_name = fl_get_input(fd_form_screen->input_roman);
-       lyxrc.sans_font_name = fl_get_input(fd_form_screen->input_sans);
-       lyxrc.typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
-       lyxrc.font_norm = fl_get_input(fd_form_screen->input_font_norm);
-       lyxrc.set_font_norm_type();
-       lyxrc.zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
-       fontloader.update();
-
-       // Of course we should only to the resize and the textcahce.clear
-       // if values really changed...but not very important right now. (Lgb)
-       
-       // All buffers will need resize
-       bufferlist.resize();
-       // We also need to empty the textcache so that
-       // the buffer will be formatted correctly after
-       // a zoom change.
-       textcache.clear();
-       
-       current_view->owner()->getMiniBuffer()->Set(_("Screen options set"));
-}
-
-
-extern "C" void ScreenCancelCB(FL_OBJECT *, long)
-{
-       fl_hide_form(fd_form_screen->form_screen);
-}
-
-
-extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
-{
-       ScreenCancelCB(ob, data);
-       ScreenApplyCB(ob, data);
-}
-
-
 // This function runs "configure" and then rereads lyx.defaults to
 // reconfigure the automatic settings.
 void Reconfigure(BufferView * bv)