Recent

Author Topic: Preventing editing of several line ranges  (Read 2922 times)

Pascal

  • Hero Member
  • *****
  • Posts: 832
Preventing editing of several line ranges
« on: April 12, 2017, 05:51:11 pm »
I am  going to implement a program wizzard in my COBOL-IDE
and want to prevent the user from editing some lines in the
generated source code.
I could think of putting parameters in comments in the source
code. My IDE can extract these parameters and block some line
ranges for editing by user.
But what would be the best way of implementing by line ReadOnly-
Attribute (which should only block user input)?
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Thaddy

  • Hero Member
  • *****
  • Posts: 9142
Re: Preventing editing of several line ranges
« Reply #1 on: April 12, 2017, 06:44:51 pm »
png,gif or jpg?
also related to equus asinus.

Pascal

  • Hero Member
  • *****
  • Posts: 832
Re: Preventing editing of several line ranges
« Reply #2 on: April 12, 2017, 07:39:21 pm »
png,gif or jpg?

For some parts of the source code the user should not be able to edit it as it is generated by a wizzard.
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 5691
    • wiki
Re: Preventing editing of several line ranges
« Reply #3 on: April 12, 2017, 08:01:01 pm »
I am afraid there is no single place....

For keyboard actions: http://forum.lazarus-ide.org/index.php/topic,35592.msg243316

For mouse actions (drag and drop edit / or whatever mouse actions you may have defined):
You need to dig into the code handling mouse actions.

For actions from menus, etc; Such as Paste (note that menu shortcuts, trigger the menu, not the keyboard): If they go through the CommandHandler => good, otherwise you need to handle in your code.

-------------------------------
Alternative you can write a subclass of TSynEditStringsLinked (need to subclass SynEdit to register it...)
And then hook all of (might be more in future versions)
Code: Pascal  [Select]
  1.     procedure EditInsert(LogX, LogY: Integer; AText: String); virtual; abstract;
  2.     function  EditDelete(LogX, LogY, ByteLen: Integer): String; virtual; abstract;
  3.     function  EditReplace(LogX, LogY, ByteLen: Integer; AText: String): String; virtual; abstract;
  4.     procedure EditLineBreak(LogX, LogY: Integer); virtual; abstract;
  5.     procedure EditLineJoin(LogY: Integer; FillText: String = ''); virtual; abstract;
  6.     procedure EditLinesInsert(LogY, ACount: Integer; AText: String = ''); virtual; abstract;
  7.     procedure EditLinesDelete(LogY, ACount: Integer); virtual; abstract;
  8.  
All editing goes through there. But that may include your programmatic edits (use a flag to indicate).

------------------------
As for storing info on per line base (read only flag).
See TSynEditStringTabData in TSynEditStringTabExpander

This gets auto adjusted if lines are inserted/removed. But you must take care of initializing new lines:
AddChangeHandler(senrLineCount, @LineCountChanged);

---
This will create one flag per line. A lot of data. If you need only 1 or 2 blocks, then store the begin/end of each block, and use the linecount changed hook to update the info.

---
If you use "shared" editors (clone window), you may need senrTextBufferChanged, since hooks are on the text buffer.

---------------------
Note:
All changes go into the undo system.
if you make changes in the protected lines, they must be part of the undo system. Or the undo system will fail.
And therefore if user actions are to be undone, so must be changes in your block.

---
Well to be precise (but that is implementation detail specific, and may break):
If you make changes that do not affect other x/y positions, then you could currently bypass the undo system (edit lines, without using EditReplace and co)

Background (again implementation specific, may change without warning).
Undo/Redo saves the absolute position(x/y) where a change was. If then another change adds/remove lines before (or chars on the same line, changing the x), then that other change must be undone first, or the undo will not work as expected.



msch

  • New member
  • *
  • Posts: 6
Re: Preventing editing of several line ranges
« Reply #4 on: April 24, 2017, 09:53:45 pm »

Welle, you could Set in first Col in the Line a lockchar perhaps an ANSI 255, specialspace Charakter. Now you look in the Key press event if in the actual line is the Lockchar in Position 0. In this case you prevent the Key Events from inserting the typed char.

Pascal

  • Hero Member
  • *****
  • Posts: 832
Re: Preventing editing of several line ranges
« Reply #5 on: April 26, 2017, 01:35:55 pm »
Well,  there are not just Key events.
Think of paste and paste into selections. Not that easy.
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)