MG: started component renaming

git-svn-id: trunk@1646 -
This commit is contained in:
lazarus 2002-04-27 18:56:50 +00:00
parent a866d8f430
commit f3cb25dc9c
9 changed files with 211 additions and 70 deletions

View File

@ -272,6 +272,9 @@ type
const AClassName,VarName, VarType: string): boolean; const AClassName,VarName, VarType: string): boolean;
function RemovePublishedVariable(Code: TCodeBuffer; function RemovePublishedVariable(Code: TCodeBuffer;
const AClassName, AVarName: string): boolean; const AClassName, AVarName: string): boolean;
function RenamePublishedVariable(Code: TCodeBuffer;
const AClassName, OldVariableName, NewVarName,
VarType: shortstring): boolean;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -1304,9 +1307,9 @@ function TCodeToolManager.RemovePublishedVariable(Code: TCodeBuffer;
const AClassName, AVarName: string): boolean; const AClassName, AVarName: string): boolean;
begin begin
Result:=false; Result:=false;
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}
writeln('TCodeToolManager.RemovePublishedVariable A ',Code.Filename,' ',AClassName,':',AVarName); writeln('TCodeToolManager.RemovePublishedVariable A ',Code.Filename,' ',AClassName,':',AVarName);
{$ENDIF} {$ENDIF}
if not InitCurCodeTool(Code) then exit; if not InitCurCodeTool(Code) then exit;
try try
Result:=FCurCodeTool.RemovePublishedVariable(UpperCaseStr(AClassName), Result:=FCurCodeTool.RemovePublishedVariable(UpperCaseStr(AClassName),
@ -1316,13 +1319,30 @@ writeln('TCodeToolManager.RemovePublishedVariable A ',Code.Filename,' ',AClassNa
end; end;
end; end;
function TCodeToolManager.RenamePublishedVariable(Code: TCodeBuffer;
const AClassName, OldVariableName, NewVarName, VarType: shortstring): boolean;
begin
Result:=false;
{$IFDEF CTDEBUG}
writeln('TCodeToolManager.RenamePublishedVariable A ',Code.Filename,' ',AClassName,' OldVar=',OldVarName,' NewVar=',NewVarName);
{$ENDIF}
if not InitCurCodeTool(Code) then exit;
try
Result:=FCurCodeTool.RenamePublishedVariable(UpperCaseStr(AClassName),
UpperCaseStr(OldVariableName),NewVarName,VarType,
SourceChangeCache);
except
on e: Exception do Result:=HandleException(e);
end;
end;
function TCodeToolManager.OnScannerGetInitValues(Code: Pointer; function TCodeToolManager.OnScannerGetInitValues(Code: Pointer;
var AChangeStep: integer): TExpressionEvaluator; var AChangeStep: integer): TExpressionEvaluator;
begin begin
Result:=nil; Result:=nil;
AChangeStep:=DefineTree.ChangeStep; AChangeStep:=DefineTree.ChangeStep;
if Code=nil then exit; if Code=nil then exit;
//DefineTree.WriteDebugReport; //DefineTree.WriteDebugReport;
if not TCodeBuffer(Code).IsVirtual then if not TCodeBuffer(Code).IsVirtual then
Result:=DefineTree.GetDefinesForDirectory( Result:=DefineTree.GetDefinesForDirectory(
ExtractFilePath(TCodeBuffer(Code).Filename)) ExtractFilePath(TCodeBuffer(Code).Filename))
@ -1334,7 +1354,7 @@ procedure TCodeToolManager.OnDefineTreeReadValue(Sender: TObject;
const VariableName: string; var Value: string); const VariableName: string; var Value: string);
begin begin
Value:=GlobalValues[VariableName]; Value:=GlobalValues[VariableName];
//writeln('[TCodeToolManager.OnDefineTreeReadValue] Name="',VariableName,'" = "',Value,'"'); //writeln('[TCodeToolManager.OnDefineTreeReadValue] Name="',VariableName,'" = "',Value,'"');
end; end;
procedure TCodeToolManager.OnGlobalValuesChanged; procedure TCodeToolManager.OnGlobalValuesChanged;

View File

@ -652,6 +652,7 @@ begin
Add('PROPERTY',{$ifdef FPC}@{$endif}AllwaysTrue); Add('PROPERTY',{$ifdef FPC}@{$endif}AllwaysTrue);
Add('RAISE',{$ifdef FPC}@{$endif}AllwaysTrue); Add('RAISE',{$ifdef FPC}@{$endif}AllwaysTrue);
Add('RECORD',{$ifdef FPC}@{$endif}AllwaysTrue); Add('RECORD',{$ifdef FPC}@{$endif}AllwaysTrue);
Add('RESOURCESTRING',{$ifdef FPC}@{$endif}AllwaysTrue);
Add('REPEAT',{$ifdef FPC}@{$endif}AllwaysTrue); Add('REPEAT',{$ifdef FPC}@{$endif}AllwaysTrue);
Add('SET',{$ifdef FPC}@{$endif}AllwaysTrue); Add('SET',{$ifdef FPC}@{$endif}AllwaysTrue);
Add('SHL',{$ifdef FPC}@{$endif}AllwaysTrue); Add('SHL',{$ifdef FPC}@{$endif}AllwaysTrue);

View File

@ -45,9 +45,9 @@ uses
{$IFDEF MEM_CHECK} {$IFDEF MEM_CHECK}
MemCheck, MemCheck,
{$ENDIF} {$ENDIF}
Classes, SysUtils, CodeTree, CodeAtom, FindDeclarationTool, PascalParserTool, Classes, SysUtils, CodeToolsStrConsts, CodeTree, CodeAtom,
SourceLog, KeywordFuncLists, BasicCodeTools, LinkScanner, CodeCache, AVL_Tree, FindDeclarationTool, PascalParserTool, SourceLog, KeywordFuncLists,
TypInfo, SourceChanger; BasicCodeTools, LinkScanner, CodeCache, AVL_Tree, TypInfo, SourceChanger;
type type
TStandardCodeTool = class(TFindDeclarationTool) TStandardCodeTool = class(TFindDeclarationTool)
@ -120,7 +120,10 @@ type
SourceChangeCache: TSourceChangeCache): boolean; SourceChangeCache: TSourceChangeCache): boolean;
function RemovePublishedVariable(const UpperClassName, UpperVarName: string; function RemovePublishedVariable(const UpperClassName, UpperVarName: string;
SourceChangeCache: TSourceChangeCache): boolean; SourceChangeCache: TSourceChangeCache): boolean;
function RenamePublishedVariable(const UpperClassName,
UpperOldVarName: string; const NewVarName, VarType: shortstring;
SourceChangeCache: TSourceChangeCache): boolean;
// blocks (e.g. begin..end) // blocks (e.g. begin..end)
function FindBlockCounterPart(CursorPos: TCodeXYPosition; function FindBlockCounterPart(CursorPos: TCodeXYPosition;
var NewPos: TCodeXYPosition; var NewTopLine: integer): boolean; var NewPos: TCodeXYPosition; var NewTopLine: integer): boolean;
@ -999,6 +1002,43 @@ begin
Result:=SourceChangeCache.Apply; Result:=SourceChangeCache.Apply;
end; end;
function TStandardCodeTool.RenamePublishedVariable(const UpperClassName,
UpperOldVarName: string; const NewVarName, VarType: shortstring;
SourceChangeCache: TSourceChangeCache): boolean;
var TypeNode, VarNode: TCodeTreeNode;
begin
Result:=false;
VarNode:=FindPublishedVariable(UpperClassName,UpperOldVarName);
if VarNode<>nil then begin
// old variable found
// check type
TypeNode:=FindTypeNodeOfDefinition(VarNode);
MoveCursorToNodeStart(TypeNode);
ReadNextAtom;
if AtomIs(VarType) then begin
// rename the identifier
MoveCursorToNodeStart(VarNode);
ReadNextAtom;
SourceChangeCache.MainScanner:=Scanner;
if not SourceChangeCache.Replace(gtNone,gtNone,
CurPos.StartPos,CurPos.EndPos,NewVarName)
then
exit;
end else begin
// auto correct type
// ToDo: auto correct
RaiseExceptionFmt(ctsStrExpectedButAtomFound,[VarType,GetAtom]);
end;
Result:=SourceChangeCache.Apply;
end else begin
// old variable not found -> add it
Result:=AddPublishedVariable(UpperClassName,NewVarName, VarType,
SourceChangeCache);
end;
end;
function TStandardCodeTool.FindBlockCounterPart(CursorPos: TCodeXYPosition; function TStandardCodeTool.FindBlockCounterPart(CursorPos: TCodeXYPosition;
var NewPos: TCodeXYPosition; var NewTopLine: integer): boolean; var NewPos: TCodeXYPosition; var NewTopLine: integer): boolean;
// jump from bracket-open to bracket-close or 'begin' to 'end' // jump from bracket-open to bracket-close or 'begin' to 'end'

