diff --git a/CHANGELOG.md b/CHANGELOG.md index eaa26d87..630338eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Added - added more documentation links to the Plus UI - added tray menu option to dismiss a pending update notification +- added Pin/Favourite files to Tray [#2913](https://github.com/sandboxie-plus/Sandboxie/issues/2913) ### Changed - improved compatibility template for Privacy Enhanced box types (thanks offhub) [#2899](https://github.com/sandboxie-plus/Sandboxie/pull/2899) diff --git a/SandboxiePlus/SandMan/SbiePlusAPI.cpp b/SandboxiePlus/SandMan/SbiePlusAPI.cpp index a166429b..d4a837a6 100644 --- a/SandboxiePlus/SandMan/SbiePlusAPI.cpp +++ b/SandboxiePlus/SandMan/SbiePlusAPI.cpp @@ -1030,6 +1030,17 @@ void CSandBoxPlus::OnCancelAsync() pProgress->Cancel(); } +QString CSandBoxPlus::MakeBoxCommand(const QString& FileName) +{ + QString BoxFileName = FileName; + //if (BoxFileName.indexOf(m_FilePath, Qt::CaseInsensitive) == 0) { + // BoxFileName.remove(0, m_FilePath.length()); + // if (BoxFileName.at(0) != '\\') + // BoxFileName.prepend('\\'); + //} + return BoxFileName.replace(m_FilePath, "%BoxRoot%", Qt::CaseInsensitive); +} + QString CSandBoxPlus::GetCommandFile(const QString& Command) { QString Path = Command; @@ -1041,9 +1052,17 @@ QString CSandBoxPlus::GetCommandFile(const QString& Command) int End = Path.indexOf(" "); if (End != -1) Path.truncate(End); } - - if (Path.left(1) == "\\") - Path.prepend(m_FilePath); - - return Path; + //if (Path.left(1) == "\\") + // Path.prepend(m_FilePath); + return Path.replace("%BoxRoot%", m_FilePath, Qt::CaseInsensitive); } + +QString CSandBoxPlus::GetFullCommand(const QString& Command) +{ + QString FullCmd = Command; + //if(FullCmd.left(1) == "\\") + // FullCmd.prepend(m_FilePath); + //else if(FullCmd.left(2) == "\"\\") + // FullCmd.insert(1, m_FilePath); + return FullCmd.replace("%BoxRoot%", m_FilePath, Qt::CaseInsensitive); +} \ No newline at end of file diff --git a/SandboxiePlus/SandMan/SbiePlusAPI.h b/SandboxiePlus/SandMan/SbiePlusAPI.h index d29ef63c..98ddfa81 100644 --- a/SandboxiePlus/SandMan/SbiePlusAPI.h +++ b/SandboxiePlus/SandMan/SbiePlusAPI.h @@ -125,7 +125,9 @@ public: virtual bool IsRecoverySuspended() const { return m_SuspendRecovery; } virtual void SetSuspendRecovery(bool bSet = true) { m_SuspendRecovery = bSet; } + virtual QString MakeBoxCommand(const QString& FileName); virtual QString GetCommandFile(const QString& Command); + virtual QString GetFullCommand(const QString& Command); const QSet& GetRecentPrograms() { return m_RecentPrograms; } diff --git a/SandboxiePlus/SandMan/Views/FileView.cpp b/SandboxiePlus/SandMan/Views/FileView.cpp index d37d58d4..da077c42 100644 --- a/SandboxiePlus/SandMan/Views/FileView.cpp +++ b/SandboxiePlus/SandMan/Views/FileView.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "FileView.h" #include "SandMan.h" +#include "../MiscHelpers/Common/Common.h" #include "../MiscHelpers/Common/Settings.h" #include "../MiscHelpers/Common/TreeItemModel.h" #include "../MiscHelpers/Common/OtherFunctions.h" @@ -105,6 +106,7 @@ void CFileView::OnAboutToBeModified() #define MENU_RECOVER_TO_ANY 2 #define MENU_CREATE_SHORTCUT 3 #define MENU_CHECK_FILE 4 +#define MENU_PIN_FILE 5 void addSeparatorToShellContextMenu(HMENU hMenu) { @@ -116,18 +118,22 @@ void addSeparatorToShellContextMenu(HMENU hMenu) InsertMenuItem(hMenu, 0, TRUE, &menu_item_info); } -void addItemToShellContextMenu(HMENU hMenu, const wchar_t *name, int ID) +void addItemToShellContextMenu(HMENU hMenu, const wchar_t *name, int ID, bool bChecked = false) { MENUITEMINFO menu_item_info; memset(&menu_item_info, 0, sizeof(MENUITEMINFO)); menu_item_info.cbSize = sizeof(MENUITEMINFO); menu_item_info.fMask = MIIM_ID | MIIM_STRING | MIIM_DATA; + if (bChecked) { + menu_item_info.fMask |= MIIM_STATE; + menu_item_info.fState |= MFS_CHECKED; + } menu_item_info.wID = 0xF000 + ID; menu_item_info.dwTypeData = (wchar_t*)name; InsertMenuItem(hMenu, 0, TRUE, &menu_item_info); } -int openShellContextMenu(const QStringList& Files, void* parentWindow, const CSandBoxPtr& pBox) +int openShellContextMenu(const QStringList& Files, void* parentWindow, const CSandBoxPtr& pBox, QString* pPin = NULL) { CComPtr pDesktop; if (!SUCCEEDED(SHGetDesktopFolder(&pDesktop))) @@ -195,6 +201,27 @@ int openShellContextMenu(const QStringList& Files, void* parentWindow, const CSa addItemToShellContextMenu(hMenu, Str4.c_str(), MENU_CHECK_FILE); } + if (pPin && Files.count() == 1) + { + auto pBoxPlus = pBox.objectCast(); + QStringList RunOptions = pBox->GetTextList("RunCommand", true); + + QString FoundPin; + QString FileName = Files.first(); + foreach(const QString & RunOption, RunOptions) { + QString CmdFile = pBoxPlus->GetCommandFile(Split2(RunOption, "|").second); + if(CmdFile.compare(FileName, Qt::CaseInsensitive) == 0) { + FoundPin = RunOption; + break; + } + } + + *pPin = FoundPin; + + std::wstring Str5 = CFileView::tr("Pin to Box Run Menu").toStdWString(); + addItemToShellContextMenu(hMenu, Str5.c_str(), MENU_PIN_FILE, !FoundPin.isEmpty()); + } + POINT point; GetCursorPos(&point); int iCmd = TrackPopupMenuEx(hMenu, TPM_RETURNCMD, point.x, point.y, (HWND)parentWindow, NULL); @@ -246,7 +273,8 @@ void CFileView::OnFileMenu(const QPoint&) if (Files.isEmpty()) return; - int iCmd = openShellContextMenu(Files, (void*)this->winId(), m_pBox); + QString FoundPin; + int iCmd = openShellContextMenu(Files, (void*)this->winId(), m_pBox, &FoundPin); if (iCmd == 0) return; @@ -296,6 +324,15 @@ void CFileView::OnFileMenu(const QPoint&) theGUI->AddAsyncOp(Status.GetValue()); break; } + case MENU_PIN_FILE: + { + auto pBoxPlus = m_pBox.objectCast(); + if (FoundPin.isEmpty()) + pBoxPlus->InsertText("RunCommand", Split2(Files.first(), "\\", true).second + "|\"" + pBoxPlus->MakeBoxCommand(Files.first()) + "\""); + else + pBoxPlus->DelValue("RunCommand", FoundPin); + break; + } case MENU_CREATE_SHORTCUT: { QString BoxName = m_pBox->GetName(); diff --git a/SandboxiePlus/SandMan/Views/SbieView.cpp b/SandboxiePlus/SandMan/Views/SbieView.cpp index 920c1807..559a79c5 100644 --- a/SandboxiePlus/SandMan/Views/SbieView.cpp +++ b/SandboxiePlus/SandMan/Views/SbieView.cpp @@ -600,22 +600,12 @@ void CSbieView::UpdateProcMenu(const CBoxedProcessPtr& pProcess, int iProcessCou QString FoundPin; QString FileName = pProcess->GetFileName(); foreach(const QString& RunOption, RunOptions) { - QString Cmd = Split2(RunOption, "|").second; - int pos = Cmd.indexOf(FileName); - if (pos == 0 || pos == 1) { // 1 for " + QString CmdFile = pBoxPlus->GetCommandFile(Split2(RunOption, "|").second); + if(CmdFile.compare(FileName, Qt::CaseInsensitive) == 0) { FoundPin = RunOption; break; } } - if (FoundPin.isEmpty() && FileName.indexOf(pBoxPlus->GetFileRoot(), Qt::CaseInsensitive) == 0) { - FileName.remove(0, pBoxPlus->GetFileRoot().length()); - foreach(const QString& RunOption, RunOptions) { - if (Split2(RunOption, "|").second.indexOf(FileName) == 0) { - FoundPin = RunOption; - break; - } - } - } if (m_pMenuPreset) { m_pMenuPinToRun->setChecked(!FoundPin.isEmpty()); @@ -1451,11 +1441,9 @@ void CSbieView::OnSandBoxAction(QAction* Action, const QList& SandB QString Command = Action->data().toString(); if (Command.isEmpty()) Results.append(SandBoxes.first()->RunStart("start_menu")); - else - { - if (Command.left(1) == "\\" && !SandBoxes.isEmpty()) - Command.prepend(SandBoxes.first()->GetFileRoot()); - Results.append(SandBoxes.first()->RunStart(Command)); + else { + auto pBoxEx = SandBoxes.first().objectCast(); + Results.append(SandBoxes.first()->RunStart(pBoxEx->GetFullCommand(Command))); } } @@ -1519,18 +1507,8 @@ void CSbieView::OnProcessAction(QAction* Action, const QList& else if (Action == m_pMenuPinToRun) { CSandBoxPlus* pBoxPlus = pProcess.objectCast()->GetBox(); - if (m_pMenuPinToRun->isChecked()) - { - QString FileName = pProcess->GetFileName(); - if (FileName.indexOf(pBoxPlus->GetFileRoot(), Qt::CaseInsensitive) == 0) { - FileName.remove(0, pBoxPlus->GetFileRoot().length()); - if (FileName.at(0) != '\\') - FileName.prepend('\\'); - } - - pBoxPlus->InsertText("RunCommand", pProcess->GetProcessName() + "|\"" + pProcess->GetFileName().replace(pBoxPlus->GetFileRoot(), "%BoxRoot%", Qt::CaseInsensitive) +"\""); - } + pBoxPlus->InsertText("RunCommand", pProcess->GetProcessName() + "|\"" + pBoxPlus->MakeBoxCommand(pProcess->GetFileName()) + "\""); else if(!m_pMenuPinToRun->data().toString().isEmpty()) pBoxPlus->DelValue("RunCommand", m_pMenuPinToRun->data().toString()); } @@ -1774,10 +1752,7 @@ void CSbieView::UpdateRunMenu(const CSandBoxPtr& pBox) } else pMenu = GetMenuFolder(FolderName.first.replace("\\", "/"), m_pMenuRun, m_RunFolders); - NameCmd.second.replace("%BoxRoot%", pBoxEx->GetFileRoot(), Qt::CaseInsensitive); - StrPair IconIndex = Split2(NameIcon.second, ",", true); - IconIndex.first.replace("%BoxRoot%", pBoxEx->GetFileRoot(), Qt::CaseInsensitive); QAction* pAction = pMenu->addAction(FolderName.second, this, SLOT(OnSandBoxAction())); if (IconIndex.first.isEmpty()) @@ -1785,7 +1760,7 @@ void CSbieView::UpdateRunMenu(const CSandBoxPtr& pBox) else if(IconIndex.second.isEmpty()) pAction->setIcon(LoadWindowsIcon(pBoxEx->GetCommandFile(NameCmd.second), IconIndex.first.toInt())); else - pAction->setIcon(LoadWindowsIcon(IconIndex.first, IconIndex.second.toInt())); + pAction->setIcon(LoadWindowsIcon(pBoxEx->GetCommandFile(IconIndex.first), IconIndex.second.toInt())); pAction->setData(NameCmd.second); } diff --git a/SandboxiePlus/SandMan/Windows/OptionsGeneral.cpp b/SandboxiePlus/SandMan/Windows/OptionsGeneral.cpp index 7d9c60a7..ae5682ec 100644 --- a/SandboxiePlus/SandMan/Windows/OptionsGeneral.cpp +++ b/SandboxiePlus/SandMan/Windows/OptionsGeneral.cpp @@ -892,12 +892,12 @@ void COptionsWindow::OnBrowsePath() if (Value.isEmpty()) return; - QString Name = QInputDialog::getText(this, "Sandboxie-Plus", tr("Please enter a menu title"), QLineEdit::Normal); + QString Name = QInputDialog::getText(this, "Sandboxie-Plus", tr("Please enter a menu title"), QLineEdit::Normal, Split2(Value, "\\", true).second); if (Name.isEmpty()) return; CSandBoxPlus* pBoxEx = qobject_cast(m_pBox.data()); - AddRunItem(Name, "", "\"" + (pBoxEx ? Value.replace(pBoxEx->GetFileRoot(), "%BoxRoot%", Qt::CaseInsensitive) : Value) + "\""); + AddRunItem(Name, "", "\"" + (pBoxEx ? pBoxEx->MakeBoxCommand(Value) : Value) + "\""); m_GeneralChanged = true; OnOptChanged(); }