public void Resort()
        {
            var column = sort_column;

            sort_column = null;
            Sort(column);
        }
        public void Load()
        {
            lock (this) {
                if (source == null)
                {
                    return;
                }

                loaded = false;

                int i = 0;
                foreach (Column column in this)
                {
                    if (column.Id != null)
                    {
                        column.Visible   = Get <bool> (column.Id, "visible", column.Visible);
                        column.Width     = Get <double> (column.Id, "width", column.Width);
                        column.OrderHint = Get <int> (column.Id, "order", i);
                    }
                    else
                    {
                        column.OrderHint = -1;
                    }
                    i++;
                }

                Columns.Sort((a, b) => a.OrderHint.CompareTo(b.OrderHint));

                string sort_column_id = Get <string> ("sort", "column", null);
                if (sort_column_id != null)
                {
                    ISortableColumn sort_column = null;
                    foreach (Column column in this)
                    {
                        if (column.Id == sort_column_id)
                        {
                            sort_column = column as ISortableColumn;
                            break;
                        }
                    }

                    if (sort_column != null)
                    {
                        int      sort_dir  = Get <int> ("sort", "direction", 0);
                        SortType sort_type = sort_dir == 0 ? SortType.None : sort_dir == 1 ? SortType.Ascending : SortType.Descending;
                        sort_column.SortType = sort_type;
                        base.SortColumn      = sort_column;
                    }
                }
                else
                {
                    base.SortColumn = null;
                }

                loaded = true;
            }

            OnUpdated();
        }
Пример #3
0
        public virtual void SetModel(IListModel <T> value, double vpos)
        {
            if (model == value)
            {
                return;
            }

            if (model != null)
            {
                model.Cleared  -= OnModelClearedHandler;
                model.Reloaded -= OnModelReloadedHandler;
            }

            model = value;

            if (model != null)
            {
                model.Cleared            += OnModelClearedHandler;
                model.Reloaded           += OnModelReloadedHandler;
                selection_proxy.Selection = model.Selection;
                IsEverReorderable         = model.CanReorder;
            }

            if (ViewLayout != null)
            {
                ViewLayout.Model = Model;
            }

            ISortable sortable = model as ISortable;

            if (sortable != null && ColumnController != null)
            {
                ISortableColumn sort_column = ColumnController.SortColumn ?? ColumnController.DefaultSortColumn;
                if (sort_column != null)
                {
                    if (sortable.Sort(sort_column))
                    {
                        model.Reload();
                    }
                    RecalculateColumnSizes();
                    RegenerateColumnCache();
                    InvalidateHeader();
                    IsReorderable = sortable.SortColumn == null || sortable.SortColumn.SortType == SortType.None;
                }
            }

            RefreshViewForModel(vpos);

            var handler = ModelChanged;

            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }
