Added second image store to retrieve SF symbols on supported systems

This commit is contained in:
Michael Starke
2021-02-03 16:55:43 +01:00
parent 51f3d6627f
commit d0f8c3eafb
2 changed files with 125 additions and 10 deletions

View File

@@ -132,6 +132,8 @@ typedef NS_ENUM(NSUInteger, MPIconType) {
*/
@property (class, nonatomic, strong, readonly) NSDictionary *availableIconNames;
@property (class, nonatomic, strong, readonly) NSDictionary *availableSymbolNames;
/**
* List of all available DatabaseIcons as an array of Images. Sorted by IconIndex.
* @return Array of Icons as NSImage objects

View File

@@ -24,18 +24,35 @@
#import "MPSettingsHelper.h"
#import "KeePassKit/KeePassKit.h"
@implementation MPIconHelper
+ (NSImage *)icon:(MPIconType)type {
static NSDictionary *symbols;
if(!symbols) {
symbols = MPIconHelper.availableSymbolNames;
}
if([symbols.allKeys containsObject:@(type)]) {
NSString *imageName = symbols[@(type)];
NSImage *image = [NSImage imageWithSystemSymbolName:imageName accessibilityDescription:nil];
if(image) {
return image;
}
}
static NSDictionary *icons;
if(!icons) {
icons = MPIconHelper.availableIconNames;
}
if([icons.allKeys containsObject:@(type)]) {
NSString *imageName = icons[@(type)];
NSImage *image = [NSImage imageNamed:imageName];
if(image) {
return image;
}
}
return [NSImage imageNamed:NSImageNameActionTemplate];
}
@@ -81,6 +98,102 @@
return iconTypes;
}
+ (NSDictionary *)availableSymbolNames {
static NSDictionary *symbolNames;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
symbolNames = @{
@(MPIconPassword): @"ellipsis.rectangle",
@(MPIconPackageNetwork): @"globe",
@(MPIconWarning): @"exclamationmark.circle",
@(MPIconServer): @"macpro.gen3.server",
@(MPIconKlipper): @"paperclip",
@(MPIconLanguages): @"mouth",
@(MPIconBlockDevice): @"06_BlockDeviceTemplate",
@(MPIconNotepad): @"07_NotepadTemplate",
@(MPIconSocket): @"08_SocketTemplate",
@(MPIconIdentity): @"09_IdentityTemplate",
@(MPIconContact): @"10_ContactTemplate",
@(MPIconCamera): @"11_CameraTemplate",
@(MPIconRemote): @"12_RemoteTemplate",
@(MPIconKeys): @"key",
@(MPIconBattery): @"14_BatteryTemplate",
@(MPIconScanner): @"15_ScannerTemplate",
@(MPIconBrowser): @"16_BrowserTemplate",
@(MPIconCDRom): @"17_CDRomTemplate",
@(MPIconDisplay): @"18_DisplayTemplate",
@(MPIconEmail): @"19_EmailTemplate",
@(MPIconMisc): @"20_MiscTemplate",
@(MPIconOrganizer): @"21_OrganizerTemplate",
@(MPIconASCII): @"22_ASCIITemplate",
@(MPIconIcons): @"23_IconsTemplate",
@(MPIconEstablishedConnection): @"24_EstablishedConnectionTemplate",
@(MPIconMailFolder): @"25_MailFolderTemplate",
@(MPIconFileSave): @"26_FileSaveTemplate",
@(MPIconNFSUnmount) :@"27_NFSUnmountTemplate",
@(MPIconQuickTime) : @"28_QuickTimeTemplate",
@(MPIconSecureTerminal) : @"29_SecureTerminalTemplate",
@(MPIconTerminal) : @"30_TerminalTemplate",
@(MPIconPrint) : @"31_PrintTemplate",
@(MPIconFileSystemView) : @"32_FileSystemViewTemplate",
@(MPIconRun) : @"33_RunTemplate",
@(MPIconConfigure) : @"34_ConfigureTemplate",
@(MPIconBrowserWindow) : @"35_BrowserWindowTemplate",
@(MPIconArchive) : @"36_ArchiveTemplate",
@(MPIconPercentage) : @"37_PercentageTemplate",
@(MPIconSambaUnmount) : @"38_SambaUnmountTemplate",
@(MPIconHistory) : @"39_HistoryTemplate",
@(MPIconFindMail) : @"40_FindMailTemplate",
@(MPIconVector) : @"41_VectorTemplate",
@(MPIconMemory) : @"42_MemoryTemplate",
@(MPIconTrash): @"43_TrashTemplate",
@(MPIconNotes) : @"44_NotesTemplate",
@(MPIconCancel) : @"45_CancelTemplate",
@(MPIconHelp) : @"46_HelpTemplate",
@(MPIconPackage) : @"47_PackageTemplate",
@(MPIconFolder): @"48_FolderTemplate",
@(MPIconFolderOpen) : @"49_FolderOpenTemplate",
@(MPIconFolderTar) : @"50_FolderTarTemplate",
@(MPIconDecrypted) : @"51_DecryptedTemplate",
@(MPIconEncrypted) : @"52_EncryptedTemplate",
@(MPIconApply) : @"53_ApplyTemplate",
@(MPIconSignature) : @"54_SignatureTemplate",
@(MPIconThumbnail) : @"55_ThumbnailTemplate",
@(MPIconAddressBook) : @"56_AddressBookTemplate",
@(MPIconTextView) : @"57_TextViewTemplate",
@(MPIconSecureAccount) : @"58_SecureAccountTemplate",
@(MPIconDevelopment) : @"59_DevelopmentTemplate",
@(MPIconHome) : @"60_HomeTemplate",
@(MPIconServices) : @"61_ServicesTemplate",
@(MPIconTux) : @"62_TuxTemplate",
@(MPIconFeather) : @"63_FeatherTemplate",
@(MPIconApple) : @"64_AppleTemplate",
@(MPIconWiki) : @"65_WikiTemplate",
@(MPIconMoney) : @"66_MoneyTemplate",
@(MPIconCertificat) : @"67_CertificatTemplate",
@(MPIconPhone): @"68_PhoneTemplate",
/* Custom */
@(MPIconInfo): @"sidebar.trailing",
@(MPIconAddFolder): @"addFolderTemplate",
@(MPIconHardDisk): @"harddiskTemplate",
@(MPIconCreated): @"createdTemplate",
@(MPIconAddEntry): @"addEntryTemplate",
@(MPIconContextTriangle): @"contextTriangleTemplate",
@(MPIconKeyboard): @"keyboardTemplate",
@(MPIconExpiredEntry): NSImageNameCaution,
@(MPIconExpiredGroup): NSImageNameCaution
};
});
if(@available(macOS 11.0, *)) {
return symbolNames;
}
else {
return nil;
}
}
+ (NSDictionary *)availableIconNames {
static NSDictionary *imageNames;