]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_cb.C
Dekels tabular/textinset patches
[lyx.git] / src / lyx_cb.C
index ea272c971624056f5d2e2f903a6e61286d9af8f5..5509d936bf428507359d3d16b7e42925dd34017a 100644 (file)
@@ -385,11 +385,11 @@ void AutoSave(BufferView * bv)
                // anyway.
                bool failed = false;
                
-               string const tmp_ret = lyx::tempName();
+               string const tmp_ret = lyx::tempName(string(), "lyxauto");
                if (!tmp_ret.empty()) {
                        bv->buffer()->writeFile(tmp_ret, 1);
                        // assume successful write of tmp_ret
-                       if (lyx::rename(tmp_ret, fname)) {
+                       if (!lyx::rename(tmp_ret, fname)) {
                                failed = true;
                                // most likely couldn't move between filesystems
                                // unless write of tmp_ret failed
@@ -491,7 +491,7 @@ void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
        // We use this until the compilers get better...
        vector<char> tmp;
        copy(ii, end, back_inserter(tmp));
-       string tmpstr(tmp.begin(), tmp.end());
+       string const tmpstr(tmp.begin(), tmp.end());
 #else
        // This is what we want to use and what we will use once the
        // compilers get good enough. 
@@ -518,8 +518,75 @@ void MenuInsertLabel(BufferView * bv, string const & arg)
        string label(arg);
        ProhibitInput(bv);
        if (label.empty()) {
-               pair<bool, string>
-                       result = askForText(_("Enter new label to insert:"));
+#ifdef LABEL_INIT
+#ifndef NEW_INSETS
+               LyXParagraph * par =
+                       bv->text->cursor.par()->FirstPhysicalPar();
+#else
+               LyXParagraph * par = bv->text->cursor.par();
+#endif
+               LyXLayout const * layout =
+                       &textclasslist.Style(bv->buffer()->params.textclass,
+                                            par->GetLayout());
+
+               if (layout->latextype == LATEX_PARAGRAPH && par->previous) {
+#ifndef NEW_INSETS
+                       LyXParagraph * par2 = par->previous->FirstPhysicalPar();
+#else
+                       LyXParagraph * par2 = par->previous;
+#endif
+                       LyXLayout const * layout2 =
+                               &textclasslist.Style(bv->buffer()->params.textclass,
+                                                    par2->GetLayout());
+                       if (layout2->latextype != LATEX_PARAGRAPH) {
+                               par = par2;
+                               layout = layout2;
+                       }
+               }
+               string text = layout->latexname().substr(0, 3);
+               if (layout->latexname() == "theorem")
+                       text = "thm"; // Create a correct prefix for prettyref
+#ifndef NEW_INSETS
+               if (par->footnoteflag==LyXParagraph::OPEN_FOOTNOTE)
+                       switch (par->footnotekind) {
+                       case LyXParagraph::FIG:
+                       case LyXParagraph::WIDE_FIG:
+                               text = "fig";
+                               break;
+                       case LyXParagraph::TAB:
+                       case LyXParagraph::WIDE_TAB:
+                               text = "tab";
+                               break;
+                       case LyXParagraph::ALGORITHM:
+                               text = "alg";
+                               break;
+                       case LyXParagraph::FOOTNOTE:    
+                       case LyXParagraph::MARGIN:
+                               break;
+                       }
+#endif
+               text += ":";
+               if (layout->latextype == LATEX_PARAGRAPH ||
+                   lyxrc.label_init_length < 0)
+                       text.erase();
+               string par_text = par->String(bv->buffer(), false);
+               for (int i = 0; i < lyxrc.label_init_length; ++i) {
+                       if (par_text.empty())
+                               break;
+                       string head;
+                       par_text = split(par_text, head, ' ');
+                       if (i > 0)
+                               text += '_'; // Is it legal to use spaces in
+                                            // labels ?
+                       text += head;
+               }
+
+               pair<bool, string> result =
+                       askForText(_("Enter new label to insert:"), text);
+#else
+               pair<bool, string> result =
+                       askForText(_("Enter new label to insert:"));
+#endif
                if (result.first) {
                        label = frontStrip(strip(result.second));
                }