Пример #4
0
        protected virtual bool NeedsReloadWhenFieldChanged(Hyena.Query.QueryField field)
        {
            if (field == null)
            {
                return(true);
            }

            // If it's the artist or album name, then we care, since it affects the browser
            if (field == Banshee.Query.BansheeQuery.ArtistField || field == Banshee.Query.BansheeQuery.AlbumField)
            {
                return(true);
            }

            ISortableColumn sort_column = (TrackModel is DatabaseTrackListModel)
                ? (TrackModel as DatabaseTrackListModel).SortColumn : null;

            // If it's the field we're sorting by, then yes, we care
            if (sort_column != null && sort_column.Field == field)
            {
                return(true);
            }

            // Make sure the query isn't dependent on this field
            QueryNode query = (TrackModel is DatabaseTrackListModel)
                ? (TrackModel as DatabaseTrackListModel).Query : null;

            if (query != null)
            {
                if (query != last_query)
                {
                    query_fields = new List <QueryField> (query.GetFields());
                    last_query   = query;
                }

                if (query_fields.Contains(field))
                {
                    return(true);
                }
            }

            return(false);
        }
        private IEnumerable <T> Sort(IEnumerable <T> elements, ISortableColumn column)
        {
            switch (column.SortType)
            {
            case SortType.Ascending:
                return(elements
                       .OrderBy(elem => typeof(T).GetProperty(column.SortKey).GetValue(elem, null)));

            case SortType.Descending:
                return(elements
                       .OrderByDescending(elem => typeof(T).GetProperty(column.SortKey).GetValue(elem, null)));

            case SortType.None:
                return(elements);

            default:
                Hyena.Log.Debug(String.Format("Unknown SortType {0}", column.SortType));
                return(elements);
            }
        }
        public bool Sort(ISortableColumn column)
        {
            lock (this) {
                if (forced_sort_query)
                {
                    return(false);
                }

                // Don't sort by the same column and the same sort-type more than once
                if (sort_column != null && sort_column == column && column.SortType == last_sort_type)
                {
                    return(false);
                }

                last_sort_type = column.SortType;
                sort_column    = column;

                GenerateSortQueryPart();
                cache.Clear();
            }
            return(true);
        }
        protected virtual void OnColumnLeftClicked(Column clickedColumn)
        {
            if (Model is ISortable && clickedColumn is ISortableColumn)
            {
                ISortableColumn sort_column = clickedColumn as ISortableColumn;
                ISortable       sortable    = Model as ISortable;

                // Change the sort-type with every click
                if (sort_column == ColumnController.SortColumn)
                {
                    switch (sort_column.SortType)
                    {
                    case SortType.Ascending:    sort_column.SortType = SortType.Descending; break;

                    case SortType.Descending:   sort_column.SortType = SortType.None; break;

                    case SortType.None:         sort_column.SortType = SortType.Ascending; break;
                    }
                }

                // If we're switching from a different column, or we aren't reorderable, make sure sort type isn't None
                if ((sort_column != ColumnController.SortColumn || !IsEverReorderable) && sort_column.SortType == SortType.None)
                {
                    sort_column.SortType = SortType.Ascending;
                }

                sortable.Sort(sort_column);
                ColumnController.SortColumn = sort_column;
                IsReorderable = sortable.SortColumn == null || sortable.SortColumn.SortType == SortType.None;

                Model.Reload();
                CenterOnSelection();
                RecalculateColumnSizes();
                RegenerateColumnCache();
                InvalidateHeader();
            }
        }
Пример #8
0
        private void RecalculateColumnSizes()
        {
            if (column_cache == null)
            {
                return;
            }

            ISortable sortable = Model as ISortable;

            sort_column_index = -1;
            int min_header_width = 0;

            for (int i = 0; i < column_cache.Length; i++)
            {
                if (sortable != null)
                {
                    ColumnHeaderCellText column_cell = column_cache[i].Column.HeaderCell as ColumnHeaderCellText;
                    if (column_cell != null)
                    {
                        ISortableColumn sort_column = column_cache[i].Column as ISortableColumn;
                        column_cell.HasSort = sort_column != null && sortable.SortColumn == sort_column;
                        if (column_cell.HasSort)
                        {
                            sort_column_index = i;
                        }
                    }
                }

                column_cache[i].Column.CalculateWidths(column_layout, HeaderVisible, HeaderHeight);
                column_cache[i].MaxWidth = column_cache[i].Column.MaxWidth;
                column_cache[i].MinWidth = column_cache[i].Column.MinWidth;
                min_header_width        += column_cache[i].MinWidth;
            }

            if (column_cache.Length == 1)
            {
                column_cache[0].Column.Width = 1.0;
            }
            else if (min_header_width >= header_interaction_alloc.Width)
            {
                header_width = min_header_width;
                resizable    = false;
                for (int i = 0; i < column_cache.Length; i++)
                {
                    column_cache[i].Column.Width = (double)column_cache[i].MinWidth / (double)header_width;
                }
            }
            else
            {
                header_width = header_interaction_alloc.Width;
                resizable    = true;

                if (elastic_columns == null)
                {
                    elastic_columns = new List <int> (column_cache.Length);
                }
                elastic_columns.Clear();
                for (int i = 0; i < column_cache.Length; i++)
                {
                    elastic_columns.Add(i);
                    column_cache[i].ElasticWidth   = 0.0;
                    column_cache[i].ElasticPercent = column_cache[i].Column.Width * header_width;
                }

                double remaining_width = RecalculateColumnSizes(header_width, header_width);

                while (Math.Round(remaining_width) != 0.0 && elastic_columns.Count > 0)
                {
                    double total_elastic_width = 0.0;
                    foreach (int i in elastic_columns)
                    {
                        total_elastic_width += column_cache[i].ElasticWidth;
                    }
                    remaining_width = RecalculateColumnSizes(remaining_width, total_elastic_width);
                }

                for (int i = 0; i < column_cache.Length; i++)
                {
                    column_cache[i].Column.Width = column_cache[i].ElasticWidth / (double)header_width;
                }
            }

            double tmp_width = 0.0;
            double tmp_max   = 0.0;

            foreach (var col in column_cache)
            {
                tmp_width += col.ElasticWidth;
                tmp_max   += col.MaxWidth == Int32.MaxValue ? col.MinWidth : col.MaxWidth;
            }
            list_width = tmp_width;
            max_width  = tmp_max;
        }
