Mercurial > projects > dwt-addons
annotate dwtx/text/undo/DocumentUndoManagerRegistry.d @ 153:f70d9508c95c
Fix java Collection imports
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 25 Aug 2008 00:27:31 +0200 |
parents | 51e6e63f930e |
children | f8d52b926852 |
rev | line source |
---|---|
129 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2008 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.text.undo.DocumentUndoManagerRegistry; | |
14 | |
131 | 15 import dwtx.text.undo.DocumentUndoManager; // packageimport |
16 import dwtx.text.undo.DocumentUndoEvent; // packageimport | |
17 import dwtx.text.undo.IDocumentUndoListener; // packageimport | |
18 import dwtx.text.undo.UndoMessages; // packageimport | |
19 import dwtx.text.undo.IDocumentUndoManager; // packageimport | |
20 | |
21 | |
129 | 22 import dwt.dwthelper.utils; |
23 | |
153
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
24 import dwtx.dwtxhelper.Collection; |
f70d9508c95c
Fix java Collection imports
Frank Benoit <benoit@tionex.de>
parents:
134
diff
changeset
|
25 |
129 | 26 |
27 import dwtx.core.runtime.Assert; | |
28 import dwtx.jface.text.IDocument; | |
29 | |
30 | |
31 /** | |
32 * This document undo manager registry provides access to a document's | |
33 * undo manager. In order to connect a document a document undo manager | |
34 * call <code>connect</code>. After that call has successfully completed | |
35 * undo manager can be obtained via <code>getDocumentUndoManager</code>. | |
36 * The undo manager is created on the first connect and disposed on the last | |
37 * disconnect, i.e. this registry keeps track of how often a undo manager is | |
38 * connected and returns the same undo manager to each client as long as the | |
39 * document is connected. | |
40 * <p> | |
41 * <em>The recoding of changes starts with the first {@link #connect(IDocument)}.</em></p> | |
42 * | |
43 * @since 3.2 | |
44 * @noinstantiate This class is not intended to be instantiated by clients. | |
45 */ | |
46 public final class DocumentUndoManagerRegistry { | |
130 | 47 |
129 | 48 private static final class Record { |
133
7d818bd32d63
Fix ctors to this with gvim regexp
Frank Benoit <benoit@tionex.de>
parents:
131
diff
changeset
|
49 public this(IDocument document) { |
129 | 50 count= 0; |
51 undoManager= new DocumentUndoManager(document); | |
52 } | |
53 private int count; | |
54 private IDocumentUndoManager undoManager; | |
55 } | |
130 | 56 |
129 | 57 private static Map fgFactory= new HashMap(); |
130 | 58 |
59 private this() { | |
60 // Do not instantiate | |
129 | 61 } |
62 | |
130 | 63 |
129 | 64 /** |
65 * Connects the file at the given location to this manager. After that call | |
66 * successfully completed it is guaranteed that each call to <code>getFileBuffer</code> | |
67 * returns the same file buffer until <code>disconnect</code> is called. | |
68 * <p> | |
69 * <em>The recoding of changes starts with the first {@link #connect(IDocument)}.</em></p> | |
70 * | |
71 * @param document the document to be connected | |
72 */ | |
73 public static synchronized void connect(IDocument document) { | |
74 Assert.isNotNull(document); | |
134 | 75 Record record= cast(Record)fgFactory.get(document); |
129 | 76 if (record is null) { |
77 record= new Record(document); | |
78 fgFactory.put(document, record); | |
79 } | |
80 record.count++; | |
81 } | |
82 | |
83 /** | |
84 * Disconnects the given document from this registry. | |
85 * | |
86 * @param document the document to be disconnected | |
87 */ | |
88 public static synchronized void disconnect(IDocument document) { | |
89 Assert.isNotNull(document); | |
134 | 90 Record record= cast(Record)fgFactory.get(document); |
129 | 91 record.count--; |
92 if (record.count is 0) | |
93 fgFactory.remove(document); | |
130 | 94 |
129 | 95 } |
96 | |
97 /** | |
98 * Returns the file buffer managed for the given location or <code>null</code> | |
99 * if there is no such file buffer. | |
100 * <p> | |
101 * The provided location is either a full path of a workspace resource or | |
102 * an absolute path in the local file system. The file buffer manager does | |
103 * not resolve the location of workspace resources in the case of linked | |
104 * resources. | |
105 * </p> | |
106 * | |
107 * @param document the document for which to get its undo manager | |
108 * @return the document undo manager or <code>null</code> | |
109 */ | |
110 public static synchronized IDocumentUndoManager getDocumentUndoManager(IDocument document) { | |
111 Assert.isNotNull(document); | |
134 | 112 Record record= cast(Record)fgFactory.get(document); |
129 | 113 if (record is null) |
114 return null; | |
115 return record.undoManager; | |
116 } | |
117 | |
118 } |