Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(634)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/workspace/UISourceCode.js

Issue 2349343002: DevTools: introduce persistence/ module (Closed)
Patch Set: reupload Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 this._contentType = contentType; 49 this._contentType = contentType;
50 /** @type {?function(?string)} */ 50 /** @type {?function(?string)} */
51 this._requestContentCallback = null; 51 this._requestContentCallback = null;
52 /** @type {?Promise<?string>} */ 52 /** @type {?Promise<?string>} */
53 this._requestContentPromise = null; 53 this._requestContentPromise = null;
54 /** @type {!Map<string, !Map<number, !WebInspector.UISourceCode.LineMarker>> } */ 54 /** @type {!Map<string, !Map<number, !WebInspector.UISourceCode.LineMarker>> } */
55 this._lineDecorations = new Map(); 55 this._lineDecorations = new Map();
56 56
57 /** @type {!Array.<!WebInspector.Revision>} */ 57 /** @type {!Array.<!WebInspector.Revision>} */
58 this.history = []; 58 this.history = [];
59 this._hasUnsavedCommittedChanges = false;
60 59
61 /** @type {!Array<!WebInspector.UISourceCode.Message>} */ 60 /** @type {!Array<!WebInspector.UISourceCode.Message>} */
62 this._messages = []; 61 this._messages = [];
63 } 62 }
64 63
65 /** @enum {symbol} */ 64 /** @enum {symbol} */
66 WebInspector.UISourceCode.Events = { 65 WebInspector.UISourceCode.Events = {
67 WorkingCopyChanged: Symbol("WorkingCopyChanged"), 66 WorkingCopyChanged: Symbol("WorkingCopyChanged"),
68 WorkingCopyCommitted: Symbol("WorkingCopyCommitted"), 67 WorkingCopyCommitted: Symbol("WorkingCopyCommitted"),
69 TitleChanged: Symbol("TitleChanged"), 68 TitleChanged: Symbol("TitleChanged"),
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 this._project.requestFileContent(this, contentLoaded.bind(this)); 284 this._project.requestFileContent(this, contentLoaded.bind(this));
286 285
287 /** 286 /**
288 * @param {?string} updatedContent 287 * @param {?string} updatedContent
289 * @this {WebInspector.UISourceCode} 288 * @this {WebInspector.UISourceCode}
290 */ 289 */
291 function contentLoaded(updatedContent) 290 function contentLoaded(updatedContent)
292 { 291 {
293 if (updatedContent === null) { 292 if (updatedContent === null) {
294 var workingCopy = this.workingCopy(); 293 var workingCopy = this.workingCopy();
295 this._contentCommitted("", true, false); 294 this._contentCommitted("", false);
296 this.setWorkingCopy(workingCopy); 295 this.setWorkingCopy(workingCopy);
297 this._terminateContentCheck(); 296 this._terminateContentCheck();
298 return; 297 return;
299 } 298 }
300 if (typeof this._lastAcceptedContent === "string" && this._lastAccep tedContent === updatedContent) { 299 if (typeof this._lastAcceptedContent === "string" && this._lastAccep tedContent === updatedContent) {
301 this._terminateContentCheck(); 300 this._terminateContentCheck();
302 return; 301 return;
303 } 302 }
304 303
305 if (this._content === updatedContent) { 304 if (this._content === updatedContent) {
306 delete this._lastAcceptedContent; 305 delete this._lastAcceptedContent;
307 this._terminateContentCheck(); 306 this._terminateContentCheck();
308 return; 307 return;
309 } 308 }
310 309
311 if (!this.isDirty() || this._workingCopy === updatedContent) { 310 if (!this.isDirty() || this._workingCopy === updatedContent) {
312 this._contentCommitted(updatedContent, true, false); 311 this._contentCommitted(updatedContent, false);
313 this._terminateContentCheck(); 312 this._terminateContentCheck();
314 return; 313 return;
315 } 314 }
316 315
317 var shouldUpdate = window.confirm(WebInspector.UIString("This file w as changed externally. Would you like to reload it?")); 316 var shouldUpdate = window.confirm(WebInspector.UIString("This file w as changed externally. Would you like to reload it?"));
318 if (shouldUpdate) 317 if (shouldUpdate)
319 this._contentCommitted(updatedContent, true, false); 318 this._contentCommitted(updatedContent, false);
320 else 319 else
321 this._lastAcceptedContent = updatedContent; 320 this._lastAcceptedContent = updatedContent;
322 this._terminateContentCheck(); 321 this._terminateContentCheck();
323 } 322 }
324 }, 323 },
325 324
326 forceLoadOnCheckContent: function() 325 forceLoadOnCheckContent: function()
327 { 326 {
328 this._forceLoadOnCheckContent = true; 327 this._forceLoadOnCheckContent = true;
329 }, 328 },
330 329
331 /** 330 /**
332 * @return {!Promise<?string>} 331 * @return {!Promise<?string>}
333 */ 332 */
334 requestOriginalContent: function() 333 requestOriginalContent: function()
335 { 334 {
336 var callback; 335 var callback;
337 var promise = new Promise(fulfill => callback = fulfill); 336 var promise = new Promise(fulfill => callback = fulfill);
338 this._project.requestFileContent(this, callback); 337 this._project.requestFileContent(this, callback);
339 return promise; 338 return promise;
340 }, 339 },
341 340
342 /** 341 /**
343 * @param {string} content 342 * @param {string} content
344 */ 343 */
345 _commitContent: function(content) 344 _commitContent: function(content)
346 { 345 {
347 var wasPersisted = false;
348 if (this._project.canSetFileContent()) { 346 if (this._project.canSetFileContent()) {
349 this._project.setFileContent(this, content, function() { }); 347 this._project.setFileContent(this, content, function() { });
350 wasPersisted = true;
351 } else if (this._project.workspace().hasResourceContentTrackingExtension s()) {
352 wasPersisted = true;
353 } else if (this._url && WebInspector.fileManager.isURLSaved(this._url)) { 348 } else if (this._url && WebInspector.fileManager.isURLSaved(this._url)) {
354 WebInspector.fileManager.save(this._url, content, false, function() { }); 349 WebInspector.fileManager.save(this._url, content, false, function() { });
355 WebInspector.fileManager.close(this._url); 350 WebInspector.fileManager.close(this._url);
356 wasPersisted = true;
357 } 351 }
358 this._contentCommitted(content, wasPersisted, true); 352 this._contentCommitted(content, true);
359 }, 353 },
360 354
361 /** 355 /**
362 * @param {string} content 356 * @param {string} content
363 * @param {boolean} wasPersisted
364 * @param {boolean} committedByUser 357 * @param {boolean} committedByUser
365 */ 358 */
366 _contentCommitted: function(content, wasPersisted, committedByUser) 359 _contentCommitted: function(content, committedByUser)
367 { 360 {
368 delete this._lastAcceptedContent; 361 delete this._lastAcceptedContent;
369 this._content = content; 362 this._content = content;
370 this._contentLoaded = true; 363 this._contentLoaded = true;
371 364
372 var lastRevision = this.history.length ? this.history[this.history.lengt h - 1] : null; 365 var lastRevision = this.history.length ? this.history[this.history.lengt h - 1] : null;
373 if (!lastRevision || lastRevision._content !== this._content) { 366 if (!lastRevision || lastRevision._content !== this._content) {
374 var revision = new WebInspector.Revision(this, this._content, new Da te()); 367 var revision = new WebInspector.Revision(this, this._content, new Da te());
375 this.history.push(revision); 368 this.history.push(revision);
376 } 369 }
377 370
378 this._innerResetWorkingCopy(); 371 this._innerResetWorkingCopy();
379 this._hasUnsavedCommittedChanges = !wasPersisted; 372 this.dispatchEventToListeners(WebInspector.UISourceCode.Events.WorkingCo pyCommitted, { content: content });
380 this.dispatchEventToListeners(WebInspector.UISourceCode.Events.WorkingCo pyCommitted);
381 this._project.workspace().dispatchEventToListeners(WebInspector.Workspac e.Events.WorkingCopyCommitted, { uiSourceCode: this, content: content }); 373 this._project.workspace().dispatchEventToListeners(WebInspector.Workspac e.Events.WorkingCopyCommitted, { uiSourceCode: this, content: content });
382 if (committedByUser) 374 if (committedByUser)
383 this._project.workspace().dispatchEventToListeners(WebInspector.Work space.Events.WorkingCopyCommittedByUser, { uiSourceCode: this, content: content }); 375 this._project.workspace().dispatchEventToListeners(WebInspector.Work space.Events.WorkingCopyCommittedByUser, { uiSourceCode: this, content: content });
384 }, 376 },
385 377
386 saveAs: function() 378 saveAs: function()
387 { 379 {
388 WebInspector.fileManager.save(this._url, this.workingCopy(), true, callb ack.bind(this)); 380 WebInspector.fileManager.save(this._url, this.workingCopy(), true, callb ack.bind(this));
389 WebInspector.fileManager.close(this._url); 381 WebInspector.fileManager.close(this._url);
390 382
391 /** 383 /**
392 * @param {boolean} accepted 384 * @param {boolean} accepted
393 * @this {WebInspector.UISourceCode} 385 * @this {WebInspector.UISourceCode}
394 */ 386 */
395 function callback(accepted) 387 function callback(accepted)
396 { 388 {
397 if (accepted) 389 if (accepted)
398 this._contentCommitted(this.workingCopy(), true, true); 390 this._contentCommitted(this.workingCopy(), true);
399 } 391 }
400 }, 392 },
401 393
402 /** 394 /**
403 * @return {boolean}
404 */
405 hasUnsavedCommittedChanges: function()
406 {
407 return this._hasUnsavedCommittedChanges;
408 },
409
410 /**
411 * @param {string} content 395 * @param {string} content
412 */ 396 */
413 addRevision: function(content) 397 addRevision: function(content)
414 { 398 {
415 this._commitContent(content); 399 this._commitContent(content);
416 }, 400 },
417 401
418 /** 402 /**
419 * @return {!Promise} 403 * @return {!Promise}
420 */ 404 */
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 }, 956 },
973 957
974 /** 958 /**
975 * @return {*} 959 * @return {*}
976 */ 960 */
977 data: function() 961 data: function()
978 { 962 {
979 return this._data; 963 return this._data;
980 } 964 }
981 } 965 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698