com.intellij.openapi.ui.DialogWrapper Java Examples

The following examples show how to use com.intellij.openapi.ui.DialogWrapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Panel.java    From GitCommitMessage with Apache License 2.0 6 votes vote down vote up
Panel(Project project) {

        String branch = CommitMessage.extractBranchName(project);
        if (branch != null) {
            // Branch name  matches Ticket Name
            setTextFieldsBasedOnBranch(branch, project);
        }

        changeTemplateButton.addActionListener(e -> {
            DialogWrapper dialog = createTemplateDialog(project);
            if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
                dialog.getExitCode();
            }

        });
    }
 
Example #2
Source File: NewStoryboardAction.java    From robovm-idea with GNU General Public License v2.0 6 votes vote down vote up
public void actionPerformed(AnActionEvent e) {
    if(module == null) {
        return;
    }

    VirtualFile file = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
    final NewStoryboardDialog dialog = new NewStoryboardDialog(e.getProject(), new File(file.getCanonicalPath()));
    dialog.show();
    if(dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
        IBIntegratorProxy proxy = IBIntegratorManager.getInstance().getProxy(module);
        if(proxy == null) {
            RoboVmPlugin.logError(e.getProject(), "Couldn't get interface builder integrator for module %s", module.getName());
        } else {
            File resourceDir = new File(file.getCanonicalPath());
            proxy.newIOSStoryboard(dialog.getStoryboardName(), resourceDir);
            VirtualFile vsfFile = VfsUtil.findFileByIoFile(resourceDir, true);
            vsfFile.refresh(false, true);
        }
    }
}
 
Example #3
Source File: CreateIpaAction.java    From robovm-idea with GNU General Public License v2.0 6 votes vote down vote up
public void actionPerformed(final AnActionEvent e) {
    final CreateIpaDialog dialog = new CreateIpaDialog(e.getProject());
    dialog.show();
    if(dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
        // create IPA
        IpaConfig ipaConfig = dialog.getIpaConfig();
        CompileScope scope = CompilerManager.getInstance(e.getProject()).createModuleCompileScope(ipaConfig.module, true);
        scope.putUserData(IPA_CONFIG_KEY, ipaConfig);
        CompilerManager.getInstance(e.getProject()).compile(scope, new CompileStatusNotification() {
            @Override
            public void finished(boolean aborted, int errors, int warnings, CompileContext compileContext) {
                RoboVmPlugin.logInfo(e.getProject(), "IPA creation complete, %d errors, %d warnings", errors, warnings);
            }
        });
    }
}
 
Example #4
Source File: CreatePatchFromChangesAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void createPatch(Project project, String commitMessage, List<Change> changeCollection) {
  project = project == null ? ProjectManager.getInstance().getDefaultProject() : project;
  final CreatePatchCommitExecutor executor = CreatePatchCommitExecutor.getInstance(project);
  CommitSession commitSession = executor.createCommitSession();
  if (commitSession instanceof CommitSessionContextAware) {
    ((CommitSessionContextAware)commitSession).setContext(new CommitContext());
  }
  DialogWrapper sessionDialog = new SessionDialog(executor.getActionText(),
                                                  project,
                                                  commitSession,
                                                  changeCollection,
                                                  commitMessage);
  sessionDialog.show();
  if (!sessionDialog.isOK()) {
    return;
  }
  preloadContent(project, changeCollection);

  commitSession.execute(changeCollection, commitMessage);
}
 
Example #5
Source File: ConfigureANTLRAction.java    From intellij-plugin-v4 with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
	if ( e.getProject()==null ) {
		LOG.error("actionPerformed no project for "+e);
		return; // whoa!
	}
	VirtualFile grammarFile = MyActionUtils.getGrammarFileFromEvent(e);
	if ( grammarFile==null ) return;
	LOG.info("actionPerformed "+grammarFile);

	ConfigANTLRPerGrammar configDialog = ConfigANTLRPerGrammar.getDialogForm(e.getProject(), grammarFile.getPath());
	configDialog.getPeer().setTitle("Configure ANTLR Tool "+ Tool.VERSION+" for "+ grammarFile.getName());

	configDialog.show();

	if ( configDialog.getExitCode()==DialogWrapper.OK_EXIT_CODE ) {
		configDialog.saveValues(e.getProject(), grammarFile.getPath());
	}
}
 
