/Source Code/PowerSong/frmMain.Helper.vb
Visual Basic | 327 lines | 217 code | 79 blank | 31 comment | 0 complexity | d6c6d3973ef278b8d2bd847bb6389ff8 MD5 | raw file
- Imports System.IO
- Imports PowerSong.SongDatabase
- Imports PowerSong.SongDatabase.Items
- Imports PowerSong.Projection
- Imports PowerSong.SongDatabase.Logging
-
- Partial Public Class frmMain
-
- Private FActiveItem As BaseItem = Nothing
- Private FActiveStyle As Style = Nothing
- Private FActivePart As Integer = -1
-
- Private FPreviewProjector As Projector = Nothing
- Private FProjections As New List(Of Projector)
- Private FProjectionForm As frmMainProjection = Nothing
-
- #Region " Form Update Routines "
-
- Public Sub UpdateAll()
- UpdateTitle()
- UpdateItemList()
- UpdateCategoryList()
- UpdateActiveItem()
- UpdateControlVisibility()
- UpdateProjectorStyle()
- End Sub
-
- Private Sub UpdateTitle()
- Text = "PowerSong"
- If Database IsNot Nothing Then Text += " - " + DatabaseLocation
- End Sub
-
- Private Sub UpdateActiveItem()
- lstVerses.Items.Clear()
- If FActiveItem IsNot Nothing Then
- For Each Part As String In FActiveItem.Parts
- lstVerses.Items.Add(Part)
- Next
- End If
- End Sub
-
- Private Sub UpdateItemList()
-
- ' If the search box is not empty then do the search instead of showing all items
- If txtSearch.Text <> "" Then
- txtSearch_TextChanged(Nothing, EventArgs.Empty)
- Exit Sub
- End If
-
- lstItems.Items.Clear()
- lstItems.BeginUpdate()
- If Database IsNot Nothing Then
- If optSongs.Checked Then
-
- ' Add all songs with the selected categories
- Dim AddedSongs As New List(Of Guid)
- For Each SelectedCategory As ListItem(Of Guid) In lstCategories.CheckedItems
- For Each SongID As Guid In Database.Songs.GetCategorySongIDs(SelectedCategory.Key)
-
- ' Has the song already been added?
- If Not AddedSongs.Contains(SongID) Then
- Dim Item As New ListItem(Of Guid)(Database.Songs.GetSongTitle(SongID), SongID)
- lstItems.Items.Add(Item)
- AddedSongs.Add(SongID)
- End If
-
- Next
- Next
- lstItems.Sorted = True
-
- Else
-
- ' Add all bible chapters
- If BibleIndex IsNot Nothing Then
- lstItems.Sorted = False
- For Each Chapter As String In BibleIndex.GetAllChapters
- lstItems.Items.Add(New ListItem(Of String)(IO.Path.GetFileNameWithoutExtension(Chapter), Chapter))
- Next
- End If
-
- End If
-
- End If
- lstItems.EndUpdate()
-
- ' Update other controls
- UpdateItemCountLabel()
- UpdateControlVisibility()
-
- End Sub
-
- Friend Sub UpdateCategoryList()
-
- If optBible.Checked Then
-
- ' Show available bible translations
- lstCategories.Enabled = False
- lblSelectWhatToInclude.Enabled = False
-
- Else
-
- lstCategories.Enabled = True
- lblSelectWhatToInclude.Enabled = True
-
- ' Determine which categories are currently selected
- Dim CheckedItems As New List(Of Guid)
- For ItemIndex As Integer = 0 To lstCategories.Items.Count - 1
- If lstCategories.GetItemChecked(ItemIndex) = True Then
- Dim Item As ListItem(Of Guid) = lstCategories.Items(ItemIndex)
- CheckedItems.Add(Item.Key)
- End If
- Next
-
- ' Clear the list
- lstCategories.Items.Clear()
-
- ' Add the categories to the list
- If Database IsNot Nothing Then
- For Each Category As KeyValuePair(Of Guid, String) In Database.Categories.GetAllCategories
- Dim Item As New ListItem(Of Guid)(Category.Value, Category.Key)
-
- ' Select the category if it were previously selected
- Dim ItemIndex As Integer = lstCategories.Items.Add(Item)
- If CheckedItems.Contains(Category.Key) Then lstCategories.SetItemChecked(ItemIndex, True)
-
- Next
- End If
-
- End If
-
- ' Update available items
- UpdateItemList()
-
- End Sub
-
- Friend Sub UpdateItemCountLabel()
-
- If optSongs.Checked Then
- lblItemCount.Text = "Songs Found: (" + lstItems.Items.Count.ToString + ")"
- Else
- lblItemCount.Text = "Bible Chapters Found: (" + lstItems.Items.Count.ToString + ")"
- End If
-
- End Sub
-
- Private Sub UpdateControlVisibility()
-
- ' Item list
- btnAddSong.Enabled = optSongs.Checked
- btnDeleteSong.Enabled = optSongs.Checked AndAlso lstItems.SelectedIndex > -1
- btnAddToPlaylist.Enabled = lstItems.SelectedIndex > -1
- EditSongToolStripMenuItem1.Enabled = optSongs.Checked AndAlso lstItems.SelectedIndex > -1
- DeleteSongToolStripMenuItem.Enabled = optSongs.Checked AndAlso lstItems.SelectedIndex > -1
- AddToPlaylistToolStripMenuItem.Enabled = lstItems.SelectedIndex > -1
- ActivateToolStripMenuItem.Enabled = lstItems.SelectedIndex > -1
-
- ' Playlist
- LoadPlayListToolStripMenuItem.Enabled = True
- SavePlayListToolStripMenuItem.Enabled = True
- btnRemoveFromPlaylist.Enabled = lstPlaylist.SelectedIndex > -1
- btnSetImage.Enabled = lstPlaylist.SelectedIndex > -1
- btnDisplaySong.Enabled = lstPlaylist.SelectedIndex > -1
- btnConfigureSong.Enabled = lstPlaylist.SelectedIndex > -1
- RemoveToolStripMenuItem.Enabled = lstPlaylist.SelectedIndex > -1
- ChangeBacToolStripMenuItem.Enabled = lstPlaylist.SelectedIndex > -1
- ConfigurePlaylistItemToolStripMenuItem.Enabled = lstPlaylist.SelectedIndex > -1
- DisplayItemNowToolStripMenuItem.Enabled = lstPlaylist.SelectedIndex > -1
- LoadListToolStripMenuItem.Enabled = True
- SaveListToolStripMenuItem.Enabled = True
- AddTitleToolStripMenuItem.Enabled = True
- btnMoveUp.Enabled = lstPlaylist.SelectedIndex > -1 AndAlso lstPlaylist.SelectedIndex > 0
- btnMoveDown.Enabled = lstPlaylist.SelectedIndex > -1 AndAlso lstPlaylist.SelectedIndex < lstPlaylist.ItemCount - 1
-
- ' Projector preview
- btnGoToFull.Enabled = FActiveItem IsNot Nothing AndAlso ToggleFullScreenViewToolStripMenuItem.Checked
- btnGoToBackground.Enabled = FActiveItem IsNot Nothing AndAlso ToggleFullScreenViewToolStripMenuItem.Checked
- btnGoToBlack.Enabled = FActiveItem IsNot Nothing AndAlso ToggleFullScreenViewToolStripMenuItem.Checked
- GoToFullDisplayToolStripMenuItem.Enabled = btnGoToFull.Enabled
- GoToBackgroundOnlyToolStripMenuItem.Enabled = btnGoToBackground.Enabled
- GoToBlackToolStripMenuItem.Enabled = btnGoToBlack.Enabled
-
- ' Active song
- btnEditSong.Enabled = FActiveItem IsNot Nothing
- btnNext.Enabled = FActiveItem IsNot Nothing
- btnPrevious.Enabled = FActiveItem IsNot Nothing
- btnSetAnnouncement.Enabled = True
- EditSongToolStripMenuItem.Enabled = FActiveItem IsNot Nothing
- EditVerseToolStripMenuItem.Enabled = FActivePart <> -1
- AddVerseToolStripMenuItem.Enabled = FActiveItem IsNot Nothing
-
- End Sub
-
- #End Region
-
- #Region " Helper Methods "
-
- Private Function FindProjector(ByVal target As Control) As Projector
- For Each Projector As Projector In FProjections
- If Projector.Target Is target Then Return Projector
- Next
- Return Nothing
- End Function
-
- Private Sub ToggleProjector(ByVal target As Control)
-
- ' Find the projector
- Dim Projector As Projector = FindProjector(target)
-
- ' Determine which of the projectors is being toggled
- If target Is FProjectionForm Then
-
- ' The live view
- If Projector.Projecting Then FProjectionForm.Hide() Else FProjectionForm.Show()
- Projector.Projecting = Not Projector.Projecting
- ToggleFullScreenViewToolStripMenuItem.Checked = FProjectionForm.Visible
-
- Else
-
- ' The preview view
- Projector.Projecting = Not Projector.Projecting
- TogglePreviewToolStripMenuItem.Checked = Projector.Projecting
-
- End If
-
- ' Clear the projection area if no longer projecting
- If Not Projector.Projecting Then Projector.Target.CreateGraphics.Clear(Color.Black)
-
- End Sub
-
- Private Sub UpdateProjectorStyle()
-
- If FActiveStyle IsNot Nothing Then
- For Each Projector As Projector In FProjections
-
- ' Update background style
- Select Case FActiveStyle.BackgroundType
- Case Style.EBackgroundType.Image : Projector.SetBackgroundImage(FActiveStyle.DefaultBackgroundImage)
- Case Style.EBackgroundType.SolidColour : Projector.SetBackgroundColour(FActiveStyle.DefaultBackgroundColour)
- End Select
-
- ' Update projectlets
- For Each Projectlet As Projectlet In Projector.Projectlets
- Dim SubStyle As ProjectletStyle = FActiveStyle(Projectlet.Category)
- Projector.SetProjectletStyle(Projectlet, SubStyle)
- Next
-
- Next
- End If
-
- End Sub
-
- Private Sub CloseDatabase()
-
- ' If a song is active, record it as hidden
- 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
-
- ' Unload plugins
- If Plugins.Instance IsNot Nothing Then Plugins.Instance.UnloadAllPlugins()
-
- ' Clear variables
- DatabaseLocation = ""
- Database = Nothing
- FActiveItem = Nothing
- FActiveStyle = Nothing
- FActivePart = -1
- txtSearch.Text = ""
-
- ' Clear list boxes
- lstCategories.Items.Clear()
- lstPlaylist.Clear()
- lstVerses.Items.Clear()
- UpdateAll()
-
- End Sub
-
- Private Sub ChangeActivePart(ByVal newPart As Integer)
-
- FActivePart = newPart
- Dim NextSelectedIndex As Integer = FActivePart + 1
- If NextSelectedIndex >= lstVerses.Items.Count Then NextSelectedIndex = 0
-
- ' Only change the active part if there is at least one verse
- If NextSelectedIndex < lstVerses.Items.Count Then
-
- ' Change the text on the projector
- lstVerses.SelectedIndex = NextSelectedIndex
- lstVerses.ActiveIndex = FActivePart
- For Each Projector As Projector In FProjections
-
- ' Determine what text to display
- Dim Projectlet As Projectlet = Projector.ProjectletByName("Verse")
- Dim VerseText As String = Projectlet.PopulateTags(FActiveItem, FActivePart)
- ' Actually set the text
- Projector.SetTextWithFade(Projectlet, _
- FActivePart, _
- FActiveItem.Parts.Count, _
- VerseText, _
- FActiveStyle.VerseFadeDuration, _
- False)
- Next
-
- End If
-
- End Sub
-
- #End Region
-
- Private Sub HandleCompletedModeChange(ByVal newMode As Projector.EMode)
-
- If newMode = Projector.EMode.Fading Then Exit Sub
-
- ' Set the colour of the three buttons appropriately
- btnGoToBlack.ForeColor = SystemColors.ControlText
- btnGoToBackground.ForeColor = SystemColors.ControlText
- btnGoToFull.ForeColor = SystemColors.ControlText
-
- Select Case newMode
- Case Projector.EMode.Black : btnGoToBlack.ForeColor = SystemColors.MenuHighlight
- Case Projector.EMode.DisplayBackground : btnGoToBackground.ForeColor = SystemColors.MenuHighlight
- Case Projector.EMode.DisplayAll : btnGoToFull.ForeColor = SystemColors.MenuHighlight
- End Select
-
- End Sub
-
- End Class