Example #1
0
 private void copyToClipboard(Clipboard clipboard) {
   if (macroList.selectedItem() != null) {
     clipboard.setText(macroList.selectedItem().asCli());
     Tooltip tooltip = Tooltip.element(copyToClipboard);
     tooltip
         .hide()
         .setTitle(resources.constants().copied())
         .show()
         .onHide(() -> tooltip.setTitle(resources.constants().copyToClipboard()));
     Browser.getWindow().setTimeout(tooltip::hide, 1000);
   }
 }
Example #2
0
 @Override
 public void setMacros(Iterable<Macro> macros) {
   Elements.setVisible(empty.asElement(), false);
   for (Element element : elements) {
     Elements.setVisible(element, true);
   }
   macroList.setItems(macros);
 }
Example #3
0
  @Inject
  public MacroEditorView(Resources resources) {
    this.resources = resources;

    empty =
        new EmptyState.Builder(resources.constants().noMacros())
            .icon(CSS.fontAwesome("dot-circle-o"))
            .description(
                resources.messages().noMacrosDescription(resources.constants().startMacro()))
            .build();
    empty.asElement().getClassList().add(noMacros);

    macroList =
        new ListView<>(
            Ids.MACRO_LIST,
            macro ->
                new ItemDisplay<Macro>() {
                  @Override
                  public String getTitle() {
                    return macro.getName();
                  }

                  @Override
                  public String getDescription() {
                    return macro.getDescription();
                  }

                  @Override
                  public boolean stacked() {
                    return true;
                  }

                  @Override
                  public List<ItemAction<Macro>> actions() {
                    return Arrays.asList(
                        new ItemAction<Macro>(
                            PLAY_ACTION,
                            resources.constants().play(),
                            macro -> presenter.play(macro)),
                        new ItemAction<Macro>(
                            RENAME_ACTION,
                            resources.constants().rename(),
                            macro -> presenter.rename(macro)),
                        new ItemAction<Macro>(
                            REMOVE_ACTION,
                            resources.constants().remove(),
                            macro ->
                                DialogFactory.showConfirmation(
                                    resources
                                        .messages()
                                        .removeResourceConfirmationTitle(macro.getName()),
                                    resources
                                        .messages()
                                        .removeResourceConfirmationQuestion(macro.getName()),
                                    () -> presenter.remove(macro))));
                  }
                });
    macroList.onSelect(this::loadMacro);
    macroList.asElement().getClassList().add(CSS.macroList);

    Options editorOptions = new Options();
    editorOptions.readOnly = true;
    editorOptions.showGutter = true;
    editorOptions.showLineNumbers = true;
    editorOptions.showPrintMargin = false;
    editor = new AceEditor(Ids.MACRO_EDITOR, editorOptions);

    // @formatter:off
    Elements.Builder builder =
        new Elements.Builder()
            .div()
            .css(macroEditor)
            .button()
            .css(btn, btnDefault, copy)
            .data(UIConstants.TOGGLE, UIConstants.TOOLTIP)
            .data(UIConstants.PLACEMENT, "left") // NON-NLS
            .title(resources.constants().copyToClipboard())
            .rememberAs(COPY_TO_CLIPBOARD_ELEMENT)
            .span()
            .css(fontAwesome("clipboard"))
            .end()
            .end()
            .add(editor)
            .end();
    // @formatter:on

    Element editorContainer = builder.build();
    copyToClipboard = builder.referenceFor(COPY_TO_CLIPBOARD_ELEMENT);
    Clipboard clipboard = new Clipboard(copyToClipboard);
    clipboard.onCopy(event -> copyToClipboard(event.client));

    // @formatter:off
    elements =
        new LayoutBuilder()
            .row()
            .column(4)
            .add(macroList.asElement())
            .end()
            .column(8)
            .add(editorContainer)
            .end()
            .end()
            .elements();
    // @formatter:on

    registerAttachable(editor);
    initElements(Iterables.concat(singletonList(empty.asElement()), elements));
  }
Example #4
0
 @Override
 public void disableMacro(final Macro macro) {
   macroList.disableAction(macro, PLAY_ACTION);
   macroList.disableAction(macro, RENAME_ACTION);
   macroList.disableAction(macro, REMOVE_ACTION);
 }
Example #5
0
 @Override
 public void selectMacro(final Macro macro) {
   macroList.selectItem(macro);
 }
Example #6
0
 private void adjustHeight() {
   int height = max(Skeleton.applicationHeight() - 2 * MARGIN_BIG - 1, MIN_HEIGHT);
   macroList.asElement().getStyle().setHeight(height, PX);
   editor.asElement().getStyle().setHeight(height, PX);
   editor.getEditor().resize();
 }