3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Abdelrazak Younes
7 * \author Jürgen Spitzmüller
9 * Full author contact details are available in file CREDITS.
16 #include "qt_helpers.h"
19 #include "buffer_funcs.h"
20 #include "BufferParams.h"
21 #include "BufferView.h"
25 #include "GuiApplication.h"
28 #include "insets/InsetInfo.h"
30 #include "support/debug.h"
31 #include "support/gettext.h"
32 #include "support/lstrings.h"
36 using namespace lyx::support;
41 /////////////////////////////////////////////////////////////////
45 /////////////////////////////////////////////////////////////////
47 char const * info_types[] =
68 // GUI names (in combo)
69 char const * info_types_gui[] =
70 { N_("Date (current)"),// date
71 N_("Date (last modified)"),// moddate
72 N_("Date (fix)"),// fixdate
73 N_("Time (current)"),// time
74 N_("Time (last modified)"),// modtime
75 N_("Time (fix)"),// fixtime
76 N_("Document Information"),// buffer
77 N_("Version Control Information"),// vcs
78 N_("LaTeX Package Availability"),// package
79 N_("LaTeX Class Availability"),// textclass
80 N_("Last Assigned Keyboard Shortcut"),// shortcut
81 N_("All Keyboard Shortcuts"),// shortcuts
82 N_("LyX Menu Location"),// menu
83 N_("Localized GUI String"),// l7n
84 N_("LyX Toolbar Icon"),// icon
85 N_("LyX Preferences Entry"),// lyxrc
86 N_("LyX Application Information"),// lyxinfo
91 char const * info_name_gui[] =
92 { N_("Custom Format"),// date
93 N_("Custom Format"),// moddate
94 N_("Custom Format"),// fixdate
95 N_("Custom Format"),// time
96 N_("Custom Format"),// modtime
97 N_("Custom Format"),// fixtime
98 N_("Not Applicable"),// buffer
99 N_("Not Applicable"),// vcs
100 N_("Package Name"),// package
101 N_("Class Name"),// textclass
102 N_("LyX Function"),// shortcut
103 N_("LyX Function"),// shortcuts
104 N_("LyX Function"),// menu
105 N_("English String"),// l7n
106 N_("LyX Function"),// icon
107 N_("Preferences Key"),// lyxrc
108 N_("Not Applicable"),// lyxinfo
109 N_("Not Applicable"),// unknown
114 char const * info_tooltip[] =
115 { N_("Enter date format specification, using the following placeholders:\n"
116 "* d: day as number without a leading zero\n"
117 "* dd: day as number with a leading zero\n"
118 "* ddd: abbreviated localized day name\n"
119 "* dddd: long localized day name\n"
120 "* M: month as number without a leading zero\n"
121 "* MM: month as number with a leading zero\n"
122 "* MMM: abbreviated localized month name\n"
123 "* MMMM: long localized month name\n"
124 "* yy: year as two digit number\n"
125 "* yyyy: year as four digit number"),// date
126 N_("Enter date format specification, using the following placeholders:\n"
127 "* d: day as number without a leading zero\n"
128 "* dd: day as number with a leading zero\n"
129 "* ddd: abbreviated localized day name\n"
130 "* dddd: long localized day name\n"
131 "* M: month as number without a leading zero\n"
132 "* MM: month as number with a leading zero\n"
133 "* MMM: abbreviated localized month name\n"
134 "* MMMM: long localized month name\n"
135 "* yy: year as two digit number\n"
136 "* yyyy: year as four digit number"),// moddate
137 N_("Enter date format specification, using the following placeholders:\n"
138 "* d: day as number without a leading zero\n"
139 "* dd: day as number with a leading zero\n"
140 "* ddd: abbreviated localized day name\n"
141 "* dddd: long localized day name\n"
142 "* M: month as number without a leading zero\n"
143 "* MM: month as number with a leading zero\n"
144 "* MMM: abbreviated localized month name\n"
145 "* MMMM: long localized month name\n"
146 "* yy: year as two digit number\n"
147 "* yyyy: year as four digit number"),// fixdate
148 N_("Enter time format specification, using the following placeholders:\n"
149 "* h: the hour without a leading zero (1-12 in AM/PM)\n"
150 "* hh: the hour with a leading zero (01-12 in AM/PM)\n"
151 "* H: the hour without a leading zero (0-23 in AM/PM)\n"
152 "* HH: the hour with a leading zero (00-23 in AM/PM)\n"
153 "* m: the minute without a leading zero\n"
154 "* mm: the minute with a leading zero\n"
155 "* s: the second without a leading zero\n"
156 "* ss: the second with a leading zero\n"
157 "* z: the milliseconds without leading zeroes\n"
158 "* zzz: the milliseconds with leading zeroes\n"
159 "* AP or A: use AM/PM display ('AM'/'PM')\n"
160 "* ap or a: use am/pm display ('am'/'pm')\n"
161 "* t: the timezone (e.g. CEST)"),// time
162 N_("Enter time format specification, using the following placeholders:\n"
163 "* h: the hour without a leading zero (1-12 in AM/PM)\n"
164 "* hh: the hour with a leading zero (01-12 in AM/PM)\n"
165 "* H: the hour without a leading zero (0-23 in AM/PM)\n"
166 "* HH: the hour with a leading zero (00-23 in AM/PM)\n"
167 "* m: the minute without a leading zero\n"
168 "* mm: the minute with a leading zero\n"
169 "* s: the second without a leading zero\n"
170 "* ss: the second with a leading zero\n"
171 "* z: the milliseconds without leading zeroes\n"
172 "* zzz: the milliseconds with leading zeroes\n"
173 "* AP or A: use AM/PM display ('AM'/'PM')\n"
174 "* ap or a: use am/pm display ('am'/'pm')\n"
175 "* t: the timezone (e.g. CEST)"),// modtime
176 N_("Enter time format specification, using the following placeholders:\n"
177 "* h: the hour without a leading zero (1-12 in AM/PM)\n"
178 "* hh: the hour with a leading zero (01-12 in AM/PM)\n"
179 "* H: the hour without a leading zero (0-23 in AM/PM)\n"
180 "* HH: the hour with a leading zero (00-23 in AM/PM)\n"
181 "* m: the minute without a leading zero\n"
182 "* mm: the minute with a leading zero\n"
183 "* s: the second without a leading zero\n"
184 "* ss: the second with a leading zero\n"
185 "* z: the milliseconds without leading zeroes\n"
186 "* zzz: the milliseconds with leading zeroes\n"
187 "* AP or A: use AM/PM display ('AM'/'PM')\n"
188 "* ap or a: use am/pm display ('am'/'pm')\n"
189 "* t: the timezone (e.g. CEST)"),// fixtime
190 N_("Please select a valid type above"),// buffer
191 N_("Please select a valid type above"),// vcs
192 N_("Enter a LaTeX package name such as 'hyperref' (extension is optional). "
193 "The output will be 'Yes' (package available) or 'No' (package unavailable)."),// package
194 N_("Enter a LaTeX class name such as 'article' (extension is optional). "
195 "The output will be 'Yes' (class available) or 'No' (class unavailable)."),// textclass
196 N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
197 "The output is the most recently assigned keyboard shortcut for this function"),// shortcut
198 N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
199 "The output lists all possible keyboard shortcuts for this function"),// shortcuts
200 N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
201 "The output is the path to the function in the menu (using the current localization)."),// menu
202 N_("Enter a localizable English string from the LyX User Interface, including accelerator markup ('&' or '|') and trailing colons. "
203 "The output is the localized string (using the current localization); trailing colons and accelerator markup are stripped."),// l7n
204 N_("Enter a function name such as 'math-insert \\alpha'. Please refer to Help > LyX Functions for a comprehensive list of functions. "
205 "The output is the toolbar icon for this function (using the active icon theme)."),// icon
206 N_("Enter a LyX preferences key such as 'bind_file'. See the proposed list for available entries. "
207 "The output is the current setting of this preference."),// lyxrc
208 N_("Please select a valid type above"),// lyxinfo
209 N_("Please select a valid type above"),// unknown
213 GuiInfo::GuiInfo(QWidget * parent) : InsetParamsWidget(parent)
217 typeCO->blockSignals(true);
218 for (int n = 0; info_types[n][0]; ++n)
219 typeCO->addItem(qt_(info_types_gui[n]), info_types[n]);
220 typeCO->blockSignals(false);
222 connect(typeCO, SIGNAL(currentIndexChanged(int)), this, SLOT(updateArguments(int)));
223 connect(nameLE, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
224 connect(fixDateLE, SIGNAL(textChanged(QString)), this, SIGNAL(changed()));
225 connect(infoLW, SIGNAL(currentTextChanged(QString)), this, SIGNAL(changed()));
229 void GuiInfo::paramsToDialog(Inset const * inset)
231 InsetInfo const * ii = static_cast<InsetInfo const *>(inset);
232 params_ = ii->params();
233 QString const type = toqstr(params_.infoType());
234 QString name = toqstr(params_.name);
236 if (type == "fixdate" || type == "fixtime") {
237 fixdate = name.section('@', 1, 1);
238 name = name.section('@', 0, 0);
239 if (!fixdate.isEmpty())
240 fixDateLE->setText(fixdate);
242 if (type == "fixdate")
243 fixDateLE->setText(QDate::currentDate().toString(Qt::ISODate));
245 fixDateLE->setText(QTime::currentTime().toString(Qt::ISODate));
248 typeCO->blockSignals(true);
249 nameLE->blockSignals(true);
251 // The "unknown" item is only in the combo if we open
252 // the dialog from an unknown info. The user should not
253 // change a valid info to an unknown one.
254 int i = typeCO->findData("unknown");
255 if (i == -1 && type == "unknown")
256 typeCO->addItem(qt_("Unknown"), toqstr("unknown"));
257 if (i != -1 && type != "unknown")
258 typeCO->removeItem(i);
259 i = typeCO->findData(type);
260 typeCO->setCurrentIndex(i);
264 for (int i = 0 ; i < infoLW->count() ; ++i) {
265 if (infoLW->item(i)->data(Qt::UserRole).toString() == name)
267 else if (infoLW->item(i)->data(Qt::UserRole).toString() == "custom")
271 infoLW->setCurrentRow(argindex);
273 // Without this test, 'math-insert' (name) will replace 'math-insert '
274 // in nameLE and effectively disallow the input of spaces after a LFUN.
275 if (nameLE->text().trimmed() != name)
276 nameLE->setText(name);
277 infoLW->setCurrentRow(customindex);
279 typeCO->blockSignals(false);
280 nameLE->blockSignals(false);
284 docstring GuiInfo::dialogToParams() const
287 typeCO->itemData(typeCO->currentIndex()).toString();
288 QString name = infoLW->currentItem() ?
289 infoLW->currentItem()->data(Qt::UserRole).toString()
291 if (name == "custom")
292 name = nameLE->text();
293 if (type == "fixdate" || type == "fixtime") {
294 QString fd = fixDateLE->text();
296 fd = (type == "fixdate") ?
297 QDate::currentDate().toString(Qt::ISODate)
298 : QTime::currentTime().toString(Qt::ISODate);
301 return qstring_to_ucs4(type + ' ' + name);
305 bool GuiInfo::initialiseParams(std::string const & sdata)
307 Language const * lang = languages.getLanguage(sdata);
311 updateArguments(typeCO->currentIndex());
316 void GuiInfo::updateArguments(int i)
322 BufferView const * bv = guiApp->currentView()->currentBufferView();
323 vector<pair<string,docstring>> args = params_.getArguments(const_cast<Buffer *>(&bv->buffer()),
325 for (auto const & p : args) {
326 QListWidgetItem * li = new QListWidgetItem(toqstr(p.second));
327 li->setData(Qt::UserRole, toqstr(p.first));
328 if (p.first == "invalid")
329 // non-selectable, disabled item!
330 li->setFlags(Qt::NoItemFlags);
331 if (p.first == "custom")
332 li->setData(Qt::ToolTipRole, qt_("Enter a valid value below"));
335 if (infoLW->count() > 0)
336 infoLW->setCurrentRow(0);
341 bool GuiInfo::checkWidgets(bool readonly) const
343 nameLE->setReadOnly(readonly);
344 typeCO->setEnabled(!readonly);
345 nameLA->setText(qt_(info_name_gui[typeCO->currentIndex()]) + toqstr(":"));
347 QString const arg = infoLW->currentItem() ?
348 infoLW->currentItem()->data(Qt::UserRole).toString()
351 bool const type_enabled = (arg == "custom");
352 nameLA->setEnabled(type_enabled);
353 nameLE->setEnabled(type_enabled);
354 nameLE->setToolTip(qt_(info_tooltip[typeCO->currentIndex()]));
356 string const typestr = info_types[typeCO->currentIndex()];
357 bool const fixdate_enabled = (typestr == "fixdate" || typestr == "fixtime");
358 fixDateLE->setVisible(fixdate_enabled);
359 fixDateLA->setVisible(fixdate_enabled);
360 if (typestr == "fixdate") {
361 fixDateLE->setToolTip(qt_("Here you can enter a fix date (in ISO format: YYYY-MM-DD)"));
362 fixDateLA->setText(qt_("&Fix Date:"));
364 else if (typestr == "fixtime") {
365 fixDateLE->setToolTip(qt_("Here you can enter a fix time (in ISO format: hh:mm:ss)"));
366 fixDateLA->setText(qt_("&Fix Time:"));
369 if (!InsetParamsWidget::checkWidgets())
371 return !arg.isEmpty() && (arg != "custom" || !nameLE->text().isEmpty());
376 } // namespace frontend
379 #include "moc_GuiInfo.cpp"