Skip to content

Commit

Permalink
Added option to highlight current line.
Browse files Browse the repository at this point in the history
  • Loading branch information
Max DR committed Aug 3, 2020
1 parent 716761d commit 82677ed
Show file tree
Hide file tree
Showing 19 changed files with 340 additions and 457 deletions.
10 changes: 3 additions & 7 deletions ModernNotepad/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using ModernNotepadLibrary.ViewModels;
using ModernNotepad.Util;
using ModernNotepadLibrary.ViewModels;
using System;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using System.Windows.Threading;
Expand Down Expand Up @@ -37,7 +37,6 @@ protected override void OnStartup(StartupEventArgs e)
MainViewModel.Title = Path.GetFileName(e.Args[0]);
MainViewModel.FilePath = Path.GetFullPath(e.Args[0]);
MainViewModel.TextEditor.TextArea.Text = File.ReadAllText(e.Args[0], Encoding.Default);
//MainViewModel.TextEditor.SavedAsFile = true;
MainViewModel.SaveFileService.FileName = e.Args[0];
}
}
Expand Down Expand Up @@ -68,7 +67,7 @@ private void Application_DispatcherUnhandledException(object sender, DispatcherU
WriteLogFile(e.Exception.ToString());
const long MB_OK = 0x0L, MB_ERROR = 0x10L;
var message = MainViewModel.LocaleManager.LoadString("ErrorMessage");
MessageBox(IntPtr.Zero, message, "Modern Notepad", (uint)(MB_OK | MB_ERROR));
NativeMethods.MessageBox(IntPtr.Zero, message, "Modern Notepad", (uint)(MB_OK | MB_ERROR));
e.Handled = true;
Current.Shutdown();
}
Expand All @@ -78,8 +77,5 @@ private void WriteLogFile(string message)
var logPath = @$"{Directory.GetCurrentDirectory()}\error.log";
File.WriteAllText(logPath, message);
}

[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
private static extern int MessageBox(IntPtr hWnd, string lpText, string lpCaption, uint uType);
}
}
7 changes: 3 additions & 4 deletions ModernNotepad/Behaviors/SelectionChangedBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ protected override void OnDetaching()
}

private void OnSelectionChanged(object sender, RoutedEventArgs e)
{
var charIndex = AssociatedObject.SelectionStart;
var currentLine = AssociatedObject.GetLineIndexFromCharacterIndex(charIndex) + 1;
{
var currentLine = AssociatedObject.GetLineIndexFromCharacterIndex(AssociatedObject.CaretIndex) + 1;
CurrentLine = $"{Application.Current.TryFindResource("CurrentLine")}: {currentLine}";

var firstCharIndex = AssociatedObject.GetCharacterIndexFromLineIndex(currentLine - 1);
var currentCharacter = charIndex - firstCharIndex + 1;
var currentCharacter = AssociatedObject.CaretIndex - firstCharIndex + 1;
CurrentCharacter = $"{Application.Current.TryFindResource("CurrentChar")}: {currentCharacter}";

}
Expand Down
71 changes: 0 additions & 71 deletions ModernNotepad/Behaviors/ZoomBehavior.cs

This file was deleted.

17 changes: 0 additions & 17 deletions ModernNotepad/Converters/StringToZoomFactorConverter.cs

This file was deleted.

95 changes: 0 additions & 95 deletions ModernNotepad/CustomControls/DraggableBorder.cs

This file was deleted.

16 changes: 13 additions & 3 deletions ModernNotepad/CustomControls/TextArea.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using ModernNotepadLibrary.Core;
using ModernNotepad.Util;
using ModernNotepadLibrary.Core;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

Expand All @@ -12,9 +14,17 @@ public class TextArea : TextBox, ITextArea
public TextArea()
{
AcceptsReturn = true;
AcceptsTab = true;
AcceptsTab = true;
Loaded += TextArea_Loaded;
}

public void SetFontFamily(string fontFamilyName) => FontFamily = new FontFamily(fontFamilyName);
public HighlightCurrentLineAdorner HighlightCurrentLineAdorner { get; private set; }

public void SetFontFamily(string fontFamilyName) => FontFamily = new FontFamily(fontFamilyName);

private void TextArea_Loaded(object sender, RoutedEventArgs e)
{
HighlightCurrentLineAdorner = new HighlightCurrentLineAdorner(this);
}
}
}
1 change: 1 addition & 0 deletions ModernNotepad/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ private static void ShowSplashScreen()
private static void RegisterServices()
{
ServiceResolver = new ServiceResolver();
ServiceResolver.Register<IAdornerService, AdornerService>();
ServiceResolver.Register<IApplicationThemeManager, ApplicationThemeManager>();
ServiceResolver.Register<IContentDialogService, ContentDialogService>();
ServiceResolver.Register<ILocaleManager, LocaleManager>();
Expand Down
29 changes: 29 additions & 0 deletions ModernNotepad/Services/AdornerService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using ModernNotepad.CustomControls;
using ModernNotepadLibrary.Core;
using ModernNotepadLibrary.Services;
using System.Windows.Documents;

namespace ModernNotepad.Services
{
class AdornerService : IAdornerService
{
public void AddAdorner(ITextArea textArea)
{
var adornedTextArea = textArea as TextArea;
var adornerLayer = AdornerLayer.GetAdornerLayer(adornedTextArea);

if (adornerLayer.GetAdorners(adornedTextArea) != null) // Workaround
{
adornerLayer.Remove(adornedTextArea.HighlightCurrentLineAdorner);
}
adornerLayer.Add(adornedTextArea.HighlightCurrentLineAdorner);
}

public void RemoveAdorner(ITextArea textArea)
{
var adornedTextArea = textArea as TextArea;
var adornerLayer = AdornerLayer.GetAdornerLayer(adornedTextArea);
adornerLayer.Remove(adornedTextArea.HighlightCurrentLineAdorner);
}
}
}
14 changes: 7 additions & 7 deletions ModernNotepad/Services/PrintService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class PrintService : IPrintService
{
public void PrintDocument()
{
if (PrintDialogWrapper.IsPrintJobSendToQueue)
{
var document = (Application.Current.MainWindow as MainWindow).Document;
var documentPaginator = document.DocumentPaginator;
var description = (string)Application.Current.TryFindResource("DescriptionPrintJob");
PrintDialogWrapper.PrintDocument(documentPaginator, description);
}
//if (PrintDialogWrapper.IsPrintJobSendToQueue)
//{
// var document = (Application.Current.MainWindow as MainWindow).Document;
// var documentPaginator = document.DocumentPaginator;
// var description = (string)Application.Current.TryFindResource("DescriptionPrintJob");
// PrintDialogWrapper.PrintDocument(documentPaginator, description);
//}
}
}
}
Loading

0 comments on commit 82677ed

Please sign in to comment.