PageRenderTime 72ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/Source Code/PowerSong/Plug Ins/frmCreatePlugIn.vb

#
Visual Basic | 63 lines | 45 code | 15 blank | 3 comment | 1 complexity | ee45145dd9bd004f8210c2fa5e987f7f MD5 | raw file
  1. Imports System.Windows.Forms
  2. Imports System.IO
  3. Imports PowerSong.SongDatabase
  4. Public Class frmCreatePlugIn
  5. Private FDatabase As Database = Nothing
  6. Public Sub New(ByVal database As Database)
  7. InitializeComponent()
  8. FDatabase = database
  9. End Sub
  10. Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
  11. Try
  12. ' Perform some checks
  13. If txtName.Text.Trim = "" Then Throw New ApplicationException("Please specify the name of the plugin.")
  14. If txtLocation.Text.Trim = "" Then Throw New ApplicationException("Please specify the location of the plugin.")
  15. If txtFolderName.Text.Trim = "" Then Throw New ApplicationException("Please specify the name of the folder for the new plugin.")
  16. ' Create the folder where the plugin should reside
  17. Dim TargetDirectory As String = txtLocation.Text + "\" + txtFolderName.Text
  18. If Directory.Exists(TargetDirectory) Then Throw New ApplicationException("That folder already exists at the specified location.")
  19. Directory.CreateDirectory(TargetDirectory)
  20. ' Create basic code files
  21. FDatabase.CreateNewPlugin(TargetDirectory, Database.InitialContentFolder + "\New.plugin")
  22. ' Show feedback
  23. MsgBox("The plugin has been created at " + txtLocation.Text + "\" + txtFolderName.Text + ".", MsgBoxStyle.Information)
  24. ' Close the form
  25. Me.DialogResult = System.Windows.Forms.DialogResult.OK
  26. Me.Close()
  27. Catch ex As Exception
  28. MsgBox(ex.Message, MsgBoxStyle.Exclamation)
  29. End Try
  30. End Sub
  31. Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
  32. Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
  33. Me.Close()
  34. End Sub
  35. Private Sub btnSelectFolder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectFolder.Click
  36. If dlgSelectPluginFolder.ShowDialog = Windows.Forms.DialogResult.OK Then
  37. txtLocation.Text = dlgSelectPluginFolder.SelectedPath
  38. End If
  39. End Sub
  40. Private Sub txtName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtName.TextChanged
  41. txtFolderName.Text = txtName.Text
  42. End Sub
  43. Private Sub frmCreatePlugIn_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  44. txtLocation.Text = FileIO.SpecialDirectories.Desktop
  45. End Sub
  46. End Class