{"action":"created","comment":{"url":"https://api.github.com/repos/limetext/lime-qml/pulls/comments/74127822","id":74127822,"diff_hunk":"@@ -0,0 +1,93 @@\n+package main\n+\n+import (\n+\t\"fmt\"\n+\n+\t\"github.com/limetext/text\"\n+)\n+\n+type settingsWatcher struct {\n+\tptr             interface{} // pointer to root struct\n+\tsettings        *text.Settings\n+\twatchedSettings map[string]watchedSetting\n+}\n+\n+func newSettingsWatcher(ptr interface{}, settings *text.Settings) *settingsWatcher {\n+\tw := &settingsWatcher{\n+\t\tptr:             ptr,\n+\t\tsettings:        settings,\n+\t\twatchedSettings: make(map[string]watchedSetting),\n+\t}\n+\tsettings.AddOnChange(\"settingsWatcher\", w.onSettingChange)\n+\treturn w\n+}\n+\n+func (w *settingsWatcher) onSettingChange(name string) {\n+\tfmt.Printf(\"SettingChanged: %s %v\\n\", name, w.settings.Get(name))\n+\n+\tif s, ok := w.watchedSettings[name]; ok {\n+\t\ts.setFromSettings(w.ptr, w.settings)\n+\t}\n+}\n+\n+type watchedSetting interface {\n+\tsetFromSettings(ptr interface{}, settings *text.Settings)\n+}\n+\n+func (w *settingsWatcher) watchSettingInt(name string, ptr *int, defaultValue int, mapFn ...func(int) int) {\n+\ts := &watchedSettingInt{\n+\t\tname:         name,\n+\t\tptr:          ptr,\n+\t\tdefaultValue: defaultValue,\n+\t}\n+\tif len(mapFn) == 1 {\n+\t\ts.mapFn = mapFn[0]\n+\t}\n+\tw.watchedSettings[name] = s\n+\ts.setFromSettings(w.ptr, w.settings)\n+}\n+\n+type watchedSettingInt struct {\n+\tname         string\n+\tptr          *int\n+\tdefaultValue int\n+\tmapFn        func(int) int\n+}\n+\n+func (s *watchedSettingInt) setFromSettings(ptr interface{}, settings *text.Settings) {\n+\tcurrent := settings.Int(s.name, s.defaultValue)\n+\tif s.mapFn != nil {\n+\t\tcurrent = s.mapFn(current)\n+\t}\n+\t*s.ptr = current\n+\tfe.qmlChanged(ptr, s.ptr)\n+}\n+\n+func (w *settingsWatcher) watchSettingString(name string, ptr *string, defaultValue string, mapFn ...func(string) string) {","path":"main/settings.go","position":66,"original_position":66,"commit_id":"847b0cfe4eb05d936a92829c53cc5c2ca51f9902","original_commit_id":"847b0cfe4eb05d936a92829c53cc5c2ca51f9902","user":{"login":"zoli","id":3286303,"avatar_url":"https://avatars.githubusercontent.com/u/3286303?v=3","gravatar_id":"","url":"https://api.github.com/users/zoli","html_url":"https://github.com/zoli","followers_url":"https://api.github.com/users/zoli/followers","following_url":"https://api.github.com/users/zoli/following{/other_user}","gists_url":"https://api.github.com/users/zoli/gists{/gist_id}","starred_url":"https://api.github.com/users/zoli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zoli/subscriptions","organizations_url":"https://api.github.com/users/zoli/orgs","repos_url":"https://api.github.com/users/zoli/repos","events_url":"https://api.github.com/users/zoli/events{/privacy}","received_events_url":"https://api.github.com/users/zoli/received_events","type":"User","site_admin":false},"body":"Also watchString for this.","created_at":"2016-08-09T19:26:06Z","updated_at":"2016-08-09T19:26:06Z","html_url":"https://github.com/limetext/lime-qml/pull/42#discussion_r74127822","pull_request_url":"https://api.github.com/repos/limetext/lime-qml/pulls/42","_links":{"self":{"href":"https://api.github.com/repos/limetext/lime-qml/pulls/comments/74127822"},"html":{"href":"https://github.com/limetext/lime-qml/pull/42#discussion_r74127822"},"pull_request":{"href":"https://api.github.com/repos/limetext/lime-qml/pulls/42"}}},"pull_request":{"url":"https://api.github.com/repos/limetext/lime-qml/pulls/42","id":80522214,"html_url":"https://github.com/limetext/lime-qml/pull/42","diff_url":"https://github.com/limetext/lime-qml/pull/42.diff","patch_url":"https://github.com/limetext/lime-qml/pull/42.patch","issue_url":"https://api.github.com/repos/limetext/lime-qml/issues/42","number":42,"state":"open","locked":false,"title":"Move settings watching to Go","user":{"login":"ricochet1k","id":76901,"avatar_url":"https://avatars.githubusercontent.com/u/76901?v=3","gravatar_id":"","url":"https://api.github.com/users/ricochet1k","html_url":"https://github.com/ricochet1k","followers_url":"https://api.github.com/users/ricochet1k/followers","following_url":"https://api.github.com/users/ricochet1k/following{/other_user}","gists_url":"https://api.github.com/users/ricochet1k/gists{/gist_id}","starred_url":"https://api.github.com/users/ricochet1k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ricochet1k/subscriptions","organizations_url":"https://api.github.com/users/ricochet1k/orgs","repos_url":"https://api.github.com/users/ricochet1k/repos","events_url":"https://api.github.com/users/ricochet1k/events{/privacy}","received_events_url":"https://api.github.com/users/ricochet1k/received_events","type":"User","site_admin":false},"body":"Okay, this is the best syntax I can come up with for watching settings. It handles setting default values and updating values when the settings change.","created_at":"2016-08-08T21:07:13Z","updated_at":"2016-08-09T19:26:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5b41574ebbf60d2f82a064e8f6a161b88314b678","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/limetext/lime-qml/pulls/42/commits","review_comments_url":"https://api.github.com/repos/limetext/lime-qml/pulls/42/comments","review_comment_url":"https://api.github.com/repos/limetext/lime-qml/pulls/comments{/number}","comments_url":"https://api.github.com/repos/limetext/lime-qml/issues/42/comments","statuses_url":"https://api.github.com/repos/limetext/lime-qml/statuses/847b0cfe4eb05d936a92829c53cc5c2ca51f9902","head":{"label":"limetext:settings","ref":"settings","sha":"847b0cfe4eb05d936a92829c53cc5c2ca51f9902","user":{"login":"limetext","id":5825890,"avatar_url":"https://avatars.githubusercontent.com/u/5825890?v=3","gravatar_id":"","url":"https://api.github.com/users/limetext","html_url":"https://github.com/limetext","followers_url":"https://api.github.com/users/limetext/followers","following_url":"https://api.github.com/users/limetext/following{/other_user}","gists_url":"https://api.github.com/users/limetext/gists{/gist_id}","starred_url":"https://api.github.com/users/limetext/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/limetext/subscriptions","organizations_url":"https://api.github.com/users/limetext/orgs","repos_url":"https://api.github.com/users/limetext/repos","events_url":"https://api.github.com/users/limetext/events{/privacy}","received_events_url":"https://api.github.com/users/limetext/received_events","type":"Organization","site_admin":false},"repo":{"id":34583941,"name":"lime-qml","full_name":"limetext/lime-qml","owner":{"login":"limetext","id":5825890,"avatar_url":"https://avatars.githubusercontent.com/u/5825890?v=3","gravatar_id":"","url":"https://api.github.com/users/limetext","html_url":"https://github.com/limetext","followers_url":"https://api.github.com/users/limetext/followers","following_url":"https://api.github.com/users/limetext/following{/other_user}","gists_url":"https://api.github.com/users/limetext/gists{/gist_id}","starred_url":"https://api.github.com/users/limetext/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/limetext/subscriptions","organizations_url":"https://api.github.com/users/limetext/orgs","repos_url":"https://api.github.com/users/limetext/repos","events_url":"https://api.github.com/users/limetext/events{/privacy}","received_events_url":"https://api.github.com/users/limetext/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/limetext/lime-qml","description":"QML frontend for Lime","fork":false,"url":"https://api.github.com/repos/limetext/lime-qml","forks_url":"https://api.github.com/repos/limetext/lime-qml/forks","keys_url":"https://api.github.com/repos/limetext/lime-qml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/limetext/lime-qml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/limetext/lime-qml/teams","hooks_url":"https://api.github.com/repos/limetext/lime-qml/hooks","issue_events_url":"https://api.github.com/repos/limetext/lime-qml/issues/events{/number}","events_url":"https://api.github.com/repos/limetext/lime-qml/events","assignees_url":"https://api.github.com/repos/limetext/lime-qml/assignees{/user}","branches_url":"https://api.github.com/repos/limetext/lime-qml/branches{/branch}","tags_url":"https://api.github.com/repos/limetext/lime-qml/tags","blobs_url":"https://api.github.com/repos/limetext/lime-qml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/limetext/lime-qml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/limetext/lime-qml/git/refs{/sha}","trees_url":"https://api.github.com/repos/limetext/lime-qml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/limetext/lime-qml/statuses/{sha}","languages_url":"https://api.github.com/repos/limetext/lime-qml/languages","stargazers_url":"https://api.github.com/repos/limetext/lime-qml/stargazers","contributors_url":"https://api.github.com/repos/limetext/lime-qml/contributors","subscribers_url":"https://api.github.com/repos/limetext/lime-qml/subscribers","subscription_url":"https://api.github.com/repos/limetext/lime-qml/subscription","commits_url":"https://api.github.com/repos/limetext/lime-qml/commits{/sha}","git_commits_url":"https://api.github.com/repos/limetext/lime-qml/git/commits{/sha}","comments_url":"https://api.github.com/repos/limetext/lime-qml/comments{/number}","issue_comment_url":"https://api.github.com/repos/limetext/lime-qml/issues/comments{/number}","contents_url":"https://api.github.com/repos/limetext/lime-qml/contents/{+path}","compare_url":"https://api.github.com/repos/limetext/lime-qml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/limetext/lime-qml/merges","archive_url":"https://api.github.com/repos/limetext/lime-qml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/limetext/lime-qml/downloads","issues_url":"https://api.github.com/repos/limetext/lime-qml/issues{/number}","pulls_url":"https://api.github.com/repos/limetext/lime-qml/pulls{/number}","milestones_url":"https://api.github.com/repos/limetext/lime-qml/milestones{/number}","notifications_url":"https://api.github.com/repos/limetext/lime-qml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/limetext/lime-qml/labels{/name}","releases_url":"https://api.github.com/repos/limetext/lime-qml/releases{/id}","deployments_url":"https://api.github.com/repos/limetext/lime-qml/deployments","created_at":"2015-04-25T20:00:29Z","updated_at":"2016-07-27T06:13:56Z","pushed_at":"2016-08-09T17:11:28Z","git_url":"git://github.com/limetext/lime-qml.git","ssh_url":"git@github.com:limetext/lime-qml.git","clone_url":"https://github.com/limetext/lime-qml.git","svn_url":"https://github.com/limetext/lime-qml","homepage":"http://limetext.org","size":219,"stargazers_count":62,"watchers_count":62,"language":"QML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":13,"forks":18,"open_issues":13,"watchers":62,"default_branch":"master"}},"base":{"label":"limetext:master","ref":"master","sha":"b379b3fe51da89c3256c3f1147faa0be87a0e7ef","user":{"login":"limetext","id":5825890,"avatar_url":"https://avatars.githubusercontent.com/u/5825890?v=3","gravatar_id":"","url":"https://api.github.com/users/limetext","html_url":"https://github.com/limetext","followers_url":"https://api.github.com/users/limetext/followers","following_url":"https://api.github.com/users/limetext/following{/other_user}","gists_url":"https://api.github.com/users/limetext/gists{/gist_id}","starred_url":"https://api.github.com/users/limetext/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/limetext/subscriptions","organizations_url":"https://api.github.com/users/limetext/orgs","repos_url":"https://api.github.com/users/limetext/repos","events_url":"https://api.github.com/users/limetext/events{/privacy}","received_events_url":"https://api.github.com/users/limetext/received_events","type":"Organization","site_admin":false},"repo":{"id":34583941,"name":"lime-qml","full_name":"limetext/lime-qml","owner":{"login":"limetext","id":5825890,"avatar_url":"https://avatars.githubusercontent.com/u/5825890?v=3","gravatar_id":"","url":"https://api.github.com/users/limetext","html_url":"https://github.com/limetext","followers_url":"https://api.github.com/users/limetext/followers","following_url":"https://api.github.com/users/limetext/following{/other_user}","gists_url":"https://api.github.com/users/limetext/gists{/gist_id}","starred_url":"https://api.github.com/users/limetext/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/limetext/subscriptions","organizations_url":"https://api.github.com/users/limetext/orgs","repos_url":"https://api.github.com/users/limetext/repos","events_url":"https://api.github.com/users/limetext/events{/privacy}","received_events_url":"https://api.github.com/users/limetext/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/limetext/lime-qml","description":"QML frontend for Lime","fork":false,"url":"https://api.github.com/repos/limetext/lime-qml","forks_url":"https://api.github.com/repos/limetext/lime-qml/forks","keys_url":"https://api.github.com/repos/limetext/lime-qml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/limetext/lime-qml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/limetext/lime-qml/teams","hooks_url":"https://api.github.com/repos/limetext/lime-qml/hooks","issue_events_url":"https://api.github.com/repos/limetext/lime-qml/issues/events{/number}","events_url":"https://api.github.com/repos/limetext/lime-qml/events","assignees_url":"https://api.github.com/repos/limetext/lime-qml/assignees{/user}","branches_url":"https://api.github.com/repos/limetext/lime-qml/branches{/branch}","tags_url":"https://api.github.com/repos/limetext/lime-qml/tags","blobs_url":"https://api.github.com/repos/limetext/lime-qml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/limetext/lime-qml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/limetext/lime-qml/git/refs{/sha}","trees_url":"https://api.github.com/repos/limetext/lime-qml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/limetext/lime-qml/statuses/{sha}","languages_url":"https://api.github.com/repos/limetext/lime-qml/languages","stargazers_url":"https://api.github.com/repos/limetext/lime-qml/stargazers","contributors_url":"https://api.github.com/repos/limetext/lime-qml/contributors","subscribers_url":"https://api.github.com/repos/limetext/lime-qml/subscribers","subscription_url":"https://api.github.com/repos/limetext/lime-qml/subscription","commits_url":"https://api.github.com/repos/limetext/lime-qml/commits{/sha}","git_commits_url":"https://api.github.com/repos/limetext/lime-qml/git/commits{/sha}","comments_url":"https://api.github.com/repos/limetext/lime-qml/comments{/number}","issue_comment_url":"https://api.github.com/repos/limetext/lime-qml/issues/comments{/number}","contents_url":"https://api.github.com/repos/limetext/lime-qml/contents/{+path}","compare_url":"https://api.github.com/repos/limetext/lime-qml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/limetext/lime-qml/merges","archive_url":"https://api.github.com/repos/limetext/lime-qml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/limetext/lime-qml/downloads","issues_url":"https://api.github.com/repos/limetext/lime-qml/issues{/number}","pulls_url":"https://api.github.com/repos/limetext/lime-qml/pulls{/number}","milestones_url":"https://api.github.com/repos/limetext/lime-qml/milestones{/number}","notifications_url":"https://api.github.com/repos/limetext/lime-qml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/limetext/lime-qml/labels{/name}","releases_url":"https://api.github.com/repos/limetext/lime-qml/releases{/id}","deployments_url":"https://api.github.com/repos/limetext/lime-qml/deployments","created_at":"2015-04-25T20:00:29Z","updated_at":"2016-07-27T06:13:56Z","pushed_at":"2016-08-09T17:11:28Z","git_url":"git://github.com/limetext/lime-qml.git","ssh_url":"git@github.com:limetext/lime-qml.git","clone_url":"https://github.com/limetext/lime-qml.git","svn_url":"https://github.com/limetext/lime-qml","homepage":"http://limetext.org","size":219,"stargazers_count":62,"watchers_count":62,"language":"QML","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":13,"forks":18,"open_issues":13,"watchers":62,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/limetext/lime-qml/pulls/42"},"html":{"href":"https://github.com/limetext/lime-qml/pull/42"},"issue":{"href":"https://api.github.com/repos/limetext/lime-qml/issues/42"},"comments":{"href":"https://api.github.com/repos/limetext/lime-qml/issues/42/comments"},"review_comments":{"href":"https://api.github.com/repos/limetext/lime-qml/pulls/42/comments"},"review_comment":{"href":"https://api.github.com/repos/limetext/lime-qml/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/limetext/lime-qml/pulls/42/commits"},"statuses":{"href":"https://api.github.com/repos/limetext/lime-qml/statuses/847b0cfe4eb05d936a92829c53cc5c2ca51f9902"}}}}
{"actor":{"display_login":"zoli"}}