Skip to content
This repository has been archived by the owner on May 29, 2023. It is now read-only.

Commit

Permalink
v4.4.4 功能更新+Bug修复
Browse files Browse the repository at this point in the history
1、新增删除便签提示功能,防止误删。
2、修复删除便签后仍在定时检测该便签窗体是否隐藏的问题。
  • Loading branch information
li-zheng-hao committed Jul 10, 2021
1 parent f79c61c commit 6486c55
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 22 deletions.
25 changes: 25 additions & 0 deletions StikyNotes/Converter/DeleteWindowMessageConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace StikyNotes.Converter
{
public class DeleteWindowMessageConverter: IMultiValueConverter
{

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
return values.Clone();
}

public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
return null;
}
}
}
24 changes: 24 additions & 0 deletions StikyNotes/Converter/boolToVisibilityConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace StikyNotes.Converter
{
public class BoolToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return (bool)value == true ? Visibility.Visible : Visibility.Collapsed;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}
2 changes: 1 addition & 1 deletion StikyNotes/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion StikyNotes/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Version" xml:space="preserve">
<value>v4.3.4</value>
<value>v4.4.4</value>
<comment>程序版本</comment>
</data>
</root>
2 changes: 2 additions & 0 deletions StikyNotes/StikyNotes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Converter\boolToVisibilityConverter.cs" />
<Compile Include="Converter\DeleteWindowMessageConverter.cs" />
<Compile Include="Converter\ShowAllHotKeyConverter.cs" />
<Compile Include="Converter\ThemeConverter.cs" />
<Compile Include="Data\ConstData.cs" />
Expand Down
1 change: 1 addition & 0 deletions StikyNotes/Style/Themes/Blue.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<SolidColorBrush x:Key="ForgroundBrush" Color="{StaticResource ForgroundColorBlue}" />
<SolidColorBrush x:Key="ForgroundBrush100" Color="{StaticResource ForgroundColorBlue100}" />
<SolidColorBrush x:Key="BackgroundBrush" Color="{StaticResource BackgroundColorBlue}" />
<SolidColorBrush x:Key="BackgroundBrush100" Color="{StaticResource BackgroundColorBlue}" />
</ResourceDictionary>
1 change: 1 addition & 0 deletions StikyNotes/Utils/WindowHide.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ point.X < (this.win.Left + this.win.Width))
catch (Exception ex)
{
Logger.Log("WindowHide.cs").Error("隐藏窗体模块出现异常 " + ex.Message);
timer.Stop();
}

}
Expand Down
96 changes: 92 additions & 4 deletions StikyNotes/View/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:utils="clr-namespace:StikyNotes.Utils"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:converter="clr-namespace:StikyNotes.Converter"
x:Name="loaded"
Width="{Binding Datas.WindowsWidth, Mode=TwoWay}"
Height="{Binding Datas.WindowsHeight, Mode=TwoWay}"
Expand Down Expand Up @@ -42,7 +44,10 @@
</i:EventTrigger>

</i:Interaction.Triggers>

<Window.Resources>
<converter:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
<converter:DeleteWindowMessageConverter x:Key="DeleteWindowMessageConverter"></converter:DeleteWindowMessageConverter>
</Window.Resources>
<!--<i:Interaction.Behaviors>-->
<!--<utils:WndHideBehavior />-->
<!--</i:Interaction.Behaviors>-->
Expand Down Expand Up @@ -114,12 +119,14 @@
HorizontalAlignment="Right"
PlacementMode="BottomAndAlignCentres">

<StackPanel>
<StackPanel >
<Button
Padding="10"
Name="SettingButton"
Command="{Binding OpenSettingCommand}"
Content="设置" />
<Button
Padding="10"
Name="AboutButton"
Command="{Binding OpenAboutCommand}"
Content="关于" />
Expand All @@ -132,10 +139,10 @@
<!-- 删除按钮 -->
<Button
Name="DeleteButton"
Tag="DeleteButton"
Grid.Column="4"
HorizontalAlignment="Right"
Command="{Binding DeletePaWindowCommand}"
CommandParameter="{Binding ElementName=loaded}"
Command="{Binding ShowDeleteWindowCommand}"
Style="{StaticResource Button_Menu}"
ToolTip="删除此便签">

Expand All @@ -144,7 +151,45 @@
Height="18"
Kind="Delete" />
</Button>
<materialDesign:DialogHost
DialogTheme="Inherit">
<materialDesign:DialogHost.DialogContent>
<StackPanel Margin="16">
<TextBlock Text="Add a new fruit."/>

<TextBox
Margin="0 8 0 0"
HorizontalAlignment="Stretch"
x:Name="FruitTextBox"/>

<StackPanel
Orientation="Horizontal"
HorizontalAlignment="Right">
<Button
Style="{StaticResource MaterialDesignFlatButton}"
IsDefault="True"
Margin="0 8 8 0"
Content="ACCEPT"
Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}">
<Button.CommandParameter>
<system:Boolean>True</system:Boolean>
</Button.CommandParameter>
</Button>

<Button
Style="{StaticResource MaterialDesignFlatButton}"
IsCancel="True"
Margin="0 8 8 0"
Content="CANCEL"
Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}">
<Button.CommandParameter>
<system:Boolean>False</system:Boolean>
</Button.CommandParameter>
</Button>
</StackPanel>
</StackPanel>
</materialDesign:DialogHost.DialogContent>
</materialDesign:DialogHost>
</StackPanel>
</Grid>

Expand Down Expand Up @@ -241,5 +286,48 @@
</materialDesign:SnackbarMessage>
</materialDesign:Snackbar>

