-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigManager.bas
More file actions
147 lines (123 loc) · 3.77 KB
/
Copy pathConfigManager.bas
File metadata and controls
147 lines (123 loc) · 3.77 KB
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
#include "windows.bi"
#include "crt.bi"
#include "Inc\PluginInterface.bi"
#include "Inc\ConfigManager.bi"
const INI_FILENAME = wstr("\Smart-Math.ini")
const NPPM_GETPLUGINSCONFIGDIR = (WM_USER + 1000 + 46)
dim shared as wstring * MAX_PATH iniFilePath
dim shared as integer storedDecimalPlaces = 2
dim shared as string enabledFiles()
dim shared as HWND hNppWnd
private sub PrepareIniPath()
dim as wstring * MAX_PATH configDir
SendMessage(hNppWnd, NPPM_GETPLUGINSCONFIGDIR, MAX_PATH, cast(LPARAM, @configDir))
CreateDirectory(configDir, NULL)
iniFilePath = configDir & INI_FILENAME
end sub
sub Config_Init(hNpp as HWND)
hNppWnd = hNpp
PrepareIniPath()
end sub
sub Config_SetDecimalPlaces(p as integer)
if p < 0 then p = 0
if p > 8 then p = 8
storedDecimalPlaces = p
end sub
function Config_GetDecimalPlaces() as integer
return storedDecimalPlaces
end function
function Config_IsFileEnabled(path as string) as boolean
dim as integer i
for i = lbound(enabledFiles) to ubound(enabledFiles)
if enabledFiles(i) = path then return TRUE
next i
return FALSE
end function
sub Config_ToggleFile(path as string)
dim as integer i, idx = -1
for i = lbound(enabledFiles) to ubound(enabledFiles)
if enabledFiles(i) = path then
idx = i
exit for
end if
next i
if idx = -1 then
if ubound(enabledFiles) = -1 then
redim enabledFiles(0)
else
redim preserve enabledFiles(ubound(enabledFiles) + 1)
end if
enabledFiles(ubound(enabledFiles)) = path
else
if idx < ubound(enabledFiles) then
enabledFiles(idx) = enabledFiles(ubound(enabledFiles))
end if
if ubound(enabledFiles) > 0 then
redim preserve enabledFiles(ubound(enabledFiles) - 1)
else
erase enabledFiles
end if
end if
end sub
sub Config_DisableFile(path as string)
dim as integer i, idx = -1
for i = lbound(enabledFiles) to ubound(enabledFiles)
if enabledFiles(i) = path then
idx = i
exit for
end if
next i
if idx <> -1 then
if idx < ubound(enabledFiles) then
enabledFiles(idx) = enabledFiles(ubound(enabledFiles))
end if
if ubound(enabledFiles) > 0 then
redim preserve enabledFiles(ubound(enabledFiles) - 1)
else
erase enabledFiles
end if
Config_Save()
end if
end sub
sub Config_Save()
dim as string allPaths = ""
dim as integer i
WritePrivateProfileString(wstr("Settings"), wstr("DecimalPlaces"), wstr(str(storedDecimalPlaces)), iniFilePath)
for i = lbound(enabledFiles) to ubound(enabledFiles)
if len(enabledFiles(i)) > 0 then
if len(allPaths) > 0 then allPaths &= "|"
allPaths &= enabledFiles(i)
end if
next i
WritePrivateProfileString(wstr("Settings"), wstr("ActiveTabs"), wstr(allPaths), iniFilePath)
end sub
sub Config_Load()
storedDecimalPlaces = GetPrivateProfileInt(wstr("Settings"), wstr("DecimalPlaces"), 2, iniFilePath)
if storedDecimalPlaces < 0 then storedDecimalPlaces = 0
if storedDecimalPlaces > 8 then storedDecimalPlaces = 8
dim as zstring * 32768 buffer
GetPrivateProfileString(wstr("Settings"), wstr("ActiveTabs"), wstr(""), @buffer, 32768, iniFilePath)
erase enabledFiles
dim as string sBuffer = buffer
dim as integer pPipe, pStart = 1
dim as string sPath
if len(sBuffer) > 0 then
do
pPipe = instr(pStart, sBuffer, "|")
if pPipe > 0 then
sPath = mid(sBuffer, pStart, pPipe - pStart)
pStart = pPipe + 1
else
sPath = mid(sBuffer, pStart)
end if
if len(sPath) > 0 then
if ubound(enabledFiles) = -1 then
redim enabledFiles(0)
else
redim preserve enabledFiles(ubound(enabledFiles) + 1)
end if
enabledFiles(ubound(enabledFiles)) = sPath
end if
loop while pPipe > 0
end if
end sub