]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_cb.C
Small fix.
[lyx.git] / src / lyx_cb.C
index b787833a86e07eb43e2d0ee31a1e53bcb693a9eb..4f47c56621a9b923f805aaa315a6a97c16341458 100644 (file)
@@ -160,7 +160,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);
-void MenuWriteAs(Buffer * buffer);
+bool MenuWriteAs(Buffer * buffer);
 void MenuReload(Buffer * buf);
 void MenuLayoutSave();
 
@@ -208,7 +208,7 @@ void MenuWrite(Buffer * buffer)
 
 // should be moved to BufferView.C
 // Half of this func should be in LyXView, the rest in BufferView.
-void MenuWriteAs(Buffer * buffer)
+bool MenuWriteAs(Buffer * buffer)
 {
        // Why do we require BufferView::text to be able to write a
        // document? I see no point in that. (Lgb)
@@ -225,14 +225,21 @@ void MenuWriteAs(Buffer * buffer)
        if (!IsLyXFilename(fname))
                fname += ".lyx";
 
-       fname = fileDlg.Select(_("Enter Filename to Save Document as"), 
-                              OnlyPath(fname),
-                              "*.lyx", 
-                              OnlyFilename(fname));
+       if (buffer->isUnnamed()) {
+               fname = fileDlg.Select(_("Enter Filename to Save Document as"), 
+                                      "",
+                                      "*.lyx", 
+                                      "");
+       } else {
+               fname = fileDlg.Select(_("Enter Filename to Save Document as"), 
+                                      OnlyPath(fname),
+                                      "*.lyx", 
+                                      OnlyFilename(fname));
+       }
        AllowInput(current_view);
 
        if (fname.empty()) {
-               return;
+               return false;
        }
        // Make sure the absolute filename ends with appropriate suffix
        string s = MakeAbsPath(fname);
@@ -244,7 +251,7 @@ void MenuWriteAs(Buffer * buffer)
                if (!AskQuestion(_("Same name as document already has:"),
                                 MakeDisplayPath(s, 50),
                                 _("Save anyway?")))
-                       return;
+                       return false;
                // Falls through to name change and save
        } 
        // No, but do we have another file with this name open?
@@ -262,23 +269,25 @@ void MenuWriteAs(Buffer * buffer)
                                ShowMessage(buffer, _("Document renamed to '"),
                                                MakeDisplayPath(s), _("', but not saved..."));
                        }
-               return;
+               return false;
        } // Check whether the file exists
        else {
                FileInfo myfile(s);
                if (myfile.isOK() && !AskQuestion(_("Document already exists:"), 
                                                  MakeDisplayPath(s, 50),
                                                  _("Replace file?")))
-                       return;
+                       return false;
        }
 
        // Ok, change the name of the buffer
        buffer->fileName(s);
        buffer->markDirty();
+       buffer->setUnnamed(false);
        // And save
        // Small bug: If the save fails, we have irreversible changed the name
        // of the document.
        MenuWrite(buffer);
+       return true;
 }    
 
 
@@ -925,15 +934,12 @@ void MenuExport(Buffer * buffer, string const & extyp)
        }
        // HTML
        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);
