Added code so the unit source changes when you do a SAVE AS

Shane

git-svn-id: trunk@193 -
This commit is contained in:
lazarus 2001-02-23 18:37:17 +00:00
parent 30734a16b7
commit 33d621a672
2 changed files with 69 additions and 9 deletions

View File

@ -147,6 +147,7 @@ type
procedure mnuEnvEditorOptionsClicked(Sender : TObject);
Procedure OpenFileDownArrowClicked(Sender : TObject);
Procedure OpenRecentFile(Sender : TObject);
Procedure FileClosedEvent(Sender : TObject; Filename : String);
Procedure FileOpenedEvent(Sender : TObject; Filename : String);
Procedure FileSavedEvent(Sender : TObject; Filename : String);
@ -1277,6 +1278,14 @@ Begin
OpenFilePopupMenu.Popup(0,0);
end;
Procedure TMainIDE.OpenRecentFile(Sender : TObject);
Begin
// SourceNotebook.OpenFile(TMenuItem(sender).Caption,True);
Application.MEssagebox('Not yet implemented','Error',MB_OK);
End;
//==============================================================================
{
This function creates a LFM file from any form.
@ -1358,7 +1367,7 @@ Begin
//Add a new menuitem to the popup that displays the filename.
MenuItem := TMenuItem.Create(Self);
MenuItem.Caption := Filename;
MenuItem.OnClick := @SourceNotebook.OpenClicked;
MenuItem.OnClick := @OpenRecentFile;
OpenFilePopupMenu.Items.Add(MenuItem);
Texts := Filename;
@ -1782,6 +1791,10 @@ end.
{ =============================================================================
$Log$
Revision 1.63 2001/02/23 18:37:17 lazarus
Added code so the unit source changes when you do a SAVE AS
Shane
Revision 1.62 2001/02/22 17:04:57 lazarus
added environment options + killed ide unit circles

View File

@ -1147,7 +1147,8 @@ Begin
try
Add('unit '+FUnitName+';');
Add('');
Add('{$mode objfpc}{$H+}');
Add('{$mode objfpc}');
Add('{$H+}');
Add('');
Add('interface');
Add('');
@ -1253,13 +1254,65 @@ end;
Function TSourceEditor.Save : Boolean;
var
s : TStringList;
I,X : Integer;
Texts : String;
NewUnitName : String;
Found : Boolean;
Begin
Result := True;
If Assigned(FOnBeforeSave) then FOnBeforeSave(Self);
try
//change the unitname
Found := False;
S := TStringList.Create;
S.Assign(FEditor.Lines);
I := 0;
NewUnitName := ExtractFileName(FileName); //in case there is a path
If ExtractFileExt(FileName) <> '' then
NewUnitName := Copy(NewUnitName,1,length(NewUnitName)-length(ExtractFileExt(Filename)));
While I < S.Count do
Begin
Texts := S.Strings[i];
Writeln('Texts = '+Texts);
if (pos('unit',lowercase(texts)) <> 0) and
(pos(lowercase(unitname)+';',Lowercase(texts)) <> 0) then
Begin
X := pos(lowercase(unitname)+';',Lowercase(texts));
delete(Texts,x,length(unitname));
insert(NewUnitName,Texts,x);
S.Strings[i] := Texts;
Found := True;
Break;
end;
inc(i);
end;
if Found then
Begin
I := 0;
While I < S.Count do
Begin
Texts := S.Strings[i];
if pos(lowercase(format('{$I %s.lrc}',[UnitName])),lowercase(Texts)) <> 0 then
Begin
X := pos(lowercase(format('{$I %s.lrc}',[UnitName])),Lowercase(Texts));
delete(Texts,x,length(format('{$I %s.lrc}',[UnitName])));
insert(format('{$I %s.lrc}',[NewUnitName]),Texts,x);
S.Strings[i] := Texts;
break;
end;
inc(i);
end;
FEditor.Lines.Assign(s);
end;
FEditor.Lines.SaveToFile(FileName);
FEditor.Modified := False;
UnitName := NewUnitName;
except
Result := False;
end;
@ -2089,12 +2142,6 @@ Procedure TSourceNotebook.OpenClicked(Sender: TObject);
Var
TempEditor : TSourceEditor;
Begin
if (sender is TMenuItem)
and (TMenuItem(sender).name <> 'FileOpen') then
//the down arrow next to open was selected
OpenFile(TMenuItem(sender).Caption,True)
else
Begin
FOpenDialog.Title := 'Open';
if FOpenDialog.Execute then Begin
//create a new page
@ -2115,7 +2162,6 @@ Begin
TempEditor.Visible := True;
UpdateStatusBar;
end;
end;
end;
Procedure TSourceNotebook.FindClicked(Sender : TObject);
@ -2295,6 +2341,7 @@ Begin
else
SaveAsClicked(Sender);
UpdateStatusBar;
end;
Function TSourceNotebook.ActiveUnitName : String;