Beispiel #1
0
        public void UpdateActions()
        {
            Source source = ServiceManager.SourceManager.ActiveSource;

            if (source == null)
            {
                Sensitive = Visible = false;
                return;
            }

            bool          in_database    = source is DatabaseSource;
            PrimarySource primary_source = (source as PrimarySource) ?? (source.Parent as PrimarySource);

            var track_source = source as ITrackModelSource;

            if (track_source != null)
            {
                if (FilterFocused)
                {
                    if (Selection == filter_selection)
                    {
                        filter_selection.MaxIndex = track_source.TrackModel.Selection.MaxIndex;
                        filter_selection.Clear(false);
                        filter_selection.SelectAll();
                    }
                    else
                    {
                        Log.Error(new Exception("Filter focused, but selection is not filter selection!"));
                    }
                }
                else
                {
                    UpdateActions(true, true, disable_for_filter_actions);
                }

                var selection       = Selection;
                var playing_track   = ServiceManager.PlayerEngine.CurrentTrack;
                var playback_source = (DatabaseSource)ServiceManager.PlaybackController.Source;
                int count           = selection.Count;
                Sensitive = Visible = true;
                bool has_selection        = count > 0;
                bool has_single_selection = count == 1;
                bool is_playing_or_paused = ServiceManager.PlayerEngine.CurrentState == PlayerState.Playing ||
                                            ServiceManager.PlayerEngine.CurrentState == PlayerState.Paused;
                bool is_idle = ServiceManager.PlayerEngine.CurrentState == PlayerState.Idle;

                foreach (string action in require_selection_actions)
                {
                    this[action].Sensitive = has_selection;
                }

                UpdateActions(source.CanSearch && !FilterFocused, has_single_selection,
                              "SearchMenuAction", "SearchForSameArtistAction", "SearchForSameAlbumAction"
                              );

                this["SelectAllAction"].Sensitive = track_source.Count > 0 && !selection.AllSelected;

                UpdateAction("PlayingTrackAction", !is_idle && playing_track is DatabaseTrackInfo, is_playing_or_paused, null);
                UpdateAction("AddPlayingTrackToPlaylistAction", source is MusicLibrarySource, is_playing_or_paused, null);
                UpdateAction("RatePlayingTrackAction", playback_source.HasEditableTrackProperties, is_playing_or_paused, null);
                UpdateAction("PlayingTrackPropertiesAction", playback_source.HasViewableTrackProperties, is_playing_or_paused, source);
                UpdateAction("PlayingTrackEditorAction", playback_source.HasEditableTrackProperties, is_playing_or_paused, source);
                UpdateAction("RemovePlayingTrackAction", playback_source.CanRemoveTracks, is_playing_or_paused, source);
                UpdateAction("DeletePlayingTrackFromDriveAction", playback_source.CanDeleteTracks, is_playing_or_paused, source);
                UpdateAction("OpenPlayingTrackFolderAction", playback_source.CanDeleteTracks, is_playing_or_paused, source);

                UpdateAction("SelectedTracksAction", has_selection, has_selection, null);
                UpdateAction("AddSelectedTracksToPlaylistAction", in_database && primary_source != null &&
                             primary_source.SupportsPlaylists && !primary_source.PlaylistsReadOnly, has_selection, null);
                UpdateAction("RateSelectedTracksAction", source.HasEditableTrackProperties, has_selection, null);
                UpdateAction("SelectedTracksEditorAction", source.HasEditableTrackProperties, has_selection, source);
                UpdateAction("RemoveSelectedTracksAction", track_source.CanRemoveTracks, has_selection, source);
                UpdateAction("RemoveTracksFromLibraryAction", source.Parent is LibrarySource, has_selection, null);
                UpdateAction("DeleteSelectedTracksFromDriveAction", track_source.CanDeleteTracks, has_selection, source);
                //if it can delete tracks, most likely it can open their folder
                UpdateAction("OpenSelectedTracksFolderAction", track_source.CanDeleteTracks, has_single_selection, source);
                UpdateAction("SelectedTracksPropertiesAction", source.HasViewableTrackProperties, has_selection, source);

                if (primary_source != null &&
                    !(primary_source is LibrarySource) &&
                    primary_source.StorageName != null)
                {
                    this["DeleteSelectedTracksFromDriveAction"].Label = String.Format(
                        Catalog.GetString("_Delete From \"{0}\""), primary_source.StorageName);
                    this["DeletePlayingTrackFromDriveAction"].Label = String.Format(
                        Catalog.GetString("_Delete From \"{0}\""), primary_source.StorageName);
                }

                if (FilterFocused)
                {
                    UpdateActions(false, false, disable_for_filter_actions);
                }
            }
            else
            {
                Sensitive = Visible = false;
            }
        }
Beispiel #2
0
        public void UpdateActions()
        {
            Source source = ServiceManager.SourceManager.ActiveSource;

            if (source == null)
            {
                Sensitive = Visible = false;
                return;
            }

            bool          in_database    = source is DatabaseSource;
            PrimarySource primary_source = (source as PrimarySource) ?? (source.Parent as PrimarySource);

            var track_source = source as ITrackModelSource;

            if (track_source != null)
            {
                if (FilterFocused)
                {
                    if (Selection == filter_selection)
                    {
                        filter_selection.MaxIndex = track_source.TrackModel.Selection.MaxIndex;
                        filter_selection.Clear(false);
                        filter_selection.SelectAll();
                    }
                    else
                    {
                        Log.Error("Filter focused, but selection is not filter selection!");
                        Console.WriteLine(System.Environment.StackTrace);
                    }
                }

                var selection = Selection;
                int count     = selection.Count;
                Sensitive = Visible = true;
                bool has_selection        = count > 0;
                bool has_single_selection = count == 1;

                foreach (string action in require_selection_actions)
                {
                    this[action].Sensitive = has_selection;
                }

                UpdateActions(source.CanSearch && !FilterFocused, has_single_selection,
                              "SearchMenuAction", "SearchForSameArtistAction", "SearchForSameAlbumAction"
                              );

                this["SelectAllAction"].Sensitive = track_source.Count > 0 && !selection.AllSelected;
                UpdateAction("RemoveTracksAction", track_source.CanRemoveTracks, has_selection, source);
                UpdateAction("DeleteTracksFromDriveAction", track_source.CanDeleteTracks, has_selection, source);

                //if it can delete tracks, most likely it can open their folder
                UpdateAction("OpenContainingFolderAction", track_source.CanDeleteTracks, has_single_selection, source);

                UpdateAction("RemoveTracksFromLibraryAction", source.Parent is LibrarySource, has_selection, null);

                UpdateAction("TrackPropertiesAction", source.HasViewableTrackProperties, has_selection, source);
                UpdateAction("TrackEditorAction", source.HasEditableTrackProperties, has_selection, source);
                UpdateAction("RateTracksAction", source.HasEditableTrackProperties, has_selection, null);
                UpdateAction("AddToPlaylistAction", in_database && primary_source != null &&
                             primary_source.SupportsPlaylists && !primary_source.PlaylistsReadOnly, has_selection, null);

                if (primary_source != null &&
                    !(primary_source is LibrarySource) &&
                    primary_source.StorageName != null)
                {
                    this["DeleteTracksFromDriveAction"].Label = String.Format(
                        Catalog.GetString("_Delete From \"{0}\""), primary_source.StorageName);
                }

                if (FilterFocused)
                {
                    UpdateActions(false, false, disable_for_filter_actions);
                }
            }
            else
            {
                Sensitive = Visible = false;
            }
        }