Home | History | Annotate | Download | only in front_end
      1 /*
      2  * Copyright (C) 2012 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 /**
     32  * @constructor
     33  * @extends {WebInspector.Object}
     34  */
     35 WebInspector.FileManager = function()
     36 {
     37     this._saveCallbacks = {};
     38 }
     39 
     40 WebInspector.FileManager.EventTypes = {
     41     SavedURL: "SavedURL",
     42     AppendedToURL: "AppendedToURL"
     43 }
     44 
     45 WebInspector.FileManager.prototype = {
     46     /**
     47      * @return {boolean}
     48      */
     49     canSave: function()
     50     {
     51         return true;
     52     },
     53 
     54     /**
     55      * @param {string} url
     56      * @param {string} content
     57      * @param {boolean} forceSaveAs
     58      * @param {function()=} callback
     59      */
     60     save: function(url, content, forceSaveAs, callback)
     61     {
     62         // Remove this url from the saved URLs while it is being saved.
     63         var savedURLs = WebInspector.settings.savedURLs.get();
     64         delete savedURLs[url];
     65         WebInspector.settings.savedURLs.set(savedURLs);
     66         InspectorFrontendHost.save(url, content, forceSaveAs);
     67         this._saveCallbacks[url] = callback;
     68     },
     69 
     70     /**
     71      * @param {string} url
     72      */
     73     savedURL: function(url)
     74     {
     75         var savedURLs = WebInspector.settings.savedURLs.get();
     76         savedURLs[url] = true;
     77         WebInspector.settings.savedURLs.set(savedURLs);
     78         this.dispatchEventToListeners(WebInspector.FileManager.EventTypes.SavedURL, url);
     79         var callback = this._saveCallbacks[url];
     80         delete this._saveCallbacks[url];
     81         if (callback)
     82             callback();
     83     },
     84 
     85     /**
     86      * @param {string} url
     87      * @return {boolean}
     88      */
     89     isURLSaved: function(url)
     90     {
     91         var savedURLs = WebInspector.settings.savedURLs.get();
     92         return savedURLs[url];
     93     },
     94 
     95     /**
     96      * @param {string} url
     97      * @param {string} content
     98      */
     99     append: function(url, content)
    100     {
    101         InspectorFrontendHost.append(url, content);
    102     },
    103 
    104     /**
    105      * @param {string} url
    106      */
    107     close: function(url)
    108     {
    109         InspectorFrontendHost.close(url);
    110     },
    111 
    112     /**
    113      * @param {string} url
    114      */
    115     appendedToURL: function(url)
    116     {
    117         this.dispatchEventToListeners(WebInspector.FileManager.EventTypes.AppendedToURL, url);
    118     },
    119 
    120     __proto__: WebInspector.Object.prototype
    121 }
    122 
    123 WebInspector.fileManager = new WebInspector.FileManager();
    124