OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011, the Dart project authors. | 2 * Copyright (c) 2011, 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 package com.google.dart.tools.ui.internal.text.editor; | 14 package com.google.dart.tools.ui.internal.text.editor; |
15 | 15 |
| 16 import com.google.dart.tools.core.DartCore; |
| 17 import com.google.dart.tools.core.internal.model.CompilationUnitImpl; |
16 import com.google.dart.tools.core.model.CompilationUnit; | 18 import com.google.dart.tools.core.model.CompilationUnit; |
17 import com.google.dart.tools.ui.IWorkingCopyManager; | 19 import com.google.dart.tools.ui.IWorkingCopyManager; |
18 import com.google.dart.tools.ui.IWorkingCopyManagerExtension; | 20 import com.google.dart.tools.ui.IWorkingCopyManagerExtension; |
19 import com.google.dart.tools.ui.internal.util.DartModelUtil; | 21 import com.google.dart.tools.ui.internal.util.DartModelUtil; |
20 | 22 |
21 import org.eclipse.core.runtime.Assert; | 23 import org.eclipse.core.runtime.Assert; |
22 import org.eclipse.core.runtime.CoreException; | 24 import org.eclipse.core.runtime.CoreException; |
23 import org.eclipse.ui.IEditorInput; | 25 import org.eclipse.ui.IEditorInput; |
| 26 import org.eclipse.ui.part.FileEditorInput; |
24 | 27 |
25 import java.util.HashMap; | 28 import java.util.HashMap; |
26 import java.util.Map; | 29 import java.util.Map; |
27 | 30 |
28 /** | 31 /** |
29 * This working copy manager works together with a given compilation unit docume
nt provider and | 32 * This working copy manager works together with a given compilation unit docume
nt provider and |
30 * additionally offers to "overwrite" the working copy provided by this document
provider. | 33 * additionally offers to "overwrite" the working copy provided by this document
provider. |
31 */ | 34 */ |
32 public class WorkingCopyManager implements IWorkingCopyManager, IWorkingCopyMana
gerExtension { | 35 public class WorkingCopyManager implements IWorkingCopyManager, IWorkingCopyMana
gerExtension { |
33 | 36 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 * @param primaryOnly if <code>true</code> only primary working copies will be
returned | 74 * @param primaryOnly if <code>true</code> only primary working copies will be
returned |
72 * @return the working copy of the compilation unit, or <code>null</code> if t
he input does not | 75 * @return the working copy of the compilation unit, or <code>null</code> if t
he input does not |
73 * encode an editor input, or if there is no remembered working copy f
or this compilation | 76 * encode an editor input, or if there is no remembered working copy f
or this compilation |
74 * unit | 77 * unit |
75 */ | 78 */ |
76 public CompilationUnit getWorkingCopy(IEditorInput input, boolean primaryOnly)
{ | 79 public CompilationUnit getWorkingCopy(IEditorInput input, boolean primaryOnly)
{ |
77 CompilationUnit unit = fMap == null ? null : fMap.get(input); | 80 CompilationUnit unit = fMap == null ? null : fMap.get(input); |
78 if (unit == null) { | 81 if (unit == null) { |
79 unit = fDocumentProvider.getWorkingCopy(input); | 82 unit = fDocumentProvider.getWorkingCopy(input); |
80 } | 83 } |
81 if (unit != null && (!primaryOnly || DartModelUtil.isPrimary(unit))) { | 84 if (unit != null) { |
82 return unit; | 85 if (unit instanceof CompilationUnitImpl && input instanceof FileEditorInpu
t) { |
| 86 return (CompilationUnit) DartCore.create(((FileEditorInput) input).getFi
le()); |
| 87 } else if (!primaryOnly || DartModelUtil.isPrimary(unit)) { |
| 88 return unit; |
| 89 } |
83 } | 90 } |
| 91 |
84 return null; | 92 return null; |
85 } | 93 } |
86 | 94 |
87 @Override | 95 @Override |
88 public void removeWorkingCopy(IEditorInput input) { | 96 public void removeWorkingCopy(IEditorInput input) { |
89 fMap.remove(input); | 97 fMap.remove(input); |
90 if (fMap.isEmpty()) { | 98 if (fMap.isEmpty()) { |
91 fMap = null; | 99 fMap = null; |
92 } | 100 } |
93 } | 101 } |
(...skipping 17 matching lines...) Expand all Loading... |
111 fMap.clear(); | 119 fMap.clear(); |
112 fMap = null; | 120 fMap = null; |
113 } | 121 } |
114 fDocumentProvider.shutdown(); | 122 fDocumentProvider.shutdown(); |
115 } finally { | 123 } finally { |
116 fIsShuttingDown = false; | 124 fIsShuttingDown = false; |
117 } | 125 } |
118 } | 126 } |
119 } | 127 } |
120 } | 128 } |
OLD | NEW |