Beispiel #1
0
        public async Task Sort(Playlist playlist, PlaylistColumn playlistColumn)
        {
            if (!this.Sorting.Value)
            {
                return;
            }
            var descending = default(bool);

            if (object.ReferenceEquals(this.SortColumn, playlistColumn))
            {
                descending = true;
            }
            var changes = await this.PlaylistManager.Sort(playlist, playlistColumn, descending).ConfigureAwait(false);

            if (changes == 0)
            {
                Logger.Write(this, LogLevel.Debug, "Playlist was already sorted, reversing direction.");
                descending = !descending;
                changes    = await this.PlaylistManager.Sort(playlist, playlistColumn, descending).ConfigureAwait(false);

                if (changes == 0)
                {
                    Logger.Write(this, LogLevel.Debug, "Playlist was already sorted, all values are equal.");
                }
            }
            if (!descending)
            {
                this.SortColumn = playlistColumn;
            }
        }
Beispiel #2
0
 protected virtual void OnPositionChanged(PlaylistColumn column)
 {
     if (this.PositionChanged == null)
     {
         return;
     }
     this.PositionChanged(this, column);
 }
Beispiel #3
0
 protected virtual void OnWidthChanged(PlaylistColumn column)
 {
     if (this.WidthChanged == null)
     {
         return;
     }
     this.WidthChanged(this, column);
 }
        public PlaylistGridViewColumn Create(PlaylistColumn column)
        {
            var gridViewColumn = new PlaylistGridViewColumn(column);

            switch (column.Type)
            {
            case PlaylistColumnType.Script:
                if (!string.IsNullOrEmpty(column.Script))
                {
                    gridViewColumn.DisplayMemberBinding = new PlaylistScriptBinding()
                    {
                        ScriptingContext = this.ScriptingContext.Value,
                        Script           = column.Script
                    };
                }
                break;

            case PlaylistColumnType.Plugin:
                if (!string.IsNullOrEmpty(column.Plugin))
                {
                    var provider = PlaylistColumnProviderManager.GetProvider(column.Plugin);
                    if (provider != null)
                    {
                        gridViewColumn.CellTemplate = provider.CellTemplate;
                    }
                }
                break;

            case PlaylistColumnType.Tag:
                if (!string.IsNullOrEmpty(column.Tag))
                {
                    gridViewColumn.DisplayMemberBinding = new PlaylistMetaDataBinding()
                    {
                        Name   = column.Tag,
                        Format = column.Format
                    };
                }
                break;
            }
            BindingHelper.Create(
                gridViewColumn,
                GridViewColumn.WidthProperty,
                typeof(GridViewColumn),
                column,
                "Width",
                ColumnWidthConverter.Instance,
                (sender, e) => this.OnWidthChanged(column)
                );
            BindingHelper.Create(
                gridViewColumn,
                GridViewColumnExtensions.PositionProperty,
                typeof(GridViewColumn),
                column,
                "Sequence",
                (sender, e) => this.OnPositionChanged(column)
                );
            return(gridViewColumn);
        }
Beispiel #5
0
        public async Task Sort(Playlist playlist, PlaylistColumn playlistColumn, bool descending)
        {
            using (var task = new SortPlaylistTask(playlist, playlistColumn, descending))
            {
                task.InitializeComponent(this.Core);
                await this.OnBackgroundTask(task).ConfigureAwait(false);

                await task.Run().ConfigureAwait(false);
            }
        }
        public GridViewColumn Create(PlaylistColumn column)
        {
            this.EnsureScriptingContext();
            var gridViewColumn = default(GridViewColumn);

            if (column.IsDynamic)
            {
                gridViewColumn = new RefreshableGridViewColumn();
            }
            else
            {
                gridViewColumn = new GridViewColumn();
            }
            gridViewColumn.Header = column.Name;
            switch (column.Type)
            {
            case PlaylistColumnType.Script:
                gridViewColumn.DisplayMemberBinding = new PlaylistScriptBinding()
                {
                    PlaybackManager  = this.PlaybackManager,
                    ScriptingContext = this.ScriptingContext,
                    Script           = column.Script
                };
                break;

            case PlaylistColumnType.Plugin:
                var provider = PlaylistColumnManager.GetProvider(column.Plugin);
                if (provider != null)
                {
                    gridViewColumn.CellTemplate = provider.CellTemplate;
                }
                break;
            }
            BindingHelper.Create(
                gridViewColumn,
                GridViewColumn.WidthProperty,
                typeof(GridViewColumn),
                column,
                "Width",
                ColumnWidthConverter.Instance,
                (sender, e) => this.OnWidthChanged(column)
                );
            BindingHelper.Create(
                gridViewColumn,
                GridViewColumnExtensions.PositionProperty,
                typeof(GridViewColumn),
                column,
                "Sequence",
                (sender, e) => this.OnPositionChanged(column)
                );
            return(gridViewColumn);
        }
Beispiel #7
0
        protected virtual Task SortItems(PlaylistColumn playlistColumn, bool descending)
        {
            switch (playlistColumn.Type)
            {
            case PlaylistColumnType.Tag:
                return(this.SortItemsByMetaData(MetaDataItemType.Tag, playlistColumn.Tag, descending));

            case PlaylistColumnType.Script:
                return(this.SortItemsByScript(playlistColumn.Script, descending));
            }
#if NET40
            return(TaskEx.FromResult(false));
#else
            return(Task.CompletedTask);
#endif
        }
