Skip to content

Commit

Permalink
[Store] Parse web link queries
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Mar 12, 2023
1 parent aee21e1 commit 2640911
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
16 changes: 11 additions & 5 deletions Amethyst/Pages/Plugins.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@
</Grid.ColumnDefinitions>
<TextBox Header="Search or paste a link:"
PlaceholderText="Search for plugins, or paste the link to a plugin repo"
IsSpellCheckEnabled="False"
TextChanged="SearchTextBox_TextChanged"
x:Name="SearchTextBox" KeyDown="SearchTextBox_KeyDown" />
<Button VerticalAlignment="Bottom" Grid.Column="1"
x:Name="SearchButton" Click="SearchButton_Click">
<Button.Content>
<FontIcon Glyph="&#xE721;" />
<Grid>
<FontIcon Glyph="&#xE721;" />
</Grid>
</Button.Content>
</Button>
</Grid>
Expand Down Expand Up @@ -484,7 +487,8 @@
<ItemsRepeater.ItemTemplate>
<DataTemplate
x:DataType="mvvm:StorePluginContributor">
<Grid ColumnSpacing="7" Height="32"
<Grid ColumnSpacing="7"
Height="32"
Margin="15,5">
<Grid.ColumnDefinitions>
<ColumnDefinition
Expand All @@ -493,9 +497,11 @@
Width="*" />
</Grid.ColumnDefinitions>

<PersonPicture Width="32" DisplayName="{x:Bind Name}">
<PersonPicture Width="32"
DisplayName="{x:Bind Name}">
<PersonPicture.ProfilePicture>
<BitmapImage UriSource="{x:Bind Avatar}" />
<BitmapImage
UriSource="{x:Bind Avatar}" />
</PersonPicture.ProfilePicture>
</PersonPicture>

Expand Down Expand Up @@ -568,7 +574,7 @@

<MenuFlyoutSeparator Grid.Row="0"
Margin="0,10"
Width="1000" />
HorizontalAlignment="Stretch" />

<Grid Grid.Row="1"
HorizontalAlignment="Stretch">
Expand Down
26 changes: 23 additions & 3 deletions Amethyst/Pages/Plugins.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,33 @@ private void OnPropertyChanged(string propertyName = null)
private async void SearchButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(SearchTextBox.Text)) return;
await ExecuteSearch(SearchTextBox.Text); // Search using our query
await ProcessQuery(SearchTextBox.Text); // Search using our query
}

private async void SearchTextBox_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key != VirtualKey.Enter || string.IsNullOrEmpty((sender as TextBox)?.Text)) return;
await ExecuteSearch(((TextBox)sender).Text); // Search using our query
if (e.Key != VirtualKey.Enter) return; // Discard non-confirms
await ProcessQuery((sender as TextBox)?.Text);
}

private async Task ProcessQuery(string query)
{
if (query.EndsWith(".zip"))
{
// The provided text is a link to the plugin zip, process as drag-and-drop
// TODO DRAGANDDROP
}
else if (query.StartsWith("https://github.com/") || query.StartsWith("http://github.com/"))
{
await ExecuteSearch(query // The provided text is a link
.Replace("https://github.com/", string.Empty)
.Replace("http://github.com/", string.Empty));
}
else
{
// Only a search query
await ExecuteSearch(query);
}
}

private async Task ExecuteSearch(string query)
Expand Down

0 comments on commit 2640911

Please sign in to comment.