+               if (buffer->isLinuxDoc())
+                       MenuMakeHTML_LinuxDoc(buffer);
+               else if (buffer->isDocBook())
+                       MenuMakeHTML_DocBook(buffer);
+               else
+                       MenuMakeHTML(buffer);
        }
        else {
                ShowMessage(buffer, _("Unknown export type: ") + extyp);
@@ -974,8 +980,8 @@ void AutoSave(BufferView * bv)
        if (!bv->available())
                return;
 
-       if (bv->buffer()->isBakClean()
-           || bv->buffer()->isReadonly()) {
+       if (bv->buffer()->isBakClean() ||
+           bv->buffer()->isReadonly() || bv->buffer()->isUnnamed()) {
                // We don't save now, but we'll try again later
                bv->owner()->resetAutosaveTimer();
                return;
@@ -1102,10 +1108,19 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
        ifs.unsetf(ios::skipws);
        istream_iterator<char> ii(ifs);
        istream_iterator<char> end;
+#if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
+       // We use this until the compilers get better...
+       vector<char> tmp;
+       copy(ii, end, back_inserter(tmp));
+       string tmpstr(tmp.begin(), tmp.end());
+#else
+       // This is what we want to use and what we will use once the
+       // compilers get good enough. 
        //string tmpstr(ii, end); // yet a reason for using std::string
        // alternate approach to get the file into a string:
        string tmpstr;
        copy(ii, end, back_inserter(tmpstr));
+#endif
        // insert the string
        current_view->hideCursor();
        
@@ -1436,20 +1451,41 @@ bool UpdateLayoutParagraph()
                fl_set_button(fd_form_paragraph->radio_align_block, 1);
                break;
        }
-        
+
+#ifndef NEW_INSETS
        fl_set_button(fd_form_paragraph->check_lines_top,
                      text->cursor.par()->FirstPhysicalPar()->line_top);
+
        fl_set_button(fd_form_paragraph->check_lines_bottom,
                      text->cursor.par()->FirstPhysicalPar()->line_bottom);
+
        fl_set_button(fd_form_paragraph->check_pagebreaks_top,
                      text->cursor.par()->FirstPhysicalPar()->pagebreak_top);
+
        fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
                      text->cursor.par()->FirstPhysicalPar()->pagebreak_bottom);
        fl_set_button(fd_form_paragraph->check_noindent,
                      text->cursor.par()->FirstPhysicalPar()->noindent);
+#else
+       fl_set_button(fd_form_paragraph->check_lines_top,
+                     text->cursor.par()->line_top);
+       fl_set_button(fd_form_paragraph->check_lines_bottom,
+                     text->cursor.par()->line_bottom);
+       fl_set_button(fd_form_paragraph->check_pagebreaks_top,
+                     text->cursor.par()->pagebreak_top);
+       fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
+                     text->cursor.par()->pagebreak_bottom);
+       fl_set_button(fd_form_paragraph->check_noindent,
+                     text->cursor.par()->noindent);
+#endif
        fl_set_input (fd_form_paragraph->input_space_above, "");
