private DartKeyBindingPersistence getBindingPersist() {
   IWorkbench workbench = PlatformUI.getWorkbench();
   IActivityManager act = workbench.getActivitySupport().getActivityManager();
   IBindingService bind = (IBindingService) workbench.getService(IBindingService.class);
   ICommandService cmd = (ICommandService) workbench.getService(ICommandService.class);
   DartKeyBindingPersistence persist = new DartKeyBindingPersistence(act, bind, cmd);
   return persist;
 }
Esempio n. 2
0
  @Override
  public void earlyStartup() {
    final IWorkbench workbench = PlatformUI.getWorkbench();

    // listen for save file events
    ICommandService commandService = (ICommandService) workbench.getService(ICommandService.class);
    executionListener = new CustomExecutionListener();
    commandService.addExecutionListener(executionListener);

    workbench
        .getDisplay()
        .asyncExec(
            new Runnable() {
              public void run() {
                IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
                if (window == null) return;

                // setup config file parsing
                MenuHandler handler = new MenuHandler();
                DEBUG = handler.getDebug();

                // prompt for apiKey if not set
                String apiKey = handler.getApiKey();
                if (apiKey == "") {
                  handler.promptForApiKey(window);
                }

                Dependencies deps = new Dependencies();

                if (!deps.isPythonInstalled()) {
                  deps.installPython();
                  if (!deps.isPythonInstalled()) {
                    MessageDialog dialog =
                        new MessageDialog(
                            window.getShell(),
                            "Warning!",
                            null,
                            "WakaTime needs Python installed. Please install Python from python.org/downloads, then restart Eclipse.",
                            MessageDialog.WARNING,
                            new String[] {IDialogConstants.OK_LABEL},
                            0);
                    dialog.open();
                  }
                }
                if (!deps.isCLIInstalled()) {
                  deps.installCLI();
                }

                if (window.getPartService() == null) return;

                // listen for caret movement
                if (window.getPartService().getActivePartReference() != null
                    && window.getPartService().getActivePartReference().getPage() != null
                    && window.getPartService().getActivePartReference().getPage().getActiveEditor()
                        != null) {
                  IEditorPart part =
                      window.getPartService().getActivePartReference().getPage().getActiveEditor();
                  if (!(part instanceof AbstractTextEditor)) return;
                  ((StyledText) part.getAdapter(Control.class))
                      .addCaretListener(new CustomCaretListener());
                }

                // listen for change of active file
                window.getPartService().addPartListener(editorListener);

                if (window.getPartService().getActivePart() == null) return;
                if (window.getPartService().getActivePart().getSite() == null) return;
                if (window.getPartService().getActivePart().getSite().getPage() == null) return;
                if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor()
                    == null) return;
                if (window
                        .getPartService()
                        .getActivePart()
                        .getSite()
                        .getPage()
                        .getActiveEditor()
                        .getEditorInput()
                    == null) return;

                // log file if one is opened by default
                IEditorInput input =
                    window
                        .getPartService()
                        .getActivePart()
                        .getSite()
                        .getPage()
                        .getActiveEditor()
                        .getEditorInput();
                if (input instanceof IURIEditorInput) {
                  URI uri = ((IURIEditorInput) input).getURI();
                  if (uri != null && uri.getPath() != null) {
                    String currentFile = uri.getPath();
                    long currentTime = System.currentTimeMillis() / 1000;
                    if (!currentFile.equals(WakaTime.getDefault().lastFile)
                        || WakaTime.getDefault().lastTime + WakaTime.FREQUENCY * 60 < currentTime) {
                      WakaTime.logFile(currentFile, WakaTime.getActiveProject(), false);
                      WakaTime.getDefault().lastFile = currentFile;
                      WakaTime.getDefault().lastTime = currentTime;
                    }
                  }
                }

                WakaTime.log(
                    "Finished initializing WakaTime plugin (https://wakatime.com) v" + VERSION);
              }
            });
  }