Ignore:
Timestamp:
May 18, 2008, 9:03:03 PM (17 years ago)
Author:
RBRi
Message:

more link handling fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.19_branch/NewView/MainForm.pas

    r293 r298  
    26852685end;
    26862686
    2687 Procedure TMainForm.WMFollowExternalLink( Var Msg: TMessage );
    2688 var
    2689   FilePath: string;
    2690   AlternativeFilePath: string;
    2691   FileIndex: longint;
    2692   HelpFile: THelpFile;
    2693   Topic: TTopic;
    2694   IsFileAlreadyOpened: boolean;
    2695 begin
     2687Procedure TMainForm.WMFollowExternalLink(Var Msg: TMessage);
     2688var
     2689  tmpFilePath: string;
     2690  tmpAltFilePath: string;
     2691  tmpIsFileAlreadyOpened: boolean;
     2692  tmpHelpFile: THelpFile;
     2693  tmpTopic: TTopic;
     2694  i: longint;
     2695begin
     2696  LogEvent(LogDebug, 'tmpFilePath ' + tmpFilePath);
     2697
    26962698  // try in same dir as source file
    2697   FilePath := AddDirectorySeparator( ExtractFilePath( g_ExternalLinkSourceFilename ) )
    2698               + g_ExternalLinkFilename;
    2699 
    2700   AlternativeFilePath := FilePath;
    2701 
     2699  tmpFilePath := AddDirectorySeparator(ExtractFilePath(g_ExternalLinkSourceFilename)) + g_ExternalLinkFilename;
     2700  tmpAltFilePath := tmpFilePath;
     2701
     2702  // we use paths with extension, because the internal list of helpfiles
     2703  // always has extensions inside
    27022704  if ExtractFileExt(g_ExternalLinkFilename) = '' then
    27032705  begin
    2704     FilePath := ChangeFileExt(FilePath, INF_FILE_EXTENSION);
    2705     AlternativeFilePath := ChangeFileExt(FilePath, HELP_FILE_EXTENSION);
     2706    tmpFilePath := ChangeFileExt(tmpFilePath, INF_FILE_EXTENSION);
     2707    tmpAltFilePath := ChangeFileExt(tmpFilePath, HELP_FILE_EXTENSION);
    27062708  end;
    27072709
    27082710  // figure out, if the file is already open
    2709   IsFileAlreadyOpened := false;
    2710   for FileIndex := 0 to CurrentOpenFiles.Count - 1 do
    2711   begin
    2712     HelpFile := CurrentOpenFiles[FileIndex];
    2713     if StrEndsWithIgnoringCase(HelpFile.Filename, FilePath)
    2714        or StrEndsWithIgnoringCase(HelpFile.Filename, g_ExternalLinkFilename + HELP_FILE_EXTENSION) then
     2711  tmpIsFileAlreadyOpened := false;
     2712  for i := 0 to CurrentOpenFiles.Count - 1 do
     2713  begin
     2714    tmpHelpFile := CurrentOpenFiles[i];
     2715    if StrEndsWithIgnoringCase(tmpHelpFile.Filename, tmpFilePath)
     2716       or StrEndsWithIgnoringCase(tmpHelpFile.Filename, tmpAltFilePath) then
    27152717    begin
    2716       IsFileAlreadyOpened := true;
     2718      tmpIsFileAlreadyOpened := true;
    27172719    end;
    27182720  end;
    27192721
    2720   if not IsFileAlreadyOpened then
     2722  if not tmpIsFileAlreadyOpened then
    27212723  begin
    27222724    // different file - try and open it
    2723     if not FileExists( FilePath ) then
     2725    if not FileExists(tmpFilePath) then
     2726    begin
    27242727      // not in same directory, find in help paths
    2725       FilePath := FindHelpFile( g_ExternalLinkFilename );
    2726 
    2727     if not FileExists( FilePath ) then
     2728      tmpFilePath := FindHelpFile(g_ExternalLinkFilename);
     2729    end;
     2730
     2731    if not FileExists(tmpFilePath) then
    27282732    begin
    27292733      DoErrorDlg('Link Error', 'Cannot find linked file ''' + g_ExternalLinkFilename +'''');
     
    27332737    if g_ExternalLinkKeepCurrent then
    27342738    begin
    2735       if not OpenAdditionalFile( FilePath, false ) then
     2739      if not OpenAdditionalFile(tmpFilePath, false) then
    27362740        exit;
    27372741    end
    27382742    else
    27392743    begin
    2740       if not OpenFile( FilePath, '', false ) then
     2744      if not OpenFile(tmpFilePath, '', false) then
    27412745        exit;
    27422746    end;
     
    27522756  // don't call this search here;
    27532757  // because we know the file to search in
     2758  // otherwise the first occurence of the topic will be
     2759  // found
    27542760  // Topic := FindTopicByGlobalName( g_ExternalLinkTopic );
    2755   Topic := nil;
    2756   for FileIndex := 0 to CurrentOpenFiles.Count - 1 do
    2757   begin
    2758     HelpFile := CurrentOpenFiles[FileIndex];
    2759     if StrEndsWithIgnoringCase(HelpFile.Filename, g_ExternalLinkFilename + INF_FILE_EXTENSION)
    2760        or StrEndsWithIgnoringCase(HelpFile.Filename, g_ExternalLinkFilename + HELP_FILE_EXTENSION) then
     2761  tmpTopic := nil;
     2762  for i := 0 to CurrentOpenFiles.Count - 1 do
     2763  begin
     2764    tmpHelpFile := CurrentOpenFiles[i];
     2765    if StrEndsWithIgnoringCase(tmpHelpFile.Filename, g_ExternalLinkFilename)
     2766       or StrEndsWithIgnoringCase(tmpHelpFile.Filename, g_ExternalLinkFilename + INF_FILE_EXTENSION)
     2767       or StrEndsWithIgnoringCase(tmpHelpFile.Filename, g_ExternalLinkFilename + HELP_FILE_EXTENSION) then
    27612768    begin
    2762       Topic := HelpFile.FindTopicByGlobalName(g_ExternalLinkTopic);
     2769      tmpTopic := tmpHelpFile.FindTopicByGlobalName(g_ExternalLinkTopic);
    27632770    end;
    27642771  end;
    27652772
    2766   if Topic = nil then
     2773  if tmpTopic = nil then
    27672774  begin
    27682775    DoErrorDlg('Link Error', 'Unable to find topic with global name ''' + g_ExternalLinkTopic + '''');
     
    27702777  end;
    27712778
    2772   DisplayTopic( Topic );
     2779  DisplayTopic(tmpTopic);
    27732780end;
    27742781
Note: See TracChangeset for help on using the changeset viewer.