📄 applicationactionbaradvisor.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;import org.eclipse.jface.action.IContributionItem;import org.eclipse.jface.action.ICoolBarManager;import org.eclipse.jface.action.IMenuManager;import org.eclipse.jface.action.IToolBarManager;import org.eclipse.jface.action.MenuManager;import org.eclipse.jface.action.Separator;import org.eclipse.jface.action.ToolBarManager;import org.eclipse.ui.IWorkbenchActionConstants;import org.eclipse.ui.IWorkbenchWindow;import org.eclipse.ui.actions.ActionFactory;import org.eclipse.ui.actions.ContributionItemFactory;import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;import org.eclipse.ui.application.ActionBarAdvisor;import org.eclipse.ui.application.IActionBarConfigurer;import com.s10r.manager.actions.CopyIdToClipboardAction;import com.s10r.manager.actions.CopyPasswordToClipboardAction;import com.s10r.manager.actions.CopyUrlToClipboardAction;import com.s10r.manager.actions.FilePropertiesAction;import com.s10r.manager.actions.MergeFileAction;import com.s10r.manager.actions.NewFileAction;import com.s10r.manager.actions.NewLabelAction;import com.s10r.manager.actions.NewPasswordEntryAction;import com.s10r.manager.actions.OpenFileAction;/** * An action bar advisor is responsible for creating, adding, and disposing of * the actions added to a workbench window. Each window will be populated with * new actions. */public class ApplicationActionBarAdvisor extends ActionBarAdvisor{ // Actions - important to allocate these only in makeActions, and then use // them // in the fill methods. This ensures that the actions aren't recreated // when fillActionBars is called with FILL_PROXY. private IWorkbenchAction exitAction; private IWorkbenchAction aboutAction; private IWorkbenchAction copyIdToClipboardAction; private IWorkbenchAction copyPasswordToClipboardAction; private IWorkbenchAction copyUrlToClipboardAction; private IWorkbenchAction deleteAction; private IWorkbenchAction importAction; private IWorkbenchAction exportAction; private IWorkbenchAction filePropertiesAction; private IWorkbenchAction saveAction; private IWorkbenchAction saveAsAction; private IWorkbenchAction saveAllAction; private IWorkbenchAction closeAction; private IWorkbenchAction closeAllAction; private IWorkbenchAction newFileAction; private IWorkbenchAction openFileAction; private IWorkbenchAction mergeFileAction; private IWorkbenchAction preferencesAction; private IWorkbenchAction newLabelAction; private IWorkbenchAction newPasswordEntryAction; private IWorkbenchWindow window; public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) { super(configurer); this.window = configurer.getWindowConfigurer().getWindow(); } protected void makeActions(final IWorkbenchWindow window) { // Creates the actions and registers them. // Registering is needed to ensure that key bindings work. // The corresponding commands keybindings are defined in the plugin.xml // file. // Registering also provides automatic disposal of the actions when // the window is closed. // this doesn't work well // and since I need to either create a new window // or a new entry I might as well create my own actions... // newAction = ActionFactory.NEW.create(window); // register(newAction); // 10/23/2006: forget the RCP new framework for now: newPasswordEntryAction = new NewPasswordEntryAction(window); register(newPasswordEntryAction); newLabelAction = new NewLabelAction(window); register(newLabelAction); newFileAction = new NewFileAction(window); register(newFileAction); openFileAction = new OpenFileAction(window); register(openFileAction); mergeFileAction = new MergeFileAction(window); // only enable when a file is open (action is registered as part listener) mergeFileAction.setEnabled(false); register(mergeFileAction); closeAction = ActionFactory.CLOSE.create(window); register(closeAction); closeAllAction = ActionFactory.CLOSE_ALL.create(window); register(closeAllAction); saveAction = ActionFactory.SAVE.create(window); register(saveAction); saveAsAction = ActionFactory.SAVE_AS.create(window); register(saveAsAction); saveAllAction = ActionFactory.SAVE_ALL.create(window); register(saveAllAction); preferencesAction = ActionFactory.PREFERENCES.create(window); register(preferencesAction); exitAction = ActionFactory.QUIT.create(window); register(exitAction); aboutAction = ActionFactory.ABOUT.create(window); register(aboutAction); importAction = ActionFactory.IMPORT.create(window); register(importAction); exportAction = ActionFactory.EXPORT.create(window); register(exportAction); filePropertiesAction = new FilePropertiesAction(window); register(filePropertiesAction); deleteAction = ActionFactory.DELETE.create(window); register(deleteAction); copyIdToClipboardAction = new CopyIdToClipboardAction(window); register(copyIdToClipboardAction); copyPasswordToClipboardAction = new CopyPasswordToClipboardAction( window); register(copyPasswordToClipboardAction); copyUrlToClipboardAction = new CopyUrlToClipboardAction(window); register(copyUrlToClipboardAction); } protected void fillMenuBar(IMenuManager menuBar) { MenuManager fileMenu = new MenuManager("&File", IWorkbenchActionConstants.M_FILE); MenuManager newMenu = new MenuManager("New", "New"); newMenu.add(newPasswordEntryAction); newMenu.add(newLabelAction); newMenu.add(newFileAction); fileMenu.add(newMenu); fileMenu.add(new Separator()); fileMenu.add(openFileAction); fileMenu.add(new Separator()); fileMenu.add(closeAction); fileMenu.add(closeAllAction); fileMenu.add(new Separator()); fileMenu.add(saveAction); fileMenu.add(saveAsAction); fileMenu.add(saveAllAction); fileMenu.add(new Separator()); fileMenu.add(mergeFileAction); // add back when import/export is implemented //fileMenu.add(new Separator()); //fileMenu.add(importAction); //fileMenu.add(exportAction); fileMenu.add(new Separator()); fileMenu.add(filePropertiesAction); fileMenu.add(new Separator()); fileMenu.add(exitAction); menuBar.add(fileMenu); MenuManager editMenu = new MenuManager("&Edit", "edit"); editMenu.add(copyIdToClipboardAction); editMenu.add(copyPasswordToClipboardAction); editMenu.add(copyUrlToClipboardAction); editMenu.add(new Separator()); editMenu.add(deleteAction); editMenu.add(new Separator()); editMenu.add(preferencesAction); menuBar.add(editMenu); MenuManager winMenuMgr = createWindowMenu(window); menuBar.add(winMenuMgr); MenuManager helpMenu = new MenuManager("&Help", "help"); helpMenu.add(aboutAction); menuBar.add(helpMenu); } private MenuManager createWindowMenu(IWorkbenchWindow window2) { // From: // http://dev.eclipse.org/newslists/news.eclipse.platform.rcp/msg12789.html MenuManager menu = new MenuManager("Window", IWorkbenchActionConstants.M_WINDOW); // overkill for a password manager: // menu.add(ActionFactory.OPEN_NEW_WINDOW.create(window)); menu.add(new Separator()); MenuManager perspectiveMenu = new MenuManager("Open Perspective", "openPerspective"); IContributionItem perspectiveList = ContributionItemFactory.PERSPECTIVES_SHORTLIST .create(window); perspectiveMenu.add(perspectiveList); menu.add(perspectiveMenu); MenuManager viewMenu = new MenuManager("Show View"); IContributionItem viewList = ContributionItemFactory.VIEWS_SHORTLIST .create(window); viewMenu.add(viewList); menu.add(viewMenu); menu.update(); return menu; } @Override protected void fillCoolBar(ICoolBarManager coolBar) { super.fillCoolBar(coolBar); IToolBarManager toolbar = new ToolBarManager(coolBar.getStyle()); coolBar.add(toolbar); toolbar.add(newFileAction); toolbar.add(newPasswordEntryAction); toolbar.add(newLabelAction); toolbar.add(new Separator()); // TODO for testing only, remove when imp/exp is completed toolbar.add(importAction); toolbar.add(exportAction); toolbar.add(new Separator()); toolbar.add(saveAction); toolbar.add(new Separator()); toolbar.add(copyIdToClipboardAction); toolbar.add(copyPasswordToClipboardAction); toolbar.add(copyUrlToClipboardAction); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -