-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoteItem.cs
More file actions
124 lines (108 loc) · 5.27 KB
/
Copy pathNoteItem.cs
File metadata and controls
124 lines (108 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using Microsoft.UI.Xaml;
using System;
using System.ComponentModel;
namespace NoteIt;
/// <summary>
/// A single quick note. Unlike the clipboard app this was adapted from,
/// notes are user-authored and editable in place rather than captured
/// read-only snapshots -- Text is a plain mutable property the note's
/// TextBox two-way binds to (see NotesPanelWindow's item template), and
/// every edit is persisted via NotesStore (see NotesPanelWindow.OnNoteTextChanged).
/// </summary>
public class NoteItem : INotifyPropertyChanged
{
/// <summary>Stable identity, assigned once and never reused. Plain
/// get/set, not init -- WinUI's generated XamlTypeInfo.g.cs constructs
/// and populates NoteItem via reflection-style property setters for
/// x:Bind, which can't target init-only accessors.</summary>
public string Id { get; set; } = Guid.NewGuid().ToString("N");
private string _text = string.Empty;
/// <summary>The note's body text. Raises PropertyChanged so the
/// preview/empty-state affordances that key off it (see IsEmpty,
/// PreviewText) stay live while the user is typing -- the ListView's
/// own TextBox binding is Mode=TwoWay so keystrokes flow back into
/// this property immediately, not just on focus loss.</summary>
public string Text
{
get => _text;
set
{
if (_text == value) return;
_text = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Text)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsEmpty)));
}
}
public DateTime CreatedAt { get; set; } = DateTime.Now;
private DateTime _modifiedAt = DateTime.Now;
/// <summary>Bumped on every edit (see NotesPanelWindow.OnNoteTextChanged);
/// drives ModifiedDisplay so each note shows a "last edited" timestamp
/// the way a real notes app would, instead of only ever showing when it
/// was first created.</summary>
public DateTime ModifiedAt
{
get => _modifiedAt;
set
{
if (_modifiedAt == value) return;
_modifiedAt = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ModifiedAt)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(ModifiedDisplay)));
}
}
private string? _paperColorKey;
/// <summary>Key of the Models.PaperColor preset the sticky pop-out (see
/// UI/StickyPopoutWindow) should paint this note with -- null/unrecognized
/// means "use the default yellow", same fallback Models.PaperColor.Resolve
/// applies. Lives on the shared NoteItem (rather than on the pop-out window
/// itself) so the choice survives closing and re-opening the pop-out, and
/// round-trips through NotesStore the same way IsPinned does (see
/// NotesPanelWindow.LoadNotesAsync/SaveNotes).</summary>
public string? PaperColorKey
{
get => _paperColorKey;
set
{
if (_paperColorKey == value) return;
_paperColorKey = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PaperColorKey)));
}
}
private bool _isPinned;
/// <summary>Pinned notes are kept contiguous at the very top of the
/// list (above every unpinned note), skip auto-trim, and are exempt
/// from Clear All -- see NotesPanelWindow.TogglePin/Trim/
/// OnClearAllClicked. Raises PropertyChanged so the pin button's glyph
/// and resting opacity (both x:Bind Mode=OneWay in the item template)
/// update live without the ListView needing to re-template the row.</summary>
public bool IsPinned
{
get => _isPinned;
set
{
if (_isPinned == value) return;
_isPinned = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsPinned)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PinGlyph)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PinOpacity)));
}
}
/// <summary>Segoe Fluent icon for the pin button: outline "Pin" glyph
/// when not yet pinned (click to pin), filled "UnPin" glyph once
/// pinned (click to unpin) -- same convention Windows itself uses for
/// pin/unpin toggle buttons.</summary>
public string PinGlyph => IsPinned ? "\uE77A" : "\uE718";
/// <summary>Resting (non-hover) opacity for the pin button: fully
/// visible once pinned, invisible otherwise. The button itself stays
/// laid out (Visibility="Visible") at all times -- only its opacity
/// and hit-testability change -- so the row height never depends on
/// whether this button happens to be showing. Hover state overrides
/// this transiently in code-behind (see OnItemPointerEntered/Exited).</summary>
public double PinOpacity => IsPinned ? 1.0 : 0.0;
public event PropertyChangedEventHandler? PropertyChanged;
/// <summary>Drives the empty-note placeholder text/opacity so a
/// freshly-added blank note still reads as a note (not a rendering
/// glitch) before the user's typed anything into it.</summary>
public bool IsEmpty => string.IsNullOrWhiteSpace(Text);
public string ModifiedDisplay => "Edited " + ModifiedAt.ToString("t");
}