blob: 833848457966a5b7abef9a267b10dc05fd527372 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/*******************************************************************************
* Copyright (c) 2000, 2013 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.make.internal.ui.editor;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.make.core.makefile.IMakefile;
import org.eclipse.cdt.make.ui.IWorkingCopyManager;
import org.eclipse.cdt.make.ui.IWorkingCopyManagerExtension;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.ui.IEditorInput;
/**
* This working copy manager works together with a given compilation unit document provider and
* additionally offers to "overwrite" the working copy provided by this document provider.
*/
public class WorkingCopyManager implements IWorkingCopyManager, IWorkingCopyManagerExtension {
private IMakefileDocumentProvider fDocumentProvider;
private Map<IEditorInput, IMakefile> fMap;
private boolean fIsShuttingDown;
/**
* Creates a new working copy manager that co-operates with the given
* compilation unit document provider.
*
* @param provider the provider
*/
public WorkingCopyManager(IMakefileDocumentProvider provider) {
Assert.isNotNull(provider);
fDocumentProvider = provider;
}
@Override
public void connect(IEditorInput input) throws CoreException {
fDocumentProvider.connect(input);
}
@Override
public void disconnect(IEditorInput input) {
fDocumentProvider.disconnect(input);
}
@Override
public void shutdown() {
if (!fIsShuttingDown) {
fIsShuttingDown = true;
try {
if (fMap != null) {
fMap.clear();
fMap = null;
}
fDocumentProvider.shutdown();
} finally {
fIsShuttingDown = false;
}
}
}
@Override
public IMakefile getWorkingCopy(IEditorInput input) {
IMakefile unit = fMap == null ? null : (IMakefile) fMap.get(input);
return unit != null ? unit : fDocumentProvider.getWorkingCopy(input);
}
@Override
public void setWorkingCopy(IEditorInput input, IMakefile workingCopy) {
if (fDocumentProvider.getDocument(input) != null) {
if (fMap == null) {
fMap = new HashMap<IEditorInput, IMakefile>();
}
fMap.put(input, workingCopy);
}
}
@Override
public void removeWorkingCopy(IEditorInput input) {
fMap.remove(input);
if (fMap.isEmpty()) {
fMap = null;
}
}
}
|