@@ -60,14 +60,30 @@ namespace Dialog
6060class MacroItem : public QTreeWidgetItem
6161{
6262public:
63- MacroItem (QTreeWidget* widget, bool systemwide)
63+ MacroItem (QTreeWidget* widget, bool systemwide, const QString& dirPath )
6464 : QTreeWidgetItem(widget)
6565 , systemWide(systemwide)
66+ , dirPath(dirPath)
6667 {}
6768
69+ /* *
70+ * Acts same as setText method but additionally set toolTip with text of
71+ * absolute file path. There may be different macros with same names from
72+ * different system paths. So it could be helpful for user to show where
73+ * exactly macro is placed.
74+ */
75+ void setFileName (int column, const QString& text)
76+ {
77+ QFileInfo file (dirPath, text);
78+
79+ setToolTip (column, file.absoluteFilePath ());
80+ return QTreeWidgetItem::setText (column, text);
81+ }
82+
6883 ~MacroItem () override = default ;
6984
7085 bool systemWide;
86+ QString dirPath;
7187};
7288} // namespace Dialog
7389} // namespace Gui
@@ -229,23 +245,37 @@ QStringList DlgMacroExecuteImp::filterFiles(const QString& folder)
229245 * Fills up the list with macro files found in the specified location
230246 * that have been filtered by both filename and by content
231247 */
232- void DlgMacroExecuteImp::fillUpList ( )
248+ void DlgMacroExecuteImp::fillUpListForDir ( const QString& dirPath, bool systemWide )
233249{
234- QStringList filteredByContent = this ->filterFiles (this -> macroPath );
250+ QStringList filteredByContent = this ->filterFiles (dirPath );
235251 ui->userMacroListBox ->clear ();
236- for (auto fn : filteredByContent) {
237- auto item = new MacroItem (ui->userMacroListBox , false );
238- item->setText (0 , fn);
252+ for (auto & fn : filteredByContent) {
253+ auto * parent = systemWide ? ui->systemMacroListBox : ui->userMacroListBox ;
254+ auto item = new MacroItem (parent, systemWide, dirPath);
255+ item->setFileName (0 , fn);
239256 }
257+ }
258+
259+ /* *
260+ * Fills up the list with macro files found in all system paths and specified by
261+ * user location that have been filtered by both filename and by content
262+ */
263+ void DlgMacroExecuteImp::fillUpList ()
264+ {
265+ fillUpListForDir (this ->macroPath , false );
240266
241267 QString dirstr =
242268 QString::fromStdString (App::Application::getHomePath ()) + QString::fromLatin1 (" Macro" );
243- filteredByContent = this ->filterFiles (dirstr);
244-
245- ui->systemMacroListBox ->clear ();
246- for (auto fn : filteredByContent) {
247- auto item = new MacroItem (ui->systemMacroListBox , true );
248- item->setText (0 , fn);
269+ fillUpListForDir (dirstr, true );
270+
271+ auto & config = App::Application::Config ();
272+ auto additionalMacros = config.find (" AdditionalMacroPaths" );
273+ if (additionalMacros != config.end ()) {
274+ QString dirsstrs = QString::fromStdString (additionalMacros->second );
275+ QStringList dirs = dirsstrs.split (QChar::fromLatin1 (' ;' ));
276+ for (const auto & dirstr : dirs) {
277+ fillUpListForDir (dirstr, true );
278+ }
249279 }
250280}
251281
@@ -392,17 +422,7 @@ void DlgMacroExecuteImp::accept()
392422
393423 auto mitem = static_cast <MacroItem*>(item);
394424
395- QDir dir;
396-
397- if (!mitem->systemWide ) {
398- dir = QDir (this ->macroPath );
399- }
400- else {
401- QString dirstr =
402- QString::fromStdString (App::Application::getHomePath ()) + QString::fromLatin1 (" Macro" );
403- dir = QDir (dirstr);
404- }
405-
425+ QDir dir (mitem->dirPath );
406426 QFileInfo fi (dir, item->text (0 ));
407427 try {
408428 getMainWindow ()->setCursor (Qt::WaitCursor);
@@ -444,26 +464,23 @@ void DlgMacroExecuteImp::onFileChooserFileNameChanged(const QString& fn)
444464 */
445465void DlgMacroExecuteImp::onEditButtonClicked ()
446466{
447- QDir dir;
448467 QTreeWidgetItem* item = nullptr ;
449468
450469 int index = ui->tabMacroWidget ->currentIndex ();
451470 if (index == 0 ) { // user-specific
452471 item = ui->userMacroListBox ->currentItem ();
453- dir.setPath (this ->macroPath );
454472 }
455473 else {
456474 // index == 1 system-wide
457475 item = ui->systemMacroListBox ->currentItem ();
458- dir.setPath (QString::fromStdString (App::Application::getHomePath ())
459- + QString::fromLatin1 (" Macro" ));
460476 }
461477
462478 if (!item) {
463479 return ;
464480 }
465481
466482 auto mitem = static_cast <MacroItem*>(item);
483+ QDir dir (mitem->dirPath );
467484
468485 QString file = QString::fromLatin1 (" %1/%2" ).arg (dir.absolutePath (), item->text (0 ));
469486 auto editor = new PythonEditor ();
0 commit comments