Beispiel #8
0
        protected virtual Task SortItems(PlaylistColumn playlistColumn, bool descending)
        {
            Logger.Write(this, LogLevel.Debug, "Sorting playlist {0} by column {1}.", this.Playlist.Name, playlistColumn.Name);
            switch (playlistColumn.Type)
            {
            case PlaylistColumnType.Tag:
                return(this.SortItemsByMetaData(playlistColumn.Tag, descending));

            case PlaylistColumnType.Script:
                return(this.SortItemsByScript(playlistColumn.Script, descending));
            }
#if NET40
            return(TaskEx.FromResult(false));
#else
            return(Task.CompletedTask);
#endif
        }
Beispiel #9
0
        protected virtual Task <int> SortItems(PlaylistColumn playlistColumn, bool descending)
        {
            Logger.Write(this, LogLevel.Debug, "Sorting playlist {0} by column {1}.", this.Playlist.Name, playlistColumn.Name);
            switch (playlistColumn.Type)
            {
            case PlaylistColumnType.Script:
                return(this.SortItemsByScript(playlistColumn.Script, descending));

            case PlaylistColumnType.Plugin:
                return(this.SortItemsByPlugin(playlistColumn.Plugin, descending));

            case PlaylistColumnType.Tag:
                return(this.SortItemsByTag(playlistColumn.Tag, descending));
            }
#if NET40
            return(TaskEx.FromResult(0));
#else
            return(Task.FromResult(0));
#endif
        }
Beispiel #10
0
        public Task Sort(Playlist playlist, PlaylistColumn playlistColumn)
        {
            if (!this.Sorting.Value)
            {
                Logger.Write(this, LogLevel.Warn, "Sorting is disabled.");
#if NET40
                return(TaskEx.FromResult(false));
#else
                return(Task.CompletedTask);
#endif
            }
            var descending = default(bool);
            if (object.ReferenceEquals(this.SortColumn, playlistColumn))
            {
                this.SortColumn = null;
                descending      = true;
            }
            else
            {
                this.SortColumn = playlistColumn;
            }
            return(this.PlaylistManager.Sort(playlist, playlistColumn, descending));
        }
 protected virtual void OnWidthChanged(object sender, PlaylistColumn playlistColumn)
 {
     this.Update(playlistColumn, false);
 }
 protected virtual void OnPositionChanged(object sender, PlaylistColumn playlistColumn)
 {
     this.Update(playlistColumn, true);
 }
 protected virtual void Update(PlaylistColumn column, bool notify)
 {
     this.Columns.AddOrUpdate(column, notify);
     this.Debouncer.Exec(() => this.Dispatch(this.Update));
     Logger.Write(this, LogLevel.Debug, "Queued update for column {0} => {1}.", column.Id, column.Name);
 }
        public PlaylistGridViewColumn Create(PlaylistColumn column)
        {
            var gridViewColumn = new PlaylistGridViewColumn(column);

            switch (column.Type)
            {
            case PlaylistColumnType.Script:
                if (!string.IsNullOrEmpty(column.Script))
                {
                    gridViewColumn.DisplayMemberBinding = new PlaylistScriptBinding()
                    {
                        ScriptingContext = this.ScriptingContext.Value,
                        Script           = column.Script
                    };
                }
                break;

            case PlaylistColumnType.Plugin:
                if (!string.IsNullOrEmpty(column.Plugin))
                {
                    var provider = PlaylistColumnProviderManager.GetProvider(column.Plugin) as IUIPlaylistColumnProvider;
                    if (provider == null)
                    {
                        Logger.Write(this, LogLevel.Warn, "Playlist column plugin \"{0}\" was not found, has it been uninstalled?", column.Plugin);
                    }
                    else
                    {
                        gridViewColumn.CellTemplate = provider.CellTemplate;
                    }
                }
                break;

            case PlaylistColumnType.Tag:
                if (!string.IsNullOrEmpty(column.Tag))
                {
                    gridViewColumn.DisplayMemberBinding = new PlaylistMetaDataBinding()
                    {
                        Name   = column.Tag,
                        Format = column.Format
                    };
                }
                break;
            }
            BindingHelper.Create(
                gridViewColumn,
                GridViewColumn.WidthProperty,
                typeof(GridViewColumn),
                column,
                "Width",
                ColumnWidthConverter.Instance,
                (sender, e) =>
            {
                if (IsAutoSizing(gridViewColumn))
                {
                    //Don't raise events while auto sizing is in progress.
                    return;
                }
                this.OnWidthChanged(column);
            }
                );
            BindingHelper.Create(
                gridViewColumn,
                GridViewColumnExtensions.PositionProperty,
                typeof(GridViewColumn),
                column,
                "Sequence",
                (sender, e) => this.OnPositionChanged(column)
                );
            return(gridViewColumn);
        }
Beispiel #15
0
 public SortPlaylistTask(Playlist playlist, PlaylistColumn playlistColumn, bool descending) : base(playlist)
 {
     this.PlaylistColumn = playlistColumn;
     this.Descending     = descending;
 }
Beispiel #16
0
 public PlaylistGridViewColumn(PlaylistColumn playlistColumn)
 {
     this.PlaylistColumn = playlistColumn;
     this.Header         = playlistColumn.Name;
 }