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