~ubuntu-branches/ubuntu/vivid/lazarus/vivid

« back to all changes in this revision

Viewing changes to doceditor/freditor.pp

  • Committer: Package Import Robot
  • Author(s): Paul Gevers, Abou Al Montacir, Paul Gevers
  • Date: 2014-02-22 10:25:57 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20140222102557-ors9d31r84nz31jq
Tags: 1.2~rc2+dfsg-1
[ Abou Al Montacir ]
* New upstream pre-release.
  + Moved ideintf to components directory.
  + Added new package cairocanvas.
* Remove usage of depreciated parameters form of find. (Closes: Bug#724776)
* Bumped standard version to 3.9.5.
* Clean the way handling make files generation and removal.

[ Paul Gevers ]
* Remove nearly obsolete bzip compression for binary packages
  (See https://lists.debian.org/debian-devel/2014/01/msg00542.html)
* Update d/copyright for newly added dir in examples and components
* Update Vcs-* fields with new packaging location
* Update d/watch file to properly (Debian way) change upstreams versions
* Prevent 46MB of package size by sym linking duplicate files
* Patches
  - refresh to remove fuzz
  - add more Lintian found spelling errors
  - new patch to add shbang to two scripts in lazarus-src
* Drop lcl-# from Provides list of lcl-units-#
* Make lazarus-ide-qt4-# an arch all until it really contains stuff
* Make all metapackages arch all as the usecase for arch any doesn't
  seem to warrant the addition archive hit
* Fix permissions of non-scripts in lazarus-src-#

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
{
 
2
 ***************************************************************************
 
3
 *                                                                         *
 
4
 *   This source is free software; you can redistribute it and/or modify   *
 
5
 *   it under the terms of the GNU General Public License as published by  *
 
6
 *   the Free Software Foundation; either version 2 of the License, or     *
 
7
 *   (at your option) any later version.                                   *
 
8
 *                                                                         *
 
9
 *   This code is distributed in the hope that it will be useful, but      *
 
10
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 
12
 *   General Public License for more details.                              *
 
13
 *                                                                         *
 
14
 *   A copy of the GNU General Public License is available on the World    *
 
15
 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
 
16
 *   obtain it by writing to the Free Software Foundation,                 *
 
17
 *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
 
18
 *                                                                         *
 
19
 ***************************************************************************
 
20
 
 
21
  Author: Michael Van Canneyt
 
22
  Changed to Frame by Vladislav V. Sudarikov 
 
23
}
 
24
unit freditor;
 
25
 
 
26
{$mode objfpc}{$H+}
 
27
 
 
28
interface
 
29
 
 
30
uses SysUtils, Classes, DOM, xmlread, xmlwrite, Forms, Controls, ExtCtrls,
 
31
     StdCtrls, Dialogs, Menus, fpdeutil, Lazdemsg, Lazdeopts,
 
32
     GraphType, ActnList, LResources, Buttons;
 
33
 
 
34
Type
 
35
 
 
36
  { TElemEditorFrame }
 
37
  TGetElementListEvent = Procedure (List : TStrings) of Object;
 
38
  TGetInitialDirEvent = function: string of object;
 
39
 
 
40
  { TElemEditorFrame }
 
41
 
 
42
  TElemEditorFrame = Class(TFrame)
 
43
    edtShortEntry: TEdit;
 
44
    GroupBox1: TGroupBox;
 
45
    lblDescr: TLabel;
 
46
    lblErrors: TLabel;
 
47
    lblExamples: TLabel;
 
48
    lblNewElem: TLabel;
 
49
    lblSeeAlso: TLabel;
 
50
    lblShortDescr: TLabel;
 
51
    lbxExamples: TListBox;
 
52
    lbxSeeAlso: TListBox;
 
53
    memDescr: TMemo;
 
54
    memErrors: TMemo;
 
55
    pnlDescr: TPanel;
 
56
    pnlErrors: TPanel;
 
57
    pnlExamples: TPanel;
 
58
    pnlSeeAlso: TPanel;
 
59
    pnlShorDescr: TPanel;
 
60
    spbAddExample: TSpeedButton;
 
61
    spbAddSeeAlso: TSpeedButton;
 
62
    spbEditExample: TSpeedButton;
 
63
    spbEditElementLink: TSpeedButton;
 
64
    spbDeleteExample: TSpeedButton;
 
65
    spbDeleteSeeAlso: TSpeedButton;
 
66
    spbEditSeeAlso: TSpeedButton;
 
67
    Splitter1: TSplitter;
 
68
    Splitter3: TSplitter;
 
69
    Splitter4: TSplitter;
 
70
    Procedure OnEnterControl(Sender : TObject);
 
71
    Procedure OnTextModified(Sender : TObject);
 
72
    Procedure DoEditSeeAlso(Sender: TObject);
 
73
    Procedure DoDeleteSeeAlso(Sender: TObject);
 
74
    Procedure DoAddExample(Sender : TObject);
 
75
    Procedure DoEditExample(Sender : TObject);
 
76
    Procedure DoDeleteExample(Sender : TObject);
 
77
    Procedure DoAddSeeAlso(Sender : TObject);
 
78
    Procedure DoEditElementLink(Sender : TObject);
 
79
  private
 
80
    FElementLink : String;
 
81
    Felement : TDomElement;
 
82
    FCurrentEditable : TWinControl;
 
83
    FGetElementList: TGetElementListEvent;
 
84
    FSavedNode,
 
85
    FModified : Boolean;
 
86
    FTargetFileName: string;
 
87
    FGetInitialDir: TGetInitialDirEvent;
 
88
    FChangeEvent: TNotifyEvent;
 
89
    FOnChangeCount: Integer;
 
90
    Function EditLink(Var Value,ALinkText : String) : Boolean;
 
91
    procedure SetModified(const AValue: Boolean);
 
92
    procedure ShowElementCaption;
 
93
  Protected
 
94
    Function GetCurrentSelection : String; virtual; abstract;
 
95
    Procedure SetElement (Value : TDomElement); virtual;
 
96
    Function GetInitialDir: String;
 
97
    procedure LockOnChange;
 
98
    procedure UnLockOnChange;
 
99
  Public
 
100
    Procedure Refresh; virtual; abstract;
 
101
    Function  TestSave(S : String) : Boolean; virtual; abstract;
 
102
    Function  CurrentXML : String; virtual; abstract;
 
103
    Function  Save : Boolean; virtual; abstract;
 
104
    Function  CanInsertTag(TagTYpe : TTagType) : Boolean; virtual; abstract;
 
105
    Procedure DeleteElement; virtual; abstract;
 
106
    Procedure InsertTag (tagName : String); virtual; abstract;
 
107
    Procedure InsertTag (TagType : TTagType); virtual; abstract;
 
108
    Procedure InsertLink(LinkTarget,LinkText : String); virtual; abstract;
 
109
    Procedure InsertTable(Cols,Rows : Integer; UseHeader : Boolean); virtual; abstract;
 
110
    procedure InsertPrintShortLink(pLinkTarget: string); virtual; abstract;
 
111
    procedure InsertItemizeList(ItemsCount: Integer); virtual; abstract;
 
112
    procedure InsertEnumerateList(ItemsCount: Integer); virtual; abstract;
 
113
 
 
114
    Property  Element : TDomElement Read FElement Write SetElement;
 
115
    Property  CurrentSelection : String Read GetCurrentSelection;
 
116
    Property  Modified : Boolean Read FModified Write SetModified;
 
117
    Property  SavedNode : Boolean Read FSavedNode Write FSavedNode;
 
118
    Property  TargetFileName: String read FTargetFileName write FTargetFileName;
 
119
    Property  OnGetElementList : TGetElementListEvent Read FGetElementList Write FGetElementList;
 
120
    Property  OnGetInitialDir: TGetInitialDirEvent read FGetInitialdir write FGetInitialDir;
 
121
    Property  OnChange: TNotifyEvent read FChangeEvent write FChangeEvent;
 
122
  end;
 
123
  
 
124
  { TElementEditor }
 
125
 
 
126
  TElementEditor = Class(TElemEditorFrame)
 
127
  Private
 
128
    FExampleNodes : TList;
 
129
    FShortNode,
 
130
    FDescrNode,
 
131
    FErrorsNode,
 
132
    FSeeAlsoNode : TDomElement;
 
133
    Procedure GetNodes;
 
134
    Function  CurrentEditable : TWinControl;
 
135
  Public
 
136
    Constructor Create (AOwner : TComponent); override;
 
137
    Destructor Destroy; override;
 
138
    Procedure Refresh;override;
 
139
    Function GetCurrentSelection : String; override;
 
140
    Procedure SetElement (Value : TDomElement);override;
 
141
    Function  TestSave(S : String) : Boolean;override;
 
142
    Function  CurrentXML : String; override;
 
143
    Function  Save : Boolean; override;
 
144
    Function  CanInsertTag(TagTYpe : TTagType) : Boolean; override;
 
145
    Procedure DeleteElement; override;
 
146
    Procedure InsertTag (tagName : String); override;
 
147
    Procedure InsertTag (TagType : TTagType); override;
 
148
    Procedure InsertLink(LinkTarget,LinkText : String); override;
 
149
    Procedure InsertTable(Cols,Rows : Integer; UseHeader : Boolean); override;
 
150
    procedure InsertPrintShortLink(pLinkTarget: string); override;
 
151
    procedure InsertItemizeList(ItemsCount: Integer); override;
 
152
    procedure InsertEnumerateList(ItemsCount: Integer); override;
 
153
  end;
 
154
 
 
155
implementation
 
156
 
 
157
uses frmexample, frmLink, StrUtils, LCLProc, FrmMain;
 
158
 
 
159
Function JoinLinkText(lblShortDescr,T : String): String;
 
160
begin
 
161
  Result:=lblShortDescr;
 
162
  If (T<>'') then
 
163
    Result:=Result+'|'+T;
 
164
end;
 
165
 
 
166
Procedure SplitLinkText(LT : String; out lblShortDescr,T : String);
 
167
 
 
168
Var
 
169
  P : Integer;
 
170
 
 
171
begin
 
172
  P:=Pos('|',LT);
 
173
  If (P=0) then
 
174
    begin
 
175
    lblShortDescr:=LT;
 
176
    T:='';
 
177
    end
 
178
  else
 
179
    begin
 
180
    T:=LT;
 
181
    lblShortDescr:=Copy(LT,1,P-1);
 
182
    Delete(T,1,P);
 
183
    end;
 
184
end;
 
185
 
 
186
{$R *.lfm}
 
187
 
 
188
{ TElemEditorFrame }
 
189
 
 
190
procedure TElemEditorFrame.SetModified(const AValue: Boolean);
 
191
begin
 
192
  FModified := AValue;
 
193
  if (FOnChangeCount=0) and FModified and Assigned(FChangeEvent) then
 
194
    FChangeEvent(Self);
 
195
end;
 
196
 
 
197
procedure TElemEditorFrame.SetElement(Value: TDomElement);
 
198
 
 
199
begin
 
200
  FElement:=Value;
 
201
end;
 
202
 
 
203
function TElemEditorFrame.GetInitialDir: String;
 
204
begin
 
205
  result := '';
 
206
  if Assigned(FGetInitialDir) then
 
207
    result := FGetInitialdir();
 
208
end;
 
209
 
 
210
procedure TElemEditorFrame.LockOnChange;
 
211
begin
 
212
  FOnChangeCount := 1;
 
213
end;
 
214
 
 
215
procedure TElemEditorFrame.UnLockOnChange;
 
216
begin
 
217
  FOnChangeCount := 0;
 
218
end;
 
219
 
 
220
{ ---------------------------------------------------------------------
 
221
  TElementEditor
 
222
  ---------------------------------------------------------------------}
 
223
 
 
224
 
 
225
Constructor TElementEditor.Create(AOwner : TComponent);
 
226
begin
 
227
  LockOnChange;
 
228
  Inherited;
 
229
  FExampleNodes:=TList.create;
 
230
  lblShortDescr.Caption := SShortDescription;
 
231
  lblDescr.Caption := sDescription;
 
232
  lblErrors.Caption := SErrors;
 
233
  lblSeeAlso.Caption := SSeeAlso;
 
234
  lblExamples.Caption := SCodeExample;
 
235
  spbAddExample.Hint := SHintToolbarAdd;
 
236
  spbAddSeeAlso.Hint := SHintToolbarAdd;
 
237
  spbDeleteExample.Hint := SHintToolbarDelete;
 
238
  spbDeleteSeeAlso.Hint := SHintToolbarDelete;
 
239
  spbEditElementLink.Hint := SHintToolbarEdit;
 
240
  spbEditExample.Hint := SHintToolbarEdit;
 
241
  spbEditSeeAlso.Hint := SHintToolbarEdit;
 
242
  memDescr.PopupMenu:=MainForm.PopupMenu1;
 
243
end;
 
244
 
 
245
destructor TElementEditor.destroy;
 
246
begin
 
247
  FreeAndNil(FExampleNodes);
 
248
  inherited destroy;
 
249
end;
 
250
 
 
251
Procedure TElementEditor.SetElement (Value : TDomElement);
 
252
 
 
253
begin
 
254
  If (Value<>FElement) then
 
255
    If (not Modified) or Save then
 
256
      begin
 
257
      Inherited;
 
258
      Refresh;
 
259
      end;
 
260
end;
 
261
 
 
262
Procedure TElementEditor.DeleteElement;
 
263
begin
 
264
  Element:=Nil;
 
265
end;
 
266
 
 
267
Procedure TElemEditorFrame.ShowElementCaption;
 
268
Var
 
269
  ST : String;
 
270
begin
 
271
  If Assigned(Felement) then
 
272
  begin
 
273
  ST:=Format(SDataForElement,[FElement['name']]);
 
274
  If (FElementLink<>'') then
 
275
    ST:=ST+SLinksTo+FElementLink;
 
276
  end
 
277
else
 
278
  ST := SNoElement;
 
279
  lblNewElem.Caption:=ST;
 
280
end;
 
281
 
 
282
Procedure TElementEditor.Refresh;
 
283
 
 
284
  function RemoveLFAfterTags(S : String) : String;
 
285
  
 
286
    function RemoveLF(S, Tag : string; LenTag : integer) : string;
 
287
    var
 
288
      Remove : Integer;
 
289
    begin
 
290
      Remove := pos(Tag, S);
 
291
      while Remove <> 0 do begin
 
292
        inc(Remove, LenTag);
 
293
        while (Remove <= length(S)) and (S[Remove] in [#10, #13]) do
 
294
          delete(S, Remove, 1);
 
295
        Remove := PosEx(Tag, S, Remove);
 
296
      end;
 
297
      Result := S;
 
298
    end;
 
299
    
 
300
  const
 
301
    Link = '</link>' + LineEnding;
 
302
    LenLink = length(Link) - length(LineEnding);
 
303
    Parag = '<p/>' + LineEnding;
 
304
    LenParag = length(Parag);
 
305
    Bold = '</b>' + LineEnding;
 
306
    LenBold = length(Bold);
 
307
  begin
 
308
    Result := RemoveLF(S, Link, LenLink);
 
309
    Result := RemoveLF(Result, Parag, LenParag);
 
310
    Result := RemoveLF(Result, Bold, LenBold);
 
311
  end;
 
312
 
 
313
Var
 
314
  S : TSTringStream;
 
315
 
 
316
  Function NodeToString(E : TDomElement) : String;
 
317
 
 
318
  Var
 
319
    N : TDomNode;
 
320
 
 
321
  begin
 
322
    If (E=Nil) then
 
323
      Result:=''
 
324
    else
 
325
      begin
 
326
      S.Seek(0,soFromBeginning);
 
327
      S.Size:=0;
 
328
      N:=E.FirstChild;
 
329
      While Assigned(N) do
 
330
        begin
 
331
        WriteXml(N,S);
 
332
        N:=N.NextSibling;
 
333
        end;
 
334
      Result:=RemoveLFAfterTags(S.Datastring);
 
335
    end;
 
336
  end;
 
337
 
 
338
  Function RemoveLineFeeds(S : String) : String;
 
339
 
 
340
  Var
 
341
    I : Integer;
 
342
 
 
343
  begin
 
344
    Result:=S;
 
345
    For i := Length(Result) downto 1 do
 
346
      If Result[i] in [#10,#13] then
 
347
        Delete(Result, i, 1);
 
348
  end;
 
349
 
 
350
Var
 
351
  I: Integer;
 
352
  N : TDomNode;
 
353
begin
 
354
  GetNodes;
 
355
  ShowElementCaption;
 
356
  S := TStringStream.Create('');
 
357
  LockOnChange;
 
358
  Try
 
359
    edtShortEntry.Text:=RemoveLineFeeds(NodeToString(FShortNode));
 
360
    memDescr.Text:=NodeToString(FDescrNode);
 
361
    memErrors.Text:=NodeToString(FErrorsNode);
 
362
    lbxSeeAlso.Items.Clear;
 
363
    If Assigned(FSeeAlsoNode) then
 
364
      begin
 
365
      N:=FSeeAlsoNode.FirstChild;
 
366
      While N<>Nil do
 
367
        begin
 
368
        If IsLinkNode(N) then
 
369
          lbxSeeAlso.Items.Add(JoinLinkText(TDomElement(N)['id'],NodeToString(TDomElement(N))));
 
370
        N:=N.NextSibling;
 
371
        end;
 
372
      end;
 
373
    lbxExamples.Items.Clear;
 
374
    For I:=0 to FExampleNodes.Count-1 do
 
375
      lbxExamples.Items.Add(TDomElement(FExampleNodes[i])['file']);
 
376
    FModified:=False;
 
377
  Finally
 
378
    S.Free;
 
379
    UnLockOnChange;
 
380
  end;
 
381
end;
 
382
 
 
383
Function TElementeditor.TestSave(S : String) : Boolean;
 
384
 
 
385
Const
 
386
  Head = '<?xml version="1.0" encoding="ISO-8859-1"?><fpdoc-descriptions>';
 
387
  Tail = '</fpdoc-descriptions>';
 
388
  SErrorSaving = 'There is an error in the documentation nodes:'+LineEnding+
 
389
                 '%s'+LineEnding+
 
390
                 'Please correct it first and try saving again.';
 
391
 
 
392
Var
 
393
  D : TXMLDocument;
 
394
  SS : TStringStream;
 
395
 
 
396
begin
 
397
  Result:=Length(S)=0;
 
398
  If Not Result then
 
399
    begin
 
400
    SS:=TStringStream.Create(Head+S+Tail);
 
401
    D:=nil;
 
402
    Try
 
403
      Try
 
404
        ReadXmlFile(D,SS);
 
405
        Result:=True;
 
406
      except
 
407
        On E : Exception do
 
408
           MessageDlg(Format(SErrorSaving,[E.Message]),mtError,[mbOK],0)
 
409
      end;
 
410
    finally
 
411
      D.Free;
 
412
      SS.Free;
 
413
    end;
 
414
    end;
 
415
end;
 
416
 
 
417
 
 
418
Function  TElementEditor.CurrentXML : String;
 
419
 
 
420
  Function GetNodeString(NodeName,Value : String) : String;
 
421
 
 
422
  begin
 
423
    Result:='';
 
424
    If (Value<>'') Then
 
425
      Result:=Format('<%s>%s</%s>',[NodeName,Value,NodeName])
 
426
    else If Not SkipEmptyNodes then
 
427
      result:='<'+NodeName+'/>';
 
428
  end;
 
429
 
 
430
Var
 
431
  I : Integer;
 
432
  S,L,LT : String;
 
433
 
 
434
begin
 
435
  Result:='';
 
436
  If Not Assigned(FElement) then
 
437
    Exit;
 
438
  Result:=GetNodeString('short',Trim(edtShortEntry.Text));
 
439
  Result:=Result+GetNodeString('descr',trim(memDescr.Text));
 
440
  Result:=Result+GetNodeString('errors',trim(memErrors.Text));
 
441
  S:='';
 
442
  for I:=0 to lbxSeeAlso.Items.Count-1 do
 
443
    begin
 
444
    LT:=Trim(lbxSeeAlso.Items[i]);
 
445
    if (LT<>'') then
 
446
      begin
 
447
      SplitLinkText(LT,L,LT);
 
448
      If (LT<>'') then
 
449
        S:=S+'<link id="'+L+'">'+LT+'</link>'
 
450
      else
 
451
        S:=S+'<link id="'+L+'"/>';
 
452
      end;
 
453
    end;
 
454
  Result:=Result+GetNodeString('seealso',S);
 
455
  S:='';
 
456
  for I:=0 to lbxExamples.Items.Count-1 do
 
457
    if Trim(lbxExamples.Items[i])<>'' then
 
458
      S:=S+'<example file="'+Trim(lbxExamples.Items[i])+'"/>';
 
459
  Result:=Result+S;
 
460
  //Result:=Result+GetNodeString('example',S);
 
461
end;
 
462
 
 
463
Function TElementEditor.Save : Boolean;
 
464
 
 
465
Var
 
466
  SS : TStream;
 
467
  S : String;
 
468
  N,NN : TDomNode;
 
469
 
 
470
begin
 
471
  Result:=Not Assigned(FElement);
 
472
  if Not Result then
 
473
    begin
 
474
    Result:=False;
 
475
    S:=CurrentXML;
 
476
    If TestSave(S) then
 
477
      begin
 
478
      SS:=TStringStream.Create(S);
 
479
      Try
 
480
        // Free child nodes.
 
481
        N:=FElement.FirstChild;
 
482
        While N<>Nil do
 
483
          begin
 
484
          NN:=N.NextSibling;
 
485
          If not (IsElementNode(N) or IsModuleNode(N) or IsTopicNode(N)) then
 
486
            FElement.RemoveChild(N);
 
487
          N:=NN;
 
488
          end;
 
489
        // Read them again from stream.
 
490
        SS.Seek(0,soFromBeginning);
 
491
        ReadXMLFragment(FElement,SS);
 
492
        FModified:=False;
 
493
        If (FElementLink<>'') then
 
494
          FElement['link']:=FElementLink;
 
495
        // We must get the nodes back, because they were deleted !
 
496
        GetNodes;
 
497
        Result:=True;
 
498
        FSavedNode:=True;
 
499
      Finally
 
500
        SS.Free;
 
501
      end;
 
502
      end;
 
503
    end;
 
504
end;
 
505
 
 
506
function TElementEditor.CanInsertTag(TagTYpe: TTagType): Boolean;
 
507
begin
 
508
  Result:=(FCurrentEditable is TCustomEdit)
 
509
          and ((TagType<>ttTable) or (FCurrentEditable is TMemo));
 
510
end;
 
511
 
 
512
procedure TElementEditor.InsertTag (tagName : String);
 
513
var
 
514
  S : String;
 
515
  SS:integer;
 
516
begin
 
517
  If Assigned(CurrentEditable) and (CurrentEditable is TCustomEdit) then
 
518
    with TCustomEdit(CurrentEditable)do
 
519
    begin
 
520
      S:=SelText;
 
521
      SS:=SelStart;
 
522
      S:=Format('<%s>%s</%s>',[TagName,S,TagName]);
 
523
      Seltext:=S;
 
524
      SelStart:=SS;
 
525
      SelLength:=UTF8Length(S);
 
526
      Modified:=True;
 
527
    end;
 
528
end;
 
529
 
 
530
Procedure TElementEditor.InsertTag(TagType : TTagType);
 
531
 
 
532
begin
 
533
  InsertTag(TagNames[TagTYpe]);
 
534
end;
 
535
 
 
536
Procedure TElementEditor.InsertLink(LinkTarget,LinkText : String);
 
537
 
 
538
begin
 
539
  If (CurrentEditable<>Nil) and (CurrentEditable is TCustomEdit) then
 
540
    With TCustomEdit(CurrentEditable) do
 
541
      begin
 
542
      If (LinkText<>'') then
 
543
        SelText:='<link id="'+LinkTarget+'">'+LinkText+'</link>'
 
544
      else
 
545
        SelText:='<link id="'+LinkTarget+'"/>';
 
546
      end
 
547
  else if (CurrentEditable=lbxSeeAlso) then
 
548
    lbxSeeAlso.Items.add(LinkTarget);
 
549
  Modified:=True;
 
550
end;
 
551
 
 
552
Procedure TElementEditor.InsertTable(Cols,Rows : Integer; UseHeader : Boolean);
 
553
 
 
554
Var
 
555
  I : Integer;
 
556
  R,T : String;
 
557
 
 
558
begin
 
559
  If (CurrentEditable is TMemo) then
 
560
    begin
 
561
    R:='<tr>';
 
562
    For I:=1 to Cols do
 
563
      R:=R+'<td></td>';
 
564
    R:=R+'</tr>'+lineEnding;
 
565
    T:='';
 
566
    If UseHeader then
 
567
      begin
 
568
      Dec(Rows);
 
569
      T:='<th>';
 
570
      For I:=1 to Cols do
 
571
        T:=T+'<td></td>';
 
572
      T:=T+'</th>'+lineEnding;
 
573
      end;
 
574
    For I:=1 to rows do
 
575
      T:=T+R;
 
576
    T:=LineEnding+'<table>'+LineEnding+T+'</table>'+LineEnding;
 
577
    With TMemo(CurrentEditable) do
 
578
      SelText:=t;
 
579
    end;
 
580
end;
 
581
 
 
582
 
 
583
procedure TElementEditor.InsertPrintShortLink(pLinkTarget: string);
 
584
begin
 
585
  { Should be Limit insert only to Long Description edit box? }
 
586
  if (CurrentEditable <> nil) and (CurrentEditable is TCustomEdit) then
 
587
  begin
 
588
    (CurrentEditable as TCustomEdit).SelText :=
 
589
        Format('<%s id="%s"/>', [TagNames[ttPrintShort], pLinkTarget]);
 
590
  end;
 
591
  Modified := True;
 
592
end;
 
593
 
 
594
procedure TElementEditor.InsertItemizeList(ItemsCount: Integer);
 
595
var
 
596
  I: Integer;
 
597
  R: String;
 
598
begin
 
599
  If (CurrentEditable is TMemo) then
 
600
    begin
 
601
    R:='<ul>'+lineEnding;
 
602
    for I:=1 to ItemsCount do
 
603
      R:=R+'<li></li>'+lineEnding;
 
604
    R:=R+'</ul>'+lineEnding;
 
605
    With TMemo(CurrentEditable) do
 
606
      SelText:=R;
 
607
    end;
 
608
end;
 
609
 
 
610
procedure TElementEditor.InsertEnumerateList(ItemsCount: Integer);
 
611
var
 
612
  I: Integer;
 
613
  R: String;
 
614
begin
 
615
  if (CurrentEditable is TMemo) then
 
616
  begin
 
617
  R:='<ol>'+lineEnding;
 
618
  for I:=1 to ItemsCount do
 
619
    R:=R+'<li></li>'+lineEnding;
 
620
  R:=R+'</ol>'+lineEnding;
 
621
  with TMemo(CurrentEditable) do
 
622
    SelText:=R;
 
623
  end;
 
624
end;
 
625
 
 
626
 
 
627
Procedure TElementEditor.GetNodes;
 
628
 
 
629
Var
 
630
  Node : TDomNode;
 
631
  S : String;
 
632
 
 
633
begin
 
634
  FShortNode:=Nil;
 
635
  FDescrNode:=Nil;
 
636
  FErrorsNode:=Nil;
 
637
  FSeeAlsoNode:=Nil;
 
638
  FExampleNodes.Clear;
 
639
  If Assigned(FElement) then
 
640
    begin
 
641
    FElementLink:=FElement['link'];
 
642
    Node:=FElement.FirstChild;
 
643
    While Assigned(Node) do
 
644
      begin
 
645
      If (Node.NodeType=ELEMENT_NODE) then
 
646
        begin
 
647
        S:=Node.NodeName;
 
648
        If S='short' then
 
649
          FShortNode:=TDomElement(Node)
 
650
        else if S='descr' then
 
651
          FDescrNode:=TDomElement(Node)
 
652
        else if S='errors' then
 
653
          FErrorsNode:=TDomElement(Node)
 
654
        else if S='seealso' then
 
655
          FSeeAlsoNode:=TDomElement(Node)
 
656
        else if S='example' then
 
657
          FExampleNodes.Add(Node);
 
658
        end;
 
659
      Node:=Node.NextSibling;
 
660
      end;
 
661
    end;
 
662
end;
 
663
 
 
664
Function TElementEditor.CurrentEditable : TWinControl;
 
665
 
 
666
begin
 
667
  Result:=FCurrentEditable;
 
668
end;
 
669
 
 
670
procedure TElemEditorFrame.OnEnterControl(Sender: TObject);
 
671
begin
 
672
  if Sender=nil then ;
 
673
  FCurrentEditable:=Sender as TWinControl;
 
674
end;
 
675
 
 
676
Procedure TElemEditorFrame.OnTextModified(Sender : TObject);
 
677
begin
 
678
  if Sender=nil then ;
 
679
  Modified:=True;
 
680
end;
 
681
 
 
682
procedure TElemEditorFrame.DoAddExample(Sender: TObject);
 
683
 
 
684
begin
 
685
  if Sender=nil then ;
 
686
  With TExampleForm.Create(Self) do
 
687
    Try
 
688
      Caption := SInsertExampleCode;
 
689
      EFileName.Text := 'example.pp';
 
690
      LEFileName.Caption := SCodeExample;
 
691
      EFileName.InitialDir := GetInitialDir;
 
692
      If ShowModal=mrOK then
 
693
        begin
 
694
          if lbxExamples.Items.IndexOf(ExampleName)<0 then
 
695
          begin
 
696
            lbxExamples.Items.Add(ExampleName);
 
697
            Modified:=True;
 
698
          end;
 
699
        end;
 
700
    Finally
 
701
      Free;
 
702
    end;
 
703
end;
 
704
 
 
705
procedure TElemEditorFrame.DoEditExample(Sender: TObject);
 
706
 
 
707
begin
 
708
  if Sender=nil then ;
 
709
  With lbxExamples do
 
710
    begin
 
711
    If ItemIndex<>-1 then
 
712
      With TExampleForm.Create(Self) do
 
713
        Try
 
714
          Caption := SInsertExampleCode;
 
715
          EFileName.Text := Items[ItemIndex];
 
716
          LEFileName.Caption := SCodeExample;
 
717
          EFileName.InitialDir := GetInitialDir;
 
718
          If ShowModal=mrOK then
 
719
            begin
 
720
            Items[ItemIndex]:=ExampleName;
 
721
            Modified:=True;
 
722
            end;
 
723
        Finally
 
724
          Free;
 
725
        end;
 
726
    end;
 
727
end;
 
728
 
 
729
procedure TElemEditorFrame.DoDeleteExample(Sender: TObject);
 
730
 
 
731
begin
 
732
  if Sender=nil then ;
 
733
  With lbxExamples do
 
734
    begin
 
735
    If ItemIndex<>-1 then
 
736
      begin
 
737
      Items.Delete(ItemIndex);
 
738
      Modified:=True;
 
739
      end;
 
740
    end;
 
741
end;
 
742
 
 
743
Function TElemEditorFrame.EditLink(Var Value,ALinkText : String) : Boolean;
 
744
begin
 
745
  With TLinkForm.Create(Self) do
 
746
    try
 
747
      Caption:=SInsertLink;
 
748
      LLinkTarget.Caption := SLinkTarget;
 
749
      LELinkText.Caption := SLinkText;
 
750
      If Assigned(OnGetElementList) then
 
751
        begin
 
752
        Links.BeginUpdate;
 
753
        Try
 
754
          OnGetElementList(Links);
 
755
        Finally
 
756
          Links.EndUpdate;
 
757
        end;
 
758
        end;
 
759
      Link:=Value;
 
760
      LinkText:=ALinkText;
 
761
      Result:=ShowModal=mrOK;
 
762
      If Result then
 
763
        begin
 
764
        Value:=CBTarget.Text;
 
765
        ALinkText:=LinkText;
 
766
        end;
 
767
    Finally
 
768
      Free;
 
769
    end;
 
770
end;
 
771
 
 
772
procedure TElemEditorFrame.DoAddSeeAlso(Sender: TObject);
 
773
Var
 
774
  S,T : String;
 
775
begin
 
776
  if Sender=nil then ;
 
777
  S:='';
 
778
  T:='';
 
779
  If EditLink(S,T) then
 
780
    begin
 
781
    S:=JoinLinkText(S,T);
 
782
      if lbxSeeAlso.Items.IndexOf(S)<0 then
 
783
        begin
 
784
          lbxSeeAlso.Items.Add(S);
 
785
          Modified:=True;
 
786
        end;
 
787
    end;
 
788
end;
 
789
 
 
790
procedure TElemEditorFrame.DoEditSeeAlso(Sender: TObject);
 
791
Var
 
792
  S,T : String;
 
793
begin
 
794
  if Sender=nil then ;
 
795
  With lbxSeeAlso do
 
796
    begin
 
797
    If (ItemIndex>=0) then
 
798
      begin
 
799
      SplitLinkText(Items[ItemIndex],S,T);
 
800
      end
 
801
    else
 
802
      begin
 
803
      S:='';
 
804
      T:='';
 
805
      end;
 
806
    If EditLink(S,T) then
 
807
      begin
 
808
      S:=JoinLinkText(S,T);
 
809
      If (ItemIndex>=0) then
 
810
        Items[ItemIndex]:=S
 
811
      else
 
812
        Items.Add(S);
 
813
      Modified:=True;
 
814
      end;
 
815
    end;
 
816
end;
 
817
 
 
818
procedure TElemEditorFrame.DoDeleteSeeAlso(Sender: TObject);
 
819
begin
 
820
  if Sender=nil then ;
 
821
  With lbxSeeAlso do
 
822
    If (ItemIndex<>-1) then
 
823
      begin
 
824
      Items.Delete(ItemIndex);
 
825
      Modified:=True;
 
826
      end;
 
827
end;
 
828
 
 
829
procedure TElemEditorFrame.DoEditElementLink(Sender: TObject);
 
830
begin
 
831
  With TLinkForm.Create(Self) do
 
832
    try
 
833
      Caption:=SHintEditElementLink;
 
834
      LLinkTarget.Caption := SLinkTarget;
 
835
      LELinkText.Caption := SLinkText;
 
836
      If Assigned(OnGetElementList) then
 
837
        begin
 
838
        Links.BeginUpdate;
 
839
        Try
 
840
          OnGetElementList(Links);
 
841
        Finally
 
842
          Links.EndUpdate;
 
843
        end;
 
844
        end;
 
845
      Link:=FElementLink;
 
846
      EnableLinkText:=False;
 
847
      If ShowModal=mrOK then
 
848
        begin
 
849
        FElementLink:=Link;
 
850
        ShowElementCaption;
 
851
        end;
 
852
    Finally
 
853
      Free;
 
854
    end;
 
855
end;
 
856
 
 
857
Function TElementEditor.GetCurrentSelection : String;
 
858
 
 
859
begin
 
860
  If (CurrentEditable=Nil) or not (CurrentEditable is TCustomEdit) then
 
861
    Result:=''
 
862
  else
 
863
    Result:=TCustomEdit(CurrentEditable).SelText;
 
864
end;
 
865
 
 
866
initialization
 
867
  {$i icons.lrs}
 
868
 
 
869
end.
 
870
 
 
871
 
 
872