uimagelist.pas 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  1. // SPDX-License-Identifier: GPL-3.0-only
  2. unit uimagelist;
  3. {$mode objfpc}{$H+}
  4. interface
  5. uses
  6. Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
  7. Grids, StdCtrls, Buttons, ComCtrls, ExtCtrls, Menus, UImageObservation,
  8. LazPaintType, UResourceStrings, UConfig, BGRAImageList, ubrowseimages,
  9. UScripting;
  10. type
  11. String1D= array of string;
  12. { TFImageList }
  13. TFImageList = class(TForm)
  14. ImageList1: TBGRAImageList;
  15. lblStatus: TLabel;
  16. pmAutouncheckOnOpen: TMenuItem;
  17. pmAutouncheckOnSave: TMenuItem;
  18. pmUncheckNonexistent: TMenuItem;
  19. pmRemoveAll: TMenuItem;
  20. pmRemoveNonexistent: TMenuItem;
  21. pmRemoveUnchecked: TMenuItem;
  22. OpenDialog1: TOpenDialog;
  23. pnlButtonsSmallWindow: TPanel;
  24. pnlButtonsNormalWindow: TPanel;
  25. pmRemove: TPopupMenu;
  26. pmUncheck: TPopupMenu;
  27. pmAutouncheck: TPopupMenu;
  28. StringGrid1: TStringGrid;
  29. tbAutoZoomFit: TToolButton;
  30. tbOpenNextSW: TToolButton;
  31. tbNormalWindows: TToolButton;
  32. tbOpenPrevSW: TToolButton;
  33. tbUncheckDropDown: TToolButton;
  34. tbRemoveItem: TToolButton;
  35. tbOpenPrev: TToolButton;
  36. tbMiniWindow: TToolButton;
  37. tbSeparator2: TToolButton;
  38. tbSeparator3: TToolButton;
  39. tbAutoUncheck: TToolButton;
  40. tbUncheckAll: TToolButton;
  41. tbCheckAll: TToolButton;
  42. tbOpenNext: TToolButton;
  43. tbOpenImage: TToolButton;
  44. tbButtonsNormalWindows: TToolBar;
  45. tbAddFiles: TToolButton;
  46. tbSeparator0: TToolButton;
  47. tbButtonsSmallWindow: TToolBar;
  48. tbMoveDown: TToolButton;
  49. tbMoveUp: TToolButton;
  50. tbRemoveDropDown: TToolButton;
  51. tbAutoUncheckDropDown: TToolButton;
  52. procedure EnableButtons;
  53. procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
  54. procedure FormCreate(Sender: TObject);
  55. procedure FormDestroy(Sender: TObject);
  56. procedure FormDropFiles(Sender: TObject; const FileNames: array of String);
  57. procedure FormKeyDown(Sender: TObject; var Key: Word; {%H-}Shift: TShiftState);
  58. procedure FormResize(Sender: TObject);
  59. procedure FormShow(Sender: TObject);
  60. procedure pmAutouncheckClose(Sender: TObject);
  61. procedure pmAutouncheckOnOpenClick(Sender: TObject);
  62. procedure pmAutouncheckOnSaveClick(Sender: TObject);
  63. procedure pmAutouncheckPopup(Sender: TObject);
  64. procedure pmRemoveAllClick(Sender: TObject);
  65. procedure pmRemoveClose(Sender: TObject);
  66. procedure pmRemoveNonexistentClick(Sender: TObject);
  67. procedure pmRemovePopup(Sender: TObject);
  68. procedure pmRemoveUncheckedClick(Sender: TObject);
  69. procedure pmUncheckClose(Sender: TObject);
  70. procedure pmUncheckNonexistentClick(Sender: TObject);
  71. procedure pmUncheckPopup(Sender: TObject);
  72. procedure StringGrid1SelectCell(Sender: TObject; {%H-}aCol, aRow: Integer; var {%H-}CanSelect: Boolean);
  73. procedure StringGrid1SetCheckboxState(Sender: TObject; {%H-}ACol, ARow: Integer; const Value: TCheckboxState);
  74. procedure tbAutoUncheckClick(Sender: TObject);
  75. procedure tbAutoZoomFitClick(Sender: TObject);
  76. procedure tbMoveDownClick(Sender: TObject);
  77. procedure tbMoveUpClick(Sender: TObject);
  78. procedure tbNormalWindowsClick(Sender: TObject);
  79. procedure tbOpenImageClick(Sender: TObject);
  80. procedure tbOpenNextClick(Sender: TObject);
  81. procedure tbOpenPrevClick(Sender: TObject);
  82. procedure tbRemoveItemClick(Sender: TObject);
  83. procedure tbMiniWindowClick(Sender: TObject);
  84. procedure tbUncheckAllClick(Sender: TObject);
  85. procedure tbCheckAllClick(Sender: TObject);
  86. procedure tbCleanListClick(Sender: TObject);
  87. procedure tbAddFilesClick(Sender: TObject);
  88. function GetRowChecked(Row: integer): Boolean;
  89. function CheckedExist (Verbose: Boolean=True): Boolean;
  90. function GetSelectedRow: integer;
  91. procedure NormalWindow (Normalsize: Boolean= True);
  92. function SaveModified: boolean;
  93. function OpenImage (FileName: string): boolean;
  94. function IsExtensionIsValid (FileName:string): boolean;
  95. procedure Renumber;
  96. private
  97. FLazPaintInstance: TLazPaintCustomInstance;
  98. FBrowseImages: TFBrowseImages;
  99. WidthNormal: integer;
  100. HeightNormal: integer;
  101. WidthMinimal: integer;
  102. HeightMinimal: integer;
  103. ManualResize: Boolean;
  104. FResizedImageList: TBGRAImageList;
  105. // ILConfig: TLazPaintConfig;
  106. procedure EnsureGridRectVisible(ARect: TGridRect);
  107. function GetFileCount: integer;
  108. function GetLongFileName(AIndex: integer): string;
  109. procedure ImageSaving({%H-}AEvent: TLazPaintImageObservationEvent);
  110. function ScriptAddFiles(AVars: TVariableSet): TScriptResult;
  111. function ScriptGetAutoUncheckMode(AVars: TVariableSet): TScriptResult;
  112. function ScriptGetAutoZoomFit(AVars: TVariableSet): TScriptResult;
  113. function ScriptGetFileChecked(AVars: TVariableSet): TScriptResult;
  114. function ScriptGetFileCount(AVars: TVariableSet): TScriptResult;
  115. function ScriptGetFileName(AVars: TVariableSet): TScriptResult;
  116. function ScriptGetSelectedIndex(AVars: TVariableSet): TScriptResult;
  117. function ScriptIndexOfFileName(AVars: TVariableSet): TScriptResult;
  118. function ScriptOpenFirst(AVars: TVariableSet): TScriptResult;
  119. function ScriptOpenNext(AVars: TVariableSet): TScriptResult;
  120. function ScriptOpenPrevious(AVars: TVariableSet): TScriptResult;
  121. function ScriptOpenSelected(AVars: TVariableSet): TScriptResult;
  122. function ScriptRemoveAll({%H-}AVars: TVariableSet): TScriptResult;
  123. function ScriptRemoveIndex(AVars: TVariableSet): TScriptResult;
  124. function ScriptRemoveNonExistent({%H-}AVars: TVariableSet): TScriptResult;
  125. function ScriptRemoveUnchecked({%H-}AVars: TVariableSet): TScriptResult;
  126. function ScriptSetAutoUncheckMode(AVars: TVariableSet): TScriptResult;
  127. function ScriptSetAutoZoomFit(AVars: TVariableSet): TScriptResult;
  128. function ScriptSetFileChecked(AVars: TVariableSet): TScriptResult;
  129. function ScriptSetSelectedIndex(AVars: TVariableSet): TScriptResult;
  130. function ScriptUncheckNonExistent({%H-}AVars: TVariableSet): TScriptResult;
  131. procedure SetLazPaintInstance(AValue: TLazPaintCustomInstance);
  132. procedure SetRowChecked(AIndex: integer; AValue: boolean);
  133. procedure RegisterScriptFunctions(ARegister: boolean);
  134. procedure CallScriptFunction(AName: string); overload;
  135. function CallScriptFunction(AVars: TVariableSet): TScriptResult; overload;
  136. procedure SetSelectedRow(AValue: integer);
  137. public
  138. function AddFiles (const FileNames: array of String; AAutoOpen: boolean): integer;
  139. property FileChecked[AIndex: integer]: boolean read GetRowChecked write SetRowChecked;
  140. property LongFileName[AIndex: integer]: string read GetLongFileName;
  141. property FileCount: integer read GetFileCount;
  142. property LazPaintInstance: TLazPaintCustomInstance read FLazPaintInstance write SetLazPaintInstance;
  143. property SelectedRow: integer read GetSelectedRow write SetSelectedRow;
  144. end;
  145. var
  146. FImageList: TFImageList;
  147. colNumber: integer=0;
  148. ColShortFname: integer= 1;
  149. ColCB: integer= 2;
  150. ColLongFname: integer= 3;
  151. implementation
  152. {$R *.lfm}
  153. uses LCLType, UFileExtensions, LazFileUtils, UFileSystem, LCScaleDPI;
  154. { TFImageList }
  155. function StringExists (aStringGrid: TStringGrid; Column: integer ; aStr: String): Boolean;
  156. var
  157. i:integer;
  158. begin
  159. Result:=False;
  160. if aStringGrid.RowCount< (aStringGrid.FixedRows+1) then exit; //Line1 is header
  161. for i:= aStringGrid.FixedRows to aStringGrid.RowCount -1 do
  162. begin
  163. //TODO: Should I use case sensitive search? Maybe enable it for *nix only
  164. if CompareStr (LowerCase(aStringGrid.Cells[Column,i]), LowerCase (aStr))= 0 then
  165. begin
  166. Result:= True;
  167. break;
  168. end;
  169. end;
  170. end;
  171. function TFImageList.OpenImage (FileName: string): boolean;
  172. begin
  173. Result:=False;
  174. if not FileManager.FileExists(FileName) then begin QuestionDlg (rsError, rsFileNotFound, mtError, [mrOk, rsOkay],''); exit; end;
  175. if not LazPaintInstance.OpenImage(FileName,False) then
  176. begin QuestionDlg (rsError, rsCannotOpenFile, mtError, [mrOk, rsOkay],''); Exit; end
  177. else Result:=True;
  178. if tbAutoZoomFit.Down then LazPaintInstance.Image.ZoomFit;
  179. end;
  180. procedure DeleteRow(aStringGrid: TStringGrid; ARow: integer);
  181. var
  182. i, j: integer;
  183. begin
  184. with aStringGrid do
  185. begin
  186. for i:=ARow to RowCount-2 do
  187. for j:=0 to ColCount-1 do
  188. Cells[j,i]:=Cells[j,i+1];
  189. RowCount:=RowCount-1;
  190. end;
  191. end;
  192. procedure TFImageList.NormalWindow (Normalsize: Boolean= True);
  193. begin
  194. StringGrid1.Visible:=Normalsize;
  195. lblStatus.Visible := Normalsize;
  196. pnlButtonsNormalWindow.Visible:=Normalsize;
  197. pnlButtonsSmallWindow.Visible:=not Normalsize;
  198. if Normalsize = True then
  199. begin
  200. Self.Constraints.MinWidth:=WidthMinimal;
  201. Self.Constraints.MinHeight:=HeightMinimal;
  202. Self.Constraints.MaxWidth:=0;
  203. Self.Constraints.MaxHeight:=0;
  204. Self.Width:=WidthNormal;
  205. Self.Height:=HeightNormal;
  206. end
  207. else
  208. begin
  209. Self.Constraints.MinWidth:= DoScaleX(80, OriginalDPI);
  210. Self.Constraints.MinHeight:=DoScaleY(28, OriginalDPI);
  211. Self.Constraints.MaxWidth:=Self.Constraints.MinWidth;
  212. Self.Constraints.MaxHeight:=Self.Constraints.MinHeight;
  213. Self.Width:= DoScaleX(80, OriginalDPI);
  214. Self.Height:=DoScaleY(28, OriginalDPI);
  215. end;
  216. end; //sub
  217. function PerCent (WholePart: Double; Portion:Double): Double;
  218. begin
  219. if WholePart <> 0 then
  220. Result:= (Portion/WholePart)*100
  221. else Result:=0;
  222. end;
  223. procedure TFImageList.EnableButtons;
  224. var
  225. TF: Boolean;
  226. i: integer;
  227. TodoFiles: integer=0;
  228. begin
  229. //first line contains headers
  230. TF:= FileCount > 0;
  231. tbRemoveItem.Enabled:=TF;
  232. tbCheckAll.Enabled:=TF;
  233. tbUncheckAll.Enabled:=TF;
  234. StringGrid1.Enabled := TF;
  235. if TF then
  236. begin
  237. TF:= False;
  238. for i:=1 to FileCount do
  239. if FileChecked[i] then TF := true;
  240. end;
  241. tbOpenPrev.Enabled:=TF;
  242. tbOpenNext.Enabled:=TF;
  243. tbOpenPrevSW.Enabled:=TF;
  244. tbOpenNextSW.Enabled:=TF;
  245. tbMoveDown.Enabled:=TF;
  246. tbMoveUp.Enabled:=TF;
  247. StringGrid1.Columns.Items[ColShortFname].Width:=StringGrid1.Width- StringGrid1.Columns.Items[colNumber].Width- StringGrid1.Columns.Items[ColCB].Width-5 - {vert scrollbar width, 0 if invisible} (StringGrid1.Width-StringGrid1.ClientWidth);
  248. tbOpenImage.Enabled:= TF and FileChecked[SelectedRow];
  249. for i:= 1 to (FileCount) do
  250. if FileChecked[i] then inc(TodoFiles);
  251. lblStatus.Caption:= StringReplace(rsTotalImages,'%1',IntToStr(FileCount),[])+ '; '+
  252. StringReplace(rsToDoImages,'%1',IntToStr(TodoFiles),[]) + ' '
  253. +'(' + IntToStr(trunc(percent(FileCount,TodoFiles)))+ '%)';
  254. end;
  255. procedure TFImageList.FormCloseQuery(Sender: TObject; var CanClose: boolean);
  256. begin
  257. LazPaintInstance.ImageListWindowVisible:=False;
  258. CanClose:=False;
  259. end;
  260. procedure TFImageList.FormCreate(Sender: TObject);
  261. begin
  262. BorderStyle := ToolWindowSizeable;
  263. FormStyle := ToolWindowStyle;
  264. WidthNormal:= DoScaleX(500, OriginalDPI);
  265. HeightNormal:=DoScaleY(360, OriginalDPI);
  266. WidthMinimal:=DoScaleX(340, OriginalDPI);
  267. HeightMinimal:=DoScaleY(200, OriginalDPI);
  268. ManualResize:=True;
  269. Self.Constraints.MinWidth:=WidthMinimal;
  270. Self.Constraints.MinHeight:=HeightMinimal;
  271. Self.Constraints.MaxWidth:=0;
  272. Self.Constraints.MaxHeight:=0;
  273. Self.Width:=WidthNormal;
  274. Self.Height:=HeightNormal;
  275. if DoScaleX(ImageList1.Width, OriginalDPI) <> ImageList1.Width then
  276. begin
  277. FResizedImageList := TBGRAImageList.Create(self);
  278. ScaleImageList(ImageList1, DoScaleX(ImageList1.Width, OriginalDPI),
  279. DoScaleY(ImageList1.Height, OriginalDPI), FResizedImageList);
  280. tbButtonsNormalWindows.Images := FResizedImageList;
  281. tbButtonsSmallWindow.Images := FResizedImageList;
  282. end;
  283. tbButtonsNormalWindows.ButtonHeight := tbButtonsNormalWindows.Images.Height + DoScaleY(4, OriginalDPI);
  284. tbButtonsNormalWindows.Align:= alClient;
  285. tbButtonsSmallWindow.ButtonHeight := tbButtonsSmallWindow.Images.Height + DoScaleY(4, OriginalDPI);
  286. tbButtonsSmallWindow.Align:= alClient;
  287. pnlButtonsNormalWindow.Height := tbButtonsNormalWindows.ButtonHeight + DoScaleY(4, OriginalDPI);
  288. pnlButtonsNormalWindow.Align := alBottom;
  289. pnlButtonsSmallWindow.Height := tbButtonsSmallWindow.ButtonHeight + DoScaleY(4, OriginalDPI);
  290. pnlButtonsSmallWindow.Align := alBottom;
  291. lblStatus.Caption:='';
  292. lblStatus.AutoSize := true;
  293. lblStatus.Align := alBottom;
  294. StringGrid1.Columns.Items[colNumber].Title.Column.Title.Caption:=rsNumber;
  295. StringGrid1.Columns.Items[ColShortFname].Title.Column.Title.Caption:=rsFilename;
  296. StringGrid1.Columns.Items[ColCB].Title.Column.Title.Caption:=rsToDo;
  297. StringGrid1.Columns.Items[ColCB].Title.Column.Title.Alignment := taCenter;
  298. StringGrid1.Columns.Items[ColLongFname].Title.Caption:='';
  299. StringGrid1.Columns.Items[ColCB].ButtonStyle:=cbsCheckboxColumn;
  300. StringGrid1.Columns.Items[colNumber].ReadOnly:=True;
  301. StringGrid1.Columns.Items[ColShortFname].ReadOnly:=True;
  302. StringGrid1.Columns.Items[ColCB].ReadOnly:=False;
  303. StringGrid1.Columns.Items[ColLongFname].ReadOnly:=True;
  304. StringGrid1.Columns.Items[colNumber].Width:= DoScaleX(30, OriginalDPI);
  305. StringGrid1.Columns.Items[ColCB].Width:= DoScaleX(80, OriginalDPI);
  306. StringGrid1.Columns.Items[ColShortFname].Width:=StringGrid1.Width- StringGrid1.Columns.Items[colNumber].Width- StringGrid1.Columns.Items[ColCB].Width-5;
  307. StringGrid1.Columns.Items[ColLongFname].Width:=0;
  308. StringGrid1.Columns.Items[ColLongFname].Visible:=False;
  309. StringGrid1.Align := alClient;
  310. OpenDialog1.Filter:= GetExtensionFilter([eoReadable]);
  311. EnableButtons;
  312. end;
  313. procedure TFImageList.FormDestroy(Sender: TObject);
  314. begin
  315. if Assigned(LazPaintInstance.Image) then
  316. begin
  317. LazPaintInstance.Image.OnImageSaving.RemoveObserver(@ImageSaving);
  318. LazPaintInstance.Image.OnImageExport.RemoveObserver(@ImageSaving);
  319. end;
  320. FreeAndNil(FBrowseImages);
  321. end;
  322. function TFImageList.IsExtensionIsValid (FileName: string): boolean;
  323. begin
  324. result := IsExtensionReadable(Filename);
  325. end;
  326. function TFImageList.AddFiles (const FileNames: array of String; AAutoOpen: boolean): integer;
  327. var
  328. PrevRowCount, Row: integer;
  329. i: integer;
  330. shouldOpenFirst: boolean;
  331. begin
  332. result := 0;
  333. if Length(FileNames) > 0 then
  334. begin
  335. shouldOpenFirst := AAutoOpen and (FileCount = 0);
  336. LazPaintInstance.Config.SetImageListLastFolder(ExtractFileDir(FileNames[0]));
  337. PrevRowCount:=StringGrid1.RowCount;
  338. Row:=PrevRowCount;
  339. StringGrid1.RowCount:= PrevRowCount+Length(FileNames);
  340. for i:= 0 to length(FileNames)- 1 do
  341. begin
  342. if (not StringExists (StringGrid1,ColLongFname,FileNames[i])) and (IsExtensionIsValid(FileNames[i]))then
  343. begin
  344. StringGrid1.Cells[colNumber,Row]:=IntToStr (Row);
  345. StringGrid1.Cells[ColShortFname,Row]:=ExtractFileName(FileNames[i]);
  346. StringGrid1.Cells[ColCB,Row]:='1'; //Checkbox is checked
  347. StringGrid1.Cells[ColLongFname,Row]:=FileNames[i];
  348. Inc(Row);
  349. inc(result);
  350. end; //if StringExists
  351. end; //for i
  352. StringGrid1.RowCount:=Row;
  353. if shouldOpenFirst then
  354. begin
  355. tbOpenImageClick(nil);
  356. if tbAutoZoomFit.Down then LazPaintInstance.Image.ZoomFit;
  357. end;
  358. EnableButtons;
  359. end; //if
  360. end;
  361. procedure TFImageList.FormDropFiles(Sender: TObject; const FileNames: array of String);
  362. begin
  363. AddFiles(FileNames, true);
  364. end;
  365. procedure TFImageList.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  366. begin
  367. if ssAlt in Shift then
  368. begin
  369. case key of
  370. VK_LEFT: begin
  371. tbOpenPrevClick(Sender);
  372. key := 0;
  373. end;
  374. VK_RIGHT: begin
  375. tbOpenNextClick(Sender);
  376. key := 0;
  377. end;
  378. end;
  379. end;
  380. end;
  381. procedure TFImageList.FormResize(Sender: TObject);
  382. begin
  383. if ManualResize then
  384. begin
  385. StringGrid1.Columns.Items[ColShortFname].Width:=StringGrid1.Width- StringGrid1.Columns.Items[colNumber].Width- StringGrid1.Columns.Items[ColCB].Width-5 - {vert scrollbar width, 0 if invisible} (StringGrid1.Width-StringGrid1.ClientWidth);
  386. HeightNormal:=Self.Height;
  387. WidthNormal:=Self.Width;
  388. end;
  389. ManualResize:=True;
  390. end;
  391. procedure TFImageList.FormShow(Sender: TObject);
  392. begin
  393. EnsureVisible(False);
  394. tbAutoUncheck.Down:= LazPaintInstance.Config.ImageListAutoUncheck;
  395. tbAutoZoomFit.Down:= LazPaintInstance.Config.ImageListAutoZoom;
  396. pmAutouncheckOnSave.Checked:=LazPaintInstance.Config.ImageListAutoUncheckMode=0;
  397. pmAutouncheckOnOpen.Checked:=LazPaintInstance.Config.ImageListAutoUncheckMode=1;
  398. if Assigned(LazPaintInstance.Image) then
  399. begin
  400. LazPaintInstance.Image.OnImageSaving.AddObserver(@ImageSaving);
  401. LazPaintInstance.Image.OnImageExport.AddObserver(@ImageSaving);
  402. end;
  403. end;
  404. procedure TFImageList.pmAutouncheckClose(Sender: TObject);
  405. begin
  406. tbAutoUncheckDropDown.Down := false;
  407. end;
  408. procedure TFImageList.pmAutouncheckOnOpenClick(Sender: TObject);
  409. begin
  410. LazPaintInstance.Config.SetImageListAutoUncheckMode(1);
  411. pmAutouncheckOnOpen.Checked := true;
  412. pmAutouncheckOnSave.Checked := false;
  413. tbAutoUncheck.Down:=True;
  414. end;
  415. procedure TFImageList.pmAutouncheckOnSaveClick(Sender: TObject);
  416. begin
  417. LazPaintInstance.Config.SetImageListAutoUncheckMode(0);
  418. pmAutouncheckOnOpen.Checked := false;
  419. pmAutouncheckOnSave.Checked := true;
  420. tbAutoUncheck.Down:=True;
  421. end;
  422. procedure TFImageList.pmAutouncheckPopup(Sender: TObject);
  423. begin
  424. tbAutoUncheckDropDown.Down := true;
  425. end;
  426. procedure TFImageList.pmRemoveAllClick(Sender: TObject);
  427. begin
  428. CallScriptFunction('ImageListRemoveAll');
  429. end;
  430. procedure TFImageList.pmRemoveClose(Sender: TObject);
  431. begin
  432. tbRemoveDropDown.Down := false;
  433. end;
  434. procedure TFImageList.pmRemoveNonexistentClick(Sender: TObject);
  435. begin
  436. CallScriptFunction('ImageListRemoveNonexistent');
  437. end;
  438. procedure TFImageList.pmRemovePopup(Sender: TObject);
  439. begin
  440. tbRemoveDropDown.Down := true;
  441. end;
  442. procedure TFImageList.Renumber;
  443. var
  444. i:integer;
  445. begin
  446. if FileCount > 0 then
  447. for i:= 1 to FileCount do
  448. StringGrid1.Cells[colNumber,i]:=IntToStr(i);
  449. end;
  450. procedure TFImageList.EnsureGridRectVisible(ARect: TGridRect);
  451. var VisibleRows, SelectedRows, MinTopRow, MaxTopRow: integer;
  452. dummyCol,LastVisibleRow: integer;
  453. begin
  454. StringGrid1.Update;
  455. StringGrid1.MouseToCell(0,StringGrid1.ClientHeight-StringGrid1.DefaultRowHeight,{%H-}dummyCol,{%H-}LastVisibleRow);
  456. VisibleRows := LastVisibleRow-StringGrid1.TopRow+1;
  457. SelectedRows := ARect.Bottom-ARect.Top+1;
  458. MaxTopRow := ARect.Top;
  459. MinTopRow := ARect.Bottom - VisibleRows + 1;
  460. if MinTopRow < 0 then MinTopRow := 0;
  461. if StringGrid1.TopRow > MaxTopRow then StringGrid1.TopRow := MaxTopRow
  462. else if (SelectedRows <= VisibleRows) and (StringGrid1.TopRow < MinTopRow) then StringGrid1.TopRow := MinTopRow;
  463. end;
  464. function TFImageList.GetFileCount: integer;
  465. begin
  466. result := StringGrid1.RowCount - StringGrid1.FixedRows;
  467. end;
  468. function TFImageList.GetLongFileName(AIndex: integer): string;
  469. begin
  470. result := StringGrid1.Cells[ColLongFname, AIndex];
  471. end;
  472. procedure TFImageList.ImageSaving(AEvent: TLazPaintImageObservationEvent);
  473. var
  474. i: Integer;
  475. begin
  476. if not pmAutouncheckOnSave.Checked then exit;
  477. for i:= 1 to FileCount do
  478. if LongFileName[i] = LazPaintInstance.Image.currentFilenameUTF8 then
  479. FileChecked[i] := false;
  480. end;
  481. function TFImageList.ScriptAddFiles(AVars: TVariableSet): TScriptResult;
  482. var
  483. files: TScriptVariableReference;
  484. fileArray: array of string;
  485. i: Integer;
  486. begin
  487. files := AVars.GetVariable('FileNames');
  488. fileArray := nil;
  489. setLength(fileArray, AVars.GetListCount(files));
  490. for i := 0 to high(fileArray) do
  491. fileArray[i] := AVars.GetStringAt(files, i);
  492. AVars.Integers['Result'] := AddFiles(fileArray, false);
  493. result := srOk;
  494. end;
  495. function TFImageList.ScriptGetAutoUncheckMode(AVars: TVariableSet): TScriptResult;
  496. begin
  497. if tbAutoUncheck.Down then
  498. begin
  499. if pmAutouncheckOnOpen.Checked then
  500. AVars.Strings['Result'] := 'UncheckOnOpen'
  501. else
  502. AVars.Strings['Result'] := 'UncheckOnSave';
  503. end else
  504. AVars.Strings['Result'] := 'UncheckOff';
  505. result := srOk;
  506. end;
  507. function TFImageList.ScriptGetAutoZoomFit(AVars: TVariableSet): TScriptResult;
  508. begin
  509. AVars.Booleans['Result'] := tbAutoZoomFit.Down;
  510. result := srOk;
  511. end;
  512. function TFImageList.ScriptGetFileChecked(AVars: TVariableSet): TScriptResult;
  513. var
  514. idx: Int64;
  515. begin
  516. if AVars.IsDefined('Index') then
  517. begin
  518. idx := AVars.Integers['Index'];
  519. if (idx < 1) or (idx > FileCount) then exit(srInvalidParameters);
  520. AVars.Booleans['Result'] := FileChecked[idx];
  521. result := srOk;
  522. end else
  523. begin
  524. if SelectedRow >= 1 then
  525. begin
  526. AVars.Booleans['Result'] := FileChecked[SelectedRow];
  527. result := srOk;
  528. end else
  529. result := srException;
  530. end;
  531. end;
  532. function TFImageList.ScriptGetFileCount(AVars: TVariableSet): TScriptResult;
  533. begin
  534. AVars.Integers['Result'] := FileCount;
  535. result := srOk;
  536. end;
  537. function TFImageList.ScriptGetFileName(AVars: TVariableSet): TScriptResult;
  538. var
  539. idx: Int64;
  540. begin
  541. if AVars.IsDefined('Index') then
  542. begin
  543. idx := AVars.Integers['Index'];
  544. if (idx < 1) or (idx > FileCount) then exit(srInvalidParameters);
  545. AVars.Strings['Result'] := LongFileName[idx];
  546. result := srOk;
  547. end else
  548. begin
  549. if SelectedRow >= 1 then
  550. begin
  551. AVars.Strings['Result'] := LongFileName[SelectedRow];
  552. result := srOk;
  553. end else
  554. result := srException;
  555. end;
  556. end;
  557. function TFImageList.ScriptGetSelectedIndex(AVars: TVariableSet): TScriptResult;
  558. begin
  559. AVars.Integers['Result'] := SelectedRow;
  560. result := srOk;
  561. end;
  562. function TFImageList.ScriptIndexOfFileName(AVars: TVariableSet): TScriptResult;
  563. var
  564. fn: String;
  565. i: Integer;
  566. begin
  567. fn := AVars.Strings['FileName'];
  568. for i := 1 to FileCount do
  569. if LongFileName[i] = fn then
  570. begin
  571. AVars.Integers['Result'] := i;
  572. exit(srOk);
  573. end;
  574. AVars.Remove('Result');
  575. result := srOk;
  576. end;
  577. function TFImageList.ScriptOpenFirst(AVars: TVariableSet): TScriptResult;
  578. var
  579. i: Integer;
  580. subVars: TVariableSet;
  581. begin
  582. for i := 1 to FileCount do
  583. if FileChecked[i] then
  584. begin
  585. SelectedRow := i;
  586. subVars := TVariableSet.Create('ImageListOpenSelected');
  587. subVars.Booleans['SkipSave'] := Avars.Booleans['SkipSave'];
  588. result := CallScriptFunction(subVars);
  589. AVars.Booleans['Result'] := true;
  590. subVars.Free;
  591. exit;
  592. end;
  593. AVars.Booleans['Result'] := false;
  594. result := srOk;
  595. end;
  596. function TFImageList.ScriptOpenNext(AVars: TVariableSet): TScriptResult;
  597. var
  598. i:integer;
  599. begin
  600. if not CheckedExist(not AVars.Booleans['Silent']) then
  601. begin
  602. AVars.Booleans['Result'] := false;
  603. exit(srOk);
  604. end;
  605. if not (AVars.Booleans['SkipSave'] or SaveModified) then exit(srCancelledByUser);
  606. if SelectedRow < FileCount then
  607. for i:= SelectedRow + 1 to FileCount do
  608. if FileChecked[i] then
  609. begin
  610. if not OpenImage(LongFileName[i]) then exit(srException);
  611. SelectedRow := i;
  612. if (tbAutoUncheck.Down and pmAutouncheckOnOpen.Checked) then
  613. FileChecked[SelectedRow]:= false;
  614. AVars.Booleans['Result'] := true;
  615. Exit(srOk);
  616. end;
  617. if AVars.Booleans['CanCycle'] then
  618. for i:= 1 to SelectedRow do
  619. if FileChecked[i] then
  620. begin
  621. if not OpenImage(LongFileName[i]) then exit(srException);
  622. SelectedRow := i;
  623. if (tbAutoUncheck.Down and pmAutouncheckOnOpen.Checked) then
  624. FileChecked[SelectedRow]:= false;
  625. AVars.Booleans['Result'] := true;
  626. Exit(srOk);
  627. end;
  628. AVars.Booleans['Result'] := false;
  629. exit(srOk);
  630. end;
  631. function TFImageList.ScriptOpenPrevious(AVars: TVariableSet): TScriptResult;
  632. var
  633. i:integer;
  634. begin
  635. if not CheckedExist(not AVars.Booleans['Silent']) then
  636. begin
  637. AVars.Booleans['Result'] := false;
  638. exit(srOk);
  639. end;
  640. if not (AVars.Booleans['SkipSave'] or SaveModified) then exit;
  641. if SelectedRow > 1 then
  642. for i:= SelectedRow -1 downto 1 do
  643. if FileChecked[i] then
  644. begin
  645. if not OpenImage(LongFileName[i]) then exit(srException);
  646. SelectedRow := i;
  647. if (tbAutoUncheck.Down and pmAutouncheckOnOpen.Checked) then
  648. FileChecked[SelectedRow]:= false;
  649. AVars.Booleans['Result'] := true;
  650. Exit(srOk);
  651. end; //if
  652. if AVars.Booleans['CanCycle'] then
  653. for i:= FileCount downto SelectedRow do
  654. if FileChecked[i] then
  655. begin
  656. if not OpenImage(LongFileName[i]) then exit(srException);
  657. SelectedRow := i;
  658. if (tbAutoUncheck.Down and pmAutouncheckOnOpen.Checked) then
  659. FileChecked[SelectedRow] := false;
  660. AVars.Booleans['Result'] := true;
  661. Exit(srOk);
  662. end; //if
  663. AVars.Booleans['Result'] := false;
  664. exit(srOk);
  665. end;
  666. function TFImageList.ScriptOpenSelected(AVars: TVariableSet): TScriptResult;
  667. begin
  668. if AVars.Booleans['SkipSave'] or SaveModified then
  669. begin
  670. if tbAutoUncheck.Down and pmAutouncheckOnOpen.Checked then
  671. FileChecked[SelectedRow]:= false;
  672. if not OpenImage (LongFileName[SelectedRow]) then
  673. result := srException
  674. else
  675. result := srOk;
  676. end else
  677. result := srCancelledByUser;
  678. end;
  679. function TFImageList.ScriptRemoveAll(AVars: TVariableSet): TScriptResult;
  680. begin
  681. StringGrid1.Clean;
  682. StringGrid1.RowCount:= StringGrid1.FixedRows;
  683. EnableButtons;
  684. result := srOk;
  685. end;
  686. function TFImageList.ScriptRemoveIndex(AVars: TVariableSet): TScriptResult;
  687. var
  688. idx: Int64;
  689. begin
  690. idx := AVars.Integers['Index'];
  691. if (idx < 1) or (idx > FileCount) then exit(srInvalidParameters);
  692. DeleteRow(StringGrid1, idx);
  693. EnableButtons;
  694. result := srOk;
  695. end;
  696. function TFImageList.ScriptRemoveNonExistent(AVars: TVariableSet): TScriptResult;
  697. var
  698. i:integer;
  699. needRenumber: boolean;
  700. begin
  701. needRenumber := false;
  702. for i:=FileCount downto 1 do
  703. if not FileManager.FileExists(LongFileName[i])
  704. then begin DeleteRow(StringGrid1,i); needRenumber :=true; end;
  705. if needRenumber then Renumber;
  706. EnableButtons;
  707. result := srOk;
  708. end;
  709. function TFImageList.ScriptRemoveUnchecked(AVars: TVariableSet): TScriptResult;
  710. var
  711. i:integer;
  712. needRenumber: boolean;
  713. begin
  714. needRenumber := false;
  715. for i:=FileCount downto 1 do
  716. if not FileChecked[i] then
  717. begin DeleteRow(StringGrid1,i); needRenumber :=true; end;
  718. if needRenumber then Renumber;
  719. EnableButtons;
  720. result := srOk;
  721. end;
  722. function TFImageList.ScriptSetAutoUncheckMode(AVars: TVariableSet): TScriptResult;
  723. begin
  724. case AVars.Strings['Mode'] of
  725. 'UncheckOnOpen': begin
  726. tbAutoUncheck.Down := true;
  727. pmAutouncheckOnSave.Checked := false;
  728. pmAutouncheckOnOpen.Checked := true;
  729. LazPaintInstance.Config.SetImageListAutoUncheckMode(1);
  730. end;
  731. 'UncheckOnSave': begin
  732. tbAutoUncheck.Down := true;
  733. pmAutouncheckOnSave.Checked := true;
  734. pmAutouncheckOnOpen.Checked := false;
  735. LazPaintInstance.Config.SetImageListAutoUncheckMode(0);
  736. end;
  737. else
  738. tbAutoUncheck.Down := false;
  739. end;
  740. LazPaintInstance.Config.SetImageListAutoUncheck(true);
  741. result := srOk;
  742. end;
  743. function TFImageList.ScriptSetAutoZoomFit(AVars: TVariableSet): TScriptResult;
  744. begin
  745. tbAutoZoomFit.Down := AVars.Booleans['Enabled'];
  746. LazPaintInstance.Config.SetImageListAutoZoom(AVars.Booleans['Enabled']);
  747. result := srOk;
  748. end;
  749. function TFImageList.ScriptSetFileChecked(AVars: TVariableSet): TScriptResult;
  750. var
  751. idx: Int64;
  752. begin
  753. if AVars.IsDefined('Index') then
  754. begin
  755. idx := AVars.Integers['Index'];
  756. if (idx < 1) or (idx > FileCount) then exit(srInvalidParameters);
  757. FileChecked[idx] := AVars.Booleans['Checked'];
  758. result := srOk;
  759. end else
  760. begin
  761. if SelectedRow >= 1 then
  762. begin
  763. FileChecked[SelectedRow] := AVars.Booleans['Checked'];
  764. result := srOk;
  765. end else
  766. result := srException;
  767. end;
  768. end;
  769. function TFImageList.ScriptSetSelectedIndex(AVars: TVariableSet): TScriptResult;
  770. var
  771. idx: Int64;
  772. begin
  773. idx := AVars.Integers['Index'];
  774. if (idx < 1) or (idx > FileCount) then exit(srInvalidParameters);
  775. SelectedRow := idx;
  776. result := srOk;
  777. end;
  778. function TFImageList.ScriptUncheckNonExistent(AVars: TVariableSet): TScriptResult;
  779. var
  780. i: integer;
  781. begin
  782. for i:= 1 to FileCount do
  783. if not FileManager.FileExists(LongFileName[i])
  784. then FileChecked[i] := false;
  785. EnableButtons;
  786. result := srOk;
  787. end;
  788. procedure TFImageList.SetLazPaintInstance(AValue: TLazPaintCustomInstance);
  789. begin
  790. if FLazPaintInstance=AValue then Exit;
  791. RegisterScriptFunctions(False);
  792. FLazPaintInstance:=AValue;
  793. RegisterScriptFunctions(True);
  794. end;
  795. procedure TFImageList.SetRowChecked(AIndex: integer; AValue: boolean);
  796. begin
  797. StringGrid1.Cells[ColCB,AIndex]:= BoolToStr(AValue, '1', '0');
  798. EnableButtons;
  799. end;
  800. procedure TFImageList.RegisterScriptFunctions(ARegister: boolean);
  801. begin
  802. if LazPaintInstance = nil then exit;
  803. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListGetFileCount', @ScriptGetFileCount, ARegister);
  804. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListAddFiles', @ScriptAddFiles, ARegister);
  805. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListRemoveIndex', @ScriptRemoveIndex, ARegister);
  806. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListRemoveUnchecked', @ScriptRemoveUnchecked, ARegister);
  807. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListRemoveNonExistent', @ScriptRemoveNonExistent, ARegister);
  808. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListRemoveAll', @ScriptRemoveAll, ARegister);
  809. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListUncheckNonExistent', @ScriptUncheckNonExistent, ARegister);
  810. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListOpenFirst', @ScriptOpenFirst, ARegister);
  811. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListOpenSelected', @ScriptOpenSelected, ARegister);
  812. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListOpenNext', @ScriptOpenNext, ARegister);
  813. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListOpenPrevious', @ScriptOpenPrevious, ARegister);
  814. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListGetSelectedIndex', @ScriptGetSelectedIndex, ARegister);
  815. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListSetSelectedIndex', @ScriptSetSelectedIndex, ARegister);
  816. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListIndexOfFileName', @ScriptIndexOfFileName, ARegister);
  817. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListGetFileName', @ScriptGetFileName, ARegister);
  818. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListGetFileChecked', @ScriptGetFileChecked, ARegister);
  819. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListSetFileChecked', @ScriptSetFileChecked, ARegister);
  820. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListGetAutoUncheckMode', @ScriptGetAutoUncheckMode, ARegister);
  821. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListSetAutoUncheckMode', @ScriptSetAutoUncheckMode, ARegister);
  822. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListGetAutoZoomFit', @ScriptGetAutoZoomFit, ARegister);
  823. LazPaintInstance.ScriptContext.RegisterScriptFunction('ImageListSetAutoZoomFit', @ScriptSetAutoZoomFit, ARegister);
  824. end;
  825. procedure TFImageList.CallScriptFunction(AName: string);
  826. begin
  827. case LazPaintInstance.ScriptContext.CallScriptFunction(AName) of
  828. srFunctionNotDefined: LazPaintInstance.ShowMessage(rsScript, StringReplace(rsFunctionNotDefined, '%1', AName, []));
  829. end;
  830. end;
  831. function TFImageList.CallScriptFunction(AVars: TVariableSet): TScriptResult;
  832. begin
  833. result := LazPaintInstance.ScriptContext.CallScriptFunction(AVars);
  834. case result of
  835. srFunctionNotDefined: LazPaintInstance.ShowMessage(rsScript, StringReplace(rsFunctionNotDefined, '%1', AVars.FunctionName, []));
  836. end;
  837. end;
  838. procedure TFImageList.SetSelectedRow(AValue: integer);
  839. var
  840. gr: TGridRect;
  841. begin
  842. StringGrid1.Row := AValue;
  843. gr := StringGrid1.Selection;
  844. gr.Top := AValue;
  845. gr.Bottom:= AValue;
  846. StringGrid1.Selection := gr;
  847. if pnlButtonsNormalWindow.Visible and self.Visible then SafeSetFocus(StringGrid1);
  848. end;
  849. procedure TFImageList.pmRemoveUncheckedClick(Sender: TObject);
  850. begin
  851. CallScriptFunction('ImageListRemoveUnchecked');
  852. end;
  853. procedure TFImageList.pmUncheckClose(Sender: TObject);
  854. begin
  855. tbUncheckDropDown.Down := false;
  856. end;
  857. procedure TFImageList.pmUncheckNonexistentClick(Sender: TObject);
  858. begin
  859. CallScriptFunction('ImageListUncheckNonexistent');
  860. end;
  861. procedure TFImageList.pmUncheckPopup(Sender: TObject);
  862. begin
  863. tbUncheckDropDown.Down := true;
  864. end;
  865. procedure TFImageList.StringGrid1SelectCell(Sender: TObject; aCol, aRow: Integer; var CanSelect: Boolean);
  866. begin
  867. tbOpenImage.Enabled:= FileChecked[ARow];
  868. end;
  869. procedure TFImageList.StringGrid1SetCheckboxState(Sender: TObject; ACol,
  870. ARow: Integer; const Value: TCheckboxState);
  871. begin
  872. FileChecked[ARow] := (Value=cbChecked);
  873. end;
  874. procedure TFImageList.tbAutoUncheckClick(Sender: TObject);
  875. begin
  876. LazPaintInstance.Config.SetImageListAutoUncheck(tbAutoUncheck.Down);
  877. end;
  878. procedure TFImageList.tbAutoZoomFitClick(Sender: TObject);
  879. begin
  880. LazPaintInstance.Config.SetImageListAutoZoom(tbAutoZoomFit.Down);
  881. end;
  882. procedure TFImageList.tbMoveDownClick(Sender: TObject);
  883. var
  884. SelRect: TGridRect;
  885. begin
  886. if (StringGrid1.RowCount>2) and (StringGrid1.Selection.Bottom< FileCount) then
  887. begin
  888. SelRect:=StringGrid1.Selection;
  889. StringGrid1.MoveColRow(False,SelRect.Bottom+1,SelRect.Top);
  890. SelRect.Top += 1;
  891. SelRect.Bottom += 1;
  892. StringGrid1.Selection:=SelRect;
  893. EnsureGridRectVisible(SelRect);
  894. end;
  895. end;
  896. procedure TFImageList.tbMoveUpClick(Sender: TObject);
  897. var
  898. SelRect: TGridRect;
  899. begin
  900. if (StringGrid1.RowCount>2) and (StringGrid1.Selection.Top>1) then
  901. begin
  902. SelRect:=StringGrid1.Selection;
  903. StringGrid1.MoveColRow(False,SelRect.Top-1,SelRect.Bottom);
  904. SelRect.Top -= 1;
  905. SelRect.Bottom -= 1;
  906. StringGrid1.Selection:=SelRect;
  907. EnsureGridRectVisible(SelRect);
  908. end;
  909. end;
  910. procedure TFImageList.tbNormalWindowsClick(Sender: TObject);
  911. begin
  912. ManualResize:=False;
  913. NormalWindow;
  914. end;
  915. function TFImageList.GetRowChecked(Row: integer): Boolean;
  916. begin
  917. Result:= (StringGrid1.Cells[ColCB, Row] = '1')
  918. end;
  919. procedure TFImageList.tbOpenImageClick(Sender: TObject);
  920. begin
  921. CallScriptFunction('ImageListOpenSelected');
  922. end;
  923. function TFImageList.GetSelectedRow: integer;
  924. begin
  925. Result:=StringGrid1.Selection.Top;
  926. end;
  927. function TFImageList.CheckedExist (Verbose: Boolean= True) : Boolean;
  928. var
  929. i: integer;
  930. begin
  931. Result:=False;
  932. for i:=1 to StringGrid1.RowCount -1 do
  933. if FileChecked[i] then
  934. begin
  935. Result:=True;
  936. Break;
  937. end;
  938. if (Result = false) and (Verbose= True) then
  939. QuestionDlg (rsInformation, rsThereAreNoCheckedItems, mtInformation, [mrOk, rsOkay],'');
  940. end;
  941. function TFImageList.SaveModified: boolean;
  942. begin
  943. Result:=True;
  944. if LazPaintInstance.Image.IsFileModified=True then
  945. case QuestionDlg (rsFileNotSaved, rsSaveChanges, mtWarning, [mrYes,rsYes,mrNo,rsNoAndProceedToNext,mrCancel,rsCancel],'') of
  946. mrYes :
  947. begin
  948. if Length(LazPaintInstance.Image.currentFilenameUTF8)=0 //TODO: Should I use < something. For Windows length cannot be less than 4.
  949. then begin QuestionDlg (rsInformation, rsThereIsNoFileNameGivenForThisFileUseSaveAs, mtInformation, [mrOk, rsOkay],''); Exit; end;
  950. LazPaintInstance.StartSavingImage(LazPaintInstance.Image.currentFilenameUTF8);
  951. try
  952. LazPaintInstance.Image.SaveToFileUTF8(LazPaintInstance.Image.currentFilenameUTF8);
  953. Except
  954. on ex:exception do
  955. begin
  956. LazPaintInstance.ShowError('FileSaveAs',ex.Message);
  957. Result:=False;
  958. end;
  959. end;
  960. LazPaintInstance.EndSavingImage;
  961. end;
  962. mrCancel: Result:=False;
  963. end;
  964. end;
  965. procedure TFImageList.tbOpenNextClick(Sender: TObject);
  966. var
  967. vars: TVariableSet;
  968. begin
  969. vars := TVariableSet.Create('ImageListOpenNext');
  970. vars.Booleans['CanCycle'] := true;
  971. CallScriptFunction(vars);
  972. vars.Free;
  973. end;
  974. procedure TFImageList.tbOpenPrevClick(Sender: TObject);
  975. var
  976. vars: TVariableSet;
  977. begin
  978. vars := TVariableSet.Create('ImageListOpenPrevious');
  979. vars.Booleans['CanCycle'] := true;
  980. CallScriptFunction(vars);
  981. vars.Free;
  982. end;
  983. procedure TFImageList.tbRemoveItemClick(Sender: TObject);
  984. var
  985. i:integer;
  986. sTop: integer;
  987. begin
  988. if (StringGrid1.Selection.Top= 0) and (StringGrid1.Selection.Bottom=0) then Exit;
  989. if StringGrid1.Selection.Top=0 then sTop:=1 else sTop:=StringGrid1.Selection.Top;
  990. for i:=sTop to StringGrid1.Selection.Bottom do
  991. DeleteRow(StringGrid1, i);
  992. EnableButtons;
  993. end;
  994. procedure TFImageList.tbMiniWindowClick(Sender: TObject);
  995. begin
  996. ManualResize:=False;
  997. NormalWindow(False);
  998. end;
  999. procedure TFImageList.tbUncheckAllClick(Sender: TObject);
  1000. var
  1001. i: integer;
  1002. begin
  1003. for i:= 1 to FileCount do
  1004. StringGrid1.Cells[ColCB,i]:= '0';
  1005. EnableButtons;
  1006. end;
  1007. procedure TFImageList.tbCheckAllClick(Sender: TObject);
  1008. var
  1009. i: integer;
  1010. begin
  1011. for i:= 1 to FileCount do
  1012. StringGrid1.Cells[ColCB,i]:= '1';
  1013. EnableButtons;
  1014. end;
  1015. procedure TFImageList.tbCleanListClick(Sender: TObject);
  1016. begin
  1017. StringGrid1.Clean;
  1018. StringGrid1.RowCount:=1;
  1019. EnableButtons;
  1020. end;
  1021. function StringsToStringArray(const aStrings: TStrings): String1D;
  1022. var
  1023. i: integer;
  1024. TempVar: array of String;
  1025. begin
  1026. TempVar := nil;
  1027. SetLength(TempVar, aStrings.Count);
  1028. For i := 0 To aStrings.Count-1 Do
  1029. TempVar[i] := aStrings[i];
  1030. Result:= TempVar;
  1031. end;
  1032. procedure TFImageList.tbAddFilesClick(Sender: TObject);
  1033. var topMostInfo: TTopMostInfo;
  1034. fileNames: array of string;
  1035. i: integer;
  1036. begin
  1037. topMostInfo := LazPaintInstance.HideTopmost;
  1038. if LazPaintInstance.Config.DefaultUseImageBrowser then
  1039. begin
  1040. if not assigned(FBrowseImages) then
  1041. begin
  1042. FBrowseImages := TFBrowseImages.Create(self);
  1043. FBrowseImages.LazPaintInstance := LazPaintInstance;
  1044. end;
  1045. if FBrowseImages.ShowModal = mrOK then
  1046. begin
  1047. fileNames := nil;
  1048. setlength(fileNames,FBrowseImages.SelectedFileCount);
  1049. for i := 0 to high(fileNames) do
  1050. fileNames[i] := FBrowseImages.SelectedFile[i];
  1051. AddFiles(Filenames, true);
  1052. FBrowseImages.FreeChosenImage;
  1053. end;
  1054. end else
  1055. begin
  1056. if Length(LazPaintInstance.Config.ImageListLastFolder)>0 then OpenDialog1.InitialDir:=LazPaintInstance.Config.ImageListLastFolder;
  1057. if OpenDialog1.Execute= True then AddFiles(StringsToStringArray(OpenDialog1.Files), true);
  1058. end;
  1059. LazPaintInstance.ShowTopmost(topMostInfo);
  1060. end;
  1061. end.