| Revision | 7 (tree) |
|---|---|
| Time | 2018-12-17 12:29:53 |
| Author | kentamaken |
(empty log message)
| @@ -83,6 +83,8 @@ | ||
| 83 | 83 | procedure writestrings(sc:string;sl:TStrings); |
| 84 | 84 | procedure readgrid(sc:string;G:TGrid); |
| 85 | 85 | procedure writegrid(sc:string;G:TGrid); |
| 86 | + procedure readtreeview(sc:string;T:TTreeView); | |
| 87 | + procedure writetreeview(sc:string;T:TTreeView); | |
| 86 | 88 | end; |
| 87 | 89 | |
| 88 | 90 | TTextDeFindForm=class(TForm,IDropSource) |
| @@ -153,6 +155,7 @@ | ||
| 153 | 155 | procedure PathSelButtonClick(Sender: TObject); |
| 154 | 156 | procedure GridFilesSetEditText(Sender: TObject; ACol, ARow: Integer; |
| 155 | 157 | const Value: string); |
| 158 | + procedure FormClose(Sender: TObject; var Action: TCloseAction); | |
| 156 | 159 | private |
| 157 | 160 | { Private 宣言 } |
| 158 | 161 | public |
| @@ -177,10 +180,12 @@ | ||
| 177 | 180 | FMouseDownPt:TPoint; |
| 178 | 181 | SL :TStringDynArray; |
| 179 | 182 | Ini :TMemIniFile; |
| 183 | + Inifile :TMemIniFile; | |
| 180 | 184 | inidir :string; |
| 181 | 185 | pname :string; |
| 182 | 186 | |
| 183 | 187 | const |
| 188 | + MAXLIST =4096; | |
| 184 | 189 | TKNMAXLEN=1024; |
| 185 | 190 | NULLNULL =#0#0; |
| 186 | 191 | CR =#13; |
| @@ -209,9 +214,11 @@ | ||
| 209 | 214 | |
| 210 | 215 | |
| 211 | 216 | |
| 217 | + | |
| 212 | 218 | procedure TTextDeFindForm.FormCreate(Sender:TObject); |
| 213 | 219 | begin |
| 214 | - Ini:=TMemIniFile.Create(ChangeFileExt(Application.ExeName,'.INI')); | |
| 220 | + Ini:=TMemIniFile.Create(ChangeFileExt(Application.ExeName,'.ini')); | |
| 221 | + Inifile:=TMemIniFile.Create(ChangeFileExt(Application.ExeName,'.txt')); | |
| 215 | 222 | inidir:=Ini.ReadString('','inidir',inidir); |
| 216 | 223 | OpenDialog.InitialDir:=ExtractFileDir(Application.ExeName); |
| 217 | 224 | SaveDialog.InitialDir:=ExtractFileDir(Application.ExeName); |
| @@ -224,18 +231,26 @@ | ||
| 224 | 231 | Path.Text:=Ini.ReadString('','Path.Text',''); |
| 225 | 232 | Url.Text:=Ini.ReadString('','Url.Text',''); |
| 226 | 233 | Ini.readstrings('Url.Items',Url.Items); |
| 234 | + Inifile.readtreeview('Tree',Tree); | |
| 227 | 235 | |
| 228 | 236 | // Files:=GridFiles; |
| 229 | 237 | Files:=TGrid.CreateEX(GridFiles); |
| 230 | 238 | |
| 231 | - Tree.LoadFromFile(ChangeFileExt(Application.ExeName,'.txt')); | |
| 232 | - NameChange(Sender); | |
| 233 | - pname:=Name.Text; | |
| 234 | - TreeClick(Sender); | |
| 239 | + try | |
| 240 | +// Tree.LoadFromFile(ChangeFileExt(Application.ExeName,'.txt')); | |
| 241 | + NameChange(Sender); | |
| 242 | + pname:=Name.Text; | |
| 243 | + TreeClick(Sender); | |
| 244 | + except | |
| 245 | + ShowMessage('ツリーテキストを読み込めませんでした'); | |
| 246 | + Application.Terminate; | |
| 247 | + end; | |
| 235 | 248 | end; |
| 236 | 249 | |
| 237 | -procedure TTextDeFindForm.FormDestroy(Sender:TObject); | |
| 250 | +procedure TTextDeFindForm.FormClose(Sender: TObject; var Action: TCloseAction); | |
| 238 | 251 | begin |
| 252 | + if Application.Terminated then exit; | |
| 253 | + | |
| 239 | 254 | Ini.WriteInteger('','Width',Width); |
| 240 | 255 | Ini.WriteInteger('','Height',Height); |
| 241 | 256 | Ini.WriteInteger('','LeftPanel.Width',LeftPanel.Width); |
| @@ -245,11 +260,18 @@ | ||
| 245 | 260 | Ini.writestrings('Url.Items',Url.Items); |
| 246 | 261 | |
| 247 | 262 | NameChange(Sender); |
| 248 | - Tree.SaveToFile(ChangeFileExt(Application.ExeName,'.txt')); | |
| 263 | + Inifile.writetreeview('Tree',Tree); | |
| 264 | +// Tree.SaveToFile(ChangeFileExt(Application.ExeName,'.txt')); | |
| 249 | 265 | |
| 266 | + Ini.UpdateFile; | |
| 267 | + Inifile.UpdateFile; | |
| 268 | +end; | |
| 250 | 269 | |
| 251 | - Ini.UpdateFile; | |
| 270 | +procedure TTextDeFindForm.FormDestroy(Sender:TObject); | |
| 271 | +begin | |
| 272 | + | |
| 252 | 273 | Ini.Free; |
| 274 | + Inifile.Free; | |
| 253 | 275 | |
| 254 | 276 | end; |
| 255 | 277 |
| @@ -554,9 +576,9 @@ | ||
| 554 | 576 | |
| 555 | 577 | NN.DeleteChildren; |
| 556 | 578 | for s in Text.lines do |
| 557 | - Tree.Items.AddChild(NN,s); | |
| 579 | + Tree.Items.AddChild(NN,Trim(s)); | |
| 558 | 580 | |
| 559 | - Ini.writegrid('grid\'+pname,TGrid(GridFiles)); | |
| 581 | + Inifile.writegrid('grid\'+pname,TGrid(GridFiles)); | |
| 560 | 582 | end; |
| 561 | 583 | |
| 562 | 584 | end; |
| @@ -566,7 +588,7 @@ | ||
| 566 | 588 | while N<>nil do begin |
| 567 | 589 | if N.text=Name.text then begin |
| 568 | 590 | childtext(N); |
| 569 | - Ini.readgrid('grid\'+Name.text,TGrid(GridFiles)); | |
| 591 | + Inifile.readgrid('grid\'+Name.text,TGrid(GridFiles)); | |
| 570 | 592 | end; |
| 571 | 593 | N:=N.getNextSibling; |
| 572 | 594 | end; |
| @@ -602,6 +624,7 @@ | ||
| 602 | 624 | sub :boolean; |
| 603 | 625 | hit :boolean; |
| 604 | 626 | ls,le,i,j,count:integer; |
| 627 | + pathtext:string; | |
| 605 | 628 | |
| 606 | 629 | |
| 607 | 630 | function zenkaku(Str : String) : String;//半角全角 |
| @@ -679,7 +702,12 @@ | ||
| 679 | 702 | try |
| 680 | 703 | Screen.Cursor:=crHourGlass; |
| 681 | 704 | Application.ProcessMessages; |
| 682 | - Path.Text:=incbs(Path.Text); | |
| 705 | + | |
| 706 | + ls:=Text.Perform(EM_LINEFROMCHAR,Text.SelStart, 0); | |
| 707 | + pathtext:=Path.Text; | |
| 708 | + pathtext:=pathtext.Replace('%リスト名%',Name.text); | |
| 709 | + pathtext:=pathtext.Replace('%検索文字%',Text.lines[ls]); | |
| 710 | + pathtext:=incbs(pathtext); | |
| 683 | 711 | // snm:=ExtractFileName(Path.Text); |
| 684 | 712 | // if snm='' then |
| 685 | 713 | snm:='*'; |
| @@ -688,7 +716,7 @@ | ||
| 688 | 716 | op:=TSearchOption.soAllDirectories; |
| 689 | 717 | // else |
| 690 | 718 | // op := TSearchOption.soTopDirectoryOnly; |
| 691 | - SA:=TDirectory.GetFiles(Path.Text,snm,op); | |
| 719 | + SA:=TDirectory.GetFiles(PathText,snm,op); | |
| 692 | 720 | Files.RowCount:=1; |
| 693 | 721 | Files.ColCount:=4; |
| 694 | 722 | Files.Rows[0].setstrings(['','検索文字','ファイル','パス']); |
| @@ -696,7 +724,7 @@ | ||
| 696 | 724 | if sender=Find then begin |
| 697 | 725 | ls:=0; |
| 698 | 726 | le:=Text.Lines.Count-1; |
| 699 | - | |
| 727 | + | |
| 700 | 728 | end else begin |
| 701 | 729 | ls:=Text.Perform(EM_LINEFROMCHAR,Text.SelStart, 0); |
| 702 | 730 | le:=Text.Perform(EM_LINEFROMCHAR,Text.SelStart+Text.SelLength-1*integer(Text.SelLength>0),0); |
| @@ -1304,13 +1332,13 @@ | ||
| 1304 | 1332 | G.rows[y].clear; |
| 1305 | 1333 | end); |
| 1306 | 1334 | G.rowcount:=1; |
| 1307 | - for y:=0 to 1024 do begin | |
| 1335 | + for y:=0 to MAXLIST do begin | |
| 1308 | 1336 | for x:=0 to G.ColCount-1 do begin |
| 1309 | 1337 | s:=inttostr(y)+','+inttostr(x); |
| 1310 | - if not ini.ValueExists(sc,s) then break; | |
| 1338 | + if not ValueExists(sc,s) then break; | |
| 1311 | 1339 | if x>=G.colcount then G.colcount:=x+1; |
| 1312 | 1340 | if y>=G.rowcount then G.rowcount:=y+1; |
| 1313 | - G.cells[x,y]:=Ini.ReadString(sc,inttostr(y)+','+inttostr(x),''); | |
| 1341 | + G.cells[x,y]:=ReadString(sc,inttostr(y)+','+inttostr(x),''); | |
| 1314 | 1342 | end; |
| 1315 | 1343 | end; |
| 1316 | 1344 | if G.rowcount<2 then G.rowcount:=2; |
| @@ -1321,11 +1349,11 @@ | ||
| 1321 | 1349 | |
| 1322 | 1350 | procedure TMemIniFileHelper.writegrid(sc: string; G: TGrid); |
| 1323 | 1351 | begin |
| 1324 | - Ini.EraseSection(sc); | |
| 1352 | + EraseSection(sc); | |
| 1325 | 1353 | G.alldo(procedure(X,Y:Integer)begin |
| 1326 | - Ini.WriteString(sc,inttostr(y)+','+inttostr(x),G.cells[x,y]); | |
| 1354 | + WriteString(sc,inttostr(y)+','+inttostr(x),G.cells[x,y]); | |
| 1327 | 1355 | end); |
| 1328 | - | |
| 1356 | + | |
| 1329 | 1357 | end; |
| 1330 | 1358 | |
| 1331 | 1359 | procedure TMemIniFileHelper.readstrings(sc: string; sl:TStrings); |
| @@ -1332,22 +1360,76 @@ | ||
| 1332 | 1360 | var i:integer; |
| 1333 | 1361 | s:string; |
| 1334 | 1362 | begin |
| 1335 | - if ini.SectionExists(sc) then sl.clear; | |
| 1336 | - for i:=0 to 1024 do begin | |
| 1337 | - if not ini.ValueExists(sc,inttostr(i)) then break; | |
| 1338 | - sl.add(Ini.ReadString(sc,inttostr(i),'')); | |
| 1363 | + if SectionExists(sc) then sl.clear; | |
| 1364 | + for i:=0 to MAXLIST do begin | |
| 1365 | + if not ValueExists(sc,inttostr(i)) then break; | |
| 1366 | + sl.add(ReadString(sc,inttostr(i),'')); | |
| 1339 | 1367 | end; |
| 1340 | 1368 | end; |
| 1341 | 1369 | |
| 1342 | 1370 | |
| 1371 | + | |
| 1343 | 1372 | procedure TMemIniFileHelper.writestrings(sc: string; sl: TStrings); |
| 1344 | 1373 | var i:integer; |
| 1345 | 1374 | begin |
| 1346 | - Ini.EraseSection(sc); | |
| 1375 | + EraseSection(sc); | |
| 1347 | 1376 | for i:=0 to sl.Count-1 do |
| 1348 | - Ini.WriteString(sc,inttostr(i),sl[i]); | |
| 1377 | + WriteString(sc,inttostr(i),sl[i]); | |
| 1349 | 1378 | end; |
| 1350 | 1379 | |
| 1380 | +procedure TMemIniFileHelper.readtreeview(sc: string; T: TTreeView); | |
| 1381 | +var | |
| 1382 | + N:TTreeNode; | |
| 1383 | + i:integer; | |
| 1384 | + procedure sub(key:string;N:TTreeNode); | |
| 1385 | + var i:integer; | |
| 1386 | + k:string; | |
| 1387 | + begin | |
| 1388 | + for i:=0 to MAXLIST do begin | |
| 1389 | + k:=key+','+inttostr(i); | |
| 1390 | + if not ValueExists(sc,k) then break; | |
| 1391 | + T.Items.AddChild(N,ReadString(sc,k,'')); | |
| 1392 | + sub(k,N); | |
| 1393 | + end; | |
| 1394 | + end; | |
| 1395 | +begin | |
| 1396 | + if SectionExists(sc) then T.Items.clear; | |
| 1397 | + for i:=0 to MAXLIST do begin | |
| 1398 | + if not ValueExists(sc,inttostr(i)) then break; | |
| 1399 | + N:=T.Items.Add(nil,ReadString(sc,inttostr(i),'')); | |
| 1400 | + sub(inttostr(i),N); | |
| 1401 | + end; | |
| 1402 | + | |
| 1403 | +end; | |
| 1404 | + | |
| 1405 | +procedure TMemIniFileHelper.writetreeview(sc: string; T: TTreeView); | |
| 1406 | +var | |
| 1407 | + N:TTreeNode; | |
| 1408 | + i:integer; | |
| 1409 | + procedure sub(key: string;N:TTreeNode); | |
| 1410 | + var i:integer; | |
| 1411 | + begin | |
| 1412 | + N:=N.getFirstChild; | |
| 1413 | + i:=0; | |
| 1414 | + while N<>nil do begin | |
| 1415 | + WriteString(sc,key+','+inttostr(N.index),N.text); | |
| 1416 | + sub(sc,N); | |
| 1417 | + N:=N.getNextSibling; | |
| 1418 | + inc(i); | |
| 1419 | + end; | |
| 1420 | + end; | |
| 1421 | +begin | |
| 1422 | + EraseSection(sc); | |
| 1423 | + i:=0; | |
| 1424 | + N:=T.Items.GetFirstNode; | |
| 1425 | + while N<>nil do begin | |
| 1426 | + WriteString(sc,inttostr(N.index),N.text); | |
| 1427 | + sub(inttostr(N.index),N); | |
| 1428 | + N:=N.getNextSibling; | |
| 1429 | + inc(i); | |
| 1430 | + end; | |
| 1431 | +end; | |
| 1432 | + | |
| 1351 | 1433 | initialization |
| 1352 | 1434 | |
| 1353 | 1435 | SHGetMalloc(Malloc); |