Example #6
Source File: CreateFromTemplateDialog.java    From consulo with Apache License 2.0 6 votes vote down vote up
public PsiElement create() {
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    doCreate(myTemplate.getName() + "." + myTemplate.getExtension());
    Disposer.dispose(getDisposable());
    return myCreatedElement;
  }
  if (myAttrPanel != null) {
    if (myAttrPanel.hasSomethingToAsk()) {
      show();
      return myCreatedElement;
    }
    doCreate(null);
  }
  close(DialogWrapper.OK_EXIT_CODE);
  return myCreatedElement;
}
 
Example #7
Source File: ArchiveDiffTool.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean canShow(DiffRequest request) {
  final DiffContent[] contents = request.getContents();
  final DialogWrapper instance = DialogWrapper.findInstance(IdeFocusManager.getInstance(request.getProject()).getFocusOwner());
  if (instance != null && instance.isModal()) return false;
  if (contents.length == 2) {
    final VirtualFile file1 = contents[0].getFile();
    final VirtualFile file2 = contents[1].getFile();
    if (file1 != null && file2 != null) {
      final FileType type1 = contents[0].getContentType();
      final FileType type2 = contents[1].getContentType();
      return type1 == type2 && type1 instanceof ArchiveFileType;
    }
  }
  return false;
}
 
Example #8
Source File: DesktopColorPicker.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void showDialog(Component parent,
                              String caption,
                              Color preselectedColor,
                              boolean enableOpacity,
                              ColorPickerListener[] listeners,
                              boolean opacityInPercent,
                              @Nonnull java.util.function.Consumer<Color> colorConsumer) {
  final ColorPickerDialog dialog = new ColorPickerDialog(parent, caption, preselectedColor, enableOpacity, listeners, opacityInPercent);
  SwingUtilities.invokeLater(() -> {
    dialog.show();

    if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
      colorConsumer.accept(dialog.getColor());
    }
    else {
      colorConsumer.accept(null);
    }
  });
}
 
Example #9
Source File: NavBarListener.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void processFocusLost(FocusEvent e) {
  final Component opposite = e.getOppositeComponent();

  if (myPanel.isInFloatingMode() && opposite != null && DialogWrapper.findInstance(opposite) != null) {
    myPanel.hideHint();
    return;
  }

  final boolean nodePopupInactive = !myPanel.isNodePopupActive();
  boolean childPopupInactive = !JBPopupFactory.getInstance().isChildPopupFocused(myPanel);
  if (nodePopupInactive && childPopupInactive) {
    if (opposite != null && opposite != myPanel && !myPanel.isAncestorOf(opposite) && !e.isTemporary()) {
      myPanel.setContextComponent(null);
      myPanel.hideHint();
    }
  }

  myPanel.updateItems();
}
 
Example #10
Source File: GlassPaneDialogWrapperPeer.java    From consulo with Apache License 2.0 6 votes vote down vote up
private MyDialog(IdeGlassPaneEx pane, DialogWrapper wrapper, Project project) {
      setLayout(new BorderLayout());
      setOpaque(false);
      setBorder(BorderFactory.createEmptyBorder(AllIcons.Ide.Shadow.Top.getIconHeight(), AllIcons.Ide.Shadow.Left.getIconWidth(), AllIcons.Ide.Shadow.Bottom.getIconHeight(),
                                                AllIcons.Ide.Shadow.Right.getIconWidth()));

      myPane = pane;
      myDialogWrapper = new WeakReference<>(wrapper);
//      myProject = new WeakReference<Project>(project);

      myRootPane = new MyRootPane(this); // be careful with DialogWrapper.dispose()!
      Disposer.register(this, myRootPane);

      myContentPane = new JPanel();
      myContentPane.setOpaque(true);
      add(myContentPane, BorderLayout.CENTER);

      myTransparentPane = createTransparentPane();

      myWrapperPane = createWrapperPane();
      myWrapperPane.add(this);

      setFocusCycleRoot(true);
    }
 
