远程图标功能 完成

This commit is contained in:
liufei
2021-07-13 15:24:05 +08:00
parent 68d21d039c
commit edb7efc7fb
12 changed files with 183 additions and 88 deletions

View File

@@ -21,22 +21,30 @@
<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"/>
<WrapPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="SVG 图标地址:" Style="{StaticResource LeftTB}"/>
<TextBlock Text="*" Foreground="Red"/>
</WrapPanel>
<TextBox x:Name="IconUrl" Text="{Binding CustomIconUrl, 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"/>
<WrapPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="JSON 配置地址:" Style="{StaticResource LeftTB}"/>
<TextBlock Text="*" Foreground="Red"/>
</WrapPanel>
<TextBox x:Name="JsonUrl" Text="{Binding CustomIconJsonUrl, Mode=OneWay}" Width="240" FontSize="14"/>
</hc:UniformSpacingPanel>
<!--<hc:UniformSpacingPanel Spacing="10" Margin="246.206,124.551,-246.206,-124.551">
<Button Content="取消" Click=""
<TextBlock Text="注: 需配置正确的url方可加载远程图标!" Foreground="Red" Margin="10,95,-10,-92" />
<hc:UniformSpacingPanel Spacing="10" Margin="246.206,124.551,-246.206,-124.551">
<Button Content="取消" Command="hc:ControlCommands.Close"
/>
<Button Content="保存" Click=""
<Button Content="保存" Click="Confirm_Click"
Command="hc:ControlCommands.Close"
Background="#5BC0DE"
Foreground="White"/>
</hc:UniformSpacingPanel>-->
</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>

View File

@@ -1,4 +1,5 @@
using GeekDesk.Util;
using GeekDesk.Control.Windows;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using Microsoft.Win32;
using System;
@@ -17,8 +18,8 @@ namespace GeekDesk.Control.Other
public CustomIconUrlDialog(AppConfig appConfig)
{
this.DataContext = appConfig;
InitializeComponent();
this.DataContext = appConfig;
}
public CustomIconUrlDialog()
@@ -26,5 +27,18 @@ namespace GeekDesk.Control.Other
InitializeComponent();
}
private void Confirm_Click(object sender, RoutedEventArgs e)
{
AppConfig appConfig = this.DataContext as AppConfig;
appConfig.CustomIconJsonUrl = JsonUrl.Text.Trim();
appConfig.CustomIconUrl = IconUrl.Text.Trim();
if (!StringUtil.IsEmpty(IconUrl.Text) && !StringUtil.IsEmpty(JsonUrl.Text))
{
IconfontWindow.vm.IsSettingUrl = "true";
} else
{
IconfontWindow.vm.IsSettingUrl = "false";
}
}
}
}

View File

@@ -8,7 +8,7 @@
mc:Ignorable="d"
>
<WrapPanel HorizontalAlignment="Center" VerticalAlignment="Top">
<ListBox x:Name="IconListBox" ItemsSource="{Binding}" BorderThickness="0" Background="AliceBlue">
<ListBox x:Name="IconListBox" ItemsSource="{Binding Iconfonts}" BorderThickness="0" Background="AliceBlue">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" Background="Transparent"/>
@@ -22,7 +22,7 @@
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Tag="{Binding}" Width="80" Height="80">
<StackPanel Width="80" Height="80">
<Button Background="Transparent"
BorderThickness="0"
IsEnabled="False"

View File

@@ -23,41 +23,8 @@ namespace GeekDesk.Control.UserControls.IconFont
{
public IconPannel()
{
//DataContext = this;
InitializeComponent();
}
public static readonly DependencyProperty IconfontListProperty = DependencyProperty.Register("IconfontList", typeof(List<IconfontInfo>), typeof(IconPannel));
public List<IconfontInfo> IconfontList
{
get
{
return (List<IconfontInfo>)GetValue(IconfontListProperty);
}
set
{
SetValue(IconfontListProperty, true);
}
}
public static readonly DependencyProperty IconInfoProperty = DependencyProperty.Register("IconInfo", typeof(IconfontInfo), typeof(IconPannel));
public IconfontInfo IconInfo
{
get
{
return (IconfontInfo)GetValue(IconInfoProperty);
}
set
{
SetValue(IconInfoProperty, true);
}
}
private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
IconfontInfo info = IconfontList[IconListBox.SelectedIndex];
IconInfo = info;
}
}
}

View File

@@ -27,25 +27,17 @@
<Border MouseDown="DragMove">
<Grid MouseDown="DragMove">
<TextBox x:Name="CheckSettingUrl" Visibility="Collapsed" Text="{Binding IsSettingUrl}" TextChanged="CheckSettingUrl_TextChanged"/>
<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" IsSelected="True" Header="系统图标" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource CalendarGeometry}" >
<hc:SimplePanel Background="AliceBlue">
<!--<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" Header="自定义图标" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource CalendarGeometry}">
<hc:SimplePanel Background="AliceBlue">
<hc:LoadingCircle/>
<uc:IconPannel x:Name="CustomIcon"/>
<hc:LoadingCircle x:Name="LoadingEle"/>
</hc:SimplePanel>
</hc:TabItem>
</hc:TabControl>

View File

