/Source Code/PowerSong/frmMain.vb
Visual Basic | 1027 lines | 700 code | 253 blank | 74 comment | 1 complexity | 2259521af4e19b5cdc27972036adee9f MD5 | raw file
1Imports PowerSong.SongDatabase 2Imports PowerSong.SongDatabase.Bibles 3Imports PowerSong.SongDatabase.Items 4Imports PowerSong.Projection 5Imports PowerSong.SongDatabase.Logging 6 7Public Class frmMain 8 9 Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click 10 Application.Exit() 11 End Sub 12 13 Private Sub btnAddSong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddSong.Click, NewSongToolStripMenuItem.Click 14 15 Dim Form As New frmSong(Database) 16 If Form.ShowDialog = Windows.Forms.DialogResult.OK Then 17 18 ' Add the song to the database, its index, and the list 19 Database.Songs.AddSong(Form.Song) 20 Database.SongIndex.AddToIndex(Form.Song) 21 lstItems.Items.Add(New ListItem(Of Guid)(Form.Song.Title, Form.Song.SongID)) 22 UpdateItemCountLabel() 23 UpdateCategoryList() 24 25 End If 26 27 End Sub 28 29 Private Sub CreateDatabaseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateDatabaseToolStripMenuItem.Click 30 31 Dim Form As New frmCreateDatabase 32 If Form.ShowDialog = Windows.Forms.DialogResult.OK Then 33 CloseDatabase() 34 Database = Form.Database 35 DatabaseLocation = Form.DatabaseLocation 36 FActiveStyle = Database.Styles.GetDefaultStyle 37 UpdateAll() 38 End If 39 40 End Sub 41 42 Private Sub LoadDatabaseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadDatabaseToolStripMenuItem.Click 43 44 If dlgSelectDatabaseFolder.ShowDialog = Windows.Forms.DialogResult.OK Then 45 46 Try 47 48 ' Unload plugins 49 Plugins.Instance.UnloadAllPlugins() 50 51 ' Load the database 52 Dim InterimDatabase As Database = Database.Load(dlgSelectDatabaseFolder.SelectedPath) 53 54 ' Set the active database to the new one 55 CloseDatabase() 56 DatabaseLocation = dlgSelectDatabaseFolder.SelectedPath 57 Database = InterimDatabase 58 FActiveStyle = Database.Styles.GetDefaultStyle 59 UpdateAll() 60 61 Catch ex As Exception 62 MsgBox("Could not load the database:" + Environment.NewLine + ex.Message, MsgBoxStyle.Critical) 63 UpdateAll() 64 End Try 65 66 ' Load plugins 67 Try 68 Plugins.Instance.LoadAllPlugins(Database) 69 Catch ex As Exception 70 MsgBox("Problem loading plugins:" + Environment.NewLine + ex.Message, MsgBoxStyle.Exclamation) 71 End Try 72 73 End If 74 75 End Sub 76 77 Private Sub lstItems_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstItems.DoubleClick, btnAddToPlaylist.Click, AddToPlaylistToolStripMenuItem.Click 78 79 ' Determine the currently active style (Default if no style active) 80 Dim Style As Style = FActiveStyle 81 If FActiveStyle Is Nothing Then Style = Database.Styles.GetDefaultStyle 82 83 If lstItems.SelectedItem IsNot Nothing Then 84 85 Try 86 87 If optSongs.Checked Then 88 89 ' Add the song 90 Dim SelectedItem As ListItem(Of Guid) = lstItems.SelectedItem 91 Dim SelectedSong As SongItem = Database.Songs.GetSong(SelectedItem.Key) 92 lstPlaylist.AddItem(New SongsListItem(SelectedSong, Style)) 93 94 Else 95 96 ' Add the bible chapter 97 Dim SelectedItem As ListItem(Of String) = lstItems.SelectedItem 98 Dim SelectedChapter As New AdhocItem 99 SelectedChapter.CopyrightLine = BibleIndex.Translation 100 SelectedChapter.Title = SelectedItem.ToString 101 For Each Verse As String In BibleIndex.FindChapter(SelectedItem.Key).Split(Environment.NewLine) 102 SelectedChapter.Parts.Add(Verse.Trim) 103 Next 104 lstPlaylist.AddItem(New SongsListItem(SelectedChapter, Style)) 105 106 End If 107 108 Catch ex As Exception 109 MsgBox(ex.Message, MsgBoxStyle.Critical) 110 End Try 111 112 End If 113 114 End Sub 115 116 Private Sub btnDeleteSong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteSong.Click, DeleteSongToolStripMenuItem.Click 117 118 If lstItems.SelectedItem IsNot Nothing Then 119 120 ' Get details for the selected item 121 Dim SelectedItem As ListItem(Of Guid) = lstItems.SelectedItem 122 Dim SongID As Guid = SelectedItem.Key 123 Dim SongTitle As String = SelectedItem.ToString 124 125 ' Confirm user wishes to delete the item 126 If MsgBox("Are you sure you wish to delete the song '" + SongTitle + "'?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then 127 128 ' Delete the item 129 Database.SongIndex.RemoveFromIndex(SongID) 130 Database.Songs.DeleteSong(SongID) 131 lstItems.Items.RemoveAt(lstItems.SelectedIndex) 132 UpdateItemCountLabel() 133 134 End If 135 136 End If 137 138 End Sub 139 140 Private Sub tmrMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMain.Tick 141 For Each Projection As Projector In FProjections 142 Projection.Update() 143 Next 144 End Sub 145 146 Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing 147 148 Try 149 150 ' Save the index 151 If Database IsNot Nothing Then Database.SongIndex.Save() 152 153 ' Close the database 154 CloseDatabase() 155 156 ' Disconnect and destroy all projectors 157 FProjections.Clear() 158 159 Catch ex As Exception 160 MsgBox("An error occured while PowerSong was being closed:" + Environment.NewLine + _ 161 ex.Message + Environment.NewLine + Environment.NewLine + _ 162 "PowerSong will now terminate.", MsgBoxStyle.Critical) 163 End Try 164 165 End Sub 166 167 Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown 168 169 Select Case e.KeyCode 170 171 Case Keys.Return 172 If txtSearch.Focused Then 173 lstItems_DoubleClick(sender, e) 174 Else 175 ChangeActivePart(lstVerses.SelectedIndex) 176 End If 177 178 End Select 179 180 End Sub 181 182 Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 183 184 GlobalContext.MainForm = Me 185 PowerSongApi.Initialise(Me) 186 187 ' Check if a command line was present 188 Dim ExternalFileName As String = "" 189 If My.Application.CommandLineArgs.Count > 0 Then 190 ExternalFileName = My.Application.CommandLineArgs(0) 191 End If 192 193 ' Determine which database to open 194 DatabaseLocation = "" 195 Database = Nothing 196 Dim ShortcutCreateRequested As Boolean = False 197 If ExternalFileName <> "" AndAlso IO.Path.GetExtension(ExternalFileName).ToUpper = ".PSDB" Then 198 199 ' Load database via link 200 Try 201 DatabaseLocation = IO.File.ReadAllText(ExternalFileName) 202 Database = Database.Load(DatabaseLocation) 203 Catch ex As Exception 204 MsgBox(ex.Message, MsgBoxStyle.Critical) 205 DatabaseLocation = "" 206 Database = Nothing 207 End Try 208 209 Else 210 211 ' Load database via startup form 212 Dim StartupForm As New frmStartup 213 If StartupForm.ShowDialog = Windows.Forms.DialogResult.OK Then 214 DatabaseLocation = StartupForm.DatabaseLocation 215 Database = StartupForm.Database 216 ShortcutCreateRequested = StartupForm.CreateShortcut 217 End If 218 219 End If 220 221 ' Set up everything if a database was loaded 222 If Database IsNot Nothing Then 223 224 ' Set an active style 225 FActiveStyle = Database.Styles.GetDefaultStyle 226 227 ' Load the bible 228 GlobalContext.LoadBible(Database.Settings.ActiveBible) 229 230 ' Add available screens to the main menu 231 Dim ScreenIndex As Integer = 0 232 For Each Screen As Screen In Screen.AllScreens 233 Dim NextMenuItem1 As New ToolStripMenuItem("Screen " + (ScreenIndex + 1).ToString) 234 Dim NextMenuItem2 As New ToolStripMenuItem("Screen " + (ScreenIndex + 1).ToString) 235 NextMenuItem1.Tag = ScreenIndex 236 NextMenuItem2.Tag = ScreenIndex 237 NextMenuItem1.ShortcutKeys = Keys.Control + Keys.D1 + ScreenIndex 238 AddHandler NextMenuItem1.Click, AddressOf HandleSelectScreenTarget 239 AddHandler NextMenuItem2.Click, AddressOf HandleSelectScreenTarget 240 ProjectionTargetToolStripMenuItem.DropDownItems.Add(NextMenuItem1) 241 ProjectionTargetToolStripMenuItem1.DropDownItems.Add(NextMenuItem2) 242 ScreenIndex += 1 243 Next 244 245 ' Set up the projection form 246 FProjectionForm = New frmMainProjection 247 Dim LastScreenBounds As Rectangle = Screen.AllScreens(Screen.AllScreens.Length - 1).Bounds 248 FProjectionForm.Location = New Point(LastScreenBounds.Left, LastScreenBounds.Top) 249 250 ' Set up projections 251 FPreviewProjector = CreateProjector(pbPreview) 252 FPreviewProjector.Projecting = False 253 Dim MainProjector As Projector = CreateProjector(FProjectionForm) 254 MainProjector.Projecting = False 255 FProjections.Add(FPreviewProjector) 256 FProjections.Add(MainProjector) 257 FProjectionForm.Projector = MainProjector 258 AddHandler MainProjector.ModeChanged, AddressOf HandleCompletedModeChange 259 260 ' Set initial state of the projectors 261 btnGoToBlack_Click(sender, e) 262 FPreviewProjector.FadeToText(0) 263 If Database.Settings.ShowMainProjection Then ToggleProjector(FProjectionForm) 264 If Database.Settings.ShowPreviewProjection Then ToggleProjector(pbPreview) 265 266 ' Display contents of all controls 267 UpdateAll() 268 269 ' Select all categories initially 270 For ItemIndex As Integer = 0 To lstCategories.Items.Count - 1 271 lstCategories.SetItemChecked(ItemIndex, True) 272 Next 273 274 ' Create a shortcut if requested 275 If ShortcutCreateRequested Then CreateShortcutToolStripMenuItem_Click(sender, e) 276 277 ' Load external file if one was specified 278 If ExternalFileName <> "" AndAlso IO.Path.GetExtension(ExternalFileName).ToUpper <> ".PSDB" Then 279 LoadExternalFile(ExternalFileName) 280 End If 281 282 Else 283 Application.Exit() 284 End If 285 286 ' Enable/disable functionality as specified in the configuration file 287 Functionality.ConfigureForm(Me) 288 289 End Sub 290 291 Private Function CreateProjector(ByVal target As Control) As Projector 292 293 Dim Result As New Projector(target) 294 Result.Projectlets.Add(New Projectlet("Title", ProjectletStyle.TITLE_TAG)) 295 Result.Projectlets.Add(New Projectlet("Verse", ProjectletStyle.VERSE_TAG)) 296 Result.Projectlets.Add(New Projectlet("Copyright", ProjectletStyle.SIMPLE_COPYRIGHT_TAG)) 297 AddHandler Result.ProjectionComplete, AddressOf PerformPluginProjection 298 Return Result 299 300 End Function 301 302 Private Sub PerformPluginProjection(ByVal graphics As Graphics, _ 303 ByVal projectionWidth As Integer, _ 304 ByVal projectionHeight As Integer) 305 306 For Each Plugin As PluginSupport.IPlugin In Plugins.Instance.Items.Values 307 Try 308 Plugin.Project(graphics, projectionWidth, projectionHeight) 309 Catch ex As Exception 310 Plugin.Stop() 311 MsgBox("A plugin has crashed with the following message:" + Environment.NewLine + _ 312 ex.Message + Environment.NewLine + Environment.NewLine + _ 313 "The plugin will be stopped.", MsgBoxStyle.Exclamation) 314 End Try 315 Next 316 317 End Sub 318 319 Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click 320 321 If FActiveItem Is Nothing Then 322 MsgBox("Please select an item first.", MsgBoxStyle.Information) 323 Exit Sub 324 End If 325 326 Dim NextActivePart As Integer = FActivePart + 1 327 If NextActivePart >= lstVerses.Items.Count Then NextActivePart = 0 328 ChangeActivePart(NextActivePart) 329 330 End Sub 331 332 Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click 333 334 If FActiveItem Is Nothing Then 335 MsgBox("Please select an item first.", MsgBoxStyle.Information) 336 Exit Sub 337 End If 338 339 ChangeActivePart(Math.Max(FActivePart - 1, 0)) 340 341 End Sub 342 343 Private Sub btnSetImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetImage.Click, ChangeBacToolStripMenuItem.Click 344 345 ' Show the set background form 346 Dim SelectedItem As SongsListItem = lstPlaylist.SelectedItem 347 Dim Form As New frmSetBackground(SelectedItem.OverrideBackground) 348 If Form.ShowDialog = Windows.Forms.DialogResult.OK Then 349 350 ' Override the item's background defined in its style 351 SelectedItem.OverrideBackground = Form.Background 352 353 ' Update projectors if the song is active 354 If SelectedItem.Item Is FActiveItem Then 355 If SelectedItem.OverrideBackground IsNot Nothing Then 356 OverrideProjectorBackground(SelectedItem.OverrideBackground) 357 End If 358 End If 359 360 End If 361 362 End Sub 363 364 Private Sub TogglePreviewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TogglePreviewToolStripMenuItem.Click 365 ToggleProjector(pbPreview) 366 End Sub 367 368 Private Sub ToggleFullScreenViewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToggleFullScreenViewToolStripMenuItem.Click 369 ToggleProjector(FProjectionForm) 370 UpdateControlVisibility() 371 Me.Activate() 372 End Sub 373 374 Private Sub ExportDatabaseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExportDatabaseToolStripMenuItem.Click 375 Call (New frmExportDatabase(Database)).ShowDialog() 376 End Sub 377 378 Private Sub ImportDatabaseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImportDatabaseToolStripMenuItem.Click 379 Dim Form As New frmImportDatabase(Database) 380 If Form.ShowDialog = Windows.Forms.DialogResult.OK Then 381 UpdateAll() 382 End If 383 End Sub 384 385 Private Sub HandleDisplaySongRequest(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstPlaylist.DoubleClick, btnDisplaySong.Click, DisplayItemNowToolStripMenuItem.Click 386 387 If lstPlaylist.SelectedIndex = -1 Then Exit Sub 388 389 ' Log that the old song is no longer visible 390 If FActiveItem IsNot Nothing AndAlso TypeOf FActiveItem Is SongItem Then 391 Database.Logging.Add(LogEntry.ItemType.Song, DirectCast(FActiveItem, SongItem).SongID, Now, LogEntry.Action.Hidden) 392 End If 393 394 ' Change the active song, selecting the first part of it 395 Dim SelectedItem As SongsListItem = lstPlaylist.Items(lstPlaylist.SelectedIndex) 396 FActiveItem = SelectedItem.Item 397 FActiveStyle = SelectedItem.Style 398 UpdateActiveItem() 399 lstPlaylist.ActiveItem = SelectedItem 400 FActivePart = 0 401 Dim NextSelectedIndex As Integer = 0 402 If lstVerses.Items.Count = 0 Then NextSelectedIndex = -1 403 If NextSelectedIndex < lstVerses.Items.Count - 1 Then NextSelectedIndex += 1 404 lstVerses.SelectedIndex = NextSelectedIndex 405 lstVerses.ActiveIndex = 0 406 407 ' Update all projectors generally 408 UpdateProjectorStyle() 409 For Each Projection As Projector In FProjections 410 Dim CurrentPart As String = "" 411 If FActiveItem.Parts.Count > 0 Then CurrentPart = FActiveItem.Parts(0) 412 413 ' Update the projectlets 414 For Each ProjectletName As String In New String() {"Title", "Copyright", "Verse"} 415 Dim Projectlet As Projectlet = Projection.ProjectletByName(ProjectletName) 416 Dim Text As String = Projectlet.PopulateTags(FActiveItem, FActivePart) 417 Projection.SetText(Projectlet, 0, FActiveItem.Parts.Count, Text, ProjectletName <> "Verse") 418 Next 419 420 Next 421 If SelectedItem.OverrideBackground IsNot Nothing Then OverrideProjectorBackground(SelectedItem.OverrideBackground) 422 423 ' Log the displaying of the new song 424 If TypeOf FActiveItem Is SongItem Then 425 Database.Logging.Add(LogEntry.ItemType.Song, DirectCast(FActiveItem, SongItem).SongID, Now, LogEntry.Action.Shown) 426 End If 427 428 End Sub 429 430 Private Sub OverrideProjectorBackground(ByVal background As OverrideBackground) 431 432 For Each Projection As Projector In FProjections 433 Select Case background.Type 434 Case Style.EBackgroundType.SolidColour 435 Projection.SetBackgroundColour(background.Value) 436 Case Style.EBackgroundType.Image 437 Projection.SetBackgroundImage(background.Value) 438 End Select 439 Next 440 441 End Sub 442 443 Private Sub btnConfigureSong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfigureSong.Click, ConfigurePlaylistItemToolStripMenuItem.Click 444 445 Dim SelectedItem As SongsListItem = lstPlaylist.Items(lstPlaylist.SelectedIndex) 446 Dim Form As New frmConfigureItem(SelectedItem.Item, SelectedItem.Style, Database.Styles) 447 If (Form.ShowDialog = Windows.Forms.DialogResult.OK) Then 448 SelectedItem.Style = Form.SelectedStyle 449 SelectedItem.OverrideBackground = Nothing 450 If FActiveItem Is SelectedItem.Item Then 451 FActiveStyle = SelectedItem.Style 452 UpdateProjectorStyle() 453 End If 454 End If 455 456 End Sub 457 458 Private Sub AboutPowerSongToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutPowerSongToolStripMenuItem.Click 459 Call (New frmAbout).ShowDialog() 460 End Sub 461 462 Private Sub ConfigureStylesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfigureStylesToolStripMenuItem.Click 463 464 ' Determine the name of the currently active style 465 Dim OldActiveStyle As String = "" 466 If FActiveStyle IsNot Nothing Then OldActiveStyle = FActiveStyle.Name 467 468 If New frmConfigureStyles(Database.Styles).ShowDialog = Windows.Forms.DialogResult.OK Then 469 If Database.Styles.GetAllStyleNames.Contains(OldActiveStyle) Then 470 FActiveStyle = Database.Styles.GetStyle(OldActiveStyle) 471 UpdateProjectorStyle() 472 473 ' Reflect changes in the playlist 474 For I As Integer = 0 To lstPlaylist.ItemCount - 1 475 Dim Item As SongsListItem = lstPlaylist.Items(I) 476 If Item.Style.Name = OldActiveStyle Then 477 Item.Style = FActiveStyle 478 Item.RefreshIcon() 479 End If 480 Next 481 482 End If 483 End If 484 485 End Sub 486 487 Private Sub btnRemoveFromPlaylist_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveFromPlaylist.Click, RemoveToolStripMenuItem.Click 488 489 ' Ensure that something is selected 490 If lstPlaylist.SelectedItem Is Nothing Then 491 MsgBox("Please select something to remove first.", MsgBoxStyle.Information) 492 Exit Sub 493 End If 494 495 Dim SelectedItem As SongsListItem = lstPlaylist.Items(lstPlaylist.SelectedIndex) 496 If FActiveItem IsNot Nothing AndAlso SelectedItem.Item Is FActiveItem Then 497 FActiveItem = Nothing 498 FActivePart = -1 499 UpdateActiveItem() 500 End If 501 lstPlaylist.RemoveItem(SelectedItem) 502 503 End Sub 504 505 Private Sub lstVerses_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstVerses.DoubleClick 506 If lstVerses.SelectedItem IsNot Nothing Then 507 ChangeActivePart(lstVerses.SelectedIndex) 508 End If 509 End Sub 510 511 Private Sub btnGoToFull_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoToFull.Click, GoToFullDisplayToolStripMenuItem.Click 512 513 btnGoToFull.ForeColor = Color.Red 514 For Each Projector As Projector In FProjections 515 If Projector.Target IsNot pbPreview Then Projector.FadeToText(FActiveStyle.GeneralFadeDuration) 516 Next 517 518 End Sub 519 520 Private Sub btnGoToBackground_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoToBackground.Click, GoToBackgroundOnlyToolStripMenuItem.Click 521 522 btnGoToBackground.ForeColor = Color.Red 523 For Each Projector As Projector In FProjections 524 If Projector.Target IsNot pbPreview Then Projector.FadeToBackground(FActiveStyle.GeneralFadeDuration) 525 Next 526 527 End Sub 528 529 Private Sub btnGoToBlack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoToBlack.Click, GoToBlackToolStripMenuItem.Click 530 531 btnGoToBlack.ForeColor = Color.Red 532 For Each Projector As Projector In FProjections 533 If Projector.Target IsNot pbPreview Then Projector.FadeToBlack(FActiveStyle.GeneralFadeDuration) 534 Next 535 536 End Sub 537 538 Private Sub btnEditSong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditSong.Click, EditSongToolStripMenuItem.Click 539 540 ' Check we can edit the item 541 If TypeOf FActiveItem Is SongItem Then 542 543 ' Show the user the edit song dialog 544 Dim Form As New frmSong(Database, FActiveItem) 545 If Form.ShowDialog = Windows.Forms.DialogResult.OK Then 546 547 ' Save changes to the song 548 Database.Songs.EditSong(Form.Song.SongID, Form.Song) 549 550 ' Update the song in the index 551 Database.SongIndex.UpdateIndex(Form.Song) 552 553 ' Update categories list 554 UpdateCategoryList() 555 556 ' Update the screen 557 If FActivePart >= Form.Song.Parts.Count Then FActivePart = Form.Song.Parts.Count - 1 558 UpdateAll() 559 lstVerses.ActiveIndex = FActivePart 560 lstVerses_DoubleClick(sender, e) 561 562 End If 563 564 ElseIf TypeOf FActiveItem Is AdhocItem Then 565 566 ' Show the user the edit title dialog 567 Dim Form As New frmTitle(FActiveItem) 568 If Form.ShowDialog = Windows.Forms.DialogResult.OK Then 569 570 ' Update the screen 571 If FActivePart >= Form.Title.Parts.Count Then FActivePart = Form.Title.Parts.Count - 1 572 UpdateAll() 573 lstVerses.ActiveIndex = FActivePart 574 lstVerses_DoubleClick(sender, e) 575 576 End If 577 578 Else 579 MsgBox("You cannot edit that item.", MsgBoxStyle.Exclamation) 580 End If 581 582 End Sub 583 584 Private Sub EditVerseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditVerseToolStripMenuItem.Click 585 586 ' Check that a verse has been selected 587 If lstVerses.SelectedIndex = -1 Then 588 MsgBox("Please select a verse to edit first.", MsgBoxStyle.Exclamation) 589 Exit Sub 590 End If 591 592 ' Show the form 593 Dim Form As New frmVerse(FActiveItem, lstVerses.SelectedIndex) 594 If Form.ShowDialog = Windows.Forms.DialogResult.OK Then 595 596 ' Update the song 597 If TypeOf Form.Item Is SongItem Then 598 Database.Songs.EditSong(DirectCast(Form.Item, SongItem).SongID, Form.Item) 599 Database.SongIndex.UpdateIndex(Form.Item) 600 End If 601 602 ' Update the song if it is active 603 If FActivePart = lstVerses.SelectedIndex Then ChangeActivePart(FActivePart) 604 UpdateActiveItem() 605 lstVerses.ActiveIndex = FActivePart 606 607 End If 608 609 End Sub 610 611 Private Sub AddVerseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddVerseToolStripMenuItem.Click 612 613 ' Show the form 614 Dim Form As New frmVerse(FActiveItem) 615 If Form.ShowDialog = Windows.Forms.DialogResult.OK Then 616 617 ' Update the song 618 If TypeOf Form.Item Is SongItem Then 619 Database.Songs.EditSong(DirectCast(Form.Item, SongItem).SongID, Form.Item) 620 Database.SongIndex.UpdateIndex(Form.Item) 621 End If 622 623 ' Update the song if it is active 624 UpdateActiveItem() 625 lstVerses.ActiveIndex = FActivePart 626 627 End If 628 629 End Sub 630 631 Private Sub ConfigurePowerSongToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfigurePowerSongToolStripMenuItem.Click 632 633 If (New frmConfiguration(Database)).ShowDialog = Windows.Forms.DialogResult.OK Then 634 Functionality.ConfigureForm(Me) 635 End If 636 637 End Sub 638 639 Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged 640 641 If Database Is Nothing Then Exit Sub 642 643 Try 644 645 If txtSearch.Text = "" Then 646 UpdateItemList() 647 Else 648 649 lstItems.Items.Clear() 650 lstItems.Sorted = False 651 lstItems.BeginUpdate() 652 653 If optSongs.Checked Then 654 655 ' Search songs 656 Dim FoundSongs As List(Of Guid) = Database.SongIndex.FindSongs(txtSearch.Text) 657 For Each SongID As Guid In FoundSongs 658 659 ' Only add a song if its category is visible 660 Dim SongAdded As Boolean = False 661 For Each SelectedCategory As ListItem(Of Guid) In lstCategories.CheckedItems 662 If Database.Songs.GetSongCategories(SongID).Contains(SelectedCategory.Key) Then 663 If Not SongAdded Then 664 lstItems.Items.Add(New ListItem(Of Guid)(Database.Songs.GetSongTitle(SongID), SongID)) 665 SongAdded = True 666 End If 667 End If 668 Next 669 670 Next 671 lblItemCount.Text = "Songs Found: (" + lstItems.Items.Count.ToString + ")" 672 673 Else 674 675 ' Search bible 676 Dim References As List(Of BibleReference) = BibleSupport.DetermineReferences(txtSearch.Text) 677 For Each Reference As BibleReference In References 678 If Reference.Chapter <> -1 Then 679 lstItems.Items.Add(New ListItem(Of String)(Reference.ToChapterString, Reference.ToChapterString + ".txt")) 680 End If 681 Next 682 If BibleIndex IsNot Nothing Then 683 For Each Chapter As String In BibleIndex.FindChapters(txtSearch.Text) 684 lstItems.Items.Add(New ListItem(Of String)(IO.Path.GetFileNameWithoutExtension(Chapter), Chapter)) 685 Next 686 lblItemCount.Text = "Bible Chapters Found: (" + lstItems.Items.Count.ToString + ")" 687 Else 688 lblItemCount.Text = "Bible Translation Unavailable" 689 End If 690 691 End If 692 lstItems.EndUpdate() 693 694 ' Select the first item in the list 695 If lstItems.Items.Count > 0 Then lstItems.SelectedIndex = 0 696 UpdateControlVisibility() 697 698 End If 699 700 Catch ex As Exception 701 702 ' There was a problem conducting the search 703 Call (New frmException(ex, "There was a problem conducting the search.")).ShowDialog() 704 If MsgBox("The searching index is corrupt, but this can probably be fixed. Do you want to recreate the index?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then 705 Database.RecreateIndex() 706 MsgBox("The index has been recreated.", MsgBoxStyle.Information) 707 End If 708 709 End Try 710 711 End Sub 712 713 Private Sub HandleSelectionChanges(ByVal sender As System.Object, ByVal e As System.EventArgs) _ 714 Handles lstItems.SelectedIndexChanged, lstPlaylist.SelectedIndexChanged, lstVerses.SelectedIndexChanged 715 UpdateControlVisibility() 716 End Sub 717 718 Private Sub EditSongToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditSongToolStripMenuItem1.Click 719 720 Dim SelectedSongID As Guid = DirectCast(lstItems.SelectedItem, ListItem(Of Guid)).Key 721 Dim Song As SongItem = Database.Songs.GetSong(SelectedSongID) 722 723 ' Determine if a song is currently active 724 Dim SongActive As Boolean = False 725 If FActiveItem IsNot Nothing AndAlso TypeOf FActiveItem Is SongItem Then 726 SongActive = DirectCast(FActiveItem, SongItem).SongID = Song.SongID 727 End If 728 729 Dim Form As New frmSong(Database, Song) 730 If Form.ShowDialog = Windows.Forms.DialogResult.OK Then 731 732 ' Edit the song 733 Database.Songs.EditSong(SelectedSongID, Form.Song) 734 735 ' Update the song in the index 736 Database.SongIndex.UpdateIndex(Form.Song) 737 738 ' Update the song in the items list 739 lstItems.Items(lstItems.SelectedIndex) = New ListItem(Of Guid)(Form.Song.Title, Form.Song.SongID) 740 741 ' If the song is active, update it on the screen 742 If SongActive Then 743 UpdateActiveItem() 744 lstVerses.ActiveIndex = FActivePart 745 lstVerses_DoubleClick(sender, e) 746 End If 747 748 End If 749 750 End Sub 751 752 Private Sub optSongs_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optSongs.CheckedChanged 753 If optSongs.Checked Then 754 UpdateCategoryList() 755 txtSearch.Text = "" 756 UpdateControlVisibility() 757 End If 758 End Sub 759 760 Private Sub optBible_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optBible.CheckedChanged 761 If optBible.Checked Then 762 UpdateCategoryList() 763 txtSearch.Text = "" 764 UpdateControlVisibility() 765 End If 766 End Sub 767 768 Private Sub btnSetAnnouncement_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetAnnouncement.Click 769 770 Dim Form As New frmNotice(Database) 771 If Form.ShowDialog = Windows.Forms.DialogResult.OK Then 772 For Each Projector As Projector In FProjections 773 Projector.Notices.Add(Form.Notice) 774 Next 775 End If 776 777 End Sub 778 779 Private Sub ActivateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ActivateToolStripMenuItem.Click 780 lstItems_DoubleClick(sender, e) 781 lstPlaylist.SelectedIndex = lstPlaylist.ItemCount - 1 782 HandleDisplaySongRequest(sender, e) 783 lstVerses.SelectedIndex = 0 784 lstVerses_DoubleClick(sender, e) 785 End Sub 786 787 Private Sub ConfigurePlugInsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfigurePlugInsToolStripMenuItem.Click 788 Call New frmPlugIns(Database).ShowDialog() 789 End Sub 790 791 Private Sub AddTitleToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddTitleToolStripMenuItem.Click 792 793 Dim Form As New frmTitle 794 If Form.ShowDialog = Windows.Forms.DialogResult.OK Then 795 796 ' Determine the currently active style (Default if no style active) 797 Dim Style As Style = FActiveStyle 798 If FActiveStyle Is Nothing Then Style = Database.Styles.GetDefaultStyle 799 lstPlaylist.AddItem(New SongsListItem(Form.Title, Style)) 800 801 End If 802 803 End Sub 804 805 Private Sub MoveUpOrDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveUp.Click, btnMoveDown.Click 806 807 If sender Is btnMoveUp Then 808 lstPlaylist.MoveUp() 809 Else 810 lstPlaylist.MoveDown() 811 End If 812 UpdateControlVisibility() 813 814 End Sub 815 816 Private Sub ImportFromPresenterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImportFromPresenterToolStripMenuItem.Click 817 Dim Form As New frmImportPresenter(Database) 818 If Form.ShowDialog = Windows.Forms.DialogResult.OK Then 819 Database.RecreateIndex() 820 UpdateAll() 821 End If 822 End Sub 823 824 Private Sub DownloadAdditionalSongsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DownloadAdditionalSongsToolStripMenuItem.Click 825 If (New frmDownload(Database)).ShowDialog = Windows.Forms.DialogResult.OK Then 826 UpdateAll() 827 End If 828 End Sub 829 830 Private Sub FeedbackPortalToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FeedbackPortalToolStripMenuItem.Click 831 Call (New frmFeedbackPortal).ShowDialog() 832 End Sub 833 834 Private Sub HandleSelectScreenTarget(ByVal sender As Object, ByVal e As System.EventArgs) 835 836 If FProjectionForm.Visible Then 837 FProjectionForm.SetFullScreen(False) 838 Dim ScreenIndex As Integer = DirectCast(sender, ToolStripMenuItem).Tag 839 Dim Bounds As Rectangle = Screen.AllScreens(ScreenIndex).Bounds 840 FProjectionForm.Location = New Point(Bounds.Left, Bounds.Top) 841 FProjectionForm.SetFullScreen(True) 842 Me.Activate() 843 End If 844 845 End Sub 846 847 Private Sub LoadPlayListToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadPlayListToolStripMenuItem.Click, LoadListToolStripMenuItem.Click 848 849 If dlgOpenPlaylist.ShowDialog = Windows.Forms.DialogResult.OK Then 850 LoadPlayList(dlgOpenPlaylist.FileName) 851 End If 852 853 End Sub 854 855 Private Sub SavePlayListToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SavePlayListToolStripMenuItem.Click, SaveListToolStripMenuItem.Click 856 857 If dlgSavePlaylist.ShowDialog = Windows.Forms.DialogResult.OK Then 858 859 Try 860 861 ' Create the play list 862 Dim PlayList As New PlayList 863 For I As Integer = 0 To lstPlaylist.ItemCount - 1 864 Dim Item As SongsListItem = lstPlaylist.Items(I) 865 PlayList.Add(New PlayListItem(Item.Item, Item.Style, Item.OverrideBackground)) 866 Next 867 868 ' Save the play list 869 PlayList.Save(dlgSavePlaylist.FileName) 870 871 Catch ex As Exception 872 MsgBox("Could not save the play list:" + Environment.NewLine + ex.Message, MsgBoxStyle.Exclamation) 873 End Try 874 875 End If 876 877 End Sub 878 879 Private Sub pbPreview_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbPreview.Resize 880 pbPreview.Height = (pbPreview.Width / 4) * 3 881 End Sub 882 883 Private Sub pnlMiddle_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pnlMiddle.Resize 884 Dim Padding As Integer = pbPreview.Left 885 pbPreview.Width = pnlMiddle.Width - (Padding * 2) 886 End Sub 887 888 Private Sub ConfigureSongCategoriesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfigureSongCategoriesToolStripMenuItem.Click, ManageCategoriesToolStripMenuItem.Click 889 890 Dim Form As New frmManageCategories(Database) 891 If Form.ShowDialog = Windows.Forms.DialogResult.OK Then 892 UpdateCategoryList() 893 End If 894 895 End Sub 896 897 Private CheckingCategory As Boolean = False 898 899 Private Sub lstCategories_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles lstCategories.ItemCheck 900 901 ' This is a work around for a known "issue" with the control 902 If Not CheckingCategory Then 903 CheckingCategory = True 904 lstCategories.SetItemCheckState(e.Index, e.NewValue) 905 UpdateItemList() 906 CheckingCategory = False 907 End If 908 909 End Sub 910 911 Private FSongPreviewTip As ToolTip = Nothing 912 913 Private Sub HandleToolTipPreview() Handles lstItems.SelectedIndexChanged 914 915 If Database.Settings.ShowSongPreviews = False Then Exit Sub 916 917 ' Create tool tip if necessary 918 If FSongPreviewTip Is Nothing Then 919 FSongPreviewTip = New ToolTip 920 FSongPreviewTip.ToolTipIcon = ToolTipIcon.None 921 FSongPreviewTip.Active = True 922 FSongPreviewTip.UseAnimation = False 923 FSongPreviewTip.UseFading = False 924 End If 925 926 ' Determine which song is selected 927 If lstItems.SelectedIndex <> -1 Then 928 If TypeOf lstItems.Items(lstItems.SelectedIndex) Is ListItem(Of Guid) Then 929 930 Dim Item As ListItem(Of Guid) = lstItems.Items(lstItems.SelectedIndex) 931 932 Dim Song As SongItem = Nothing 933 Try 934 Song = Database.Songs.GetSong(Item.Key) 935 Catch ex As Exception 936 Song = New SongItem(Item.ToString, "This song has been deleted.") 937 End Try 938 939 ' Show new song preview tool tip 940 FSongPreviewTip.ToolTipTitle = Song.Title 941 FSongPreviewTip.RemoveAll() 942 Dim SongText As String = Song.CombineIntoString 943 If SongText.Length > 400 Then SongText = SongText.Substring(0, 400) + "..." 944 Dim Point As New Point(lstItems.Bounds.Right, lstItems.GetItemRectangle(lstItems.SelectedIndex).Y) 945 FSongPreviewTip.Show(SongText, lstItems, Point.X + 3, Point.Y + 3, 6000) 946 947 End If 948 949 End If 950 951 End Sub 952 953 Private Sub lstItems_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstItems.Leave 954 If FSongPreviewTip IsNot Nothing Then 955 FSongPreviewTip.Dispose() 956 FSongPreviewTip = Nothing 957 End If 958 End Sub 959 960 Private Sub ClearPlayListToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearPlayListToolStripMenuItem.Click 961 962 If lstPlaylist.ItemCount > 0 Then 963 If MsgBox("Are you sure you wish to remove all of the items in the play list?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then 964 lstPlaylist.Clear() 965 End If 966 End If 967 968 End Sub 969 970 Private Sub ReportingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReportingToolStripMenuItem.Click 971 Call New frmReporting().ShowDialog() 972 End Sub 973 974 Private Sub CreateShortcutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateShortcutToolStripMenuItem.Click 975 976 ' Determine a file name for the link 977 dlgSaveShortcut.FileName = My.Computer.FileSystem.SpecialDirectories.Desktop + "\" + _ 978 IO.Path.GetFileName(Database.Location) + ".psdb" 979 980 ' Ask to save the link 981 If dlgSaveShortcut.ShowDialog = Windows.Forms.DialogResult.OK Then 982 Try 983 IO.File.WriteAllText(dlgSaveShortcut.FileName, Database.Location) 984 Catch ex As Exception 985 MsgBox("A shortcut could not be created:" + Environment.NewLine + ex.Message, MsgBoxStyle.Exclamation) 986 End Try 987 End If 988 989 End Sub 990 991 Private Sub HandleMainMenuOpen(ByVal sender As System.Object, ByVal e As System.EventArgs) _ 992 Handles FileToolStripMenuItem.DropDownOpened, PlayListToolStripMenuItem.DropDownOpened, _ 993 ToolsToolStripMenuItem.DropDownOpened, HelpToolStripMenuItem.DropDownOpened, _ 994 ProjectionToolStripMenuItem.DropDownOpened, mnuCategories.Opened, _ 995 mnuItems.Opened, mnuPlaylist.Opened, mnuProjection.Opened, mnuVerses.Opened 996 997 ' Get items to iterate through 998 Dim AllItems As ToolStripItemCollection = Nothing 999 If TypeOf sender Is ContextMenuStrip Then 1000 AllItems = DirectCast(sender, ContextMenuStrip).Items 1001 Else 1002 AllItems = DirectCast(sender, ToolStripMenuItem).DropDownItems 1003 End If 1004 1005 ' Make all separators visible to begin with 1006 Dim VisibleItems As New List(Of ToolStripItem) 1007 For Each Item As ToolStripItem In AllItems 1008 If TypeOf Item Is ToolStripSeparator Then Item.Visible = True 1009 If Item.Visible Then VisibleItems.Add(Item) 1010 Next 1011 1012 ' Hide unnecessary separators 1013 Dim PrevItem As ToolStripItem = Nothing 1014 For I As Integer = 0 To VisibleItems.Count - 1 1015 Dim ThisItem As ToolStripItem = VisibleItems(I) 1016 Dim PrevSeparator As Boolean = TypeOf PrevItem Is ToolStripSeparator 1017 Dim ThisSeparator As Boolean = TypeOf ThisItem Is ToolStripSeparator 1018 Dim IsDuplicate As Boolean = PrevItem IsNot Nothing AndAlso ThisItem.Visible AndAlso PrevSeparator AndAlso ThisSeparator 1019 Dim IsFirst As Boolean = I = 0 AndAlso ThisSeparator 1020 Dim IsLast As Boolean = I = VisibleItems.Count - 1 AndAlso ThisSeparator 1021 If IsDuplicate OrElse IsFirst OrElse IsLast Then ThisItem.Visible = False 1022 PrevItem = ThisItem 1023 Next 1024 1025 End Sub 1026 1027End Class