Banshee.Gui.TrackActions.ConfirmRemove C# (CSharp) Method

ConfirmRemove() private static method

private static ConfirmRemove ( ITrackModelSource source, bool delete, int selCount ) : bool
source ITrackModelSource
delete bool
selCount int
return bool
        private static bool ConfirmRemove (ITrackModelSource source, bool delete, int selCount)
        {
            if (!source.ConfirmRemoveTracks) {
                return true;
            }

            bool ret = false;
            string header = null;
            string message = null;
            string button_label = null;

            if (delete) {
                header = String.Format (
                    Catalog.GetPluralString (
                        "Are you sure you want to permanently delete this item?",
                        "Are you sure you want to permanently delete the selected {0} items?", selCount
                    ), selCount
                );
                message = Catalog.GetString ("If you delete the selection, it will be permanently lost.");
                button_label = "gtk-delete";
            } else {
                header = String.Format (Catalog.GetString ("Remove selection from {0}?"), source.Name);
                message = String.Format (
                    Catalog.GetPluralString (
                        "Are you sure you want to remove the selected item from your {1}?",
                        "Are you sure you want to remove the selected {0} items from your {1}?", selCount
                    ), selCount, source.GenericName
                );
                button_label = "gtk-remove";
            }

            HigMessageDialog md = new HigMessageDialog (
                ServiceManager.Get<GtkElementsService> ().PrimaryWindow,
                DialogFlags.DestroyWithParent, delete ? MessageType.Warning : MessageType.Question,
                ButtonsType.None, header, message
            );
            // Delete from Disk defaults to Cancel and the others to OK/Confirm.
            md.AddButton ("gtk-cancel", ResponseType.No, delete);
            md.AddButton (button_label, ResponseType.Yes, !delete);

            try {
                if (md.Run () == (int) ResponseType.Yes) {
                    ret = true;
                }
            } finally {
                md.Destroy ();
            }
            return ret;
        }
    }

Usage Example

Example #1
0
        public GlobalActions() : base("Global")
        {
            Add(new ActionEntry [] {
                // Media Menu
                new ActionEntry("MediaMenuAction", null,
                                Catalog.GetString("_Media"), null, null, null),

                new ActionEntry("ImportAction", Stock.Open,
                                Catalog.GetString("Import _Media..."), "<control>I",
                                Catalog.GetString("Import media from a variety of sources"), OnImport),

                new ActionEntry("ImportPlaylistAction", null,
                                Catalog.GetString("Import _Playlist..."), null,
                                Catalog.GetString("Import a playlist"), OnImportPlaylist),

                new ActionEntry("OpenLocationAction", null,
                                Catalog.GetString("Open _Location..."), "<control>L",
                                Catalog.GetString("Open a remote location for playback"), OnOpenLocation),

                new ActionEntry("QuitAction", Stock.Quit,
                                Catalog.GetString("_Quit"), "<control>Q",
                                Catalog.GetString("Quit Banshee"), OnQuit),

                // Edit Menu
                new ActionEntry("EditMenuAction", null,
                                Catalog.GetString("_Edit"), null, null, null),

                new ActionEntry("PreferencesAction", Stock.Preferences,
                                Catalog.GetString("_Preferences"), "",
                                Catalog.GetString("Modify your personal preferences"), OnPreferences),

                // Tools menu
                new ActionEntry("ToolsMenuAction", null,
                                Catalog.GetString("_Tools"), null, null, null),

                new ActionEntry("RescanAction", null,
                                Catalog.GetString("Rescan Music Library"), null,
                                Catalog.GetString("Rescan the Music Library folder"), delegate {
                    new Banshee.Collection.RescanPipeline(ServiceManager.SourceManager.MusicLibrary, tracks => {
                        string msg = String.Format(
                            Catalog.GetPluralString(
                                // singular form unused b/c we know it's > 1, but we still need GetPlural
                                "The rescan operation will remove one track from your music library.",
                                "The rescan operation will remove {0} tracks from your music library.",
                                tracks),
                            tracks);

                        return(TrackActions.ConfirmRemove(msg));
                    });
                }),

                // Help Menu
                new ActionEntry("HelpMenuAction", null,
                                Catalog.GetString("_Help"), null, null, null),

                new ActionEntry("UserHelp", Gtk.Stock.Help,
                                Catalog.GetString("_Contents"), "F1", null,
                                delegate { Banshee.ServiceStack.Application.DisplayHelp(null); }),

                new ActionEntry("WikiSearchHelpAction", null,
                                Catalog.GetString("Advanced Collection Searching"), null,
                                Catalog.GetString("Learn advanced ways to search your media collection"), delegate {
                    Banshee.Web.Browser.Open("http://banshee.fm/support/guide/searching/");
                }),

                new ActionEntry("WikiAction", null,
                                Catalog.GetString("Banshee _Home Page"), null,
                                Catalog.GetString("Visit the Banshee Home Page"), delegate {
                    Banshee.Web.Browser.Open("http://banshee.fm/");
                }),

                new ActionEntry("WikiDeveloperAction", null,
                                Catalog.GetString("_Get Involved"), null,
                                Catalog.GetString("Become a contributor to Banshee"), delegate {
                    Banshee.Web.Browser.Open("http://banshee.fm/contribute/");
                }),

                new ActionEntry("VersionInformationAction", null,
                                Catalog.GetString("_Version Information"), null,
                                Catalog.GetString("View detailed version and configuration information"), OnVersionInformation),

                new ActionEntry("AboutAction", "gtk-about", OnAbout)
            });

            this["VersionInformationAction"].Visible = ApplicationContext.Debugging;

            GLib.Timeout.Add(500, delegate {
                if (ApplicationContext.CommandLine.Contains("show-import-media"))
                {
                    OnImport(null, null);
                }

                if (ApplicationContext.CommandLine.Contains("show-about"))
                {
                    OnAbout(null, null);
                }

                if (ApplicationContext.CommandLine.Contains("show-open-location"))
                {
                    OnOpenLocation(null, null);
                }

                if (ApplicationContext.CommandLine.Contains("show-preferences"))
                {
                    OnPreferences(null, null);
                }

                return(false);
            });
        }