Skip to content

Commit

Permalink
Fixed settings screen
Browse files Browse the repository at this point in the history
  • Loading branch information
jefflord committed Dec 16, 2023
1 parent bf49d2f commit 0dd9516
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/modules/keyboardmanager/common/KeyboardManagerConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ namespace KeyboardManagerConstants
inline const std::wstring ShortcutSecondKeyOfChordSettingName = L"secondKeyOfChord";

// Name of the property use to store openUri.
inline const std::wstring ShortcutOpenURI = L"openUri ";
inline const std::wstring ShortcutOpenURI = L"openUri";

// Name of the property use to store shortcutOperationType.
inline const std::wstring ShortcutOperationType = L"operationType ";
inline const std::wstring ShortcutOperationType = L"operationType";

// Name of the property use to store runProgramFilePath.
//inline const std::wstring IsRunProgramSettingName = L"isRunProgram";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class AppSpecificKeysDataModel : KeysDataModel
return base.GetMappedOriginalKeys();
}

public new List<string> GetMappedNewRemapKeys()
public new List<string> GetMappedNewRemapKeys(int runProgramMaxLength)
{
return base.GetMappedNewRemapKeys();
return base.GetMappedNewRemapKeys(runProgramMaxLength);
}

public bool Compare(AppSpecificKeysDataModel arg)
Expand Down
84 changes: 65 additions & 19 deletions src/settings-ui/Settings.UI.Library/KeysDataModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Management;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
Expand All @@ -27,8 +29,11 @@ public class KeysDataModel
[JsonPropertyName("runProgramArgs")]
public string RunProgramArgs { get; set; }

[JsonPropertyName("isRunProgram")]
public bool IsRunProgram { get; set; }
[JsonPropertyName("openUri")]
public string OpenUri { get; set; }

[JsonPropertyName("operationType")]
public int OperationType { get; set; }

private static List<string> MapKeys(string stringOfKeys)
{
Expand All @@ -49,7 +54,31 @@ public List<string> GetMappedOriginalKeys()
return MapKeys(OriginalKeys);
}

public List<string> GetMappedNewRemapKeys()
public bool IsRunProgram
{
get
{
return OperationType == 1;
}
}

public bool IsOpenURI
{
get
{
return OperationType == 2;
}
}

public bool IsOpenURIOrIsRunProgram
{
get
{
return IsOpenURI || IsRunProgram;
}
}

public List<string> GetMappedNewRemapKeys(int runProgramMaxLength)
{
if (IsRunProgram)
{
Expand All @@ -60,7 +89,26 @@ public List<string> GetMappedNewRemapKeys()
}
else
{
return new List<string> { FormatFakeKeyForDisplay() };
return new List<string> { FormatFakeKeyForDisplay(runProgramMaxLength) };
}
}
else if (IsOpenURI)
{
// we're going to just pretend this is a "key" if we have a RunProgramFilePath
if (string.IsNullOrEmpty(OpenUri))
{
return new List<string>();
}
else
{
if (OpenUri.Length > runProgramMaxLength)
{
return new List<string> { $"{OpenUri.Substring(0, runProgramMaxLength - 3)}..." };
}
else
{
return new List<string> { OpenUri };
}
}
}

