コード例 #1
0
        /// <summary>
        /// Add track to playlist.
        /// </summary>
        /// <param name="playlistId">
        /// ID of playlist (1 and 2 supported only).
        /// </param>
        /// <param name="trackId">
        /// Track ID of track to add.
        /// </param>
        /// <param name="allowTwice">
        /// True if track should be added although it's already in available in the playlist.
        /// </param>
        /// <returns>
        /// True if track successfully added to playlist.
        /// </returns>
        public static bool AddTrackToPlayList(int playlistId, int trackId, bool allowTwice)
        {
            if (!allowTwice)
            {
                TrackListModel m = (playlistId == 1 ? RemotePlaylist : PlayQueuePlaylist).TrackModel;

                for (int i = 0; i < m.Count; i++)
                {
                    object t = m.GetItem(i);

                    if (t is DatabaseTrackInfo && ((DatabaseTrackInfo)t).TrackId == trackId)
                    {
                        return(false);
                    }
                }
            }

            switch (playlistId)
            {
            case 1: {
                Selection          selection = null;
                MusicLibrarySource source    = MusicLibrary;

                for (int i = 0; i < source.TrackModel.Count; i++)
                {
                    object t = source.TrackModel.GetItem(i);

                    if (t is DatabaseTrackInfo && ((DatabaseTrackInfo)t).TrackId == trackId)
                    {
                        selection = new Hyena.Collections.Selection();
                        selection.Select(i);
                        break;
                    }
                }

                if (selection != null)
                {
                    RemotePlaylist.AddSelectedTracks(source, selection);
                    return(true);
                }

                break;
            }

            case 2: {
                DatabaseTrackInfo track = new DatabaseTrackModelProvider <DatabaseTrackInfo>(
                    ServiceManager.DbConnection).FetchSingle(trackId);

                if (track != null)
                {
                    PlayQueuePlaylist.EnqueueTrack(track, false);
                    return(true);
                }

                break;
            }
            }

            return(false);
        }
コード例 #2
0
 protected bool ActivateSelection()
 {
     if (Selection != null && Selection.FocusedIndex != -1)
     {
         Selection.Clear(false);
         Selection.Select(Selection.FocusedIndex);
         OnRowActivated();
         return(true);
     }
     return(false);
 }
コード例 #3
0
 bool UpdateSelectionForKeyboardScroll(Gdk.ModifierType modifier, int relative_row)
 {
     if (Selection != null)
     {
         if ((modifier & Gdk.ModifierType.ControlMask) != 0)
         {
             // Don't change the selection
         }
         else
         {
             Selection.Notify();
         }
     }
     return(true);
 }
コード例 #4
0
 public CS_PlayListsModel(CS_PlayListCollection pls)
 {
     _pla               = pls;
     Selection          = new Hyena.Collections.Selection();
     Selection.Changed += delegate(object sender, EventArgs args) {
         try {
             int index = ((Selection)sender).FirstIndex;
             if (index >= 0)
             {
                 CS_PlayList pl = (CS_PlayList)this[index];
                 Hyena.Log.Information("playlist=" + pl);
                 OnPlayListSelect(pl);
             }
         } catch (System.Exception ex) {
             Hyena.Log.Error(ex.ToString());
         }
     };
 }
コード例 #5
0
        protected void CenterOnSelection()
        {
            if (Selection != null && Selection.Count > 0 && !Selection.AllSelected)
            {
                bool selection_in_view = false;
                int  first_row         = GetModelRowAt(0, 0);
                for (int i = 0; i < ItemsInView; i++)
                {
                    if (Selection.Contains(first_row + i))
                    {
                        selection_in_view = true;
                        break;
                    }
                }

                if (!selection_in_view)
                {
                    CenterOn(Selection.Ranges[0].Start);
                }
            }
        }
コード例 #6
0
        bool OnListButtonRelease(Gdk.EventButton evnt)
        {
            if (Model == null)
            {
                return(true);
            }

            int x = (int)evnt.X - list_interaction_alloc.X;
            int y = (int)evnt.Y - list_interaction_alloc.Y;

            GrabFocus();

            int row_index = GetModelRowAt(x, y);

            if (row_index >= Model.Count)
            {
                return(true);
            }

            object item = model[row_index];

            if (item == null)
            {
                return(true);
            }

            //if (Selection != null && Selection.Contains (row_index) && Selection.Count > 1) {
            if (Selection != null && evnt.Button == 1 && Hyena.Gui.GtkUtilities.NoImportantModifiersAreSet())
            {
                if (Selection.Count > 1)
                {
                    Selection.Clear(false);
                    Selection.Select(row_index);
                    FocusModelRow(row_index);
                    InvalidateList();
                }
            }

            return(true);
        }
