-
Notifications
You must be signed in to change notification settings - Fork 1
/
configunit.pas
165 lines (127 loc) · 5.15 KB
/
configunit.pas
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
unit ConfigUnit;
//
// Класс инициализации приложения
//
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, IniFiles,
FormValueInitUnit;
type
{ TConfig }
TConfig=class(TObject)
private
public
Default_CharSet:string; // кодировка по умолчанию
Default_AsmDecode:string; // декодирование инструкций по умолчанию
ProjectPanelShow:boolean;
SymbolPanelShow:boolean;
constructor Create;
destructor Free;
procedure OpenOldSessionFiles; // открытие файлов прошлой сессии
procedure SaveSessionFiles; // сохранение открытых файлов сессии
end;
implementation
uses MainUnit, SourceTextUnit, EditorFilesUnit;
{ TConfig }
constructor TConfig.Create;
var
inif:TIniFile;
begin
inif:=TIniFile.Create(app_conf_name);
Default_CharSet:=inif.ReadString ('APPLICATION', 'Default_CharSet', 'CP1251');
Default_AsmDecode:=inif.ReadString('APPLICATION', 'Default_AsmDecode', 'cortex-m4');
ProjectPanelShow:=inif.ReadBool ('APPLICATION', 'ProjectPanelShow', false);
SymbolPanelShow:=inif.ReadBool ('APPLICATION', 'SymbolPanelShow', false);
MainForm.CenterTopPanel.Visible:=inif.ReadBool('APPLICATION', 'FxPanelShow', false);
MainForm.Menu_View_FxShow.Checked:=MainForm.CenterTopPanel.Visible;
MainForm.Menu_Edit_AutoFormat.Checked:=inif.ReadBool ('APPLICATION', 'Autoformat', false);
inif.Free;
end;
destructor TConfig.Free;
var
inif:TIniFile;
begin
inif:=TIniFile.Create(app_conf_name);
inif.WriteString('APPLICATION', 'Default_CharSet', Default_CharSet);
inif.WriteString('APPLICATION', 'Default_AsmDecode', Default_AsmDecode);
inif.WriteBool ('APPLICATION', 'ProjectPanelShow', ProjectPanelShow);
inif.WriteBool ('APPLICATION', 'SymbolPanelShow', SymbolPanelShow);
inif.WriteBool ('APPLICATION', 'FxPanelShow', MainForm.CenterTopPanel.Visible);
inif.WriteBool ('APPLICATION', 'Autoformat', MainForm.Menu_Edit_AutoFormat.Checked);
inif.UpdateFile;
inif.Free;
end;
// открытие файлов прошлой сессии
procedure TConfig.OpenOldSessionFiles;
var
i:integer;
cnt:integer;
inif:TIniFile;
ST:TSourceText;
text_ch:boolean; // флаг изменения файла
text_nm:string; // имя файла
text_chs:string;
tmp:string;
begin
inif:=TIniFile.Create(app_conf_name);
cnt:=inif.ReadInteger('OLDSESSIONFILES', 'Count', 0);
if cnt=0 then exit;
for i:=0 to cnt-1 do
begin
text_nm:= inif.ReadString('OLDSESSIONFILES', 'file_'+inttostr(i)+'_nm', '');
text_ch:= inif.ReadBool('OLDSESSIONFILES', 'file_'+inttostr(i)+'_ch', false);
text_chs:=inif.ReadString('OLDSESSIONFILES', 'file_'+inttostr(i)+'_chs', Default_CharSet);
tmp:=Default_CharSet;
Default_CharSet:=text_chs;
ST:=EditorFiles.Open(text_nm); // откроем файл (это обязательно даже при чтении из кеша!!)
if text_ch then // файл содержал несохраненные изменения, читаем из кеша
begin
ST.OpenFile(app_path+'tmp\'+inttostr(i)); // откроем из кеша
ST.FileName:=text_nm; // реальное имя файла
ST.TextChange:=text_ch; // восстановим флаг изменений
ST.FileNamed:=inif.ReadBool('OLDSESSIONFILES', 'file_'+inttostr(i)+'_nd', false);
end;
Default_CharSet:=tmp;
EditorFiles.OpenInEditor(ST);
end;
EditorFiles.Update;
text_nm:=inif.ReadString('OLDSESSIONFILES', 'OpenInEditor', '-');
if EditorFiles.get(text_nm)<>nil then EditorFiles.OpenInEditor(text_nm);
inif.Free;
end;
// сохранение открытых файлов сессии
procedure TConfig.SaveSessionFiles;
var
cnt, i:integer;
inif:TIniFile;
ST:TSourceText;
begin
inif:=TIniFile.Create(app_conf_name);
inif.EraseSection('OLDSESSIONFILES');
i:=0;
for cnt:=0 to EditorFiles.Count-1 do
begin
ST:=EditorFiles.Get(cnt);
if (ST.OpenInEditor) and
((ST.TextChange and (not ST.FileNamed)) or ST.FileNamed) then
begin
inif.WriteString('OLDSESSIONFILES', 'file_'+inttostr(i)+'_nm', ST.FileName); // имя файла
inif.WriteString('OLDSESSIONFILES', 'file_'+inttostr(i)+'_chs', ST.CharSet); // кодировка
inif.WriteBool ('OLDSESSIONFILES', 'file_'+inttostr(i)+'_ch', ST.TextChange);// флаг изменений
inif.WriteBool ('OLDSESSIONFILES', 'file_'+inttostr(i)+'_nd', ST.FileNamed); // флаг новизны
if ST.TextChange then
begin
ST.FileName:=app_path+'tmp\'+inttostr(i);
ST.FileNamed:=true;
ST.SaveFile;
end;
i:=i+1;
end;
end;
inif.WriteInteger('OLDSESSIONFILES', 'Count', i);
inif.WriteString('OLDSESSIONFILES', 'OpenInEditor', EditorFiles.GetNameSelected);
inif.UpdateFile;
inif.Free;
end;
end.