]> git.lyx.org Git - lyx.git/commitdiff
LyX version info for InsetInfo.
authorRichard Heck <rgheck@comcast.net>
Sat, 17 Apr 2010 13:04:41 +0000 (13:04 +0000)
committerRichard Heck <rgheck@comcast.net>
Sat, 17 Apr 2010 13:04:41 +0000 (13:04 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@34186 a592a061-630c-0410-9148-cb99ea01b6c8

lib/lyx2lyx/lyx_2_0.py
src/Buffer.cpp
src/frontends/qt4/GuiInfo.cpp
src/insets/InsetInfo.cpp
src/insets/InsetInfo.h

index d7f00c8e80ad4377b19990909797a80ee267714e..f5204464061da85052763cd40a9144ec9338f6e3 100644 (file)
@@ -22,6 +22,7 @@
 import re, string
 import unicodedata
 import sys, os
+import lyx2lyx_version
 
 from parser_tools import find_token, find_end_of, find_tokens, get_value, get_value_string
 
@@ -1466,6 +1467,44 @@ def revert_shadedboxcolor(document):
                            + ', ' + str(blueout) + '}\n')
 
 
+def revert_lyx_version(document):
+    " Reverts LyX Version information from Inset Info "
+    i = 0
+    while 1:
+        i = find_token(document.body, '\\begin_inset Info', i)
+        if i == -1:
+            return
+        j = find_end_of_inset(document.body, i + 1)
+        if j == -1:
+            # should not happen
+            document.warning("Malformed LyX document: Could not find end of Info inset.")
+        # We expect:
+        # \begin_inset Info
+        # type  "lyxinfo"
+        # arg   "version"
+        # \end_inset
+        # but we shall try to be forgiving.
+        arg = typ = ""
+        for k in range(i, j):
+            if document.body[k].startswith("arg"):
+                arg = document.body[k][3:].strip().strip('"')
+            if document.body[k].startswith("type"):
+                typ = document.body[k][4:].strip().strip('"')
+        if arg != "version" or typ != "lyxinfo":
+            i = j+1
+            continue
+        # We do not actually know the version of LyX used to produce the document.
+        # But we can use our version, since we are reverting.
+        s = [lyx2lyx_version.version]
+        # Now we want to check if the line after "\end_inset" is empty. It normally
+        # is, so we want to remove it, too.
+        lastline = j+1
+        if document.body[j+1].strip() == "":
+            lastline = j+2
+        document.body[i: lastline] = s
+        i = i+1
+
+
 ##
 # Conversion hub
 #
@@ -1510,10 +1549,12 @@ convert = [[346, []],
            [382, []],
            [383, []],
            [384, []],
-           [385, []]
+           [385, []],
+           [386, []]
           ]
 
-revert =  [[384, [revert_shadedboxcolor]],
+revert =  [[385, [revert_lyx_version]],
+           [384, [revert_shadedboxcolor]],
            [383, [revert_fontcolor]],
            [382, [revert_turkmen]],
            [381, [revert_notefontcolor]],
index fa98e369581f7aecfe6eecf5ac976be88fbd877e..b0688cb318a531704bb7e70e77a057af322e04d1 100644 (file)
@@ -126,7 +126,7 @@ namespace {
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-int const LYX_FORMAT = 385; // uwestoehr: support to change the shaded box color
+int const LYX_FORMAT = 386; // rgh: LyX version for InsetInfo
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
index db7efb5d6542b464ff5933bf7780ab0d44da7e18..91476389617cb0868856e39dc25c303f0369b3d4 100644 (file)
@@ -40,11 +40,11 @@ namespace frontend {
 /////////////////////////////////////////////////////////////////
 
 char const * info_types[] =
-{ "unknown", "shortcut", "shortcuts", "lyxrc", "package", "textclass", "menu", "icon", "buffer", "" };
+{ "unknown", "shortcut", "shortcuts", "lyxrc", "package", "textclass", "menu", "icon", "buffer", "lyxinfo", "" };
 
 char const * info_types_gui[] =
 { N_("unknown"), N_("shortcut"), N_("shortcuts"), N_("lyxrc"), N_("package"), N_("textclass"),
-  N_("menu"), N_("icon"), N_("buffer"), ""};
+  N_("menu"), N_("icon"), N_("buffer"), N_("lyxinfo"), ""};
 
 
 GuiInfo::GuiInfo(QWidget * parent) : InsetParamsWidget(parent)
index bf9bdda93b6ba0150e2e679abcc4692a285b9c4c..62e2f663cd721a88f89440e3a89245a91f47790f 100644 (file)
@@ -61,6 +61,7 @@ NameTranslator const initTranslator()
        translator.addPair(InsetInfo::MENU_INFO, "menu");
        translator.addPair(InsetInfo::ICON_INFO, "icon");
        translator.addPair(InsetInfo::BUFFER_INFO, "buffer");
+       translator.addPair(InsetInfo::LYX_INFO, "lyxinfo");
 
        return translator;
 }
@@ -176,6 +177,8 @@ bool InsetInfo::validateModifyArgument(docstring const & arg) const
                return name == "name" || name == "path" || name == "class" ||
                       name == "vcs-revision" || name == "vcs-tree-revision" ||
                       name == "vcs-author" || name == "vcs-date" || name == "vcs-time";
+       case LYX_INFO:
+               return name == "version";
        }
        return false;
 }
@@ -385,6 +388,9 @@ void InsetInfo::updateInfo()
                        setText(_("Unknown buffer info"));
                break;
        }
+       case LYX_INFO:
+               if (name_ == "version")
+                       setText(from_ascii(PACKAGE_VERSION));
        }
 }
 
index ebe987b9cc671e78a54d0b68fbd4b1a07f82c47c..6bcd8ed4d0379b287a209cd2debe95ac4023fa9f 100644 (file)
@@ -60,6 +60,9 @@ icon: argument is the name of the LFUN such as "paste". The syntax is the same
 
 buffer: argument can be one of "name", "path", "class". This inset output the
     filename, path, and textclass of this buffer.
+               
+lyxinfo: argument must (presently) be "version". This inset outputs information 
+               about the version of LyX currently in use.
 
 There is currently no GUI, no menu entry for this inset. A user can define a
 shortcut for "info-insert" (e.g. C-S-I), and
@@ -87,6 +90,7 @@ public:
                MENU_INFO,      // Which menu item is used for certain function
                ICON_INFO,      // which toolbar icon is used for certain function
                BUFFER_INFO,    // Buffer related information
+               LYX_INFO,       // LyX version information
        };
 
        ///