Skip to content

Commit

Permalink
Improving window handling
Browse files Browse the repository at this point in the history
- Add menu item to create new windows
- Set window title based on audiobook author/title
  • Loading branch information
gonzoua committed Dec 16, 2013
1 parent 3af1860 commit 290e8f7
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 17 deletions.
29 changes: 25 additions & 4 deletions AudioBinderWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define TEXT_MAXDURATION_VIOLATED NSLocalizedString(@"%s: duration (%d sec) is larger then max. volume duration (%lld sec.)", nil)
#define TEXT_FAILED_TO_PLAY NSLocalizedString(@"Failed to play", nil)
#define TEXT_CANT_PLAY NSLocalizedString(@"Failed to play: %@", nil)
#define TEXT_AUDIOBOOK NSLocalizedString(@"Audiobook", nil)
#define TEXT_AUDIOBOOKS NSLocalizedString(@"Audiobooks", nil)
#define TEXT_FILE_EXISTS NSLocalizedString(@"File exists", @"epub file exists")
#define TEXT_FILE_OVERWRITE NSLocalizedString(@"File %@ already exists, replace?", @"epub file exists")
Expand All @@ -47,8 +48,6 @@
#define KVO_CONTEXT_COMMONAUTHOR_CHANGED @"CommonAuthorChanged"
#define KVO_CONTEXT_COMMONALBUM_CHANGED @"CommonAlbumChanged"



column_t columnDefs[] = {
{COLUMNID_FILE, @"File", NO},
{COLUMNID_AUTHOR, @"Author", NO},
Expand Down Expand Up @@ -122,6 +121,8 @@ - (void)windowDidLoad
forKeyPath:@"commonAlbum"
options:0
context:KVO_CONTEXT_COMMONALBUM_CHANGED];

[self updateWindowTitle];
}

- (void)awakeFromNib {
Expand Down Expand Up @@ -274,8 +275,6 @@ - (void)saveTableColumns {
[[NSUserDefaults standardUserDefaults] setObject:cols forKey:ColumnsConfiguration];
}



- (IBAction) addFiles: (id)sender
{
int i; // Loop counter.
Expand Down Expand Up @@ -1033,4 +1032,26 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
}
}

