Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into pedrolamas/peek-qoi
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/modules/peek/Peek.FilePreviewer/Previewers/MediaPreviewer/ImagePreviewer.cs
  • Loading branch information
pedrolamas committed Dec 12, 2023
2 parents 3e56bcb + 1daeba7 commit 86da2e3
Show file tree
Hide file tree
Showing 32 changed files with 172 additions and 338 deletions.
7 changes: 7 additions & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,10 @@ killrunner
Knownfolders
KSPROPERTY
Kybd
LAlt
Lambson
languagesjson
langword
lastcodeanalysissucceeded
Lastdevice
LAYOUTRTL
Expand Down Expand Up @@ -1016,6 +1020,7 @@ NOTSRCCOPY
NOTSRCERASE
NOZORDER
NPH
npmjs
NResize
nrw
nsunt
Expand Down Expand Up @@ -1708,6 +1713,8 @@ wcsnicmp
WDA
wdp
wdupenv
weakme
webbrowsers
webcam
webpage
websites
Expand Down
2 changes: 1 addition & 1 deletion .pipelines/applyXamlStyling.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ if (-not $Passive)
else
{
Write-Output "Checking all files (passively)"
$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\\)" }
$files = Get-ChildItem -Path "$PSScriptRoot\..\src\*.xaml" -Recurse | Select-Object -ExpandProperty FullName | Where-Object { $_ -notmatch "(\\obj\\)|(\\bin\\)|(\\x64\\)|(\\Generated Files\\PowerRenameXAML\\)|(\\colorPicker\\ColorPickerUI\\)" }

if ($files.count -gt 0)
{
Expand Down
75 changes: 75 additions & 0 deletions doc/devdocs/common/FilePreviewCommon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# [FilePreviewCommon](/src/common/FilePreviewCommon)

This project contains common code used for previewing and displaying files.

## Monaco preview

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.

This previewer is used for the File Explorer Dev File Previewer, as well as PowerToys Peek.

### Update Monaco Editor

1. Download Monaco editor with [npm](https://www.npmjs.com/): Run `npm i monaco-editor` in the command prompt.
2. Delete everything except the `min` folder (the minimised code) from the downloaded files.
3. Copy the `min` folder into the `src/common/FilePreviewCommon/Assets/Monaco/monacoSRC` folder of the PowerToys project.
4. Generate the JSON file as described in the generate [monaco_languages.json file](#monaco_languagesjson) section.

### Add a new language definition

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).

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.)

```javascript
export function idDefinition() {
return {
...
}
}
```

2. Add the following line to the [`monacoSpecialLanguages.js`](/src/common/FilePreviewCommon/Assets/Monaco/monacoSpecialLanguages.js) file, after the other import statements:

```javascript
import { idDefinition } from './customLanguages/file.js';
```

> Replace file.js with the name of your definition file from step 1. Please replace idDefinition with the string you used in step 1.
3. In the [`monacoSpecialLanguages.js`](/src/common/FilePreviewCommon/Assets/Monaco/monacoSpecialLanguages.js) file add the following line into the `registerAdditionalLanguages` function:

```javascript
registerAdditionalNewLanguage("id", [".fileExtension"], idDefinition(), monaco)
```

> 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.
* The id can be anything. Recommended is one of the file extensions. For example "php" or "reg".

4. Execute the steps described in the [monaco_languages.json](#monaco_languagesjson) section.

### Add a new file extension to an existing language

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):

```javascript
registerAdditionalLanguage("id", [".fileExtension"], "existingId", monaco)
```

* If for instance you want to add more extensions to the php language set the id to `phpExt` and the existingId to `php`.

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/).

