|
| 1 | +// about_dialog.mm — About dialog |
| 2 | +// Part of the Notepad++ macOS port modular refactor. |
| 3 | + |
| 4 | +#import <Cocoa/Cocoa.h> |
| 5 | +#include "about_dialog.h" |
| 6 | + |
| 7 | +@interface AboutDialogController : NSObject |
| 8 | +- (void)openRepository:(id)sender; |
| 9 | +@end |
| 10 | + |
| 11 | +@implementation AboutDialogController |
| 12 | +- (void)openRepository:(id)sender |
| 13 | +{ |
| 14 | + [[NSWorkspace sharedWorkspace] openURL: |
| 15 | + [NSURL URLWithString:@"https://github.com/hybridmachine/MacOS-NotePP"]]; |
| 16 | +} |
| 17 | +@end |
| 18 | + |
| 19 | +void showAboutDlg() |
| 20 | +{ |
| 21 | + @autoreleasepool { |
| 22 | + NSPanel* panel = [[NSPanel alloc] |
| 23 | + initWithContentRect:NSMakeRect(0, 0, 400, 360) |
| 24 | + styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
| 25 | + backing:NSBackingStoreBuffered |
| 26 | + defer:NO]; |
| 27 | + [panel setTitle:@"About MacNote++"]; |
| 28 | + [panel center]; |
| 29 | + |
| 30 | + // Keep the controller alive during modal |
| 31 | + AboutDialogController* controller = [[AboutDialogController alloc] init]; |
| 32 | + |
| 33 | + NSView* contentView = [panel contentView]; |
| 34 | + CGFloat y = 310; |
| 35 | + |
| 36 | + // App icon |
| 37 | + NSImage* logo = [NSApp applicationIconImage]; |
| 38 | + if (!logo) |
| 39 | + { |
| 40 | + NSString* dir = [[[NSBundle mainBundle] executablePath] stringByDeletingLastPathComponent]; |
| 41 | + logo = [[NSImage alloc] initWithContentsOfFile:[dir stringByAppendingPathComponent:@"logo.png"]]; |
| 42 | + } |
| 43 | + if (logo) |
| 44 | + { |
| 45 | + NSImageView* iconView = [[NSImageView alloc] initWithFrame:NSMakeRect(168, y - 64, 64, 64)]; |
| 46 | + [iconView setImage:logo]; |
| 47 | + [iconView setImageScaling:NSImageScaleProportionallyUpOrDown]; |
| 48 | + [contentView addSubview:iconView]; |
| 49 | + } |
| 50 | + y -= 80; |
| 51 | + |
| 52 | + // App name |
| 53 | + NSTextField* nameLabel = [NSTextField labelWithString:@"MacNote++"]; |
| 54 | + [nameLabel setFont:[NSFont boldSystemFontOfSize:18]]; |
| 55 | + [nameLabel setAlignment:NSTextAlignmentCenter]; |
| 56 | + [nameLabel setFrame:NSMakeRect(20, y, 360, 24)]; |
| 57 | + [contentView addSubview:nameLabel]; |
| 58 | + y -= 22; |
| 59 | + |
| 60 | + // Version — read from bundle at runtime |
| 61 | + NSString* version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; |
| 62 | + if (!version) version = @"1.0.0"; |
| 63 | + NSString* build = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]; |
| 64 | + NSString* versionStr = build && ![build isEqualToString:version] |
| 65 | + ? [NSString stringWithFormat:@"Version %@ (%@)", version, build] |
| 66 | + : [NSString stringWithFormat:@"Version %@", version]; |
| 67 | + NSTextField* versionLabel = [NSTextField labelWithString:versionStr]; |
| 68 | + [versionLabel setFont:[NSFont systemFontOfSize:13]]; |
| 69 | + [versionLabel setTextColor:[NSColor secondaryLabelColor]]; |
| 70 | + [versionLabel setAlignment:NSTextAlignmentCenter]; |
| 71 | + [versionLabel setFrame:NSMakeRect(20, y, 360, 18)]; |
| 72 | + [contentView addSubview:versionLabel]; |
| 73 | + y -= 28; |
| 74 | + |
| 75 | + // Attribution |
| 76 | + NSTextField* creditLabel = [NSTextField labelWithString:@"Based on Notepad++ by Don Ho"]; |
| 77 | + [creditLabel setFont:[NSFont systemFontOfSize:13]]; |
| 78 | + [creditLabel setAlignment:NSTextAlignmentCenter]; |
| 79 | + [creditLabel setFrame:NSMakeRect(20, y, 360, 18)]; |
| 80 | + [contentView addSubview:creditLabel]; |
| 81 | + y -= 30; |
| 82 | + |
| 83 | + // Separator |
| 84 | + NSBox* separator = [[NSBox alloc] initWithFrame:NSMakeRect(40, y, 320, 1)]; |
| 85 | + [separator setBoxType:NSBoxSeparator]; |
| 86 | + [contentView addSubview:separator]; |
| 87 | + y -= 24; |
| 88 | + |
| 89 | + // Component versions |
| 90 | + NSTextField* compLabel = [NSTextField labelWithString: |
| 91 | + @"Scintilla 5.5.3 \u2022 Lexilla 5.4.0 \u2022 Boost.Regex 1.90.0"]; |
| 92 | + [compLabel setFont:[NSFont systemFontOfSize:11]]; |
| 93 | + [compLabel setTextColor:[NSColor tertiaryLabelColor]]; |
| 94 | + [compLabel setAlignment:NSTextAlignmentCenter]; |
| 95 | + [compLabel setFrame:NSMakeRect(20, y, 360, 16)]; |
| 96 | + [contentView addSubview:compLabel]; |
| 97 | + y -= 22; |
| 98 | + |
| 99 | + // Build date |
| 100 | + NSString* buildDate = [NSString stringWithFormat:@"Built: %s", __DATE__]; |
| 101 | + NSTextField* buildLabel = [NSTextField labelWithString:buildDate]; |
| 102 | + [buildLabel setFont:[NSFont systemFontOfSize:11]]; |
| 103 | + [buildLabel setTextColor:[NSColor tertiaryLabelColor]]; |
| 104 | + [buildLabel setAlignment:NSTextAlignmentCenter]; |
| 105 | + [buildLabel setFrame:NSMakeRect(20, y, 360, 16)]; |
| 106 | + [contentView addSubview:buildLabel]; |
| 107 | + y -= 28; |
| 108 | + |
| 109 | + // Repository link (clickable button styled as link) |
| 110 | + NSButton* linkButton = [[NSButton alloc] initWithFrame:NSMakeRect(60, y, 280, 20)]; |
| 111 | + [linkButton setTitle:@"github.com/hybridmachine/MacOS-NotePP"]; |
| 112 | + [linkButton setBezelStyle:NSBezelStyleInline]; |
| 113 | + [linkButton setBordered:NO]; |
| 114 | + [linkButton setTarget:controller]; |
| 115 | + [linkButton setAction:@selector(openRepository:)]; |
| 116 | + NSMutableAttributedString* linkAttr = [[NSMutableAttributedString alloc] |
| 117 | + initWithString:@"github.com/hybridmachine/MacOS-NotePP"]; |
| 118 | + [linkAttr addAttribute:NSForegroundColorAttributeName |
| 119 | + value:[NSColor linkColor] |
| 120 | + range:NSMakeRange(0, linkAttr.length)]; |
| 121 | + [linkAttr addAttribute:NSUnderlineStyleAttributeName |
| 122 | + value:@(NSUnderlineStyleSingle) |
| 123 | + range:NSMakeRange(0, linkAttr.length)]; |
| 124 | + [linkAttr addAttribute:NSFontAttributeName |
| 125 | + value:[NSFont systemFontOfSize:11] |
| 126 | + range:NSMakeRange(0, linkAttr.length)]; |
| 127 | + [linkButton setAttributedTitle:linkAttr]; |
| 128 | + [linkButton setAlignment:NSTextAlignmentCenter]; |
| 129 | + [contentView addSubview:linkButton]; |
| 130 | + y -= 24; |
| 131 | + |
| 132 | + // License |
| 133 | + NSTextField* licenseLabel = [NSTextField labelWithString:@"GNU General Public License v3"]; |
| 134 | + [licenseLabel setFont:[NSFont systemFontOfSize:11]]; |
| 135 | + [licenseLabel setTextColor:[NSColor secondaryLabelColor]]; |
| 136 | + [licenseLabel setAlignment:NSTextAlignmentCenter]; |
| 137 | + [licenseLabel setFrame:NSMakeRect(20, y, 360, 16)]; |
| 138 | + [contentView addSubview:licenseLabel]; |
| 139 | + |
| 140 | + // OK button |
| 141 | + NSButton* okButton = [[NSButton alloc] initWithFrame:NSMakeRect(160, 12, 80, 32)]; |
| 142 | + [okButton setTitle:@"OK"]; |
| 143 | + [okButton setBezelStyle:NSBezelStyleRounded]; |
| 144 | + [okButton setTarget:NSApp]; |
| 145 | + [okButton setAction:@selector(stopModal)]; |
| 146 | + [okButton setKeyEquivalent:@"\r"]; |
| 147 | + [contentView addSubview:okButton]; |
| 148 | + |
| 149 | + // Also handle Escape to close |
| 150 | + [panel setDefaultButtonCell:[okButton cell]]; |
| 151 | + |
| 152 | + [NSApp runModalForWindow:panel]; |
| 153 | + [panel close]; |
| 154 | + |
| 155 | + // prevent ARC from releasing controller during modal |
| 156 | + (void)controller; |
| 157 | + } |
| 158 | +} |
0 commit comments