- (void)updateWindowTitle
{
NSString *author = [[[form cellAtIndex:ABBAuthor] stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString *title = [[[form cellAtIndex:ABBTitle] stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
if (([author length] == 0) && ([title length] == 0))
{
[self.window setTitle:TEXT_AUDIOBOOK];
}
else {
NSString *winTitle = [NSString stringWithFormat:@"%@ - %@", title, author];
[self.window setTitle:winTitle];
}
}

-(BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor {
if (control == form) {
[self updateWindowTitle];
}

return YES;
}

@end
2 changes: 2 additions & 0 deletions AudioBookBinderAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
+ (void) initialize;

- (IBAction) openChaptersHowTo: (id)sender;
- (IBAction) newAudiobookWindow: (id)sender;



#ifndef APP_STORE_BUILD
Expand Down
16 changes: 11 additions & 5 deletions AudioBookBinderAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[SUUpdater sharedUpdater];
#endif

AudioBinderWindowController *controller = [[[AudioBinderWindowController alloc] initWithWindowNibName:@"AudioBinderWindow"] retain];

[controller showWindow:self];

[[controller window] makeMainWindow];
[self newAudiobookWindow:nil];
}

- (void)openChaptersHowTo:(id)sender
Expand Down Expand Up @@ -181,5 +177,15 @@ - (void) resetTotalProgress
[NSApp setApplicationIconImage:_appIcon];
}

- (IBAction) newAudiobookWindow: (id)sender
{
AudioBinderWindowController *controller = [[[AudioBinderWindowController alloc] initWithWindowNibName:@"AudioBinderWindow"] retain];

[controller showWindow:self];

[[controller window] makeMainWindow];
}



@end
59 changes: 51 additions & 8 deletions en.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,25 @@
<string key="NSTitle">File</string>
<object class="NSMutableArray" key="NSMenuItems">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMenuItem" id="493011739">
<reference key="NSMenu" ref="720053764"/>
<string key="NSTitle">New Audiobook</string>
<string key="NSKeyEquiv">N</string>
<int key="NSKeyEquivModMask">1048576</int>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="35465992"/>
<reference key="NSMixedImage" ref="502551668"/>
</object>
<object class="NSMenuItem" id="433447469">
<reference key="NSMenu" ref="720053764"/>
<bool key="NSIsDisabled">YES</bool>
<bool key="NSIsSeparator">YES</bool>
<string key="NSTitle"/>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="35465992"/>
<reference key="NSMixedImage" ref="502551668"/>
</object>
<object class="NSMenuItem" id="722745758">
<reference key="NSMenu" ref="720053764"/>
<string key="NSTitle">Add Files</string>
Expand Down Expand Up @@ -1616,6 +1635,14 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
</object>
<int key="connectionID">1053</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">newAudiobookWindow:</string>
<reference key="source" ref="976324537"/>
<reference key="destination" ref="493011739"/>
</object>
<int key="connectionID">1064</int>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">makeKeyAndOrderFront:</string>
Expand Down Expand Up @@ -2085,6 +2112,8 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<reference ref="722745758"/>
<reference ref="708754028"/>
<reference ref="724214841"/>
<reference ref="493011739"/>
<reference ref="433447469"/>
</object>
<reference key="parent" ref="379814623"/>
</object>
Expand Down Expand Up @@ -2672,6 +2701,16 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<reference key="object" ref="665263495"/>
<reference key="parent" ref="212817051"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">1062</int>
<reference key="object" ref="493011739"/>
<reference key="parent" ref="720053764"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">1063</int>
<reference key="object" ref="433447469"/>
<reference key="parent" ref="720053764"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
Expand All @@ -2685,6 +2724,8 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string>1043.IBPluginDependency</string>
<string>1044.IBPluginDependency</string>
<string>1045.IBPluginDependency</string>
<string>1062.IBPluginDependency</string>
<string>1063.IBPluginDependency</string>
<string>129.IBPluginDependency</string>
<string>130.IBPluginDependency</string>
<string>131.IBPluginDependency</string>
Expand Down Expand Up @@ -2835,6 +2876,8 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{{297, 458}, {429, 259}}</string>
<boolean value="NO"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
Expand Down Expand Up @@ -2935,7 +2978,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<reference key="dict.values" ref="0"/>
</object>
<nil key="sourceID"/>
<int key="maxID">1061</int>
<int key="maxID">1064</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand All @@ -2951,7 +2994,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string>bind:</string>
<string>cancel:</string>
<string>delFiles:</string>
<string>genresButtonChanged:</string>
<string>joinFiles:</string>
<string>playStop:</string>
<string>renumberChapters:</string>
Expand All @@ -2977,7 +3019,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
Expand All @@ -2988,7 +3029,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string>bind:</string>
<string>cancel:</string>
<string>delFiles:</string>
<string>genresButtonChanged:</string>
<string>joinFiles:</string>
<string>playStop:</string>
<string>renumberChapters:</string>
Expand Down Expand Up @@ -3017,10 +3057,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string key="name">delFiles:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">genresButtonChanged:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">joinFiles:</string>
<string key="candidateClassName">id</string>
Expand Down Expand Up @@ -3188,19 +3224,22 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>checkForUpdates:</string>
<string>newAudiobookWindow:</string>
<string>openChaptersHowTo:</string>
</object>
<object class="NSArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>id</string>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>checkForUpdates:</string>
<string>newAudiobookWindow:</string>
<string>openChaptersHowTo:</string>
</object>
<object class="NSArray" key="dict.values">
Expand All @@ -3209,6 +3248,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
<string key="name">checkForUpdates:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">newAudiobookWindow:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
<string key="name">openChaptersHowTo:</string>
<string key="candidateClassName">id</string>
Expand Down

0 comments on commit 290e8f7

Please sign in to comment.