-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFrmSettings.vb
79 lines (69 loc) · 3.43 KB
/
FrmSettings.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
Imports System.Windows.Forms
Imports System.Xml
Public Class FrmSettings
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
Dim LibraryNode As XmlNode = FrmMain.ProgramSettings.SelectSingleNode("unPCB/libraries")
If TxtAutoSaveInterval.Value <= 0 Then
MsgBox("Auto save interval must be > 0.")
Exit Sub
End If
LibraryNode.RemoveAll()
For Each Item As String In LstLibraries.Items
LibraryNode.AppendChild(FrmMain.ProgramSettings.CreateElement("library")).InnerText = Item
Next
FrmMain.ProgramSettings.SelectSingleNode("unPCB/auto_save").InnerText = ChAutoSave.Checked
FrmMain.ProgramSettings.SelectSingleNode("unPCB/auto_save_interval").InnerText = TxtAutoSaveInterval.Value * 60
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
End Sub
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Close()
End Sub
Private Sub FrmSettings_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim LibraryNodes As XmlNodeList = FrmMain.ProgramSettings.SelectNodes("unPCB/libraries/library")
For Each LibraryNode As XmlNode In LibraryNodes
LstLibraries.Items.Add(LibraryNode.InnerText)
Next
ChAutoSave.Checked = FrmMain.ProgramSettings.SelectSingleNode("unPCB/auto_save").InnerText
TxtAutoSaveInterval.Value = CInt(FrmMain.ProgramSettings.SelectSingleNode("unPCB/auto_save_interval").InnerText) \ 60
End Sub
Private Sub CmdAddLibrary_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdAddLibrary.Click
OpenFileDialog.Multiselect = True
If OpenFileDialog.ShowDialog() Then
For Each FileName As String In OpenFileDialog.FileNames
AddLibrary(FileName)
Next
End If
End Sub
Private Function LibraryExists(ByVal FileName As String) As Boolean
Dim ShortFileName As String = System.IO.Path.GetFileName(FileName)
For Each Item As String In LstLibraries.Items
If System.IO.Path.GetFileName(Item) = shortfilename Then
Return True
End If
Next
Return False
End Function
Private Sub AddLibrary(ByVal FileName As String)
Dim Project As New Eagle.Project
If Not Project.Load(FileName) Then
MsgBox("Invalid Eagle project! Must be saved by a newer eagle version first. " & FileName, MsgBoxStyle.Critical)
Exit Sub
End If
If Project.Drawing.DrawingType <> Eagle.DrawingType.library Then
MsgBox("This is not an eagle library (schematic or something else)! " & FileName)
Exit Sub
End If
If LibraryExists(FileName) Then
MsgBox("Another library with the same name " & System.IO.Path.GetFileName(FileName) & " is already added, remove that first!")
Exit Sub
End If
LstLibraries.Items.Add(FileName)
End Sub
Private Sub CmdDel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdDel.Click
If LstLibraries.SelectedIndex > -1 Then
LstLibraries.Items.RemoveAt(LstLibraries.SelectedIndex)
End If
End Sub
End Class