FSpot.MainWindow.HandleDeleteSelectedTagCommand C# (CSharp) Method

HandleDeleteSelectedTagCommand() public method

public HandleDeleteSelectedTagCommand ( object sender, EventArgs args ) : void
sender object
args System.EventArgs
return void
		public void HandleDeleteSelectedTagCommand (object sender, EventArgs args)
		{
			Tag[] tags = this.tag_selection_widget.TagHighlight;

			System.Array.Sort (tags, new TagRemoveComparer ());

			//How many pictures are associated to these tags?
			Db db = App.Instance.Database;
			FSpot.PhotoQuery count_query = new FSpot.PhotoQuery (db.Photos);
			count_query.Terms = OrTerm.FromTags (tags);
			int associated_photos = count_query.Count;

			string header;
			if (tags.Length == 1)
				header = String.Format (Catalog.GetString ("Delete tag \"{0}\"?"), tags [0].Name.Replace ("_", "__"));
			else
				header = String.Format (Catalog.GetString ("Delete the {0} selected tags?"), tags.Length);

			header = String.Format (header, tags.Length);
			string msg = String.Empty;
			if (associated_photos > 0) {
				string photodesc = Catalog.GetPluralString ("photo", "photos", associated_photos);
				msg = String.Format (
					Catalog.GetPluralString ("If you delete this tag, the association with {0} {1} will be lost.",
						"If you delete these tags, the association with {0} {1} will be lost.",
						tags.Length),
					associated_photos, photodesc);
			}
			string ok_caption = Catalog.GetPluralString ("_Delete tag", "_Delete tags", tags.Length);

			if (ResponseType.Ok == HigMessageDialog.RunHigConfirmation (main_window,
				    DialogFlags.DestroyWithParent,
				    MessageType.Warning,
				    header,
				    msg,
				    ok_caption)) {
				try {
					db.Photos.Remove (tags);
				} catch (InvalidTagOperationException e) {
					Log.Debug ("this is something or another");

					// A Category is not empty. Can not delete it.
					string error_msg = Catalog.GetString ("Tag is not empty");
					string error_desc = String.Format (Catalog.GetString ("Can not delete tags that have tags within them.  " +
					                    "Please delete tags under \"{0}\" first"),
						                    e.Tag.Name.Replace ("_", "__"));

					HigMessageDialog md = new HigMessageDialog (main_window, DialogFlags.DestroyWithParent,
						                      Gtk.MessageType.Error, ButtonsType.Ok,
						                      error_msg,
						                      error_desc);
					md.Run ();
					md.Destroy ();
				}
			}
		}
MainWindow