mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-16 10:29:28 +02:00
MG: source notebook pagenames are now updated more often
git-svn-id: trunk@1794 -
This commit is contained in:
parent
47d3e0ff51
commit
48e9d401cb
@ -230,6 +230,7 @@ type
|
||||
|
||||
// source name e.g. 'unit UnitName;'
|
||||
function GetSourceName(Code: TCodeBuffer; SearchMainCode: boolean): string;
|
||||
function GetCachedSourceName(Code: TCodeBuffer): string;
|
||||
function RenameSource(Code: TCodeBuffer; const NewName: string): boolean;
|
||||
function GetSourceType(Code: TCodeBuffer; SearchMainCode: boolean): string;
|
||||
|
||||
@ -964,6 +965,32 @@ begin
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
function TCodeToolManager.GetCachedSourceName(Code: TCodeBuffer): string;
|
||||
begin
|
||||
Result:='';
|
||||
if (Code=nil)
|
||||
or (Code.LastIncludedByFile<>'') then exit;
|
||||
{$IFDEF CTDEBUG}
|
||||
writeln('TCodeToolManager.GetCachedSourceName A ',Code.Filename,' ',Code.SourceLength);
|
||||
{$ENDIF}
|
||||
{$IFDEF MEM_CHECK}
|
||||
CheckHeap(IntToStr(GetMem_Cnt));
|
||||
{$ENDIF}
|
||||
if not InitCurCodeTool(Code) then exit;
|
||||
try
|
||||
Result:=FCurCodeTool.GetCachedSourceName;
|
||||
except
|
||||
on e: Exception do HandleException(e);
|
||||
end;
|
||||
{$IFDEF CTDEBUG}
|
||||
writeln('TCodeToolManager.GetCachedSourceName B ',Code.Filename,' ',Code.SourceLength);
|
||||
{$IFDEF MEM_CHECK}
|
||||
CheckHeap(IntToStr(GetMem_Cnt));
|
||||
{$ENDIF}
|
||||
writeln('SourceName=',Result);
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
function TCodeToolManager.GetSourceType(Code: TCodeBuffer;
|
||||
SearchMainCode: boolean): string;
|
||||
begin
|
||||
|
@ -61,6 +61,7 @@ type
|
||||
// source name e.g. 'unit UnitName;'
|
||||
function GetSourceNamePos(var NamePos: TAtomPosition): boolean;
|
||||
function GetSourceName: string;
|
||||
function GetCachedSourceName: string;
|
||||
function RenameSource(const NewName: string;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
|
||||
@ -185,7 +186,7 @@ begin
|
||||
ReadNextAtom; // read source type 'program', 'unit' ...
|
||||
ReadNextAtom; // read name
|
||||
NamePos:=CurPos;
|
||||
Result:=(NamePos.StartPos<SrcLen);
|
||||
Result:=(NamePos.StartPos<=SrcLen);
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.GetSourceName: string;
|
||||
@ -196,6 +197,27 @@ begin
|
||||
Result:=copy(Src,NamePos.StartPos,NamePos.EndPos-NamePos.StartPos);
|
||||
end;
|
||||
|
||||
{-------------------------------------------------------------------------------
|
||||
function TStandardCodeTool.GetCachedSourceName: string;
|
||||
Params: none
|
||||
Result: the source name (= e.g. the identifier behind 'program'/'unit' keyword)
|
||||
|
||||
This function does neither check if source needs reparsing, nor does it check
|
||||
for errors in code. It simple checks if there is a first node, which is
|
||||
typically the source type and name.
|
||||
This function can therefore be used as a fast GetSourceName function.
|
||||
-------------------------------------------------------------------------------}
|
||||
function TStandardCodeTool.GetCachedSourceName: string;
|
||||
begin
|
||||
Result:='';
|
||||
if Tree.Root=nil then exit;
|
||||
MoveCursorToNodeStart(Tree.Root);
|
||||
ReadNextAtom; // read source type 'program', 'unit' ...
|
||||
ReadNextAtom; // read name
|
||||
if (CurPos.StartPos<=SrcLen) then
|
||||
Result:=GetAtom;
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.RenameSource(const NewName: string;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
var NamePos: TAtomPosition;
|
||||
|
44
ide/main.pp
44
ide/main.pp
@ -393,6 +393,7 @@ type
|
||||
ActiveUnitInfo: TUnitInfo;
|
||||
NewSource: TCodeBuffer; NewX, NewY, NewTopLine: integer;
|
||||
AddJumpPoint: boolean): TModalResult;
|
||||
procedure UpdateSourceNames;
|
||||
procedure SaveSourceEditorChangesToCodeCache(PageIndex: integer);
|
||||
procedure ApplyCodeToolChanges;
|
||||
procedure DoJumpToProcedureSection;
|
||||
@ -3606,6 +3607,10 @@ begin
|
||||
if (not (sfSaveToTestDir in Flags)) and (ActiveUnitInfo.IsVirtual) then
|
||||
Include(Flags,sfSaveAs);
|
||||
|
||||
// update source notebook page names
|
||||
if (not (sfProjectSaving in Flags)) then
|
||||
UpdateSourceNames;
|
||||
|
||||
// if file is readonly then a simple Save is skipped
|
||||
ActiveUnitInfo.ReadOnly:=ActiveSrcEdit.ReadOnly;
|
||||
if (ActiveUnitInfo.ReadOnly) and ([sfSaveToTestDir,sfSaveAs]*Flags=[]) then
|
||||
@ -4200,6 +4205,9 @@ writeln('TMainIDE.DoSaveProject A SaveAs=',sfSaveAs in Flags,' SaveToTestDir=',s
|
||||
else
|
||||
Project1.ActiveEditorIndexAtStart:=SourceNotebook.Notebook.PageIndex;
|
||||
|
||||
// update source notebook page names
|
||||
UpdateSourceNames;
|
||||
|
||||
// find mainunit
|
||||
GetMainUnit(MainUnitInfo,MainUnitSrcEdit,true);
|
||||
|
||||
@ -5762,9 +5770,36 @@ begin
|
||||
SetFocus;
|
||||
end;
|
||||
BringWindowToTop(SourceNoteBook.Handle);
|
||||
UpdateSourceNames;
|
||||
Result:=mrOk;
|
||||
end;
|
||||
|
||||
{-------------------------------------------------------------------------------
|
||||
procedure TMainIDE.UpdateSourceNames
|
||||
Params: none
|
||||
|
||||
Check every unit in sourceeditor if the source name has changed and updates
|
||||
the notebook page names.
|
||||
-------------------------------------------------------------------------------}
|
||||
procedure TMainIDE.UpdateSourceNames;
|
||||
var
|
||||
PageIndex: integer;
|
||||
AnUnitInfo: TUnitInfo;
|
||||
SourceName, PageName: string;
|
||||
begin
|
||||
if SourceNotebook.NoteBook=nil then exit;
|
||||
for PageIndex:=0 to SourceNotebook.NoteBook.PageCount-1 do begin
|
||||
AnUnitInfo:=Project1.UnitWithEditorIndex(PageIndex);
|
||||
if AnUnitInfo=nil then continue;
|
||||
if FilenameIsPascalUnit(AnUnitInfo.Filename) then
|
||||
SourceName:=CodeToolBoss.GetCachedSourceName(AnUnitInfo.Source)
|
||||
else
|
||||
SourceName:='';
|
||||
PageName:=CreateSrcEditPageName(SourceName,AnUnitInfo.Filename,PageIndex);
|
||||
SourceNotebook.NoteBook.Pages[PageIndex]:=PageName;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMainIDE.ApplyCodeToolChanges;
|
||||
begin
|
||||
// all changes were handled automatically by events
|
||||
@ -5799,7 +5834,10 @@ var
|
||||
ActiveSrcEdit:TSourceEditor;
|
||||
ErrorCaret: TPoint;
|
||||
begin
|
||||
if CodeToolBoss.ErrorMessage='' then exit;
|
||||
if CodeToolBoss.ErrorMessage='' then begin
|
||||
UpdateSourceNames;
|
||||
exit;
|
||||
end;
|
||||
// syntax error -> show error and jump
|
||||
// show error in message view
|
||||
DoArrangeSourceEditorAndMessageView;
|
||||
@ -5834,6 +5872,7 @@ begin
|
||||
BringWindowToTop(SourceNoteBook.Handle);
|
||||
end;
|
||||
end;
|
||||
UpdateSourceNames;
|
||||
end;
|
||||
|
||||
procedure TMainIDE.DoFindDeclarationAtCursor;
|
||||
@ -6665,6 +6704,9 @@ end.
|
||||
|
||||
{ =============================================================================
|
||||
$Log$
|
||||
Revision 1.327 2002/07/29 13:26:54 lazarus
|
||||
MG: source notebook pagenames are now updated more often
|
||||
|
||||
Revision 1.326 2002/07/22 18:25:10 lazarus
|
||||
MG: reduced output
|
||||
|
||||
|
@ -209,7 +209,9 @@ var
|
||||
begin
|
||||
EventTrace('activate', data);
|
||||
Mess.Msg := LM_ACTIVATE;
|
||||
Mess.Result := 0;
|
||||
Result := DeliverMessage(Data, Mess) = 0;
|
||||
//writeln('gtkactivateCB ',Result);
|
||||
end;
|
||||
|
||||
function gtkchangedCB( widget: PGtkWidget; data: gPointer) : GBoolean; cdecl;
|
||||
@ -2155,6 +2157,9 @@ end;
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.93 2002/07/29 13:26:57 lazarus
|
||||
MG: source notebook pagenames are now updated more often
|
||||
|
||||
Revision 1.92 2002/07/23 07:40:51 lazarus
|
||||
MG: fixed get widget position for inherited gdkwindows
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user