Skip to content

Commit

Permalink
fix numbering bullet not displayed properly
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Chang committed May 11, 2019
1 parent cf18343 commit 29245b1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
16 changes: 12 additions & 4 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +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"/>
<local:ThicknessConverter x:Key="ThicknessConverter"/>
</Window.Resources>
<Grid>
<Rectangle x:Name="Rec_BG" Fill="#FFFFF7C5" Margin="10" RadiusX="12" RadiusY="12"
Expand All @@ -34,10 +34,18 @@
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{StaticResource {x:Static SystemColors.HighlightColorKey}}"/>
<Style TargetType="{x:Type List}">
<Setter Property="Margin" Value="0"/>
<!--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="Padding" Value="{Binding
RelativeSource={RelativeSource AncestorType=RichTextBox}, Path=FontSize, Mode=OneWay,
Converter={StaticResource ThicknessConverter}, ConverterParameter='1.5 0 0 0'}"/>
<!--<Setter Property="MarkerOffset" Value="{Binding RelativeSource={RelativeSource AncestorType=RichTextBox}, Path=FontSize, Mode=OneWay, Converter={StaticResource BulletLocationConverter}}"/>-->
<!--marker padding according to the type of the marker. if the marker is not a fixed length character, give more space to the marker-->
<Style.Triggers>
<Trigger Property="MarkerStyle" Value="Decimal">
<Setter Property="Padding" Value="{Binding
RelativeSource={RelativeSource AncestorType=RichTextBox}, Path=FontSize, Mode=OneWay,
Converter={StaticResource ThicknessConverter}, ConverterParameter='3 0 0 0'}"/>
</Trigger>
</Style.Triggers>
</Style>
<Style TargetType="{x:Type Paragraph}">
<Setter Property="Margin" Value="0"/>
Expand Down
47 changes: 37 additions & 10 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@

namespace DesktopNote
{
public class MarkerPaddingConverter : IValueConverter
public class ThicknessConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return new Thickness((double)value * 3, 0d, 0d, 0d);
Thickness p;
if (parameter == null) p = new Thickness(1);
else p = (Thickness) new System.Windows.ThicknessConverter().ConvertFrom(parameter);
var d = (double) value;
System.Diagnostics.Debug.Print(new Thickness(d * p.Left, d * p.Top, d * p.Right, d * p.Bottom).ToString());
return new Thickness(d * p.Left, d * p.Top, d * p.Right, d * p.Bottom);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down Expand Up @@ -352,7 +357,7 @@ internal void SaveToXamlPkg()
{
using (var ms = new FileStream(CurrentSetting.Doc_Location, FileMode.Create))
{
tr.Save(ms, DataFormats.XamlPackage, true);
tr.Save(ms, DataFormats.Xaml, true);
}
File.WriteAllText(CurrentSetting.Bak_Location, tr.Text);
}
Expand All @@ -362,7 +367,7 @@ internal void SaveToXamlPkg()
{
using (var ms = new FileStream(CurrentSetting.Doc_Location, FileMode.Create))
{
tr.Save(ms, DataFormats.XamlPackage, true);
tr.Save(ms, DataFormats.Xaml, true);
};
File.WriteAllText(CurrentSetting.Bak_Location, tr.Text);
});
Expand Down Expand Up @@ -412,7 +417,7 @@ private void Win_Main_Loaded(object sender, RoutedEventArgs e)
}

//check and merge previous settings
if (Properties.Settings.Default.UpgradeFlag == true)
if (Properties.Settings.Default.UpgradeFlag)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.UpgradeFlag = false;
Expand Down Expand Up @@ -462,7 +467,7 @@ private void Win_Main_Loaded(object sender, RoutedEventArgs e)
try
{
var tr = new TextRange(RTB_Main.Document.ContentStart, RTB_Main.Document.ContentEnd);
tr.Load(new FileStream(CurrentSetting.Doc_Location, FileMode.Open), DataFormats.XamlPackage);
tr.Load(new FileStream(CurrentSetting.Doc_Location, FileMode.Open), DataFormats.Xaml);
}
catch
{
Expand All @@ -472,19 +477,25 @@ private void Win_Main_Loaded(object sender, RoutedEventArgs e)
}
}


//unifying font for new paragraghs. without these, wont be able to change fonts after reload.
//the following doesnt affect specifically set font sizes in Inlines & Run.
//reset dependency property values saved explicitly
//this is to reduce format inconsistency across reloads
if (RTB_Main.Document.Blocks.Count > 0)
{
RTB_Main.FontSize = RTB_Main.Document.Blocks.FirstBlock.FontSize;
foreach (var b in RTB_Main.Document.Blocks)
{
//unify font for new paragraghs. otherwise wont be able to change fonts after reload.
//doesnt affect specifically set font sizes in Inlines & Run.
b.ClearValue(TextElement.FontSizeProperty);
b.ClearValue(TextElement.FontFamilyProperty);
b.ClearValue(TextElement.ForegroundProperty);
b.ClearValue(TextElement.BackgroundProperty);
}

//reset Padding on List
foreach (var block in RTB_Main.Document.Blocks) {
resetPadding(block);
}
}

RTB_Main.IsUndoEnabled = false;
Expand All @@ -499,7 +510,23 @@ private void Win_Main_Loaded(object sender, RoutedEventArgs e)
var source = PresentationSource.FromVisual(this) as System.Windows.Interop.HwndSource;
source.AddHook(WndProc);
}


private void resetPadding(TextElement ele) {
switch (ele) {
case List lst:
lst.ClearValue(Block.PaddingProperty);
foreach (var lstItem in lst.ListItems) {
resetPadding(lstItem);
}
break;
case ListItem lstItem:
foreach (var blk in lstItem.Blocks) {
resetPadding(blk);
}
break;
}
}

private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == SingleInstance.RegisteredWM)
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.2.1")]
[assembly: AssemblyFileVersion("1.4.2.1")]
[assembly: AssemblyVersion("1.4.3.0")]
[assembly: AssemblyFileVersion("1.4.3.0")]
Binary file modified bin/Release/DesktopNote.exe
Binary file not shown.

0 comments on commit 29245b1

Please sign in to comment.