List of usage examples for com.intellij.openapi.ui DialogBuilder DialogBuilder
public DialogBuilder()
From source file:consulo.devkit.module.library.ConsuloPluginLibraryType.java
License:Apache License
@Nullable @Override//from www . j a v a 2 s . c om public NewLibraryConfiguration createNewLibrary(@NotNull JComponent jComponent, @Nullable VirtualFile virtualFile, @NotNull Project project) { DialogBuilder builder = new DialogBuilder(); builder.title("Enter Plugin ID"); ChoosePluginPanel centerPanel = new ChoosePluginPanel(project); builder.centerPanel(centerPanel); builder.setPreferredFocusComponent(centerPanel.getTextField()); builder.dimensionKey("ConsuloPluginLibraryType#ChoosePluginPanel"); if (!builder.showAndGet()) { return null; } IdeaPluginDescriptor pluginDescriptor = centerPanel.getPluginDescriptor(); if (pluginDescriptor == null) { Messages.showErrorDialog(project, "Plugin is not found", ApplicationInfo.getInstance().getFullVersion()); return null; } Ref<VirtualFile> libRef = Ref.create(); String pluginId = pluginDescriptor.getPluginId().getIdString(); new Task.Modal(project, "Downloading plugin: " + pluginDescriptor.getPluginId().getIdString(), false) { @Override public void run(@NotNull ProgressIndicator progressIndicator) { String url = RepositoryHelper.buildUrlForDownload(UpdateSettings.getInstance().getChannel(), pluginId, null, true, false); try { File tempFile = FileUtil.createTempFile("download", "zip"); HttpRequests.request(url).saveToFile(tempFile, progressIndicator); File depDir = new File(project.getBasePath(), DEP_LIBRARY); depDir.mkdir(); ZipUtil.extract(tempFile, depDir, null); tempFile.delete(); libRef.set(LocalFileSystem.getInstance() .refreshAndFindFileByIoFile(new File(depDir, pluginId + "/lib"))); } catch (IOException e) { // } } }.queue(); VirtualFile libDirectory = libRef.get(); if (libDirectory == null) { Messages.showErrorDialog(project, "Plugin directory is not found", ApplicationInfo.getInstance().getFullVersion()); return null; } return new NewLibraryConfiguration(LIBRARY_PREFIX + pluginId, this, DummyLibraryProperties.INSTANCE) { @Override public void addRoots(@NotNull LibraryEditor libraryEditor) { for (VirtualFile file : libDirectory.getChildren()) { if (file.isDirectory()) { continue; } VirtualFile localVirtualFileByPath = ArchiveVfsUtil.getArchiveRootForLocalFile(file); if (localVirtualFileByPath == null) { continue; } libraryEditor.addRoot(localVirtualFileByPath, BinariesOrderRootType.getInstance()); } } }; }
From source file:io.github.holgerbrandl.send2terminal.connectors.AppleScriptConnector.java
License:BSD License
private static void submitCodeInternal(String codeSelection, boolean switchFocusToTerminal, @Nullable FileType fileType) {//w w w .j ava2 s. co m try { if (Utils.isMacOSX()) { Runtime runtime = Runtime.getRuntime(); boolean isKotlin = fileType != null && fileType.getName().toLowerCase().equals("kotlin"); boolean pasteModeRequired = isKotlin && Arrays.stream(codeSelection.split("\\r?\\n")).map(String::trim).anyMatch(s -> //is chained call or javadoc s.startsWith(".") || s.startsWith("*")); if (pasteModeRequired && !S2TSettings.getInstance().usePasteMode) { DialogBuilder builder = new DialogBuilder(); JLabel jLabel = new JLabel( "<html>Can not send multi-line expression to terminal. <br>Please vote for <a href='https://youtrack.jetbrains.net/issue/KT-13319'>KT-13319</a> to push for a REPL paste-mode.<br>Alternatively you could use kshell from <a href='https://github.com/khud/sparklin'>https://github.com/khud/sparklin</a> and enable the paste mode support in the preferences of this plugin</html>"); builder.centerPanel(jLabel); // builder.setDimensionServiceKey("GrepConsoleSound"); builder.setTitle("Multi-line Expression Error"); builder.removeAllActions(); builder.addOkAction(); // builder.addCancelAction(); builder.show(); return; } boolean usePasteMode = S2TSettings.getInstance().usePasteMode && isKotlin; // just use paste mode if any line starts with a dot usePasteMode = usePasteMode && pasteModeRequired; if (usePasteMode) { codeSelection = ":paste\n" + codeSelection; } String dquotesExpandedText = codeSelection.replace("\\", "\\\\"); dquotesExpandedText = dquotesExpandedText.replace("\"", "\\\""); // trim to remove tailing newline for blocks and especially line evaluation dquotesExpandedText = dquotesExpandedText.trim(); String evalTarget = S2TSettings.getInstance().codeSnippetEvalTarget; // String evalTarget = "R64"; // http://stackoverflow.com/questions/1870270/sending-commands-and-strings-to-terminal-app-with-applescript String evalSelection; if (evalTarget.equals("Terminal")) { // if (codeSelection.length() > 1000) { // DialogBuilder db = new DialogBuilder(); // db.setTitle("Operation canceled: "); // db.setCenterPanel(new JLabel("Can't paste more that 1024 characters to MacOS terminal.")); // db.addOkAction(); // db.show(); // // return; // } evalSelection = "tell application \"" + "Terminal" + "\" to do script \"" + dquotesExpandedText + "\" in window 0"; if (switchFocusToTerminal) { evalSelection = "tell application \"Terminal\" to activate\n" + evalSelection; } if (usePasteMode) { // https://stackoverflow.com/questions/3690167/how-can-one-invoke-a-keyboard-shortcut-from-within-an-applescript evalSelection = evalSelection + "\n" + "tell application \"System Events\"\n" + // " set currentApplication to name of 1st process whose frontmost is true\n" + // " set currentApplication to process appName\n" + " set currentApplication to path to frontmost application as text\n" + "end tell" + "\n" + // "delay 1\n" + "activate application \"Terminal\"\n" + "tell application \"System Events\"\n" + " keystroke \"d\" using {control down}\n" + "end tell\n" + "\n" + "activate application currentApplication\n"; // "activate \"Intellij IDEA\""; } } else if (evalTarget.equals("iTerm")) { evalSelection = "tell application \"iTerm\" to tell current session of current terminal to write text \"" + dquotesExpandedText + "\""; if (switchFocusToTerminal) { evalSelection = "tell application \"iTerm\" to activate\n" + evalSelection; } } else { if (switchFocusToTerminal) { evalSelection = "tell application \"" + evalTarget + "\" to activate\n" + "tell application \"" + evalTarget + "\" to cmd \"" + dquotesExpandedText + "\""; } else { evalSelection = "tell application \"" + evalTarget + "\" to cmd \"" + dquotesExpandedText + "\""; } } String[] args = { "osascript", "-e", evalSelection }; runtime.exec(args); } } catch (IOException e1) { ConnectorUtils.log.error(e1); } }