From b07731e2f0daad0952fa5fe7c73a9794ddc7f530 Mon Sep 17 00:00:00 2001 From: ycastonguay Date: Sun, 18 Aug 2013 23:26:05 -0400 Subject: [PATCH] Mac: Updated Main view after changes on Windows (added Markers, Loops, etc.). Markers are now refreshed and can be added/played. Added contextual menu for Library Browser and Song Browser but not fully working yet. Related to issue #381. --- .../Controllers/MainWindowController.cs | 200 +++++++++++++----- MPfm/MPfm.Mac/Windows/MainWindow.designer.cs | 3 + MPfm/MPfm.Mac/Windows/XIB/MainWindow.xib | 152 ++++++++++++- 3 files changed, 297 insertions(+), 58 deletions(-) diff --git a/MPfm/MPfm.Mac/Windows/Controllers/MainWindowController.cs b/MPfm/MPfm.Mac/Windows/Controllers/MainWindowController.cs index 7ee8cf7c..4404da47 100644 --- a/MPfm/MPfm.Mac/Windows/Controllers/MainWindowController.cs +++ b/MPfm/MPfm.Mac/Windows/Controllers/MainWindowController.cs @@ -38,6 +38,7 @@ using MPfm.Mac.Classes.Helpers; using MPfm.Mac.Classes.Delegates; using MPfm.Player.Objects; +using MPfm.MVP.Presenters; namespace MPfm.Mac { @@ -46,6 +47,7 @@ namespace MPfm.Mac /// public partial class MainWindowController : BaseWindowController, IMainView { + List _markers = new List(); LibraryBrowserOutlineViewDelegate _libraryBrowserOutlineViewDelegate = null; LibraryBrowserDataSource _libraryBrowserDataSource = null; SongBrowserTableViewDelegate _songBrowserOutlineViewDelegate = null; @@ -101,6 +103,10 @@ public override void WindowDidLoad() tableSongBrowser.AllowsMultipleSelection = true; tableSongBrowser.DoubleClick += HandleSongBrowserDoubleClick; + tableMarkers.WeakDelegate = this; + tableMarkers.WeakDataSource = this; + tableMarkers.DoubleClick += HandleMarkersDoubleClick; + LoadImages(); SetTheme(); @@ -482,10 +488,15 @@ private void LoadImages() partial void actionGoToMarker(NSObject sender) { + if(tableMarkers.SelectedRow == -1) + return; + + OnSelectMarker(_markers[tableMarkers.SelectedRow]); } partial void actionAddMarker(NSObject sender) { + OnAddMarker(MarkerTemplateNameType.Verse); } partial void actionEditMarker(NSObject sender) @@ -496,6 +507,45 @@ private void LoadImages() { } + partial void actionContextualMenuPlay(NSObject sender) + { + } + + [Export ("numberOfRowsInTableView:")] + public int GetRowCount(NSTableView tableView) + { + if(tableView.Identifier == "tableMarkers") + return _markers.Count; + + return 0; + } + + [Export ("tableView:dataCellForTableColumn:row:")] + public NSObject GetObjectValue(NSTableView tableView, NSTableColumn tableColumn, int row) + { + return new NSString(); + } + + [Export ("tableView:viewForTableColumn:row:")] + public NSView GetViewForItem(NSTableView tableView, NSTableColumn tableColumn, int row) + { + NSTableCellView view; + view = (NSTableCellView)tableView.MakeView(tableColumn.Identifier.ToString().Replace("column", "cell"), this); + view.TextField.Font = NSFont.FromFontName("Junction", 11); + + if (tableView.Identifier == "tableMarkers") + { + if (tableColumn.Identifier.ToString() == "columnMarkerName") + view.TextField.StringValue = _markers[row].Name; + else if (tableColumn.Identifier.ToString() == "columnMarkerPosition") + view.TextField.StringValue = _markers[row].Position; + else + view.TextField.StringValue = string.Empty; + } + + return view; + } + [Export ("outlineViewItemDidExpand")] public void ItemDidExpand(NSNotification notification) { @@ -514,34 +564,23 @@ public void ItemDidExpand(NSNotification notification) outlineLibraryBrowser.ReloadData(); } } + + private void HandleMarkersDoubleClick(object sender, EventArgs e) + { + if (tableMarkers.SelectedRow == -1) + return; + + OnSelectMarker(_markers[tableMarkers.SelectedRow]); + } protected void HandleLibraryBrowserDoubleClick(object sender, EventArgs e) { if(outlineLibraryBrowser.SelectedRow == -1) return; - try - { - // Get selected item and start playback - Tracing.Log("MainWindowController.HandleLibraryBrowserDoubleClick -- Getting library browser item..."); - LibraryBrowserItem item = (LibraryBrowserItem)outlineLibraryBrowser.ItemAtRow(outlineLibraryBrowser.SelectedRow); - Tracing.Log("MainWindowController.HandleLibraryBrowserDoubleClick -- Calling LibraryBrowserPresenter.TreeNodeDoubleClicked..."); - if(OnTreeNodeDoubleClicked != null) - OnTreeNodeDoubleClicked.Invoke(item.Entity); - } - catch (Exception ex) - { - // Build text - StringBuilder sb = new StringBuilder(); - sb.AppendLine("An error occured in the Main Window Controller component (when double-clicking on an item in the Library Browser):"); - sb.AppendLine(ex.Message); - sb.AppendLine(); - sb.AppendLine(ex.StackTrace); - - // Show alert - Tracing.Log(sb.ToString()); - CocoaHelper.ShowAlert("Error", sb.ToString(), NSAlertStyle.Critical); - } + LibraryBrowserItem item = (LibraryBrowserItem)outlineLibraryBrowser.ItemAtRow(outlineLibraryBrowser.SelectedRow); + if(OnTreeNodeDoubleClicked != null) + OnTreeNodeDoubleClicked.Invoke(item.Entity); } protected void HandleSongBrowserDoubleClick(object sender, EventArgs e) @@ -549,24 +588,9 @@ protected void HandleSongBrowserDoubleClick(object sender, EventArgs e) if (tableSongBrowser.SelectedRow == -1) return; - try - { - // Get selected item and start playback - AudioFile audioFile = _songBrowserSource.Items[tableSongBrowser.SelectedRow].AudioFile; - if(OnTableRowDoubleClicked != null) - OnTableRowDoubleClicked.Invoke(audioFile); - } - catch (Exception ex) - { - StringBuilder sb = new StringBuilder(); - sb.AppendLine("An error occured in the Main Window Controller component (when double-clicking on an item in the Song Browser):"); - sb.AppendLine(ex.Message); - sb.AppendLine(); - sb.AppendLine(ex.StackTrace); - - Tracing.Log(sb.ToString()); - CocoaHelper.ShowAlert("Error", sb.ToString(), NSAlertStyle.Critical); - } + AudioFile audioFile = _songBrowserSource.Items[tableSongBrowser.SelectedRow].AudioFile; + if(OnTableRowDoubleClicked != null) + OnTableRowDoubleClicked.Invoke(audioFile); } public void RefreshAll() @@ -683,14 +707,7 @@ public void RefreshPlayerTimeShifting(PlayerTimeShiftingEntity entity) public void PlayerError(Exception ex) { InvokeOnMainThread(delegate { - StringBuilder sb = new StringBuilder(); - sb.AppendLine("An error occured in the Player component:"); - sb.AppendLine(ex.Message); - sb.AppendLine(); - sb.AppendLine(ex.StackTrace); - - Tracing.Log(sb.ToString()); - CocoaHelper.ShowAlert("Error", sb.ToString(), NSAlertStyle.Critical); + CocoaHelper.ShowAlert("Error", string.Format("An error occured in the Player component: {0}", ex), NSAlertStyle.Critical); }); } @@ -747,5 +764,92 @@ public void RefreshLibraryBrowserNode(LibraryBrowserEntity entity, IEnumerable OnChangeKey { get; set; } + public Action OnSetInterval { get; set; } + public Action OnResetInterval { get; set; } + public Action OnIncrementInterval { get; set; } + public Action OnDecrementInterval { get; set; } + + public void PitchShiftingError(Exception ex) + { + InvokeOnMainThread(delegate { + CocoaHelper.ShowAlert("Error", string.Format("An error occured in the PitchShifting component: {0}", ex), NSAlertStyle.Critical); + }); + } + + public void RefreshKeys(List> keys) + { + } + + public void RefreshPitchShifting(PlayerPitchShiftingEntity entity) + { + } + + #endregion + + #region ITimeShiftingView implementation + + public Action OnSetTimeShifting { get; set; } + public Action OnResetTimeShifting { get; set; } + public Action OnUseDetectedTempo { get; set; } + public Action OnIncrementTempo { get; set; } + public Action OnDecrementTempo { get; set; } + + public void TimeShiftingError(Exception ex) + { + InvokeOnMainThread(delegate { + CocoaHelper.ShowAlert("Error", string.Format("An error occured in the TimeShifting component: {0}", ex), NSAlertStyle.Critical); + }); + } + + public void RefreshTimeShifting(PlayerTimeShiftingEntity entity) + { + } + + #endregion + + #region ILoopsView implementation + + public Action OnAddLoop { get; set; } + public Action OnEditLoop { get; set; } + + public void LoopError(Exception ex) + { + InvokeOnMainThread(delegate { + CocoaHelper.ShowAlert("Error", string.Format("An error occured in the Loops component: {0}", ex), NSAlertStyle.Critical); + }); + } + + public void RefreshLoops(List loops) + { + } + + #endregion + + #region IMarkersView implementation + + public Action OnAddMarker { get; set; } + public Action OnEditMarker { get; set; } + public Action OnSelectMarker { get; set; } + + public void MarkerError(Exception ex) + { + InvokeOnMainThread(delegate { + CocoaHelper.ShowAlert("Error", string.Format("An error occured in the Markers component: {0}", ex), NSAlertStyle.Critical); + }); + } + + public void RefreshMarkers(List markers) + { + InvokeOnMainThread(delegate { + _markers = markers.ToList(); + tableMarkers.ReloadData(); + }); + } + + #endregion + } } diff --git a/MPfm/MPfm.Mac/Windows/MainWindow.designer.cs b/MPfm/MPfm.Mac/Windows/MainWindow.designer.cs index a58d0585..728321d1 100644 --- a/MPfm/MPfm.Mac/Windows/MainWindow.designer.cs +++ b/MPfm/MPfm.Mac/Windows/MainWindow.designer.cs @@ -322,6 +322,9 @@ partial class MainWindowController [Action ("actionRemoveMarker:")] partial void actionRemoveMarker (MonoMac.Foundation.NSObject sender); + + [Action ("actionContextualMenuPlay:")] + partial void actionContextualMenuPlay (MonoMac.Foundation.NSObject sender); void ReleaseDesignerOutlets () { diff --git a/MPfm/MPfm.Mac/Windows/XIB/MainWindow.xib b/MPfm/MPfm.Mac/Windows/XIB/MainWindow.xib index c71882af..3c540d00 100644 --- a/MPfm/MPfm.Mac/Windows/XIB/MainWindow.xib +++ b/MPfm/MPfm.Mac/Windows/XIB/MainWindow.xib @@ -2002,7 +2002,7 @@ {402, 152} - + _NS:13 YES NO @@ -2029,7 +2029,7 @@ YES - columnIsPlaying + columnIsLoopPlaying 22 22 22 @@ -2257,7 +2257,7 @@ {{0, -5}, {402, 169}} - + _NS:9 133680 @@ -2440,7 +2440,7 @@ {377, 150} - + _NS:13 YES NO @@ -2631,7 +2631,7 @@ {{0, -3}, {377, 167}} - + _NS:9 133680 @@ -2703,7 +2703,7 @@ {256, 143} - + _NS:13 YES NO @@ -2834,7 +2834,7 @@ {256, 160} - + _NS:9 133680 @@ -2879,7 +2879,7 @@ {523, 143} - + _NS:13 YES NO @@ -3128,6 +3128,7 @@ {{1, 161}, {422, 15}} + _NS:60 NO 1 @@ -3156,7 +3157,7 @@ {523, 160} - + _NS:9 133680 @@ -3409,6 +3410,44 @@ {10000000000000, 10000000000000} YES + + Contextual menu + + YES + + + Play + + 2147483647 + + + + + + Add to playlist + + 2147483647 + + + + + + Remove from library + + 2147483647 + + + + + + Delete from hard disk + + 2147483647 + + + + + @@ -4269,6 +4308,14 @@ 826 + + + actionContextualMenuPlay: + + + + 862 + Toolbar @@ -4293,6 +4340,14 @@ 57 + + + menu + + + + 856 + textField @@ -6825,6 +6880,38 @@ + + 827 + + + YES + + + + + + + + + 858 + + + + + 857 + + + + + 846 + + + + + 845 + + + @@ -6923,6 +7010,7 @@ 29.IBPluginDependency 290.IBPluginDependency 290.ibExternalAutomaticallyCalculatesRowSizeFromViewHeight + 290.userInterfaceItemIdentifier 291.IBPluginDependency 292.CustomClassName 292.IBPluginDependency @@ -6932,6 +7020,7 @@ 294.prototypeCellViews 297.IBPluginDependency 298.IBPluginDependency + 298.userInterfaceItemIdentifier 299.IBPluginDependency 3.CustomClassName 3.IBPluginDependency @@ -6958,6 +7047,7 @@ 323.isInViewBasedMode 323.prototypeCellViews 324.IBPluginDependency + 324.userInterfaceItemIdentifier 325.IBPluginDependency 326.IBPluginDependency 327.IBPluginDependency @@ -6966,6 +7056,7 @@ 329.prototypeCellViews 330.IBPluginDependency 331.IBPluginDependency + 331.userInterfaceItemIdentifier 332.IBPluginDependency 333.IBPluginDependency 335.IBPluginDependency @@ -6977,6 +7068,7 @@ 337.prototypeCellViews 338.IBPluginDependency 339.IBPluginDependency + 339.userInterfaceItemIdentifier 340.IBPluginDependency 341.IBPluginDependency 35.IBPluginDependency @@ -6991,6 +7083,7 @@ 392.IBPluginDependency 393.IBPluginDependency 393.ibExternalAutomaticallyCalculatesRowSizeFromViewHeight + 393.userInterfaceItemIdentifier 394.IBPluginDependency 394.isInViewBasedMode 394.prototypeCellViews @@ -7001,14 +7094,17 @@ 398.isInViewBasedMode 398.prototypeCellViews 399.IBPluginDependency + 399.userInterfaceItemIdentifier 400.IBPluginDependency 401.IBPluginDependency 402.IBPluginDependency 403.IBPluginDependency 404.IBPluginDependency + 404.userInterfaceItemIdentifier 405.IBPluginDependency 406.IBPluginDependency 412.IBPluginDependency + 412.userInterfaceItemIdentifier 413.IBPluginDependency 414.IBPluginDependency 415.IBPluginDependency @@ -7122,6 +7218,7 @@ 706.IBPluginDependency 707.IBPluginDependency 709.IBPluginDependency + 709.userInterfaceItemIdentifier 71.IBPluginDependency 710.IBPluginDependency 711.IBPluginDependency @@ -7181,11 +7278,16 @@ 820.IBPluginDependency 824.IBPluginDependency 824.designableToolbarItemIdentifier + 827.IBPluginDependency 83.CustomClassName 83.IBPluginDependency 84.CustomClassName 84.IBPluginDependency + 845.IBPluginDependency + 846.IBPluginDependency 85.IBPluginDependency + 857.IBPluginDependency + 858.IBPluginDependency 86.IBPluginDependency @@ -7303,6 +7405,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + tableLoops com.apple.InterfaceBuilder.CocoaPlugin MPfmTableHeaderView com.apple.InterfaceBuilder.CocoaPlugin @@ -7315,6 +7418,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + cellLoopName com.apple.InterfaceBuilder.CocoaPlugin MPfmView com.apple.InterfaceBuilder.CocoaPlugin @@ -7344,6 +7448,7 @@ com.apple.InterfaceBuilder.CocoaPlugin + cellLoopLength com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -7355,6 +7460,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + cellLoopEndPosition com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -7372,6 +7478,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + cellLoopStartPosition com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -7386,6 +7493,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + tableMarkers com.apple.InterfaceBuilder.CocoaPlugin @@ -7405,14 +7513,17 @@ com.apple.InterfaceBuilder.CocoaPlugin + cellMarkerName com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + cellMarkerPosition com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + cellMarkerComments com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -7530,6 +7641,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + cellIsLoopPlaying com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -7589,12 +7701,17 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin toolbarShuffle + com.apple.InterfaceBuilder.CocoaPlugin MPfmSongPositionSlider com.apple.InterfaceBuilder.CocoaPlugin MPfmSliderCell com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -7609,7 +7726,7 @@ - 826 + 862 @@ -7717,6 +7834,7 @@ actionChangeSongPosition: actionChangeTimeShifting: actionChangeVolume: + actionContextualMenuPlay: actionEditLoop: actionEditMarker: actionEditSongMetadata: @@ -7772,6 +7890,7 @@ id id id + id @@ -7786,6 +7905,7 @@ actionChangeSongPosition: actionChangeTimeShifting: actionChangeVolume: + actionContextualMenuPlay: actionEditLoop: actionEditMarker: actionEditSongMetadata: @@ -7843,6 +7963,10 @@ actionChangeVolume: id + + actionContextualMenuPlay: + id + actionEditLoop: id @@ -8474,6 +8598,14 @@ ./Classes/MainWindowController.h + + NSTableRowView + NSView + + IBProjectSource + ./Classes/NSTableRowView.h + + 0