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