Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/Classes/PasteWarningPanelController.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 190 - (show annotations) (download)
Sat Mar 14 14:32:34 2020 UTC (4 years, 2 months ago) by toshinagata1964
File size: 4777 byte(s)
Copy & paste for multiple tracks are reworked
1 //
2 // PasteWarningPanelController.m
3 // Alchemusica
4 //
5 // Created by Toshi Nagata on 2020/03/14.
6 // Copyright 2020 Toshi Nagata. All rights reserved.
7 //
8 /*
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation version 2 of the License.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 */
18
19 #import "PasteWarningPanelController.h"
20 #import "NSWindowControllerAdditions.h"
21 #import "MyAppController.h"
22
23 @implementation PasteWarningPanelController
24
25 + (id)createPasteWarningPanelControllerOfType:(int)aType
26 {
27 PasteWarningPanelController *cont;
28 NSString *nibName;
29 switch (aType) {
30 case kPasteWarningTypeTooFewTargets:
31 nibName = @"PasteWarningTooFewTargets";
32 break;
33 case kPasteWarningTypeTooManyTargets:
34 nibName = @"PasteWarningTooManyTargets";
35 break;
36 case kPasteWarningTypeConductorShouldBeEditable:
37 nibName = @"PasteWarningConductorShouldBeEditable";
38 break;
39 case kPasteWarningTypeConductorShouldNotBeEditable:
40 nibName = @"PasteWarningConductorShouldNotBeEditable";
41 break;
42 default:
43 return nil;
44 }
45 cont = [[[PasteWarningPanelController alloc] initWithWindowNibName:nibName] autorelease];
46 cont->type = aType;
47 return cont;
48 }
49
50 - (void)windowDidLoad
51 {
52 id obj;
53 int n;
54 returnCode = 1;
55 switch (type) {
56 case kPasteWarningTypeTooFewTargets:
57 obj = MyAppCallback_getObjectGlobalSettings(@"paste.toofewtargets");
58 n = (obj ? [obj intValue] : 1);
59 if (n == 1) {
60 [radio1 setState:NSOnState];
61 [radio2 setState:NSOffState];
62 } else {
63 [radio1 setState:NSOffState];
64 [radio2 setState:NSOnState];
65 }
66 break;
67 case kPasteWarningTypeTooManyTargets:
68 obj = MyAppCallback_getObjectGlobalSettings(@"paste.toomanytargets");
69 n = (obj ? [obj intValue] : 1);
70 if (n == 1) {
71 [radio1 setState:NSOnState];
72 [radio2 setState:NSOffState];
73 } else {
74 [radio1 setState:NSOffState];
75 [radio2 setState:NSOnState];
76 }
77 break;
78 }
79 }
80
81 - (void)setMainMessageWithInteger:(int)n1 and:(int)n2
82 {
83 NSString *str;
84 [[self window] center]; // Dummy code for loading window
85 if (mainMessage == nil)
86 return;
87 str = [mainMessage stringValue];
88 str = [str stringByReplacingOccurrencesOfString:@"%1" withString:[NSString stringWithFormat:@"%d", n1]];
89 str = [str stringByReplacingOccurrencesOfString:@"%2" withString:[NSString stringWithFormat:@"%d", n2]];
90 [mainMessage setStringValue:str];
91 }
92
93 - (int)runSheetModalWithWindow:(NSWindow *)window
94 {
95 NSModalSession session;
96 NSInteger result;
97 session = [NSApp beginModalSessionForWindow:window];
98 [NSApp beginSheet:[self window] modalForWindow:window modalDelegate:self didEndSelector: @selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:nil];
99 while ((result = [NSApp runModalSession:session]) == NSRunContinuesResponse)
100 ;
101 [NSApp endModalSession:session];
102 [self close];
103 switch (type) {
104 case kPasteWarningTypeTooFewTargets:
105 if (result == 1 || result == 2)
106 MyAppCallback_setObjectGlobalSettings(@"paste.toofewtargets", [NSNumber numberWithInteger:result]);
107 break;
108 case kPasteWarningTypeTooManyTargets:
109 if (result == 1 || result == 2)
110 MyAppCallback_setObjectGlobalSettings(@"paste.toomanytargets", [NSNumber numberWithInteger:result]);
111 break;
112 }
113 return (int)result;
114 }
115
116 - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
117 {
118 [[self window] close];
119 [NSApp stopModalWithCode:returnCode];
120 }
121
122 - (IBAction)radioSelected:(id)sender
123 {
124 returnCode = (int)[sender tag];
125 /* On MacOS 10.8 and later, the radio group behavior is automatically implemented. However, on MacOS 10.6 and 10.7, we should handle it manually (because NSMatrix is made deprecated). */
126 if (sender == radio1)
127 [radio2 setState:NSOffState];
128 else if (sender == radio2)
129 [radio1 setState:NSOffState];
130 }
131
132 - (IBAction)cancelPressed:(id)sender
133 {
134 [NSApp endSheet:[self window] returnCode:0];
135 }
136
137 - (IBAction)pastePressed:(id)sender
138 {
139 [NSApp endSheet:[self window] returnCode:returnCode];
140 }
141
142 @end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26