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

Side by Side Diff: dart/editor/tools/plugins/com.google.dart.tools.debug.core/src/com/google/dart/tools/debug/core/dartium/CssScriptManager.java

Issue 371253002: Version 1.5.7 (Closed) Base URL: http://dart.googlecode.com/svn/branches/1.5/
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012, the Dart project authors. 2 * Copyright (c) 2012, the Dart project authors.
3 * 3 *
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except
5 * in compliance with the License. You may obtain a copy of the License at 5 * in compliance with the License. You may obtain a copy of the License at
6 * 6 *
7 * http://www.eclipse.org/legal/epl-v10.html 7 * http://www.eclipse.org/legal/epl-v10.html
8 * 8 *
9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License 9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express
11 * or implied. See the License for the specific language governing permissions a nd limitations under 11 * or implied. See the License for the specific language governing permissions a nd limitations under
12 * the License. 12 * the License.
13 */ 13 */
14 14
15 package com.google.dart.tools.debug.core.dartium; 15 package com.google.dart.tools.debug.core.dartium;
16 16
17 import com.google.dart.tools.core.utilities.resource.IFileUtilities; 17 import com.google.dart.tools.core.utilities.resource.IFileUtilities;
18 import com.google.dart.tools.debug.core.DartDebugCorePlugin; 18 import com.google.dart.tools.debug.core.DartDebugCorePlugin;
19 import com.google.dart.tools.debug.core.util.ResourceChangeManager; 19 import com.google.dart.tools.debug.core.util.ResourceChangeManager;
20 import com.google.dart.tools.debug.core.util.ResourceChangeParticipant; 20 import com.google.dart.tools.debug.core.util.ResourceChangeParticipant;
21 import com.google.dart.tools.debug.core.webkit.WebkitStyleSheetRef; 21 import com.google.dart.tools.debug.core.webkit.WebkitStyleSheetRef;
22 22
23 import org.eclipse.core.resources.IFile; 23 import org.eclipse.core.resources.IFile;
24 import org.eclipse.core.runtime.CoreException; 24 import org.eclipse.core.runtime.CoreException;
25 import org.eclipse.core.runtime.IProgressMonitor;
26 import org.eclipse.core.runtime.IStatus;
27 import org.eclipse.core.runtime.Status;
28 import org.eclipse.core.runtime.jobs.Job;
25 29
26 import java.io.IOException; 30 import java.io.IOException;
27 import java.util.List; 31 import java.util.List;
28 32
29 /** 33 /**
30 * Manage known css scripts loaded in the target browser. Listen for resource ch ange events (using 34 * Manage known css scripts loaded in the target browser. Listen for resource ch ange events (using
31 * the ResourceChangeManager class). When a css scripts changes on disk that the browser knows 35 * the ResourceChangeManager class). When a css scripts changes on disk that the browser knows
32 * about, send the new contents to the browser using the Webkit inspector protoc ol. 36 * about, send the new contents to the browser using the Webkit inspector protoc ol.
33 */ 37 */
34 class CssScriptManager implements ResourceChangeParticipant { 38 class CssScriptManager implements ResourceChangeParticipant {
39
40 private class UpdateCssFileJob extends Job {
41
42 IFile file;
43
44 public UpdateCssFileJob(IFile file) {
45 super("Updating file");
46 this.file = file;
47 }
48
49 @Override
50 protected IStatus run(IProgressMonitor monitor) {
51 String fileUrl = target.getResourceResolver().getUrlForResource(file);
52
53 if (fileUrl != null) {
54 List<WebkitStyleSheetRef> scripts = target.getConnection().getCSS().getS tyleSheets();
55
56 for (WebkitStyleSheetRef ref : scripts) {
57 if (fileUrl.equals(ref.getSourceURL())) {
58 uploadNewSource(ref, file);
59 }
60 }
61 }
62
63 return Status.OK_STATUS;
64 }
65
66 }
67
35 private DartiumDebugTarget target; 68 private DartiumDebugTarget target;
36 69
37 public CssScriptManager(DartiumDebugTarget target) { 70 public CssScriptManager(DartiumDebugTarget target) {
38 this.target = target; 71 this.target = target;
39 72
40 ResourceChangeManager.getManager().addChangeParticipant(this); 73 ResourceChangeManager.getManager().addChangeParticipant(this);
41 } 74 }
42 75
43 public void dispose() { 76 public void dispose() {
44 ResourceChangeManager.removeChangeParticipant(this); 77 ResourceChangeManager.removeChangeParticipant(this);
45 } 78 }
46 79
47 @Override 80 @Override
48 public void handleFileAdded(IFile file) { 81 public void handleFileAdded(IFile file) {
49 handleFileChanged(file); 82 handleFileChanged(file);
50 } 83 }
51 84
52 @Override 85 @Override
53 public void handleFileChanged(IFile file) { 86 public void handleFileChanged(IFile file) {
54 if ("css".equals(file.getFileExtension())) { 87 if ("css".equals(file.getFileExtension())) {
55 String fileUrl = target.getResourceResolver().getUrlForResource(file); 88 UpdateCssFileJob job = new UpdateCssFileJob(file);
56 89 job.schedule();
57 if (fileUrl != null) {
58 List<WebkitStyleSheetRef> scripts = target.getConnection().getCSS().getS tyleSheets();
59
60 for (WebkitStyleSheetRef ref : scripts) {
61 if (fileUrl.equals(ref.getSourceURL())) {
62 uploadNewSource(ref, file);
63 }
64 }
65 }
66 } 90 }
67 } 91 }
68 92
69 @Override 93 @Override
70 public void handleFileRemoved(IFile file) { 94 public void handleFileRemoved(IFile file) {
71 95
72 } 96 }
73 97
74 private void uploadNewSource(WebkitStyleSheetRef ref, IFile file) { 98 private void uploadNewSource(WebkitStyleSheetRef ref, IFile file) {
75 try { 99 try {
76 target.getConnection().getCSS().setStyleSheetText( 100 target.getConnection().getCSS().setStyleSheetText(
77 ref.getStyleSheetId(), 101 ref.getStyleSheetId(),
78 IFileUtilities.getContents(file)); 102 IFileUtilities.getContents(file));
79 } catch (IOException e) { 103 } catch (IOException e) {
80 // We upload changed css scripts on a best-effort basis. 104 // We upload changed css scripts on a best-effort basis.
81 //DartDebugCorePlugin.logError(e); 105 //DartDebugCorePlugin.logError(e);
82 } catch (CoreException e) { 106 } catch (CoreException e) {
83 DartDebugCorePlugin.logError(e); 107 DartDebugCorePlugin.logError(e);
84 } 108 }
85 } 109 }
86 110
87 } 111 }
OLDNEW
« no previous file with comments | « no previous file | dart/editor/tools/plugins/com.google.dart.tools.debug.core/src/com/google/dart/tools/debug/core/dartium/DartCodeManager.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698