VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "comdlg32.ocx"
Begin VB.Form frmGroups 
   BorderStyle     =   4  'Fixed ToolWindow
   Caption         =   "Group Editor"
   ClientHeight    =   3720
   ClientLeft      =   45
   ClientTop       =   405
   ClientWidth     =   6015
   BeginProperty Font 
      Name            =   "Verdana"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "frmGroups.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3720
   ScaleWidth      =   6015
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton cmdRenameGroup 
      Caption         =   "Rename"
      Height          =   375
      Left            =   1440
      TabIndex        =   8
      Top             =   3240
      Width           =   855
   End
   Begin VB.ListBox lstGroup 
      Height          =   2985
      Left            =   120
      TabIndex        =   7
      Top             =   120
      Width           =   2175
   End
   Begin MSComDlg.CommonDialog cd 
      Left            =   1320
      Top             =   2040
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton cmdRemoveGroup 
      Caption         =   "Remove"
      Height          =   375
      Left            =   600
      TabIndex        =   6
      Top             =   3240
      Width           =   855
   End
   Begin VB.CommandButton cmdAdd 
      Caption         =   "Add"
      Height          =   375
      Left            =   120
      TabIndex        =   5
      Top             =   3240
      Width           =   495
   End
   Begin VB.CommandButton cmdSave 
      Caption         =   "Save"
      BeginProperty Font 
         Name            =   "Verdana"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   5040
      TabIndex        =   4
      Top             =   3240
      Width           =   855
   End
   Begin VB.TextBox txtMembers 
      Height          =   2175
      Left            =   2400
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   3
      Top             =   960
      Width           =   3495
   End
   Begin VB.CommandButton cmdApply 
      Caption         =   "Apply"
      Height          =   375
      Left            =   4200
      TabIndex        =   9
      Top             =   3240
      Width           =   855
   End
   Begin VB.Label lblColor 
      BackColor       =   &H00FFFFFF&
      BorderStyle     =   1  'Fixed Single
      Height          =   315
      Left            =   2400
      TabIndex        =   2
      Top             =   360
      Width           =   615
   End
   Begin VB.Label Label3 
      Caption         =   "Members:"
      Height          =   195
      Left            =   2400
      TabIndex        =   1
      Top             =   720
      Width           =   855
   End
   Begin VB.Label Label2 
      Caption         =   "Color:"
      Height          =   195
      Left            =   2400
      TabIndex        =   0
      Top             =   120
      Width           =   540
   End
End
Attribute VB_Name = "frmGroups"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub cmdApply_Click()
    If lstGroup.ListIndex = -1 Then Exit Sub
    Open AppData & "Groups\" & lstGroup.text & ".txt" For Append As #1
    Close #1
    Open AppData & "Groups\" & lstGroup.text & ".txt" For Output As #1
        Dim I As Integer, Splt() As String
        Splt() = Split(txtMembers.text, vbNewLine)
        Print #1, "Color=" & lblColor.BackColor
        For I = 0 To UBound(Splt())
            Print #1, Splt(I)
        Next I
    Close #1
    LoadGroups
    DisplayGroups
End Sub

Private Sub cmdRenameGroup_Click()
    If lstGroup.ListIndex > -1 Then
        Dim str As String
        str = InputBox("Rename to what?", "Rename Group", lstGroup.text)
        If LenB(str) > 0 And LCase$(str) <> LCase$(lstGroup.text) Then
            On Error GoTo hErr
            FileCopy AppData & "Groups\" & lstGroup.text & ".txt", AppData & "Groups\" & FixFilename(str) & ".txt"
            Kill AppData & "Groups\" & lstGroup.text & ".txt"
hErr:
            LoadGroups
            DisplayGroups
            Form_Load
        End If
    End If
End Sub

Private Sub lstGroup_Click()
    cmdSave.Enabled = lstGroup.ListIndex > 0
    cmdRemoveGroup.Enabled = lstGroup.ListIndex > 0
    lblColor.Enabled = lstGroup.ListIndex > 0
    txtMembers.Enabled = lstGroup.ListIndex > 0
    If lstGroup.ListIndex = -1 Then
        lblColor.BackColor = vbWhite
        txtMembers.text = vbNullString
    Else
        Dim I As Integer
        For I = 0 To UBound(Groups())
            If LCase$(Groups(I).Name) = LCase$(lstGroup.text) Then
                lblColor.BackColor = Groups(I).Color
                On Error GoTo hErr:
                txtMembers.text = Join(Groups(I).Members, vbNewLine)
            End If
        Next I
        Exit Sub
hErr:
        txtMembers.text = vbNullString
    End If
End Sub

Private Sub cmdAdd_Click()
    On Error GoTo hErr
    Dim str As String
    str = InputBox("Enter name of group: ", "Add Group")
    If LenB(str) > 0 Then
        Open AppData & "Groups\" & str & ".txt" For Append As #1: Close #1
    End If
    LoadGroups
    Form_Load
hErr:
End Sub

Private Sub cmdRemoveGroup_Click()
    If lstGroup.ListIndex > -1 Then
        On Error GoTo hErr
        Kill AppData & "Groups\" & lstGroup.text & ".txt"
        LoadGroups
        Form_Load
hErr:
    End If
End Sub

Private Sub cmdSave_Click()
    cmdApply_Click
    Unload Me
End Sub

Private Sub Form_Load()
    lstGroup.Clear
    lblColor.BackColor = vbWhite
    txtMembers.text = vbNullString
    On Error GoTo hErr:
    Dim I As Integer
    For I = 0 To UBound(Groups)
        lstGroup.AddItem Groups(I).Name
        lstGroup.ListIndex = 0
    Next I
    Exit Sub
hErr:
    'MsgBox "Cannot display groups, perhaps there are none?", vbExclamation
End Sub

Private Sub lblColor_Click()
    If lstGroup.ListIndex = -1 Then Exit Sub
    cd.ShowColor
    If cd.CancelError = False Then
        lblColor.BackColor = cd.Color
    End If
End Sub
