Skip to content

Commit

Permalink
File monitor, quotes, xaml screens one
Browse files Browse the repository at this point in the history
  • Loading branch information
jefflord committed Dec 3, 2023
1 parent 66ce887 commit 1f44025
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
<value>To send:</value>
</data>
<data name="EditShortcuts_TargetHeader" xml:space="preserve">
<value>To send:</value>
<value>To:</value>
</data>
<data name="EditShortcuts_TargetAppHeader" xml:space="preserve">
<value>Target app:</value>
Expand Down Expand Up @@ -297,10 +297,10 @@
<comment>Key on a keyboard</comment>
</data>
<data name="Mapping_Type_DropDown_Text" xml:space="preserve">
<value>Text</value>
<value>Send Text</value>
</data>
<data name="Mapping_Type_DropDown_Key_Shortcut" xml:space="preserve">
<value>Key/Shortcut</value>
<value>Send Key/Shortcut</value>
<comment>Key on a keyboard</comment>
</data>
<data name="Mapping_Type_DropDown_Run_Program" xml:space="preserve">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vector<s
runProgramPathInput.Margin(textInputMargin);

runProgramPathInput.AcceptsReturn(false);
runProgramPathInput.IsSpellCheckEnabled(false);
runProgramPathInput.Visibility(Visibility::Collapsed);
runProgramPathInput.Width(EditorConstants::TableDropDownHeight);
controlStackPanel.Children().Append(runProgramPathInput);
Expand All @@ -179,12 +180,14 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vector<s
runProgramArgsForProgramInput.Margin(textInputMargin);

runProgramArgsForProgramInput.AcceptsReturn(false);
runProgramArgsForProgramInput.IsSpellCheckEnabled(false);
runProgramArgsForProgramInput.Visibility(Visibility::Collapsed);
runProgramArgsForProgramInput.Width(EditorConstants::TableDropDownHeight);
controlStackPanel.Children().Append(runProgramArgsForProgramInput);
runProgramArgsForProgramInput.HorizontalAlignment(HorizontalAlignment::Left);

auto runProgramStartInDirInput = TextBox();
runProgramStartInDirInput.IsSpellCheckEnabled(false);
runProgramStartInDirInput.PlaceholderText(KeyboardManagerEditorStrings::EditShortcutsStartInDirForProgram());
runProgramStartInDirInput.Margin(textInputMargin);

Expand All @@ -202,9 +205,9 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vector<s
}
Shortcut tempShortcut;
tempShortcut.isRunProgram = true;
tempShortcut.runProgramFilePath = runProgramPathInput.Text().c_str();
tempShortcut.runProgramArgs = runProgramArgsForProgramInput.Text().c_str();
tempShortcut.runProgramStartInDir = runProgramStartInDirInput.Text().c_str();
tempShortcut.runProgramFilePath = ShortcutControl::RemoveExtraQuotes(runProgramPathInput.Text().c_str());
tempShortcut.runProgramArgs = ShortcutControl::RemoveExtraQuotes(runProgramArgsForProgramInput.Text().c_str());
tempShortcut.runProgramStartInDir = ShortcutControl::RemoveExtraQuotes(runProgramStartInDirInput.Text().c_str());
// Assign instead of setting the value in the buffer since the previous value may not be a Shortcut
shortcutRemapBuffer[rowIndex].first[1] = tempShortcut;

Expand All @@ -219,9 +222,9 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vector<s
}
Shortcut tempShortcut;
tempShortcut.isRunProgram = true;
tempShortcut.runProgramFilePath = runProgramPathInput.Text().c_str();
tempShortcut.runProgramArgs = runProgramArgsForProgramInput.Text().c_str();
tempShortcut.runProgramStartInDir = runProgramStartInDirInput.Text().c_str();
tempShortcut.runProgramFilePath = ShortcutControl::RemoveExtraQuotes(runProgramPathInput.Text().c_str());
tempShortcut.runProgramArgs = ShortcutControl::RemoveExtraQuotes(runProgramArgsForProgramInput.Text().c_str());
tempShortcut.runProgramStartInDir = ShortcutControl::RemoveExtraQuotes(runProgramStartInDirInput.Text().c_str());
// Assign instead of setting the value in the buffer since the previous value may not be a Shortcut
shortcutRemapBuffer[rowIndex].first[1] = tempShortcut;
//ShortcutControl::RunProgramTextOnChange(rowIndex, shortcutRemapBuffer, runProgramPathInput, runProgramArgsForProgramInput, runProgramStartInDirInput);
Expand All @@ -236,16 +239,15 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vector<s

