-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathAppController.m
More file actions
executable file
·104 lines (87 loc) · 2.71 KB
/
AppController.m
File metadata and controls
executable file
·104 lines (87 loc) · 2.71 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
//
// AppController.m
// WhatSub
//
// Created by Marcin Grabda on 5/10/09.
// Copyright 2010 Marcin Grabda. All rights reserved.
//
#import "AppController.h"
#import "DropFileView.h"
#import "AppPreferencesController.h"
#import "FileHandler.h"
#import "AppPreferences.h"
@implementation AppController
@synthesize mainWindow;
static AppController* instance = nil;
- (id)init
{
self = [super init];
if (self)
{
instance = self;
allowedFileTypes = [[AppPreferences typeExtensionsForName:@"Movie"] arrayByAddingObjectsFromArray:
[AppPreferences typeExtensionsForName:@"Subtitles"]];
}
return self;
}
/* register application defaults */
+ (void)initialize
{
NSBundle* mainBundle = [NSBundle mainBundle];
NSString* defaultsFile = [mainBundle pathForResource:@"Defaults" ofType:@"plist"];
NSDictionary* defaults = [NSDictionary dictionaryWithContentsOfFile:defaultsFile];
NSUserDefaults* standardUserDefaults = [NSUserDefaults standardUserDefaults];
[standardUserDefaults registerDefaults:defaults];
}
+ (AppController*)instance
{
return instance;
}
- (IBAction)openPreferencesWindow:(id)sender
{
[[AppPreferencesController sharedPrefsWindowController] showWindow:nil];
}
/* handle files dropped on the dock */
- (void)application:(NSApplication *)sender openFiles:(NSArray*)files
{
[fileHandler startProcessingFiles:files];
}
/* handle files dropped on the view area */
- (void)filesDragged:(DropFileView*)sender
{
NSArray* files = [sender filenames];
NSMutableArray* filteredFiles = [NSMutableArray new];
NSMutableArray* updatedAllowedFileTypes = [[NSMutableArray alloc] initWithArray:allowedFileTypes];
if (![AppPreferences isSRTOnlyConversionAllowed])
{
[updatedAllowedFileTypes removeObjectsInArray:[AppPreferences typeExtensionsForName:@"Subtitles"]];
}
for (NSString* file in files)
{
NSString* pathExtension = [file pathExtension];
if ([updatedAllowedFileTypes containsObject:pathExtension])
{
[filteredFiles addObject:file];
}
}
if ([filteredFiles count] > 0)
{
[fileHandler startProcessingFiles:filteredFiles];
}
}
/* handle files opened via the menu item */
- (IBAction)openFile:(id)sender
{
NSOpenPanel* openPanel = [NSOpenPanel openPanel];
[openPanel setCanChooseFiles:YES];
[openPanel setCanChooseDirectories:NO];
[openPanel setCanCreateDirectories:NO];
[openPanel setAllowsMultipleSelection:YES];
[openPanel setTitle:@"Select a file to open..."];
if ([openPanel runModalForDirectory:nil file:nil types:allowedFileTypes] == NSOKButton)
{
NSArray* files = [openPanel filenames];
[fileHandler startProcessingFiles:files];
}
}
@end