📄 copyidtoclipboardaction.java
字号:
/*
* Copyright 2006 Marcel Schoffelmeer
*
* 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 com.s10r.manager.actions;
import org.eclipse.jface.action.IAction;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import com.s10r.manager.Application;
import com.s10r.manager.model.PasswordEntry;
import com.s10r.util.ClipboardUtil;
/**
* @author schoffem
*/
public class CopyIdToClipboardAction extends PasswordEntryAction implements
IWorkbenchAction, IObjectActionDelegate
{
public final static String ID = "manager_rcp.copyIdToClipboard";
public CopyIdToClipboardAction()
{
}
public CopyIdToClipboardAction(IWorkbenchWindow window)
{
super(window);
setId(ID);
setText("Copy Id To Clipboard");
setToolTipText("Copy Id To Clipboard");
// setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
setImageDescriptor(AbstractUIPlugin.imageDescriptorFromPlugin(
Application.PLUGIN_ID, "icons/user_go.png"));
}
@Override
public void run()
{
PasswordEntry entry = getSelectedPasswordEntry();
if (entry != null)
{
if (entry.getId() != null && entry.getId().length() > 0)
{
ClipboardUtil.copyTextToClipboard(getDisplay(), entry.getId());
entry.incUsageCount();
showStatusMessage("ID has been copied to the clipboard");
}
else
{
MessageBox mb = new MessageBox(window.getShell(),
SWT.ICON_ERROR);
mb.setText("Cannot copy ID to clipboard");
mb
.setMessage("Cannot copy the ID to the clipboard because "
+ "the ID of the selected password entry is empty. Use "
+ "the properties editor and set an ID for this password entry "
+ "before using this action.");
mb.open();
}
}
}
// popup run
public void run(IAction action)
{
run();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -