]> git.lyx.org Git - lyx.git/blobdiff - src/Text3.cpp
add the background image to distribution tarball
[lyx.git] / src / Text3.cpp
index 1dead38685eacf92e009e88d1cd8f4fcc6a9cf0b..764c22d4e76f16ff35dcd4c3bc007a5fb8b8812b 100644 (file)
@@ -73,6 +73,7 @@
 #include "support/lstrings.h"
 #include "support/lyxtime.h"
 #include "support/os.h"
+#include "support/regex.h"
 
 #include "mathed/InsetMathHull.h"
 #include "mathed/MathMacroTemplate.h"
@@ -1405,7 +1406,11 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                                lyx::dispatch(FuncRequest(LFUN_DEPTH_DECREMENT));
                }
                bool const morecont = cur.lastpos() > cur.pos();
-               lyx::dispatch(FuncRequest(LFUN_LAYOUT, "Separator"));
+               // FIXME This hardcoding is bad
+               docstring const sep =
+                               cur.buffer()->params().documentClass().hasLayout(from_ascii("Separator"))
+                                       ? from_ascii("Separator") : from_ascii("--Separator--");
+               lyx::dispatch(FuncRequest(LFUN_LAYOUT, sep));
                lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse"));
                if (morecont) 
                        lyx::dispatch(FuncRequest(LFUN_DOWN));
@@ -1471,12 +1476,12 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                bool const hebrew = 
                        par.getFontSettings(bufparams, pos).language()->lang() == "hebrew";
                bool const allow_inset_quote = !(par.isPassThru() || hebrew);
-               
+
+               string const arg = to_utf8(cmd.argument());
                if (allow_inset_quote) {
                        char_type c = ' ';
                        if (pos > 0 && (!cur.prevInset() || !cur.prevInset()->isSpace()))
                                c = par.getChar(pos - 1);
-                       string const arg = to_utf8(cmd.argument());
                        InsetQuotes::QuoteTimes const quote_type = (arg == "single")
                                ? InsetQuotes::SingleQuotes : InsetQuotes::DoubleQuotes;
                        cur.insert(new InsetQuotes(cur.buffer(), c, quote_type));
@@ -1484,8 +1489,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                } else {
                        // The cursor might have been invalidated by the replaceSelection.
                        cur.buffer()->changed(true);
-                       lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
-               }                       
+                       string const quote_string = (arg == "single") ? "'" : "\"";
+                       lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, quote_string));
+               }
                break;
        }
 
@@ -1668,15 +1674,46 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        }
 
        case LFUN_HREF_INSERT: {
-               InsetCommandParams p(HYPERLINK_CODE);
-               docstring content;
+               // FIXME If we're actually given an argument, shouldn't
+               // we use it, whether or not we have a selection?
+               docstring content = cmd.argument();
                if (cur.selection()) {
                        content = cur.selectionAsString(false);
                        cutSelection(cur, true, false);
                }
-               p["target"] = (cmd.argument().empty()) ?
-                       content : cmd.argument();
+
+               InsetCommandParams p(HYPERLINK_CODE);
+               if (!content.empty()){
+                       // if it looks like a link, we'll put it as target,
+                       // otherwise as name (bug #8792).
+
+                       // We can't do:
+                       //   regex_match(to_utf8(content), matches, link_re)
+                       // because smatch stores pointers to the substrings rather
+                       // than making copies of them. And those pointers become
+                       // invalid after regex_match returns, since it is then
+                       // being given a temporary object. (Thanks to Georg for
+                       // figuring that out.)
+                       regex const link_re("^([a-z]+):.*");
+                       smatch matches;
+                       string const c = to_utf8(lowercase(content));
+
+                       if (c.substr(0,7) == "mailto:") {
+                               p["target"] = content;
+                               p["type"] = from_ascii("mailto:");
+                       } else if (regex_match(c, matches, link_re)) {
+                               p["target"] = content;
+                               string protocol = matches.str(1);
+                               if (protocol == "file")
+                                       p["type"] = from_ascii("file:");
+                       } else
+                               p["name"] = content;
+               }
                string const data = InsetCommand::params2string(p);
+
+               // we need to have a target. if we already have one, then
+               // that gets used at the default for the name, too, which
+               // is probably what is wanted.
                if (p["target"].empty()) {
                        bv->showDialog("href", data);
                } else {
@@ -2440,6 +2477,10 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                        code = INDEX_CODE;
                else if (cmd.argument() == "index_print")
                        code = INDEX_PRINT_CODE;
+               else if (cmd.argument() == "listings")
+                       code = LISTINGS_CODE;
+               else if (cmd.argument() == "mathspace")
+                       code = MATH_HULL_CODE;
                else if (cmd.argument() == "nomenclature")
                        code = NOMENCL_CODE;
                else if (cmd.argument() == "nomencl_print")
@@ -2462,8 +2503,6 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                        code = VSPACE_CODE;
                else if (cmd.argument() == "wrap")
                        code = WRAP_CODE;
-               else if (cmd.argument() == "listings")
-                       code = LISTINGS_CODE;
                break;
 
        case LFUN_ERT_INSERT:
@@ -2864,7 +2903,8 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
 
        case LFUN_NEWLINE_INSERT:
                // LaTeX restrictions (labels or empty par)
-               enable = (cur.pos() > cur.paragraph().beginOfBody());
+               enable = !cur.paragraph().isPassThru()
+                       && cur.pos() > cur.paragraph().beginOfBody();
                break;
 
        case LFUN_TAB_INSERT:
@@ -2914,7 +2954,9 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
                break;
        
        case LFUN_ENVIRONMENT_SPLIT: {
-               if (!cur.buffer()->params().documentClass().hasLayout(from_ascii("Separator"))) {
+               // FIXME This hardcoding is bad
+               if (!cur.buffer()->params().documentClass().hasLayout(from_ascii("Separator"))
+                   && !cur.buffer()->params().documentClass().hasLayout(from_ascii("--Separator--"))) {
                        enable = false;
                        break;
                }