コード例 #7
0
        bool OnListButtonPressEvent(Gdk.EventButton evnt)
        {
            if (Model == null)
            {
                return(true);
            }

            int x = (int)evnt.X - list_interaction_alloc.X;
            int y = (int)evnt.Y - list_interaction_alloc.Y;

            GrabFocus();

            int row_index = GetModelRowAt(x, y);

            if (row_index < 0 || row_index >= Model.Count)
            {
                Gtk.Drag.SourceUnset(this);
                return(true);
            }

            if (LayoutChildHandlesEvent(evnt, true))
            {
                return(true);
            }

            ProxyEventToCell(evnt, true);

            object item = model[row_index];

            if (item == null)
            {
                return(true);
            }

            if (evnt.Button == 1 && evnt.Type == Gdk.EventType.TwoButtonPress)
            {
                // Double clicked
                OnRowActivated();
            }
            else if (Selection != null)
            {
                if ((evnt.State & Gdk.ModifierType.ControlMask) != 0)
                {
                    if (evnt.Button == 3)
                    {
                        // Right clicked with ctrl pressed, so make sure row selected
                        if (!Selection.Contains(row_index))
                        {
                            Selection.Select(row_index);
                        }
                    }
                    else
                    {
                        // Normal ctrl-click, so toggle
                        Selection.ToggleSelect(row_index);
                    }
                }
                else if ((evnt.State & Gdk.ModifierType.ShiftMask) != 0)
                {
                    // Shift-click, so select from first-row-selected (if any) to the current row
                    Selection.SelectFromFirst(row_index, true);
                }
                else
                {
                    if (evnt.Button == 3)
                    {
                        // Normal right-click, make sure row is only row selected
                        if (!Selection.Contains(row_index))
                        {
                            Selection.Clear(false);
                            Selection.Select(row_index);
                        }
                    }
                    else
                    {
                        // Normal click, if row not already selected, select only it right now,
                        // but if it's already selected, wait until the Release to unselect any others so that
                        // drag and drop of 2+ items works.
                        if (!Selection.Contains(row_index))
                        {
                            Selection.Clear(false);
                            Selection.Select(row_index);
                        }
                    }
                }

                FocusModelRow(row_index);

                // Now that we've worked out the selections, open the context menu
                if (evnt.Button == 3)
                {
                    OnPopupMenu();
                }
            }

            InvalidateList();
            return(true);
        }
コード例 #8
0
 public void SetSelection(Selection selection)
 {
     this.selection = (SingleSelection)selection;
 }
コード例 #9
0
        protected override bool OnKeyPressEvent(Gdk.EventKey press)
        {
            bool handled = false;

            switch (press.Key)
            {
            case Gdk.Key.a:
                if ((press.State & Gdk.ModifierType.ControlMask) != 0 && Model.Count > 0)
                {
                    SelectionProxy.Selection.SelectAll();
                    handled = true;
                }
                break;

            case Gdk.Key.A:
                if ((press.State & Gdk.ModifierType.ControlMask) != 0 && Selection.Count > 0)
                {
                    SelectionProxy.Selection.Clear();
                    handled = true;
                }
                break;

            case Gdk.Key.Return:
            case Gdk.Key.KP_Enter:
                if (!HeaderFocused)
                {
                    handled = ActivateSelection();
                }
                else if (HeaderFocused && ActiveColumn >= 0)
                {
                    OnColumnLeftClicked(
                        column_cache[ActiveColumn].Column);
                    handled = true;
                }
                break;

            case Gdk.Key.Escape:
                handled = CancelColumnDrag();
                break;

            case Gdk.Key.space:
                if (Selection != null && Selection.FocusedIndex != 1 &&
                    !HeaderFocused)
                {
                    Selection.ToggleSelect(Selection.FocusedIndex);
                    handled = true;
                }
                break;

            case Gdk.Key.F10:
                if ((press.State & Gdk.ModifierType.ShiftMask) != 0)
                {
                    goto case Gdk.Key.Menu;
                }
                break;

            case Gdk.Key.Menu:
                // OnPopupMenu() is reserved for list items in derived classes.
                if (HeaderFocused)
                {
                    InvokeColumnHeaderMenu(ActiveColumn);
                    handled = true;
                }
                break;

            default:
                handled = HandleKeyboardScrollKey(press, KeyDirection.Press);
                break;
            }

            return(handled ? true : base.OnKeyPressEvent(press));
        }
コード例 #10
0
 public void SetSelection(Selection selection)
 {
     this.selection = selection;
 }
