Fix button being present in other pages

This commit is contained in:
timoreo 2022-01-28 19:32:42 +01:00
parent 8b790a6dd9
commit efc44c56a6
No known key found for this signature in database
GPG Key ID: 121A72C3512BA288
4 changed files with 20 additions and 9 deletions

View File

@ -143,6 +143,11 @@ ModFolderPage::ModFolderPage(
ui(new Ui::ModFolderPage)
{
ui->setupUi(this);
if(id == "mods") {
auto act = new QAction(tr("Install Mods"), this);
ui->actionsToolbar->insertActionBefore(ui->actionView_configs,act);
connect(act, &QAction::triggered, this, &ModFolderPage::on_actionInstall_mods_triggered);
}
ui->actionsToolbar->insertSpacer(ui->actionView_configs);
m_inst = inst;

View File

@ -88,7 +88,6 @@
<addaction name="actionRemove"/>
<addaction name="actionEnable"/>
<addaction name="actionDisable"/>
<addaction name="actionInstall_mods"/>
<addaction name="actionView_configs"/>
<addaction name="actionView_Folder"/>
</widget>
@ -137,14 +136,6 @@
<string>View &amp;Folder</string>
</property>
</action>
<action name="actionInstall_mods">
<property name="text">
<string>Install mods</string>
</property>
<property name="toolTip">
<string>Install mods from Modrinth or Curseforge</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -76,6 +76,20 @@ void WideBar::addSeparator()
m_entries.push_back(entry);
}
void WideBar::insertActionBefore(QAction* before, QAction* action){
auto iter = std::find_if(m_entries.begin(), m_entries.end(), [before](BarEntry * entry) {
return entry->wideAction == before;
});
if(iter == m_entries.end()) {
return;
}
auto entry = new BarEntry();
entry->qAction = insertWidget((*iter)->qAction, new ActionButton(action, this));
entry->wideAction = action;
entry->type = BarEntry::Action;
m_entries.insert(iter, entry);
}
void WideBar::insertSpacer(QAction* action)
{
auto iter = std::find_if(m_entries.begin(), m_entries.end(), [action](BarEntry * entry) {

View File

@ -18,6 +18,7 @@ public:
void addAction(QAction *action);
void addSeparator();
void insertSpacer(QAction *action);
void insertActionBefore(QAction *before, QAction *action);
QMenu *createContextMenu(QWidget *parent = nullptr, const QString & title = QString());
private: