]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_cb.C
Forgot to add this files.
[lyx.git] / src / lyx_cb.C
index dc982373108ba431e3274a78fb0102d116c0b457..45d9c08fa8d8cfbe4094a5d63168c4c16ff41e19 100644 (file)
@@ -71,7 +71,6 @@ 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_toc * fd_form_toc;
 extern FD_form_ref * fd_form_ref;
 extern FD_form_bullet * fd_form_bullet;
 
@@ -160,7 +159,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 +207,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 +224,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 +250,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 +268,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 +933,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 +979,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 +1107,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();
        
@@ -1119,26 +1133,6 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
 }
 
 
-void MenuShowTableOfContents()
-{
-       static int ow = -1, oh;
-
-       TocUpdateCB(0, 0);
-       if (fd_form_toc->form_toc->visible) {
-               fl_raise_form(fd_form_toc->form_toc);
-       } else {
-               fl_show_form(fd_form_toc->form_toc,
-                            FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
-                            _("Table Of Contents"));
-               if (ow < 0) {
-                       ow = fd_form_toc->form_toc->w;
-                       oh = fd_form_toc->form_toc->h;
-               }
-               fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
-       }
-}
-
-
 void MenuInsertLabel(char const * arg)
 {
        string label = arg;
@@ -1151,9 +1145,9 @@ void MenuInsertLabel(char const * arg)
                }
        }
        if (!label.empty()) {
-               InsetLabel * new_inset = new InsetLabel;
-               new_inset->setContents(label);
-               current_view->insertInset(new_inset);
+               InsetCommandParams p( "label", label );
+               InsetLabel * inset = new InsetLabel( p );
+               current_view->insertInset( inset );
        }
        AllowInput(current_view);
 }
@@ -2629,7 +2623,8 @@ 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!"),
@@ -2637,7 +2632,7 @@ 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);
@@ -2693,10 +2688,10 @@ void TableApplyCB(FL_OBJECT *, long)
                                       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);
@@ -2766,7 +2761,10 @@ 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"));
@@ -2900,92 +2898,6 @@ void Reconfigure(BufferView * bv)
 }
 
 
-//
-// Table of Contents
-//
-
-static vector<Buffer::TocItem> toclist;
-
-
-extern "C" void TocSelectCB(FL_OBJECT * ob, long)
-{
-       if (!current_view->available())
-               return;
-   
-       TocUpdateCB(0, 0);
-       unsigned int choice = fl_get_browser(ob);
-       if (0 < choice && choice - 1 < toclist.size()) {
-               current_view->beforeChange();
-               current_view->text->SetCursor(current_view, toclist[choice-1].par, 0);
-               current_view->text->sel_cursor = 
-                       current_view->text->cursor;
-               current_view->update(BufferView::SELECT|BufferView::FITCUR);
-       } else {
-               WriteAlert(_("Error"), 
-                          _("Couldn't find this label"), 
-                          _("in current document."));
-       }
-}
-
-
-extern "C" void TocCancelCB(FL_OBJECT *, long)
-{
-       fl_hide_form(fd_form_toc->form_toc);
-}
-
-
-extern "C"
-void TocUpdateCB(FL_OBJECT *, long)
-{
-       if (!current_view->available()) {
-               toclist.clear();
-               fl_clear_browser(fd_form_toc->browser_toc);
-               fl_add_browser_line(fd_form_toc->browser_toc,
-                                   _("*** No Document ***"));
-               return;
-       }
-
-       vector<vector<Buffer::TocItem> > tmp =
-               current_view->buffer()->getTocList();
-       int type = fl_get_choice(fd_form_toc->toctype)-1;
-       //if (toclist == tmp[type])
-       //      return;
-       if (toclist.size() == tmp[type].size()) {
-               // Check if all elements are the same.
-               unsigned int i = 0;
-               for (; i < toclist.size(); ++i) {
-                       if (toclist[i] !=  tmp[type][i])
-                               break;
-               }
-               if (i >= toclist.size()) return;
-       }
-
-       toclist = tmp[type];
-
-       static Buffer * buffer = 0;
-       int topline = 0;
-       int line = 0;
-       if (buffer == current_view->buffer()) {
-               topline = fl_get_browser_topline(fd_form_toc->browser_toc);
-               line = fl_get_browser(fd_form_toc->browser_toc);
-       } else
-               buffer = current_view->buffer();
-
-       fl_clear_browser(fd_form_toc->browser_toc);
-       fl_hide_object(fd_form_toc->browser_toc);
-
-       for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
-            it != toclist.end(); ++it)
-               fl_add_browser_line(fd_form_toc->browser_toc,
-                                   (string(4*(*it).depth,' ')+
-                                    (*it).str).c_str());
-
-       fl_set_browser_topline(fd_form_toc->browser_toc, topline);
-       fl_select_browser_line(fd_form_toc->browser_toc, line);
-       fl_show_object(fd_form_toc->browser_toc);
-}
-
-
 /* callbacks for form form_ref */
 extern "C" void RefSelectCB(FL_OBJECT *, long data)
 {
@@ -3016,19 +2928,16 @@ extern "C" void RefSelectCB(FL_OBJECT *, long data)
                return;
        }       
 
-       static string const commands[5]
-               = { "\\ref", "\\pageref", "\\vref", "\\vpageref",
-                   "\\prettyref"};
-       string t = commands[data];
-
+       static string const cmdname[5]
+               = { "ref", "pageref", "vref", "vpageref", "prettyref"};
+       InsetCommandParams p( cmdname[data] );
+       p.setContents( s );
+       
        if (current_view->buffer()->isSGML())
-               t += "[" + u + "]" + "{" + s + "}";
-       else
-               t += "{" + s + "}";
+               p.setOptions( u );
 
-       Inset * new_inset = 
-               new InsetRef(t, current_view->buffer());
-       current_view->insertInset(new_inset);
+       Inset * inset = new InsetRef( p, current_view->buffer() );
+       current_view->insertInset( inset );
 }