From 942f2d30149c2eb448855431312e955b49c36207 Mon Sep 17 00:00:00 2001 From: DavidXanatos <3890945+DavidXanatos@users.noreply.github.com> Date: Wed, 13 Nov 2024 12:46:37 +0100 Subject: [PATCH] #4231 --- CHANGELOG.md | 1 + .../SandMan/Windows/SelectBoxWindow.cpp | 29 +++++++++++++++---- .../SandMan/Windows/SelectBoxWindow.h | 3 ++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3ae95b3..c42dc09e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added - added the ability to hide certificates in editbox in Global Setting (idea by Yeyixiao) +- added Opening a program in several sandboxes at once [#4231](https://github.com/sandboxie-plus/Sandboxie/issues/4231) ### Fixed - fixed Sign the .tmp file that gets dropped when installing or updating Sandboxie Plus [#2643](https://github.com/sandboxie-plus/Sandboxie/issues/2643) diff --git a/SandboxiePlus/SandMan/Windows/SelectBoxWindow.cpp b/SandboxiePlus/SandMan/Windows/SelectBoxWindow.cpp index 2c721dcd..d5083aa2 100644 --- a/SandboxiePlus/SandMan/Windows/SelectBoxWindow.cpp +++ b/SandboxiePlus/SandMan/Windows/SelectBoxWindow.cpp @@ -34,6 +34,11 @@ CBoxPicker::CBoxPicker(QString DefaultBox, QWidget* parent) LoadBoxed("", DefaultBox); } +void CBoxPicker::EnableMultiSel(bool bEnable) +{ + m_pTreeBoxes->setSelectionMode(bEnable ? QAbstractItemView::ExtendedSelection : QAbstractItemView::SingleSelection); +} + void CBoxPicker::SetFilter(const QString& Exp, int iOptions, int Column) { LoadBoxed(Exp); @@ -101,6 +106,14 @@ QString CBoxPicker::GetBoxName() const return pItem->data(0, Qt::UserRole).toString(); } +QStringList CBoxPicker::GetBoxNames() const +{ + QStringList BoxNames; + foreach(auto pItem, m_pTreeBoxes->selectedItems()) + BoxNames.append(pItem->data(0, Qt::UserRole).toString()); + return BoxNames; +} + QTreeWidgetItem* CBoxPicker::GetBoxParent(const QMap& Groups, QMap& GroupItems, QTreeWidget* treeBoxes, const QString& Name, int Depth) { if (Depth > 100) @@ -192,6 +205,7 @@ CSelectBoxWindow::CSelectBoxWindow(const QStringList& Commands, const QString& B connect(ui.buttonBox, SIGNAL(rejected()), SLOT(reject())); m_pBoxPicker = new CBoxPicker(BoxName); + m_pBoxPicker->EnableMultiSel(true); connect(m_pBoxPicker, SIGNAL(BoxDblClick()), this, SLOT(OnRun())); ui.treeBoxes->parentWidget()->layout()->replaceWidget(ui.treeBoxes, m_pBoxPicker); delete ui.treeBoxes; @@ -225,7 +239,7 @@ void CSelectBoxWindow::OnBoxType() void CSelectBoxWindow::OnRun() { - QString BoxName; + QStringList BoxNames; int Flags = CSbieAPI::eStartDefault; if (ui.chkAdmin->isChecked()) Flags |= CSbieAPI::eStartElevated; @@ -236,25 +250,28 @@ void CSelectBoxWindow::OnRun() } if (ui.radBoxedNew->isChecked()) { - BoxName = theGUI->GetBoxView()->AddNewBox(true); + QString BoxName = theGUI->GetBoxView()->AddNewBox(true); if (BoxName.isEmpty()) { close(); return; } + BoxNames.append(BoxName); } else if (!ui.radUnBoxed->isChecked() || ui.chkFCP->isChecked()) { if (ui.chkFCP->isChecked()) Flags |= CSbieAPI::eStartFCP; - BoxName = m_pBoxPicker->GetBoxName(); - if (BoxName.isEmpty()) { + BoxNames = m_pBoxPicker->GetBoxNames(); + if (BoxNames.isEmpty()) { QMessageBox("Sandboxie-Plus", tr("Please select a sandbox."), QMessageBox::Information, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton, this).exec(); return; } } - foreach(const QString& Command, m_Commands) - theGUI->RunStart(BoxName, Command, (CSbieAPI::EStartFlags)Flags, m_WrkDir); + foreach(const QString & BoxName, BoxNames) { + foreach(const QString & Command, m_Commands) + theGUI->RunStart(BoxName, Command, (CSbieAPI::EStartFlags)Flags, m_WrkDir); + } setResult(1); close(); diff --git a/SandboxiePlus/SandMan/Windows/SelectBoxWindow.h b/SandboxiePlus/SandMan/Windows/SelectBoxWindow.h index ab71a61d..e3c146ea 100644 --- a/SandboxiePlus/SandMan/Windows/SelectBoxWindow.h +++ b/SandboxiePlus/SandMan/Windows/SelectBoxWindow.h @@ -15,9 +15,12 @@ class CBoxPicker : public QWidget public: CBoxPicker(QString DefaultBox = "", QWidget *parent = Q_NULLPTR); + void EnableMultiSel(bool bEnable); + void LoadBoxed(const QString& Filter = QString(), const QString& SelectBox = QString()); QString GetBoxName() const; + QStringList GetBoxNames() const; static QTreeWidgetItem* GetBoxParent(const QMap& Groups, QMap& GroupItems, QTreeWidget* treeBoxes, const QString& Name, int Depth = 0); static double GetBoxOrder(const QMap& Groups, const QString& Name, double value = 0.0, int Depth = 0);