mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
rename/delete of sketches works again.. other ide tweakies
This commit is contained in:
@@ -88,7 +88,6 @@ public class PdeBase {
|
||||
|
||||
|
||||
public PdeBase() {
|
||||
|
||||
// figure out which operating system
|
||||
// this has to be first, since editor needs to know
|
||||
|
||||
@@ -796,8 +795,10 @@ public class PdeBase {
|
||||
static public int calcFolderSize(File folder) {
|
||||
int size = 0;
|
||||
|
||||
//System.out.println("calcFolderSize " + folder);
|
||||
String files[] = folder.list();
|
||||
// null if folder doesn't exist, happens when deleting sketch
|
||||
if (files == null) return -1;
|
||||
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
if (files[i].equals(".") || (files[i].equals("..")) ||
|
||||
files[i].equals(".DS_Store")) continue;
|
||||
|
||||
@@ -1310,6 +1310,19 @@ public class PdeEditor extends JFrame
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extra public method so that PdeSketch can call
|
||||
* this when a sketch is selected to be deleted,
|
||||
* and it won't prompt for save as.
|
||||
*/
|
||||
public void handleNew() {
|
||||
doStop();
|
||||
handleNewShift = false;
|
||||
handleNewLibrary = false;
|
||||
handleNew2(true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* User selected "New Library", this will act just like handleNew
|
||||
* but internally set a flag that the new guy is a library,
|
||||
@@ -1326,12 +1339,13 @@ public class PdeEditor extends JFrame
|
||||
/**
|
||||
* Does all the plumbing to create a new project
|
||||
* then calls handleOpen to load it up.
|
||||
* @param startup true if the app is starting (auto-create a sketch)
|
||||
*
|
||||
* @param noPrompt true if the app is starting (auto-create a sketch)
|
||||
*/
|
||||
protected void handleNew2(boolean startup) {
|
||||
protected void handleNew2(boolean noPrompt) {
|
||||
try {
|
||||
String pdePath =
|
||||
sketchbook.handleNew(startup, handleNewShift, handleNewLibrary);
|
||||
sketchbook.handleNew(noPrompt, handleNewShift, handleNewLibrary);
|
||||
if (pdePath != null) handleOpen2(pdePath);
|
||||
|
||||
} catch (IOException e) {
|
||||
@@ -1376,6 +1390,18 @@ public class PdeEditor extends JFrame
|
||||
* need to be saved.
|
||||
*/
|
||||
protected void handleOpen2(String path) {
|
||||
if (sketch != null) {
|
||||
// if leaving an empty sketch (i.e. the default) do an
|
||||
// auto-clean right away
|
||||
if (PdeBase.calcFolderSize(sketch.folder) == 0) {
|
||||
//System.err.println("removing empty poopster");
|
||||
PdeBase.removeDir(sketch.folder);
|
||||
sketchbook.rebuildMenus();
|
||||
}
|
||||
//} else {
|
||||
//System.err.println("sketch was null");
|
||||
}
|
||||
|
||||
try {
|
||||
// check to make sure that this .pde file is
|
||||
// in a folder of the same name
|
||||
|
||||
@@ -46,7 +46,7 @@ public class PdeEditorHeader extends JComponent {
|
||||
JMenu menu;
|
||||
JPopupMenu popup;
|
||||
|
||||
JMenuItem deleteItem;
|
||||
JMenuItem hideItem;
|
||||
|
||||
int menuLeft;
|
||||
int menuRight;
|
||||
@@ -168,9 +168,8 @@ public class PdeEditorHeader extends JComponent {
|
||||
tabRight = new int[sketch.codeCount];
|
||||
}
|
||||
|
||||
// disable rename on the first tab
|
||||
deleteItem.setEnabled(sketch.current != sketch.code[0]);
|
||||
// re-enabling for 75 to bring back renaming of sketches
|
||||
// disable hide on the first tab
|
||||
hideItem.setEnabled(sketch.current != sketch.code[0]);
|
||||
|
||||
//int x = 0; //PdePreferences.GUI_SMALL;
|
||||
int x = (PdeBase.platform == PdeBase.MACOSX) ? 0 : 1;
|
||||
@@ -308,7 +307,6 @@ public class PdeEditorHeader extends JComponent {
|
||||
}
|
||||
});
|
||||
menu.add(item);
|
||||
deleteItem = item;
|
||||
|
||||
item = new JMenuItem("Hide");
|
||||
item.addActionListener(new ActionListener() {
|
||||
@@ -317,6 +315,7 @@ public class PdeEditorHeader extends JComponent {
|
||||
}
|
||||
});
|
||||
menu.add(item);
|
||||
hideItem = item;
|
||||
|
||||
JMenu unhide = new JMenu("Unhide");
|
||||
ActionListener unhideListener = new ActionListener() {
|
||||
|
||||
@@ -363,6 +363,11 @@ public class PdeSketch {
|
||||
File newFolder = new File(folder.getParentFile(), newName);
|
||||
boolean success = folder.renameTo(newFolder);
|
||||
folder = newFolder;
|
||||
|
||||
// get the changes into the sketchbook menu
|
||||
editor.sketchbook.rebuildMenus();
|
||||
|
||||
// reload the sketch
|
||||
load();
|
||||
|
||||
} else {
|
||||
@@ -402,16 +407,19 @@ public class PdeSketch {
|
||||
public void deleteCode() {
|
||||
// don't allow delete of the main code
|
||||
// TODO maybe gray out the menu on setCurrent(0)
|
||||
/*
|
||||
if (current == code[0]) {
|
||||
PdeBase.showMessage("Can't do that",
|
||||
"You cannot delete the main " +
|
||||
".pde file from a sketch\n");
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
// confirm deletion with user, yes/no
|
||||
Object[] options = { "OK", "Cancel" };
|
||||
String prompt =
|
||||
String prompt = (current == code[0]) ?
|
||||
"Are you sure you want to delete this sketch?" :
|
||||
"Are you sure you want to delete \"" + current.name + "\"?";
|
||||
int result = JOptionPane.showOptionDialog(editor,
|
||||
prompt,
|
||||
@@ -422,21 +430,33 @@ public class PdeSketch {
|
||||
options,
|
||||
options[0]);
|
||||
if (result == JOptionPane.YES_OPTION) {
|
||||
// delete the file
|
||||
if (!current.file.delete()) {
|
||||
PdeBase.showMessage("Couldn't do it",
|
||||
"Could not delete \"" + current.name + "\".");
|
||||
return;
|
||||
if (current == code[0]) {
|
||||
// delete the entire sketch
|
||||
PdeBase.removeDir(folder);
|
||||
|
||||
// get the changes into the sketchbook menu
|
||||
//sketchbook.rebuildMenus();
|
||||
|
||||
// make a new sketch, and i think this will rebuild the sketch menu
|
||||
editor.handleNew();
|
||||
|
||||
} else {
|
||||
// delete the file
|
||||
if (!current.file.delete()) {
|
||||
PdeBase.showMessage("Couldn't do it",
|
||||
"Could not delete \"" + current.name + "\".");
|
||||
return;
|
||||
}
|
||||
|
||||
// remove code from the list
|
||||
removeCode(current);
|
||||
|
||||
// just set current tab to the main tab
|
||||
setCurrent(0);
|
||||
|
||||
// update the tabs
|
||||
editor.header.repaint();
|
||||
}
|
||||
|
||||
// remove code from the list
|
||||
removeCode(current);
|
||||
|
||||
// just set current tab to the main tab
|
||||
setCurrent(0);
|
||||
|
||||
// update the tabs
|
||||
editor.header.repaint();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -130,7 +130,7 @@ public class PdeSketchbook {
|
||||
* Handle creating a sketch folder, return its base .pde file
|
||||
* or null if the operation was cancelled.
|
||||
*/
|
||||
public String handleNew(boolean startup,
|
||||
public String handleNew(boolean noPrompt,
|
||||
boolean shift,
|
||||
boolean library) throws IOException {
|
||||
File newbieDir = null;
|
||||
@@ -147,7 +147,7 @@ public class PdeSketchbook {
|
||||
// unless, ermm, they user tested it and people preferred that as
|
||||
// a way to get started. shite. now i hate myself.
|
||||
//
|
||||
if (startup) prompt = false;
|
||||
if (noPrompt) prompt = false;
|
||||
|
||||
if (prompt) {
|
||||
//if (!startup) {
|
||||
|
||||
Reference in New Issue
Block a user