forked from microsoft/copilot-for-eclipse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWhatsNewAction.java
More file actions
61 lines (49 loc) · 2.24 KB
/
Copy pathWhatsNewAction.java
File metadata and controls
61 lines (49 loc) · 2.24 KB
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
59
60
61
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package com.microsoft.copilot.eclipse.ui.actions;
import java.util.Properties;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.NotEnabledException;
import org.eclipse.core.commands.NotHandledException;
import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.intro.IIntroPart;
import org.eclipse.ui.intro.IIntroSite;
import org.eclipse.ui.intro.config.IIntroAction;
import com.microsoft.copilot.eclipse.core.CopilotCore;
import com.microsoft.copilot.eclipse.ui.UiConstants;
/**
* Action to show the "What's New" information in the Eclipse IDE. This action is typically triggered from the What's
* New section of the Welcome page.
*/
public class WhatsNewAction implements IIntroAction {
private static final String COMMAND = UiConstants.OPEN_WHATS_NEW_COMMAND_ID;
@Override
public void run(IIntroSite site, Properties params) {
closeWelcomePage();
Shell currentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
currentShell.getDisplay().asyncExec(() -> executeUpdateCommand(COMMAND));
}
void closeWelcomePage() {
IIntroPart introPart = PlatformUI.getWorkbench().getIntroManager().getIntro();
if (introPart != null) {
PlatformUI.getWorkbench().getIntroManager().closeIntro(introPart);
}
}
void executeUpdateCommand(String command) {
ICommandService commandService = PlatformUI.getWorkbench().getService(ICommandService.class);
IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
Command cmd = commandService.getCommand(command);
ExecutionEvent executionEvent = handlerService.createExecutionEvent(cmd, null);
try {
cmd.executeWithChecks(executionEvent);
} catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
CopilotCore.LOGGER.error("Failed to execute command: " + command, e);
}
}
}