1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

Opening a sketch ALWAYS open a new window

This commit is contained in:
Federico Fissore 2015-07-03 11:24:17 +02:00
parent 0e4dcc6fc7
commit 43743bb1a3
2 changed files with 27 additions and 36 deletions

View File

@ -34,8 +34,9 @@ import cc.arduino.contributions.packages.ui.ContributionManagerUI;
import cc.arduino.files.DeleteFilesOnShutdown; import cc.arduino.files.DeleteFilesOnShutdown;
import cc.arduino.packages.DiscoveryManager; import cc.arduino.packages.DiscoveryManager;
import cc.arduino.utils.Progress; import cc.arduino.utils.Progress;
import cc.arduino.view.*;
import cc.arduino.view.Event; import cc.arduino.view.Event;
import cc.arduino.view.JMenuUtils;
import cc.arduino.view.SplashScreenHelper;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.Collections2; import com.google.common.collect.Collections2;
@ -58,7 +59,6 @@ import processing.app.tools.MenuScroller;
import processing.app.tools.ZipDeflater; import processing.app.tools.ZipDeflater;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.io.*; import java.io.*;
@ -1122,18 +1122,18 @@ public class Base {
menu.addSeparator(); menu.addSeparator();
// Add a list of all sketches and subfolders // Add a list of all sketches and subfolders
boolean sketches = addSketches(menu, BaseNoGui.getSketchbookFolder(), true); boolean sketches = addSketches(menu, BaseNoGui.getSketchbookFolder());
if (sketches) menu.addSeparator(); if (sketches) menu.addSeparator();
// Add each of the subfolders of examples directly to the menu // Add each of the subfolders of examples directly to the menu
boolean found = addSketches(menu, BaseNoGui.getExamplesFolder(), true); boolean found = addSketches(menu, BaseNoGui.getExamplesFolder());
if (found) menu.addSeparator(); if (found) menu.addSeparator();
} }
protected void rebuildSketchbookMenu(JMenu menu) { protected void rebuildSketchbookMenu(JMenu menu) {
menu.removeAll(); menu.removeAll();
addSketches(menu, BaseNoGui.getSketchbookFolder(), false); addSketches(menu, BaseNoGui.getSketchbookFolder());
JMenu librariesMenu = JMenuUtils.findSubMenuWithLabel(menu, "libraries"); JMenu librariesMenu = JMenuUtils.findSubMenuWithLabel(menu, "libraries");
if (librariesMenu != null) { if (librariesMenu != null) {
@ -1235,21 +1235,21 @@ public class Base {
menu.removeAll(); menu.removeAll();
// Add examples from distribution "example" folder // Add examples from distribution "example" folder
boolean found = addSketches(menu, BaseNoGui.getExamplesFolder(), false); boolean found = addSketches(menu, BaseNoGui.getExamplesFolder());
if (found) menu.addSeparator(); if (found) menu.addSeparator();
// Add examples from libraries // Add examples from libraries
LibraryList ideLibs = getIDELibs(); LibraryList ideLibs = getIDELibs();
ideLibs.sort(); ideLibs.sort();
for (UserLibrary lib : ideLibs) for (UserLibrary lib : ideLibs)
addSketchesSubmenu(menu, lib, false); addSketchesSubmenu(menu, lib);
LibraryList userLibs = getUserLibs(); LibraryList userLibs = getUserLibs();
if (userLibs.size() > 0) { if (userLibs.size() > 0) {
menu.addSeparator(); menu.addSeparator();
userLibs.sort(); userLibs.sort();
for (UserLibrary lib : userLibs) for (UserLibrary lib : userLibs)
addSketchesSubmenu(menu, lib, false); addSketchesSubmenu(menu, lib);
} }
} }
@ -1580,7 +1580,7 @@ public class Base {
* should replace the sketch in the current window, or false when the * should replace the sketch in the current window, or false when the
* sketch should open in a new window. * sketch should open in a new window.
*/ */
protected boolean addSketches(JMenu menu, File folder, final boolean replaceExisting) { protected boolean addSketches(JMenu menu, File folder) {
if (folder == null) if (folder == null)
return false; return false;
@ -1607,7 +1607,7 @@ public class Base {
if (!subfolder.isDirectory()) continue; if (!subfolder.isDirectory()) continue;
if (addSketchesSubmenu(menu, subfolder.getName(), subfolder, replaceExisting)) { if (addSketchesSubmenu(menu, subfolder.getName(), subfolder)) {
ifound = true; ifound = true;
} }
} }
@ -1615,32 +1615,21 @@ public class Base {
return ifound; return ifound;
} }
private boolean addSketchesSubmenu(JMenu menu, UserLibrary lib, private boolean addSketchesSubmenu(JMenu menu, UserLibrary lib) {
boolean replaceExisting) { return addSketchesSubmenu(menu, lib.getName(), lib.getInstalledFolder());
return addSketchesSubmenu(menu, lib.getName(), lib.getInstalledFolder(),
replaceExisting);
} }
private boolean addSketchesSubmenu(JMenu menu, String name, File folder, private boolean addSketchesSubmenu(JMenu menu, String name, File folder) {
final boolean replaceExisting) {
ActionListener listener = new ActionListener() { ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String path = e.getActionCommand(); String path = e.getActionCommand();
File file = new File(path); File file = new File(path);
if (file.exists()) { if (file.exists()) {
boolean replace = replaceExisting; try {
if ((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0) { handleOpen(file);
replace = !replace; } catch (Exception e1) {
} e1.printStackTrace();
if (replace) {
handleOpenReplace(file);
} else {
try {
handleOpen(file);
} catch (Exception e1) {
e1.printStackTrace();
}
} }
} else { } else {
showWarning(_("Sketch Does Not Exist"), showWarning(_("Sketch Does Not Exist"),
@ -1682,11 +1671,11 @@ public class Base {
// don't create an extra menu level for a folder named "examples" // don't create an extra menu level for a folder named "examples"
if (folder.getName().equals("examples")) if (folder.getName().equals("examples"))
return addSketches(menu, folder, replaceExisting); return addSketches(menu, folder);
// not a sketch folder, but maybe a subfolder containing sketches // not a sketch folder, but maybe a subfolder containing sketches
JMenu submenu = new JMenu(name); JMenu submenu = new JMenu(name);
boolean found = addSketches(submenu, folder, replaceExisting); boolean found = addSketches(submenu, folder);
if (found) { if (found) {
menu.add(submenu); menu.add(submenu);
MenuScroller.setScrollerFor(submenu); MenuScroller.setScrollerFor(submenu);

View File

@ -22,13 +22,15 @@
*/ */
package processing.app; package processing.app;
import static processing.app.I18n._;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*; import javax.swing.event.MouseInputListener;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import static processing.app.I18n._;
/** /**
@ -43,7 +45,7 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key
/** Titles for each button when the shift key is pressed. */ /** Titles for each button when the shift key is pressed. */
static final String titleShift[] = { static final String titleShift[] = {
_("Verify"), _("Upload Using Programmer"), _("New"), _("Open in Another Window"), _("Save As..."), _("Serial Monitor") _("Verify"), _("Upload Using Programmer"), _("New"), _("Open"), _("Save As..."), _("Serial Monitor")
}; };
static final int BUTTON_COUNT = title.length; static final int BUTTON_COUNT = title.length;