Expand All @@ -72,28 +120,26 @@ public List<string> GetMappedNewRemapKeys()
// e.g.: c:\MyCool\PathIs\Long\software.exe myArg1 myArg2 myArg3 -> (something like) "...ng\software.exe myArg1..."
// the idea is you get the most important part of the program to run and some of the args in case that the only thing thats different,
// e.g: "...path\software.exe cool1.txt" and "...path\software.exe cool3.txt"
private string FormatFakeKeyForDisplay()
private string FormatFakeKeyForDisplay(int runProgramMaxLength)
{
// was going to use this:
// var fakeKey = Path.GetFileName(RunProgramFilePath);
// but I like this better:
var fakeKey = RunProgramFilePath;

if (fakeKey.Length > 15)
try
{
if (File.Exists(fakeKey))
{
fakeKey = Path.GetFileName(RunProgramFilePath);
}
}
catch
{
fakeKey = $"...{fakeKey.Substring(fakeKey.Length - 12)}";
}

if (!string.IsNullOrEmpty(RunProgramArgs))
fakeKey = $"{fakeKey} {RunProgramArgs}".Trim();

if (fakeKey.Length > runProgramMaxLength)
{
if (RunProgramArgs.Length > 10)
{
fakeKey = $"{fakeKey} {RunProgramArgs.Substring(0, 7)}...";
}
else
{
fakeKey = $"{fakeKey} {RunProgramArgs}";
}
fakeKey = $"{fakeKey.Substring(0, runProgramMaxLength - 3)}...";
}

return fakeKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
<ItemsControl
AutomationProperties.AccessibilityView="Raw"
IsTabStop="False"
ItemsSource="{x:Bind GetMappedNewRemapKeys()}">
ItemsSource="{x:Bind GetMappedNewRemapKeys(15)}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="12" />
Expand Down Expand Up @@ -221,13 +221,13 @@
x:Uid="To"
Margin="8,0,8,0"
VerticalAlignment="Center"
Visibility="{x:Bind Path=IsRunProgram, Mode=OneWay, Converter={StaticResource BoolToInvertedVisibilityConverter}}"
Visibility="{x:Bind Path=IsOpenURIOrIsRunProgram, Mode=OneWay, Converter={StaticResource BoolToInvertedVisibilityConverter}}"
Style="{StaticResource SecondaryIsEnabledTextBlockStyle}" />
<custom:IsEnabledTextBlock
x:Uid="Starts"
Margin="8,0,8,0"
VerticalAlignment="Center"
Visibility="{x:Bind Path=IsRunProgram, Mode=OneWay}"
Visibility="{x:Bind Path=IsOpenURIOrIsRunProgram, Mode=OneWay}"
Style="{StaticResource SecondaryIsEnabledTextBlockStyle}" />
<Border
Padding="8,4"
Expand All @@ -238,7 +238,7 @@
<ItemsControl
AutomationProperties.AccessibilityView="Raw"
IsTabStop="False"
ItemsSource="{x:Bind GetMappedNewRemapKeys()}">
ItemsSource="{x:Bind GetMappedNewRemapKeys(15)}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="12" />
Expand All @@ -260,7 +260,7 @@
<TextBlock
Margin="4,0,0,0"
VerticalAlignment="Center"
Visibility="{x:Bind Path=IsRunProgram, Mode=OneWay, Converter={StaticResource BoolToInvertedVisibilityConverter}}"
Visibility="{x:Bind Path=IsOpenURIOrIsRunProgram, Mode=OneWay, Converter={StaticResource BoolToInvertedVisibilityConverter}}"
Foreground="{ThemeResource AccentFillColorDefaultBrush}"
Text="{x:Bind TargetApp}" />
</StackPanel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
x:Uid="KeyboardManager_RemappedTo"
IsTabStop="False"
ItemTemplate="{StaticResource RemappedKeyTemplate}"
ItemsSource="{x:Bind GetMappedNewRemapKeys()}">
ItemsSource="{x:Bind GetMappedNewRemapKeys(50)}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="4" />
Expand Down Expand Up @@ -159,14 +159,14 @@
x:Uid="To"
Margin="8,0,8,0"
VerticalAlignment="Center"
Visibility="{x:Bind Path=IsRunProgram, Mode=OneWay, Converter={StaticResource BoolToInvertedVisibilityConverter}}"
Visibility="{x:Bind Path=IsOpenURIOrIsRunProgram, Mode=OneWay, Converter={StaticResource BoolToInvertedVisibilityConverter}}"
Style="{StaticResource SecondaryIsEnabledTextBlockStyle}" />

<custom:IsEnabledTextBlock
x:Uid="Starts"
Margin="8,0,8,0"
VerticalAlignment="Center"
Visibility="{x:Bind Path=IsRunProgram, Mode=OneWay}"
Visibility="{x:Bind Path=IsOpenURIOrIsRunProgram, Mode=OneWay}"
Style="{StaticResource SecondaryIsEnabledTextBlockStyle}" />


Expand All @@ -175,7 +175,7 @@
x:Uid="KeyboardManager_RemappedTo"
IsTabStop="False"
ItemTemplate="{StaticResource RemappedKeyTemplate}"
ItemsSource="{x:Bind GetMappedNewRemapKeys()}">
ItemsSource="{x:Bind GetMappedNewRemapKeys(50)}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="4" />
Expand All @@ -187,7 +187,7 @@
Padding="12,4,12,6"
VerticalAlignment="Center"
CornerRadius="12"
Visibility="{x:Bind Path=IsRunProgram, Mode=OneWay, Converter={StaticResource BoolToInvertedVisibilityConverter}}">
Visibility="{x:Bind Path=IsOpenURIOrIsRunProgram, Mode=OneWay, Converter={StaticResource BoolToInvertedVisibilityConverter}}">
<Border.Background>
<SolidColorBrush Opacity="0.3" Color="{ThemeResource SystemAccentColor}" />
</Border.Background>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO.Abstractions;
using System.Linq;
using System.Windows.Threading;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ public static List<AppSpecificKeysDataModel> CombineShortcutLists(List<KeysDataM
}
else if (appSpecificShortcutList == null)
{
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, NewRemapString = x.NewRemapString, TargetApp = allAppsDescription }).ToList();
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, NewRemapString = x.NewRemapString, RunProgramFilePath = x.RunProgramFilePath, OperationType = x.OperationType, OpenUri = x.OpenUri, RunProgramArgs = x.RunProgramArgs, TargetApp = allAppsDescription }).ToList();
}
else
{
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, NewRemapString = x.NewRemapString, RunProgramFilePath = x.RunProgramFilePath, IsRunProgram = x.IsRunProgram, RunProgramArgs = x.RunProgramArgs, TargetApp = allAppsDescription }).Concat(appSpecificShortcutList).ToList();
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, NewRemapString = x.NewRemapString, RunProgramFilePath = x.RunProgramFilePath, OperationType = x.OperationType, OpenUri = x.OpenUri, RunProgramArgs = x.RunProgramArgs, TargetApp = allAppsDescription }).Concat(appSpecificShortcutList).ToList();
}
}