<Grid Name="CheckDeleteWindow" Visibility="{Binding IsDeleteWindowShowed,Converter={StaticResource BoolToVisibilityConverter}}" Grid.Row="0" ZIndex="100" Grid.RowSpan="3" Background="#7F868686">
<Grid Margin="10 100 10 100" Background="{StaticResource BackgroundBrush}">
<Grid.Effect>
<DropShadowEffect
BlurRadius="5"
ShadowDepth="-3"
Color="Gray" />
</Grid.Effect>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Label FontSize="22" Grid.ColumnSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" FontFamily="/StikyNotes;component/Resources/Fonts/#Lato">是否删除当前便签?</Label>
<Button Name="DeleteWindowButton" Grid.Row="1" Grid.Column="0"
Command="{Binding DeleteWindowCommand}"
Margin="20 5 20 5" Background="{StaticResource AccentColorBrush2}">
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource DeleteWindowMessageConverter}">
<Binding Path="Name" RelativeSource="{RelativeSource Self}" ></Binding>
<Binding ElementName="loaded"/>
</MultiBinding>
</Button.CommandParameter>
确定
</Button>
<Button Name="CancelDeleteWindowButton"
Command="{Binding DeleteWindowCommand}"

Grid.Row="1" Grid.Column="1" Background="AliceBlue" Margin="20 5 20 5">
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource DeleteWindowMessageConverter}">
<Binding Path="Name" RelativeSource="{RelativeSource Self}"></Binding>
<Binding ElementName="loaded"/>
</MultiBinding>
</Button.CommandParameter>
取消
</Button>
</Grid>

</Grid>
</Grid>
</Window>
1 change: 1 addition & 0 deletions StikyNotes/View/SettingWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
所有窗体置顶
</Label>
<Controls:ToggleSwitch

Name="IsTopMostBtn"
Margin="3"
CheckChangedCommand="{Binding IsTopMostChangedCommand}"
Expand Down
56 changes: 40 additions & 16 deletions StikyNotes/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public class MainViewModel : ViewModelBase
/// </summary>
DispatcherTimer timer;

public bool IsDeleteWindowShowed { get; set; } = false;

public ProgramData ProgramData { get; set; }
#region 命令
public RelayCommand NewWindowCommand { get; private set; }
Expand All @@ -44,7 +46,10 @@ public class MainViewModel : ViewModelBase
public RelayCommand AddFontSizeCommand { get; private set; }
public RelayCommand ReduceFontSizeCommand { get; private set; }
public RelayCommand<object> MoveWindowCommand { get; private set; }
public RelayCommand<MainWindow> DeletePaWindowCommand { get; private set; }
public RelayCommand ShowDeleteWindowCommand { get; private set; }

public RelayCommand<object> DeleteWindowCommand { get; private set; }

public RelayCommand OnContentRenderedCommand { get; private set; }
public RelayCommand<MainWindow> OnSourceInitializedCommand { get; private set; }
public RelayCommand<object> ChangeIsFocusedPropertyCommand { get; set; }
Expand Down Expand Up @@ -76,7 +81,8 @@ public MainViewModel()
NewWindowCommand = new RelayCommand(NewWindowMethod);
OpenSettingCommand = new RelayCommand(OpenSettingMethod);
OpenAboutCommand = new RelayCommand(OpenAboutMethod);
DeletePaWindowCommand = new RelayCommand<MainWindow>(DeleteWindowMethod);
ShowDeleteWindowCommand = new RelayCommand(ShowDeleteWindowMethod);
DeleteWindowCommand=new RelayCommand<object>(DeleteWindowMethod);
MoveWindowCommand = new RelayCommand<object>(MoveWindowMethod);
AddFontSizeCommand = new RelayCommand(AddFontSizeMethod);
ReduceFontSizeCommand = new RelayCommand(ReduceFontSizeMethod);
Expand All @@ -85,6 +91,35 @@ public MainViewModel()
ChangeIsFocusedPropertyCommand = new RelayCommand<object>(ChangeIsFocusedPropertyMethod);
ProgramData = ProgramData.Instance;
}

private void DeleteWindowMethod(object parameter)
{
var values = (object[])parameter;
var btnName= (string)values[0];
MainWindow win = (MainWindow)values[1];
if (btnName == "DeleteWindowButton")
{
// 删除窗体
IsDeleteWindowShowed = false;
string documentFileName = string.Empty;
if (WindowsManager.Instance.Windows.Contains(win))
{
WindowsManager.Instance.Windows.Remove(win);
ProgramData.Instance.Datas.Remove(Datas);
documentFileName = Datas.DocumentFileName;
}
win.Close();
if (documentFileName != string.Empty)
{
RemoveDocumentFile(documentFileName);
}
}
else
{
IsDeleteWindowShowed = false;
}
}

/// <summary>
/// 修改IsFocused属性
/// </summary>
Expand Down Expand Up @@ -329,21 +364,10 @@ void NewWindowMethod()
/// <summary>
/// 删除窗体
/// </summary>
void DeleteWindowMethod(MainWindow obj)
void ShowDeleteWindowMethod()
{
var win = obj as MainWindow;
string documentFileName = string.Empty;
if (WindowsManager.Instance.Windows.Contains(win))
{
WindowsManager.Instance.Windows.Remove(win);
ProgramData.Instance.Datas.Remove(Datas);
documentFileName = Datas.DocumentFileName;
}
win.Close();
if (documentFileName != string.Empty)
{
RemoveDocumentFile(documentFileName);
}
IsDeleteWindowShowed = true;

}
/// <summary>
/// 删除已经不需要的文档数据
Expand Down

0 comments on commit 6486c55

Please sign in to comment.