/
ItemViewControl.vb
169 lines (140 loc) · 6.17 KB
/
ItemViewControl.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
Imports System.Xml
Imports System.IO
Public Class ItemViewControl
Public FileName As String
Private m_strPath As String = DataDirectory.GetFolderPath() + "\Lightened Dream\Lucidity\"
Private m_strType As String
Private m_boolSpelling As Boolean = False
Public Sub EnableSpellCheck()
m_boolSpelling = True
End Sub
Public Sub DisableSpellCheck()
m_boolSpelling = False
End Sub
Public Function Changed() As Boolean
If m_strType = "Subliminal" Then
Return objSublinalControl.Changed
ElseIf m_strType = "Reading" Then
Return objSpeedReadingControl.Changed
ElseIf m_strType = "Recording" Then
Return objRecordingViewControl.Changed
End If
End Function
Public Sub LoadFile(ByVal strFileName As String)
Try
Dim xmlDoc As New XmlDocument
FileName = strFileName
xmlDoc.Load(strFileName)
pnlContainer.Controls.Clear()
m_strType = xmlDoc.DocumentElement.Name
txtTitle.Text = xmlDoc.DocumentElement.SelectSingleNode("Title").InnerText
txtDescription.Text = xmlDoc.DocumentElement.SelectSingleNode("Description").InnerText
If m_strType = "Subliminal" Then
pnlContainer.Controls.Add(objSublinalControl)
objSublinalControl.Location = New Point(0, 0)
objSublinalControl.Dock = DockStyle.Fill
lblTitle.Text = "Lucidity - Subliminals - " + txtTitle.Text
objSublinalControl.LoadFile(strFileName)
NHunspellTextBoxExtender1.SetSpellCheckEnabled(objSublinalControl.txtMessages, True)
ElseIf m_strType = "Reading" Then
pnlContainer.Controls.Add(objSpeedReadingControl)
objSpeedReadingControl.Location = New Point(0, 0)
objSpeedReadingControl.Dock = DockStyle.Fill
lblTitle.Text = "Lucidity - Readings - " + txtTitle.Text
objSpeedReadingControl.LoadFile(strFileName)
NHunspellTextBoxExtender1.SetSpellCheckEnabled(objSpeedReadingControl.txtReadings, True)
ElseIf m_strType = "Recording" Then
pnlContainer.Controls.Add(objRecordingViewControl)
objRecordingViewControl.Location = New Point(0, 0)
objRecordingViewControl.Dock = DockStyle.Fill
lblTitle.Text = "Lucidity - Recordings - " + txtTitle.Text
objRecordingViewControl.LoadFile(strFileName)
NHunspellTextBoxExtender1.SetSpellCheckEnabled(objRecordingViewControl.txtSpeech, True)
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "LightenedDream.Lucidity.Item.Load()", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Public Sub Save(ByVal Type As String)
Try
Dim strFileName As String
strFileName = m_strPath + m_strType + "s\" + txtTitle.Text + ".ld3"
If (FileName <> strFileName) Then
' Make sure the file doesn't already exist
If (File.Exists(strFileName)) Then
If MessageBox.Show("The file '" & New FileInfo(strFileName).Name.Replace(".ld3", "") & "' already exists." & vbNewLine & "Would you like to replace it?", "Overwrite File?", MessageBoxButtons.YesNoCancel) = DialogResult.Yes Then
File.Delete(strFileName)
Else
Return
End If
End If
File.Move(FileName, strFileName)
FileName = strFileName
End If
If m_strType = "Subliminal" Then
objSublinalControl.Save(txtTitle.Text, txtDescription.Text, strFileName)
ElseIf m_strType = "Reading" Then
objSpeedReadingControl.Save(txtTitle.Text, txtDescription.Text, strFileName)
ElseIf m_strType = "Recording" Then
objRecordingViewControl.Save(txtTitle.Text, txtDescription.Text, strFileName)
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "LightenedDream.Lucidity.Item.Save()", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Public Function CreateNew(ByVal Type As String) As String
Try
m_strType = Type
Dim strTitle As String = "New " + m_strType
Dim strFileName As String
strFileName = m_strPath + m_strType + "s\" + strTitle + ".ld3"
Dim intPos As Integer = 2
Do
If (File.Exists(strFileName)) Then
strTitle = "New " + m_strType + " " + intPos.ToString
strFileName = m_strPath + m_strType + "s\" + strTitle + ".ld3"
intPos += 1
Else
Exit Do
End If
Loop
Dim strXml As String
strXml = "<" + m_strType + ">"
strXml += "<Title>" + strTitle + "</Title>"
strXml += "<Description></Description>"
strXml += "</" + m_strType + ">"
Dim xmlDoc As New XmlDocument
xmlDoc.LoadXml(strXml)
xmlDoc.Save(strFileName)
Return strFileName
Catch ex As Exception
MessageBox.Show(ex.Message, "LightenedDream.Lucidity.Item.Create()", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Function
Public Function Play() As Boolean
If m_strType = "Subliminal" Then
objSublinalControl.Play()
Return True
ElseIf m_strType = "Reading" Then
objSpeedReadingControl.Play()
ElseIf m_strType = "Recording" Then
objRecordingViewControl.Play()
End If
Return False
End Function
Public Function Playing() As Boolean
If m_strType = "Subliminal" Then
Return objSublinalControl.Playing
End If
Return False
End Function
Public Sub StopRunning()
If m_strType = "Subliminal" Then
objSublinalControl.StopRunning()
ElseIf m_strType = "Reading" Then
objSpeedReadingControl.StopRunning()
ElseIf m_strType = "Recording" Then
objRecordingViewControl.StopRunning()
End If
End Sub
End Class