Revision | 14 (tree) |
---|---|
Zeit | 2014-09-01 01:17:05 |
Autor | twm |
* drag and drop for files
* autocomplete for filenames
@@ -52,9 +52,8 @@ | ||
52 | 52 | <DCC_DebugInformation>false</DCC_DebugInformation> |
53 | 53 | </PropertyGroup> |
54 | 54 | <PropertyGroup Condition="'$(Cfg_2)'!=''"> |
55 | - <DCC_ConsoleTarget>true</DCC_ConsoleTarget> | |
56 | 55 | <DCC_Optimize>false</DCC_Optimize> |
57 | - <DCC_Define>DEBUG;dzMESSAGEDEBUG;$(DCC_Define)</DCC_Define> | |
56 | + <DCC_Define>DEBUG;$(DCC_Define)</DCC_Define> | |
58 | 57 | </PropertyGroup> |
59 | 58 | <ItemGroup> |
60 | 59 | <DelphiCompile Include="dzIniFileFormatter.dpr"> |
@@ -13,11 +13,13 @@ | ||
13 | 13 | Forms, |
14 | 14 | StdCtrls, |
15 | 15 | ComCtrls, |
16 | + ExtCtrls, | |
16 | 17 | u_dzTranslator, |
17 | 18 | u_IniFileFormatterConfig; |
18 | 19 | |
19 | 20 | type |
20 | 21 | Tf_IniFileFormatter = class(TForm) |
22 | + p_Filename: TPanel; | |
21 | 23 | l_Filename: TLabel; |
22 | 24 | ed_Filename: TEdit; |
23 | 25 | b_Filename: TButton; |
@@ -39,6 +41,7 @@ | ||
39 | 41 | rb_ItemsByTemplate: TRadioButton; |
40 | 42 | b_Close: TButton; |
41 | 43 | b_SaveAs: TButton; |
44 | + p_TemplateFile: TPanel; | |
42 | 45 | l_Template: TLabel; |
43 | 46 | ed_Template: TEdit; |
44 | 47 | b_Template: TButton; |
@@ -54,8 +57,14 @@ | ||
54 | 57 | procedure b_TemplateClick(Sender: TObject); |
55 | 58 | procedure b_AboutClick(Sender: TObject); |
56 | 59 | procedure b_ConfigureClick(Sender: TObject); |
60 | + procedure ed_FilenameChange(Sender: TObject); | |
61 | + procedure ed_TemplateChange(Sender: TObject); | |
57 | 62 | private |
58 | 63 | FFileComparer: string; |
64 | + FFnAutoComplete: TObject; | |
65 | + FFnDropFiles: TObject; | |
66 | + FTemplateAutoComplete: TObject; | |
67 | + FTemplateDropFiles: TObject; | |
59 | 68 | procedure LoadAndSort(const _Filename: string); |
60 | 69 | function FormatIni: Boolean; |
61 | 70 | procedure ReadConfig(_cfg: TIniFileFormatterConfig); |
@@ -62,6 +71,8 @@ | ||
62 | 71 | procedure ConfigToForm(_cfg: TIniFileFormatterConfig); |
63 | 72 | procedure WriteConfig(cfg: TIniFileFormatterConfig); |
64 | 73 | procedure FormToConfig(_cfg: TIniFileFormatterConfig); |
74 | + procedure OnDropInputFiles(_Sender: TObject; _Files: TStrings); | |
75 | + procedure OnDropTemplateFiles(_Sender: TObject; _Files: TStrings); | |
65 | 76 | public |
66 | 77 | constructor Create(_Owner: TComponent); override; |
67 | 78 | destructor Destroy; override; |
@@ -79,6 +90,7 @@ | ||
79 | 90 | uses |
80 | 91 | u_dzIniFileFormatter, |
81 | 92 | u_dzIniSections, |
93 | + u_dzFileUtils, | |
82 | 94 | u_dzVclUtils, |
83 | 95 | u_dzClassUtils, |
84 | 96 | u_dzDialogUtils, |
@@ -105,6 +117,14 @@ | ||
105 | 117 | finally |
106 | 118 | FreeAndNil(cfg); |
107 | 119 | end; |
120 | + | |
121 | + p_Filename.BevelOuter := bvNone; | |
122 | + FFnAutoComplete := TEdit_AutoComplete(ed_Filename, [acsFileSystem], [actSuggest]); | |
123 | + FFnDropFiles := TWinControl_ActivateDropFiles(p_Filename, OnDropInputFiles); | |
124 | + | |
125 | + p_TemplateFile.BevelOuter := bvNone; | |
126 | + FTemplateAutoComplete := TEdit_AutoComplete(ed_Template, [acsFileSystem], [actSuggest]); | |
127 | + FTemplateDropFiles := TWinControl_ActivateDropFiles(p_TemplateFile, OnDropTemplateFiles); | |
108 | 128 | end; |
109 | 129 | |
110 | 130 | destructor Tf_IniFileFormatter.Destroy; |
@@ -122,6 +142,35 @@ | ||
122 | 142 | inherited; |
123 | 143 | end; |
124 | 144 | |
145 | +procedure Tf_IniFileFormatter.ed_FilenameChange(Sender: TObject); | |
146 | +var | |
147 | + fn: string; | |
148 | +begin | |
149 | + fn := ed_Filename.Text; | |
150 | + if not TFileSystem.FileExists(fn) then | |
151 | + Exit; | |
152 | + LoadAndSort(fn); | |
153 | +end; | |
154 | + | |
155 | +procedure Tf_IniFileFormatter.ed_TemplateChange(Sender: TObject); | |
156 | +begin | |
157 | + FormatIni; | |
158 | +end; | |
159 | + | |
160 | +procedure Tf_IniFileFormatter.OnDropInputFiles(_Sender: TObject; _Files: TStrings); | |
161 | +begin | |
162 | + if _Files.Count < 1 then | |
163 | + Exit; | |
164 | + ed_Filename.Text := _Files[0]; | |
165 | +end; | |
166 | + | |
167 | +procedure Tf_IniFileFormatter.OnDropTemplateFiles(_Sender: TObject; _Files: TStrings); | |
168 | +begin | |
169 | + if _Files.Count < 1 then | |
170 | + Exit; | |
171 | + ed_Template.Text := _Files[0]; | |
172 | +end; | |
173 | + | |
125 | 174 | procedure Tf_IniFileFormatter.FormToConfig(_cfg: TIniFileFormatterConfig); |
126 | 175 | begin |
127 | 176 | if rb_SectionsAlpha.Checked then |
@@ -216,7 +265,6 @@ | ||
216 | 265 | if not TOpenDialog_Execute(Self, _('Select template file'), FileFilterBuilder().AddIni.Filter, fn) then |
217 | 266 | Exit; |
218 | 267 | ed_Template.Text := fn; |
219 | - FormatIni; | |
220 | 268 | end; |
221 | 269 | |
222 | 270 | procedure Tf_IniFileFormatter.b_SaveAsClick(Sender: TObject); |
@@ -311,19 +359,22 @@ | ||
311 | 359 | SortTemplate: TStringList; |
312 | 360 | Sections: TStringList; |
313 | 361 | s: string; |
362 | + fn: string; | |
314 | 363 | begin |
315 | 364 | Result := False; |
316 | 365 | |
317 | 366 | Template := nil; |
318 | 367 | |
319 | - if ed_Template.Text = '' then | |
320 | - m_Template.Lines.Clear | |
321 | - else | |
368 | + fn := ed_Template.Text; | |
369 | + if (fn = '') or not TFileSystem.FileExists(fn) then begin | |
370 | + fn := ''; | |
371 | + m_Template.Lines.Clear; | |
372 | + end else | |
322 | 373 | m_Template.Lines.LoadFromFile(ed_Template.Text); |
323 | 374 | |
324 | 375 | b := rb_SectionsByTemplate.Checked or rb_ItemsByTemplate.Checked; |
325 | 376 | if b then begin |
326 | - if (ed_Template.Text = '') then begin | |
377 | + if fn = '' then begin | |
327 | 378 | m_Preview.Lines.Clear; |
328 | 379 | Exit; |
329 | 380 | end; |