[lazarus] OpenFileAtCursor

Jarto Tarpio jarto at starsoft.fi
Mon Dec 10 10:47:10 EST 2001


Mattias Gaertner wrote:
> If you don't know, where to start, here are some features, which
> don't need gtk and should also be easy enough to start: 
> 
> -Find Text History (see Moleskine)
> -Makefile and bash hilighting
> -Find in files
> -MessageDialog Editor (see GExperts)
> -Backup Project to directory
> -compare files (diff output)
> -Macro Start: Ctrl-Shift-R, End: Ctrl-Shift-R, Play: Ctrl-Shift-P
>  (see official synedit cvs)
> -Incremental Search:  Ctrl-E
>     +typed letters in statusbar
> -Colors for Object inspector

I'll have a look which one I'll choose. Meanwhile, I completed Open 
File at Cursor. I assume I don't have write permissions to cvs, so 
here's the code. FindPasFile can be moved to another unit. I just 
don't know yet, where you prefer to have such functions. The path-
problem is solved with a constant path for the moment.

This one doesn't support inc-files yet as GetWordAtRowCol doesn't 
return the extension.

/jarto

function TMainIDE.DoOpenFileAtCursor(Sender: TObject):TModalResult;
var SE: TSourceEditor;
    FName,SPath: String;

  function FindPasFile(var FName: String; SPath: String): Boolean;
  //  Searches for FName in Spath
  //  If FName is not found, we'll check extensions pp and pas too
  //  Returns true if found. FName contains the full file+path in that case
  var TempFile,TempPath,Ext: String;
      i,p: Integer;
  begin
    if SPath='' then SPath:='.';
    for i:=0 to 2 do begin
      case i of
        1: Ext:='.pp';
        2: Ext:='.pas';
        else Ext:='';
      end;
      TempPath:=SPath;
      while TempPath<>'' do begin
        p:=pos(';',TempPath);
        if p=0 then p:=length(TempPath)+1;
        TempFile:=copy(TempPath,1,p-1)+'/'+FName+Ext;
        Delete(TempPath,1,p);
        if FileExists(TempFile) then begin
          result:=true;
          FName:=ExpandFileName(TempFile);
          exit;
        end;
      end;
    end;
    result:=false;
  end;

begin
  writeln('TMainIDE.DoOpenFileAtCursor');
  Result:=mrCancel;
  SE:=SourceNoteBook.GetActiveSE;
  if SE=nil then exit;
  FName:=SE.EditorComponent.GetWordAtRowCol(SE.EditorComponent.CaretXY);
  FName:=Lowercase(FName);
  SPath:='.;lcl;designer'; //Take this from project options later when available
  if FindPasFile(FName,SPath) then begin
    result:=mrOk;
    EnvironmentOptions.LastOpenDialogDir:=ExtractFilePath(FName);
    if DoOpenEditorFile(FName,false)=mrOk then begin
      EnvironmentOptions.AddToRecentOpenFiles(FName);
      SaveEnvironment;
    end;
  end;
end;






More information about the Lazarus mailing list