Further extend Info insets:

* Add time type (time, modtime, fixtime)
* Add "name-noext" buffer type (file name w/o extension)
This commit is contained in:
Juergen Spitzmueller 2018-08-07 12:14:45 +02:00
parent 74158ec6a7
commit 7efdf98fc8
9 changed files with 452 additions and 42 deletions

View File

@ -7,6 +7,10 @@ changes happened in particular if possible. A good example would be
-----------------------
2018-08-07 Jürgen Spitzmüller <spitz@lyx.org>
* format incremented to 560: Time-related info insets: time, modtime, fixtime;
new buffer info inset type: name-noext.
2018-08-04 Jürgen Spitzmüller <spitz@lyx.org>
* format incremented to 559: Date-related info insets: date, moddate, fixdate.

View File

@ -22,7 +22,7 @@ import re, string
import unicodedata
import sys, os
from datetime import date
from datetime import (datetime, date, time)
# Uncomment only what you need to import, please.
@ -846,6 +846,210 @@ def revert_dateinfo(document):
i = i + 1
def revert_timeinfo(document):
" Revert time info insets to static text. "
# FIXME This currently only considers the main language and uses the system locale
# Ideally, it should honor context languages and switch the locale accordingly.
# Also, the time object is "naive", i.e., it does not know of timezones (%Z will
# be empty).
# The time formats for each language using strftime syntax:
# long, short
timeformats = {
"afrikaans" : ["%H:%M:%S %Z", "%H:%M"],
"albanian" : ["%I:%M:%S %p, %Z", "%I:%M %p"],
"american" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"amharic" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"ancientgreek" : ["%H:%M:%S %Z", "%H:%M:%S"],
"arabic_arabi" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"arabic_arabtex" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"armenian" : ["%H:%M:%S %Z", "%H:%M"],
"asturian" : ["%H:%M:%S %Z", "%H:%M"],
"australian" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"austrian" : ["%H:%M:%S %Z", "%H:%M"],
"bahasa" : ["%H.%M.%S %Z", "%H.%M"],
"bahasam" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"basque" : ["%H:%M:%S (%Z)", "%H:%M"],
"belarusian" : ["%H:%M:%S, %Z", "%H:%M"],
"bosnian" : ["%H:%M:%S %Z", "%H:%M"],
"brazilian" : ["%H:%M:%S %Z", "%H:%M"],
"breton" : ["%H:%M:%S %Z", "%H:%M"],
"british" : ["%H:%M:%S %Z", "%H:%M"],
"bulgarian" : ["%H:%M:%S %Z", "%H:%M"],
"canadian" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"canadien" : ["%H:%M:%S %Z", "%H h %M"],
"catalan" : ["%H:%M:%S %Z", "%H:%M"],
"chinese-simplified" : ["%Z %p%I:%M:%S", "%p%I:%M"],
"chinese-traditional" : ["%p%I:%M:%S [%Z]", "%p%I:%M"],
"coptic" : ["%H:%M:%S %Z", "%H:%M:%S"],
"croatian" : ["%H:%M:%S (%Z)", "%H:%M"],
"czech" : ["%H:%M:%S %Z", "%H:%M"],
"danish" : ["%H.%M.%S %Z", "%H.%M"],
"divehi" : ["%H:%M:%S %Z", "%H:%M"],
"dutch" : ["%H:%M:%S %Z", "%H:%M"],
"english" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"esperanto" : ["%H:%M:%S %Z", "%H:%M:%S"],
"estonian" : ["%H:%M:%S %Z", "%H:%M"],
"farsi" : ["%H:%M:%S (%Z)", "%H:%M"],
"finnish" : ["%H.%M.%S %Z", "%H.%M"],
"french" : ["%H:%M:%S %Z", "%H:%M"],
"friulan" : ["%H:%M:%S %Z", "%H:%M"],
"galician" : ["%H:%M:%S %Z", "%H:%M"],
"georgian" : ["%H:%M:%S %Z", "%H:%M"],
"german" : ["%H:%M:%S %Z", "%H:%M"],
"german-ch" : ["%H:%M:%S %Z", "%H:%M"],
"german-ch-old" : ["%H:%M:%S %Z", "%H:%M"],
"greek" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"hebrew" : ["%H:%M:%S %Z", "%H:%M"],
"hindi" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"icelandic" : ["%H:%M:%S %Z", "%H:%M"],
"interlingua" : ["%H:%M:%S %Z", "%H:%M"],
"irish" : ["%H:%M:%S %Z", "%H:%M"],
"italian" : ["%H:%M:%S %Z", "%H:%M"],
"japanese" : ["%H時%M分%S秒 %Z", "%H:%M"],
"japanese-cjk" : ["%H時%M分%S秒 %Z", "%H:%M"],
"kannada" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"kazakh" : ["%H:%M:%S %Z", "%H:%M"],
"khmer" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"korean" : ["%p %I시%M분 %S초 %Z", "%p %I:%M"],
"kurmanji" : ["%H:%M:%S %Z", "%H:%M:%S"],
"lao" : ["%H ໂມງ%M ນາທີ %S ວິນາທີ %Z", "%H:%M"],
"latin" : ["%H:%M:%S %Z", "%H:%M:%S"],
"latvian" : ["%H:%M:%S %Z", "%H:%M"],
"lithuanian" : ["%H:%M:%S %Z", "%H:%M"],
"lowersorbian" : ["%H:%M:%S %Z", "%H:%M"],
"macedonian" : ["%H:%M:%S %Z", "%H:%M"],
"magyar" : ["%H:%M:%S %Z", "%H:%M"],
"marathi" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"mongolian" : ["%H:%M:%S %Z", "%H:%M"],
"naustrian" : ["%H:%M:%S %Z", "%H:%M"],
"newzealand" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"ngerman" : ["%H:%M:%S %Z", "%H:%M"],
"norsk" : ["%H:%M:%S %Z", "%H:%M"],
"nynorsk" : ["kl. %H:%M:%S %Z", "%H:%M"],
"occitan" : ["%H:%M:%S %Z", "%H:%M"],
"piedmontese" : ["%H:%M:%S %Z", "%H:%M:%S"],
"polish" : ["%H:%M:%S %Z", "%H:%M"],
"polutonikogreek" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"portuguese" : ["%H:%M:%S %Z", "%H:%M"],
"romanian" : ["%H:%M:%S %Z", "%H:%M"],
"romansh" : ["%H:%M:%S %Z", "%H:%M"],
"russian" : ["%H:%M:%S %Z", "%H:%M"],
"samin" : ["%H:%M:%S %Z", "%H:%M"],
"sanskrit" : ["%H:%M:%S %Z", "%H:%M"],
"scottish" : ["%H:%M:%S %Z", "%H:%M"],
"serbian" : ["%H:%M:%S %Z", "%H:%M"],
"serbian-latin" : ["%H:%M:%S %Z", "%H:%M"],
"slovak" : ["%H:%M:%S %Z", "%H:%M"],
"slovene" : ["%H:%M:%S %Z", "%H:%M"],
"spanish" : ["%H:%M:%S (%Z)", "%H:%M"],
"spanish-mexico" : ["%H:%M:%S %Z", "%H:%M"],
"swedish" : ["kl. %H:%M:%S %Z", "%H:%M"],
"syriac" : ["%H:%M:%S %Z", "%H:%M"],
"tamil" : ["%p %I:%M:%S %Z", "%p %I:%M"],
"telugu" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"thai" : ["%H นาฬิกา %M นาที %S วินาที %Z", "%H:%M"],
"tibetan" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"turkish" : ["%H:%M:%S %Z", "%H:%M"],
"turkmen" : ["%H:%M:%S %Z", "%H:%M"],
"ukrainian" : ["%H:%M:%S %Z", "%H:%M"],
"uppersorbian" : ["%H:%M:%S %Z", "%H:%M hodź."],
"urdu" : ["%I:%M:%S %p %Z", "%I:%M %p"],
"vietnamese" : ["%H:%M:%S %Z", "%H:%M"],
"welsh" : ["%H:%M:%S %Z", "%H:%M"]
}
types = ["time", "fixtime", "modtime" ]
i = 0
i = find_token(document.header, "\\language", 0)
if i == -1:
# this should not happen
document.warning("Malformed LyX document! No \\language header found!")
return
lang = get_value(document.header, "\\language", i)
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 not in types:
i = i + 1
continue
arg = find_token(document.body, 'arg', i, j)
argv = get_quoted_value(document.body, "arg", arg)
isotime = ""
dtme = datetime.now()
tme = dtme.time()
if tpv == "fixtime":
timecomps = argv.split('@')
if len(timecomps) > 1:
argv = timecomps[0]
isotime = timecomps[1]
m = re.search('(\d\d):(\d\d):(\d\d)', isotime)
if m:
tme = time(int(m.group(1)), int(m.group(2)), int(m.group(3)))
else:
m = re.search('(\d\d):(\d\d)', isotime)
if m:
tme = time(int(m.group(1)), int(m.group(2)))
# FIXME if we had the path to the original document (not the one in the tmp dir),
# we could use the mtime.
# elif tpv == "moddate":
# dte = date.fromtimestamp(os.path.getmtime(document.dir))
result = ""
if argv == "ISO":
result = tme.isoformat()
elif argv == "long":
result = tme.strftime(timeformats[lang][0])
elif argv == "short":
result = tme.strftime(timeformats[lang][1])
else:
fmt = argv.replace("HH", "%H").replace("H", "%H").replace("hh", "%I").replace("h", "%I")
fmt = fmt.replace("mm", "%M").replace("m", "%M").replace("ss", "%S").replace("s", "%S")
fmt = fmt.replace("zzz", "%f").replace("z", "%f").replace("t", "%Z")
fmt = fmt.replace("AP", "%p").replace("ap", "%p").replace("A", "%p").replace("a", "%p")
fmt = fmt.replace("'", "")
result = dte.strftime(fmt)
document.body[i : j+1] = result
i = i + 1
def revert_namenoextinfo(document):
" Merge buffer Info inset type name-noext to name. "
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 != "name-noext":
i = i + 1
continue
document.body[arg] = "arg \"name\""
i = i + 1
##
# Conversion hub
#
@ -866,10 +1070,12 @@ convert = [
[556, []],
[557, [convert_vcsinfo]],
[558, [removeFrontMatterStyles]],
[559, []]
[559, []],
[560, []]
]
revert = [
[558, [revert_timeinfo, revert_namenoextinfo]],
[558, [revert_dateinfo]],
[557, [addFrontMatterStyles]],
[556, [revert_vcsinfo]],

View File

@ -426,6 +426,12 @@ Menuset
Item "Date (Last Modification)|L" "info-insert moddate"
Item "Date (Fix)|F" "info-insert fixdate"
Separator
Item "Time (Current)|T" "info-insert time"
Item "Time (Last Modification)|M" "info-insert modtime"
Item "Time (Fix)|x" "info-insert fixtime"
Separator
Item "File Name (Excl. Extension)|N" "info-insert buffer name-noext"
Separator
Item "Other...|O" "info-insert"
End

View File

@ -1936,6 +1936,9 @@ void LyXAction::init()
date: current date (formatted and localized)\n
moddate: date of last modification (saving) (formatted and localized)\n
fixdate: a static date (formatted and localized)\n
time: current time (formatted and localized)\n
modtime: time of last modification (saving) (formatted and localized)\n
fixtime: a static time (formatted and localized)\n
shortcut[s]: name of lfun (e.g math-insert \alpha) \n
lyxrc: name of rc_entry (e.g. bind_file) \n
lyxinfo: "version" - used version of LyX \n
@ -1943,7 +1946,7 @@ void LyXAction::init()
textclass: name of textclass (e.g. article) \n
menu: name of lfun used in menu \n
icon: icon of lfun used in toolbar or direct icon name\n
buffer: "name"|"path"|"class"
buffer: "name"|"name-noext"|"path"|"class"
vcs: "tree-revision"|"revision"|"author"|"date"|"time"
* \li Sample: command-sequence info-insert buffer path; info-insert buffer name
* \li Origin: bpeng, 7 Oct 2007

View File

@ -48,6 +48,9 @@ char const * info_types[] =
{ "date",
"moddate",
"fixdate",
"time",
"modtime",
"fixtime",
"buffer",
"vcs",
"package",
@ -67,6 +70,9 @@ char const * info_types_gui[] =
{ N_("Date (current)"),// date
N_("Date (last modified)"),// moddate
N_("Date (fix)"),// fixdate
N_("Time (current)"),// time
N_("Time (last modified)"),// modtime
N_("Time (fix)"),// fixtime
N_("Document Information"),// buffer
N_("Version Control Information"),// vcs
N_("LaTeX Package Availability"),// package
@ -86,6 +92,9 @@ char const * info_name_gui[] =
{ N_("Custom Format"),// date
N_("Custom Format"),// moddate
N_("Custom Format"),// fixdate
N_("Custom Format"),// time
N_("Custom Format"),// modtime
N_("Custom Format"),// fixtime
N_("Not Applicable"),// buffer
N_("Not Applicable"),// vcs
N_("Package Name"),// package
@ -114,27 +123,69 @@ char const * info_tooltip[] =
"* yy: year as two digit number\n"
"* yyyy: year as four digit number"),// date
N_("Enter date format specification, using the following placeholders:\n"
"* d: day as number without a leading zero\n"
"* dd: day as number with a leading zero\n"
"* ddd: abbreviated localized day name\n"
"* dddd: long localized day name\n"
"* M: month as number without a leading zero\n"
"* MM: month as number with a leading zero\n"
"* MMM: abbreviated localized month name\n"
"* MMMM: long localized month name\n"
"* yy: year as two digit number\n"
"* yyyy: year as four digit number"),// moddate
"* d: day as number without a leading zero\n"
"* dd: day as number with a leading zero\n"
"* ddd: abbreviated localized day name\n"
"* dddd: long localized day name\n"
"* M: month as number without a leading zero\n"
"* MM: month as number with a leading zero\n"
"* MMM: abbreviated localized month name\n"
"* MMMM: long localized month name\n"
"* yy: year as two digit number\n"
"* yyyy: year as four digit number"),// moddate
N_("Enter date format specification, using the following placeholders:\n"
"* d: day as number without a leading zero\n"
"* dd: day as number with a leading zero\n"
"* ddd: abbreviated localized day name\n"
"* dddd: long localized day name\n"
"* M: month as number without a leading zero\n"
"* MM: month as number with a leading zero\n"
"* MMM: abbreviated localized month name\n"
"* MMMM: long localized month name\n"
"* yy: year as two digit number\n"
"* yyyy: year as four digit number"),// fixdate
"* d: day as number without a leading zero\n"
"* dd: day as number with a leading zero\n"
"* ddd: abbreviated localized day name\n"
"* dddd: long localized day name\n"
"* M: month as number without a leading zero\n"
"* MM: month as number with a leading zero\n"
"* MMM: abbreviated localized month name\n"
"* MMMM: long localized month name\n"
"* yy: year as two digit number\n"
"* yyyy: year as four digit number"),// fixdate
N_("Enter time format specification, using the following placeholders:\n"
"* h: the hour without a leading zero (01-12 in AM/PM)\n"
"* hh: the hour with a leading zero (1-12 in AM/PM)\n"
"* H: the hour without a leading zero (0-23 in AM/PM)\n"
"* HH: the hour with a leading zero (00-23 in AM/PM)\n"
"* m: the minute without a leading zero\n"
"* mm: the minute with a leading zero\n"
"* s: the second without a leading zero\n"
"* ss: the second with a leading zero\n"
"* z: the milliseconds without leading zeroes\n"
"* zzz: the milliseconds with leading zeroes\n"
"* AP or A: use AM/PM display ('AM'/'PM')\n"
"* ap or a: use am/pm display ('am'/'pm')\n"
"* t: the timezone (e.g. CEST)"),// time
N_("Enter time format specification, using the following placeholders:\n"
"* h: the hour without a leading zero (01-12 in AM/PM)\n"
"* hh: the hour with a leading zero (1-12 in AM/PM)\n"
"* H: the hour without a leading zero (0-23 in AM/PM)\n"
"* HH: the hour with a leading zero (00-23 in AM/PM)\n"
"* m: the minute without a leading zero\n"
"* mm: the minute with a leading zero\n"
"* s: the second without a leading zero\n"
"* ss: the second with a leading zero\n"
"* z: the milliseconds without leading zeroes\n"
"* zzz: the milliseconds with leading zeroes\n"
"* AP or A: use AM/PM display ('AM'/'PM')\n"
"* ap or a: use am/pm display ('am'/'pm')\n"
"* t: the timezone (e.g. CEST)"),// modtime
N_("Enter time format specification, using the following placeholders:\n"
"* h: the hour without a leading zero (01-12 in AM/PM)\n"
"* hh: the hour with a leading zero (1-12 in AM/PM)\n"
"* H: the hour without a leading zero (0-23 in AM/PM)\n"
"* HH: the hour with a leading zero (00-23 in AM/PM)\n"
"* m: the minute without a leading zero\n"
"* mm: the minute with a leading zero\n"
"* s: the second without a leading zero\n"
"* ss: the second with a leading zero\n"
"* z: the milliseconds without leading zeroes\n"
"* zzz: the milliseconds with leading zeroes\n"
"* AP or A: use AM/PM display ('AM'/'PM')\n"
"* ap or a: use am/pm display ('am'/'pm')\n"
"* t: the timezone (e.g. CEST)"),// fixtime
N_("Please select a valid type above"),// buffer
N_("Please select a valid type above"),// vcs
N_("Enter a LaTeX package name such as 'hyperref' (extension is optional). "
@ -178,13 +229,17 @@ void GuiInfo::paramsToDialog(Inset const * inset)
QString const type = toqstr(params_.infoType());
QString name = toqstr(params_.name);
QString fixdate;
if (type == "fixdate") {
if (type == "fixdate" || type == "fixtime") {
fixdate = name.section('@', 1, 1);
name = name.section('@', 0, 0);
if (!fixdate.isEmpty())
fixDateLE->setText(fixdate);
else
fixDateLE->setText(QDate::currentDate().toString(Qt::ISODate));
else {
if (type == "fixdate")
fixDateLE->setText(QDate::currentDate().toString(Qt::ISODate));
else
fixDateLE->setText(QTime::currentTime().toString(Qt::ISODate));
}
}
typeCO->blockSignals(true);
nameLE->blockSignals(true);
@ -223,10 +278,12 @@ docstring GuiInfo::dialogToParams() const
: QString();
if (name == "custom")
name = nameLE->text();
if (type == "fixdate") {
if (type == "fixdate" || type == "fixtime") {
QString fd = fixDateLE->text();
if (fd.isEmpty())
fd = QDate::currentDate().toString(Qt::ISODate);
fd = (type == "fixdate") ?
QDate::currentDate().toString(Qt::ISODate)
: QTime::currentTime().toString(Qt::ISODate);
name += "@" + fd;
}
return qstring_to_ucs4(type + ' ' + name);
@ -281,10 +338,18 @@ bool GuiInfo::checkWidgets(bool readonly) const
nameLE->setEnabled(type_enabled);
nameLE->setToolTip(qt_(info_tooltip[typeCO->currentIndex()]));
bool const fixdate_enabled =
(info_types[typeCO->currentIndex()] == from_ascii("fixdate"));
string const typestr = info_types[typeCO->currentIndex()];
bool const fixdate_enabled = (typestr == "fixdate" || typestr == "fixtime");
fixDateLE->setVisible(fixdate_enabled);
fixDateLA->setVisible(fixdate_enabled);
if (typestr == "fixdate") {
fixDateLE->setToolTip(qt_("Here you can enter a fix date (in ISO format: YYYY-MM-DD)"));
fixDateLA->setText(qt_("&Fix Date:"));
}
else if (typestr == "fixtime") {
fixDateLE->setToolTip(qt_("Here you can enter a fix time (in ISO format: hh:mm:ss)"));
fixDateLA->setText(qt_("&Fix Time:"));
}
if (!InsetParamsWidget::checkWidgets())
return false;

View File

@ -46,7 +46,7 @@
<item>
<widget class="QLabel" name="fixDateLA">
<property name="text">
<string>Fix Date:</string>
<string>&amp;Fix Date:</string>
</property>
<property name="buddy">
<cstring>fixDateLE</cstring>

View File

@ -82,6 +82,9 @@ NameTranslator const initTranslator()
translator.addPair(InsetInfoParams::DATE_INFO, "date");
translator.addPair(InsetInfoParams::MODDATE_INFO, "moddate");
translator.addPair(InsetInfoParams::FIXDATE_INFO, "fixdate");
translator.addPair(InsetInfoParams::TIME_INFO, "time");
translator.addPair(InsetInfoParams::MODTIME_INFO, "modtime");
translator.addPair(InsetInfoParams::FIXTIME_INFO, "fixtime");
return translator;
}
@ -107,12 +110,15 @@ DefaultValueTranslator const initDVTranslator()
translator.addPair(InsetInfoParams::TEXTCLASS_INFO, "article");
translator.addPair(InsetInfoParams::MENU_INFO, "info-insert");
translator.addPair(InsetInfoParams::ICON_INFO, "info-insert");
translator.addPair(InsetInfoParams::BUFFER_INFO, "name");
translator.addPair(InsetInfoParams::BUFFER_INFO, "name-noext");
translator.addPair(InsetInfoParams::LYX_INFO, "version");
translator.addPair(InsetInfoParams::VCS_INFO, "revision");
translator.addPair(InsetInfoParams::DATE_INFO, "loclong");
translator.addPair(InsetInfoParams::MODDATE_INFO, "loclong");
translator.addPair(InsetInfoParams::FIXDATE_INFO, "loclong");
translator.addPair(InsetInfoParams::TIME_INFO, "long");
translator.addPair(InsetInfoParams::MODTIME_INFO, "long");
translator.addPair(InsetInfoParams::FIXTIME_INFO, "long");
return translator;
}
@ -161,6 +167,7 @@ set<string> getTexFileList(string const & filename)
}
} // namespace anon
docstring InsetInfoParams::getDate(string const iname, QDate const date) const
{
QLocale loc;
@ -183,6 +190,22 @@ docstring InsetInfoParams::getDate(string const iname, QDate const date) const
}
docstring InsetInfoParams::getTime(string const iname, QTime const time) const
{
QLocale loc;
if (lang)
loc = QLocale(toqstr(lang->code()));
if (iname == "long")
return qstring_to_ucs4(loc.toString(time, QLocale::LongFormat));
else if (iname == "short")
return qstring_to_ucs4(loc.toString(time, QLocale::ShortFormat));
else if (iname == "ISO")
return qstring_to_ucs4(time.toString(Qt::ISODate));
else
return qstring_to_ucs4(loc.toString(time, toqstr(iname)));
}
vector<pair<string,docstring>> InsetInfoParams::getArguments(Buffer const * buf,
string const & itype) const
{
@ -228,7 +251,8 @@ vector<pair<string,docstring>> InsetInfoParams::getArguments(Buffer const * buf,
}
case BUFFER_INFO:
result.push_back(make_pair("name", _("File name")));
result.push_back(make_pair("name", _("File name (with extension)")));
result.push_back(make_pair("name-noext", _("File name (without extension)")));
result.push_back(make_pair("path", _("File path")));
result.push_back(make_pair("class", _("Used text class")));
break;
@ -252,7 +276,7 @@ vector<pair<string,docstring>> InsetInfoParams::getArguments(Buffer const * buf,
case FIXDATE_INFO:
case DATE_INFO:
case MODDATE_INFO:
case MODDATE_INFO: {
string const dt = split(name, '@');
QDate date;
if (itype == "moddate")
@ -275,6 +299,24 @@ vector<pair<string,docstring>> InsetInfoParams::getArguments(Buffer const * buf,
result.push_back(make_pair("custom", _("Custom")));
break;
}
case FIXTIME_INFO:
case TIME_INFO:
case MODTIME_INFO: {
string const tt = split(name, '@');
QTime time;
if (itype == "modtime")
time = QDateTime::fromTime_t(buf->fileName().lastModified()).time();
else if (itype == "fixtime" && !tt.empty())
time = QTime::fromString(toqstr(tt), Qt::ISODate);
else
time = QTime::currentTime();
result.push_back(make_pair("long",getTime("long", time)));
result.push_back(make_pair("short", getTime("short", time)));
result.push_back(make_pair("ISO", getTime("ISO", time)));
result.push_back(make_pair("custom", _("Custom")));
break;
}
}
return result;
}
@ -355,7 +397,9 @@ docstring InsetInfo::toolTip(BufferView const &, int, int) const
break;
case InsetInfoParams::BUFFER_INFO:
if (params_.name == "name")
result = _("The name of this file");
result = _("The name of this file (incl. extension)");
else if (params_.name == "name-noext")
result = _("The name of this file (without extension)");
else if (params_.name == "path")
result = _("The path where this file is saved");
else if (params_.name == "class")
@ -385,6 +429,15 @@ docstring InsetInfo::toolTip(BufferView const &, int, int) const
case InsetInfoParams::FIXDATE_INFO:
result = _("A static date");
break;
case InsetInfoParams::TIME_INFO:
result = _("The current time");
break;
case InsetInfoParams::MODTIME_INFO:
result = _("The time of last save");
break;
case InsetInfoParams::FIXTIME_INFO:
result = _("A static time");
break;
}
return result;
@ -458,7 +511,8 @@ bool InsetInfo::validateModifyArgument(docstring const & arg) const
return true;
case InsetInfoParams::BUFFER_INFO:
return (name == "name" || name == "path" || name == "class");
return (name == "name" || name == "name-noext"
|| name == "path" || name == "class");
case InsetInfoParams::VCS_INFO:
if (name == "revision" || name == "tree-revision"
@ -488,6 +542,25 @@ bool InsetInfo::validateModifyArgument(docstring const & arg) const
return !date.toString(toqstr(name)).isEmpty();
}
}
case InsetInfoParams::FIXTIME_INFO: {
string time;
string piece;
time = split(name, piece, '@');
if (!time.empty() && !QTime::fromString(toqstr(time), Qt::ISODate).isValid())
return false;
if (!piece.empty())
name = piece;
}
// fall through
case InsetInfoParams::TIME_INFO:
case InsetInfoParams::MODTIME_INFO: {
if (name == "long" || name == "short" || name == "ISO")
return true;
else {
QTime time = QTime::currentTime();
return !time.toString(toqstr(name)).isEmpty();
}
}
}
return false;
@ -520,7 +593,8 @@ bool InsetInfo::getStatus(Cursor & cur, FuncRequest const & cmd,
string name = trim(split(to_utf8(cmd.argument()), typestr, ' '));
InsetInfoParams::info_type type = nameTranslator().find(typestr);
string origname = params_.name;
if (type == InsetInfoParams::FIXDATE_INFO)
if (type == InsetInfoParams::FIXDATE_INFO
|| type == InsetInfoParams::FIXTIME_INFO)
split(params_.name, origname, '@');
flag.setOnOff(type == params_.type && name == origname);
return true;
@ -591,6 +665,18 @@ void InsetInfo::setInfo(string const & name)
params_.name += "@" + saved_date_specifier;
}
}
else if (params_.type == InsetInfoParams::FIXTIME_INFO) {
string const time_specifier = split(params_.name, '@');
// If an explicit new fix time is specified, use that
// Otherwise, use the old one or, if there is none,
// the current time
if (time_specifier.empty()) {
if (saved_date_specifier.empty())
params_.name += "@" + fromqstr(QTime::currentTime().toString(Qt::ISODate));
else
params_.name += "@" + saved_date_specifier;
}
}
}
@ -832,6 +918,8 @@ void InsetInfo::updateBuffer(ParIterator const & it, UpdateType utype) {
// this could all change, so we will recalculate each time
if (params_.name == "name")
setText(from_utf8(buffer().fileName().onlyFileName()), params_.lang);
else if (params_.name == "name-noext")
setText(from_utf8(buffer().fileName().onlyFileNameWithoutExt()), params_.lang);
else if (params_.name == "path")
setText(from_utf8(os::latex_path(buffer().filePath())), params_.lang);
else if (params_.name == "class")
@ -888,8 +976,27 @@ void InsetInfo::updateBuffer(ParIterator const & it, UpdateType utype) {
else
date = QDate::currentDate();
setText(params_.getDate(date_format, date), params_.lang);
break;
}
case InsetInfoParams::TIME_INFO:
case InsetInfoParams::MODTIME_INFO:
case InsetInfoParams::FIXTIME_INFO: {
string time_format = params_.name;
string const time_specifier = (params_.type == InsetInfoParams::FIXTIME_INFO
&& contains(params_.name, '@'))
? split(params_.name, time_format, '@') : string();
QTime time;
if (params_.type == InsetInfoParams::MODTIME_INFO)
time = QDateTime::fromTime_t(buffer().fileName().lastModified()).time();
else if (params_.type == InsetInfoParams::FIXTIME_INFO && !time_specifier.empty())
time = QTime::fromString(toqstr(time_specifier), Qt::ISODate);
else
time = QTime::currentTime();
setText(params_.getTime(time_format, time), params_.lang);
break;
}
}
// Just to do something with that string
LYXERR(Debug::INFO, "info inset text: " << gui);
InsetCollapsible::updateBuffer(it, utype);

