Browse Source
This improves separation between main menu and the unrelated goto time window. Besides that, note that each time bindings are used with the file owner, this owner needs to be an NSWindowController class. Only in this case retain cycles are avoided (bindings have a strong reference to the object used). Thus, this commit helps to properly deinitialize the VLCMain object.pull/35/head
10 changed files with 304 additions and 144 deletions
@ -0,0 +1,101 @@ |
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
|||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="7706" systemVersion="14F25a" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none"> |
|||
<dependencies> |
|||
<deployment version="1070" identifier="macosx"/> |
|||
<development version="5100" identifier="xcode"/> |
|||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="7706"/> |
|||
</dependencies> |
|||
<objects> |
|||
<customObject id="-2" userLabel="File's Owner" customClass="VLCTimeSelectionPanelController"> |
|||
<connections> |
|||
<outlet property="cancelButton" destination="C7h-06-Udn" id="vms-H9-Fs6"/> |
|||
<outlet property="goToLabel" destination="bB6-Le-Ilg" id="Psy-fF-eTf"/> |
|||
<outlet property="okButton" destination="zrN-B3-Ede" id="TzS-HN-YE3"/> |
|||
<outlet property="secsLabel" destination="oMI-0n-rej" id="Heh-nH-7Dv"/> |
|||
<outlet property="stepper" destination="zsp-zD-QHr" id="yab-Mp-27O"/> |
|||
<outlet property="textField" destination="ovY-qj-fWV" id="NtQ-WV-2da"/> |
|||
<outlet property="window" destination="Fqe-af-Tt9" id="u4H-rX-p0W"/> |
|||
</connections> |
|||
</customObject> |
|||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> |
|||
<customObject id="-3" userLabel="Application" customClass="NSObject"/> |
|||
<window title="GoTo Specific Time" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" animationBehavior="default" id="Fqe-af-Tt9" userLabel="GoToTime"> |
|||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/> |
|||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/> |
|||
<rect key="contentRect" x="429" y="553" width="249" height="103"/> |
|||
<rect key="screenRect" x="0.0" y="0.0" width="2560" height="1417"/> |
|||
<view key="contentView" id="NrR-3A-NOR"> |
|||
<rect key="frame" x="0.0" y="0.0" width="249" height="103"/> |
|||
<autoresizingMask key="autoresizingMask"/> |
|||
<subviews> |
|||
<textField verticalHuggingPriority="750" id="bB6-Le-Ilg"> |
|||
<rect key="frame" x="-3" y="79" width="240" height="17"/> |
|||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> |
|||
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="center" title="Go to specific position" id="vXn-nw-Nrc"> |
|||
<font key="font" metaFont="systemBold"/> |
|||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/> |
|||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/> |
|||
</textFieldCell> |
|||
</textField> |
|||
<textField verticalHuggingPriority="750" id="ovY-qj-fWV"> |
|||
<rect key="frame" x="20" y="52" width="159" height="19"/> |
|||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> |
|||
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" alignment="right" title="0" drawsBackground="YES" id="qZx-Li-5O2"> |
|||
<font key="font" metaFont="smallSystem"/> |
|||
<color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/> |
|||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/> |
|||
</textFieldCell> |
|||
<connections> |
|||
<binding destination="-2" name="value" keyPath="self.jumpTimeValue" id="xWJ-vG-f9H"/> |
|||
</connections> |
|||
</textField> |
|||
<button verticalHuggingPriority="750" id="zrN-B3-Ede"> |
|||
<rect key="frame" x="150" y="13" width="84" height="28"/> |
|||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> |
|||
<buttonCell key="cell" type="push" title="OK" bezelStyle="rounded" alignment="center" controlSize="small" borderStyle="border" inset="2" id="icy-jS-WFH"> |
|||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> |
|||
<font key="font" metaFont="smallSystem"/> |
|||
<string key="keyEquivalent" base64-UTF8="YES"> |
|||
DQ |
|||
</string> |
|||
</buttonCell> |
|||
<connections> |
|||
<action selector="buttonPressed:" target="-2" id="0qF-5H-5Fz"/> |
|||
</connections> |
|||
</button> |
|||
<stepper horizontalHuggingPriority="750" verticalHuggingPriority="750" id="zsp-zD-QHr"> |
|||
<rect key="frame" x="185" y="50" width="15" height="22"/> |
|||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> |
|||
<stepperCell key="cell" controlSize="small" continuous="YES" alignment="left" increment="10" maxValue="30000" valueWraps="YES" id="8Ok-J5-Vfx"/> |
|||
<connections> |
|||
<binding destination="-2" name="value" keyPath="self.jumpTimeValue" id="ade-2M-vOh"/> |
|||
</connections> |
|||
</stepper> |
|||
<button verticalHuggingPriority="750" id="C7h-06-Udn"> |
|||
<rect key="frame" x="68" y="13" width="84" height="28"/> |
|||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> |
|||
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" controlSize="small" borderStyle="border" inset="2" id="fXt-nh-exA"> |
|||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/> |
|||
<font key="font" metaFont="smallSystem"/> |
|||
<string key="keyEquivalent" base64-UTF8="YES"> |
|||
Gw |
|||
</string> |
|||
</buttonCell> |
|||
<connections> |
|||
<action selector="buttonPressed:" target="-2" id="Ad9-7v-03L"/> |
|||
</connections> |
|||
</button> |
|||
<textField verticalHuggingPriority="750" id="oMI-0n-rej"> |
|||
<rect key="frame" x="203" y="54" width="34" height="14"/> |
|||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> |
|||
<textFieldCell key="cell" sendsActionOnEndEditing="YES" title="sec." id="74c-xI-3AS"> |
|||
<font key="font" metaFont="smallSystem"/> |
|||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/> |
|||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/> |
|||
</textFieldCell> |
|||
</textField> |
|||
</subviews> |
|||
</view> |
|||
</window> |
|||
</objects> |
|||
</document> |
|||
@ -0,0 +1,53 @@ |
|||
/*****************************************************************************
|
|||
* TimeSelectionPanelController.h: Controller for time selection panel |
|||
***************************************************************************** |
|||
* Copyright (C) 2015 VideoLAN and authors |
|||
* Author: David Fuhrmann <david dot fuhrmann at googlemail dot com> |
|||
* |
|||
* This program 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 2 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program 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 this program; if not, write to the Free Software |
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
|||
*****************************************************************************/ |
|||
|
|||
#import <Cocoa/Cocoa.h> |
|||
|
|||
@interface VLCTimeSelectionPanelController : NSWindowController |
|||
|
|||
@property (readwrite, weak) IBOutlet NSButton *cancelButton; |
|||
@property (readwrite, weak) IBOutlet NSTextField *textField; |
|||
@property (readwrite, weak) IBOutlet NSTextField *goToLabel; |
|||
@property (readwrite, weak) IBOutlet NSButton *okButton; |
|||
@property (readwrite, weak) IBOutlet NSTextField *secsLabel; |
|||
@property (readwrite, weak) IBOutlet NSStepper *stepper; |
|||
|
|||
@property (nonatomic) int jumpTimeValue; |
|||
@property (nonatomic) int maxValue; |
|||
|
|||
- (IBAction)buttonPressed:(id)sender; |
|||
|
|||
/**
|
|||
* Completion handler for textfield panel |
|||
* \param returnCode Result from panel. Can be NSOKButton or NSCancelButton. |
|||
* \param returnTime Resulting time in seconds entered in panel. |
|||
*/ |
|||
typedef void(^TimeSelectionCompletionHandler)(NSInteger returnCode, int64_t returnTime); |
|||
|
|||
/**
|
|||
* Shows the panel as a modal dialog with window as its owner. |
|||
* \param window Parent window for the dialog. |
|||
* \param handler Completion block. |
|||
*/ |
|||
- (void)runModalForWindow:(NSWindow *)window completionHandler:(TimeSelectionCompletionHandler)handler; |
|||
|
|||
|
|||
@end |
|||
@ -0,0 +1,98 @@ |
|||
/***************************************************************************** |
|||
* TimeSelectionPanelController.m: Controller for time selection panel |
|||
***************************************************************************** |
|||
* Copyright (C) 2015 VideoLAN and authors |
|||
* Author: David Fuhrmann <david dot fuhrmann at googlemail dot com> |
|||
* |
|||
* This program 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 2 of the License, or |
|||
* (at your option) any later version. |
|||
* |
|||
* This program 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 this program; if not, write to the Free Software |
|||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
|||
*****************************************************************************/ |
|||
|
|||
#import "VLCTimeSelectionPanelController.h" |
|||
|
|||
#import "misc.h" |
|||
#import "StringUtility.h" |
|||
|
|||
@interface VLCTimeSelectionPanelController() |
|||
{ |
|||
TimeSelectionCompletionHandler _completionHandler; |
|||
} |
|||
|
|||
@end |
|||
|
|||
@implementation VLCTimeSelectionPanelController |
|||
|
|||
#pragma mark - object handling |
|||
|
|||
- (id)init |
|||
{ |
|||
self = [super initWithWindowNibName:@"TimeSelectionPanel"]; |
|||
|
|||
return self; |
|||
} |
|||
|
|||
|
|||
#pragma mark - UI handling |
|||
|
|||
- (void)windowDidLoad |
|||
{ |
|||
[_cancelButton setTitle: _NS("Cancel")]; |
|||
[_okButton setTitle: _NS("OK")]; |
|||
[_secsLabel setStringValue: _NS("sec.")]; |
|||
[_goToLabel setStringValue: _NS("Jump to Time")]; |
|||
[_textField setFormatter:[[PositionFormatter alloc] init]]; |
|||
} |
|||
|
|||
- (IBAction)buttonPressed:(id)sender |
|||
{ |
|||
[self.window orderOut:sender]; |
|||
[NSApp endSheet: self.window]; |
|||
|
|||
// calculate resulting time in secs: |
|||
int64_t timeInSec = 0; |
|||
NSString *string = [_textField stringValue]; |
|||
if ([[string componentsSeparatedByString: @":"] count] > 1 && |
|||
[[string componentsSeparatedByString: @":"] count] <= 3) { |
|||
NSArray *ourTempArray = \ |
|||
[string componentsSeparatedByString: @":"]; |
|||
|
|||
if ([[string componentsSeparatedByString: @":"] count] == 3) { |
|||
timeInSec += ([[ourTempArray firstObject] intValue] *3600); //h |
|||
timeInSec += ([[ourTempArray objectAtIndex:1] intValue] *60); //m |
|||
timeInSec += [[ourTempArray objectAtIndex:2] intValue]; //s |
|||
} else { |
|||
timeInSec += ([[ourTempArray firstObject] intValue] *60); //m |
|||
timeInSec += [[ourTempArray objectAtIndex:1] intValue]; //s |
|||
} |
|||
} |
|||
else |
|||
timeInSec = [string intValue]; |
|||
|
|||
if (_completionHandler) |
|||
_completionHandler(sender == _okButton ? NSOKButton : NSCancelButton, timeInSec); |
|||
} |
|||
|
|||
- (void)runModalForWindow:(NSWindow *)window completionHandler:(TimeSelectionCompletionHandler)handler |
|||
{ |
|||
[self window]; |
|||
[_stepper setMaxValue:self.maxValue]; |
|||
|
|||
_completionHandler = [handler copy]; |
|||
[NSApp beginSheet:self.window |
|||
modalForWindow:window modalDelegate:self |
|||
didEndSelector:nil |
|||
contextInfo:nil]; |
|||
} |
|||
|
|||
@end |
|||
Loading…
Reference in new issue