Example #11
Source File: RNUpgradeAction.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public boolean beforeAction() {
    String exePath = RNPathUtil.getExecuteFileFullPath(EXEC);

    if (exePath == null || EXEC.equals(RNPathUtil.getExecuteFileFullPath(EXEC))) {
        int options = Messages.showIdeaMessageDialog(getProject(),
                "Would you like to install " + EXEC + " globally now?\n" +
                        "This might take one or two minutes without any console update, please wait for the final result.\n" +
                        "After that, you'll need to click this button again.",
                "Can Not Found " + EXEC, new String[]{"Yes", "No"}, 0,
                AllIcons.General.QuestionDialog, new DialogWrapper.DoNotAskOption.Adapter() {
                    @Override
                    public void rememberChoice(boolean b, int i) {

                    }
                });
        if (options == 0) {
            cmd = INSTALL_CMD;
            return true;
        } else {
            RNConsole consoleView = terminal.getRNConsole(getText(), getIcon());

            if (consoleView != null) {
                consoleView.clear();
                consoleView.print(
                        "Can't found " + EXEC + ", if you were first running this command, make sure you have " + EXEC + " installed globally.\n" +
                                "To install, please run in terminal with command: \n" +
                                INSTALL_CMD +
                                "\n\n",
                        ConsoleViewContentType.ERROR_OUTPUT);

            }
            return false;
        }

    }

    cmd = EXEC;
    return true;
}
 
Example #12
Source File: ReactDevToolsAction.java    From react-native-console with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
    public boolean beforeAction() {
        String exePath = RNPathUtil.getExecuteFileFullPath(EXEC);
        if (exePath == null || EXEC.equals(RNPathUtil.getExecuteFileFullPath(EXEC))) {
//            GlobalPropertyBasedDoNotAskOption dontAsk = new GlobalPropertyBasedDoNotAskOption("react-devtools.to.show"); // TODO no use so far
            int options = Messages.showIdeaMessageDialog(getProject(),
                    "Would you like to install react-devtools globally now?\n" +
                            "This might take one or two minutes without any console update, please wait for the final result.\n" +
                            "After that, you'll need to click this button again.",
                    "Can Not Found React-Devtools", new String[]{"Yes", "No"}, 0,
                    AllIcons.General.QuestionDialog, new DialogWrapper.DoNotAskOption.Adapter() {
                        @Override
                        public void rememberChoice(boolean b, int i) {

                        }
                    });
            if (options == 0) {
                cmd = "npm install -g react-devtools";
                return true;
            } else {
                RNConsole consoleView = terminal.getRNConsole(getText(), getIcon());

                if (consoleView != null) {
                    consoleView.clear();
                    consoleView.print(
                            "Can't found " + EXEC + ", if you were first running this command, make sure you have react-devtools installed globally.\n" +
                                    "To install by yourself, please run in terminal with command: \n" +
                                    "npm install -g react-devtools\n\n",
                            ConsoleViewContentType.ERROR_OUTPUT);

                }
                return false;
            }

        }

        cmd = EXEC;
        return true;
    }
 
Example #13
Source File: CreateCommitAction.java    From commit-template-idea-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent actionEvent) {
    final CommitMessageI commitPanel = getCommitPanel(actionEvent);
    if (commitPanel == null)
        return;

    CommitDialog dialog = new CommitDialog(actionEvent.getProject());
    dialog.show();
    if (dialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
        commitPanel.setCommitMessage(dialog.getCommitMessage().toString());
    }
}
 