Shortcut tempShortcut;
tempShortcut.isRunProgram = true;
tempShortcut.runProgramFilePath = runProgramPathInput.Text().c_str();
tempShortcut.runProgramArgs = runProgramArgsForProgramInput.Text().c_str();
tempShortcut.runProgramStartInDir = runProgramStartInDirInput.Text().c_str();
tempShortcut.runProgramFilePath = ShortcutControl::RemoveExtraQuotes(runProgramPathInput.Text().c_str());
tempShortcut.runProgramArgs = ShortcutControl::RemoveExtraQuotes(runProgramArgsForProgramInput.Text().c_str());
tempShortcut.runProgramStartInDir = ShortcutControl::RemoveExtraQuotes(runProgramStartInDirInput.Text().c_str());
// Assign instead of setting the value in the buffer since the previous value may not be a Shortcut
shortcutRemapBuffer[rowIndex].first[1] = tempShortcut;

//ShortcutControl::RunProgramTextOnChange(rowIndex, shortcutRemapBuffer, runProgramPathInput, runProgramArgsForProgramInput, runProgramStartInDirInput);
});


// add grid for when it's a key/shortcut
auto shortcutGrid = keyboardRemapControlObjects.back()[1]->shortcutDropDownVariableSizedWrapGrid.as<VariableSizedWrapGrid>();
auto gridMargin = Windows::UI::Xaml::Thickness();
Expand Down Expand Up @@ -530,15 +532,14 @@ void ShortcutControl::AddNewShortcutControlRow(StackPanel& parent, std::vector<s
}
}

void ShortcutControl::RunProgramTextOnChange(const int rowIndex, RemapBuffer shortcutRemapBuffer, const winrt::Windows::UI::Xaml::Controls::TextBox& runProgramPathInput, const winrt::Windows::UI::Xaml::Controls::TextBox& runProgramArgsForProgramInput, const winrt::Windows::UI::Xaml::Controls::TextBox& runProgramStartInDirInput)
std::wstring ShortcutControl::RemoveExtraQuotes(const std::wstring& str)
{
Shortcut tempShortcut;
tempShortcut.isRunProgram = true;
tempShortcut.runProgramFilePath = runProgramPathInput.Text().c_str();
tempShortcut.runProgramArgs = runProgramArgsForProgramInput.Text().c_str();
tempShortcut.runProgramStartInDir = runProgramStartInDirInput.Text().c_str();
// Assign instead of setting the value in the buffer since the previous value may not be a Shortcut
shortcutRemapBuffer[rowIndex].first[1] = tempShortcut;
if (!str.empty() && str.front() == L'"' && str.back() == L'"')
{
return str.substr(1, str.size() - 2);
}

return str;
}

