From: Juergen Spitzmueller Date: Sun, 29 Jul 2018 17:41:34 +0000 (+0200) Subject: Split vcs Info inset from buffer Info inset X-Git-Tag: lyx-2.4.0dev-acb2ca7b~3232 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=358436ea1ea7352c6ac93871b5d4ec05ed48efe6;p=features.git Split vcs Info inset from buffer Info inset This should go separately in the GUI, and thus in the inset. --- diff --git a/development/FORMAT b/development/FORMAT index edab9cb82d..3c77ed4183 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -7,6 +7,9 @@ changes happened in particular if possible. A good example would be ----------------------- +2018-07-29 Jürgen Spitzmüller + * format incremented to 557: Separate vcs Info inset from buffer Info inset. + 2018-07-07 Jürgen Spitzmüller * format incremented to 556: Support for bib file encoding. - New param "encoding" for CommandInset bibtex diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py index c00e630148..8bf0dc17bf 100644 --- a/lib/lyx2lyx/lyx_2_4.py +++ b/lib/lyx2lyx/lyx_2_4.py @@ -537,6 +537,72 @@ def revert_bibencoding(document): i = j + 1 + +def convert_vcsinfo(document): + " Separate vcs Info inset from buffer Info inset. " + + types = { + "vcs-revision" : "revision", + "vcs-tree-revision" : "tree-revision", + "vcs-author" : "author", + "vcs-time" : "time", + "vcs-date" : "date" + } + i = 0 + while True: + 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: + document.warning("Malformed LyX document: Could not find end of Info inset.") + i = i + 1 + continue + tp = find_token(document.body, 'type', i, j) + tpv = get_quoted_value(document.body, "type", tp) + if tpv != "buffer": + i = i + 1 + continue + arg = find_token(document.body, 'arg', i, j) + argv = get_quoted_value(document.body, "arg", arg) + if argv not in list(types.keys()): + i = i + 1 + continue + document.body[tp] = "type \"vcs\"" + document.body[arg] = "arg \"" + types[argv] + "\"" + i = i + 1 + + +def revert_vcsinfo(document): + " Merge vcs Info inset to buffer Info inset. " + + args = ["revision", "tree-revision", "author", "time", "date" ] + i = 0 + while True: + 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: + document.warning("Malformed LyX document: Could not find end of Info inset.") + i = i + 1 + continue + tp = find_token(document.body, 'type', i, j) + tpv = get_quoted_value(document.body, "type", tp) + if tpv != "vcs": + i = i + 1 + continue + arg = find_token(document.body, 'arg', i, j) + argv = get_quoted_value(document.body, "arg", arg) + if argv not in args: + document.warning("Malformed Info inset. Invalid vcs arg.") + i = i + 1 + continue + document.body[tp] = "type \"buffer\"" + document.body[arg] = "arg \"vcs-" + argv + "\"" + i = i + 1 + + ## # Conversion hub # @@ -554,10 +620,12 @@ convert = [ [553, []], [554, []], [555, []], - [556, []] + [556, []], + [557, [convert_vcsinfo]] ] revert = [ + [556, [revert_vcsinfo]], [555, [revert_bibencoding]], [554, [revert_vcolumns]], [553, [revert_stretchcolumn]], diff --git a/src/frontends/qt4/GuiInfo.cpp b/src/frontends/qt4/GuiInfo.cpp index 2ba2ec645b..cafcca8634 100644 --- a/src/frontends/qt4/GuiInfo.cpp +++ b/src/frontends/qt4/GuiInfo.cpp @@ -40,16 +40,18 @@ namespace frontend { ///////////////////////////////////////////////////////////////// char const * info_types[] = -{ "unknown", "shortcut", "shortcuts", "lyxrc", "package", "textclass", "menu", "icon", "buffer", "lyxinfo", "" }; +{ "unknown", "shortcut", "shortcuts", "lyxrc", "package", "textclass", "menu", "icon", "buffer", "vcs", "lyxinfo", "" }; char const * info_types_gui[] = { N_("Unknown"), N_("Last Assigned Keyboard Shortcut"), N_("All Keyboard Shortcuts"), N_("LyX Preferences Entry"), N_("LaTeX Package Availability"), N_("LaTeX Class Availability"), - N_("LyX Menu Location"), N_("LyX Toolbar Icon"), N_("Document Information"), N_("LyX Application Information"), ""}; + N_("LyX Menu Location"), N_("LyX Toolbar Icon"), N_("Document Information"), + N_("Version Control Information"), N_("LyX Application Information"), ""}; char const * info_name_gui[] = { N_("Not Applicable"), N_("LyX Function"), N_("LyX Function"), N_("Preferences Key"), N_("Package Name"), - N_("Class Name"), N_("LyX Function"), N_("LyX Function"), N_("Information Type"), N_("Information Type"), ""}; + N_("Class Name"), N_("LyX Function"), N_("LyX Function"), N_("Information"), + N_("Information"), N_("Information"), ""}; char const * info_tooltip[] = { N_("Please select a valid type above"), @@ -68,6 +70,7 @@ char const * info_tooltip[] = N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. " "The output is the toolbar icon for this function (using the active icon theme)."), N_("Enter either 'name' (outputs the filename of the current document), 'path' (outputs the file path), or 'class' (outputs the text class)."), + N_("Enter either 'revision', 'tree-revision', 'author', 'time' or 'date'. If available, the respective version control information is output."), N_("Currently supported information type: 'version' (outputs the current LyX version)."), ""}; diff --git a/src/insets/InsetInfo.cpp b/src/insets/InsetInfo.cpp index 3da1d00470..403ba10dec 100644 --- a/src/insets/InsetInfo.cpp +++ b/src/insets/InsetInfo.cpp @@ -75,6 +75,7 @@ NameTranslator const initTranslator() translator.addPair(InsetInfo::ICON_INFO, "icon"); translator.addPair(InsetInfo::BUFFER_INFO, "buffer"); translator.addPair(InsetInfo::LYX_INFO, "lyxinfo"); + translator.addPair(InsetInfo::VCS_INFO, "vcs"); return translator; } @@ -166,15 +167,17 @@ docstring InsetInfo::toolTip(BufferView const &, int, int) const result = _("The path were this file is saved"); else if (name_ == "class") result = _("The class this document uses"); - else if (name_ == "vcs-revision") + break; + case VCS_INFO: + if (name_ == "revision") result = _("Version control revision"); - else if (name_ == "vcs-tree-revision") + else if (name_ == "tree-revision") result = _("Version control tree revision"); - else if (name_ == "vcs-author") + else if (name_ == "author") result = _("Version control author"); - else if (name_ == "vcs-date") + else if (name_ == "date") result = _("Version control date"); - else if (name_ == "vcs-time") + else if (name_ == "time") result = _("Version control time"); break; case LYX_INFO: @@ -254,10 +257,11 @@ bool InsetInfo::validateModifyArgument(docstring const & arg) const return true; case BUFFER_INFO: - if (name == "name" || name == "path" || name == "class") - return true; - if (name == "vcs-revision" || name == "vcs-tree-revision" || - name == "vcs-author" || name == "vcs-date" || name == "vcs-time") + return (name == "name" || name == "path" || name == "class"); + + case VCS_INFO: + if (name == "revision" || name == "tree-revision" + || name == "author" || name == "date" || name == "time") return buffer().lyxvc().inUse(); return false; @@ -579,23 +583,15 @@ void InsetInfo::updateBuffer(ParIterator const & it, UpdateType utype) { } case BUFFER_INFO: { // this could all change, so we will recalculate each time - if (name_ == "name") { + if (name_ == "name") setText(from_utf8(buffer().fileName().onlyFileName()), lang); - break; - } - if (name_ == "path") { + else if (name_ == "path") setText(from_utf8(os::latex_path(buffer().filePath())), lang); - break; - } - if (name_ == "class") { + else if (name_ == "class") setText(from_utf8(bp.documentClass().name()), lang); - break; - } - - //////////////////////////////////////////////////////////////// - // everything that follows is for version control. - // nothing that isn't version control should go below this line. - + break; + } + case VCS_INFO: { // this information could change, in principle, so we will // recalculate each time through if (!buffer().lyxvc().inUse()) { @@ -604,15 +600,15 @@ void InsetInfo::updateBuffer(ParIterator const & it, UpdateType utype) { break; } LyXVC::RevisionInfo itype = LyXVC::Unknown; - if (name_ == "vcs-revision") + if (name_ == "revision") itype = LyXVC::File; - else if (name_ == "vcs-tree-revision") + else if (name_ == "tree-revision") itype = LyXVC::Tree; - else if (name_ == "vcs-author") + else if (name_ == "author") itype = LyXVC::Author; - else if (name_ == "vcs-time") + else if (name_ == "time") itype = LyXVC::Time; - else if (name_ == "vcs-date") + else if (name_ == "date") itype = LyXVC::Date; string binfo = buffer().lyxvc().revisionInfo(itype); if (binfo.empty()) { diff --git a/src/insets/InsetInfo.h b/src/insets/InsetInfo.h index c553062952..4a4bf89d4d 100644 --- a/src/insets/InsetInfo.h +++ b/src/insets/InsetInfo.h @@ -30,7 +30,7 @@ uses it to display currently used shortcuts. This inset has two arguments: the type and argument of the information. The screen and latex output is the content of the information. An InsetInfo can have type "shortcuts", "shortcut", "lyxrc", "package", "textclass", "menu", -or "buffer". Arguments and outputs vary by type. +"buffer" or "vcs". Arguments and outputs vary by type. shortcuts: argument of this type of InsetInfo is the name of the LFUN such as "math-insert \alpha". The syntax is the same as what is used in the bind @@ -63,7 +63,10 @@ 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. + about the version of LyX currently in use. + +vcs: argument can be one of "revision", "tree-revision", "author", "time", "date". + This insets outputs revision control information, if available. 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 @@ -89,7 +92,8 @@ 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 + LYX_INFO, // LyX version information + VCS_INFO, // Version control information }; /// diff --git a/src/version.h b/src/version.h index e8ca153473..ce168b3d17 100644 --- a/src/version.h +++ b/src/version.h @@ -32,8 +32,8 @@ extern char const * const lyx_version_info; // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -#define LYX_FORMAT_LYX 556 // spitz: bib encoding -#define LYX_FORMAT_TEX2LYX 556 +#define LYX_FORMAT_LYX 557 // spitz: separate vcs info inset +#define LYX_FORMAT_TEX2LYX 557 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #ifndef _MSC_VER