cody: declare var: switch back to src

git-svn-id: trunk@30842 -
This commit is contained in:
mattias 2011-05-21 22:15:13 +00:00
parent 53866fee38
commit 78a0a9a879
2 changed files with 31 additions and 24 deletions

View File

@ -5439,7 +5439,7 @@ begin
// apply the changes // apply the changes
if not SourceChangeCache.Apply then if not SourceChangeCache.Apply then
RaiseException(ctsUnableToApplyChanges); RaiseException(ctsUnableToApplyChanges);
exit; exit(true);
end; end;
Node:=Node.Parent; Node:=Node.Parent;
end; end;

View File

@ -34,7 +34,7 @@ interface
uses uses
Classes, SysUtils, LCLProc, contnrs, LResources, Forms, Controls, Graphics, Classes, SysUtils, LCLProc, contnrs, LResources, Forms, Controls, Graphics,
Dialogs, ButtonPanel, StdCtrls, ExtCtrls, Dialogs, ButtonPanel, StdCtrls, ExtCtrls,
IDEDialogs, LazIDEIntf, IDEDialogs, LazIDEIntf, SrcEditorIntf,
FileProcs, CodeToolManager, FindDeclarationTool, CodeTree, FileProcs, CodeToolManager, FindDeclarationTool, CodeTree,
KeywordFuncLists, BasicCodeTools, CodeAtom, KeywordFuncLists, BasicCodeTools, CodeAtom,
CodyUtils, CodyStrConsts; CodyUtils, CodyStrConsts;
@ -198,8 +198,6 @@ end;
procedure TCodyDeclareVarDialog.OKButtonClick(Sender: TObject); procedure TCodyDeclareVarDialog.OKButtonClick(Sender: TObject);
var var
NewType: TCaption; NewType: TCaption;
Target: TCodyDeclareVarTarget;
OldChange: boolean;
begin begin
NewType:=Trim(TypeEdit.Text); NewType:=Trim(TypeEdit.Text);
if NewType='' then begin if NewType='' then begin
@ -214,22 +212,6 @@ begin
IDEMessageDialog('Error','Please specify a location',mtError,[mbCancel]); IDEMessageDialog('Error','Please specify a location',mtError,[mbCancel]);
exit; exit;
end; end;
Target:=TCodyDeclareVarTarget(Targets[WhereRadioGroup.ItemIndex]);
OldChange:=LazarusIDE.OpenEditorsOnCodeToolChange;
try
LazarusIDE.OpenEditorsOnCodeToolChange:=true;
if not CodeToolBoss.DeclareVariable(Target.NodeStartPos.Code,
Target.NodeStartPos.X,Target.NodeStartPos.Y,
Identifier,RecommendedType,UnitOfType,Target.Visibility)
then begin
LazarusIDE.DoJumpToCodeToolBossError;
ModalResult:=mrCancel;
exit;
end;
finally
LazarusIDE.OpenEditorsOnCodeToolChange:=OldChange;
end;
ModalResult:=mrOk; ModalResult:=mrOk;
end; end;
@ -265,6 +247,9 @@ var
Target: TCodyDeclareVarTarget; Target: TCodyDeclareVarTarget;
Context: TFindContext; Context: TFindContext;
i: Integer; i: Integer;
OldChange: boolean;
OldSrcEdit: TSourceEditorInterface;
NewType: String;
begin begin
Result:=false; Result:=false;
PossibleContexts:=nil; PossibleContexts:=nil;
@ -274,10 +259,6 @@ begin
RecommendedType,UnitOfType,PossibleContexts) RecommendedType,UnitOfType,PossibleContexts)
then exit; then exit;
// ToDo: target interface
// ToDo: target implementation
// ToDo: target global (program)
if PossibleContexts<>nil then begin if PossibleContexts<>nil then begin
for i:=0 to PossibleContexts.Count-1 do begin for i:=0 to PossibleContexts.Count-1 do begin
Context:=PFindContext(PossibleContexts[i])^; Context:=PFindContext(PossibleContexts[i])^;
@ -308,6 +289,32 @@ begin
WhereRadioGroup.ItemIndex:=0; WhereRadioGroup.ItemIndex:=0;
Result:=ShowModal=mrOk; Result:=ShowModal=mrOk;
if Result then begin
NewType:=Trim(TypeEdit.Text);
Target:=TCodyDeclareVarTarget(Targets[WhereRadioGroup.ItemIndex]);
OldChange:=LazarusIDE.OpenEditorsOnCodeToolChange;
try
OldSrcEdit:=SourceEditorManagerIntf.ActiveEditor;
LazarusIDE.OpenEditorsOnCodeToolChange:=true;
if not CodeToolBoss.DeclareVariable(Target.NodeStartPos.Code,
Target.NodeStartPos.X,Target.NodeStartPos.Y,
Identifier,NewType,UnitOfType,Target.Visibility)
then begin
debugln(['TCodyDeclareVarDialog.Run Error']);
LazarusIDE.DoJumpToCodeToolBossError;
ModalResult:=mrCancel;
exit;
end;
if Target.NodeStartPos.Code<>CodePos.Code then begin
// declaration was in another unit => switch back to cursor
//debugln(['TCodyDeclareVarDialog.OKButtonClick switching back to ',OldSrcEdit.FileName]);
SourceEditorManagerIntf.ActiveEditor:=OldSrcEdit;
end;
finally
LazarusIDE.OpenEditorsOnCodeToolChange:=OldChange;
end;
end;
end; end;
end. end.