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
.ide
.actions
;
18 import com
.intellij
.ide
.IdeBundle
;
19 import com
.intellij
.openapi
.actionSystem
.AnAction
;
20 import com
.intellij
.openapi
.actionSystem
.AnActionEvent
;
21 import com
.intellij
.openapi
.actionSystem
.PlatformDataKeys
;
22 import com
.intellij
.openapi
.actionSystem
.Presentation
;
23 import com
.intellij
.openapi
.project
.Project
;
24 import com
.intellij
.openapi
.project
.DumbAware
;
25 import com
.intellij
.openapi
.wm
.ToolWindow
;
26 import com
.intellij
.openapi
.wm
.ex
.ToolWindowManagerEx
;
27 import com
.intellij
.openapi
.wm
.impl
.DesktopLayout
;
29 public class HideAllToolWindowsAction
extends AnAction
implements DumbAware
{
30 public void actionPerformed(AnActionEvent e
) {
31 Project project
= PlatformDataKeys
.PROJECT
.getData(e
.getDataContext());
32 if (project
== null) {
36 performAction(project
);
39 public static void performAction(final Project project
) {
40 ToolWindowManagerEx toolWindowManager
= ToolWindowManagerEx
.getInstanceEx(project
);
42 DesktopLayout layout
= new DesktopLayout();
43 layout
.copyFrom(toolWindowManager
.getLayout());
45 // to clear windows stack
46 toolWindowManager
.clearSideStack();
47 //toolWindowManager.activateEditorComponent();
50 String
[] ids
= toolWindowManager
.getToolWindowIds();
51 boolean hasVisible
= false;
52 for (String id
: ids
) {
53 ToolWindow toolWindow
= toolWindowManager
.getToolWindow(id
);
54 if (toolWindow
.isVisible()) {
55 toolWindow
.hide(null);
61 toolWindowManager
.setLayoutToRestoreLater(layout
);
62 toolWindowManager
.activateEditorComponent();
65 final DesktopLayout restoredLayout
= toolWindowManager
.getLayoutToRestoreLater();
66 if (restoredLayout
!= null) {
67 toolWindowManager
.setLayoutToRestoreLater(null);
68 toolWindowManager
.setLayout(restoredLayout
);
73 public void update(AnActionEvent event
) {
74 Presentation presentation
= event
.getPresentation();
75 Project project
= PlatformDataKeys
.PROJECT
.getData(event
.getDataContext());
76 if (project
== null) {
77 presentation
.setEnabled(false);
81 ToolWindowManagerEx toolWindowManager
= ToolWindowManagerEx
.getInstanceEx(project
);
82 String
[] ids
= toolWindowManager
.getToolWindowIds();
83 for (String id
: ids
) {
84 if (toolWindowManager
.getToolWindow(id
).isVisible()) {
85 presentation
.setEnabled(true);
86 presentation
.setText(IdeBundle
.message("action.hide.all.windows"), true);
91 final DesktopLayout layout
= toolWindowManager
.getLayoutToRestoreLater();
93 presentation
.setEnabled(true);
94 presentation
.setText(IdeBundle
.message("action.restore.windows"));
98 presentation
.setEnabled(false);