优化代码

This commit is contained in:
liufei
2021-07-19 17:30:34 +08:00
parent cdbdae09c7
commit 4a8ddc4ce9
9 changed files with 69 additions and 29 deletions

File diff suppressed because one or more lines are too long

View File

@@ -66,7 +66,7 @@
KeyUp="HotKeyUp"
Margin="12.967,-7.38,-12.967,0"/>
</hc:UniformSpacingPanel>
<hc:UniformSpacingPanel Spacing="10" Margin="30,229,0,-216.337" Grid.ColumnSpan="4">
<!--<hc:UniformSpacingPanel Spacing="10" Margin="30,229,0,-216.337" Grid.ColumnSpan="4">
<TextBlock Text="新建待办:" Width="55"/>
<hc:TextBox HorizontalAlignment="Left"
Tag="ToDo"
@@ -78,7 +78,7 @@
KeyDown="HotKeyDown"
KeyUp="HotKeyUp"
Margin="12.967,-7.38,-12.967,0"/>
</hc:UniformSpacingPanel>
</hc:UniformSpacingPanel>-->
<StackPanel hc:Growl.GrowlParent="True" hc:Growl.Token="HotKeyGrowl" VerticalAlignment="Top"/>
</hc:SimplePanel>

View File

@@ -20,7 +20,8 @@
<SolidColorBrush Opacity="0"/>
</Setter.Value>
</Setter>
<EventSetter Event="MouseLeftButtonDown" Handler="MenuClick"/>
<EventSetter Event="MouseRightButtonDown" Handler="MenuClick"/>
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
@@ -74,12 +75,13 @@
</ContextMenu>
</hc:Card.ContextMenu>
<WrapPanel Orientation="Horizontal">
<ListBox x:Name="menus"
<ListBox x:Name="MenuListBox"
ItemsSource="{Binding MenuList}"
Tag="{Binding AppConfig.MenuCardWidth}"
BorderThickness="0" Foreground="{x:Null}"
SelectedIndex="{Binding AppConfig.SelectedMenuIndex}"
VirtualizingPanel.VirtualizationMode="Recycling"
SelectionChanged="menus_SelectionChanged"
>
<ListBox.Resources>
<ContextMenu x:Key="menuDialog" Width="200">
@@ -108,6 +110,9 @@
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel MouseLeftButtonDown="MenuClick" MouseRightButtonDown="MenuClick" Tag="{Binding}">
<StackPanel.Background>
<SolidColorBrush Color="AliceBlue" Opacity="0.01"/>
</StackPanel.Background>
<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}}"

View File

@@ -25,7 +25,13 @@ namespace GeekDesk.Control.UserControls.PannelCard
public LeftCardControl()
{
InitializeComponent();
if (appData.AppConfig.SelectedMenuIndex >= appData.MenuList.Count || appData.AppConfig.SelectedMenuIndex == -1)
{
appData.AppConfig.SelectedMenuIcons = appData.MenuList[0].IconList;
} else
{
appData.AppConfig.SelectedMenuIcons = appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList;
}
}
@@ -46,7 +52,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
var dragged = menuList[fromS];
menuList.Remove(dragged);
menuList.Insert(to, dragged);
menus.SelectedIndex = to;
MenuListBox.SelectedIndex = to;
MainWindow.appData.MenuList = menuList;
}
);
@@ -73,14 +79,14 @@ namespace GeekDesk.Control.UserControls.PannelCard
TextBlock tb = sender as TextBlock;
if (tb.Visibility == Visibility.Collapsed)
{
if (menus.SelectedIndex != -1)
if (MenuListBox.SelectedIndex != -1)
{
menuSelectIndexTemp = menus.SelectedIndex;
menus.SelectedIndex = -1;
menuSelectIndexTemp = MenuListBox.SelectedIndex;
MenuListBox.SelectedIndex = -1;
}
else
{
menus.SelectedIndex = menuSelectIndexTemp;
MenuListBox.SelectedIndex = menuSelectIndexTemp;
}
}
}
@@ -94,9 +100,9 @@ namespace GeekDesk.Control.UserControls.PannelCard
{
MenuInfo info = new MenuInfo() { MenuEdit = Visibility.Collapsed, MenuId = System.Guid.NewGuid().ToString(), MenuName = "NewMenu" };
appData.MenuList.Add(info);
menus.Items.Refresh();
menus.SelectedIndex = appData.MenuList.Count - 1;
appData.AppConfig.SelectedMenuIndex = menus.SelectedIndex;
MenuListBox.Items.Refresh();
MenuListBox.SelectedIndex = appData.MenuList.Count - 1;
appData.AppConfig.SelectedMenuIndex = MenuListBox.SelectedIndex;
appData.AppConfig.SelectedMenuIcons = info.IconList;
}
@@ -124,14 +130,20 @@ namespace GeekDesk.Control.UserControls.PannelCard
//如果删除以后没有菜单的话 先创建一个
CreateMenu(null, null);
}
appData.MenuList.Remove(menuInfo);
if (menus.SelectedIndex == -1)
int index = appData.MenuList.IndexOf(menuInfo);
if(index == 0)
{
// 选中下一个菜单
menus.SelectedIndex = 0;
appData.AppConfig.SelectedMenuIndex = menus.SelectedIndex;
appData.AppConfig.SelectedMenuIcons = appData.MenuList[0].IconList;
index = 0;
} else
{
index = index - 1;
}
appData.MenuList.Remove(menuInfo);
// 选中下一个菜单
MenuListBox.SelectedIndex = index;
appData.AppConfig.SelectedMenuIndex = MenuListBox.SelectedIndex;
appData.AppConfig.SelectedMenuIcons = appData.MenuList[index].IconList;
}
/// <summary>
@@ -189,5 +201,17 @@ namespace GeekDesk.Control.UserControls.PannelCard
MenuInfo menuInfo = ((MenuItem)sender).Tag as MenuInfo;
IconfontWindow.Show(SvgToGeometry.GetIconfonts(), menuInfo);
}
private void menus_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//设置对应菜单的图标列表
if (MenuListBox.SelectedIndex == -1)
{
appData.AppConfig.SelectedMenuIcons = appData.MenuList[appData.MenuList.Count-1].IconList;
} else
{
appData.AppConfig.SelectedMenuIcons = appData.MenuList[MenuListBox.SelectedIndex].IconList;
}
}
}
}

