Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
**🎯 Selection & editing**
- Lasso and rectangle select; move, resize, rotate, duplicate, recolor and change line width of the selection
- Type text or paste images straight onto the page
- Convert handwriting to text: lasso it, check what was read, then swap the ink for a text box or copy the text
- Stickers: save a lasso selection (a diagram, a stamp, a signature), optionally with the PDF behind it, or just a piece of a PDF, and drop a copy into any note
- Screenshot tool: capture a region and copy, save or insert it into the page
- Undo and redo for ink, page changes and templates
Expand All @@ -58,6 +59,7 @@
- Share a note as a PDF or as images through the Windows share window (Mail, Teams, Nearby sharing, …)
- Page templates: blank, grid, dots, lined, Cornell, with adjustable spacing
- Widen a page to the left or right (it snaps to match neighbouring widened pages), or keep scrolling past the end to add a page
- Make room to write: with the Page size tool, drag down inside a page to open blank space at that line (the PDF below moves down with it, e.g. between two exercises), or drag up to close it again. Saved and exported PDFs keep the space, and the PDF text stays selectable
- Page sorter: reorder, delete and jump between pages; bookmark pages
- Autosave and version history: preview an earlier version next to the note, then restore it if you want
- `.yunote` files are SQLite, so every stroke stays editable after you close and reopen
Expand All @@ -72,6 +74,7 @@
- Home screen with folders (with colors), pinned notes, a "continue where you left off" row, and sorting by date, name or folder
- Trash and Archive, with restore
- Tabs: keep several notes open in one window (**Ctrl+T**, **Ctrl+W**, **Ctrl+Tab**, or Ctrl+click a note on Home); each tab keeps its own undo history
- Windows like a browser: drag tabs to reorder them, drag one out into its own window or onto another window's tabs, or right-click a tab to move it. Opening a note from File Explorer adds a tab to the YuNotes that's already open instead of starting a second copy
- Side by side: open a second note read-only next to the one you're editing

**🎤 Presenting**
Expand Down
90 changes: 74 additions & 16 deletions src/YuNotes/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ namespace YuNotes;

