@@ -3,22 +3,126 @@ enum PSNoteKind {
33 Script
44}
55
6- enum PSNoteMenuItems{
7- Main
8- Catalogs
9- Tags
10- Favorites
11- NoteList
12- NoteActions
13- Settings
14- Help
15- Quit
16- Welcome
17- AllCatalogs
18- Preview
19- Search
6+ class PSNoteMenuItem {
7+
8+ [string ] $Name
9+ [string ] $Key
10+ [char ] $Alt
11+ [string ] $Label
12+
13+ hidden PSNoteMenuItem(
14+ [string ] $name ,
15+ [string ] $key ,
16+ [char ] $alt ,
17+ [string ] $label
18+ ) {
19+ $this.Name = $name
20+ $this.Key = $key
21+ $this.Alt = $alt
22+ $this.Label = $label
23+ }
24+
25+ hidden PSNoteMenuItem(
26+ [string ] $name ,
27+ [string ] $label
28+ ) {
29+ $this.Name = $name
30+ $this.Key = $null
31+ $this.Alt = $null
32+ $this.Label = $label
33+ }
34+
35+ # --- Static "enum-like" instances ---
36+ static [PSNoteMenuItem ] $Main = [PSNoteMenuItem ]::new(' Main' , ' ^M' , ' M' , ' Main' )
37+ static [PSNoteMenuItem ] $Catalogs = [PSNoteMenuItem ]::new(' Catalogs' , ' ^G' , ' G' , ' Catalogs' )
38+ static [PSNoteMenuItem ] $Tags = [PSNoteMenuItem ]::new(' Tags' , ' ^T' , ' T' , ' Tags' )
39+ static [PSNoteMenuItem ] $Favorites = [PSNoteMenuItem ]::new(' Favorites' , ' ^F' , ' F' , ' Favorites' )
40+ static [PSNoteMenuItem ] $Settings = [PSNoteMenuItem ]::new(' Settings' , ' ^O' , ' O' , ' Settings' )
41+ static [PSNoteMenuItem ] $Search = [PSNoteMenuItem ]::new(' Search' , ' ^W' , ' W' , ' Search' )
42+ static [PSNoteMenuItem ] $Help = [PSNoteMenuItem ]::new(' Help' , ' ^H' , ' H' , ' Help' )
43+ static [PSNoteMenuItem ] $Back = [PSNoteMenuItem ]::new(' Back' , ' ^B' , ' B' , ' Back' )
44+ static [PSNoteMenuItem ] $Quit = [PSNoteMenuItem ]::new(' Quit' , ' ^Q' , ' Q' , ' Quit' )
45+ static [PSNoteMenuItem ] $Welcome = [PSNoteMenuItem ]::new(' Welcome' , ' ^W' , ' W' , ' Welcome' )
46+ static [PSNoteMenuItem ] $AllCatalogs = [PSNoteMenuItem ]::new(' AllCatalogs' , ' ^A' , ' A' , ' All' )
47+ static [PSNoteMenuItem ] $Preview = [PSNoteMenuItem ]::new(' Preview' , ' ^P' , ' P' , ' Preview' )
48+ static [PSNoteMenuItem ] $NewNote = [PSNoteMenuItem ]::new(' NewNote' , ' ^N' , ' N' , ' New' )
49+ static [PSNoteMenuItem ] $NoteList = [PSNoteMenuItem ]::new(' NoteList' , ' NoteList' )
50+ static [PSNoteMenuItem ] $NoteActions = [PSNoteMenuItem ]::new(' NoteActions' , ' NoteActions' )
51+ static [PSNoteMenuItem ] $Previous = [PSNoteMenuItem ]::new(' Previous' , ' ^Y' , ' Y' , ' Previous' )
52+ static [PSNoteMenuItem ] $Next = [PSNoteMenuItem ]::new(' Next' , ' ^U' , ' U' , ' Next' )
53+ static [PSNoteMenuItem ] $Copy = [PSNoteMenuItem ]::new(' Copy' , ' ^C' , ' C' , ' Copy' )
54+ static [PSNoteMenuItem ] $Execute = [PSNoteMenuItem ]::new(' Execute' , ' ^E' , ' E' , ' Execute' )
55+ static [PSNoteMenuItem ] $ToggleFav = [PSNoteMenuItem ]::new(' ToggleFav' , ' ^T' , ' T' , ' Toggle Favorite' )
56+
57+ static [PSNoteMenuItem []] GetAll() {
58+ return @ (
59+ [PSNoteMenuItem ]::Main
60+ [PSNoteMenuItem ]::Catalogs
61+ [PSNoteMenuItem ]::Tags
62+ [PSNoteMenuItem ]::Favorites
63+ [PSNoteMenuItem ]::Settings
64+ [PSNoteMenuItem ]::Search
65+ [PSNoteMenuItem ]::Help
66+ [PSNoteMenuItem ]::Back
67+ [PSNoteMenuItem ]::Quit
68+ [PSNoteMenuItem ]::Welcome
69+ [PSNoteMenuItem ]::AllCatalogs
70+ [PSNoteMenuItem ]::Preview
71+ [PSNoteMenuItem ]::NewNote
72+ [PSNoteMenuItem ]::Copy
73+ [PSNoteMenuItem ]::Execute
74+ [PSNoteMenuItem ]::ToggleFav
75+ )
76+ }
77+
78+ static [PSNoteMenuItem []] GetMain() {
79+ return @ (
80+ # Top Row
81+ [PSNoteMenuItem ]::Main
82+ [PSNoteMenuItem ]::NewNote
83+ [PSNoteMenuItem ]::AllCatalogs
84+ [PSNoteMenuItem ]::Search
85+ [PSNoteMenuItem ]::Help
86+ # Bottom Row
87+ [PSNoteMenuItem ]::Quit
88+ [PSNoteMenuItem ]::Favorites
89+ [PSNoteMenuItem ]::Catalogs
90+ [PSNoteMenuItem ]::Back
91+ [PSNoteMenuItem ]::Settings
92+ )
93+ }
94+
95+ static [PSNoteMenuItem []] GetNoteActions() {
96+ return @ (
97+ # Top Row
98+ [PSNoteMenuItem ]::Copy
99+ [PSNoteMenuItem ]::Execute
100+ [PSNoteMenuItem ]::ToggleFav
101+ [PSNoteMenuItem ]::Back
102+ )
103+ }
104+
105+ static [PSNoteMenuItem ] FromKey([string ]$key ) {
106+ $from = [PSNoteMenuItem ]::GetAll() |
107+ Where-Object { $_.Key -eq $key -and -not [string ]::IsNullOrEmpty($_.Key ) } | Select-Object - First 1
108+ if (-not $from ) {
109+ $from = [PSNoteMenuItem ]::GetAll() |
110+ Where-Object { $_.Alt -eq $key.TrimStart (' ^' ) -and -not [string ]::IsNullOrEmpty($_.Alt ) } | Select-Object - First 1
111+ }
112+ return $from
113+ }
114+
115+ static [PSNoteMenuItem ] FromString([string ]$name ) {
116+ return [PSNoteMenuItem ]::GetAll() |
117+ Where-Object { $_.Name -eq $name } | Select-Object - First 1
118+ }
119+
120+ [string ] ToString() {
121+ return $this.Name
122+ }
20123}
21124
125+
22126# Create the PSNote class
23127class PSNote {
24128 [string ]$Note
@@ -602,7 +706,7 @@ class NoteConfigStore {
602706
603707 [string ] $Path
604708 [int ] $Version
605- [PSNoteMenuItems ] $Main
709+ [PSNoteMenuItem ] $Main
606710 [bool ] $ExitOnCopy
607711 [ConsoleColor ] $ForegroundColor
608712 [ConsoleColor ] $BackgroundColor
@@ -625,7 +729,7 @@ class NoteConfigStore {
625729
626730 [void ] SetDefaults() {
627731 $this.Version = [NoteConfigStore ]::CurrentVersion
628- $this.Main = [PSNoteMenuItems ]::Welcome
732+ $this.Main = [PSNoteMenuItem ]::Welcome
629733 $this.ExitOnCopy = $true
630734 $this.ForegroundColor = [ConsoleColor ]::Black
631735 $this.BackgroundColor = [ConsoleColor ]::Gray
@@ -640,7 +744,7 @@ class NoteConfigStore {
640744
641745 $data = $json | ConvertFrom-Json - ErrorAction Stop
642746 if (-not [string ]::IsNullOrWhiteSpace([string ]$data.Main )) {
643- $tryFg = [PSNoteMenuItems ]::Welcome
747+ $tryFg = [PSNoteMenuItem ]::Welcome
644748 if ([Enum ]::TryParse([string ]$data.Main , [ref ]$tryFg )) {
645749 $this.Main = $tryFg
646750 }
@@ -683,8 +787,8 @@ class NoteConfigStore {
683787class NoteConsoleState {
684788 static [int ] $CurrentVersion = 1
685789
686- [PSNoteMenuItems ] $Mode
687- [PSNoteMenuItems []] $ReturnMode
790+ [PSNoteMenuItem ] $Mode
791+ [PSNoteMenuItem []] $ReturnMode
688792 [string ] $ScopeLabel
689793 [System.Collections.Generic.List [PSNote ]] $ScopeNotes
690794 [System.Collections.Generic.List [PSNote ]] $LastList
@@ -702,14 +806,14 @@ class NoteConsoleState {
702806 $this.SetDefaults ()
703807 $this.ScopeNotes = @ ($Store.Notes )
704808 $this.Settings = $Store.Config
705- $tryMode = [PSNoteMenuItems ]::Welcome
706- if ([ Enum ]::TryParse([ string ] $Store .Config.Main , [ ref ] $ tryMode) ) {
809+ $tryMode = [PSNoteMenuItem ]::FromString( $Store .Config.Main )
810+ if ($ tryMode ) {
707811 $this.Mode = $tryMode
708812 }
709813 }
710814
711815 [void ] SetDefaults() {
712- $this.Mode = [PSNoteMenuItems ]::Welcome
816+ $this.Mode = [PSNoteMenuItem ]::Welcome
713817 $this.ReturnMode = @ ()
714818 $this.ScopeLabel = ' All'
715819 $this.ScopeNotes = @ ()
0 commit comments