View File

@@ -173,7 +173,7 @@ namespace GeekDesk.Control.UserControls.PannelCard
{
string path = (string)obj;
string base64 = ImageUtil.FileImageToBase64(path, ImageFormat.Png);
string base64 = ImageUtil.FileImageToBase64(path, ImageFormat.Jpeg);
IconInfo iconInfo = new IconInfo
{

View File

@@ -29,12 +29,12 @@
<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:TabItem Tag="System" IsSelected="True" Header="系统图标" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource SystemIcon}" >
<hc:SimplePanel Background="AliceBlue">
<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:TabItem Tag="Custom" Header="自定义图标" hc:IconElement.Height="16" hc:IconElement.Width="16" hc:IconElement.Geometry="{StaticResource CustomIcon}">
<hc:SimplePanel Background="AliceBlue">
<uc:IconPannel x:Name="CustomIcon"/>
<hc:LoadingCircle x:Name="LoadingEle"/>

View File

@@ -125,10 +125,10 @@ namespace GeekDesk.Control.Windows
if (window == null || !window.Activate())
{
window = new ToDoInfoWindow();
window.Show();
}
windowType = NEW_TODO;
window.Show();
window.Visibility = Visibility.Visible;
}
@@ -137,8 +137,9 @@ namespace GeekDesk.Control.Windows
if (window == null || !window.Activate())
{
window = new ToDoInfoWindow();
window.Show();
}
window.Visibility = Visibility.Collapsed;
windowType = NEW_TODO;
return window;
}

View File

