添加自定义菜单图标

This commit is contained in:
liufei
2021-07-12 17:28:57 +08:00
parent a6b7a2e816
commit 68d21d039c
15 changed files with 234 additions and 76 deletions

View File

@@ -0,0 +1,43 @@
<Border x:Class="GeekDesk.Control.Other.CustomIconUrlDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol"
CornerRadius="3"
Width="400"
Height="230"
Opacity="0.95">
<Border.Resources>
<Style x:Key="LeftTB" TargetType="TextBlock" BasedOn="{StaticResource TextBlockBaseStyle}">
<Setter Property="Width" Value="100"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontSize" Value="14"/>
</Style>
</Border.Resources>
<Border.Background>
<SolidColorBrush Color="AliceBlue" Opacity="1"/>
</Border.Background>
<hc:SimplePanel Margin="10">
<Grid Margin="8,20,8,20">
<hc:UniformSpacingPanel Spacing="10" Margin="0,10,0,-10">
<TextBlock Text="SVG 图标地址:" Style="{StaticResource LeftTB}"/>
<TextBox x:Name="IconUrl" Text="{Binding Name, Mode=OneWay}" Width="240" FontSize="14"/>
</hc:UniformSpacingPanel>
<hc:UniformSpacingPanel Spacing="10" Margin="0,58.276,0,-58.276">
<TextBlock Text="JSON 配置地址:" Style="{StaticResource LeftTB}"/>
<TextBox x:Name="JsonUrl" Text="{Binding Name, Mode=OneWay}" Width="240" FontSize="14"/>
</hc:UniformSpacingPanel>
<!--<hc:UniformSpacingPanel Spacing="10" Margin="246.206,124.551,-246.206,-124.551">
<Button Content="取消" Click=""
/>
<Button Content="保存" Click=""
Background="#5BC0DE"
Foreground="White"/>
</hc:UniformSpacingPanel>-->
</Grid>
<!--<Button Width="22" Height="22" Command="hc:ControlCommands.Close" Style="{StaticResource ButtonIcon}" Foreground="{DynamicResource {x:Static SystemColors.ControlDarkDarkBrushKey}}" hc:IconElement.Geometry="{StaticResource ErrorGeometry}" Padding="0" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,4,4,0"/>-->
</hc:SimplePanel>
</Border>

View File

@@ -0,0 +1,30 @@
using GeekDesk.Util;
using GeekDesk.ViewModel;
using Microsoft.Win32;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
namespace GeekDesk.Control.Other
{
/// <summary>
/// TextDialog.xaml 的交互逻辑
/// </summary>
public partial class CustomIconUrlDialog
{
public CustomIconUrlDialog(AppConfig appConfig)
{
this.DataContext = appConfig;
InitializeComponent();
}
public CustomIconUrlDialog()
{
InitializeComponent();
}
}
}

View File

@@ -19,12 +19,6 @@
</Border.Background>
<hc:SimplePanel Margin="10">
<Grid Margin="8,20,8,20">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="93*"/>
<ColumnDefinition Width="38*"/>
<ColumnDefinition Width="126*"/>
<ColumnDefinition Width="7*"/>
</Grid.ColumnDefinitions>
<hc:UniformSpacingPanel Spacing="10" Grid.ColumnSpan="4">
<TextBlock Text="名称:" Style="{StaticResource LeftTB}"/>
<TextBox x:Name="IconName" Text="{Binding Name, Mode=OneWay}" Width="180" FontSize="14"/>

View File

@@ -4,7 +4,6 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:cvt="clr-namespace:GeekDesk.Converts"
xmlns:local="clr-namespace:GeekDesk.Control.UserControls"
xmlns:hc="https://handyorg.github.io/handycontrol"
mc:Ignorable="d"
Background="AliceBlue"

View File

@@ -8,7 +8,7 @@
mc:Ignorable="d"
>
<WrapPanel HorizontalAlignment="Center" VerticalAlignment="Top">
<ListBox x:Name="IconListBox" ItemsSource="{Binding iconListSystem}" SelectionChanged="ListBox_SelectionChanged" BorderThickness="0" Background="AliceBlue">
<ListBox x:Name="IconListBox" ItemsSource="{Binding}" BorderThickness="0" Background="AliceBlue">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" Background="Transparent"/>

View File

