Recent

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

Pascal

  • Hero Member
  • *****
  • Posts: 932
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 x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (21H2)

Thaddy

  • Hero Member
  • *****
  • Posts: 14213
  • Probably until I exterminate Putin.
Re: Preventing editing of several line ranges
« Reply #1 on: April 12, 2017, 06:44:51 pm »
png,gif or jpg?
Specialize a type, not a var.

Pascal

  • Hero Member
  • *****
  • Posts: 932
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 x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (21H2)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • 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: 10
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: 932
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 x64 - fpc trunk i386 (cross x64) - Windows 10 Pro x64 (21H2)

 

TinyPortal © 2005-2018