Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ public static Action[] createDefaultPopupActions(TopComponent tc) {
allBut.setEnabled(false);
}
actions.add(allBut);
//close all right of this
int index = mode.getTopComponentTabPosition(tc);
CloseAllRightOfThisAction allRight = new CloseAllRightOfThisAction(index);
actions.add(allRight);
}

actions.add(null); // Separator
Expand Down Expand Up @@ -499,6 +503,18 @@ public static void closeAllExcept (TopComponent tc, boolean isContext) {
closeAll(tcs);
});
}

/**
* Closes all documents after given index, according to isContext flag
*/
public static void closeRight(int index) {
// See closeAllDocuments.
SwingUtilities.invokeLater(() -> {
List<TopComponent> tcs = new ArrayList<>(getOpened(TopComponent.getRegistry().getActivated()));
closeAll(tcs.subList(index + 1, tcs.size()));
});
}


private static void closeAll( Iterable<TopComponent> tcs ) {
for (TopComponent curTC : tcs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ CTL_SwitchToRecentDocumentAction=&Editor

CTL_CloseAllDocumentsAction=Close &All Documents

CTL_CloseAllRightOfThisAction=Close Right
CTL_CloseAllRightOfThisAction_MainMenu=Close All Documents Right Of This

# UndockAction
CTL_UndockWindowAction=&Float
CTL_UndockWindowAction_Dock=Doc&k
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.netbeans.core.windows.actions;

import javax.swing.AbstractAction;
import javax.swing.Action;
import static javax.swing.Action.NAME;
import org.netbeans.core.windows.WindowManagerImpl;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;

/**
*
* @author davidwolf
*/
public class CloseAllRightOfThisAction extends AbstractAction {

/**
* TopComponent index to mark after which tab should all subsequent tabs be
* closed or -1 for the instance used in the Menu Bar
*/
private int index;

/**
* Constructor used in Menu Bar menu called "Window" in the "Close All
* Documents Right Of This" option
*/
public CloseAllRightOfThisAction() {
this(-1);
}

/**
* Constructor used by right clicking on an opened file.
*
* @param index
*/
public CloseAllRightOfThisAction(int index) {
this.index = index;
String key = index == -1 ? "CTL_CloseAllRightOfThisAction_MainMenu" : "CTL_CloseAllRightOfThisAction";
putValue(NAME, NbBundle.getMessage(CloseAllRightOfThisAction.class, key));
}

@Override
public void actionPerformed(java.awt.event.ActionEvent ev) {
// index CANNOT be reassigned because this class is used in Menu Bar where the instance is not regenerated
if (index == -1) {
ActionUtils.closeRight(TopComponent.getRegistry().getActivated().getTabPosition());
} else {
ActionUtils.closeRight(index);
}
}

/**
* Overriden to share accelerator with
* org.netbeans.core.windows.actions.ActionUtils.CloseAllRightOfThisAction
*/
@Override
public void putValue(String key, Object newValue) {
if (Action.ACCELERATOR_KEY.equals(key)) {
ActionUtils.putSharedAccelerator("CloseAllRightOfThisAction", newValue); //NOI18N
} else {
super.putValue(key, newValue);
}
}

/**
* Overriden to share accelerator with
* org.netbeans.core.windows.actions.ActionUtils.CloseAllRightOfThisAction
*/
@Override
public Object getValue(String key) {
if (Action.ACCELERATOR_KEY.equals(key)) {
return ActionUtils.getSharedAccelerator("CloseAllRightOfThisAction"); //NOI18N
} else {
return super.getValue(key);
}
}

@Override
public boolean isEnabled() {
WindowManagerImpl wmi = WindowManagerImpl.getInstance();
TopComponent tc = TopComponent.getRegistry().getActivated();
if (!wmi.isOpenedEditorTopComponent(tc)) {
return false;
}
int i = index == -1 ? tc.getTabPosition() : index;
return i != wmi.getEditorTopComponents().length - 1;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<file name="org-netbeans-core-windows-actions-NextTabAction.instance"/>
<file name="org-netbeans-core-windows-actions-PreviousTabAction.instance"/>
<file name="org-netbeans-core-windows-actions-CloseAllButThisAction.instance"/>
<file name="org-netbeans-core-windows-actions-CloseAllRightOfThisAction.instance"/>
<file name="org-netbeans-core-windows-actions-ToggleFullScreenAction.instance"/>
<file name="org-netbeans-core-windows-actions-UndockWindowAction.instance"/>
<file name="org-netbeans-core-windows-actions-DockWindowAction.instance"/>
Expand Down Expand Up @@ -257,6 +258,10 @@
<attr name="originalFile" stringvalue="Actions/Window/org-netbeans-core-windows-actions-CloseAllButThisAction.instance"/>
<attr name="position" intvalue="20600"/>
</file>
<file name="CloseAllRightOfThisAction.shadow">
<attr name="originalFile" stringvalue="Actions/Window/org-netbeans-core-windows-actions-CloseAllRightOfThisAction.instance"/>
<attr name="position" intvalue="20625"/>
</file>
<file name="GroupsMenuAction.shadow">
<attr name="originalFile" stringvalue="Actions/Window/GroupsMenuAction.instance"/>
<attr name="position" intvalue="20650"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@
import java.beans.PropertyChangeListener;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import org.netbeans.core.windows.Constants;
import org.netbeans.core.windows.ModeImpl;
import org.netbeans.core.windows.Switches;
Expand Down Expand Up @@ -329,7 +327,10 @@ public void actionPerformed(ActionEvent e) {
} else if (TabbedContainer.COMMAND_CLOSE_ALL_BUT_THIS == cmd) {
TopComponent tc = tabbed.getTopComponentAt(tae.getTabIndex());
ActionUtils.closeAllExcept(tc, true);
//Pin button handling here
} else if (TabbedContainer.COMMAND_CLOSE_RIGHT.equals(cmd)) {
TopComponent tc = tabbed.getTopComponentAt(tae.getTabIndex());
ActionUtils.closeRight(tc.getTabPosition());
//Pin button handling here
} else if (TabbedContainer.COMMAND_ENABLE_AUTO_HIDE.equals(cmd)) {
if( Switches.isTopComponentSlidingEnabled() && tabbed.getComponent().isShowing() ) {
TopComponent tc = tabbed.getTopComponentAt(tae.getTabIndex());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@

package org.netbeans.swing.tabcontrol;

import javax.accessibility.Accessible;
import org.netbeans.swing.tabcontrol.event.TabActionEvent;
import org.netbeans.swing.tabcontrol.plaf.DefaultTabbedContainerUI;

import javax.swing.*;
import java.awt.*;
import java.awt.event.AWTEventListener;
import java.awt.event.ActionListener;
Expand All @@ -32,8 +27,12 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleRole;
import javax.swing.*;
import javax.swing.JComponent.AccessibleJComponent;
import org.netbeans.swing.tabcontrol.event.TabActionEvent;
import org.netbeans.swing.tabcontrol.plaf.DefaultTabbedContainerUI;
import org.openide.util.NbBundle;


Expand Down Expand Up @@ -192,6 +191,8 @@ public class TabbedContainer extends JComponent implements Accessible {
public static final String COMMAND_CLOSE_ALL = "closeAll"; //NOI18N

public static final String COMMAND_CLOSE_ALL_BUT_THIS = "closeAllButThis"; //NOI18N

public static final String COMMAND_CLOSE_RIGHT = "closeRight"; //NOI18N

public static final String COMMAND_ENABLE_AUTO_HIDE = "enableAutoHide"; //NOI18N

Expand Down