public partial class App : Application
{
public static Window? MainWindow { get; private set; }
// The window the user last worked in (YuNotes can have several).
public static Window? MainWindow => YuNotes.MainWindow.Active;
private static Microsoft.UI.Dispatching.DispatcherQueue? s_ui;
public static ServiceContainer Services { get; } = new();

public static string CrashLogPath { get; } = Path.Combine(
Expand Down Expand Up @@ -47,35 +49,91 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
DebugSettings.BindingFailed += (_, ev) => Append($"[BindingFailed] {ev.Message}");

Services.Initialize();
MainWindow = new MainWindow();
MainWindow.Activate();
s_ui = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
var first = new MainWindow();
first.Activate();

// If Explorer launched us via a file association (.pdf / .yunote), open
// that file in the editor on top of the home page.
TryOpenActivationFile();
try
{
var path = FileFromActivation(Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent().GetActivatedEventArgs())
?? FileFromCommandLine(Environment.GetCommandLineArgs(), skipFirst: true);
if (path is not null) YuNotes.MainWindow.OpenFile(path);
}
catch (Exception ex) { LogError(ex, "OnLaunched file activation"); }

// Later launches hand their activation to this instance (see Program).
Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent().Activated += (_, a) =>
s_ui?.TryEnqueue(() => OnRedirected(a));

// Background update check (no-op when turned off in Settings).
_ = YuNotes.Services.UpdateService.CheckOnStartupAsync();
}

// When the app is started by opening an associated file, Windows delivers the
// file through the AppLifecycle activation args (not OnLaunched's args). Read
// them and route the path through the normal editor-open flow.
private static void TryOpenActivationFile()
// Another launch of YuNotes: open its file as a tab in the window last
// used, or, for a plain launch, a new window (like a browser does).
private static void OnRedirected(Microsoft.Windows.AppLifecycle.AppActivationArguments args)
{
try
{
var activation = Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent().GetActivatedEventArgs();
if (activation?.Kind == Microsoft.Windows.AppLifecycle.ExtendedActivationKind.File
&& activation.Data is Windows.ApplicationModel.Activation.IFileActivatedEventArgs fileArgs
&& fileArgs.Files.Count > 0
&& fileArgs.Files[0] is Windows.Storage.StorageFile file
&& !string.IsNullOrEmpty(file.Path))
var path = FileFromActivation(args);
if (path is not null) { YuNotes.MainWindow.OpenFile(path); return; }
var w = new MainWindow();
w.Activate();
w.BringToFront();
}
catch (Exception ex) { LogError(ex, "Redirected activation"); }
}

// When the app is started by opening an associated file, packaged YuNotes
// gets the file in File activation args; unpackaged YuNotes gets it on the
// command line (Launch activation).
private static string? FileFromActivation(Microsoft.Windows.AppLifecycle.AppActivationArguments? activation)
{
if (activation is null) return null;
if (activation.Kind == Microsoft.Windows.AppLifecycle.ExtendedActivationKind.File
&& activation.Data is Windows.ApplicationModel.Activation.IFileActivatedEventArgs fileArgs
&& fileArgs.Files.Count > 0
&& !string.IsNullOrEmpty(fileArgs.Files[0].Path))
return fileArgs.Files[0].Path;
if (activation.Kind == Microsoft.Windows.AppLifecycle.ExtendedActivationKind.Launch
&& activation.Data is Windows.ApplicationModel.Activation.ILaunchActivatedEventArgs launch
&& !string.IsNullOrWhiteSpace(launch.Arguments))
return FileFromCommandLine(SplitCommandLine(launch.Arguments), skipFirst: false);
return null;
}

private static string? FileFromCommandLine(System.Collections.Generic.IEnumerable<string> args, bool skipFirst)
{
foreach (var a in skipFirst ? System.Linq.Enumerable.Skip(args, 1) : args)
{
var p = a.Trim().Trim('"');
if ((p.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase) || p.EndsWith(".yunote", StringComparison.OrdinalIgnoreCase))
&& File.Exists(p))
return Path.GetFullPath(p);
}
return null;
}

// Splits a command line into arguments, keeping quoted paths with spaces whole.
private static System.Collections.Generic.List<string> SplitCommandLine(string line)
{
var result = new System.Collections.Generic.List<string>();
var cur = new System.Text.StringBuilder();
bool quoted = false;
foreach (char c in line)
{
if (c == '"') { quoted = !quoted; continue; }
if (char.IsWhiteSpace(c) && !quoted)
{
YuNotes.MainWindow.Navigate<Views.EditorPage>(file.Path);
if (cur.Length > 0) { result.Add(cur.ToString()); cur.Clear(); }
continue;
}
cur.Append(c);
}
catch (Exception ex) { LogError(ex, "OnLaunched file activation"); }
if (cur.Length > 0) result.Add(cur.ToString());
return result;
}

private static void Append(string detail)
Expand Down
39 changes: 18 additions & 21 deletions src/YuNotes/Controls/InkCanvasControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,6 @@
public event EventHandler<YuNotes.Tools.ToolKind>? MomentaryToolStart;
public event EventHandler? MomentaryToolEnd;
public event EventHandler? ActivePageScrolled;
// True while any page is showing a live (uncommitted) stroke.
public event EventHandler<bool>? LiveInkActiveChanged;
// Pages currently showing live ink. A stroke handed between pages can
// raise the new page's start before the old page's end, so count instead
// of forwarding each page's flag.
private int _liveInkPages;

private void OnPageLiveInkActiveChanged(object? sender, bool active)
{
bool was = _liveInkPages > 0;
_liveInkPages = Math.Max(0, _liveInkPages + (active ? 1 : -1));
bool now = _liveInkPages > 0;
if (now != was) LiveInkActiveChanged?.Invoke(this, now);
}