View File

@ -28,6 +28,8 @@ uses
AlignCompsDlg, SizeCompsDlg, ScaleCompsDlg, ExtCtrls; AlignCompsDlg, SizeCompsDlg, ScaleCompsDlg, ExtCtrls;
type type
TDesigner = class;
TOnGetSelectedComponentClass = procedure(Sender: TObject; TOnGetSelectedComponentClass = procedure(Sender: TObject;
var RegisteredComponent: TRegisteredComponent) of object; var RegisteredComponent: TRegisteredComponent) of object;
TOnSetDesigning = procedure(Sender: TObject; Component: TComponent; TOnSetDesigning = procedure(Sender: TObject; Component: TComponent;
@ -38,6 +40,8 @@ type
of object; of object;
TOnGetNonVisualCompIconCanvas = procedure(Sender: TObject; TOnGetNonVisualCompIconCanvas = procedure(Sender: TObject;
AComponent: TComponent; var IconCanvas: TCanvas) of object; AComponent: TComponent; var IconCanvas: TCanvas) of object;
TOnRenameComponent = procedure(Designer: TDesigner; AComponent: TComponent;
const NewName: string) of object;
TDesigner = class(TIDesigner) TDesigner = class(TIDesigner)
private private
@ -57,6 +61,7 @@ type
FOnSetDesigning: TOnSetDesigning; FOnSetDesigning: TOnSetDesigning;
FOnUnselectComponentClass: TNotifyEvent; FOnUnselectComponentClass: TNotifyEvent;
FOnActivated: TNotifyEvent; FOnActivated: TNotifyEvent;
FOnRenameComponent: TOnRenameComponent;
FPopupMenu: TPopupMenu; FPopupMenu: TPopupMenu;
FAlignMenuItem: TMenuItem; FAlignMenuItem: TMenuItem;
FMirrorHorizontalMenuItem: TMenuItem; FMirrorHorizontalMenuItem: TMenuItem;
@ -133,6 +138,8 @@ type
read FOnUnselectComponentClass write FOnUnselectComponentClass; read FOnUnselectComponentClass write FOnUnselectComponentClass;
property OnActivated: TNotifyEvent property OnActivated: TNotifyEvent
read FOnActivated write FOnActivated; read FOnActivated write FOnActivated;
property OnRenameComponent: TOnRenameComponent
read FOnRenameComponent write FOnRenameComponent;
function NonVisualComponentAtPos(x,y: integer): TComponent; function NonVisualComponentAtPos(x,y: integer): TComponent;
procedure DrawNonVisualComponents(DC: HDC); procedure DrawNonVisualComponents(DC: HDC);
property OnGetNonVisualCompIconCanvas: TOnGetNonVisualCompIconCanvas property OnGetNonVisualCompIconCanvas: TOnGetNonVisualCompIconCanvas
@ -802,7 +809,11 @@ end;
procedure TDesigner.ValidateRename(AComponent: TComponent; procedure TDesigner.ValidateRename(AComponent: TComponent;
const CurName, NewName: string); const CurName, NewName: string);
Begin Begin
writeln('ToDo: TDesigner.ValidateRename ',CurName,', ',NewName); if AComponent=nil then AComponent:=FCustomForm;
if CurName<>AComponent.Name then
writeln('WARNING: TDesigner.ValidateRename: OldComponentName="',CurName,'"');
if Assigned(OnRenameComponent) then
OnRenameComponent(Self,AComponent,NewName);
end; end;
function TDesigner.GetIsControl: Boolean; function TDesigner.GetIsControl: Boolean;

View File

@ -118,13 +118,15 @@ type
end; end;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
TOIPropertyGridState = (pgsChangingItemIndex, pgsApplyingValue);
TOIPropertyGridStates = set of TOIPropertyGridState;
TOIPropertyGrid = class(TCustomControl) TOIPropertyGrid = class(TCustomControl)
private private
FComponentList: TComponentSelectionList; FComponentList: TComponentSelectionList;
FPropertyEditorHook:TPropertyEditorHook; FPropertyEditorHook:TPropertyEditorHook;
FFilter: TTypeKinds; FFilter: TTypeKinds;
FItemIndex:integer; FItemIndex:integer;
FChangingItemIndex:boolean;
FRows:TList; FRows:TList;
FExpandingRow:TOIPropertyGridRow; FExpandingRow:TOIPropertyGridRow;
FTopY:integer; FTopY:integer;
@ -141,6 +143,7 @@ type
FOnModified: TNotifyEvent; FOnModified: TNotifyEvent;
FExpandedProperties:TStringList; FExpandedProperties:TStringList;
FBorderStyle:TBorderStyle; FBorderStyle:TBorderStyle;
FStates: TOIPropertyGridStates;
//hint stuff //hint stuff
FHintTimer : TTimer; FHintTimer : TTimer;
@ -319,7 +322,7 @@ begin
FPropertyEditorHook:=APropertyEditorHook; FPropertyEditorHook:=APropertyEditorHook;
FFilter:=TypeFilter; FFilter:=TypeFilter;
FItemIndex:=-1; FItemIndex:=-1;
FChangingItemIndex:=false; FStates:=[];
FRows:=TList.Create; FRows:=TList.Create;
FExpandingRow:=nil; FExpandingRow:=nil;
FDragging:=false; FDragging:=false;
@ -560,7 +563,8 @@ procedure TOIPropertyGrid.SetRowValue;
var CurRow:TOIPropertyGridRow; var CurRow:TOIPropertyGridRow;
NewValue:string; NewValue:string;
begin begin
if (FChangingItemIndex=false) and (FCurrentEdit<>nil) if (FStates*[pgsChangingItemIndex,pgsApplyingValue]=[])
and (FCurrentEdit<>nil)
and (FItemIndex>=0) and (FItemIndex<FRows.Count) then begin and (FItemIndex>=0) and (FItemIndex<FRows.Count) then begin
CurRow:=Rows[FItemIndex]; CurRow:=Rows[FItemIndex];
if FCurrentEdit=ValueEdit then if FCurrentEdit=ValueEdit then
@ -570,12 +574,19 @@ begin
if length(NewValue)>CurRow.Editor.GetEditLimit then if length(NewValue)>CurRow.Editor.GetEditLimit then
NewValue:=LeftStr(NewValue,CurRow.Editor.GetEditLimit); NewValue:=LeftStr(NewValue,CurRow.Editor.GetEditLimit);
if NewValue<>CurRow.Editor.GetVisualValue then begin if NewValue<>CurRow.Editor.GetVisualValue then begin
Include(FStates,pgsApplyingValue);
try try
CurRow.Editor.SetValue(NewValue); CurRow.Editor.SetValue(NewValue);
except except
on E: Exception do on E: Exception do begin
MessageDlg(E.Message,mtError,[mbOk],0); MessageDlg('Error',E.Message,mtError,[mbOk],0);
if FCurrentEdit=ValueEdit then
ValueEdit.Text:=CurRow.Editor.GetVisualValue
else
ValueComboBox.Text:=CurRow.Editor.GetVisualValue;
end;
end; end;
Exclude(FStates,pgsApplyingValue);
if Assigned(FOnModified) then FOnModified(Self); if Assigned(FOnModified) then FOnModified(Self);
end; end;
end; end;
@ -584,11 +595,16 @@ end;
procedure TOIPropertyGrid.ValueEditKeyDown(Sender: TObject; var Key: Word; procedure TOIPropertyGrid.ValueEditKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState); Shift: TShiftState);
begin begin
if (Key=VK_UP) and (FItemIndex>0) then begin case Key of
ItemIndex:=ItemIndex-1; VK_UP:
end; if (FItemIndex>0) then ItemIndex:=ItemIndex-1;
if (Key=VK_Down) and (FItemIndex<FRows.Count-1) then begin
ItemIndex:=ItemIndex+1; VK_Down:
if (FItemIndex<FRows.Count-1) then ItemIndex:=ItemIndex+1;
VK_RETURN:
SetRowValue;
end; end;
end; end;
@ -653,7 +669,7 @@ var NewRow:TOIPropertyGridRow;
NewValue:string; NewValue:string;
begin begin
SetRowValue; SetRowValue;
FChangingItemIndex:=true; Include(FStates,pgsChangingItemIndex);
if (FItemIndex<>NewIndex) then begin if (FItemIndex<>NewIndex) then begin
if (FItemIndex>=0) and (FItemIndex<FRows.Count) then if (FItemIndex>=0) and (FItemIndex<FRows.Count) then
Rows[FItemIndex].Editor.Deactivate; Rows[FItemIndex].Editor.Deactivate;
@ -706,7 +722,7 @@ begin
FCurrentButton.Enabled:=true; FCurrentButton.Enabled:=true;
end; end;
end; end;
FChangingItemIndex:=false; Exclude(FStates,pgsChangingItemIndex);
end; end;
function TOIPropertyGrid.GetRowCount:integer; function TOIPropertyGrid.GetRowCount:integer;

View File

@ -47,12 +47,12 @@ implementation
constructor TFormEditor.Create; constructor TFormEditor.Create;
Begin Begin
inherited; inherited;
end; end;
destructor TFormEditor.destroy; destructor TFormEditor.destroy;
Begin Begin
inherited; inherited;
end; end;
end. end.

View File

@ -36,14 +36,14 @@ uses
Buttons, Menus, ComCtrls, Spin, Project, SysUtils, FileCtrl, Controls, Buttons, Menus, ComCtrls, Spin, Project, SysUtils, FileCtrl, Controls,
Graphics, ExtCtrls, Dialogs, LazConf, CompReg, CodeToolManager, CodeCache, Graphics, ExtCtrls, Dialogs, LazConf, CompReg, CodeToolManager, CodeCache,
DefineTemplates, MsgView, NewProjectDlg, IDEComp, AbstractFormEditor, DefineTemplates, MsgView, NewProjectDlg, IDEComp, AbstractFormEditor,
FormEditor, CustomFormEditor, ObjectInspector, PropEdits, ControlSelection, Designer, FormEditor, CustomFormEditor, ObjectInspector, PropEdits,
UnitEditor, CompilerOptions, EditorOptions, EnvironmentOpts, TransferMacros, ControlSelection, UnitEditor, CompilerOptions, EditorOptions, EnvironmentOpts,
SynEditKeyCmds, KeyMapping, ProjectOpts, IDEProcs, Process, UnitInfoDlg, TransferMacros, SynEditKeyCmds, KeyMapping, ProjectOpts, IDEProcs, Process,
Debugger, DBGOutputForm, GDBMIDebugger, RunParamsOpts, ExtToolDialog, UnitInfoDlg, Debugger, DBGOutputForm, GDBMIDebugger, RunParamsOpts,
MacroPromptDlg, LMessages, ProjectDefs, Watchesdlg, BreakPointsdlg, ColumnDlg, ExtToolDialog, MacroPromptDlg, LMessages, ProjectDefs, Watchesdlg,
OutputFilter, BuildLazDialog, MiscOptions, EditDefineTree, CodeToolsOptions, BreakPointsdlg, ColumnDlg, OutputFilter, BuildLazDialog, MiscOptions,
TypInfo, IDEOptionDefs, CodeToolsDefines, LocalsDlg, DebuggerDlg, EditDefineTree, CodeToolsOptions, TypInfo, IDEOptionDefs, CodeToolsDefines,
InputHistory, LocalsDlg, DebuggerDlg, InputHistory,
BaseDebugManager, DebugManager, MainBar; BaseDebugManager, DebugManager, MainBar;
type type
@ -177,6 +177,23 @@ type
procedure OnPropHookShowMethod(const AMethodName:ShortString); procedure OnPropHookShowMethod(const AMethodName:ShortString);
procedure OnPropHookRenameMethod(const CurName, NewName:ShortString); procedure OnPropHookRenameMethod(const CurName, NewName:ShortString);
// designer
procedure OnDesignerGetSelectedComponentClass(Sender: TObject;
var RegisteredComponent: TRegisteredComponent);
procedure OnDesignerUnselectComponentClass(Sender: TObject);
procedure OnDesignerSetDesigning(Sender: TObject; Component: TComponent;
Value: boolean);
procedure OnDesignerComponentListChanged(Sender: TObject);
procedure OnDesignerPropertiesChanged(Sender: TObject);
procedure OnDesignerAddComponent(Sender: TObject; Component: TComponent;
ComponentClass: TRegisteredComponent);
procedure OnDesignerRemoveComponent(Sender: TObject; Component: TComponent);
procedure OnDesignerModified(Sender: TObject);
Procedure OnDesignerActivated(Sender : TObject);
procedure OnDesignerRenameComponent(ADesigner: TDesigner;
AComponent: TComponent; const NewName: string);
procedure OnControlSelectionChanged(Sender: TObject);
// Environment options dialog events // Environment options dialog events
procedure OnLoadEnvironmentSettings(Sender: TObject; procedure OnLoadEnvironmentSettings(Sender: TObject;
TheEnvironmentOptions: TEnvironmentOptions); TheEnvironmentOptions: TEnvironmentOptions);
@ -354,7 +371,7 @@ type
ActiveUnitInfo: TUnitInfo; ActiveUnitInfo: TUnitInfo;
NewSource: TCodeBuffer; NewX, NewY, NewTopLine: integer; NewSource: TCodeBuffer; NewX, NewY, NewTopLine: integer;
AddJumpPoint: boolean): TModalResult; AddJumpPoint: boolean): TModalResult;
procedure SaveSourceEditorChangesToCodeCache; procedure SaveSourceEditorChangesToCodeCache(PageIndex: integer);
procedure ApplyCodeToolChanges; procedure ApplyCodeToolChanges;
procedure DoJumpToProcedureSection; procedure DoJumpToProcedureSection;
procedure DoFindDeclarationAtCursor; procedure DoFindDeclarationAtCursor;
@ -384,19 +401,6 @@ type
// form editor and designer // form editor and designer
property SelectedComponent : TRegisteredComponent property SelectedComponent : TRegisteredComponent
read FSelectedComponent write FSelectedComponent; read FSelectedComponent write FSelectedComponent;
procedure OnDesignerGetSelectedComponentClass(Sender: TObject;
var RegisteredComponent: TRegisteredComponent);
procedure OnDesignerUnselectComponentClass(Sender: TObject);
procedure OnDesignerSetDesigning(Sender: TObject; Component: TComponent;
Value: boolean);
procedure OnDesignerComponentListChanged(Sender: TObject);
procedure OnDesignerPropertiesChanged(Sender: TObject);
procedure OnDesignerAddComponent(Sender: TObject; Component: TComponent;
ComponentClass: TRegisteredComponent);
procedure OnDesignerRemoveComponent(Sender: TObject; Component: TComponent);
procedure OnDesignerModified(Sender: TObject);
Procedure OnDesignerActivated(Sender : TObject);
procedure OnControlSelectionChanged(Sender: TObject);
procedure DoBringToFrontFormOrUnit; procedure DoBringToFrontFormOrUnit;
procedure SetDesigning(Control : TComponent; Value : Boolean); procedure SetDesigning(Control : TComponent; Value : Boolean);
@ -414,7 +418,7 @@ const
implementation implementation
uses uses
ViewUnit_dlg, Math, LResources, Designer; ViewUnit_dlg, Math, LResources;
//============================================================================== //==============================================================================
{ {
@ -1903,7 +1907,8 @@ Begin
OnRemoveComponent:=@OnDesignerRemoveComponent; OnRemoveComponent:=@OnDesignerRemoveComponent;
OnGetNonVisualCompIconCanvas:=@IDECompList.OnGetNonVisualCompIconCanvas; OnGetNonVisualCompIconCanvas:=@IDECompList.OnGetNonVisualCompIconCanvas;
OnModified:=@OnDesignerModified; OnModified:=@OnDesignerModified;
OnActivated := @OnDesignerActivated; OnActivated:=@OnDesignerActivated;
OnRenameComponent:=@OnDesignerRenameComponent;
ShowHints:=EnvironmentOptions.ShowEditorHints; ShowHints:=EnvironmentOptions.ShowEditorHints;
end; end;
end; end;
@ -3268,8 +3273,9 @@ writeln('TMainIDE.DoNewEditorUnit A NewFilename=',NewFilename);
Result:=CreateNewCodeBuffer(NewUnitType,NewFilename,NewBuffer,NewUnitName); Result:=CreateNewCodeBuffer(NewUnitType,NewFilename,NewBuffer,NewUnitName);
if Result<>mrOk then exit; if Result<>mrOk then exit;
Result:=mrCancel; Result:=mrCancel;
SaveSourceEditorChangesToCodeCache(-1);
NewFilename:=NewBuffer.Filename; NewFilename:=NewBuffer.Filename;
NewUnitInfo:=TUnitInfo.Create(NewBuffer); NewUnitInfo:=TUnitInfo.Create(NewBuffer);
// create source code // create source code
@ -3332,7 +3338,9 @@ begin
end; end;
GetUnitWithPageIndex(PageIndex,ActiveSrcEdit,ActiveUnitInfo); GetUnitWithPageIndex(PageIndex,ActiveSrcEdit,ActiveUnitInfo);
if ActiveUnitInfo=nil then exit; if ActiveUnitInfo=nil then exit;
if not (sfProjectSaving in Flags) then
SaveSourceEditorChangesToCodeCache(-1);
// if this file is part of the project and the project is virtual then save // if this file is part of the project and the project is virtual then save
// project first // project first
if (not (sfProjectSaving in Flags)) and Project1.IsVirtual if (not (sfProjectSaving in Flags)) and Project1.IsVirtual
@ -3885,6 +3893,7 @@ begin
Result:=mrAbort; Result:=mrAbort;
exit; exit;
end; end;
SaveSourceEditorChangesToCodeCache(-1);
writeln('TMainIDE.DoSaveProject A SaveAs=',sfSaveAs in Flags,' SaveToTestDir=',sfSaveToTestDir in Flags); writeln('TMainIDE.DoSaveProject A SaveAs=',sfSaveAs in Flags,' SaveToTestDir=',sfSaveToTestDir in Flags);
// check that all new units are saved first to get valid filenames // check that all new units are saved first to get valid filenames
@ -4506,8 +4515,8 @@ begin
GetCurrentUnit(ActiveSrcEdit,ActiveUnitInfo); GetCurrentUnit(ActiveSrcEdit,ActiveUnitInfo);
if (ActiveUnitInfo=nil) or (ActiveUnitInfo.Source=nil) if (ActiveUnitInfo=nil) or (ActiveUnitInfo.Source=nil)
or (ActiveSrcEdit=nil) then exit; or (ActiveSrcEdit=nil) then exit;
SaveSourceEditorChangesToCodeCache(-1);
CodeToolBoss.VisibleEditorLines:=ActiveSrcEdit.EditorComponent.LinesInWindow; CodeToolBoss.VisibleEditorLines:=ActiveSrcEdit.EditorComponent.LinesInWindow;
SaveSourceEditorChangesToCodeCache;
if not CodeToolBoss.CheckSyntax(ActiveUnitInfo.Source,NewCode,NewX,NewY, if not CodeToolBoss.CheckSyntax(ActiveUnitInfo.Source,NewCode,NewX,NewY,
NewTopLine,ErrorMsg) then NewTopLine,ErrorMsg) then
begin begin
@ -5356,23 +5365,31 @@ begin
SourceNoteBook.UnlockAllEditorsInSourceChangeCache; SourceNoteBook.UnlockAllEditorsInSourceChangeCache;
end; end;
procedure TMainIDE.SaveSourceEditorChangesToCodeCache; procedure TMainIDE.SaveSourceEditorChangesToCodeCache(PageIndex: integer);
// save all open sources to code tools cache // save all open sources to code tools cache
var i: integer; var i: integer;
CurUnitInfo: TUnitInfo;
SrcEdit: TSourceEditor; procedure SaveChanges(APageIndex: integer);
begin var
for i:=0 to Project1.UnitCount-1 do begin SrcEdit: TSourceEditor;
CurUnitInfo:=Project1.Units[i]; AnUnitInfo: TUnitInfo;
if CurUnitInfo.EditorIndex>=0 then begin begin
SrcEdit:=SourceNotebook.FindSourceEditorWithPageIndex( GetUnitWithPageIndex(APageIndex,SrcEdit,AnUnitInfo);
CurUnitInfo.EditorIndex); if (SrcEdit<>nil) and (AnUnitInfo<>nil) and (SrcEdit.Modified) then begin
if SrcEdit.Modified then begin SrcEdit.UpdateCodeBuffer;
SrcEdit.UpdateCodeBuffer; AnUnitInfo.Modified:=true;
CurUnitInfo.Modified:=true;
end;
end; end;
end; end;
begin
if PageIndex<0 then begin
if (SourceNotebook.NoteBook<>nil) then begin
for i:=0 to SourceNotebook.NoteBook.PageCount-1 do
SaveChanges(i);
end;
end else begin
SaveChanges(PageIndex);
end;
end; end;
function TMainIDE.BeginCodeTool(var ActiveSrcEdit: TSourceEditor; function TMainIDE.BeginCodeTool(var ActiveSrcEdit: TSourceEditor;
@ -5385,7 +5402,7 @@ begin
else else
GetCurrentUnit(ActiveSrcEdit,ActiveUnitInfo); GetCurrentUnit(ActiveSrcEdit,ActiveUnitInfo);
if (ActiveSrcEdit=nil) or (ActiveUnitInfo=nil) then exit; if (ActiveSrcEdit=nil) or (ActiveUnitInfo=nil) then exit;
SaveSourceEditorChangesToCodeCache; SaveSourceEditorChangesToCodeCache(-1);
CodeToolBoss.VisibleEditorLines:=ActiveSrcEdit.EditorComponent.LinesInWindow; CodeToolBoss.VisibleEditorLines:=ActiveSrcEdit.EditorComponent.LinesInWindow;
Result:=true; Result:=true;
end; end;
@ -5683,6 +5700,37 @@ begin
FLastFormActivated := TCustomForm(Sender); FLastFormActivated := TCustomForm(Sender);
end; end;
procedure TMainIDE.OnDesignerRenameComponent(ADesigner: TDesigner;
AComponent: TComponent; const NewName: string);
var
ActiveSrcEdit: TSourceEditor;
ActiveUnitInfo: TUnitInfo;
begin
BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,false);
if AComponent.Owner<>nil then begin
// rename published variable in form source
ActiveUnitInfo:=Project1.UnitWithForm(ADesigner.Form);
if CodeToolBoss.RenamePublishedVariable(ActiveUnitInfo.Source,
ADesigner.Form.ClassName,
AComponent.Name,NewName,AComponent.ClassName) then
begin
ApplyCodeToolChanges;
end else begin
ApplyCodeToolChanges;
DoJumpToCodeToolBossError;
raise Exception.Create('Unable to rename variable in source.'#13
+'See messages.');
end;
end else if AComponent=ADesigner.Form then begin
// rename form in source, form variable and createform statement
MessageDlg('Not implemented yet.',
'Form renaming in source is not implemented yet.',
mtInformation,[mbOk],0);
end else begin
raise Exception.Create('TMainIDE.OnDesignerRenameComponent internal error');
end;
end;
Procedure TMainIDE.OnSrcNoteBookAddJumpPoint(ACaretXY: TPoint; Procedure TMainIDE.OnSrcNoteBookAddJumpPoint(ACaretXY: TPoint;
ATopLine: integer; APageIndex: integer; DeleteForwardHistory: boolean); ATopLine: integer; APageIndex: integer; DeleteForwardHistory: boolean);
var var
@ -6237,6 +6285,9 @@ end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.287 2002/04/27 18:56:47 lazarus
MG: started component renaming
Revision 1.286 2002/04/26 13:50:14 lazarus Revision 1.286 2002/04/26 13:50:14 lazarus
MG: IDE and codetools work now with trimmed filenames MG: IDE and codetools work now with trimmed filenames

View File

@ -322,15 +322,13 @@ type
procedure PaintGrid; virtual; abstract; procedure PaintGrid; virtual; abstract;
procedure ValidateRename(AComponent: TComponent; procedure ValidateRename(AComponent: TComponent;
const CurName, NewName: string); virtual; abstract; const CurName, NewName: string); virtual; abstract;
end; end;
TProcedure = procedure; TProcedure = procedure;
function KeysToShiftState(Keys:Word): TShiftState; function KeysToShiftState(Keys:Word): TShiftState;
function KeyDataToShiftState(KeyData: Longint): TShiftState; function KeyDataToShiftState(KeyData: Longint): TShiftState;
function GetParentForm(Control:TControl): TCustomForm; function GetParentForm(Control:TControl): TCustomForm;

View File

@ -465,7 +465,8 @@ Begin
end; end;
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------}
{ TCustomForm ValidateRename } { TCustomForm ValidateRename }
{ if AComponent is nil, then the name of Self is changed }
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------}
procedure TCustomForm.ValidateRename(AComponent: TComponent; procedure TCustomForm.ValidateRename(AComponent: TComponent;
const CurName, NewName: String); const CurName, NewName: String);
@ -476,7 +477,7 @@ begin
end; end;
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------}
{ TCustomForm WndProc } { TCustomForm WndProc }
{------------------------------------------------------------------------------} {------------------------------------------------------------------------------}
procedure TCustomForm.WndProc(Var Message : TLMessage); procedure TCustomForm.WndProc(Var Message : TLMessage);
var var
@ -1014,6 +1015,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.42 2002/04/27 18:56:50 lazarus
MG: started component renaming
Revision 1.41 2002/04/27 15:35:50 lazarus Revision 1.41 2002/04/27 15:35:50 lazarus
MG: fixed window shrinking MG: fixed window shrinking