CAS: use the generic dialogs to fetch a text input from the user or to let him/her choose an item in a popup

This commit is contained in:
Felix Paul Kühne 2012-09-12 11:09:15 +02:00
parent 8db7da131e
commit 8d95ee6111
4 changed files with 134 additions and 1071 deletions

View File

@ -111,6 +111,7 @@ EXTRA_DIST += \
extras/package/macosx/Resources/English.lproj/MediaInfo.xib \
extras/package/macosx/Resources/English.lproj/Open.xib \
extras/package/macosx/Resources/English.lproj/Preferences.xib \
extras/package/macosx/Resources/English.lproj/SharedDialogs.xib \
extras/package/macosx/Resources/English.lproj/SyncTracks.xib \
extras/package/macosx/Resources/English.lproj/VideoEffects.xib \
extras/package/macosx/Resources/English.lproj/Wizard.xib \

View File

@ -22,6 +22,7 @@
*****************************************************************************/
#import <Cocoa/Cocoa.h>
#import "SharedDialogs.h"
@interface VLCConvertAndSave : NSObject
{
@ -91,20 +92,6 @@
IBOutlet id _customize_subs_pop;
IBOutlet id _customize_subs_overlay_ckb;
IBOutlet id _addProfile_panel;
IBOutlet id _addProfile_title_lbl;
IBOutlet id _addProfile_subtitle_lbl;
IBOutlet id _addProfile_name_fld;
IBOutlet id _addProfile_cancel_btn;
IBOutlet id _addProfile_ok_btn;
IBOutlet id _deleteProfile_panel;
IBOutlet id _deleteProfile_title_lbl;
IBOutlet id _deleteProfile_subtitle_lbl;
IBOutlet id _deleteProfile_pop;
IBOutlet id _deleteProfile_cancel_btn;
IBOutlet id _deleteProfile_ok_btn;
IBOutlet id _stream_panel;
IBOutlet id _stream_ok_btn;
IBOutlet id _stream_destination_lbl;
@ -152,7 +139,6 @@
- (IBAction)customizeProfile:(id)sender;
- (IBAction)closeCustomizationSheet:(id)sender;
- (IBAction)newProfileAction:(id)sender;
- (IBAction)deleteProfileAction:(id)sender;
- (IBAction)iWantAFile:(id)sender;
- (IBAction)iWantAStream:(id)sender;
- (IBAction)cancelDestination:(id)sender;
@ -162,6 +148,9 @@
- (IBAction)streamTypeToggle:(id)sender;
- (IBAction)streamAnnouncementToggle:(id)sender;
- (void)panel:(VLCEnterTextPanel *)panel returnValue:(NSUInteger)value text:(NSString *)text;
- (void)panel:(VLCSelectItemInPopupPanel *)panel returnValue:(NSUInteger)value item:(NSUInteger)item;
- (void)updateDropView;
@end

View File

@ -185,14 +185,6 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
[_customize_aud_samplerate_lbl setStringValue: _NS("Sample Rate")];
[_customize_subs_ckb setTitle: _NS("Subtitles")];
[_customize_subs_overlay_ckb setTitle: _NS("Overlay subtitles on the video")];
[_addProfile_title_lbl setStringValue:_NS("Save as new profile")];
[_addProfile_subtitle_lbl setStringValue:_NS("Enter a name for the new profile:")];
[_addProfile_cancel_btn setTitle:_NS("Cancel")];
[_addProfile_ok_btn setTitle:_NS("Save")];
[_deleteProfile_title_lbl setStringValue:_NS("Remove a profile")];
[_deleteProfile_subtitle_lbl setStringValue:_NS("Select the profile you would like to remove:")];
[_deleteProfile_cancel_btn setTitle:_NS("Cancel")];
[_deleteProfile_ok_btn setTitle:_NS("Remove")];
[_stream_ok_btn setTitle:_NS("Close")];
[_stream_destination_lbl setStringValue:_NS("Stream Destination")];
[_stream_announcement_lbl setStringValue:_NS("Stream Announcement")];
@ -348,77 +340,29 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
- (IBAction)newProfileAction:(id)sender
{
if (sender == _customize_newProfile_btn) {
[_addProfile_name_fld setStringValue:@""];
[NSApp beginSheet:_addProfile_panel modalForWindow:_customize_panel modalDelegate:self didEndSelector:NULL contextInfo:nil];
} else {
[_addProfile_panel orderOut:sender];
[NSApp endSheet: _addProfile_panel];
/* show panel */
VLCEnterTextPanel * panel = [VLCEnterTextPanel sharedInstance];
[panel setTitle: _NS("Save as new profile")];
[panel setSubTitle: _NS("Enter a name for the new profile:")];
[panel setCancelButtonLabel: _NS("Cancel")];
[panel setOKButtonLabel: _NS("Save")];
[panel setTarget:self];
if (sender == _addProfile_ok_btn && [[_addProfile_name_fld stringValue] length] > 0) {
/* prepare current data */
[self updateCurrentProfile];
/* add profile to arrays */
NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:self.profileNames];
[workArray addObject:[_addProfile_name_fld stringValue]];
[self setProfileNames:[[[NSArray alloc] initWithArray:workArray] autorelease]];
[workArray release];
workArray = [[NSMutableArray alloc] initWithArray:self.profileValueList];
[workArray addObject:[[[NSArray alloc] initWithArray:self.currentProfile] autorelease]];
[self setProfileValueList:[[[NSArray alloc] initWithArray:workArray] autorelease]];
[workArray release];
/* update UI */
[self recreateProfilePopup];
[_profile_pop selectItemWithTitle:[_addProfile_name_fld stringValue]];
/* update internals */
[self switchProfile:sender];
[self storeProfilesOnDisk];
}
}
[panel runModalForWindow:_customize_panel];
}
- (IBAction)deleteProfileAction:(id)sender
{
if (sender == _deleteProfile_cancel_btn) {
/* close panel */
[_deleteProfile_panel orderOut:sender];
[NSApp endSheet: _deleteProfile_panel];
} else if (sender == _deleteProfile_ok_btn) {
/* close panel */
[_deleteProfile_panel orderOut:sender];
[NSApp endSheet: _deleteProfile_panel];
/* show panel */
VLCSelectItemInPopupPanel * panel = [VLCSelectItemInPopupPanel sharedInstance];
[panel setTitle:_NS("Remove a profile")];
[panel setSubTitle:_NS("Select the profile you would like to remove:")];
[panel setOKButtonLabel:_NS("Remove")];
[panel setCancelButtonLabel:_NS("Cancel")];
[panel setPopupButtonContent:self.profileNames];
[panel setTarget:self];
/* remove requested profile from the arrays */
NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:self.profileNames];
[workArray removeObjectAtIndex:[_deleteProfile_pop indexOfSelectedItem]];
[self setProfileNames:[[[NSArray alloc] initWithArray:workArray] autorelease]];
[workArray release];
workArray = [[NSMutableArray alloc] initWithArray:self.profileValueList];
[workArray removeObjectAtIndex:[_deleteProfile_pop indexOfSelectedItem]];
[self setProfileValueList:[[[NSArray alloc] initWithArray:workArray] autorelease]];
[workArray release];
/* update UI */
[_profile_pop removeAllItems];
[_profile_pop addItemsWithTitles:self.profileNames];
[_profile_pop addItemWithTitle:_NS("Custom")];
[[_profile_pop menu] addItem:[NSMenuItem separatorItem]];
[_profile_pop addItemWithTitle:_NS("Organize Profiles")];
[[_profile_pop lastItem] setTarget: self];
[[_profile_pop lastItem] setAction: @selector(deleteProfileAction:)];
/* update internals */
[self switchProfile:sender];
[self storeProfilesOnDisk];
} else {
/* show panel */
[_deleteProfile_pop removeAllItems];
[_deleteProfile_pop addItemsWithTitles:self.profileNames];
[NSApp beginSheet:_deleteProfile_panel modalForWindow:_window modalDelegate:self didEndSelector:NULL contextInfo:nil];
}
[panel runModalForWindow:_window];
}
- (IBAction)iWantAFile:(id)sender
@ -617,6 +561,62 @@ static VLCConvertAndSave *_o_sharedInstance = nil;
return NO;
}
- (void)panel:(VLCEnterTextPanel *)panel returnValue:(NSUInteger)value text:(NSString *)text
{
if (value == NSOKButton) {
if ([text length] > 0) {
/* prepare current data */
[self updateCurrentProfile];
/* add profile to arrays */
NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:self.profileNames];
[workArray addObject:text];
[self setProfileNames:[[[NSArray alloc] initWithArray:workArray] autorelease]];
[workArray release];
workArray = [[NSMutableArray alloc] initWithArray:self.profileValueList];
[workArray addObject:[[[NSArray alloc] initWithArray:self.currentProfile] autorelease]];
[self setProfileValueList:[[[NSArray alloc] initWithArray:workArray] autorelease]];
[workArray release];
/* update UI */
[self recreateProfilePopup];
[_profile_pop selectItemWithTitle:text];
/* update internals */
[self switchProfile:self];
[self storeProfilesOnDisk];
}
}
}
- (void)panel:(VLCSelectItemInPopupPanel *)panel returnValue:(NSUInteger)value item:(NSUInteger)item
{
if (value == NSOKButton) {
/* remove requested profile from the arrays */
NSMutableArray * workArray = [[NSMutableArray alloc] initWithArray:self.profileNames];
[workArray removeObjectAtIndex:item];
[self setProfileNames:[[[NSArray alloc] initWithArray:workArray] autorelease]];
[workArray release];
workArray = [[NSMutableArray alloc] initWithArray:self.profileValueList];
[workArray removeObjectAtIndex:item];
[self setProfileValueList:[[[NSArray alloc] initWithArray:workArray] autorelease]];
[workArray release];
/* update UI */
[_profile_pop removeAllItems];
[_profile_pop addItemsWithTitles:self.profileNames];
[_profile_pop addItemWithTitle:_NS("Custom")];
[[_profile_pop menu] addItem:[NSMenuItem separatorItem]];
[_profile_pop addItemWithTitle:_NS("Organize Profiles...")];
[[_profile_pop lastItem] setTarget: self];
[[_profile_pop lastItem] setAction: @selector(deleteProfileAction:)];
/* update internals */
[self switchProfile:self];
[self storeProfilesOnDisk];
}
}
# pragma mark -
# pragma mark Private Functionality
- (void)updateDropView