@@ -4,17 +4,13 @@ using GeekDesk.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;
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.Imaging;
using System.Windows.Shapes;
namespace GeekDesk.Control.Windows
{
@@ -23,17 +19,24 @@ namespace GeekDesk.Control.Windows
/// </summary>
public partial class IconfontWindow : Window
{
private static AppConfig appConfig = MainWindow.appData.AppConfig;
private static MenuInfo menuInfo;
private static List<IconfontInfo> systemIcons;
private static List<IconfontInfo> customIcons;
public static IconfontViewModel vm;
private IconfontWindow(List<IconfontInfo> icons, MenuInfo menuInfo)
{
InitializeComponent();
systemIcons = icons;
this.DataContext = systemIcons;
this.Topmost = true;
IconfontWindow.menuInfo = menuInfo;
InitializeComponent();
vm = new IconfontViewModel
{
Iconfonts = systemIcons
};
this.DataContext = vm;
}
@@ -64,14 +67,33 @@ namespace GeekDesk.Control.Windows
{
case "Custom":
CustomButton.IsEnabled = true;
this.DataContext = customIcons;
if (StringUtil.IsEmpty(appConfig.CustomIconUrl) || StringUtil.IsEmpty(appConfig.CustomIconJsonUrl))
{
LoadingEle.Visibility = Visibility.Visible;
CustomIcon.Visibility = Visibility.Collapsed;
HandyControl.Controls.Dialog.Show(new CustomIconUrlDialog(appConfig));
} else
{
if (customIcons == null)
{
LoadingOnlineIcon();
} else
{
vm.Iconfonts = customIcons;
LoadingEle.Visibility = Visibility.Collapsed;
CustomIcon.Visibility = Visibility.Visible;
}
}
break;
default:
if (CustomButton != null)
{
CustomButton.IsEnabled = false;
}
this.DataContext = systemIcons;
if (vm != null)
{
vm.Iconfonts = systemIcons;
}
break;
}
}
@@ -113,8 +135,80 @@ namespace GeekDesk.Control.Windows
private void CustomButton_Click(object sender, RoutedEventArgs e)
{
HandyControl.Controls.Dialog.Show(new CustomIconUrlDialog(appConfig));
}
private void CheckSettingUrl_TextChanged(object sender, TextChangedEventArgs e)
{
if (CheckSettingUrl.Text == "true")
{
LoadingOnlineIcon();
} else
{
LoadingEle.IsRunning = true;
CustomIcon.Visibility = Visibility.Collapsed;
}
}
private void LoadingOnlineIcon()
{
try
{
string svgJsStr = HttpUtil.Get(appConfig.CustomIconUrl);
string jsonStr = HttpUtil.Get(appConfig.CustomIconJsonUrl);
List<IconfontInfo> icons = SvgToGeometry.GetIconfonts(svgJsStr, jsonStr);
customIcons = icons;
vm.Iconfonts = customIcons;
LoadingEle.Visibility = Visibility.Collapsed;
CustomIcon.Visibility = Visibility.Visible;
}
catch (Exception)
{
HandyControl.Controls.Growl.WarningGlobal("加载远程图标异常!");
}
}
public class IconfontViewModel : INotifyPropertyChanged
{
private List<IconfontInfo> iconfonts;
private string isSettingUrl;
public List<IconfontInfo> Iconfonts
{
get
{
return iconfonts;
}
set
{
iconfonts = value;
OnPropertyChanged("Iconfonts");
}
}
public string IsSettingUrl
{
get
{
return isSettingUrl;
}
set
{
isSettingUrl = value;
OnPropertyChanged("IsSettingUrl");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}

View File

@@ -177,6 +177,7 @@
<Compile Include="Util\MouseUtil.cs" />
<Compile Include="Util\MouseUtilities.cs" />
<Compile Include="Util\ShellContextMenu.cs" />
<Compile Include="Util\StringUtil.cs" />
<Compile Include="Util\SvgToGeometry.cs" />
<Compile Include="Util\SystemIcon.cs" />
<Compile Include="ViewModel\AppConfig.cs" />
@@ -265,10 +266,6 @@
<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">
@@ -292,9 +289,6 @@
<Resource Include="Fonts\iconfont.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Resource Include="iconfont.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>

View File

@@ -1,7 +0,0 @@
<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>

View File

@@ -11,7 +11,7 @@ namespace GeekDesk.Util
public class HttpUtil
{
#region Get请求
public string Get(string url)
public static string Get(string url)
{
//创建Web访问对 象
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);

22
Util/StringUtil.cs Normal file
View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GeekDesk.Util
{
public class StringUtil
{
public static bool IsEmpty(string str)
{
if (str == null || str.Length == 0 || str.Trim().Length == 0)
{
return true;
}
return false;
}
}
}

View File

@@ -26,6 +26,18 @@ namespace GeekDesk.Util
StreamReader streamReader = new StreamReader(svgStream);
string svgJsStr = streamReader.ReadToEnd();
JObject jo = ReadJson(jsonStream);
return GetIconfonts(svgJsStr, jo);
}
public static List<IconfontInfo> GetIconfonts(string svgJsStr, string jsonStr)
{
return GetIconfonts(svgJsStr, JObject.Parse(jsonStr));
}
public static List<IconfontInfo> GetIconfonts(string svgJsStr, JObject json)
{
svgJsStr = svgJsStr.Substring(svgJsStr.IndexOf("<svg>"),
svgJsStr.Length - (svgJsStr.Length - (svgJsStr.IndexOf("</svg>") + "</svg>".Length)) - svgJsStr.IndexOf("<svg>"));
@@ -34,8 +46,7 @@ namespace GeekDesk.Util
xmlDoc.LoadXml(svgJsStr);
XmlNodeList nodeList = xmlDoc.SelectNodes("/svg/symbol");
JObject jo = ReadJson(jsonStream);
JArray ja = JArray.Parse(jo["glyphs"].ToString());
JArray ja = JArray.Parse(json["glyphs"].ToString());
List<IconfontInfo> listInfo = new List<IconfontInfo>();
for (int i = 0; i < nodeList.Count; i++)

Binary file not shown.