Title: [144598] trunk/Source/WebCore
Revision
144598
Author
[email protected]
Date
2013-03-03 22:53:18 -0800 (Sun, 03 Mar 2013)

Log Message

Web Inspector: Let user know when file system based uiSourceCode was changed on disk.
https://bugs.webkit.org/show_bug.cgi?id=110133

Reviewed by Pavel Feldman.

We now check if file system based uiSourceCode content was updated externally when
UISourceCodeFrame is shown or inspector window is focused.
If there is no working copy being edited right now we replace old content with the new one silently.
Otherwise ask user if he wants to replace his working copy with the new content.

* English.lproj/localizedStrings.js:
* WebCore.vcproj/WebCore.vcproj:
* inspector/front-end/DefaultTextEditor.js:
(WebInspector.DefaultTextEditor.prototype.editRange):
* inspector/front-end/FileSystemProjectDelegate.js:
(WebInspector.FileSystemProjectDelegate.prototype.innerCallback):
(WebInspector.FileSystemProjectDelegate.prototype.requestFileContent):
(WebInspector.FileSystemProjectDelegate.prototype._contentRequestFinished):
(WebInspector.FileSystemProjectDelegate.prototype.requestUpdatedFileContent):
(WebInspector.FileSystemProjectDelegate.prototype.contentCallback):
(WebInspector.FileSystemProjectDelegate.prototype.searchInFileContent):
* inspector/front-end/_javascript_SourceFrame.js:
(WebInspector._javascript_SourceFrame.prototype.wasShown):
(WebInspector._javascript_SourceFrame.prototype.willHide):
* inspector/front-end/SimpleWorkspaceProvider.js:
(WebInspector.SimpleProjectDelegate.prototype.requestUpdatedFileContent):
* inspector/front-end/SourceFrame.js:
(WebInspector.SourceFrame.prototype.setContent):
* inspector/front-end/UISourceCode.js:
(WebInspector.UISourceCode.prototype.checkContentUpdated.updatedContentLoaded):
(WebInspector.UISourceCode.prototype.checkContentUpdated):
* inspector/front-end/UISourceCodeFrame.js:
(WebInspector.UISourceCodeFrame.prototype.wasShown):
(WebInspector.UISourceCodeFrame.prototype.willHide):
(WebInspector.UISourceCodeFrame.prototype._windowFocused):
(WebInspector.UISourceCodeFrame.prototype._checkContentUpdated):
* inspector/front-end/Workspace.js:
(WebInspector.ProjectDelegate.prototype.requestUpdatedFileContent):
(WebInspector.Project.prototype.requestUpdatedFileContent):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (144597 => 144598)


