be6eea1054
- aggiunta possibilità di comando Copia a GunStock.
124 lines
4.4 KiB
VB.net
124 lines
4.4 KiB
VB.net
'----------------------------------------------------------------------------
|
|
' EgalTech 2015-2019
|
|
'----------------------------------------------------------------------------
|
|
' File : MruList.vb Data : 17.03.19 Versione : 2.c3
|
|
' Contenuto : Classe MruList (gestione elenco file appena usati).
|
|
'
|
|
'
|
|
'
|
|
' Modifiche : 27.02.15 DS Creazione modulo.
|
|
' 17.03.19 DS Scrittura e lettura path file da Ini come Utf8.
|
|
'
|
|
'----------------------------------------------------------------------------
|
|
|
|
'--------------------------------------------------------------------------------------------------
|
|
Imports System.Collections.ObjectModel
|
|
|
|
Public Class MruList
|
|
|
|
'---------------------------------------------------------------------------
|
|
Private m_sSection As String
|
|
Private m_nMaxEntries As Integer
|
|
Friend m_FileNames As ObservableCollection(Of String)
|
|
|
|
'---------------------------------------------------------------------------
|
|
'Public Sub Init(sSection As String, nMaxEntries As Integer, Command As ICommand)
|
|
Public Sub Init(sSection As String, nMaxEntries As Integer)
|
|
' Inizializzo
|
|
m_sSection = sSection
|
|
m_nMaxEntries = nMaxEntries
|
|
m_FileNames = New ObservableCollection(Of String)
|
|
' Carico lista da Ini.
|
|
LoadMruList()
|
|
End Sub
|
|
|
|
'---------------------------------------------------------------------------
|
|
Private Sub LoadMruList()
|
|
' Pulisco la lista dei file
|
|
m_FileNames.Clear()
|
|
' Carico la lista dei file salvati in INI
|
|
Dim sFileName As String = String.Empty
|
|
For i As Integer = 1 To m_nMaxEntries
|
|
Dim sKey As String = K_FILE + i.ToString()
|
|
If GetPrivateProfileStringUtf8(m_sSection, sKey, "", sFileName) Then
|
|
m_FileNames.Add(sFileName)
|
|
End If
|
|
Next
|
|
End Sub
|
|
|
|
'---------------------------------------------------------------------------
|
|
Private Sub SaveMruList()
|
|
For i As Integer = 1 To m_nMaxEntries
|
|
Dim sKey As String = K_FILE + i.ToString()
|
|
If i <= m_FileNames.Count Then
|
|
WritePrivateProfileStringUtf8(m_sSection, sKey, m_FileNames(i - 1).ToString)
|
|
Else
|
|
WritePrivateProfileString(m_sSection, sKey, "")
|
|
End If
|
|
Next
|
|
End Sub
|
|
|
|
'---------------------------------------------------------------------------
|
|
Public Sub Add(sFileName As String)
|
|
' Gestione '_'
|
|
Dim sMyFileName As String = sFileName.Replace("_", "__")
|
|
' Se stringa vuota, esco subito
|
|
If String.IsNullOrEmpty(sMyFileName) Then Return
|
|
' Se già presente, rimuovo il file dalla lista
|
|
Dim i As Integer = FileNameIndex(sMyFileName)
|
|
If i >= 0 Then
|
|
m_FileNames.RemoveAt(i)
|
|
End If
|
|
' Aggiungo il file in cima alla lista
|
|
If m_FileNames.Count > 0 Then
|
|
m_FileNames.Insert(0, sMyFileName)
|
|
Else
|
|
m_FileNames.Add(sMyFileName)
|
|
End If
|
|
' Se la lista ha superato la massima dimensione, cancello l'ultimo record
|
|
If m_FileNames.Count > m_nMaxEntries Then
|
|
m_FileNames.RemoveAt(m_nMaxEntries)
|
|
End If
|
|
' Salvo la lista aggiornata
|
|
SaveMruList()
|
|
End Sub
|
|
|
|
'---------------------------------------------------------------------------
|
|
Private Function FileNameIndex(sFileName As String) As Integer
|
|
For i As Integer = 0 To m_FileNames.Count - 1
|
|
If String.Compare(m_FileNames(i).ToString, sFileName, True) = 0 Then
|
|
Return i
|
|
End If
|
|
Next
|
|
Return -1
|
|
End Function
|
|
|
|
'---------------------------------------------------------------------------
|
|
Public Sub Remove(sFileName As String)
|
|
' Gestione '_'
|
|
Dim sMyFileName As String = sFileName.Replace("_", "__")
|
|
' Rimozione
|
|
Dim i As Integer = FileNameIndex(sMyFileName)
|
|
If i >= 0 Then
|
|
' Rimuovo il file
|
|
m_FileNames.RemoveAt(i)
|
|
' Salvo la lista aggiornata
|
|
SaveMruList()
|
|
End If
|
|
End Sub
|
|
|
|
'---------------------------------------------------------------------------
|
|
Public Function GetFileName(nInd As Integer, ByRef sFileName As String) As Boolean
|
|
If nInd >= 0 And nInd < m_FileNames.Count() Then
|
|
' Gestione '_'
|
|
sFileName = m_FileNames(nInd).ToString().Replace("__", "_")
|
|
Return True
|
|
Else
|
|
sFileName = String.Empty
|
|
Return False
|
|
End If
|
|
End Function
|
|
|
|
End Class
|
|
|