ShortcutControl::ShortcutType ShortcutControl::GetShortcutType(const winrt::Windows::UI::Xaml::Controls::ComboBox& typeCombo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ShortcutControl

static ShortcutType GetShortcutType(const winrt::Windows::UI::Xaml::Controls::ComboBox& typeCombo);

static void ShortcutControl::RunProgramTextOnChange(const int rowIndex, RemapBuffer shortcutRemapBuffer, const winrt::Windows::UI::Xaml::Controls::TextBox& runProgramPathInput, const winrt::Windows::UI::Xaml::Controls::TextBox& runProgramArgsForProgramInput, const winrt::Windows::UI::Xaml::Controls::TextBox& runProgramStartInDirInput);
static std::wstring ShortcutControl::RemoveExtraQuotes(const std::wstring& str);

// Function to return the stack panel element of the ShortcutControl. This is the externally visible UI element which can be used to add it to other layouts
StackPanel GetShortcutControl();
Expand Down
52 changes: 52 additions & 0 deletions src/settings-ui/Settings.UI.Library/KeysDataModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
Expand All @@ -24,8 +25,19 @@ public class KeysDataModel
[JsonPropertyName("runProgramFilePath")]
public string RunProgramFilePath { get; set; }

[JsonPropertyName("runProgramArgs")]
public string RunProgramArgs { get; set; }

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

private static List<string> MapKeys(string stringOfKeys)
{
if (stringOfKeys == null)
{
return new List<string>();
}

return stringOfKeys
.Split(';')
.Select(uint.Parse)
Expand All @@ -40,9 +52,49 @@ public List<string> GetMappedOriginalKeys()

public List<string> GetMappedNewRemapKeys()
{
if (IsRunProgram)
{
// we're going to just pretend this is a "key" if we have a RunProgramFilePath
if (string.IsNullOrEmpty(RunProgramFilePath))
{
return new List<string>();
}
else
{
return new List<string> { FormatFakeKeyForDisplay() };
}
}

return string.IsNullOrEmpty(NewRemapString) ? MapKeys(NewRemapKeys) : new List<string> { NewRemapString };
}

private string FormatFakeKeyForDisplay()
{
// was going to use this:
// var fakeKey = Path.GetFileName(RunProgramFilePath);
// but I like this better:
var fakeKey = RunProgramFilePath;

if (fakeKey.Length > 15)
{
fakeKey = $"...{fakeKey.Substring(fakeKey.Length - 12)}";
}

if (!string.IsNullOrEmpty(RunProgramArgs))
{
if (RunProgramArgs.Length > 10)
{
fakeKey = $"{fakeKey} {RunProgramArgs.Substring(0, 7)}...";
}
else
{
fakeKey = $"{fakeKey} {RunProgramArgs}";
}
}

return fakeKey;
}

public string ToJsonString()
{
return JsonSerializer.Serialize(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,19 @@
</ItemsControl.ItemTemplate>
</ItemsControl>
</Border>

<custom:IsEnabledTextBlock
x:Uid="To"
Margin="8,0,8,0"
VerticalAlignment="Center"
Visibility="{x:Bind Path=IsRunProgram, 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}"
Style="{StaticResource SecondaryIsEnabledTextBlockStyle}" />
<Border
Padding="8,4"
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
Expand Down Expand Up @@ -252,6 +260,7 @@
<TextBlock
Margin="4,0,0,0"
VerticalAlignment="Center"
Visibility="{x:Bind Path=IsRunProgram, 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 @@ -14,6 +14,10 @@

<Page.Resources>
<converters:CollectionVisibilityConverter x:Key="CollectionVisibilityConverter" />
<converters:BoolToVisibilityConverter
x:Key="BoolToInvertedVisibilityConverter"
FalseValue="Visible"
TrueValue="Collapsed" />
<Style x:Name="KeysListViewContainerStyle" TargetType="ListViewItem">
<Setter Property="IsTabStop" Value="False" />
</Style>
Expand Down Expand Up @@ -150,12 +154,22 @@
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>

<custom:IsEnabledTextBlock
x:Uid="To"
Margin="8,0,8,0"
VerticalAlignment="Center"
Visibility="{x:Bind Path=IsRunProgram, 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}"
Style="{StaticResource SecondaryIsEnabledTextBlockStyle}" />


<ItemsControl
Name="KeyboardManager_RemappedTo"
x:Uid="KeyboardManager_RemappedTo"
Expand All @@ -172,7 +186,8 @@
Margin="16,0,0,0"
Padding="12,4,12,6"
VerticalAlignment="Center"
CornerRadius="12">
CornerRadius="12"
Visibility="{x:Bind Path=IsRunProgram, Mode=OneWay, Converter={StaticResource BoolToInvertedVisibilityConverter}}">
<Border.Background>
<SolidColorBrush Opacity="0.3" Color="{ThemeResource SystemAccentColor}" />
</Border.Background>
Expand Down
6 changes: 5 additions & 1 deletion src/settings-ui/Settings.UI/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2354,7 +2354,11 @@ From there, simply click on one of the supported files in the File Explorer and
<value>to</value>
<comment>as in: from x to y</comment>
</data>
<data name="LearnMore_Awake.Text" xml:space="preserve">
<data name="Starts.Text" xml:space="preserve">
<value>starts</value>
<comment>as in: doing x start y</comment>
</data>
<data name="LearnMore_Awake.Text" xml:space="preserve">
<value>Learn more about Awake</value>
<comment>Awake is a product name, do not loc</comment>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public static List<AppSpecificKeysDataModel> CombineShortcutLists(List<KeysDataM
}
else
{
return globalShortcutList.ConvertAll(x => new AppSpecificKeysDataModel { OriginalKeys = x.OriginalKeys, NewRemapKeys = x.NewRemapKeys, NewRemapString = x.NewRemapString, TargetApp = allAppsDescription }).Concat(appSpecificShortcutList).ToList();
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();
}
}

Expand Down

1 comment on commit 1f44025

@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 (12)
ARGSFORPROGRAM
cmdow
direcotry
PATHTOPROGRAM
PROCESSENTRY
ritchielawrence
SNAPPROCESS
splitw
STARTINDIRFORPROGRAM
tlhelp
Toolhelp
wcsicmp
Previously acknowledged words that are now absent CHT constexpr DEU hashcode HEB JPN nodiscard pcs qps roundf RUS RValue SVE 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/7076675029/attempts/1'
Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary

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

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.