IDE: fpdoceditor: save topic short+descr only if changed

git-svn-id: trunk@34255 -
This commit is contained in:
mattias 2011-12-18 11:46:20 +00:00
parent 97b7e5c8ef
commit ae148b3d08

View File

@ -152,6 +152,7 @@ type
FFlags: TFPDocEditorFlags; FFlags: TFPDocEditorFlags;
fUpdateLock: Integer; fUpdateLock: Integer;
fSourceFilename: string; fSourceFilename: string;
fDocFile: TLazFPDocFile;
fChain: TCodeHelpElementChain; fChain: TCodeHelpElementChain;
FOldValues: TFPDocElementValues; FOldValues: TFPDocElementValues;
FOldVisualValues: TFPDocElementValues; FOldVisualValues: TFPDocElementValues;
@ -177,6 +178,7 @@ type
procedure OnLazDocChanged(Sender: TObject; LazDocFPFile: TLazFPDocFile); procedure OnLazDocChanged(Sender: TObject; LazDocFPFile: TLazFPDocFile);
procedure LoadGUIValues(Element: TCodeHelpElement); procedure LoadGUIValues(Element: TCodeHelpElement);
procedure MoveToInherited(Element: TCodeHelpElement); procedure MoveToInherited(Element: TCodeHelpElement);
function GetDefaultDocFile(CreateIfNotExists: Boolean = False): TLazFPDocFile;
function ExtractIDFromLinkTag(const LinkTag: string; out ID, Title: string): boolean; function ExtractIDFromLinkTag(const LinkTag: string; out ID, Title: string): boolean;
function CreateElement(Element: TCodeHelpElement): Boolean; function CreateElement(Element: TCodeHelpElement): Boolean;
procedure UpdateButtons; procedure UpdateButtons;
@ -190,7 +192,6 @@ type
FCurrentTopic: String; FCurrentTopic: String;
procedure UpdateTopicCombo; procedure UpdateTopicCombo;
procedure ClearTopicControls; procedure ClearTopicControls;
function TopicDocFile(CreateIfNotExists: Boolean = False): TLazFPDocFile;
public public
procedure Reset; procedure Reset;
procedure InvalidateChain; procedure InvalidateChain;
@ -518,7 +519,7 @@ var
Dfile: TLazFPDocFile; Dfile: TLazFPDocFile;
begin begin
if NewTopicNameEdit.Text = '' then exit; if NewTopicNameEdit.Text = '' then exit;
Dfile := TopicDocFile(True); Dfile := GetDefaultDocFile(True);
if not assigned(DFile) then exit; if not assigned(DFile) then exit;
if DFile.GetModuleTopic(NewTopicNameEdit.Text) = nil then begin if DFile.GetModuleTopic(NewTopicNameEdit.Text) = nil then begin
DFile.CreateModuleTopic(NewTopicNameEdit.Text); DFile.CreateModuleTopic(NewTopicNameEdit.Text);
@ -617,7 +618,7 @@ begin
FCurrentTopic := ''; FCurrentTopic := '';
if TopicListBox.ItemIndex < 0 then exit; if TopicListBox.ItemIndex < 0 then exit;
Dfile := TopicDocFile(True); Dfile := GetDefaultDocFile(True);
if DFile = nil then exit; if DFile = nil then exit;
Node := DFile.GetModuleTopic(TopicListBox.Items[TopicListBox.ItemIndex]); Node := DFile.GetModuleTopic(TopicListBox.Items[TopicListBox.ItemIndex]);
@ -672,8 +673,10 @@ end;
function TFPDocEditor.GetDocFile: TLazFPDocFile; function TFPDocEditor.GetDocFile: TLazFPDocFile;
begin begin
Result:=nil; Result:=nil;
if fChain=nil then exit; if fChain<>nil then
Result:=fChain.DocFile; Result:=fChain.DocFile
else
Result:=fDocFile;
end; end;
function TFPDocEditor.GetSourceFilename: string; function TFPDocEditor.GetSourceFilename: string;
@ -776,6 +779,7 @@ var
NewChain: TCodeHelpElementChain; NewChain: TCodeHelpElementChain;
CacheWasUsed: Boolean; CacheWasUsed: Boolean;
begin begin
fDocFile:=nil;
FreeAndNil(fChain); FreeAndNil(fChain);
if fUpdateLock>0 then begin if fUpdateLock>0 then begin
Include(FFlags,fpdefChainNeedsUpdate); Include(FFlags,fpdefChainNeedsUpdate);
@ -819,11 +823,16 @@ begin
NewChain.WriteDebugReport; NewChain.WriteDebugReport;
{$ENDIF} {$ENDIF}
fChain:=NewChain; fChain:=NewChain;
fDocFile:=fChain.DocFile;
NewChain:=nil; NewChain:=nil;
end; end;
finally finally
NewChain.Free; NewChain.Free;
end; end;
if (fDocFile=nil) then begin
// load default docfile, needed to show syntax errors in xml and for topics
fDocFile:=GetDefaultDocFile;
end;
end; end;
procedure TFPDocEditor.OnLazDocChanging(Sender: TObject; procedure TFPDocEditor.OnLazDocChanging(Sender: TObject;
@ -831,7 +840,9 @@ procedure TFPDocEditor.OnLazDocChanging(Sender: TObject;
begin begin
if fpdefWriting in FFlags then exit; if fpdefWriting in FFlags then exit;
if (fChain<>nil) and (fChain.IndexOfFile(LazDocFPFile)>=0) then if (fChain<>nil) and (fChain.IndexOfFile(LazDocFPFile)>=0) then
InvalidateChain; InvalidateChain
else if (fDocFile<>nil) and (fDocFile=LazDocFPFile) then
Include(FFlags,fpdefTopicNeedsUpdate);
end; end;
procedure TFPDocEditor.OnLazDocChanged(Sender: TObject; procedure TFPDocEditor.OnLazDocChanged(Sender: TObject;
@ -1058,7 +1069,7 @@ end;
procedure TFPDocEditor.UpdateTopicCombo; procedure TFPDocEditor.UpdateTopicCombo;
var var
c, i: LongInt; cnt, i: LongInt;
DFile: TLazFPDocFile; DFile: TLazFPDocFile;
Topics: TStringList; Topics: TStringList;
begin begin
@ -1067,35 +1078,34 @@ begin
try try
FCurrentTopic := ''; FCurrentTopic := '';
ClearTopicControls; ClearTopicControls;
Dfile := TopicDocFile; Dfile := DocFile;
if not assigned(DFile) then exit; if not assigned(DFile) then exit;
c := DFile.GetModuleTopicCount; cnt := DFile.GetModuleTopicCount;
for i := 0 to c - 1 do for i := 0 to cnt - 1 do
Topics.Add(DFile.GetModuleTopicName(i)); Topics.Add(DFile.GetModuleTopicName(i));
finally finally
TopicListBox.Items.Assign(Topics); TopicListBox.Items.Assign(Topics);
end; end;
end; end;
function TFPDocEditor.TopicDocFile(CreateIfNotExists: Boolean): TLazFPDocFile; function TFPDocEditor.GetDefaultDocFile(CreateIfNotExists: Boolean): TLazFPDocFile;
var var
CacheWasUsed : Boolean; CacheWasUsed : Boolean;
AnOwner: TObject; AnOwner: TObject;
DFileName: String; FPDocFileName: String;
begin begin
Result := nil; Result := nil;
if assigned(DocFile) then if (not CreateIfNotExists) and (fDocFile<>nil) then
Result := DocFile exit(fDocFile);
else begin
DFileName := CodeHelpBoss.GetFPDocFilenameForSource(SourceFilename, true, FPDocFileName := CodeHelpBoss.GetFPDocFilenameForSource(SourceFilename, true,
CacheWasUsed, AnOwner, CreateIfNotExists); CacheWasUsed, AnOwner, CreateIfNotExists);
if (DFileName = '') if (FPDocFileName = '')
or (CodeHelpBoss.LoadFPDocFile(DFileName, [chofUpdateFromDisk], Result, or (CodeHelpBoss.LoadFPDocFile(FPDocFileName, [chofUpdateFromDisk], Result,
CacheWasUsed) <> chprSuccess) CacheWasUsed) <> chprSuccess)
then then
Result := nil; Result := nil;
end; end;
end;
procedure TFPDocEditor.Reset; procedure TFPDocEditor.Reset;
var var
@ -1119,7 +1129,6 @@ begin
Modified := False; Modified := False;
CreateButton.Enabled:=false; CreateButton.Enabled:=false;
finally finally
Exclude(FFlags,fpdefReading); Exclude(FFlags,fpdefReading);
end; end;
@ -1128,9 +1137,9 @@ end;
procedure TFPDocEditor.InvalidateChain; procedure TFPDocEditor.InvalidateChain;
begin begin
FreeAndNil(fChain); FreeAndNil(fChain);
FFlags:=FFlags+[fpdefCodeCacheNeedsUpdate,fpdefChainNeedsUpdate, FFlags:=FFlags+[fpdefCodeCacheNeedsUpdate,
fpdefCaptionNeedsUpdate,fpdefValueControlsNeedsUpdate, fpdefChainNeedsUpdate,fpdefCaptionNeedsUpdate,
fpdefInheritedControlsNeedsUpdate]; fpdefValueControlsNeedsUpdate,fpdefInheritedControlsNeedsUpdate];
end; end;
procedure TFPDocEditor.UpdateFPDocEditor(const SrcFilename: string; procedure TFPDocEditor.UpdateFPDocEditor(const SrcFilename: string;
@ -1186,14 +1195,17 @@ end;
procedure TFPDocEditor.Save(CheckGUI: boolean); procedure TFPDocEditor.Save(CheckGUI: boolean);
var var
Values: TFPDocElementValues; Values: TFPDocElementValues;
DFile: TLazFPDocFile; TopicDocFile: TLazFPDocFile;
Node: TDOMNode; Node: TDOMNode;
Child: TDOMNode;
TopicChanged: Boolean;
begin begin
//DebugLn(['TFPDocEditor.Save FModified=',FModified]); //DebugLn(['TFPDocEditor.Save FModified=',FModified]);
if fpdefReading in FFlags then exit; if fpdefReading in FFlags then exit;
if (not FModified) if (not FModified)
and ((not CheckGUI) or (not GUIModified)) then begin and ((not CheckGUI) or (not GUIModified)) then
begin
SaveButton.Enabled:=false; SaveButton.Enabled:=false;
Exit; // nothing changed => exit Exit; // nothing changed => exit
end; end;
@ -1201,39 +1213,55 @@ begin
FModified:=false; FModified:=false;
SaveButton.Enabled:=false; SaveButton.Enabled:=false;
DFile := nil; TopicChanged:=false;
if FCurrentTopic <> '' then begin TopicDocFile:=DocFile;
Dfile := TopicDocFile(True); if FCurrentTopic <> '' then
if DFile <> nil then begin begin
Node := DFile.GetModuleTopic(FCurrentTopic); if fDocFile=nil then
fDocFile := GetDefaultDocFile(True);
TopicDocFile:=DocFile;
if TopicDocFile <> nil then begin
Node := TopicDocFile.GetModuleTopic(FCurrentTopic);
if Node <> nil then begin if Node <> nil then begin
DFile.SetChildValue(Node, 'short', TopicShort.Text); Child := Node.FindNode('short');
DFile.SetChildValue(Node, 'descr', TopicDescr.Text); if (Child = nil)
or (TopicDocFile.GetChildValuesAsString(Child)<>TopicShort.Text)
then begin
TopicDocFile.SetChildValue(Node, 'short', TopicShort.Text);
TopicChanged:=true;
end;
Child := Node.FindNode('descr');
if (Child = nil)
or (TopicDocFile.GetChildValuesAsString(Child)<>TopicDescr.Text)
then begin
TopicDocFile.SetChildValue(Node, 'descr', TopicDescr.Text);
TopicChanged:=true;
end; end;
end; end;
end; end;
if (fChain=nil) or (fChain.Count=0) then begin end;
if (FCurrentTopic <> '') and (DFile <> nil) then if (fChain=nil) or (fChain.Count=0) then
CodeHelpBoss.SaveFPDocFile(DFile) begin
else if IsVisible then if IsVisible then
DebugLn(['TFPDocEditor.Save failed: no chain']); DebugLn(['TFPDocEditor.Save failed: no chain']);
exit; end else if not fChain.IsValid then
end; begin
if not fChain.IsValid then begin if IsVisible then
if (FCurrentTopic <> '') and (DFile <> nil) then
CodeHelpBoss.SaveFPDocFile(DFile)
else if IsVisible then
DebugLn(['TFPDocEditor.Save failed: chain not valid']); DebugLn(['TFPDocEditor.Save failed: chain not valid']);
exit; end else if (fChain[0].FPDocFile <> nil) then
end; begin
if (fChain[0].FPDocFile = nil) and (DFile <> nil) then
CodeHelpBoss.SaveFPDocFile(DFile)
else begin
Values:=GetGUIValues; Values:=GetGUIValues;
if not WriteNode(fChain[0],Values,true) then begin if WriteNode(fChain[0],Values,true) then
begin
// write succeeded
if fChain.DocFile=TopicDocFile then
TopicChanged:=false;
end else begin
DebugLn(['TLazDocForm.Save WriteNode FAILED']); DebugLn(['TLazDocForm.Save WriteNode FAILED']);
end; end;
end; end;
if TopicChanged then
CodeHelpBoss.SaveFPDocFile(TopicDocFile);
end; end;
function TFPDocEditor.GetGUIValues: TFPDocElementValues; function TFPDocEditor.GetGUIValues: TFPDocElementValues;