--- trunk/Source/WebCore/ChangeLog	2013-03-04 06:34:20 UTC (rev 144597)
+++ trunk/Source/WebCore/ChangeLog	2013-03-04 06:53:18 UTC (rev 144598)
@@ -1,3 +1,45 @@
+2013-03-01  Vsevolod Vlasov  <[email protected]>
+
+        Web Inspector: Let user know when file system based uiSourceCode was changed on disk.
+        https://bugs.webkit.org/show_bug.cgi?id=110133
+
+        Reviewed by Pavel Feldman.
+
+        We now check if file system based uiSourceCode content was updated externally when 
+        UISourceCodeFrame is shown or inspector window is focused.
+        If there is no working copy being edited right now we replace old content with the new one silently.
+        Otherwise ask user if he wants to replace his working copy with the new content.
+
+        * English.lproj/localizedStrings.js:
+        * WebCore.vcproj/WebCore.vcproj:
+        * inspector/front-end/DefaultTextEditor.js:
+        (WebInspector.DefaultTextEditor.prototype.editRange):
+        * inspector/front-end/FileSystemProjectDelegate.js:
+        (WebInspector.FileSystemProjectDelegate.prototype.innerCallback):
+        (WebInspector.FileSystemProjectDelegate.prototype.requestFileContent):
+        (WebInspector.FileSystemProjectDelegate.prototype._contentRequestFinished):
+        (WebInspector.FileSystemProjectDelegate.prototype.requestUpdatedFileContent):
+        (WebInspector.FileSystemProjectDelegate.prototype.contentCallback):
+        (WebInspector.FileSystemProjectDelegate.prototype.searchInFileContent):
+        * inspector/front-end/_javascript_SourceFrame.js:
+        (WebInspector._javascript_SourceFrame.prototype.wasShown):
+        (WebInspector._javascript_SourceFrame.prototype.willHide):
+        * inspector/front-end/SimpleWorkspaceProvider.js:
+        (WebInspector.SimpleProjectDelegate.prototype.requestUpdatedFileContent):
+        * inspector/front-end/SourceFrame.js:
+        (WebInspector.SourceFrame.prototype.setContent):
+        * inspector/front-end/UISourceCode.js:
+        (WebInspector.UISourceCode.prototype.checkContentUpdated.updatedContentLoaded):
+        (WebInspector.UISourceCode.prototype.checkContentUpdated):
+        * inspector/front-end/UISourceCodeFrame.js:
+        (WebInspector.UISourceCodeFrame.prototype.wasShown):
+        (WebInspector.UISourceCodeFrame.prototype.willHide):
+        (WebInspector.UISourceCodeFrame.prototype._windowFocused):
+        (WebInspector.UISourceCodeFrame.prototype._checkContentUpdated):
+        * inspector/front-end/Workspace.js:
+        (WebInspector.ProjectDelegate.prototype.requestUpdatedFileContent):
+        (WebInspector.Project.prototype.requestUpdatedFileContent):
+
 2013-03-03  Arpita Bahuguna  <[email protected]>
 
         createAttribute/setAttributeNode does not properly normalize case

Modified: trunk/Source/WebCore/English.lproj/localizedStrings.js (144597 => 144598)


--- trunk/Source/WebCore/English.lproj/localizedStrings.js	2013-03-04 06:34:20 UTC (rev 144597)
+++ trunk/Source/WebCore/English.lproj/localizedStrings.js	2013-03-04 06:53:18 UTC (rev 144598)
@@ -874,3 +874,4 @@
 localizedStrings["Destroy WebSocket"] = "Destroy WebSocket";
 localizedStrings["Split panels vertically when docked to right"] = "Split panels vertically when docked to right";
 localizedStrings["(no domain)"] = "(no domain)";
+localizedStrings["This file was changed externally. Would you like to reload it?"] = "This file was changed externally. Would you like to reload it?";

Modified: trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js (144597 => 144598)


--- trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js	2013-03-04 06:34:20 UTC (rev 144597)
+++ trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js	2013-03-04 06:53:18 UTC (rev 144598)
@@ -350,7 +350,7 @@
      */
     editRange: function(range, text)
     {
-        return this._textModel.editRange(range, text);
+        return this._textModel.editRange(range, text, this.lastSelection());
     },
 
     _updatePanelOffsets: function()

Modified: trunk/Source/WebCore/inspector/front-end/FileSystemProjectDelegate.js (144597 => 144598)


--- trunk/Source/WebCore/inspector/front-end/FileSystemProjectDelegate.js	2013-03-04 06:34:20 UTC (rev 144597)
+++ trunk/Source/WebCore/inspector/front-end/FileSystemProjectDelegate.js	2013-03-04 06:53:18 UTC (rev 144598)
@@ -91,6 +91,7 @@
          */
         function innerCallback(content)
         {
+            this._contentRequestFinished(path, content);
             var contentType = this._contentTypeForPath(path);
             callback(content, false, contentType.canonicalMimeType());
         }