Пример #9
0
        public bool Sort(ISortableColumn column)
        {
            lock (this) {
                if (forced_sort_query) {
                    return false;
                }

                // Don't sort by the same column and the same sort-type more than once
                if (sort_column != null && sort_column == column && column.SortType == last_sort_type) {
                    return false;
                }

                last_sort_type = column.SortType;
                sort_column = column;

                GenerateSortQueryPart ();
                cache.Clear ();
            }
            return true;
        }
Пример #10
0
 public void Resort()
 {
     var column = sort_column;
     sort_column = null;
     Sort (column);
 }
        public void Load()
        {
            lock (this) {
                if (source == null)
                {
                    return;
                }

                loaded = false;

                foreach (Column column in this)
                {
                    if (column.Id != null)
                    {
                        string @namespace = MakeNamespace(column.Id);
                        column.Visible = ConfigurationClient.Get <bool> (@namespace, "visible", column.Visible);
                        column.Width   = ConfigurationClient.Get <double> (@namespace, "width", column.Width);
                    }
                }

                // Create a copy so we can read the original index
                List <Column> columns = new List <Column> (Columns);

                Columns.Sort(delegate(Column a, Column b) {
                    int a_order = a.Id == null ? -1 : ConfigurationClient.Get <int> (
                        MakeNamespace(a.Id), "order", columns.IndexOf(a));
                    int b_order = b.Id == null ? -1 : ConfigurationClient.Get <int> (
                        MakeNamespace(b.Id), "order", columns.IndexOf(b));

                    return(a_order.CompareTo(b_order));
                });

                string sort_ns        = String.Format("{0}.{1}.{2}", root_namespace, unique_source_id, "sort");
                string sort_column_id = ConfigurationClient.Get <string> (sort_ns, "column", null);
                if (sort_column_id != null)
                {
                    ISortableColumn sort_column = null;
                    foreach (Column column in this)
                    {
                        if (column.Id == sort_column_id)
                        {
                            sort_column = column as ISortableColumn;
                            break;
                        }
                    }

                    if (sort_column != null)
                    {
                        int      sort_dir  = ConfigurationClient.Get <int> (sort_ns, "direction", 0);
                        SortType sort_type = sort_dir == 0 ? SortType.None : sort_dir == 1 ? SortType.Ascending : SortType.Descending;
                        sort_column.SortType = sort_type;
                        base.SortColumn      = sort_column;
                    }
                }
                else
                {
                    base.SortColumn = null;
                }

                loaded = true;
            }

            OnUpdated();
        }
 public bool Sort(ISortableColumn column)
 {
     this.column = column;
     Reload();
     return(true);
 }