blob: ce42e9a10dd2ded2e20fe464f47a7a4ac5b5f23c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
/*******************************************************************************
* Copyright (C) 2014 Robin Stocker <robin@nibor.org> and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
package org.eclipse.egit.ui.internal.actions;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IWorkbenchWindowPulldownDelegate;
/**
* Action for the "Stash" toolbar item, for stashing changes and listing
* existing stashes.
*/
public class StashToolbarAction extends RepositoryAction implements
IWorkbenchWindowPulldownDelegate {
private Menu menu;
private final StashesMenu stashesMenu = new StashesMenu();
/**
* Create the action
*/
public StashToolbarAction() {
super(ActionCommands.STASH_CREATE, new StashCreateHandler() {
/*
* We need to override this because the toolbar action and its menu
* have the same "enabled" state. The menu needs to be enabled even
* when creating a new stash is not currently possible.
*/
@Override
public boolean isEnabled() {
return getRepository() != null;
}
});
}
public Menu getMenu(Control parent) {
stashesMenu.initialize(getServiceLocator());
if (menu != null)
menu.dispose();
menu = new Menu(parent);
stashesMenu.fill(menu, 0);
return menu;
}
@Override
public void dispose() {
if (menu != null)
menu.dispose();
super.dispose();
}
}
|