void newResB_actionPerformed(ActionEvent e) { AddResourceDialog dlg = new AddResourceDialog(App.getFrame(), Local.getString("New resource")); Dimension frmSize = App.getFrame().getSize(); Point loc = App.getFrame().getLocation(); dlg.setLocation( (frmSize.width - dlg.getSize().width) / 2 + loc.x, (frmSize.height - dlg.getSize().height) / 2 + loc.y); dlg.setVisible(true); if (dlg.CANCELLED) return; if (dlg.localFileRB.isSelected()) { String fpath = dlg.pathField.getText(); MimeType mt = MimeTypesList.getMimeTypeForFile(fpath); if (mt.getMimeTypeId().equals("__UNKNOWN")) { mt = addResourceType(fpath); if (mt == null) return; } if (!checkApp(mt)) return; // if file if projectFile, than copy the file and change url. if (dlg.projectFileCB.isSelected()) { fpath = copyFileToProjectDir(fpath); CurrentProject.getResourcesList().addResource(fpath, false, true); } else CurrentProject.getResourcesList().addResource(fpath); resourcesTable.tableChanged(); } else { if (!Util.checkBrowser()) return; CurrentProject.getResourcesList().addResource(dlg.urlField.getText(), true, false); resourcesTable.tableChanged(); } }
MimeType addResourceType(String fpath) { ResourceTypeDialog dlg = new ResourceTypeDialog(App.getFrame(), Local.getString("Resource type")); Dimension dlgSize = new Dimension(420, 300); dlg.setSize(dlgSize); Dimension frmSize = App.getFrame().getSize(); Point loc = App.getFrame().getLocation(); dlg.setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); dlg.ext = MimeTypesList.getExtension(fpath); dlg.setVisible(true); if (dlg.CANCELLED) return null; int ix = dlg.getTypesList().getSelectedIndex(); MimeType mt = (MimeType) MimeTypesList.getAllMimeTypes().toArray()[ix]; mt.addExtension(MimeTypesList.getExtension(fpath)); CurrentStorage.get().storeMimeTypesList(); return mt; }
void runApp(String fpath) { MimeType mt = MimeTypesList.getMimeTypeForFile(fpath); if (mt.getMimeTypeId().equals("__UNKNOWN")) { mt = addResourceType(fpath); if (mt == null) return; } if (!checkApp(mt)) return; String[] command = MimeTypesList.getAppList().getCommand(mt.getAppId(), fpath); if (command == null) return; /*DEBUG*/ System.out.println("Run: " + command[0]); try { Runtime.getRuntime().exec(command); } catch (Exception ex) { new ExceptionDialog( ex, "Failed to run an external application <br><code>" + command[0] + "</code>", "Check the application path and command line parameters for this resource type " + "(File->Preferences->Resource types)."); } }
public static void runBrowser(String url) { if (!checkBrowser()) return; String commandLine = MimeTypesList.getAppList().getBrowserExec() + " " + url; System.out.println("Run: " + commandLine); try { /*DEBUG*/ Runtime.getRuntime().exec(commandLine); } catch (Exception ex) { new ExceptionDialog( ex, "Failed to run an external web-browser application with commandline<br><code>" + commandLine + "</code>", "Check the application path and command line parameters " + "(File->Preferences->Resource types)."); } }
public static boolean checkBrowser() { AppList appList = MimeTypesList.getAppList(); String bpath = appList.getBrowserExec(); if (bpath != null) if (new File(bpath).isFile()) return true; JFileChooser chooser = new JFileChooser(); chooser.setFileHidingEnabled(false); chooser.setDialogTitle(Local.getString("Select the web-browser executable")); chooser.setAcceptAllFileFilterUsed(true); chooser.setFileSelectionMode(JFileChooser.FILES_ONLY); /*java.io.File lastSel = (java.io.File) Context.get("LAST_SELECTED_RESOURCE_FILE"); if (lastSel != null) chooser.setCurrentDirectory(lastSel);*/ if (chooser.showOpenDialog(App.getFrame()) != JFileChooser.APPROVE_OPTION) return false; appList.setBrowserExec(chooser.getSelectedFile().getPath()); CurrentStorage.get().storeMimeTypesList(); return true; }
boolean checkApp(MimeType mt) { String appId = mt.getAppId(); AppList appList = MimeTypesList.getAppList(); File d; if (appId == null) { appId = Util.generateId(); d = new File("/"); } else { File exe = new File(appList.getFindPath(appId) + "/" + appList.getExec(appId)); if (exe.isFile()) return true; d = new File(exe.getParent()); while (!d.exists()) d = new File(d.getParent()); } SetAppDialog dlg = new SetAppDialog( App.getFrame(), Local.getString( Local.getString("Select the application to open files of type") + " '" + mt.getLabel() + "'")); Dimension dlgSize = new Dimension(420, 300); dlg.setSize(dlgSize); Dimension frmSize = App.getFrame().getSize(); Point loc = App.getFrame().getLocation(); dlg.setLocation( (frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y); dlg.setDirectory(d); dlg.appPanel.argumentsField.setText("$1"); dlg.setVisible(true); if (dlg.CANCELLED) return false; File f = new File(dlg.appPanel.applicationField.getText()); appList.addOrReplaceApp( appId, f.getParent().replace('\\', '/'), f.getName().replace('\\', '/'), dlg.appPanel.argumentsField.getText()); mt.setApp(appId); /*appList.setFindPath(appId, chooser.getSelectedFile().getParent().replace('\\','/')); appList.setExec(appId, chooser.getSelectedFile().getName().replace('\\','/'));*/ CurrentStorage.get().storeMimeTypesList(); return true; }