View File

@ -50,6 +50,20 @@ fixdate: Same as date. A fixed date (in ISO format) is prepended to the argument
delimited by '@'.
The output is a localized formatted fix date.
time: argument of this type of InsetInfo is either a fixed time type of
"long" (long localized time, as provided by QLocale),
"short" (short localized time, as provided by QLocale),
"ISO" (ISO-conforming time)
or a custom date using the QTime syntax.
The output is a localized formatted (current) time.
modtime: Same as time.
The output is a localized formatted time of last file modification (saving).
fixtime: Same as time. A fixed time (in ISO format) is prepended to the argument,
delimited by '@'.
The output is a localized formatted fix time.
shortcuts: argument is the name of the LFUN such as "math-insert \alpha".
The syntax is the same as what is used in the bind and ui files.
The output of this inset is all shortcuts for this LFUN separated by comma.
@ -76,8 +90,8 @@ icon: argument is the name of the LFUN such as "paste". The syntax is the same
the toolbar for this LFUN. Alternatively, argument can be the icon path
without extension specified with respect to the images directory.
buffer: argument can be one of "name", "path", "class". This inset output the
filename, path, and textclass of this buffer.
buffer: argument can be one of "name", "name-noext", "path", "class". This inset output the
filename (with extension), filename (without extension), path, and textclass of this buffer.
lyxinfo: argument must (presently) be "version". This inset outputs information
about the version of LyX currently in use.
@ -100,9 +114,12 @@ the command buffer (view->Toolbar->Command Buffer).
class InsetInfoParams {
public:
enum info_type {
DATE_INFO, // Current Date
DATE_INFO, // Current date
MODDATE_INFO, // Date of last modification
FIXDATE_INFO, // Fix date
TIME_INFO, // Current time
MODTIME_INFO, // Time of last modification
FIXTIME_INFO, // Fix time
BUFFER_INFO, // Buffer related information
VCS_INFO, // Version control information
PACKAGE_INFO, // Availability of package
@ -118,6 +135,8 @@ public:
///
docstring getDate(std::string const, QDate const date = QDate::currentDate()) const;
///
docstring getTime(std::string const, QTime const time = QTime::currentTime()) const;
///
std::vector<std::pair<std::string,docstring>> getArguments(Buffer const * buf,
std::string const &) const;
///

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
// independent branches. Instead add your own.
#define LYX_FORMAT_LYX 559 // spitz: date info insets
#define LYX_FORMAT_TEX2LYX 559
#define LYX_FORMAT_LYX 560 // spitz: time info insets
#define LYX_FORMAT_TEX2LYX 560
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#ifndef _MSC_VER