/Source Code/PowerSong/frmMain.vb
Visual Basic | 1027 lines | 700 code | 253 blank | 74 comment | 1 complexity | 2259521af4e19b5cdc27972036adee9f MD5 | raw file
- Imports PowerSong.SongDatabase
- Imports PowerSong.SongDatabase.Bibles
- Imports PowerSong.SongDatabase.Items
- Imports PowerSong.Projection
- Imports PowerSong.SongDatabase.Logging
-
- Public Class frmMain
-
- Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
- Application.Exit()
- End Sub
-
- Private Sub btnAddSong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddSong.Click, NewSongToolStripMenuItem.Click
-
- Dim Form As New frmSong(Database)
- If Form.ShowDialog = Windows.Forms.DialogResult.OK Then
-
- ' Add the song to the database, its index, and the list
- Database.Songs.AddSong(Form.Song)
- Database.SongIndex.AddToIndex(Form.Song)
- lstItems.Items.Add(New ListItem(Of Guid)(Form.Song.Title, Form.Song.SongID))
- UpdateItemCountLabel()
- UpdateCategoryList()
-
- End If
-
- End Sub
-
- Private Sub CreateDatabaseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateDatabaseToolStripMenuItem.Click
-
- Dim Form As New frmCreateDatabase
- If Form.ShowDialog = Windows.Forms.DialogResult.OK Then
- CloseDatabase()
- Database = Form.Database
- DatabaseLocation = Form.DatabaseLocation
- FActiveStyle = Database.Styles.GetDefaultStyle
- UpdateAll()
- End If
-
- End Sub
-
- Private Sub LoadDatabaseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadDatabaseToolStripMenuItem.Click
-
- If dlgSelectDatabaseFolder.ShowDialog = Windows.Forms.DialogResult.OK Then
-
- Try
-
- ' Unload plugins
- Plugins.Instance.UnloadAllPlugins()
-
- ' Load the database
- Dim InterimDatabase As Database = Database.Load(dlgSelectDatabaseFolder.SelectedPath)
-
- ' Set the active database to the new one
- CloseDatabase()
- DatabaseLocation = dlgSelectDatabaseFolder.SelectedPath
- Database = InterimDatabase
- FActiveStyle = Database.Styles.GetDefaultStyle
- UpdateAll()
-
- Catch ex As Exception
- MsgBox("Could not load the database:" + Environment.NewLine + ex.Message, MsgBoxStyle.Critical)
- UpdateAll()
- End Try
-
- ' Load plugins
- Try
- Plugins.Instance.LoadAllPlugins(Database)
- Catch ex As Exception
- MsgBox("Problem loading plugins:" + Environment.NewLine + ex.Message, MsgBoxStyle.Exclamation)
- End Try
-
- End If
-
- End Sub
-
- Private Sub lstItems_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstItems.DoubleClick, btnAddToPlaylist.Click, AddToPlaylistToolStripMenuItem.Click
-
- ' Determine the currently active style (Default if no style active)
- Dim Style As Style = FActiveStyle
- If FActiveStyle Is Nothing Then Style = Database.Styles.GetDefaultStyle
-
- If lstItems.SelectedItem IsNot Nothing Then
-
- Try
-
- If optSongs.Checked Then
-
- ' Add the song
- Dim SelectedItem As ListItem(Of Guid) = lstItems.SelectedItem
- Dim SelectedSong As SongItem = Database.Songs.GetSong(SelectedItem.Key)
- lstPlaylist.AddItem(New SongsListItem(SelectedSong, Style))
-
- Else
-
- ' Add the bible chapter
- Dim SelectedItem As ListItem(Of String) = lstItems.SelectedItem
- Dim SelectedChapter As New AdhocItem
- SelectedChapter.CopyrightLine = BibleIndex.Translation
- SelectedChapter.Title = SelectedItem.ToString
- For Each Verse As String In BibleIndex.FindChapter(SelectedItem.Key).Split(Environment.NewLine)
- SelectedChapter.Parts.Add(Verse.Trim)
- Next
- lstPlaylist.AddItem(New SongsListItem(SelectedChapter, Style))
-
- End If
-
- Catch ex As Exception
- MsgBox(ex.Message, MsgBoxStyle.Critical)
- End Try
-
- End If
-
- End Sub
-
- Private Sub btnDeleteSong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteSong.Click, DeleteSongToolStripMenuItem.Click
-
- If lstItems.SelectedItem IsNot Nothing Then
-
- ' Get details for the selected item
- Dim SelectedItem As ListItem(Of Guid) = lstItems.SelectedItem
- Dim SongID As Guid = SelectedItem.Key
- Dim SongTitle As String = SelectedItem.ToString
-
- ' Confirm user wishes to delete the item
- If MsgBox("Are you sure you wish to delete the song '" + SongTitle + "'?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
-
- ' Delete the item
- Database.SongIndex.RemoveFromIndex(SongID)
- Database.Songs.DeleteSong(SongID)
- lstItems.Items.RemoveAt(lstItems.SelectedIndex)
- UpdateItemCountLabel()
-
- End If
-
- End If
-
- End Sub
-
- Private Sub tmrMain_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMain.Tick
- For Each Projection As Projector In FProjections
- Projection.Update()
- Next
- End Sub
-
- Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
-
- Try
-
- ' Save the index
- If Database IsNot Nothing Then Database.SongIndex.Save()
-
- ' Close the database
- CloseDatabase()
-
- ' Disconnect and destroy all projectors
- FProjections.Clear()
-
- Catch ex As Exception
- MsgBox("An error occured while PowerSong was being closed:" + Environment.NewLine + _
- ex.Message + Environment.NewLine + Environment.NewLine + _
- "PowerSong will now terminate.", MsgBoxStyle.Critical)
- End Try
-
- End Sub
-
- Private Sub frmMain_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
-
- Select Case e.KeyCode
-
- Case Keys.Return
- If txtSearch.Focused Then
- lstItems_DoubleClick(sender, e)
- Else
- ChangeActivePart(lstVerses.SelectedIndex)
- End If
-
- End Select
-
- End Sub
-
- Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
- GlobalContext.MainForm = Me
- PowerSongApi.Initialise(Me)
-
- ' Check if a command line was present
- Dim ExternalFileName As String = ""
- If My.Application.CommandLineArgs.Count > 0 Then
- ExternalFileName = My.Application.CommandLineArgs(0)
- End If
-
- ' Determine which database to open
- DatabaseLocation = ""
- Database = Nothing
- Dim ShortcutCreateRequested As Boolean = False
- If ExternalFileName <> "" AndAlso IO.Path.GetExtension(ExternalFileName).ToUpper = ".PSDB" Then
-
- ' Load database via link
- Try
- DatabaseLocation = IO.File.ReadAllText(ExternalFileName)
- Database = Database.Load(DatabaseLocation)
- Catch ex As Exception
- MsgBox(ex.Message, MsgBoxStyle.Critical)
- DatabaseLocation = ""
- Database = Nothing
- End Try
-
- Else
-
- ' Load database via startup form
- Dim StartupForm As New frmStartup
- If StartupForm.ShowDialog = Windows.Forms.DialogResult.OK Then
- DatabaseLocation = StartupForm.DatabaseLocation
- Database = StartupForm.Database
- ShortcutCreateRequested = StartupForm.CreateShortcut
- End If
-
- End If
-
- ' Set up everything if a database was loaded
- If Database IsNot Nothing Then
-
- ' Set an active style
- FActiveStyle = Database.Styles.GetDefaultStyle
-
- ' Load the bible
- GlobalContext.LoadBible(Database.Settings.ActiveBible)
-
- ' Add available screens to the main menu
- Dim ScreenIndex As Integer = 0
- For Each Screen As Screen In Screen.AllScreens
- Dim NextMenuItem1 As New ToolStripMenuItem("Screen " + (ScreenIndex + 1).ToString)
- Dim NextMenuItem2 As New ToolStripMenuItem("Screen " + (ScreenIndex + 1).ToString)
- NextMenuItem1.Tag = ScreenIndex
- NextMenuItem2.Tag = ScreenIndex
- NextMenuItem1.ShortcutKeys = Keys.Control + Keys.D1 + ScreenIndex
- AddHandler NextMenuItem1.Click, AddressOf HandleSelectScreenTarget
- AddHandler NextMenuItem2.Click, AddressOf HandleSelectScreenTarget
- ProjectionTargetToolStripMenuItem.DropDownItems.Add(NextMenuItem1)
- ProjectionTargetToolStripMenuItem1.DropDownItems.Add(NextMenuItem2)
- ScreenIndex += 1
- Next
-
- ' Set up the projection form
- FProjectionForm = New frmMainProjection
- Dim LastScreenBounds As Rectangle = Screen.AllScreens(Screen.AllScreens.Length - 1).Bounds
- FProjectionForm.Location = New Point(LastScreenBounds.Left, LastScreenBounds.Top)
-
- ' Set up projections
- FPreviewProjector = CreateProjector(pbPreview)
- FPreviewProjector.Projecting = False
- Dim MainProjector As Projector = CreateProjector(FProjectionForm)
- MainProjector.Projecting = False
- FProjections.Add(FPreviewProjector)
- FProjections.Add(MainProjector)
- FProjectionForm.Projector = MainProjector
- AddHandler MainProjector.ModeChanged, AddressOf HandleCompletedModeChange
-
- ' Set initial state of the projectors
- btnGoToBlack_Click(sender, e)
- FPreviewProjector.FadeToText(0)
- If Database.Settings.ShowMainProjection Then ToggleProjector(FProjectionForm)
- If Database.Settings.ShowPreviewProjection Then ToggleProjector(pbPreview)
-
- ' Display contents of all controls
- UpdateAll()
-
- ' Select all categories initially
- For ItemIndex As Integer = 0 To lstCategories.Items.Count - 1
- lstCategories.SetItemChecked(ItemIndex, True)
- Next
-
- ' Create a shortcut if requested
- If ShortcutCreateRequested Then CreateShortcutToolStripMenuItem_Click(sender, e)
-
- ' Load external file if one was specified
- If ExternalFileName <> "" AndAlso IO.Path.GetExtension(ExternalFileName).ToUpper <> ".PSDB" Then
- LoadExternalFile(ExternalFileName)
- End If
-
- Else
- Application.Exit()
- End If
-
- ' Enable/disable functionality as specified in the configuration file
- Functionality.ConfigureForm(Me)
-
- End Sub
-
- Private Function CreateProjector(ByVal target As Control) As Projector
-
- Dim Result As New Projector(target)
- Result.Projectlets.Add(New Projectlet("Title", ProjectletStyle.TITLE_TAG))
- Result.Projectlets.Add(New Projectlet("Verse", ProjectletStyle.VERSE_TAG))
- Result.Projectlets.Add(New Projectlet("Copyright", ProjectletStyle.SIMPLE_COPYRIGHT_TAG))
- AddHandler Result.ProjectionComplete, AddressOf PerformPluginProjection
- Return Result
-
- End Function
-
- Private Sub PerformPluginProjection(ByVal graphics As Graphics, _
- ByVal projectionWidth As Integer, _
- ByVal projectionHeight As Integer)
-
- For Each Plugin As PluginSupport.IPlugin In Plugins.Instance.Items.Values
- Try
- Plugin.Project(graphics, projectionWidth, projectionHeight)
- Catch ex As Exception
- Plugin.Stop()
- MsgBox("A plugin has crashed with the following message:" + Environment.NewLine + _
- ex.Message + Environment.NewLine + Environment.NewLine + _
- "The plugin will be stopped.", MsgBoxStyle.Exclamation)
- End Try
- Next
-
- End Sub
-
- Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
-
- If FActiveItem Is Nothing Then
- MsgBox("Please select an item first.", MsgBoxStyle.Information)
- Exit Sub
- End If
-
- Dim NextActivePart As Integer = FActivePart + 1
- If NextActivePart >= lstVerses.Items.Count Then NextActivePart = 0
- ChangeActivePart(NextActivePart)
-
- End Sub
-
- Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
-
- If FActiveItem Is Nothing Then
- MsgBox("Please select an item first.", MsgBoxStyle.Information)
- Exit Sub
- End If
-
- ChangeActivePart(Math.Max(FActivePart - 1, 0))
-
- End Sub
-
- Private Sub btnSetImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetImage.Click, ChangeBacToolStripMenuItem.Click
-
- ' Show the set background form
- Dim SelectedItem As SongsListItem = lstPlaylist.SelectedItem
- Dim Form As New frmSetBackground(SelectedItem.OverrideBackground)
- If Form.ShowDialog = Windows.Forms.DialogResult.OK Then
-
- ' Override the item's background defined in its style
- SelectedItem.OverrideBackground = Form.Background
-
- ' Update projectors if the song is active
- If SelectedItem.Item Is FActiveItem Then
- If SelectedItem.OverrideBackground IsNot Nothing Then
- OverrideProjectorBackground(SelectedItem.OverrideBackground)
- End If
- End If
-
- End If
-
- End Sub
-
- Private Sub TogglePreviewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TogglePreviewToolStripMenuItem.Click
- ToggleProjector(pbPreview)
- End Sub
-
- Private Sub ToggleFullScreenViewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToggleFullScreenViewToolStripMenuItem.Click
- ToggleProjector(FProjectionForm)
- UpdateControlVisibility()
- Me.Activate()
- End Sub
-
- Private Sub ExportDatabaseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExportDatabaseToolStripMenuItem.Click
- Call (New frmExportDatabase(Database)).ShowDialog()
- End Sub
-
- Private Sub ImportDatabaseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImportDatabaseToolStripMenuItem.Click
- Dim Form As New frmImportDatabase(Database)
- If Form.ShowDialog = Windows.Forms.DialogResult.OK Then
- UpdateAll()
- End If
- End Sub
-
- Private Sub HandleDisplaySongRequest(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstPlaylist.DoubleClick, btnDisplaySong.Click, DisplayItemNowToolStripMenuItem.Click
-
- If lstPlaylist.SelectedIndex = -1 Then Exit Sub
-
- ' Log that the old song is no longer visible
- If FActiveItem IsNot Nothing AndAlso TypeOf FActiveItem Is SongItem Then
- Database.Logging.Add(LogEntry.ItemType.Song, DirectCast(FActiveItem, SongItem).SongID, Now, LogEntry.Action.Hidden)
- End If
-
- ' Change the active song, selecting the first part of it
- Dim SelectedItem As SongsListItem = lstPlaylist.Items(lstPlaylist.SelectedIndex)
- FActiveItem = SelectedItem.Item
- FActiveStyle = SelectedItem.Style
- UpdateActiveItem()
- lstPlaylist.ActiveItem = SelectedItem
- FActivePart = 0
- Dim NextSelectedIndex As Integer = 0
- If lstVerses.Items.Count = 0 Then NextSelectedIndex = -1
- If NextSelectedIndex < lstVerses.Items.Count - 1 Then NextSelectedIndex += 1
- lstVerses.SelectedIndex = NextSelectedIndex
- lstVerses.ActiveIndex = 0
-
- ' Update all projectors generally
- UpdateProjectorStyle()
- For Each Projection As Projector In FProjections
- Dim CurrentPart As String = ""
- If FActiveItem.Parts.Count > 0 Then CurrentPart = FActiveItem.Parts(0)
-
- ' Update the projectlets
- For Each ProjectletName As String In New String() {"Title", "Copyright", "Verse"}
- Dim Projectlet As Projectlet = Projection.ProjectletByName(ProjectletName)
- Dim Text As String = Projectlet.PopulateTags(FActiveItem, FActivePart)
- Projection.SetText(Projectlet, 0, FActiveItem.Parts.Count, Text, ProjectletName <> "Verse")
- Next
-
- Next
- If SelectedItem.OverrideBackground IsNot Nothing Then OverrideProjectorBackground(SelectedItem.OverrideBackground)
-
- ' Log the displaying of the new song
- If TypeOf FActiveItem Is SongItem Then
- Database.Logging.Add(LogEntry.ItemType.Song, DirectCast(FActiveItem, SongItem).SongID, Now, LogEntry.Action.Shown)
- End If
-
- End Sub
-
- Private Sub OverrideProjectorBackground(ByVal background As OverrideBackground)
-
- For Each Projection As Projector In FProjections
- Select Case background.Type
- Case Style.EBackgroundType.SolidColour
- Projection.SetBackgroundColour(background.Value)
- Case Style.EBackgroundType.Image
- Projection.SetBackgroundImage(background.Value)
- End Select
- Next
-
- End Sub
-
- Private Sub btnConfigureSong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfigureSong.Click, ConfigurePlaylistItemToolStripMenuItem.Click
-
- Dim SelectedItem As SongsListItem = lstPlaylist.Items(lstPlaylist.SelectedIndex)
- Dim Form As New frmConfigureItem(SelectedItem.Item, SelectedItem.Style, Database.Styles)
- If (Form.ShowDialog = Windows.Forms.DialogResult.OK) Then
- SelectedItem.Style = Form.SelectedStyle
- SelectedItem.OverrideBackground = Nothing
- If FActiveItem Is SelectedItem.Item Then
- FActiveStyle = SelectedItem.Style
- UpdateProjectorStyle()
- End If
- End If
-
- End Sub
-
- Private Sub AboutPowerSongToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutPowerSongToolStripMenuItem.Click
- Call (New frmAbout).ShowDialog()
- End Sub
-
- Private Sub ConfigureStylesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfigureStylesToolStripMenuItem.Click
-
- ' Determine the name of the currently active style
- Dim OldActiveStyle As String = ""
- If FActiveStyle IsNot Nothing Then OldActiveStyle = FActiveStyle.Name
-
- If New frmConfigureStyles(Database.Styles).ShowDialog = Windows.Forms.DialogResult.OK Then
- If Database.Styles.GetAllStyleNames.Contains(OldActiveStyle) Then
- FActiveStyle = Database.Styles.GetStyle(OldActiveStyle)
- UpdateProjectorStyle()
-
- ' Reflect changes in the playlist
- For I As Integer = 0 To lstPlaylist.ItemCount - 1
- Dim Item As SongsListItem = lstPlaylist.Items(I)
- If Item.Style.Name = OldActiveStyle Then
- Item.Style = FActiveStyle
- Item.RefreshIcon()
- End If
- Next
-
- End If
- End If
-
- End Sub
-
- Private Sub btnRemoveFromPlaylist_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveFromPlaylist.Click, RemoveToolStripMenuItem.Click
-
- ' Ensure that something is selected
- If lstPlaylist.SelectedItem Is Nothing Then
- MsgBox("Please select something to remove first.", MsgBoxStyle.Information)
- Exit Sub
- End If
-
- Dim SelectedItem As SongsListItem = lstPlaylist.Items(lstPlaylist.SelectedIndex)
- If FActiveItem IsNot Nothing AndAlso SelectedItem.Item Is FActiveItem Then
- FActiveItem = Nothing
- FActivePart = -1
- UpdateActiveItem()
- End If
- lstPlaylist.RemoveItem(SelectedItem)
-
- End Sub
-
- Private Sub lstVerses_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstVerses.DoubleClick
- If lstVerses.SelectedItem IsNot Nothing Then
- ChangeActivePart(lstVerses.SelectedIndex)
- End If
- End Sub
-
- Private Sub btnGoToFull_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoToFull.Click, GoToFullDisplayToolStripMenuItem.Click
-
- btnGoToFull.ForeColor = Color.Red
- For Each Projector As Projector In FProjections
- If Projector.Target IsNot pbPreview Then Projector.FadeToText(FActiveStyle.GeneralFadeDuration)
- Next
-
- End Sub
-
- Private Sub btnGoToBackground_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoToBackground.Click, GoToBackgroundOnlyToolStripMenuItem.Click
-
- btnGoToBackground.ForeColor = Color.Red
- For Each Projector As Projector In FProjections
- If Projector.Target IsNot pbPreview Then Projector.FadeToBackground(FActiveStyle.GeneralFadeDuration)
- Next
-
- End Sub
-
- Private Sub btnGoToBlack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGoToBlack.Click, GoToBlackToolStripMenuItem.Click
-
- btnGoToBlack.ForeColor = Color.Red
- For Each Projector As Projector In FProjections
- If Projector.Target IsNot pbPreview Then Projector.FadeToBlack(FActiveStyle.GeneralFadeDuration)
- Next
-
- End Sub
-
- Private Sub btnEditSong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEditSong.Click, EditSongToolStripMenuItem.Click
-
- ' Check we can edit the item
- If TypeOf FActiveItem Is SongItem Then
-
- ' Show the user the edit song dialog
- Dim Form As New frmSong(Database, FActiveItem)
- If Form.ShowDialog = Windows.Forms.DialogResult.OK Then
-
- ' Save changes to the song
- Database.Songs.EditSong(Form.Song.SongID, Form.Song)
-
- ' Update the song in the index
- Database.SongIndex.UpdateIndex(Form.Song)
-
- ' Update categories list
- UpdateCategoryList()
-
- ' Update the screen
- If FActivePart >= Form.Song.Parts.Count Then FActivePart = Form.Song.Parts.Count - 1
- UpdateAll()
- lstVerses.ActiveIndex = FActivePart
- lstVerses_DoubleClick(sender, e)
-
- End If
-
- ElseIf TypeOf FActiveItem Is AdhocItem Then
-
- ' Show the user the edit title dialog
- Dim Form As New frmTitle(FActiveItem)
- If Form.ShowDialog = Windows.Forms.DialogResult.OK Then
-
- ' Update the screen
- If FActivePart >= Form.Title.Parts.Count Then FActivePart = Form.Title.Parts.Count - 1
- UpdateAll()
- lstVerses.ActiveIndex = FActivePart
- lstVerses_DoubleClick(sender, e)
-
- End If
-
- Else
- MsgBox("You cannot edit that item.", MsgBoxStyle.Exclamation)
- End If
-
- End Sub
-
- Private Sub EditVerseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditVerseToolStripMenuItem.Click
-
- ' Check that a verse has been selected
- If lstVerses.SelectedIndex = -1 Then
- MsgBox("Please select a verse to edit first.", MsgBoxStyle.Exclamation)
- Exit Sub
- End If
-
- ' Show the form
- Dim Form As New frmVerse(FActiveItem, lstVerses.SelectedIndex)
- If Form.ShowDialog = Windows.Forms.DialogResult.OK Then
-
- ' Update the song
- If TypeOf Form.Item Is SongItem Then
- Database.Songs.EditSong(DirectCast(Form.Item, SongItem).SongID, Form.Item)
- Database.SongIndex.UpdateIndex(Form.Item)
- End If
-
- ' Update the song if it is active
- If FActivePart = lstVerses.SelectedIndex Then ChangeActivePart(FActivePart)
- UpdateActiveItem()
- lstVerses.ActiveIndex = FActivePart
-
- End If
-
- End Sub
-
- Private Sub AddVerseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddVerseToolStripMenuItem.Click
-
- ' Show the form
- Dim Form As New frmVerse(FActiveItem)
- If Form.ShowDialog = Windows.Forms.DialogResult.OK Then
-
- ' Update the song
- If TypeOf Form.Item Is SongItem Then
- Database.Songs.EditSong(DirectCast(Form.Item, SongItem).SongID, Form.Item)
- Database.SongIndex.UpdateIndex(Form.Item)
- End If
-
- ' Update the song if it is active
- UpdateActiveItem()
- lstVerses.ActiveIndex = FActivePart
-
- End If
-
- End Sub
-
- Private Sub ConfigurePowerSongToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfigurePowerSongToolStripMenuItem.Click
-
- If (New frmConfiguration(Database)).ShowDialog = Windows.Forms.DialogResult.OK Then
- Functionality.ConfigureForm(Me)
- End If
-
- End Sub
-
- Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged
-
- If Database Is Nothing Then Exit Sub
-
- Try
-
- If txtSearch.Text = "" Then
- UpdateItemList()
- Else
-
- lstItems.Items.Clear()
- lstItems.Sorted = False
- lstItems.BeginUpdate()
-
- If optSongs.Checked Then
-
- ' Search songs
- Dim FoundSongs As List(Of Guid) = Database.SongIndex.FindSongs(txtSearch.Text)
- For Each SongID As Guid In FoundSongs
-
- ' Only add a song if its category is visible
- Dim SongAdded As Boolean = False
- For Each SelectedCategory As ListItem(Of Guid) In lstCategories.CheckedItems
- If Database.Songs.GetSongCategories(SongID).Contains(SelectedCategory.Key) Then
- If Not SongAdded Then
- lstItems.Items.Add(New ListItem(Of Guid)(Database.Songs.GetSongTitle(SongID), SongID))
- SongAdded = True
- End If
- End If
- Next
-
- Next
- lblItemCount.Text = "Songs Found: (" + lstItems.Items.Count.ToString + ")"
-
- Else
-
- ' Search bible
- Dim References As List(Of BibleReference) = BibleSupport.DetermineReferences(txtSearch.Text)
- For Each Reference As BibleReference In References
- If Reference.Chapter <> -1 Then
- lstItems.Items.Add(New ListItem(Of String)(Reference.ToChapterString, Reference.ToChapterString + ".txt"))
- End If
- Next
- If BibleIndex IsNot Nothing Then
- For Each Chapter As String In BibleIndex.FindChapters(txtSearch.Text)
- lstItems.Items.Add(New ListItem(Of String)(IO.Path.GetFileNameWithoutExtension(Chapter), Chapter))
- Next
- lblItemCount.Text = "Bible Chapters Found: (" + lstItems.Items.Count.ToString + ")"
- Else
- lblItemCount.Text = "Bible Translation Unavailable"
- End If
-
- End If
- lstItems.EndUpdate()
-
- ' Select the first item in the list
- If lstItems.Items.Count > 0 Then lstItems.SelectedIndex = 0
- UpdateControlVisibility()
-
- End If
-
- Catch ex As Exception
-
- ' There was a problem conducting the search
- Call (New frmException(ex, "There was a problem conducting the search.")).ShowDialog()
- 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
- Database.RecreateIndex()
- MsgBox("The index has been recreated.", MsgBoxStyle.Information)
- End If
-
- End Try
-
- End Sub
-
- Private Sub HandleSelectionChanges(ByVal sender As System.Object, ByVal e As System.EventArgs) _
- Handles lstItems.SelectedIndexChanged, lstPlaylist.SelectedIndexChanged, lstVerses.SelectedIndexChanged
- UpdateControlVisibility()
- End Sub
-
- Private Sub EditSongToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EditSongToolStripMenuItem1.Click
-
- Dim SelectedSongID As Guid = DirectCast(lstItems.SelectedItem, ListItem(Of Guid)).Key
- Dim Song As SongItem = Database.Songs.GetSong(SelectedSongID)
-
- ' Determine if a song is currently active
- Dim SongActive As Boolean = False
- If FActiveItem IsNot Nothing AndAlso TypeOf FActiveItem Is SongItem Then
- SongActive = DirectCast(FActiveItem, SongItem).SongID = Song.SongID
- End If
-
- Dim Form As New frmSong(Database, Song)
- If Form.ShowDialog = Windows.Forms.DialogResult.OK Then
-
- ' Edit the song
- Database.Songs.EditSong(SelectedSongID, Form.Song)
-
- ' Update the song in the index
- Database.SongIndex.UpdateIndex(Form.Song)
-
- ' Update the song in the items list
- lstItems.Items(lstItems.SelectedIndex) = New ListItem(Of Guid)(Form.Song.Title, Form.Song.SongID)
-
- ' If the song is active, update it on the screen
- If SongActive Then
- UpdateActiveItem()
- lstVerses.ActiveIndex = FActivePart
- lstVerses_DoubleClick(sender, e)
- End If
-
- End If
-
- End Sub
-
- Private Sub optSongs_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optSongs.CheckedChanged
- If optSongs.Checked Then
- UpdateCategoryList()
- txtSearch.Text = ""
- UpdateControlVisibility()
- End If
- End Sub
-
- Private Sub optBible_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optBible.CheckedChanged
- If optBible.Checked Then
- UpdateCategoryList()
- txtSearch.Text = ""
- UpdateControlVisibility()
- End If
- End Sub
-
- Private Sub btnSetAnnouncement_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetAnnouncement.Click
-
- Dim Form As New frmNotice(Database)
- If Form.ShowDialog = Windows.Forms.DialogResult.OK Then
- For Each Projector As Projector In FProjections
- Projector.Notices.Add(Form.Notice)
- Next
- End If
-
- End Sub
-
- Private Sub ActivateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ActivateToolStripMenuItem.Click
- lstItems_DoubleClick(sender, e)
- lstPlaylist.SelectedIndex = lstPlaylist.ItemCount - 1
- HandleDisplaySongRequest(sender, e)
- lstVerses.SelectedIndex = 0
- lstVerses_DoubleClick(sender, e)
- End Sub
-
- Private Sub ConfigurePlugInsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfigurePlugInsToolStripMenuItem.Click
- Call New frmPlugIns(Database).ShowDialog()
- End Sub
-
- Private Sub AddTitleToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddTitleToolStripMenuItem.Click
-
- Dim Form As New frmTitle
- If Form.ShowDialog = Windows.Forms.DialogResult.OK Then
-
- ' Determine the currently active style (Default if no style active)
- Dim Style As Style = FActiveStyle
- If FActiveStyle Is Nothing Then Style = Database.Styles.GetDefaultStyle
- lstPlaylist.AddItem(New SongsListItem(Form.Title, Style))
-
- End If
-
- End Sub
-
- Private Sub MoveUpOrDown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMoveUp.Click, btnMoveDown.Click
-
- If sender Is btnMoveUp Then
- lstPlaylist.MoveUp()
- Else
- lstPlaylist.MoveDown()
- End If
- UpdateControlVisibility()
-
- End Sub
-
- Private Sub ImportFromPresenterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ImportFromPresenterToolStripMenuItem.Click
- Dim Form As New frmImportPresenter(Database)
- If Form.ShowDialog = Windows.Forms.DialogResult.OK Then
- Database.RecreateIndex()
- UpdateAll()
- End If
- End Sub
-
- Private Sub DownloadAdditionalSongsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DownloadAdditionalSongsToolStripMenuItem.Click
- If (New frmDownload(Database)).ShowDialog = Windows.Forms.DialogResult.OK Then
- UpdateAll()
- End If
- End Sub
-
- Private Sub FeedbackPortalToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FeedbackPortalToolStripMenuItem.Click
- Call (New frmFeedbackPortal).ShowDialog()
- End Sub
-
- Private Sub HandleSelectScreenTarget(ByVal sender As Object, ByVal e As System.EventArgs)
-
- If FProjectionForm.Visible Then
- FProjectionForm.SetFullScreen(False)
- Dim ScreenIndex As Integer = DirectCast(sender, ToolStripMenuItem).Tag
- Dim Bounds As Rectangle = Screen.AllScreens(ScreenIndex).Bounds
- FProjectionForm.Location = New Point(Bounds.Left, Bounds.Top)
- FProjectionForm.SetFullScreen(True)
- Me.Activate()
- End If
-
- End Sub
-
- Private Sub LoadPlayListToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadPlayListToolStripMenuItem.Click, LoadListToolStripMenuItem.Click
-
- If dlgOpenPlaylist.ShowDialog = Windows.Forms.DialogResult.OK Then
- LoadPlayList(dlgOpenPlaylist.FileName)
- End If
-
- End Sub
-
- Private Sub SavePlayListToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SavePlayListToolStripMenuItem.Click, SaveListToolStripMenuItem.Click
-
- If dlgSavePlaylist.ShowDialog = Windows.Forms.DialogResult.OK Then
-
- Try
-
- ' Create the play list
- Dim PlayList As New PlayList
- For I As Integer = 0 To lstPlaylist.ItemCount - 1
- Dim Item As SongsListItem = lstPlaylist.Items(I)
- PlayList.Add(New PlayListItem(Item.Item, Item.Style, Item.OverrideBackground))
- Next
-
- ' Save the play list
- PlayList.Save(dlgSavePlaylist.FileName)
-
- Catch ex As Exception
- MsgBox("Could not save the play list:" + Environment.NewLine + ex.Message, MsgBoxStyle.Exclamation)
- End Try
-
- End If
-
- End Sub
-
- Private Sub pbPreview_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbPreview.Resize
- pbPreview.Height = (pbPreview.Width / 4) * 3
- End Sub
-
- Private Sub pnlMiddle_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pnlMiddle.Resize
- Dim Padding As Integer = pbPreview.Left
- pbPreview.Width = pnlMiddle.Width - (Padding * 2)
- End Sub
-
- Private Sub ConfigureSongCategoriesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConfigureSongCategoriesToolStripMenuItem.Click, ManageCategoriesToolStripMenuItem.Click
-
- Dim Form As New frmManageCategories(Database)
- If Form.ShowDialog = Windows.Forms.DialogResult.OK Then
- UpdateCategoryList()
- End If
-
- End Sub
-
- Private CheckingCategory As Boolean = False
-
- Private Sub lstCategories_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles lstCategories.ItemCheck
-
- ' This is a work around for a known "issue" with the control
- If Not CheckingCategory Then
- CheckingCategory = True
- lstCategories.SetItemCheckState(e.Index, e.NewValue)
- UpdateItemList()
- CheckingCategory = False
- End If
-
- End Sub
-
- Private FSongPreviewTip As ToolTip = Nothing
-
- Private Sub HandleToolTipPreview() Handles lstItems.SelectedIndexChanged
-
- If Database.Settings.ShowSongPreviews = False Then Exit Sub
-
- ' Create tool tip if necessary
- If FSongPreviewTip Is Nothing Then
- FSongPreviewTip = New ToolTip
- FSongPreviewTip.ToolTipIcon = ToolTipIcon.None
- FSongPreviewTip.Active = True
- FSongPreviewTip.UseAnimation = False
- FSongPreviewTip.UseFading = False
- End If
-
- ' Determine which song is selected
- If lstItems.SelectedIndex <> -1 Then
- If TypeOf lstItems.Items(lstItems.SelectedIndex) Is ListItem(Of Guid) Then
-
- Dim Item As ListItem(Of Guid) = lstItems.Items(lstItems.SelectedIndex)
-
- Dim Song As SongItem = Nothing
- Try
- Song = Database.Songs.GetSong(Item.Key)
- Catch ex As Exception
- Song = New SongItem(Item.ToString, "This song has been deleted.")
- End Try
-
- ' Show new song preview tool tip
- FSongPreviewTip.ToolTipTitle = Song.Title
- FSongPreviewTip.RemoveAll()
- Dim SongText As String = Song.CombineIntoString
- If SongText.Length > 400 Then SongText = SongText.Substring(0, 400) + "..."
- Dim Point As New Point(lstItems.Bounds.Right, lstItems.GetItemRectangle(lstItems.SelectedIndex).Y)
- FSongPreviewTip.Show(SongText, lstItems, Point.X + 3, Point.Y + 3, 6000)
-
- End If
-
- End If
-
- End Sub
-
- Private Sub lstItems_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstItems.Leave
- If FSongPreviewTip IsNot Nothing Then
- FSongPreviewTip.Dispose()
- FSongPreviewTip = Nothing
- End If
- End Sub
-
- Private Sub ClearPlayListToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearPlayListToolStripMenuItem.Click
-
- If lstPlaylist.ItemCount > 0 Then
- If MsgBox("Are you sure you wish to remove all of the items in the play list?", MsgBoxStyle.Question + MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
- lstPlaylist.Clear()
- End If
- End If
-
- End Sub
-
- Private Sub ReportingToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReportingToolStripMenuItem.Click
- Call New frmReporting().ShowDialog()
- End Sub
-
- Private Sub CreateShortcutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateShortcutToolStripMenuItem.Click
-
- ' Determine a file name for the link
- dlgSaveShortcut.FileName = My.Computer.FileSystem.SpecialDirectories.Desktop + "\" + _
- IO.Path.GetFileName(Database.Location) + ".psdb"
-
- ' Ask to save the link
- If dlgSaveShortcut.ShowDialog = Windows.Forms.DialogResult.OK Then
- Try
- IO.File.WriteAllText(dlgSaveShortcut.FileName, Database.Location)
- Catch ex As Exception
- MsgBox("A shortcut could not be created:" + Environment.NewLine + ex.Message, MsgBoxStyle.Exclamation)
- End Try
- End If
-
- End Sub
-
- Private Sub HandleMainMenuOpen(ByVal sender As System.Object, ByVal e As System.EventArgs) _
- Handles FileToolStripMenuItem.DropDownOpened, PlayListToolStripMenuItem.DropDownOpened, _
- ToolsToolStripMenuItem.DropDownOpened, HelpToolStripMenuItem.DropDownOpened, _
- ProjectionToolStripMenuItem.DropDownOpened, mnuCategories.Opened, _
- mnuItems.Opened, mnuPlaylist.Opened, mnuProjection.Opened, mnuVerses.Opened
-
- ' Get items to iterate through
- Dim AllItems As ToolStripItemCollection = Nothing
- If TypeOf sender Is ContextMenuStrip Then
- AllItems = DirectCast(sender, ContextMenuStrip).Items
- Else
- AllItems = DirectCast(sender, ToolStripMenuItem).DropDownItems
- End If
-
- ' Make all separators visible to begin with
- Dim VisibleItems As New List(Of ToolStripItem)
- For Each Item As ToolStripItem In AllItems
- If TypeOf Item Is ToolStripSeparator Then Item.Visible = True
- If Item.Visible Then VisibleItems.Add(Item)
- Next
-
- ' Hide unnecessary separators
- Dim PrevItem As ToolStripItem = Nothing
- For I As Integer = 0 To VisibleItems.Count - 1
- Dim ThisItem As ToolStripItem = VisibleItems(I)
- Dim PrevSeparator As Boolean = TypeOf PrevItem Is ToolStripSeparator
- Dim ThisSeparator As Boolean = TypeOf ThisItem Is ToolStripSeparator
- Dim IsDuplicate As Boolean = PrevItem IsNot Nothing AndAlso ThisItem.Visible AndAlso PrevSeparator AndAlso ThisSeparator
- Dim IsFirst As Boolean = I = 0 AndAlso ThisSeparator
- Dim IsLast As Boolean = I = VisibleItems.Count - 1 AndAlso ThisSeparator
- If IsDuplicate OrElse IsFirst OrElse IsLast Then ThisItem.Visible = False
- PrevItem = ThisItem
- Next
-
- End Sub
-
- End Class