From bd59e9b4abc91843dda17a7d0fca042873c266d9 Mon Sep 17 00:00:00 2001 From: Matthias Neeracher Date: Wed, 16 Jan 2008 13:16:53 +0000 Subject: [PATCH] Silently transpose between major and minor modes --- Sources/VLSheetView.mm | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/Sources/VLSheetView.mm b/Sources/VLSheetView.mm index 9baa261..6320555 100644 --- a/Sources/VLSheetView.mm +++ b/Sources/VLSheetView.mm @@ -599,19 +599,31 @@ const char * sBreak[3] = {"", "\xE2\xA4\xBE", "\xE2\x8E\x98"}; - (IBAction) setKey:(id)sender { - if ([self song]->IsNonEmpty()) - [[NSAlert alertWithMessageText:@"Transpose Song?" - defaultButton:@"Transpose" - alternateButton:@"Cancel" - otherButton:@"Change Key" - informativeTextWithFormat: - @"Do you want to transpose the song into the new key?"] - beginSheetModalForWindow:[self window] - modalDelegate:self - didEndSelector:@selector(setKey:returnCode:contextInfo:) - contextInfo:sender]; - else - [self setKey:nil returnCode:NSAlertOtherReturn contextInfo:sender]; + if ([self song]->IsNonEmpty()) { + int newKey = [[sender selectedItem] tag] >> 8; + NSRange sections= [self sectionsInSelection]; + VLSong *song = [self song]; + bool plural = sections.length > 1; + + while (sections.length-- > 0) + if (song->fProperties[sections.location++].fKey != newKey) { + [[NSAlert alertWithMessageText:@"Transpose Song?" + defaultButton:@"Transpose" + alternateButton:@"Cancel" + otherButton:@"Change Key" + informativeTextWithFormat: + @"Do you want to transpose the %@ into the new key?", + (fSelEnd > -1 && song->fProperties.size() > 1) + ? (plural ? @"sections" : @"section") : @"song" + ] + beginSheetModalForWindow:[self window] + modalDelegate:self + didEndSelector:@selector(setKey:returnCode:contextInfo:) + contextInfo:sender]; + return; + } + } + [self setKey:nil returnCode:NSAlertOtherReturn contextInfo:sender]; } - (IBAction) setTime:(id)sender