Refactor duplicated code patterns in context menu and utility functions #1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses significant code duplication in the Sandboxie codebase by consolidating similar functions and patterns into reusable helper functions.
Changes Made
1. Context Menu Functions Refactoring
Consolidated 4 similar context menu functions (
AddContextMenu,AddContextMenu2,AddContextMenu3,AddContextMenu4) that contained nearly identical logic:Before:
After:
New Helper Function:
AddContextMenuHelper()- Handles common logic for creating context menu entriesHasContextMenuHelper()- Checks for context menu existenceRemoveContextMenuHelper()- Removes context menu entries2. Registry Access Pattern Consolidation
Created a helper function to reduce duplicated registry read operations:
Before:
After:
3. Application Directory Path Standardization
Eliminated repeated
QApplication::applicationDirPath().replace("/", "\\")calls:Before:
After:
Impact
Files Modified
SandboxiePlus/QSbieAPI/SbieUtils.cpp- Main refactoring of utility functionsSandboxiePlus/QSbieAPI/SbieUtils.h- Added helper function declarationsSandboxiePlus/SandMan/Windows/SettingsWindow.cpp- Updated to use helper functionsSandboxiePlus/SandMan/Engine/SbieObject.cpp- Updated to use helper functionsSandboxiePlus/SandMan/SandMan.cpp- Updated to use helper functionsTesting
The refactored code maintains the same functionality while improving maintainability. All existing context menu operations, registry access patterns, and path handling continue to work as expected.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.