@@ -23,6 +23,7 @@ namespace GeekDesk.Control.UserControls.IconFont
{
public IconPannel()
{
//DataContext = this;
InitializeComponent();
}

View File

@@ -107,7 +107,7 @@
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel MouseLeftButtonDown="MenuClick" Tag="{Binding}">
<StackPanel MouseLeftButtonDown="MenuClick" MouseRightButtonDown="MenuClick" Tag="{Binding}">
<hc:TextBox Text="{Binding Path=MenuName, Mode=TwoWay}"
HorizontalAlignment="Left"
Width="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type ListBox},AncestorLevel=1},Path=Tag, Mode=TwoWay, Converter={StaticResource MenuWidthConvert}}"
@@ -119,27 +119,19 @@
IsVisibleChanged="MenuEditWhenVisibilityChanged"
Visibility="{Binding MenuEdit}"/>
<StackPanel Orientation="Horizontal">
<!--<Button Background="Transparent"
BorderThickness="0"
hc:IconElement.Geometry="{StaticResource test}"
hc:IconElement.Height="18"
hc:IconElement.Width="18"
/>-->
<!--<Button Background="Transparent" BorderThickness="0" Height="10" Width="10">
<Canvas>
<Path Fill="#92E3C3" Data="M391.68 957.44h-66.56v-158.4128H66.56v-66.56h258.56v-174.08H66.56v-66.56h258.56V307.2h66.56l-0.0512 184.6272h240.6912V307.2h66.56l-0.0512 184.6272H957.44v307.2h-258.6112V957.44h-66.4576l-0.0512-158.4128H391.6288V957.44z m-0.0512-224.9728h240.6912v-174.08H391.6288v174.08z m565.8112-174.08h-258.6112v174.08H957.44v-174.08z"/>
<Path Fill="#5D7092" Data="M51.2 51.2h921.6v256H51.2z"/>
<Path Fill="#5D7092" Data="M921.6 0a102.4 102.4 0 0 1 102.4 102.4v819.2a102.4 102.4 0 0 1-102.4 102.4H102.4a102.4 102.4 0 0 1-102.4-102.4V102.4a102.4 102.4 0 0 1 102.4-102.4h819.2z m0 66.56H102.4a35.84 35.84 0 0 0-35.5328 30.976L66.56 102.4v819.2a35.84 35.84 0 0 0 30.976 35.5328L102.4 957.44h819.2a35.84 35.84 0 0 0 35.5328-30.976L957.44 921.6V102.4a35.84 35.84 0 0 0-30.976-35.5328L921.6 66.56z"/>
</Canvas>
</Button>-->
<!--<TextBlock Text="&#xe606;" Style="{StaticResource MyIcon}"/>-->
<TextBlock Text="{Binding MenuName}"
HorizontalAlignment="Center"
TextAlignment="Center"
VerticalAlignment="Center"
IsVisibleChanged="MenuWhenVisibilityChanged"
Visibility="{Binding NotMenuEdit}"
/>
<Button Background="Transparent"
BorderThickness="0"
hc:IconElement.Geometry="{Binding MenuGeometry}"
hc:IconElement.Height="18"
hc:IconElement.Width="18"
/>
<TextBlock Text="{Binding MenuName}"
HorizontalAlignment="Center"
TextAlignment="Center"
VerticalAlignment="Center"
IsVisibleChanged="MenuWhenVisibilityChanged"
Visibility="{Binding NotMenuEdit}"
/>
</StackPanel>
</StackPanel>
</DataTemplate>

View File

@@ -3,21 +3,14 @@ using GeekDesk.Control.Windows;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace GeekDesk.Control.UserControls.PannelCard
{

View File

@@ -15,25 +15,45 @@
MouseDown="DragMove"
>
<Window.Resources>
<Style x:Key="LeftTB" TargetType="TextBlock" BasedOn="{StaticResource TextBlockBaseStyle}">
<Setter Property="Width" Value="80"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontSize" Value="11"/>
</Style>
</Window.Resources>
<Border MouseDown="DragMove">
<Grid MouseDown="DragMove">
<hc:TabControl x:Name="MyTabControl" IsAnimationEnabled="True" SelectionChanged="TabControl_SelectionChanged" ShowContextMenu="True" IsTabFillEnabled="True" Margin="20,30,20,20" Height="350" VerticalAlignment="Top">
<hc:TabItem Tag="System" Header="系统" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource CalendarGeometry}" >
<hc:TabItem Tag="System" IsSelected="True" Header="系统图标" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource CalendarGeometry}" >
<hc:SimplePanel Background="AliceBlue">
<uc:IconPannel IconfontList="{Binding iconListSystem}" IconInfo="{Binding iconInfoSystem}"/>
<!--<hc:UniformSpacingPanel Spacing="10" Margin="0,10,0,-10">
<TextBlock Text="SVG 图标地址:" Style="{StaticResource LeftTB}"/>
<TextBox x:Name="IconUrl1" Text="{Binding Name, Mode=OneWay}" Width="240" FontSize="11"/>
</hc:UniformSpacingPanel>
<hc:UniformSpacingPanel Spacing="10" Margin="0,40,0,-40">
<TextBlock Text="JSON 配置地址:" Style="{StaticResource LeftTB}"/>
<TextBox x:Name="JsonUrl2" Text="{Binding Name, Mode=OneWay}" Width="240" FontSize="11"/>
</hc:UniformSpacingPanel>-->
<uc:IconPannel x:Name="SystemIcon"/>
</hc:SimplePanel>
</hc:TabItem>
<hc:TabItem Tag="Custom" IsSelected="True" Header="自定义" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource CalendarGeometry}">
<hc:TabItem Tag="Custom" Header="自定义图标" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource CalendarGeometry}">
<hc:SimplePanel Background="AliceBlue">
<uc:IconPannel IconfontList="{Binding iconListCustom}" IconInfo="{Binding iconInfoCustom}"/>
<hc:LoadingCircle/>
<uc:IconPannel x:Name="CustomIcon"/>
</hc:SimplePanel>
</hc:TabItem>
</hc:TabControl>
<Button Content="取消" Click="Close_Click" Margin="406,397.5,148,22.5"/>
<Button Content="确定" Click="Confirm_Click" Background="#5BC0DE" Foreground="White" Margin="500.5,397.5,53.5,22.5" RenderTransformOrigin="0.696,0.45"/>
<Button Content="取消" Click="Close_Click" Margin="391,397.5,163,22.5"/>
<Button Content="自定义设置" Click="CustomButton_Click" IsEnabled="False" Name="CustomButton" Background="#5BC0DE" Foreground="White" RenderTransformOrigin="-0.868,0.583" Margin="447,397.5,71,22.5"/>
<Button Content="确定" Click="Confirm_Click" Background="#5BC0DE" Foreground="White" Margin="534,397.5,20,22.5" RenderTransformOrigin="0.696,0.45"/>
</Grid>
</Border>

