/// <summary> /// returns true if it is a new song /// </summary> /// <returns></returns> internal bool SaveSong() { if (txtTitle.Text.Trim() == "") { Helpers.PopupMessages.ShowErrorMessage(this, "Song title cannot be blank"); return(false); } //update the song object with the data in the gui updateSongObjectFromGui(); //Check if there is already a song with the name chosen bool anotherSongWithThisNameAlreadyExists = !string.Equals(CurrentSong.SongFileName, CurrentSong.title, StringComparison.OrdinalIgnoreCase) && Song.Exists(CurrentSong.title); if (anotherSongWithThisNameAlreadyExists) { Helpers.PopupMessages.ShowErrorMessage(this, "Song '{0}' already exists please choose another name", CurrentSong.title); return(false); } //save the song CurrentSong.deleteSong(); bool isNewSong = CurrentSong.saveSong(); //notify the user Helpers.PopupMessages.ShowInformationMessage(this, "Song '{0}' saved", CurrentSong.title); SongChanged = false; return(isNewSong); }
internal bool DeleteSong() { if (Helpers.PopupMessages.ShowConfirmationMessage(this, "Are you sure you want to delete song '{0}'?", CurrentSong.SongFileName)) { CurrentSong.deleteSong(); return(true); } else { return(false); } }
/// <summary> /// returns true if it is a new song /// </summary> /// <returns></returns> internal bool SaveSong() { if (txtTitle.Text.Trim() == "") { Helpers.PopupMessages.ShowErrorMessage(this, "Song title cannot be blank"); return(false); } if (txtTitle.Text.Contains("\\")) { Helpers.PopupMessages.ShowErrorMessage(this, "Song title cannot contain '\\' character"); return(false); } if (txtTitle.Text.Contains("/")) { Helpers.PopupMessages.ShowErrorMessage(this, "Song title cannot contain '/' character"); return(false); } string originalSongName = (string.IsNullOrWhiteSpace(CurrentSong.SongSubFolder)) ? CurrentSong.title : $"{CurrentSong.SongSubFolder}/{CurrentSong.title}"; string newSongName = (string.IsNullOrWhiteSpace(txtSubFolder.Text)) ? txtTitle.Text : $"{txtSubFolder.Text}/{txtTitle.Text}"; bool wasSongNameChanged = !string.Equals(originalSongName, newSongName, StringComparison.InvariantCultureIgnoreCase); //Check if there is already a song with the name chosen bool doesSongExist = Song.Exists(newSongName); if (doesSongExist && wasSongNameChanged) { Helpers.PopupMessages.ShowErrorMessage(this, $"Song '{newSongName}' already exists please choose another name"); return(false); } // If the song is a rename delete the old song if (wasSongNameChanged) { CurrentSong.deleteSong(); } // Save the song and updateSongObjectFromGui(); bool isNewSong = CurrentSong.saveSong(); //notify the user Helpers.PopupMessages.ShowInformationMessage(this, $"Song '{CurrentSong.SongTitleIncludingSubFolder}' saved"); SongChanged = false; return(isNewSong); }