首页  编辑  

操作IDE编辑框的一些函数

Tags: /超级猛料/IDE.集成开发环境/第三方工具和Expert/   Date Created:

操作IDE编辑框的一些函数

function EditGetLine(mIEditorInterface: TIEditorInterface;

 mBeginLine, mEndLine: Integer): string;

var

 vCharPos: TCharPos;

 vIEditReader: TIEditReader;

 vIEditView: TIEditView;

 vBegin, vEnd: Longint;

 vBuffer: PChar;

 vSize: Integer;

begin

 Result := '';

 if not Assigned(mIEditorInterface) then Exit;

 vIEditView := mIEditorInterface.GetView(0);

 vCharPos.Line := mBeginLine;

 vCharPos.CharIndex := 1;

 vBegin := vIEditView.CharPosToPos(vCharPos);

 vCharPos.Line := mEndLine;

 vCharPos.CharIndex := 1023;

 vEnd := vIEditView.CharPosToPos(vCharPos);

 if (vEnd < 0) or (vBegin < 0) then Exit;

 vIEditReader := mIEditorInterface.CreateReader;

 vSize := vEnd - vBegin;

 GetMem(vBuffer, vSize);

 vIEditReader.GetText(Pred(vBegin), vBuffer, vSize);

 vIEditReader.Free;

 Result := Copy(vBuffer, 1, vSize);

 FreeMem(vBuffer);

end; { EditGetLine }

procedure EditSetLine(mIEditorInterface: TIEditorInterface;

 mBeginLine, mEndLine: Integer; mText: string);

var

 vCharPos: TCharPos;

 vIEditWriter: TIEditWriter;

 vIEditView: TIEditView;

 vBegin, vEnd: Longint;

begin

 if not Assigned(mIEditorInterface) then Exit;

 vIEditView := mIEditorInterface.GetView(0);

 vCharPos.Line := mBeginLine;

 vCharPos.CharIndex := 1;

 vBegin := vIEditView.CharPosToPos(vCharPos);

 vCharPos.Line := mEndLine;

 vCharPos.CharIndex := 1023;

 vEnd := vIEditView.CharPosToPos(vCharPos);

 if (vEnd < 0) or (vBegin < 0) then Exit;

 vIEditWriter := mIEditorInterface.CreateWriter;

 vIEditWriter.CopyTo(Pred(vBegin));

 vIEditWriter.DeleteTo(vEnd);

 vIEditWriter.Insert(PChar(mText));

 vIEditWriter.Free;

end; { EditSetLine }

function EditGetText(mIEditorInterface: TIEditorInterface): string;

begin

 Result := EditGetLine(mIEditorInterface, 1, mIEditorInterface.LinesInBuffer);

end; { EditGetText }

procedure EditSetText(mIEditorInterface: TIEditorInterface; mText: string);

begin

 EditSetLine(mIEditorInterface, 1, mIEditorInterface.LinesInBuffer, mText);

end; { EditSetText }

function EditGetBlock(mIEditorInterface: TIEditorInterface): string;

var

 vCharPos: TCharPos;

 vIEditReader: TIEditReader;

 vIEditView: TIEditView;

 vBegin, vEnd: Longint;

 vBuffer: PChar;

 vSize: Integer;

 vBlockAfter: TCharPos;

 vBlockStart: TCharPos;

 I: Integer;

begin

 Result := '';

 if not Assigned(mIEditorInterface) then Exit;

 vIEditView := mIEditorInterface.GetView(0);

 vBlockStart := mIEditorInterface.GetBlockStart;

 vBlockAfter := mIEditorInterface.GetBlockAfter;

 if (vBlockStart.CharIndex = vBlockAfter.CharIndex) and

   (vBlockStart.Line = vBlockAfter.Line) then Exit;

 case mIEditorInterface.GetBlockType of

   btColumn:

   begin

     vIEditReader := mIEditorInterface.CreateReader;

     for I := vBlockStart.Line to vBlockAfter.Line do begin

       vCharPos.Line := I;

       vCharPos.CharIndex := vBlockStart.CharIndex;

       vBegin := vIEditView.CharPosToPos(vCharPos);

       vCharPos.Line := I;

       vCharPos.CharIndex := vBlockAfter.CharIndex + 1;

       vEnd := vIEditView.CharPosToPos(vCharPos);

       if (vEnd < 0) or (vBegin < 0) then Break;

       vSize := Abs(vEnd - vBegin);

       GetMem(vBuffer, vSize);

       vIEditReader.GetText(Pred(vBegin), vBuffer, vSize);

       AppendStr(Result, Copy(vBuffer, 1, vSize) + #13#10);

       FreeMem(vBuffer);

     end;

     vIEditReader.Free;

   end;

   btNonInclusive:

   begin

     vCharPos.Line := vBlockStart.Line;

     vCharPos.CharIndex := vBlockStart.CharIndex + 1;

     vBegin := vIEditView.CharPosToPos(vCharPos);

     if vBlockAfter.CharIndex = 0 then begin

       vCharPos.Line := vBlockAfter.Line - 1;

       vCharPos.CharIndex := 1023;

     end else begin

       vCharPos.Line := vBlockAfter.Line;

       vCharPos.CharIndex := vBlockAfter.CharIndex + 1;

     end;

     vEnd := vIEditView.CharPosToPos(vCharPos);

     if (vEnd < 0) or (vBegin < 0) then Exit;

     vIEditReader := mIEditorInterface.CreateReader;

     vSize := Abs(vEnd - vBegin);

     GetMem(vBuffer, vSize);

     vIEditReader.GetText(Pred(vBegin), vBuffer, vSize);

     vIEditReader.Free;

     Result := Copy(vBuffer, 1, vSize);

     FreeMem(vBuffer);

   end;

 end;

end; { EditGetBlock }

procedure EditInsertLine(mIEditorInterface: TIEditorInterface; mText: string);

var

 vCharPos: TCharPos;

 vEditPos: TEditPos;

 vIEditWriter: TIEditWriter;

 vIEditView: TIEditView;

 vPosition : DWORD;

begin

 if not Assigned(mIEditorInterface) then Exit;

 vIEditView := mIEditorInterface.GetView(0);

 if not Assigned(vIEditView) then Exit;

 vEditPos := vIEditView.CursorPos;

 vIEditView.ConvertPos(True, vEditPos, vCharPos);

 vPosition := vIEditView.CharPosToPos(vCharPos);

 vIEditWriter := mIEditorInterface.CreateUndoableWriter;

 vIEditWriter.CopyTo(vPosition);

 vIEditWriter.Insert(PChar(mText));  

 vIEditWriter.Free;

end; { EditSetLine }

///////////////////