1 {
2  *****************************************************************************
3   See the file COPYING.modifiedLGPL.txt, included in this distribution,
4   for details about the license.
5  *****************************************************************************
6 
7  Authors: Michael W. Vogel
8 
9 }
10 
11 unit DockedTools;
12 
13 {$mode objfpc}{$H+}
14 { $define DEBUGDOCKEDFORMEDITORINIDE}
15 
16 interface
17 
18 uses
19   // RTL, FCL
20   Classes, SysUtils,
21   // LCL
22   LCLProc, Forms, Controls,
23   // IDEIntf
24   IDEMsgIntf, SrcEditorIntf, IDEExternToolIntf,
25   // DockedFormEditor
26   DockedDesignForm;
27 
28 {$IFDEF DEBUGDOCKEDFORMEDITORINIDE}
29 procedure DebugLn(s: String); overload;
30 procedure DebugLn(s1, s2: String); overload;
31 procedure DebugLn(s1, s2, s3: String); overload;
32 {$ENDIF}
33 
EnumerationStringnull34 function  EnumerationString(Str1, Str2: String): String;
FindSourceEditorForDesignernull35 function  FindSourceEditorForDesigner(ADesigner: TIDesigner): TSourceEditorInterface;
36 procedure IDEMessage(AString: String);
LinedStringnull37 function  LinedString(Str1, Str2: String): String;
SourceWindowCaptionnull38 function  SourceWindowCaption(ASourceEditor: TSourceEditorInterface): String;
SourceWindowGetnull39 function  SourceWindowGet(ASourceEditor: TSourceEditorInterface): TSourceEditorWindowInterface;
40 
41 implementation
42 
43 {$IFDEF DEBUGDOCKEDFORMEDITORINIDE}
44 procedure DebugLn(s: String);
45 begin
46   IDEMessage(s);
47 end;
48 
49 procedure DebugLn(s1, s2: String);
50 begin
51   IDEMessage(s1 + s2);
52 end;
53 
54 procedure DebugLn(s1, s2, s3: String);
55 begin
56   IDEMessage(s1 + s2 + s3);
57 end;
58 {$ENDIF}
59 
EnumerationStringnull60 function EnumerationString(Str1, Str2: String): String;
61 begin
62   if Str1.IsEmpty then
63     Result := Str2
64   else
65     Result := Str1 + ', ' + Str2;
66 end;
67 
FindSourceEditorForDesignernull68 function FindSourceEditorForDesigner(ADesigner: TIDesigner): TSourceEditorInterface;
69 var
70   i: Integer;
71 begin
72   for i := 0 to SourceEditorManagerIntf.SourceEditorCount - 1 do
73     if SourceEditorManagerIntf.SourceEditors[i].GetDesigner(False) = ADesigner then
74       Exit(SourceEditorManagerIntf.SourceEditors[i]);
75   Result := nil;
76 end;
77 
78 procedure IDEMessage(AString: String);
79 begin
80   LCLProc.DebugLn(AString);
81   if Assigned(IDEMessagesWindow) then
82     IDEMessagesWindow.AddCustomMessage(mluNone, AString, '');
83 end;
84 
LinedStringnull85 function LinedString(Str1, Str2: String): String;
86 begin
87   if Str1.IsEmpty then
88     Result := Str2
89   else
90     Result := Str1 + LineEnding + Str2;
91 end;
92 
SourceWindowCaptionnull93 function SourceWindowCaption(ASourceEditor: TSourceEditorInterface): String;
94 var
95   LSourceWindowIntf: TSourceEditorWindowInterface;
96 begin
97   LSourceWindowIntf := SourceWindowGet(ASourceEditor);
98   if Assigned(LSourceWindowIntf) then
99     Result := LSourceWindowIntf.Caption
100   else
101     Result := 'nil';
102 end;
103 
SourceWindowGetnull104 function SourceWindowGet(ASourceEditor: TSourceEditorInterface): TSourceEditorWindowInterface;
105 var
106   LWinControl: TWinControl;
107 begin
108   Result := nil;
109   if not Assigned(ASourceEditor) then Exit;
110   LWinControl := ASourceEditor.EditorControl;
111   while Assigned(LWinControl) do
112   begin
113     if LWinControl is TSourceEditorWindowInterface then
114       Exit(TSourceEditorWindowInterface(LWinControl));
115     LWinControl := LWinControl.Parent;
116   end;
117 end;
118 
119 end.
120 
121