3. Execute the steps described in the [monaco_languages.json](#monaco_languagesjson) section.

### monaco_languages.json

[`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.

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.

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.)
* 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.
2. The browser will download the new `monaco_languages.json` file
3. Replace the old file with the newly downloaded one in the source code folder.
2 changes: 2 additions & 0 deletions doc/devdocs/common.md → doc/devdocs/common/common.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Classes and structures

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

Expand Down
7 changes: 7 additions & 0 deletions doc/devdocs/common/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Common

The [common](/src/common) folder contains projects with code, that is used in multiple projects.

## [FilePreviewCommon](FilePreviewCommon.md)

This project contains common code for file previewing.
7 changes: 7 additions & 0 deletions doc/devdocs/modules/peek/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# PowerToys Peek

> Documentation is currently under construction
## Dev file previewer

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).
24 changes: 0 additions & 24 deletions doc/devdocs/modules/powerpreview/monaco/readme.md

This file was deleted.

20 changes: 11 additions & 9 deletions src/common/utils/excluded_apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ inline bool find_folder_in_path(const std::wstring& where, const std::vector<std
}

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

std::wstring titleStr(title);
auto lastBackslashPos = processPath.find_last_of(L'\\');
if (lastBackslashPos != std::wstring::npos)
CharUpperBuffW(titleStr.data(), static_cast<DWORD>(titleStr.length()));

for (const auto& app : excludedApps)
{
processPath = processPath.substr(0, lastBackslashPos + 1); // retain up to the last backslash
processPath.append(titleStr); // append the title
if (titleStr.contains(app))
{
return true;
}
}
CharUpperBuffW(processPath.data(), static_cast<DWORD>(processPath.length()));
return find_app_name_in_path(processPath, excludedApps);
return false;
}

inline bool check_excluded_app(const HWND& hwnd, std::wstring& processPath, const std::vector<std::wstring>& excludedApps)
inline bool check_excluded_app(const HWND& hwnd, const std::wstring& processPath, const std::vector<std::wstring>& excludedApps)
{
bool res = find_app_name_in_path(processPath, excludedApps);

if (!res)
{
res = check_excluded_app_with_title(hwnd, processPath, excludedApps);
res = check_excluded_app_with_title(hwnd, excludedApps);
}

return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using EnvironmentVariables.Helpers;
using EnvironmentVariables.Helpers.Win32;
using EnvironmentVariables.ViewModels;
using ManagedCommon;
using Microsoft.UI.Dispatching;
using WinUIEx;

Expand All @@ -30,19 +31,20 @@ public MainWindow()
Title = title;
AppTitleTextBlock.Text = title;

RegisterWindow();
var handle = this.GetWindowHandle();
RegisterWindow(handle);

WindowHelpers.BringToForeground(handle);
}

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

private void RegisterWindow()
private void RegisterWindow(IntPtr handle)
{
newWndProc = new NativeMethods.WinProc(WndProc);

var handle = this.GetWindowHandle();

oldWndProc = NativeMethods.SetWindowLongPtr(handle, NativeMethods.WindowLongIndexFlags.GWL_WNDPROC, newWndProc);
}

Expand Down
4 changes: 2 additions & 2 deletions src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ bool FancyZonesWindowUtils::IsExcluded(HWND window)
return false;
}

bool FancyZonesWindowUtils::IsExcludedByUser(const HWND& hwnd, std::wstring& processPath) noexcept
bool FancyZonesWindowUtils::IsExcludedByUser(const HWND& hwnd, const std::wstring& processPath) noexcept
{
return (check_excluded_app(hwnd, processPath, FancyZonesSettings::settings().excludedAppsArray));
}

bool FancyZonesWindowUtils::IsExcludedByDefault(const HWND& hwnd, std::wstring& processPath) noexcept
bool FancyZonesWindowUtils::IsExcludedByDefault(const HWND& hwnd, const std::wstring& processPath) noexcept
{
static std::vector<std::wstring> defaultExcludedFolders = { NonLocalizable::SystemAppsFolder };
if (find_folder_in_path(processPath, defaultExcludedFolders))
Expand Down
4 changes: 2 additions & 2 deletions src/modules/fancyzones/FancyZonesLib/WindowUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace FancyZonesWindowUtils
bool IsProcessOfWindowElevated(HWND window); // If HWND is already dead, we assume it wasn't elevated

bool IsExcluded(HWND window);
bool IsExcludedByUser(const HWND& hwnd, std::wstring& processPath) noexcept;
bool IsExcludedByDefault(const HWND& hwnd, std::wstring& processPath) noexcept;
bool IsExcludedByUser(const HWND& hwnd, const std::wstring& processPath) noexcept;
bool IsExcludedByDefault(const HWND& hwnd, const std::wstring& processPath) noexcept;

void SwitchToWindow(HWND window) noexcept;
void SizeWindowToRect(HWND window, RECT rect) noexcept; // Parameter rect must be in screen coordinates (e.g. obtained from GetWindowRect)
Expand Down
4 changes: 2 additions & 2 deletions src/modules/launcher/PowerLauncher/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
xmlns:vm="clr-namespace:PowerLauncher.ViewModel"
Title="PowerToys Run"
Width="640"
MinHeight="0"
d:DataContext="{d:DesignInstance vm:MainViewModel}"
ui:ExtendsContentIntoTitleBar="True"
AllowDrop="True"
Expand All @@ -27,8 +28,7 @@
Visibility="{Binding MainWindowVisibility, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
WindowStartupLocation="Manual"
WindowStyle="None"
mc:Ignorable="d"
MinHeight="0">
mc:Ignorable="d">

<Grid x:Name="RootGrid" MouseDown="OnMouseDown">
<!-- We set the background here because the Acrylic can be too translucent / background too bright on Light theme -->
Expand Down
25 changes: 12 additions & 13 deletions src/modules/launcher/PowerLauncher/ReportWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,23 @@
Topmost="True"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">
<Grid Margin="12">
<Grid Margin="12" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="64" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<TextBlock
FontFamily="Segoe UI Light"
FontSize="32"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
FontSize="24"
FontWeight="SemiBold"
Foreground="Black"
Text="{x:Static p:Resources.reportWindow_header}" />

<TextBlock
Grid.Row="1"
FontSize="14"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Foreground="Black"
TextWrapping="Wrap">
<Run Text="{x:Static p:Resources.reportWindow_file_bug}" />
<Hyperlink
Expand All @@ -49,12 +48,12 @@
<TextBox
x:Name="LogFilePathBox"
Grid.Row="2"
Margin="-8,16,-8,16"
Margin="0,16,0,16"
Background="Transparent"
BorderThickness="0"
BorderBrush="Black"
BorderThickness="1"
FontFamily="Consolas"
FontSize="14"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Foreground="Black"
IsReadOnly="True"
TextWrapping="Wrap" />

Expand All @@ -63,10 +62,10 @@
Grid.Row="3"
VerticalAlignment="Stretch"
Background="Transparent"
BorderBrush="Black"
BorderThickness="1"
FontFamily="Consolas"
FontSize="14"
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Foreground="Black"
HorizontalScrollBarVisibility="Auto"
IsDocumentEnabled="True"
VerticalScrollBarVisibility="Auto" />
Expand Down
Loading

0 comments on commit 86da2e3

Please sign in to comment.