Skip to content

Commit

Permalink
add user tags to side panel
Browse files Browse the repository at this point in the history
  • Loading branch information
octaeder committed Mar 15, 2024
1 parent 5627a1e commit 4eedfb0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
31 changes: 28 additions & 3 deletions src/texstudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<XmlTagsListWidget *>(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);
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/texstudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 4eedfb0

Please sign in to comment.