リビジョン | 5 (tree) |
---|---|
日時 | 2018-12-11 20:29:21 |
作者 | kentamaken |
GRID保存
@@ -15,10 +15,6 @@ | ||
15 | 15 | function this:TStringList; |
16 | 16 | end; |
17 | 17 | |
18 | - TIniFileHelper=class helper for TInifile | |
19 | - procedure readstrings(sc:string;sl:TStrings); | |
20 | - procedure writestrings(sc:string;sl:TStrings); | |
21 | - end; | |
22 | 18 | |
23 | 19 | TStringsHelper=class helper for TStrings |
24 | 20 | function setstrings(sa:TStringDynArray):Integer; |
@@ -41,7 +37,6 @@ | ||
41 | 37 | end; |
42 | 38 | |
43 | 39 | TGrid=class(TStringGrid) |
44 | - | |
45 | 40 | type |
46 | 41 | TFuncXY=reference to procedure(X,Y:Integer); |
47 | 42 |
@@ -52,6 +47,8 @@ | ||
52 | 47 | procedure MouseDown(Button:TMouseButton;Shift:TShiftState;X,Y:Integer);override; |
53 | 48 | procedure MouseMove(Shift:TShiftState;X,Y:Integer);override; |
54 | 49 | |
50 | + procedure SetEditText(ACol, ARow: Integer; const Value: string);override; | |
51 | + | |
55 | 52 | function DoMouseWheelDown(Shift:TShiftState;MousePos:TPoint):boolean;override; |
56 | 53 | function DoMouseWheelUp(Shift:TShiftState;MousePos:TPoint):boolean;override; |
57 | 54 | function ColExpand(min:Integer):Integer; |
@@ -67,7 +64,9 @@ | ||
67 | 64 | procedure cutcopy(modecut:boolean); |
68 | 65 | function paste:TGridRect; |
69 | 66 | function selrowdo(func:TFuncXY):Integer; |
67 | + function rowdo(func:TFuncXY):Integer; | |
70 | 68 | function seldo(func:TFuncXY):Integer; |
69 | + function alldo(func:TFuncXY):Integer; | |
71 | 70 | procedure copy(G:TGrid); |
72 | 71 | procedure savebuf; |
73 | 72 | procedure seldel; |
@@ -79,6 +78,12 @@ | ||
79 | 78 | property InplaceEditor; |
80 | 79 | end; |
81 | 80 | |
81 | + TMemIniFileHelper=class helper for TMemInifile | |
82 | + procedure readstrings(sc:string;sl:TStrings); | |
83 | + procedure writestrings(sc:string;sl:TStrings); | |
84 | + procedure readgrid(sc:string;G:TGrid); | |
85 | + procedure writegrid(sc:string;G:TGrid); | |
86 | + end; | |
82 | 87 | |
83 | 88 | TTextDeFindForm=class(TForm,IDropSource) |
84 | 89 | Panel1:TPanel; |
@@ -101,22 +106,23 @@ | ||
101 | 106 | TMP:TComboBox; |
102 | 107 | SaveDialog:TSaveDialog; |
103 | 108 | OpenDialog:TOpenDialog; |
104 | - LeftPanel: TPanel; | |
109 | + LeftPanel: TPanel; | |
105 | 110 | Name: TComboBox; |
106 | 111 | Text: TRichEdit; |
107 | 112 | Tree: TTreeView; |
108 | 113 | Button1: TButton; |
109 | 114 | Splitter1: TSplitter; |
110 | - PFileExec: TMenuItem; | |
111 | - PFileFolder: TMenuItem; | |
112 | - Panel3: TPanel; | |
113 | - Url: TComboBox; | |
114 | - FindUrlButton: TButton; | |
115 | - UrlEditButton: TButton; | |
116 | - PathEditButton: TButton; | |
117 | - PTextFind: TMenuItem; | |
118 | - PTextFindUrl: TMenuItem; | |
119 | - N1: TMenuItem; | |
115 | + PFileExec: TMenuItem; | |
116 | + PFileFolder: TMenuItem; | |
117 | + Panel3: TPanel; | |
118 | + Url: TComboBox; | |
119 | + FindUrlButton: TButton; | |
120 | + UrlEditButton: TButton; | |
121 | + PathEditButton: TButton; | |
122 | + PTextFind: TMenuItem; | |
123 | + PTextFindUrl: TMenuItem; | |
124 | + N1: TMenuItem; | |
125 | + PathSelButton: TButton; | |
120 | 126 | procedure FindClick(Sender:TObject); |
121 | 127 | procedure FormCreate(Sender:TObject); |
122 | 128 | procedure GridFilesMouseDown(Sender:TObject;Button:TMouseButton; |
@@ -135,7 +141,7 @@ | ||
135 | 141 | procedure NameChange(Sender: TObject); |
136 | 142 | procedure TreeClick(Sender: TObject); |
137 | 143 | procedure Button1Click(Sender: TObject); |
138 | - procedure PFileFolderClick(Sender: TObject); | |
144 | + procedure PFileFolderClick(Sender: TObject); | |
139 | 145 | procedure PFileExecClick(Sender: TObject); |
140 | 146 | procedure FindUrlButtonClick(Sender: TObject); |
141 | 147 | procedure TextMouseUp(Sender: TObject; Button: TMouseButton; |
@@ -144,6 +150,9 @@ | ||
144 | 150 | procedure PathEditButtonClick(Sender: TObject); |
145 | 151 | procedure PTextFindClick(Sender: TObject); |
146 | 152 | procedure PTextFindUrlClick(Sender: TObject); |
153 | + procedure PathSelButtonClick(Sender: TObject); | |
154 | + procedure GridFilesSetEditText(Sender: TObject; ACol, ARow: Integer; | |
155 | + const Value: string); | |
147 | 156 | private |
148 | 157 | { Private 宣言 } |
149 | 158 | public |
@@ -161,13 +170,13 @@ | ||
161 | 170 | |
162 | 171 | implementation |
163 | 172 | |
164 | -uses strutils,IOUtils,masks,clipbrd,SHELLAPI; | |
173 | +uses strutils,IOUtils,masks,clipbrd,SHELLAPI,Vcl.FileCtrl; | |
165 | 174 | |
166 | 175 | var |
167 | 176 | Malloc :IMalloc; |
168 | 177 | FMouseDownPt:TPoint; |
169 | 178 | SL :TStringDynArray; |
170 | - Ini :TIniFile; | |
179 | + Ini :TMemIniFile; | |
171 | 180 | inidir :string; |
172 | 181 | pname :string; |
173 | 182 |
@@ -182,7 +191,7 @@ | ||
182 | 191 | CFILE =2; |
183 | 192 | CPATH =3; |
184 | 193 | var |
185 | - CHEAD:TStringDynArray =['','テキスト','ファイル','パス']; | |
194 | + CHEAD:TStringDynArray =['','検索文字','ファイル','パス']; | |
186 | 195 | |
187 | 196 | {$R *.dfm} |
188 | 197 |
@@ -202,7 +211,7 @@ | ||
202 | 211 | |
203 | 212 | procedure TTextDeFindForm.FormCreate(Sender:TObject); |
204 | 213 | begin |
205 | - Ini:=TIniFile.Create(ChangeFileExt(Application.ExeName,'.INI')); | |
214 | + Ini:=TMemIniFile.Create(ChangeFileExt(Application.ExeName,'.INI')); | |
206 | 215 | inidir:=Ini.ReadString('','inidir',inidir); |
207 | 216 | OpenDialog.InitialDir:=ExtractFileDir(Application.ExeName); |
208 | 217 | SaveDialog.InitialDir:=ExtractFileDir(Application.ExeName); |
@@ -220,7 +229,6 @@ | ||
220 | 229 | Files:=TGrid.CreateEX(GridFiles); |
221 | 230 | |
222 | 231 | Tree.LoadFromFile(ChangeFileExt(Application.ExeName,'.txt')); |
223 | - files.Load(ChangeFileExt(Application.ExeName,'.csv')); | |
224 | 232 | NameChange(Sender); |
225 | 233 | pname:=Name.Text; |
226 | 234 | TreeClick(Sender); |
@@ -235,12 +243,14 @@ | ||
235 | 243 | Ini.WriteString('','Path.Text',Path.Text); |
236 | 244 | Ini.WriteString('','Url.Text',Url.Text); |
237 | 245 | Ini.writestrings('Url.Items',Url.Items); |
238 | - Ini.Free; | |
239 | 246 | |
240 | 247 | NameChange(Sender); |
241 | 248 | Tree.SaveToFile(ChangeFileExt(Application.ExeName,'.txt')); |
242 | - files.save(ChangeFileExt(Application.ExeName,'.csv')); | |
243 | 249 | |
250 | + | |
251 | + Ini.UpdateFile; | |
252 | + Ini.Free; | |
253 | + | |
244 | 254 | end; |
245 | 255 | |
246 | 256 |
@@ -401,6 +411,14 @@ | ||
401 | 411 | end; |
402 | 412 | |
403 | 413 | |
414 | +procedure TTextDeFindForm.GridFilesSetEditText(Sender: TObject; ACol, | |
415 | + ARow: Integer; const Value: string); | |
416 | +begin | |
417 | +// ShowMessage(Value); | |
418 | +// GridFiles.Options:=GridFiles.Options-[goEditing]+[goRangeSelect]; | |
419 | + | |
420 | +end; | |
421 | + | |
404 | 422 | procedure TTextDeFindForm.TextMouseUp(Sender: TObject; Button: TMouseButton; |
405 | 423 | Shift: TShiftState; X, Y: Integer); |
406 | 424 | var l:integer; |
@@ -476,6 +494,16 @@ | ||
476 | 494 | end; |
477 | 495 | |
478 | 496 | |
497 | +procedure TTextDeFindForm.PathSelButtonClick(Sender: TObject); | |
498 | +var | |
499 | + SelectFolder : String; | |
500 | +begin | |
501 | + SelectFolder := Path.text; | |
502 | + if SelectDirectory(Path.text,'',SelectFolder,[sdNewUI, sdNewFolder, sdShowEdit],Self) then begin | |
503 | + Path.text:=SelectFolder; | |
504 | + end; | |
505 | +end; | |
506 | + | |
479 | 507 | procedure TTextDeFindForm.UrlEditButtonClick(Sender: TObject); |
480 | 508 | begin |
481 | 509 | Url.Items.Text:=inputtextbox(self,Url,Url.Items.Text); |
@@ -528,6 +556,7 @@ | ||
528 | 556 | for s in Text.lines do |
529 | 557 | Tree.Items.AddChild(NN,s); |
530 | 558 | |
559 | + Ini.writegrid('grid\'+pname,TGrid(GridFiles)); | |
531 | 560 | end; |
532 | 561 | |
533 | 562 | end; |
@@ -537,6 +566,7 @@ | ||
537 | 566 | while N<>nil do begin |
538 | 567 | if N.text=Name.text then begin |
539 | 568 | childtext(N); |
569 | + Ini.readgrid('grid\'+Name.text,TGrid(GridFiles)); | |
540 | 570 | end; |
541 | 571 | N:=N.getNextSibling; |
542 | 572 | end; |
@@ -694,39 +724,33 @@ | ||
694 | 724 | |
695 | 725 | function TTextDeFindForm.GetFilePathDataObject(G:TStringGrid):IDataObject; |
696 | 726 | var |
697 | - fDesktop,fTargetFolder:IShellFolder; | |
698 | - Filepidl :packed array of PItemIDList; | |
699 | - Dirpidl :PItemIDList; | |
727 | + ISFD,ISF:IShellFolder; | |
728 | + PItems :packed array of PItemIDList; | |
729 | + PItem :PItemIDList; | |
700 | 730 | pchEaten,dwAttributes :Cardinal; |
701 | - Dir,FileName :Widestring; | |
702 | - i,r,count :Integer; | |
703 | - SourceFile :string; | |
731 | + fn,fnpath :Widestring; | |
732 | + i,count :Integer; | |
704 | 733 | begin |
705 | 734 | Result:=nil; |
735 | + count:=0; | |
706 | 736 | |
707 | - count:=G.selection.Bottom-G.selection.top+1; | |
708 | - SetLength(Filepidl,count); | |
709 | - SHGetDesktopFolder(fDesktop); | |
710 | - if Failed(fDesktop.ParseDisplayName(0,nil,PWideChar(Path.text),pchEaten,Dirpidl,dwAttributes)) then exit; | |
711 | - if Failed(fDesktop.BindToObject(Dirpidl,nil,IID_IShellFolder,fTargetFolder)) then exit; | |
737 | + SHGetDesktopFolder(ISFD); | |
738 | + if Failed(ISFD.ParseDisplayName(0,nil,PWideChar(Path.text),pchEaten,PItem,dwAttributes)) then exit; | |
739 | + if Failed(ISFD.BindToObject(PItem,nil,IID_IShellFolder,ISF)) then exit; | |
712 | 740 | |
741 | + for i:=G.selection.top to G.selection.Bottom do begin | |
742 | + fn:=INCBS(G.cells[CPATH,i])+G.cells[CFILE,i]; | |
713 | 743 | |
714 | - for i:=0 to count-1 do begin | |
715 | - r:=i+G.selection.top; | |
744 | + if not FileExists(fn) then continue; | |
745 | + inc(count); | |
746 | + SetLength(PItems,count); | |
747 | + fnpath:=ExtractRelativePath(INCBS(Path.text),fn); | |
716 | 748 | |
717 | - SourceFile:=INCBS(G.cells[CPATH,r])+G.cells[CFILE,r]; | |
718 | - if not FileExists(SourceFile) then exit; | |
719 | - | |
720 | - Dir:=ExtractFileDir(SourceFile); | |
721 | - FileName:=ExtractRelativePath(INCBS(Path.text),SourceFile); | |
722 | - | |
723 | - if Failed(fTargetFolder.ParseDisplayName(0,nil,PWideChar(FileName),pchEaten,Filepidl[i],dwAttributes)) then exit; | |
724 | - | |
749 | + if Failed(ISF.ParseDisplayName(0,nil,PWideChar(fnpath),pchEaten,PItems[count-1],dwAttributes)) then exit; | |
725 | 750 | end; |
726 | - | |
727 | 751 | if count<1 then exit; |
728 | 752 | |
729 | - fTargetFolder.GetUIObjectOf(0,count,Filepidl[0],IDataObject,nil,Pointer(Result)); | |
753 | + ISF.GetUIObjectOf(0,count,PItems[0],IDataObject,nil,Pointer(Result)); | |
730 | 754 | end; |
731 | 755 | |
732 | 756 |
@@ -960,6 +984,14 @@ | ||
960 | 984 | for j:=selection.left to selection.right do func(j,i); |
961 | 985 | end; |
962 | 986 | |
987 | +function TGrid.alldo(func:TFuncXY):Integer; | |
988 | +var | |
989 | + i,j:Integer; | |
990 | +begin | |
991 | + for i:=0 to rowcount-1 do | |
992 | + for j:=0 to colcount-1 do func(j,i); | |
993 | +end; | |
994 | + | |
963 | 995 | function TGrid.selrowdo(func:TFuncXY):Integer; |
964 | 996 | var |
965 | 997 | i:Integer; |
@@ -967,6 +999,21 @@ | ||
967 | 999 | for i:=selection.top to selection.Bottom do func(0,i); |
968 | 1000 | end; |
969 | 1001 | |
1002 | +procedure TGrid.SetEditText(ACol, ARow: Integer; | |
1003 | + const Value: string); | |
1004 | +begin | |
1005 | + inherited; | |
1006 | + Options:=Options-[goEditing]+[goRangeSelect]; | |
1007 | +end; | |
1008 | + | |
1009 | +function TGrid.rowdo(func: TFuncXY): Integer; | |
1010 | +var | |
1011 | + i:Integer; | |
1012 | +begin | |
1013 | + for i:=0 to rowcount-1 do func(0,i); | |
1014 | + | |
1015 | +end; | |
1016 | + | |
970 | 1017 | procedure TGrid.KeyDown(var Key:Word;Shift:TShiftState); |
971 | 1018 | var |
972 | 1019 | w:Word; |
@@ -995,6 +1042,12 @@ | ||
995 | 1042 | begin |
996 | 1043 | MouseToCell(X,Y,ACol,ARow); |
997 | 1044 | downinselection:=gridInRect(ACol,ARow,selection); |
1045 | + if ssDouble in Shift then begin | |
1046 | + Options:=Options+[goEditing]-[goRangeSelect]; | |
1047 | + Col:=ACol; | |
1048 | + Row:=ARow; | |
1049 | + EditorMode:=true; | |
1050 | + end; | |
998 | 1051 | if downinselection then exit; |
999 | 1052 | |
1000 | 1053 | // Options:=Options-[goEditing]+[goRangeSelect]; |
@@ -1116,6 +1169,7 @@ | ||
1116 | 1169 | RowCount:=w; |
1117 | 1170 | end; |
1118 | 1171 | |
1172 | + | |
1119 | 1173 | function TGrid.RowInsert(Y,cnt:Integer):Integer; |
1120 | 1174 | var |
1121 | 1175 | i :Integer; |
@@ -1238,25 +1292,55 @@ | ||
1238 | 1292 | for i:=0 to sa.Count-1 do |
1239 | 1293 | if i<Count then |
1240 | 1294 | Self[i]:=sa[i]; |
1295 | +end; | |
1241 | 1296 | |
1297 | +{ TIniFileHelper } | |
1242 | 1298 | |
1299 | +procedure TMemIniFileHelper.readgrid(sc: string; G: TGrid); | |
1300 | +var x,y:integer; | |
1301 | + s:string; | |
1302 | +begin | |
1303 | + G.rowdo(procedure(X,Y:Integer)begin | |
1304 | + G.rows[y].clear; | |
1305 | + end); | |
1306 | + G.rowcount:=1; | |
1307 | + for y:=0 to 1024 do begin | |
1308 | + for x:=0 to G.ColCount-1 do begin | |
1309 | + s:=inttostr(y)+','+inttostr(x); | |
1310 | + if not ini.ValueExists(sc,s) then break; | |
1311 | + if x>=G.colcount then G.colcount:=x+1; | |
1312 | + if y>=G.rowcount then G.rowcount:=y+1; | |
1313 | + G.cells[x,y]:=Ini.ReadString(sc,inttostr(y)+','+inttostr(x),''); | |
1314 | + end; | |
1315 | + end; | |
1316 | + if G.rowcount<2 then G.rowcount:=2; | |
1317 | + G.fixedrows:=1; | |
1318 | + G.Rows[0].setstrings(CHEAD); | |
1319 | + G.ColExpand(10); | |
1243 | 1320 | end; |
1244 | 1321 | |
1245 | -{ TIniFileHelper } | |
1322 | +procedure TMemIniFileHelper.writegrid(sc: string; G: TGrid); | |
1323 | +begin | |
1324 | + Ini.EraseSection(sc); | |
1325 | + G.alldo(procedure(X,Y:Integer)begin | |
1326 | + Ini.WriteString(sc,inttostr(y)+','+inttostr(x),G.cells[x,y]); | |
1327 | + end); | |
1328 | + | |
1329 | +end; | |
1246 | 1330 | |
1247 | -procedure TIniFileHelper.readstrings(sc: string; sl:TStrings); | |
1331 | +procedure TMemIniFileHelper.readstrings(sc: string; sl:TStrings); | |
1248 | 1332 | var i:integer; |
1249 | 1333 | s:string; |
1250 | 1334 | begin |
1251 | 1335 | sl.Clear; |
1252 | 1336 | for i:=0 to 1024 do begin |
1253 | - if not ini.ValueExists(sc,inttostr(i)) then | |
1254 | - break; | |
1337 | + if not ini.ValueExists(sc,inttostr(i)) then break; | |
1255 | 1338 | sl.add(Ini.ReadString(sc,inttostr(i),'')); |
1256 | 1339 | end; |
1257 | 1340 | end; |
1258 | 1341 | |
1259 | -procedure TIniFileHelper.writestrings(sc: string; sl: TStrings); | |
1342 | + | |
1343 | +procedure TMemIniFileHelper.writestrings(sc: string; sl: TStrings); | |
1260 | 1344 | var i:integer; |
1261 | 1345 | begin |
1262 | 1346 | Ini.EraseSection(sc); |