1 {(*}
2 (*------------------------------------------------------------------------------
3  Delphi Code formatter source code
4 
5 The Original Code is SetTransform.pas, released June 2004.
6 The Initial Developer of the Original Code is Anthony Steele.
7 Portions created by Anthony Steele are Copyright (C) 1999-2008 Anthony Steele.
8 All Rights Reserved.
9 Contributor(s): Anthony Steele.
10 
11 The contents of this file are subject to the Mozilla Public License Version 1.1
12 (the "License"). you may not use this file except in compliance with the License.
13 You may obtain a copy of the License at http://www.mozilla.org/NPL/
14 
15 Software distributed under the License is distributed on an "AS IS" basis,
16 WITHOUT WARRANTY OF ANY KIND, either express or implied.
17 See the License for the specific language governing rights and limitations
18 under the License.
19 
20 Alternatively, the contents of this file may be used under the terms of
21 the GNU General Public License Version 2 or later (the "GPL")
22 See http://www.gnu.org/licenses/gpl.html
23 ------------------------------------------------------------------------------*)
24 {*)}
25 
26 unit SetTransform;
27 
28 { settings to do with Code transformation
29   AFS 5 June 2004
30 }
31 
32 {$I JcfGlobal.inc}
33 
34 interface
35 
36 uses JcfSetBase, SettingsTypes, SettingsStream;
37 
38 type
39   TUsesSortOrder = (eAlpha, eReverseAlpha, eShortToLong, eLongToShort);
40 
41   TSetTransform = class(TSetBase)
42   private
43     { add/remove begin/end from single statement blocks }
44     feBeginEndStyle: TTriOptionStyle;
45     { add a semicolon at the last statement of a block }
46     fbAddBlockEndSemicolon: Boolean;
47 
48     { sort uses clauses }
49 
50     { when to sort }
51     fbSortInterfaceUses: Boolean;
52     fbSortImplementationUses: Boolean;
53     fbSortProgramUses: boolean;
54 
55     fbSortUsesNoComments: boolean;
56 
57     { how to sort}
58     fbBreakUsesSortOnReturn: Boolean;
59     fbBreakUsesSortOnComment: Boolean;
60     feUsesSortOrder: TUsesSortOrder;
61   public
62     constructor Create;
63 
64     procedure WriteToStream(const pcOut: TSettingsOutput); override;
65     procedure ReadFromStream(const pcStream: TSettingsInput); override;
66 
67     property BeginEndStyle: TTriOptionStyle read feBeginEndStyle write feBeginEndStyle;
68     property AddBlockEndSemicolon: boolean read fbAddBlockEndSemicolon write fbAddBlockEndSemicolon;
69 
70     property SortInterfaceUses: Boolean read fbSortInterfaceUses write fbSortInterfaceUses;
71     property SortImplementationUses: Boolean read fbSortImplementationUses write fbSortImplementationUses;
72     property SortProgramUses: Boolean read fbSortProgramUses write fbSortProgramUses;
73 
74     property SortUsesNoComments: Boolean read fbSortUsesNoComments write fbSortUsesNoComments;
75 
76     property BreakUsesSortOnReturn: Boolean read fbBreakUsesSortOnReturn write fbBreakUsesSortOnReturn;
77     property BreakUsesSortOnComment: Boolean read fbBreakUsesSortOnComment write fbBreakUsesSortOnComment;
78     property UsesSortOrder: TUsesSortOrder read feUsesSortOrder write feUsesSortOrder;
79 
80   end;
81 
82 implementation
83 
84 const
85   REG_BEGIN_END_STYLE = 'BeginEndStyle';
86   REG_ADD_BLOCK_END_SEMICOLON = 'AddBlockEndSemicolon';
87   REG_SORT_USES_INTERFACE = 'SortUsesInterface';
88   REG_SORT_USES_IMPLEMENTATION = 'SortUsesImplmentation';
89   REG_SORT_USES_PROGRAM = 'SortUsesProgram';
90   REG_SORT_USES_BREAK_ON_RETURN = 'SortUsesBreakOnReturn';
91   REG_SORT_USES_BREAK_ON_COMMENT = 'SortUsesBreakOnComment';
92   REG_SORT_USES_SORT_ORDER = 'SortUsesSortOrder';
93   REG_SORT_USES_NO_COMMENTS = 'SortUsesNoComments';
94 
95 constructor TSetTransform.Create;
96 begin
97   inherited;
98   SetSection('Transform');
99 end;
100 
101 procedure TSetTransform.ReadFromStream(const pcStream: TSettingsInput);
102 begin
103   Assert(pcStream <> nil);
104   feBeginEndStyle := TTriOptionStyle(pcStream.Read(REG_BEGIN_END_STYLE, Ord(eLeave)));
105   fbAddBlockEndSemicolon := pcStream.Read(REG_ADD_BLOCK_END_SEMICOLON, True);
106 
107   fbSortInterfaceUses := pcStream.Read(REG_SORT_USES_INTERFACE, True);
108   fbSortImplementationUses := pcStream.Read(REG_SORT_USES_IMPLEMENTATION, True);
109   fbSortProgramUses := pcStream.Read(REG_SORT_USES_PROGRAM, False);
110 
111   fbBreakUsesSortOnReturn := pcStream.Read(REG_SORT_USES_BREAK_ON_RETURN, True);
112   fbBreakUsesSortOnComment := pcStream.Read(REG_SORT_USES_BREAK_ON_COMMENT, True);
113   feUsesSortOrder := TUsesSortOrder(pcStream.Read(REG_SORT_USES_SORT_ORDER, Ord(eAlpha)));
114   fbSortUsesNoComments := pcStream.Read(REG_SORT_USES_NO_COMMENTS, True);
115 end;
116 
117 procedure TSetTransform.WriteToStream(const pcOut: TSettingsOutput);
118 begin
119   Assert(pcOut <> nil);
120 
121   pcOut.Write(REG_BEGIN_END_STYLE, Ord(feBeginEndStyle));
122   pcOut.Write(REG_ADD_BLOCK_END_SEMICOLON, fbAddBlockEndSemicolon);
123 
124   pcOut.Write(REG_SORT_USES_INTERFACE, fbSortInterfaceUses);
125   pcOut.Write(REG_SORT_USES_IMPLEMENTATION, fbSortImplementationUses);
126   pcOut.Write(REG_SORT_USES_PROGRAM, fbSortProgramUses);
127 
128   pcOut.Write(REG_SORT_USES_BREAK_ON_RETURN, fbBreakUsesSortOnReturn);
129   pcOut.Write(REG_SORT_USES_BREAK_ON_COMMENT, fbBreakUsesSortOnComment);
130   pcOut.Write(REG_SORT_USES_SORT_ORDER, Ord(feUsesSortOrder));
131   pcOut.Write(REG_SORT_USES_NO_COMMENTS, fbSortUsesNoComments);
132 end;
133 
134 end.
135