Example #14
Source File: Panel.java    From GitCommitMessage with Apache License 2.0 5 votes vote down vote up
public DialogWrapper createTemplateDialog(Project project) {
    Template template = new Template(project);

    DialogBuilder builder = new DialogBuilder(project);
    builder.setTitle("Git / Hg Mercurial Commit Message Template.");
    builder.setCenterPanel(template.getMainPanel());
    builder.removeAllActions();
    builder.addOkAction();
    builder.addCancelAction();
    boolean isOk = builder.show() == DialogWrapper.OK_EXIT_CODE;
    if (isOk) {
        TemplateFileHandler.storeFile(project, template.getTemplateContent());
    }
    return builder.getDialogWrapper();
}
 
Example #15
Source File: RefactoringDialog.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected void invokeRefactoring(BaseRefactoringProcessor processor) {
  final Runnable prepareSuccessfulCallback = new Runnable() {
    @Override
    public void run() {
      close(DialogWrapper.OK_EXIT_CODE);
    }
  };
  processor.setPrepareSuccessfulSwingThreadCallback(prepareSuccessfulCallback);
  processor.setPreviewUsages(isPreviewUsages());
  processor.run();
}
 
Example #16
Source File: DecryptPropertyAction.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
    final Project project = (Project) anActionEvent.getData(CommonDataKeys.PROJECT);

    PsiFile psiFile = anActionEvent.getData(CommonDataKeys.PSI_FILE);

    IProperty selectedProperty = getSelectedProperty(anActionEvent.getDataContext());

    final EncryptDialog form = new EncryptDialog();
    form.setTitle("Decrypt Property: " + selectedProperty.getKey());
    form.show();
    boolean isOk = form.getExitCode() == DialogWrapper.OK_EXIT_CODE;

    logger.debug("**** ALGORITHM " + form.getAlgorithm().getSelectedItem());
    logger.debug("**** MODE " + form.getMode().getSelectedItem());

    if (isOk) {
        new WriteCommandAction.Simple(project, psiFile) {
            @Override
            protected void run() throws Throwable {
                EncryptionAlgorithm algorithm = (EncryptionAlgorithm) form.getAlgorithm().getSelectedItem();
                EncryptionMode mode = (EncryptionMode) form.getMode().getSelectedItem();

                try {
                    String originalValue = selectedProperty.getValue();
                    String encryptedProperty = originalValue.substring(2, originalValue.length() - 1);

                    byte[] decryptedBytes = algorithm.getBuilder().forKey(form.getEncryptionKey().getText()).using(mode)
                            .build().decrypt(Base64.decode(encryptedProperty));

                    selectedProperty.setValue(new String(decryptedBytes));
                } catch (Exception e) {
                    Notification notification = MuleUIUtils.MULE_NOTIFICATION_GROUP.createNotification("Unable to decrypt property",
                            "Property '" + selectedProperty.getKey() + "' cannot be decrypted : " + e, NotificationType.ERROR, null);
                    Notifications.Bus.notify(notification, project);
                }
            }
        }.execute();
    }
}
 
Example #17
Source File: BaseAction.java    From ADB-Duang with MIT License 5 votes vote down vote up
private static DeviceResult askUserForDevice(AnActionEvent anActionEvent, AndroidFacet facet, String packageName) {
    final DeviceChooserDialog chooser = new DeviceChooserDialog(facet);
    chooser.show();

    if (chooser.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
        return null;
    }

    IDevice[] selectedDevices = chooser.getSelectedDevices();
    if (selectedDevices.length == 0) {
        return null;
    }

    return new DeviceResult(anActionEvent, selectedDevices[0], facet, packageName);
}
 