コード例 #11
0
        protected override bool OnKeyPressEvent(Gdk.EventKey press)
        {
            bool handled = false;

            switch (press.Key)
            {
            case Gdk.Key.a:
                if ((press.State & Gdk.ModifierType.ControlMask) != 0)
                {
                    SelectionProxy.Selection.SelectAll();
                    handled = true;
                }
                break;

            case Gdk.Key.A:
                if ((press.State & Gdk.ModifierType.ControlMask) != 0)
                {
                    SelectionProxy.Selection.Clear();
                    handled = true;
                }
                break;

            case Gdk.Key.k:
            case Gdk.Key.K:
            case Gdk.Key.Up:
            case Gdk.Key.KP_Up:
                if (!HeaderFocused)
                {
                    handled = KeyboardScroll(press.State, -1, true);
                }
                break;

            case Gdk.Key.j:
            case Gdk.Key.J:
            case Gdk.Key.Down:
            case Gdk.Key.KP_Down:
                if (!HeaderFocused)
                {
                    handled = KeyboardScroll(press.State, 1, true);
                }
                else if (HeaderFocused)
                {
                    handled       = true;
                    HeaderFocused = false;
                }
                break;

            case Gdk.Key.Right:
            case Gdk.Key.KP_Right:
                if (ActiveColumn + 1 < column_cache.Length)
                {
                    ActiveColumn++;
                    InvalidateHeader();
                }
                handled = true;
                break;

            case Gdk.Key.Left:
            case Gdk.Key.KP_Left:
                if (ActiveColumn - 1 >= 0)
                {
                    ActiveColumn--;
                    InvalidateHeader();
                }
                handled = true;
                break;

            case Gdk.Key.Page_Up:
            case Gdk.Key.KP_Page_Up:
                if (!HeaderFocused)
                {
                    handled = vadjustment != null && KeyboardScroll(press.State,
                                                                    (int)(-vadjustment.PageIncrement / (double)RowHeight), false);
                }
                break;

            case Gdk.Key.Page_Down:
            case Gdk.Key.KP_Page_Down:
                if (!HeaderFocused)
                {
                    handled = vadjustment != null && KeyboardScroll(press.State,
                                                                    (int)(vadjustment.PageIncrement / (double)RowHeight), false);
                }
                break;

            case Gdk.Key.Home:
            case Gdk.Key.KP_Home:
                if (!HeaderFocused)
                {
                    handled = KeyboardScroll(press.State, -10000000, false);
                }
                break;

            case Gdk.Key.End:
            case Gdk.Key.KP_End:
                if (!HeaderFocused)
                {
                    handled = KeyboardScroll(press.State, 10000000, false);
                }
                break;

            case Gdk.Key.Return:
            case Gdk.Key.KP_Enter:
                if (!HeaderFocused)
                {
                    handled = ActivateSelection();
                }
                else if (HeaderFocused && ActiveColumn >= 0)
                {
                    OnColumnLeftClicked(
                        column_cache[ActiveColumn].Column);
                    handled = true;
                }
                break;

            case Gdk.Key.Escape:
                handled = CancelColumnDrag();
                break;

            case Gdk.Key.space:
                if (Selection != null && Selection.FocusedIndex != 1 &&
                    !HeaderFocused)
                {
                    Selection.ToggleSelect(Selection.FocusedIndex);
                    handled = true;
                }
                break;

            case Gdk.Key.F10:
                if ((press.State & Gdk.ModifierType.ShiftMask) != 0)
                {
                    goto case Gdk.Key.Menu;
                }
                break;

            case Gdk.Key.Menu:
                // OnPopupMenu() is reserved for list items in derived classes.
                if (HeaderFocused)
                {
                    InvokeColumnHeaderMenu(ActiveColumn);
                    handled = true;
                }
                break;
            }

            if (handled)
            {
                return(true);
            }

            return(base.OnKeyPressEvent(press));
        }
コード例 #12
0
 public LiveRadioStatisticListModel(List <LiveRadioStatistic> list) : base()
 {
     original_list = list;
     this.list     = original_list.ToArray();
     selection     = new Selection();
 }
