wcedit.pas 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998-2000 by Berczi Gabor
  5. Code editor template objects
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$i globdir.inc}
  13. unit WCEdit;
  14. interface
  15. uses Objects,Drivers,Views,
  16. { necessary for ExistsFile }FPUtils,
  17. WUtils,WEditor;
  18. type
  19. PIndicator = ^TIndicator;
  20. TIndicator = object(TView)
  21. Location: TPoint;
  22. Modified : Boolean;
  23. {$ifdef debug}
  24. StoreUndo : Boolean;
  25. SyntaxComplete : boolean;
  26. UseTabs : Boolean;
  27. {$endif debug}
  28. constructor Init(var Bounds: TRect);
  29. procedure Draw; virtual;
  30. function GetPalette: PPalette; virtual;
  31. procedure SetState(AState: Word; Enable: Boolean); virtual;
  32. procedure SetValue(ALocation: TPoint; AModified: Boolean);
  33. end;
  34. PLine = ^TLine;
  35. TLine = object(TCustomLine)
  36. public { internal use only! }
  37. Text : PString;
  38. EditorInfos : PEditorLineInfoCollection;
  39. Flags : longint;
  40. Owner : PCustomCodeEditorCore;
  41. procedure AddEditorInfo(Index: sw_integer; AEditor: PCustomCodeEditor); virtual;
  42. procedure RemoveEditorInfo(AEditor: PCustomCodeEditor); virtual;
  43. public
  44. constructor Init(AOwner: PCustomCodeEditorCore; const AText: string; AFlags: longint);
  45. function GetText: string; virtual;
  46. procedure SetText(const AText: string); virtual;
  47. function GetEditorInfo(Editor: PCustomCodeEditor): PEditorLineInfo; virtual;
  48. function GetFlags: longint; virtual;
  49. procedure SetFlags(AFlags: longint); virtual;
  50. destructor Done; virtual;
  51. end;
  52. PCodeEditorCore = ^TCodeEditorCore;
  53. TCodeEditorCore = object(TCustomCodeEditorCore)
  54. {$ifdef TP}public{$else}protected{$endif}
  55. Lines : PLineCollection;
  56. CanUndo : Boolean;
  57. StoreUndo : boolean;
  58. Modified : Boolean;
  59. ReadOnly : Boolean;
  60. TabSize : integer;
  61. {$ifdef UNDO}public{$endif}
  62. UndoList : PEditorActionCollection;
  63. RedoList : PEditorActionCollection;
  64. public
  65. constructor Init;
  66. destructor Done; virtual;
  67. public
  68. function GetModified: boolean; virtual;
  69. procedure SetModified(AModified: boolean); virtual;
  70. function GetTabSize: integer; virtual;
  71. procedure SetTabSize(ATabSize: integer); virtual;
  72. function GetStoreUndo: boolean; virtual;
  73. procedure SetStoreUndo(AStore: boolean); virtual;
  74. function GetSyntaxCompleted: boolean; virtual;
  75. procedure SetSyntaxCompleted(SC : boolean); virtual;
  76. function GetLastSyntaxedLine: sw_integer; virtual;
  77. procedure SetLastSyntaxedLine(ALine: sw_integer); virtual;
  78. public
  79. { Storage }
  80. {$ifdef TP}public{$else}protected{$endif}
  81. { Text & info storage abstraction }
  82. procedure ISetLineFlagState(Binding: PEditorBinding; LineNo: sw_integer; Flag: longint; ASet: boolean); virtual;
  83. procedure IGetDisplayTextFormat(Binding: PEditorBinding; LineNo: sw_integer;var DT,DF:string); virtual;
  84. function IGetLineFormat(Binding: PEditorBinding; LineNo: sw_integer): string; virtual;
  85. procedure ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: string); virtual;
  86. public
  87. { Text & info storage abstraction }
  88. function GetLineCount: sw_integer; virtual;
  89. function GetLine(LineNo: sw_integer): PCustomLine; virtual;
  90. function GetLineText(LineNo: sw_integer): string; virtual;
  91. procedure SetDisplayText(I: sw_integer;const S: string); virtual;
  92. function GetDisplayText(I: sw_integer): string; virtual;
  93. procedure SetLineText(I: sw_integer;const S: string); virtual;
  94. procedure DeleteAllLines; virtual;
  95. procedure DeleteLine(I: sw_integer); virtual;
  96. function InsertLine(LineNo: sw_integer; const S: string): PCustomLine; virtual;
  97. procedure AddLine(const S: string); virtual;
  98. procedure GetContent(ALines: PUnsortedStringCollection); virtual;
  99. procedure SetContent(ALines: PUnsortedStringCollection); virtual;
  100. public
  101. { Undo info storage }
  102. procedure AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string); virtual;
  103. procedure AddGroupedAction(AAction : byte); virtual;
  104. procedure CloseGroupedAction(AAction : byte); virtual;
  105. function GetUndoActionCount: sw_integer; virtual;
  106. function GetRedoActionCount: sw_integer; virtual;
  107. private
  108. procedure LinesInsert(Idx: sw_integer; Line: PLine);
  109. end;
  110. PCodeEditor = ^TCodeEditor;
  111. TCodeEditor = object(TCustomCodeEditor)
  112. Core : PCodeEditorCore;
  113. Flags : longint;
  114. Indicator : PIndicator;
  115. HighlightRow: sw_integer;
  116. DebuggerRow: sw_integer;
  117. CodeCompleteFrag: PString;
  118. CodeCompleteWord: PString;
  119. ReadOnly : boolean;
  120. CompleteState: TCompleteState;
  121. ErrorMessage: PString;
  122. IndicatorDrawCalled : boolean;
  123. Folds : PFoldCollection;
  124. MaxFoldLevel: sw_integer;
  125. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  126. PScrollBar; AIndicator: PIndicator; ACore: PCodeEditorCore);
  127. public
  128. procedure DrawIndicator; virtual;
  129. public
  130. function GetFlags: longint; virtual;
  131. procedure SetFlags(AFlags: longint); virtual;
  132. function GetModified: boolean; virtual;
  133. procedure SetModified(AModified: boolean); virtual;
  134. function GetStoreUndo: boolean; virtual;
  135. procedure SetStoreUndo(AStore: boolean); virtual;
  136. function GetSyntaxCompleted: boolean; virtual;
  137. procedure SetSyntaxCompleted(SC : boolean); virtual;
  138. function GetLastSyntaxedLine: sw_integer; virtual;
  139. procedure SetLastSyntaxedLine(ALine: sw_integer); virtual;
  140. function GetTabSize: integer; virtual;
  141. procedure SetTabSize(ATabSize: integer); virtual;
  142. function IsReadOnly: boolean; virtual;
  143. public
  144. procedure UpdateIndicator; virtual;
  145. procedure ModifiedChanged; virtual;
  146. procedure PositionChanged; virtual;
  147. procedure LimitsChanged; virtual;
  148. function IsClipboard: Boolean; virtual;
  149. function LoadFromStream(Stream: PStream): boolean; virtual;
  150. function SaveToStream(Stream: PStream): boolean; virtual;
  151. function SaveAreaToStream(Stream: PStream; StartP,EndP: TPoint): boolean;virtual;
  152. destructor Done; virtual;
  153. public
  154. { ChangedLine : sw_integer;}
  155. { Text & info storage abstraction }
  156. function GetLineCount: sw_integer; virtual;
  157. function GetLine(LineNo: sw_integer): PCustomLine; virtual;
  158. function CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer; virtual;
  159. function LinePosToCharIdx(Line,X: sw_integer): sw_integer; virtual;
  160. function GetLineText(I: sw_integer): string; virtual;
  161. procedure SetDisplayText(I: sw_integer;const S: string); virtual;
  162. function GetDisplayText(I: sw_integer): string; virtual;
  163. procedure SetLineText(I: sw_integer;const S: string); virtual;
  164. procedure GetDisplayTextFormat(I: sw_integer;var DT,DF:string); virtual;
  165. function GetLineFormat(I: sw_integer): string; virtual;
  166. procedure SetLineFormat(I: sw_integer;const S: string); virtual;
  167. procedure DeleteAllLines; virtual;
  168. procedure DeleteLine(I: sw_integer); virtual;
  169. function InsertLine(LineNo: sw_integer; const S: string): PCustomLine; virtual;
  170. procedure AddLine(const S: string); virtual;
  171. function GetErrorMessage: string; virtual;
  172. procedure SetErrorMessage(const S: string); virtual;
  173. procedure GetContent(ALines: PUnsortedStringCollection); virtual;
  174. procedure SetContent(ALines: PUnsortedStringCollection); virtual;
  175. procedure Lock; virtual;
  176. procedure UnLock; virtual;
  177. public
  178. { CodeComplete support }
  179. function GetCodeCompleteWord: string; virtual;
  180. procedure SetCodeCompleteWord(const S: string); virtual;
  181. function GetCodeCompleteFrag: string; virtual;
  182. procedure SetCodeCompleteFrag(const S: string); virtual;
  183. function GetCompleteState: TCompleteState; virtual;
  184. procedure SetCompleteState(AState: TCompleteState); virtual;
  185. public
  186. { Syntax highlight }
  187. {a}function UpdateAttrs(FromLine: sw_integer; Attrs: byte): sw_integer; virtual;
  188. {a}function UpdateAttrsRange(FromLine, ToLine: sw_integer; Attrs: byte): sw_integer; virtual;
  189. public
  190. { Undo info storage }
  191. procedure AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string); virtual;
  192. procedure AddGroupedAction(AAction : byte); virtual;
  193. procedure CloseGroupedAction(AAction : byte); virtual;
  194. function GetUndoActionCount: sw_integer; virtual;
  195. function GetRedoActionCount: sw_integer; virtual;
  196. procedure JumpToLastCursorPos; virtual;
  197. procedure Undo; virtual;
  198. procedure Redo; virtual;
  199. { Fold support }
  200. function GetMaxFoldLevel: sw_integer; virtual;
  201. function GetFoldCount: sw_integer; virtual;
  202. function GetFold(Index: sw_integer): PFold; virtual;
  203. procedure RegisterFold(AFold: PFold); virtual;
  204. procedure UnRegisterFold(AFold: PFold); virtual;
  205. end;
  206. PFileEditor = ^TFileEditor;
  207. TFileEditor = object(TCodeEditor)
  208. FileName: string;
  209. constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  210. PScrollBar; AIndicator: PIndicator; ACore: PCodeEditorCore; const AFileName: string);
  211. function Save: Boolean; virtual;
  212. function SaveAs: Boolean; virtual;
  213. function SaveAsk(Force: boolean): Boolean; virtual;
  214. function LoadFile: boolean; virtual;
  215. function SaveFile: boolean; virtual;
  216. function Valid(Command: Word): Boolean; virtual;
  217. procedure HandleEvent(var Event: TEvent); virtual;
  218. function ShouldSave: boolean; virtual;
  219. function IsChangedOnDisk : boolean;
  220. public
  221. procedure BindingsChanged; virtual;
  222. private
  223. OnDiskLoadTime : longint;
  224. end;
  225. function DefUseSyntaxHighlight(Editor: PFileEditor): boolean;
  226. function DefUseTabsPattern(Editor: PFileEditor): boolean;
  227. const
  228. DefaultCodeEditorFlags : longint =
  229. efBackupFiles+efInsertMode+efAutoIndent+efPersistentBlocks+
  230. {efUseTabCharacters+}efBackSpaceUnindents+efSyntaxHighlight+
  231. efExpandAllTabs+efCodeComplete{+efFolds};
  232. DefaultTabSize : integer = 8;
  233. UseSyntaxHighlight : function(Editor: PFileEditor): boolean = DefUseSyntaxHighlight;
  234. UseTabsPattern : function(Editor: PFileEditor): boolean = DefUseTabsPattern;
  235. procedure RegisterWCEdit;
  236. implementation
  237. uses Dos,
  238. Commands,App,WViews;
  239. {$ifndef NOOBJREG}
  240. const
  241. RIndicator: TStreamRec = (
  242. ObjType: 1100;
  243. VmtLink: Ofs(TypeOf(TIndicator)^);
  244. Load: @TIndicator.Load;
  245. Store: @TIndicator.Store
  246. );
  247. RCodeEditor: TStreamRec = (
  248. ObjType: 1101;
  249. VmtLink: Ofs(TypeOf(TCodeEditor)^);
  250. Load: @TCodeEditor.Load;
  251. Store: @TCodeEditor.Store
  252. );
  253. RFileEditor: TStreamRec = (
  254. ObjType: 1102;
  255. VmtLink: Ofs(TypeOf(TFileEditor)^);
  256. Load: @TFileEditor.Load;
  257. Store: @TFileEditor.Store
  258. );
  259. {$endif}
  260. constructor TLine.Init(AOwner: PCustomCodeEditorCore; const AText: string; AFlags: longint);
  261. begin
  262. inherited Init(AText,AFlags);
  263. New(EditorInfos, Init(10,10));
  264. Owner:=AOwner;
  265. end;
  266. procedure TLine.AddEditorInfo(Index: sw_integer; AEditor: PCustomCodeEditor);
  267. begin
  268. EditorInfos^.AtInsert(Index,New(PEditorLineInfo, Init(AEditor)));
  269. end;
  270. procedure TLine.RemoveEditorInfo(AEditor: PCustomCodeEditor);
  271. var E: PEditorLineInfo;
  272. begin
  273. E:=GetEditorInfo(AEditor);
  274. EditorInfos^.Free(E);
  275. end;
  276. function TLine.GetText: string;
  277. begin
  278. GetText:=GetStr(Text);
  279. end;
  280. procedure TLine.SetText(const AText: string);
  281. begin
  282. SetStr(Text,AText);
  283. end;
  284. function TLine.GetEditorInfo(Editor: PCustomCodeEditor): PEditorLineInfo;
  285. function Match(P: PEditorLineInfo): boolean; {$ifdef TP}far;{$endif}
  286. begin
  287. Match:=P^.Editor=Editor;
  288. end;
  289. begin
  290. GetEditorInfo:=EditorInfos^.FirstThat(@Match);
  291. end;
  292. function TLine.GetFlags: longint;
  293. begin
  294. GetFlags:=Flags;
  295. end;
  296. procedure TLine.SetFlags(AFlags: longint);
  297. begin
  298. Flags:=AFlags;
  299. if Assigned(Owner) then
  300. Owner^.ContentsChanged;
  301. end;
  302. destructor TLine.Done;
  303. begin
  304. if Assigned(Text) then DisposeStr(Text); Text:=nil;
  305. if Assigned(EditorInfos) then Dispose(EditorInfos, Done); EditorInfos:=nil;
  306. inherited Done;
  307. end;
  308. constructor TCodeEditorCore.Init;
  309. begin
  310. inherited Init;
  311. {$ifndef Undo}
  312. StoreUndo:=false;
  313. {$else Undo}
  314. StoreUndo:=true;
  315. {$endif def Undo}
  316. new(UndoList,init(500,1000));
  317. new(RedoList,init(500,1000));
  318. New(Lines, Init(500,1000));
  319. TabSize:=DefaultTabSize;
  320. end;
  321. function TCodeEditorCore.GetLineCount: sw_integer;
  322. begin
  323. GetLineCount:=Lines^.Count;
  324. end;
  325. function TCodeEditorCore.GetLine(LineNo: sw_integer): PCustomLine;
  326. begin
  327. GetLine:=Lines^.At(LineNo);
  328. end;
  329. function TCodeEditorCore.GetModified: boolean;
  330. begin
  331. GetModified:=Modified;
  332. end;
  333. procedure TCodeEditorCore.SetModified(AModified: boolean);
  334. begin
  335. if AModified<>Modified then
  336. begin
  337. Modified:=AModified;
  338. ModifiedChanged;
  339. end;
  340. end;
  341. function TCodeEditorCore.GetStoreUndo: boolean;
  342. begin
  343. GetStoreUndo:=StoreUndo;
  344. end;
  345. procedure TCodeEditorCore.SetStoreUndo(AStore: boolean);
  346. begin
  347. if StoreUndo<>AStore then
  348. begin
  349. StoreUndo:=AStore;
  350. StoreUndoChanged;
  351. end;
  352. end;
  353. function TCodeEditorCore.GetSyntaxCompleted: boolean;
  354. begin
  355. {$ifdef TEST_PARTIAL_SYNTAX}
  356. GetSyntaxCompleted:=SyntaxComplete;
  357. {$else}
  358. GetSyntaxCompleted:=true;
  359. {$endif}
  360. end;
  361. procedure TCodeEditorCore.SetSyntaxCompleted(SC: boolean);
  362. begin
  363. {$ifdef TEST_PARTIAL_SYNTAX}
  364. if SC<>SyntaxComplete then
  365. begin
  366. SyntaxComplete:=SC;
  367. end;
  368. {$endif}
  369. end;
  370. function TCodeEditorCore.GetLastSyntaxedLine: sw_integer;
  371. begin
  372. GetLastSyntaxedLine:=LastSyntaxedLine;
  373. end;
  374. procedure TCodeEditorCore.SetLastSyntaxedLine(ALine: sw_integer);
  375. begin
  376. LastSyntaxedLine:=ALine;
  377. end;
  378. procedure TCodeEditorCore.ISetLineFlagState(Binding: PEditorBinding; LineNo: sw_integer; Flag: longint; ASet: boolean);
  379. var P: PCustomLine;
  380. begin
  381. if LineNo<GetLineCount then
  382. begin
  383. P:=GetLine(LineNo);
  384. if assigned(P) then
  385. P^.SetFlagState(Flag,ASet);
  386. end;
  387. end;
  388. procedure TCodeEditorCore.GetContent(ALines: PUnsortedStringCollection);
  389. procedure AddIt(P: PCustomLine); {$ifndef FPC}far;{$endif}
  390. begin
  391. if Assigned(P) then
  392. ALines^.Insert(NewStr(P^.GetText));
  393. end;
  394. begin
  395. if Assigned(Lines) then
  396. Lines^.ForEach(@AddIt);
  397. end;
  398. procedure TCodeEditorCore.SetContent(ALines: PUnsortedStringCollection);
  399. procedure AddIt(P: PString); {$ifndef FPC}far;{$endif}
  400. begin
  401. AddLine(GetStr(P));
  402. end;
  403. begin
  404. DeleteAllLines;
  405. if Assigned(ALines) then
  406. ALines^.ForEach(@AddIt);
  407. LimitsChanged;
  408. end;
  409. function TCodeEditorCore.GetTabSize: integer;
  410. begin
  411. GetTabSize:=TabSize;
  412. end;
  413. procedure TCodeEditorCore.SetTabSize(ATabSize: integer);
  414. begin
  415. if ATabSize<>TabSize then
  416. begin
  417. TabSize:=ATabSize;
  418. TabSizeChanged;
  419. end;
  420. end;
  421. function TCodeEditorCore.GetLineText(LineNo: sw_integer): string;
  422. var
  423. L : PCustomLine;
  424. begin
  425. GetLineText:='';
  426. if LineNo<Lines^.Count then
  427. begin
  428. L:=Lines^.At(LineNo);
  429. GetLineText:=L^.GetText;
  430. end;
  431. end;
  432. procedure TCodeEditorCore.LinesInsert(Idx: sw_integer; Line: PLine);
  433. var I: sw_integer;
  434. procedure RegLine(P: PEditorBinding); {$ifndef FPC}far;{$endif}
  435. begin
  436. Line^.AddEditorInfo(I,P^.Editor);
  437. Inc(I);
  438. end;
  439. begin
  440. if Idx=-1 then Idx:=Lines^.Count;
  441. I:=0;
  442. Bindings^.ForEach(@RegLine);
  443. Lines^.AtInsert(Idx,Line);
  444. end;
  445. procedure TCodeEditorCore.SetLineText(I: sw_integer;const S: string);
  446. var
  447. L : PCustomLine;
  448. AddCount : Sw_Integer;
  449. begin
  450. AddCount:=0;
  451. while (Lines^.Count<I+1) do
  452. begin
  453. LinesInsert(-1,New(PLine, Init(@Self,'',0)));
  454. Inc(AddCount);
  455. end;
  456. if AddCount>0 then
  457. LimitsChanged;
  458. L:=Lines^.At(I);
  459. L^.SetText(S);
  460. ContentsChanged;
  461. end;
  462. function TCodeEditorCore.GetDisplayText(I: sw_integer): string;
  463. begin
  464. GetDisplayText:=ExtractTabs(GetLineText(I),GetTabSize);
  465. end;
  466. procedure TCodeEditorCore.SetDisplayText(I: sw_integer;const S: string);
  467. begin
  468. { I disagree here
  469. I don't want the editor to change the position of the tabs
  470. in my makefiles !! PM
  471. if FlagSet(efUseTabCharacters) and (TabSize>0) then
  472. SetLineText(I,CompressUsingTabs(S,TabSize))
  473. else }
  474. { ... then you better make this optional - Gabor }
  475. SetLineText(I,S);
  476. end;
  477. procedure TCodeEditorCore.IGetDisplayTextFormat(Binding: PEditorBinding; LineNo: sw_integer;var DT,DF:string);
  478. var
  479. L : PCustomLine;
  480. P,PAdd : SW_Integer;
  481. begin
  482. DF:='';
  483. DT:='';
  484. if (0<=LineNo) and (LineNo<GetLineCount) then
  485. begin
  486. L:=GetLine(LineNo);
  487. if not assigned(L) then
  488. exit;
  489. DF:=IGetLineFormat(Binding,LineNo);
  490. DT:=L^.GetText;
  491. p:=0;
  492. while p<length(DT) do
  493. begin
  494. inc(p);
  495. if DT[p]=#9 then
  496. begin
  497. PAdd:=TabSize-((p-1) mod TabSize);
  498. if DF<>'' then
  499. DF:=copy(DF,1,P-1)+CharStr(DF[p],PAdd)+copy(DF,P+1,High(DF));
  500. DT:=copy(DT,1,P-1)+CharStr(' ',PAdd)+copy(DT,P+1,High(DF));
  501. inc(P,PAdd-1);
  502. end;
  503. end;
  504. end;
  505. end;
  506. function TCodeEditorCore.IGetLineFormat(Binding: PEditorBinding; LineNo: sw_integer): string;
  507. var P: PCustomLine;
  508. LI: PEditorLineInfo;
  509. S: string;
  510. begin
  511. if (0<=LineNo) and (LineNo<GetLineCount) then
  512. P:=GetLine(LineNo)
  513. else
  514. P:=nil;
  515. if P=nil then LI:=nil else
  516. LI:=P^.GetEditorInfo(Binding^.Editor);
  517. if LI=nil then S:='' else S:=LI^.GetFormat;
  518. IGetLineFormat:=S;
  519. end;
  520. procedure TCodeEditorCore.ISetLineFormat(Binding: PEditorBinding; LineNo: sw_integer;const S: string);
  521. var P: PCustomLine;
  522. LI: PEditorLineInfo;
  523. begin
  524. if (LineNo<GetLineCount) then
  525. begin
  526. P:=GetLine(LineNo);
  527. if P=nil then LI:=nil else LI:=P^.GetEditorInfo(Binding^.Editor);
  528. if Assigned(LI) then LI^.SetFormat(S);
  529. end;
  530. end;
  531. procedure TCodeEditorCore.DeleteAllLines;
  532. begin
  533. if Assigned(Lines) then
  534. Lines^.FreeAll;
  535. end;
  536. procedure TCodeEditorCore.DeleteLine(I: sw_integer);
  537. var
  538. CP : Tpoint;
  539. begin
  540. if I<Lines^.Count then
  541. begin
  542. if StoreUndo then
  543. begin
  544. CP.X:=0;CP.Y:=I;
  545. AddAction(eaDeleteLine,CP,CP,GetLineText(I));
  546. end;
  547. Lines^.AtFree(I);
  548. end;
  549. end;
  550. function TCodeEditorCore.InsertLine(LineNo: sw_integer; const S: string): PCustomLine;
  551. var L: PLine;
  552. begin
  553. L:=New(PLine, Init(@Self,S,0));
  554. LinesInsert(LineNo, L);
  555. InsertLine:=L;
  556. end;
  557. procedure TCodeEditorCore.AddLine(const S: string);
  558. begin
  559. LinesInsert(-1,New(PLine, Init(@Self,S,0)));
  560. end;
  561. procedure TCodeEditorCore.AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string);
  562. {$ifdef Undo}
  563. var
  564. ActionIntegrated : boolean;
  565. pa : PEditorAction;
  566. S : String;
  567. {$endif Undo}
  568. begin
  569. {$ifdef Undo}
  570. if (UndoList=nil) or (not StoreUndo) then Exit;
  571. ActionIntegrated:=false;
  572. if UndoList^.count>0 then
  573. begin
  574. pa:=UndoList^.At(UndoList^.count-1);
  575. if (pa^.action=AAction) and
  576. (pa^.EndPos.X=AStartPos.X) and
  577. (pa^.EndPos.Y=AStartPos.Y) and
  578. { do not group InsertLine and DeleteLine !! }
  579. ((AAction=eaMoveCursor) or
  580. (AAction=eaInsertText) or
  581. (AAction=eaDeleteText))
  582. then
  583. begin
  584. pa^.EndPos:=AEndPos;
  585. S:=GetStr(pa^.text);
  586. if S<>'' then
  587. DisposeStr(pa^.text);
  588. if (AAction=eaDeleteText) and
  589. (AStartPos.X>AEndPos.X) then
  590. pa^.text:=NewStr(AText+S)
  591. else
  592. pa^.text:=NewStr(S+AText);
  593. ActionIntegrated:=true;
  594. end;
  595. end;
  596. if not ActionIntegrated then
  597. begin
  598. UndoList^.Insert(New(PEditorAction,Init(AAction,AStartPos,AEndPos,AText)));
  599. if assigned(UndoList^.CurrentGroupedAction) then
  600. Inc(UndoList^.CurrentGroupedAction^.actionCount);
  601. UpdateUndoRedo(cmUndo,AAction);
  602. end;
  603. if UndoList^.count>0 then
  604. begin
  605. UpdateUndoRedo(cmRedo,0);
  606. RedoList^.FreeAll;
  607. end;
  608. {$endif Undo}
  609. end;
  610. procedure TCodeEditorCore.AddGroupedAction(AAction : byte);
  611. begin
  612. {$ifdef Undo}
  613. if Assigned(UndoList^.CurrentGroupedAction) then
  614. inc(UndoList^.GroupLevel)
  615. else
  616. begin
  617. UndoList^.CurrentGroupedAction:=New(PEditorAction,Init_group(AAction));
  618. UndoList^.GroupLevel:=1;
  619. end;
  620. {$endif Undo}
  621. end;
  622. procedure TCodeEditorCore.CloseGroupedAction(AAction : byte);
  623. begin
  624. {$ifdef Undo}
  625. dec(UndoList^.GroupLevel);
  626. if UndoList^.GroupLevel=0 then
  627. begin
  628. UndoList^.Insert(UndoList^.CurrentGroupedAction);
  629. UndoList^.CurrentGroupedAction:=nil;
  630. UpdateUndoRedo(cmUndo,AAction);
  631. end;
  632. {$endif Undo}
  633. end;
  634. function TCodeEditorCore.GetUndoActionCount: sw_integer;
  635. begin
  636. GetUndoActionCount:=UndoList^.Count;
  637. end;
  638. function TCodeEditorCore.GetRedoActionCount: sw_integer;
  639. begin
  640. GetRedoActionCount:=RedoList^.Count;
  641. end;
  642. destructor TCodeEditorCore.Done;
  643. begin
  644. inherited Done;
  645. if Assigned(Lines) then Dispose(Lines, Done); Lines:=nil;
  646. if Assigned(RedoList) then Dispose(RedoList, Done); RedoList:=nil;
  647. if Assigned(UndoList) then Dispose(UndoList, Done); UndoList:=nil;
  648. end;
  649. constructor TIndicator.Init(var Bounds: TRect);
  650. begin
  651. inherited Init(Bounds);
  652. GrowMode := gfGrowLoY + gfGrowHiY;
  653. end;
  654. procedure TIndicator.Draw;
  655. var
  656. Color: Byte;
  657. Frame: Char;
  658. L: array[0..1] of Longint;
  659. S: String[15];
  660. B: TDrawBuffer;
  661. begin
  662. if (State and sfDragging = 0) and (State and sfActive <> 0) then
  663. begin
  664. Color := GetColor(1);
  665. Frame := #205;
  666. end
  667. else
  668. begin
  669. if (State and sfDragging)<>0 then
  670. Color := GetColor(2)
  671. else
  672. Color := GetColor(3);
  673. Frame := #196;
  674. end;
  675. MoveChar(B, Frame, Color, Size.X);
  676. if State and sfActive<>0 then
  677. begin
  678. if Modified then
  679. WordRec (B[0]).Lo := ord('*');
  680. {$ifdef debug}
  681. if StoreUndo then
  682. WordRec (B[1]).Lo := ord('S');
  683. if SyntaxComplete then
  684. WordRec(B[2]).lo := ord('C');
  685. if UseTabs then
  686. WordRec(B[3]).lo := ord('T');
  687. {$endif debug}
  688. L[0] := Location.Y + 1;
  689. L[1] := Location.X + 1;
  690. FormatStr(S, '%d:%d ', L);
  691. MoveStr(B[8 - Pos(':', S)], S, Color);
  692. end;
  693. WriteBuf(0, 0, Size.X, 1, B);
  694. end;
  695. function TIndicator.GetPalette: PPalette;
  696. const
  697. P: string[Length(CIndicator)] = CIndicator;
  698. begin
  699. GetPalette := @P;
  700. end;
  701. procedure TIndicator.SetState(AState: Word; Enable: Boolean);
  702. begin
  703. inherited SetState(AState, Enable);
  704. if (AState = sfDragging) or (AState=sfActive) then
  705. DrawView;
  706. end;
  707. procedure TIndicator.SetValue(ALocation: TPoint; AModified: Boolean);
  708. begin
  709. if (Location.X<>ALocation.X) or
  710. (Location.Y<>ALocation.Y) or
  711. (Modified <> AModified) then
  712. begin
  713. Location := ALocation;
  714. Modified := AModified;
  715. DrawView;
  716. end;
  717. end;
  718. {constructor TIndicator.Load(var S: TStream);
  719. begin
  720. inherited Load(S);
  721. S.Read(Location,SizeOf(Location));
  722. S.Read(Modified,SizeOf(Modified));
  723. end;
  724. procedure TIndicator.Store(var S: TStream);
  725. begin
  726. inherited Store(S);
  727. S.Write(Location,SizeOf(Location));
  728. S.Write(Modified,SizeOf(Modified));
  729. end;}
  730. {*****************************************************************************
  731. TCodeEditor
  732. *****************************************************************************}
  733. constructor TCodeEditor.Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  734. PScrollBar; AIndicator: PIndicator; ACore: PCodeEditorCore);
  735. begin
  736. inherited Init(Bounds,AHScrollBar,AVScrollBar);
  737. New(Folds, Init(100,100));
  738. if ACore=nil then ACore:=New(PCodeEditorCore, Init);
  739. Core:=ACore;
  740. Core^.BindEditor(@Self);
  741. SetState(sfCursorVis,true);
  742. SetFlags(DefaultCodeEditorFlags);
  743. SetCurPtr(0,0);
  744. Indicator:=AIndicator;
  745. UpdateIndicator;
  746. LimitsChanged;
  747. end;
  748. function TCodeEditor.GetFlags: longint;
  749. begin
  750. GetFlags:=Flags;
  751. end;
  752. procedure TCodeEditor.SetFlags(AFlags: longint);
  753. var OFlags: longint;
  754. begin
  755. if AFlags<>Flags then
  756. begin
  757. OFlags:=Flags;
  758. Flags:=AFlags;
  759. FlagsChanged(OFlags);
  760. end;
  761. end;
  762. function TCodeEditor.GetModified: boolean;
  763. begin
  764. GetModified:=Core^.GetModified;
  765. end;
  766. procedure TCodeEditor.SetModified(AModified: boolean);
  767. begin
  768. Core^.SetModified(AModified);
  769. end;
  770. function TCodeEditor.GetStoreUndo: boolean;
  771. begin
  772. GetStoreUndo:=Core^.GetStoreUndo;
  773. end;
  774. procedure TCodeEditor.SetStoreUndo(AStore: boolean);
  775. begin
  776. Core^.SetStoreUndo(AStore);
  777. end;
  778. function TCodeEditor.GetSyntaxCompleted: boolean;
  779. begin
  780. GetSyntaxCompleted:=Core^.GetSyntaxCompleted;
  781. end;
  782. procedure TCodeEditor.SetSyntaxCompleted(SC : boolean);
  783. begin
  784. Core^.SetSyntaxCompleted(SC);
  785. end;
  786. function TCodeEditor.GetLastSyntaxedLine: sw_integer;
  787. begin
  788. GetLastSyntaxedLine:=Core^.GetLastSyntaxedLine;
  789. end;
  790. procedure TCodeEditor.SetLastSyntaxedLine(ALine: sw_integer);
  791. begin
  792. Core^.SetLastSyntaxedLine(ALine);
  793. end;
  794. function TCodeEditor.GetTabSize: integer;
  795. begin
  796. GetTabSize:=Core^.GetTabSize;
  797. end;
  798. procedure TCodeEditor.SetTabSize(ATabSize: integer);
  799. begin
  800. Core^.SetTabSize(ATabSize);
  801. end;
  802. function TCodeEditor.IsReadOnly: boolean;
  803. begin
  804. IsReadOnly:=ReadOnly or (Core^.ReadOnly);
  805. end;
  806. function TCodeEditor.IsClipboard: Boolean;
  807. begin
  808. IsClipboard:=Core^.IsClipboard;
  809. end;
  810. function TCodeEditor.GetErrorMessage: string;
  811. begin
  812. GetErrorMessage:=GetStr(ErrorMessage);
  813. end;
  814. procedure TCodeEditor.SetErrorMessage(const S: string);
  815. begin
  816. SetStr(ErrorMessage,S);
  817. DrawView;
  818. end;
  819. function TCodeEditor.GetLineCount: sw_integer;
  820. begin
  821. GetLineCount:=Core^.GetLineCount;
  822. end;
  823. function TCodeEditor.GetLine(LineNo: sw_integer): PCustomLine;
  824. begin
  825. GetLine:=Core^.GetLine(LineNo);
  826. end;
  827. function TCodeEditor.CharIdxToLinePos(Line,CharIdx: sw_integer): sw_integer;
  828. begin
  829. CharIdxToLinePos:=Core^.CharIdxToLinePos(Line,CharIdx);
  830. end;
  831. function TCodeEditor.LinePosToCharIdx(Line,X: sw_integer): sw_integer;
  832. begin
  833. LinePosToCharIdx:=Core^.LinePosToCharIdx(Line,X);
  834. end;
  835. function TCodeEditor.GetLineText(I: sw_integer): string;
  836. begin
  837. GetLineText:=Core^.GetLineText(I);
  838. end;
  839. procedure TCodeEditor.SetDisplayText(I: sw_integer;const S: string);
  840. begin
  841. Core^.SetDisplayText(I,S);
  842. end;
  843. function TCodeEditor.GetDisplayText(I: sw_integer): string;
  844. begin
  845. GetDisplayText:=Core^.GetDisplayText(I);
  846. end;
  847. procedure TCodeEditor.SetLineText(I: sw_integer;const S: string);
  848. begin
  849. Core^.SetLineText(I,S);
  850. end;
  851. procedure TCodeEditor.GetDisplayTextFormat(I: sw_integer;var DT,DF:string);
  852. begin
  853. Core^.GetDisplayTextFormat(@Self,I,DT,DF);
  854. end;
  855. function TCodeEditor.GetLineFormat(I: sw_integer): string;
  856. begin
  857. GetLineFormat:=Core^.GetLineFormat(@Self,I);
  858. end;
  859. procedure TCodeEditor.SetLineFormat(I: sw_integer;const S: string);
  860. begin
  861. Core^.SetLineFormat(@Self,I,S);
  862. end;
  863. procedure TCodeEditor.DeleteAllLines;
  864. begin
  865. Core^.DeleteAllLines;
  866. end;
  867. procedure TCodeEditor.DeleteLine(I: sw_integer);
  868. begin
  869. Core^.DeleteLine(I);
  870. end;
  871. function TCodeEditor.InsertLine(LineNo: sw_integer; const S: string): PCustomLine;
  872. begin
  873. InsertLine:=Core^.InsertLine(LineNo,S);
  874. end;
  875. procedure TCodeEditor.AddLine(const S: string);
  876. begin
  877. Core^.AddLine(S);
  878. end;
  879. function TCodeEditor.GetMaxFoldLevel: sw_integer;
  880. begin
  881. GetMaxFoldLevel:=MaxFoldLevel;
  882. end;
  883. procedure TCodeEditor.RegisterFold(AFold: PFold);
  884. var L: sw_integer;
  885. begin
  886. if Assigned(Folds) then
  887. begin
  888. Folds^.Insert(AFold);
  889. L:=AFold^.GetLevel+1;
  890. if L>MaxFoldLevel then MaxFoldLevel:=L;
  891. end;
  892. end;
  893. procedure TCodeEditor.UnRegisterFold(AFold: PFold);
  894. begin
  895. if Assigned(Folds) then
  896. begin
  897. Folds^.Delete(AFold);
  898. if Folds^.Count=0 then
  899. MaxFoldLevel:=0
  900. else
  901. MaxFoldLevel:=inherited GetMaxFoldLevel+1;
  902. end;
  903. end;
  904. function TCodeEditor.GetFoldCount: sw_integer;
  905. begin
  906. GetFoldCount:=Folds^.Count;
  907. end;
  908. function TCodeEditor.GetFold(Index: sw_integer): PFold;
  909. begin
  910. GetFold:=Folds^.At(Index);
  911. end;
  912. {function TCodeEditor.GetLineTextPos(Line,X: integer): integer;
  913. var
  914. S: string;
  915. rx,i : Sw_integer;
  916. begin
  917. S:=GetLineText(Line);
  918. i:=0; rx:=0;
  919. while (RX<X) and (i<Length(s)) do
  920. begin
  921. inc(i);
  922. inc(rx);
  923. if s[i]=#9 then
  924. inc(rx,TabSize-(rx mod tabsize));
  925. end;
  926. if RX<X then Inc(I,X-RX);
  927. GetLineTextPos:=i;
  928. end;
  929. function TCodeEditor.GetDisplayTextPos(Line,X: integer): integer;
  930. var
  931. S: string;
  932. L: PCustomLine;
  933. rx,i : Sw_integer;
  934. begin
  935. S:='';
  936. if Line<Lines^.Count then
  937. begin
  938. L:=Lines^.At(Line);
  939. if assigned(L^.Text) then
  940. S:=L^.Text^;
  941. end;
  942. i:=0;
  943. rx:=0;
  944. while (i<X) and (i<Length(s)) do
  945. begin
  946. inc(i);
  947. inc(rx);
  948. if s[i]=#9 then
  949. inc(rx,TabSize-(rx mod tabsize));
  950. end;
  951. GetDisplayTextPos:=rx;
  952. end;}
  953. procedure TCodeEditor.GetContent(ALines: PUnsortedStringCollection);
  954. begin
  955. Core^.GetContent(ALines);
  956. end;
  957. procedure TCodeEditor.SetContent(ALines: PUnsortedStringCollection);
  958. begin
  959. Lock;
  960. TextStart; HideSelect;
  961. Core^.SetContent(ALines);
  962. LimitsChanged;
  963. if IsFlagSet(efSyntaxHighlight) then
  964. Core^.UpdateAttrsRange(0,Min(Delta.Y+Size.Y,GetLineCount-1),
  965. attrAll
  966. {$ifndef TEST_PARTIAL_SYNTAX}
  967. +attrForceFull
  968. {$endif TEST_PARTIAL_SYNTAX}
  969. );
  970. TextStart;
  971. UnLock;
  972. end;
  973. function TCodeEditor.GetCodeCompleteFrag: string;
  974. begin
  975. GetCodeCompleteFrag:=GetStr(CodeCompleteFrag);
  976. end;
  977. procedure TCodeEditor.SetCodeCompleteFrag(const S: string);
  978. begin
  979. SetStr(CodeCompleteFrag,S);
  980. end;
  981. function TCodeEditor.GetCompleteState: TCompleteState;
  982. begin
  983. GetCompleteState:=CompleteState;
  984. end;
  985. procedure TCodeEditor.SetCompleteState(AState: TCompleteState);
  986. begin
  987. if AState<>CompleteState then
  988. begin
  989. CompleteState:=AState;
  990. if CompleteState<>csOffering then
  991. ClearCodeCompleteWord;
  992. end;
  993. end;
  994. function TCodeEditor.GetCodeCompleteWord: string;
  995. begin
  996. GetCodeCompleteWord:=GetStr(CodeCompleteWord);
  997. end;
  998. procedure TCodeEditor.SetCodeCompleteWord(const S: string);
  999. begin
  1000. if Assigned(CodeCompleteWord) then DisposeStr(CodeCompleteWord);
  1001. CodeCompleteWord:=NewStr(S);
  1002. inherited SetCodeCompleteWord(S);
  1003. end;
  1004. procedure TCodeEditor.DrawIndicator;
  1005. begin
  1006. if Assigned(Indicator) then
  1007. Indicator^.DrawView;
  1008. end;
  1009. procedure TCodeEditor.Lock;
  1010. begin
  1011. inherited Lock;
  1012. Core^.Lock(@Self);
  1013. end;
  1014. procedure TCodeEditor.UnLock;
  1015. begin
  1016. Core^.UnLock(@Self);
  1017. inherited UnLock;
  1018. If IndicatorDrawCalled then
  1019. begin
  1020. DrawIndicator;
  1021. IndicatorDrawCalled:=false;
  1022. end;
  1023. end;
  1024. procedure TCodeEditor.UpdateIndicator;
  1025. begin
  1026. if Indicator<>nil then
  1027. begin
  1028. Indicator^.Location:=CurPos;
  1029. Indicator^.Modified:=GetModified;
  1030. {$ifdef debug}
  1031. Indicator^.StoreUndo:=GetStoreUndo;
  1032. {$ifdef TEST_PARTIAL_SYNTAX}
  1033. Indicator^.SyntaxComplete:=GetSyntaxCompleted and IsFlagSet(efSyntaxHighlight);
  1034. {$endif TEST_PARTIAL_SYNTAX}
  1035. Indicator^.UseTabs:=IsFlagSet(efUseTabCharacters);
  1036. {$endif debug}
  1037. if lockflag>0 then
  1038. IndicatorDrawCalled:=true
  1039. else
  1040. Indicator^.DrawView;
  1041. end;
  1042. end;
  1043. procedure TCodeEditor.LimitsChanged;
  1044. begin
  1045. Core^.LimitsChanged;
  1046. end;
  1047. procedure TCodeEditor.ModifiedChanged;
  1048. begin
  1049. UpdateIndicator;
  1050. end;
  1051. procedure TCodeEditor.PositionChanged;
  1052. begin
  1053. UpdateIndicator;
  1054. end;
  1055. procedure TCodeEditor.JumpToLastCursorPos;
  1056. {$ifdef Undo}
  1057. var
  1058. pa : PEditorAction;
  1059. {$endif Undo}
  1060. begin
  1061. {$ifdef Undo}
  1062. if (Core^.UndoList^.count>0) and (Core^.RedoList^.count=0) then
  1063. begin
  1064. { Or should we just call Undo ?? PM }
  1065. pa:=Core^.UndoList^.At(Core^.UndoList^.count-1);
  1066. if (pa^.action=eaMoveCursor) then
  1067. SetCurPtr(pa^.StartPos.X,pa^.StartPos.Y);
  1068. end;
  1069. {$else not Undo}
  1070. NotImplemented;
  1071. {$endif Undo}
  1072. end;
  1073. procedure TCodeEditor.Undo;
  1074. {$ifdef Undo}
  1075. var
  1076. Temp,Idx,Last,Count : Longint;
  1077. Is_grouped,Had_efNoIndent : boolean;
  1078. MaxY,MinY : sw_integer;
  1079. procedure SetMinMax(y : sw_integer);
  1080. begin
  1081. if MinY=-1 then
  1082. MinY:=Y;
  1083. if Y<MinY then
  1084. MinY:=Y;
  1085. if MaxY=-1 then
  1086. MaxY:=Y;
  1087. if Y>MaxY then
  1088. MaxY:=Y;
  1089. end;
  1090. {$endif Undo}
  1091. begin
  1092. {$ifdef Undo}
  1093. Core^.SetStoreUndo(False);
  1094. Lock;
  1095. MinY:=-1;
  1096. MaxY:=-1;
  1097. if Core^.UndoList^.count > 0 then
  1098. begin
  1099. Last:=Core^.UndoList^.count-1;
  1100. if Core^.UndoList^.At(Last)^.Is_grouped_action then
  1101. begin
  1102. Count:=Core^.UndoList^.At(Last)^.ActionCount;
  1103. Dec(Last);
  1104. Is_grouped:=true;
  1105. end
  1106. else
  1107. begin
  1108. Count:=1;
  1109. Is_grouped:=false;
  1110. end;
  1111. for Idx:=Last downto Last-Count+1 do
  1112. with Core^.UndoList^.At(Idx)^ do
  1113. begin
  1114. case action of
  1115. eaMoveCursor :
  1116. begin
  1117. { move cursor back to original position }
  1118. SetCurPtr(startpos.x,startpos.y);
  1119. end;
  1120. eaInsertText :
  1121. begin
  1122. SetCurPtr(StartPos.X,StartPos.Y);
  1123. if assigned(text) then
  1124. for Temp := 1 to length(Text^) do
  1125. DelChar;
  1126. SetMinMax(StartPos.Y);
  1127. end;
  1128. eaDeleteText :
  1129. begin
  1130. { reinsert deleted text }
  1131. SetCurPtr(EndPos.X,EndPos.Y);
  1132. if assigned(text) then
  1133. for Temp := 1 to length(Text^) do
  1134. AddChar(Text^[Temp]);
  1135. SetMinMax(EndPos.Y);
  1136. SetCurPtr(StartPos.X,StartPos.Y);
  1137. end;
  1138. eaInsertLine :
  1139. begin
  1140. SetCurPtr(EndPos.X,EndPos.Y);
  1141. SetDisplayText(EndPos.Y,Copy(GetDisplayText(EndPos.Y),EndPos.X+1,255));
  1142. SetMinMax(EndPos.Y);
  1143. BackSpace;
  1144. SetCurPtr(StartPos.X,StartPos.Y);
  1145. SetMinMax(StartPos.Y);
  1146. end;
  1147. eaDeleteLine :
  1148. begin
  1149. SetCurPtr(EndPos.X,EndPos.Y);
  1150. SetMinMax(EndPos.Y);
  1151. Had_efNoIndent:=(GetFlags and efNoIndent)<>0;
  1152. SetFlags(GetFlags or efNoIndent);
  1153. InsertNewLine;
  1154. if not Had_efNoIndent then
  1155. SetFlags(GetFlags and not efNoIndent);
  1156. {DelEnd; wrong for eaCut at least }
  1157. SetCurPtr(StartPos.X,StartPos.Y);
  1158. SetLineText(StartPos.Y,Copy(GetDisplayText(StartPos.Y),1,StartPos.X)+GetStr(Text));
  1159. SetMinMax(StartPos.Y);
  1160. end;
  1161. eaSelectionChanged :
  1162. begin
  1163. { move cursor to end of last set selection }
  1164. end;
  1165. else
  1166. { what the 'ell's an undefined action doing round 'ere mate! }
  1167. ;
  1168. end; { once this lot is done paste into redo and modify to suit needs }
  1169. { move item to redo stack }
  1170. Core^.RedoList^.Insert(Core^.UndoList^.At(Idx));
  1171. UpdateUndoRedo(cmRedo,Core^.UndoList^.At(Idx)^.Action);
  1172. Core^.UndoList^.atDelete(Idx);
  1173. If Idx>0 then
  1174. UpdateUndoRedo(cmUndo,Core^.UndoList^.At(Idx-1)^.Action)
  1175. else
  1176. UpdateUndoRedo(cmUndo,0);
  1177. end;{Idx loop for grouped actions }
  1178. if is_grouped then
  1179. begin
  1180. Idx:=Core^.UndoList^.Count-1;
  1181. Core^.RedoList^.Insert(Core^.UndoList^.At(Idx));
  1182. UpdateUndoRedo(cmRedo,Core^.UndoList^.At(Idx)^.Action);
  1183. Core^.UndoList^.atDelete(Idx);
  1184. If Idx>0 then
  1185. UpdateUndoRedo(cmUndo,Core^.UndoList^.At(Idx-1)^.Action)
  1186. else
  1187. UpdateUndoRedo(cmUndo,0);
  1188. end;
  1189. if Core^.UndoList^.count=0 then
  1190. SetCmdState(UndoCmd,false);
  1191. SetCmdState(RedoCmd,true);
  1192. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  1193. if MinY<>-1 then
  1194. UpdateAttrsRange(MinY,MaxY,attrAll);
  1195. DrawView;
  1196. end;
  1197. Core^.SetStoreUndo(True);
  1198. Unlock;
  1199. {$else}
  1200. NotImplemented; Exit;
  1201. {$endif Undo}
  1202. end;
  1203. procedure TCodeEditor.Redo;
  1204. {$ifdef Undo}
  1205. var
  1206. Temp,Idx,Last,Count : Longint;
  1207. Is_grouped,Had_efNoIndent : boolean;
  1208. {$endif Undo}
  1209. begin
  1210. {$ifdef Undo}
  1211. Core^.SetStoreUndo(False);
  1212. Lock;
  1213. if Core^.RedoList^.count <> 0 then
  1214. begin
  1215. Last:=Core^.RedoList^.count-1;
  1216. if Core^.RedoList^.At(Last)^.Is_grouped_action then
  1217. begin
  1218. Count:=Core^.RedoList^.At(Last)^.ActionCount;
  1219. Dec(Last);
  1220. Is_grouped:=true;
  1221. end
  1222. else
  1223. begin
  1224. Count:=1;
  1225. Is_grouped:=false;
  1226. end;
  1227. for Idx:=Last downto Last-Count+1 do
  1228. with Core^.RedoList^.At(Idx)^ do
  1229. begin
  1230. case action of
  1231. eaMoveCursor :
  1232. begin
  1233. { move cursor back to original position }
  1234. SetCurPtr(EndPos.X,EndPos.Y);
  1235. end;
  1236. eaInsertText :
  1237. begin
  1238. SetCurPtr(startpos.x,startpos.y);
  1239. InsertText(GetStr(Text));
  1240. end;
  1241. eaDeleteText :
  1242. begin
  1243. SetCurPtr(EndPos.X,EndPos.Y);
  1244. for Temp := 1 to length(GetStr(Text)) do
  1245. DelChar;
  1246. end;
  1247. eaInsertLine :
  1248. begin
  1249. SetCurPtr(StartPos.X,StartPos.Y);
  1250. Had_efNoIndent:=(GetFlags and efNoIndent)<>0;
  1251. SetFlags(GetFlags or efNoIndent);
  1252. InsertNewLine;
  1253. if not Had_efNoIndent then
  1254. SetFlags(GetFlags and not efNoIndent);
  1255. SetCurPtr(0,StartPos.Y+1);
  1256. InsertText(GetStr(Text));
  1257. SetCurPtr(EndPos.X,EndPos.Y);
  1258. end;
  1259. eaDeleteLine :
  1260. begin
  1261. SetCurPtr(StartPos.X,StartPos.Y);
  1262. DeleteLine(StartPos.Y);
  1263. SetCurPtr(EndPos.X,EndPos.Y);
  1264. if EndPos.Y=StartPos.Y-1 then
  1265. SetDisplayText(EndPos.Y,RExpand(
  1266. copy(GetDisplayText(EndPos.Y),1,EndPos.X),EndPos.X)
  1267. +GetStr(Text));
  1268. SetCurPtr(EndPos.X,EndPos.Y);
  1269. end;
  1270. eaSelectionChanged :
  1271. begin
  1272. { move cursor to end of last set test selection }
  1273. end;
  1274. else
  1275. { what the 'ell's an undefined action doing round 'ere mate! }
  1276. ;
  1277. end; { once this lot is done paste back into undo and modify to suit needs }
  1278. { move item to undo stack }
  1279. Core^.UndoList^.Insert(Core^.RedoList^.At(Idx));
  1280. UpdateUndoRedo(cmUndo,Core^.RedoList^.At(Idx)^.Action);
  1281. If Idx>0 then
  1282. UpdateUndoRedo(cmRedo,Core^.RedoList^.At(Idx-1)^.Action)
  1283. else
  1284. UpdateUndoRedo(cmRedo,0);
  1285. Core^.RedoList^.atDelete(Idx);
  1286. end;{ Idx loop for grouped action }
  1287. If is_grouped then
  1288. begin
  1289. Idx:=Core^.RedoList^.count-1;
  1290. Core^.UndoList^.Insert(Core^.RedoList^.At(Idx));
  1291. UpdateUndoRedo(cmUndo,Core^.RedoList^.At(Idx)^.Action);
  1292. If Idx>0 then
  1293. UpdateUndoRedo(cmRedo,Core^.RedoList^.At(Idx-1)^.Action)
  1294. else
  1295. UpdateUndoRedo(cmRedo,0);
  1296. Core^.RedoList^.atDelete(Idx);
  1297. end;
  1298. if Core^.RedoList^.count=0 then
  1299. SetCmdState(RedoCmd,false);
  1300. SetCmdState(UndoCmd,true);
  1301. DrawView;
  1302. Message(Application,evBroadcast,cmCommandSetChanged,nil);
  1303. end;
  1304. Core^.SetStoreUndo(True);
  1305. Unlock;
  1306. {$else}
  1307. NotImplemented; Exit;
  1308. {$endif Undo}
  1309. end;
  1310. (*constructor TCodeEditor.Load(var S: TStream);
  1311. var TS: PSubStream;
  1312. TSize: longint;
  1313. begin
  1314. inherited Load(S);
  1315. New(UndoList,init(500,1000));
  1316. New(RedoList,init(500,1000));
  1317. New(Lines, Init(500,1000));
  1318. { we have always need at least 1 line }
  1319. LinesInsert(New(PLine, Init('',0)));
  1320. GetPeerViewPtr(S,Indicator);
  1321. S.Read(Flags,SizeOf(Flags));
  1322. S.Read(TabSize,SizeOf(TabSize));
  1323. if IsFlagSet(efStoreContent) then
  1324. begin
  1325. S.Read(TSize,SizeOf(TSize));
  1326. New(TS, Init(@S,S.GetPos,TSize));
  1327. {$ifdef TEST_PARTIAL_SYNTAX}
  1328. Core^.SearchBinding(Editor)^.SyntaxComplete:=false;
  1329. { Idle necessary }
  1330. EventMask:=EventMask or evIdle;
  1331. {$endif TEST_PARTIAL_SYNTAX}
  1332. LoadFromStream(TS);
  1333. Dispose(TS, Done);
  1334. end;
  1335. S.Read(SelStart,SizeOf(SelStart));
  1336. S.Read(SelEnd,SizeOf(SelEnd));
  1337. S.Read(Highlight,SizeOf(Highlight));
  1338. S.Read(CurPos,SizeOf(CurPos));
  1339. S.Read(StoreUndo,SizeOf(StoreUndo));
  1340. S.Read(IsReadOnly,SizeOf(IsReadOnly));
  1341. S.Read(NoSelect,SizeOf(NoSelect));
  1342. S.Read(HighlightRow,SizeOf(HighlightRow));
  1343. SetDebuggerRow(-1);
  1344. LimitsChanged;
  1345. SelectionChanged; HighlightChanged;
  1346. UpdateIndicator;
  1347. end;
  1348. procedure TCodeEditor.Store(var S: TStream);
  1349. var {NS: TNulStream;}
  1350. TSizePos,TSize,EndPos: longint;
  1351. begin
  1352. inherited Store(S);
  1353. PutPeerViewPtr(S,Indicator);
  1354. S.Write(Flags,SizeOf(Flags));
  1355. S.Write(TabSize,SizeOf(TabSize));
  1356. if IsFlagSet(efStoreContent) then
  1357. begin
  1358. { NS.Init;
  1359. SaveToStream(@NS);
  1360. TSize:=NS.GetSize;
  1361. NS.Done;
  1362. This is waste of time PM
  1363. use Seek instead !! }
  1364. { yep. and this won't work for serial streams. - Gabor }
  1365. TSize:=0;
  1366. TSizePos:=S.GetPos;
  1367. S.Write(TSize,SizeOf(TSize));
  1368. SaveToStream(@S);
  1369. EndPos:=S.GetPos;
  1370. TSize:=EndPos-TSizePos-SizeOf(TSize);
  1371. S.Seek(TSizePos);
  1372. S.Write(TSize,SizeOf(TSize));
  1373. S.Seek(EndPos);
  1374. end;
  1375. S.Write(SelStart,SizeOf(SelStart));
  1376. S.Write(SelEnd,SizeOf(SelEnd));
  1377. S.Write(Highlight,SizeOf(Highlight));
  1378. S.Write(CurPos,SizeOf(CurPos));
  1379. S.Write(StoreUndo,SizeOf(StoreUndo));
  1380. S.Write(IsReadOnly,SizeOf(IsReadOnly));
  1381. S.Write(NoSelect,SizeOf(NoSelect));
  1382. S.Write(HighlightRow,SizeOf(HighlightRow));
  1383. end;*)
  1384. function TCodeEditor.LoadFromStream(Stream: PStream): boolean;
  1385. var OK: boolean;
  1386. begin
  1387. OK:=Core^.LoadFromStream(@Self,Stream);
  1388. if IsFlagSet(efSyntaxHighlight) then
  1389. UpdateAttrsRange(0,Min(Delta.Y+Size.Y,GetLineCount-1),
  1390. attrAll
  1391. {$ifndef TEST_PARTIAL_SYNTAX}
  1392. +attrForceFull
  1393. {$endif TEST_PARTIAL_SYNTAX}
  1394. );
  1395. TextStart;
  1396. LoadFromStream:=OK;
  1397. end;
  1398. function TCodeEditor.SaveToStream(Stream: PStream): boolean;
  1399. begin
  1400. SaveToStream:=Core^.SaveToStream(@Self,Stream);
  1401. end;
  1402. function TCodeEditor.SaveAreaToStream(Stream: PStream; StartP,EndP: TPoint): boolean;
  1403. begin
  1404. SaveAreaToStream:=Core^.SaveAreaToStream(@Self,Stream,StartP,EndP);
  1405. end;
  1406. function TCodeEditor.UpdateAttrs(FromLine: sw_integer; Attrs: byte): sw_integer;
  1407. begin
  1408. UpdateAttrs:=Core^.UpdateAttrs(FromLine,Attrs);
  1409. end;
  1410. function TCodeEditor.UpdateAttrsRange(FromLine, ToLine: sw_integer; Attrs: byte): sw_integer;
  1411. begin
  1412. UpdateAttrsRange:=Core^.UpdateAttrsRange(FromLine,ToLine,Attrs);
  1413. end;
  1414. procedure TCodeEditor.AddAction(AAction: byte; AStartPos, AEndPos: TPoint; AText: string);
  1415. begin
  1416. Core^.AddAction(AAction,AStartPos,AEndPos,AText);
  1417. end;
  1418. procedure TCodeEditor.AddGroupedAction(AAction : byte);
  1419. begin
  1420. Core^.AddGroupedAction(AAction);
  1421. end;
  1422. procedure TCodeEditor.CloseGroupedAction(AAction : byte);
  1423. begin
  1424. Core^.CloseGroupedAction(AAction);
  1425. end;
  1426. function TCodeEditor.GetUndoActionCount: sw_integer;
  1427. begin
  1428. GetUndoActionCount:=Core^.GetUndoActionCount;
  1429. end;
  1430. function TCodeEditor.GetRedoActionCount: sw_integer;
  1431. begin
  1432. GetRedoActionCount:=Core^.GetRedoActionCount;
  1433. end;
  1434. destructor TCodeEditor.Done;
  1435. begin
  1436. inherited Done;
  1437. if Assigned(Core) then
  1438. begin
  1439. Core^.UnBindEditor(@Self);
  1440. if Core^.CanDispose then
  1441. Dispose(Core, Done);
  1442. end;
  1443. Core:=nil;
  1444. if Assigned(CodeCompleteFrag) then
  1445. DisposeStr(CodeCompleteFrag);
  1446. if Assigned(CodeCompleteWord) then
  1447. DisposeStr(CodeCompleteWord);
  1448. if Assigned(Folds) then Dispose(Folds, Done); Folds:=nil;
  1449. end;
  1450. constructor TFileEditor.Init(var Bounds: TRect; AHScrollBar, AVScrollBar:
  1451. PScrollBar; AIndicator: PIndicator;ACore: PCodeEditorCore; const AFileName: string);
  1452. begin
  1453. inherited Init(Bounds,AHScrollBAr,AVScrollBAr,AIndicator,ACore);
  1454. FileName:=AFileName;
  1455. UpdateIndicator;
  1456. Message(@Self,evBroadcast,cmFileNameChanged,@Self);
  1457. OnDiskLoadTime:=-1;
  1458. end;
  1459. function TFileEditor.LoadFile: boolean;
  1460. var OK: boolean;
  1461. PA : Array[1..2] of pointer;
  1462. begin
  1463. OK:=LoadFromFile(FileName);
  1464. if GetModified then
  1465. begin
  1466. PA[1]:=@FileName;
  1467. longint(PA[2]):=Core^.GetChangedLine;
  1468. EditorDialog(edChangedOnloading,@PA);
  1469. end;
  1470. OnDiskLoadTime:=GetFileTime(FileName);
  1471. LoadFile:=OK;
  1472. end;
  1473. function TFileEditor.IsChangedOnDisk : boolean;
  1474. begin
  1475. IsChangedOnDisk:=(OnDiskLoadTime<>GetFileTime(FileName)) and (OnDiskLoadTime<>-1);
  1476. end;
  1477. function TFileEditor.SaveFile: boolean;
  1478. var OK: boolean;
  1479. BAKName: string;
  1480. f: text;
  1481. begin
  1482. If IsChangedOnDisk then
  1483. begin
  1484. if EditorDialog(edFileOnDiskChanged, @FileName) <> cmYes then
  1485. begin
  1486. SaveFile:=false;
  1487. exit;
  1488. end;
  1489. end;
  1490. {$I-}
  1491. if IsFlagSet(efBackupFiles) and ExistsFile(FileName) then
  1492. begin
  1493. BAKName:=DirAndNameOf(FileName)+'.bak';
  1494. Assign(f,BAKName);
  1495. Erase(f);
  1496. EatIO;
  1497. Assign(f,FileName);
  1498. Rename(F,BAKName);
  1499. EatIO;
  1500. end;
  1501. {$I+}
  1502. OK:=SaveToFile(FileName);
  1503. if OK then
  1504. SetModified(false)
  1505. { Restore the original }
  1506. else if IsFlagSet(efBackupFiles) and ExistsFile(BakName) then
  1507. begin
  1508. {$I-}
  1509. Assign(f,BakName);
  1510. Rename(F,FileName);
  1511. EatIO;
  1512. {$I+}
  1513. end;
  1514. { don't forget to update the OnDiskLoadTime value }
  1515. if OK then
  1516. OnDiskLoadTime:=GetFileTime(FileName);
  1517. if not OK then
  1518. EditorDialog(edSaveError,@FileName);
  1519. SaveFile:=OK;
  1520. end;
  1521. function TFileEditor.ShouldSave: boolean;
  1522. begin
  1523. ShouldSave:=GetModified{ or (FileName='')};
  1524. end;
  1525. function TFileEditor.Save: Boolean;
  1526. begin
  1527. if ShouldSave=false then begin Save:=true; Exit; end;
  1528. if FileName = '' then Save := SaveAs else Save := SaveFile;
  1529. end;
  1530. function TFileEditor.SaveAs: Boolean;
  1531. begin
  1532. SaveAs := False;
  1533. if EditorDialog(edSaveAs, @FileName) <> cmCancel then
  1534. begin
  1535. FileName := FExpand(FileName);
  1536. Message(Owner, evBroadcast, cmUpdateTitle, @Self);
  1537. { if we rename the file the OnDiskLoadTime is wrong so we reset it }
  1538. OnDiskLoadTime:=-1;
  1539. SaveAs := SaveFile;
  1540. if IsClipboard then FileName := '';
  1541. Message(Application,evBroadcast,cmFileNameChanged,@Self);
  1542. end;
  1543. end;
  1544. function TFileEditor.SaveAsk(Force: boolean): boolean;
  1545. var OK: boolean;
  1546. D: Sw_integer;
  1547. begin
  1548. OK:=GetModified=false;
  1549. if Force=false then
  1550. if (OK=false) and (Core^.GetBindingCount>1) then
  1551. OK:=true;
  1552. if OK=false then
  1553. begin
  1554. if FileName = '' then D := edSaveUntitled else D := edSaveModify;
  1555. case EditorDialog(D, @FileName) of
  1556. cmYes : OK := Save;
  1557. cmNo : begin SetModified(False); OK:=true; end;
  1558. cmCancel : begin
  1559. OK := False;
  1560. Message(Application,evBroadcast,cmSaveCancelled,@Self);
  1561. end;
  1562. end;
  1563. end;
  1564. SaveAsk:=OK;
  1565. end;
  1566. procedure TFileEditor.BindingsChanged;
  1567. begin
  1568. Message(Application,evBroadcast,cmUpdateTitle,@Self);
  1569. end;
  1570. procedure TFileEditor.HandleEvent(var Event: TEvent);
  1571. var SH,B: boolean;
  1572. begin
  1573. case Event.What of
  1574. evBroadcast :
  1575. case Event.Command of
  1576. cmFileNameChanged :
  1577. if (Event.InfoPtr=nil) or (Event.InfoPtr=@Self) then
  1578. begin
  1579. B:=IsFlagSet(efSyntaxHighlight);
  1580. SH:=UseSyntaxHighlight(@Self);
  1581. if SH<>B then
  1582. if SH then
  1583. SetFlags(Flags or efSyntaxHighlight)
  1584. else
  1585. SetFlags(Flags and not efSyntaxHighlight);
  1586. if UseTabsPattern(@Self) then
  1587. SetFlags(Flags or efUseTabCharacters);
  1588. end;
  1589. end;
  1590. end;
  1591. inherited HandleEvent(Event);
  1592. end;
  1593. function TFileEditor.Valid(Command: Word): Boolean;
  1594. var OK: boolean;
  1595. begin
  1596. OK:=inherited Valid(Command);
  1597. if OK and ((Command=cmClose) or (Command=cmQuit)) then
  1598. if IsClipboard=false then
  1599. OK:=SaveAsk(Command=cmQuit);
  1600. Valid:=OK;
  1601. end;
  1602. (* constructor TFileEditor.Load(var S: TStream);
  1603. var P: PString;
  1604. SSP,SEP,CP,DP: TPoint;
  1605. HR: TRect;
  1606. PA : Array[1..2] of pointer;
  1607. HoldUndo : boolean;
  1608. begin
  1609. inherited Load(S);
  1610. HoldUndo:=GetStoreUndo;
  1611. SetStoreUndo(False);
  1612. P:=S.ReadStr;
  1613. FileName:=GetStr(P);
  1614. if P<>nil then DisposeStr(P);
  1615. UpdateIndicator;
  1616. { Message(@Self,evBroadcast,cmFileNameChanged,@Self);}
  1617. SSP:=SelStart; SEP:=SelEnd;
  1618. CP:=CurPos;
  1619. HR:=Highlight;
  1620. DP:=Delta;
  1621. if FileName<>'' then
  1622. LoadFile;
  1623. { if GetModified then
  1624. begin
  1625. PA[1]:=@FileName;
  1626. longint(PA[2]):=ChangedLine;
  1627. EditorDialog(edChangedOnloading,@PA);
  1628. end;}
  1629. SetHighlight(HR.A,HR.B);
  1630. SetSelection(SSP,SEP);
  1631. SetCurPtr(CP.X,CP.Y);
  1632. ScrollTo(DP.X,DP.Y);
  1633. SetModified(false);
  1634. LimitsChanged;
  1635. SetStoreUndo(HoldUndo);
  1636. end;
  1637. procedure TFileEditor.Store(var S: TStream);
  1638. begin
  1639. inherited Store(S);
  1640. S.WriteStr(@FileName);
  1641. end;
  1642. *)
  1643. function DefUseSyntaxHighlight(Editor: PFileEditor): boolean;
  1644. begin
  1645. DefUseSyntaxHighlight:=Editor^.IsFlagSet(efSyntaxHighlight);
  1646. end;
  1647. function DefUseTabsPattern(Editor: PFileEditor): boolean;
  1648. begin
  1649. DefUseTabsPattern:=Editor^.IsFlagSet(efUseTabCharacters);
  1650. end;
  1651. procedure RegisterWCEdit;
  1652. begin
  1653. {$ifndef NOOBJREG}
  1654. RegisterType(RIndicator);
  1655. RegisterType(RCodeEditor);
  1656. RegisterType(RFileEditor);
  1657. {$endif}
  1658. end;
  1659. END.
  1660. {
  1661. $Log$
  1662. Revision 1.5 2000-11-15 00:14:11 pierre
  1663. new merge
  1664. Revision 1.1.2.7 2000/11/14 23:41:32 pierre
  1665. * fix for bug 1234
  1666. Revision 1.4 2000/11/03 16:05:38 pierre
  1667. * (merged)
  1668. Revision 1.1.2.6 2000/11/03 15:49:26 pierre
  1669. * more Undo fixes
  1670. Revision 1.1.2.5 2000/11/03 13:31:33 pierre
  1671. + more Undo stuff and smarter indent/unindent
  1672. Revision 1.3 2000/10/31 22:35:55 pierre
  1673. * New big merge from fixes branch
  1674. Revision 1.1.2.4 2000/10/24 23:06:30 pierre
  1675. * some Undo/redo fixes
  1676. Revision 1.1.2.3 2000/09/18 13:20:55 pierre
  1677. New bunch of Gabor changes
  1678. }