Example #18
Source File: BaseDialog.java    From PackageTemplates with Apache License 2.0 5 votes vote down vote up
@Override
public void show() {
    preShow();
    super.show();

    switch (getExitCode()) {
        case DialogWrapper.OK_EXIT_CODE:
            onOKAction();
            break;
        case DialogWrapper.CANCEL_EXIT_CODE:
            onCancelAction();
            break;
    }
}
 
Example #19
Source File: RenderingOptionsForm.java    From markdown-doclet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    DialogBuilder dialogBuilder = new DialogBuilder((Component)e.getSource());
    dialogBuilder.setTitle("Markdown Javadoc Rendering Options");
    dialogBuilder.addOkAction();
    dialogBuilder.addCancelAction();
    RenderingOptionsForm form = new RenderingOptionsForm(options.renderingOptions);
    dialogBuilder.setCenterPanel(form.getComponent());
    int exitCode = dialogBuilder.show();
    if (exitCode == DialogWrapper.OK_EXIT_CODE) {
        options.renderingOptions = form.get();
    }
}
 
Example #20
Source File: ModuleDependencyTabContext.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public List<OrderEntry> createOrderEntries(@Nonnull ModifiableModuleRootLayer layer, DialogWrapper dialogWrapper) {
  Object[] selectedValues = myModuleList.getSelectedValues();
  List<OrderEntry> orderEntries = new ArrayList<OrderEntry>(selectedValues.length);
  for (Object selectedValue : selectedValues) {
    orderEntries.add(layer.addModuleOrderEntry((Module)selectedValue));
  }
  return orderEntries;
}
 
Example #21
Source File: UsingReportAction.java    From freeline with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent event) {
    final Project project = event.getProject();
    Module[] modules = ModuleManager.getInstance(project).getModules();
    List<Pair<Module, PsiFile>> selectModulesList = new ArrayList<Pair<Module, PsiFile>>();
    for (Module module : modules) {
        GradleBuildFile file = GradleBuildFile.get(module);
        if (file != null && !GradleUtil.isLibrary(file)) {
            selectModulesList.add(Pair.create(module, file.getPsiFile()));
        }
    }

    if (selectModulesList.size() > 1) {
        final DialogBuilder builder = new DialogBuilder();
        builder.setTitle("Freeline Reporter");
        builder.resizable(false);
        builder.setCenterPanel(new JLabel("There are multiple application modules, Please select the exact one.",
                Messages.getInformationIcon(), SwingConstants.CENTER));
        builder.addOkAction().setText("Cancel");
        for (final Pair<Module, PsiFile> pair : selectModulesList) {
            builder.addAction(new AbstractAction(":" + pair.first.getName()) {
                @Override
                public void actionPerformed(ActionEvent e) {
                    builder.getDialogWrapper().close(DialogWrapper.CANCEL_EXIT_CODE);
                    report(project, pair.getSecond());
                }
            });
        }
        if (builder.show() > -1) {
            //return false;
        }
    } else if (selectModulesList.size() == 1) {
        report(project, selectModulesList.get(0).getSecond());
    }
}
 
Example #22
Source File: SyncDirectoriesWarning.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** Warns the user that sources may not resolve. Returns false if sync should be aborted. */
public static boolean warn(Project project) {
  if (warningSuppressed()) {
    return true;
  }
  String buildSystem = Blaze.buildSystemName(project);
  String message =
      String.format(
          "Syncing without a %s build will result in unresolved symbols "
              + "in your source files.<p>This can be useful for quickly adding directories to "
              + "your project, but if you're seeing sources marked as '(unsynced)', run a normal "
              + "%<s sync to fix it.",
          buildSystem);
  String title = String.format("Syncing without a %s build", buildSystem);
  DialogWrapper.DoNotAskOption dontAskAgain =
      new DialogWrapper.DoNotAskOption.Adapter() {
        @Override
        public void rememberChoice(boolean isSelected, int exitCode) {
          if (isSelected) {
            suppressWarning();
          }
        }

        @Override
        public String getDoNotShowMessage() {
          return "Don't warn again";
        }
      };
  int result =
      Messages.showOkCancelDialog(
          project,
          XmlStringUtil.wrapInHtml(message),
          title,
          "Run Sync",
          "Cancel",
          Messages.getWarningIcon(),
          dontAskAgain);
  return result == Messages.OK;
}
 
