Show native paths in macro IDE too

So far, only the macro paths (macros/pymacros/drc)
are shown. With this fix, also the native paths
like "ruby" and "python" are listed.
This commit is contained in:
Matthias Koefferlein 2017-10-23 21:45:58 +02:00
parent 77b63a14d9
commit 6364530c69
5 changed files with 125 additions and 52 deletions

View File

@ -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<std::string, std::string> ("macros", tl::to_string (QObject::tr ("Ruby"))));
m_macro_categories.push_back (std::pair<std::string, std::string> ("pymacros", tl::to_string (QObject::tr ("Python"))));
m_macro_categories.push_back (std::pair<std::string, std::string> ("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 <InternalPathDescriptor>::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<std::string>::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<std::string>::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<std::string, std::vector<std::string> >::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<std::string, std::vector<std::string> >::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<std::string>::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<std::pair<std::string, std::string> > &mc = macro_categories ();
for (std::vector<std::pair<std::string, std::string> >::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<lay::MacroController::MacroCategory> &mc = macro_categories ();
for (std::vector<lay::MacroController::MacroCategory>::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))));
}
}

View File

@ -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<std::string> folders;
};
/**
* @brief Default constructor
*/
@ -150,7 +162,7 @@ public:
/**
* @brief Obtain the list of macro categories
*/
const std::vector< std::pair<std::string, std::string> > &macro_categories () const
const std::vector<MacroCategory> &macro_categories () const
{
return m_macro_categories;
}
@ -219,7 +231,7 @@ private:
std::vector<lay::Action> m_macro_actions;
std::map<QAction *, lym::Macro *> m_action_to_macro;
lym::MacroCollection m_temp_macros;
std::vector< std::pair<std::string, std::string> > m_macro_categories;
std::vector<MacroCategory> m_macro_categories;
std::vector<InternalPathDescriptor> m_internal_paths;
std::vector<ExternalPathDescriptor> m_external_paths;
std::vector<std::string> m_package_locations;

View File

@ -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 ();

View File

@ -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 <QDialog>
#include <QTextCharFormat>
@ -300,7 +301,7 @@ private:
bool m_file_watcher_enabled;
std::string m_font_family;
int m_font_size;
std::vector<std::pair<std::string, std::string> > m_categories;
std::vector<lay::MacroController::MacroCategory> m_categories;
std::vector<std::pair<gsi::Interpreter *, std::string> > m_watch_expressions;
std::vector<EditTrace> m_edit_trace;
size_t m_edit_trace_index;

View File

@ -903,11 +903,11 @@ TechSetupDialog::update_tech_tree ()
tci->setData (0, Qt::FontRole, QVariant (f));
if (lay::MacroController::instance ()) {
const std::vector<std::pair<std::string, std::string> > &mc = lay::MacroController::instance ()->macro_categories ();
for (std::vector<std::pair<std::string, std::string> >::const_iterator c = mc.begin (); c != mc.end (); ++c) {
const std::vector<lay::MacroController::MacroCategory> &mc = lay::MacroController::instance ()->macro_categories ();
for (std::vector<lay::MacroController::MacroCategory>::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<std::pair<std::string, std::string> > &mc = lay::MacroController::instance ()->macro_categories ();
for (std::vector<std::pair<std::string, std::string> >::const_iterator c = mc.begin (); c != mc.end (); ++c) {
tce_widget = new TechMacrosPage (this, c->first, c->second);
const std::vector<lay::MacroController::MacroCategory> &mc = lay::MacroController::instance ()->macro_categories ();
for (std::vector<lay::MacroController::MacroCategory>::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));
}
}