-       
+
+#ifndef NEW_INSETS
        switch (text->cursor.par()->FirstPhysicalPar()->added_space_top.kind()) {
+#else
+       switch (text->cursor.par()->added_space_top.kind()) {
+#endif
+
        case VSpace::NONE:
                fl_set_choice (fd_form_paragraph->choice_space_above, 1);
                break;
@@ -1469,15 +1505,27 @@ bool UpdateLayoutParagraph()
                fl_set_choice (fd_form_paragraph->choice_space_above, 6);
                break;
        case VSpace::LENGTH:
-               fl_set_choice (fd_form_paragraph->choice_space_above, 7); 
+               fl_set_choice (fd_form_paragraph->choice_space_above, 7);
+#ifndef NEW_INSETS
                fl_set_input  (fd_form_paragraph->input_space_above, 
                               text->cursor.par()->FirstPhysicalPar()->added_space_top.length().asString().c_str());
+#else
+               fl_set_input  (fd_form_paragraph->input_space_above, 
+                              text->cursor.par()->added_space_top.length().asString().c_str());
+#endif
                break;
        }
+#ifndef NEW_INSETS
        fl_set_button (fd_form_paragraph->check_space_above,
                       text->cursor.par()->FirstPhysicalPar()->added_space_top.keep());
        fl_set_input (fd_form_paragraph->input_space_below, "");
        switch (text->cursor.par()->FirstPhysicalPar()->added_space_bottom.kind()) {
+#else
+       fl_set_button (fd_form_paragraph->check_space_above,
+                      text->cursor.par()->added_space_top.keep());
+       fl_set_input (fd_form_paragraph->input_space_below, "");
+       switch (text->cursor.par()->added_space_bottom.kind()) {
+#endif
        case VSpace::NONE:
                fl_set_choice (fd_form_paragraph->choice_space_below,
                               1);
@@ -1504,7 +1552,8 @@ bool UpdateLayoutParagraph()
                break;
        case VSpace::LENGTH:
                fl_set_choice (fd_form_paragraph->choice_space_below,
-                              7); 
+                              7);
+#ifndef NEW_INSETS
                fl_set_input  (fd_form_paragraph->input_space_below, 
                               text->cursor.par()->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
                break;
@@ -1514,7 +1563,17 @@ bool UpdateLayoutParagraph()
 
        fl_set_button(fd_form_paragraph->check_noindent,
                      text->cursor.par()->FirstPhysicalPar()->noindent);
+#else
+               fl_set_input  (fd_form_paragraph->input_space_below, 
+                              text->cursor.par()->added_space_bottom.length().asString().c_str());
+               break;
+       }
+       fl_set_button (fd_form_paragraph->check_space_below,
+                      text->cursor.par()->added_space_bottom.keep());
 
+       fl_set_button(fd_form_paragraph->check_noindent,
+                     text->cursor.par()->noindent);
+#endif
        if (current_view->buffer()->isReadonly()) {
                DisableParagraphLayout();
        } else {
@@ -2580,11 +2639,13 @@ extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
 
 /* callbacks for form form_table */
 
-extern "C" void TableApplyCB(FL_OBJECT *, long)
+extern "C"
+void TableApplyCB(FL_OBJECT *, long)
 {
        if (!current_view->available())
                return;
-   
+
+#ifndef NEW_TABULAR
        // check for tables in tables
        if (current_view->text->cursor.par()->table){
                WriteAlert(_("Impossible Operation!"),
@@ -2592,7 +2653,7 @@ extern "C" void TableApplyCB(FL_OBJECT *, long)
                           _("Sorry."));
                return;
        }
+#endif
        current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
 
        int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
@@ -2620,8 +2681,10 @@ extern "C" void TableApplyCB(FL_OBJECT *, long)
        //if (!fl_get_button(fd_form_table->check_latex)){
        // insert the new wysiwy table
        current_view->text->SetLayout(current_view, 0); // standard layout
+#ifndef NEW_INSETS
        if (current_view->text->cursor.par()->footnoteflag == 
            LyXParagraph::NO_FOOTNOTE) {
+#endif
                current_view->text
                        ->SetParagraph(current_view, 0, 0,
                                       0, 0,
@@ -2634,6 +2697,7 @@ extern "C" void TableApplyCB(FL_OBJECT *, long)
                                       LYX_ALIGN_CENTER,
                                       string(),
                                       0);
+#ifndef NEW_INSETS
        } else {
                current_view->text
                        ->SetParagraph(current_view, 0, 0,
@@ -2644,10 +2708,11 @@ extern "C" void TableApplyCB(FL_OBJECT *, long)
                                       string(),
                                       0);
        }
-       
+#endif
+#ifndef NEW_TABULAR
        current_view->text->cursor.par()->table =
                new LyXTable(xsize, ysize);
-
+#endif
        Language const * lang = 
                current_view->text->cursor.par()->getParLanguage(current_view->buffer()->params);
        LyXFont font(LyXFont::ALL_INHERIT, lang);
@@ -2665,13 +2730,15 @@ extern "C" void TableApplyCB(FL_OBJECT *, long)
 }
 
 
-extern "C" void TableCancelCB(FL_OBJECT *, long)
+extern "C"
+void TableCancelCB(FL_OBJECT *, long)
 {
        fl_hide_form(fd_form_table->form_table);
 }
 
 
-extern "C" void TableOKCB(FL_OBJECT * ob, long data)
+extern "C"
+void TableOKCB(FL_OBJECT * ob, long data)
 {
        TableApplyCB(ob, data);
        TableCancelCB(ob, data);
@@ -2703,7 +2770,8 @@ void Table()
 
 
 /* callbacks for form form_figure */
-extern "C" void FigureApplyCB(FL_OBJECT *, long)
+extern "C"
+void FigureApplyCB(FL_OBJECT *, long)
 {
        if (!current_view->available())
                return;
@@ -2714,7 +2782,10 @@ extern "C" void FigureApplyCB(FL_OBJECT *, long)
        
        current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
        if (fl_get_button(fd_form_figure->radio_inline)
-           || current_view->text->cursor.par()->table) {
+#ifndef NEW_TABULAR
+           || current_view->text->cursor.par()->table
+#endif
+               ) {
                InsetFig * new_inset = new InsetFig(100, 20, buffer);
                current_view->insertInset(new_inset);
                current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
@@ -2741,9 +2812,11 @@ extern "C" void FigureApplyCB(FL_OBJECT *, long)
 
        // The standard layout should always be numer 0;
        current_view->text->SetLayout(current_view, 0);
-       
+
+#ifndef NEW_INSETS
        if (current_view->text->cursor.par()->footnoteflag == 
            LyXParagraph::NO_FOOTNOTE) {
+#endif
                current_view->text->
                        SetParagraph(current_view, 0, 0,
                                     0, 0,
@@ -2753,6 +2826,7 @@ extern "C" void FigureApplyCB(FL_OBJECT *, long)
                                             buffer->params.spacing.getValue(),
                                             LyXLength::CM),
                                     LYX_ALIGN_CENTER, string(), 0);
+#ifndef NEW_INSETS
        } else {
                current_view->text->SetParagraph(current_view, 0, 0,
                                                 0, 0,
@@ -2762,6 +2836,7 @@ extern "C" void FigureApplyCB(FL_OBJECT *, long)
                                                 string(),
                                                 0);
        }
+#endif
        
        current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);