Split vcs Info inset from buffer Info inset

This should go separately in the GUI, and thus in the inset.
This commit is contained in:
Juergen Spitzmueller 2018-07-29 19:41:34 +02:00
parent d0d4fc3578
commit 358436ea1e
6 changed files with 111 additions and 37 deletions

View File

@ -7,6 +7,9 @@ changes happened in particular if possible. A good example would be
----------------------- -----------------------
2018-07-29 Jürgen Spitzmüller <spitz@lyx.org>
* format incremented to 557: Separate vcs Info inset from buffer Info inset.
2018-07-07 Jürgen Spitzmüller <spitz@lyx.org> 2018-07-07 Jürgen Spitzmüller <spitz@lyx.org>
* format incremented to 556: Support for bib file encoding. * format incremented to 556: Support for bib file encoding.
- New param "encoding" for CommandInset bibtex - New param "encoding" for CommandInset bibtex

View File

@ -537,6 +537,72 @@ def revert_bibencoding(document):
i = j + 1 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 # Conversion hub
# #
@ -554,10 +620,12 @@ convert = [
[553, []], [553, []],
[554, []], [554, []],
[555, []], [555, []],
[556, []] [556, []],
[557, [convert_vcsinfo]]
] ]
revert = [ revert = [
[556, [revert_vcsinfo]],
[555, [revert_bibencoding]], [555, [revert_bibencoding]],
[554, [revert_vcolumns]], [554, [revert_vcolumns]],
[553, [revert_stretchcolumn]], [553, [revert_stretchcolumn]],

View File

@ -40,16 +40,18 @@ namespace frontend {
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
char const * info_types[] = 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[] = char const * info_types_gui[] =
{ N_("Unknown"), N_("Last Assigned Keyboard Shortcut"), N_("All Keyboard Shortcuts"), { 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 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[] = char const * info_name_gui[] =
{ N_("Not Applicable"), N_("LyX Function"), N_("LyX Function"), N_("Preferences Key"), N_("Package Name"), { 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[] = char const * info_tooltip[] =
{ N_("Please select a valid type above"), { 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. " 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)."), "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 '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)."), N_("Currently supported information type: 'version' (outputs the current LyX version)."),
""}; ""};

View File

@ -75,6 +75,7 @@ NameTranslator const initTranslator()
translator.addPair(InsetInfo::ICON_INFO, "icon"); translator.addPair(InsetInfo::ICON_INFO, "icon");
translator.addPair(InsetInfo::BUFFER_INFO, "buffer"); translator.addPair(InsetInfo::BUFFER_INFO, "buffer");
translator.addPair(InsetInfo::LYX_INFO, "lyxinfo"); translator.addPair(InsetInfo::LYX_INFO, "lyxinfo");
translator.addPair(InsetInfo::VCS_INFO, "vcs");
return translator; return translator;
} }
@ -166,15 +167,17 @@ docstring InsetInfo::toolTip(BufferView const &, int, int) const
result = _("The path were this file is saved"); result = _("The path were this file is saved");
else if (name_ == "class") else if (name_ == "class")
result = _("The class this document uses"); result = _("The class this document uses");
else if (name_ == "vcs-revision") break;
case VCS_INFO:
if (name_ == "revision")
result = _("Version control revision"); result = _("Version control revision");
else if (name_ == "vcs-tree-revision") else if (name_ == "tree-revision")
result = _("Version control tree revision"); result = _("Version control tree revision");
else if (name_ == "vcs-author") else if (name_ == "author")
result = _("Version control author"); result = _("Version control author");
else if (name_ == "vcs-date") else if (name_ == "date")
result = _("Version control date"); result = _("Version control date");
else if (name_ == "vcs-time") else if (name_ == "time")
result = _("Version control time"); result = _("Version control time");
break; break;
case LYX_INFO: case LYX_INFO:
@ -254,10 +257,11 @@ bool InsetInfo::validateModifyArgument(docstring const & arg) const
return true; return true;
case BUFFER_INFO: case BUFFER_INFO:
if (name == "name" || name == "path" || name == "class") return (name == "name" || name == "path" || name == "class");
return true;
if (name == "vcs-revision" || name == "vcs-tree-revision" || case VCS_INFO:
name == "vcs-author" || name == "vcs-date" || name == "vcs-time") if (name == "revision" || name == "tree-revision"
|| name == "author" || name == "date" || name == "time")
return buffer().lyxvc().inUse(); return buffer().lyxvc().inUse();
return false; return false;
@ -579,23 +583,15 @@ void InsetInfo::updateBuffer(ParIterator const & it, UpdateType utype) {
} }
case BUFFER_INFO: { case BUFFER_INFO: {
// this could all change, so we will recalculate each time // this could all change, so we will recalculate each time
if (name_ == "name") { if (name_ == "name")
setText(from_utf8(buffer().fileName().onlyFileName()), lang); setText(from_utf8(buffer().fileName().onlyFileName()), lang);
break; else if (name_ == "path")
}
if (name_ == "path") {
setText(from_utf8(os::latex_path(buffer().filePath())), lang); setText(from_utf8(os::latex_path(buffer().filePath())), lang);
break; else if (name_ == "class")
}
if (name_ == "class") {
setText(from_utf8(bp.documentClass().name()), lang); setText(from_utf8(bp.documentClass().name()), lang);
break; break;
} }
case VCS_INFO: {
////////////////////////////////////////////////////////////////
// everything that follows is for version control.
// nothing that isn't version control should go below this line.
// this information could change, in principle, so we will // this information could change, in principle, so we will
// recalculate each time through // recalculate each time through
if (!buffer().lyxvc().inUse()) { if (!buffer().lyxvc().inUse()) {
@ -604,15 +600,15 @@ void InsetInfo::updateBuffer(ParIterator const & it, UpdateType utype) {
break; break;
} }
LyXVC::RevisionInfo itype = LyXVC::Unknown; LyXVC::RevisionInfo itype = LyXVC::Unknown;
if (name_ == "vcs-revision") if (name_ == "revision")
itype = LyXVC::File; itype = LyXVC::File;
else if (name_ == "vcs-tree-revision") else if (name_ == "tree-revision")
itype = LyXVC::Tree; itype = LyXVC::Tree;
else if (name_ == "vcs-author") else if (name_ == "author")
itype = LyXVC::Author; itype = LyXVC::Author;
else if (name_ == "vcs-time") else if (name_ == "time")
itype = LyXVC::Time; itype = LyXVC::Time;
else if (name_ == "vcs-date") else if (name_ == "date")
itype = LyXVC::Date; itype = LyXVC::Date;
string binfo = buffer().lyxvc().revisionInfo(itype); string binfo = buffer().lyxvc().revisionInfo(itype);
if (binfo.empty()) { if (binfo.empty()) {

View File

@ -30,7 +30,7 @@ uses it to display currently used shortcuts.
This inset has two arguments: the type and argument of the information. The 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 screen and latex output is the content of the information. An InsetInfo can
have type "shortcuts", "shortcut", "lyxrc", "package", "textclass", "menu", 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 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 "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. filename, path, and textclass of this buffer.
lyxinfo: argument must (presently) be "version". This inset outputs information 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 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 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 MENU_INFO, // Which menu item is used for certain function
ICON_INFO, // which toolbar icon is used for certain function ICON_INFO, // which toolbar icon is used for certain function
BUFFER_INFO, // Buffer related information BUFFER_INFO, // Buffer related information
LYX_INFO // LyX version information LYX_INFO, // LyX version information
VCS_INFO, // Version control information
}; };
/// ///

View File

@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
// Do not remove the comment below, so we get merge conflict in // Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own. // independent branches. Instead add your own.
#define LYX_FORMAT_LYX 556 // spitz: bib encoding #define LYX_FORMAT_LYX 557 // spitz: separate vcs info inset
#define LYX_FORMAT_TEX2LYX 556 #define LYX_FORMAT_TEX2LYX 557
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#ifndef _MSC_VER #ifndef _MSC_VER