mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add support for customized usercontrol
This commit is contained in:
parent
c2d2fc0092
commit
733ebb8ac1
4 changed files with 123 additions and 66 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Controls;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
|
||||||
namespace Flow.Launcher.Plugin
|
namespace Flow.Launcher.Plugin
|
||||||
|
|
@ -193,6 +194,11 @@ namespace Flow.Launcher.Plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string SubTitleToolTip { get; set; }
|
public string SubTitleToolTip { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Customized Preview Panel
|
||||||
|
/// </summary>
|
||||||
|
public Lazy<UserControl> PreviewPanel { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Run this result, asynchronously
|
/// Run this result, asynchronously
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@
|
||||||
Title="Flow Launcher"
|
Title="Flow Launcher"
|
||||||
MinWidth="{Binding MainWindowWidth, Mode=OneWay}"
|
MinWidth="{Binding MainWindowWidth, Mode=OneWay}"
|
||||||
MaxWidth="{Binding MainWindowWidth, Mode=OneWay}"
|
MaxWidth="{Binding MainWindowWidth, Mode=OneWay}"
|
||||||
d:DataContext="{d:DesignInstance vm:MainViewModel}"
|
|
||||||
AllowDrop="True"
|
AllowDrop="True"
|
||||||
AllowsTransparency="True"
|
AllowsTransparency="True"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
|
|
@ -235,9 +234,10 @@
|
||||||
</ContentControl.Style>
|
</ContentControl.Style>
|
||||||
</ContentControl>
|
</ContentControl>
|
||||||
<Rectangle
|
<Rectangle
|
||||||
Width="Auto"
|
Width="Auto"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
Style="{DynamicResource SeparatorStyle}" Visibility="Visible" />
|
Style="{DynamicResource SeparatorStyle}"
|
||||||
|
Visibility="Visible" />
|
||||||
<Line
|
<Line
|
||||||
x:Name="ProgressBar"
|
x:Name="ProgressBar"
|
||||||
Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=ActualWidth}"
|
Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Grid}}, Path=ActualWidth}"
|
||||||
|
|
@ -254,71 +254,108 @@
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
<ColumnDefinition Width="0.7*"/>
|
<ColumnDefinition Width="0.7*" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<StackPanel Grid.Column="0" x:Name="ResultArea">
|
<StackPanel x:Name="ResultArea" Grid.Column="0">
|
||||||
<Border Style="{DynamicResource WindowRadius}">
|
<Border Style="{DynamicResource WindowRadius}">
|
||||||
<Border.Clip>
|
<Border.Clip>
|
||||||
<MultiBinding Converter="{StaticResource BorderClipConverter}">
|
<MultiBinding Converter="{StaticResource BorderClipConverter}">
|
||||||
<Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}" />
|
<Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}" />
|
||||||
<Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}" />
|
<Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}" />
|
||||||
<Binding Path="CornerRadius" RelativeSource="{RelativeSource Self}" />
|
<Binding Path="CornerRadius" RelativeSource="{RelativeSource Self}" />
|
||||||
</MultiBinding>
|
</MultiBinding>
|
||||||
</Border.Clip>
|
</Border.Clip>
|
||||||
<ContentControl>
|
<ContentControl>
|
||||||
<flowlauncher:ResultListBox
|
<flowlauncher:ResultListBox
|
||||||
x:Name="ResultListBox"
|
x:Name="ResultListBox"
|
||||||
DataContext="{Binding Results}"
|
DataContext="{Binding Results}"
|
||||||
PreviewMouseDown="OnPreviewMouseButtonDown" />
|
PreviewMouseDown="OnPreviewMouseButtonDown" />
|
||||||
</ContentControl>
|
</ContentControl>
|
||||||
</Border>
|
|
||||||
<Border Style="{DynamicResource WindowRadius}">
|
|
||||||
<Border.Clip>
|
|
||||||
<MultiBinding Converter="{StaticResource BorderClipConverter}">
|
|
||||||
<Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}" />
|
|
||||||
<Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}" />
|
|
||||||
<Binding Path="CornerRadius" RelativeSource="{RelativeSource Self}" />
|
|
||||||
</MultiBinding>
|
|
||||||
</Border.Clip>
|
|
||||||
<ContentControl>
|
|
||||||
<flowlauncher:ResultListBox
|
|
||||||
x:Name="ContextMenu"
|
|
||||||
DataContext="{Binding ContextMenu}"
|
|
||||||
PreviewMouseDown="OnPreviewMouseButtonDown" />
|
|
||||||
</ContentControl>
|
|
||||||
</Border>
|
|
||||||
<Border Style="{DynamicResource WindowRadius}">
|
|
||||||
<Border.Clip>
|
|
||||||
<MultiBinding Converter="{StaticResource BorderClipConverter}">
|
|
||||||
<Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}" />
|
|
||||||
<Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}" />
|
|
||||||
<Binding Path="CornerRadius" RelativeSource="{RelativeSource Self}" />
|
|
||||||
</MultiBinding>
|
|
||||||
</Border.Clip>
|
|
||||||
<ContentControl>
|
|
||||||
<flowlauncher:ResultListBox
|
|
||||||
x:Name="History"
|
|
||||||
DataContext="{Binding History}"
|
|
||||||
PreviewMouseDown="OnPreviewMouseButtonDown" />
|
|
||||||
</ContentControl>
|
|
||||||
</Border>
|
|
||||||
</StackPanel>
|
|
||||||
<Grid x:Name="Preview" Style="{DynamicResource PreviewArea}" Grid.Column="1" DataContext="{Binding SelectedItem, ElementName=ResultListBox}" VerticalAlignment="Stretch" Visibility="Collapsed">
|
|
||||||
<Border Style="{DynamicResource PreviewBorderStyle}">
|
|
||||||
<Grid Margin="10 0 10 0" VerticalAlignment="Center" Background="Transparent">
|
|
||||||
<Grid.RowDefinitions>
|
|
||||||
<RowDefinition Height="*"/>
|
|
||||||
<RowDefinition Height="auto"/>
|
|
||||||
<RowDefinition Height="auto" />
|
|
||||||
</Grid.RowDefinitions>
|
|
||||||
<Image Grid.Row="0" Grid.Column="0" Height="128" x:Name="ImageIcon" HorizontalAlignment="Center" Source="{Binding PreviewImage}" Visibility="{Binding ShowIcon}" Margin="0 0 0 8" />
|
|
||||||
<TextBlock Grid.Row="1" x:Name="Title" Text="{Binding Result.Title}" FontSize="18" TextAlignment="Center" FontWeight="SemiBold" Style="{DynamicResource ItemTitleStyle}" TextWrapping="Wrap" HorizontalAlignment="Stretch" />
|
|
||||||
<TextBlock Grid.Row="2" x:Name="SubTitle" Text="{Binding Result.SubTitle}" FontSize="13" LineHeight="22" Style="{DynamicResource ItemSubTitleStyle}" TextWrapping="Wrap" HorizontalAlignment="Stretch" Margin="0 12 0 0" TextAlignment="Center"></TextBlock>
|
|
||||||
</Grid>
|
|
||||||
</Border>
|
</Border>
|
||||||
|
<Border Style="{DynamicResource WindowRadius}">
|
||||||
|
<Border.Clip>
|
||||||
|
<MultiBinding Converter="{StaticResource BorderClipConverter}">
|
||||||
|
<Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}" />
|
||||||
|
<Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}" />
|
||||||
|
<Binding Path="CornerRadius" RelativeSource="{RelativeSource Self}" />
|
||||||
|
</MultiBinding>
|
||||||
|
</Border.Clip>
|
||||||
|
<ContentControl>
|
||||||
|
<flowlauncher:ResultListBox
|
||||||
|
x:Name="ContextMenu"
|
||||||
|
DataContext="{Binding ContextMenu}"
|
||||||
|
PreviewMouseDown="OnPreviewMouseButtonDown" />
|
||||||
|
</ContentControl>
|
||||||
|
</Border>
|
||||||
|
<Border Style="{DynamicResource WindowRadius}">
|
||||||
|
<Border.Clip>
|
||||||
|
<MultiBinding Converter="{StaticResource BorderClipConverter}">
|
||||||
|
<Binding Path="ActualWidth" RelativeSource="{RelativeSource Self}" />
|
||||||
|
<Binding Path="ActualHeight" RelativeSource="{RelativeSource Self}" />
|
||||||
|
<Binding Path="CornerRadius" RelativeSource="{RelativeSource Self}" />
|
||||||
|
</MultiBinding>
|
||||||
|
</Border.Clip>
|
||||||
|
<ContentControl>
|
||||||
|
<flowlauncher:ResultListBox
|
||||||
|
x:Name="History"
|
||||||
|
DataContext="{Binding History}"
|
||||||
|
PreviewMouseDown="OnPreviewMouseButtonDown" />
|
||||||
|
</ContentControl>
|
||||||
|
</Border>
|
||||||
|
</StackPanel>
|
||||||
|
<Grid
|
||||||
|
x:Name="Preview"
|
||||||
|
Grid.Column="1"
|
||||||
|
VerticalAlignment="Stretch"
|
||||||
|
d:DataContext="{d:DesignInstance vm:ResultViewModel}"
|
||||||
|
DataContext="{Binding SelectedItem, ElementName=ResultListBox}"
|
||||||
|
Style="{DynamicResource PreviewArea}"
|
||||||
|
Visibility="Collapsed">
|
||||||
|
<Border Style="{DynamicResource PreviewBorderStyle}" Visibility="{Binding ShowDefaultPreview}">
|
||||||
|
<Grid
|
||||||
|
Margin="10,0,10,0"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Background="Transparent">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="*" />
|
||||||
|
<RowDefinition Height="auto" />
|
||||||
|
<RowDefinition Height="auto" />
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Image
|
||||||
|
x:Name="ImageIcon"
|
||||||
|
Grid.Row="0"
|
||||||
|
Grid.Column="0"
|
||||||
|
Height="128"
|
||||||
|
Margin="0,0,0,8"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
Source="{Binding PreviewImage}"
|
||||||
|
Visibility="{Binding ShowIcon}" />
|
||||||
|
<TextBlock
|
||||||
|
x:Name="Title"
|
||||||
|
Grid.Row="1"
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
FontSize="18"
|
||||||
|
FontWeight="SemiBold"
|
||||||
|
Style="{DynamicResource ItemTitleStyle}"
|
||||||
|
Text="{Binding Result.Title}"
|
||||||
|
TextAlignment="Center"
|
||||||
|
TextWrapping="Wrap" />
|
||||||
|
<TextBlock
|
||||||
|
x:Name="SubTitle"
|
||||||
|
Grid.Row="2"
|
||||||
|
Margin="0,12,0,0"
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
FontSize="13"
|
||||||
|
LineHeight="22"
|
||||||
|
Style="{DynamicResource ItemSubTitleStyle}"
|
||||||
|
Text="{Binding Result.SubTitle}"
|
||||||
|
TextAlignment="Center"
|
||||||
|
TextWrapping="Wrap" />
|
||||||
|
</Grid>
|
||||||
|
</Border>
|
||||||
|
<ContentControl Content="{Binding Result.PreviewPanel.Value}" Visibility="{Binding ShowCustomizedPrewview}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Border>
|
</Border>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ namespace Flow.Launcher.ViewModel
|
||||||
public class ResultViewModel : BaseModel
|
public class ResultViewModel : BaseModel
|
||||||
{
|
{
|
||||||
private static PrivateFontCollection fontCollection = new();
|
private static PrivateFontCollection fontCollection = new();
|
||||||
private static Dictionary<string, string> fonts = new();
|
private static Dictionary<string, string> fonts = new();
|
||||||
|
|
||||||
public ResultViewModel(Result result, Settings settings)
|
public ResultViewModel(Result result, Settings settings)
|
||||||
{
|
{
|
||||||
|
|
@ -67,6 +67,10 @@ namespace Flow.Launcher.ViewModel
|
||||||
public Visibility ShowOpenResultHotkey =>
|
public Visibility ShowOpenResultHotkey =>
|
||||||
Settings.ShowOpenResultHotkey ? Visibility.Visible : Visibility.Collapsed;
|
Settings.ShowOpenResultHotkey ? Visibility.Visible : Visibility.Collapsed;
|
||||||
|
|
||||||
|
public Visibility ShowDefaultPreview => Result.PreviewPanel == null ? Visibility.Visible : Visibility.Collapsed;
|
||||||
|
|
||||||
|
public Visibility ShowCustomizedPrewview => Result.PreviewPanel == null ? Visibility.Collapsed : Visibility.Visible;
|
||||||
|
|
||||||
public Visibility ShowIcon
|
public Visibility ShowIcon
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ using System.Diagnostics;
|
||||||
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
|
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Threading.Channels;
|
using System.Threading.Channels;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
|
||||||
namespace Flow.Launcher.Plugin.Program.Programs
|
namespace Flow.Launcher.Plugin.Program.Programs
|
||||||
{
|
{
|
||||||
|
|
@ -104,6 +105,15 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
||||||
Score = matchResult.Score,
|
Score = matchResult.Score,
|
||||||
TitleHighlightData = matchResult.MatchData,
|
TitleHighlightData = matchResult.MatchData,
|
||||||
ContextData = this,
|
ContextData = this,
|
||||||
|
PreviewPanel = new Lazy<System.Windows.Controls.UserControl>(() =>
|
||||||
|
{
|
||||||
|
var control = new UserControl();
|
||||||
|
control.Content = new TextBlock()
|
||||||
|
{
|
||||||
|
Text = "test"
|
||||||
|
};
|
||||||
|
return control;
|
||||||
|
}),
|
||||||
Action = c =>
|
Action = c =>
|
||||||
{
|
{
|
||||||
var runAsAdmin = (
|
var runAsAdmin = (
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue