added make resourcestring dialog, not finished

git-svn-id: trunk@2882 -
This commit is contained in:
mattias 2002-08-18 08:55:28 +00:00
parent b0113dd83c
commit c71c909bc7
4 changed files with 593 additions and 11 deletions

2
.gitattributes vendored
View File

@ -10,6 +10,7 @@ components/codetools/codetoolmanager.pas svneol=native#text/pascal
components/codetools/codetoolmemmanager.pas svneol=native#text/pascal
components/codetools/codetools.inc svneol=native#text/pascal
components/codetools/codetoolsstrconsts.pas svneol=native#text/pascal
components/codetools/codetoolsstructs.pas svneol=native#text/pascal
components/codetools/codetree.pas svneol=native#text/pascal
components/codetools/customcodetool.pas svneol=native#text/pascal
components/codetools/definetemplates.pas svneol=native#text/pascal
@ -206,6 +207,7 @@ ide/lazconf.pp svneol=native#text/pascal
ide/macropromptdlg.pas svneol=native#text/pascal
ide/main.pp svneol=native#text/pascal
ide/mainbar.pas svneol=native#text/pascal
ide/makeresstrdlg.pas svneol=native#text/pascal
ide/miscoptions.pas svneol=native#text/pascal
ide/msgview.pp svneol=native#text/pascal
ide/newdialog.pas svneol=native#text/pascal

View File

@ -0,0 +1,181 @@
{
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This code is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
***************************************************************************
Author: Mattias Gaertner
Abstract:
Most codetools returns simple values like a single code position or a
string. But some creates lists of data.
This unit provides structures for complex results.
TCodeXYPositions - a list of PCodeXYPosition
}
unit CodeToolsStructs;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, CodeCache, CodeAtom;
type
{ TCodeXYPositions - a list of PCodeXYPosition }
TCodeXYPositions = class
private
FItems: TList; // list of PCodeXYPosition, can be nil
function GetCaretsXY(Index: integer): TPoint;
function GetCodes(Index: integer): TCodeBuffer;
function GetItems(Index: integer): PCodeXYPosition;
procedure SetCaretsXY(Index: integer; const AValue: TPoint);
procedure SetCodes(Index: integer; const AValue: TCodeBuffer);
procedure SetItems(Index: integer; const AValue: PCodeXYPosition);
public
constructor Create;
destructor Destroy; override;
procedure Clear;
function Add(const Position: TCodeXYPosition): integer;
function Add(X,Y: integer; Code: TCodeBuffer): integer;
function Count: integer;
procedure Delete(Index: integer);
public
property Items[Index: integer]: PCodeXYPosition
read GetItems write SetItems; default;
property CaretsXY[Index: integer]: TPoint read GetCaretsXY write SetCaretsXY;
property Codes[Index: integer]: TCodeBuffer read GetCodes write SetCodes;
end;
implementation
{ TCodeXYPositions }
function TCodeXYPositions.GetItems(Index: integer): PCodeXYPosition;
begin
Result:=PCodeXYPosition(FItems[Index]);
end;
function TCodeXYPositions.GetCaretsXY(Index: integer): TPoint;
var
Item: PCodeXYPosition;
begin
Item:=Items[Index];
Result:=Point(Item^.X,Item^.Y);
end;
function TCodeXYPositions.GetCodes(Index: integer): TCodeBuffer;
var
Item: PCodeXYPosition;
begin
Item:=Items[Index];
Result:=Item^.Code;
end;
procedure TCodeXYPositions.SetCaretsXY(Index: integer; const AValue: TPoint);
var
Item: PCodeXYPosition;
begin
Item:=Items[Index];
Item^.X:=AValue.X;
Item^.Y:=AValue.Y;
end;
procedure TCodeXYPositions.SetCodes(Index: integer; const AValue: TCodeBuffer);
var
Item: PCodeXYPosition;
begin
Item:=Items[Index];
Item^.Code:=AValue;
end;
procedure TCodeXYPositions.SetItems(Index: integer;
const AValue: PCodeXYPosition);
begin
FItems[Index]:=AValue;
end;
constructor TCodeXYPositions.Create;
begin
end;
destructor TCodeXYPositions.Destroy;
begin
Clear;
FItems.Free;
FItems:=nil;
inherited Destroy;
end;
procedure TCodeXYPositions.Clear;
var
i: Integer;
Item: PCodeXYPosition;
begin
if FItems<>nil then begin
for i:=0 to FItems.Count-1 do begin
Item:=Items[i];
Dispose(Item);
end;
FItems.Clear;
end;
end;
function TCodeXYPositions.Add(const Position: TCodeXYPosition): integer;
var
NewItem: PCodeXYPosition;
begin
New(NewItem);
NewItem^:=Position;
if FItems=nil then FItems:=TList.Create;
Result:=FItems.Add(NewItem);
end;
function TCodeXYPositions.Add(X, Y: integer; Code: TCodeBuffer): integer;
var
NewItem: TCodeXYPosition;
begin
NewItem.X:=X;
NewItem.Y:=Y;
NewItem.Code:=Code;
Result:=Add(NewItem);
end;
function TCodeXYPositions.Count: integer;
begin
if FItems<>nil then
Result:=FItems.Count
else
Result:=0;
end;
procedure TCodeXYPositions.Delete(Index: integer);
var
Item: PCodeXYPosition;
begin
Item:=Items[Index];
Dispose(Item);
FItems.Delete(Index);
end;
end.

View File

@ -55,7 +55,7 @@ uses
BuildLazDialog, MiscOptions, EditDefineTree, CodeToolsOptions, TypInfo,
IDEOptionDefs, CodeToolsDefines, LocalsDlg, DebuggerDlg, InputHistory,
DiskDiffsDialog, UnitDependencies, PublishProjectDlg, ClipBoardHistory,
ProcessList, InitialSetupDlgs, NewDialog,
ProcessList, InitialSetupDlgs, NewDialog, MakeResStrDlg,
// main ide
BaseDebugManager, DebugManager, MainBar;
@ -6881,10 +6881,10 @@ var
begin
Result:=mrCancel;
if not BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,[]) then exit;
{$IFDEF IDE_DEBUG}
{ $IFDEF IDE_DEBUG}
writeln('');
writeln('[TMainIDE.DoMakeResourceString] ************');
{$ENDIF}
{ $ENDIF}
// calculate start and end of expression in source
if CodeToolBoss.GetStringConstBounds(ActiveUnitInfo.Source,
ActiveSrcEdit.EditorComponent.CaretX,
@ -6893,6 +6893,7 @@ begin
EndCode,EndPos.X,EndPos.Y,
true) then
begin
writeln('[TMainIDE.DoMakeResourceString] B');
// the codetools have calculated the maximum bounds
if (StartCode=EndCode) and (CompareCaret(StartPos,EndPos)=0) then begin
MessageDlg('No String Constant Found',
@ -6901,6 +6902,7 @@ begin
mtError,[mbCancel],0);
exit;
end;
writeln('[TMainIDE.DoMakeResourceString] C');
// the user can shorten this range by selecting text
if (Trim(ActiveSrcEdit.EditorComponent.SelText)='') then begin
// the user has not selected text
@ -6921,7 +6923,7 @@ begin
or (CompareCaret(ActiveSrcEdit.EditorComponent.BlockEnd,EndPos)>0)
then begin
MessageDlg('Selection exceeds string constant',
+'Hint: The Make Resourcestring Function expects a string constant.'#13
'Hint: The Make Resourcestring Function expects a string constant.'#13
+'Please select only a string expression and try again.',
mtError,[mbCancel],0);
exit;
@ -6933,17 +6935,23 @@ begin
end;
// gather all reachable resourcestring sections
// ToDo:
{if not CodeToolBoss.FindAllResourceStringSections(ActiveUnitInfo.Source,
if not CodeToolBoss.GatherResourceStringSections(ActiveUnitInfo.Source,
ActiveSrcEdit.EditorComponent.CaretX,
ActiveSrcEdit.EditorComponent.CaretY,
CurResStrCode,CurResStrPos)
ActiveSrcEdit.EditorComponent.CaretY)
then begin
DoJumpToCodeToolBossError;
exit;
end;}
end;
if CodeToolBoss.Positions.Count=0 then begin
MessageDlg('No ResourceString Section found',
'Unable to find a ResourceString section in this or any of the used units.',
mtError,[mbCancel],0);
exit;
end;
Result:=ShowMakeResStrDialog(StartPos,EndPos,StartCode,
CodeToolBoss.Positions);
if Result<>mrOk then exit;
// ToDo:
// - write and open wizard
@ -7806,6 +7814,9 @@ end.
{ =============================================================================
$Log$
Revision 1.473 2003/03/02 09:04:02 mattias
added make resourcestring dialog, not finished
Revision 1.472 2003/02/28 19:10:25 mattias
added new ... dialog

388
ide/makeresstrdlg.pas Normal file
View File

@ -0,0 +1,388 @@
{ $Id$ }
{
/***************************************************************************
makerestrdlg.pas
----------------
***************************************************************************/
***************************************************************************
* *
* This source is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This code is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* General Public License for more details. *
* *
* A copy of the GNU General Public License is available on the World *
* Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
* obtain it by writing to the Free Software Foundation, *
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
***************************************************************************
Author: Mattias Gaertner
Abstract:
TMakeResStrDialog is the dialog to setup how to convert a string constant
into pascal resourcestrings.
}
unit MakeResStrDlg;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Buttons, ComCtrls, StdCtrls, Dialogs,
ExtCtrls, LResources, LazarusIDEStrConsts, IDEOptionDefs, CodeToolManager,
CodeAtom, CodeToolsStructs, CodeCache, SynHighlighterPas, SynEdit,
EditorOptions;
type
TMakeResStrDialog = class(TForm)
MainNotebook: TNoteBook;
SourcePage: TPage;
IdentifierPage: TPage;
ResStrPage: TPage;
StringConstGroupBox: TGroupBox;
StringConstSynEdit: TSynEdit;
SrcPreviewGroupBox: TGroupBox;
SrcPreviewSynEdit: TSynEdit;
IdentPrefixGroupBox: TGroupBox;
IdentPrefixComboBox: TComboBox;
IdentifierListView: TListView;
ResStrSectionGroupBox: TGroupBox;
ResStrSectionComboBox: TComboBox;
InsertPositionRadioGroup: TRadioGroup;
ResStrPreviewGroupBox: TGroupBox;
ResStrPreviewSynEdit: TSynEdit;
OkButton: TButton;
CancelButton: TButton;
SynPasSyn: TSynPasSyn;
procedure CancelButtonClick(Sender: TObject);
procedure IdentPrefixGroupBoxResize(Sender: TObject);
procedure IdentifierPageResize(Sender: TObject);
procedure MakeResStrDialogResize(Sender: TObject);
procedure OkButtonClick(Sender: TObject);
procedure ResStrPageResize(Sender: TObject);
procedure ResStrSectionGroupBoxResize(Sender: TObject);
procedure SourcePageResize(Sender: TObject);
private
procedure SetupComponents;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure FillResourceStringSections(Positions: TCodeXYPositions);
end;
function ShowMakeResStrDialog(
const StartPos, EndPos: TPoint; Code: TCodeBuffer;
Positions: TCodeXYPositions): TModalResult;
implementation
uses
Math;
function ShowMakeResStrDialog(
const StartPos, EndPos: TPoint; Code: TCodeBuffer;
Positions: TCodeXYPositions): TModalResult;
var
MakeResStrDialog: TMakeResStrDialog;
begin
MakeResStrDialog:=TMakeResStrDialog.Create(Application);
// string constant
MakeResStrDialog.StringConstSynEdit.Text:=Code.GetLines(StartPos.Y,EndPos.Y);
// reachable resourcestring sections
MakeResStrDialog.FillResourceStringSections(Positions);
// identifier prefixes
// ToDo
// identifiers and values
// ToDo
// resourcestrings
// ToDo
// new source
// ToDo
Result:=MakeResStrDialog.ShowModal;
IDEDialogLayoutList.SaveLayout(MakeResStrDialog);
MakeResStrDialog.Free;
end;
{ TMakeResStrDialog }
procedure TMakeResStrDialog.MakeResStrDialogResize(Sender: TObject);
begin
with MainNotebook do begin
SetBounds(0,0,Parent.ClientWidth,Parent.ClientHeight-45);
end;
with OkButton do begin
SetBounds(Parent.ClientWidth-200,Parent.ClientHeight-35,80,25);
end;
with CancelButton do begin
SetBounds(OkButton.Left+100,OkButton.Top,OkButton.Width,OkButton.Height);
end;
end;
procedure TMakeResStrDialog.CancelButtonClick(Sender: TObject);
begin
ModalResult:=mrCancel;
end;
procedure TMakeResStrDialog.IdentPrefixGroupBoxResize(Sender: TObject);
begin
with IdentPrefixComboBox do begin
SetBounds(0,0,Parent.ClientWidth,Height);
end;
end;
procedure TMakeResStrDialog.IdentifierPageResize(Sender: TObject);
var
NewTop: Integer;
begin
with IdentPrefixGroupBox do begin
SetBounds(0,0,Parent.ClientWidth,50);
end;
with IdentifierListView do begin
NewTop:=IdentPrefixGroupBox.Top+IdentPrefixGroupBox.Height+5;
SetBounds(0,NewTop,Parent.ClientWidth,Parent.ClientHeight-NewTop);
end;
end;
procedure TMakeResStrDialog.OkButtonClick(Sender: TObject);
begin
ModalResult:=mrOk;
end;
procedure TMakeResStrDialog.ResStrPageResize(Sender: TObject);
var
NewTop: Integer;
begin
with ResStrSectionGroupBox do begin
SetBounds(0,0,Parent.ClientWidth,50);
end;
with InsertPositionRadioGroup do begin
SetBounds(0,ResStrSectionGroupBox.Top+ResStrSectionGroupBox.Height+5,
Parent.ClientWidth,50);
end;
with ResStrPreviewGroupBox do begin
NewTop:=InsertPositionRadioGroup.Top+InsertPositionRadioGroup.Height+5;
SetBounds(0,NewTop,
Parent.ClientWidth,Max(Parent.ClientHeight-NewTop,5));
end;
end;
procedure TMakeResStrDialog.ResStrSectionGroupBoxResize(Sender: TObject);
begin
with ResStrSectionComboBox do begin
SetBounds(0,0,Parent.ClientWidth,Height);
end;
end;
procedure TMakeResStrDialog.SourcePageResize(Sender: TObject);
var
NewTop: Integer;
begin
with StringConstGroupBox do begin
SetBounds(0,0,Parent.ClientWidth,(Parent.ClientHeight div 2)-5);
end;
with SrcPreviewGroupBox do begin
NewTop:=StringConstGroupBox.Top+StringConstGroupBox.Height+5;
SetBounds(StringConstGroupBox.Left,NewTop,
StringConstGroupBox.Width,Parent.ClientHeight-NewTop);
end;
end;
procedure TMakeResStrDialog.SetupComponents;
begin
SynPasSyn:=TSynPasSyn.Create(Self);
MainNotebook:=TNoteBook.Create(Self);
with MainNotebook do begin
Name:='MainNotebook';
Parent:=Self;
Pages.Add('Source');
Pages.Add('Identifiers');
Pages.Add('ResourceStrings');
SourcePage:=Page[0];
IdentifierPage:=Page[1];
ResStrPage:=Page[2];
end;
SourcePage.OnResize:=@SourcePageResize;
IdentifierPage.OnResize:=@IdentifierPageResize;
ResStrPage.OnResize:=@ResStrPageResize;
StringConstGroupBox:=TGroupBox.Create(Self);
with StringConstGroupBox do begin
Name:='StringConstGroupBox';
Parent:=SourcePage;
Caption:='String Constant in source';
end;
StringConstSynEdit:=TSynEdit.Create(Self);
with StringConstSynEdit do begin
Name:='StringConstSynEdit';
Parent:=StringConstGroupBox;
Align:=alClient;
Highlighter:=SynPasSyn;
end;
SrcPreviewGroupBox:=TGroupBox.Create(Self);
with SrcPreviewGroupBox do begin
Name:='SrcPreviewGroupBox';
Parent:=SourcePage;
Caption:='Source preview';
end;
SrcPreviewSynEdit:=TSynEdit.Create(Self);
with SrcPreviewSynEdit do begin
Name:='SrcPreviewSynEdit';
Parent:=SrcPreviewGroupBox;
Align:=alClient;
Highlighter:=SynPasSyn;
end;
IdentPrefixGroupBox:=TGroupBox.Create(Self);
with IdentPrefixGroupBox do begin
Name:='IdentPrefixGroupBox';
Parent:=IdentifierPage;
Caption:='Identifier Prefix';
OnResize:=@IdentPrefixGroupBoxResize;
end;
IdentPrefixComboBox:=TComboBox.Create(Self);
with IdentPrefixComboBox do begin
Name:='IdentPrefixComboBox';
Parent:=IdentPrefixGroupBox;
end;
IdentifierListView:=TListView.Create(Self);
with IdentifierListView do begin
Name:='IdentifierListView';
Parent:=IdentifierPage;
end;
ResStrSectionGroupBox:=TGroupBox.Create(Self);
with ResStrSectionGroupBox do begin
Name:='ResStrSectionGroupBox';
Parent:=ResStrPage;
OnResize:=@ResStrSectionGroupBoxResize;
end;
ResStrSectionComboBox:=TComboBox.Create(Self);
with ResStrSectionComboBox do begin
Name:='ResStrSectionComboBox';
Parent:=ResStrSectionGroupBox;
end;
InsertPositionRadioGroup:=TRadioGroup.Create(Self);
with InsertPositionRadioGroup do begin
Name:='InsertPositionRadioGroup';
Parent:=ResStrPage;
Caption:='Insert Position';
with Items do begin
Add('Alphabetical');
Add('Append');
end;
Columns:=2;
end;
ResStrPreviewGroupBox:=TGroupBox.Create(Self);
with ResStrPreviewGroupBox do begin
Name:='ResStrPreviewGroupBox';
Parent:=ResStrPage;
Caption:='ResourceStrings preview';
end;
ResStrPreviewSynEdit:=TSynEdit.Create(Self);
with ResStrPreviewSynEdit do begin
Name:='ResStrPreviewSynEdit';
Parent:=ResStrPreviewGroupBox;
Align:=alClient;
Highlighter:=SynPasSyn;
end;
OkButton:=TButton.Create(Self);
with OkButton do begin
Name:='OkButton';
Parent:=Self;
Caption:='Ok';
OnClick:=@OkButtonClick;
end;
CancelButton:=TButton.Create(Self);
with CancelButton do begin
Name:='CancelButton';
Parent:=Self;
Caption:='Cancel';
OnClick:=@CancelButtonClick;
end;
end;
constructor TMakeResStrDialog.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
if LazarusResources.Find(Classname)=nil then begin
Name:='MakeResStrDialog';
Caption := 'Make ResourceStrings';
Width:=550;
Height:=400;
Position:=poScreenCenter;
OnResize:=@MakeResStrDialogResize;
SetupComponents;
end;
IDEDialogLayoutList.ApplyLayout(Self,550,400);
OnResize(nil);
EditorOpts.GetHighlighterSettings(SynPasSyn);
EditorOpts.GetSynEditSettings(StringConstSynEdit);
StringConstSynEdit.ReadOnly:=true;
EditorOpts.GetSynEditSettings(SrcPreviewSynEdit);
SrcPreviewSynEdit.ReadOnly:=true;
EditorOpts.GetSynEditSettings(ResStrPreviewSynEdit);
ResStrPreviewSynEdit.ReadOnly:=true;
end;
destructor TMakeResStrDialog.Destroy;
begin
inherited Destroy;
end;
procedure TMakeResStrDialog.FillResourceStringSections(
Positions: TCodeXYPositions);
var
i: Integer;
p: PCodeXYPosition;
s: String;
begin
with ResStrSectionComboBox do begin
Items.BeginUpdate;
for i:=0 to Positions.Count-1 do begin
p:=Positions[i];
s:=p^.Code.Filename+' ('+IntToStr(p^.Y)+','+IntToStr(p^.X)+')';
if i<Items.Count then
Items[i]:=s
else
Items.Add(s);
end;
while Items.Count>Positions.Count do
Items.Delete(Items.Count-1);
Items.EndUpdate;
end;
end;
end.