View File

@@ -1,5 +1,7 @@
using GeekDesk.Util;
using GeekDesk.Control.Other;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -23,14 +25,15 @@ namespace GeekDesk.Control.Windows
{
private static MenuInfo menuInfo;
private DataContextInfo dataContextInfo = new DataContextInfo();
private IconfontWindow(List<IconfontInfo> listInfo, MenuInfo menuInfo)
private static List<IconfontInfo> systemIcons;
private static List<IconfontInfo> customIcons;
private IconfontWindow(List<IconfontInfo> icons, MenuInfo menuInfo)
{
InitializeComponent();
dataContextInfo.iconListSystem = listInfo;
this.DataContext = dataContextInfo;
systemIcons = icons;
this.DataContext = systemIcons;
this.Topmost = true;
IconfontWindow.menuInfo = menuInfo;
InitializeComponent();
}
@@ -55,25 +58,42 @@ namespace GeekDesk.Control.Windows
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//this.DataContext = listInfo;
TabItem ti = this.MyTabControl.SelectedItem as TabItem;
switch (ti.Tag.ToString())
{
case "Custom":
CustomButton.IsEnabled = true;
this.DataContext = customIcons;
break;
default:
if (CustomButton != null)
{
CustomButton.IsEnabled = false;
}
this.DataContext = systemIcons;
break;
}
}
private void Confirm_Click(object sender, RoutedEventArgs e)
{
string tag = (MyTabControl.SelectedContent as TabItem).Tag.ToString();
switch (tag)
TabItem ti = this.MyTabControl.SelectedItem as TabItem;
int index;
switch (ti.Tag.ToString())
{
case "Custom":
if (dataContextInfo.iconInfoCustom != null)
index = this.CustomIcon.IconListBox.SelectedIndex;
if (index != -1)
{
menuInfo.MenuGeometry = dataContextInfo.iconInfoCustom.Text;
menuInfo.MenuGeometry = customIcons[index].Text;
}
break;
default:
if (dataContextInfo.iconInfoSystem != null)
index = this.SystemIcon.IconListBox.SelectedIndex;
if (index != -1)
{
menuInfo.MenuGeometry = dataContextInfo.iconInfoSystem.Text;
menuInfo.MenuGeometry = systemIcons[index].Text;
}
break;
}
@@ -91,13 +111,8 @@ namespace GeekDesk.Control.Windows
window.Show();
}
private class DataContextInfo
private void CustomButton_Click(object sender, RoutedEventArgs e)
{
public List<IconfontInfo> iconListSystem;
public List<IconfontInfo> iconListCustom;
public IconfontInfo iconInfoSystem;
public IconfontInfo iconInfoCustom;
}

