VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsTags"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Option Compare Text

Public Tags As New Collection
Const Separator As String = "זק"

Public Sub LoadTags()
    Set Tags = New Collection
    Dim r As String, S() As String, I As Integer
    r = modFileIO.ReadFile(AppData & "Data\Preferences\Tags.ini")
    S = Split(r, vbNewLine)
    For I = 0 To UBound(S)
        If InStr(S(I), Separator) Then
            Dim t() As String
            t = Split(S(I), Separator, 2)
            If UBound(t) = 1 Then
                AddTag t(0), t(1), False
            End If
        End If
    Next
    SaveTags
End Sub

Public Sub SaveTags()
    Dim r As String, I As Integer, A As objTag
    For I = 1 To Tags.Count
        Set A = Tags(I)
        r = r & A.Channel & Separator & A.Tag & vbNewLine
    Next
    SaveFile AppData & "Data\Preferences\Tags.ini", r
End Sub

Public Function AddTag(ByRef Channel As String, Tag As String, Optional Save As Boolean = True) As Boolean
    If TagExists(Channel) Then
        Dim I As Integer
        For I = 1 To Tags.Count
            If Tags(I).Channel = Channel Then
                Tags(I).Tag = Tag
                AddTag = True
            End If
        Next
    Else
        Dim A As New objTag
        A.Channel = Channel
        A.Tag = Tag
        Tags.Add A
        AddTag = True
    End If
    If Save Then SaveTags
End Function

Public Function TagExists(ByRef Channel As String) As Boolean
On Error Resume Next
    Dim I As Integer
    For I = 1 To Tags.Count
        If Tags(I).Channel = Channel Then
            TagExists = True
            Exit Function
        End If
    Next
End Function

Public Function GetTag(ByRef Channel As String) As String
On Error Resume Next
    Dim I As Integer
    For I = 1 To Tags.Count
        If Tags(I).Channel = Channel Then
            GetTag = Tags(I).Tag
            Exit Function
        End If
    Next
End Function

Public Function RemoveTag(ByRef Channel As String) As Boolean
On Error Resume Next
    Dim I As Integer
    For I = Tags.Count To 1 Step -1
        If Tags(I).Channel = Channel Then
            Tags.Remove I
            RemoveTag = True
            Exit Function
        End If
    Next
    SaveTags
End Function


