@@ -39,6 +39,7 @@ private void StartNewShortcut()
3939 return ;
4040 }
4141
42+ DiscardUnsavedIcon ( ) ;
4243 draft = new ShortcutEntry { Tint = HexColor . ToDigits ( ShortcutPalette . Wheel [ 0 ] ) } ;
4344 draft . Steps . Add ( new ShortcutStep { Kind = ShortcutStepKind . Command } ) ;
4445 draftId = Guid . Empty ;
@@ -48,6 +49,7 @@ private void StartNewShortcut()
4849
4950 private void StartEditShortcut ( ShortcutEntry entry )
5051 {
52+ DiscardUnsavedIcon ( ) ;
5153 draft = entry . Copy ( ) ;
5254 draftId = entry . Id ;
5355 draftPinned = store . IsPinned ( entry . Id ) ;
@@ -429,9 +431,14 @@ private void CommitDraft()
429431 }
430432 else
431433 {
434+ var previousIcon = target . IconImage ;
432435 target . CopyFrom ( draft ) ;
433436 store . Save ( ) ;
434437 store . SetPinned ( target . Id , draftPinned ) ;
438+ if ( previousIcon . Length > 0 && previousIcon != target . IconImage )
439+ {
440+ store . ReleaseIcon ( previousIcon ) ;
441+ }
435442 }
436443
437444 draft = null ;
@@ -446,10 +453,22 @@ private void DuplicateDraft()
446453 return ;
447454 }
448455
456+ var previousUnsavedIcon = UnsavedIconOf ( draft ) ;
457+
449458 var copy = draft . Copy ( ) ;
450459 copy . Name = CopyName ( draft . Name ) ;
451460 PruneEmptySteps ( copy ) ;
461+ if ( copy . IconImage . Length > 0 )
462+ {
463+ copy . IconImage = store . DuplicateIcon ( copy . IconImage ) ?? string . Empty ;
464+ }
465+
452466 store . Add ( copy ) ;
467+ if ( previousUnsavedIcon . Length > 0 )
468+ {
469+ store . ReleaseIcon ( previousUnsavedIcon ) ;
470+ }
471+
453472 draft = copy . Copy ( ) ;
454473 draftId = copy . Id ;
455474 draftPinned = false ;
@@ -499,6 +518,7 @@ private void AskDeleteDraft()
499518 private void DeleteShortcut ( Guid id )
500519 {
501520 store . Remove ( id ) ;
521+ DiscardUnsavedIcon ( ) ;
502522 draft = null ;
503523 draftId = Guid . Empty ;
504524 router . Reset ( ) ;
@@ -607,7 +627,8 @@ private void DrawGlyphSection(ShortcutEntry entry, float scale)
607627 {
608628 ui . SectionLabel ( Loc . T ( L . Shortcuts . Symbol ) , TextStyles . FootnoteEmphasized , 6f ) ;
609629 var usesPluginIcon = entry . IconPlugin . Length > 0 ;
610- DrawIconPluginRow ( entry , usesPluginIcon , scale ) ;
630+ var usesCustomIcon = entry . IconImage . Length > 0 ;
631+ DrawIconSourceRows ( entry , usesPluginIcon , usesCustomIcon , scale ) ;
611632
612633 var origin = ImGui . GetCursorScreenPos ( ) ;
613634 var width = ImGui . GetContentRegionAvail ( ) . X ;
@@ -644,29 +665,44 @@ private void DrawGlyphSection(ShortcutEntry entry, float scale)
644665
645666 if ( UiInteract . HoverClick ( min , max ) )
646667 {
668+ var unsavedIcon = UnsavedIconOf ( entry ) ;
669+ if ( unsavedIcon . Length > 0 )
670+ {
671+ store . ReleaseIcon ( unsavedIcon ) ;
672+ }
673+
647674 entry . Glyph = glyph ;
648675 entry . IconPlugin = string . Empty ;
676+ entry . IconImage = string . Empty ;
649677 }
650678 }
651679
652680 ImGui . SetCursorScreenPos ( origin ) ;
653681 ImGui . Dummy ( new Vector2 ( width , rows * cell ) ) ;
654682 }
655683
656- private void DrawIconPluginRow ( ShortcutEntry entry , bool usesPluginIcon , float scale )
684+ private void DrawIconSourceRows ( ShortcutEntry entry , bool usesPluginIcon , bool usesCustomIcon , float scale )
657685 {
658- var card = GroupCard . Begin ( theme , 1 , Metrics . Size . Row ) ;
659- var value = usesPluginIcon
686+ var card = GroupCard . Begin ( theme , 2 , Metrics . Size . Row ) ;
687+ var pluginValue = usesPluginIcon
660688 ? catalog . DisplayName ( entry . IconPlugin )
661689 : Loc . T ( L . Shortcuts . PluginIconNone ) ;
662- var picked = SettingsRow . Disclosure ( card . NextRow ( ) , Loc . T ( L . Shortcuts . PluginIcon ) , value , theme ,
690+ var pickedPlugin = SettingsRow . Disclosure ( card . NextRow ( ) , Loc . T ( L . Shortcuts . PluginIcon ) , pluginValue , theme ,
663691 "shortcuts.iconPlugin" ) ;
692+ var customValue = usesCustomIcon ? Loc . T ( L . Shortcuts . CustomIcon ) : Loc . T ( L . Shortcuts . PluginIconNone ) ;
693+ var pickedCustom = SettingsRow . Disclosure ( card . NextRow ( ) , Loc . T ( L . Shortcuts . CustomIcon ) , customValue , theme ,
694+ "shortcuts.iconImage" ) ;
664695 card . End ( ) ;
665- if ( picked )
696+ if ( pickedPlugin )
666697 {
667698 OpenPluginPicker ( true ) ;
668699 }
669700
701+ if ( pickedCustom )
702+ {
703+ OpenCustomIconPicker ( ) ;
704+ }
705+
670706 ImGui . Dummy ( new Vector2 ( 0f , Metrics . Space . Md * scale ) ) ;
671707 }
672708}
0 commit comments