2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.openapi
.editor
.impl
;
18 import com
.intellij
.openapi
.actionSystem
.ActionManager
;
19 import com
.intellij
.openapi
.editor
.EditorBundle
;
20 import com
.intellij
.openapi
.editor
.ReadOnlyFragmentModificationException
;
21 import com
.intellij
.openapi
.editor
.Document
;
22 import com
.intellij
.openapi
.editor
.actionSystem
.*;
23 import com
.intellij
.openapi
.ui
.Messages
;
24 import com
.intellij
.injected
.editor
.DocumentWindow
;
25 import org
.jetbrains
.annotations
.NotNull
;
27 public class EditorActionManagerImpl
extends EditorActionManager
{
28 private final TypedAction myTypedAction
= new TypedAction();
29 private ReadonlyFragmentModificationHandler myReadonlyFragmentsHandler
= new DefaultReadOnlyFragmentModificationHandler();
30 private final ActionManager myActionManager
;
32 public EditorActionManagerImpl(ActionManager actionManager
) {
33 myActionManager
= actionManager
;
36 public EditorActionHandler
getActionHandler(@NotNull String actionId
) {
37 return ((EditorAction
) myActionManager
.getAction(actionId
)).getHandler();
40 public EditorActionHandler
setActionHandler(@NotNull String actionId
, @NotNull EditorActionHandler handler
) {
41 EditorAction action
= (EditorAction
)myActionManager
.getAction(actionId
);
42 return action
.setupHandler(handler
);
46 public TypedAction
getTypedAction() {
50 public ReadonlyFragmentModificationHandler
getReadonlyFragmentModificationHandler() {
51 return myReadonlyFragmentsHandler
;
55 public ReadonlyFragmentModificationHandler
getReadonlyFragmentModificationHandler(@NotNull final Document document
) {
56 final Document doc
= document
instanceof DocumentWindow ?
((DocumentWindow
)document
).getDelegate() : document
;
57 final ReadonlyFragmentModificationHandler docHandler
=
58 doc
instanceof DocumentImpl ?
((DocumentImpl
)doc
).getReadonlyFragmentModificationHandler() : null;
59 return docHandler
== null ? myReadonlyFragmentsHandler
: docHandler
;
63 public void setReadonlyFragmentModificationHandler(@NotNull final Document document
, final ReadonlyFragmentModificationHandler handler
) {
64 final Document doc
= document
instanceof DocumentWindow ?
((DocumentWindow
)document
).getDelegate() : document
;
65 if (doc
instanceof DocumentImpl
) {
66 ((DocumentImpl
)document
).setReadonlyFragmentModificationHandler(handler
);
70 public ReadonlyFragmentModificationHandler
setReadonlyFragmentModificationHandler(@NotNull ReadonlyFragmentModificationHandler handler
) {
71 ReadonlyFragmentModificationHandler oldHandler
= myReadonlyFragmentsHandler
;
72 myReadonlyFragmentsHandler
= handler
;
77 private static class DefaultReadOnlyFragmentModificationHandler
implements ReadonlyFragmentModificationHandler
{
78 public void handle(ReadOnlyFragmentModificationException e
) {
79 Messages
.showErrorDialog(EditorBundle
.message("guarded.block.modification.attempt.error.message"),
80 EditorBundle
.message("guarded.block.modification.attempt.error.title"));