Example #23
Source File: DialogWrapperPeerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private DialogWrapper getActiveWrapper() {
  DialogWrapper activeWrapper = getDialogWrapper();
  if (activeWrapper == null || !activeWrapper.isShowing()) {
    return null;
  }

  return activeWrapper;
}
 
Example #24
Source File: LayoutAction.java    From android-codegenerator-plugin-intellij with Apache License 2.0 5 votes vote down vote up
private void showCodeDialog(AnActionEvent event, final Project project, final VirtualFile selectedFile, Settings settings) throws ParserConfigurationException, SAXException, XPathExpressionException, IOException {
    CodeGeneratorController codeGeneratorController = new CodeGeneratorController(getTemplateName(), getResourceProvidersFactory());
    String generatedCode = codeGeneratorController.generateCode(project, selectedFile, event.getData(PlatformDataKeys.EDITOR));
    final CodeDialogBuilder codeDialogBuilder = new CodeDialogBuilder(project,
            String.format(StringResources.TITLE_FORMAT_TEXT, selectedFile.getName()), generatedCode);
    codeDialogBuilder.addSourcePathSection(projectHelper.getSourceRootPathList(project, event), settings.getSourcePath());
    codeDialogBuilder.addPackageSection(packageHelper.getPackageName(project, event));
    codeDialogBuilder.addAction(StringResources.COPY_ACTION_LABEL, new Runnable() {
        @Override
        public void run() {
            ClipboardHelper.copy(getFinalCode(codeDialogBuilder));
            codeDialogBuilder.closeDialog();
        }
    });
    codeDialogBuilder.addAction(StringResources.CREATE_ACTION_LABEL, new Runnable() {
        @Override
        public void run() {
            try {
                createFileWithGeneratedCode(codeDialogBuilder, selectedFile, project);
            } catch (IOException exception) {
                errorHandler.handleError(project, exception);
            }
        }
    }, true);
    if (codeDialogBuilder.showDialog() == DialogWrapper.OK_EXIT_CODE) {
        settings.setSourcePath(codeDialogBuilder.getSourcePath());
    }
}
 
Example #25
Source File: DialogWrapperPeerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void createDialog(@Nullable Window owner, boolean canBeParent, @Nonnull DialogWrapper.IdeModalityType ideModalityType) {
  if (isHeadless()) {
    myDialog = new HeadlessDialog(myWrapper);
  }
  else {
    ActionCallback focused = new ActionCallback("DialogFocusedCallback");

    myDialog = new MyDialog(owner, myWrapper, myProject, focused);

    myDialog.setModalityType(ideModalityType.toAwtModality());

    myCanBeParent = canBeParent;
  }
}
 
Example #26
Source File: PopupChoiceAction.java    From StringManipulation with Apache License 2.0 5 votes vote down vote up
public static boolean isFromDialog(Project project) {
	final Component owner = IdeFocusManager.getInstance(project).getFocusOwner();
	if (owner != null) {
		final DialogWrapper instance = DialogWrapper.findInstance(owner);
		return instance != null;
	}
	return false;
}
 
Example #27
Source File: CppOverrideImplementMethodHandler.java    From CppTools with Apache License 2.0 5 votes vote down vote up
private void proceedWithChoosingMethods(Project project, PsiFile file, final Editor editor,
                                        List<CppMethodElementNode> candidates, boolean override) {
  final MemberChooser<CppMethodElementNode> chooser = new MemberChooser<CppMethodElementNode>(
    candidates.toArray(new CppMethodElementNode[candidates.size()]), false, true, project, false
  ) {
  };

  chooser.setTitle("Choose Methods to " + (override ? "Override":"Implement"));
  chooser.setCopyJavadocVisible(false);
  chooser.show();
  if (chooser.getExitCode() != DialogWrapper.OK_EXIT_CODE) return;
  final List<CppMethodElementNode> selectedElements = chooser.getSelectedElements();
  if (selectedElements == null || selectedElements.size() == 0) return;

  CommandProcessor.getInstance().executeCommand(project, new Runnable() {
    public void run() {
      ApplicationManager.getApplication().runWriteAction(new Runnable() {
        public void run() {
          Document document = editor.getDocument();
          int offset = editor.getCaretModel().getOffset();

          for(CppMethodElementNode c:selectedElements) {
            String cType = c.getType();
            String methodText = "virtual " + cType + " " + c.getText() + " {\n" +
              (!"void".equals(cType) ? "return ":"") + (c.myIsAbstract ? "": c.getParentName() + "::" + c.myName + "(" + c.myParamNames + ");") + "\n" +
              "}\n";
            document.insertString(offset, methodText);
            offset += methodText.length();
          }
        }
      });
    }
  }, override ? "Override Methods":"Implement Methods", this);
}
 
Example #28
Source File: DialogWrapperPeerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @param parent parent component which is used to calculate heavy weight window ancestor.
 *               <code>parent</code> cannot be <code>null</code> and must be showing.
 */
protected DialogWrapperPeerImpl(@Nonnull DialogWrapper wrapper, @Nonnull Component parent, final boolean canBeParent) {
  myWrapper = wrapper;

  myWindowManager = null;
  Application application = ApplicationManager.getApplication();
  if (application != null) {
    myWindowManager = (DesktopWindowManagerImpl)WindowManager.getInstance();
  }

  OwnerOptional.fromComponent(parent).ifWindow(window -> {
    createDialog(window, canBeParent);
  });
}
 
Example #29
Source File: ExtractSuperClassUtil.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
public static boolean showConflicts(DialogWrapper dialog, MultiMap<PsiElement, String> conflicts, final Project project) {
  if (!conflicts.isEmpty()) {
    fireConflictsEvent(conflicts, project);
    ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts);
    conflictsDialog.show();
    final boolean ok = conflictsDialog.isOK();
    if (!ok && conflictsDialog.isShowConflicts()) dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
    return ok;
  }
  return true;
}
 
Example #30
Source File: HaxePullUpHandler.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public boolean checkConflicts(final HaxePullUpDialog dialog) {
  final List<MemberInfo> infos = dialog.getSelectedMemberInfos();
  final MemberInfo[] memberInfos = infos.toArray(new MemberInfo[infos.size()]);
  final PsiClass superClass = dialog.getSuperClass();
  if (!checkWritable(superClass, memberInfos)) return false;
  final MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>();
  if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
    @Override
    public void run() {
      ApplicationManager.getApplication().runReadAction(new Runnable() {
        @Override
        public void run() {
          //final PsiDirectory targetDirectory = superClass.getContainingFile().getContainingDirectory();
          //final PsiPackage targetPackage = targetDirectory != null ? JavaDirectoryService.getInstance().getPackage(targetDirectory) : null;
          //conflicts
          //  .putAllValues(PullUpConflictsUtil.checkConflicts(memberInfos, mySubclass, superClass, targetPackage, targetDirectory,
          //                                                   dialog.getContainmentVerifier()));
        }
      });
    }
  }, RefactoringBundle.message("detecting.possible.conflicts"), true, myProject)) return false;
  if (!conflicts.isEmpty()) {
    ConflictsDialog conflictsDialog = new ConflictsDialog(myProject, conflicts);
    conflictsDialog.show();
    final boolean ok = conflictsDialog.isOK();
    if (!ok && conflictsDialog.isShowConflicts()) dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
    return ok;
  }
  return true;
}