コード例 #1
0
ファイル: TorrentTreeView.cs プロジェクト: ivaylo5ev/monsoon
        private void buildColumns()
        {
            Column downloadColumn = new Column {
                Ignore = true, Visible = false, Title = "N/A"
            };

            Gtk.CellRendererText     torrentNameCell      = new Gtk.CellRendererText();
            Gtk.CellRendererText     torrentStatusCell    = new Gtk.CellRendererText();
            Gtk.CellRendererProgress torrentDoneCell      = new Gtk.CellRendererProgress();
            Gtk.CellRendererText     torrentSeedsCell     = new Gtk.CellRendererText();
            Gtk.CellRendererText     torrentPeersCell     = new Gtk.CellRendererText();
            Gtk.CellRendererText     torrentPriorityCell  = new Gtk.CellRendererText();
            Gtk.CellRendererText     torrentDownSpeedCell = new Gtk.CellRendererText();
            Gtk.CellRendererText     torrentUpSpeedCell   = new Gtk.CellRendererText();
            Gtk.CellRendererText     torrentRatioCell     = new Gtk.CellRendererText();
            Gtk.CellRendererText     torrentSizeCell      = new Gtk.CellRendererText();
            Gtk.CellRendererText     torrentEtaCell       = new Gtk.CellRendererText();

            nameColumn.PackStart(torrentNameCell, true);
            statusColumn.PackStart(torrentStatusCell, true);
            doneColumn.PackStart(torrentDoneCell, true);
            seedsColumn.PackStart(torrentSeedsCell, true);
            peersColumn.PackStart(torrentPeersCell, true);
            priorityColumn.PackStart(torrentPriorityCell, true);
            downSpeedColumn.PackStart(torrentDownSpeedCell, true);
            upSpeedColumn.PackStart(torrentUpSpeedCell, true);
            ratioColumn.PackStart(torrentRatioCell, true);
            sizeColumn.PackStart(torrentSizeCell, true);
            etaColumn.PackStart(torrentEtaCell, true);

            nameColumn.AddAttribute(torrentNameCell, "text", 1);
            statusColumn.AddAttribute(torrentStatusCell, "text", 2);
            statusColumn.AddAttribute(torrentStatusCell, "foreground", 11);
            doneColumn.AddAttribute(torrentDoneCell, "value", 3);
            seedsColumn.AddAttribute(torrentSeedsCell, "text", 4);
            peersColumn.AddAttribute(torrentPeersCell, "text", 5);
            priorityColumn.AddAttribute(torrentPriorityCell, "text", 12);
            downSpeedColumn.AddAttribute(torrentDownSpeedCell, "text", 6);
            upSpeedColumn.AddAttribute(torrentUpSpeedCell, "text", 7);
            ratioColumn.AddAttribute(torrentRatioCell, "text", 8);
            sizeColumn.AddAttribute(torrentSizeCell, "text", 9);
            etaColumn.AddAttribute(torrentEtaCell, "text", 10);

            AppendColumn(priorityColumn);
            AppendColumn(downloadColumn);
            AppendColumn(nameColumn);
            AppendColumn(statusColumn);
            AppendColumn(doneColumn);
            AppendColumn(seedsColumn);
            AppendColumn(peersColumn);
            AppendColumn(downSpeedColumn);
            AppendColumn(upSpeedColumn);
            AppendColumn(etaColumn);
            AppendColumn(ratioColumn);
            AppendColumn(sizeColumn);

            foreach (TreeViewColumn c in this.Columns)
            {
                c.Sizing      = TreeViewColumnSizing.Fixed;
                c.Reorderable = true;
                c.Resizable   = true;

                c.Clicked += delegate(object o, EventArgs e) {
                    int            oldId;
                    SortType       oldSort;
                    TreeViewColumn sender = (TreeViewColumn)o;

                    Torrents.GetSortColumnId(out oldId, out oldSort);

                    // Invert the sort order if we're the same
                    if (oldId == sender.SortColumnId)
                    {
                        sender.SortOrder = sender.SortOrder == SortType.Ascending ? SortType.Descending : SortType.Ascending;
                    }
                    else
                    {
                        sender.SortOrder = SortType.Ascending;
                    }
                    Torrents.SetSortColumnId(sender.SortColumnId, sender.SortOrder);
                };
            }
        }