diff --git a/src/lay/lay/layMacroController.cc b/src/lay/lay/layMacroController.cc index 61af02ea1..a0edfb34f 100644 --- a/src/lay/lay/layMacroController.cc +++ b/src/lay/lay/layMacroController.cc @@ -49,6 +49,35 @@ MacroController::MacroController () connect (&m_temp_macros, SIGNAL (macro_collection_changed (lym::MacroCollection *)), this, SLOT (macro_collection_changed ())); } +static lay::MacroController::MacroCategory ruby_cat () +{ + lay::MacroController::MacroCategory cat; + cat.name = "macros"; + cat.description = tl::to_string (QObject::tr ("Ruby")); + cat.folders.push_back ("macros"); + cat.folders.push_back ("ruby"); + return cat; +} + +static lay::MacroController::MacroCategory python_cat () +{ + lay::MacroController::MacroCategory cat; + cat.name = "pymacros"; + cat.description = tl::to_string (QObject::tr ("Python")); + cat.folders.push_back ("pymacros"); + cat.folders.push_back ("python"); + return cat; +} + +static lay::MacroController::MacroCategory drc_cat () +{ + lay::MacroController::MacroCategory cat; + cat.name = "drc"; + cat.description = tl::to_string (QObject::tr ("DRC")); + cat.folders.push_back ("drc"); + return cat; +} + void MacroController::finish (bool load) { @@ -63,25 +92,41 @@ MacroController::finish (bool load) // TODO: consider adding "drc" dynamically and allow more dynamic categories // We can do so if we first load the macros with the initial interpreters, then do autorun (which creates DSL interpreters) and then // register the remaining categories. - m_macro_categories.push_back (std::pair ("macros", tl::to_string (QObject::tr ("Ruby")))); - m_macro_categories.push_back (std::pair ("pymacros", tl::to_string (QObject::tr ("Python")))); - m_macro_categories.push_back (std::pair ("drc", tl::to_string (QObject::tr ("DRC")))); + + m_macro_categories.push_back (ruby_cat ()); + m_macro_categories.push_back (python_cat ()); + m_macro_categories.push_back (drc_cat ()); // Scan for macros and set interpreter path for (std::vector ::const_iterator p = m_internal_paths.begin (); p != m_internal_paths.end (); ++p) { if (load) { + for (size_t c = 0; c < m_macro_categories.size (); ++c) { - if (p->cat.empty () || p->cat == m_macro_categories [c].first) { - std::string mp; - if (p->cat.empty ()) { - mp = tl::to_string (QDir (tl::to_qstring (p->path)).absoluteFilePath (tl::to_qstring (m_macro_categories [c].first))); - } else { - mp = p->path; + + if (p->cat.empty ()) { + + for (std::vector::const_iterator f = m_macro_categories[c].folders.begin (); f != m_macro_categories[c].folders.end (); ++f) { + + std::string mp = tl::to_string (QDir (tl::to_qstring (p->path)).absoluteFilePath (tl::to_qstring (*f))); + + std::string description = p->description; + if (*f != m_macro_categories[c].name) { + description += " - " + tl::to_string (tr ("%1 branch").arg (tl::to_qstring (*f))); + } + + lym::MacroCollection::root ().add_folder (description, mp, m_macro_categories[c].name, p->readonly); + } - lym::MacroCollection::root ().add_folder (p->description, mp, m_macro_categories [c].first, p->readonly); + + } else if (p->cat == m_macro_categories[c].name) { + + lym::MacroCollection::root ().add_folder (p->description, p->path, m_macro_categories[c].name, p->readonly); + } + } + } // Add the unspecific paths as "package locations", so we get "ruby", "python" and similar folders as @@ -375,28 +420,36 @@ MacroController::sync_implicit_macros (bool ask_before_autorun) for (size_t c = 0; c < macro_categories ().size (); ++c) { - QDir base_dir (tl::to_qstring (t->first)); - QDir macro_dir (base_dir.filePath (tl::to_qstring (macro_categories () [c].first))); - if (macro_dir.exists ()) { + for (std::vector::const_iterator f = macro_categories () [c].folders.begin (); f != macro_categories () [c].folders.end (); ++f) { - std::string description; - if (t->second.size () == 1) { - description = tl::to_string (tr ("Technology %1").arg (tl::to_qstring (t->second.front ()))); - } else { - description = tl::to_string (tr ("Technologies %1").arg (tl::to_qstring (tl::join (t->second, ",")))); - } + QDir base_dir (tl::to_qstring (t->first)); + QDir macro_dir (base_dir.filePath (tl::to_qstring (*f))); + if (macro_dir.exists ()) { - std::map >::const_iterator gn = grain_names_by_path.find (t->first); - if (gn != grain_names_by_path.end ()) { - description += " - "; - if (gn->second.size () == 1) { - description += tl::to_string (tr ("Package %1").arg (tl::to_qstring (gn->second.front ()))); + std::string description; + if (t->second.size () == 1) { + description = tl::to_string (tr ("Technology %1").arg (tl::to_qstring (t->second.front ()))); } else { - description += tl::to_string (tr ("Packages %1").arg (tl::to_qstring (tl::join (gn->second, ",")))); + description = tl::to_string (tr ("Technologies %1").arg (tl::to_qstring (tl::join (t->second, ",")))); } - } - external_paths.push_back (ExternalPathDescriptor (tl::to_string (macro_dir.path ()), description, macro_categories () [c].first, lym::MacroCollection::TechFolder, readonly_paths.find (t->first) != readonly_paths.end ())); + std::map >::const_iterator gn = grain_names_by_path.find (t->first); + if (gn != grain_names_by_path.end ()) { + description += " - "; + if (gn->second.size () == 1) { + description += tl::to_string (tr ("Package %1").arg (tl::to_qstring (gn->second.front ()))); + } else { + description += tl::to_string (tr ("Packages %1").arg (tl::to_qstring (tl::join (gn->second, ",")))); + } + } + + if (*f != macro_categories () [c].name) { + description += " - " + tl::to_string (tr ("%1 branch").arg (tl::to_qstring (*f))); + } + + external_paths.push_back (ExternalPathDescriptor (tl::to_string (macro_dir.path ()), description, macro_categories () [c].name, lym::MacroCollection::TechFolder, readonly_paths.find (t->first) != readonly_paths.end ())); + + } } @@ -416,12 +469,19 @@ MacroController::sync_implicit_macros (bool ask_before_autorun) for (size_t c = 0; c < macro_categories ().size (); ++c) { - QDir base_dir (tl::to_qstring (g->path ())); - QDir macro_dir (base_dir.filePath (tl::to_qstring (macro_categories () [c].first))); - if (macro_dir.exists ()) { + for (std::vector::const_iterator f = macro_categories () [c].folders.begin (); f != macro_categories () [c].folders.end (); ++f) { - std::string description = tl::to_string (tr ("Package %1").arg (tl::to_qstring (g->name ()))); - external_paths.push_back (ExternalPathDescriptor (tl::to_string (macro_dir.path ()), description, macro_categories () [c].first, lym::MacroCollection::SaltFolder, g->is_readonly ())); + QDir base_dir (tl::to_qstring (g->path ())); + QDir macro_dir (base_dir.filePath (tl::to_qstring (*f))); + if (macro_dir.exists ()) { + + std::string description = tl::to_string (tr ("Package %1").arg (tl::to_qstring (g->name ()))); + if (*f != macro_categories () [c].name) { + description += " - " + tl::to_string (tr ("%1 branch").arg (tl::to_qstring (*f))); + } + external_paths.push_back (ExternalPathDescriptor (tl::to_string (macro_dir.path ()), description, macro_categories () [c].name, lym::MacroCollection::SaltFolder, g->is_readonly ())); + + } } @@ -545,9 +605,9 @@ MacroController::add_macro_items_to_menu (lym::MacroCollection &collection, int if (! tech || c->second->virtual_mode () != lym::MacroCollection::TechFolder) { consider = true; } else { - const std::vector > &mc = macro_categories (); - for (std::vector >::const_iterator cc = mc.begin (); cc != mc.end () && !consider; ++cc) { - consider = (c->second->path () == tl::to_string (QDir (tl::to_qstring (tech->base_path ())).filePath (tl::to_qstring (cc->first)))); + const std::vector &mc = macro_categories (); + for (std::vector::const_iterator cc = mc.begin (); cc != mc.end () && !consider; ++cc) { + consider = (c->second->path () == tl::to_string (QDir (tl::to_qstring (tech->base_path ())).filePath (tl::to_qstring (cc->name)))); } } diff --git a/src/lay/lay/layMacroController.h b/src/lay/lay/layMacroController.h index 14fb8d0fd..1ceff83cd 100644 --- a/src/lay/lay/layMacroController.h +++ b/src/lay/lay/layMacroController.h @@ -64,6 +64,18 @@ class MacroController Q_OBJECT public: + /** + * @brief A structure describing a macro category + */ + struct MacroCategory + { + MacroCategory () { } + + std::string name; + std::string description; + std::vector folders; + }; + /** * @brief Default constructor */ @@ -150,7 +162,7 @@ public: /** * @brief Obtain the list of macro categories */ - const std::vector< std::pair > ¯o_categories () const + const std::vector ¯o_categories () const { return m_macro_categories; } @@ -219,7 +231,7 @@ private: std::vector m_macro_actions; std::map m_action_to_macro; lym::MacroCollection m_temp_macros; - std::vector< std::pair > m_macro_categories; + std::vector m_macro_categories; std::vector m_internal_paths; std::vector m_external_paths; std::vector m_package_locations; diff --git a/src/lay/lay/layMacroEditorDialog.cc b/src/lay/lay/layMacroEditorDialog.cc index f83b89382..2dc366c0f 100644 --- a/src/lay/lay/layMacroEditorDialog.cc +++ b/src/lay/lay/layMacroEditorDialog.cc @@ -273,16 +273,16 @@ MacroEditorDialog::MacroEditorDialog (QWidget * /*parent*/, lym::MacroCollection for (size_t i = 0; i < m_categories.size (); ++i) { - lay::MacroEditorTree *macro_tree = new lay::MacroEditorTree (treeTab, m_categories [i].first); + lay::MacroEditorTree *macro_tree = new lay::MacroEditorTree (treeTab, m_categories [i].name); m_macro_trees.push_back (macro_tree); - treeTab->addTab(macro_tree, tl::to_qstring (m_categories [i].second)); + treeTab->addTab(macro_tree, tl::to_qstring (m_categories [i].description)); macro_tree->setup (this); macro_tree->setSortingEnabled (true); macro_tree->sortByColumn (0, Qt::AscendingOrder); - macro_tree->setObjectName (tl::to_qstring (m_categories [i].first) + QString::fromUtf8 ("_tree")); + macro_tree->setObjectName (tl::to_qstring (m_categories [i].name) + QString::fromUtf8 ("_tree")); macro_tree->setContextMenuPolicy (Qt::ActionsContextMenu); @@ -622,7 +622,7 @@ void MacroEditorDialog::select_category (const std::string &cat) { for (size_t i = 0; i < m_categories.size (); ++i) { - if (m_categories [i].first == cat) { + if (m_categories [i].name == cat) { treeTab->setCurrentIndex (int (i)); } } @@ -2051,7 +2051,7 @@ MacroEditorDialog::new_macro() // ask for a template std::string cat; if (treeTab->currentIndex () < int (m_categories.size ())) { - cat = m_categories [treeTab->currentIndex ()].first; + cat = m_categories [treeTab->currentIndex ()].name; } lay::MacroTemplateSelectionDialog template_dialog (this, m_macro_templates, cat); int template_index = template_dialog.exec_dialog (); diff --git a/src/lay/lay/layMacroEditorDialog.h b/src/lay/lay/layMacroEditorDialog.h index f3df4c305..bdbeda512 100644 --- a/src/lay/lay/layMacroEditorDialog.h +++ b/src/lay/lay/layMacroEditorDialog.h @@ -28,13 +28,14 @@ #include "ui_MacroEditorDialog.h" #include "layMacroEditorPage.h" +#include "layMacroController.h" #include "tlDeferredExecution.h" #include "tlTimer.h" #include "tlFileSystemWatcher.h" #include "tlDeferredExecution.h" +#include "tlScriptError.h" #include "lymMacro.h" #include "gsiInterpreter.h" -#include "tlScriptError.h" #include #include @@ -300,7 +301,7 @@ private: bool m_file_watcher_enabled; std::string m_font_family; int m_font_size; - std::vector > m_categories; + std::vector m_categories; std::vector > m_watch_expressions; std::vector m_edit_trace; size_t m_edit_trace_index; diff --git a/src/lay/lay/layTechSetupDialog.cc b/src/lay/lay/layTechSetupDialog.cc index 16adb96d3..d7fd7fdce 100644 --- a/src/lay/lay/layTechSetupDialog.cc +++ b/src/lay/lay/layTechSetupDialog.cc @@ -903,11 +903,11 @@ TechSetupDialog::update_tech_tree () tci->setData (0, Qt::FontRole, QVariant (f)); if (lay::MacroController::instance ()) { - const std::vector > &mc = lay::MacroController::instance ()->macro_categories (); - for (std::vector >::const_iterator c = mc.begin (); c != mc.end (); ++c) { + const std::vector &mc = lay::MacroController::instance ()->macro_categories (); + for (std::vector::const_iterator c = mc.begin (); c != mc.end (); ++c) { tci = new QTreeWidgetItem (ti); - tci->setData (0, Qt::DisplayRole, QVariant (tl::to_qstring (c->second))); - tci->setData (0, Qt::UserRole + 1, QVariant (tl::to_qstring (std::string ("_macros_") + c->first))); + tci->setData (0, Qt::DisplayRole, QVariant (tl::to_qstring (c->description))); + tci->setData (0, Qt::UserRole + 1, QVariant (tl::to_qstring (std::string ("_macros_") + c->name))); tci->setData (0, Qt::FontRole, QVariant (f)); } } @@ -942,13 +942,13 @@ TechSetupDialog::update_tech (lay::Technology *t) m_component_editors.insert (std::make_pair (std::string ("_general"), tce_widget)); if (lay::MacroController::instance ()) { - const std::vector > &mc = lay::MacroController::instance ()->macro_categories (); - for (std::vector >::const_iterator c = mc.begin (); c != mc.end (); ++c) { - tce_widget = new TechMacrosPage (this, c->first, c->second); + const std::vector &mc = lay::MacroController::instance ()->macro_categories (); + for (std::vector::const_iterator c = mc.begin (); c != mc.end (); ++c) { + tce_widget = new TechMacrosPage (this, c->name, c->description); tce_widget->setEnabled (!t->is_readonly ()); tce_widget->set_technology (t, 0); tc_stack->addWidget (tce_widget); - m_component_editors.insert (std::make_pair (std::string ("_macros_") + c->first, tce_widget)); + m_component_editors.insert (std::make_pair (std::string ("_macros_") + c->name, tce_widget)); } }