Created
August 13, 2017 05:08
-
-
Save desiderantes/a73da8b8068455a2696e7b7d24dd5378 to your computer and use it in GitHub Desktop.
Emit custom notify in Vala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using GLib; | |
public class TestClass : GLib.Object { | |
public string test1 {get;set;default = "test1";} | |
//Ths one won't emit on assignment | |
[CCode (notify = false)] | |
public string test2 {get;set;default = "test2";} | |
public static void main (string[] args) { | |
var test = new TestClass (); | |
test.notify["test1"].connect (() => GLib.print ("test1 notification\n")); | |
test.notify["test2"].connect (() => GLib.print ("test2 notification\n")); | |
test.test1 = "Ahoy"; | |
test.test2 = "Újale"; | |
test.test2 = "Ajúa"; | |
ParamSpec pspec = ((ObjectClass) typeof (TestClass).class_ref ()).find_property ("test2"); | |
GLib.print ("First try, will not work %s\n", pspec.name); | |
test.notify(pspec); | |
GLib.print ("second one, this is how it works"); | |
test.notify["test2"] (pspec); | |
return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot. I didn't know this is possible and I used it to implement notifications on a derived property (no setter).