{"action":"created","comment":{"url":"https://api.github.com/repos/theia-ide/theia/pulls/comments/149631622","pull_request_review_id":75053553,"id":149631622,"diff_hunk":"@@ -0,0 +1,115 @@\n+/*\n+ * Copyright (C) 2017 TypeFox and others.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0\n+ */\n+\n+import { Widget } from '@phosphor/widgets';\n+import { Message } from '@phosphor/messaging';\n+import { Event, MaybePromise, Key } from '../common';\n+import { AbstractDialog } from './dialogs';\n+\n+export interface Saveable {\n+    readonly dirty: boolean;\n+    readonly onDirtyChanged: Event<void>;\n+    save(): MaybePromise<void>;\n+}\n+\n+export interface SaveableSource {\n+    readonly saveable: Saveable;\n+}\n+\n+export namespace Saveable {\n+    export function isSource(arg: any): arg is SaveableSource {\n+        return !!arg && ('saveable' in arg);\n+    }\n+    export function is(arg: any): arg is Saveable {\n+        return !!arg && ('dirty' in arg) && ('onDirtyChanged' in arg);\n+    }\n+    export function get(arg: any): Saveable | undefined {\n+        if (is(arg)) {\n+            return arg;\n+        }\n+        if (isSource(arg)) {\n+            return arg.saveable;\n+        }\n+    }\n+    export function getDirty(arg: any): Saveable | undefined {\n+        const saveable = get(arg);\n+        if (saveable && saveable.dirty) {\n+            return saveable;\n+        }\n+    }\n+    export function isDirty(arg: any): boolean {\n+        return !!getDirty(arg);\n+    }\n+    export async function save(arg: any): Promise<void> {\n+        const saveable = getDirty(arg);\n+        if (saveable) {\n+            await saveable.save();\n+        }\n+    }\n+    export function apply(widget: Widget): void {\n+        const saveable = Saveable.get(widget);\n+        if (saveable) {\n+            setDirty(widget, saveable.dirty);\n+            saveable.onDirtyChanged(() => setDirty(widget, saveable.dirty));\n+\n+            const close = widget.close.bind(widget);\n+            widget.close = async () => {\n+                if (saveable.dirty) {\n+                    const dialog = new ShouldSaveDialog(widget);\n+                    if (await dialog.open()) {\n+                        await Saveable.save(widget);\n+                    }\n+                }\n+                close();\n+            };\n+        }\n+    }\n+}\n+\n+/**\n+ * The class name added to the dirty widget's title.\n+ */\n+const DIRTY_CLASS = 'theia-mod-dirty';\n+export function setDirty(widget: Widget, dirty: boolean): void {\n+    const dirtyClass = ` ${DIRTY_CLASS}`;\n+    widget.title.className = widget.title.className.replace(dirtyClass, '');\n+    if (dirty) {\n+        widget.title.className += dirtyClass;\n+    }\n+}\n+\n+export class ShouldSaveDialog extends AbstractDialog<boolean> {\n+\n+    protected readonly dontSaveButton: HTMLButtonElement;\n+\n+    constructor(widget: Widget) {\n+        super({\n+            title: `Do you want to save the changes you made to ${widget.title.label || widget.title.caption}?`\n+        });\n+\n+        const messageNode = document.createElement(\"div\");\n+        messageNode.textContent = \"Your change will be lost if you don't save them.\";\n+        messageNode.setAttribute('style', 'flex: 1 100%; padding-bottom: calc(var(--theia-ui-padding)*3);');\n+        this.contentNode.appendChild(messageNode);\n+        this.contentNode.appendChild(this.dontSaveButton = this.createButton(\"Don't Save\"));\n+        this.appendCloseButton();\n+        this.appendAcceptButton('Save');\n+    }\n+\n+    protected onAfterAttach(msg: Message): void {\n+        super.onAfterAttach(msg);\n+        this.addKeyListener(this.dontSaveButton, Key.ENTER, () => {\n+            this.shouldSave = false;\n+            this.accept();\n+        }, 'click');\n+    }\n+\n+    protected shouldSave = true;","path":"packages/core/src/browser/saveable.ts","position":111,"original_position":111,"commit_id":"c61c7d6fbb0d6944ffc06eb5202e3e8b1fd9bec0","original_commit_id":"c61c7d6fbb0d6944ffc06eb5202e3e8b1fd9bec0","user":{"login":"kittaakos","id":1405703,"avatar_url":"https://avatars3.githubusercontent.com/u/1405703?v=4","gravatar_id":"","url":"https://api.github.com/users/kittaakos","html_url":"https://github.com/kittaakos","followers_url":"https://api.github.com/users/kittaakos/followers","following_url":"https://api.github.com/users/kittaakos/following{/other_user}","gists_url":"https://api.github.com/users/kittaakos/gists{/gist_id}","starred_url":"https://api.github.com/users/kittaakos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kittaakos/subscriptions","organizations_url":"https://api.github.com/users/kittaakos/orgs","repos_url":"https://api.github.com/users/kittaakos/repos","events_url":"https://api.github.com/users/kittaakos/events{/privacy}","received_events_url":"https://api.github.com/users/kittaakos/received_events","type":"User","site_admin":false},"body":"Please move this up, next to the `dontSaveButton`. It would be better to see them together.","created_at":"2017-11-08T10:38:26Z","updated_at":"2017-11-08T10:38:26Z","html_url":"https://github.com/theia-ide/theia/pull/798#discussion_r149631622","pull_request_url":"https://api.github.com/repos/theia-ide/theia/pulls/798","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/theia-ide/theia/pulls/comments/149631622"},"html":{"href":"https://github.com/theia-ide/theia/pull/798#discussion_r149631622"},"pull_request":{"href":"https://api.github.com/repos/theia-ide/theia/pulls/798"}}},"pull_request":{"url":"https://api.github.com/repos/theia-ide/theia/pulls/798","id":151294347,"html_url":"https://github.com/theia-ide/theia/pull/798","diff_url":"https://github.com/theia-ide/theia/pull/798.diff","patch_url":"https://github.com/theia-ide/theia/pull/798.patch","issue_url":"https://api.github.com/repos/theia-ide/theia/issues/798","number":798,"state":"open","locked":false,"title":"Save cycle","user":{"login":"akosyakov","id":3082655,"avatar_url":"https://avatars2.githubusercontent.com/u/3082655?v=4","gravatar_id":"","url":"https://api.github.com/users/akosyakov","html_url":"https://github.com/akosyakov","followers_url":"https://api.github.com/users/akosyakov/followers","following_url":"https://api.github.com/users/akosyakov/following{/other_user}","gists_url":"https://api.github.com/users/akosyakov/gists{/gist_id}","starred_url":"https://api.github.com/users/akosyakov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akosyakov/subscriptions","organizations_url":"https://api.github.com/users/akosyakov/orgs","repos_url":"https://api.github.com/users/akosyakov/repos","events_url":"https://api.github.com/users/akosyakov/events{/privacy}","received_events_url":"https://api.github.com/users/akosyakov/received_events","type":"User","site_admin":false},"body":"Fixes #209","created_at":"2017-11-08T05:04:04Z","updated_at":"2017-11-08T10:38:26Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e49ecc00c3df9ccf515746655c178088e4fba1e9","assignee":null,"assignees":[],"requested_reviewers":[{"login":"hexa00","id":698076,"avatar_url":"https://avatars2.githubusercontent.com/u/698076?v=4","gravatar_id":"","url":"https://api.github.com/users/hexa00","html_url":"https://github.com/hexa00","followers_url":"https://api.github.com/users/hexa00/followers","following_url":"https://api.github.com/users/hexa00/following{/other_user}","gists_url":"https://api.github.com/users/hexa00/gists{/gist_id}","starred_url":"https://api.github.com/users/hexa00/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hexa00/subscriptions","organizations_url":"https://api.github.com/users/hexa00/orgs","repos_url":"https://api.github.com/users/hexa00/repos","events_url":"https://api.github.com/users/hexa00/events{/privacy}","received_events_url":"https://api.github.com/users/hexa00/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/theia-ide/theia/pulls/798/commits","review_comments_url":"https://api.github.com/repos/theia-ide/theia/pulls/798/comments","review_comment_url":"https://api.github.com/repos/theia-ide/theia/pulls/comments{/number}","comments_url":"https://api.github.com/repos/theia-ide/theia/issues/798/comments","statuses_url":"https://api.github.com/repos/theia-ide/theia/statuses/c61c7d6fbb0d6944ffc06eb5202e3e8b1fd9bec0","head":{"label":"theia-ide:ak/save_cycle","ref":"ak/save_cycle","sha":"c61c7d6fbb0d6944ffc06eb5202e3e8b1fd9bec0","user":{"login":"theia-ide","id":28530323,"avatar_url":"https://avatars1.githubusercontent.com/u/28530323?v=4","gravatar_id":"","url":"https://api.github.com/users/theia-ide","html_url":"https://github.com/theia-ide","followers_url":"https://api.github.com/users/theia-ide/followers","following_url":"https://api.github.com/users/theia-ide/following{/other_user}","gists_url":"https://api.github.com/users/theia-ide/gists{/gist_id}","starred_url":"https://api.github.com/users/theia-ide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theia-ide/subscriptions","organizations_url":"https://api.github.com/users/theia-ide/orgs","repos_url":"https://api.github.com/users/theia-ide/repos","events_url":"https://api.github.com/users/theia-ide/events{/privacy}","received_events_url":"https://api.github.com/users/theia-ide/received_events","type":"Organization","site_admin":false},"repo":{"id":83050680,"name":"theia","full_name":"theia-ide/theia","owner":{"login":"theia-ide","id":28530323,"avatar_url":"https://avatars1.githubusercontent.com/u/28530323?v=4","gravatar_id":"","url":"https://api.github.com/users/theia-ide","html_url":"https://github.com/theia-ide","followers_url":"https://api.github.com/users/theia-ide/followers","following_url":"https://api.github.com/users/theia-ide/following{/other_user}","gists_url":"https://api.github.com/users/theia-ide/gists{/gist_id}","starred_url":"https://api.github.com/users/theia-ide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theia-ide/subscriptions","organizations_url":"https://api.github.com/users/theia-ide/orgs","repos_url":"https://api.github.com/users/theia-ide/repos","events_url":"https://api.github.com/users/theia-ide/events{/privacy}","received_events_url":"https://api.github.com/users/theia-ide/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/theia-ide/theia","description":"Theia is a cloud & desktop IDE framework implemented in TypeScript.","fork":false,"url":"https://api.github.com/repos/theia-ide/theia","forks_url":"https://api.github.com/repos/theia-ide/theia/forks","keys_url":"https://api.github.com/repos/theia-ide/theia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/theia-ide/theia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/theia-ide/theia/teams","hooks_url":"https://api.github.com/repos/theia-ide/theia/hooks","issue_events_url":"https://api.github.com/repos/theia-ide/theia/issues/events{/number}","events_url":"https://api.github.com/repos/theia-ide/theia/events","assignees_url":"https://api.github.com/repos/theia-ide/theia/assignees{/user}","branches_url":"https://api.github.com/repos/theia-ide/theia/branches{/branch}","tags_url":"https://api.github.com/repos/theia-ide/theia/tags","blobs_url":"https://api.github.com/repos/theia-ide/theia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/theia-ide/theia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/theia-ide/theia/git/refs{/sha}","trees_url":"https://api.github.com/repos/theia-ide/theia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/theia-ide/theia/statuses/{sha}","languages_url":"https://api.github.com/repos/theia-ide/theia/languages","stargazers_url":"https://api.github.com/repos/theia-ide/theia/stargazers","contributors_url":"https://api.github.com/repos/theia-ide/theia/contributors","subscribers_url":"https://api.github.com/repos/theia-ide/theia/subscribers","subscription_url":"https://api.github.com/repos/theia-ide/theia/subscription","commits_url":"https://api.github.com/repos/theia-ide/theia/commits{/sha}","git_commits_url":"https://api.github.com/repos/theia-ide/theia/git/commits{/sha}","comments_url":"https://api.github.com/repos/theia-ide/theia/comments{/number}","issue_comment_url":"https://api.github.com/repos/theia-ide/theia/issues/comments{/number}","contents_url":"https://api.github.com/repos/theia-ide/theia/contents/{+path}","compare_url":"https://api.github.com/repos/theia-ide/theia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/theia-ide/theia/merges","archive_url":"https://api.github.com/repos/theia-ide/theia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/theia-ide/theia/downloads","issues_url":"https://api.github.com/repos/theia-ide/theia/issues{/number}","pulls_url":"https://api.github.com/repos/theia-ide/theia/pulls{/number}","milestones_url":"https://api.github.com/repos/theia-ide/theia/milestones{/number}","notifications_url":"https://api.github.com/repos/theia-ide/theia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/theia-ide/theia/labels{/name}","releases_url":"https://api.github.com/repos/theia-ide/theia/releases{/id}","deployments_url":"https://api.github.com/repos/theia-ide/theia/deployments","created_at":"2017-02-24T14:42:05Z","updated_at":"2017-11-08T07:47:54Z","pushed_at":"2017-11-08T09:50:49Z","git_url":"git://github.com/theia-ide/theia.git","ssh_url":"git@github.com:theia-ide/theia.git","clone_url":"https://github.com/theia-ide/theia.git","svn_url":"https://github.com/theia-ide/theia","homepage":"","size":34112,"stargazers_count":286,"watchers_count":286,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":56,"mirror_url":null,"archived":false,"open_issues_count":202,"forks":56,"open_issues":202,"watchers":286,"default_branch":"master"}},"base":{"label":"theia-ide:master","ref":"master","sha":"1ef6e7219bc24309eed027dda1da7993748801b1","user":{"login":"theia-ide","id":28530323,"avatar_url":"https://avatars1.githubusercontent.com/u/28530323?v=4","gravatar_id":"","url":"https://api.github.com/users/theia-ide","html_url":"https://github.com/theia-ide","followers_url":"https://api.github.com/users/theia-ide/followers","following_url":"https://api.github.com/users/theia-ide/following{/other_user}","gists_url":"https://api.github.com/users/theia-ide/gists{/gist_id}","starred_url":"https://api.github.com/users/theia-ide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theia-ide/subscriptions","organizations_url":"https://api.github.com/users/theia-ide/orgs","repos_url":"https://api.github.com/users/theia-ide/repos","events_url":"https://api.github.com/users/theia-ide/events{/privacy}","received_events_url":"https://api.github.com/users/theia-ide/received_events","type":"Organization","site_admin":false},"repo":{"id":83050680,"name":"theia","full_name":"theia-ide/theia","owner":{"login":"theia-ide","id":28530323,"avatar_url":"https://avatars1.githubusercontent.com/u/28530323?v=4","gravatar_id":"","url":"https://api.github.com/users/theia-ide","html_url":"https://github.com/theia-ide","followers_url":"https://api.github.com/users/theia-ide/followers","following_url":"https://api.github.com/users/theia-ide/following{/other_user}","gists_url":"https://api.github.com/users/theia-ide/gists{/gist_id}","starred_url":"https://api.github.com/users/theia-ide/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theia-ide/subscriptions","organizations_url":"https://api.github.com/users/theia-ide/orgs","repos_url":"https://api.github.com/users/theia-ide/repos","events_url":"https://api.github.com/users/theia-ide/events{/privacy}","received_events_url":"https://api.github.com/users/theia-ide/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/theia-ide/theia","description":"Theia is a cloud & desktop IDE framework implemented in TypeScript.","fork":false,"url":"https://api.github.com/repos/theia-ide/theia","forks_url":"https://api.github.com/repos/theia-ide/theia/forks","keys_url":"https://api.github.com/repos/theia-ide/theia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/theia-ide/theia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/theia-ide/theia/teams","hooks_url":"https://api.github.com/repos/theia-ide/theia/hooks","issue_events_url":"https://api.github.com/repos/theia-ide/theia/issues/events{/number}","events_url":"https://api.github.com/repos/theia-ide/theia/events","assignees_url":"https://api.github.com/repos/theia-ide/theia/assignees{/user}","branches_url":"https://api.github.com/repos/theia-ide/theia/branches{/branch}","tags_url":"https://api.github.com/repos/theia-ide/theia/tags","blobs_url":"https://api.github.com/repos/theia-ide/theia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/theia-ide/theia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/theia-ide/theia/git/refs{/sha}","trees_url":"https://api.github.com/repos/theia-ide/theia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/theia-ide/theia/statuses/{sha}","languages_url":"https://api.github.com/repos/theia-ide/theia/languages","stargazers_url":"https://api.github.com/repos/theia-ide/theia/stargazers","contributors_url":"https://api.github.com/repos/theia-ide/theia/contributors","subscribers_url":"https://api.github.com/repos/theia-ide/theia/subscribers","subscription_url":"https://api.github.com/repos/theia-ide/theia/subscription","commits_url":"https://api.github.com/repos/theia-ide/theia/commits{/sha}","git_commits_url":"https://api.github.com/repos/theia-ide/theia/git/commits{/sha}","comments_url":"https://api.github.com/repos/theia-ide/theia/comments{/number}","issue_comment_url":"https://api.github.com/repos/theia-ide/theia/issues/comments{/number}","contents_url":"https://api.github.com/repos/theia-ide/theia/contents/{+path}","compare_url":"https://api.github.com/repos/theia-ide/theia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/theia-ide/theia/merges","archive_url":"https://api.github.com/repos/theia-ide/theia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/theia-ide/theia/downloads","issues_url":"https://api.github.com/repos/theia-ide/theia/issues{/number}","pulls_url":"https://api.github.com/repos/theia-ide/theia/pulls{/number}","milestones_url":"https://api.github.com/repos/theia-ide/theia/milestones{/number}","notifications_url":"https://api.github.com/repos/theia-ide/theia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/theia-ide/theia/labels{/name}","releases_url":"https://api.github.com/repos/theia-ide/theia/releases{/id}","deployments_url":"https://api.github.com/repos/theia-ide/theia/deployments","created_at":"2017-02-24T14:42:05Z","updated_at":"2017-11-08T07:47:54Z","pushed_at":"2017-11-08T09:50:49Z","git_url":"git://github.com/theia-ide/theia.git","ssh_url":"git@github.com:theia-ide/theia.git","clone_url":"https://github.com/theia-ide/theia.git","svn_url":"https://github.com/theia-ide/theia","homepage":"","size":34112,"stargazers_count":286,"watchers_count":286,"language":"TypeScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":56,"mirror_url":null,"archived":false,"open_issues_count":202,"forks":56,"open_issues":202,"watchers":286,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/theia-ide/theia/pulls/798"},"html":{"href":"https://github.com/theia-ide/theia/pull/798"},"issue":{"href":"https://api.github.com/repos/theia-ide/theia/issues/798"},"comments":{"href":"https://api.github.com/repos/theia-ide/theia/issues/798/comments"},"review_comments":{"href":"https://api.github.com/repos/theia-ide/theia/pulls/798/comments"},"review_comment":{"href":"https://api.github.com/repos/theia-ide/theia/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/theia-ide/theia/pulls/798/commits"},"statuses":{"href":"https://api.github.com/repos/theia-ide/theia/statuses/c61c7d6fbb0d6944ffc06eb5202e3e8b1fd9bec0"}},"author_association":"OWNER"}}
{"actor":{"display_login":"kittaakos"}}