Skip to content

Commit cde7c51

Browse files
committed
Merge remote-tracking branch 'upstream/main' into pedrolamas/peek-qoi
# Conflicts: # src/modules/peek/Peek.FilePreviewer/Previewers/MediaPreviewer/ImagePreviewer.cs
2 parents 3e56bcb + 1daeba7 commit cde7c51

File tree

32 files changed

+172
-338
lines changed

32 files changed

+172
-338
lines changed

.github/actions/spell-check/expect.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,10 @@ killrunner
745745
Knownfolders
746746
KSPROPERTY
747747
Kybd
748+
LAlt
749+
Lambson
750+
languagesjson
751+
langword
748752
lastcodeanalysissucceeded
749753
Lastdevice
750754
LAYOUTRTL
@@ -1016,6 +1020,7 @@ NOTSRCCOPY
10161020
NOTSRCERASE
10171021
NOZORDER
10181022
NPH
1023+
npmjs
10191024
NResize
10201025
nrw
10211026
nsunt
@@ -1708,6 +1713,8 @@ wcsnicmp
17081713
WDA
17091714
wdp
17101715
wdupenv
1716+
weakme
1717+
webbrowsers
17111718
webcam
17121719
webpage
17131720
websites

.pipelines/applyXamlStyling.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ if (-not $Passive)
107107
else
108108
{
109109
Write-Output "Checking all files (passively)"
110-
$files = Get-ChildItem -Path "$PSScriptRoot\..\src\*.xaml" -Recurse | Select-Object -ExpandProperty FullName | Where-Object { $_ -notmatch "(\\obj\\)|(\\bin\\)|(\\x64\\)|(\\Generated Files\\PowerRenameXAML\\)|(\\launcher\\PowerLauncher\\)|(\\launcher\\Wox.Plugin\\)|(\\colorPicker\\ColorPickerUI\\)" }
110+
$files = Get-ChildItem -Path "$PSScriptRoot\..\src\*.xaml" -Recurse | Select-Object -ExpandProperty FullName | Where-Object { $_ -notmatch "(\\obj\\)|(\\bin\\)|(\\x64\\)|(\\Generated Files\\PowerRenameXAML\\)|(\\colorPicker\\ColorPickerUI\\)" }
111111

112112
if ($files.count -gt 0)
113113
{
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# [FilePreviewCommon](/src/common/FilePreviewCommon)
2+
3+
This project contains common code used for previewing and displaying files.
4+
5+
## Monaco preview
6+
7+
Monaco preview enables to display developer files. It is based on [Microsoft's Monaco Editor](https://microsoft.github.io/monaco-editor/) which is maintained by the Visual Studio Code team.
8+
9+
This previewer is used for the File Explorer Dev File Previewer, as well as PowerToys Peek.
10+
11+
### Update Monaco Editor
12+
13+
1. Download Monaco editor with [npm](https://www.npmjs.com/): Run `npm i monaco-editor` in the command prompt.
14+
2. Delete everything except the `min` folder (the minimised code) from the downloaded files.
15+
3. Copy the `min` folder into the `src/common/FilePreviewCommon/Assets/Monaco/monacoSRC` folder of the PowerToys project.
16+
4. Generate the JSON file as described in the generate [monaco_languages.json file](#monaco_languagesjson) section.
17+
18+
### Add a new language definition
19+
20+
As an example on how to add a new language definition you can look at the one for [registry files](/src/common/FilePreviewCommon/Assets/Monaco/customLanguages/reg.js).
21+
22+
1. Add the new language definition (written with [Monarch](https://microsoft.github.io/monaco-editor/monarch.html)) as a new file to the [folder containing Monaco custom languages](/src/common/FilePreviewCommon/Assets/Monaco/customLanguages/) (Remember the file name and the string you used for "idDefinition" as you need it later.). The file should be formatted like in the example below. (Please change `idDefinition` to the name of your language.)
23+
24+
```javascript
25+
export function idDefinition() {
26+
return {
27+
...
28+
}
29+
}
30+
```
31+
32+
2. Add the following line to the [`monacoSpecialLanguages.js`](/src/common/FilePreviewCommon/Assets/Monaco/monacoSpecialLanguages.js) file, after the other import statements:
33+
34+
```javascript
35+
import { idDefinition } from './customLanguages/file.js';
36+
```
37+
38+
> Replace file.js with the name of your definition file from step 1. Please replace idDefinition with the string you used in step 1.
39+
40+
3. In the [`monacoSpecialLanguages.js`](/src/common/FilePreviewCommon/Assets/Monaco/monacoSpecialLanguages.js) file add the following line into the `registerAdditionalLanguages` function:
41+
42+
```javascript
43+
registerAdditionalNewLanguage("id", [".fileExtension"], idDefinition(), monaco)
44+
```
45+
46+
> Replace id and idDefinition with your id and string used in step 1. Replace fileExtension with a set of file extensions you want the language to register to.
47+
48+
* The id can be anything. Recommended is one of the file extensions. For example "php" or "reg".
49+
50+
4. Execute the steps described in the [monaco_languages.json](#monaco_languagesjson) section.
51+
52+
### Add a new file extension to an existing language
53+
54+
1. In the [`monacoSpecialLanguages.js`](/src/common/FilePreviewCommon/Assets/Monaco/monacoSpecialLanguages.js) file add the following line to the `registerAdditionalLanguages` function. (`existingId` is the id of the language you want to add the extension to. You can find these id's in the [`monaco_languages.json`](/src/common/FilePreviewCommon/Assets/Monaco/monaco_languages.json) file):
55+
56+
```javascript
57+
registerAdditionalLanguage("id", [".fileExtension"], "existingId", monaco)
58+
```
59+
60+
* If for instance you want to add more extensions to the php language set the id to `phpExt` and the existingId to `php`.
61+
62+
2. Copy the existing language definition into the `languageDefinitions` function in the same file. You can find the existing definitions in the following folder: [`/src/common/FilePreviewCommon/Assets/Monaco/monacoSRC/min/vs/basic-languages/`](/src/common/FilePreviewCommon/Assets/Monaco/monacoSRC/min/vs/basic-languages/).
63+
64+
3. Execute the steps described in the [monaco_languages.json](#monaco_languagesjson) section.
65+
66+
### monaco_languages.json
67+
68+
[`monaco_languages.json`](/src/common/FilePreviewCommon/Assets/Monaco/monaco_languages.json) contains all extensions and IDs for the languages supported by Monaco. The [`MonacoHelper`](/src/common/FilePreviewCommon/MonacoHelper.cs) class and the installer are using this file to register preview handlers for the defined extensions.
69+
70+
After updating Monaco Editor and/or adding a new language you should update the [`monaco_languages.json`](/src/common/FilePreviewCommon/Assets/Monaco/monaco_languages.json) file.
71+
72+
1. Run the [`generateLanguagesJson.html`](/src/common/FilePreviewCommon/Assets/Monaco/generateLanguagesJson.html) file on a local webserver (as webbrowsers will block certain needed features when running the file locally.)
73+
* This can for example be achieved by using the [Preview Server](https://marketplace.visualstudio.com/items?itemName=yuichinukiyama.vscode-preview-server) extension for Visual Studio Code: Open the file in Visual Studio Code, right click in the code editor and select `vscode-preview-server: Launch on browser`. The file will be opened in a browser.
74+
2. The browser will download the new `monaco_languages.json` file
75+
3. Replace the old file with the newly downloaded one in the source code folder.

doc/devdocs/common.md renamed to doc/devdocs/common/common.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Classes and structures
22

3+
> This document is outdated and will soon be renewed.
4+
35
#### class Animation: [header](/src/common/animation.h) [source](/src/common/animation.cpp)
46
Animation helper class with two easing-in animations: linear and exponential.
57

doc/devdocs/common/readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Common
2+
3+
The [common](/src/common) folder contains projects with code, that is used in multiple projects.
4+
5+
## [FilePreviewCommon](FilePreviewCommon.md)
6+
7+
This project contains common code for file previewing.

doc/devdocs/modules/peek/readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# PowerToys Peek
2+
3+
> Documentation is currently under construction
4+
5+
## Dev file previewer
6+
7+
The previewer for developer files uses the project in [FileExplorerCommon] common project to render monaco. You can find its documentation here: [/doc/devdocs/common/FilePreviewCommon.md](/doc/devdocs/common/FilePreviewCommon.md).

doc/devdocs/modules/powerpreview/monaco/readme.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/common/utils/excluded_apps.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ inline bool find_folder_in_path(const std::wstring& where, const std::vector<std
3232
}
3333

3434
#define MAX_TITLE_LENGTH 255
35-
inline bool check_excluded_app_with_title(const HWND& hwnd, std::wstring& processPath, const std::vector<std::wstring>& excludedApps)
35+
inline bool check_excluded_app_with_title(const HWND& hwnd, const std::vector<std::wstring>& excludedApps)
3636
{
3737
WCHAR title[MAX_TITLE_LENGTH];
3838
int len = GetWindowTextW(hwnd, title, MAX_TITLE_LENGTH);
@@ -42,23 +42,25 @@ inline bool check_excluded_app_with_title(const HWND& hwnd, std::wstring& proces
4242
}
4343

4444
std::wstring titleStr(title);
45-
auto lastBackslashPos = processPath.find_last_of(L'\\');
46-
if (lastBackslashPos != std::wstring::npos)
45+
CharUpperBuffW(titleStr.data(), static_cast<DWORD>(titleStr.length()));
46+
47+
for (const auto& app : excludedApps)
4748
{
48-
processPath = processPath.substr(0, lastBackslashPos + 1); // retain up to the last backslash
49-
processPath.append(titleStr); // append the title
49+
if (titleStr.contains(app))
50+
{
51+
return true;
52+
}
5053
}
51-
CharUpperBuffW(processPath.data(), static_cast<DWORD>(processPath.length()));
52-
return find_app_name_in_path(processPath, excludedApps);
54+
return false;
5355
}
5456

55-
inline bool check_excluded_app(const HWND& hwnd, std::wstring& processPath, const std::vector<std::wstring>& excludedApps)
57+
inline bool check_excluded_app(const HWND& hwnd, const std::wstring& processPath, const std::vector<std::wstring>& excludedApps)
5658
{
5759
bool res = find_app_name_in_path(processPath, excludedApps);
5860

5961
if (!res)
6062
{
61-
res = check_excluded_app_with_title(hwnd, processPath, excludedApps);
63+
res = check_excluded_app_with_title(hwnd, excludedApps);
6264
}
6365

6466
return res;

src/modules/EnvironmentVariables/EnvironmentVariables/EnvironmentVariablesXAML/MainWindow.xaml.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using EnvironmentVariables.Helpers;
88
using EnvironmentVariables.Helpers.Win32;
99
using EnvironmentVariables.ViewModels;
10+
using ManagedCommon;
1011
using Microsoft.UI.Dispatching;
1112
using WinUIEx;
1213

@@ -30,19 +31,20 @@ public MainWindow()
3031
Title = title;
3132
AppTitleTextBlock.Text = title;
3233

33-
RegisterWindow();
34+
var handle = this.GetWindowHandle();
35+
RegisterWindow(handle);
36+
37+
WindowHelpers.BringToForeground(handle);
3438
}
3539

3640
private static readonly DispatcherQueue _dispatcherQueue = DispatcherQueue.GetForCurrentThread();
3741
private static NativeMethods.WinProc newWndProc;
3842
private static IntPtr oldWndProc = IntPtr.Zero;
3943

40-
private void RegisterWindow()
44+
private void RegisterWindow(IntPtr handle)
4145
{
4246
newWndProc = new NativeMethods.WinProc(WndProc);
4347

44-
var handle = this.GetWindowHandle();
45-
4648
oldWndProc = NativeMethods.SetWindowLongPtr(handle, NativeMethods.WindowLongIndexFlags.GWL_WNDPROC, newWndProc);
4749
}
4850

src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ bool FancyZonesWindowUtils::IsExcluded(HWND window)
202202
return false;
203203
}
204204

205-
bool FancyZonesWindowUtils::IsExcludedByUser(const HWND& hwnd, std::wstring& processPath) noexcept
205+
bool FancyZonesWindowUtils::IsExcludedByUser(const HWND& hwnd, const std::wstring& processPath) noexcept
206206
{
207207
return (check_excluded_app(hwnd, processPath, FancyZonesSettings::settings().excludedAppsArray));
208208
}
209209

210-
bool FancyZonesWindowUtils::IsExcludedByDefault(const HWND& hwnd, std::wstring& processPath) noexcept
210+
bool FancyZonesWindowUtils::IsExcludedByDefault(const HWND& hwnd, const std::wstring& processPath) noexcept
211211
{
212212
static std::vector<std::wstring> defaultExcludedFolders = { NonLocalizable::SystemAppsFolder };
213213
if (find_folder_in_path(processPath, defaultExcludedFolders))

src/modules/fancyzones/FancyZonesLib/WindowUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ namespace FancyZonesWindowUtils
2727
bool IsProcessOfWindowElevated(HWND window); // If HWND is already dead, we assume it wasn't elevated
2828

2929
bool IsExcluded(HWND window);
30-
bool IsExcludedByUser(const HWND& hwnd, std::wstring& processPath) noexcept;
31-
bool IsExcludedByDefault(const HWND& hwnd, std::wstring& processPath) noexcept;
30+
bool IsExcludedByUser(const HWND& hwnd, const std::wstring& processPath) noexcept;
31+
bool IsExcludedByDefault(const HWND& hwnd, const std::wstring& processPath) noexcept;
3232

3333
void SwitchToWindow(HWND window) noexcept;
3434
void SizeWindowToRect(HWND window, RECT rect) noexcept; // Parameter rect must be in screen coordinates (e.g. obtained from GetWindowRect)

src/modules/launcher/PowerLauncher/MainWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
xmlns:vm="clr-namespace:PowerLauncher.ViewModel"
1111
Title="PowerToys Run"
1212
Width="640"
13+
MinHeight="0"
1314
d:DataContext="{d:DesignInstance vm:MainViewModel}"
1415
ui:ExtendsContentIntoTitleBar="True"
1516
AllowDrop="True"
@@ -27,8 +28,7 @@
2728
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
2829
WindowStartupLocation="Manual"
2930
WindowStyle="None"
30-
mc:Ignorable="d"
31-
MinHeight="0">
31+
mc:Ignorable="d">
3232

3333
<Grid x:Name="RootGrid" MouseDown="OnMouseDown">
3434
<!-- We set the background here because the Acrylic can be too translucent / background too bright on Light theme -->

src/modules/launcher/PowerLauncher/ReportWindow.xaml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,23 @@
1515
Topmost="True"
1616
WindowStartupLocation="CenterScreen"
1717
mc:Ignorable="d">
18-
<Grid Margin="12">
18+
<Grid Margin="12" Background="White">
1919
<Grid.RowDefinitions>
20-
<RowDefinition Height="64" />
20+
<RowDefinition Height="Auto" />
2121
<RowDefinition Height="Auto" />
2222
<RowDefinition Height="Auto" />
2323
<RowDefinition Height="*" />
2424
</Grid.RowDefinitions>
2525

2626
<TextBlock
27-
FontFamily="Segoe UI Light"
28-
FontSize="32"
29-
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
27+
FontSize="24"
28+
FontWeight="SemiBold"
29+
Foreground="Black"
3030
Text="{x:Static p:Resources.reportWindow_header}" />
3131

3232
<TextBlock
3333
Grid.Row="1"
34-
FontSize="14"
35-
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
34+
Foreground="Black"
3635
TextWrapping="Wrap">
3736
<Run Text="{x:Static p:Resources.reportWindow_file_bug}" />
3837
<Hyperlink
@@ -49,12 +48,12 @@
4948
<TextBox
5049
x:Name="LogFilePathBox"
5150
Grid.Row="2"
52-
Margin="-8,16,-8,16"
51+
Margin="0,16,0,16"
5352
Background="Transparent"
54-
BorderThickness="0"
53+
BorderBrush="Black"
54+
BorderThickness="1"
5555
FontFamily="Consolas"
56-
FontSize="14"
57-
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
56+
Foreground="Black"
5857
IsReadOnly="True"
5958
TextWrapping="Wrap" />
6059

@@ -63,10 +62,10 @@
6362
Grid.Row="3"
6463
VerticalAlignment="Stretch"
6564
Background="Transparent"
65+
BorderBrush="Black"
6666
BorderThickness="1"
6767
FontFamily="Consolas"
68-
FontSize="14"
69-
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
68+
Foreground="Black"
7069
HorizontalScrollBarVisibility="Auto"
7170
IsDocumentEnabled="True"
7271
VerticalScrollBarVisibility="Auto" />

0 commit comments

Comments
 (0)