File: feditbook.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (127 lines) | stat: -rw-r--r-- 2,739 bytes parent folder | download | duplicates (5)
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
unit fEditBook;
(* Maintain a chain of active (editor) windows.
  Move form to front whenever activated.
  Dequeue form when destroyed.

  The queue head is stored in the global variable MRUEdit.

  The EditBook should become a frame, embeddable without docking.
*)

{$mode objfpc}{$H+}

{ TODO : figure out what's wrong with the mru list - with multiple windows }
{.$DEFINE mru} //problems with MRU list???

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  SynEdit,
  fDockBook;

type
  TEditPage = class(TSynEdit)
  protected
    function  GetFloatingDockSiteClass: TWinControlClass; override;
  public
    FileName: string;
    procedure LoadFile(const AName: string);
  end;

  TEditBook = class(TEasyDockBook)
    procedure FormActivate(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  private
    { private declarations }
  protected
    NRUEdit: TEditBook; //Next Recently Used EditBook
  public
    constructor Create(TheOwner: TComponent); override;
    function OpenFile(const AName: string): boolean;
  end; 

var
  MRUEdit: TEditBook; //Most Recently Used EditBook

implementation

{$R feditbook.lfm}

uses
  uMakeSite;

{ TEditBook }

constructor TEditBook.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  //DockMaster.AddElasticSites(self, [alLeft, alRight, alBottom]);
end;

procedure TEditBook.FormActivate(Sender: TObject);
var
  prev: TEditBook;
begin
//enQ self as first
  if MRUEdit = Self then
    exit; //is alread head
  prev := MRUEdit;
{$IFDEF mru}
  while (prev <> nil) and (prev.NRUEdit <> self) do
    prev := prev.NRUEdit;
  if prev <> nil then
    prev.NRUEdit := self.NRUEdit; //was already in Q
  NRUEdit := MRUEdit; //old head
  MRUEdit := self;  //become head
{$ELSE}
{$ENDIF}
end;

procedure TEditBook.FormClose(Sender: TObject; var CloseAction: TCloseAction);
var
  prev: TEditBook;
begin
//deQ self
  prev := MRUEdit;
{$IFDEF mru}
  if prev = self then
    MRUEdit := NRUEdit
  else begin
    while (prev <> nil) and (prev.NRUEdit <> self) do
      prev := prev.NRUEdit;
    if prev.NRUEdit = self then
      prev.NRUEdit := NRUEdit;
    //else not in chain?
  end;
  NRUEdit := nil;
{$ELSE}
{$ENDIF}
end;

function TEditBook.OpenFile(const AName: string): boolean;
var
  se: TEditPage;
begin
  se := TEditPage.Create(Owner);
  se.ManualDock(self);
  se.LoadFile(AName);
  Result := True;
end;

{ TEditPage }

function TEditPage.GetFloatingDockSiteClass: TWinControlClass;
begin
  //Result:=inherited GetFloatingDockSiteClass;
  Result := TEditBook; //try auto-wrap
end;

procedure TEditPage.LoadFile(const AName: string);
begin
  FileName := AName;
  Lines.LoadFromFile(AName);
end;

end.