Das Problem mit dem Text einfügen habe ich gelöst. Hab einen Code gefunden der den markierten Text sortiert. Diesen habe ich angepasst und schon geht's. Der Code ist noch nicht bereinigt, also nicht wundern.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115:
| uses ... , ExptIntf, ToolIntf, EditIntf;
resourcestring sCloseViews = 'Alle Views ausser einem geschlossen';
procedure Insert(txt: string); var Module: TIModuleInterface; Editor: TIEditorInterface; View: TIEditView;
BlockStart: TCharPos; BlockAfter: TCharPos; StartPos, EndPos: LongInt; Reader: TIEditReader; Writer: TIEditWriter; TopPos, CursorPos: TEditPos; Text: string; Strings: TStringList; begin
with ToolServices do Module := GetModuleInterface(GetCurrentFile); if Module = nil then Exit;
try Editor := Module.GetEditorInterface; if Editor = nil then Exit;
try if Editor.GetViewCount > 1 then raise Exception.Create(sCloseViews);
View := Editor.GetView(0); except end;
except end;
BlockStart := Editor.BlockStart; BlockAfter := Editor.BlockAfter;
BlockStart.CharIndex := 0; if BlockAfter.CharIndex > 0 then begin BlockAfter.CharIndex := 0; Inc(BlockAfter.Line); end;
StartPos := View.CharPosToPos(BlockStart); EndPos := View.CharPosToPos(BlockAfter);
Reader := Editor.CreateReader; try SetLength(Text, EndPos - StartPos - 1); Reader.GetText(StartPos, PChar(Text), Length(Text)); finally Reader.Free; end;
Writer := Editor.CreateUndoableWriter; try Writer.CopyTo(StartPos); Writer.DeleteTo(EndPos); Writer.Insert(PChar(txt)); finally Writer.Free; end;
View.ConvertPos(False, CursorPos, BlockStart); View.CursorPos := CursorPos;
if (BlockStart.Line < View.TopPos.Line) or (BlockAfter.Line >= View.TopPos.Line + View.ViewSize.CY) then begin View.ConvertPos(False, TopPos, BlockStart); View.TopPos := TopPos; end;
Editor.BlockVisible := False; Editor.BlockType := btNonInclusive; Editor.BlockStart := BlockStart; Editor.BlockAfter := BlockAfter; Editor.BlockVisible := True; end; |
Bleibt nur noch die Sache mit dem Menü.
Moderiert von
Tino: Code- durch Delphi-Tags ersetzt.