public void LoadProperty(int id) { switch (_editType) { case AddEditPropertyType.Track: _tProperty = DAL.AdHocData.TrackProperties.FirstOrDefault(x => x.Id == id); if (_tProperty != null) { _property = _tProperty.Property; } break; case AddEditPropertyType.SearchCriteria: _sProperty = DAL.AdHocData.SearchCritrias.FirstOrDefault(x => x.Id == id); if (_sProperty != null) { _property = _sProperty.Property; } break; } if (_property == null) { return; } PropertyName = _property.Name; switch (_property.PropertyType.Name) { case "Select One": ControlType = PropertyControlType.SelectOne; Options = DAL.AdHocData.PropertyOptions.Where(x => x.PropertyId == _property.Id).ToList(); SelectedOption = Options.FirstOrDefault(x => x.Value == _value); break; case "Text Value": ControlType = PropertyControlType.Text; TextValue = _value; break; case "Yes / No": ControlType = PropertyControlType.Bool; _boolValue = _value == "1"; NotifyOfPropertyChange(() => BoolValue); break; case "Select Multiple": ControlType = PropertyControlType.SelectMultiple; List = DAL.AdHocData.PropertyOptions.Where(x => x.PropertyId == _property.Id).ToList(); break; } }
public void InsertColumn(TrackProperty propertyToInsert, TrackProperty? priorColumnProperty) { int position = 0; foreach (var property in ColumnPropertyList) { position++; if (property == priorColumnProperty) break; } ColumnPropertyList.Insert(position, propertyToInsert); _saveTimer.Change(SaveTimerResetTime, Timeout.Infinite); }
private void AddTextColumn(StringPropertySelector selector, string columnName, TrackComparer comparer, TrackProperty property, TrackProperty? priorColumnProperty) { if (comparer == null) { comparer = (track1, track2) => string.Compare(selector(track1), selector(track2), StringComparison.CurrentCulture); } int fixedWidth; if (!_settings.ColumnWidths.TryGetValue(property, out fixedWidth)) fixedWidth = 200; TrackListViewColumn genericColumn = new TrackListViewColumn(columnName) {FixedWidth = fixedWidth}; PropertiesToColumns.Add(property, genericColumn); ColumnsToProperties.Add(genericColumn, property); TrackCellRenderer pathCellTextRenderer = new TrackCellRenderer(); genericColumn.PackStart(pathCellTextRenderer, true); genericColumn.SetCellDataFunc(pathCellTextRenderer, (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) => { Track track = (Track) model.GetValue(iter, 0); Track playingTrack = ((ITrackListModel) model).CurrentTrack; bool playing = playingTrack != null && track.Equals(playingTrack); ((CellRendererText) cell).Text = selector(track); ((CellRendererText) cell).Weight = playing ? 800 : 400; }); genericColumn.SortColumnId = (int) property; ((ITrackListModel) TrackListView.Model).SetSortFunc((int) property, (model, iter1, iter2) => { Track track1 = (Track) model.GetValue(iter1, 0); Track track2 = (Track) model.GetValue(iter2, 0); int result = comparer(track1, track2); if (result == 0) result = DefaultSortFunc(model, iter1, iter2); return result; }); int position = 0; foreach (var column in TrackListView.Columns) { position++; TrackProperty columnProperty; if (ColumnsToProperties.TryGetValue((TrackListViewColumn) column, out columnProperty)) { if (columnProperty == priorColumnProperty) break; } } TrackListView.InsertColumn(genericColumn, position); genericColumn.AddNotification("width", TrackListViewColumnNotifyHandler); var label = new Label(columnName); genericColumn.Widget = label; var widget = genericColumn.Widget; widget.GetAncestor(Button.GType); var columnHeader = widget.GetAncestor(Button.GType); columnHeader.ButtonPressEvent += ColumnHeaderOnButtonPressEvent; label.Show(); }
private void AddColumn(TrackProperty property, TrackProperty? priorColumnProperty = null) { string description = Extensions.GetEnumDescription(property); switch (property) { case TrackProperty.Album: AddTextColumn(t => t.Album != null ? t.Album.Title : null, description, null, property, priorColumnProperty); break; case TrackProperty.Artist: AddTextColumn( t => t.Artists == null || t.Artists.Count == 0 ? null : String.Join("; ", t.Artists.Select(a => a.Name)), description, null, property, priorColumnProperty); break; case TrackProperty.AlbumArtist: AddTextColumn(t => (t.Album == null || t.Album.Artists == null || t.Artists.Count == 0) ? null : String.Join("; ", t.Album.Artists.Select(a => a.Name)), description, null, property, priorColumnProperty); break; case TrackProperty.Duration: AddTextColumn(t => { TimeSpan timeSpan = TimeSpan.FromMilliseconds(t.Duration); string length = t.Duration >= 1000*60*60 ? String.Format(CultureInfo.CurrentCulture, "{0}:{1:D2}:{2:D2}", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds) : String.Format(CultureInfo.CurrentCulture, "{0}:{1:D2}", timeSpan.Minutes, timeSpan.Seconds); return length; }, description, null, property, priorColumnProperty); break; case TrackProperty.Bitrate: AddTextColumn(t => t.Bitrate.ToString(CultureInfo.InvariantCulture), description, (track1, track2) => track1.Bitrate.CompareTo(track2.Bitrate), property, priorColumnProperty); break; case TrackProperty.BitsPerSample: AddTextColumn(t => t.BitsPerSample.ToString(CultureInfo.InvariantCulture), description, (track1, track2) => track1.BitsPerSample.CompareTo(track2.BitsPerSample), property, priorColumnProperty); break; case TrackProperty.Bpm: AddTextColumn(t => t.Bpm.ToString(), description, (track1, track2) => { uint bpm1 = track1.Bpm ?? 0; uint bpm2 = track2.Bpm ?? 0; return bpm1.CompareTo(bpm2); }, property, priorColumnProperty); break; case TrackProperty.ChannelCount: AddTextColumn(t => t.ChannelCount.ToString(CultureInfo.InvariantCulture), description, (track1, track2) => track1.ChannelCount.CompareTo(track2.ChannelCount), property, priorColumnProperty); break; case TrackProperty.Codec: AddTextColumn(t => t.Codec, description, null, property, priorColumnProperty); break; case TrackProperty.Date: AddTextColumn(t => t.Date, description, null, property, priorColumnProperty); break; case TrackProperty.DateAdded: AddTextColumn( t => string.Format("{0} {1}", t.DateAdded.ToShortDateString(), t.DateAdded.ToLongTimeString()), description, (track1, track2) => track1.DateAdded.CompareTo(track2.DateAdded), property, priorColumnProperty); break; case TrackProperty.DateLastPlayed: AddTextColumn(t => t.DateLastPlayed.HasValue && t.DateLastPlayed.Value > DateTime.MinValue ? string.Format("{0} {1}", t.DateLastPlayed.Value.ToShortDateString(), t.DateLastPlayed.Value.ToLongTimeString()) : null, description, (track1, track2) => { DateTime date1 = track1.DateLastPlayed ?? DateTime.MinValue; DateTime date2 = track2.DateLastPlayed ?? DateTime.MinValue; return date1.CompareTo(date2); }, property, priorColumnProperty); break; case TrackProperty.DiscNumber: AddTextColumn(t => t.DiscNumber.ToString(), description, (track1, track2) => { uint discNumber1 = track1.DiscNumber ?? 0; uint discNumber2 = track2.DiscNumber ?? 0; return discNumber1.CompareTo(discNumber2); }, property, priorColumnProperty); break; case TrackProperty.Genre: AddTextColumn( t => t.Artists == null || t.Artists.Count == 0 ? null : String.Join("; ", t.Genres.Select(g => g.Name)), description, null, property, priorColumnProperty); break; case TrackProperty.MusicBrainzAlbumId: AddTextColumn(t => t.Album != null ? t.Album.MusicBrainzId : null, description, null, property, priorColumnProperty); break; case TrackProperty.MusicBrainzReleaseId: AddTextColumn(t => t.MusicBrainzId, description, null, property, priorColumnProperty); break; case TrackProperty.Path: AddTextColumn(t => t.Path, description, null, property, priorColumnProperty); break; case TrackProperty.Playcount: AddTextColumn(t => t.Playcount.ToString(CultureInfo.InvariantCulture), description, (track1, track2) => track1.Playcount.CompareTo(track2.Playcount), property, priorColumnProperty); break; case TrackProperty.Rating: // TODO: implement stars AddTextColumn(t => t.Rating.ToString(), description, (track1, track2) => { uint rating1 = track1.Rating ?? 0; uint rating2 = track2.Rating ?? 0; return rating1.CompareTo(rating2); }, property, priorColumnProperty); break; case TrackProperty.SampleRate: AddTextColumn(t => string.Format("{0} Hz", t.SampleRate), description, (track1, track2) => track1.SampleRate.CompareTo(track2.SampleRate), property, priorColumnProperty); break; case TrackProperty.Size: AddTextColumn(t => string.Format("{0:N1} MB", (double) t.Size/(1024*1024)), description, (track1, track2) => track1.Size.CompareTo(track2.Size), property, priorColumnProperty); break; case TrackProperty.Summary: AddTextColumn( t => string.Format("{0} - {1}", String.Join("; ", t.Artists.Select(a => a.Name)), t.Title), description, null, property, priorColumnProperty); break; case TrackProperty.Title: AddTextColumn(t => t.Title, description, null, property, priorColumnProperty); break; case TrackProperty.TrackNumber: AddTextColumn(t => t.TrackNumber.ToString(), description, (track1, track2) => { uint num1 = track1.TrackNumber ?? uint.MinValue; uint num2 = track2.TrackNumber ?? uint.MinValue; return num1.CompareTo(num2); }, property, priorColumnProperty); break; default: Console.WriteLine("Column not implemented for track property name {0}", description); break; } }
public void RemoveColumn(TrackProperty property) { _settings.RemoveColumn(property); TrackListViewColumn column; if (PropertiesToColumns.TryGetValue(property, out column)) { TrackListView.RemoveColumn(column); ColumnsToProperties.Remove(column); PropertiesToColumns.Remove(property); } }
public void InsertColumn(TrackProperty propertyToInsert, TrackProperty? priorColumnProperty) { _settings.AddColumn(propertyToInsert); _settings.InsertColumn(propertyToInsert, priorColumnProperty); AddColumn(propertyToInsert, priorColumnProperty); }
public void RemoveColumn(TrackProperty property) { ColumnPropertyList.Remove(property); _saveTimer.Change(SaveTimerResetTime, Timeout.Infinite); }
public void AddColumn(TrackProperty propertyToInsert) { ColumnPropertyList.Add(propertyToInsert); _saveTimer.Change(SaveTimerResetTime, Timeout.Infinite); }
set => SetValue(TrackProperty, value);