-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppController.m
More file actions
executable file
·2084 lines (1646 loc) · 80.6 KB
/
Copy pathAppController.m
File metadata and controls
executable file
·2084 lines (1646 loc) · 80.6 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*Copyright (c) 2010, Zachary Schneirov. All rights reserved.
This file is part of Notational Velocity.
Notational Velocity is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Notational Velocity is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Notational Velocity. If not, see <http://www.gnu.org/licenses/>. */
#import "AppController.h"
#import "KNAlert.h"
#import "NoteObject.h"
#import "GlobalPrefs.h"
#import "AlienNoteImporter.h"
#import "KNMigrationController.h"
#import "AppController_Importing.h"
#import "NotationPrefs.h"
#import "PrefsWindowController.h"
#import "NoteAttributeColumn.h"
#import "NotationSyncServiceManager.h"
#import "NotationDirectoryManager.h"
#import "NotationFileManager.h"
#import "NSString_NV.h"
#import "NSFileManager_NV.h"
#import "EncodingsManager.h"
#import "ExporterManager.h"
#import "ExternalEditorListController.h"
#import "NSData_transformations.h"
#import "BufferUtils.h"
#import "LinkingEditor.h"
#import "EmptyView.h"
#import "DualField.h"
#import "TitlebarButton.h"
#import "RBSplitView/RBSplitView.h"
#import "AugmentedScrollView.h"
#import "BookmarksController.h"
#import "SyncSessionController.h"
#import "MultiplePageView.h"
#import "InvocationRecorder.h"
#import "LinearDividerShader.h"
#import "SecureTextEntryManager.h"
#import "NSString_CustomTruncation.h"
#import "KNSupportController.h"
#import "KNUpdateController.h"
//where the Help menu's "Kinetic Notes Web Site" item points
static NSString *KNProductSiteURLString = @"https://www.kineticnotes.org";
//where its "Development Web Site" item points; update alongside the repository if it moves
static NSString *KNProjectURLString = @"https://github.com/jptechco/kn";
@implementation AppController
//an instance of this class is designated in the nib as the delegate of the window, nstextfield and two nstextviews
- (id)init {
if ([super init]) {
windowUndoManager = [[NSUndoManager alloc] init];
// Setup URL Handling
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
dividerShader = [[LinearDividerShader alloc] initWithStartColor:[NSColor colorWithCalibratedWhite:0.988 alpha:1.0]
endColor:[NSColor colorWithCalibratedWhite:0.875 alpha:1.0]];
isCreatingANote = isFilteringFromTyping = typedStringIsCached = NO;
typedString = @"";
}
return self;
}
- (void)awakeFromNib {
prefsController = [GlobalPrefs defaultPrefs];
[NSColor setIgnoresAlpha:NO];
NSView *dualSV = [field superview];
dualFieldItem = [[NSToolbarItem alloc] initWithItemIdentifier:@"DualField"];
//[[dualSV superview] setFrameSize:NSMakeSize([[dualSV superview] frame].size.width, [[dualSV superview] frame].size.height -1)];
[dualFieldItem setView:dualSV];
[dualFieldItem setMaxSize:NSMakeSize(FLT_MAX, [dualSV frame].size.height)];
[dualFieldItem setMinSize:NSMakeSize(50.0f, [dualSV frame].size.height)];
[dualFieldItem setLabel:NSLocalizedString(@"Search or Create", @"placeholder text in search/create field")];
toolbar = [[NSToolbar alloc] initWithIdentifier:@"NVToolbar"];
[toolbar setAllowsUserCustomization:NO];
[toolbar setAutosavesConfiguration:NO];
[toolbar setDisplayMode:NSToolbarDisplayModeIconOnly];
// [toolbar setSizeMode:NSToolbarSizeModeRegular];
[toolbar setShowsBaselineSeparator:YES];
[toolbar setVisible:![[NSUserDefaults standardUserDefaults] boolForKey:@"ToolbarHidden"]];
[toolbar setDelegate:self];
[window setToolbar:toolbar];
[self _applyTitleBarLayout];
//so a scheduled check can put its "Update Available" indicator here instead of interrupting
[[KNUpdateController sharedInstance] setToolbar:toolbar];
[window setShowsToolbarButton:NO];
titleBarButton = [[TitlebarButton alloc] initWithFrame:NSMakeRect(0, 0, 17.0, 17.0) pullsDown:YES];
[titleBarButton addToWindow:window];
[NSApp setDelegate:self];
[notesTableView setDelegate:self];
[window setDelegate:self];
[field setDelegate:self];
[textView setDelegate:self];
[splitView setDelegate:self];
//set up temporary FastListDataSource containing false visible notes
//this will not make a difference
[window useOptimizedDrawing:YES];
//[window makeKeyAndOrderFront:self];
//[self setEmptyViewState:YES];
outletObjectAwoke(self);
}
//really need make AppController a subclass of NSWindowController and stick this junk in windowDidLoad
- (void)setupViewsAfterAppAwakened {
static BOOL awakenedViews = NO;
if (!awakenedViews) {
//NSLog(@"all (hopefully relevant) views awakend!");
[self _configureDividerForCurrentLayout];
[splitView restoreState:YES];
[splitSubview addSubview:editorStatusView positioned:NSWindowAbove relativeTo:splitSubview];
[editorStatusView setFrame:[[textView enclosingScrollView] frame]];
[notesTableView restoreColumns];
[field setNextKeyView:textView];
[textView setNextKeyView:field];
[window setAutorecalculatesKeyViewLoop:NO];
[self setEmptyViewState:YES];
//this is necessary on 10.3; keep just in case
[splitView display];
awakenedViews = YES;
}
}
//what a hack
void outletObjectAwoke(id sender) {
static NSMutableSet *awokenOutlets = nil;
if (!awokenOutlets) awokenOutlets = [[NSMutableSet alloc] initWithCapacity:5];
[awokenOutlets addObject:sender];
AppController* appDelegate = (AppController*)[NSApp delegate];
if (appDelegate && [awokenOutlets containsObject:appDelegate] &&
[awokenOutlets containsObject:appDelegate->notesTableView] &&
[awokenOutlets containsObject:appDelegate->textView] &&
[awokenOutlets containsObject:appDelegate->editorStatusView] &&
[awokenOutlets containsObject:appDelegate->splitView]) {
[appDelegate setupViewsAfterAppAwakened];
}
}
//MainMenu.nib is in the Interface Builder 3 format and cannot safely be re-saved by a modern Xcode,
//so the old product name is still baked into several menu titles and the window title. Rather than
//touch the nib, substitute the bundle's name at launch wherever the old one was hard-coded.
//Known occurrences: the application menu and its About/Hide/Quit items, and "... Web Site" in Help.
static void RenameMenuTreeFromOldNameToNew(NSMenu *menu, NSString *oldName, NSString *newName) {
if ([[menu title] rangeOfString:oldName].location != NSNotFound)
[menu setTitle:[[menu title] stringByReplacingOccurrencesOfString:oldName withString:newName]];
NSInteger i = 0;
for (i = 0; i < [menu numberOfItems]; i++) {
NSMenuItem *item = [menu itemAtIndex:i];
if ([[item title] rangeOfString:oldName].location != NSNotFound)
[item setTitle:[[item title] stringByReplacingOccurrencesOfString:oldName withString:newName]];
//the Help and Window menus are populated by AppKit, but everything else nests through here
if ([item hasSubmenu])
RenameMenuTreeFromOldNameToNew([item submenu], oldName, newName);
}
}
//CFBundleName: the name -applyApplicationNameToInterface substitutes into the nib-authored menu
//titles at launch, and the name the window reverts to when the toolbar is shown again
- (NSString*)applicationName {
return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
}
- (void)applyApplicationNameToInterface {
NSString *appName = [self applicationName];
if (![appName length]) return;
//AppKit draws the name in the menu bar from the first item of the main menu, not from its
//submenu, so walking the whole tree covers that along with everything nested below it
RenameMenuTreeFromOldNameToNew([NSApp mainMenu], @"Notational Velocity", appName);
[window setTitle:appName];
}
- (void)runDelayedUIActionsAfterLaunch {
[[prefsController bookmarksController] setAppController:self];
[[prefsController bookmarksController] restoreWindowFromSave];
[[prefsController bookmarksController] updateBookmarksUI];
[self updateNoteMenus];
[textView setupFontMenu];
[prefsController registerAppActivationKeystrokeWithTarget:self selector:@selector(toggleNVActivation:)];
[notationController updateLabelConnectionsAfterDecoding];
[notationController checkIfNotationIsTrashed];
[[SecureTextEntryManager sharedInstance] checkForIncompatibleApps];
//MainMenu.nib's "Check for Updates..." item has neither target nor action -- the nib is Interface
//Builder 3 format and is never re-saved. KNUpdateController gives it both, retitles it, and starts
//Sparkle. Here rather than in -applicationDidFinishLaunching:, which can still put up the
//first-run import dialogs or the notes-folder open panel, or terminate outright.
[[KNUpdateController sharedInstance] installInMenuItem:sparkleUpdateItem];
[NSApp setServicesProvider:self];
}
//Runs on a genuine first launch only. Detects an existing Notational Velocity notes directory and,
//with the user's consent, copies it into place as Kinetic Notes' own database. Notational Velocity's
//data is only ever read; see KNMigrationController for the safety invariants. An encrypted database
//is committed as-is and unlocked by the normal passphrase prompt when the notes directory is opened
//just below -- Kinetic Notes uses its own keychain service, so nothing NV relies on is touched.
- (void)importFromNotationalVelocityIfFirstRun {
if (![KNMigrationController isFirstRun]) return;
NSString *source = [KNMigrationController detectedNotationalVelocityDirectory];
//nil source is fine: the user can still point us at a folder, or start fresh
//the offer repeats if the user chooses a different folder, so it is a loop
while (YES) {
//a database being written by a running NV could be copied mid-write
while ([KNMigrationController isNotationalVelocityRunning]) {
NSAlert *runningAlert = [[[NSAlert alloc] init] autorelease];
[runningAlert setMessageText:NSLocalizedString(@"Quit Notational Velocity to import your notes", nil)];
[runningAlert setInformativeText:NSLocalizedString(@"Notational Velocity is running. Please quit it so its notes can be copied safely, then click Retry.", nil)];
[runningAlert addButtonWithTitle:NSLocalizedString(@"Retry", nil)];
[runningAlert addButtonWithTitle:NSLocalizedString(@"Skip Import", nil)];
if ([runningAlert runModal] != NSAlertFirstButtonReturn) return;
}
NSInteger choice = [self runImportOfferForSource:source];
if (choice == NSAlertSecondButtonReturn) {
//"Choose a Different Folder…" -- pick a folder and re-offer; nil result means they cancelled
NSString *chosen = [self runImportFolderChooser];
if (chosen) source = chosen;
continue;
}
if (choice != NSAlertFirstButtonReturn) return; //"Start Fresh"
if ([self performImportFromSource:source]) return;
//an import failure leaves everything recoverable; drop back to the offer so the user can retry
}
}
//Builds and runs the import offer. Shows the note count when it can be determined cheaply (an
//unencrypted database) and notes when the database is encrypted. Returns the NSAlert button constant.
- (NSInteger)runImportOfferForSource:(NSString*)source {
BOOL haveSource = [source length] != 0;
NSMutableString *info = [NSMutableString string];
if (haveSource) {
NSInteger count = [KNMigrationController noteCountInDirectory:source];
if (count > 0)
[info appendFormat:NSLocalizedString(@"Kinetic Notes found %ld notes from Notational Velocity in:\n%@\n\n", nil),
(long)count, [source stringByAbbreviatingWithTildeInPath]];
else
[info appendFormat:NSLocalizedString(@"Kinetic Notes found Notational Velocity notes in:\n%@\n\n", nil),
[source stringByAbbreviatingWithTildeInPath]];
[info appendString:NSLocalizedString(@"Your notes are copied, not moved. Notational Velocity will keep working exactly as it does now.", nil)];
} else {
[info appendString:NSLocalizedString(@"Kinetic Notes didn't find a Notational Velocity notes folder automatically. If you have one, you can choose it; otherwise start with an empty database.", nil)];
}
NSAlert *offer = [[[NSAlert alloc] init] autorelease];
[offer setMessageText:haveSource ?
NSLocalizedString(@"Import your notes from Notational Velocity?", nil) :
NSLocalizedString(@"Import notes from Notational Velocity?", nil)];
[offer setInformativeText:info];
//keep the button order stable so the returned constants are meaningful: first/second/third
[offer addButtonWithTitle:haveSource ? NSLocalizedString(@"Import", nil) : NSLocalizedString(@"Import…", nil)];
[offer addButtonWithTitle:NSLocalizedString(@"Choose a Different Folder…", nil)];
[offer addButtonWithTitle:NSLocalizedString(@"Start Fresh", nil)];
NSInteger result = [offer runModal];
//with no detected source, "Import" has nothing to import, so treat it as "choose a folder"
if (!haveSource && result == NSAlertFirstButtonReturn) return NSAlertSecondButtonReturn;
return result;
}
//Runs an open panel for the user to pick a Notational Velocity notes folder. Returns the chosen path,
//or nil if they cancelled or the folder holds no database.
- (NSString*)runImportFolderChooser {
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setCanChooseFiles:NO];
[panel setCanChooseDirectories:YES];
[panel setAllowsMultipleSelection:NO];
[panel setPrompt:NSLocalizedString(@"Choose", nil)];
[panel setMessage:NSLocalizedString(@"Choose the Notational Velocity notes folder to import from.", nil)];
if ([panel runModal] != NSModalResponseOK) return nil;
NSString *chosen = [[panel URL] path];
NSError *error = nil;
if (![KNMigrationController verifyDatabaseInDirectory:chosen isEncrypted:NULL error:&error]) {
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText:NSLocalizedString(@"That folder doesn't contain Notational Velocity notes", nil)];
[alert setInformativeText:NSLocalizedString(@"Choose the folder that contains the \"Notes & Settings\" database.", nil)];
[alert addButtonWithTitle:NSLocalizedString(@"OK", nil)];
[alert runModal];
return nil;
}
return chosen;
}
//Stages, verifies and commits the copy. Returns YES when the import is committed (or when there is
//nothing to import and the user asked to start fresh), NO when a failure should drop back to the offer.
- (BOOL)performImportFromSource:(NSString*)source {
if (![source length]) return YES; //nothing to import: fall through to a normal empty first run
NSError *error = nil;
NSString *staged = [KNMigrationController stageImportFromDirectory:source error:&error];
if (!staged) { [self presentMigrationError:error]; return NO; }
BOOL isEncrypted = NO;
if (![KNMigrationController verifyDatabaseInDirectory:staged isEncrypted:&isEncrypted error:&error]) {
//leave the staged copy in place for inspection; nothing has replaced the live directory
[self presentMigrationError:error];
return NO;
}
//count before committing, while the copy is still plainly readable (unencrypted only)
NSInteger importedCount = [KNMigrationController noteCountInDirectory:staged];
NSString *committed = [KNMigrationController commitStagedImport:staged error:&error];
if (!committed) { [self presentMigrationError:error]; return NO; }
//the normal open path below will now open `committed`; if it is encrypted the standard passphrase
//prompt handles unlocking, so warn the user to expect it and to have their NV passphrase ready
if (isEncrypted) {
NSAlert *encryptedNote = [[[NSAlert alloc] init] autorelease];
[encryptedNote setMessageText:NSLocalizedString(@"Your imported notes are encrypted", nil)];
[encryptedNote setInformativeText:NSLocalizedString(@"Kinetic Notes will now ask for the passphrase you used in Notational Velocity.", nil)];
[encryptedNote addButtonWithTitle:NSLocalizedString(@"Continue", nil)];
[encryptedNote runModal];
} else {
[self presentImportSummaryForSource:source destination:committed noteCount:importedCount];
}
return YES;
}
//A short confirmation after a successful unencrypted import. (Encrypted imports get the passphrase
//prompt instead; the notes appear once it is entered.)
- (void)presentImportSummaryForSource:(NSString*)source destination:(NSString*)destination noteCount:(NSInteger)noteCount {
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText:NSLocalizedString(@"Your notes were imported", nil)];
NSString *countLine = (noteCount > 0) ?
[NSString stringWithFormat:NSLocalizedString(@"%ld notes were copied into Kinetic Notes.\n\n", nil), (long)noteCount] :
NSLocalizedString(@"Your notes were copied into Kinetic Notes.\n\n", nil);
[alert setInformativeText:[countLine stringByAppendingString:
NSLocalizedString(@"Notational Velocity's notes in their original folder were not changed.", nil)]];
[alert addButtonWithTitle:NSLocalizedString(@"OK", nil)];
[alert runModal];
}
- (void)presentMigrationError:(NSError*)error {
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setAlertStyle:NSAlertStyleWarning];
[alert setMessageText:NSLocalizedString(@"Your notes could not be imported", nil)];
NSString *reason = [error localizedDescription];
[alert setInformativeText:[NSString stringWithFormat:
NSLocalizedString(@"%@\n\nNotational Velocity's notes were not changed. Kinetic Notes will start with an empty database; you can try importing again by removing its notes folder.", nil),
reason ?: NSLocalizedString(@"An unexpected error occurred.", nil)]];
[alert addButtonWithTitle:NSLocalizedString(@"OK", nil)];
[alert runModal];
}
- (void)applicationDidFinishLaunching:(NSNotification*)aNote {
//has to happen here rather than in -awakeFromNib: MainMenu.nib is still loading at that point,
//so -[NSApp mainMenu] is not yet set
[self applyApplicationNameToInterface];
//honor a saved Appearance override (Force Dark/Force Light) before any window is shown
[self applyAppearanceMode];
//after the rename above, which walks every existing menu title looking for the old product name
[[KNSupportController sharedInstance] installMenuItemInMainMenu];
//before any notes directory is opened: on a genuine first run, offer to import from an existing
//Notational Velocity installation. A successful import commits into Kinetic Notes' own directory,
//which the normal open path below then picks up.
[self importFromNotationalVelocityIfFirstRun];
//on tiger dualfield is often not ready to add tracking tracks until this point:
[field setTrackingRect];
NSDate *before = [NSDate date];
prefsWindowController = [[PrefsWindowController alloc] init];
OSStatus err = noErr;
NotationController *newNotation = nil;
NSData *bookmarkData = [prefsController bookmarkDataForDefaultDirectory];
NSData *legacyAliasData = bookmarkData ? nil : [prefsController legacyAliasDataForDefaultDirectory];
NSString *subMessage = @"";
//if the option key is depressed, go straight to picking a new notes folder location
if (kCGEventFlagMaskAlternate == (CGEventSourceFlagsState(kCGEventSourceStateCombinedSessionState) & NSDeviceIndependentModifierFlagsMask)) {
goto showOpenPanel;
}
if (bookmarkData) {
newNotation = [[NotationController alloc] initWithBookmarkData:bookmarkData error:&err];
subMessage = NSLocalizedString(@"Please choose a different folder in which to store your notes.",nil);
} else if (legacyAliasData) {
//recorded before the move to bookmarks; opening it is what converts it
newNotation = [[NotationController alloc] initWithLegacyAliasData:legacyAliasData error:&err];
subMessage = NSLocalizedString(@"Please choose a different folder in which to store your notes.",nil);
} else {
newNotation = [[NotationController alloc] initWithDefaultDirectoryReturningError:&err];
subMessage = NSLocalizedString(@"Please choose a folder in which your notes will be stored.",nil);
}
//no need to display an alert if the error wasn't real
if (err == kPassCanceledErr)
goto showOpenPanel;
NSString *location = (bookmarkData || legacyAliasData) ? [prefsController pathForDefaultDirectoryIsStale:NULL]
: NSLocalizedString(@"your Application Support directory",nil);
if (!location) location = NSLocalizedString(@"its current location",nil);
while (!newNotation) {
location = [location stringByAbbreviatingWithTildeInPath];
NSString *reason = [NSString reasonStringFromCarbonFSError:err];
if (KNRunAlert([NSString stringWithFormat:NSLocalizedString(@"Unable to initialize notes database in \n%@ because %@.",nil), location, reason],
subMessage, NSLocalizedString(@"Choose another folder",nil),NSLocalizedString(@"Quit",nil),NULL) == NSAlertFirstButtonReturn) {
//show nsopenpanel, defaulting to current default notes dir
showOpenPanel:
if (!(location = [prefsWindowController newNotesDirectoryFromOpenPanel])) {
//they cancelled the open panel, or it was unable to get the path of the folder
goto terminateApp;
} else if ((newNotation = [[NotationController alloc] initWithDirectoryPath:location error:&err])) {
//have to make sure the bookmark is saved from setNotationController
[newNotation setBookmarkNeedsUpdating:YES];
break;
}
} else {
goto terminateApp;
}
}
[self setNotationController:newNotation];
[newNotation release];
NSLog(@"load time: %g, ",[[NSDate date] timeIntervalSinceDate:before]);
// NSLog(@"version: %s", PRODUCT_NAME);
//import old database(s) here if necessary
[AlienNoteImporter importBlorOrHelpFilesIfNecessaryIntoNotation:newNotation];
if (pathsToOpenOnLaunch) {
[notationController openFiles:[pathsToOpenOnLaunch autorelease]];
pathsToOpenOnLaunch = nil;
}
if (URLToInterpretOnLaunch) {
[self interpretNVURL:[URLToInterpretOnLaunch autorelease]];
URLToInterpretOnLaunch = nil;
}
//tell us..
[prefsController registerWithTarget:self forChangesInSettings:
@selector(setBookmarkDataForDefaultDirectory:sender:), //when someone wants to load a new database
@selector(setSortedTableColumnKey:reversed:sender:), //when sorting prefs changed
@selector(setNoteBodyFont:sender:), //when to tell notationcontroller to restyle its notes
@selector(setForegroundTextColor:sender:), //ditto
@selector(setTableFontSize:sender:), //when to tell notationcontroller to regenerate the (now potentially too-short) note-body previews
@selector(addTableColumn:sender:), //ditto
@selector(removeTableColumn:sender:), //ditto
@selector(setTableColumnsShowPreview:sender:), //when to tell notationcontroller to generate or disable note-body previews
@selector(setConfirmNoteDeletion:sender:), //whether "delete note" should have an ellipsis
@selector(setSideBySideTitleBar:sender:), //whether the search field shares the title's row
@selector(setAppearanceMode:sender:), //when to force the app light/dark or follow the system
@selector(setAutoCompleteSearches:sender:), nil]; //when to tell notationcontroller to build its title-prefix connections
[self performSelector:@selector(runDelayedUIActionsAfterLaunch) withObject:nil afterDelay:0.0];
return;
terminateApp:
[NSApp terminate:self];
}
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
NSURL *fullURL = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]];
if (notationController) {
if (![self interpretNVURL:fullURL])
NSBeep();
} else {
URLToInterpretOnLaunch = [fullURL retain];
}
}
//called by the editor when the system switches between Light and Dark Mode. The notes are owned by
//the notation controller, so it re-applies the (appearance-following) foreground color to their content.
- (void)applyAutomaticTextColorsToNotes {
[notationController makeForegroundTextColorMatchGlobalPrefs];
}
- (void)setNotationController:(NotationController*)newNotation {
if (newNotation) {
if (notationController) {
[notationController closeAllResources];
[[NSNotificationCenter defaultCenter] removeObserver:self name:SyncSessionsChangedVisibleStatusNotification
object:[notationController syncSessionController]];
}
NotationController *oldNotation = notationController;
notationController = [newNotation retain];
if (oldNotation) {
[notesTableView abortEditing];
[prefsController setLastSearchString:[self fieldSearchString] selectedNote:currentNote
scrollOffsetForTableView:notesTableView sender:self];
//if we already had a notation, appController should already be bookmarksController's delegate
[[prefsController bookmarksController] performSelector:@selector(updateBookmarksUI) withObject:nil afterDelay:0.0];
}
[notationController setSortColumn:[notesTableView noteAttributeColumnForIdentifier:[prefsController sortedTableColumnKey]]];
[notesTableView setDataSource:[notationController notesListDataSource]];
[notesTableView setLabelsListSource:[notationController labelsListDataSource]];
[notationController setDelegate:self];
//allow resolution of UUIDs to NoteObjects from saved searches
[[prefsController bookmarksController] setDataSource:notationController];
//update the list using the new notation and saved settings
[self restoreListStateUsingPreferences];
//window's undomanager could be referencing actions from the old notation object
[[window undoManager] removeAllActions];
[notationController setUndoManager:[window undoManager]];
if ([notationController bookmarkNeedsUpdating]) {
[prefsController setBookmarkDataForDefaultDirectory:[notationController bookmarkDataForNoteDirectory] sender:self];
}
if ([prefsController tableColumnsShowPreview] || [prefsController horizontalLayout]) {
[self _forceRegeneratePreviewsForTitleColumn];
[notesTableView setNeedsDisplay:YES];
}
[titleBarButton setMenu:[[notationController syncSessionController] syncStatusMenu]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(syncSessionsChangedVisibleStatus:)
name:SyncSessionsChangedVisibleStatusNotification
object:[notationController syncSessionController]];
//these should probably be triggered from within NotationController:
[notationController performSelector:@selector(startSyncServices) withObject:nil afterDelay:0.0];
if ([[notationController notationPrefs] secureTextEntry]) {
[[SecureTextEntryManager sharedInstance] enableSecureTextEntry];
} else {
[[SecureTextEntryManager sharedInstance] disableSecureTextEntry];
}
[field selectText:nil];
[oldNotation autorelease];
}
}
- (BOOL)applicationOpenUntitledFile:(NSApplication *)sender {
if (![prefsController quitWhenClosingWindow]) {
[self bringFocusToControlField:nil];
return YES;
}
return NO;
}
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag {
if ([itemIdentifier isEqualToString:KNUpdateToolbarItemIdentifier])
return [[KNUpdateController sharedInstance] updateToolbarItem];
return [itemIdentifier isEqualToString:@"DualField"] ? dualFieldItem : nil;
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)theToolbar {
//the update indicator is allowed but not default: it is inserted only when a scheduled check has
//actually found something, and removed again once the user has dealt with it
return [NSArray arrayWithObjects:@"DualField", KNUpdateToolbarItemIdentifier, nil];
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)theToolbar {
return [NSArray arrayWithObject:@"DualField"];
}
- (BOOL)validateMenuItem:(NSMenuItem*)menuItem {
SEL selector = [menuItem action];
int numberSelected = [notesTableView numberOfSelectedRows];
if (selector == @selector(printNote:) ||
selector == @selector(deleteNote:) ||
selector == @selector(exportNote:) ||
selector == @selector(tagNote:)) {
return (numberSelected > 0);
} else if (selector == @selector(renameNote:) ||
selector == @selector(copyNoteLink:)) {
return (numberSelected == 1);
} else if (selector == @selector(revealNote:)) {
return (numberSelected == 1) && [notationController currentNoteStorageFormat] != SingleDatabaseFormat;
} else if (selector == @selector(fixFileEncoding:)) {
return (currentNote != nil && storageFormatOfNote(currentNote) == PlainTextFormat && ![currentNote contentsWere7Bit]);
} else if (selector == @selector(editNoteExternally:)) {
return (numberSelected > 0) && [[menuItem representedObject] canEditAllNotes:
[notationController notesAtIndexes:[notesTableView selectedRowIndexes]]];
}
return YES;
}
- (void)updateNoteMenus {
NSMenu *notesMenu = [[[NSApp mainMenu] itemWithTag:NOTES_MENU_ID] submenu];
int menuIndex = [notesMenu indexOfItemWithTarget:self andAction:@selector(deleteNote:)];
NSMenuItem *deleteItem = nil;
if (menuIndex > -1 && (deleteItem = [notesMenu itemAtIndex:menuIndex])) {
NSString *trailingQualifier = [prefsController confirmNoteDeletion] ? NSLocalizedString(@"...", @"ellipsis character") : @"";
[deleteItem setTitle:[NSString stringWithFormat:@"%@%@",
NSLocalizedString(@"Delete", nil), trailingQualifier]];
}
[notesMenu setSubmenu:[[ExternalEditorListController sharedInstance] addEditNotesMenu] forItem:[notesMenu itemWithTag:88]];
NSMenu *viewMenu = [[[NSApp mainMenu] itemWithTag:VIEW_MENU_ID] submenu];
menuIndex = [viewMenu indexOfItemWithTarget:notesTableView andAction:@selector(toggleNoteBodyPreviews:)];
NSMenuItem *bodyPreviewItem = nil;
if (menuIndex > -1 && (bodyPreviewItem = [viewMenu itemAtIndex:menuIndex])) {
[bodyPreviewItem setTitle: [prefsController tableColumnsShowPreview] ?
NSLocalizedString(@"Hide Note Previews in Title", @"menu item in the View menu to turn off note-body previews in the Title column") :
NSLocalizedString(@"Show Note Previews in Title", @"menu item in the View menu to turn on note-body previews in the Title column")];
}
menuIndex = [viewMenu indexOfItemWithTarget:self andAction:@selector(switchViewLayout:)];
NSMenuItem *switchLayoutItem = nil;
if (menuIndex > -1 && (switchLayoutItem = [viewMenu itemAtIndex:menuIndex])) {
[switchLayoutItem setTitle:[prefsController horizontalLayout] ?
NSLocalizedString(@"Switch to Vertical Layout", @"title of alternate view layout menu item") :
NSLocalizedString(@"Switch to Horizontal Layout", @"title of view layout menu item")];
}
}
/*
Notational Velocity's title bar was stacked: the window title on its own row, the search field on a
full-width row beneath it. That was not a design decision anyone made here -- it is what
NSWindowStyleMaskUnifiedTitleAndToolbar, which MainMenu.nib has always asked for, meant on every
version of Mac OS X up to Catalina. macOS 11 redefined toolbar rendering: -toolbarStyle now defaults
to NSWindowToolbarStyleAutomatic, which resolves to Unified and folds the two rows into one, putting
the title and the search field side by side.
Expanded is the old behaviour, kept by AppKit for exactly this purpose. No nib work and no change to
the style mask is involved -- the mask already requests the unified title bar; -toolbarStyle is what
decides how many rows it occupies.
*/
- (void)_applyTitleBarLayout {
[window setToolbarStyle:[prefsController sideBySideTitleBar] ?
NSWindowToolbarStyleUnified : NSWindowToolbarStyleExpanded];
}
- (void)applyAppearanceMode {
//nil lets the app follow the system appearance; the other two pin every window light or dark
NSAppearance *appearance = nil;
switch ([prefsController appearanceMode]) {
case KNAppearanceForceDark:
appearance = [NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
break;
case KNAppearanceForceLight:
appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
break;
case KNAppearanceFollowSystem:
break;
}
[NSApp setAppearance:appearance];
}
- (void)_forceRegeneratePreviewsForTitleColumn {
[notationController regeneratePreviewsForColumn:[notesTableView noteAttributeColumnForIdentifier:NoteTitleColumnString]
visibleFilteredRows:[notesTableView rowsInRect:[notesTableView visibleRect]] forceUpdate:YES];
}
- (void)_configureDividerForCurrentLayout {
BOOL horiz = [prefsController horizontalLayout];
[splitView setVertical:horiz];
if (!verticalDividerImg && [splitView divider]) verticalDividerImg = [[splitView divider] retain];
[splitView setDivider: horiz ? nil : verticalDividerImg];
[splitView setDividerThickness: horiz ? 0.0 : 8.0];
[[notesTableView enclosingScrollView] setBorderType: horiz ? NSNoBorder : NSBezelBorder];
NSSize size = [[splitView subviewAtPosition:0] frame].size;
[[notesTableView enclosingScrollView] setFrame: horiz ? NSMakeRect(1, 0, size.width - 1, size.height - 1) : (NSRect){.size = size, .origin = NSZeroPoint}];
[[splitView subviewAtPosition:0] setMinDimension:horiz ? 100.0 : 0.0 andMaxDimension:0.0];
[splitSubview setMinDimension:horiz ? 100.0 : 0.0 andMaxDimension:0.0];
}
- (IBAction)switchViewLayout:(id)sender {
ViewLocationContext ctx = [notesTableView viewingLocation];
ctx.pivotRowWasEdge = NO;
[notesTableView noteFirstVisibleRow];
[self _expandToolbar];
[prefsController setHorizontalLayout:![prefsController horizontalLayout] sender:self];
[notationController updateDateStringsIfNecessary];
[self _configureDividerForCurrentLayout];
[notationController regenerateAllPreviews];
[splitView adjustSubviews];
[notesTableView setViewingLocation:ctx];
[notesTableView makeFirstPreviouslyVisibleRowVisibleIfNecessary];
[self updateNoteMenus];
}
- (void)createFromSelection:(NSPasteboard *)pboard userData:(NSString *)userData error:(NSString **)error {
if (!notationController || ![self addNotesFromPasteboard:pboard]) {
*error = NSLocalizedString(@"Error: Couldn't create a note from the selection.", @"error message to set during a Service call when adding a note failed");
}
}
- (IBAction)renameNote:(id)sender {
//edit the first selected note
[notesTableView editRowAtColumnWithIdentifier:NoteTitleColumnString];
}
- (void)deleteAlertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
id retainedDeleteObj = (id)contextInfo;
if (returnCode == NSAlertFirstButtonReturn) {
//delete! nil-msgsnd-checking
//ensure that there are no pending edits in the tableview,
//lest editing end with the same field editor and a different selected note
//resulting in the renaming of notes in adjacent rows
[notesTableView abortEditing];
if ([retainedDeleteObj isKindOfClass:[NSArray class]]) {
[notationController removeNotes:retainedDeleteObj];
} else if ([retainedDeleteObj isKindOfClass:[NoteObject class]]) {
[notationController removeNote:retainedDeleteObj];
}
[self clearSearchIfDeletionEmptiedList];
if ([[alert suppressionButton] state] == NSOnState) {
[prefsController setConfirmNoteDeletion:NO sender:self];
}
}
[retainedDeleteObj release];
}
- (IBAction)deleteNote:(id)sender {
NSIndexSet *indexes = [notesTableView selectedRowIndexes];
if ([indexes count] > 0) {
id deleteObj = [indexes count] > 1 ? (id)([notationController notesAtIndexes:indexes]) : (id)([notationController noteObjectAtFilteredIndex:[indexes firstIndex]]);
if ([prefsController confirmNoteDeletion]) {
[deleteObj retain];
NSString *warningSingleFormatString = NSLocalizedString(@"Delete the note titled “%@”?", @"alert title when asked to delete a note");
NSString *warningMultipleFormatString = NSLocalizedString(@"Delete %d notes?", @"alert title when asked to delete multiple notes");
NSString *warnString = currentNote ? [NSString stringWithFormat:warningSingleFormatString, titleOfNote(currentNote)] :
[NSString stringWithFormat:warningMultipleFormatString, [indexes count]];
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:warnString];
[alert setInformativeText:NSLocalizedString(@"Press Command-Z to undo this action later.", @"informational delete-this-note? text")];
[alert addButtonWithTitle:NSLocalizedString(@"Delete", @"name of delete button")];
[alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"name of cancel button")];
[alert setShowsSuppressionButton:YES];
[alert beginSheetModalForWindow:window completionHandler:^(NSModalResponse returnCode) {
[self deleteAlertDidEnd:alert returnCode:returnCode contextInfo:(void*)deleteObj];
}];
[alert release];
} else {
//just delete the notes outright
[notationController performSelector:[indexes count] > 1 ? @selector(removeNotes:) : @selector(removeNote:) withObject:deleteObj];
[self clearSearchIfDeletionEmptiedList];
}
}
}
//Deleting the note(s) the current search had narrowed to leaves the search matching nothing: the
//surviving notes no longer match the filter string, so -refilterNotes empties the displayed list and
//the window goes blank -- while the search field can look empty, giving no hint a filter is active --
//until Undo or a relaunch clears the filter. When a deletion empties the list, clear the search so the
//remaining notes reappear. If no notes remain, this just shows the empty database, exactly as before.
- (void)clearSearchIfDeletionEmptiedList {
if ([notesTableView numberOfRows] == 0)
[self cancelOperation:nil];
}
- (IBAction)copyNoteLink:(id)sender {
NSIndexSet *indexes = [notesTableView selectedRowIndexes];
if ([indexes count] == 1) {
[[[[[notationController notesAtIndexes:indexes] lastObject]
uniqueNoteLink] absoluteString] copyItemToPasteboard:nil];
}
}
- (IBAction)exportNote:(id)sender {
NSIndexSet *indexes = [notesTableView selectedRowIndexes];
NSArray *notes = [notationController notesAtIndexes:indexes];
[notationController synchronizeNoteChanges:nil];
[[ExporterManager sharedManager] exportNotes:notes forWindow:window];
}
- (IBAction)revealNote:(id)sender {
NSIndexSet *indexes = [notesTableView selectedRowIndexes];
NSString *path = nil;
if ([indexes count] != 1 || !(path = [[notationController noteObjectAtFilteredIndex:[indexes lastIndex]] noteFilePath])) {
NSBeep();
return;
}
[[NSWorkspace sharedWorkspace] selectFile:path inFileViewerRootedAtPath:@""];
}
- (IBAction)editNoteExternally:(id)sender {
ExternalEditor *ed = [sender representedObject];
if ([ed isKindOfClass:[ExternalEditor class]]) {
NSIndexSet *indexes = [notesTableView selectedRowIndexes];
if (kCGEventFlagMaskAlternate == (CGEventSourceFlagsState(kCGEventSourceStateCombinedSessionState) & NSDeviceIndependentModifierFlagsMask)) {
//allow changing the default editor directly from Notes menu
[[ExternalEditorListController sharedInstance] setDefaultEditor:ed];
}
//force-write any queued changes to disk in case notes are being stored as separate files which might be opened directly by the method below
[notationController synchronizeNoteChanges:nil];
[[notationController notesAtIndexes:indexes] makeObjectsPerformSelector:@selector(editExternallyUsingEditor:) withObject:ed];
} else {
NSBeep();
}
}
- (IBAction)printNote:(id)sender {
NSIndexSet *indexes = [notesTableView selectedRowIndexes];
[MultiplePageView printNotes:[notationController notesAtIndexes:indexes] forWindow:window];
}
- (IBAction)tagNote:(id)sender {
//if single note, add the tag column if necessary and then begin editing
NSIndexSet *indexes = [notesTableView selectedRowIndexes];
if ([indexes count] > 1) {
//show dialog for multiple notes, add or remove tags from them all using a dialog
//tags to remove is constituted by a union of all selected notes' tags
NSLog(@"multiple rows");
} else if ([indexes count] == 1) {
[notesTableView editRowAtColumnWithIdentifier:NoteLabelsColumnString];
}
}
- (void)noteImporter:(AlienNoteImporter*)importer importedNotes:(NSArray*)notes {
[notationController addNotes:notes];
}
- (IBAction)importNotes:(id)sender {
AlienNoteImporter *importer = [[AlienNoteImporter alloc] init];
[importer importNotesFromDialogAroundWindow:window receptionDelegate:self];
[importer autorelease];
}
- (void)settingChangedForSelectorString:(NSString*)selectorString {
if ([selectorString isEqualToString:SEL_STR(setBookmarkDataForDefaultDirectory:sender:)]) {
//defaults changed for the database location -- load the new one!
OSStatus err = noErr;
NotationController *newNotation = nil;
NSData *newData = [prefsController bookmarkDataForDefaultDirectory];
if (newData) {
if ((newNotation = [[NotationController alloc] initWithBookmarkData:newData error:&err])) {
[self setNotationController:newNotation];
[newNotation release];
} else {
//set the recorded location back
NSData *oldData = [notationController bookmarkDataForNoteDirectory];
[prefsController setBookmarkDataForDefaultDirectory:oldData sender:self];
//display alert with err--could not set notation directory
NSString *location = [[newData pathFromBookmarkDataIsStale:NULL] stringByAbbreviatingWithTildeInPath];
NSString *oldLocation = [[oldData pathFromBookmarkDataIsStale:NULL] stringByAbbreviatingWithTildeInPath];
NSString *reason = [NSString reasonStringFromCarbonFSError:err];
KNRunAlert([NSString stringWithFormat:NSLocalizedString(@"Unable to initialize notes database in \n%@ because %@.",nil), location, reason],
[NSString stringWithFormat:NSLocalizedString(@"Reverting to current location of %@.",nil), oldLocation],
NSLocalizedString(@"OK",nil), NULL, NULL);
}
}
} else if ([selectorString isEqualToString:SEL_STR(setSortedTableColumnKey:reversed:sender:)]) {
NoteAttributeColumn *oldSortCol = [notationController sortColumn];
NoteAttributeColumn *newSortCol = [notesTableView noteAttributeColumnForIdentifier:[prefsController sortedTableColumnKey]];
BOOL changedColumns = oldSortCol != newSortCol;
ViewLocationContext ctx;
if (changedColumns) {
ctx = [notesTableView viewingLocation];
ctx.pivotRowWasEdge = NO;
}
[notationController setSortColumn:newSortCol];
if (changedColumns) [notesTableView setViewingLocation:ctx];
} else if ([selectorString isEqualToString:SEL_STR(setNoteBodyFont:sender:)]) {
[notationController restyleAllNotes];
if (currentNote) {
[self contentsUpdatedForNote:currentNote];
}
} else if ([selectorString isEqualToString:SEL_STR(setForegroundTextColor:sender:)]) {
[notationController setForegroundTextColor:[prefsController foregroundTextColor]];
if (currentNote) {
[self contentsUpdatedForNote:currentNote];
}
} else if ([selectorString isEqualToString:SEL_STR(setTableFontSize:sender:)] || [selectorString isEqualToString:SEL_STR(setTableColumnsShowPreview:sender:)]) {
ResetFontRelatedTableAttributes();
[notesTableView updateTitleDereferencorState];
[[notationController labelsListDataSource] invalidateCachedLabelImages];
[self _forceRegeneratePreviewsForTitleColumn];
if ([selectorString isEqualToString:SEL_STR(setTableColumnsShowPreview:sender:)]) [self updateNoteMenus];
[notesTableView performSelector:@selector(reloadData) withObject:nil afterDelay:0];
} else if ([selectorString isEqualToString:SEL_STR(addTableColumn:sender:)] || [selectorString isEqualToString:SEL_STR(removeTableColumn:sender:)]) {
ResetFontRelatedTableAttributes();
[self _forceRegeneratePreviewsForTitleColumn];
[notesTableView performSelector:@selector(reloadDataIfNotEditing) withObject:nil afterDelay:0];
} else if ([selectorString isEqualToString:SEL_STR(setConfirmNoteDeletion:sender:)]) {
[self updateNoteMenus];
} else if ([selectorString isEqualToString:SEL_STR(setSideBySideTitleBar:sender:)]) {
[self _applyTitleBarLayout];
} else if ([selectorString isEqualToString:SEL_STR(setAppearanceMode:sender:)]) {