]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_cb.C
Small fix.
[lyx.git] / src / lyx_cb.C
index dc9b4debafe2626790d3127300655cc47056f555..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();