PageRenderTime 51ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/Source Code/PowerSong/frmMain.vb

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