@@ -30,7 +30,8 @@ namespace GeekDesk
{
public static AppData appData = CommonCode.GetAppDataByFile();
public static ToDoInfoWindow toDoInfoWindow = (ToDoInfoWindow)ToDoInfoWindow.GetThis();
//public static ToDoInfoWindow toDoInfoWindow = (ToDoInfoWindow)ToDoInfoWindow.GetThis();
public static ToDoInfoWindow toDoInfoWindow;
public static int hotKeyId = -1;
public static int toDoHotKeyId = -1;
public static MainWindow mainWindow;
@@ -69,7 +70,7 @@ namespace GeekDesk
ShowApp();
}
RegisterHotKey(true);
RegisterCreateToDoHotKey(true);
//RegisterCreateToDoHotKey(true);
}
/// <summary>
@@ -126,7 +127,7 @@ namespace GeekDesk
if (appData.AppConfig.ToDoHotkeyModifiers!=0)
{
//加载完毕注册热键
toDoHotKeyId = Hotkey.Regist(new WindowInteropHelper(toDoInfoWindow).Handle, appData.AppConfig.ToDoHotkeyModifiers, appData.AppConfig.ToDoHotkey, () =>
toDoHotKeyId = Hotkey.Regist(new WindowInteropHelper(MainWindow.mainWindow).Handle, appData.AppConfig.ToDoHotkeyModifiers, appData.AppConfig.ToDoHotkey, () =>
{
if (MotionControl.hotkeyFinished)
{

View File

@@ -24,5 +24,14 @@
M512 64C262.4 64 64 262.4 64 512s198.4 448 448 448 448-198.4 448-448S761.6 64 512 64z m256 544h-256c-19.2 0-32-12.8-32-32V256c0-19.2 12.8-32 32-32s32 12.8 32 32v288h224c19.2 0 32 12.8 32 32s-12.8 32-32 32z
</Geometry>
<Geometry x:Key="SystemIcon">
M768 665.6H256a102.4 102.4 0 0 1-102.4-102.4V256A102.4 102.4 0 0 1 256 153.6h512A102.4 102.4 0 0 1 870.4 256v307.2A102.4 102.4 0 0 1 768 665.6zM409.6 460.8a51.2 51.2 0 0 0-51.2 51.2 51.2 51.2 0 0 0 51.2 51.2h204.8a51.2 51.2 0 0 0 51.2-51.2 51.2 51.2 0 0 0-51.2-51.2zM307.2 768h409.6q51.2 0 51.2 51.2t-51.2 51.2H307.2q-51.2 0-51.2-51.2t51.2-51.2z
M460.8 819.251v-153.6q0-51.2 51.2-51.2t51.2 51.2v153.6q0 51.2-51.2 51.2t-51.2-51.2z
</Geometry>
<Geometry x:Key="CustomIcon">
M760.844227 482.947384l227.272092-215.929406a116.216042 116.216042 0 0 0 0-164.329483l-56.713429-56.713429a116.216042 116.216042 0 0 0-162.144622-2.068645l-221.995883 210.792657-215.673731-230.363439-1.766484-1.836213A75.958805 75.958805 0 0 0 222.392061 22.057805L60.526358 183.923508a75.912319 75.912319 0 0 0-1.30162 105.593896l212.442925 226.946687-200.867807 190.803497a116.216042 116.216042 0 0 0-33.098329 57.73613L3.7432 909.971609a76.888533 76.888533 0 0 0 96.529044 91.276079l139.738169-41.163722a116.843609 116.843609 0 0 0 47.2302-27.217797l198.032135-188.153772 238.521805 254.838537 1.766484 1.836213a75.958805 75.958805 0 0 0 107.430109 0.441621l161.865703-161.865703a75.912319 75.912319 0 0 0 1.30162-105.593896zM283.475213 833.129562L177.90456 727.558909a36.886972 36.886972 0 0 0-11.482145-7.600529L690.74271 221.833181l110.428483 110.428483a34.399948 34.399948 0 0 0 5.578371 3.718913z m537.452708-734.95025a41.233452 41.233452 0 0 1 57.550184 0.743783l56.713428 56.713428a41.419397 41.419397 0 0 1-0.743783 59.03775l-75.610156 71.658811a35.492379 35.492379 0 0 0-4.648642-7.158908l-109.196593-109.057134zM247.169321 380.630781a37.189133 37.189133 0 0 0 25.892934-10.877822l56.225322-56.225321a37.491295 37.491295 0 0 0-52.994516-52.994515l-56.225321 56.225321a37.189133 37.189133 0 0 0-10.459443 23.731316l-95.62256-102.270117c-0.604323-0.604323-0.604323-1.208647-0.418378-1.348106l161.865704-161.91219c0.139459-0.139459 0.790269-0.139459 1.464322 0.488107l215.999136 230.758573-166.862994 158.518682zM79.074438 929.309958a1.8827 1.8827 0 0 1-2.324321-2.324321l33.958328-144.96789a41.558857 41.558857 0 0 1 6.22918-13.457818 37.189133 37.189133 0 0 0 7.902691 11.877279l103.432277 103.432278a41.070749 41.070749 0 0 1-9.297283 4.160534l-139.784656 41.186965z m700.922193 19.524295c-0.139459 0.139459-0.790269 0.139459-1.464322-0.488107l-147.12951-157.170575a36.58481 36.58481 0 0 0 16.502678-9.041608l56.225321-56.225322a37.491295 37.491295 0 1 0-52.994515-52.994515l-56.225321 56.225321a37.189133 37.189133 0 0 0-8.553501 13.945925l-46.742092-49.972898L706.478362 534.593793 941.443956 785.620444c0.557837 0.604323 0.557837 1.208647 0.418378 1.348106l-161.819217 161.865703z
</Geometry>
</ResourceDictionary>