コード例 #13
0
        bool KeyboardScroll(Gdk.ModifierType modifier, int relative_row, bool align_y)
        {
            if (Model == null)
            {
                return(true);
            }

            int row_limit;

            if (relative_row < 0)
            {
                if (Selection.FocusedIndex == -1)
                {
                    return(false);
                }

                row_limit = 0;
            }
            else
            {
                row_limit = Model.Count - 1;
            }

            if (Selection.FocusedIndex == row_limit)
            {
                return(true);
            }

            int scroll_target_item_index = Math.Min(Model.Count - 1, Math.Max(0, Selection.FocusedIndex + relative_row));

            if (Selection != null)
            {
                if ((modifier & Gdk.ModifierType.ControlMask) != 0)
                {
                    // Don't change the selection
                }
                else if ((modifier & Gdk.ModifierType.ShiftMask) != 0)
                {
                    // Behave like nautilus: if and arrow key + shift is pressed and the currently focused item
                    // is not selected, select it and don't move the focus or vadjustment.
                    // Otherwise, select the new row and scroll etc as necessary.
                    if (relative_row * relative_row != 1)
                    {
                        Selection.SelectFromFirst(scroll_target_item_index, true, false);
                    }
                    else if (Selection.Contains(Selection.FocusedIndex))
                    {
                        Selection.SelectFromFirst(scroll_target_item_index, true, false);
                    }
                    else
                    {
                        Selection.Select(Selection.FocusedIndex, false);
                        return(true);
                    }
                }
                else
                {
                    Selection.Clear(false);
                    Selection.Select(scroll_target_item_index, false);
                }
            }

            // Scroll if needed
            double y_at_row = GetViewPointForModelRow(scroll_target_item_index).Y;

            if (align_y)
            {
                if (y_at_row < VadjustmentValue)
                {
                    ScrollToY(y_at_row);
                }
                else if (vadjustment != null)
                {
                    var bottom_of_item = y_at_row + ChildSize.Height;
                    var bottom_of_view = vadjustment.Value + vadjustment.PageSize;
                    if (bottom_of_item > bottom_of_view)
                    {
                        // Scroll down just enough to put the item fully into view
                        ScrollToY(bottom_of_item - (vadjustment.PageSize));
                    }
                }
            }
            else if (vadjustment != null)
            {
                ScrollToY(vadjustment.Value + y_at_row - GetViewPointForModelRow(Selection.FocusedIndex).Y);
            }

            Selection.FocusedIndex = scroll_target_item_index;
            InvalidateList();
            return(true);
        }
コード例 #14
0
        private bool KeyboardScroll(Gdk.ModifierType modifier, int relative_row, bool align_y)
        {
            if (Model == null)
            {
                return(true);
            }

            int row_limit;

            if (relative_row < 0)
            {
                if (Selection.FocusedIndex == -1)
                {
                    return(false);
                }

                row_limit = 0;
            }
            else
            {
                row_limit = Model.Count - 1;
            }

            if (Selection.FocusedIndex == row_limit)
            {
                return(true);
            }

            int row_index = Math.Min(Model.Count - 1, Math.Max(0, Selection.FocusedIndex + relative_row));

            if (Selection != null)
            {
                if ((modifier & Gdk.ModifierType.ControlMask) != 0)
                {
                    // Don't change the selection
                }
                else if ((modifier & Gdk.ModifierType.ShiftMask) != 0)
                {
                    // Behave like nautilus: if and arrow key + shift is pressed and the currently focused item
                    // is not selected, select it and don't move the focus or vadjustment.
                    // Otherwise, select the new row and scroll etc as necessary.
                    if (relative_row * relative_row != 1)
                    {
                        Selection.SelectFromFirst(row_index, true);
                    }
                    else if (Selection.Contains(Selection.FocusedIndex))
                    {
                        Selection.SelectFromFirst(row_index, true);
                    }
                    else
                    {
                        Selection.Select(Selection.FocusedIndex);
                        return(true);
                    }
                }
                else
                {
                    Selection.Clear(false);
                    Selection.Select(row_index);
                }
            }

            // Scroll if needed
            double y_at_row = GetYAtRow(row_index);

            if (align_y)
            {
                if (y_at_row < VadjustmentValue)
                {
                    ScrollTo(y_at_row);
                }
                else if (vadjustment != null && (y_at_row + RowHeight) > (vadjustment.Value + vadjustment.PageSize))
                {
                    ScrollTo(y_at_row + RowHeight - (vadjustment.PageSize));
                }
            }
            else if (vadjustment != null)
            {
                ScrollTo(vadjustment.Value + ((row_index - Selection.FocusedIndex) * RowHeight));
            }

            Selection.FocusedIndex = row_index;
            InvalidateList();
            return(true);
        }
コード例 #15
0
 public GenreListModel(List <Genre> list) : base()
 {
     original_list = list;
     this.list     = original_list.ToArray();
     selection     = new Selection();
 }
コード例 #16
0
 public void DeleteTracks(Hyena.Collections.Selection selection)
 {
 }
コード例 #17
0
 public void RemoveTracks(Hyena.Collections.Selection selection)
 {
 }