public InkCanvasControl()
{
Expand Down Expand Up @@ -288,12 +274,6 @@
{
PagesPanel.Children.Clear();
_pageCanvases.Clear();
// Discarded pages never report their live ink ending.
if (_liveInkPages > 0)
{
_liveInkPages = 0;
LiveInkActiveChanged?.Invoke(this, false);
}
_pullZone = null;
_pullRingHost = null;
_addBtnWrapper = null;
Expand Down Expand Up @@ -344,9 +324,9 @@
canvas.MomentaryToolStart += (_, kind) => MomentaryToolStart?.Invoke(this, kind);
canvas.MomentaryToolEnd += (_, __) => MomentaryToolEnd?.Invoke(this, EventArgs.Empty);
canvas.RectSelectionCompleted += (_, __) => RectSelectionCompleted?.Invoke(this, EventArgs.Empty);
canvas.LiveInkActiveChanged += OnPageLiveInkActiveChanged;
canvas.SelectionDragDropped += OnSelectionDragDropped;
canvas.ExtensionDragCompleted += OnExtensionDragCompleted;
canvas.SpaceDragCompleted += OnSpaceDragCompleted;
canvas.ExtendModeActive = ExtendModeActive;
PagesPanel.Children.Add(canvas);
_pageCanvases.Add(canvas);
Expand Down Expand Up @@ -592,7 +572,7 @@
if (PullDisabled) return double.MaxValue;
try
{
double top = _pullZone.TransformToVisual(ContentRoot).TransformPoint(new Windows.Foundation.Point(0, 0)).Y;

Check warning on line 575 in src/YuNotes/Controls/InkCanvasControl.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 575 in src/YuNotes/Controls/InkCanvasControl.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 575 in src/YuNotes/Controls/InkCanvasControl.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.

Check warning on line 575 in src/YuNotes/Controls/InkCanvasControl.xaml.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
return Math.Max(0, top * Scroller.ZoomFactor - Scroller.ViewportHeight);
}
catch { return double.MaxValue; }
Expand Down Expand Up @@ -1164,6 +1144,10 @@
public bool SelectionHasResizableWidth => ActivePageCanvas?.SelectionHasResizableWidth == true;
public float? SelectionWidth() => ActivePageCanvas?.SelectionWidth();
public void SetSelectionWidth(float width) => ActivePageCanvas?.SetSelectionWidth(width);
public bool SelectionHasPenInk => ActivePageCanvas?.SelectionHasPenInk == true;
public List<Stroke> SelectedPenStrokes() => ActivePageCanvas?.SelectedPenStrokes() ?? new();
public bool ReplaceSelectedPenInkWithText(string text, Windows.UI.Color color, float fontSize) =>
ActivePageCanvas?.ReplaceSelectedPenInkWithText(text, color, fontSize) == true;
public byte[]? RenderRegionOfCurrentPage(float x, float y, float w, float h)
=> ActivePageCanvas?.RenderRegionToPng(x, y, w, h);

Expand Down Expand Up @@ -1653,6 +1637,19 @@
CommitPageExtension(pc.Page, args.Side, args.Amount, pc);
}

// A Page size drag inside a page: open space below the row it started at
// (Delta > 0) or close inserted space above it (Delta < 0). One undo step.
private void OnSpaceDragCompleted(object? sender, (double Y, double Delta) args)
{
if (sender is not PageCanvas pc) return;
var page = pc.Page;
if (args.Delta > 0) PageGaps.Insert(page, args.Y, args.Delta);
else if (PageGaps.Remove(page, args.Y + args.Delta, args.Y) <= 0) return;
pc.ResizeCanvas();
UpdateSeparators();
DocumentMutated?.Invoke(this, page);
}

// Called by EditorPage when the dialog is used for precise control.
public void CommitPageExtension(NotePage page, ExtendSide side, double amount)
{
Expand Down
Loading
Loading