Skip to content

Commit

Permalink
fix crash in reset settings after removing a note window;
Browse files Browse the repository at this point in the history
fix command targeting wrong window;
(WIP) fix numbering bullet not displayed properly;
  • Loading branch information
Carl Chang committed May 10, 2019
1 parent f6fef47 commit cf18343
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 26 deletions.
7 changes: 5 additions & 2 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<MenuItem Header="{StaticResource menu_reset_positions}" Click="TM_ResetPos_Click"/>
<MenuItem Header="{StaticResource menu_exit}" Click="TM_Exit_Click"/>
</ContextMenu>
<local:MarkerPaddingConverter x:Key="MarkerPaddingConverter"/>
</Window.Resources>
<Grid>
<Rectangle x:Name="Rec_BG" Fill="#FFFFF7C5" Margin="10" RadiusX="12" RadiusY="12"
Expand All @@ -33,8 +34,10 @@
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{StaticResource {x:Static SystemColors.HighlightColorKey}}"/>
<Style TargetType="{x:Type List}">
<Setter Property="Margin" Value="0"/>
<Setter Property="Padding" Value="16,0,0,0"/>
<Setter Property="MarkerOffset" Value="10"/>
<!--marker padding according to the type of the marker
if the marker is not a fixed length character, give more space to the marker-->
<Setter Property="Padding" Value="{Binding RelativeSource={RelativeSource AncestorType=RichTextBox}, Path=FontSize, Mode=OneWay, Converter={StaticResource MarkerPaddingConverter}}"/>
<!--<Setter Property="MarkerOffset" Value="{Binding RelativeSource={RelativeSource AncestorType=RichTextBox}, Path=FontSize, Mode=OneWay, Converter={StaticResource BulletLocationConverter}}"/>-->
</Style>
<Style TargetType="{x:Type Paragraph}">
<Setter Property="Margin" Value="0"/>
Expand Down
35 changes: 17 additions & 18 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
using Hardcodet.Wpf.TaskbarNotification;
using System;
using System.Globalization;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
using System.IO;
using System.Threading;
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.Animation;

namespace DesktopNote
{
public class MarkerPaddingConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return new Thickness((double)value * 3, 0d, 0d, 0d);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}


public partial class MainWindow : Window
{
public Setting CurrentSetting;
Expand Down Expand Up @@ -267,7 +283,6 @@ private void RTB_Main_PreviewMouseDown(object sender, MouseButtonEventArgs e)
App.FormatWindow.FadeOut();
}
}

#endregion

#region Rect Events
Expand Down Expand Up @@ -419,7 +434,7 @@ private void Win_Main_Loaded(object sender, RoutedEventArgs e)

if (App.FormatWindow == null)
{
App.FormatWindow = new Win_Format(this) { Tag = RTB_Main };
App.FormatWindow = new Win_Format(this);
((Xceed.Wpf.Toolkit.ColorPicker)App.FormatWindow.CP_Font.Content).SelectedColor = CurrentSetting.FontColor;
((Xceed.Wpf.Toolkit.ColorPicker)App.FormatWindow.CP_Back.Content).SelectedColor = CurrentSetting.BackColor;

Expand All @@ -437,21 +452,6 @@ private void Win_Main_Loaded(object sender, RoutedEventArgs e)
if (f.Source == CurrentSetting.Font) mi.IsSelected = true;
}
App.FormatWindow.CB_Font.Items.SortDescriptions.Add(new System.ComponentModel.SortDescription("Content", System.ComponentModel.ListSortDirection.Ascending));
//App.FormatWindow.CB_Font.SelectionChanged += (object s1, SelectionChangedEventArgs e1) =>
//{
// if (App.FormatWindow.Opacity == 1 && e1.AddedItems.Count == 1)
// {
// var mi = (ComboBoxItem)e1.AddedItems[0];

// if (!RTB_Main.Selection.IsEmpty) //only change selected
// RTB_Main.Selection.ApplyPropertyValue(TextElement.FontFamilyProperty, mi.FontFamily);
// else //change default
// {
// RTB_Main.FontFamily = mi.FontFamily;
// CurrentSetting.Font = mi.FontFamily.Source;
// }
// }
//};
}

//loading contents
Expand Down Expand Up @@ -498,7 +498,6 @@ private void Win_Main_Loaded(object sender, RoutedEventArgs e)

var source = PresentationSource.FromVisual(this) as System.Windows.Interop.HwndSource;
source.AddHook(WndProc);

}

private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
Expand Down
2 changes: 1 addition & 1 deletion Setting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void Save()
}

/// <summary>
/// Reset the setting for specified index. Leave default to reset current.
/// Reset the setting for specified index. Leave setidx default to reset current.
/// </summary>
public void Reset(int setidx = -1)
{
Expand Down
2 changes: 1 addition & 1 deletion Win_Format.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Margin" Value="2"/>
<Setter Property="Background" Value="#FFEAEAEA"/>
<Setter Property="CommandTarget" Value="{Binding Tag, ElementName=FB1}"/>
<Setter Property="CommandTarget" Value="{Binding RTB_Main, ElementName=FB1, Mode=OneWay}"/>
</Style>
<Style TargetType="ContentPresenter">
<Setter Property="HorizontalAlignment" Value="Center"/>
Expand Down
13 changes: 10 additions & 3 deletions Win_Format.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@ namespace DesktopNote
public partial class Win_Format : RoundedWindow
{
public MainWindow MainWin;
public RichTextBox RTB_Main;
//public RichTextBox RTB_Main;

public RichTextBox RTB_Main
{
get { return (RichTextBox)GetValue(RTB_MainProperty); }
set { SetValue(RTB_MainProperty, value); }
}
public static readonly DependencyProperty RTB_MainProperty =
DependencyProperty.Register("RTB_Main", typeof(RichTextBox), typeof(Win_Format), new PropertyMetadata(null));


public Win_Format(MainWindow mainwin)
{
Expand Down Expand Up @@ -288,15 +297,13 @@ private void Button_Close_Click(object sender, RoutedEventArgs e)
set.Doc_Location[MainWin.CurrentSetting.SettingIndex] = "";//mark setting item to be removed after restart
set.Save();
App.MainWindows.Remove(MainWin);
//App.MainWindows[MainWin.CurrentSetting.SettingIndex] = null;
MainWin.Close();
FadeOut();
break;
case MessageBoxResult.No:
set.Doc_Location[MainWin.CurrentSetting.SettingIndex] = "";//mark setting item to be removed after restart
set.Save();
App.MainWindows.Remove(MainWin);
//App.MainWindows[MainWin.CurrentSetting.SettingIndex] = null;
MainWin.Close();
FadeOut();
break;
Expand Down
3 changes: 2 additions & 1 deletion Win_Options.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ private void Button_ResetSet_Click(object sender, RoutedEventArgs e)
MainWin.CurrentSetting.Save();

var win = new MainWindow(MainWin.CurrentSetting.SettingIndex);
App.MainWindows[MainWin.CurrentSetting.SettingIndex] = win;
App.MainWindows.Remove(MainWin);
MainWin.Close();
App.MainWindows.Add(win);
win.Show();

FadeOut(true);
Expand Down
Binary file modified bin/Release/DesktopNote.exe
Binary file not shown.

0 comments on commit cf18343

Please sign in to comment.