mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-07-01 16:09:46 +02:00
Compare commits
45 Commits
shawn/Pyth
...
dev/snickl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
987affd483 | ||
|
|
0296370ce9 | ||
|
|
e5d6195d18 | ||
|
|
b560c20e91 | ||
|
|
19185b5fe3 | ||
|
|
7037f3e610 | ||
|
|
977d74a4cb | ||
|
|
85219e0983 | ||
|
|
46f32e6de7 | ||
|
|
0f653eab2d | ||
|
|
1f0758abcd | ||
|
|
30baff093d | ||
|
|
692349f9ba | ||
|
|
5e8afb3850 | ||
|
|
d9725f9d00 | ||
|
|
5bb0366750 | ||
|
|
464d002029 | ||
|
|
feff804199 | ||
|
|
0347ea3432 | ||
|
|
f651d1a611 | ||
|
|
d20ae940d5 | ||
|
|
86860df314 | ||
|
|
d28f312b81 | ||
|
|
f6309ac549 | ||
|
|
c23ba227b4 | ||
|
|
ce2e72832c | ||
|
|
c066cc3deb | ||
|
|
9089ca2ede | ||
|
|
798564eea4 | ||
|
|
738b78c406 | ||
|
|
1cb99e32ef | ||
|
|
95835a4cfa | ||
|
|
4146876d88 | ||
|
|
a6e49c941d | ||
|
|
734c738751 | ||
|
|
22b4dda3aa | ||
|
|
fd399045f7 | ||
|
|
7e3f9f0c3f | ||
|
|
9e4bf1e3e0 | ||
|
|
cc3c3c0367 | ||
|
|
637b58b136 | ||
|
|
6c691f59e8 | ||
|
|
7dfe6c0159 | ||
|
|
543399b62b | ||
|
|
90e81cbfd5 |
16
.github/actions/spell-check/expect.txt
vendored
16
.github/actions/spell-check/expect.txt
vendored
@@ -67,6 +67,7 @@ ARPINSTALLLOCATION
|
||||
ARPPRODUCTICON
|
||||
ARRAYSIZE
|
||||
ARROWKEYS
|
||||
arrowshape
|
||||
asf
|
||||
AShortcut
|
||||
ASingle
|
||||
@@ -204,6 +205,7 @@ comdlg
|
||||
comexp
|
||||
cominterop
|
||||
commandpalette
|
||||
commoncontrols
|
||||
compmgmt
|
||||
COMPOSITIONFULL
|
||||
CONFIGW
|
||||
@@ -537,6 +539,8 @@ HIBYTE
|
||||
hicon
|
||||
HIDEWINDOW
|
||||
Hif
|
||||
highlightbackground
|
||||
highlightthickness
|
||||
HIMAGELIST
|
||||
himl
|
||||
hinst
|
||||
@@ -627,6 +631,7 @@ inetcpl
|
||||
Infobar
|
||||
INFOEXAMPLE
|
||||
Infotip
|
||||
initialfile
|
||||
INITDIALOG
|
||||
INITGUID
|
||||
INITTOLOGFONTSTRUCT
|
||||
@@ -673,6 +678,7 @@ jpnime
|
||||
Jsons
|
||||
jsonval
|
||||
jxr
|
||||
kbmcontrols
|
||||
keybd
|
||||
KEYBDDATA
|
||||
KEYBDINPUT
|
||||
@@ -809,6 +815,7 @@ Metadatas
|
||||
metafile
|
||||
metapackage
|
||||
mfc
|
||||
mfalse
|
||||
Mgmt
|
||||
Microwaved
|
||||
midl
|
||||
@@ -867,6 +874,7 @@ msrc
|
||||
msstore
|
||||
msvcp
|
||||
MTND
|
||||
mtrue
|
||||
MULTIPLEUSE
|
||||
multizone
|
||||
muxc
|
||||
@@ -976,6 +984,7 @@ NTAPI
|
||||
ntdll
|
||||
NTSTATUS
|
||||
NTSYSAPI
|
||||
nullability
|
||||
NULLCURSOR
|
||||
nullonfailure
|
||||
numberbox
|
||||
@@ -1017,6 +1026,8 @@ OWNDC
|
||||
OWNERDRAWFIXED
|
||||
Packagemanager
|
||||
PACL
|
||||
padx
|
||||
pady
|
||||
PAINTSTRUCT
|
||||
PALETTEWINDOW
|
||||
PARENTNOTIFY
|
||||
@@ -1448,6 +1459,7 @@ STYLECHANGING
|
||||
subkeys
|
||||
sublang
|
||||
SUBMODULEUPDATE
|
||||
sug
|
||||
Superbar
|
||||
sut
|
||||
svchost
|
||||
@@ -1520,6 +1532,7 @@ tlc
|
||||
TPMLEFTALIGN
|
||||
TPMRETURNCMD
|
||||
TNP
|
||||
Toggleable
|
||||
Toolhelp
|
||||
toolwindow
|
||||
TOPDOWNDIB
|
||||
@@ -2032,6 +2045,7 @@ metadatamatters
|
||||
middleclickaction
|
||||
MIIM
|
||||
mikeclayton
|
||||
mikehall
|
||||
minimizebox
|
||||
modelcontextprotocol
|
||||
mousehighlighter
|
||||
@@ -2152,6 +2166,7 @@ taskbar
|
||||
TESTONLY
|
||||
TEXTBOXNEWLINE
|
||||
textextractor
|
||||
textvariable
|
||||
tgamma
|
||||
THEMECHANGED
|
||||
thickframe
|
||||
@@ -2191,6 +2206,7 @@ wft
|
||||
wikimedia
|
||||
wikipedia
|
||||
windowedge
|
||||
WINDOWSAPPRUNTIME
|
||||
windowsml
|
||||
winexe
|
||||
winforms
|
||||
|
||||
3
.github/actions/spell-check/patterns.txt
vendored
3
.github/actions/spell-check/patterns.txt
vendored
@@ -289,3 +289,6 @@ St&yle
|
||||
|
||||
# Microsoft Store URLs and product IDs
|
||||
ms-windows-store://\S+
|
||||
|
||||
# ANSI color codes
|
||||
(?:\\(?:u00|x)1[Bb]|\\03[1-7]|\x1b|\\u\{1[Bb]\})\[\d+(?:;\d+)*m
|
||||
|
||||
2
.github/copilot-instructions.md
vendored
2
.github/copilot-instructions.md
vendored
@@ -33,4 +33,4 @@ These are auto-applied based on file location:
|
||||
## Detailed Documentation
|
||||
|
||||
- [Architecture](../doc/devdocs/core/architecture.md)
|
||||
- [Coding Style](../doc/devdocs/development/style.md)
|
||||
- [Coding Style](../doc/devdocs/development/style.md)
|
||||
@@ -33,7 +33,7 @@ Generated Files/ReleaseNotes/
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- GitHub CLI (`gh`) installed and authenticated
|
||||
- **GitHub CLI (`gh`) installed and authenticated** — The collection script uses `gh pr view` and `gh api graphql` to fetch PR metadata and co-author information. Run `gh auth status` to verify; if not logged in, run `gh auth login` first. See [Step 1.0.0](./references/step1-collection.md) for details.
|
||||
- MCP Server: github-mcp-server installed
|
||||
- GitHub Copilot code review enabled for the org/repo
|
||||
|
||||
@@ -49,6 +49,10 @@ Generated Files/ReleaseNotes/
|
||||
|
||||
```
|
||||
┌────────────────────────────────┐
|
||||
│ 1.0 Verify gh auth + MemberList │
|
||||
└────────────────────────────────┘
|
||||
↓
|
||||
┌────────────────────────────────┐
|
||||
│ 1.1 Collect PRs (stable range) │
|
||||
└────────────────────────────────┘
|
||||
↓
|
||||
@@ -85,6 +89,7 @@ Generated Files/ReleaseNotes/
|
||||
|
||||
| Step | Action | Details |
|
||||
|------|--------|---------|
|
||||
| 1.0 | Verify prerequisites | `gh auth status` must pass; generate MemberList.md |
|
||||
| 1.1 | Collect PRs | From previous release tag on `stable` branch → `sorted_prs.csv` |
|
||||
| 1.2 | Assign Milestones | Ensure all PRs have correct milestone |
|
||||
| 2.1–2.4 | Label PRs | Auto-suggest + human label low-confidence |
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
- Added mouse button actions so you can choose what left, right, or middle click does. Thanks [@PesBandi](https://github.com/PesBandi)!
|
||||
- Added mouse button actions so you can choose what left, right, or middle click does in [#1234](https://github.com/microsoft/PowerToys/pull/1234) by [@PesBandi](https://github.com/PesBandi)
|
||||
|
||||
- Aligned window styling with current Windows theme for a cleaner look. Thanks [@sadirano](https://github.com/sadirano)!
|
||||
- Aligned window styling with current Windows theme for a cleaner look in [#1235](https://github.com/microsoft/PowerToys/pull/1235) by [@sadirano](https://github.com/sadirano)
|
||||
|
||||
- Ensured screen readers are notified when the selected item in the list changes for better accessibility.
|
||||
- Ensured screen readers are notified when the selected item in the list changes for better accessibility in [#1236](https://github.com/microsoft/PowerToys/pull/1236)
|
||||
|
||||
- Implemented configurable UI test pipeline that can use pre-built official releases instead of building everything from scratch, reducing test execution time from 2+ hours.
|
||||
- Implemented configurable UI test pipeline that can use pre-built official releases instead of building everything from scratch, reducing test execution time from 2+ hours in [#1237](https://github.com/microsoft/PowerToys/pull/1237)
|
||||
|
||||
- Fixed Alt+Left Arrow navigation not working when search box contains text. Thanks [@jiripolasek](https://github.com/jiripolasek)!
|
||||
- Fixed Alt+Left Arrow navigation not working when search box contains text in [#1238](https://github.com/microsoft/PowerToys/pull/1238) by [@jiripolasek](https://github.com/jiripolasek)
|
||||
@@ -1,6 +1,7 @@
|
||||
# Step 1: Collection and Milestones
|
||||
|
||||
## 1.0 To-do
|
||||
- 1.0.0 Verify GitHub CLI authentication (REQUIRED)
|
||||
- 1.0.1 Generate MemberList.md (REQUIRED)
|
||||
- 1.1 Collect PRs
|
||||
- 1.2 Assign Milestones (REQUIRED)
|
||||
@@ -20,6 +21,34 @@
|
||||
|
||||
---
|
||||
|
||||
## 1.0.0 Verify GitHub CLI Authentication (REQUIRED)
|
||||
|
||||
⚠️ **BLOCKING:** The collection script requires an authenticated `gh` CLI to fetch PR metadata and co-author information via GitHub's GraphQL API. Without authentication, PR data and `NeedThanks` attribution will be incomplete.
|
||||
|
||||
### Check authentication status
|
||||
|
||||
```powershell
|
||||
gh auth status
|
||||
```
|
||||
|
||||
**If authenticated:** You'll see `Logged in to github.com account <username>`. Proceed to 1.0.1.
|
||||
|
||||
**If NOT authenticated:** Run the login flow before continuing:
|
||||
|
||||
```powershell
|
||||
# Interactive login (opens browser for OAuth)
|
||||
gh auth login --hostname github.com --web
|
||||
|
||||
# Or use a personal access token
|
||||
gh auth login --with-token <<< "YOUR_GITHUB_TOKEN"
|
||||
```
|
||||
|
||||
**Required scopes:** `repo` (for reading PR data and assigning milestones)
|
||||
|
||||
After login, verify again with `gh auth status` and confirm exit code 0.
|
||||
|
||||
---
|
||||
|
||||
## 1.0.1 Generate MemberList.md (REQUIRED)
|
||||
|
||||
Create `Generated Files/ReleaseNotes/MemberList.md` from the **PowerToys core team** section in [COMMUNITY.md](../../../COMMUNITY.md).
|
||||
@@ -80,6 +109,8 @@ The script detects both merge commits (`Merge pull request #12345`) and squash c
|
||||
**Output** (in `Generated Files/ReleaseNotes/`):
|
||||
- `milestone_prs.json` - raw PR data
|
||||
- `sorted_prs.csv` - sorted PR list with columns: Id, Title, Labels, Author, Url, Body, CopilotSummary, NeedThanks
|
||||
- `Author`: Comma-separated list of all contributors (PR opener + co-authors from commit trailers)
|
||||
- `NeedThanks`: Comma-separated list of external contributors to thank (excludes core team members from MemberList.md). Empty string means no thanks needed.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ For each CSV in `Generated Files/ReleaseNotes/grouped_csv/`, create a markdown f
|
||||
- Use the “Verb-ed + Scenario + Impact” sentence structure—make readers think, “That’s exactly what I need” or “Yes, that’s an awesome fix.”; The "impact" can be end-user focused (written to convey user excitement) or technical (performance/stability) when user-facing impact is minimal.
|
||||
- If nothing special on impact or unclear impact, mark as needing human summary
|
||||
- Source from Title, Body, and CopilotSummary (prefer CopilotSummary when available)
|
||||
- If the column `NeedThanks` in CSV is `True`, append: `Thanks [@Author](https://github.com/Author)!`
|
||||
- The `NeedThanks` column contains a comma-separated list of external contributor usernames who should be thanked (empty = no thanks needed, all authors are core team). For each non-empty `NeedThanks` value, append thanks for **every** listed contributor: `Thanks [@user1](https://github.com/user1)!` for a single contributor, or `Thanks [@user1](https://github.com/user1) and [@user2](https://github.com/user2)!` for two, or `Thanks [@user1](https://github.com/user1), [@user2](https://github.com/user2), and [@user3](https://github.com/user3)!` for three or more.
|
||||
- Do NOT include PR numbers in bullet lines
|
||||
- Do NOT mention “security” or “privacy” issues, since these are not known and could be leveraged by attackers in earlier versions. Instead, describe the user-facing scenario, usage, or impact.
|
||||
- If confidence < 70%, write: `Human Summary Needed: <PR full link>`
|
||||
@@ -72,13 +72,13 @@ Some items in the Development section may overlap and should be moved to the Mod
|
||||
|
||||
## Advanced Paste
|
||||
|
||||
- Wrapped paste option lists in a single ScrollViewer
|
||||
- Added image input handling for AI-powered transformations
|
||||
- Wrapped paste option lists in a single ScrollViewer in [#5678](https://github.com/microsoft/PowerToys/pull/5678)
|
||||
- Added image input handling for AI-powered transformations in [#5679](https://github.com/microsoft/PowerToys/pull/5679)
|
||||
...
|
||||
|
||||
## Awake
|
||||
|
||||
- Fixed timed mode expiration. Thanks [@daverayment](https://github.com/daverayment)!
|
||||
- Fixed timed mode expiration in [#5680](https://github.com/microsoft/PowerToys/pull/5680) by [@daverayment](https://github.com/daverayment)
|
||||
...
|
||||
|
||||
---
|
||||
|
||||
@@ -42,30 +42,7 @@ param(
|
||||
[string]$OutputJson = "milestone_prs.json"
|
||||
)
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Dump merged PR information whose merge commits are reachable from EndCommit but not from StartCommit.
|
||||
.DESCRIPTION
|
||||
Uses git rev-list to compute commits in the (StartCommit, EndCommit] range, extracts PR numbers from merge commit messages,
|
||||
queries GitHub (gh CLI) for details, then outputs a CSV.
|
||||
|
||||
PR merge commit messages in PowerToys generally contain patterns like:
|
||||
Merge pull request #12345 from ...
|
||||
|
||||
.EXAMPLE
|
||||
pwsh ./dump-prs-since-commit.ps1 -StartCommit 0123abcd -Branch stable
|
||||
|
||||
.EXAMPLE
|
||||
pwsh ./dump-prs-since-commit.ps1 -StartCommit 0123abcd -EndCommit 89ef7654 -OutputCsv changes.csv
|
||||
|
||||
.NOTES
|
||||
Requires: gh CLI authenticated; git available in working directory (must be inside PowerToys repo clone).
|
||||
CopilotSummary behavior:
|
||||
- Attempts to locate the latest GitHub Copilot authored review (preferred).
|
||||
- If no review is found, lazily fetches PR comments to look for a Copilot-authored comment.
|
||||
- Normalizes whitespace and strips newlines. Empty when no Copilot activity detected.
|
||||
- Run with -Verbose to see whether the summary came from a 'review' or 'comment' source.
|
||||
#>
|
||||
# (See top-level synopsis above for full documentation)
|
||||
|
||||
function Write-Info($msg) { Write-Host $msg -ForegroundColor Cyan }
|
||||
function Write-Warn($msg) { Write-Host $msg -ForegroundColor Yellow }
|
||||
@@ -151,11 +128,11 @@ catch {
|
||||
}
|
||||
|
||||
Write-Info "Collecting commits between $startSha..$endSha (excluding start, including end)."
|
||||
# Get list of commits reachable from end but not from start.
|
||||
# IMPORTANT: In PowerShell, the .. operator creates a numeric/char range. If $startSha and $endSha look like hex strings,
|
||||
# `$startSha..$endSha` must be passed as a single string argument.
|
||||
$rangeArg = "$startSha..$endSha"
|
||||
$commitList = git rev-list $rangeArg
|
||||
# Get list of commits reachable from end but not from start.
|
||||
# IMPORTANT: In PowerShell, the .. operator creates a numeric/char range. If $startSha and $endSha look like hex strings,
|
||||
# `$startSha..$endSha` must be passed as a single string argument.
|
||||
$rangeArg = "$startSha..$endSha"
|
||||
$commitList = git rev-list $rangeArg
|
||||
|
||||
# Normalize list (filter out empty strings)
|
||||
$normalizedCommits = $commitList | Where-Object { $_ -and $_.Trim() -ne '' }
|
||||
@@ -210,6 +187,63 @@ $prNumbers = $mergeCommits | Select-Object -ExpandProperty Pr -Unique | Sort-Obj
|
||||
Write-Info ("Found {0} unique PRs: {1}" -f $prNumbers.Count, ($prNumbers -join ', '))
|
||||
Write-DebugMsg ("Total merge commits examined: {0}" -f $mergeCommits.Count)
|
||||
|
||||
# Build a map of PR number → list of commit SHAs (for co-author extraction)
|
||||
$prToCommits = @{}
|
||||
foreach ($mc in $mergeCommits) {
|
||||
if (-not $prToCommits.ContainsKey($mc.Pr)) {
|
||||
$prToCommits[$mc.Pr] = @()
|
||||
}
|
||||
$prToCommits[$mc.Pr] += $mc.Sha
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Get all authors (including co-authors) for a set of commits via GitHub GraphQL API.
|
||||
.DESCRIPTION
|
||||
Uses the Commit.authors field in GitHub's GraphQL API which natively includes
|
||||
co-authors (from Co-authored-by trailers). Returns GitHub usernames (login)
|
||||
without any email parsing — GitHub resolves the association for us.
|
||||
|
||||
NOTE: For squash merges this captures all co-authors correctly because GitHub
|
||||
preserves Co-authored-by trailers in the squash commit. For traditional merge
|
||||
commits, only the merger's author is returned — co-authors on individual PR
|
||||
commits are not traversed. This is acceptable because PowerToys primarily uses
|
||||
squash merging.
|
||||
#>
|
||||
function Get-CommitAuthors {
|
||||
param(
|
||||
[string[]]$CommitShas,
|
||||
[string]$RepoFullName = "microsoft/PowerToys"
|
||||
)
|
||||
$parts = $RepoFullName -split '/'
|
||||
$owner = $parts[0]
|
||||
$repoName = $parts[1]
|
||||
$allAuthors = @()
|
||||
|
||||
foreach ($sha in $CommitShas) {
|
||||
try {
|
||||
$query = "{ repository(owner: `"$owner`", name: `"$repoName`") { object(expression: `"$sha`") { ... on Commit { authors(first: 20) { nodes { user { login } name } } } } } }"
|
||||
$result = gh api graphql -f query="$query" 2>$null | ConvertFrom-Json
|
||||
$nodes = $result.data.repository.object.authors.nodes
|
||||
if ($nodes) {
|
||||
foreach ($node in $nodes) {
|
||||
if ($node.user -and $node.user.login) {
|
||||
$allAuthors += $node.user.login
|
||||
} else {
|
||||
# User without a GitHub account (rare) — use display name as fallback
|
||||
Write-DebugMsg "Commit $sha has an author without GitHub account: $($node.name)"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-DebugMsg "GraphQL authors query failed for commit ${sha}: $_"
|
||||
}
|
||||
}
|
||||
|
||||
return $allAuthors | Select-Object -Unique
|
||||
}
|
||||
|
||||
# Query GitHub for each PR
|
||||
$prDetails = @()
|
||||
function Get-CopilotSummaryFromPrJson {
|
||||
@@ -307,22 +341,45 @@ foreach ($pr in $prNumbers) {
|
||||
$bodyValue = if ($json.body) { ($json.body -replace "`r", '') -replace "`n", ' ' } else { '' }
|
||||
$bodyValue = $bodyValue -replace '\s+', ' '
|
||||
|
||||
# Determine if author needs thanks (not in member list)
|
||||
# Collect all contributors: PR author + co-authors from commit messages
|
||||
$authorLogin = $json.author.login
|
||||
$needThanks = $true
|
||||
if ($memberList.Count -gt 0 -and $authorLogin) {
|
||||
$needThanks = -not ($memberList -contains $authorLogin)
|
||||
$allContributors = @($authorLogin)
|
||||
|
||||
# Extract all authors (including co-authors) from associated commits via GitHub GraphQL API
|
||||
if ($prToCommits.ContainsKey([int]$pr)) {
|
||||
$commitAuthors = Get-CommitAuthors -CommitShas $prToCommits[[int]$pr] -RepoFullName $Repo
|
||||
if ($commitAuthors) {
|
||||
$allContributors += $commitAuthors
|
||||
}
|
||||
}
|
||||
|
||||
# Deduplicate contributors (case-insensitive)
|
||||
$allContributors = $allContributors | Where-Object { $_ } | Sort-Object -Unique
|
||||
|
||||
# Filter to only external contributors (not in member list) for thanks
|
||||
$externalContributors = @()
|
||||
if ($memberList.Count -gt 0) {
|
||||
$externalContributors = $allContributors | Where-Object { -not ($memberList -contains $_) }
|
||||
} else {
|
||||
$externalContributors = $allContributors
|
||||
}
|
||||
|
||||
# Author column: all contributors (comma-separated)
|
||||
$authorField = ($allContributors -join ', ')
|
||||
|
||||
# NeedThanks column: comma-separated list of external contributors who
|
||||
# deserve thanks attribution. Empty string means no thanks needed.
|
||||
$needThanksField = ($externalContributors -join ', ')
|
||||
|
||||
$prDetails += [PSCustomObject]@{
|
||||
Id = $json.number
|
||||
Title = $json.title
|
||||
Labels = $labelNames
|
||||
Author = $authorLogin
|
||||
Author = $authorField
|
||||
Url = $json.url
|
||||
Body = $bodyValue
|
||||
CopilotSummary = $copilot.Summary
|
||||
NeedThanks = $needThanks
|
||||
NeedThanks = $needThanksField
|
||||
}
|
||||
}
|
||||
catch {
|
||||
|
||||
@@ -106,7 +106,12 @@
|
||||
"PowerToys.SvgThumbnailProvider.dll",
|
||||
"PowerToys.SvgThumbnailProvider.exe",
|
||||
"PowerToys.SvgThumbnailProviderCpp.dll",
|
||||
"PowerToys.KeyboardManager.dll",
|
||||
|
||||
"KeyboardManagerEditor\\PowerToys.KeyboardManagerEditor.exe",
|
||||
"KeyboardManagerEditorUI\\PowerToys.KeyboardManagerEditorUI.exe",
|
||||
"KeyboardManagerEngine\\PowerToys.KeyboardManagerEngine.exe",
|
||||
"PowerToys.KeyboardManagerEditorLibraryWrapper.dll",
|
||||
"WinUI3Apps\\PowerToys.HostsModuleInterface.dll",
|
||||
"WinUI3Apps\\PowerToys.HostsUILib.dll",
|
||||
"WinUI3Apps\\PowerToys.Hosts.dll",
|
||||
|
||||
@@ -9,7 +9,7 @@ schedules:
|
||||
always: false # only run if there's code changes!
|
||||
|
||||
pool:
|
||||
vmImage: windows-2019
|
||||
vmImage: windows-latest
|
||||
|
||||
resources:
|
||||
repositories:
|
||||
|
||||
@@ -17,10 +17,10 @@ $nonDirectoryAssetsItems = Get-ChildItem $targetAssetsDir -Attributes !Directory
|
||||
$directoryAssetsItems = Get-ChildItem $targetAssetsDir -Attributes Directory
|
||||
|
||||
if ($directoryAssetsItems.Count -le 0) {
|
||||
Write-Host -ForegroundColor Red "No directories detected in " $nonDirectoryAssetsItems ". Are you sure this is the right path?`r`n"
|
||||
Write-Host -ForegroundColor Red "ERROR: No directories detected in " $nonDirectoryAssetsItems ". Are you sure this is the right path?`r`n"
|
||||
$totalFailures++;
|
||||
} elseif ($nonDirectoryAssetsItems.Count -gt 0) {
|
||||
Write-Host -ForegroundColor Red "Detected " $nonDirectoryAssetsItems " files in " $targetAssetsDir "`r`n"
|
||||
Write-Host -ForegroundColor Red "ERROR: Detected " $nonDirectoryAssetsItems " files in " $targetAssetsDir ". Each application should use a named subdirectory for assets.`r`n"
|
||||
$totalFailures++;
|
||||
} else {
|
||||
Write-Host -ForegroundColor Green "Only directories detected in " $targetAssetsDir "`r`n"
|
||||
@@ -29,7 +29,7 @@ if ($directoryAssetsItems.Count -le 0) {
|
||||
# Make sure there's no resources.pri file. Each application should use a different name for their own resources file path.
|
||||
$resourcesPriFiles = Get-ChildItem $targetDir -Filter resources.pri
|
||||
if ($resourcesPriFiles.Count -gt 0) {
|
||||
Write-Host -ForegroundColor Red "Detected a resources.pri file in " $targetDir "`r`n"
|
||||
Write-Host -ForegroundColor Red "ERROR: Detected a resources.pri file in " $targetDir ". Each application should use a unique name for its resources file.`r`n"
|
||||
$totalFailures++;
|
||||
} else {
|
||||
Write-Host -ForegroundColor Green "No resources.pri file detected in " $targetDir "`r`n"
|
||||
@@ -38,7 +38,7 @@ if ($resourcesPriFiles.Count -gt 0) {
|
||||
# Each application should have their XAML files in their own paths to avoid these conflicts.
|
||||
$resourcesPriFiles = Get-ChildItem $targetDir -Filter *.xbf
|
||||
if ($resourcesPriFiles.Count -gt 0) {
|
||||
Write-Host -ForegroundColor Red "Detected a .xbf file in " $targetDir "`r`n"
|
||||
Write-Host -ForegroundColor Red "ERROR: Detected a .xbf file in " $targetDir ". Ensure all XAML files are placed in a subdirectory in each application.`r`n"
|
||||
$totalFailures++;
|
||||
} else {
|
||||
Write-Host -ForegroundColor Green "No .xbf files detected in " $targetDir "`r`n"
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<NuGetAuditMode>direct</NuGetAuditMode>
|
||||
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion> <!-- Don't add source revision hash to the product version of binaries. -->
|
||||
<PlatformTarget>$(Platform)</PlatformTarget>
|
||||
<RestoreEnablePackagePruning Condition=" '$(VisualStudioVersion)' == '17.0'">false </RestoreEnablePackagePruning>
|
||||
|
||||
<!-- Enable Microsoft.Testing.Platform -->
|
||||
<EnableMSTestRunner>true</EnableMSTestRunner>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<PackageVersion Include="CommunityToolkit.WinUI.Controls.Sizers" Version="8.2.250402" />
|
||||
<PackageVersion Include="CommunityToolkit.WinUI.Converters" Version="8.2.250402" />
|
||||
<PackageVersion Include="CommunityToolkit.WinUI.Extensions" Version="8.2.250402" />
|
||||
<PackageVersion Include="CommunityToolkit.WinUI.UI.Controls.DataGrid" Version="7.1.2" />
|
||||
<PackageVersion Include="CommunityToolkit.WinUI.UI.Controls.DataGrid" Version="7.1.2" />
|
||||
<PackageVersion Include="CommunityToolkit.Labs.WinUI.Controls.MarkdownTextBlock" Version="0.1.260116-build.2514" />
|
||||
<PackageVersion Include="ControlzEx" Version="6.0.0" />
|
||||
<PackageVersion Include="HelixToolkit" Version="2.24.0" />
|
||||
@@ -40,7 +40,7 @@
|
||||
<!-- Including MessagePack to force version, since it's used by StreamJsonRpc but contains vulnerabilities. After StreamJsonRpc updates the version of MessagePack, we can upgrade StreamJsonRpc instead. -->
|
||||
<PackageVersion Include="MessagePack" Version="3.1.3" />
|
||||
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0" />
|
||||
<PackageVersion Include="Microsoft.CommandPalette.Extensions" Version="0.5.250829002" />
|
||||
<PackageVersion Include="Microsoft.CommandPalette.Extensions" Version="0.9.260303001" />
|
||||
<PackageVersion Include="Microsoft.Data.Sqlite" Version="9.0.10" />
|
||||
<!-- Including Microsoft.Bcl.AsyncInterfaces to force version, since it's used by Microsoft.SemanticKernel. -->
|
||||
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.10" />
|
||||
|
||||
@@ -497,6 +497,31 @@
|
||||
<Project Path="src/modules/keyboardmanager/KeyboardManagerEngine/KeyboardManagerEngine.vcxproj" Id="ba661f5b-1d5a-4ffc-9bf1-fc39df280bdd" />
|
||||
<Project Path="src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardManagerEngineLibrary.vcxproj" Id="e496b7fc-1e99-4bab-849b-0e8367040b02" />
|
||||
</Folder>
|
||||
<Folder Name="/modules/keyboardmanager/MouseUtils/">
|
||||
<Project Path="src/modules/MouseUtils/CursorWrap/CursorWrap.vcxproj" Id="48a1db8c-5df8-4fb3-9e14-2b67f3f2d8b5" />
|
||||
<Project Path="src/modules/MouseUtils/FindMyMouse/FindMyMouse.vcxproj" Id="e94fd11c-0591-456f-899f-efc0ca548336" />
|
||||
<Project Path="src/modules/MouseUtils/MouseHighlighter/MouseHighlighter.vcxproj" Id="782a61be-9d85-4081-b35c-1ccc9dcc1e88" />
|
||||
<Project Path="src/modules/MouseUtils/MouseJump.Common/MouseJump.Common.csproj">
|
||||
<Platform Solution="*|ARM64" Project="ARM64" />
|
||||
<Platform Solution="*|x64" Project="x64" />
|
||||
</Project>
|
||||
<Project Path="src/modules/MouseUtils/MouseJump/MouseJump.vcxproj" Id="8a08d663-4995-40e3-b42c-3f910625f284" />
|
||||
<Project Path="src/modules/MouseUtils/MouseJumpUI/MouseJumpUI.csproj">
|
||||
<Platform Solution="*|ARM64" Project="ARM64" />
|
||||
<Platform Solution="*|x64" Project="x64" />
|
||||
</Project>
|
||||
<Project Path="src/modules/MouseUtils/MousePointerCrosshairs/MousePointerCrosshairs.vcxproj" Id="eae14c0e-7a6b-45da-9080-a7d8c077ba6e" />
|
||||
</Folder>
|
||||
<Folder Name="/modules/keyboardmanager/MouseUtils/Tests/">
|
||||
<Project Path="src/modules/MouseUtils/MouseJump.Common.UnitTests/MouseJump.Common.UnitTests.csproj">
|
||||
<Platform Solution="*|ARM64" Project="ARM64" />
|
||||
<Platform Solution="*|x64" Project="x64" />
|
||||
</Project>
|
||||
<Project Path="src/modules/MouseUtils/MouseUtils.UITests/MouseUtils.UITests.csproj">
|
||||
<Platform Solution="*|ARM64" Project="ARM64" />
|
||||
<Platform Solution="*|x64" Project="x64" />
|
||||
</Project>
|
||||
</Folder>
|
||||
<Folder Name="/modules/keyboardmanager/Tests/">
|
||||
<Project Path="src/modules/keyboardmanager/KeyboardManagerEditorTest/KeyboardManagerEditorTest.vcxproj" Id="62173d9a-6724-4c00-a1c8-fb646480a9ec" />
|
||||
<Project Path="src/modules/keyboardmanager/KeyboardManagerEngineTest/KeyboardManagerEngineTest.vcxproj" Id="7f4b3a60-bc27-45a7-8000-68b0b6ea7466" />
|
||||
@@ -720,31 +745,6 @@
|
||||
<Platform Solution="*|x64" Project="x64" />
|
||||
</Project>
|
||||
</Folder>
|
||||
<Folder Name="/modules/MouseUtils/">
|
||||
<Project Path="src/modules/MouseUtils/CursorWrap/CursorWrap.vcxproj" Id="48a1db8c-5df8-4fb3-9e14-2b67f3f2d8b5" />
|
||||
<Project Path="src/modules/MouseUtils/FindMyMouse/FindMyMouse.vcxproj" Id="e94fd11c-0591-456f-899f-efc0ca548336" />
|
||||
<Project Path="src/modules/MouseUtils/MouseHighlighter/MouseHighlighter.vcxproj" Id="782a61be-9d85-4081-b35c-1ccc9dcc1e88" />
|
||||
<Project Path="src/modules/MouseUtils/MouseJump.Common/MouseJump.Common.csproj">
|
||||
<Platform Solution="*|ARM64" Project="ARM64" />
|
||||
<Platform Solution="*|x64" Project="x64" />
|
||||
</Project>
|
||||
<Project Path="src/modules/MouseUtils/MouseJump/MouseJump.vcxproj" Id="8a08d663-4995-40e3-b42c-3f910625f284" />
|
||||
<Project Path="src/modules/MouseUtils/MouseJumpUI/MouseJumpUI.csproj">
|
||||
<Platform Solution="*|ARM64" Project="ARM64" />
|
||||
<Platform Solution="*|x64" Project="x64" />
|
||||
</Project>
|
||||
<Project Path="src/modules/MouseUtils/MousePointerCrosshairs/MousePointerCrosshairs.vcxproj" Id="eae14c0e-7a6b-45da-9080-a7d8c077ba6e" />
|
||||
</Folder>
|
||||
<Folder Name="/modules/MouseUtils/Tests/">
|
||||
<Project Path="src/modules/MouseUtils/MouseJump.Common.UnitTests/MouseJump.Common.UnitTests.csproj">
|
||||
<Platform Solution="*|ARM64" Project="ARM64" />
|
||||
<Platform Solution="*|x64" Project="x64" />
|
||||
</Project>
|
||||
<Project Path="src/modules/MouseUtils/MouseUtils.UITests/MouseUtils.UITests.csproj">
|
||||
<Platform Solution="*|ARM64" Project="ARM64" />
|
||||
<Platform Solution="*|x64" Project="x64" />
|
||||
</Project>
|
||||
</Folder>
|
||||
<Folder Name="/modules/MouseWithoutBorders/">
|
||||
<Project Path="src/modules/MouseWithoutBorders/App/Helper/MouseWithoutBordersHelper.csproj">
|
||||
<Platform Solution="*|ARM64" Project="ARM64" />
|
||||
|
||||
@@ -141,3 +141,10 @@ Note: The DllHost process loads the DLL only when the context menu is triggered
|
||||
- A signature issue with the MSIX package
|
||||
|
||||
- For development and testing, using the Windows 10 handler can be easier since it doesn't require signing.
|
||||
|
||||
## Restoring Built-in Windows New context menu
|
||||
If the Windows 11 built-in New context menu doesn't reappear on uninstalling PowerToys, some issue with settings etc. here's how to restore the built-in New context menu.
|
||||
|
||||
1. Open Registry Editor
|
||||
1. Go to the key "Computer\HKEY_CURRENT_USER\Software\Classes\Directory\background\ShellEx\ContextMenuHandlers"
|
||||
1. Delete the "New" subkey (i.e. fullpath "Computer\HKEY_CURRENT_USER\Software\Classes\Directory\background\ShellEx\ContextMenuHandlers\New")
|
||||
@@ -1119,6 +1119,35 @@ LExit:
|
||||
return WcaFinalize(er);
|
||||
}
|
||||
|
||||
UINT __stdcall RestoreBuiltInNewContextMenuCA(MSIHANDLE hInstall)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
hr = WcaInitialize(hInstall, "RestoreBuiltInNewContextMenuCA");
|
||||
|
||||
constexpr wchar_t built_in_new_registry_path[] = LR"(Software\Classes\Directory\Background\ShellEx\ContextMenuHandlers\New)";
|
||||
|
||||
HKEY key{};
|
||||
|
||||
if (RegOpenKeyExW(HKEY_CURRENT_USER,
|
||||
built_in_new_registry_path,
|
||||
0,
|
||||
KEY_ALL_ACCESS,
|
||||
&key) != ERROR_SUCCESS)
|
||||
{
|
||||
return WcaFinalize(ERROR_SUCCESS);
|
||||
}
|
||||
|
||||
if (RegDeleteValueW(key, nullptr) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(key);
|
||||
return WcaFinalize(ERROR_SUCCESS);
|
||||
}
|
||||
|
||||
RegCloseKey(key);
|
||||
|
||||
return WcaFinalize(ERROR_SUCCESS);
|
||||
}
|
||||
|
||||
UINT __stdcall TelemetryLogInstallSuccessCA(MSIHANDLE hInstall)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
@@ -7,6 +7,7 @@ EXPORTS
|
||||
ApplyModulesRegistryChangeSetsCA
|
||||
DetectPrevInstallPathCA
|
||||
RemoveScheduledTasksCA
|
||||
RestoreBuiltInNewContextMenuCA
|
||||
TelemetryLogInstallSuccessCA
|
||||
TelemetryLogInstallCancelCA
|
||||
TelemetryLogInstallFailCA
|
||||
|
||||
@@ -161,6 +161,9 @@
|
||||
<!-- Clean Video Conference Mute registry keys that might be around from previous installations. We've deprecated this utility since then. -->
|
||||
<Custom Action="CleanVideoConferenceRegistry" Before="InstallFinalize" Condition="NOT Installed" />
|
||||
|
||||
<!-- Restore built-in "New" context menu in case user disabled it via New+ -->
|
||||
<Custom Action="RestoreBuiltInNewContextMenu" Before="RemoveFiles" Condition="Installed AND (REMOVE="ALL")" />
|
||||
|
||||
</InstallExecuteSequence>
|
||||
|
||||
<CustomAction Id="SetLaunchPowerToysParam" Property="LaunchPowerToys" Value="[INSTALLFOLDER]" />
|
||||
@@ -262,6 +265,8 @@
|
||||
|
||||
<CustomAction Id="SetBundleInstallLocation" Return="ignore" Impersonate="no" Execute="deferred" DllEntry="SetBundleInstallLocationCA" BinaryRef="PTCustomActions" />
|
||||
|
||||
<CustomAction Id="RestoreBuiltInNewContextMenu" Return="ignore" Impersonate="yes" Execute="deferred" DllEntry="RestoreBuiltInNewContextMenuCA" BinaryRef="PTCustomActions" />
|
||||
|
||||
<!-- Close 'PowerToys.exe' before uninstall-->
|
||||
<Property Id="MSIRESTARTMANAGERCONTROL" Value="DisableShutdown" />
|
||||
<Property Id="MSIFASTINSTALL" Value="DisableShutdown" />
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted $(RepoRoot)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h actionRunner.base.rc actionRunner.rc" />
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted '$(RepoRoot)tools\build\convert-resx-to-rc.ps1' '$(MSBuildThisFileDirectory)' resource.base.h resource.h actionRunner.base.rc actionRunner.rc" />
|
||||
</Target>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted $(RepoRoot)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h PowerToys.Update.base.rc PowerToys.Update.rc" />
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted '$(RepoRoot)tools\build\convert-resx-to-rc.ps1' '$(MSBuildThisFileDirectory)' resource.base.h resource.h PowerToys.Update.base.rc PowerToys.Update.rc" />
|
||||
</Target>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:Microsoft.PowerToys.Common.UI.Controls">
|
||||
xmlns:commoncontrols="using:Microsoft.PowerToys.Common.UI.Controls">
|
||||
|
||||
<Style BasedOn="{StaticResource DefaultKeyVisualStyle}" TargetType="local:KeyVisual" />
|
||||
<Style BasedOn="{StaticResource DefaultKeyVisualStyle}" TargetType="commoncontrols:KeyVisual" />
|
||||
|
||||
<Style x:Key="DefaultKeyVisualStyle" TargetType="local:KeyVisual">
|
||||
<Style x:Key="DefaultKeyVisualStyle" TargetType="commoncontrols:KeyVisual">
|
||||
<Setter Property="MinWidth" Value="16" />
|
||||
<Setter Property="AutomationProperties.AccessibilityView" Value="Raw" />
|
||||
<Setter Property="IsTabStop" Value="False" />
|
||||
@@ -25,7 +25,7 @@
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="local:KeyVisual">
|
||||
<ControlTemplate TargetType="commoncontrols:KeyVisual">
|
||||
<Grid
|
||||
x:Name="KeyHolder"
|
||||
MinWidth="{TemplateBinding MinWidth}"
|
||||
@@ -40,7 +40,7 @@
|
||||
<Grid.BackgroundTransition>
|
||||
<BrushTransition Duration="0:0:0.083" />
|
||||
</Grid.BackgroundTransition>
|
||||
<local:KeyCharPresenter
|
||||
<commoncontrols:KeyCharPresenter
|
||||
x:Name="KeyPresenter"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
@@ -87,12 +87,12 @@
|
||||
<Style
|
||||
x:Key="SubtleKeyVisualStyle"
|
||||
BasedOn="{StaticResource DefaultKeyVisualStyle}"
|
||||
TargetType="local:KeyVisual">
|
||||
TargetType="commoncontrols:KeyVisual">
|
||||
<Setter Property="Background" Value="{ThemeResource SubtleFillColorTransparentBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{ThemeResource SubtleFillColorTransparentBrush}" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="local:KeyVisual">
|
||||
<ControlTemplate TargetType="commoncontrols:KeyVisual">
|
||||
<Grid
|
||||
x:Name="KeyHolder"
|
||||
MinWidth="{TemplateBinding MinWidth}"
|
||||
@@ -106,7 +106,7 @@
|
||||
<Grid.BackgroundTransition>
|
||||
<BrushTransition Duration="0:0:0.083" />
|
||||
</Grid.BackgroundTransition>
|
||||
<local:KeyCharPresenter
|
||||
<commoncontrols:KeyCharPresenter
|
||||
x:Name="KeyPresenter"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
@@ -145,14 +145,14 @@
|
||||
<Style
|
||||
x:Key="AccentKeyVisualStyle"
|
||||
BasedOn="{StaticResource DefaultKeyVisualStyle}"
|
||||
TargetType="local:KeyVisual">
|
||||
TargetType="commoncontrols:KeyVisual">
|
||||
<Setter Property="Background" Value="{ThemeResource AccentFillColorDefaultBrush}" />
|
||||
<Setter Property="Foreground" Value="{ThemeResource TextOnAccentFillColorPrimaryBrush}" />
|
||||
<Setter Property="BorderBrush" Value="{ThemeResource AccentControlElevationBorderBrush}" />
|
||||
<Setter Property="BackgroundSizing" Value="OuterBorderEdge" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="local:KeyVisual">
|
||||
<ControlTemplate TargetType="commoncontrols:KeyVisual">
|
||||
<Grid
|
||||
x:Name="KeyHolder"
|
||||
MinWidth="{TemplateBinding MinWidth}"
|
||||
@@ -168,7 +168,7 @@
|
||||
<Grid.BackgroundTransition>
|
||||
<BrushTransition Duration="0:0:0.083" />
|
||||
</Grid.BackgroundTransition>
|
||||
<local:KeyCharPresenter
|
||||
<commoncontrols:KeyCharPresenter
|
||||
x:Name="KeyPresenter"
|
||||
Margin="{TemplateBinding Padding}"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
|
||||
@@ -292,4 +292,8 @@ namespace winrt::PowerToys::GPOWrapper::implementation
|
||||
{
|
||||
return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredRunAtStartupValue());
|
||||
}
|
||||
GpoRuleConfigured GPOWrapper::GetConfiguredNewPlusHideBuiltInNewContextMenuValue()
|
||||
{
|
||||
return static_cast<GpoRuleConfigured>(powertoys_gpo::getConfiguredNewPlusHideBuiltInNewContextMenuValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ namespace winrt::PowerToys::GPOWrapper::implementation
|
||||
static GpoRuleConfigured GetAllowDataDiagnosticsValue();
|
||||
static GpoRuleConfigured GetConfiguredRunAtStartupValue();
|
||||
static GpoRuleConfigured GetConfiguredNewPlusReplaceVariablesValue();
|
||||
static GpoRuleConfigured GetConfiguredNewPlusHideBuiltInNewContextMenuValue();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ namespace PowerToys
|
||||
static GpoRuleConfigured GetAllowDataDiagnosticsValue();
|
||||
static GpoRuleConfigured GetConfiguredRunAtStartupValue();
|
||||
static GpoRuleConfigured GetConfiguredNewPlusReplaceVariablesValue();
|
||||
static GpoRuleConfigured GetConfiguredNewPlusHideBuiltInNewContextMenuValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,4 +287,8 @@ namespace winrt::PowerToys::Interop::implementation
|
||||
{
|
||||
return CommonSharedConstants::POWER_DISPLAY_TERMINATE_APP_MESSAGE;
|
||||
}
|
||||
hstring Constants::OpenNewKeyboardManagerEvent()
|
||||
{
|
||||
return CommonSharedConstants::OPEN_NEW_KEYBOARD_MANAGER_EVENT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ namespace winrt::PowerToys::Interop::implementation
|
||||
static hstring PowerDisplayToggleMessage();
|
||||
static hstring PowerDisplayApplyProfileMessage();
|
||||
static hstring PowerDisplayTerminateAppMessage();
|
||||
static hstring OpenNewKeyboardManagerEvent();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ namespace PowerToys
|
||||
static String PowerDisplayToggleMessage();
|
||||
static String PowerDisplayApplyProfileMessage();
|
||||
static String PowerDisplayTerminateAppMessage();
|
||||
static String OpenNewKeyboardManagerEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,6 +170,9 @@ namespace CommonSharedConstants
|
||||
const wchar_t LIGHT_SWITCH_LIGHT_THEME_EVENT[] = L"Local\\PowerToysLightSwitch-LightThemeEvent-50077121-2ffc-4841-9c86-ab1bd3f9baca";
|
||||
const wchar_t LIGHT_SWITCH_DARK_THEME_EVENT[] = L"Local\\PowerToysLightSwitch-DarkThemeEvent-b3a835c0-eaa2-49b0-b8eb-f793e3df3368";
|
||||
|
||||
// Path to events used by Keyboard Manager
|
||||
const wchar_t OPEN_NEW_KEYBOARD_MANAGER_EVENT[] = L"Local\\PowerToysOpenNewKeyboardManagerEvent-9c1d2e3f-4b5a-6c7d-8e9f-0a1b2c3d4e5f";
|
||||
|
||||
// used from quick access window
|
||||
const wchar_t CMDPAL_SHOW_EVENT[] = L"Local\\PowerToysCmdPal-ShowEvent-62336fcd-8611-4023-9b30-091a6af4cc5a";
|
||||
const wchar_t CMDPAL_EXIT_EVENT[] = L"Local\\PowerToysCmdPal-ExitEvent-eb73f6be-3f22-4b36-aee3-62924ba40bfd";
|
||||
|
||||
@@ -103,6 +103,7 @@ namespace powertoys_gpo
|
||||
const std::wstring POLICY_MWB_POLICY_DEFINED_IP_MAPPING_RULES = L"MwbPolicyDefinedIpMappingRules";
|
||||
const std::wstring POLICY_NEW_PLUS_HIDE_TEMPLATE_FILENAME_EXTENSION = L"NewPlusHideTemplateFilenameExtension";
|
||||
const std::wstring POLICY_NEW_PLUS_REPLACE_VARIABLES = L"NewPlusReplaceVariablesInTemplateFilenames";
|
||||
const std::wstring POLICY_NEW_PLUS_HIDE_BUILT_IN_NEW_CONTEXT_MENU = L"NewPlusHideBuiltInNewContextMenu";
|
||||
|
||||
// Methods used for reading the registry
|
||||
#pragma region ReadRegistryMethods
|
||||
@@ -700,5 +701,10 @@ namespace powertoys_gpo
|
||||
return getConfiguredValue(POLICY_NEW_PLUS_REPLACE_VARIABLES);
|
||||
}
|
||||
|
||||
inline gpo_rule_configured_t getConfiguredNewPlusHideBuiltInNewContextMenuValue()
|
||||
{
|
||||
return getConfiguredValue(POLICY_NEW_PLUS_HIDE_BUILT_IN_NEW_CONTEXT_MENU);
|
||||
}
|
||||
|
||||
#pragma endregion IndividualModuleSettingPolicies
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (c) Microsoft Corporation.
|
||||
Licensed under the MIT License. -->
|
||||
<policyDefinitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" revision="1.19" schemaVersion="1.0" xmlns="http://schemas.microsoft.com/GroupPolicy/2006/07/PolicyDefinitions">
|
||||
<policyDefinitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" revision="1.20" schemaVersion="1.0" xmlns="http://schemas.microsoft.com/GroupPolicy/2006/07/PolicyDefinitions">
|
||||
<policyNamespaces>
|
||||
<target prefix="powertoys" namespace="Microsoft.Policies.PowerToys" />
|
||||
</policyNamespaces>
|
||||
<resources minRequiredRevision="1.19"/><!-- Last changed with PowerToys v0.97.0 -->
|
||||
<resources minRequiredRevision="1.20"/><!-- Last changed with PowerToys v0.98.0 -->
|
||||
<supportedOn>
|
||||
<definitions>
|
||||
<definition name="SUPPORTED_POWERTOYS_0_64_0" displayName="$(string.SUPPORTED_POWERTOYS_0_64_0)"/>
|
||||
@@ -28,6 +28,7 @@
|
||||
<definition name="SUPPORTED_POWERTOYS_0_90_0" displayName="$(string.SUPPORTED_POWERTOYS_0_90_0)"/>
|
||||
<definition name="SUPPORTED_POWERTOYS_0_96_0" displayName="$(string.SUPPORTED_POWERTOYS_0_96_0)"/>
|
||||
<definition name="SUPPORTED_POWERTOYS_0_97_0" displayName="$(string.SUPPORTED_POWERTOYS_0_97_0)"/>
|
||||
<definition name="SUPPORTED_POWERTOYS_0_98_0" displayName="$(string.SUPPORTED_POWERTOYS_0_98_0)"/>
|
||||
<definition name="SUPPORTED_POWERTOYS_0_64_0_TO_0_87_1" displayName="$(string.SUPPORTED_POWERTOYS_0_64_0_TO_0_87_1)"/>
|
||||
</definitions>
|
||||
</supportedOn>
|
||||
@@ -826,5 +827,15 @@
|
||||
<decimal value="0" />
|
||||
</disabledValue>
|
||||
</policy>
|
||||
<policy name="NewPlusHideBuiltInNewContextMenu" class="Both" displayName="$(string.NewPlusHideBuiltInNewContextMenu)" explainText="$(string.NewPlusHideBuiltInNewContextMenuDescription)" key="Software\Policies\PowerToys" valueName="NewPlusHideBuiltInNewContextMenu">
|
||||
<parentCategory ref="NewPlus" />
|
||||
<supportedOn ref="SUPPORTED_POWERTOYS_0_98_0" />
|
||||
<enabledValue>
|
||||
<decimal value="1" />
|
||||
</enabledValue>
|
||||
<disabledValue>
|
||||
<decimal value="0" />
|
||||
</disabledValue>
|
||||
</policy>
|
||||
</policies>
|
||||
</policyDefinitions>
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
<string id="SUPPORTED_POWERTOYS_0_90_0">PowerToys version 0.90.0 or later</string>
|
||||
<string id="SUPPORTED_POWERTOYS_0_96_0">PowerToys version 0.96.0 or later</string>
|
||||
<string id="SUPPORTED_POWERTOYS_0_97_0">PowerToys version 0.97.0 or later</string>
|
||||
<string id="SUPPORTED_POWERTOYS_0_98_0">PowerToys version 0.98.0 or later</string>
|
||||
<string id="SUPPORTED_POWERTOYS_0_64_0_TO_0_87_1">From PowerToys version 0.64.0 until PowerToys version 0.87.1</string>
|
||||
|
||||
<string id="ConfigureAllUtilityGlobalEnabledStateDescription">This policy configures the enabled state for all PowerToys utilities.
|
||||
@@ -238,7 +239,7 @@ If you disable this policy, the setting is disabled and variables in filenames w
|
||||
|
||||
If you don't configure this policy, the user will be able to control the setting and can enable or disable it.
|
||||
</string>
|
||||
|
||||
|
||||
<string id="ConfigureAllUtilityGlobalEnabledState">Configure global utility enabled state</string>
|
||||
<string id="ConfigureEnabledUtilityAdvancedPaste">Advanced Paste: Configure enabled state</string>
|
||||
<string id="ConfigureEnabledUtilityAlwaysOnTop">Always On Top: Configure enabled state</string>
|
||||
@@ -356,6 +357,15 @@ If you disable this policy, users will not be able to select or use Foundry Loca
|
||||
<string id="AllowDiagnosticData">Allow sending diagnostic data</string>
|
||||
<string id="ConfigureRunAtStartup">Configure the run at startup setting</string>
|
||||
<string id="NewPlusReplaceVariablesInTemplateFilenames">Replace variables in template filenames</string>
|
||||
<string id="NewPlusHideBuiltInNewContextMenu">Hide the built-in "New" context menu</string>
|
||||
<string id="NewPlusHideBuiltInNewContextMenuDescription">This policy configures if Windows' built-in New context menu should be hidden on the context menu.
|
||||
|
||||
If you enable this policy, then the built-in New context menu will be hidden, and user can only create new files and folders using New+ and the explorer toolbar New button.
|
||||
|
||||
If you disable this policy, then the build-in New context menu will be displayed as normal in Windows.
|
||||
|
||||
If you don't configure this policy, the user will be able to control the setting and can enable or disable it.
|
||||
</string>
|
||||
</stringTable>
|
||||
|
||||
<presentationTable>
|
||||
@@ -369,4 +379,3 @@ If you disable this policy, users will not be able to select or use Foundry Loca
|
||||
|
||||
</resources>
|
||||
</policyDefinitionResources>
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted ..\..\..\..\tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h AdvancedPaste.base.rc AdvancedPaste.rc" />
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted '..\..\..\..\tools\build\convert-resx-to-rc.ps1' '$(MSBuildThisFileDirectory)' resource.base.h resource.h AdvancedPaste.base.rc AdvancedPaste.rc" />
|
||||
</Target>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted $(RepoRoot)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h EnvironmentVariablesModuleInterface.base.rc EnvironmentVariablesModuleInterface.rc" />
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted '$(RepoRoot)tools\build\convert-resx-to-rc.ps1' '$(MSBuildThisFileDirectory)' resource.base.h resource.h EnvironmentVariablesModuleInterface.base.rc EnvironmentVariablesModuleInterface.rc" />
|
||||
</Target>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted $(RepoRoot)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h FileLocksmithContextMenu.base.rc FileLocksmithContextMenu.rc" />
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted '$(RepoRoot)tools\build\convert-resx-to-rc.ps1' '$(MSBuildThisFileDirectory)' resource.base.h resource.h FileLocksmithContextMenu.base.rc FileLocksmithContextMenu.rc" />
|
||||
</Target>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted $(RepoRoot)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h FileLocksmithExt.base.rc FileLocksmithExt.rc" />
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted '$(RepoRoot)tools\build\convert-resx-to-rc.ps1' '$(MSBuildThisFileDirectory)' resource.base.h resource.h FileLocksmithExt.base.rc FileLocksmithExt.rc" />
|
||||
</Target>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted ..\..\..\..\tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h HostsModuleInterface.base.rc HostsModuleInterface.rc" />
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted '..\..\..\..\tools\build\convert-resx-to-rc.ps1' '$(MSBuildThisFileDirectory)' resource.base.h resource.h HostsModuleInterface.base.rc HostsModuleInterface.rc" />
|
||||
</Target>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
|
||||
@@ -13,13 +13,11 @@
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
@@ -112,12 +110,8 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="COMPLETE_REWRITE_SUMMARY.md" />
|
||||
<None Include="CRITICAL_BUG_ANALYSIS.md" />
|
||||
<None Include="CURSOR_WRAP_FIX_ANALYSIS.md" />
|
||||
<None Include="DEBUG_GUIDE.md" />
|
||||
<None Include="CursorWrapTests\WrapSimulator\test_new_algorithm.py" />
|
||||
<None Include="packages.config" />
|
||||
<None Include="VERTICAL_WRAP_BUG_FIX.md" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
@@ -130,4 +124,4 @@
|
||||
<Error Condition="!Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props'))" />
|
||||
<Error Condition="!Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
</Project>
|
||||
@@ -163,6 +163,39 @@ void CursorWrapCore::UpdateMonitorInfo()
|
||||
Logger::info(L"======= UPDATE MONITOR INFO END =======");
|
||||
}
|
||||
|
||||
void CursorWrapCore::ResetWrapState()
|
||||
{
|
||||
m_hasPreviousPosition = false;
|
||||
m_hasLastWrapDestination = false;
|
||||
m_previousPosition = { LONG_MIN, LONG_MIN };
|
||||
m_lastWrapDestination = { LONG_MIN, LONG_MIN };
|
||||
}
|
||||
|
||||
CursorDirection CursorWrapCore::CalculateDirection(const POINT& currentPos) const
|
||||
{
|
||||
CursorDirection dir = { 0, 0 };
|
||||
if (m_hasPreviousPosition)
|
||||
{
|
||||
dir.dx = currentPos.x - m_previousPosition.x;
|
||||
dir.dy = currentPos.y - m_previousPosition.y;
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
|
||||
bool CursorWrapCore::IsWithinWrapThreshold(const POINT& currentPos) const
|
||||
{
|
||||
if (!m_hasLastWrapDestination)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int dx = currentPos.x - m_lastWrapDestination.x;
|
||||
int dy = currentPos.y - m_lastWrapDestination.y;
|
||||
int distanceSquared = dx * dx + dy * dy;
|
||||
|
||||
return distanceSquared <= (WRAP_DISTANCE_THRESHOLD * WRAP_DISTANCE_THRESHOLD);
|
||||
}
|
||||
|
||||
POINT CursorWrapCore::HandleMouseMove(const POINT& currentPos, bool disableWrapDuringDrag, int wrapMode, bool disableOnSingleMonitor)
|
||||
{
|
||||
// Check if wrapping should be disabled on single monitor
|
||||
@@ -176,6 +209,8 @@ POINT CursorWrapCore::HandleMouseMove(const POINT& currentPos, bool disableWrapD
|
||||
loggedOnce = true;
|
||||
}
|
||||
#endif
|
||||
m_previousPosition = currentPos;
|
||||
m_hasPreviousPosition = true;
|
||||
return currentPos;
|
||||
}
|
||||
|
||||
@@ -185,9 +220,31 @@ POINT CursorWrapCore::HandleMouseMove(const POINT& currentPos, bool disableWrapD
|
||||
#ifdef _DEBUG
|
||||
OutputDebugStringW(L"[CursorWrap] [DRAG] Left mouse button down - skipping wrap\n");
|
||||
#endif
|
||||
m_previousPosition = currentPos;
|
||||
m_hasPreviousPosition = true;
|
||||
return currentPos;
|
||||
}
|
||||
|
||||
// Check distance threshold to prevent rapid oscillation
|
||||
if (IsWithinWrapThreshold(currentPos))
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
OutputDebugStringW(L"[CursorWrap] [THRESHOLD] Cursor within wrap threshold - skipping wrap\n");
|
||||
#endif
|
||||
m_previousPosition = currentPos;
|
||||
m_hasPreviousPosition = true;
|
||||
return currentPos;
|
||||
}
|
||||
|
||||
// Clear wrap destination threshold once cursor moves away
|
||||
if (m_hasLastWrapDestination && !IsWithinWrapThreshold(currentPos))
|
||||
{
|
||||
m_hasLastWrapDestination = false;
|
||||
}
|
||||
|
||||
// Calculate cursor movement direction
|
||||
CursorDirection direction = CalculateDirection(currentPos);
|
||||
|
||||
// Convert int wrapMode to WrapMode enum
|
||||
WrapMode mode = static_cast<WrapMode>(wrapMode);
|
||||
|
||||
@@ -195,6 +252,7 @@ POINT CursorWrapCore::HandleMouseMove(const POINT& currentPos, bool disableWrapD
|
||||
{
|
||||
std::wostringstream oss;
|
||||
oss << L"[CursorWrap] [MOVE] Cursor at (" << currentPos.x << L", " << currentPos.y << L")";
|
||||
oss << L" direction=(" << direction.dx << L", " << direction.dy << L")";
|
||||
|
||||
// Get current monitor and identify which one
|
||||
HMONITOR currentMonitor = MonitorFromPoint(currentPos, MONITOR_DEFAULTTONEAREST);
|
||||
@@ -229,9 +287,9 @@ POINT CursorWrapCore::HandleMouseMove(const POINT& currentPos, bool disableWrapD
|
||||
// Get current monitor
|
||||
HMONITOR currentMonitor = MonitorFromPoint(currentPos, MONITOR_DEFAULTTONEAREST);
|
||||
|
||||
// Check if cursor is on an outer edge (filtered by wrap mode)
|
||||
// Check if cursor is on an outer edge (filtered by wrap mode and direction)
|
||||
EdgeType edgeType;
|
||||
if (!m_topology.IsOnOuterEdge(currentMonitor, currentPos, edgeType, mode))
|
||||
if (!m_topology.IsOnOuterEdge(currentMonitor, currentPos, edgeType, mode, &direction))
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
static bool lastWasNotOuter = false;
|
||||
@@ -241,6 +299,8 @@ POINT CursorWrapCore::HandleMouseMove(const POINT& currentPos, bool disableWrapD
|
||||
lastWasNotOuter = true;
|
||||
}
|
||||
#endif
|
||||
m_previousPosition = currentPos;
|
||||
m_hasPreviousPosition = true;
|
||||
return currentPos; // Not on an outer edge
|
||||
}
|
||||
|
||||
@@ -278,5 +338,16 @@ POINT CursorWrapCore::HandleMouseMove(const POINT& currentPos, bool disableWrapD
|
||||
}
|
||||
#endif
|
||||
|
||||
// Update tracking state
|
||||
m_previousPosition = currentPos;
|
||||
m_hasPreviousPosition = true;
|
||||
|
||||
// Store wrap destination for threshold checking
|
||||
if (newPos.x != currentPos.x || newPos.y != currentPos.y)
|
||||
{
|
||||
m_lastWrapDestination = newPos;
|
||||
m_hasLastWrapDestination = true;
|
||||
}
|
||||
|
||||
return newPos;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,24 @@
|
||||
#include <string>
|
||||
#include "MonitorTopology.h"
|
||||
|
||||
// Distance threshold to prevent rapid back-and-forth wrapping (in pixels)
|
||||
constexpr int WRAP_DISTANCE_THRESHOLD = 50;
|
||||
|
||||
// Cursor movement direction
|
||||
struct CursorDirection
|
||||
{
|
||||
int dx; // Horizontal movement (positive = right, negative = left)
|
||||
int dy; // Vertical movement (positive = down, negative = up)
|
||||
|
||||
bool IsMovingLeft() const { return dx < 0; }
|
||||
bool IsMovingRight() const { return dx > 0; }
|
||||
bool IsMovingUp() const { return dy < 0; }
|
||||
bool IsMovingDown() const { return dy > 0; }
|
||||
|
||||
// Returns true if horizontal movement is dominant
|
||||
bool IsPrimarilyHorizontal() const { return abs(dx) >= abs(dy); }
|
||||
};
|
||||
|
||||
// Core cursor wrapping engine
|
||||
class CursorWrapCore
|
||||
{
|
||||
@@ -25,11 +43,28 @@ public:
|
||||
size_t GetMonitorCount() const { return m_monitors.size(); }
|
||||
const MonitorTopology& GetTopology() const { return m_topology; }
|
||||
|
||||
// Reset wrap state (call when disabling/re-enabling)
|
||||
void ResetWrapState();
|
||||
|
||||
private:
|
||||
#ifdef _DEBUG
|
||||
std::wstring GenerateTopologyJSON() const;
|
||||
#endif
|
||||
|
||||
// Calculate movement direction from previous position
|
||||
CursorDirection CalculateDirection(const POINT& currentPos) const;
|
||||
|
||||
// Check if cursor is within threshold distance of last wrap position
|
||||
bool IsWithinWrapThreshold(const POINT& currentPos) const;
|
||||
|
||||
std::vector<MonitorInfo> m_monitors;
|
||||
MonitorTopology m_topology;
|
||||
|
||||
// Movement tracking for direction-based edge priority
|
||||
POINT m_previousPosition = { LONG_MIN, LONG_MIN };
|
||||
bool m_hasPreviousPosition = false;
|
||||
|
||||
// Wrap stability: prevent rapid oscillation
|
||||
POINT m_lastWrapDestination = { LONG_MIN, LONG_MIN };
|
||||
bool m_hasLastWrapDestination = false;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<Solution>
|
||||
<Configurations>
|
||||
<Platform Name="x64" />
|
||||
<Platform Name="x86" />
|
||||
</Configurations>
|
||||
<Project Path="CursorLog/CursorLog.vcxproj" Id="646f6684-9f11-42cd-8b35-b2954404f985" />
|
||||
</Solution>
|
||||
@@ -0,0 +1,196 @@
|
||||
// CursorLog.cpp : Monitors mouse position and logs to file with monitor/DPI info
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
#include <Windows.h>
|
||||
#include <ShellScalingApi.h>
|
||||
|
||||
#pragma comment(lib, "Shcore.lib")
|
||||
|
||||
// Global variables
|
||||
std::ofstream g_outputFile;
|
||||
HHOOK g_mouseHook = nullptr;
|
||||
POINT g_lastPosition = { LONG_MIN, LONG_MIN };
|
||||
DWORD g_mainThreadId = 0;
|
||||
|
||||
// Get monitor information for a given point
|
||||
std::string GetMonitorInfo(POINT pt, UINT* dpiX, UINT* dpiY)
|
||||
{
|
||||
HMONITOR hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
|
||||
if (!hMonitor)
|
||||
return "Unknown";
|
||||
|
||||
MONITORINFOEX monitorInfo = {};
|
||||
monitorInfo.cbSize = sizeof(MONITORINFOEX);
|
||||
GetMonitorInfo(hMonitor, &monitorInfo);
|
||||
|
||||
// Get DPI for this monitor
|
||||
if (SUCCEEDED(GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, dpiX, dpiY)))
|
||||
{
|
||||
// DPI retrieved successfully
|
||||
}
|
||||
else
|
||||
{
|
||||
*dpiX = 96;
|
||||
*dpiY = 96;
|
||||
}
|
||||
|
||||
// Convert device name to string using proper wide-to-narrow conversion
|
||||
std::wstring deviceName(monitorInfo.szDevice);
|
||||
int sizeNeeded = WideCharToMultiByte(CP_UTF8, 0, deviceName.c_str(), static_cast<int>(deviceName.length()), nullptr, 0, nullptr, nullptr);
|
||||
std::string result(sizeNeeded, 0);
|
||||
WideCharToMultiByte(CP_UTF8, 0, deviceName.c_str(), static_cast<int>(deviceName.length()), &result[0], sizeNeeded, nullptr, nullptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Calculate scale factor from DPI
|
||||
constexpr double GetScaleFactor(UINT dpi)
|
||||
{
|
||||
return static_cast<double>(dpi) / 96.0;
|
||||
}
|
||||
|
||||
// Low-level mouse hook callback
|
||||
LRESULT CALLBACK LowLevelMouseProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (nCode == HC_ACTION && wParam == WM_MOUSEMOVE)
|
||||
{
|
||||
MSLLHOOKSTRUCT* mouseStruct = reinterpret_cast<MSLLHOOKSTRUCT*>(lParam);
|
||||
POINT pt = mouseStruct->pt;
|
||||
|
||||
// Only log if position changed
|
||||
if (pt.x != g_lastPosition.x || pt.y != g_lastPosition.y)
|
||||
{
|
||||
g_lastPosition = pt;
|
||||
|
||||
UINT dpiX = 96, dpiY = 96;
|
||||
std::string monitorName = GetMonitorInfo(pt, &dpiX, &dpiY);
|
||||
double scale = GetScaleFactor(dpiX);
|
||||
|
||||
if (g_outputFile.is_open())
|
||||
{
|
||||
g_outputFile << monitorName
|
||||
<< "," << pt.x
|
||||
<< "," << pt.y
|
||||
<< "," << dpiX
|
||||
<< "," << static_cast<int>(scale * 100) << "%"
|
||||
<< "\n";
|
||||
g_outputFile.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return CallNextHookEx(g_mouseHook, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
// Console control handler for clean shutdown
|
||||
BOOL WINAPI ConsoleHandler(DWORD ctrlType)
|
||||
{
|
||||
if (ctrlType == CTRL_C_EVENT || ctrlType == CTRL_CLOSE_EVENT)
|
||||
{
|
||||
std::cout << "\nShutting down..." << std::endl;
|
||||
|
||||
if (g_mouseHook)
|
||||
{
|
||||
UnhookWindowsHookEx(g_mouseHook);
|
||||
g_mouseHook = nullptr;
|
||||
}
|
||||
|
||||
if (g_outputFile.is_open())
|
||||
{
|
||||
g_outputFile.close();
|
||||
}
|
||||
|
||||
// Post quit message to the main thread to exit the message loop
|
||||
PostThreadMessage(g_mainThreadId, WM_QUIT, 0, 0);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// Set DPI awareness FIRST, before any other Windows API calls
|
||||
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
||||
|
||||
// Store main thread ID for clean shutdown
|
||||
g_mainThreadId = GetCurrentThreadId();
|
||||
|
||||
// Check command line arguments
|
||||
if (argc != 2)
|
||||
{
|
||||
std::cerr << "Usage: CursorLog.exe <output_path_and_filename>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::filesystem::path outputPath(argv[1]);
|
||||
std::filesystem::path parentPath = outputPath.parent_path();
|
||||
|
||||
// Validate the directory exists
|
||||
if (!parentPath.empty() && !std::filesystem::exists(parentPath))
|
||||
{
|
||||
std::cerr << "Error: The directory '" << parentPath.string() << "' does not exist." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Check if file exists and prompt for overwrite
|
||||
if (std::filesystem::exists(outputPath))
|
||||
{
|
||||
std::cout << "File '" << outputPath.string() << "' already exists. Overwrite? (y/n): ";
|
||||
char response;
|
||||
std::cin >> response;
|
||||
|
||||
if (response != 'y' && response != 'Y')
|
||||
{
|
||||
std::cout << "Operation cancelled." << std::endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Open output file
|
||||
g_outputFile.open(outputPath, std::ios::out | std::ios::trunc);
|
||||
if (!g_outputFile.is_open())
|
||||
{
|
||||
std::cerr << "Error: Unable to create or open file '" << outputPath.string() << "'." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Logging mouse position to: " << outputPath.string() << std::endl;
|
||||
std::cout << "Press Ctrl+C to stop..." << std::endl;
|
||||
|
||||
// Set up console control handler
|
||||
SetConsoleCtrlHandler(ConsoleHandler, TRUE);
|
||||
|
||||
// Install low-level mouse hook
|
||||
g_mouseHook = SetWindowsHookEx(WH_MOUSE_LL, LowLevelMouseProc, nullptr, 0);
|
||||
if (!g_mouseHook)
|
||||
{
|
||||
std::cerr << "Error: Failed to install mouse hook. Error code: " << GetLastError() << std::endl;
|
||||
g_outputFile.close();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Message loop - required for low-level hooks
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, nullptr, 0, 0))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
if (g_mouseHook)
|
||||
{
|
||||
UnhookWindowsHookEx(g_mouseHook);
|
||||
}
|
||||
|
||||
if (g_outputFile.is_open())
|
||||
{
|
||||
g_outputFile.close();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>18.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{646f6684-9f11-42cd-8b35-b2954404f985}</ProjectGuid>
|
||||
<RootNamespace>CursorLog</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard><PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard><PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard><PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp20</LanguageStandard><PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="CursorLog.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="CursorLog.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,287 @@
|
||||
# CursorWrap Simulator
|
||||
|
||||
A Python visualization tool that displays monitor layouts and shows which edges will wrap to other monitors using the exact same logic as the PowerToys CursorWrap implementation.
|
||||
|
||||
## Purpose
|
||||
|
||||
This tool helps you:
|
||||
- Visualize your multi-monitor setup
|
||||
- Identify which screen edges are "outer edges" (edges that don't connect to another monitor)
|
||||
- See where cursor wrapping will occur when you move the cursor to an outer edge
|
||||
- **Find problem areas** where edges have NO wrap destination (shown in red)
|
||||
|
||||
## Requirements
|
||||
|
||||
- Python 3.6+
|
||||
- Tkinter (included with standard Python on Windows)
|
||||
|
||||
## Usage
|
||||
|
||||
### Command Line
|
||||
|
||||
```bash
|
||||
python wrap_simulator.py <path_to_monitor_layout.json>
|
||||
```
|
||||
|
||||
### Without Arguments
|
||||
|
||||
```bash
|
||||
python wrap_simulator.py
|
||||
```
|
||||
|
||||
This opens the application with no layout loaded. Use the "Load JSON" button to select a file.
|
||||
|
||||
## JSON File Format
|
||||
|
||||
The monitor layout JSON file should have this structure:
|
||||
|
||||
```json
|
||||
{
|
||||
"captured_at": "2026-02-16T08:50:34+00:00",
|
||||
"computer_name": "MY-PC",
|
||||
"user_name": "User",
|
||||
"monitor_count": 3,
|
||||
"monitors": [
|
||||
{
|
||||
"left": 0,
|
||||
"top": 0,
|
||||
"right": 2560,
|
||||
"bottom": 1440,
|
||||
"width": 2560,
|
||||
"height": 1440,
|
||||
"dpi": 96,
|
||||
"scaling_percent": 100.0,
|
||||
"primary": true,
|
||||
"device_name": "DISPLAY1"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Understanding the Visualization
|
||||
|
||||
### Monitor Display
|
||||
- **Gray rectangles**: Individual monitors
|
||||
- **Orange border**: Primary monitor
|
||||
- **Labels**: Show monitor index, device name, and resolution
|
||||
|
||||
### Edge Bars (Outside Monitor Boundaries)
|
||||
|
||||
Colored bars are drawn outside each **outer edge** (edges not adjacent to another monitor):
|
||||
|
||||
| Color | Meaning |
|
||||
|-------|---------|
|
||||
| **Yellow** | Edge segment has a wrap destination ✓ |
|
||||
| **Red with stripes** | NO wrap destination - Problem area! ⚠️ |
|
||||
|
||||
The bar outline color indicates the edge type:
|
||||
- Red = Left edge
|
||||
- Teal = Right edge
|
||||
- Blue = Top edge
|
||||
- Green = Bottom edge
|
||||
|
||||
### Interactive Features
|
||||
|
||||
1. **Hover over edge segments**:
|
||||
- See wrap destination info in the status bar
|
||||
- Green arrow shows where the cursor would wrap to
|
||||
- Green dashed rectangle highlights the destination
|
||||
|
||||
2. **Click on edge segments**:
|
||||
- Detailed information appears in the info panel
|
||||
- Shows full problem analysis with reason codes
|
||||
- Explains why wrapping does/doesn't occur
|
||||
- Provides suggestions for fixing problems
|
||||
|
||||
|
||||
3. **Wrap Mode Selection**:
|
||||
- **Both**: Wrap in all directions (default)
|
||||
- **Vertical Only**: Only top/bottom edges wrap
|
||||
- **Horizontal Only**: Only left/right edges wrap
|
||||
|
||||
4. **Export Analysis**:
|
||||
- Click "Export Analysis" to save detailed diagnostic data
|
||||
- Exports to JSON format for use in algorithm development
|
||||
- Includes all problem segments with reason codes and suggestions
|
||||
|
||||
5. **Edge Test Simulation** (NEW):
|
||||
- Click "🧪 Test Edges" to start automated edge testing
|
||||
- Visually animates cursor movement along ALL outer edges
|
||||
- Shows wrap destination for each test point with colored lines:
|
||||
- **Red circle**: Source position on outer edge
|
||||
- **Green circle**: Wrap destination
|
||||
- **Green dashed line**: Connection showing wrap path
|
||||
- **Red X**: No wrap destination (problem area)
|
||||
- Use "New Algorithm" checkbox to toggle between:
|
||||
- **NEW**: Projection-based algorithm (eliminates dead zones)
|
||||
- **OLD**: Direct overlap only (may have dead zones)
|
||||
- Results summary shows per-edge coverage statistics
|
||||
|
||||
## Problem Analysis
|
||||
|
||||
When a segment has no wrap destination, the tool provides detailed analysis:
|
||||
|
||||
### Problem Reason Codes
|
||||
|
||||
| Code | Description |
|
||||
|------|-------------|
|
||||
| `WRAP_MODE_DISABLED` | Edge type disabled by current wrap mode setting |
|
||||
| `NO_OPPOSITE_OUTER_EDGES` | No outer edges of the opposite type exist at all |
|
||||
| `NO_OVERLAPPING_RANGE` | Opposite edges exist but don't cover this coordinate range |
|
||||
| `SINGLE_MONITOR` | Only one monitor - nowhere to wrap to |
|
||||
|
||||
### Diagnostic Details
|
||||
|
||||
For `NO_OVERLAPPING_RANGE` problems, the tool shows:
|
||||
- Distance to the nearest valid wrap destination
|
||||
- List of available opposite edges sorted by distance
|
||||
- Whether the gap is above/below or left/right of the segment
|
||||
- Suggested fixes (extend monitors or adjust positions)
|
||||
|
||||
## Sample Files
|
||||
|
||||
Included sample layouts:
|
||||
|
||||
- `sample_layout.json` - 3 monitors in a row with one offset
|
||||
- `sample_staggered.json` - 3 monitors with staggered vertical positions (shows problem areas)
|
||||
- `sample_with_gap.json` - 2 monitors with a gap between them
|
||||
|
||||
## Exported Analysis Format
|
||||
|
||||
The "Export Analysis" button generates a JSON file with this structure:
|
||||
|
||||
```json
|
||||
{
|
||||
"export_timestamp": "2026-02-16T08:50:34+00:00",
|
||||
"wrap_mode": "BOTH",
|
||||
"monitor_count": 3,
|
||||
"monitors": [...],
|
||||
"outer_edges": [...],
|
||||
"problem_segments": [
|
||||
{
|
||||
"source": {
|
||||
"monitor_index": 0,
|
||||
"monitor_name": "DISPLAY1",
|
||||
"edge_type": "TOP",
|
||||
"edge_position": 200,
|
||||
"segment_range": {"start": 0, "end": 200},
|
||||
"segment_length_px": 200
|
||||
},
|
||||
"analysis": {
|
||||
"reason_code": "NO_OVERLAPPING_RANGE",
|
||||
"description": "No BOTTOM outer edge overlaps...",
|
||||
"suggestion": "To fix: Either extend...",
|
||||
"details": {
|
||||
"gap_to_nearest": 200,
|
||||
"available_opposite_edges": [...]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"summary": {
|
||||
"total_outer_edges": 8,
|
||||
"total_problem_segments": 4,
|
||||
"total_problem_pixels": 800,
|
||||
"problems_by_reason": {"NO_OVERLAPPING_RANGE": 4},
|
||||
"has_problems": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## How CursorWrap Logic Works
|
||||
|
||||
### Original Algorithm (v1)
|
||||
|
||||
1. **Outer Edge Detection**: An edge is "outer" if no other monitor's opposite edge is within 50 pixels AND has sufficient vertical/horizontal overlap
|
||||
|
||||
2. **Wrap Destination**: When cursor reaches an outer edge:
|
||||
- Find the opposite type outer edge (Left→Right, Top→Bottom, etc.)
|
||||
- The destination must overlap with the cursor's perpendicular position
|
||||
- Cursor warps to the furthest matching outer edge
|
||||
|
||||
3. **Problem Areas**: If no opposite outer edge overlaps with a portion of an outer edge, that segment has no wrap destination - the cursor will simply stop at that edge.
|
||||
|
||||
### Enhanced Algorithm (v2) - With Projection
|
||||
|
||||
The enhanced algorithm eliminates dead zones by projecting cursor positions to valid destinations:
|
||||
|
||||
1. **Direct Overlap**: If an opposite outer edge directly overlaps the cursor's perpendicular coordinate, use it (same as v1)
|
||||
|
||||
2. **Nearest Edge Projection**: If no direct overlap exists:
|
||||
- Find the nearest opposite outer edge by coordinate distance
|
||||
- Calculate a projected position using offset-from-boundary approach
|
||||
- The projection preserves relative position similar to how Windows handles monitor transitions
|
||||
|
||||
3. **No Dead Zones**: Every point on every outer edge will have a valid wrap destination
|
||||
|
||||
### Testing the Algorithm
|
||||
|
||||
Use the included test script to validate both algorithms:
|
||||
|
||||
```bash
|
||||
python test_new_algorithm.py [layout_file.json]
|
||||
```
|
||||
|
||||
This compares the old algorithm (with dead zones) against the new algorithm (with projection) and reports coverage.
|
||||
|
||||
## Cursor Log Playback
|
||||
|
||||
The simulator can play back recorded cursor movement logs to visualize how the cursor moves across monitors.
|
||||
|
||||
### Loading a Cursor Log
|
||||
|
||||
1. Click "Load Log" to select a cursor movement log file
|
||||
2. Use the playback controls:
|
||||
- **▶ Play / ⏸ Pause**: Start or pause playback
|
||||
- **⏹ Stop**: Stop and reset to beginning
|
||||
- **⏮ Reset**: Reset to beginning without stopping
|
||||
- **Speed slider**: Adjust playback speed (10-500ms between frames)
|
||||
|
||||
### Log File Format
|
||||
|
||||
The cursor log file is CSV format with the following columns:
|
||||
|
||||
```
|
||||
display_name,x,y,dpi,scaling%
|
||||
```
|
||||
|
||||
Example:
|
||||
```csv
|
||||
\\.\DISPLAY1,1234,567,96,100%
|
||||
\\.\DISPLAY2,2560,720,144,150%
|
||||
\\.\DISPLAY3,-500,800,96,100%
|
||||
```
|
||||
|
||||
- **display_name**: Windows display name (e.g., `\\.\DISPLAY1`)
|
||||
- **x, y**: Screen coordinates
|
||||
- **dpi**: Display DPI
|
||||
- **scaling%**: Display scaling percentage (with or without % sign)
|
||||
|
||||
Lines starting with `#` are treated as comments and ignored.
|
||||
|
||||
### Playback Visualization
|
||||
|
||||
- **Green cursor**: Normal movement within a monitor
|
||||
- **Red cursor with burst effect**: Monitor transition detected
|
||||
- **Blue trail**: Recent cursor movement path (fades over time)
|
||||
- **Dashed red arrow**: Shows transition path between monitors
|
||||
|
||||
The playback automatically slows down when a monitor transition is detected, making it easier to observe wrap behavior.
|
||||
|
||||
### Sample Log File
|
||||
|
||||
A sample cursor log file `sample_cursor_log.csv` is included that demonstrates cursor movement across a three-monitor setup.
|
||||
|
||||
## Architecture
|
||||
|
||||
The Python implementation mirrors the C++ code structure:
|
||||
|
||||
- `MonitorTopology` class: Manages edge-based monitor layout
|
||||
- `MonitorEdge` dataclass: Represents a single edge of a monitor
|
||||
- `EdgeSegment` dataclass: A portion of an edge with wrap info
|
||||
- `CursorLogEntry` dataclass: A single cursor movement log entry
|
||||
- `WrapSimulatorApp`: Tkinter GUI application
|
||||
|
||||
## Integration with PowerToys
|
||||
|
||||
This tool is designed to validate and debug the CursorWrap feature. The JSON files can be generated by the debug build of CursorWrap or created manually for testing specific configurations.
|
||||
@@ -0,0 +1,110 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script to validate the new projection-based wrapping algorithm.
|
||||
"""
|
||||
|
||||
import json
|
||||
import sys
|
||||
from wrap_simulator import MonitorTopology, MonitorInfo, WrapMode
|
||||
|
||||
def test_layout(layout_file: str):
|
||||
"""Test a monitor layout with both old and new algorithms."""
|
||||
|
||||
# Load the layout
|
||||
with open(layout_file, 'r') as f:
|
||||
layout = json.load(f)
|
||||
|
||||
# Create monitor info objects
|
||||
monitors = []
|
||||
for i, m in enumerate(layout['monitors']):
|
||||
monitors.append(MonitorInfo(
|
||||
left=m['left'], top=m['top'], right=m['right'], bottom=m['bottom'],
|
||||
width=m['width'], height=m['height'], dpi=m.get('dpi', 96),
|
||||
scaling_percent=m.get('scaling_percent', 100), primary=m.get('primary', False),
|
||||
device_name=m.get('device_name', f'DISPLAY{i+1}'), monitor_id=i
|
||||
))
|
||||
|
||||
# Initialize topology
|
||||
topology = MonitorTopology()
|
||||
topology.initialize(monitors)
|
||||
|
||||
print(f"Layout: {layout_file}")
|
||||
print(f"Monitors: {len(monitors)}")
|
||||
print(f"Outer edges: {len(topology.outer_edges)}")
|
||||
|
||||
# Validate with OLD algorithm
|
||||
print("\n--- OLD Algorithm (may have dead zones) ---")
|
||||
old_problems = 0
|
||||
old_problem_details = []
|
||||
for edge in topology.outer_edges:
|
||||
segments = topology.get_edge_segments_with_wrap_info(edge, WrapMode.BOTH)
|
||||
for seg in segments:
|
||||
if not seg.has_wrap_destination:
|
||||
length = seg.end - seg.start
|
||||
old_problems += length
|
||||
detail = f"Mon {edge.monitor_index} {edge.edge_type.name} [{seg.start}-{seg.end}] ({length}px)"
|
||||
old_problem_details.append(detail)
|
||||
print(f" PROBLEM: {detail}")
|
||||
print(f"Total problematic pixels: {old_problems}")
|
||||
|
||||
# Validate with NEW algorithm
|
||||
print("\n--- NEW Algorithm (with projection) ---")
|
||||
result = topology.validate_all_edges_have_destinations(WrapMode.BOTH)
|
||||
print(f"Total edge length: {result['total_edge_length']}px")
|
||||
print(f"Covered: {result['covered_length']}px ({result['coverage_percent']:.1f}%)")
|
||||
print(f"Uncovered: {result['uncovered_length']}px")
|
||||
print(f"Fully covered: {result['is_fully_covered']}")
|
||||
|
||||
if result['problem_areas']:
|
||||
for prob in result['problem_areas']:
|
||||
print(f" PROBLEM: {prob}")
|
||||
|
||||
# Summary
|
||||
print("\n--- COMPARISON ---")
|
||||
print(f"Old algorithm dead zones: {old_problems}px")
|
||||
print(f"New algorithm dead zones: {result['uncovered_length']}px")
|
||||
if old_problems > 0 and result['uncovered_length'] == 0:
|
||||
print("SUCCESS: New algorithm eliminates all dead zones!")
|
||||
elif result['uncovered_length'] > 0:
|
||||
print("WARNING: New algorithm still has dead zones")
|
||||
else:
|
||||
print("Both algorithms have no dead zones for this layout")
|
||||
|
||||
return result['is_fully_covered']
|
||||
|
||||
|
||||
def main():
|
||||
layout_files = [
|
||||
'mikehall_monitor_layout.json',
|
||||
'sample_layout.json',
|
||||
'sample_staggered.json',
|
||||
]
|
||||
|
||||
# Allow specifying layout on command line
|
||||
if len(sys.argv) > 1:
|
||||
layout_files = sys.argv[1:]
|
||||
|
||||
all_passed = True
|
||||
for layout_file in layout_files:
|
||||
try:
|
||||
print(f"\n{'='*60}")
|
||||
passed = test_layout(layout_file)
|
||||
if not passed:
|
||||
all_passed = False
|
||||
except FileNotFoundError:
|
||||
print(f"File not found: {layout_file}")
|
||||
except Exception as e:
|
||||
print(f"Error testing {layout_file}: {e}")
|
||||
all_passed = False
|
||||
|
||||
print(f"\n{'='*60}")
|
||||
if all_passed:
|
||||
print("ALL TESTS PASSED")
|
||||
else:
|
||||
print("SOME TESTS FAILED")
|
||||
|
||||
return 0 if all_passed else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "pch.h"
|
||||
#include "MonitorTopology.h"
|
||||
#include "CursorWrapCore.h" // For CursorDirection struct
|
||||
#include "../../../common/logger/logger.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
@@ -13,6 +14,7 @@ void MonitorTopology::Initialize(const std::vector<MonitorInfo>& monitors)
|
||||
Logger::info(L"======= TOPOLOGY INITIALIZATION START =======");
|
||||
Logger::info(L"Initializing edge-based topology for {} monitors", monitors.size());
|
||||
|
||||
|
||||
m_monitors = monitors;
|
||||
m_outerEdges.clear();
|
||||
m_edgeMap.clear();
|
||||
@@ -163,10 +165,80 @@ bool MonitorTopology::EdgesAreAdjacent(const MonitorEdge& edge1, const MonitorEd
|
||||
int overlapStart = max(edge1.start, edge2.start);
|
||||
int overlapEnd = min(edge1.end, edge2.end);
|
||||
|
||||
|
||||
return overlapEnd > overlapStart + tolerance;
|
||||
}
|
||||
|
||||
bool MonitorTopology::IsOnOuterEdge(HMONITOR monitor, const POINT& cursorPos, EdgeType& outEdgeType, WrapMode wrapMode) const
|
||||
EdgeType MonitorTopology::PrioritizeEdgeByDirection(const std::vector<EdgeType>& candidates,
|
||||
const CursorDirection* direction) const
|
||||
{
|
||||
if (candidates.empty())
|
||||
{
|
||||
return EdgeType::Left; // Should not happen, but return a default
|
||||
}
|
||||
|
||||
if (candidates.size() == 1 || direction == nullptr)
|
||||
{
|
||||
return candidates[0];
|
||||
}
|
||||
|
||||
// Prioritize based on movement direction
|
||||
// If moving primarily horizontally, prefer horizontal edges (Left/Right)
|
||||
// If moving primarily vertically, prefer vertical edges (Top/Bottom)
|
||||
|
||||
if (direction->IsPrimarilyHorizontal())
|
||||
{
|
||||
// Prefer Left if moving left, Right if moving right
|
||||
if (direction->IsMovingLeft())
|
||||
{
|
||||
for (EdgeType edge : candidates)
|
||||
{
|
||||
if (edge == EdgeType::Left) return edge;
|
||||
}
|
||||
}
|
||||
else if (direction->IsMovingRight())
|
||||
{
|
||||
for (EdgeType edge : candidates)
|
||||
{
|
||||
if (edge == EdgeType::Right) return edge;
|
||||
}
|
||||
}
|
||||
// Fall back to any horizontal edge
|
||||
for (EdgeType edge : candidates)
|
||||
{
|
||||
if (edge == EdgeType::Left || edge == EdgeType::Right) return edge;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Prefer Top if moving up, Bottom if moving down
|
||||
if (direction->IsMovingUp())
|
||||
{
|
||||
for (EdgeType edge : candidates)
|
||||
{
|
||||
if (edge == EdgeType::Top) return edge;
|
||||
}
|
||||
}
|
||||
else if (direction->IsMovingDown())
|
||||
{
|
||||
for (EdgeType edge : candidates)
|
||||
{
|
||||
if (edge == EdgeType::Bottom) return edge;
|
||||
}
|
||||
}
|
||||
// Fall back to any vertical edge
|
||||
for (EdgeType edge : candidates)
|
||||
{
|
||||
if (edge == EdgeType::Top || edge == EdgeType::Bottom) return edge;
|
||||
}
|
||||
}
|
||||
|
||||
// Default to first candidate
|
||||
return candidates[0];
|
||||
}
|
||||
|
||||
bool MonitorTopology::IsOnOuterEdge(HMONITOR monitor, const POINT& cursorPos, EdgeType& outEdgeType,
|
||||
WrapMode wrapMode, const CursorDirection* direction) const
|
||||
{
|
||||
RECT monitorRect;
|
||||
if (!GetMonitorRect(monitor, monitorRect))
|
||||
@@ -248,13 +320,40 @@ bool MonitorTopology::IsOnOuterEdge(HMONITOR monitor, const POINT& cursorPos, Ed
|
||||
return false;
|
||||
}
|
||||
|
||||
// Try each candidate edge and return first with valid wrap destination
|
||||
// Prioritize candidates by movement direction at corners
|
||||
EdgeType prioritizedEdge = PrioritizeEdgeByDirection(candidateEdges, direction);
|
||||
|
||||
// Get the source edge info
|
||||
auto sourceIt = m_edgeMap.find({monitorIndex, prioritizedEdge});
|
||||
if (sourceIt == m_edgeMap.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use the new FindNearestOppositeEdge which handles non-overlapping regions
|
||||
int cursorCoord = (prioritizedEdge == EdgeType::Left || prioritizedEdge == EdgeType::Right)
|
||||
? cursorPos.y : cursorPos.x;
|
||||
OppositeEdgeResult result = FindNearestOppositeEdge(prioritizedEdge, cursorCoord, sourceIt->second);
|
||||
|
||||
if (result.found)
|
||||
{
|
||||
outEdgeType = prioritizedEdge;
|
||||
return true;
|
||||
}
|
||||
|
||||
// If prioritized edge didn't work, try other candidates
|
||||
for (EdgeType candidate : candidateEdges)
|
||||
{
|
||||
MonitorEdge oppositeEdge = FindOppositeOuterEdge(candidate,
|
||||
(candidate == EdgeType::Left || candidate == EdgeType::Right) ? cursorPos.y : cursorPos.x);
|
||||
|
||||
if (oppositeEdge.monitorIndex >= 0)
|
||||
if (candidate == prioritizedEdge) continue;
|
||||
|
||||
auto it = m_edgeMap.find({monitorIndex, candidate});
|
||||
if (it == m_edgeMap.end()) continue;
|
||||
|
||||
int coord = (candidate == EdgeType::Left || candidate == EdgeType::Right)
|
||||
? cursorPos.y : cursorPos.x;
|
||||
OppositeEdgeResult altResult = FindNearestOppositeEdge(candidate, coord, it->second);
|
||||
|
||||
if (altResult.found)
|
||||
{
|
||||
outEdgeType = candidate;
|
||||
return true;
|
||||
@@ -280,16 +379,14 @@ POINT MonitorTopology::GetWrapDestination(HMONITOR fromMonitor, const POINT& cur
|
||||
}
|
||||
|
||||
const MonitorEdge& fromEdge = it->second;
|
||||
|
||||
// Get cursor coordinate perpendicular to the edge
|
||||
int cursorCoord = (edgeType == EdgeType::Left || edgeType == EdgeType::Right) ? cursorPos.y : cursorPos.x;
|
||||
|
||||
// Calculate relative position on current edge (0.0 to 1.0)
|
||||
double relativePos = GetRelativePosition(fromEdge,
|
||||
(edgeType == EdgeType::Left || edgeType == EdgeType::Right) ? cursorPos.y : cursorPos.x);
|
||||
// Use the new FindNearestOppositeEdge which handles non-overlapping regions
|
||||
OppositeEdgeResult oppositeResult = FindNearestOppositeEdge(edgeType, cursorCoord, fromEdge);
|
||||
|
||||
// Find opposite outer edge
|
||||
MonitorEdge oppositeEdge = FindOppositeOuterEdge(edgeType,
|
||||
(edgeType == EdgeType::Left || edgeType == EdgeType::Right) ? cursorPos.y : cursorPos.x);
|
||||
|
||||
if (oppositeEdge.monitorIndex < 0)
|
||||
if (!oppositeResult.found)
|
||||
{
|
||||
// No opposite edge found, wrap within same monitor
|
||||
RECT monitorRect;
|
||||
@@ -321,15 +418,35 @@ POINT MonitorTopology::GetWrapDestination(HMONITOR fromMonitor, const POINT& cur
|
||||
|
||||
if (edgeType == EdgeType::Left || edgeType == EdgeType::Right)
|
||||
{
|
||||
// Horizontal edge -> vertical movement
|
||||
result.x = oppositeEdge.position;
|
||||
result.y = GetAbsolutePosition(oppositeEdge, relativePos);
|
||||
// Horizontal wrapping (Left<->Right edges)
|
||||
result.x = oppositeResult.edge.position;
|
||||
|
||||
if (oppositeResult.requiresProjection)
|
||||
{
|
||||
// Use the pre-calculated projected coordinate for non-overlapping regions
|
||||
result.y = oppositeResult.projectedCoordinate;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Overlapping region - preserve Y coordinate
|
||||
result.y = cursorPos.y;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Vertical edge -> horizontal movement
|
||||
result.y = oppositeEdge.position;
|
||||
result.x = GetAbsolutePosition(oppositeEdge, relativePos);
|
||||
// Vertical wrapping (Top<->Bottom edges)
|
||||
result.y = oppositeResult.edge.position;
|
||||
|
||||
if (oppositeResult.requiresProjection)
|
||||
{
|
||||
// Use the pre-calculated projected coordinate for non-overlapping regions
|
||||
result.x = oppositeResult.projectedCoordinate;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Overlapping region - preserve X coordinate
|
||||
result.x = cursorPos.x;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -387,6 +504,170 @@ MonitorEdge MonitorTopology::FindOppositeOuterEdge(EdgeType fromEdge, int relati
|
||||
return result;
|
||||
}
|
||||
|
||||
OppositeEdgeResult MonitorTopology::FindNearestOppositeEdge(EdgeType fromEdge, int cursorCoordinate,
|
||||
const MonitorEdge& sourceEdge) const
|
||||
{
|
||||
OppositeEdgeResult result;
|
||||
result.found = false;
|
||||
result.requiresProjection = false;
|
||||
result.projectedCoordinate = 0;
|
||||
result.edge.monitorIndex = -1;
|
||||
|
||||
EdgeType targetType;
|
||||
bool findMax; // true = find max position (furthest right/bottom), false = find min (furthest left/top)
|
||||
|
||||
switch (fromEdge)
|
||||
{
|
||||
case EdgeType::Left:
|
||||
targetType = EdgeType::Right;
|
||||
findMax = true;
|
||||
break;
|
||||
case EdgeType::Right:
|
||||
targetType = EdgeType::Left;
|
||||
findMax = false;
|
||||
break;
|
||||
case EdgeType::Top:
|
||||
targetType = EdgeType::Bottom;
|
||||
findMax = true;
|
||||
break;
|
||||
case EdgeType::Bottom:
|
||||
targetType = EdgeType::Top;
|
||||
findMax = false;
|
||||
break;
|
||||
default:
|
||||
return result; // Invalid edge type
|
||||
}
|
||||
|
||||
// First, try to find an edge that directly overlaps the cursor coordinate
|
||||
MonitorEdge directMatch = FindOppositeOuterEdge(fromEdge, cursorCoordinate);
|
||||
if (directMatch.monitorIndex >= 0)
|
||||
{
|
||||
result.found = true;
|
||||
result.requiresProjection = false;
|
||||
result.edge = directMatch;
|
||||
result.projectedCoordinate = cursorCoordinate; // Not used, but set for completeness
|
||||
return result;
|
||||
}
|
||||
|
||||
// No direct overlap - find the nearest opposite edge by coordinate distance
|
||||
// This handles the "dead zone" case where cursor is in a non-overlapping region
|
||||
|
||||
int bestDistance = INT_MAX;
|
||||
MonitorEdge bestEdge = { .monitorIndex = -1 };
|
||||
int bestProjectedCoord = 0;
|
||||
|
||||
for (const auto& edge : m_outerEdges)
|
||||
{
|
||||
if (edge.type != targetType)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Calculate distance from cursor coordinate to this edge's range
|
||||
int distance = 0;
|
||||
int projectedCoord = 0;
|
||||
|
||||
if (cursorCoordinate < edge.start)
|
||||
{
|
||||
// Cursor is before the edge's start - project to edge start with offset
|
||||
distance = edge.start - cursorCoordinate;
|
||||
projectedCoord = edge.start; // Clamp to edge start
|
||||
}
|
||||
else if (cursorCoordinate > edge.end)
|
||||
{
|
||||
// Cursor is after the edge's end - project to edge end with offset
|
||||
distance = cursorCoordinate - edge.end;
|
||||
projectedCoord = edge.end; // Clamp to edge end
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cursor overlaps - this shouldn't happen since we checked direct match
|
||||
distance = 0;
|
||||
projectedCoord = cursorCoordinate;
|
||||
}
|
||||
|
||||
// Choose the best edge: prefer closer edges, and among equals prefer extreme position
|
||||
bool isBetter = false;
|
||||
if (distance < bestDistance)
|
||||
{
|
||||
isBetter = true;
|
||||
}
|
||||
else if (distance == bestDistance && bestEdge.monitorIndex >= 0)
|
||||
{
|
||||
// Same distance - prefer the extreme position (furthest in wrap direction)
|
||||
if ((findMax && edge.position > bestEdge.position) ||
|
||||
(!findMax && edge.position < bestEdge.position))
|
||||
{
|
||||
isBetter = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isBetter)
|
||||
{
|
||||
bestDistance = distance;
|
||||
bestEdge = edge;
|
||||
bestProjectedCoord = projectedCoord;
|
||||
}
|
||||
}
|
||||
|
||||
if (bestEdge.monitorIndex >= 0)
|
||||
{
|
||||
result.found = true;
|
||||
result.requiresProjection = true;
|
||||
result.edge = bestEdge;
|
||||
|
||||
// Calculate projected position using offset-from-boundary approach
|
||||
result.projectedCoordinate = CalculateProjectedPosition(cursorCoordinate, sourceEdge, bestEdge);
|
||||
|
||||
Logger::trace(L"FindNearestOppositeEdge: Non-overlapping wrap from {} to Mon {} edge, cursor={}, projected={}",
|
||||
static_cast<int>(fromEdge), bestEdge.monitorIndex, cursorCoordinate, result.projectedCoordinate);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int MonitorTopology::CalculateProjectedPosition(int cursorCoordinate, const MonitorEdge& sourceEdge,
|
||||
const MonitorEdge& targetEdge) const
|
||||
{
|
||||
// Windows behavior for non-overlapping regions:
|
||||
// When cursor is in a region that doesn't overlap with the target edge,
|
||||
// clamp to the nearest boundary of the target edge.
|
||||
// This matches observed Windows cursor transition behavior.
|
||||
|
||||
// Find the shared boundary region between source and target edges
|
||||
int sharedStart = max(sourceEdge.start, targetEdge.start);
|
||||
int sharedEnd = min(sourceEdge.end, targetEdge.end);
|
||||
|
||||
if (cursorCoordinate >= sharedStart && cursorCoordinate <= sharedEnd)
|
||||
{
|
||||
// Cursor is in shared region - preserve the coordinate exactly
|
||||
return cursorCoordinate;
|
||||
}
|
||||
|
||||
// For non-overlapping regions, clamp to the nearest boundary of the target edge
|
||||
// This matches Windows behavior where the cursor is projected to the closest
|
||||
// valid point on the destination edge
|
||||
int projectedCoord;
|
||||
|
||||
if (cursorCoordinate < sharedStart)
|
||||
{
|
||||
// Cursor is BEFORE the shared region (e.g., above shared area)
|
||||
// Clamp to the start of the target edge (with small offset to stay within bounds)
|
||||
projectedCoord = targetEdge.start + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cursor is AFTER the shared region (e.g., below shared area)
|
||||
// Clamp to the end of the target edge (with small offset to stay within bounds)
|
||||
projectedCoord = targetEdge.end - 1;
|
||||
}
|
||||
|
||||
// Final bounds check
|
||||
projectedCoord = max(targetEdge.start, min(projectedCoord, targetEdge.end - 1));
|
||||
|
||||
return projectedCoord;
|
||||
}
|
||||
|
||||
double MonitorTopology::GetRelativePosition(const MonitorEdge& edge, int coordinate) const
|
||||
{
|
||||
if (edge.end == edge.start)
|
||||
@@ -411,6 +692,7 @@ int MonitorTopology::GetAbsolutePosition(const MonitorEdge& edge, double relativ
|
||||
return static_cast<int>(result);
|
||||
}
|
||||
|
||||
|
||||
std::vector<MonitorTopology::GapInfo> MonitorTopology::DetectMonitorGaps() const
|
||||
{
|
||||
std::vector<GapInfo> gaps;
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
// Forward declaration
|
||||
struct CursorDirection;
|
||||
|
||||
// Monitor information structure
|
||||
struct MonitorInfo
|
||||
{
|
||||
@@ -44,6 +47,15 @@ struct MonitorEdge
|
||||
bool isOuter; // True if no adjacent monitor touches this edge
|
||||
};
|
||||
|
||||
// Result of finding an opposite edge, including projection info for non-overlapping regions
|
||||
struct OppositeEdgeResult
|
||||
{
|
||||
MonitorEdge edge;
|
||||
bool found; // True if an opposite edge was found
|
||||
bool requiresProjection; // True if cursor position needs to be projected (non-overlapping region)
|
||||
int projectedCoordinate; // The calculated coordinate on the target edge
|
||||
};
|
||||
|
||||
// Monitor topology helper - manages edge-based monitor layout
|
||||
struct MonitorTopology
|
||||
{
|
||||
@@ -51,7 +63,9 @@ struct MonitorTopology
|
||||
|
||||
// Check if cursor is on an outer edge of the given monitor
|
||||
// wrapMode filters which edges are considered (Both, VerticalOnly, HorizontalOnly)
|
||||
bool IsOnOuterEdge(HMONITOR monitor, const POINT& cursorPos, EdgeType& outEdgeType, WrapMode wrapMode) const;
|
||||
// direction is used to prioritize edges at corners based on cursor movement
|
||||
bool IsOnOuterEdge(HMONITOR monitor, const POINT& cursorPos, EdgeType& outEdgeType,
|
||||
WrapMode wrapMode, const CursorDirection* direction = nullptr) const;
|
||||
|
||||
// Get the wrap destination point for a cursor on an outer edge
|
||||
POINT GetWrapDestination(HMONITOR fromMonitor, const POINT& cursorPos, EdgeType edgeType) const;
|
||||
@@ -95,12 +109,26 @@ private:
|
||||
// Check if two edges are adjacent (within tolerance)
|
||||
bool EdgesAreAdjacent(const MonitorEdge& edge1, const MonitorEdge& edge2, int tolerance = 50) const;
|
||||
|
||||
// Find the opposite outer edge for wrapping
|
||||
// Find the opposite outer edge for wrapping (original method - for overlapping regions)
|
||||
MonitorEdge FindOppositeOuterEdge(EdgeType fromEdge, int relativePosition) const;
|
||||
|
||||
// Find the nearest opposite outer edge, including projection for non-overlapping regions
|
||||
// This implements Windows-like behavior for cursor transitions
|
||||
OppositeEdgeResult FindNearestOppositeEdge(EdgeType fromEdge, int cursorCoordinate,
|
||||
const MonitorEdge& sourceEdge) const;
|
||||
|
||||
// Calculate projected position for cursor in non-overlapping region
|
||||
// Returns the coordinate on the destination edge using offset-from-boundary approach
|
||||
int CalculateProjectedPosition(int cursorCoordinate, const MonitorEdge& sourceEdge,
|
||||
const MonitorEdge& targetEdge) const;
|
||||
|
||||
// Calculate relative position along an edge (0.0 to 1.0)
|
||||
double GetRelativePosition(const MonitorEdge& edge, int coordinate) const;
|
||||
|
||||
// Convert relative position to absolute coordinate on target edge
|
||||
int GetAbsolutePosition(const MonitorEdge& edge, double relativePosition) const;
|
||||
|
||||
// Prioritize edge candidates based on cursor movement direction
|
||||
EdgeType PrioritizeEdgeByDirection(const std::vector<EdgeType>& candidates,
|
||||
const CursorDirection* direction) const;
|
||||
};
|
||||
|
||||
@@ -54,6 +54,7 @@ namespace
|
||||
const wchar_t JSON_KEY_AUTO_ACTIVATE[] = L"auto_activate";
|
||||
const wchar_t JSON_KEY_DISABLE_WRAP_DURING_DRAG[] = L"disable_wrap_during_drag";
|
||||
const wchar_t JSON_KEY_WRAP_MODE[] = L"wrap_mode";
|
||||
const wchar_t JSON_KEY_ACTIVATION_MODE[] = L"activation_mode";
|
||||
const wchar_t JSON_KEY_DISABLE_ON_SINGLE_MONITOR[] = L"disable_cursor_wrap_on_single_monitor";
|
||||
}
|
||||
|
||||
@@ -83,6 +84,7 @@ private:
|
||||
bool m_disableWrapDuringDrag = true; // Default to true to prevent wrap during drag
|
||||
bool m_disableOnSingleMonitor = false; // Default to false
|
||||
int m_wrapMode = 0; // 0=Both (default), 1=VerticalOnly, 2=HorizontalOnly
|
||||
int m_activationMode = 0; // 0=Always (default), 1=HoldingCtrl (disables wrap), 2=HoldingShift (disables wrap)
|
||||
|
||||
// Mouse hook
|
||||
HHOOK m_mouseHook = nullptr;
|
||||
@@ -430,6 +432,21 @@ private:
|
||||
Logger::warn("Failed to initialize CursorWrap wrap mode from settings. Will use default value (0=Both)");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Parse activation mode
|
||||
auto propertiesObject = settingsObject.GetNamedObject(JSON_KEY_PROPERTIES);
|
||||
if (propertiesObject.HasKey(JSON_KEY_ACTIVATION_MODE))
|
||||
{
|
||||
auto activationModeObject = propertiesObject.GetNamedObject(JSON_KEY_ACTIVATION_MODE);
|
||||
m_activationMode = static_cast<int>(activationModeObject.GetNamedNumber(JSON_KEY_VALUE));
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Logger::warn("Failed to initialize CursorWrap activation mode from settings. Will use default value (0=Always)");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Parse disable on single monitor
|
||||
@@ -672,6 +689,26 @@ private:
|
||||
|
||||
if (g_cursorWrapInstance && g_cursorWrapInstance->m_hookActive)
|
||||
{
|
||||
// Check activation mode to determine if wrapping should be disabled
|
||||
// 0=Always, 1=HoldingCtrl (disables wrap when Ctrl held), 2=HoldingShift (disables wrap when Shift held)
|
||||
int activationMode = g_cursorWrapInstance->m_activationMode;
|
||||
bool disableByKey = false;
|
||||
|
||||
if (activationMode == 1) // HoldingCtrl - disable wrap when Ctrl is held
|
||||
{
|
||||
disableByKey = (GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0;
|
||||
}
|
||||
else if (activationMode == 2) // HoldingShift - disable wrap when Shift is held
|
||||
{
|
||||
disableByKey = (GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0;
|
||||
}
|
||||
|
||||
if (disableByKey)
|
||||
{
|
||||
// Key is held, do not wrap - let normal behavior happen
|
||||
return CallNextHookEx(nullptr, nCode, wParam, lParam);
|
||||
}
|
||||
|
||||
POINT newPos = g_cursorWrapInstance->m_core.HandleMouseMove(
|
||||
currentPos,
|
||||
g_cursorWrapInstance->m_disableWrapDuringDrag,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted $(RepoRoot)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h new.base.rc new.rc" />
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted '$(RepoRoot)tools\build\convert-resx-to-rc.ps1' '$(MSBuildThisFileDirectory)' resource.base.h resource.h new.base.rc new.rc" />
|
||||
</Target>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted $(RepoRoot)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h new.base.rc new.rc" />
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted '$(RepoRoot)tools\build\convert-resx-to-rc.ps1' '$(MSBuildThisFileDirectory)' resource.base.h resource.h new.base.rc new.rc" />
|
||||
</Target>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
|
||||
@@ -18,6 +18,8 @@ namespace newplus::constants::non_localizable
|
||||
|
||||
constexpr WCHAR settings_json_key_template_location[] = L"TemplateLocation";
|
||||
|
||||
constexpr WCHAR settings_json_key_hide_built_in_new[] = L"BuiltInNewHidePreference";
|
||||
|
||||
constexpr WCHAR context_menu_package_name[] = L"NewPlusContextMenu";
|
||||
|
||||
constexpr WCHAR msix_package_name[] = L"NewPlusPackage.msix";
|
||||
|
||||
@@ -4,22 +4,6 @@
|
||||
|
||||
namespace newplus::helpers::filesystem
|
||||
{
|
||||
namespace constants::non_localizable
|
||||
{
|
||||
constexpr WCHAR desktop_ini_filename[] = L"desktop.ini";
|
||||
}
|
||||
|
||||
inline bool is_hidden(const std::filesystem::path path)
|
||||
{
|
||||
const std::filesystem::path::string_type name = path.filename();
|
||||
if (name == constants::non_localizable::desktop_ini_filename)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool is_directory(const std::filesystem::path path)
|
||||
{
|
||||
const auto entry = std::filesystem::directory_entry(path);
|
||||
|
||||
@@ -129,6 +129,18 @@ namespace newplus::helpers::variables
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool exclude_item(const std::filesystem::path& path)
|
||||
{
|
||||
DWORD attrs = GetFileAttributesW(path.c_str());
|
||||
if (attrs == INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Exclude if hidden or system
|
||||
return (attrs & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0;
|
||||
}
|
||||
|
||||
inline void resolve_variables_in_filename_and_rename_files(const std::filesystem::path& path, const bool do_rename = true)
|
||||
{
|
||||
// Depth first recursion, so that we start renaming the leaves, and avoid having to rescan
|
||||
@@ -143,7 +155,7 @@ namespace newplus::helpers::variables
|
||||
// Perform the actual rename
|
||||
for (const auto& current : std::filesystem::directory_iterator(path))
|
||||
{
|
||||
if (!newplus::helpers::filesystem::is_hidden(current))
|
||||
if (!exclude_item(current))
|
||||
{
|
||||
const std::filesystem::path resolved_path = resolve_variables_in_path(current.path());
|
||||
|
||||
|
||||
@@ -446,4 +446,69 @@ namespace newplus::utilities
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
constexpr wchar_t built_in_new_registry_path[] = LR"(Software\Classes\Directory\Background\ShellEx\ContextMenuHandlers\New)";
|
||||
constexpr wchar_t built_in_new_registry_disabled_value_prefix[] = L"disabled_";
|
||||
|
||||
inline bool disable_built_in_new_via_registry()
|
||||
{
|
||||
// This is implemented to support where New+ GPO is configured to
|
||||
// hide the built-in New context menu but Settings UI hasn't been launched
|
||||
// Mirrors the logic in DisableBuiltInNewViaRegistry in .cs
|
||||
|
||||
HKEY key{};
|
||||
|
||||
if (RegCreateKeyExW(HKEY_CURRENT_USER,
|
||||
built_in_new_registry_path,
|
||||
0,
|
||||
nullptr,
|
||||
REG_OPTION_NON_VOLATILE,
|
||||
KEY_ALL_ACCESS,
|
||||
nullptr,
|
||||
&key,
|
||||
nullptr) != ERROR_SUCCESS)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto built_in_new_registry_disabled_value_prefix_len = lstrlenW(built_in_new_registry_disabled_value_prefix);
|
||||
|
||||
if (RegSetValueExW(key, nullptr, 0, REG_SZ, reinterpret_cast<const BYTE*>(&built_in_new_registry_disabled_value_prefix), built_in_new_registry_disabled_value_prefix_len) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(key);
|
||||
return true;
|
||||
}
|
||||
|
||||
RegCloseKey(key);
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
inline bool enable_built_in_new_via_registry()
|
||||
{
|
||||
// This is implemented to support where New+ GPO is configured to
|
||||
// display the built-in New context menu but Settings UI hasn't been launched
|
||||
// Mirrors the logic in EnableBuiltInNewViaRegistry in .cs
|
||||
|
||||
HKEY key{};
|
||||
|
||||
if (RegOpenKeyExW(HKEY_CURRENT_USER,
|
||||
built_in_new_registry_path,
|
||||
0,
|
||||
KEY_ALL_ACCESS,
|
||||
&key) != ERROR_SUCCESS)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (RegDeleteValueW(key, nullptr) != ERROR_SUCCESS)
|
||||
{
|
||||
RegCloseKey(key);
|
||||
return true;
|
||||
}
|
||||
|
||||
RegCloseKey(key);
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,7 +172,22 @@ private:
|
||||
void init_settings()
|
||||
{
|
||||
powertoy_new_enabled = NewSettingsInstance().GetEnabled();
|
||||
|
||||
UpdateRegistration(powertoy_new_enabled);
|
||||
|
||||
if (powertoy_new_enabled)
|
||||
{
|
||||
// NOTE: This requires that the runner is running and have loaded the new plus module.
|
||||
// It's not enough for user to just invoke the context menu.
|
||||
if (NewSettingsInstance().GetHideBuiltInNew())
|
||||
{
|
||||
newplus::utilities::disable_built_in_new_via_registry();
|
||||
}
|
||||
else
|
||||
{
|
||||
newplus::utilities::enable_built_in_new_via_registry();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -45,6 +45,7 @@ void NewSettings::Save()
|
||||
values.add_property(newplus::constants::non_localizable::settings_json_key_hide_starting_digits, new_settings.hide_starting_digits);
|
||||
values.add_property(newplus::constants::non_localizable::settings_json_key_replace_variables, new_settings.replace_variables);
|
||||
values.add_property(newplus::constants::non_localizable::settings_json_key_template_location, new_settings.template_location);
|
||||
values.add_property(newplus::constants::non_localizable::settings_json_key_hide_built_in_new, new_settings.hide_built_in_new_preference);
|
||||
|
||||
values.save_to_settings_file();
|
||||
|
||||
@@ -75,6 +76,9 @@ void NewSettings::InitializeWithDefaultSettings()
|
||||
SetReplaceVariables(false);
|
||||
|
||||
SetTemplateLocation(GetTemplateLocationDefaultPath());
|
||||
|
||||
// By default we show the built-in New context menu
|
||||
SetHideBuiltInNew(false);
|
||||
}
|
||||
|
||||
void NewSettings::RefreshEnabledState()
|
||||
@@ -149,6 +153,12 @@ void NewSettings::ParseJson()
|
||||
new_settings.replace_variables = resolveVariables.value();
|
||||
}
|
||||
|
||||
const auto hideBuiltInNewValue = settings.get_bool_value(newplus::constants::non_localizable::settings_json_key_hide_built_in_new);
|
||||
if (hideBuiltInNewValue.has_value())
|
||||
{
|
||||
new_settings.hide_built_in_new_preference = hideBuiltInNewValue.value();
|
||||
}
|
||||
|
||||
GetSystemTimeAsFileTime(&new_settings_last_loaded_timestamp);
|
||||
}
|
||||
|
||||
@@ -239,6 +249,26 @@ std::wstring NewSettings::GetTemplateLocationDefaultPath() const
|
||||
return full_path;
|
||||
}
|
||||
|
||||
bool NewSettings::GetHideBuiltInNew()
|
||||
{
|
||||
const auto gpoSetting = powertoys_gpo::getConfiguredNewPlusHideBuiltInNewContextMenuValue();
|
||||
if (gpoSetting == powertoys_gpo::gpo_rule_configured_enabled)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (gpoSetting == powertoys_gpo::gpo_rule_configured_disabled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return new_settings.hide_built_in_new_preference;
|
||||
}
|
||||
|
||||
void NewSettings::SetHideBuiltInNew(const bool hide_built_in_new)
|
||||
{
|
||||
new_settings.hide_built_in_new_preference = hide_built_in_new;
|
||||
}
|
||||
|
||||
NewSettings& NewSettingsInstance()
|
||||
{
|
||||
static NewSettings instance;
|
||||
|
||||
@@ -16,6 +16,8 @@ public:
|
||||
void SetReplaceVariables(const bool resolve_variables);
|
||||
std::wstring GetTemplateLocation() const;
|
||||
void SetTemplateLocation(const std::wstring template_location);
|
||||
bool GetHideBuiltInNew();
|
||||
void SetHideBuiltInNew(const bool hide_built_in_new);
|
||||
|
||||
void Save();
|
||||
void Load();
|
||||
@@ -29,6 +31,7 @@ private:
|
||||
bool hide_starting_digits{ true };
|
||||
bool replace_variables{ true };
|
||||
std::wstring template_location;
|
||||
bool hide_built_in_new_preference{ false };
|
||||
};
|
||||
|
||||
void RefreshEnabledState();
|
||||
|
||||
@@ -35,7 +35,7 @@ void template_folder::rescan_template_folder()
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!helpers::filesystem::is_hidden(entry.path()))
|
||||
if (!newplus::helpers::variables::exclude_item(entry.path()))
|
||||
{
|
||||
files.push_back({ entry.path().wstring(), new template_item(entry) });
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
#include "pch.h"
|
||||
#include "template_item.h"
|
||||
#include <shellapi.h>
|
||||
@@ -60,10 +58,91 @@ std::wstring template_item::get_target_filename(const bool include_starting_digi
|
||||
|
||||
std::wstring template_item::remove_starting_digits_from_filename(std::wstring filename) const
|
||||
{
|
||||
filename.erase(0, std::min(filename.find_first_not_of(L"0123456789"), filename.size()));
|
||||
filename.erase(0, std::min(filename.find_first_not_of(L" ."), filename.size()));
|
||||
// Filename cases to support
|
||||
// type | filename | result
|
||||
// [file] | 01. First entry.txt | First entry.txt
|
||||
// [folder] | 02. Second entry | Second entry
|
||||
// [folder] | 03 Third entry | Third entry
|
||||
// [file] | 04 Fourth entry.txt | Fourth entry.txt
|
||||
// [file] | 05.Fifth entry.txt | Fifth entry.txt
|
||||
// [folder] | 001231 | 001231
|
||||
// [file] | 001231.txt | 001231.txt
|
||||
// [file] | 13. 0123456789012345.txt | 0123456789012345.txt
|
||||
|
||||
return filename;
|
||||
std::filesystem::path filename_path(filename);
|
||||
const std::wstring stem = filename_path.stem().wstring();
|
||||
|
||||
bool stem_is_only_digits = !stem.empty();
|
||||
for (const wchar_t c : stem)
|
||||
{
|
||||
if (c < L'0' || c > L'9')
|
||||
{
|
||||
stem_is_only_digits = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (stem_is_only_digits)
|
||||
{
|
||||
// Edge cases where digits ARE the filename.
|
||||
// If it's a file, we always keep it (e.g. 001231.txt or 001231).
|
||||
// If it's a folder, we only strip if it looks like it has an extension (which is actually part of the name for folders).
|
||||
// e.g. "0123.Name" -> Strip. "001231" -> Keep.
|
||||
const bool is_folder = helpers::filesystem::is_directory(path);
|
||||
const bool has_extension = filename_path.has_extension();
|
||||
|
||||
if (!is_folder || !has_extension)
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
}
|
||||
|
||||
// Find end of leading digits
|
||||
size_t digits_end_index = 0;
|
||||
while (digits_end_index < filename.length() && filename[digits_end_index] >= L'0' && filename[digits_end_index] <= L'9')
|
||||
{
|
||||
digits_end_index++;
|
||||
}
|
||||
|
||||
if (digits_end_index == 0)
|
||||
{
|
||||
// No leading digits
|
||||
return filename;
|
||||
}
|
||||
|
||||
// Determine if we should also strip a separator (dot or space)
|
||||
size_t strip_length = digits_end_index;
|
||||
|
||||
// Check patterns to strip separators:
|
||||
// 1. "01. Name" -> Strip "01. "
|
||||
// 2. "01 .Name" -> Strip "01 ."
|
||||
// 3. "01.Name" -> Strip "01."
|
||||
// 4. "01 Name" -> Strip "01 "
|
||||
// 5. "01Name" -> Strip "01" (No separator)
|
||||
|
||||
if (strip_length < filename.length())
|
||||
{
|
||||
if (filename[strip_length] == L'.')
|
||||
{
|
||||
strip_length++;
|
||||
// If dot is followed by space, strip that too (e.g. "01. Name")
|
||||
if (strip_length < filename.length() && filename[strip_length] == L' ')
|
||||
{
|
||||
strip_length++;
|
||||
}
|
||||
}
|
||||
else if (filename[strip_length] == L' ')
|
||||
{
|
||||
strip_length++;
|
||||
// If space is followed by dot, strip that too (e.g. "01 .Name")
|
||||
if (strip_length < filename.length() && filename[strip_length] == L'.')
|
||||
{
|
||||
strip_length++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return filename.substr(strip_length);
|
||||
}
|
||||
|
||||
std::wstring template_item::get_explorer_icon() const
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted $(RepoRoot)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h PowerOCR.base.rc PowerOCR.rc" />
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted '$(RepoRoot)tools\build\convert-resx-to-rc.ps1' '$(MSBuildThisFileDirectory)' resource.base.h resource.h PowerOCR.base.rc PowerOCR.rc" />
|
||||
</Target>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted $(RepoRoot)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h ShortcutGuide.base.rc ShortcutGuide.rc" />
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted '$(RepoRoot)tools\build\convert-resx-to-rc.ps1' '$(MSBuildThisFileDirectory)' resource.base.h resource.h ShortcutGuide.base.rc ShortcutGuide.rc" />
|
||||
</Target>
|
||||
<PropertyGroup Label="Globals">
|
||||
<CppWinRTOptimized>true</CppWinRTOptimized>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted $(RepoRoot)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h ShortcutGuideModuleInterface.base.rc ShortcutGuideModuleInterface.rc" />
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted '$(RepoRoot)tools\build\convert-resx-to-rc.ps1' '$(MSBuildThisFileDirectory)' resource.base.h resource.h ShortcutGuideModuleInterface.base.rc ShortcutGuideModuleInterface.rc" />
|
||||
</Target>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<!-- Props that should be disabled while building on CI server -->
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted $(SolutionDir)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h WorkspacesLauncherResource.base.rc WorkspacesLauncherResource.rc" />
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted '$(SolutionDir)tools\build\convert-resx-to-rc.ps1' '$(MSBuildThisFileDirectory)' resource.base.h resource.h WorkspacesLauncherResource.base.rc WorkspacesLauncherResource.rc" />
|
||||
</Target>
|
||||
<!-- C++ source compile-specific things for all configurations -->
|
||||
<ItemDefinitionGroup>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<!-- Props that should be disabled while building on CI server -->
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted $(SolutionDir)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h WorkspacesSnapshotToolResources.base.rc WorkspacesSnapshotToolResources.rc" />
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted '$(SolutionDir)tools\build\convert-resx-to-rc.ps1' '$(MSBuildThisFileDirectory)' resource.base.h resource.h WorkspacesSnapshotToolResources.base.rc WorkspacesSnapshotToolResources.rc" />
|
||||
</Target>
|
||||
<!-- C++ source compile-specific things for all configurations -->
|
||||
<ItemDefinitionGroup>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<!-- Props that should be disabled while building on CI server -->
|
||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted $(SolutionDir)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h WorkspacesWindowArrangerResource.base.rc WorkspacesWindowArrangerResource.rc" />
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted '$(SolutionDir)tools\build\convert-resx-to-rc.ps1' '$(MSBuildThisFileDirectory)' resource.base.h resource.h WorkspacesWindowArrangerResource.base.rc WorkspacesWindowArrangerResource.rc" />
|
||||
</Target>
|
||||
<!-- C++ source compile-specific things for all configurations -->
|
||||
<ItemDefinitionGroup>
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace NonLocalizable
|
||||
const static wchar_t* TOOL_WINDOW_CLASS_NAME = L"AlwaysOnTopWindow";
|
||||
const static wchar_t* WINDOW_IS_PINNED_PROP = L"AlwaysOnTop_Pinned";
|
||||
constexpr UINT SYSTEM_MENU_TOGGLE_ALWAYS_ON_TOP_COMMAND = 0xEFE0;
|
||||
constexpr ULONG_PTR SYSTEM_MENU_TOGGLE_ALWAYS_ON_TOP_COMMAND_OWNER_TAG = 0x414F5450;
|
||||
constexpr DWORD SYSTEM_EVENT_MENU_POPUP_START = 0x0006;
|
||||
constexpr DWORD SYSTEM_EVENT_MENU_POPUP_END = 0x0007;
|
||||
}
|
||||
@@ -40,6 +41,29 @@ namespace
|
||||
|
||||
hooks.clear();
|
||||
}
|
||||
|
||||
bool HasMenuCommand(HMENU menu, UINT commandId) noexcept
|
||||
{
|
||||
return menu && GetMenuState(menu, commandId, MF_BYCOMMAND) != static_cast<UINT>(-1);
|
||||
}
|
||||
|
||||
bool IsAlwaysOnTopMenuCommand(HMENU menu) noexcept
|
||||
{
|
||||
if (!HasMenuCommand(menu, NonLocalizable::SYSTEM_MENU_TOGGLE_ALWAYS_ON_TOP_COMMAND))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
MENUITEMINFOW menuItemInfo{};
|
||||
menuItemInfo.cbSize = sizeof(menuItemInfo);
|
||||
menuItemInfo.fMask = MIIM_DATA;
|
||||
|
||||
return GetMenuItemInfoW(menu,
|
||||
NonLocalizable::SYSTEM_MENU_TOGGLE_ALWAYS_ON_TOP_COMMAND,
|
||||
FALSE,
|
||||
&menuItemInfo) &&
|
||||
menuItemInfo.dwItemData == NonLocalizable::SYSTEM_MENU_TOGGLE_ALWAYS_ON_TOP_COMMAND_OWNER_TAG;
|
||||
}
|
||||
}
|
||||
|
||||
bool isExcluded(HWND window)
|
||||
@@ -503,7 +527,7 @@ void AlwaysOnTop::UpdateSystemMenuItem(HWND window) const noexcept
|
||||
|
||||
if (!AlwaysOnTopSettings::settings().showInSystemMenu)
|
||||
{
|
||||
if (GetMenuState(systemMenu, NonLocalizable::SYSTEM_MENU_TOGGLE_ALWAYS_ON_TOP_COMMAND, MF_BYCOMMAND) != static_cast<UINT>(-1))
|
||||
if (IsAlwaysOnTopMenuCommand(systemMenu))
|
||||
{
|
||||
RemoveMenu(systemMenu, NonLocalizable::SYSTEM_MENU_TOGGLE_ALWAYS_ON_TOP_COMMAND, MF_BYCOMMAND);
|
||||
}
|
||||
@@ -513,20 +537,26 @@ void AlwaysOnTop::UpdateSystemMenuItem(HWND window) const noexcept
|
||||
auto text = GET_RESOURCE_STRING(IDS_SYSTEM_MENU_TOGGLE_ALWAYS_ON_TOP);
|
||||
MENUITEMINFOW menuItemInfo{};
|
||||
menuItemInfo.cbSize = sizeof(menuItemInfo);
|
||||
menuItemInfo.fMask = MIIM_ID | MIIM_STATE | MIIM_STRING;
|
||||
menuItemInfo.fMask = MIIM_ID | MIIM_STATE | MIIM_STRING | MIIM_DATA;
|
||||
menuItemInfo.wID = NonLocalizable::SYSTEM_MENU_TOGGLE_ALWAYS_ON_TOP_COMMAND;
|
||||
menuItemInfo.fState = IsPinned(window) ? MFS_CHECKED : MFS_UNCHECKED;
|
||||
menuItemInfo.dwTypeData = text.data();
|
||||
menuItemInfo.dwItemData = NonLocalizable::SYSTEM_MENU_TOGGLE_ALWAYS_ON_TOP_COMMAND_OWNER_TAG;
|
||||
|
||||
if (GetMenuState(systemMenu, NonLocalizable::SYSTEM_MENU_TOGGLE_ALWAYS_ON_TOP_COMMAND, MF_BYCOMMAND) == static_cast<UINT>(-1))
|
||||
if (!HasMenuCommand(systemMenu, NonLocalizable::SYSTEM_MENU_TOGGLE_ALWAYS_ON_TOP_COMMAND))
|
||||
{
|
||||
InsertMenuItemW(systemMenu, SC_CLOSE, FALSE, &menuItemInfo);
|
||||
}
|
||||
else
|
||||
else if (IsAlwaysOnTopMenuCommand(systemMenu))
|
||||
{
|
||||
menuItemInfo.fMask = MIIM_STATE | MIIM_STRING;
|
||||
SetMenuItemInfoW(systemMenu, NonLocalizable::SYSTEM_MENU_TOGGLE_ALWAYS_ON_TOP_COMMAND, FALSE, &menuItemInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger::warn(L"Skipping Always On Top system menu command registration because ID 0x{:X} is already in use by another item.",
|
||||
NonLocalizable::SYSTEM_MENU_TOGGLE_ALWAYS_ON_TOP_COMMAND);
|
||||
}
|
||||
}
|
||||
|
||||
void AlwaysOnTop::UnpinAll()
|
||||
@@ -652,8 +682,7 @@ void AlwaysOnTop::HandleWinHookEvent(WinHookEvent* data) noexcept
|
||||
}
|
||||
|
||||
const auto systemMenu = GetSystemMenu(window, false);
|
||||
return systemMenu &&
|
||||
GetMenuState(systemMenu, NonLocalizable::SYSTEM_MENU_TOGGLE_ALWAYS_ON_TOP_COMMAND, MF_BYCOMMAND) != static_cast<UINT>(-1);
|
||||
return systemMenu && IsAlwaysOnTopMenuCommand(systemMenu);
|
||||
};
|
||||
|
||||
HWND commandWindow = nullptr;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<!-- Props that should be disabled while building on CI server -->
|
||||
<Import Project="$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props" Condition="Exists('$(RepoRoot)packages\Microsoft.Windows.CppWinRT.2.0.250303.1\build\native\Microsoft.Windows.CppWinRT.props')" />
|
||||
<Target Name="GenerateResourceFiles" BeforeTargets="PrepareForBuild">
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted $(RepoRoot)tools\build\convert-resx-to-rc.ps1 $(MSBuildThisFileDirectory) resource.base.h resource.h AlwaysOnTop.base.rc AlwaysOnTop.rc" />
|
||||
<Exec Command="powershell -NonInteractive -executionpolicy Unrestricted '$(RepoRoot)tools\build\convert-resx-to-rc.ps1' '$(MSBuildThisFileDirectory)' resource.base.h resource.h AlwaysOnTop.base.rc AlwaysOnTop.rc" />
|
||||
</Target>
|
||||
<!-- C++ source compile-specific things for all configurations -->
|
||||
<ItemDefinitionGroup>
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Microsoft.CmdPal.Common.Properties {
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "18.0.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
@@ -2,31 +2,54 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using CommunityToolkit.WinUI;
|
||||
using Microsoft.CmdPal.UI.ViewModels.Messages;
|
||||
using Microsoft.CommandPalette.Extensions.Toolkit;
|
||||
using Windows.System;
|
||||
using DispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue;
|
||||
using DispatcherQueueTimer = Microsoft.UI.Dispatching.DispatcherQueueTimer;
|
||||
|
||||
namespace Microsoft.CmdPal.UI.ViewModels;
|
||||
|
||||
public partial class CommandBarViewModel : ObservableObject,
|
||||
public sealed partial class CommandBarViewModel : ObservableObject,
|
||||
IRecipient<UpdateCommandBarMessage>
|
||||
{
|
||||
private readonly DispatcherQueueTimer _debounceTimer;
|
||||
|
||||
private volatile ICommandBarContext? _pendingSelectedItem;
|
||||
|
||||
public ICommandBarContext? SelectedItem
|
||||
{
|
||||
get => field;
|
||||
get;
|
||||
set
|
||||
{
|
||||
if (field != null)
|
||||
// TODO: verify if we can safely return early
|
||||
// if (ReferenceEquals(field, value))
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
if (field is not null)
|
||||
{
|
||||
field.PropertyChanged -= SelectedItemPropertyChanged;
|
||||
}
|
||||
|
||||
field = value;
|
||||
SetSelectedItem(value);
|
||||
|
||||
OnPropertyChanged(nameof(SelectedItem));
|
||||
if (field is not null)
|
||||
{
|
||||
PrimaryCommand = field.PrimaryCommand;
|
||||
field.PropertyChanged += SelectedItemPropertyChanged;
|
||||
}
|
||||
else
|
||||
{
|
||||
PrimaryCommand = null;
|
||||
}
|
||||
|
||||
UpdateContextItems();
|
||||
OnPropertyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +57,8 @@ public partial class CommandBarViewModel : ObservableObject,
|
||||
[NotifyPropertyChangedFor(nameof(HasPrimaryCommand))]
|
||||
public partial CommandItemViewModel? PrimaryCommand { get; set; }
|
||||
|
||||
// TODO: PrimaryCommand.ShouldBeVisible is not observed, if it changes the bar won't refresh;
|
||||
// but at this moment CommandItemViewModel won't raise INPC for ShouldBeVisible anyway.
|
||||
public bool HasPrimaryCommand => PrimaryCommand is not null && PrimaryCommand.ShouldBeVisible;
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -50,29 +75,31 @@ public partial class CommandBarViewModel : ObservableObject,
|
||||
|
||||
public CommandBarViewModel()
|
||||
{
|
||||
var dispatcherQueue = DispatcherQueue.GetForCurrentThread();
|
||||
if (dispatcherQueue is null)
|
||||
{
|
||||
throw new InvalidOperationException("DispatcherQueue is not available for the current thread.");
|
||||
}
|
||||
|
||||
_debounceTimer = dispatcherQueue.CreateTimer();
|
||||
WeakReferenceMessenger.Default.Register<UpdateCommandBarMessage>(this);
|
||||
}
|
||||
|
||||
public void Receive(UpdateCommandBarMessage message) => SelectedItem = message.ViewModel;
|
||||
|
||||
private void SetSelectedItem(ICommandBarContext? value)
|
||||
public void Receive(UpdateCommandBarMessage message)
|
||||
{
|
||||
if (value is not null)
|
||||
{
|
||||
PrimaryCommand = value.PrimaryCommand;
|
||||
value.PropertyChanged += SelectedItemPropertyChanged;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SelectedItem is not null)
|
||||
{
|
||||
SelectedItem.PropertyChanged -= SelectedItemPropertyChanged;
|
||||
}
|
||||
_pendingSelectedItem = message.ViewModel;
|
||||
|
||||
PrimaryCommand = null;
|
||||
}
|
||||
// immediate: false is intentional — the timer tick always fires on the
|
||||
// dispatcher queue thread, which guarantees ApplyPendingSelectedItem
|
||||
// runs on the UI thread even if Receive is called from a background
|
||||
// thread. Using immediate: true would invoke the delegate synchronously
|
||||
// on the calling thread, bypassing the dispatcher.
|
||||
_debounceTimer.Debounce(ApplyPendingSelectedItem, TimeSpan.FromMilliseconds(50));
|
||||
}
|
||||
|
||||
UpdateContextItems();
|
||||
private void ApplyPendingSelectedItem()
|
||||
{
|
||||
SelectedItem = _pendingSelectedItem;
|
||||
}
|
||||
|
||||
private void SelectedItemPropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
|
||||
@@ -215,9 +215,7 @@ public sealed class CommandProviderWrapper : ICommandProviderContext
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError("Failed to load commands from extension");
|
||||
Logger.LogError($"Extension was {Extension!.PackageFamilyName}");
|
||||
Logger.LogError(e.ToString());
|
||||
Logger.LogError($"Failed to load commands from extension {Extension!.PackageFamilyName}", e);
|
||||
|
||||
if (!displayInfoInitialized)
|
||||
{
|
||||
|
||||
@@ -39,6 +39,7 @@ public sealed partial class MainListPage : DynamicListPage,
|
||||
// recognise them across successive GetItems() calls
|
||||
private readonly Separator _resultsSeparator = new(Resources.results);
|
||||
private readonly Separator _fallbacksSeparator = new(Resources.fallbacks);
|
||||
private readonly Separator _commandsSeparator = new(Resources.home_sections_commands_title);
|
||||
|
||||
private RoScored<IListItem>[]? _filteredItems;
|
||||
private RoScored<IListItem>[]? _filteredApps;
|
||||
@@ -119,7 +120,7 @@ public sealed partial class MainListPage : DynamicListPage,
|
||||
}
|
||||
else
|
||||
{
|
||||
RaiseItemsChanged();
|
||||
RaiseItemsChanged(ListViewModel.IncrementalRefresh);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,7 +197,7 @@ public sealed partial class MainListPage : DynamicListPage,
|
||||
|
||||
// +1 for the separator
|
||||
var result = new IListItem[eligibleCount + 1];
|
||||
result[0] = _resultsSeparator;
|
||||
result[0] = _commandsSeparator;
|
||||
|
||||
// Second pass: populate
|
||||
var writeIndex = 1;
|
||||
@@ -330,7 +331,7 @@ public sealed partial class MainListPage : DynamicListPage,
|
||||
{
|
||||
_filteredItemsIncludesApps = _includeApps;
|
||||
ClearResults();
|
||||
RaiseItemsChanged(commands.Count);
|
||||
RaiseItemsChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -502,7 +503,7 @@ public sealed partial class MainListPage : DynamicListPage,
|
||||
return;
|
||||
}
|
||||
|
||||
RaiseItemsChanged();
|
||||
RaiseItemsChanged(ListViewModel.IncrementalRefresh);
|
||||
}
|
||||
},
|
||||
token);
|
||||
|
||||
@@ -18,6 +18,8 @@ namespace Microsoft.CmdPal.UI.ViewModels;
|
||||
|
||||
public partial class ListViewModel : PageViewModel, IDisposable
|
||||
{
|
||||
public const int IncrementalRefresh = -2;
|
||||
|
||||
private readonly TaskFactory filterTaskFactory = new(new ConcurrentExclusiveSchedulerPair().ExclusiveScheduler);
|
||||
|
||||
private readonly Dictionary<IListItem, ListItemViewModel> _vmCache = new(new ProxyReferenceEqualityComparer());
|
||||
@@ -83,6 +85,11 @@ public partial class ListViewModel : PageViewModel, IDisposable
|
||||
|
||||
private ListItemViewModel? _lastSelectedItem;
|
||||
|
||||
// Persists across cancelled FetchItems calls so a forceFirstItem=true
|
||||
// intent is never lost when FetchItems(false) is cancelled by a
|
||||
// subsequent FetchItems(true).
|
||||
private volatile bool _forceFirstItemPending;
|
||||
|
||||
// For cancelling a deferred SafeSlowInit when the user navigates rapidly
|
||||
private CancellationTokenSource? _selectedItemCts;
|
||||
|
||||
@@ -115,7 +122,7 @@ public partial class ListViewModel : PageViewModel, IDisposable
|
||||
}
|
||||
|
||||
// TODO: Does this need to hop to a _different_ thread, so that we don't block the extension while we're fetching?
|
||||
private void Model_ItemsChanged(object sender, IItemsChangedEventArgs args) => FetchItems();
|
||||
private void Model_ItemsChanged(object sender, IItemsChangedEventArgs args) => FetchItems(args.TotalItems == IncrementalRefresh);
|
||||
|
||||
protected override void OnSearchTextBoxUpdated(string searchTextBox)
|
||||
{
|
||||
@@ -191,8 +198,15 @@ public partial class ListViewModel : PageViewModel, IDisposable
|
||||
}
|
||||
|
||||
//// Run on background thread, from InitializeAsync or Model_ItemsChanged
|
||||
private void FetchItems()
|
||||
private void FetchItems(bool keepSelection)
|
||||
{
|
||||
// If this fetch should reset selection, remember that intent even if
|
||||
// a later incremental fetch cancels us.
|
||||
if (!keepSelection)
|
||||
{
|
||||
_forceFirstItemPending = true;
|
||||
}
|
||||
|
||||
// Cancel any previous FetchItems operation
|
||||
_fetchItemsCancellationTokenSource?.Cancel();
|
||||
_fetchItemsCancellationTokenSource?.Dispose();
|
||||
@@ -382,7 +396,12 @@ public partial class ListViewModel : PageViewModel, IDisposable
|
||||
UpdateEmptyContent();
|
||||
}
|
||||
|
||||
ItemsUpdated?.Invoke(this, new ItemsUpdatedEventArgs(IsRootPage));
|
||||
// Consume the pending flag on the UI thread so a
|
||||
// forceFirstItem=true intent survives cancellation.
|
||||
var forceFirst = _forceFirstItemPending;
|
||||
_forceFirstItemPending = false;
|
||||
|
||||
ItemsUpdated?.Invoke(this, new ItemsUpdatedEventArgs(forceFirstItem: IsRootPage && forceFirst));
|
||||
_isLoading.Clear();
|
||||
});
|
||||
}
|
||||
@@ -567,8 +586,12 @@ public partial class ListViewModel : PageViewModel, IDisposable
|
||||
WeakReferenceMessenger.Default.Send<HideDetailsMessage>();
|
||||
}
|
||||
|
||||
TextToSuggest = item.TextToSuggest;
|
||||
WeakReferenceMessenger.Default.Send<UpdateSuggestionMessage>(new(item.TextToSuggest));
|
||||
var suggestion = item.TextToSuggest;
|
||||
DoOnUiThread(() =>
|
||||
{
|
||||
TextToSuggest = suggestion;
|
||||
WeakReferenceMessenger.Default.Send<UpdateSuggestionMessage>(new(suggestion));
|
||||
});
|
||||
},
|
||||
ct);
|
||||
}
|
||||
@@ -657,7 +680,7 @@ public partial class ListViewModel : PageViewModel, IDisposable
|
||||
Filters?.InitializeProperties();
|
||||
UpdateProperty(nameof(Filters));
|
||||
|
||||
FetchItems();
|
||||
FetchItems(true);
|
||||
model.ItemsChanged += Model_ItemsChanged;
|
||||
}
|
||||
|
||||
|
||||
@@ -528,6 +528,15 @@ namespace Microsoft.CmdPal.UI.ViewModels.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Commands.
|
||||
/// </summary>
|
||||
public static string home_sections_commands_title {
|
||||
get {
|
||||
return ResourceManager.GetString("home_sections_commands_title", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Pinned.
|
||||
/// </summary>
|
||||
@@ -536,7 +545,8 @@ namespace Microsoft.CmdPal.UI.ViewModels.Properties {
|
||||
return ResourceManager.GetString("PinnedItemSuffix", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Results.
|
||||
/// </summary>
|
||||
public static string results {
|
||||
|
||||
@@ -283,7 +283,7 @@
|
||||
<data name="dock_settings_name" xml:space="preserve">
|
||||
<value>Dock settings</value>
|
||||
<comment>Command name for opening dock settings</comment>
|
||||
</data>
|
||||
</data>
|
||||
<data name="ShowDetailsCommand" xml:space="preserve">
|
||||
<value>Show details</value>
|
||||
<comment>Name for the command that shows details of an item</comment>
|
||||
@@ -296,4 +296,7 @@
|
||||
<value>Results</value>
|
||||
<comment>Section title for list of all search results that doesn't fall into any other category</comment>
|
||||
</data>
|
||||
<data name="home_sections_commands_title" xml:space="preserve">
|
||||
<value>Commands</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -5,6 +5,7 @@
|
||||
using System.Collections.Immutable;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
@@ -19,13 +20,18 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Microsoft.CmdPal.UI.ViewModels;
|
||||
|
||||
public partial class TopLevelCommandManager : ObservableObject,
|
||||
public sealed partial class TopLevelCommandManager : ObservableObject,
|
||||
IRecipient<ReloadCommandsMessage>,
|
||||
IRecipient<PinCommandItemMessage>,
|
||||
IRecipient<UnpinCommandItemMessage>,
|
||||
IRecipient<PinToDockMessage>,
|
||||
IDisposable
|
||||
{
|
||||
private static readonly TimeSpan ExtensionStartTimeout = TimeSpan.FromSeconds(10);
|
||||
private static readonly TimeSpan CommandLoadTimeout = TimeSpan.FromSeconds(10);
|
||||
private static readonly TimeSpan BackgroundStartTimeout = TimeSpan.FromSeconds(60);
|
||||
private static readonly TimeSpan BackgroundCommandLoadTimeout = TimeSpan.FromSeconds(60);
|
||||
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly ICommandProviderCache _commandProviderCache;
|
||||
private readonly TaskScheduler _taskScheduler;
|
||||
@@ -39,11 +45,14 @@ public partial class TopLevelCommandManager : ObservableObject,
|
||||
// deadlock.
|
||||
private readonly Lock _dockBandsLock = new();
|
||||
private readonly SupersedingAsyncGate _reloadCommandsGate;
|
||||
private CancellationTokenSource _extensionLoadCts = new();
|
||||
private CancellationToken _currentExtensionLoadCancellationToken;
|
||||
|
||||
public TopLevelCommandManager(IServiceProvider serviceProvider, ICommandProviderCache commandProviderCache)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_commandProviderCache = commandProviderCache;
|
||||
_currentExtensionLoadCancellationToken = _extensionLoadCts.Token;
|
||||
_taskScheduler = _serviceProvider.GetService<TaskScheduler>()!;
|
||||
WeakReferenceMessenger.Default.Register<ReloadCommandsMessage>(this);
|
||||
WeakReferenceMessenger.Default.Register<PinCommandItemMessage>(this);
|
||||
@@ -260,8 +269,15 @@ public partial class TopLevelCommandManager : ObservableObject,
|
||||
private async Task ReloadAllCommandsAsyncCore(CancellationToken cancellationToken)
|
||||
{
|
||||
IsLoading = true;
|
||||
|
||||
// Invalidate any background continuations from the previous load cycle
|
||||
await _extensionLoadCts.CancelAsync().ConfigureAwait(false);
|
||||
_extensionLoadCts.Dispose();
|
||||
_extensionLoadCts = new();
|
||||
_currentExtensionLoadCancellationToken = _extensionLoadCts.Token;
|
||||
|
||||
var extensionService = _serviceProvider.GetService<IExtensionService>()!;
|
||||
await extensionService.SignalStopExtensionsAsync();
|
||||
await extensionService.SignalStopExtensionsAsync().ConfigureAwait(false);
|
||||
|
||||
lock (TopLevelCommands)
|
||||
{
|
||||
@@ -273,8 +289,8 @@ public partial class TopLevelCommandManager : ObservableObject,
|
||||
DockBands.Clear();
|
||||
}
|
||||
|
||||
await LoadBuiltinsAsync();
|
||||
_ = Task.Run(LoadExtensionsAsync);
|
||||
await LoadBuiltinsAsync().ConfigureAwait(false);
|
||||
_ = Task.Run(LoadExtensionsAsync, cancellationToken);
|
||||
}
|
||||
|
||||
// Load commands from our extensions. Called on a background thread.
|
||||
@@ -292,16 +308,15 @@ public partial class TopLevelCommandManager : ObservableObject,
|
||||
extensionService.OnExtensionAdded -= ExtensionService_OnExtensionAdded;
|
||||
extensionService.OnExtensionRemoved -= ExtensionService_OnExtensionRemoved;
|
||||
|
||||
var extensions = (await extensionService.GetInstalledExtensionsAsync()).ToImmutableList();
|
||||
var ct = _currentExtensionLoadCancellationToken;
|
||||
|
||||
var extensions = (await extensionService.GetInstalledExtensionsAsync().ConfigureAwait(false)).ToImmutableList();
|
||||
lock (_commandProvidersLock)
|
||||
{
|
||||
_extensionCommandProviders.Clear();
|
||||
}
|
||||
|
||||
if (extensions is not null)
|
||||
{
|
||||
await StartExtensionsAndGetCommands(extensions);
|
||||
}
|
||||
await StartExtensionsAndGetCommands(extensions, ct).ConfigureAwait(false);
|
||||
|
||||
extensionService.OnExtensionAdded += ExtensionService_OnExtensionAdded;
|
||||
extensionService.OnExtensionRemoved += ExtensionService_OnExtensionRemoved;
|
||||
@@ -316,46 +331,219 @@ public partial class TopLevelCommandManager : ObservableObject,
|
||||
|
||||
private void ExtensionService_OnExtensionAdded(IExtensionService sender, IEnumerable<IExtensionWrapper> extensions)
|
||||
{
|
||||
var ct = _currentExtensionLoadCancellationToken;
|
||||
|
||||
// When we get an extension install event, hop off to a BG thread
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
// for each newly installed extension, start it and get commands
|
||||
// from it. One single package might have more than one
|
||||
// IExtensionWrapper in it.
|
||||
await StartExtensionsAndGetCommands(extensions);
|
||||
});
|
||||
_ = Task.Run(
|
||||
async () =>
|
||||
{
|
||||
// for each newly installed extension, start it and get commands
|
||||
// from it. One single package might have more than one
|
||||
// IExtensionWrapper in it.
|
||||
await StartExtensionsAndGetCommands(extensions, ct).ConfigureAwait(false);
|
||||
},
|
||||
ct);
|
||||
}
|
||||
|
||||
private async Task StartExtensionsAndGetCommands(IEnumerable<IExtensionWrapper> extensions)
|
||||
private async Task StartExtensionsAndGetCommands(IEnumerable<IExtensionWrapper> extensions, CancellationToken ct)
|
||||
{
|
||||
var timer = new Stopwatch();
|
||||
timer.Start();
|
||||
var timer = Stopwatch.StartNew();
|
||||
|
||||
// Start all extensions in parallel
|
||||
var startTasks = extensions.Select(StartExtensionWithTimeoutAsync);
|
||||
var startResults = await Task.WhenAll(extensions.Select(TryStartExtensionAsync)).ConfigureAwait(false);
|
||||
|
||||
// Wait for all extensions to start
|
||||
var wrappers = (await Task.WhenAll(startTasks)).Where(wrapper => wrapper is not null).Select(w => w!).ToList();
|
||||
var startedWrappers = new List<CommandProviderWrapper>();
|
||||
foreach (var r in startResults)
|
||||
{
|
||||
if (r.IsStarted)
|
||||
{
|
||||
startedWrappers.Add(r.Wrapper);
|
||||
}
|
||||
else if (r.IsTimedOut)
|
||||
{
|
||||
_ = StartExtensionWhenReadyAsync(r.Extension, r.PendingStartTask, r.Stopwatch, ct);
|
||||
}
|
||||
}
|
||||
|
||||
// Register started extensions and load their commands
|
||||
var loadSummary = await RegisterAndLoadCommandsAsync(startedWrappers, ct).ConfigureAwait(false);
|
||||
|
||||
timer.Stop();
|
||||
Logger.LogInfo($"Loaded {loadSummary.CommandCount} command(s) and {loadSummary.DockBandCount} band(s) from {startedWrappers.Count} extension(s) in {timer.ElapsedMilliseconds} ms");
|
||||
}
|
||||
|
||||
private async Task<RegisterAndLoadSummary> RegisterAndLoadCommandsAsync(ICollection<CommandProviderWrapper> wrappers, CancellationToken ct)
|
||||
{
|
||||
lock (_commandProvidersLock)
|
||||
{
|
||||
_extensionCommandProviders.AddRange(wrappers);
|
||||
}
|
||||
|
||||
// Load the commands from the providers in parallel
|
||||
var loadTasks = wrappers.Select(LoadCommandsWithTimeoutAsync);
|
||||
var loadResults = await Task.WhenAll(wrappers.Select(w => TryLoadCommandsAsync(w, ct))).ConfigureAwait(false);
|
||||
|
||||
var commandSets = (await Task.WhenAll(loadTasks)).Where(results => results is not null).Select(r => r!).ToList();
|
||||
var totalCommands = 0;
|
||||
var totalDockBands = 0;
|
||||
var timedOut = new List<CommandLoadResult>();
|
||||
List<TopLevelViewModel> commandsToAdd = [];
|
||||
List<TopLevelViewModel> dockBandsToAdd = [];
|
||||
|
||||
foreach (var providerObjects in commandSets)
|
||||
foreach (var r in loadResults)
|
||||
{
|
||||
var commandsCount = providerObjects.Commands?.Count() ?? 0;
|
||||
var bandsCount = providerObjects.DockBands?.Count() ?? 0;
|
||||
Logger.LogDebug($"(some provider) Loaded {commandsCount} commands and {bandsCount} bands");
|
||||
|
||||
lock (TopLevelCommands)
|
||||
if (r.IsLoaded)
|
||||
{
|
||||
if (providerObjects.Commands is IEnumerable<TopLevelViewModel> commands)
|
||||
var commands = r.TopLevelObjectSets.Commands;
|
||||
if (commands is not null)
|
||||
{
|
||||
foreach (var c in commands)
|
||||
{
|
||||
commandsToAdd.Add(c);
|
||||
totalCommands++;
|
||||
}
|
||||
}
|
||||
|
||||
var bands = r.TopLevelObjectSets.DockBands;
|
||||
if (bands is not null)
|
||||
{
|
||||
foreach (var b in bands)
|
||||
{
|
||||
dockBandsToAdd.Add(b);
|
||||
totalDockBands++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (r.IsTimedOut)
|
||||
{
|
||||
timedOut.Add(r);
|
||||
}
|
||||
}
|
||||
|
||||
lock (TopLevelCommands)
|
||||
{
|
||||
foreach (var c in commandsToAdd)
|
||||
{
|
||||
TopLevelCommands.Add(c);
|
||||
}
|
||||
}
|
||||
|
||||
lock (_dockBandsLock)
|
||||
{
|
||||
foreach (var b in dockBandsToAdd)
|
||||
{
|
||||
DockBands.Add(b);
|
||||
}
|
||||
}
|
||||
|
||||
// Fire background continuations for timed-out loads outside the lock
|
||||
foreach (var r in timedOut)
|
||||
{
|
||||
// It's weird to repeat the condition here, but it allows the compiler to track nullability of other properties
|
||||
if (r.IsTimedOut)
|
||||
{
|
||||
_ = AppendCommandsWhenReadyAsync(r.Wrapper, r.PendingLoadTask, r.Stopwatch, ct);
|
||||
}
|
||||
}
|
||||
|
||||
return new RegisterAndLoadSummary(totalCommands, totalDockBands);
|
||||
}
|
||||
|
||||
private async Task<ExtensionStartResult> TryStartExtensionAsync(IExtensionWrapper extension)
|
||||
{
|
||||
Logger.LogDebug($"Starting {extension.PackageFullName}");
|
||||
var sw = Stopwatch.StartNew();
|
||||
var ct = _currentExtensionLoadCancellationToken;
|
||||
var startTask = extension.StartExtensionAsync();
|
||||
try
|
||||
{
|
||||
await startTask.WaitAsync(ExtensionStartTimeout, ct).ConfigureAwait(false);
|
||||
Logger.LogInfo($"Started extension {extension.PackageFullName} in {sw.ElapsedMilliseconds} ms");
|
||||
return ExtensionStartResult.Started(extension, new CommandProviderWrapper(extension, _taskScheduler, _commandProviderCache));
|
||||
}
|
||||
catch (TimeoutException)
|
||||
{
|
||||
Logger.LogWarning($"Starting extension {extension.PackageFullName} timed out after {sw.ElapsedMilliseconds} ms, continuing in background");
|
||||
return ExtensionStartResult.TimedOut(extension, startTask, sw);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
Logger.LogDebug($"Starting extension {extension.PackageFullName} was cancelled after {sw.ElapsedMilliseconds} ms");
|
||||
return ExtensionStartResult.Failed(extension);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError($"Failed to start extension {extension.PackageFullName} after {sw.ElapsedMilliseconds} ms: {ex}");
|
||||
return ExtensionStartResult.Failed(extension);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task StartExtensionWhenReadyAsync(
|
||||
IExtensionWrapper extension,
|
||||
Task startTask,
|
||||
Stopwatch sw,
|
||||
CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
await startTask.WaitAsync(BackgroundStartTimeout, ct).ConfigureAwait(false);
|
||||
|
||||
var wrapper = new CommandProviderWrapper(extension, _taskScheduler, _commandProviderCache);
|
||||
Logger.LogInfo($"Late-started extension {extension.PackageFullName} in {sw.ElapsedMilliseconds} ms, loading commands and bands");
|
||||
|
||||
await RegisterAndLoadCommandsAsync([wrapper], ct).ConfigureAwait(false);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// Reload happened -- discard stale results
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError($"Background start/load of extension {extension.PackageFullName} failed after {sw.ElapsedMilliseconds} ms: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<CommandLoadResult> TryLoadCommandsAsync(CommandProviderWrapper wrapper, CancellationToken ct)
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
var loadTask = LoadTopLevelCommandsFromProvider(wrapper);
|
||||
try
|
||||
{
|
||||
var result = await loadTask.WaitAsync(CommandLoadTimeout, ct).ConfigureAwait(false);
|
||||
var commandCount = result.Commands?.Count ?? 0;
|
||||
var dockBandCount = result.DockBands?.Count ?? 0;
|
||||
Logger.LogInfo($"Loaded {commandCount} command(s) and {dockBandCount} band(s) from {wrapper.ExtensionHost?.Extension?.PackageFullName} in {sw.ElapsedMilliseconds} ms");
|
||||
return CommandLoadResult.Loaded(wrapper, result);
|
||||
}
|
||||
catch (TimeoutException)
|
||||
{
|
||||
Logger.LogWarning($"Loading commands and bands from {wrapper.ExtensionHost?.Extension?.PackageFullName} timed out after {sw.ElapsedMilliseconds} ms, continuing in background");
|
||||
return CommandLoadResult.TimedOut(wrapper, loadTask, sw);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
Logger.LogDebug($"Loading commands and bands from {wrapper.ExtensionHost?.Extension?.PackageFullName} was cancelled after {sw.ElapsedMilliseconds} ms");
|
||||
return CommandLoadResult.Failed(wrapper);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError($"Failed to load commands and bands for extension {wrapper.ExtensionHost?.Extension?.PackageFullName} after {sw.ElapsedMilliseconds} ms: {ex}");
|
||||
return CommandLoadResult.Failed(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task AppendCommandsWhenReadyAsync(
|
||||
CommandProviderWrapper wrapper,
|
||||
Task<TopLevelObjectSets> loadTask,
|
||||
Stopwatch sw,
|
||||
CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
var topLevelObjectSets = await loadTask.WaitAsync(BackgroundCommandLoadTimeout, ct).ConfigureAwait(false);
|
||||
|
||||
var commands = topLevelObjectSets.Commands;
|
||||
if (commands is not null)
|
||||
{
|
||||
lock (TopLevelCommands)
|
||||
{
|
||||
foreach (var c in commands)
|
||||
{
|
||||
@@ -364,57 +552,30 @@ public partial class TopLevelCommandManager : ObservableObject,
|
||||
}
|
||||
}
|
||||
|
||||
lock (_dockBandsLock)
|
||||
var dockBands = topLevelObjectSets.DockBands;
|
||||
if (dockBands is not null)
|
||||
{
|
||||
if (providerObjects.DockBands is IEnumerable<TopLevelViewModel> bands)
|
||||
lock (_dockBandsLock)
|
||||
{
|
||||
foreach (var c in bands)
|
||||
foreach (var band in dockBands)
|
||||
{
|
||||
DockBands.Add(c);
|
||||
DockBands.Add(band);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Logger.LogInfo($"Late-loaded {commands?.Count ?? 0} command(s) and {dockBands?.Count ?? 0} band(s) from {wrapper.ExtensionHost?.Extension?.PackageFullName} in {sw.ElapsedMilliseconds} ms");
|
||||
}
|
||||
|
||||
timer.Stop();
|
||||
Logger.LogDebug($"Loading extensions took {timer.ElapsedMilliseconds} ms");
|
||||
}
|
||||
|
||||
private async Task<CommandProviderWrapper?> StartExtensionWithTimeoutAsync(IExtensionWrapper extension)
|
||||
{
|
||||
Logger.LogDebug($"Starting {extension.PackageFullName}");
|
||||
try
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
await extension.StartExtensionAsync().WaitAsync(TimeSpan.FromSeconds(10));
|
||||
return new CommandProviderWrapper(extension, _taskScheduler, _commandProviderCache);
|
||||
// Reload happened - discard stale results
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError($"Failed to start extension {extension.PackageFullName}: {ex}");
|
||||
return null; // Return null for failed extensions
|
||||
Logger.LogError($"Background loading of commands and bands from {wrapper.ExtensionHost?.Extension?.PackageFullName} failed after {sw.ElapsedMilliseconds} ms: {ex}");
|
||||
}
|
||||
}
|
||||
|
||||
private record TopLevelObjectSets(IEnumerable<TopLevelViewModel>? Commands, IEnumerable<TopLevelViewModel>? DockBands);
|
||||
|
||||
private async Task<TopLevelObjectSets?> LoadCommandsWithTimeoutAsync(CommandProviderWrapper wrapper)
|
||||
{
|
||||
try
|
||||
{
|
||||
return await LoadTopLevelCommandsFromProvider(wrapper!).WaitAsync(TimeSpan.FromSeconds(10));
|
||||
}
|
||||
catch (TimeoutException)
|
||||
{
|
||||
Logger.LogError($"Loading commands from {wrapper!.ExtensionHost?.Extension?.PackageFullName} timed out");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError($"Failed to load commands for extension {wrapper!.ExtensionHost?.Extension?.PackageFullName}: {ex}");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void ExtensionService_OnExtensionRemoved(IExtensionService sender, IEnumerable<IExtensionWrapper> extensions)
|
||||
{
|
||||
// When we get an extension uninstall event, hop off to a BG thread
|
||||
@@ -515,7 +676,7 @@ public partial class TopLevelCommandManager : ObservableObject,
|
||||
}
|
||||
|
||||
public void Receive(ReloadCommandsMessage message) =>
|
||||
ReloadAllCommandsAsync().ConfigureAwait(false);
|
||||
_ = ReloadAllCommandsAsync();
|
||||
|
||||
public void Receive(PinCommandItemMessage message)
|
||||
{
|
||||
@@ -611,7 +772,87 @@ public partial class TopLevelCommandManager : ObservableObject,
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_extensionLoadCts.Cancel();
|
||||
_extensionLoadCts.Dispose();
|
||||
_reloadCommandsGate.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
private sealed class ExtensionStartResult
|
||||
{
|
||||
public IExtensionWrapper Extension { get; }
|
||||
|
||||
public CommandProviderWrapper? Wrapper { get; private init; }
|
||||
|
||||
public Task? PendingStartTask { get; private init; }
|
||||
|
||||
public Stopwatch? Stopwatch { get; private init; }
|
||||
|
||||
[MemberNotNullWhen(true, nameof(Wrapper))]
|
||||
public bool IsStarted => Wrapper is not null;
|
||||
|
||||
[MemberNotNullWhen(true, nameof(PendingStartTask), nameof(Stopwatch))]
|
||||
public bool IsTimedOut => PendingStartTask is not null;
|
||||
|
||||
private ExtensionStartResult(IExtensionWrapper extension)
|
||||
{
|
||||
Extension = extension;
|
||||
}
|
||||
|
||||
public static ExtensionStartResult Started(IExtensionWrapper extension, CommandProviderWrapper wrapper)
|
||||
{
|
||||
return new ExtensionStartResult(extension) { Wrapper = wrapper };
|
||||
}
|
||||
|
||||
public static ExtensionStartResult TimedOut(IExtensionWrapper extension, Task pendingStartTask, Stopwatch sw)
|
||||
{
|
||||
return new ExtensionStartResult(extension) { PendingStartTask = pendingStartTask, Stopwatch = sw };
|
||||
}
|
||||
|
||||
public static ExtensionStartResult Failed(IExtensionWrapper extension)
|
||||
{
|
||||
return new ExtensionStartResult(extension);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class CommandLoadResult
|
||||
{
|
||||
public TopLevelObjectSets? TopLevelObjectSets { get; private init; }
|
||||
|
||||
public CommandProviderWrapper Wrapper { get; }
|
||||
|
||||
public Task<TopLevelObjectSets>? PendingLoadTask { get; private init; }
|
||||
|
||||
public Stopwatch? Stopwatch { get; private init; }
|
||||
|
||||
[MemberNotNullWhen(true, nameof(TopLevelObjectSets))]
|
||||
public bool IsLoaded => TopLevelObjectSets is not null;
|
||||
|
||||
[MemberNotNullWhen(true, nameof(PendingLoadTask), nameof(Stopwatch))]
|
||||
public bool IsTimedOut => PendingLoadTask is not null;
|
||||
|
||||
private CommandLoadResult(CommandProviderWrapper wrapper)
|
||||
{
|
||||
Wrapper = wrapper;
|
||||
}
|
||||
|
||||
public static CommandLoadResult Loaded(CommandProviderWrapper wrapper, TopLevelObjectSets topLevelObjectSets)
|
||||
{
|
||||
return new CommandLoadResult(wrapper) { TopLevelObjectSets = topLevelObjectSets };
|
||||
}
|
||||
|
||||
public static CommandLoadResult TimedOut(CommandProviderWrapper wrapper, Task<TopLevelObjectSets> pendingLoadTask, Stopwatch sw)
|
||||
{
|
||||
return new CommandLoadResult(wrapper) { PendingLoadTask = pendingLoadTask, Stopwatch = sw };
|
||||
}
|
||||
|
||||
public static CommandLoadResult Failed(CommandProviderWrapper wrapper)
|
||||
{
|
||||
return new CommandLoadResult(wrapper);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly record struct RegisterAndLoadSummary(int CommandCount, int DockBandCount);
|
||||
|
||||
private record TopLevelObjectSets(ICollection<TopLevelViewModel>? Commands, ICollection<TopLevelViewModel>? DockBands);
|
||||
}
|
||||
|
||||
@@ -193,7 +193,11 @@
|
||||
SelectionMode="None">
|
||||
<GridView.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<controls:UniformGrid ui:FrameworkElementExtensions.AncestorType="local:ColorPalette" Columns="{Binding (ui:FrameworkElementExtensions.Ancestor).CustomPaletteColumnCount, RelativeSource={RelativeSource Self}}" />
|
||||
<controls:UniformGrid ui:FrameworkElementExtensions.AncestorType="local:ColorPalette">
|
||||
<controls:UniformGrid.Columns>
|
||||
<Binding Path="(ui:FrameworkElementExtensions.Ancestor).CustomPaletteColumnCount" RelativeSource="{RelativeSource Self}" />
|
||||
</controls:UniformGrid.Columns>
|
||||
</controls:UniformGrid>
|
||||
</ItemsPanelTemplate>
|
||||
</GridView.ItemsPanel>
|
||||
<GridView.ItemTemplate>
|
||||
|
||||
@@ -53,7 +53,15 @@
|
||||
TextTrimming="WordEllipsis"
|
||||
TextWrapping="NoWrap">
|
||||
<ToolTipService.ToolTip>
|
||||
<ToolTip Content="{x:Bind Title, Mode=OneWay}" Visibility="{Binding IsTextTrimmed, ElementName=TitleTextBlock, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}" />
|
||||
<ToolTip x:DataType="TextBlock" Content="{x:Bind Title, Mode=OneWay}">
|
||||
<ToolTip.Visibility>
|
||||
<Binding
|
||||
Converter="{StaticResource BoolToVisibilityConverter}"
|
||||
ElementName="TitleTextBlock"
|
||||
Mode="OneWay"
|
||||
Path="IsTextTrimmed" />
|
||||
</ToolTip.Visibility>
|
||||
</ToolTip>
|
||||
</ToolTipService.ToolTip>
|
||||
</TextBlock>
|
||||
<TextBlock
|
||||
@@ -95,7 +103,15 @@
|
||||
TextTrimming="WordEllipsis"
|
||||
TextWrapping="NoWrap">
|
||||
<ToolTipService.ToolTip>
|
||||
<ToolTip Content="{x:Bind Title, Mode=OneWay}" Visibility="{Binding IsTextTrimmed, ElementName=TitleTextBlock, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}" />
|
||||
<ToolTip Content="{x:Bind Title, Mode=OneWay}">
|
||||
<ToolTip.Visibility>
|
||||
<Binding
|
||||
Converter="{StaticResource BoolToVisibilityConverter}"
|
||||
ElementName="TitleTextBlock"
|
||||
Mode="OneWay"
|
||||
Path="IsTextTrimmed" />
|
||||
</ToolTip.Visibility>
|
||||
</ToolTip>
|
||||
</ToolTipService.ToolTip>
|
||||
</TextBlock>
|
||||
<TextBlock
|
||||
@@ -161,6 +177,17 @@
|
||||
Style="{StaticResource SearchTextBoxStyle}"
|
||||
TextChanged="ContextFilterBox_TextChanged" />
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="FilterBoxVisibility">
|
||||
<VisualState x:Name="FilterBoxVisible" />
|
||||
<VisualState x:Name="FilterBoxCollapsed">
|
||||
<VisualState.StateTriggers>
|
||||
<ui:IsEqualStateTrigger Value="{x:Bind ShowFilterBox, Mode=OneWay}" To="False" />
|
||||
</VisualState.StateTriggers>
|
||||
<VisualState.Setters>
|
||||
<Setter Target="ContextFilterBox.Visibility" Value="Collapsed" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
<VisualStateGroup x:Name="ContextMenuOrder">
|
||||
<VisualState x:Name="FilterOnTop">
|
||||
<VisualState.StateTriggers>
|
||||
|
||||
@@ -5,16 +5,15 @@
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using CommunityToolkit.WinUI;
|
||||
using Microsoft.CmdPal.Common.Text;
|
||||
using Microsoft.CmdPal.UI.Helpers;
|
||||
using Microsoft.CmdPal.UI.Messages;
|
||||
using Microsoft.CmdPal.UI.ViewModels;
|
||||
using Microsoft.CmdPal.UI.ViewModels.Messages;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.UI.Input;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Windows.System;
|
||||
using Windows.UI.Core;
|
||||
|
||||
namespace Microsoft.CmdPal.UI.Controls;
|
||||
|
||||
@@ -23,6 +22,15 @@ public sealed partial class ContextMenu : UserControl,
|
||||
IRecipient<UpdateCommandBarMessage>,
|
||||
IRecipient<TryCommandKeybindingMessage>
|
||||
{
|
||||
public static readonly DependencyProperty ShowFilterBoxProperty =
|
||||
DependencyProperty.Register(nameof(ShowFilterBox), typeof(bool), typeof(ContextMenu), new PropertyMetadata(true));
|
||||
|
||||
public bool ShowFilterBox
|
||||
{
|
||||
get => (bool)GetValue(ShowFilterBoxProperty);
|
||||
set => SetValue(ShowFilterBoxProperty, value);
|
||||
}
|
||||
|
||||
public ContextMenuViewModel ViewModel { get; }
|
||||
|
||||
public ContextMenu()
|
||||
@@ -92,13 +100,9 @@ public sealed partial class ContextMenu : UserControl,
|
||||
return;
|
||||
}
|
||||
|
||||
var ctrlPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
|
||||
var altPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Menu).HasFlag(CoreVirtualKeyStates.Down);
|
||||
var shiftPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
|
||||
var winPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.LeftWindows).HasFlag(CoreVirtualKeyStates.Down) ||
|
||||
InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.RightWindows).HasFlag(CoreVirtualKeyStates.Down);
|
||||
var mods = KeyModifiers.GetCurrent();
|
||||
|
||||
var result = ViewModel?.CheckKeybinding(ctrlPressed, altPressed, shiftPressed, winPressed, e.Key);
|
||||
var result = ViewModel?.CheckKeybinding(mods.Ctrl, mods.Alt, mods.Shift, mods.Win, e.Key);
|
||||
|
||||
if (result == ContextKeybindingResult.Hide)
|
||||
{
|
||||
@@ -156,11 +160,7 @@ public sealed partial class ContextMenu : UserControl,
|
||||
|
||||
private void ContextFilterBox_KeyDown(object sender, KeyRoutedEventArgs e)
|
||||
{
|
||||
var ctrlPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
|
||||
var altPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Menu).HasFlag(CoreVirtualKeyStates.Down);
|
||||
var shiftPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
|
||||
var winPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.LeftWindows).HasFlag(CoreVirtualKeyStates.Down) ||
|
||||
InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.RightWindows).HasFlag(CoreVirtualKeyStates.Down);
|
||||
var modifiers = KeyModifiers.GetCurrent();
|
||||
|
||||
if (e.Key == VirtualKey.Enter)
|
||||
{
|
||||
@@ -177,7 +177,7 @@ public sealed partial class ContextMenu : UserControl,
|
||||
}
|
||||
}
|
||||
else if (e.Key == VirtualKey.Escape ||
|
||||
(e.Key == VirtualKey.Left && altPressed))
|
||||
(e.Key == VirtualKey.Left && modifiers.Alt))
|
||||
{
|
||||
if (ViewModel.CanPopContextStack())
|
||||
{
|
||||
|
||||
@@ -22,20 +22,9 @@
|
||||
Default="{StaticResource FilterItemViewModelTemplate}"
|
||||
Separator="{StaticResource SeparatorViewModelTemplate}" />
|
||||
|
||||
<Style
|
||||
x:Name="ComboBoxStyle"
|
||||
BasedOn="{StaticResource DefaultComboBoxStyle}"
|
||||
TargetType="ComboBox">
|
||||
<Style.Setters>
|
||||
<Setter Property="Visibility" Value="Collapsed" />
|
||||
<Setter Property="Margin" Value="0,0,12,0" />
|
||||
<Setter Property="Padding" Value="16,4" />
|
||||
</Style.Setters>
|
||||
</Style>
|
||||
|
||||
<!-- Template for the filter items -->
|
||||
<DataTemplate x:Key="FilterItemViewModelTemplate" x:DataType="viewModels:FilterItemViewModel">
|
||||
<Grid AutomationProperties.Name="{x:Bind Name, Mode=OneWay}">
|
||||
<Grid Padding="12,8,12,8" AutomationProperties.Name="{x:Bind Name, Mode=OneWay}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="32" />
|
||||
<ColumnDefinition Width="*" />
|
||||
@@ -58,34 +47,100 @@
|
||||
<DataTemplate x:Key="SeparatorViewModelTemplate" x:DataType="viewModels:SeparatorViewModel">
|
||||
<Rectangle
|
||||
Height="1"
|
||||
Margin="-16,-12,-12,-12"
|
||||
Margin="0,2,0,2"
|
||||
Fill="{ThemeResource MenuFlyoutSeparatorBackground}" />
|
||||
</DataTemplate>
|
||||
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
|
||||
<ComboBox
|
||||
Name="FiltersComboBox"
|
||||
x:Uid="FiltersComboBox"
|
||||
<DropDownButton
|
||||
x:Name="FilterDropDownButton"
|
||||
x:Uid="FiltersDropDown"
|
||||
MinWidth="200"
|
||||
Margin="0,0,12,0"
|
||||
Padding="16,5,8,5"
|
||||
VerticalAlignment="Center"
|
||||
ItemTemplateSelector="{StaticResource FilterTemplateSelector}"
|
||||
ItemsSource="{x:Bind ViewModel.Filters, Mode=OneWay}"
|
||||
PlaceholderText="Filters"
|
||||
PreviewKeyDown="FiltersComboBox_PreviewKeyDown"
|
||||
SelectedValue="{x:Bind ViewModel.CurrentFilter, Mode=OneWay}"
|
||||
SelectionChanged="FiltersComboBox_SelectionChanged"
|
||||
Style="{StaticResource ComboBoxStyle}"
|
||||
HorizontalContentAlignment="Left"
|
||||
PreviewKeyDown="FilterDropDownButton_PreviewKeyDown"
|
||||
Visibility="{x:Bind ViewModel.ShouldShowFilters, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}, FallbackValue=Collapsed}">
|
||||
<ComboBox.ItemContainerStyle>
|
||||
<Style BasedOn="{StaticResource DefaultComboBoxItemStyle}" TargetType="ComboBoxItem">
|
||||
<Setter Property="MinHeight" Value="0" />
|
||||
<Setter Property="Padding" Value="12,8" />
|
||||
</Style>
|
||||
</ComboBox.ItemContainerStyle>
|
||||
<ComboBox.ItemContainerTransitions>
|
||||
<TransitionCollection />
|
||||
</ComboBox.ItemContainerTransitions>
|
||||
</ComboBox>
|
||||
<DropDownButton.Content>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<cpcontrols:IconBox
|
||||
x:Name="SelectedFilterIcon"
|
||||
Width="16"
|
||||
Margin="0,0,8,0"
|
||||
VerticalAlignment="Center"
|
||||
AutomationProperties.AccessibilityView="Raw"
|
||||
SourceRequested="{x:Bind help:IconCacheProvider.SourceRequested20}"
|
||||
Visibility="Collapsed" />
|
||||
<TextBlock x:Name="SelectedFilterText" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</DropDownButton.Content>
|
||||
<DropDownButton.Flyout>
|
||||
<Flyout
|
||||
x:Name="FilterFlyout"
|
||||
Closed="FilterFlyout_Closed"
|
||||
Opened="FilterFlyout_Opened"
|
||||
Placement="BottomEdgeAlignedRight">
|
||||
<Flyout.FlyoutPresenterStyle>
|
||||
<Style BasedOn="{StaticResource DefaultFlyoutPresenterStyle}" TargetType="FlyoutPresenter">
|
||||
<Setter Property="Padding" Value="0" />
|
||||
<Setter Property="CornerRadius" Value="{StaticResource OverlayCornerRadius}" />
|
||||
</Style>
|
||||
</Flyout.FlyoutPresenterStyle>
|
||||
<Grid MinWidth="200">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBox
|
||||
x:Name="FilterSearchBox"
|
||||
x:Uid="FilterSearchBox"
|
||||
Margin="0"
|
||||
Padding="10,7,6,8"
|
||||
Background="{ThemeResource AcrylicBackgroundFillColorBaseBrush}"
|
||||
BorderThickness="0,0,0,2"
|
||||
CornerRadius="8,8,0,0"
|
||||
PreviewKeyDown="FilterSearchBox_PreviewKeyDown"
|
||||
Style="{StaticResource SearchTextBoxStyle}"
|
||||
TextChanged="FilterSearchBox_TextChanged" />
|
||||
<Border
|
||||
Grid.Row="1"
|
||||
BorderBrush="{ThemeResource MenuFlyoutSeparatorBackground}"
|
||||
BorderThickness="0,0,0,1" />
|
||||
<ListView
|
||||
x:Name="FilterListView"
|
||||
x:Uid="FilterListView"
|
||||
Grid.Row="2"
|
||||
MaxHeight="300"
|
||||
Margin="0,4,0,4"
|
||||
IsItemClickEnabled="True"
|
||||
ItemClick="FilterListView_ItemClick"
|
||||
ItemTemplateSelector="{StaticResource FilterTemplateSelector}"
|
||||
SelectionMode="Single">
|
||||
<ListView.ItemContainerStyle>
|
||||
<Style BasedOn="{StaticResource DefaultListViewItemStyle}" TargetType="ListViewItem">
|
||||
<Setter Property="MinHeight" Value="0" />
|
||||
<Setter Property="Padding" Value="0" />
|
||||
</Style>
|
||||
</ListView.ItemContainerStyle>
|
||||
<ListView.ItemContainerTransitions>
|
||||
<TransitionCollection />
|
||||
</ListView.ItemContainerTransitions>
|
||||
</ListView>
|
||||
<TextBlock
|
||||
x:Name="NoResultsText"
|
||||
x:Uid="FiltersDropDown_NoResults"
|
||||
Grid.Row="2"
|
||||
Margin="0,16"
|
||||
HorizontalAlignment="Center"
|
||||
AutomationProperties.LiveSetting="Polite"
|
||||
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
|
||||
Visibility="Collapsed" />
|
||||
</Grid>
|
||||
</Flyout>
|
||||
</DropDownButton.Flyout>
|
||||
</DropDownButton>
|
||||
</UserControl>
|
||||
|
||||
@@ -2,11 +2,17 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using Microsoft.CmdPal.UI.Helpers;
|
||||
using Microsoft.CmdPal.UI.ViewModels;
|
||||
using Microsoft.CmdPal.UI.ViewModels.Messages;
|
||||
using Microsoft.CmdPal.UI.Views;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Windows.Foundation;
|
||||
using Windows.System;
|
||||
|
||||
namespace Microsoft.CmdPal.UI.Controls;
|
||||
@@ -14,6 +20,11 @@ namespace Microsoft.CmdPal.UI.Controls;
|
||||
public sealed partial class FiltersDropDown : UserControl,
|
||||
ICurrentPageAware
|
||||
{
|
||||
private bool _isDropDownOpen;
|
||||
private string? _pendingSearchText;
|
||||
private IFilterItemViewModel[] _allItems = [];
|
||||
private FilterItemViewModel? _lastSelectedFilter;
|
||||
|
||||
public PageViewModel? CurrentPageViewModel
|
||||
{
|
||||
get => (PageViewModel?)GetValue(CurrentPageViewModelProperty);
|
||||
@@ -62,11 +73,146 @@ public sealed partial class FiltersDropDown : UserControl,
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ViewModelProperty =
|
||||
DependencyProperty.Register(nameof(ViewModel), typeof(FiltersViewModel), typeof(FiltersDropDown), new PropertyMetadata(null));
|
||||
DependencyProperty.Register(nameof(ViewModel), typeof(FiltersViewModel), typeof(FiltersDropDown), new PropertyMetadata(null, OnViewModelChanged));
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the dropdown is currently open or the button has keyboard focus.
|
||||
/// </summary>
|
||||
public bool IsActive => _isDropDownOpen ||
|
||||
FilterDropDownButton.FocusState != FocusState.Unfocused;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the filter control is visible (has filters to show).
|
||||
/// </summary>
|
||||
public bool IsFilterVisible => ViewModel?.ShouldShowFilters ?? false;
|
||||
|
||||
private static readonly string _defaultFilterText = ResourceLoaderInstance.GetString("FiltersDropDown_DefaultText");
|
||||
|
||||
public FiltersDropDown()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
SelectedFilterText.Text = _defaultFilterText;
|
||||
FilterDropDownButton.AddHandler(
|
||||
CharacterReceivedEvent,
|
||||
new TypedEventHandler<UIElement, CharacterReceivedRoutedEventArgs>(FilterDropDownButton_CharacterReceived),
|
||||
true);
|
||||
}
|
||||
|
||||
private static void OnViewModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is not FiltersDropDown @this)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.OldValue is FiltersViewModel oldVm)
|
||||
{
|
||||
oldVm.PropertyChanged -= @this.ViewModel_PropertyChanged;
|
||||
}
|
||||
|
||||
if (e.NewValue is FiltersViewModel newVm)
|
||||
{
|
||||
newVm.PropertyChanged += @this.ViewModel_PropertyChanged;
|
||||
}
|
||||
|
||||
@this.OnFiltersChanged();
|
||||
}
|
||||
|
||||
private void ViewModel_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName is nameof(FiltersViewModel.Filters)
|
||||
or nameof(FiltersViewModel.CurrentFilter)
|
||||
or nameof(FiltersViewModel.ShouldShowFilters))
|
||||
{
|
||||
OnFiltersChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFiltersChanged()
|
||||
{
|
||||
_allItems = ViewModel?.Filters ?? [];
|
||||
UpdateFilteredList();
|
||||
UpdateSelectedFilterDisplay();
|
||||
}
|
||||
|
||||
private void UpdateSelectedFilterDisplay()
|
||||
{
|
||||
if (ViewModel?.CurrentFilter is FilterItemViewModel filter)
|
||||
{
|
||||
SelectedFilterText.Text = filter.Name;
|
||||
SelectedFilterIcon.SourceKey = filter.Icon;
|
||||
SelectedFilterIcon.Visibility = Visibility.Visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedFilterText.Text = _defaultFilterText;
|
||||
SelectedFilterIcon.SourceKey = null;
|
||||
SelectedFilterIcon.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateFilteredList()
|
||||
{
|
||||
if (FilterListView == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var searchText = FilterSearchBox?.Text?.Trim() ?? string.Empty;
|
||||
|
||||
IFilterItemViewModel[] filtered;
|
||||
if (string.IsNullOrEmpty(searchText))
|
||||
{
|
||||
filtered = _allItems;
|
||||
}
|
||||
else
|
||||
{
|
||||
var list = new List<IFilterItemViewModel>();
|
||||
foreach (var item in _allItems)
|
||||
{
|
||||
if (item is FilterItemViewModel filterItem &&
|
||||
filterItem.Name.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) > -1)
|
||||
{
|
||||
list.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
filtered = list.ToArray();
|
||||
}
|
||||
|
||||
FilterListView.ItemsSource = filtered;
|
||||
|
||||
var hasResults = filtered.Length > 0;
|
||||
FilterListView.Visibility = hasResults ? Visibility.Visible : Visibility.Collapsed;
|
||||
NoResultsText.Visibility = hasResults ? Visibility.Collapsed : Visibility.Visible;
|
||||
|
||||
// Restore selection to current filter if present
|
||||
if (_lastSelectedFilter != null && Array.IndexOf(filtered, _lastSelectedFilter) >= 0)
|
||||
{
|
||||
FilterListView.SelectedItem = _lastSelectedFilter;
|
||||
}
|
||||
else if (ViewModel?.CurrentFilter != null && Array.IndexOf(filtered, ViewModel.CurrentFilter) >= 0)
|
||||
{
|
||||
FilterListView.SelectedItem = ViewModel.CurrentFilter;
|
||||
}
|
||||
else if (hasResults)
|
||||
{
|
||||
// Select the first non-separator item
|
||||
IFilterItemViewModel? first = null;
|
||||
foreach (var item in filtered)
|
||||
{
|
||||
if (item is not SeparatorViewModel)
|
||||
{
|
||||
first = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (first != null)
|
||||
{
|
||||
FilterListView.SelectedItem = first;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Used to handle the case when a ListPage's `Filters` may have changed
|
||||
@@ -83,55 +229,239 @@ public sealed partial class FiltersDropDown : UserControl,
|
||||
}
|
||||
}
|
||||
|
||||
private void FiltersComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
private void FilterDropDownButton_CharacterReceived(UIElement sender, CharacterReceivedRoutedEventArgs args)
|
||||
{
|
||||
if (CurrentPageViewModel is ListViewModel listViewModel &&
|
||||
FiltersComboBox.SelectedItem is FilterItemViewModel filterItem)
|
||||
// Redirect printable (non-space) characters to open flyout and type into search
|
||||
if (!char.IsControl(args.Character) && args.Character != ' ')
|
||||
{
|
||||
listViewModel.UpdateCurrentFilter(filterItem.Id);
|
||||
OpenFlyoutAndType(args.Character.ToString());
|
||||
args.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void FiltersComboBox_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
|
||||
private void FilterDropDownButton_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
|
||||
{
|
||||
if (e.Key == VirtualKey.Up)
|
||||
{
|
||||
NavigateUp();
|
||||
var modifiers = KeyModifiers.GetCurrent();
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
else if (e.Key == VirtualKey.Down)
|
||||
switch (e.Key)
|
||||
{
|
||||
NavigateDown();
|
||||
case VirtualKey.Down when modifiers.OnlyAlt:
|
||||
goto case VirtualKey.F4;
|
||||
|
||||
e.Handled = true;
|
||||
case VirtualKey.Down or VirtualKey.Up:
|
||||
{
|
||||
if (!_isDropDownOpen)
|
||||
{
|
||||
FilterFlyout.ShowAt(FilterDropDownButton);
|
||||
}
|
||||
|
||||
if (e.Key == VirtualKey.Down)
|
||||
{
|
||||
NavigateDown();
|
||||
}
|
||||
else
|
||||
{
|
||||
NavigateUp();
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case VirtualKey.F4:
|
||||
{
|
||||
if (!_isDropDownOpen)
|
||||
{
|
||||
FilterFlyout.ShowAt(FilterDropDownButton);
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FilterSearchBox_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
|
||||
{
|
||||
var modifiers = KeyModifiers.GetCurrent();
|
||||
|
||||
switch (e.Key)
|
||||
{
|
||||
case VirtualKey.Down:
|
||||
NavigateDown();
|
||||
e.Handled = true;
|
||||
break;
|
||||
case VirtualKey.Up:
|
||||
NavigateUp();
|
||||
e.Handled = true;
|
||||
break;
|
||||
case VirtualKey.Enter:
|
||||
SelectCurrentAndClose();
|
||||
e.Handled = true;
|
||||
break;
|
||||
case VirtualKey.Escape:
|
||||
if (!string.IsNullOrEmpty(FilterSearchBox.Text))
|
||||
{
|
||||
FilterSearchBox.Text = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
CloseDropDownAndFocusSearch();
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
break;
|
||||
case VirtualKey.F when modifiers.Alt:
|
||||
CloseDropDownAndFocusSearch();
|
||||
e.Handled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void FilterSearchBox_TextChanged(object sender, TextChangedEventArgs e) =>
|
||||
UpdateFilteredList();
|
||||
|
||||
private void FilterListView_ItemClick(object sender, ItemClickEventArgs e)
|
||||
{
|
||||
if (e.ClickedItem is FilterItemViewModel filterItem)
|
||||
{
|
||||
SelectFilter(filterItem);
|
||||
CloseDropDownAndFocusSearch();
|
||||
}
|
||||
}
|
||||
|
||||
private void FilterFlyout_Opened(object sender, object e)
|
||||
{
|
||||
_isDropDownOpen = true;
|
||||
|
||||
FilterSearchBox.Text = _pendingSearchText ?? string.Empty;
|
||||
FilterSearchBox.SelectionStart = FilterSearchBox.Text.Length;
|
||||
_pendingSearchText = null;
|
||||
|
||||
UpdateFilteredList();
|
||||
FilterSearchBox.Focus(FocusState.Programmatic);
|
||||
}
|
||||
|
||||
private void FilterFlyout_Closed(object sender, object e)
|
||||
{
|
||||
_isDropDownOpen = false;
|
||||
_pendingSearchText = null;
|
||||
FilterSearchBox.Text = string.Empty;
|
||||
}
|
||||
|
||||
private void OpenFlyoutAndType(string text)
|
||||
{
|
||||
_pendingSearchText = (_pendingSearchText ?? string.Empty) + text;
|
||||
if (!_isDropDownOpen)
|
||||
{
|
||||
FilterFlyout.ShowAt(FilterDropDownButton);
|
||||
}
|
||||
else
|
||||
{
|
||||
FilterSearchBox.Text = _pendingSearchText;
|
||||
FilterSearchBox.SelectionStart = FilterSearchBox.Text.Length;
|
||||
FilterSearchBox.Focus(FocusState.Programmatic);
|
||||
_pendingSearchText = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens the filter dropdown flyout.
|
||||
/// </summary>
|
||||
public void OpenDropDown()
|
||||
{
|
||||
if (!_isDropDownOpen)
|
||||
{
|
||||
FilterFlyout.ShowAt(FilterDropDownButton);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Closes the filter dropdown flyout and returns focus to the main search box.
|
||||
/// </summary>
|
||||
public void CloseDropDownAndFocusSearch()
|
||||
{
|
||||
if (_isDropDownOpen)
|
||||
{
|
||||
FilterFlyout.Hide();
|
||||
}
|
||||
|
||||
WeakReferenceMessenger.Default.Send<FocusSearchBoxMessage>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Closes the filter dropdown flyout.
|
||||
/// </summary>
|
||||
public void CloseDropDown()
|
||||
{
|
||||
if (_isDropDownOpen)
|
||||
{
|
||||
FilterFlyout.Hide();
|
||||
}
|
||||
|
||||
FilterDropDownButton.Focus(FocusState.Programmatic);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves focus to this control (the dropdown button).
|
||||
/// </summary>
|
||||
public void FocusControl()
|
||||
{
|
||||
FilterDropDownButton.Focus(FocusState.Programmatic);
|
||||
}
|
||||
|
||||
private void SelectCurrentAndClose()
|
||||
{
|
||||
if (FilterListView.SelectedItem is FilterItemViewModel filterItem)
|
||||
{
|
||||
SelectFilter(filterItem);
|
||||
}
|
||||
|
||||
CloseDropDownAndFocusSearch();
|
||||
}
|
||||
|
||||
private void SelectFilter(FilterItemViewModel filterItem)
|
||||
{
|
||||
_lastSelectedFilter = filterItem;
|
||||
|
||||
if (CurrentPageViewModel is ListViewModel listViewModel)
|
||||
{
|
||||
listViewModel.UpdateCurrentFilter(filterItem.Id);
|
||||
}
|
||||
|
||||
// Update display immediately (UpdateCurrentFilter is async)
|
||||
SelectedFilterText.Text = filterItem.Name;
|
||||
SelectedFilterIcon.SourceKey = filterItem.Icon;
|
||||
SelectedFilterIcon.Visibility = Visibility.Visible;
|
||||
}
|
||||
|
||||
private void NavigateUp()
|
||||
{
|
||||
var newIndex = FiltersComboBox.SelectedIndex;
|
||||
if (FilterListView.ItemsSource is not IFilterItemViewModel[] items || items.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (FiltersComboBox.SelectedIndex > 0)
|
||||
if (!HasSelectableItem(items))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var newIndex = FilterListView.SelectedIndex;
|
||||
|
||||
if (newIndex > 0)
|
||||
{
|
||||
newIndex--;
|
||||
|
||||
while (
|
||||
newIndex >= 0 &&
|
||||
IsSeparator(FiltersComboBox.Items[newIndex]) &&
|
||||
newIndex != FiltersComboBox.SelectedIndex)
|
||||
while (newIndex >= 0 && IsSeparator(items[newIndex]))
|
||||
{
|
||||
newIndex--;
|
||||
}
|
||||
|
||||
if (newIndex < 0)
|
||||
{
|
||||
newIndex = FiltersComboBox.Items.Count - 1;
|
||||
|
||||
while (
|
||||
newIndex >= 0 &&
|
||||
IsSeparator(FiltersComboBox.Items[newIndex]) &&
|
||||
newIndex != FiltersComboBox.SelectedIndex)
|
||||
newIndex = items.Length - 1;
|
||||
while (newIndex >= 0 && IsSeparator(items[newIndex]))
|
||||
{
|
||||
newIndex--;
|
||||
}
|
||||
@@ -139,17 +469,35 @@ public sealed partial class FiltersDropDown : UserControl,
|
||||
}
|
||||
else
|
||||
{
|
||||
newIndex = FiltersComboBox.Items.Count - 1;
|
||||
newIndex = items.Length - 1;
|
||||
while (newIndex >= 0 && IsSeparator(items[newIndex]))
|
||||
{
|
||||
newIndex--;
|
||||
}
|
||||
}
|
||||
|
||||
FiltersComboBox.SelectedIndex = newIndex;
|
||||
if (newIndex >= 0)
|
||||
{
|
||||
FilterListView.SelectedIndex = newIndex;
|
||||
FilterListView.ScrollIntoView(FilterListView.SelectedItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void NavigateDown()
|
||||
{
|
||||
var newIndex = FiltersComboBox.SelectedIndex;
|
||||
if (FilterListView.ItemsSource is not IFilterItemViewModel[] items || items.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (FiltersComboBox.SelectedIndex == FiltersComboBox.Items.Count - 1)
|
||||
if (!HasSelectableItem(items))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var newIndex = FilterListView.SelectedIndex;
|
||||
|
||||
if (newIndex >= items.Length - 1)
|
||||
{
|
||||
newIndex = 0;
|
||||
}
|
||||
@@ -157,33 +505,40 @@ public sealed partial class FiltersDropDown : UserControl,
|
||||
{
|
||||
newIndex++;
|
||||
|
||||
while (
|
||||
newIndex < FiltersComboBox.Items.Count &&
|
||||
IsSeparator(FiltersComboBox.Items[newIndex]) &&
|
||||
newIndex != FiltersComboBox.SelectedIndex)
|
||||
while (newIndex < items.Length && IsSeparator(items[newIndex]))
|
||||
{
|
||||
newIndex++;
|
||||
}
|
||||
|
||||
if (newIndex >= FiltersComboBox.Items.Count)
|
||||
if (newIndex >= items.Length)
|
||||
{
|
||||
newIndex = 0;
|
||||
|
||||
while (
|
||||
newIndex < FiltersComboBox.Items.Count &&
|
||||
IsSeparator(FiltersComboBox.Items[newIndex]) &&
|
||||
newIndex != FiltersComboBox.SelectedIndex)
|
||||
while (newIndex < items.Length && IsSeparator(items[newIndex]))
|
||||
{
|
||||
newIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FiltersComboBox.SelectedIndex = newIndex;
|
||||
if (newIndex < items.Length)
|
||||
{
|
||||
FilterListView.SelectedIndex = newIndex;
|
||||
FilterListView.ScrollIntoView(FilterListView.SelectedItem);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsSeparator(object item)
|
||||
private static bool IsSeparator(object item) => item is SeparatorViewModel;
|
||||
|
||||
private static bool HasSelectableItem(IFilterItemViewModel[] items)
|
||||
{
|
||||
return item is SeparatorViewModel;
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (!IsSeparator(item))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
<Setter Property="Foreground" Value="{ThemeResource ButtonForeground}" />
|
||||
<Setter Property="BorderBrush" Value="{ThemeResource FlipViewNextPreviousButtonBorderBrush}" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="Padding" Value="0" />
|
||||
<Setter Property="Padding" Value="8,0,8,0" />
|
||||
<Setter Property="Margin" Value="0" />
|
||||
<Setter Property="HorizontalAlignment" Value="Left" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
|
||||
@@ -141,10 +142,10 @@
|
||||
Grid.Column="1">
|
||||
<ScrollViewer
|
||||
x:Name="scroller"
|
||||
HorizontalScrollBarVisibility="Hidden"
|
||||
HorizontalScrollBarVisibility="Disabled"
|
||||
HorizontalScrollMode="Enabled"
|
||||
SizeChanged="Scroller_SizeChanged"
|
||||
VerticalScrollBarVisibility="Hidden"
|
||||
VerticalScrollBarVisibility="Disabled"
|
||||
VerticalScrollMode="Disabled"
|
||||
ViewChanging="Scroller_ViewChanging">
|
||||
<Grid x:Name="ContentGrid">
|
||||
@@ -154,7 +155,7 @@
|
||||
<Button
|
||||
x:Name="ScrollBackBtn"
|
||||
Margin="8,0,0,0"
|
||||
Padding="2,8,2,8"
|
||||
Padding="4,8,4,8"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
AutomationProperties.Name="Scroll left"
|
||||
@@ -169,8 +170,8 @@
|
||||
</Button>
|
||||
<Button
|
||||
x:Name="ScrollForwardBtn"
|
||||
Margin="0,0,8,0"
|
||||
Padding="2,8,2,8"
|
||||
Margin="8,0,0,0"
|
||||
Padding="4,8,4,8"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Center"
|
||||
AutomationProperties.Name="Scroll right"
|
||||
@@ -180,7 +181,7 @@
|
||||
<FontIcon
|
||||
x:Name="ScrollForwardIcon"
|
||||
FontSize="{ThemeResource FlipViewButtonFontSize}"
|
||||
Glyph="" />
|
||||
Glyph="" />
|
||||
</Button>
|
||||
</Grid>
|
||||
|
||||
@@ -188,18 +189,18 @@
|
||||
<VisualStateGroup x:Name="OrientationStates">
|
||||
<VisualState x:Name="HorizontalState">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="scroller.HorizontalScrollBarVisibility" Value="Hidden" />
|
||||
<Setter Target="scroller.HorizontalScrollBarVisibility" Value="Disabled" />
|
||||
<Setter Target="scroller.HorizontalScrollMode" Value="Enabled" />
|
||||
<Setter Target="scroller.VerticalScrollBarVisibility" Value="Hidden" />
|
||||
<Setter Target="scroller.VerticalScrollBarVisibility" Value="Disabled" />
|
||||
<Setter Target="scroller.VerticalScrollMode" Value="Disabled" />
|
||||
<Setter Target="ScrollBackBtn.Padding" Value="4,12,4,12" />
|
||||
<Setter Target="ScrollBackBtn.Padding" Value="4,8,4,8" />
|
||||
<Setter Target="ScrollBackBtn.Margin" Value="8,0,0,0" />
|
||||
<Setter Target="ScrollBackBtn.HorizontalAlignment" Value="Left" />
|
||||
<Setter Target="ScrollBackBtn.VerticalAlignment" Value="Center" />
|
||||
<Setter Target="ScrollBackBtn.(AutomationProperties.Name)" Value="Scroll left" />
|
||||
<Setter Target="ScrollBackBtn.(ToolTipService.ToolTip)" Value="Scroll left" />
|
||||
<Setter Target="ScrollBackIcon.Glyph" Value="" />
|
||||
<Setter Target="ScrollForwardBtn.Padding" Value="4,12,4,12" />
|
||||
<Setter Target="ScrollForwardBtn.Padding" Value="4,8,4,8" />
|
||||
<Setter Target="ScrollForwardBtn.Margin" Value="0,0,8,0" />
|
||||
<Setter Target="ScrollForwardBtn.HorizontalAlignment" Value="Right" />
|
||||
<Setter Target="ScrollForwardBtn.VerticalAlignment" Value="Center" />
|
||||
@@ -210,9 +211,9 @@
|
||||
</VisualState>
|
||||
<VisualState x:Name="VerticalState">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="scroller.HorizontalScrollBarVisibility" Value="Hidden" />
|
||||
<Setter Target="scroller.HorizontalScrollBarVisibility" Value="Disabled" />
|
||||
<Setter Target="scroller.HorizontalScrollMode" Value="Disabled" />
|
||||
<Setter Target="scroller.VerticalScrollBarVisibility" Value="Hidden" />
|
||||
<Setter Target="scroller.VerticalScrollBarVisibility" Value="Disabled" />
|
||||
<Setter Target="scroller.VerticalScrollMode" Value="Enabled" />
|
||||
<Setter Target="ScrollBackBtn.Padding" Value="12,4,12,4" />
|
||||
<Setter Target="ScrollBackBtn.Margin" Value="0,8,0,0" />
|
||||
@@ -227,7 +228,7 @@
|
||||
<Setter Target="ScrollForwardBtn.VerticalAlignment" Value="Bottom" />
|
||||
<Setter Target="ScrollForwardBtn.(AutomationProperties.Name)" Value="Scroll down" />
|
||||
<Setter Target="ScrollForwardBtn.(ToolTipService.ToolTip)" Value="Scroll down" />
|
||||
<Setter Target="ScrollForwardIcon.Glyph" Value="" />
|
||||
<Setter Target="ScrollForwardIcon.Glyph" Value="" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
|
||||
@@ -5,17 +5,16 @@
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using CommunityToolkit.WinUI;
|
||||
using Microsoft.CmdPal.Ext.ClipboardHistory.Messages;
|
||||
using Microsoft.CmdPal.UI.Helpers;
|
||||
using Microsoft.CmdPal.UI.ViewModels;
|
||||
using Microsoft.CmdPal.UI.ViewModels.Commands;
|
||||
using Microsoft.CmdPal.UI.ViewModels.Messages;
|
||||
using Microsoft.CmdPal.UI.Views;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.UI.Dispatching;
|
||||
using Microsoft.UI.Input;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using CoreVirtualKeyStates = Windows.UI.Core.CoreVirtualKeyStates;
|
||||
using VirtualKey = Windows.System.VirtualKey;
|
||||
|
||||
namespace Microsoft.CmdPal.UI.Controls;
|
||||
@@ -125,8 +124,7 @@ public sealed partial class SearchBar : UserControl,
|
||||
return;
|
||||
}
|
||||
|
||||
var ctrlPressed = (InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control) & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down;
|
||||
if (ctrlPressed && e.Key == VirtualKey.I)
|
||||
if (KeyModifiers.GetCurrent().Ctrl && e.Key == VirtualKey.I)
|
||||
{
|
||||
// Today you learned that Ctrl+I in a TextBox will insert a tab
|
||||
// We don't want that, so we'll suppress it, this way it can be used for other purposes
|
||||
|
||||
@@ -74,8 +74,14 @@
|
||||
Grid.Column="0"
|
||||
Width="12"
|
||||
Height="12"
|
||||
Margin="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource IconMarginConverter}}"
|
||||
SourceKey="{TemplateBinding Icon}" />
|
||||
SourceKey="{TemplateBinding Icon}">
|
||||
<local:IconBox.Margin>
|
||||
<Binding
|
||||
Converter="{StaticResource IconMarginConverter}"
|
||||
Path="Text"
|
||||
RelativeSource="{RelativeSource TemplatedParent}" />
|
||||
</local:IconBox.Margin>
|
||||
</local:IconBox>
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
Margin="0,-1,0,0"
|
||||
|
||||
@@ -16,21 +16,38 @@ internal sealed partial class FilterTemplateSelector : DataTemplateSelector
|
||||
public DataTemplate? Separator { get; set; }
|
||||
|
||||
[DynamicDependency(DynamicallyAccessedMemberTypes.All, "Microsoft.UI.Xaml.Controls.ComboBoxItem", "Microsoft.WinUI")]
|
||||
[DynamicDependency(DynamicallyAccessedMemberTypes.All, "Microsoft.UI.Xaml.Controls.ListViewItem", "Microsoft.WinUI")]
|
||||
protected override DataTemplate? SelectTemplateCore(object item, DependencyObject dependencyObject)
|
||||
{
|
||||
DataTemplate? dataTemplate = Default;
|
||||
|
||||
if (dependencyObject is ComboBoxItem comboBoxItem)
|
||||
{
|
||||
comboBoxItem.IsEnabled = true;
|
||||
var isSeparator = item is SeparatorViewModel;
|
||||
|
||||
if (item is SeparatorViewModel)
|
||||
{
|
||||
comboBoxItem.IsEnabled = false;
|
||||
comboBoxItem.AllowFocusWhenDisabled = false;
|
||||
comboBoxItem.AllowFocusOnInteraction = false;
|
||||
dataTemplate = Separator;
|
||||
}
|
||||
switch (dependencyObject)
|
||||
{
|
||||
case ComboBoxItem comboBoxItem:
|
||||
comboBoxItem.IsEnabled = !isSeparator;
|
||||
if (isSeparator)
|
||||
{
|
||||
comboBoxItem.AllowFocusWhenDisabled = false;
|
||||
comboBoxItem.AllowFocusOnInteraction = false;
|
||||
}
|
||||
|
||||
break;
|
||||
case ListViewItem listViewItem:
|
||||
listViewItem.IsEnabled = !isSeparator;
|
||||
if (isSeparator)
|
||||
{
|
||||
listViewItem.MinHeight = 0;
|
||||
listViewItem.IsHitTestVisible = false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (isSeparator)
|
||||
{
|
||||
dataTemplate = Separator;
|
||||
}
|
||||
|
||||
return dataTemplate;
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<UserControl
|
||||
x:Class="Microsoft.CmdPal.UI.Dock.DockContentControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:cpcontrols="using:Microsoft.CmdPal.UI.Controls"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:ui="using:CommunityToolkit.WinUI"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Grid x:Name="ContentGrid" Background="Transparent">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition x:Name="StartColumn" Width="*" />
|
||||
<ColumnDefinition x:Name="CenterColumn" Width="Auto" />
|
||||
<ColumnDefinition x:Name="EndColumn" Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition x:Name="StartRow" Height="*" />
|
||||
<RowDefinition x:Name="CenterRow" Height="Auto" />
|
||||
<RowDefinition x:Name="EndRow" Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<cpcontrols:ScrollContainer
|
||||
x:Name="StartScroller"
|
||||
Grid.RowSpan="3"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Stretch"
|
||||
ActionButton="{x:Bind StartActionButton, Mode=OneWay}"
|
||||
Source="{x:Bind StartSource, Mode=OneWay}" />
|
||||
|
||||
<cpcontrols:ScrollContainer
|
||||
x:Name="CenterScroller"
|
||||
Grid.RowSpan="3"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Stretch"
|
||||
ActionButton="{x:Bind CenterActionButton, Mode=OneWay}"
|
||||
Source="{x:Bind CenterSource, Mode=OneWay}" />
|
||||
|
||||
<cpcontrols:ScrollContainer
|
||||
x:Name="EndScroller"
|
||||
Grid.RowSpan="3"
|
||||
Grid.Column="2"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Stretch"
|
||||
ActionButton="{x:Bind EndActionButton, Mode=OneWay}"
|
||||
ContentAlignment="End"
|
||||
Source="{x:Bind EndSource, Mode=OneWay}" />
|
||||
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="OrientationStates">
|
||||
<VisualState x:Name="HorizontalState" />
|
||||
<VisualState x:Name="VerticalState">
|
||||
<VisualState.StateTriggers>
|
||||
<ui:IsEqualStateTrigger Value="{x:Bind Orientation, Mode=OneWay}" To="Vertical" />
|
||||
</VisualState.StateTriggers>
|
||||
<VisualState.Setters>
|
||||
<Setter Target="StartColumn.Width" Value="*" />
|
||||
<Setter Target="CenterColumn.Width" Value="*" />
|
||||
<Setter Target="EndColumn.Width" Value="*" />
|
||||
|
||||
<Setter Target="StartRow.Height" Value="*" />
|
||||
<Setter Target="CenterRow.Height" Value="Auto" />
|
||||
<Setter Target="EndRow.Height" Value="*" />
|
||||
|
||||
<Setter Target="StartScroller.(Grid.Row)" Value="0" />
|
||||
<Setter Target="StartScroller.(Grid.RowSpan)" Value="1" />
|
||||
<Setter Target="StartScroller.(Grid.Column)" Value="0" />
|
||||
<Setter Target="StartScroller.(Grid.ColumnSpan)" Value="3" />
|
||||
<Setter Target="StartScroller.Orientation" Value="Vertical" />
|
||||
<Setter Target="StartScroller.HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Target="StartScroller.VerticalAlignment" Value="Top" />
|
||||
|
||||
<Setter Target="CenterScroller.(Grid.Row)" Value="1" />
|
||||
<Setter Target="CenterScroller.(Grid.RowSpan)" Value="1" />
|
||||
<Setter Target="CenterScroller.(Grid.Column)" Value="0" />
|
||||
<Setter Target="CenterScroller.(Grid.ColumnSpan)" Value="3" />
|
||||
<Setter Target="CenterScroller.Orientation" Value="Vertical" />
|
||||
<Setter Target="CenterScroller.HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Target="CenterScroller.VerticalAlignment" Value="Center" />
|
||||
|
||||
<Setter Target="EndScroller.(Grid.Row)" Value="2" />
|
||||
<Setter Target="EndScroller.(Grid.RowSpan)" Value="1" />
|
||||
<Setter Target="EndScroller.(Grid.Column)" Value="0" />
|
||||
<Setter Target="EndScroller.(Grid.ColumnSpan)" Value="3" />
|
||||
<Setter Target="EndScroller.Orientation" Value="Vertical" />
|
||||
<Setter Target="EndScroller.HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Target="EndScroller.VerticalAlignment" Value="Bottom" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
|
||||
<VisualStateGroup x:Name="CenterVisibilityStates">
|
||||
<VisualState x:Name="CenterVisibleState" />
|
||||
<VisualState x:Name="CenterCollapsedState">
|
||||
<VisualState.StateTriggers>
|
||||
<ui:IsEqualStateTrigger Value="{x:Bind IsCenterVisible, Mode=OneWay}" To="False" />
|
||||
</VisualState.StateTriggers>
|
||||
<VisualState.Setters>
|
||||
<Setter Target="CenterColumn.Width" Value="0" />
|
||||
<Setter Target="CenterRow.Height" Value="0" />
|
||||
<Setter Target="EndColumn.Width" Value="Auto" />
|
||||
<Setter Target="EndRow.Height" Value="Auto" />
|
||||
<Setter Target="CenterScroller.Visibility" Value="Collapsed" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
|
||||
<VisualStateGroup x:Name="EditModeStates">
|
||||
<VisualState x:Name="EditModeOff" />
|
||||
<VisualState x:Name="EditModeOn">
|
||||
<VisualState.StateTriggers>
|
||||
<ui:IsEqualStateTrigger Value="{x:Bind IsEditMode, Mode=OneWay}" To="True" />
|
||||
</VisualState.StateTriggers>
|
||||
<VisualState.Setters>
|
||||
<Setter Target="CenterScroller.MinWidth" Value="48" />
|
||||
<Setter Target="StartScroller.BorderBrush" Value="{ThemeResource CardStrokeColorDefaultBrush}" />
|
||||
<Setter Target="StartScroller.Background" Value="{ThemeResource CardBackgroundFillColorDefaultBrush}" />
|
||||
<Setter Target="StartScroller.BorderThickness" Value="1" />
|
||||
<Setter Target="StartScroller.CornerRadius" Value="{StaticResource OverlayCornerRadius}" />
|
||||
<Setter Target="CenterScroller.BorderBrush" Value="{ThemeResource CardStrokeColorDefaultBrush}" />
|
||||
<Setter Target="CenterScroller.Background" Value="{ThemeResource CardBackgroundFillColorDefaultBrush}" />
|
||||
<Setter Target="CenterScroller.BorderThickness" Value="1" />
|
||||
<Setter Target="CenterScroller.CornerRadius" Value="{StaticResource OverlayCornerRadius}" />
|
||||
<Setter Target="EndScroller.BorderBrush" Value="{ThemeResource CardStrokeColorDefaultBrush}" />
|
||||
<Setter Target="EndScroller.Background" Value="{ThemeResource CardBackgroundFillColorDefaultBrush}" />
|
||||
<Setter Target="EndScroller.BorderThickness" Value="1" />
|
||||
<Setter Target="EndScroller.CornerRadius" Value="{StaticResource OverlayCornerRadius}" />
|
||||
<Setter Target="StartScroller.ActionButtonVisibility" Value="Visible" />
|
||||
<Setter Target="CenterScroller.ActionButtonVisibility" Value="Visible" />
|
||||
<Setter Target="EndScroller.ActionButtonVisibility" Value="Visible" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,103 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Microsoft.CmdPal.UI.Dock;
|
||||
|
||||
/// <summary>
|
||||
/// A control that arranges Start, Center, and End sections in a dock layout
|
||||
/// with built-in ScrollContainers. When <see cref="IsCenterVisible"/> is false,
|
||||
/// the center is collapsed, the start section stretches, and the end section
|
||||
/// auto-sizes. Supports horizontal/vertical orientation and edit mode styling.
|
||||
/// </summary>
|
||||
public sealed partial class DockContentControl : UserControl
|
||||
{
|
||||
public static readonly DependencyProperty OrientationProperty =
|
||||
DependencyProperty.Register(nameof(Orientation), typeof(Orientation), typeof(DockContentControl), new PropertyMetadata(Orientation.Horizontal));
|
||||
|
||||
public Orientation Orientation
|
||||
{
|
||||
get => (Orientation)GetValue(OrientationProperty);
|
||||
set => SetValue(OrientationProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsCenterVisibleProperty =
|
||||
DependencyProperty.Register(nameof(IsCenterVisible), typeof(bool), typeof(DockContentControl), new PropertyMetadata(true));
|
||||
|
||||
public bool IsCenterVisible
|
||||
{
|
||||
get => (bool)GetValue(IsCenterVisibleProperty);
|
||||
set => SetValue(IsCenterVisibleProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsEditModeProperty =
|
||||
DependencyProperty.Register(nameof(IsEditMode), typeof(bool), typeof(DockContentControl), new PropertyMetadata(false));
|
||||
|
||||
public bool IsEditMode
|
||||
{
|
||||
get => (bool)GetValue(IsEditModeProperty);
|
||||
set => SetValue(IsEditModeProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty StartSourceProperty =
|
||||
DependencyProperty.Register(nameof(StartSource), typeof(object), typeof(DockContentControl), new PropertyMetadata(null));
|
||||
|
||||
public object StartSource
|
||||
{
|
||||
get => GetValue(StartSourceProperty);
|
||||
set => SetValue(StartSourceProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty StartActionButtonProperty =
|
||||
DependencyProperty.Register(nameof(StartActionButton), typeof(object), typeof(DockContentControl), new PropertyMetadata(null));
|
||||
|
||||
public object StartActionButton
|
||||
{
|
||||
get => GetValue(StartActionButtonProperty);
|
||||
set => SetValue(StartActionButtonProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty CenterSourceProperty =
|
||||
DependencyProperty.Register(nameof(CenterSource), typeof(object), typeof(DockContentControl), new PropertyMetadata(null));
|
||||
|
||||
public object CenterSource
|
||||
{
|
||||
get => GetValue(CenterSourceProperty);
|
||||
set => SetValue(CenterSourceProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty CenterActionButtonProperty =
|
||||
DependencyProperty.Register(nameof(CenterActionButton), typeof(object), typeof(DockContentControl), new PropertyMetadata(null));
|
||||
|
||||
public object CenterActionButton
|
||||
{
|
||||
get => GetValue(CenterActionButtonProperty);
|
||||
set => SetValue(CenterActionButtonProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty EndSourceProperty =
|
||||
DependencyProperty.Register(nameof(EndSource), typeof(object), typeof(DockContentControl), new PropertyMetadata(null));
|
||||
|
||||
public object EndSource
|
||||
{
|
||||
get => GetValue(EndSourceProperty);
|
||||
set => SetValue(EndSourceProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty EndActionButtonProperty =
|
||||
DependencyProperty.Register(nameof(EndActionButton), typeof(object), typeof(DockContentControl), new PropertyMetadata(null));
|
||||
|
||||
public object EndActionButton
|
||||
{
|
||||
get => GetValue(EndActionButtonProperty);
|
||||
set => SetValue(EndActionButtonProperty, value);
|
||||
}
|
||||
|
||||
public DockContentControl()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,10 @@
|
||||
</ItemsPanelTemplate>
|
||||
|
||||
<DataTemplate x:Key="DockBandTemplate" x:DataType="dockVm:DockBandViewModel">
|
||||
<ItemsRepeater ItemsSource="{x:Bind Items, Mode=OneWay}" Layout="{StaticResource ItemsOrientationLayout}">
|
||||
<ItemsRepeater
|
||||
ItemsSource="{x:Bind Items, Mode=OneWay}"
|
||||
Layout="{StaticResource ItemsOrientationLayout}"
|
||||
TabFocusNavigation="Local">
|
||||
<ItemsRepeater.Transitions>
|
||||
<TransitionCollection />
|
||||
</ItemsRepeater.Transitions>
|
||||
@@ -63,10 +66,12 @@
|
||||
<Setter Property="Padding" Value="0" />
|
||||
<Setter Property="IsItemClickEnabled" Value="False" />
|
||||
<Setter Property="SelectionMode" Value="None" />
|
||||
<Setter Property="IsTabStop" Value="False" />
|
||||
<!-- Drag properties controlled by code-behind based on IsEditMode -->
|
||||
<Setter Property="CanDragItems" Value="False" />
|
||||
<Setter Property="CanReorderItems" Value="False" />
|
||||
<Setter Property="AllowDrop" Value="False" />
|
||||
<Setter Property="TabFocusNavigation" Value="Local" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="DockBandListViewItemStyle" TargetType="ListViewItem">
|
||||
@@ -76,6 +81,7 @@
|
||||
<Setter Property="MinWidth" Value="0" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="IsTabStop" Value="False" />
|
||||
</Style>
|
||||
|
||||
<Style
|
||||
@@ -178,168 +184,138 @@
|
||||
x:Name="RootGrid"
|
||||
BorderThickness="0,0,0,1"
|
||||
RightTapped="RootGrid_RightTapped">
|
||||
<!-- Edit Mode Overlay - shown when in edit mode -->
|
||||
<Grid
|
||||
<!-- Dock content with Start / Center / End sections -->
|
||||
<local:DockContentControl
|
||||
x:Name="ContentGrid"
|
||||
Margin="4"
|
||||
Padding="4,0,4,0"
|
||||
Padding="0,0,0,0"
|
||||
Background="Transparent"
|
||||
IsEditMode="{x:Bind IsEditMode, Mode=OneWay}"
|
||||
RightTapped="RootGrid_RightTapped">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<local:DockContentControl.StartSource>
|
||||
<ListView
|
||||
x:Name="StartListView"
|
||||
HorizontalAlignment="Stretch"
|
||||
DragItemsCompleted="BandListView_DragItemsCompleted"
|
||||
DragItemsStarting="BandListView_DragItemsStarting"
|
||||
DragOver="BandListView_DragOver"
|
||||
Drop="StartListView_Drop"
|
||||
ItemContainerStyle="{StaticResource DockBandListViewItemStyle}"
|
||||
ItemTemplate="{StaticResource DockBandTemplate}"
|
||||
ItemsPanel="{StaticResource HorizontalItemsPanel}"
|
||||
ItemsSource="{x:Bind ViewModel.StartItems, Mode=OneWay}"
|
||||
SelectionMode="None"
|
||||
Style="{StaticResource DockBandListViewStyle}" />
|
||||
</local:DockContentControl.StartSource>
|
||||
<local:DockContentControl.StartActionButton>
|
||||
<Button
|
||||
x:Name="StartAddButton"
|
||||
Click="AddBandButton_Click"
|
||||
Style="{StaticResource SubtleButtonStyle}"
|
||||
Tag="Start"
|
||||
ToolTipService.ToolTip="Add band to Start">
|
||||
<FontIcon FontSize="12" Glyph="" />
|
||||
</Button>
|
||||
</local:DockContentControl.StartActionButton>
|
||||
|
||||
<cpcontrols:ScrollContainer
|
||||
x:Name="StartScroller"
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="3"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Stretch">
|
||||
<cpcontrols:ScrollContainer.ActionButton>
|
||||
<local:DockContentControl.CenterSource>
|
||||
<ListView
|
||||
x:Name="CenterListView"
|
||||
HorizontalAlignment="Stretch"
|
||||
DragItemsCompleted="BandListView_DragItemsCompleted"
|
||||
DragItemsStarting="BandListView_DragItemsStarting"
|
||||
DragOver="BandListView_DragOver"
|
||||
Drop="CenterListView_Drop"
|
||||
ItemContainerStyle="{StaticResource DockBandListViewItemStyle}"
|
||||
ItemTemplate="{StaticResource DockBandTemplate}"
|
||||
ItemsPanel="{StaticResource HorizontalItemsPanel}"
|
||||
ItemsSource="{x:Bind ViewModel.CenterItems, Mode=OneWay}"
|
||||
SelectionMode="None"
|
||||
Style="{StaticResource DockBandListViewStyle}" />
|
||||
</local:DockContentControl.CenterSource>
|
||||
<local:DockContentControl.CenterActionButton>
|
||||
<Button
|
||||
x:Name="CenterAddButton"
|
||||
Click="AddBandButton_Click"
|
||||
Style="{StaticResource SubtleButtonStyle}"
|
||||
Tag="Center"
|
||||
ToolTipService.ToolTip="Add band to Center">
|
||||
<FontIcon FontSize="12" Glyph="" />
|
||||
</Button>
|
||||
</local:DockContentControl.CenterActionButton>
|
||||
|
||||
<local:DockContentControl.EndSource>
|
||||
<ListView
|
||||
x:Name="EndListView"
|
||||
DragItemsCompleted="BandListView_DragItemsCompleted"
|
||||
DragItemsStarting="BandListView_DragItemsStarting"
|
||||
DragOver="BandListView_DragOver"
|
||||
Drop="EndListView_Drop"
|
||||
ItemContainerStyle="{StaticResource DockBandListViewItemStyle}"
|
||||
ItemTemplate="{StaticResource DockBandTemplate}"
|
||||
ItemsPanel="{StaticResource HorizontalItemsPanel}"
|
||||
ItemsSource="{x:Bind ViewModel.EndItems, Mode=OneWay}"
|
||||
SelectionMode="None"
|
||||
Style="{StaticResource DockBandListViewStyle}">
|
||||
<ListView.ItemContainerTransitions>
|
||||
<TransitionCollection />
|
||||
</ListView.ItemContainerTransitions>
|
||||
</ListView>
|
||||
</local:DockContentControl.EndSource>
|
||||
<local:DockContentControl.EndActionButton>
|
||||
<Button
|
||||
x:Name="EndAddButton"
|
||||
Click="AddBandButton_Click"
|
||||
Style="{StaticResource SubtleButtonStyle}"
|
||||
Tag="End"
|
||||
ToolTipService.ToolTip="Add band to End">
|
||||
<FontIcon FontSize="12" Glyph="" />
|
||||
</Button>
|
||||
</local:DockContentControl.EndActionButton>
|
||||
</local:DockContentControl>
|
||||
|
||||
<TeachingTip
|
||||
x:Name="EditButtonsTeachingTip"
|
||||
MinWidth="0"
|
||||
PreferredPlacement="Bottom"
|
||||
ShouldConstrainToRootBounds="False"
|
||||
Style="{StaticResource TeachingTipWithoutCloseButtonStyle}"
|
||||
Target="{x:Bind ContentGrid}">
|
||||
|
||||
<TeachingTip.Content>
|
||||
<StackPanel
|
||||
x:Name="EditButtonsPanel"
|
||||
HorizontalAlignment="Stretch"
|
||||
Orientation="Vertical"
|
||||
Spacing="4">
|
||||
<Button
|
||||
x:Name="StartAddButton"
|
||||
Click="AddBandButton_Click"
|
||||
Style="{StaticResource SubtleButtonStyle}"
|
||||
Tag="Start"
|
||||
ToolTipService.ToolTip="Add band to Start">
|
||||
<FontIcon FontSize="12" Glyph="" />
|
||||
</Button>
|
||||
</cpcontrols:ScrollContainer.ActionButton>
|
||||
<cpcontrols:ScrollContainer.Source>
|
||||
<ListView
|
||||
x:Name="StartListView"
|
||||
HorizontalAlignment="Stretch"
|
||||
DragItemsCompleted="BandListView_DragItemsCompleted"
|
||||
DragItemsStarting="BandListView_DragItemsStarting"
|
||||
DragOver="BandListView_DragOver"
|
||||
Drop="StartListView_Drop"
|
||||
ItemContainerStyle="{StaticResource DockBandListViewItemStyle}"
|
||||
ItemTemplate="{StaticResource DockBandTemplate}"
|
||||
ItemsPanel="{StaticResource HorizontalItemsPanel}"
|
||||
ItemsSource="{x:Bind ViewModel.StartItems, Mode=OneWay}"
|
||||
SelectionMode="None"
|
||||
Style="{StaticResource DockBandListViewStyle}" />
|
||||
</cpcontrols:ScrollContainer.Source>
|
||||
</cpcontrols:ScrollContainer>
|
||||
|
||||
<cpcontrols:ScrollContainer
|
||||
x:Name="CenterScroller"
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="3"
|
||||
Grid.Column="1"
|
||||
MinWidth="48"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Stretch">
|
||||
<cpcontrols:ScrollContainer.ActionButton>
|
||||
Click="DoneEditingButton_Click"
|
||||
Content="Save"
|
||||
Style="{StaticResource AccentButtonStyle}" />
|
||||
<Button
|
||||
x:Name="CenterAddButton"
|
||||
Click="AddBandButton_Click"
|
||||
Style="{StaticResource SubtleButtonStyle}"
|
||||
Tag="Center"
|
||||
ToolTipService.ToolTip="Add band to Center">
|
||||
<FontIcon FontSize="12" Glyph="" />
|
||||
</Button>
|
||||
</cpcontrols:ScrollContainer.ActionButton>
|
||||
<cpcontrols:ScrollContainer.Source>
|
||||
<ListView
|
||||
x:Name="CenterListView"
|
||||
HorizontalAlignment="Stretch"
|
||||
DragItemsCompleted="BandListView_DragItemsCompleted"
|
||||
DragItemsStarting="BandListView_DragItemsStarting"
|
||||
DragOver="BandListView_DragOver"
|
||||
Drop="CenterListView_Drop"
|
||||
ItemContainerStyle="{StaticResource DockBandListViewItemStyle}"
|
||||
ItemTemplate="{StaticResource DockBandTemplate}"
|
||||
ItemsPanel="{StaticResource HorizontalItemsPanel}"
|
||||
ItemsSource="{x:Bind ViewModel.CenterItems, Mode=OneWay}"
|
||||
SelectionMode="None"
|
||||
Style="{StaticResource DockBandListViewStyle}" />
|
||||
</cpcontrols:ScrollContainer.Source>
|
||||
</cpcontrols:ScrollContainer>
|
||||
|
||||
<cpcontrols:ScrollContainer
|
||||
x:Name="EndScroller"
|
||||
Grid.Row="0"
|
||||
Grid.RowSpan="3"
|
||||
Grid.Column="2"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Stretch"
|
||||
ContentAlignment="End">
|
||||
<cpcontrols:ScrollContainer.ActionButton>
|
||||
<Button
|
||||
x:Name="EndAddButton"
|
||||
Click="AddBandButton_Click"
|
||||
Style="{StaticResource SubtleButtonStyle}"
|
||||
Tag="End"
|
||||
ToolTipService.ToolTip="Add band to End">
|
||||
<FontIcon FontSize="12" Glyph="" />
|
||||
</Button>
|
||||
</cpcontrols:ScrollContainer.ActionButton>
|
||||
<cpcontrols:ScrollContainer.Source>
|
||||
<ListView
|
||||
x:Name="EndListView"
|
||||
DragItemsCompleted="BandListView_DragItemsCompleted"
|
||||
DragItemsStarting="BandListView_DragItemsStarting"
|
||||
DragOver="BandListView_DragOver"
|
||||
Drop="EndListView_Drop"
|
||||
ItemContainerStyle="{StaticResource DockBandListViewItemStyle}"
|
||||
ItemTemplate="{StaticResource DockBandTemplate}"
|
||||
ItemsPanel="{StaticResource HorizontalItemsPanel}"
|
||||
ItemsSource="{x:Bind ViewModel.EndItems, Mode=OneWay}"
|
||||
SelectionMode="None"
|
||||
Style="{StaticResource DockBandListViewStyle}">
|
||||
<ListView.ItemContainerTransitions>
|
||||
<TransitionCollection />
|
||||
</ListView.ItemContainerTransitions>
|
||||
</ListView>
|
||||
</cpcontrols:ScrollContainer.Source>
|
||||
</cpcontrols:ScrollContainer>
|
||||
<TeachingTip
|
||||
x:Name="EditButtonsTeachingTip"
|
||||
MinWidth="0"
|
||||
PreferredPlacement="Bottom"
|
||||
ShouldConstrainToRootBounds="False"
|
||||
Style="{StaticResource TeachingTipWithoutCloseButtonStyle}"
|
||||
Target="{x:Bind ContentGrid}">
|
||||
|
||||
<TeachingTip.Content>
|
||||
<StackPanel
|
||||
x:Name="EditButtonsPanel"
|
||||
HorizontalAlignment="Stretch"
|
||||
Orientation="Vertical"
|
||||
Spacing="4">
|
||||
<Button
|
||||
HorizontalAlignment="Stretch"
|
||||
Click="DoneEditingButton_Click"
|
||||
Content="Save"
|
||||
Style="{StaticResource AccentButtonStyle}" />
|
||||
<Button
|
||||
HorizontalAlignment="Stretch"
|
||||
Click="DiscardEditingButton_Click"
|
||||
Content="Discard" />
|
||||
</StackPanel>
|
||||
</TeachingTip.Content>
|
||||
</TeachingTip>
|
||||
</Grid>
|
||||
Click="DiscardEditingButton_Click"
|
||||
Content="Discard" />
|
||||
</StackPanel>
|
||||
</TeachingTip.Content>
|
||||
</TeachingTip>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="DockOrientation">
|
||||
<VisualState x:Name="DockOnTop">
|
||||
<VisualState.StateTriggers>
|
||||
<ui:IsEqualStateTrigger Value="{x:Bind DockSide, Mode=OneWay}" To="Top" />
|
||||
</VisualState.StateTriggers>
|
||||
<VisualState.Setters>
|
||||
<Setter Target="ContentGrid.Margin" Value="4,0,4,4" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
<VisualState x:Name="DockOnBottom">
|
||||
<VisualState.StateTriggers>
|
||||
<ui:IsEqualStateTrigger Value="{x:Bind DockSide, Mode=OneWay}" To="Bottom" />
|
||||
</VisualState.StateTriggers>
|
||||
<VisualState.Setters>
|
||||
<Setter Target="ContentGrid.Margin" Value="4,4,4,0" />
|
||||
<Setter Target="RootGrid.BorderThickness" Value="0,1,0,0" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
@@ -348,34 +324,10 @@
|
||||
<ui:IsEqualStateTrigger Value="{x:Bind DockSide, Mode=OneWay}" To="Left" />
|
||||
</VisualState.StateTriggers>
|
||||
<VisualState.Setters>
|
||||
<Setter Target="StartScroller.(Grid.Row)" Value="0" />
|
||||
<Setter Target="StartScroller.(Grid.RowSpan)" Value="1" />
|
||||
<Setter Target="StartScroller.(Grid.Column)" Value="0" />
|
||||
<Setter Target="StartScroller.(Grid.ColumnSpan)" Value="3" />
|
||||
<Setter Target="StartScroller.Orientation" Value="Vertical" />
|
||||
<Setter Target="StartScroller.HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Target="StartScroller.VerticalAlignment" Value="Top" />
|
||||
<Setter Target="StartScroller.Orientation" Value="Vertical" />
|
||||
|
||||
<Setter Target="CenterScroller.(Grid.Row)" Value="1" />
|
||||
<Setter Target="CenterScroller.(Grid.RowSpan)" Value="1" />
|
||||
<Setter Target="CenterScroller.(Grid.Column)" Value="0" />
|
||||
<Setter Target="CenterScroller.(Grid.ColumnSpan)" Value="3" />
|
||||
<Setter Target="CenterScroller.Orientation" Value="Vertical" />
|
||||
<Setter Target="CenterScroller.HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Target="CenterScroller.VerticalAlignment" Value="Center" />
|
||||
<Setter Target="CenterScroller.Orientation" Value="Vertical" />
|
||||
|
||||
<Setter Target="EndScroller.Orientation" Value="Vertical" />
|
||||
<Setter Target="EndScroller.(Grid.Row)" Value="2" />
|
||||
<Setter Target="EndScroller.(Grid.RowSpan)" Value="1" />
|
||||
<Setter Target="EndScroller.(Grid.Column)" Value="0" />
|
||||
<Setter Target="EndScroller.(Grid.ColumnSpan)" Value="3" />
|
||||
<Setter Target="EndScroller.HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Target="EndScroller.VerticalAlignment" Value="Bottom" />
|
||||
<Setter Target="ContentGrid.Padding" Value="4,8,4,8" />
|
||||
<Setter Target="ContentGrid.Orientation" Value="Vertical" />
|
||||
<Setter Target="ContentGrid.Margin" Value="0,0,4,4" />
|
||||
<Setter Target="ContentGrid.Padding" Value="0,0,4,8" />
|
||||
<Setter Target="RootGrid.BorderThickness" Value="0,0,1,0" />
|
||||
|
||||
<Setter Target="StartListView.ItemsPanel" Value="{StaticResource VerticalItemsPanel}" />
|
||||
<Setter Target="CenterListView.ItemsPanel" Value="{StaticResource VerticalItemsPanel}" />
|
||||
<Setter Target="EndListView.ItemsPanel" Value="{StaticResource VerticalItemsPanel}" />
|
||||
@@ -386,64 +338,16 @@
|
||||
<ui:IsEqualStateTrigger Value="{x:Bind DockSide, Mode=OneWay}" To="Right" />
|
||||
</VisualState.StateTriggers>
|
||||
<VisualState.Setters>
|
||||
<Setter Target="StartScroller.(Grid.Row)" Value="0" />
|
||||
<Setter Target="StartScroller.(Grid.RowSpan)" Value="1" />
|
||||
<Setter Target="StartScroller.(Grid.Column)" Value="0" />
|
||||
<Setter Target="StartScroller.(Grid.ColumnSpan)" Value="3" />
|
||||
<Setter Target="StartScroller.Orientation" Value="Vertical" />
|
||||
<Setter Target="StartScroller.HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Target="StartScroller.VerticalAlignment" Value="Top" />
|
||||
<Setter Target="StartScroller.Orientation" Value="Vertical" />
|
||||
|
||||
<Setter Target="CenterScroller.(Grid.Row)" Value="1" />
|
||||
<Setter Target="CenterScroller.(Grid.RowSpan)" Value="1" />
|
||||
<Setter Target="CenterScroller.(Grid.Column)" Value="0" />
|
||||
<Setter Target="CenterScroller.(Grid.ColumnSpan)" Value="3" />
|
||||
<Setter Target="CenterScroller.Orientation" Value="Vertical" />
|
||||
<Setter Target="CenterScroller.HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Target="CenterScroller.VerticalAlignment" Value="Center" />
|
||||
<Setter Target="CenterScroller.Orientation" Value="Vertical" />
|
||||
|
||||
<Setter Target="EndScroller.Orientation" Value="Vertical" />
|
||||
<Setter Target="EndScroller.(Grid.Row)" Value="2" />
|
||||
<Setter Target="EndScroller.(Grid.RowSpan)" Value="1" />
|
||||
<Setter Target="EndScroller.(Grid.Column)" Value="0" />
|
||||
<Setter Target="EndScroller.(Grid.ColumnSpan)" Value="3" />
|
||||
<Setter Target="EndScroller.HorizontalAlignment" Value="Stretch" />
|
||||
<Setter Target="EndScroller.VerticalAlignment" Value="Bottom" />
|
||||
<Setter Target="ContentGrid.Padding" Value="4,8,4,8" />
|
||||
<Setter Target="ContentGrid.Orientation" Value="Vertical" />
|
||||
<Setter Target="ContentGrid.Margin" Value="4,0,0,4" />
|
||||
<Setter Target="ContentGrid.Padding" Value="4,0,0,8" />
|
||||
<Setter Target="RootGrid.BorderThickness" Value="1,0,0,0" />
|
||||
|
||||
<Setter Target="StartListView.ItemsPanel" Value="{StaticResource VerticalItemsPanel}" />
|
||||
<Setter Target="CenterListView.ItemsPanel" Value="{StaticResource VerticalItemsPanel}" />
|
||||
<Setter Target="EndListView.ItemsPanel" Value="{StaticResource VerticalItemsPanel}" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
|
||||
<!-- Edit Mode Visual States -->
|
||||
<VisualStateGroup x:Name="EditModeStates">
|
||||
<VisualState x:Name="EditModeOff" />
|
||||
<VisualState x:Name="EditModeOn">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="StartScroller.BorderBrush" Value="{ThemeResource CardStrokeColorDefaultBrush}" />
|
||||
<Setter Target="StartScroller.Background" Value="{ThemeResource CardBackgroundFillColorDefaultBrush}" />
|
||||
<Setter Target="StartScroller.BorderThickness" Value="1" />
|
||||
<Setter Target="StartScroller.CornerRadius" Value="{StaticResource OverlayCornerRadius}" />
|
||||
<Setter Target="CenterScroller.BorderBrush" Value="{ThemeResource CardStrokeColorDefaultBrush}" />
|
||||
<Setter Target="CenterScroller.Background" Value="{ThemeResource CardBackgroundFillColorDefaultBrush}" />
|
||||
<Setter Target="CenterScroller.BorderThickness" Value="1" />
|
||||
<Setter Target="CenterScroller.CornerRadius" Value="{StaticResource OverlayCornerRadius}" />
|
||||
<Setter Target="EndScroller.BorderBrush" Value="{ThemeResource CardStrokeColorDefaultBrush}" />
|
||||
<Setter Target="EndScroller.Background" Value="{ThemeResource CardBackgroundFillColorDefaultBrush}" />
|
||||
<Setter Target="EndScroller.BorderThickness" Value="1" />
|
||||
<Setter Target="EndScroller.CornerRadius" Value="{StaticResource OverlayCornerRadius}" />
|
||||
<Setter Target="StartScroller.ActionButtonVisibility" Value="Visible" />
|
||||
<Setter Target="CenterScroller.ActionButtonVisibility" Value="Visible" />
|
||||
<Setter Target="EndScroller.ActionButtonVisibility" Value="Visible" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -3,6 +3,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Runtime.InteropServices;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using ManagedCommon;
|
||||
@@ -69,10 +70,22 @@ public sealed partial class DockControl : UserControl, IRecipient<CloseContextMe
|
||||
WeakReferenceMessenger.Default.Register<CloseContextMenuMessage>(this);
|
||||
WeakReferenceMessenger.Default.Register<EnterDockEditModeMessage>(this);
|
||||
|
||||
ViewModel.CenterItems.CollectionChanged += CenterItems_CollectionChanged;
|
||||
|
||||
// Start with edit mode disabled - normal click behavior
|
||||
UpdateEditMode(false);
|
||||
}
|
||||
|
||||
private void CenterItems_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
UpdateCenterVisibility();
|
||||
}
|
||||
|
||||
private void UpdateCenterVisibility()
|
||||
{
|
||||
ContentGrid.IsCenterVisible = IsEditMode || ViewModel.CenterItems.Count > 0;
|
||||
}
|
||||
|
||||
public void Receive(EnterDockEditModeMessage message)
|
||||
{
|
||||
// Message may arrive from a background thread, dispatch to UI thread
|
||||
@@ -84,6 +97,9 @@ public sealed partial class DockControl : UserControl, IRecipient<CloseContextMe
|
||||
|
||||
private void UpdateEditMode(bool isEditMode)
|
||||
{
|
||||
// Update center visibility based on edit mode and center items
|
||||
UpdateCenterVisibility();
|
||||
|
||||
// Enable/disable drag-and-drop based on edit mode
|
||||
StartListView.CanDragItems = isEditMode;
|
||||
StartListView.CanReorderItems = isEditMode;
|
||||
@@ -110,9 +126,6 @@ public sealed partial class DockControl : UserControl, IRecipient<CloseContextMe
|
||||
}
|
||||
|
||||
EditButtonsTeachingTip.IsOpen = isEditMode;
|
||||
|
||||
// Update visual state
|
||||
VisualStateManager.GoToState(this, isEditMode ? "EditModeOn" : "EditModeOff", true);
|
||||
}
|
||||
|
||||
internal void EnterEditMode()
|
||||
@@ -218,6 +231,7 @@ public sealed partial class DockControl : UserControl, IRecipient<CloseContextMe
|
||||
if (item.HasMoreCommands)
|
||||
{
|
||||
ContextControl.ViewModel.SelectedItem = item;
|
||||
ContextControl.ShowFilterBox = true;
|
||||
ContextMenuFlyout.ShowAt(
|
||||
dockItem,
|
||||
new FlyoutShowOptions()
|
||||
@@ -299,6 +313,7 @@ public sealed partial class DockControl : UserControl, IRecipient<CloseContextMe
|
||||
if (item.HasMoreCommands)
|
||||
{
|
||||
ContextControl.ViewModel.SelectedItem = item;
|
||||
ContextControl.ShowFilterBox = false;
|
||||
ContextMenuFlyout.ShowAt(
|
||||
this.RootGrid,
|
||||
new FlyoutShowOptions()
|
||||
|
||||
@@ -54,66 +54,76 @@
|
||||
<Setter Property="BorderThickness" Value="{ThemeResource ButtonBorderThemeThickness}" />
|
||||
<Setter Property="CornerRadius" Value="{StaticResource DockItemCornerRadius}" />
|
||||
<Setter Property="TextVisibility" Value="Visible" />
|
||||
<Setter Property="IsTabStop" Value="True" />
|
||||
<Setter Property="UseSystemFocusVisuals" Value="True" />
|
||||
<Setter Property="FocusVisualMargin" Value="-2" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="local:DockItemControl">
|
||||
<Grid
|
||||
x:Name="PART_RootGrid"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
VerticalAlignment="Stretch"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="{TemplateBinding CornerRadius}"
|
||||
x:Name="PART_HitTestGrid"
|
||||
Background="Transparent"
|
||||
ToolTipService.ToolTip="{TemplateBinding ToolTip}">
|
||||
<Grid
|
||||
x:Name="ContentGrid"
|
||||
AutomationProperties.Name="{TemplateBinding Title}"
|
||||
Background="Transparent"
|
||||
ColumnSpacing="8">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
x:Name="PART_RootGrid"
|
||||
MinWidth="32"
|
||||
MinHeight="30"
|
||||
Margin="{TemplateBinding InnerMargin}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
VerticalAlignment="Stretch"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="{TemplateBinding CornerRadius}">
|
||||
<Grid
|
||||
x:Name="ContentGrid"
|
||||
AutomationProperties.Name="{TemplateBinding Title}"
|
||||
Background="Transparent"
|
||||
ColumnSpacing="8">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Icon -->
|
||||
<ContentPresenter
|
||||
x:Name="IconPresenter"
|
||||
VerticalAlignment="Center"
|
||||
Content="{TemplateBinding Icon}" />
|
||||
<!-- Icon -->
|
||||
<ContentPresenter
|
||||
x:Name="IconPresenter"
|
||||
VerticalAlignment="Center"
|
||||
Content="{TemplateBinding Icon}" />
|
||||
|
||||
<!-- Text (Title + Subtitle) -->
|
||||
<StackPanel
|
||||
x:Name="TextPanel"
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
Visibility="{TemplateBinding TextVisibility}">
|
||||
<TextBlock
|
||||
x:Name="TitleText"
|
||||
MinWidth="24"
|
||||
MaxWidth="100"
|
||||
HorizontalAlignment="Left"
|
||||
<!-- Text (Title + Subtitle) -->
|
||||
<StackPanel
|
||||
x:Name="TextPanel"
|
||||
Grid.Column="1"
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="Segoe UI"
|
||||
FontSize="12"
|
||||
Text="{TemplateBinding Title}"
|
||||
TextAlignment="Left"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
TextWrapping="NoWrap" />
|
||||
<TextBlock
|
||||
x:Name="SubtitleText"
|
||||
MaxWidth="100"
|
||||
Margin="0,-4,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="Segoe UI"
|
||||
FontSize="10"
|
||||
Foreground="{ThemeResource TextFillColorTertiary}"
|
||||
Text="{TemplateBinding Subtitle}"
|
||||
TextAlignment="Center"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
TextWrapping="NoWrap" />
|
||||
</StackPanel>
|
||||
Visibility="{TemplateBinding TextVisibility}">
|
||||
<TextBlock
|
||||
x:Name="TitleText"
|
||||
MinWidth="24"
|
||||
MaxWidth="100"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="Segoe UI"
|
||||
FontSize="12"
|
||||
Text="{TemplateBinding Title}"
|
||||
TextAlignment="Left"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
TextWrapping="NoWrap" />
|
||||
<TextBlock
|
||||
x:Name="SubtitleText"
|
||||
MaxWidth="100"
|
||||
Margin="0,-4,0,0"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Center"
|
||||
FontFamily="Segoe UI"
|
||||
FontSize="10"
|
||||
Foreground="{ThemeResource TextFillColorTertiary}"
|
||||
Text="{TemplateBinding Subtitle}"
|
||||
TextAlignment="Center"
|
||||
TextTrimming="CharacterEllipsis"
|
||||
TextWrapping="NoWrap" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="CommonStates">
|
||||
@@ -156,6 +166,7 @@
|
||||
<VisualState x:Name="TextHidden">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="ContentGrid.ColumnSpacing" Value="0" />
|
||||
<Setter Target="ContentGrid.HorizontalAlignment" Value="Center" />
|
||||
<Setter Target="TextPanel.Visibility" Value="Collapsed" />
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
using Microsoft.CmdPal.UI.Controls;
|
||||
using Microsoft.CmdPal.UI.ViewModels;
|
||||
using Microsoft.CmdPal.UI.ViewModels.Dock;
|
||||
using Microsoft.CmdPal.UI.ViewModels.Settings;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Microsoft.UI.Xaml.Markup;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
|
||||
namespace Microsoft.CmdPal.UI.Dock;
|
||||
|
||||
@@ -56,6 +58,15 @@ public sealed partial class DockItemControl : Control
|
||||
set => SetValue(IconProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty InnerMarginProperty =
|
||||
DependencyProperty.Register(nameof(InnerMargin), typeof(Thickness), typeof(DockItemControl), new PropertyMetadata(new Thickness(0)));
|
||||
|
||||
public Thickness InnerMargin
|
||||
{
|
||||
get => (Thickness)GetValue(InnerMarginProperty);
|
||||
set => SetValue(InnerMarginProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty TextVisibilityProperty =
|
||||
DependencyProperty.Register(nameof(TextVisibility), typeof(Visibility), typeof(DockItemControl), new PropertyMetadata(null, OnTextPropertyChanged));
|
||||
|
||||
@@ -68,6 +79,8 @@ public sealed partial class DockItemControl : Control
|
||||
private const string IconPresenterName = "IconPresenter";
|
||||
|
||||
private FrameworkElement? _iconPresenter;
|
||||
private DockControl? _parentDock;
|
||||
private long _dockSideCallbackToken = -1;
|
||||
|
||||
private static void OnTextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
@@ -157,7 +170,7 @@ public sealed partial class DockItemControl : Control
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalAlignment = HorizontalAlignment.Center;
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
}
|
||||
|
||||
private void UpdateAllVisibility()
|
||||
@@ -174,9 +187,13 @@ public sealed partial class DockItemControl : Control
|
||||
|
||||
PointerEntered -= Control_PointerEntered;
|
||||
PointerExited -= Control_PointerExited;
|
||||
Loaded -= DockItemControl_Loaded;
|
||||
Unloaded -= DockItemControl_Unloaded;
|
||||
|
||||
PointerEntered += Control_PointerEntered;
|
||||
PointerExited += Control_PointerExited;
|
||||
Loaded += DockItemControl_Loaded;
|
||||
Unloaded += DockItemControl_Unloaded;
|
||||
|
||||
IsEnabledChanged += OnIsEnabledChanged;
|
||||
|
||||
@@ -187,6 +204,62 @@ public sealed partial class DockItemControl : Control
|
||||
UpdateAllVisibility();
|
||||
}
|
||||
|
||||
private void DockItemControl_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
// Walk the visual tree to find our parent DockControl and watch its DockSide.
|
||||
// This lets us extend the hit-test area toward the screen edge.
|
||||
DependencyObject? parent = VisualTreeHelper.GetParent(this);
|
||||
while (parent is not null and not DockControl)
|
||||
{
|
||||
parent = VisualTreeHelper.GetParent(parent);
|
||||
}
|
||||
|
||||
if (parent is DockControl dock)
|
||||
{
|
||||
_parentDock = dock;
|
||||
UpdateInnerMarginForDockSide(dock.DockSide);
|
||||
_dockSideCallbackToken = dock.RegisterPropertyChangedCallback(
|
||||
DockControl.DockSideProperty,
|
||||
OnParentDockSideChanged);
|
||||
}
|
||||
}
|
||||
|
||||
private void DockItemControl_Unloaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (_parentDock is not null && _dockSideCallbackToken >= 0)
|
||||
{
|
||||
_parentDock.UnregisterPropertyChangedCallback(
|
||||
DockControl.DockSideProperty,
|
||||
_dockSideCallbackToken);
|
||||
_dockSideCallbackToken = -1;
|
||||
_parentDock = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnParentDockSideChanged(DependencyObject sender, DependencyProperty dp)
|
||||
{
|
||||
if (sender is DockControl dock)
|
||||
{
|
||||
UpdateInnerMarginForDockSide(dock.DockSide);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateInnerMarginForDockSide(DockSide side)
|
||||
{
|
||||
// Push the visual (PART_RootGrid) inward on the screen-edge side so
|
||||
// the transparent hit-test area extends all the way to the edge.
|
||||
// The values here compensate for the margin/padding removed from the
|
||||
// DockControl's ContentGrid on the screen-edge side.
|
||||
InnerMargin = side switch
|
||||
{
|
||||
DockSide.Top => new Thickness(0, 4, 0, 0),
|
||||
DockSide.Bottom => new Thickness(0, 0, 0, 4),
|
||||
DockSide.Left => new Thickness(8, 0, 0, 0),
|
||||
DockSide.Right => new Thickness(0, 0, 8, 0),
|
||||
_ => new Thickness(0),
|
||||
};
|
||||
}
|
||||
|
||||
private void Control_PointerEntered(object sender, PointerRoutedEventArgs e)
|
||||
{
|
||||
VisualStateManager.GoToState(this, "PointerOver", true);
|
||||
|
||||
@@ -231,25 +231,7 @@ public sealed partial class ListPage : Page,
|
||||
if (_scrollOnNextSelectionChange)
|
||||
{
|
||||
_scrollOnNextSelectionChange = false;
|
||||
|
||||
var scrollTarget = li;
|
||||
|
||||
// If the previous item is a separator, also scroll it into view to provide
|
||||
// better context for the user
|
||||
var index = ItemView.Items.IndexOf(li);
|
||||
if (index > 0)
|
||||
{
|
||||
var prevItem = ItemView.Items[index - 1] as ListItemViewModel;
|
||||
if (prevItem?.Type == ListItemType.SectionHeader)
|
||||
{
|
||||
scrollTarget = prevItem;
|
||||
}
|
||||
}
|
||||
|
||||
if (scrollTarget is not null)
|
||||
{
|
||||
ItemView.ScrollIntoView(scrollTarget);
|
||||
}
|
||||
ScrollToItem(li);
|
||||
}
|
||||
|
||||
// Automation notification for screen readers
|
||||
@@ -263,6 +245,28 @@ public sealed partial class ListPage : Page,
|
||||
}
|
||||
}
|
||||
|
||||
private void ScrollToItem(ListItemViewModel li)
|
||||
{
|
||||
var scrollTarget = li;
|
||||
|
||||
// If the previous item is a separator, also scroll it into view to provide
|
||||
// better context for the user
|
||||
var index = ItemView.Items.IndexOf(li);
|
||||
if (index > 0)
|
||||
{
|
||||
var prevItem = ItemView.Items[index - 1] as ListItemViewModel;
|
||||
if (prevItem?.Type == ListItemType.SectionHeader)
|
||||
{
|
||||
scrollTarget = prevItem;
|
||||
}
|
||||
}
|
||||
|
||||
if (scrollTarget is not null)
|
||||
{
|
||||
ItemView.ScrollIntoView(scrollTarget);
|
||||
}
|
||||
}
|
||||
|
||||
private void Items_RightTapped(object sender, RightTappedRoutedEventArgs e)
|
||||
{
|
||||
if (e.OriginalSource is FrameworkElement element &&
|
||||
@@ -717,6 +721,8 @@ public sealed partial class ListPage : Page,
|
||||
{
|
||||
using (SuppressSelectionChangedScope())
|
||||
{
|
||||
ListItemViewModel? stickyRestored = null;
|
||||
|
||||
if (!forceFirstItem &&
|
||||
_stickySelectedItem is not null &&
|
||||
items.Contains(_stickySelectedItem) &&
|
||||
@@ -724,6 +730,7 @@ public sealed partial class ListPage : Page,
|
||||
{
|
||||
// Preserve sticky selection for nested dynamic updates.
|
||||
ItemView.SelectedItem = _stickySelectedItem;
|
||||
stickyRestored = _stickySelectedItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -741,7 +748,26 @@ public sealed partial class ListPage : Page,
|
||||
return;
|
||||
}
|
||||
|
||||
ResetScrollToTop();
|
||||
if (stickyRestored is not null)
|
||||
{
|
||||
ScrollToItem(stickyRestored);
|
||||
}
|
||||
else
|
||||
{
|
||||
ResetScrollToTop();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Selection is valid and unchanged, just make sure the item is visible
|
||||
if (_stickySelectedItem is ListItemViewModel li)
|
||||
{
|
||||
_ = DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Low, () =>
|
||||
{
|
||||
ItemView.UpdateLayout();
|
||||
ScrollToItem(li);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.UI.Input;
|
||||
using Windows.System;
|
||||
using Windows.UI.Core;
|
||||
|
||||
namespace Microsoft.CmdPal.UI.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// Snapshot of the current keyboard modifier state (Ctrl, Alt, Shift, Win).
|
||||
/// </summary>
|
||||
internal readonly struct KeyModifiers
|
||||
{
|
||||
public bool Ctrl { get; }
|
||||
|
||||
public bool Alt { get; }
|
||||
|
||||
public bool Shift { get; }
|
||||
|
||||
public bool Win { get; }
|
||||
|
||||
private KeyModifiers(bool ctrl, bool alt, bool shift, bool win)
|
||||
{
|
||||
Ctrl = ctrl;
|
||||
Alt = alt;
|
||||
Shift = shift;
|
||||
Win = win;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a snapshot of the modifier keys currently held down.
|
||||
/// </summary>
|
||||
public static KeyModifiers GetCurrent()
|
||||
{
|
||||
var ctrl = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
|
||||
var alt = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Menu).HasFlag(CoreVirtualKeyStates.Down);
|
||||
var shift = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
|
||||
var win = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.LeftWindows).HasFlag(CoreVirtualKeyStates.Down) ||
|
||||
InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.RightWindows).HasFlag(CoreVirtualKeyStates.Down);
|
||||
return new KeyModifiers(ctrl, alt, shift, win);
|
||||
}
|
||||
|
||||
public bool OnlyAlt => Alt && !Ctrl && !Shift && !Win;
|
||||
|
||||
public bool OnlyCtrl => Ctrl && !Alt && !Shift && !Win;
|
||||
|
||||
public bool None => !Ctrl && !Alt && !Shift && !Win;
|
||||
}
|
||||
@@ -59,6 +59,16 @@ internal static class WindowExtensions
|
||||
return wasSet;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the specified extended window style flag(s) are currently set on the window.
|
||||
/// </summary>
|
||||
internal static bool HasExtendedStyle(this Window window, WINDOW_EX_STYLE style)
|
||||
{
|
||||
var hWnd = GetWindowHwnd(window);
|
||||
var currentStyle = (WINDOW_EX_STYLE)PInvoke.GetWindowLong(hWnd, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE);
|
||||
return (currentStyle & style) != 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the window corner preference
|
||||
/// </summary>
|
||||
|
||||
@@ -311,15 +311,26 @@ public sealed partial class MainWindow : WindowEx,
|
||||
|
||||
var rect = placement.rcNormalPosition;
|
||||
var displayArea = DisplayArea.GetFromWindowId(AppWindow.Id, DisplayAreaFallback.Nearest) ?? DisplayArea.Primary;
|
||||
|
||||
// GetWindowPlacement returns rcNormalPosition in workspace coordinates for
|
||||
// normal windows, but in screen coordinates for tool windows (WS_EX_TOOLWINDOW).
|
||||
// HiddenOwnerWindowBehavior applies WS_EX_TOOLWINDOW to hide from taskbar/Alt+Tab,
|
||||
// so we must check the current style before converting coordinates.
|
||||
//
|
||||
// To be on the safe side, we should consider the possibility that setting
|
||||
// WS_EX_TOOLWINDOW failed or isn't applied while debugging.
|
||||
var workArea = displayArea.WorkArea;
|
||||
var isToolWindow = this.HasExtendedStyle(WINDOW_EX_STYLE.WS_EX_TOOLWINDOW);
|
||||
|
||||
_currentWindowPosition = new WindowPosition
|
||||
{
|
||||
X = rect.X,
|
||||
Y = rect.Y,
|
||||
X = rect.X + (isToolWindow ? 0 : workArea.X),
|
||||
Y = rect.Y + (isToolWindow ? 0 : workArea.Y),
|
||||
Width = rect.Width,
|
||||
Height = rect.Height,
|
||||
Dpi = (int)this.GetDpiForWindow(),
|
||||
ScreenWidth = displayArea.WorkArea.Width,
|
||||
ScreenHeight = displayArea.WorkArea.Height,
|
||||
ScreenWidth = workArea.Width,
|
||||
ScreenHeight = workArea.Height,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -504,6 +504,23 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
|
||||
});
|
||||
}
|
||||
|
||||
private void ToggleFilterFocus()
|
||||
{
|
||||
if (!FiltersDropDown.IsFilterVisible)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (FiltersDropDown.IsActive)
|
||||
{
|
||||
FiltersDropDown.CloseDropDownAndFocusSearch();
|
||||
}
|
||||
else
|
||||
{
|
||||
FiltersDropDown.OpenDropDown();
|
||||
}
|
||||
}
|
||||
|
||||
private void BackButton_Clicked(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) => WeakReferenceMessenger.Default.Send<NavigateBackMessage>(new());
|
||||
|
||||
private void RootFrame_Navigated(object sender, Microsoft.UI.Xaml.Navigation.NavigationEventArgs e)
|
||||
@@ -688,34 +705,32 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
|
||||
|
||||
private static void ShellPage_OnPreviewKeyDown(object sender, KeyRoutedEventArgs e)
|
||||
{
|
||||
var ctrlPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
|
||||
var altPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Menu).HasFlag(CoreVirtualKeyStates.Down);
|
||||
var shiftPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down);
|
||||
var winPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.LeftWindows).HasFlag(CoreVirtualKeyStates.Down) ||
|
||||
InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.RightWindows).HasFlag(CoreVirtualKeyStates.Down);
|
||||
var modifiers = KeyModifiers.GetCurrent();
|
||||
|
||||
var onlyAlt = altPressed && !ctrlPressed && !shiftPressed && !winPressed;
|
||||
var onlyCtrl = !altPressed && ctrlPressed && !shiftPressed && !winPressed;
|
||||
switch (e.Key)
|
||||
{
|
||||
case VirtualKey.Left when onlyAlt: // Alt+Left arrow
|
||||
case VirtualKey.Left when modifiers.OnlyAlt: // Alt+Left arrow
|
||||
WeakReferenceMessenger.Default.Send<NavigateBackMessage>(new());
|
||||
e.Handled = true;
|
||||
break;
|
||||
case VirtualKey.Home when onlyAlt: // Alt+Home
|
||||
case VirtualKey.Home when modifiers.OnlyAlt: // Alt+Home
|
||||
WeakReferenceMessenger.Default.Send<GoHomeMessage>(new(WithAnimation: false));
|
||||
e.Handled = true;
|
||||
break;
|
||||
case (VirtualKey)188 when onlyCtrl: // Ctrl+,
|
||||
case (VirtualKey)188 when modifiers.OnlyCtrl: // Ctrl+,
|
||||
WeakReferenceMessenger.Default.Send<OpenSettingsMessage>(new());
|
||||
e.Handled = true;
|
||||
break;
|
||||
case VirtualKey.F when modifiers.OnlyAlt: // Alt+F: toggle filter focus
|
||||
((ShellPage)sender).ToggleFilterFocus();
|
||||
e.Handled = true;
|
||||
break;
|
||||
default:
|
||||
{
|
||||
// The CommandBar is responsible for handling all the item keybindings,
|
||||
// since the bound context item may need to then show another
|
||||
// context menu
|
||||
TryCommandKeybindingMessage msg = new(ctrlPressed, altPressed, shiftPressed, winPressed, e.Key);
|
||||
TryCommandKeybindingMessage msg = new(modifiers.Ctrl, modifiers.Alt, modifiers.Shift, modifiers.Win, e.Key);
|
||||
WeakReferenceMessenger.Default.Send(msg);
|
||||
e.Handled = msg.Handled;
|
||||
break;
|
||||
@@ -725,8 +740,8 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
|
||||
|
||||
private static void ShellPage_OnKeyDown(object sender, KeyRoutedEventArgs e)
|
||||
{
|
||||
var ctrlPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
|
||||
if (ctrlPressed && e.Key == VirtualKey.Enter)
|
||||
var mods = KeyModifiers.GetCurrent();
|
||||
if (mods.Ctrl && e.Key == VirtualKey.Enter)
|
||||
{
|
||||
// ctrl+enter
|
||||
WeakReferenceMessenger.Default.Send<ActivateSecondaryCommandMessage>();
|
||||
@@ -737,7 +752,7 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
|
||||
WeakReferenceMessenger.Default.Send<ActivateSelectedListItemMessage>();
|
||||
e.Handled = true;
|
||||
}
|
||||
else if (ctrlPressed && e.Key == VirtualKey.K)
|
||||
else if (mods.Ctrl && e.Key == VirtualKey.K)
|
||||
{
|
||||
// ctrl+k
|
||||
WeakReferenceMessenger.Default.Send<OpenContextMenuMessage>(new OpenContextMenuMessage(null, null, null, ContextMenuFilterLocation.Bottom));
|
||||
|
||||
@@ -46,34 +46,23 @@
|
||||
<TextBlock x:Uid="DockAppearanceSettingsHeader" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" />
|
||||
|
||||
<!-- Dock Position -->
|
||||
<controls:SettingsExpander x:Uid="DockAppearance_DockPosition_SettingsExpander" IsExpanded="True">
|
||||
<controls:SettingsExpander.HeaderIcon>
|
||||
<controls:SettingsCard x:Uid="DockAppearance_DockPosition_SettingsCard">
|
||||
<controls:SettingsCard.HeaderIcon>
|
||||
<SymbolIcon Symbol="MoveToFolder" />
|
||||
</controls:SettingsExpander.HeaderIcon>
|
||||
</controls:SettingsCard.HeaderIcon>
|
||||
<ComboBox
|
||||
x:Name="DockPositionComboBox"
|
||||
MinWidth="120"
|
||||
MinWidth="{StaticResource SettingActionControlMinWidth}"
|
||||
SelectedIndex="{x:Bind SelectedSideIndex, Mode=TwoWay}">
|
||||
<ComboBoxItem x:Uid="DockAppearance_DockPosition_Left" />
|
||||
<ComboBoxItem x:Uid="DockAppearance_DockPosition_Top" />
|
||||
<ComboBoxItem x:Uid="DockAppearance_DockPosition_Right" />
|
||||
<ComboBoxItem x:Uid="DockAppearance_DockPosition_Bottom" />
|
||||
</ComboBox>
|
||||
<controls:SettingsExpander.Items>
|
||||
|
||||
<!-- Show Labels -->
|
||||
<controls:SettingsCard ContentAlignment="Left">
|
||||
<ptcontrols:CheckBoxWithDescriptionControl x:Uid="DockAppearance_ShowLabels_CheckBox" IsChecked="{x:Bind ShowLabels, Mode=TwoWay}" />
|
||||
</controls:SettingsCard>
|
||||
</controls:SettingsExpander.Items>
|
||||
</controls:SettingsExpander>
|
||||
|
||||
<!-- Theme Section -->
|
||||
<TextBlock x:Uid="DockAppearance_ThemeSettingsHeader" Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" />
|
||||
</controls:SettingsCard>
|
||||
|
||||
<controls:SettingsCard x:Uid="DockAppearance_AppTheme_SettingsCard" HeaderIcon="{ui:FontIcon Glyph=}">
|
||||
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind ViewModel.DockAppearance.ThemeIndex, Mode=TwoWay}">
|
||||
|
||||
<ComboBoxItem x:Uid="Settings_GeneralPage_AppTheme_Mode_System_Automation" Tag="Default">
|
||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||
<FontIcon FontSize="16" Glyph="" />
|
||||
|
||||
@@ -16,7 +16,6 @@ using Microsoft.UI.Xaml.Controls;
|
||||
using Microsoft.UI.Xaml.Input;
|
||||
using Microsoft.UI.Xaml.Navigation;
|
||||
using Windows.System;
|
||||
using Windows.UI.Core;
|
||||
using WinUIEx;
|
||||
using RS_ = Microsoft.CmdPal.UI.Helpers.ResourceLoaderInstance;
|
||||
using TitleBar = Microsoft.UI.Xaml.Controls.TitleBar;
|
||||
@@ -251,8 +250,7 @@ public sealed partial class SettingsWindow : WindowEx,
|
||||
break;
|
||||
|
||||
case VirtualKey.Left:
|
||||
var altPressed = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Menu).HasFlag(CoreVirtualKeyStates.Down);
|
||||
if (altPressed)
|
||||
if (KeyModifiers.GetCurrent().Alt)
|
||||
{
|
||||
TryGoBack();
|
||||
}
|
||||
|
||||
@@ -763,9 +763,6 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
|
||||
<data name="Settings_PageTitles_DockAppearancePage" xml:space="preserve">
|
||||
<value>Dock Appearance</value>
|
||||
</data>
|
||||
<data name="DockAppearance_ThemeSettingsHeader.Text" xml:space="preserve">
|
||||
<value>Theme</value>
|
||||
</data>
|
||||
<data name="DockAppearance_AppTheme_SettingsCard.Header" xml:space="preserve">
|
||||
<value>Dock theme mode</value>
|
||||
</data>
|
||||
@@ -796,9 +793,6 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
|
||||
<data name="DockAppearance_ColorizationMode.Header" xml:space="preserve">
|
||||
<value>Colorization mode</value>
|
||||
</data>
|
||||
<data name="DockAppearance_NoBackground_SettingsCard.Header" xml:space="preserve">
|
||||
<value>No background</value>
|
||||
</data>
|
||||
<data name="DockAppearance_NoBackground_DescriptionTextBlock.Text" xml:space="preserve">
|
||||
<value>No settings</value>
|
||||
</data>
|
||||
@@ -894,8 +888,8 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
|
||||
<data name="ConfigureShortcutText.Text" xml:space="preserve">
|
||||
<value>Assign shortcut</value>
|
||||
</data>
|
||||
<data name="DockAppearance_DockPosition_SettingsExpander.Header" xml:space="preserve">
|
||||
<value>Dock position and appearance</value>
|
||||
<data name="DockAppearance_DockPosition_SettingsCard.Header" xml:space="preserve">
|
||||
<value>Dock position</value>
|
||||
</data>
|
||||
<data name="DockAppearance_DockPosition_SettingsExpander.Description" xml:space="preserve">
|
||||
<value>Choose where the dock appears on your screen</value>
|
||||
@@ -934,4 +928,25 @@ Right-click to remove the key combination, thereby deactivating the shortcut.</v
|
||||
<value>Unpin from dock</value>
|
||||
<comment>Command name for unpinning an item from the dock</comment>
|
||||
</data>
|
||||
<data name="FiltersDropDown.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
|
||||
<value>Filters</value>
|
||||
</data>
|
||||
<data name="FiltersDropDown.[using:Microsoft.UI.Xaml.Controls]ToolTipService.ToolTip" xml:space="preserve">
|
||||
<value>Filters (Alt+F)</value>
|
||||
</data>
|
||||
<data name="FiltersDropDown_DefaultText" xml:space="preserve">
|
||||
<value>Filters</value>
|
||||
</data>
|
||||
<data name="FilterSearchBox.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
|
||||
<value>Search filters</value>
|
||||
</data>
|
||||
<data name="FilterSearchBox.PlaceholderText" xml:space="preserve">
|
||||
<value>Search filters...</value>
|
||||
</data>
|
||||
<data name="FilterListView.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
|
||||
<value>Filter options</value>
|
||||
</data>
|
||||
<data name="FiltersDropDown_NoResults.Text" xml:space="preserve">
|
||||
<value>No results</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -257,13 +257,29 @@
|
||||
<VisualState x:Name="HeroContentTop">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="HeroContentBorder.(Grid.Row)" Value="0" />
|
||||
<Setter Target="HeroContentBorder.CornerRadius" Value="{Binding CornerRadius, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource TopCornerRadiusFilterConverter}, FallbackValue=0}" />
|
||||
<Setter Target="HeroContentBorder.CornerRadius">
|
||||
<Setter.Value>
|
||||
<Binding
|
||||
Converter="{StaticResource TopCornerRadiusFilterConverter}"
|
||||
FallbackValue="0"
|
||||
Path="CornerRadius"
|
||||
RelativeSource="{RelativeSource TemplatedParent}" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
<VisualState x:Name="HeroContentBottom">
|
||||
<VisualState.Setters>
|
||||
<Setter Target="HeroContentBorder.(Grid.Row)" Value="2" />
|
||||
<Setter Target="HeroContentBorder.CornerRadius" Value="{Binding CornerRadius, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource BottomCornerRadiusFilterConverter}, FallbackValue=0}" />
|
||||
<Setter Target="HeroContentBorder.CornerRadius">
|
||||
<Setter.Value>
|
||||
<Binding
|
||||
Converter="{StaticResource BottomCornerRadiusFilterConverter}"
|
||||
FallbackValue="0"
|
||||
Path="CornerRadius"
|
||||
RelativeSource="{RelativeSource TemplatedParent}" />
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</VisualState.Setters>
|
||||
</VisualState>
|
||||
</VisualStateGroup>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user