Files
GeekDesk/ViewModel/MenuInfo.cs

174 lines
4.1 KiB
C#
Raw Normal View History

2021-07-13 17:29:33 +08:00
using GeekDesk.Constant;
using GeekDesk.Util;
2022-01-20 15:47:40 +08:00
using Newtonsoft.Json;
2021-05-20 17:33:49 +08:00
using System;
2022-01-20 15:47:40 +08:00
using System.Collections.Generic;
2021-05-12 10:00:12 +08:00
using System.Collections.ObjectModel;
2021-05-08 17:27:41 +08:00
using System.ComponentModel;
using System.Windows;
namespace GeekDesk.ViewModel
{
[Serializable]
2021-05-14 16:48:26 +08:00
public class MenuInfo : INotifyPropertyChanged
2021-05-08 17:27:41 +08:00
{
2022-01-20 15:47:40 +08:00
2021-05-08 17:27:41 +08:00
private string menuName;
private string menuId;
2021-05-19 17:31:28 +08:00
private Visibility menuEdit = Visibility.Collapsed;
private Visibility notMenuEdit = Visibility.Visible;
2022-01-20 15:47:40 +08:00
private bool isEdit = false;
private string menuGeometry; //菜单几何图标
private string geometryColor; //几何图标颜色
2021-05-12 10:00:12 +08:00
private ObservableCollection<IconInfo> iconList = new ObservableCollection<IconInfo>();
2021-05-08 17:27:41 +08:00
2022-01-20 15:47:40 +08:00
[field: NonSerializedAttribute()]
private static string[] NO_WRITE_ARR = new string[] { "IsEdit"};
2022-01-20 15:47:40 +08:00
2022-01-20 15:47:40 +08:00
public bool IsEdit
{
get
{
return isEdit;
}
set
{
isEdit = value;
OnPropertyChanged("IsEdit");
}
}
public string MenuGeometry
{
get
{
2021-07-13 17:29:33 +08:00
if (menuGeometry == null)
{
return Constants.DEFAULT_MENU_GEOMETRY;
}
return menuGeometry;
}
set
{
menuGeometry = value;
OnPropertyChanged("MenuGeometry");
}
}
public string GeometryColor
{
get
{
2021-07-13 17:29:33 +08:00
if (geometryColor == null)
{
return Constants.DEFAULT_MENU_GEOMETRY_COLOR;
}
return geometryColor;
}
set
{
geometryColor = value;
OnPropertyChanged("GeometryColor");
}
}
2021-05-08 17:27:41 +08:00
public string MenuName
{
get
{
return menuName;
}
set
{
menuName = value;
2022-01-20 15:47:40 +08:00
OnPropertyChanged("MenuName");
2021-05-08 17:27:41 +08:00
}
}
public string MenuId
{
get
{
return menuId;
}
set
{
menuId = value;
OnPropertyChanged("MenuId");
}
}
2021-05-19 17:31:28 +08:00
public Visibility MenuEdit
2021-05-08 17:27:41 +08:00
{
get
{
return menuEdit;
}
set
{
menuEdit = value;
2021-05-19 17:31:28 +08:00
if (menuEdit == Visibility.Visible)
2021-05-08 17:27:41 +08:00
{
2022-01-20 15:47:40 +08:00
IsEdit = true;
2021-05-19 17:31:28 +08:00
NotMenuEdit = Visibility.Collapsed;
2022-01-20 15:47:40 +08:00
}
else
2021-05-08 17:27:41 +08:00
{
2022-01-20 15:47:40 +08:00
IsEdit = false;
2021-05-19 17:31:28 +08:00
NotMenuEdit = Visibility.Visible;
2021-05-08 17:27:41 +08:00
}
OnPropertyChanged("MenuEdit");
}
}
2021-05-19 17:31:28 +08:00
public Visibility NotMenuEdit
2021-05-08 17:27:41 +08:00
{
get
{
return notMenuEdit;
}
set
{
notMenuEdit = value;
OnPropertyChanged("NotMenuEdit");
}
}
2021-05-12 10:00:12 +08:00
public ObservableCollection<IconInfo> IconList
{
get
{
return iconList;
}
set
{
iconList = value;
OnPropertyChanged("IconList");
}
}
2022-01-20 15:47:40 +08:00
public override String ToString()
{
return JsonConvert.SerializeObject(this);
}
2021-05-12 10:00:12 +08:00
[field: NonSerializedAttribute()]
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
2022-01-22 14:20:04 +08:00
foreach (string field in NO_WRITE_ARR)
2022-01-20 15:47:40 +08:00
{
if (field.Equals(propertyName))
{
return;
}
}
2021-05-20 17:33:49 +08:00
CommonCode.SaveAppData(MainWindow.appData);
2021-05-12 10:00:12 +08:00
}
2021-05-08 17:27:41 +08:00
}
2022-01-20 15:47:40 +08:00
}