Texteditor haschange

Discuss GUI programming with the MUI Royale plugin here
Post Reply
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

Texteditor haschange

Post by lazi »

Please help me on how to get every changes from a texteditor?
Here is my example script where only the first keypress in the texteditor triggers "haschanged" event.

Code: Select all

@REQUIRE "muiroyale.hwp"
@DISPLAY {hidden=True}

Function p_EventFunc(msg)
	DebugPrint(msg.class,msg.id,msg.attribute)
	If msg.class="Window" Then End
EndFunction

mainwindow=[[
<?xml version="1.0" encoding="utf-8"?>
<application id="TextCraft" base="TextCraft">

<window AppWindow="true" id="win" title="TextCraft" muiid="MAIN" notify="closerequest; appmessage" sizegadget="True">
	<vgroup>
		<texteditor id="editor"/>
	</vgroup>
</window>
</application>
]]
mui.CreateGui(mainwindow)

InstallEventHandler({MUIRoyale = p_EventFunc})

mui.notify("editor","haschanged",True)

Repeat
	WaitEvent
Forever
Texteditor.mcp 15.48
muimaster.library 21.79 (nightly build)
OS4
PEB
Posts: 567
Joined: Sun Feb 21, 2010 1:28 am

Re: Texteditor haschange

Post by PEB »

"UndoAvailable" works better with Amigas. ("HasChanged" works better with Windows.)
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Texteditor haschange

Post by airsoftsoftwair »

TextEditor.HasChanged really seems to behave differently on MUI and Windows. On Windows it triggers for every character that changes, on MUI only for the first change. Now the question is which is the better behaviour: Should it trigger just once or for every character that changes? Triggering for every character can be a huge waste of CPU cycles of course so I'm not sure whether this is the best behaviour.

Both lazi and PEB seem to need such a behaviour, though, so maybe you can describe why exactly you want to be notified for every character that changes? I currently can't think of a situation in which such a behaviour is necessary so please elaborate...
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

Re: Texteditor haschange

Post by lazi »

My current need of haschanged is very simple. I want to know if the content is changed after opening or after last save operation.
I got a notify on the first change and after saving the content this changed state should be cleared somehow to look for the next change.
So there is no need to get every change if I can reset the changed state manually.

According to the notify on every keypress, I can imagine an editor like the good old Amos editor which was formatted the line or comand after every space or enter keypress.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Texteditor haschange

Post by airsoftsoftwair »

lazi wrote:My current need of haschanged is very simple. I want to know if the content is changed after opening or after last save operation.
I got a notify on the first change and after saving the content this changed state should be cleared somehow to look for the next change.
So there is no need to get every change if I can reset the changed state manually.
Hmm, now I'm confused. So why did you ask how to get a notification for every key press? :)
According to the notify on every keypress, I can imagine an editor like the good old Amos editor which was formatted the line or comand after every space or enter keypress.
That's true but implementing syntax highlighting is far too advanced for RapaGUI's text editor class. This will lead to trouble. We'd need a platform-independent, more flexible engine like Scintilla for that.
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

Re: Texteditor haschange

Post by lazi »

Hmm, now I'm confused. So why did you ask how to get a notification for every key press?
Did I ask it? :)
When I was not able to solve the problem just got the idea that squeezing every changes from the gadget will give a solution. And if one thinks too much in the bad direction can't leave it easily :)

And what do you say? Have you found a good idea for this particular problem?
It is surely a tough task to foresee how evil things the users will do and call it programming :)

Ok forget about the requirements of syntax highlighting. Scintilla is really far better for code editing than current texteditor.mcp.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Texteditor haschange

Post by airsoftsoftwair »

I think I know now why the different behaviour could be a problem: When using the TextEditor.hws example on Amiga, you'll only get one "HasChanged" notification. This leads to the problem that if you modify the text after having saved it, there'll be no more "HasChanged" notifications which is indeed a problem. On Windows, Linux, and Mac OS this isn't a problem because the "HasChanged" events will be generated for every change. That's why I have fixed RapaGUI now to use the same behaviour on AmigaOS too.

Code: Select all

- Fix [Amiga]: TextEditor.HasChanged triggers for every change now, not only for the first one; this
  makes the Amiga version consistent to the behaviour of the Windows, Linux, and Mac OS versions of
  RapaGUI; requires TextEditor.mcc 15.48 or better
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

Re: Texteditor haschange

Post by lazi »

Hmmm. But what about MUIRoyale? :)
As I said it should not notify on every keypress.
But what is it good for if only the first keypress is notified?
The best way IMHO would be the ability to reset the modified state.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Texteditor haschange

Post by airsoftsoftwair »

lazi wrote:Hmmm. But what about MUIRoyale? :)
As I said it should not notify on every keypress.
But what is it good for if only the first keypress is notified?
The best way IMHO would be the ability to reset the modified state.
That's already possible. Just reset it manually and you'll get a new notification on the next keypress, i.e. do something like this:

Code: Select all

Switch msg.action
Case "MUIRoyale":
	Switch msg.attribute
	Case "HasChanged":
		mui.set("editor", "nonotify", True, "haschanged", False)
	EndSwitch
EndSwitch
But make sure to use TextEditor 15.48 from here: http://www.airsoftsoftwair.de/binary/tm ... -15.48.lha
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

Re: Texteditor haschange

Post by lazi »

Ohh, thanks!

I forgot "nonotify", True.

No more problem here, please break it up! Nothing to see here. :)
Post Reply