OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 /** | 4 /** |
5 * @implements {Sources.TabbedEditorContainerDelegate} | 5 * @implements {Sources.TabbedEditorContainerDelegate} |
6 * @implements {UI.Searchable} | 6 * @implements {UI.Searchable} |
7 * @implements {UI.Replaceable} | 7 * @implements {UI.Replaceable} |
8 * @unrestricted | 8 * @unrestricted |
9 */ | 9 */ |
10 Sources.SourcesView = class extends UI.VBox { | 10 Sources.SourcesView = class extends UI.VBox { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 192 } |
193 | 193 |
194 /** | 194 /** |
195 * @return {?UI.Widget} | 195 * @return {?UI.Widget} |
196 */ | 196 */ |
197 visibleView() { | 197 visibleView() { |
198 return this._editorContainer.visibleView; | 198 return this._editorContainer.visibleView; |
199 } | 199 } |
200 | 200 |
201 /** | 201 /** |
202 * @return {?Sources.UISourceCodeFrame} | 202 * @return {?SourceFrame.UISourceCodeFrame} |
203 */ | 203 */ |
204 currentSourceFrame() { | 204 currentSourceFrame() { |
205 var view = this.visibleView(); | 205 var view = this.visibleView(); |
206 if (!(view instanceof Sources.UISourceCodeFrame)) | 206 if (!(view instanceof SourceFrame.UISourceCodeFrame)) |
207 return null; | 207 return null; |
208 return /** @type {!Sources.UISourceCodeFrame} */ (view); | 208 return /** @type {!SourceFrame.UISourceCodeFrame} */ (view); |
209 } | 209 } |
210 | 210 |
211 /** | 211 /** |
212 * @return {?Workspace.UISourceCode} | 212 * @return {?Workspace.UISourceCode} |
213 */ | 213 */ |
214 currentUISourceCode() { | 214 currentUISourceCode() { |
215 return this._editorContainer.currentFile(); | 215 return this._editorContainer.currentFile(); |
216 } | 216 } |
217 | 217 |
218 /** | 218 /** |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 319 |
320 if (contentType.hasScripts()) | 320 if (contentType.hasScripts()) |
321 sourceFrame = new Sources.JavaScriptSourceFrame(uiSourceCode); | 321 sourceFrame = new Sources.JavaScriptSourceFrame(uiSourceCode); |
322 else if (contentType.isStyleSheet()) | 322 else if (contentType.isStyleSheet()) |
323 sourceFrame = new Sources.CSSSourceFrame(uiSourceCode); | 323 sourceFrame = new Sources.CSSSourceFrame(uiSourceCode); |
324 else if (contentType === Common.resourceTypes.Image) | 324 else if (contentType === Common.resourceTypes.Image) |
325 sourceView = new SourceFrame.ImageView(Bindings.NetworkProject.uiSourceCod
eMimeType(uiSourceCode), uiSourceCode); | 325 sourceView = new SourceFrame.ImageView(Bindings.NetworkProject.uiSourceCod
eMimeType(uiSourceCode), uiSourceCode); |
326 else if (contentType === Common.resourceTypes.Font) | 326 else if (contentType === Common.resourceTypes.Font) |
327 sourceView = new SourceFrame.FontView(Bindings.NetworkProject.uiSourceCode
MimeType(uiSourceCode), uiSourceCode); | 327 sourceView = new SourceFrame.FontView(Bindings.NetworkProject.uiSourceCode
MimeType(uiSourceCode), uiSourceCode); |
328 else | 328 else |
329 sourceFrame = new Sources.UISourceCodeFrame(uiSourceCode); | 329 sourceFrame = new SourceFrame.UISourceCodeFrame(uiSourceCode); |
330 | 330 |
331 if (sourceFrame) { | 331 if (sourceFrame) { |
332 sourceFrame.setHighlighterType(Bindings.NetworkProject.uiSourceCodeMimeTyp
e(uiSourceCode)); | 332 sourceFrame.setHighlighterType(Bindings.NetworkProject.uiSourceCodeMimeTyp
e(uiSourceCode)); |
333 this._historyManager.trackSourceFrameCursorJumps(sourceFrame); | 333 this._historyManager.trackSourceFrameCursorJumps(sourceFrame); |
334 } | 334 } |
335 var widget = /** @type {!UI.Widget} */ (sourceFrame || sourceView); | 335 var widget = /** @type {!UI.Widget} */ (sourceFrame || sourceView); |
336 this._sourceViewByUISourceCode.set(uiSourceCode, widget); | 336 this._sourceViewByUISourceCode.set(uiSourceCode, widget); |
337 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.TitleChanged, th
is._uiSourceCodeTitleChanged, this); | 337 uiSourceCode.addEventListener(Workspace.UISourceCode.Events.TitleChanged, th
is._uiSourceCodeTitleChanged, this); |
338 return widget; | 338 return widget; |
339 } | 339 } |
340 | 340 |
341 /** | 341 /** |
342 * @param {!Workspace.UISourceCode} uiSourceCode | 342 * @param {!Workspace.UISourceCode} uiSourceCode |
343 * @return {!UI.Widget} | 343 * @return {!UI.Widget} |
344 */ | 344 */ |
345 _getOrCreateSourceView(uiSourceCode) { | 345 _getOrCreateSourceView(uiSourceCode) { |
346 return this._sourceViewByUISourceCode.get(uiSourceCode) || this._createSourc
eView(uiSourceCode); | 346 return this._sourceViewByUISourceCode.get(uiSourceCode) || this._createSourc
eView(uiSourceCode); |
347 } | 347 } |
348 | 348 |
349 /** | 349 /** |
350 * @param {!Sources.UISourceCodeFrame} sourceFrame | 350 * @param {!SourceFrame.UISourceCodeFrame} sourceFrame |
351 * @param {!Workspace.UISourceCode} uiSourceCode | 351 * @param {!Workspace.UISourceCode} uiSourceCode |
352 * @return {boolean} | 352 * @return {boolean} |
353 */ | 353 */ |
354 _sourceFrameMatchesUISourceCode(sourceFrame, uiSourceCode) { | 354 _sourceFrameMatchesUISourceCode(sourceFrame, uiSourceCode) { |
355 if (uiSourceCode.contentType().hasScripts()) | 355 if (uiSourceCode.contentType().hasScripts()) |
356 return sourceFrame instanceof Sources.JavaScriptSourceFrame; | 356 return sourceFrame instanceof Sources.JavaScriptSourceFrame; |
357 if (uiSourceCode.contentType().isStyleSheet()) | 357 if (uiSourceCode.contentType().isStyleSheet()) |
358 return sourceFrame instanceof Sources.CSSSourceFrame; | 358 return sourceFrame instanceof Sources.CSSSourceFrame; |
359 return !(sourceFrame instanceof Sources.JavaScriptSourceFrame); | 359 return !(sourceFrame instanceof Sources.JavaScriptSourceFrame); |
360 } | 360 } |
361 | 361 |
362 /** | 362 /** |
363 * @param {!Workspace.UISourceCode} uiSourceCode | 363 * @param {!Workspace.UISourceCode} uiSourceCode |
364 */ | 364 */ |
365 _recreateSourceFrameIfNeeded(uiSourceCode) { | 365 _recreateSourceFrameIfNeeded(uiSourceCode) { |
366 var oldSourceView = this._sourceViewByUISourceCode.get(uiSourceCode); | 366 var oldSourceView = this._sourceViewByUISourceCode.get(uiSourceCode); |
367 if (!oldSourceView || !(oldSourceView instanceof Sources.UISourceCodeFrame)) | 367 if (!oldSourceView || !(oldSourceView instanceof SourceFrame.UISourceCodeFra
me)) |
368 return; | 368 return; |
369 var oldSourceFrame = /** @type {!Sources.UISourceCodeFrame} */ (oldSourceVie
w); | 369 var oldSourceFrame = /** @type {!SourceFrame.UISourceCodeFrame} */ (oldSourc
eView); |
370 if (this._sourceFrameMatchesUISourceCode(oldSourceFrame, uiSourceCode)) { | 370 if (this._sourceFrameMatchesUISourceCode(oldSourceFrame, uiSourceCode)) { |
371 oldSourceFrame.setHighlighterType(Bindings.NetworkProject.uiSourceCodeMime
Type(uiSourceCode)); | 371 oldSourceFrame.setHighlighterType(Bindings.NetworkProject.uiSourceCodeMime
Type(uiSourceCode)); |
372 } else { | 372 } else { |
373 this._editorContainer.removeUISourceCode(uiSourceCode); | 373 this._editorContainer.removeUISourceCode(uiSourceCode); |
374 this._removeSourceFrame(uiSourceCode); | 374 this._removeSourceFrame(uiSourceCode); |
375 } | 375 } |
376 } | 376 } |
377 | 377 |
378 /** | 378 /** |
379 * @override | 379 * @override |
380 * @param {!Workspace.UISourceCode} uiSourceCode | 380 * @param {!Workspace.UISourceCode} uiSourceCode |
381 * @return {!UI.Widget} | 381 * @return {!UI.Widget} |
382 */ | 382 */ |
383 viewForFile(uiSourceCode) { | 383 viewForFile(uiSourceCode) { |
384 return this._getOrCreateSourceView(uiSourceCode); | 384 return this._getOrCreateSourceView(uiSourceCode); |
385 } | 385 } |
386 | 386 |
387 /** | 387 /** |
388 * @param {!Workspace.UISourceCode} uiSourceCode | 388 * @param {!Workspace.UISourceCode} uiSourceCode |
389 */ | 389 */ |
390 _removeSourceFrame(uiSourceCode) { | 390 _removeSourceFrame(uiSourceCode) { |
391 var sourceView = this._sourceViewByUISourceCode.get(uiSourceCode); | 391 var sourceView = this._sourceViewByUISourceCode.get(uiSourceCode); |
392 this._sourceViewByUISourceCode.remove(uiSourceCode); | 392 this._sourceViewByUISourceCode.remove(uiSourceCode); |
393 uiSourceCode.removeEventListener(Workspace.UISourceCode.Events.TitleChanged,
this._uiSourceCodeTitleChanged, this); | 393 uiSourceCode.removeEventListener(Workspace.UISourceCode.Events.TitleChanged,
this._uiSourceCodeTitleChanged, this); |
394 if (sourceView && sourceView instanceof Sources.UISourceCodeFrame) | 394 if (sourceView && sourceView instanceof SourceFrame.UISourceCodeFrame) |
395 /** @type {!Sources.UISourceCodeFrame} */ (sourceView).dispose(); | 395 /** @type {!SourceFrame.UISourceCodeFrame} */ (sourceView).dispose(); |
396 } | 396 } |
397 | 397 |
398 _onBindingChanged() { | 398 _onBindingChanged() { |
399 this.setExecutionLocation(this._executionLocation); | 399 this.setExecutionLocation(this._executionLocation); |
400 this.showSourceLocation( | 400 this.showSourceLocation( |
401 this._executionLocation.uiSourceCode, this._executionLocation.lineNumber
, this._executionLocation.columnNumber); | 401 this._executionLocation.uiSourceCode, this._executionLocation.lineNumber
, this._executionLocation.columnNumber); |
402 } | 402 } |
403 | 403 |
404 clearCurrentExecutionLine() { | 404 clearCurrentExecutionLine() { |
405 if (!this._executionLocation) | 405 if (!this._executionLocation) |
406 return; | 406 return; |
407 Persistence.persistence.unsubscribeFromBindingEvent(this._executionLocation.
uiSourceCode, this._bindingChangeBound); | 407 Persistence.persistence.unsubscribeFromBindingEvent(this._executionLocation.
uiSourceCode, this._bindingChangeBound); |
408 this._executionSourceFrame.clearExecutionLine(); | 408 this._executionSourceFrame.clearExecutionLine(); |
409 this._executionSourceFrame = null; | 409 this._executionSourceFrame = null; |
410 this._executionLocation = null; | 410 this._executionLocation = null; |
411 } | 411 } |
412 | 412 |
413 /** | 413 /** |
414 * @param {!Workspace.UILocation} uiLocation | 414 * @param {!Workspace.UILocation} uiLocation |
415 */ | 415 */ |
416 setExecutionLocation(uiLocation) { | 416 setExecutionLocation(uiLocation) { |
417 this.clearCurrentExecutionLine(); | 417 this.clearCurrentExecutionLine(); |
418 var binding = Persistence.persistence.binding(uiLocation.uiSourceCode); | 418 var binding = Persistence.persistence.binding(uiLocation.uiSourceCode); |
419 var uiSourceCode = binding ? binding.fileSystem : uiLocation.uiSourceCode; | 419 var uiSourceCode = binding ? binding.fileSystem : uiLocation.uiSourceCode; |
420 var sourceView = this._getOrCreateSourceView(uiSourceCode); | 420 var sourceView = this._getOrCreateSourceView(uiSourceCode); |
421 if (!(sourceView instanceof Sources.UISourceCodeFrame)) | 421 if (!(sourceView instanceof SourceFrame.UISourceCodeFrame)) |
422 return; | 422 return; |
423 Persistence.persistence.subscribeForBindingEvent(uiLocation.uiSourceCode, th
is._bindingChangeBound); | 423 Persistence.persistence.subscribeForBindingEvent(uiLocation.uiSourceCode, th
is._bindingChangeBound); |
424 var sourceFrame = /** @type {!Sources.UISourceCodeFrame} */ (sourceView); | 424 var sourceFrame = /** @type {!SourceFrame.UISourceCodeFrame} */ (sourceView)
; |
425 sourceFrame.setExecutionLocation( | 425 sourceFrame.setExecutionLocation( |
426 new Workspace.UILocation(uiSourceCode, uiLocation.lineNumber, uiLocation
.columnNumber)); | 426 new Workspace.UILocation(uiSourceCode, uiLocation.lineNumber, uiLocation
.columnNumber)); |
427 this._executionSourceFrame = sourceFrame; | 427 this._executionSourceFrame = sourceFrame; |
428 this._executionLocation = uiLocation; | 428 this._executionLocation = uiLocation; |
429 } | 429 } |
430 | 430 |
431 /** | 431 /** |
432 * @param {!Common.Event} event | 432 * @param {!Common.Event} event |
433 */ | 433 */ |
434 _editorClosed(event) { | 434 _editorClosed(event) { |
(...skipping 12 matching lines...) Expand all Loading... |
447 data.uiSourceCode = uiSourceCode; | 447 data.uiSourceCode = uiSourceCode; |
448 data.wasSelected = wasSelected; | 448 data.wasSelected = wasSelected; |
449 this.dispatchEventToListeners(Sources.SourcesView.Events.EditorClosed, data)
; | 449 this.dispatchEventToListeners(Sources.SourcesView.Events.EditorClosed, data)
; |
450 } | 450 } |
451 | 451 |
452 /** | 452 /** |
453 * @param {!Common.Event} event | 453 * @param {!Common.Event} event |
454 */ | 454 */ |
455 _editorSelected(event) { | 455 _editorSelected(event) { |
456 var previousSourceFrame = | 456 var previousSourceFrame = |
457 event.data.previousView instanceof Sources.UISourceCodeFrame ? event.dat
a.previousView : null; | 457 event.data.previousView instanceof SourceFrame.UISourceCodeFrame ? event
.data.previousView : null; |
458 if (previousSourceFrame) | 458 if (previousSourceFrame) |
459 previousSourceFrame.setSearchableView(null); | 459 previousSourceFrame.setSearchableView(null); |
460 var currentSourceFrame = | 460 var currentSourceFrame = |
461 event.data.currentView instanceof Sources.UISourceCodeFrame ? event.data
.currentView : null; | 461 event.data.currentView instanceof SourceFrame.UISourceCodeFrame ? event.
data.currentView : null; |
462 if (currentSourceFrame) | 462 if (currentSourceFrame) |
463 currentSourceFrame.setSearchableView(this._searchableView); | 463 currentSourceFrame.setSearchableView(this._searchableView); |
464 | 464 |
465 this._searchableView.setReplaceable(!!currentSourceFrame && currentSourceFra
me.canEditSource()); | 465 this._searchableView.setReplaceable(!!currentSourceFrame && currentSourceFra
me.canEditSource()); |
466 this._searchableView.refreshSearch(); | 466 this._searchableView.refreshSearch(); |
467 this._updateScriptViewToolbarItems(); | 467 this._updateScriptViewToolbarItems(); |
468 | 468 |
469 this.dispatchEventToListeners(Sources.SourcesView.Events.EditorSelected, thi
s._editorContainer.currentFile()); | 469 this.dispatchEventToListeners(Sources.SourcesView.Events.EditorSelected, thi
s._editorContainer.currentFile()); |
470 } | 470 } |
471 | 471 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 _saveAll() { | 641 _saveAll() { |
642 var sourceFrames = this._editorContainer.fileViews(); | 642 var sourceFrames = this._editorContainer.fileViews(); |
643 sourceFrames.forEach(this._saveSourceFrame.bind(this)); | 643 sourceFrames.forEach(this._saveSourceFrame.bind(this)); |
644 return true; | 644 return true; |
645 } | 645 } |
646 | 646 |
647 /** | 647 /** |
648 * @param {?UI.Widget} sourceFrame | 648 * @param {?UI.Widget} sourceFrame |
649 */ | 649 */ |
650 _saveSourceFrame(sourceFrame) { | 650 _saveSourceFrame(sourceFrame) { |
651 if (!(sourceFrame instanceof Sources.UISourceCodeFrame)) | 651 if (!(sourceFrame instanceof SourceFrame.UISourceCodeFrame)) |
652 return; | 652 return; |
653 var uiSourceCodeFrame = /** @type {!Sources.UISourceCodeFrame} */ (sourceFra
me); | 653 var uiSourceCodeFrame = /** @type {!SourceFrame.UISourceCodeFrame} */ (sourc
eFrame); |
654 uiSourceCodeFrame.commitEditing(); | 654 uiSourceCodeFrame.commitEditing(); |
655 } | 655 } |
656 | 656 |
657 /** | 657 /** |
658 * @return {boolean} | 658 * @return {boolean} |
659 */ | 659 */ |
660 _toggleBreakpoint() { | 660 _toggleBreakpoint() { |
661 var sourceFrame = this.currentSourceFrame(); | 661 var sourceFrame = this.currentSourceFrame(); |
662 if (!sourceFrame) | 662 if (!sourceFrame) |
663 return false; | 663 return false; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 * @return {boolean} | 768 * @return {boolean} |
769 */ | 769 */ |
770 handleAction(context, actionId) { | 770 handleAction(context, actionId) { |
771 var sourcesView = UI.context.flavor(Sources.SourcesView); | 771 var sourcesView = UI.context.flavor(Sources.SourcesView); |
772 if (!sourcesView) | 772 if (!sourcesView) |
773 return false; | 773 return false; |
774 sourcesView._editorContainer.closeAllFiles(); | 774 sourcesView._editorContainer.closeAllFiles(); |
775 return true; | 775 return true; |
776 } | 776 } |
777 }; | 777 }; |
OLD | NEW |