Menu

[r2745]: / trunk / Src / FmFavouritesDlg.pas  Maximize  Restore  History

Download this file

711 lines (628 with data), 23.0 kB

  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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
{
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/
*
* Copyright (C) 2013, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* Implements a dialogue box that displays and manages the user's favourite
* snippets.
}
unit FmFavouritesDlg;
interface
uses
// Delphi
Classes, ActnList, StdCtrls, Controls, ExtCtrls, Forms, ComCtrls, Types,
Generics.Collections {must be listed after Classes},
// 3rd party
LVEx,
// Project
USnippetIDs,
FmGenericNonModalDlg, Favourites.UFavourites, IntfNotifier, UWindowSettings;
type
/// <summary>Implements a non-modal dialogue box that displays and manages
/// the user's favourite snippets.</summary>
/// <remarks>By default the dialog box fades to semi-transparency when it is
/// not active and returns to full opacity when activated.</remarks>
TFavouritesDlg = class(TGenericNonModalDlg)
actDelete: TAction;
actDeleteAll: TAction;
actDisplay: TAction;
alDlg: TActionList;
btnDelete: TButton;
btnDeleteAll: TButton;
btnDisplay: TButton;
chkNewTab: TCheckBox;
lblTransparency: TLabel;
tbTransparency: TTrackBar;
/// <summary>Clears all favourites.</summary>
/// <remarks>Prompts user for permission before proceeding.</remarks>
procedure actDeleteAllExecute(Sender: TObject);
/// <summary>Disables DeleteAll action iff there are no favourites.
/// </summary>
procedure actDeleteAllUpdate(Sender: TObject);
/// <summary>Removes favourite selected in list view from list.</summary>
procedure actDeleteExecute(Sender: TObject);
/// <summary>Enables Delete action iff a favourite is selected in list
/// view.</summary>
procedure actDeleteUpdate(Sender: TObject);
/// <summary>Displays favourite selected in list view.</summary>
procedure actDisplayExecute(Sender: TObject);
/// <summary>Enables Display action iff a favourite is selected in list
/// view.</summary>
procedure actDisplayUpdate(Sender: TObject);
/// <summary>Fades form to full opacity when dialogue box is activated.
/// </summary>
procedure FormActivate(Sender: TObject);
/// <summary>Causes form's object instance to be automatically freed when
/// closed.</summary>
procedure FormClose(Sender: TObject; var Action: TCloseAction);
/// <summary>Sets default property values when form created.</summary>
procedure FormCreate(Sender: TObject);
/// <summary>Fades form to specified transparency when dialogue box is
/// de-activated.</summary>
procedure FormDeactivate(Sender: TObject);
/// <summary>Saves form's window state before it is destroyed.</summary>
procedure FormDestroy(Sender: TObject);
/// <summary>Adjusts form transparency when transparency trackbar changes,
/// per new trackbar position.</summary>
procedure tbTransparencyChange(Sender: TObject);
/// <summary>Records that a key has been pressed over the transparency
/// trackbar and fades the form down to the transparency specified by the
/// trackbar.</summary>
procedure tbTransparencyKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
/// <summary>Records that the currently depressed key has been released
/// over trackbar and fades the form back up to full opacity.</summary>
procedure tbTransparencyKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
strict private
type
/// <summary>Class used to read and store persistent options in settings
/// </summary>
TPersistentOptions = class(TObject)
strict private
var
/// <summary>Value of DisplayInNewTabs property.</summary>
fDisplayInNewTabs: Boolean;
/// <summary>Value of InactiveAlphaBlendValue property.</summary>
fInactiveAlphaBlendValue: Byte;
public
/// <summary>Constructs object and reads options from settings.
/// </summary>
constructor Create;
/// <summary>Writes options to settings then destroys object.</summary>
destructor Destroy; override;
/// <summary>Specifies whether selected favourites are to be displayed
/// in new tabs in main window's detail pane or not.</summary>
property DisplayInNewTabs: Boolean
read fDisplayInNewTabs write fDisplayInNewTabs;
/// <summary>Stores alpha blend value that determines transparency of
/// deactivated form.</summary>
property InactiveAlphaBlendValue: Byte
read fInactiveAlphaBlendValue write fInactiveAlphaBlendValue;
end;
strict private
var
/// <summary>Custom list view control used to display favourites.
/// </summary>
fLVFavs: TListViewEx;
/// <summary>Object encapsulating favourites.</summary>
fFavourites: TFavourites;
/// <summary>Notifier object used to request display of snippets in main
/// form.</summary>
fNotifier: INotifier;
/// <summary>Form's persistent options.</summary>
fOptions: TPersistentOptions;
/// <summary>Object used to read / write window position.</summary>
fWindowSettings: TDlgWindowSettings;
/// <summary>Flag indicating if a key is currently pressed when
/// transparency trackbar has keyboard focus.</summary>
fTrackBarKeyDown: Boolean;
/// <summary>Flag indicating if mouse is currently pressed over
/// transparency trackbar.</summary>
fTrackBarMouseDown: Boolean;
class var
/// <summary>Reference to dialogue box form instance.</summary>
/// <remarks>Set to nil if there is no instance of the form.</remarks>
fInstance: TFavouritesDlg;
strict private
/// <summary>Specifies list item class to be used to create list view items.
/// </summary>
/// <param name="Sender">TCustomListView [in] List view control for which
/// list item class is required.</param>
/// <param name="ItemClass">TListItemClass [in/out] Set to required class:
/// TFavouriteListItem in all cases.</param>
procedure LVFavouriteCreateItemClass(Sender: TCustomListView;
var ItemClass: TListItemClass);
/// <summary>Compares two list items, Item1 and Item2 and records the
/// result of the comparison in the Compare parameter.</summary>
/// <remarks>Comparison depends on which column of data is being sorted.
/// </remarks>
procedure LVFavouritesCompare(Sender: TObject; Item1, Item2: TListItem;
Data: Integer; var Compare: Integer);
/// <summary>Handles double clicks on list view items by causing the
/// associated favourite's snippet to be displayed.</summary>
procedure LVDoubleClick(Sender: TObject);
/// <summary>Overrides default drawing of given list viewed item caption by
/// ensuring the associated favourite's snippet display name is rendered in
/// correct colour.</summary>
/// <remarks>Colour used depends on if snippet is user defined.</remarks>
procedure LVCustomDrawItem(Sender: TCustomListView; Item: TListItem;
State: TCustomDrawState; var DefaultDraw: Boolean);
/// <summary>Ensures that given list view sub item is drawn in correct
/// colour.</summary>
/// <remarks>Colour is reverted to window text rather than colour set in
/// LVCustomDrawItem method.</remarks>
procedure LVCustomDrawSubItem(Sender: TCustomListView; Item: TListItem;
SubItem: Integer; State: TCustomDrawState; var DefaultDraw: Boolean);
/// <summary>Creates and initialises properties of custom list view control
/// used for displaying favourites.</summary>
procedure CreateLV;
/// <summary>Displays all favourites in favourites list view.</summary>
procedure PopulateLV;
/// <summary>Resorts favourites list view according to current sort column.
/// </summary>
procedure ReSortLV;
/// <summary>Adds given favourite to favourites list view.</summary>
procedure AddLVItem(const Favourite: TFavourite);
/// <summary>Removes given favourite from favourites list view.</summary>
/// <remarks>Does nothing if favourite is not in list view.</remarks>
procedure RemoveLVItem(const Favourite: TFavourite);
/// <summary>Listener method that receives and acts on change events
/// triggered by favourites object.</summary>
/// <param name="Sender">TObject [in] Reference to favourites object that
/// triggered event.</param>
/// <param name="EvtInfo">IInterface [in] Reference to object that carries
/// information about the event.</param>
/// <remarks>EvtInfo will always support the IFavouritesChangeEventInfo
/// interface.</remarks>
procedure FavouritesListener(Sender: TObject; const EvtInfo: IInterface);
/// <summary>Changes the transparency old the form from its current level
/// to the given new transparency level.</summary>
/// <remarks>The change in transparency is done in steps to make it appear
/// animated.</remarks>
procedure FadeTo(const EndTransparency: Byte);
/// <summary>Fades the form in from its transparent state to full opacity.
/// </summary>
procedure FadeIn;
/// <summary>Fades the form from its current transparency to the level
/// indicated by the transparency trackbar.</summary>
procedure FadeOut;
/// <summary>Finds the list item associated with the favourite that has the
/// given snippet ID.</summary>
/// <remarks>Returns nil if no mathcing list item exists.</remarks>
function FindListItem(const SnippetID: TSnippetID): TListItem;
/// <summary>Records that a mouse button has been pressed over the
/// transparency trackbar and fades the form down to the transparency
/// specified by the trackbar.</summary>
procedure TBTransparencyMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
/// <summary>Records that the currently depressed mouse button has been
/// released over the trackbar and fades the form back up to full
/// opacity.</summary>
procedure TBTransparencyMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
strict protected
/// <summary>Configures some of the form's objects.</summary>
procedure ConfigForm; override;
/// <summary>Arranges and aligns the form's controls.</summary>
procedure ArrangeForm; override;
/// <summary>Initialises form's controls and restores last window position.
/// </summary>
procedure InitForm; override;
public
/// <summary>Displays and intialises the dialogue box non-modally, or re-activates it if
/// already displayed.</summary>
/// <param name="AOwner">TComponent [in] Reference to any owning component.
/// May be nil.</param>
/// <param name="Favourites">TFavourites [in] Reference to favourites
/// object to be displayed or managed.</param>
/// <param name="Notifier">INotifier [in] Reference to notifier object used
/// to cause a favourite snippet to be displayed in main window.</param>
class procedure Display(AOwner: TComponent; const Favourites: TFavourites;
Notifier: INotifier);
/// <summary>Closes the dialogue box, freeing any form instance.</summary>
class procedure Close;
/// <summary>Checks if the form is currently displayed.</summary>
class function IsDisplayed: Boolean;
end;
implementation
uses
// Delphi
SysUtils, DateUtils, Windows, Graphics,
// Project
UCtrlArranger, UMessageBox, UPreferences, USettings, UStructs, UStrUtils;
{$R *.dfm}
type
/// <summary>Custom list item class that adds ability to store a TFavourite
/// record with list item.</summary>
TFavouriteListItem = class(TListItem)
strict private
var
/// <summary>Value of Warning property.</summary>
fFavourite: TFavourite;
public
/// <summary>Favourite associated with list item.</summary>
property Favourite: TFavourite read fFavourite write fFavourite;
end;
type
/// <summary>Hack to enable OnMouseUp and OnMouseDown events of TTrackBar to
/// be set.</summary>
/// <remarks>For some reason these events are protected in TTrackBar.
/// </remarks>
TTrackBarHack = class(TTrackBar);
{ TFavouritesDlg }
procedure TFavouritesDlg.actDeleteAllExecute(Sender: TObject);
resourcestring
sQuery = 'Do you really want to delete all your favourites?';
begin
if TMessageBox.Confirm(Self, sQuery) then
begin
fLVFavs.Items.BeginUpdate;
try
fFavourites.Clear;
finally
fLVFavs.Items.EndUpdate;
end;
end;
end;
procedure TFavouritesDlg.actDeleteAllUpdate(Sender: TObject);
begin
actDeleteAll.Enabled := not fFavourites.IsEmpty;
end;
procedure TFavouritesDlg.actDeleteExecute(Sender: TObject);
var
LI: TFavouriteListItem;
begin
LI := fLVFavs.Selected as TFavouriteListItem;
fFavourites.Remove(LI.Favourite.SnippetID);
end;
procedure TFavouritesDlg.actDeleteUpdate(Sender: TObject);
begin
actDelete.Enabled := Assigned(fLVFavs.Selected);
end;
procedure TFavouritesDlg.actDisplayExecute(Sender: TObject);
var
LI: TFavouriteListItem;
SelectedSnippet: TSnippetID;
begin
LI := fLVFavs.Selected as TFavouriteListItem;
SelectedSnippet := LI.Favourite.SnippetID;
fNotifier.DisplaySnippet(
SelectedSnippet.Name,
SelectedSnippet.UserDefined,
chkNewTab.Checked
);
fFavourites.Touch(SelectedSnippet);
fLVFavs.Selected := FindListItem(SelectedSnippet);
end;
procedure TFavouritesDlg.actDisplayUpdate(Sender: TObject);
begin
actDisplay.Enabled := Assigned(fLVFavs.Selected);
end;
procedure TFavouritesDlg.AddLVItem(const Favourite: TFavourite);
var
LI: TFavouriteListItem;
begin
LI := fLVFavs.Items.Add as TFavouriteListItem;
LI.Caption := Favourite.SnippetID.Name;
if IsToday(Favourite.LastAccessed) then
LI.SubItems.Add(TimeToStr(Favourite.LastAccessed))
else
LI.SubItems.Add(DateTimeToStr(Favourite.LastAccessed));
LI.Favourite := Favourite;
end;
procedure TFavouritesDlg.ArrangeForm;
begin
TCtrlArranger.AlignTops([fLVFavs, btnDisplay], 0);
TCtrlArranger.AlignLefts([fLVFavs, chkNewTab], 0);
TCtrlArranger.AlignLefts(
[btnDisplay, btnDelete, btnDeleteAll],
TCtrlArranger.RightOf(fLVFavs, 8)
);
TCtrlArranger.MoveBelow(fLVFavs, chkNewTab, 8);
pnlBody.ClientWidth := TCtrlArranger.TotalControlWidth(pnlBody) + 4;
pnlBody.ClientHeight := TCtrlArranger.TotalControlHeight(pnlBody);
inherited;
TCtrlArranger.AlignLefts([pnlBody, lblTransparency]);
TCtrlArranger.MoveToRightOf(lblTransparency, tbTransparency, 4);
TCtrlArranger.AlignTops([btnClose, lblTransparency, tbTransparency]);
end;
class procedure TFavouritesDlg.Close;
begin
if IsDisplayed then
FreeAndNil(fInstance);
end;
procedure TFavouritesDlg.ConfigForm;
begin
inherited;
fFavourites.AddListener(FavouritesListener);
TTrackBarHack(tbTransparency).OnMouseDown := TBTransparencyMouseDown;
TTrackBarHack(tbTransparency).OnMouseUp := TBTransparencyMouseUp;
end;
procedure TFavouritesDlg.CreateLV;
resourcestring
sSnippetName = 'Snippet';
sLastAccessed = 'Last used';
begin
fLVFavs := TListViewEx.Create(Self);
with fLVFavs do
begin
Parent := pnlBody;
Height := 240;
Width := 360;
HideSelection := False;
ReadOnly := True;
RowSelect := True;
TabOrder := 0;
TabStop := True;
ViewStyle := vsReport;
SortImmediately := False;
with Columns.Add do
begin
Caption := sSnippetName;
Width := 180;
end;
with Columns.Add do
begin
Caption := sLastAccessed;
Width := 140;
end;
OnDblClick := LVDoubleClick;
OnCompare := LVFavouritesCompare;
OnCreateItemClass := LVFavouriteCreateItemClass;
OnCustomDrawItem := LVCustomDrawItem;
OnCustomDrawSubItem := LVCustomDrawSubItem;
end;
end;
class procedure TFavouritesDlg.Display(AOwner: TComponent;
const Favourites: TFavourites; Notifier: INotifier);
begin
if not Assigned(fInstance) then
fInstance := Create(AOwner);
fInstance.fFavourites := Favourites;
fInstance.fNotifier := Notifier;
if not fInstance.Visible then
begin
fInstance.Show;
end;
fInstance.SetFocus;
end;
procedure TFavouritesDlg.FadeIn;
begin
FadeTo(High(Byte));
end;
procedure TFavouritesDlg.FadeOut;
begin
FadeTo(tbTransparency.Position);
end;
procedure TFavouritesDlg.FadeTo(const EndTransparency: Byte);
var
Step: Int8;
begin
Step := -1;
if AlphaBlendValue < EndTransparency then
Step := -Step;
while AlphaBlendValue <> EndTransparency do
begin
AlphaBlendValue := AlphaBlendValue + Step;
Sleep(2);
end;
end;
procedure TFavouritesDlg.FavouritesListener(Sender: TObject;
const EvtInfo: IInterface);
var
Evt: IFavouritesChangeEventInfo;
SelectedSnippet: TSnippetID;
HaveSelection: Boolean;
begin
Evt := EvtInfo as IFavouritesChangeEventInfo;
case Evt.Action of
cnAdded:
begin
HaveSelection := Assigned(fLVFavs.Selected);
if HaveSelection then
SelectedSnippet :=
(fLVFavs.Selected as TFavouriteListItem).Favourite.SnippetID;
AddLVItem(Evt.Favourite);
ReSortLV;
if HaveSelection then
fLVFavs.Selected := FindListItem(SelectedSnippet);
end;
cnRemoved:
begin
HaveSelection := Assigned(fLVFavs.Selected);
if HaveSelection then
SelectedSnippet :=
(fLVFavs.Selected as TFavouriteListItem).Favourite.SnippetID;
RemoveLVItem(Evt.Favourite);
ReSortLV;
if HaveSelection and (Evt.Favourite.SnippetID <> SelectedSnippet) then
fLVFavs.Selected := FindListItem(SelectedSnippet);
end;
end;
end;
function TFavouritesDlg.FindListItem(const SnippetID: TSnippetID): TListItem;
var
LI: TListItem;
begin
for LI in fLVFavs.Items do
begin
if (LI as TFavouriteListItem).Favourite.SnippetID = SnippetID then
Exit(LI);
end;
Result := nil;
end;
procedure TFavouritesDlg.FormActivate(Sender: TObject);
begin
FadeIn;
end;
procedure TFavouritesDlg.FormClose(Sender: TObject; var Action: TCloseAction);
begin
inherited;
fInstance := nil;
Action := caFree;
end;
procedure TFavouritesDlg.FormCreate(Sender: TObject);
begin
inherited;
CreateLV;
fOptions := TPersistentOptions.Create;
fWindowSettings := TDlgWindowSettings.CreateStandAlone(Self);
AlphaBlendValue := High(Byte);
end;
procedure TFavouritesDlg.FormDeactivate(Sender: TObject);
begin
FadeOut;
end;
procedure TFavouritesDlg.FormDestroy(Sender: TObject);
begin
fFavourites.RemoveListener(FavouritesListener);
fOptions.DisplayInNewTabs := chkNewTab.Checked;
fOptions.InactiveAlphaBlendValue := tbTransparency.Position;
fOptions.Free;
fWindowSettings.Save;
inherited;
end;
procedure TFavouritesDlg.InitForm;
begin
inherited;
fWindowSettings.Restore;
PopulateLV;
chkNewTab.Checked := fOptions.DisplayInNewTabs;
tbTransparency.OnChange := nil;
tbTransparency.Position := fOptions.InactiveAlphaBlendValue;
tbTransparency.OnChange := tbTransparencyChange;
end;
class function TFavouritesDlg.IsDisplayed: Boolean;
begin
Result := Assigned(fInstance) and fInstance.Visible;
end;
procedure TFavouritesDlg.LVCustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
var
UserDefined: Boolean;
begin
UserDefined := (Item as TFavouriteListItem).Favourite.SnippetID.UserDefined;
fLVFavs.Canvas.Font.Color := Preferences.DBHeadingColours[UserDefined];
end;
procedure TFavouritesDlg.LVCustomDrawSubItem(Sender: TCustomListView;
Item: TListItem; SubItem: Integer; State: TCustomDrawState;
var DefaultDraw: Boolean);
begin
fLVFavs.Canvas.Font.Color := clNone; // required to force later colour change
fLVFavs.Canvas.Font.Color := clWindowText;
end;
procedure TFavouritesDlg.LVDoubleClick(Sender: TObject);
begin
actDisplay.Execute;
end;
procedure TFavouritesDlg.LVFavouriteCreateItemClass(Sender: TCustomListView;
var ItemClass: TListItemClass);
begin
ItemClass := TFavouriteListItem;
end;
procedure TFavouritesDlg.LVFavouritesCompare(Sender: TObject; Item1,
Item2: TListItem; Data: Integer; var Compare: Integer);
var
Fav1, Fav2: TFavourite;
begin
Fav1 := (Item1 as TFavouriteListItem).Favourite;
Fav2 := (Item2 as TFavouriteListItem).Favourite;
case fLVFavs.SortColumn of
0:
Compare := Fav1.SnippetID.CompareTo(Fav2.SnippetID);
1:
Compare := CompareDateTime(Fav1.LastAccessed, Fav2.LastAccessed);
end;
if fLVFavs.SortOrder = soDown then
Compare := -Compare;
end;
procedure TFavouritesDlg.PopulateLV;
var
Fav: TFavourite;
begin
fLVFavs.Clear;
for Fav in fFavourites do
AddLVItem(Fav);
fLVFavs.Selected := nil;
ReSortLV;
end;
procedure TFavouritesDlg.RemoveLVItem(const Favourite: TFavourite);
var
LI: TListItem;
begin
for LI in fLVFavs.Items do
begin
if (LI as TFavouriteListItem).Favourite.SnippetID = Favourite.SnippetID then
begin
LI.Free;
Exit;
end;
end;
end;
procedure TFavouritesDlg.ReSortLV;
begin
if fLVFavs.SortColumn <> -1 then
fLVFavs.CustomSort(nil, fLVFavs.SortColumn);
end;
procedure TFavouritesDlg.tbTransparencyChange(Sender: TObject);
begin
if fTrackBarKeyDown or fTrackBarMouseDown then
AlphaBlendValue := tbTransparency.Position;
end;
procedure TFavouritesDlg.tbTransparencyKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
fTrackBarKeyDown := True;
FadeOut;
end;
procedure TFavouritesDlg.tbTransparencyKeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
FadeIn;
fTrackBarKeyDown := False;
end;
procedure TFavouritesDlg.TBTransparencyMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
FadeOut;
fTrackBarMouseDown := True;
end;
procedure TFavouritesDlg.TBTransparencyMouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
fTrackBarMouseDown := False;
FadeIn;
end;
{ TFavouritesDlg.TPersistentOptions }
constructor TFavouritesDlg.TPersistentOptions.Create;
var
Section: ISettingsSection;
begin
inherited Create;
Section := Settings.ReadSection(ssFavourites);
fDisplayInNewTabs := Boolean(
StrToIntDef(Section.ItemValues['DisplayInNewTabs'], Ord(False))
);
fInactiveAlphaBlendValue := StrToIntDef(
Section.ItemValues['InactiveAlphaBlendValue'], 160)
;
end;
destructor TFavouritesDlg.TPersistentOptions.Destroy;
var
Section: ISettingsSection;
begin
Section := Settings.EmptySection(ssFavourites);
Section.ItemValues['DisplayInNewTabs'] := IntToStr(Ord(fDisplayInNewTabs));
Section.ItemValues['InactiveAlphaBlendValue'] := IntToStr(
fInactiveAlphaBlendValue
);
Section.Save;
inherited;
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.