-
Notifications
You must be signed in to change notification settings - Fork 28
/
CreeveyController.m
1351 lines (1227 loc) · 51.3 KB
/
CreeveyController.m
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 2005-2023 Dominic Yu. Some rights reserved.
//This work is licensed under the Creative Commons
//Attribution-NonCommercial-ShareAlike License. To view a copy of this
//license, visit http://creativecommons.org/licenses/by-nc-sa/2.0/ or send
//a letter to Creative Commons, 559 Nathan Abbott Way, Stanford,
//California 94305, USA.
#import "CreeveyController.h"
#import "DYJpegtran.h"
#import "DYCarbonGoodies.h"
#import "DYWrappingMatrix.h"
#import "CreeveyMainWindowController.h"
#import "DYImageCache.h"
#import "SlideshowWindow.h"
#import "DYJpegtranPanel.h"
#import "DYVersChecker.h"
#import "DYExiftags.h"
// The thumbs cache should always store images using the resolved filename as the key.
// This prevents duplication somewhat, but it means when you look things up
// you need to make a call to ResolveAliasToPath.
#define MAX_THUMBS 2000
#define DYVERSCHECKINTERVAL 604800
#define MAX_FILES_TO_CHECK_FOR_JPEG 100
static BOOL FilesContainJPEG(NSArray *paths) {
// find out if at least one file is a JPEG
if (paths.count > MAX_FILES_TO_CHECK_FOR_JPEG) return YES; // but give up there's too many to check
for (NSString *path in paths) {
if (FileIsJPEG(path))
return YES;
}
return NO;
}
#define TAB(x,y) [[NSTextTab alloc] initWithType:x location:y]
NSMutableAttributedString* Fileinfo2EXIFString(NSString *origPath, DYImageCache *cache, BOOL moreExif) {
NSString *path = ResolveAliasToPath(origPath);
NSMutableString *s = [[NSMutableString alloc] init];
[s appendString:origPath.lastPathComponent];
if (path != origPath)
[s appendFormat:@"\n[%@->%@]", NSLocalizedString(@"Alias", @""), path];
DYImageInfo *i = [cache infoForKey:path];
if (i) {
id exifStr = [DYExiftags tagsForFile:path moreTags:moreExif];
[s appendFormat:@"\n%@ (%qu bytes)\n%@: %d %@: %d",
FileSize2String(i->fileSize), i->fileSize,
NSLocalizedString(@"Width", @""), (int)i->pixelSize.width,
NSLocalizedString(@"Height", @""), (int)i->pixelSize.height];
if (exifStr) {
[s appendString:@"\n"];
[s appendString:exifStr];
}
} else {
unsigned long long fsize;
fsize = [[NSFileManager.defaultManager attributesOfItemAtPath:path.stringByResolvingSymlinksInPath error:NULL] fileSize];
// fsize will be 0 on error
[s appendFormat:@"\n%@ (%qu bytes)",
FileSize2String(fsize), fsize];
}
static NSDictionary *atts;
if (atts == nil) {
float x = 160;
NSMutableParagraphStyle *styl = [[NSMutableParagraphStyle alloc] init];
styl.headIndent = x;
styl.tabStops = @[TAB(NSRightTabStopType,x-5), TAB(NSLeftTabStopType,x)];
styl.defaultTabInterval = 5;
atts = @{
NSFontAttributeName: [NSFont userFontOfSize:12],
NSParagraphStyleAttributeName: styl,
};
}
return [[NSMutableAttributedString alloc] initWithString:s attributes:atts];
}
@interface TimeIntervalPlusWeekToStringTransformer : NSValueTransformer
// using a val xformer means the field gets updated automatically
@end
@implementation TimeIntervalPlusWeekToStringTransformer
+ (Class)transformedValueClass { return [NSString class]; }
- (id)transformedValue:(id)v {
return [NSDateFormatter localizedStringFromDate:[NSDate dateWithTimeIntervalSinceReferenceDate:[v floatValue]+DYVERSCHECKINTERVAL]
dateStyle:NSDateFormatterLongStyle timeStyle:NSDateFormatterMediumStyle];
}
@end
@interface CreeveyController ()
@property (nonatomic) BOOL appDidFinishLaunching;
@property (nonatomic) BOOL filesWereOpenedAtLaunch;
@property (nonatomic) BOOL windowsWereRestoredAtLaunch;
@end
@implementation CreeveyController
{
NSMutableSet *cats[NUM_FNKEY_CATS];
NSUserDefaults *catDefaults;
BOOL exifWasVisible;
NSMutableSet *filetypes;
NSMutableSet *disabledFiletypes;
NSMutableSet *fileostypes;
NSArray *fileextensions;
NSMutableDictionary *filetypeDescriptions;
NSMutableArray *creeveyWindows;
CreeveyMainWindowController * __weak frontWindow;
NSArray *_prefWinNibItems;
DYImageCache *thumbsCache;
id localeChangeObserver;
NSArray<NSURL*> *_movedUrls;
NSArray<NSString*> *_originalPaths;
NSMutableArray *_coalescedFilesToOpen;
}
@synthesize slidesWindow, jpegProgressBar, exifTextView, exifThumbnailDiscloseBtn, prefsWin, slideshowApplyBtn;
+(void)initialize
{
if (self != [CreeveyController class]) return;
dcraw_init();
NSUserDefaults *defaults = NSUserDefaults.standardUserDefaults;
NSString *s = CREEVEY_DEFAULT_PATH;
[defaults registerDefaults:@{
@"picturesFolderPath": s,
@"lastFolderPath": s,
@"startupOption": @0,
@"appearance": @0,
@"thumbCellWidth": @120.0f,
@"getInfoVisible": @NO,
@"autoVersCheck": @YES,
@"jpegPreserveModDate": @NO,
@"slideshowAutoadvance": @NO,
@"slideshowAutoadvanceTime": @5.5f,
@"slideshowLoop": @NO,
@"slideshowRandom": @NO,
@"slideshowScaleUp": @NO,
@"slideshowActualSize": @NO,
@"slideshowBgColor": [NSKeyedArchiver archivedDataWithRootObject:NSColor.blackColor requiringSecureCoding:YES error:NULL],
@"exifThumbnailShow": @NO,
@"showFilenames": @YES,
@"sortBy": @1, // sort by filename, ascending
@"Slideshow:RerandomizeOnLoop": @YES,
@"SlideshowSuppressLoopIndicator": @NO,
@"maxThumbsToLoad": @100,
@"autoRotateByOrientationTag": @YES,
@"openFilesDoSlideshow": @YES,
@"openFilesIgnoreAutoadvance": @NO,
@"startupSlideshowFromFolder":@NO,
@"startupSlideshowSubfolders":@NO,
@"startupSlideshowSuppressNewWindows":@NO,
@"slideshowDefaultMode":@0,
@"MainWindowSplitViewTopHeight":@151.0f,
}];
// migrate old RBSplitView pref
if (0.0 == [defaults floatForKey:@"MainWindowSplitViewTopHeight"]) {
NSString *rbsplitviewvalue = [defaults stringForKey:@"RBSplitView H DividerLoc"];
if (rbsplitviewvalue) {
NSScanner *scanner = [NSScanner scannerWithString:rbsplitviewvalue];
if ([scanner scanInt:NULL]) {
int rbsplitviewheight;
if ([scanner scanInt:&rbsplitviewheight])
[defaults setFloat:(float)rbsplitviewheight forKey:@"MainWindowSplitViewTopHeight"];
}
}
}
[NSValueTransformer setValueTransformer:[[TimeIntervalPlusWeekToStringTransformer alloc] init]
forName:@"TimeIntervalPlusWeekToStringTransformer"];
}
- (instancetype)init {
if (self = [super init]) {
filetypes = [[NSMutableSet alloc] init];
fileostypes = [[NSMutableSet alloc] init];
disabledFiletypes = [[NSMutableSet alloc] init];
filetypeDescriptions = [[NSMutableDictionary alloc] init];
for (NSString *identifier in NSImage.imageUnfilteredTypes) {
// easier to use UTType class from UniformTypeIdentifiers, but that's only available in macOS 11
CFDictionaryRef t = UTTypeCopyDeclaration((__bridge CFStringRef)identifier);
if (t == NULL) continue;
CFDictionaryRef tags = CFDictionaryGetValue(t, kUTTypeTagSpecificationKey);
if (tags) {
NSArray *exts = CFDictionaryGetValue(tags, kUTTagClassFilenameExtension);
if (exts) {
[filetypes addObjectsFromArray:exts];
NSString *description = CFDictionaryGetValue(t, kUTTypeDescriptionKey);
if (description) for (NSString *ext in exts) {
NSString *s = filetypeDescriptions[ext];
filetypeDescriptions[ext] = s ? [s stringByAppendingFormat:@" / %@", description] : description;
}
}
CFArrayRef ostypes = CFDictionaryGetValue(tags, kUTTagClassOSType);
if (ostypes) for (NSString *s in (__bridge NSArray *)ostypes) {
// enclose HFS file types in single quotes, e.g. "'PICT'"
[fileostypes addObject:[NSString stringWithFormat:@"'%@'", s]];
}
}
CFRelease(t);
}
_revealedDirectories = [[NSMutableSet alloc] initWithObjects:[NSURL fileURLWithPath:(@"~/Desktop/").stringByResolvingSymlinksInPath isDirectory:YES], nil];
fileextensions = [filetypes.allObjects sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
creeveyWindows = [[NSMutableArray alloc] initWithCapacity:5];
_coalescedFilesToOpen = [[NSMutableArray alloc] init];
thumbsCache = [[DYImageCache alloc] initWithCapacity:MAX_THUMBS];
thumbsCache.boundingSize = DYWrappingMatrix.maxCellSize;
thumbsCache.fastThumbnails = YES;
short int i;
for (i=0; i<NUM_FNKEY_CATS; ++i) {
cats[i] = [[NSMutableSet alloc] initWithCapacity:0];
}
catDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"net.blyt.phoenixslides.categories"];
exifWasVisible = [NSUserDefaults.standardUserDefaults boolForKey:@"getInfoVisible"];
}
return self;
}
- (void)applicationWillFinishLaunching:(NSNotification *)notification {
[(NSPanel *)exifTextView.window setBecomesKeyOnlyIfNeeded:YES];
//[[exifTextView window] setHidesOnDeactivate:NO];
// this causes problems b/c the window can be foregrounded without the app
// coming to the front (oops)
[slidesWindow setCats:cats];
NSUserDefaults *u = NSUserDefaults.standardUserDefaults;
slidesWindow.autoRotate = [u boolForKey:@"autoRotateByOrientationTag"];
[disabledFiletypes addObjectsFromArray:[u stringArrayForKey:@"ignoredFileTypes"]];
for (NSString *type in disabledFiletypes) {
[filetypes removeObject:type];
}
[self updateMoveToMenuItem];
[self updateAlternateSlideshowMenuItem];
[self updateAppearance];
NSUserDefaultsController *ud = NSUserDefaultsController.sharedUserDefaultsController;
[ud addObserver:self forKeyPath:@"values.slideshowBgColor" options:0 context:NULL];
[ud addObserver:self forKeyPath:@"values.DYWrappingMatrixMaxCellWidth" options:0 context:NULL];
[ud addObserver:self forKeyPath:@"values.appearance" options:0 context:NULL];
localeChangeObserver = [NSNotificationCenter.defaultCenter addObserverForName:NSCurrentLocaleDidChangeNotification object:nil queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification *note) {
[u setDouble:[u doubleForKey:@"lastVersCheckTime"] forKey:@"lastVersCheckTime"];
}];
}
- (BOOL)macos1014available { if (@available(macOS 10.14, *)) return YES; return NO; }
- (void)dealloc {
NSUserDefaultsController *u = NSUserDefaultsController.sharedUserDefaultsController;
[u removeObserver:self forKeyPath:@"values.slideshowBgColor"];
[u removeObserver:self forKeyPath:@"values.DYWrappingMatrixMaxCellWidth"];
[u removeObserver:self forKeyPath:@"values.appearance"];
[NSNotificationCenter.defaultCenter removeObserver:localeChangeObserver];
short int i;
for (i=0; i<NUM_FNKEY_CATS; ++i)
cats[i] = nil;
}
- (void)slideshowFromAppOpen:(NSArray *)files {
BOOL fullscreen = slidesWindow.visible ? slidesWindow.fullscreenMode : [NSUserDefaults.standardUserDefaults integerForKey:@"slideshowDefaultMode"] == 0;
[self startSlideshowFullscreen:fullscreen withFiles:files];
}
- (void)startSlideshowFullscreen:(BOOL)flag {
[self startSlideshowFullscreen:flag withFiles:nil];
}
- (void)startSlideshowFullscreen:(BOOL)flag withFiles:(nullable NSArray *)files {
slidesWindow.fullscreenMode = flag;
BOOL wantsUpdates;
NSUInteger startIdx = NSNotFound;
if (files) {
if ((wantsUpdates = files.count <= 1)) {
if (files.count == 1) startIdx = [frontWindow indexOfFilename:files[0]];
files = frontWindow.displayedFilenames;
}
} else {
NSIndexSet *s = frontWindow.selectedIndexes;
if ((wantsUpdates = s.count <= 1)) {
files = frontWindow.displayedFilenames;
if (s.count == 1) startIdx = s.firstIndex;
} else {
files = frontWindow.currentSelection;
}
}
if (wantsUpdates) {
[slidesWindow setFilenames:files basePath:frontWindow.path wantsSubfolders:frontWindow.wantsSubfolders comparator:frontWindow.comparator sortOrder:frontWindow.sortOrder];
} else {
[slidesWindow setFilenames:files basePath:frontWindow.path comparator:frontWindow.comparator sortOrder:frontWindow.sortOrder];
}
NSUserDefaults *u = NSUserDefaults.standardUserDefaults;
slidesWindow.autoRotate = frontWindow.imageMatrix.autoRotate;
// if files != nil these files are being opened from the finder, so check the relevant pref
float aaInterval;
if ([u boolForKey:@"slideshowAutoadvance"] && (files == nil || ![u boolForKey:@"openFilesIgnoreAutoadvance"]))
aaInterval = [u floatForKey:@"slideshowAutoadvanceTime"];
else
aaInterval = 0;
slidesWindow.autoadvanceTime = aaInterval;
[slidesWindow startSlideshowAtIndex:startIdx];
}
- (IBAction)slideshow:(id)sender
{
[self startSlideshowFullscreen:[NSUserDefaults.standardUserDefaults integerForKey:@"slideshowDefaultMode"] == 0];
}
- (IBAction)slideshowAlternateMode:(id)sender {
[self startSlideshowFullscreen:[NSUserDefaults.standardUserDefaults integerForKey:@"slideshowDefaultMode"] != 0];
}
- (IBAction)openSelectedFiles:(id)sender {
BOOL fullscreen = [NSUserDefaults.standardUserDefaults integerForKey:@"slideshowDefaultMode"] == 0;
if (NSApp.currentEvent.modifierFlags & NSEventModifierFlagOption) fullscreen = !fullscreen;
[self startSlideshowFullscreen:fullscreen];
}
- (IBAction)revealSelectedFilesInFinder:(id)sender {
if (slidesWindow.isMainWindow) {
if (slidesWindow.currentFile) {
NSString *s = slidesWindow.currentFile;
[NSWorkspace.sharedWorkspace selectFile:s inFileViewerRootedAtPath:s.stringByDeletingLastPathComponent];
} else {
[NSWorkspace.sharedWorkspace openFile:slidesWindow.basePath];
}
} else {
NSArray *a = frontWindow.currentSelection;
if (a.count) {
NSMutableArray *b = [NSMutableArray arrayWithCapacity:a.count];
for (NSString *s in a) {
[b addObject:[NSURL fileURLWithPath:s isDirectory:NO]];
}
[NSWorkspace.sharedWorkspace activateFileViewerSelectingURLs:b];
} else {
[NSWorkspace.sharedWorkspace openFile:frontWindow.path];
}
}
}
- (IBAction)setDesktopPicture:(id)sender {
NSString *s = slidesWindow.isMainWindow
? slidesWindow.currentFile
: frontWindow.currentSelection[0];
NSError * __autoreleasing error = nil;
[NSWorkspace.sharedWorkspace setDesktopImageURL:[NSURL fileURLWithPath:s isDirectory:NO]
forScreen:NSScreen.mainScreen
options:@{}
error:&error];
if (error) {
NSAlert *alert = [[NSAlert alloc] init];
alert.informativeText = [NSString stringWithFormat:NSLocalizedString(@"Could not set the desktop because an error occurred. %@", @""), error.localizedDescription];
[alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"")];
[alert runModal];
};
}
- (IBAction)transformJpeg:(id)sender {
DYJpegtranInfo jinfo;
NSInteger t = [sender tag] - 100;
if (t == 0) {
if (!self.jpegController)
if (![NSBundle.mainBundle loadNibNamed:@"DYJpegtranPanel" owner:self topLevelObjects:NULL]) return;
if (![self.jpegController runOptionsPanel:&jinfo]) return;
} else {
jinfo.thumbOnly = t > 30;
if (jinfo.thumbOnly) t -= 30;
jinfo.tinfo.transform = t < DYJPEGTRAN_XFORM_PROGRESSIVE ? (JXFORM_CODE)t : JXFORM_NONE;
jinfo.tinfo.trim = FALSE;
jinfo.tinfo.force_grayscale = t == DYJPEGTRAN_XFORM_GRAYSCALE;
jinfo.cp = JCOPYOPT_ALL;
jinfo.progressive = t == DYJPEGTRAN_XFORM_PROGRESSIVE;
jinfo.optimize = 0;
jinfo.autorotate = t == DYJPEGTRAN_XFORM_AUTOROTATE;
jinfo.resetOrientation = t == DYJPEGTRAN_XFORM_RESETORIENT;
jinfo.replaceThumb = t == DYJPEGTRAN_XFORM_REGENTHUMB;
jinfo.delThumb = t == DYJPEGTRAN_XFORM_DELETETHUMB;
}
// throw up warning if necessary
if (jinfo.tinfo.force_grayscale || jinfo.cp != JCOPYOPT_ALL || jinfo.tinfo.trim
|| jinfo.resetOrientation || jinfo.replaceThumb || jinfo.delThumb) {
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = NSLocalizedString(@"Warning", @"");
alert.informativeText = NSLocalizedString(@"This operation cannot be undone! Are you sure you want to continue?", @"");
[alert addButtonWithTitle:NSLocalizedString(@"Continue", @"")];
[alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"")];
NSModalResponse response = [alert runModal];
if (response != NSAlertFirstButtonReturn)
return; // user cancelled
jinfo.preserveModificationDate = jinfo.resetOrientation ? [NSUserDefaults.standardUserDefaults boolForKey:@"jpegPreserveModDate"]
: NO;
// make an exception for reset orientation,
// since it doesn't _really_ change anything
} else {
jinfo.preserveModificationDate = [NSUserDefaults.standardUserDefaults boolForKey:@"jpegPreserveModDate"];
}
NSArray *a;
DYImageInfo *imgInfo;
BOOL slidesWasKey = slidesWindow.isMainWindow; // ** test for main is better than key
BOOL autoRotate = YES; // set this to yes, if the browser is active and not autorotating we change it below. I.e., autorotate will be true if we're in a slideshow
if (slidesWasKey) {
NSString *slidesFile = slidesWindow.currentFile;
a = @[slidesFile];
// we need to get the current (viewing) orientation of the slide
// we *don't* need to save the current cached thumbnail info since it's going to get deleted
unsigned short orientation = slidesWindow.currentOrientation;
if (orientation != 0) {
imgInfo = [thumbsCache infoForKey:ResolveAliasToPath(slidesFile)];
if (imgInfo)
imgInfo->exifOrientation = slidesWindow.currentOrientation;
}
} else {
a = frontWindow.currentSelection;
autoRotate = frontWindow.imageMatrix.autoRotate;
}
jpegProgressBar.usesThreadedAnimation = YES;
jpegProgressBar.indeterminate = YES;
jpegProgressBar.doubleValue = 0;
jpegProgressBar.maxValue = a.count;
((NSButton *)[jpegProgressBar.window.contentView viewWithTag:1]).enabled = a.count > 1; // cancel btn
NSModalSession session = [NSApp beginModalSessionForWindow:jpegProgressBar.window];
[NSApp runModalSession:session];
[jpegProgressBar startAnimation:self];
for (NSString *s in a) {
NSString *resolvedPath = ResolveAliasToPath(s);
if (FileIsJPEG(resolvedPath)) {
if (jinfo.replaceThumb) {
NSSize tmpSize;
NSData *i = [DYImageCache createNewThumbFromFile:resolvedPath getSize:&tmpSize];
if (i) {
jinfo.newThumb = i;
jinfo.newThumbSize = tmpSize;
} else {
jinfo.newThumb = NULL;
}
}
imgInfo = [thumbsCache infoForKey:resolvedPath];
jinfo.starting_exif_orientation = autoRotate
? (imgInfo ? imgInfo->exifOrientation : 0) // thumbsCache should always have the info we want, but just in case it doesn't don't crash!
: 0;
if ([DYJpegtran transformImage:resolvedPath transform:jinfo]) {
[thumbsCache removeImageForKey:resolvedPath];
[creeveyWindows makeObjectsPerformSelector:@selector(fileWasChanged:) withObject:s];
[slidesWindow uncacheImage:s];
} else {
// ** fail silently
//NSLog(@"rot failed!");
}
}
if (jpegProgressBar.indeterminate) {
[jpegProgressBar stopAnimation:self];
jpegProgressBar.indeterminate = NO;
}
[jpegProgressBar incrementBy:1];
if ([NSApp runModalSession:session] != NSModalResponseContinue) break;
}
[frontWindow updateExifInfo];
[NSApp endModalSession:session];
[jpegProgressBar.window orderOut:self];
}
- (IBAction)stopModal:(id)sender {
[NSApp stopModal];
}
- (void)updateMoveToMenuItem {
NSString *path = [NSUserDefaults.standardUserDefaults stringForKey:@"lastUsedMoveToFolder"];
if (path == nil) return;
NSMenu *m = [NSApp.mainMenu itemWithTag:FILE_MENU].submenu;
NSMenuItem *item = [m itemWithTag:MOVE_TO_AGAIN];
NSString *name = [NSFileManager.defaultManager displayNameAtPath:path];
item.title = [NSString stringWithFormat:NSLocalizedString(@"Move to “%@” Again", @"File menu"), name];
}
- (void)updateAlternateSlideshowMenuItem {
NSMenu *m = [NSApp.mainMenu itemWithTag:SLIDESHOW_MENU].submenu;
NSMenuItem *item = [m itemWithTag:BEGIN_SLIDESHOW_ALTERNATE];
item.title = [NSUserDefaults.standardUserDefaults integerForKey:@"slideshowDefaultMode"] == 0 ? NSLocalizedString(@"Begin Slideshow In Window", @"Slideshow menu") : NSLocalizedString(@"Begin Slideshow (Full Screen)", @"Slideshow menu");
}
- (void)moveSelectedFilesTo:(NSURL *)dest {
NSString *curr = slidesWindow.isMainWindow ? slidesWindow.basePath : frontWindow.path;
if ([dest isEqual:[NSURL fileURLWithPath:curr]]) return;
NSArray *files = slidesWindow.isMainWindow ? @[slidesWindow.currentFile] : frontWindow.currentSelection;
NSMutableArray<NSString*> *paths = [NSMutableArray array];
NSMutableArray<NSURL*> *moved = [NSMutableArray arrayWithCapacity:files.count];
NSMutableArray<NSString*> *notMoved = [NSMutableArray array];
NSError * __autoreleasing err;
for (NSString *f in files) {
NSURL *destUrl = [dest URLByAppendingPathComponent:f.lastPathComponent];
if ([NSFileManager.defaultManager moveItemAtPath:f toPath:destUrl.path error:&err]) {
[paths addObject:f];
[moved addObject:destUrl];
} else {
[notMoved addObject:f];
}
}
if (notMoved.count) {
NSAlert *alert = [[NSAlert alloc] init];
if (notMoved.count == 1) {
alert.informativeText = [NSString stringWithFormat:NSLocalizedString(@"The file “%@” could not be moved because of an error: %@", @""), notMoved[0].lastPathComponent, err.localizedDescription];
} else {
alert.informativeText = [NSString stringWithFormat:NSLocalizedString(@"%lu files could not be moved because of an error.",@""), notMoved.count];
}
[alert runModal];
}
_originalPaths = [paths copy];
_movedUrls = [moved copy];
[self removePicsAndTrash:NO];
[creeveyWindows makeObjectsPerformSelector:@selector(filesWereUndeleted:) withObject:[moved valueForKey:@"path"]];
}
- (IBAction)moveSelectedFiles:(id)sender {
NSOpenPanel *op = [NSOpenPanel openPanel];
op.canChooseFiles = NO;
op.canChooseDirectories = YES;
if ([op runModal] != NSModalResponseOK) return;
NSURL *dest = op.URL;
[self moveSelectedFilesTo:dest];
[NSUserDefaults.standardUserDefaults setObject:dest.path forKey:@"lastUsedMoveToFolder"];
[self updateMoveToMenuItem];
}
- (IBAction)moveSelectedFilesAgain:(id)sender {
NSString *folder = [NSUserDefaults.standardUserDefaults stringForKey:@"lastUsedMoveToFolder"];
NSURL *dest = [NSURL fileURLWithPath:folder isDirectory:YES];
[self moveSelectedFilesTo:dest];
}
// returns 1 if successful
// unsuccessful: 0 user wants to continue; 2 cancel/abort
- (char)trashFile:(NSString *)fullpath numLeft:(NSUInteger)numFiles resultingURL:(NSURL **)newURL {
NSURL *url = [NSURL fileURLWithPath:fullpath isDirectory:NO];
NSError * __autoreleasing error = nil;
[NSFileManager.defaultManager trashItemAtURL:url resultingItemURL:newURL error:&error];
if (!error)
return 1;
NSAlert *alert = [[NSAlert alloc] init];
alert.informativeText = [NSString stringWithFormat:NSLocalizedString(@"The file %@ could not be moved to the trash because an error of %i occurred.", @""), fullpath.lastPathComponent, (int)error.code];
[alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"")];
if (numFiles > 1)
[alert addButtonWithTitle:NSLocalizedString(@"Continue", @"")];
NSModalResponse response = [alert runModal];
if (response == NSAlertFirstButtonReturn)
return 2;
return 0;
}
// pass YES to move to trash; pass NO if this was a drag-to-Finder operation
- (void)removePicsAndTrash:(BOOL)doTrash {
// *** to be more efficient, we should change the path in the cache instead of deleting it
if (slidesWindow.isMainWindow) {
NSString *s = slidesWindow.currentFile;
NSURL *u;
if (doTrash ? [self trashFile:s numLeft:1 resultingURL:&u] : (u = _movedUrls[0]) != nil) {
[creeveyWindows makeObjectsPerformSelector:@selector(fileWasDeleted:) withObject:s];
[thumbsCache removeImageForKey:s];
[slidesWindow removeImageForFile:s];
NSUInteger idx = slidesWindow.currentIndex;
NSUndoManager *um = slidesWindow.undoManager;
[um registerUndoWithTarget:self handler:^(id target) {
NSError * __autoreleasing err;
if ([NSFileManager.defaultManager moveItemAtPath:u.path toPath:s error:&err]) {
if (slidesWindow.isMainWindow)
[slidesWindow insertFile:s atIndex:idx];
[creeveyWindows makeObjectsPerformSelector:@selector(filesWereUndeleted:) withObject:@[s]];
if (!doTrash) {
[creeveyWindows makeObjectsPerformSelector:@selector(fileWasDeleted:) withObject:u.path];
if (slidesWindow.isMainWindow)
[slidesWindow removeImageForFile:u.path];
}
} else {
NSAlert *alert = [[NSAlert alloc] init];
alert.informativeText = [NSString stringWithFormat:doTrash ? NSLocalizedString(@"The file \"%@\" could not be restored from the trash because of an error: %@", @"") : NSLocalizedString(@"The file “%@” could not be moved because of an error: %@", @""), s.lastPathComponent, err.localizedDescription];
[alert runModal];
}
}];
[um setActionName:[NSString stringWithFormat:doTrash ? NSLocalizedString(@"Move to Trash",@"") : NSLocalizedString(@"Move File",@"for undo")]];
}
} else {
NSUInteger oldIndex = frontWindow.selectedIndexes.firstIndex;
NSArray *selectedPaths = frontWindow.currentSelection;
NSUInteger n = selectedPaths.count;
NSMutableArray<NSArray *> *trashedFiles = [NSMutableArray arrayWithCapacity:n];
for (NSUInteger i=0; i < n; ++i) {
NSString *fullpath = selectedPaths[i];
NSURL * __autoreleasing newURL;
char result = (doTrash ? [self trashFile:fullpath numLeft:n-i resultingURL:&newURL] : 1);
if (result == 1) {
[thumbsCache removeImageForKey:fullpath]; // we don't resolve alias here, but that's OK
[creeveyWindows makeObjectsPerformSelector:@selector(fileWasDeleted:) withObject:fullpath];
if (slidesWindow.visible)
[slidesWindow removeImageForFile:fullpath];
if (doTrash)
[trashedFiles addObject:@[fullpath, newURL]]; // this is a pair representing the old and new file locations
} else if (result == 2)
break;
}
NSUndoManager *um = frontWindow.window.undoManager;
n = trashedFiles.count;
if (n) {
[um registerUndoWithTarget:self handler:^(id target) {
NSMutableArray *moved = [NSMutableArray arrayWithCapacity:n];
for (NSArray *a in trashedFiles) {
if ([NSFileManager.defaultManager moveItemAtPath:[a[1] path] toPath:a[0] error:NULL])
[moved addObject:a[0]];
}
[creeveyWindows makeObjectsPerformSelector:@selector(filesWereUndeleted:) withObject:moved];
if (slidesWindow.visible)
[slidesWindow filesWereUndeleted:moved];
if (moved.count < n) {
NSAlert *alert = [[NSAlert alloc] init];
alert.informativeText = [NSString stringWithFormat:NSLocalizedString(@"%lu file(s) could not be restored from the trash because of an error. You should probably check your Trash.",@""), n-moved.count];
[alert runModal];
}
}];
[um setActionName:[NSString stringWithFormat:NSLocalizedString(@"Move to Trash (%lu File(s))",@"for undo"), n]];
} else if (!doTrash) {
NSArray<NSURL *> *urls = _movedUrls; // nonmutable copy, suitable to be captured by block below
// these are file reference URLs so we will be able to resolve the new paths
n = urls.count;
if (n) {
NSArray *paths = _originalPaths;
[um registerUndoWithTarget:self handler:^(id target) {
NSMutableArray *moved = [NSMutableArray arrayWithCapacity:n];
for (NSUInteger i=0; i<n; ++i) {
NSString *fromPath = urls[i].path;
if ([NSFileManager.defaultManager moveItemAtPath:fromPath toPath:paths[i] error:NULL]) {
[moved addObject:paths[i]];
[creeveyWindows makeObjectsPerformSelector:@selector(fileWasDeleted:) withObject:fromPath];
if (slidesWindow.visible)
[slidesWindow removeImageForFile:fromPath];
}
}
[creeveyWindows makeObjectsPerformSelector:@selector(filesWereUndeleted:) withObject:moved];
if (slidesWindow.visible)
[slidesWindow filesWereUndeleted:moved];
if (moved.count < n) {
NSAlert *alert = [[NSAlert alloc] init];
alert.informativeText = [NSString stringWithFormat:NSLocalizedString(@"%lu file(s) could not be moved back because of an error.",@""), n-moved.count];
[alert runModal];
}
}];
[um setActionName:[NSString stringWithFormat:NSLocalizedString(@"Move Files (%lu File(s))",@"for undo"), n]];
}
}
[frontWindow updateExifInfo];
// no selection means all files were successfully deleted; select the next image if possible
if (frontWindow.selectedIndexes.firstIndex == NSNotFound && oldIndex < frontWindow.displayedFilenames.count) {
[frontWindow selectIndex:oldIndex];
}
}
}
- (IBAction)moveToTrash:(id)sender {
[self removePicsAndTrash:YES];
}
#pragma mark matrix view methods
- (void)moveElsewhere {
_movedUrls = frontWindow.imageMatrix.movedUrls;
_originalPaths = frontWindow.imageMatrix.originPaths;
[self removePicsAndTrash:NO];
}
- (unsigned short)exifOrientationForFile:(NSString *)s {
NSString *path = ResolveAliasToPath(s);
DYImageInfo *i = [thumbsCache infoForKey:path];
return i ? i->exifOrientation : [DYExiftags orientationForFile:path];
}
#pragma mark app delegate methods
- (BOOL)slideshowFromStartupPreference {
NSUserDefaults *u = NSUserDefaults.standardUserDefaults;
NSString *path = [u integerForKey:@"startupOption"] == 0 ? [u stringForKey:@"lastFolderPath"] : [u stringForKey:@"picturesFolderPath"];
BOOL isDir;
if ([NSFileManager.defaultManager fileExistsAtPath:path isDirectory:&isDir] && isDir) {
BOOL fullScreen = ![u boolForKey:@"startupSlideshowInWindow"];
short int sortOrder = [u integerForKey:@"sortBy"];
[slidesWindow loadFilenamesFromPath:path fullScreen:fullScreen wantsSubfolders:[u boolForKey:@"startupSlideshowSubfolders"] comparator:ComparatorForSortOrder(sortOrder) sortOrder:sortOrder];
return YES;
}
return NO;
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSUserDefaults *u = NSUserDefaults.standardUserDefaults;
[self showExifThumbnail:[u boolForKey:@"exifThumbnailShow"]
shrinkWindow:NO];
_appDidFinishLaunching = YES;
if (_windowsWereRestoredAtLaunch && _filesWereOpenedAtLaunch) {
// ugly hack to force the slideshow window to be on top of the restored windows
BOOL wasVisible = slidesWindow.isVisible;
[slidesWindow orderFront:nil];
if (!wasVisible) [slidesWindow orderOut:nil];
}
[self applySlideshowPrefs:nil];
[self updateSlideshowBgColor];
BOOL doSlideshow = [u boolForKey:@"startupSlideshowFromFolder"];
BOOL suppressNewWindow = doSlideshow && [u boolForKey:@"startupSlideshowSuppressNewWindows"];
if (doSlideshow) {
if (![self slideshowFromStartupPreference]) {
// fail silently and open a new window if necessary
suppressNewWindow = NO;
}
}
// between version 1.5.3 and 1.5.8, new users would get the splitview collapsed by default,
// which was unintentional and made certain features undiscoverable
if (0.0 == [u floatForKey:@"MainWindowSplitViewTopHeight"] && ![u integerForKey:@"zSplitViewZeroHeightFixed"]) {
if (creeveyWindows.count) {
// as a hint to the user, set the frontmost window's splitview position to something non-zero
NSSplitView *splitView = ((NSWindowController *)creeveyWindows.lastObject).window.contentView.subviews[0];
dispatch_async(dispatch_get_main_queue(), ^{
[splitView setPosition:151.0 ofDividerAtIndex:0];
});
} else {
[u setFloat:151.0 forKey:@"MainWindowSplitViewTopHeight"];
}
// only ever do this once
[u setInteger:1 forKey:@"zSplitViewZeroHeightFixed"];
}
// open a new window if there isn't one (either from dropping icons onto app at launch, or from restoring saved state)
if (!frontWindow && !_windowsWereRestoredAtLaunch && !suppressNewWindow)
[self newWindow:self];
NSTimeInterval t = NSDate.timeIntervalSinceReferenceDate;
if ([u boolForKey:@"autoVersCheck"]
&& (t - [u doubleForKey:@"lastVersCheckTime"] > DYVERSCHECKINTERVAL)) // one week
DYVersCheckForUpdateAndNotify(NO);
dispatch_async(dispatch_get_global_queue(QOS_CLASS_DEFAULT, 0), ^{
// because screw thread safety
@autoreleasepool {
NSArray<NSArray *> *savedCats = [catDefaults arrayForKey:@"cats"];
short i = 0;
for (NSArray *a in savedCats) {
NSMutableArray *readable = [NSMutableArray arrayWithCapacity:a.count];
for (NSString *path in a) {
if (0 == access(path.fileSystemRepresentation, R_OK))
[readable addObject:path];
}
[cats[i++] addObjectsFromArray:readable];
}
[self updateCats];
}
});
}
- (void)applicationWillTerminate:(NSNotification *)notification
{
NSUserDefaults *u = NSUserDefaults.standardUserDefaults;
if (creeveyWindows.count)
[frontWindow updateDefaults];
[u setBool:(slidesWindow.isMainWindow || creeveyWindows.count == 0) ? exifWasVisible : exifTextView.window.visible
forKey:@"getInfoVisible"];
[u synchronize];
}
- (void)openFilesCoalesced {
BOOL doSlideshow = [NSUserDefaults.standardUserDefaults boolForKey:@"openFilesDoSlideshow"];
[frontWindow openFiles:_coalescedFilesToOpen withSlideshow:doSlideshow];
[_coalescedFilesToOpen removeAllObjects];
}
- (void)openFiles:(NSArray *)files {
if (!creeveyWindows.count) [self newWindow:nil];
[frontWindow.window makeKeyAndOrderFront:nil];
if (!_appDidFinishLaunching)
_filesWereOpenedAtLaunch = YES;
[_coalescedFilesToOpen addObjectsFromArray:files];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
[self performSelector:@selector(openFilesCoalesced) withObject:nil afterDelay:0.5];
}
- (BOOL)application:(NSApplication *)sender
openFile:(NSString *)filename {
[self openFiles:@[filename]];
return YES;
}
- (void)application:(NSApplication *)sender
openFiles:(NSArray *)files {
[self openFiles:files];
[sender replyToOpenOrPrint:NSApplicationDelegateReplySuccess];
}
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag {
if (!creeveyWindows.count) {
NSUserDefaults *u = NSUserDefaults.standardUserDefaults;
if ([u boolForKey:@"startupSlideshowFromFolder"]) {
if ([self slideshowFromStartupPreference])
if ([u boolForKey:@"startupSlideshowSuppressNewWindows"])
return NO;
}
[self newWindow:self];
return NO;
}
return YES;
}
-(void)applicationDidChangeScreenParameters:(NSNotification *)notification {
if (slidesWindow.visible)
[slidesWindow resetScreen];
}
#pragma mark menu methods
enum {
REVEAL_IN_FINDER = 1,
MOVE_TO_TRASH,
LOOP, // Embiggen is also 3
BEGIN_SLIDESHOW,
SET_DESKTOP,
GET_INFO,
RANDOM_MODE,
SLIDESHOW_SCALE_UP,
SLIDESHOW_ACTUAL_SIZE,
NEW_TAB,
BEGIN_SLIDESHOW_ALTERNATE,
MOVE_TO,
MOVE_TO_AGAIN,
JPEG_OP = 100,
ROTATE_L = 107,
ROTATE_R = 105,
EXIF_ORIENT_ROTATE = 113,
EXIF_ORIENT_RESET = 114,
EXIF_THUMB_DELETE = 116,
ROTATE_SAVE = 117,
SORT_NAME = 201,
SORT_DATE_MODIFIED = 202,
SORT_EXIF_DATE = 203,
SHOW_FILE_NAMES = 251,
AUTO_ROTATE = 261,
SLIDESHOW_MENU = 1001,
VIEW_MENU = 200,
FILE_MENU = 300,
};
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
NSInteger t = menuItem.tag;
NSInteger test_t = t;
if (!NSApp.mainWindow) {
// menu items with tags only enabled if there's a window
return !t;
}
if (t>JPEG_OP && t < SORT_NAME) {
if ((t > JPEG_OP + 30 || t == EXIF_THUMB_DELETE) &&
!menuItem.menu.supermenu && // only for contextual menu
![[exifThumbnailDiscloseBtn.window.contentView viewWithTag:2] image]) {
return NO;
}
test_t = JPEG_OP;
}
if (!creeveyWindows.count) frontWindow = nil;
NSUInteger numSelected = frontWindow ? frontWindow.selectedIndexes.count : 0;
BOOL writable, isjpeg;
NSString *moveTo;
switch (test_t) {
case NEW_TAB:
return frontWindow.window.isMainWindow;
case MOVE_TO_AGAIN:
moveTo = [NSUserDefaults.standardUserDefaults stringForKey:@"lastUsedMoveToFolder"];
// fall through
case MOVE_TO:
case MOVE_TO_TRASH:
case JPEG_OP:
// only when slides isn't loading cache!
// only if writeable (we just test the first file in the list)
writable = slidesWindow.isMainWindow
? slidesWindow.currentFile &&
slidesWindow.currentImageLoaded &&
[NSFileManager.defaultManager isDeletableFileAtPath:
slidesWindow.currentFile]
: numSelected > 0 && frontWindow && frontWindow.currentFilesDeletable;
if (t != JPEG_OP) return writable && (t == MOVE_TO_AGAIN ? moveTo != nil : YES);
isjpeg = slidesWindow.isMainWindow
? slidesWindow.currentFile && FileIsJPEG(slidesWindow.currentFile)
: numSelected > 0 && frontWindow && FilesContainJPEG(frontWindow.currentSelection);
if (t == ROTATE_SAVE) { // only allow saving rotations during the slideshow
return writable && isjpeg && slidesWindow.isMainWindow
&& slidesWindow.currentOrientation > 1;
}
if ((t == EXIF_ORIENT_ROTATE || t == EXIF_ORIENT_RESET) && slidesWindow.isMainWindow) {
return writable && isjpeg && slidesWindow.currentFileExifOrientation > 1;
}
return writable && isjpeg;
case REVEAL_IN_FINDER:
return YES;
case BEGIN_SLIDESHOW:
case BEGIN_SLIDESHOW_ALTERNATE:
if (slidesWindow.isMainWindow ) return NO;
return frontWindow && frontWindow.filenamesDone && frontWindow.displayedFilenames.count;
case SET_DESKTOP:
return slidesWindow.isMainWindow
? (slidesWindow.currentFile != nil)
: numSelected == 1;
case AUTO_ROTATE:
return YES;
case GET_INFO:
case SORT_NAME:
case SORT_DATE_MODIFIED:
case SORT_EXIF_DATE:
case SHOW_FILE_NAMES:
return !slidesWindow.isMainWindow;
default:
return YES;
}
}
- (void)updateMenuItemsForSorting:(short int)sortNum {
short int sortType = abs(sortNum);
NSInteger tag = 200 + sortType;
NSMenu *m = [NSApp.mainMenu itemWithTag:VIEW_MENU].submenu;
for (NSInteger i = 201; i <= SORT_EXIF_DATE; ++i) {
NSMenuItem *item = [m itemWithTag:i];
if (i == tag) {
item.state = sortNum > 0 ? NSOnState : NSMixedState;
} else {
item.state = NSOffState;
}
}
}
- (IBAction)sortThumbnails:(id)sender {
short int newSort, oldSort;
oldSort = frontWindow.sortOrder;
newSort = [sender tag] - 200;
if (newSort == abs(oldSort)) {
newSort = -oldSort; // reverse the sort if user selects it again
} else {
if (newSort == 2) newSort = -2; // default to reverse sort if sorting by date
}
[self updateMenuItemsForSorting:newSort];
[frontWindow changeSortOrder:newSort];
if (creeveyWindows.count == 1) // save as default if this is the only window
[NSUserDefaults.standardUserDefaults setInteger:newSort forKey:@"sortBy"];
}
- (IBAction)doShowFilenames:(id)sender {
BOOL b = !frontWindow.imageMatrix.showFilenames;
NSMenuItem *item = sender;
item.state = b;
frontWindow.imageMatrix.showFilenames = b;
if (creeveyWindows.count == 1) // save as default if this is the only window
[NSUserDefaults.standardUserDefaults setBool:b forKey:@"showFilenames"];
}
- (IBAction)doAutoRotateDisplayedImage:(id)sender {
BOOL b = slidesWindow.isMainWindow ? !slidesWindow.autoRotate : !frontWindow.imageMatrix.autoRotate;
NSMenuItem *item = sender;
item.state = b;
frontWindow.imageMatrix.autoRotate = b;
slidesWindow.autoRotate = b;
if (creeveyWindows.count == 1 || slidesWindow.isMainWindow)
[NSUserDefaults.standardUserDefaults setBool:b forKey:@"autoRotateByOrientationTag"];
}
#pragma mark prefs stuff
- (IBAction)openPrefWin:(id)sender; {
if (!prefsWin) {
NSArray * __autoreleasing arr;
if (![NSBundle.mainBundle loadNibNamed:@"PrefsWin" owner:self topLevelObjects:&arr]) return;
_prefWinNibItems = arr;
// non-NSMatrix based radio buttons don't seem to have a way to bind values
NSButton *btn = [NSUserDefaults.standardUserDefaults integerForKey:@"slideshowDefaultMode"] ? [self.slideshowDefaultModeFullscreenBtn.superview viewWithTag:1] : self.slideshowDefaultModeFullscreenBtn;
btn.state = NSOnState;
}
[prefsWin makeKeyAndOrderFront:nil];
}
- (IBAction)chooseStartupDir:(id)sender; {
NSOpenPanel *op=[NSOpenPanel openPanel];
NSUserDefaults *u = NSUserDefaults.standardUserDefaults;
op.canChooseDirectories = YES;
op.canChooseFiles = NO;
op.directoryURL = [NSURL fileURLWithPath:[u stringForKey:@"picturesFolderPath"] isDirectory:YES];