@@ -98,6 +99,40 @@
 
     /**
      * @param {Array.<string>} path
+     * @param {string} content
+     * @return {string}
+     */
+    _contentRequestFinished: function(path, content)
+    {
+        this._lastContentRequestPath = path;
+        this._lastContentRequestContent = content;
+    },
+
+    /**
+     * @param {Array.<string>} path
+     * @param {string} currentContent
+     * @param {function(?string)} callback
+     */
+    requestUpdatedFileContent: function(path, currentContent, callback)
+    {
+        var filePath = this._filePathForPath(path);
+        this._fileSystem.requestFileContent(filePath, innerCallback.bind(this));
+
+        /**
+         * @param {?string} content
+         */
+        function innerCallback(content)
+        {
+            var previousContent = this._lastContentRequestPath === path ? this._lastContentRequestContent : null;
+            if (typeof previousContent !== "string")
+                previousContent = currentContent;
+            this._contentRequestFinished(path, content);
+            callback(content !== previousContent ? content : null);
+        }
+    },
+
+    /**
+     * @param {Array.<string>} path
      * @param {string} newContent
      * @param {function(?string)} callback
      */
@@ -116,14 +151,13 @@
      */
     searchInFileContent: function(path, query, caseSensitive, isRegex, callback)
     {
-        this.requestFileContent(path, contentCallback.bind(this));
+        var filePath = this._filePathForPath(path);
+        this._fileSystem.requestFileContent(filePath, contentCallback.bind(this));
 
         /**
          * @param {?string} content
-         * @param {boolean} base64Encoded
-         * @param {string} mimeType
          */
-        function contentCallback(content, base64Encoded, mimeType)
+        function contentCallback(content)
         {
             var result = [];
             if (content !== null)

Modified: trunk/Source/WebCore/inspector/front-end/_javascript_SourceFrame.js (144597 => 144598)


--- trunk/Source/WebCore/inspector/front-end/_javascript_SourceFrame.js	2013-03-04 06:34:20 UTC (rev 144597)
+++ trunk/Source/WebCore/inspector/front-end/_javascript_SourceFrame.js	2013-03-04 06:53:18 UTC (rev 144598)
@@ -68,12 +68,12 @@
     // View events
     wasShown: function()
     {
-        WebInspector.SourceFrame.prototype.wasShown.call(this);
+        WebInspector.UISourceCodeFrame.prototype.wasShown.call(this);
     },
 
     willHide: function()
     {
-        WebInspector.SourceFrame.prototype.willHide.call(this);
+        WebInspector.UISourceCodeFrame.prototype.willHide.call(this);
         this._popoverHelper.hidePopover();
     },
 
@@ -110,7 +110,6 @@
 
     populateTextAreaContextMenu: function(contextMenu, lineNumber)
     {
-        WebInspector.SourceFrame.prototype.populateTextAreaContextMenu.call(this, contextMenu, lineNumber);
         var selection = window.getSelection();
         if (selection.type === "Range" && !selection.isCollapsed) {
             var addToWatchLabel = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Add to watch" : "Add to Watch");

Modified: trunk/Source/WebCore/inspector/front-end/SimpleWorkspaceProvider.js (144597 => 144598)


--- trunk/Source/WebCore/inspector/front-end/SimpleWorkspaceProvider.js	2013-03-04 06:34:20 UTC (rev 144597)
+++ trunk/Source/WebCore/inspector/front-end/SimpleWorkspaceProvider.js	2013-03-04 06:53:18 UTC (rev 144598)
@@ -99,6 +99,16 @@
 
     /**
      * @param {Array.<string>} path
+     * @param {string} currentContent
+     * @param {function(?string)} callback
+     */
+    requestUpdatedFileContent: function(path, currentContent, callback)
+    {
+        callback(null);
+    },
+
+    /**
+     * @param {Array.<string>} path
      * @param {string} newContent
      * @param {function(?string)} callback
      */

Modified: trunk/Source/WebCore/inspector/front-end/SourceFrame.js (144597 => 144598)


--- trunk/Source/WebCore/inspector/front-end/SourceFrame.js	2013-03-04 06:34:20 UTC (rev 144597)
+++ trunk/Source/WebCore/inspector/front-end/SourceFrame.js	2013-03-04 06:53:18 UTC (rev 144598)
@@ -305,8 +305,11 @@
     {
         this._textEditor.mimeType = mimeType;
 
-        this._loaded = true;
-        this._textEditor.setText(content || "");
+        if (!this._loaded) {
+            this._loaded = true;
+            this._textEditor.setText(content || "");
+        } else
+            this._textEditor.editRange(this._textEditor.range(), content || "");
 
         this._textEditor.beginUpdates();
 

Modified: trunk/Source/WebCore/inspector/front-end/UISourceCode.js (144597 => 144598)


--- trunk/Source/WebCore/inspector/front-end/UISourceCode.js	2013-03-04 06:34:20 UTC (rev 144597)
+++ trunk/Source/WebCore/inspector/front-end/UISourceCode.js	2013-03-04 06:53:18 UTC (rev 144598)
@@ -214,6 +214,26 @@
             this._project.requestFileContent(this, this._fireContentAvailable.bind(this));
     },
 
+    checkContentUpdated: function()
+    {
+        this._project.requestUpdatedFileContent(this, updatedContentLoaded.bind(this));
+
+        function updatedContentLoaded(updatedContent)
+        {
+            if (typeof updatedContent !== "string")
+                return;
+
+            if (!this.isDirty()) {
+                this.addRevision(updatedContent);
+                return;
+            }
+
+            var shouldUpdate = window.confirm(WebInspector.UIString("This file was changed externally. Would you like to reload it?"));
+            if (shouldUpdate)
+                this.addRevision(updatedContent);
+        }
+    },
+
     /**
      * @param {function(?string,boolean,string)} callback
      */

Modified: trunk/Source/WebCore/inspector/front-end/UISourceCodeFrame.js (144597 => 144598)


--- trunk/Source/WebCore/inspector/front-end/UISourceCodeFrame.js	2013-03-04 06:34:20 UTC (rev 144597)
+++ trunk/Source/WebCore/inspector/front-end/UISourceCodeFrame.js	2013-03-04 06:53:18 UTC (rev 144598)
@@ -41,6 +41,21 @@
 }
 
 WebInspector.UISourceCodeFrame.prototype = {
+    wasShown: function()
+    {
+        WebInspector.SourceFrame.prototype.wasShown.call(this);
+        this._boundWindowFocused = this._windowFocused.bind(this);
+        window.addEventListener("focus", this._boundWindowFocused, false);
+        this._checkContentUpdated();
+    },
+
+    willHide: function()
+    {
+        WebInspector.SourceFrame.prototype.willHide.call(this);
+        window.removeEventListener("focus", this._boundWindowFocused, false);
+        delete this._boundWindowFocused;
+    },
+
     /**
      * @return {boolean}
      */
@@ -49,6 +64,18 @@
         return this._uiSourceCode.isEditable();
     },
 
+    _windowFocused: function(event)
+    {
+        this._checkContentUpdated();
+    },
+
+    _checkContentUpdated: function()
+    {
+        if (!this.loaded || !this.isShowing())
+            return;
+        this._uiSourceCode.checkContentUpdated();
+    },
+
     /**
      * @param {string} text
      */

Modified: trunk/Source/WebCore/inspector/front-end/Workspace.js (144597 => 144598)


--- trunk/Source/WebCore/inspector/front-end/Workspace.js	2013-03-04 06:34:20 UTC (rev 144597)
+++ trunk/Source/WebCore/inspector/front-end/Workspace.js	2013-03-04 06:53:18 UTC (rev 144598)
@@ -101,6 +101,13 @@
 
     /**
      * @param {Array.<string>} path
+     * @param {string} currentContent
+     * @param {function(?string)} callback
+     */
+    requestUpdatedFileContent: function(path, currentContent, callback) { },
+
+    /**
+     * @param {Array.<string>} path
      * @param {string} newContent
      * @param {function(?string)} callback
      */
@@ -256,6 +263,15 @@
 
     /**
      * @param {WebInspector.UISourceCode} uiSourceCode
+     * @param {function(?string)} callback
+     */
+    requestUpdatedFileContent: function(uiSourceCode, callback)
+    {
+        this._projectDelegate.requestUpdatedFileContent(uiSourceCode.path(), uiSourceCode.workingCopy(), callback);
+    },
+
+    /**
+     * @param {WebInspector.UISourceCode} uiSourceCode
      * @param {string} newContent
      * @param {function(?string)} callback
      */
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to