/* ###
 * IP: GHIDRA
 *
 * Licensed 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 ghidra.app.plugin.core.codebrowser.actions;

import docking.ActionContext;
import docking.action.MenuData;
import docking.tool.ToolConstants;
import ghidra.app.plugin.core.codebrowser.CodeViewerActionContext;
import ghidra.app.plugin.core.codebrowser.CodeViewerProvider;
import ghidra.app.util.HelpTopics;
import ghidra.program.util.ProgramSelection;
import ghidra.util.HelpLocation;

/**
 * Action for changing the selection to the complement of all the currently 
 * selected addresses and restricting this new selection to the current view.
 */
public class SelectComplementAction extends CodeViewerContextAction {

	public SelectComplementAction(String owner) {
		super("Select Complement", owner);

		// this is in the main tool menu, so make it a tool action
		setSupportsDefaultToolContext(true);

		setMenuBarData(new MenuData(
			new String[] { ToolConstants.MENU_SELECTION, "&Complement" },
			null,
			"Select"));

		setEnabled(false);
		setHelpLocation(new HelpLocation(HelpTopics.SELECTION, getName()));
	}

	@Override
	public void actionPerformed(ActionContext context) {
		CodeViewerProvider provider = (CodeViewerProvider) context.getComponentProvider();
		provider.selectComplement();
	}

	@Override
	public boolean isEnabledForContext(CodeViewerActionContext context) {
		ProgramSelection selection = context.getSelection();
		if (selection != null && selection.getInteriorSelection() != null) {
			return false;
		}
		return true;
	}
}
