Skip to content

Commit

Permalink
Mac: Updated Main view after changes on Windows (added Markers, Loops…
Browse files Browse the repository at this point in the history
…, 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.
  • Loading branch information
ycastonguay committed Aug 19, 2013
1 parent b84cb97 commit b07731e
Show file tree
Hide file tree
Showing 3 changed files with 297 additions and 58 deletions.
200 changes: 152 additions & 48 deletions MPfm/MPfm.Mac/Windows/Controllers/MainWindowController.cs
Expand Up @@ -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
{
Expand All @@ -46,6 +47,7 @@ namespace MPfm.Mac
/// </summary>
public partial class MainWindowController : BaseWindowController, IMainView
{
List<Marker> _markers = new List<Marker>();
LibraryBrowserOutlineViewDelegate _libraryBrowserOutlineViewDelegate = null;
LibraryBrowserDataSource _libraryBrowserDataSource = null;
SongBrowserTableViewDelegate _songBrowserOutlineViewDelegate = null;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand All @@ -514,59 +564,33 @@ 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)
{
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()
Expand Down Expand Up @@ -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);
});
}

Expand Down Expand Up @@ -747,5 +764,92 @@ public void RefreshLibraryBrowserNode(LibraryBrowserEntity entity, IEnumerable<L

#endregion

#region IPitchShiftingView implementation

public Action<int> OnChangeKey { get; set; }
public Action<int> 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<Tuple<int, string>> keys)
{
}

public void RefreshPitchShifting(PlayerPitchShiftingEntity entity)
{
}

#endregion

#region ITimeShiftingView implementation

public Action<float> 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<Loop> 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<Loop> loops)
{
}

#endregion

#region IMarkersView implementation

public Action<MarkerTemplateNameType> OnAddMarker { get; set; }
public Action<Marker> OnEditMarker { get; set; }
public Action<Marker> 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<Marker> markers)
{
InvokeOnMainThread(delegate {
_markers = markers.ToList();
tableMarkers.ReloadData();
});
}

#endregion

}
}
3 changes: 3 additions & 0 deletions MPfm/MPfm.Mac/Windows/MainWindow.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b07731e

Please sign in to comment.