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