Expand Down

1 comment on commit 0dd9516

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log or 📝 job summary for details.

Unrecognized words (31)
ALLOWCHORDS
ARGSFORPROGRAM
BIF
BROWSEINFO
CKBH
cmdow
commdlg
CRTL
ELEVATIONTYPEDIFFERENTUSER
ELEVATIONTYPEELEVATED
ELEVATIONTYPENORMAL
FILEMUSTEXIST
Lencode
LPITEMIDLIST
lpstr
NEWDIALOGSTYLE
ofn
OPENFILENAME
PATHMUSTEXIST
PATHTOPROGRAM
PROCESSENTRY
RETURNONLYFSDIRS
ritchielawrence
runasuser
SNAPPROCESS
STARTINDIRFORPROGRAM
tlhelp
Toolhelp
URIOr
urlmon
wcsicmp
Previously acknowledged words that are now absent CHT constexpr DEU hashcode HEB JPN LAlt Lambson langword nodiscard pcs qps roundf RUS RValue SVE tonos weakme wifi 🫥
To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the git@github.com:jefflord/PowerToys.git repository
on the launch-apps-3350 branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.22/apply.pl' |
perl - 'https://github.com/jefflord/PowerToys/actions/runs/7229464813/attempts/1'
Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary

This includes both expected items (1857) from .github/actions/spell-check/expect.txt and unrecognized words (31)

Dictionary Entries Covers Uniquely
cspell:r/src/r.txt 543 1 1
cspell:cpp/src/people.txt 23 1
cspell:cpp/src/ecosystem.txt 51 1

Consider adding them (in .github/workflows/spelling2.yml) for uses: check-spelling/check-spelling@v0.0.22 in its with:

      with:
        extra_dictionaries:
          cspell:r/src/r.txt
          cspell:cpp/src/people.txt
          cspell:cpp/src/ecosystem.txt

To stop checking additional dictionaries, add (in .github/workflows/spelling2.yml) for uses: check-spelling/check-spelling@v0.0.22 in its with:

check_extra_dictionaries: ''
If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.