added prettyformat package for IDE beautification features from Michael VC

git-svn-id: trunk@7920 -
This commit is contained in:
mattias 2005-10-06 09:29:21 +00:00
parent 52d68d377f
commit 494dd9c1b5
6 changed files with 1605 additions and 1 deletions

4
.gitattributes vendored
View File

@ -145,6 +145,10 @@ components/mysql/registermysql.lrs svneol=native#text/pascal
components/mysql/registermysql.pas svneol=native#text/pascal
components/mysql/tmysqldatabase.xpm -text svneol=native#image/x-xpixmap
components/mysql/tmysqldataset.xpm -text svneol=native#image/x-xpixmap
components/prettyformat/pfidesource.pas svneol=native#text/plain
components/prettyformat/prettyformat.lpk svneol=native#text/plain
components/prettyformat/prettyformat.pas svneol=native#text/plain
components/prettyformat/ptopu.pp svneol=native#text/plain
components/printers/linux/cupsdyn.pp svneol=native#text/pascal
components/printers/linux/cupsprinters.inc svneol=native#text/pascal
components/printers/linux/cupsprinters_h.inc svneol=native#text/pascal

View File

@ -0,0 +1,147 @@
unit pfidesource;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,LCLtype;
Procedure PrettyPrintSelection(Sender : TObject);
Procedure PrettyPrintFile(Sender : TObject);
Procedure Register;
implementation
uses menuintf, idecommands, srceditorintf, ptopu;
Const
SCmdPFSelection = 'PrettyFormatSelection';
SCmdPFFile = 'PrettyFormatFile';
SCatFormatting = 'Formatting';
Resourcestring
SDescrPFSelection = 'Pretty-Format Selection';
SDescrPFFile = 'Pretty-Format File';
SDescrFormatting = 'Formatting commands';
Var
CmdFormatSelection : TIDECommand;
CmdFormatFile : TIDECommand;
Procedure Register;
Var
Key : TIDEShortCut;
Cat : TIDECommandCategory;
begin
Key:=IDEShortCut(VK_F,[SSctrl,ssShift],VK_UNKNOWN,[]);
{$ifndef USECustomCategory}
Cat:=IDECommandList.CreateCategory(Nil,
SCatFormatting,
SDescrFormatting,
IDECmdScopeSrcEditOnly);
{$else}
cat:=nil,
{$endif}
CmdFormatSelection:=RegisterIDECommand(Cat,
SDescrPFSelection,
SCmdPFSelection,
Key);
Key:=IDEShortCut(VK_F,[SSctrl,ssAlt],VK_UNKNOWN,[]);
CmdFormatFile:=RegisterIDECommand(Cat,
SDescrPFFile,
SCmdPFFile,
Key);
RegisterIDEMenuCommand(SrcEditSubMenuRefactor,
SCmdPFSelection,
SDescrPFSelection,
Nil,@PrettyPrintSelection,CmdFormatSelection);
RegisterIDEMenuCommand(SrcEditSubMenuRefactor,
SCmdPFFile,
SDescrPFFile,
Nil,@PrettyPrintFile,CmdFormatFile);
RegisterIDEMenuCommand(itmEditBlockIndentation,
SCmdPFSelection,
SDescrPFSelection,
Nil,@PrettyPrintSelection,CmdFormatSelection);
RegisterIDEMenuCommand(itmEditBlockIndentation,
SCmdPFFile,
SDescrPFFile,
Nil,@PrettyPrintFile,CmdFormatFile);
end;
Procedure PrettyPrintStream(SIn,SOut : TStream);
Var
PP : TPrettyPrinter;
begin
PP:=TPrettyPrinter.Create;
Try
PP.Source:=Sin;
PP.Dest:=Sout;
PP.PrettyPrint;
Finally
PP.Free;
end;
end;
Procedure PrettyPrintSelection(Sender : TObject);
Var
S1,S2 : TSTringStream;
E : TSourceEditorInterface;
begin
if Sender=nil then ;
E:=SourceEditorWindow.ActiveEditor;
If (E=Nil) or (Not E.SelectionAvailable) then
Exit;
S1:=TStringStream.Create(E.Selection);
Try
S2:=TStringStream.Create('');
Try
S1.Position:=0;
PrettyPrintStream(S1,S2);
E.Selection:=S2.DataString;
Finally
S2.Free;
end;
Finally
S1.Free;
end;
end;
Procedure PrettyPrintFile(Sender : TObject);
Var
S1,S2 : TMemoryStream;
E : TSourceEditorInterface;
begin
if Sender=nil then ;
E:=SourceEditorWindow.ActiveEditor;
If (E=Nil) then
Exit;
S1:=TMemoryStream.Create;
Try
E.Lines.SaveToStream(S1);
S1.Position:=0;
S2:=TMemoryStream.Create;
Try
PrettyPrintStream(S1,S2);
S2.Position:=0;
E.Lines.LoadFromStream(S2);
Finally
S2.Free;
end;
Finally
S1.Free;
end;
end;
end.

View File

@ -0,0 +1,46 @@
<?xml version="1.0"?>
<CONFIG>
<Package Version="2">
<Name Value="prettyformat"/>
<CompilerOptions>
<Version Value="5"/>
<SearchPaths>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)/"/>
</SearchPaths>
<CodeGeneration>
<Generate Value="Faster"/>
</CodeGeneration>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Files Count="2">
<Item1>
<Filename Value="ptopu.pp"/>
<UnitName Value="PtoPu"/>
</Item1>
<Item2>
<Filename Value="pfidesource.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="pfidesource"/>
</Item2>
</Files>
<Type Value="RunAndDesignTime"/>
<RequiredPkgs Count="2">
<Item1>
<PackageName Value="IDEIntf"/>
</Item1>
<Item2>
<PackageName Value="FCL"/>
<MinVersion Major="1" Valid="True"/>
</Item2>
</RequiredPkgs>
<UsageOptions>
<UnitPath Value="$(PkgOutDir)"/>
</UsageOptions>
<PublishOptions>
<Version Value="2"/>
<IgnoreBinaries Value="False"/>
</PublishOptions>
</Package>
</CONFIG>

View File

@ -0,0 +1,21 @@
{ This file was automatically created by Lazarus. Do not edit!
This source is only used to compile and install the package.
}
unit prettyformat;
interface
uses
PtoPu, pfidesource, LazarusPackageIntf;
implementation
procedure Register;
begin
RegisterUnit('pfidesource', @pfidesource.Register);
end;
initialization
RegisterPackage('prettyformat', @Register);
end.

File diff suppressed because it is too large Load Diff

View File

@ -2227,7 +2227,7 @@ begin
FFlags:=[lpfAutoIncrementVersionOnBuild];
FAutoUpdate:=pupAsNeeded;
fCompilerOptions.UnitOutputDirectory:=
'lib'+PathDelim+'$(TargetCPU)-$(Target_OS)'+PathDelim;
'lib'+PathDelim+'$(TargetCPU)-$(TargetOS)'+PathDelim;
FUsageOptions.UnitPath:='$(PkgOutDir)';
end else begin
FFlags:=[lpfDestroying];