From 4eedfb0db4165cefb35f8a15134010c745d4182b Mon Sep 17 00:00:00 2001 From: octaeder <102688820+octaeder@users.noreply.github.com> Date: Fri, 15 Mar 2024 18:45:48 +0100 Subject: [PATCH] add user tags to side panel --- src/texstudio.cpp | 31 ++++++++++++++++++++++++++++--- src/texstudio.h | 2 +- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/texstudio.cpp b/src/texstudio.cpp index 32bbdddb52..bf8250cf15 100644 --- a/src/texstudio.cpp +++ b/src/texstudio.cpp @@ -585,16 +585,23 @@ void Texstudio::loadManagedMenu(const QString &fn) * \param text name of taglist * \param tagFile file to be read as tag list */ -void Texstudio::addTagList(const QString &id, const QString &iconName, const QString &text, const QString &tagFile) +void Texstudio::addTagList(const QString &id, const QString &iconName, const QString &text, const QString &tagFile, const bool &isUserTagFile) { XmlTagsListWidget *list = qobject_cast(leftPanel->widget(id)); if (!list) { - list = new XmlTagsListWidget(this, ":/tags/" + tagFile); + QString pathPrefix = ""; + if (isUserTagFile) { // user defined list + QString configBaseDir = configManager.configBaseDir; + pathPrefix = joinPath(configBaseDir,"tags/"); + } + else { + pathPrefix = ":/tags/"; + } + list = new XmlTagsListWidget(this, pathPrefix + tagFile); list->setObjectName("tags/" + tagFile.left(tagFile.indexOf("_tags.xml"))); UtilsUi::enableTouchScrolling(list); connect(list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(insertXmlTag(QListWidgetItem*))); leftPanel->addWidget(list, id, text, iconName); - //(*list)->setProperty("mType",2); } else { leftPanel->setWidgetText(list, text); leftPanel->setWidgetIcon(list,iconName); @@ -740,6 +747,24 @@ void Texstudio::setupDockWidgets() addTagList("beamer", getRealIconFile("beamer"), tr("Beamer Commands"), "beamer_tags.xml"); addTagList("xymatrix", getRealIconFile("xy"), tr("XY Commands"), "xymatrix_tags.xml"); addMacrosAsTagList(); + // load user tags + QString configBaseDir = configManager.configBaseDir; + QDir dir(joinPath(configBaseDir,"tags")); + dir.setFilter(QDir::Files | QDir::NoSymLinks); + dir.setSorting(QDir::Name); + if(dir.exists()){ + int i=0; + QString configBaseDir = configManager.configBaseDir; + QStringList fileNames=dir.entryList(QStringList()<<"*_tags.xml"); + for (QString fileName:fileNames) { + QString tagName=fileName.left(fileName.indexOf("_tags.xml")); + QString id=QString(tagName+"%1").arg(++i); + QString pathName=joinPath(configBaseDir,"tags",fileName); + QString pathIcon=joinPath(configBaseDir,"tags",tagName+"_icon"); + QString title=tagName.split("#").join(" "); + addTagList(id, pathIcon, title, fileName, true); + } + } leftPanel->showWidgets(); // restore selected view in sidepanel diff --git a/src/texstudio.h b/src/texstudio.h index 7b0afcda3f..e9ce5572b8 100644 --- a/src/texstudio.h +++ b/src/texstudio.h @@ -117,7 +117,7 @@ public slots: Q_INVOKABLE void setupToolBars(); - void addTagList(const QString &id, const QString &iconName, const QString &text, const QString &tagFile); + void addTagList(const QString &id, const QString &iconName, const QString &text, const QString &tagFile, const bool &isUserTagFile=false); void addMacrosAsTagList(); private slots: