From 75a5cc1277f1478cec5d7611559df07a60f7c190 Mon Sep 17 00:00:00 2001 From: Tim Robinson Date: Fri, 9 Sep 2016 23:50:59 +0000 Subject: [PATCH] Refactoring Gui --- plugins/c9.ide.watcher/gui.js | 42 ++++++++++++++--------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/plugins/c9.ide.watcher/gui.js b/plugins/c9.ide.watcher/gui.js index 7249cee7..ad216e7a 100644 --- a/plugins/c9.ide.watcher/gui.js +++ b/plugins/c9.ide.watcher/gui.js @@ -82,31 +82,23 @@ define(function(require, exports, module) { }, plugin); } - tabManager.getTabs().forEach(function(tab) { - if (!tab.path) - return; + function initializeTab(tab) { + if (!tab.path) return; if (tab.document.undoManager.isAtBookmark()) { initializeDocument(tab.document); } - else { - console.error("Unsupported state"); - } - if (tab.classList.contains("conflict")) { addChangedTab(tab, comparisonType.TIMESTAMP_AND_CONTENTS); } - }); + } + tabManager.getTabs().forEach(initializeTab); tabManager.on("open", function(e) { - initializeDocument(e.tab.document); - if (e.tab.classList.contains("conflict")) { - addChangedTab(e.tab, comparisonType.TIMESTAMP_AND_CONTENTS); - } + initializeTab(e.tab); }, plugin); // Hook the save of the document value - save.on("beforeSave", function(e) { e.document.meta.$savingValue = e.save; if (e.tab.classList.contains("conflict")) { @@ -178,6 +170,10 @@ define(function(require, exports, module) { delete changedPaths[path]; } + function isTabSaving(tab) { + return tab.document.meta.$saving; + } + function addChangedTab(tab, doubleCheckComparisonType) { // If we already have a dialog open, just update it, but mark the value dirty if (changedPaths[tab.path]) { @@ -188,8 +184,14 @@ define(function(require, exports, module) { } // Ignore changes that come in while tab is being saved - if (tab.document.meta.$saving) { - console.log("[watchers] Watcher fired, but tab is still saving", path); + if (isTabSaving(tab)) return; + + // If the terminal is currently focussed, lets wait until + // another tab is focussed + if (tabManager.focussedTab && tabManager.focussedTab.editorType == "terminal") { + tabManager.once("focus", function(){ + addChangedTab(tab, comparisonType.CONTENTS); + }); return; } @@ -198,16 +200,6 @@ define(function(require, exports, module) { changedPaths[tab.path] = { tab: tab, resolve: resolve }; - // If the terminal is currently focussed, lets wait until - // another tab is focussed - if (tabManager.focussedTab - && tabManager.focussedTab.editorType == "terminal") { - tabManager.once("focus", function(){ - addChangedTab(tab, comparisonType.CONTENTS); - }); - return; - } - function resolve() { if (collabEnabled && collab.send) collab.send({type: "RESOLVE_CONFLICT", data: {docId: path}});