View File

@@ -113,6 +113,9 @@
<Compile Include="Control\Other\BacklogNotificatin.xaml.cs">
<DependentUpon>BacklogNotificatin.xaml</DependentUpon>
</Compile>
<Compile Include="Control\Other\CustomIconUrlDialog.xaml.cs">
<DependentUpon>CustomIconUrlDialog.xaml</DependentUpon>
</Compile>
<Compile Include="Control\UserControls\Backlog\BacklogControl.xaml.cs">
<DependentUpon>BacklogControl.xaml</DependentUpon>
</Compile>
@@ -167,6 +170,7 @@
<Compile Include="Util\DragAdorner.cs" />
<Compile Include="Util\FileIcon.cs" />
<Compile Include="Util\HotKey.cs" />
<Compile Include="Util\HttpUtil.cs" />
<Compile Include="Util\ImageUtil.cs" />
<Compile Include="Util\ListViewDragDropManager.cs" />
<Compile Include="Converts\MenuWidthConvert.cs" />
@@ -185,6 +189,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Control\Other\CustomIconUrlDialog.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Control\UserControls\Backlog\BacklogControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -257,6 +265,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Themes\Generic.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">

View File

@@ -79,9 +79,6 @@ namespace GeekDesk
{
HandyControl.Controls.Growl.WarningGlobal("启动快捷键已被其它程序占用(" + appData.AppConfig.HotkeyStr + ")!");
}
//AeroGlassHelper.ExtendGlass(this);
//AeroGlassHelper.ExtendGlass(BBB, (int)this.Margin.Left, (int)this.Margin.Right, (int)this.Margin.Top, (int)this.Margin.Bottom);
}

7
Themes/Generic.xaml Normal file
View File

@@ -0,0 +1,7 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:GeekDesk.Control.Other">
</ResourceDictionary>

29
Util/HttpUtil.cs Normal file
View File

@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
namespace GeekDesk.Util
{
public class HttpUtil
{
#region Get请求
public string Get(string url)
{
//创建Web访问对 象
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
//通过Web访问对象获取响应内容
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
//通过响应内容流创建StreamReader对象因为StreamReader更高级更快
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string returnStr = reader.ReadToEnd();//利用StreamReader就可以从响应内容从头读到尾
reader.Close();
myResponse.Close();
return returnStr;
}
#endregion
}
}

View File

@@ -4,7 +4,6 @@ using GeekDesk.Util;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media.Imaging;
@@ -38,11 +37,38 @@ namespace GeekDesk.ViewModel
private int pannelCornerRadius = 4; //面板圆角 默认4
[field: NonSerialized]
private ObservableCollection<IconInfo> selectedMenuIcons;
private string hotkeyStr = "Ctrl + Q";
private HotkeyModifiers hotkeyModifiers = HotkeyModifiers.MOD_CONTROL;
private Key hotkey = Key.Q;
private string hotkeyStr = "Ctrl + Q"; //默认启动面板快捷键
private HotkeyModifiers hotkeyModifiers = HotkeyModifiers.MOD_CONTROL; //默认启动面板快捷键
private Key hotkey = Key.Q; //默认启动面板快捷键
private string customIconUrl; //自定义图标url
private string customIconJsonUrl; //自定义图标json信息url
#region GetSet
public string CustomIconUrl
{
get
{
return customIconUrl;
}
set
{
customIconUrl = value;
OnPropertyChanged("CustomIconUrl");
}
}
public string CustomIconJsonUrl
{
get
{
return customIconJsonUrl;
}
set
{
customIconJsonUrl = value;
OnPropertyChanged("CustomIconJsonUrl");
}
}
public Key Hotkey
{
get