Files
GeekDesk/Control/Windows/IconfontWindow.xaml.cs

232 lines
7.1 KiB
C#
Raw Permalink Normal View History

2021-07-12 17:28:57 +08:00
using GeekDesk.Control.Other;
2021-12-20 09:39:27 +08:00
using GeekDesk.Interface;
2021-07-12 17:28:57 +08:00
using GeekDesk.Util;
2021-07-07 17:28:29 +08:00
using GeekDesk.ViewModel;
2021-07-12 17:28:57 +08:00
2021-07-07 17:28:29 +08:00
using System;
using System.Collections.Generic;
2021-07-13 15:24:05 +08:00
using System.ComponentModel;
2021-07-07 17:28:29 +08:00
using System.Windows;
using System.Windows.Controls;
2021-07-13 15:24:05 +08:00
2021-07-07 17:28:29 +08:00
using System.Windows.Input;
2021-07-29 17:04:36 +08:00
using static GeekDesk.Util.ShowWindowFollowMouse;
2021-07-07 17:28:29 +08:00
namespace GeekDesk.Control.Windows
{
/// <summary>
/// IconfontWindow.xaml 的交互逻辑
/// </summary>
2021-12-20 09:39:27 +08:00
public partial class IconfontWindow : Window, IWindowCommon
2021-07-07 17:28:29 +08:00
{
2021-07-13 15:24:05 +08:00
private static AppConfig appConfig = MainWindow.appData.AppConfig;
2021-07-07 17:28:29 +08:00
private static MenuInfo menuInfo;
2021-07-12 17:28:57 +08:00
private static List<IconfontInfo> systemIcons;
private static List<IconfontInfo> customIcons;
2021-07-13 15:24:05 +08:00
public static IconfontViewModel vm;
2021-07-12 17:28:57 +08:00
private IconfontWindow(List<IconfontInfo> icons, MenuInfo menuInfo)
2021-07-07 17:28:29 +08:00
{
2022-01-09 15:42:19 +08:00
2021-07-13 15:24:05 +08:00
InitializeComponent();
2021-07-12 17:28:57 +08:00
systemIcons = icons;
this.Topmost = true;
2021-07-07 17:28:29 +08:00
IconfontWindow.menuInfo = menuInfo;
2021-07-13 15:24:05 +08:00
vm = new IconfontViewModel
{
Iconfonts = systemIcons
};
this.DataContext = vm;
2021-07-07 17:28:29 +08:00
}
2021-07-09 17:31:44 +08:00
2021-07-07 17:28:29 +08:00
/// <summary>
/// 移动窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DragMove(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
DragMove();
}
}
private void Close_Click(object sender, RoutedEventArgs e)
{
2022-01-09 15:42:19 +08:00
this.DataContext = null;
2021-07-07 17:28:29 +08:00
this.Close();
}
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
2021-07-12 17:28:57 +08:00
TabItem ti = this.MyTabControl.SelectedItem as TabItem;
switch (ti.Tag.ToString())
{
case "Custom":
CustomButton.IsEnabled = true;
2021-07-13 15:24:05 +08:00
if (StringUtil.IsEmpty(appConfig.CustomIconUrl) || StringUtil.IsEmpty(appConfig.CustomIconJsonUrl))
{
LoadingEle.Visibility = Visibility.Visible;
CustomIcon.Visibility = Visibility.Collapsed;
2021-12-20 09:39:27 +08:00
HandyControl.Controls.Dialog.Show(new CustomIconUrlDialog(appConfig), "IconUrlDialog");
2022-01-09 15:42:19 +08:00
}
else
2021-07-13 15:24:05 +08:00
{
if (customIcons == null)
{
2021-07-13 17:29:33 +08:00
vm.Iconfonts = null;
2021-07-13 15:24:05 +08:00
LoadingOnlineIcon();
2022-01-09 15:42:19 +08:00
}
else
2021-07-13 15:24:05 +08:00
{
vm.Iconfonts = customIcons;
LoadingEle.Visibility = Visibility.Collapsed;
CustomIcon.Visibility = Visibility.Visible;
}
}
2021-07-12 17:28:57 +08:00
break;
default:
if (CustomButton != null)
{
CustomButton.IsEnabled = false;
}
2021-07-13 15:24:05 +08:00
if (vm != null)
{
vm.Iconfonts = systemIcons;
}
2021-07-12 17:28:57 +08:00
break;
}
2021-07-07 17:28:29 +08:00
}
private void Confirm_Click(object sender, RoutedEventArgs e)
{
2021-07-12 17:28:57 +08:00
TabItem ti = this.MyTabControl.SelectedItem as TabItem;
int index;
switch (ti.Tag.ToString())
2021-07-07 17:28:29 +08:00
{
case "Custom":
2021-07-12 17:28:57 +08:00
index = this.CustomIcon.IconListBox.SelectedIndex;
if (index != -1)
2021-07-07 17:28:29 +08:00
{
2021-07-12 17:28:57 +08:00
menuInfo.MenuGeometry = customIcons[index].Text;
2021-07-07 17:28:29 +08:00
}
break;
default:
2021-07-12 17:28:57 +08:00
index = this.SystemIcon.IconListBox.SelectedIndex;
if (index != -1)
2021-07-07 17:28:29 +08:00
{
2021-07-12 17:28:57 +08:00
menuInfo.MenuGeometry = systemIcons[index].Text;
2021-07-07 17:28:29 +08:00
}
break;
}
2022-01-09 15:42:19 +08:00
this.DataContext = null;
2021-07-07 17:28:29 +08:00
this.Close();
}
private static System.Windows.Window window = null;
public static void Show(List<IconfontInfo> listInfo, MenuInfo menuInfo)
{
if (window == null || !window.Activate())
{
window = new IconfontWindow(listInfo, menuInfo);
}
window.Show();
2021-12-20 09:39:27 +08:00
Keyboard.Focus(window);
ShowWindowFollowMouse.Show(window, MousePosition.LEFT_CENTER, 0, 0, false);
2021-07-07 17:28:29 +08:00
}
2021-07-09 17:31:44 +08:00
2021-07-12 17:28:57 +08:00
private void CustomButton_Click(object sender, RoutedEventArgs e)
2021-07-09 17:31:44 +08:00
{
2022-01-09 15:42:19 +08:00
HandyControl.Controls.Dialog.Show(new CustomIconUrlDialog(appConfig), "IconUrlDialog");
2021-07-13 15:24:05 +08:00
}
private void CheckSettingUrl_TextChanged(object sender, TextChangedEventArgs e)
{
if (CheckSettingUrl.Text == "true")
{
LoadingOnlineIcon();
2022-01-09 15:42:19 +08:00
}
else
2021-07-13 15:24:05 +08:00
{
LoadingEle.IsRunning = true;
CustomIcon.Visibility = Visibility.Collapsed;
}
2021-07-09 17:31:44 +08:00
}
2021-07-13 15:24:05 +08:00
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;
}
2022-01-09 15:42:19 +08:00
catch (Exception e)
2021-07-13 15:24:05 +08:00
{
HandyControl.Controls.Growl.WarningGlobal("加载远程图标异常!");
2022-01-09 15:42:19 +08:00
LogUtil.WriteErrorLog(e, "加载远程图标异常!");
2021-07-13 15:24:05 +08:00
}
}
2021-12-20 09:39:27 +08:00
public void OnKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
2022-01-09 15:42:19 +08:00
this.DataContext = null;
2021-12-20 09:39:27 +08:00
this.Close();
}
}
2021-07-13 15:24:05 +08:00
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));
}
}
2021-07-07 17:28:29 +08:00
}
}