more work on multi-file support

This commit is contained in:
benfry
2004-01-09 17:11:09 +00:00
parent e43794bfbd
commit 5bbbbe223e
2 changed files with 117 additions and 2 deletions

View File

@@ -39,6 +39,12 @@ public class PdeEditorHeader extends JComponent {
PdeEditor editor;
//PdeSketch sketch;
int tabLeft[];
int tabRight[];
int menuLeft;
int menuRight;
//int sketchLeft;
//int sketchRight;
//int sketchTitleLeft;
@@ -50,6 +56,11 @@ public class PdeEditorHeader extends JComponent {
//
boolean menuVisible;
JMenu menu;
//
static final String STATUS[] = { "unsel", "sel" };
static final int UNSELECTED = 0;
static final int SELECTED = 1;
@@ -150,6 +161,12 @@ public class PdeEditorHeader extends JComponent {
fontAscent = metrics.getAscent();
}
if ((tabLeft == null) ||
(tabLeft.length < sketch.fileCount)) {
tabLeft = new int[sketch.fileCount];
tabRight = new int[sketch.fileCount];
}
int x = PdePreferences.GUI_SMALL;
for (int i = 0; i < sketch.fileCount; i++) {
String text = sketch.modified[i] ?
@@ -165,10 +182,12 @@ public class PdeEditorHeader extends JComponent {
x += PIECE_WIDTH;
int contentLeft = x;
tabLeft[i] = x;
for (int j = 0; j < pieceCount; j++) {
g.drawImage(pieces[state][MIDDLE], x, 0, null);
x += PIECE_WIDTH;
}
tabRight[i] = x;
int textLeft = contentLeft + (pieceWidth - textWidth) / 2;
g.setColor(textColor[STATUS]);
@@ -179,6 +198,12 @@ public class PdeEditorHeader extends JComponent {
x += PIECE_WIDTH - 1; // overlap by 1 pixel
}
menuLeft = sizeW - (16 + pieces[0][MENU].getWidth());
menuRight = sizeW - 16;
// draw the dropdown menu target
g.drawImage(pieces[menuVisible ? SELECTED : UNSELECTED][MENU],
menuLeft, 0);
/*
sketchTitleLeft = PdePreferences.GUI_SMALL;
sketchLeft = sketchTitleLeft +
@@ -203,6 +228,96 @@ public class PdeEditorHeader extends JComponent {
}
/*
New [code,tab,source] file... Cmd-shift-N
Rename
Delete
Hide
Unhide >
Reset file list (not needed?)
*/
public JMenu rebuildMenu() {
if (menu != null) {
menu.removeAll();
} else {
menu = new JMenu();
}
JMenuItem item;
item = new JMenuItem("New");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
menu.add(item);
item = new JMenuItem("Rename");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
menu.add(item);
item = new JMenuItem("Delete");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
menu.add(item);
item = new JMenuItem("Hide");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// don't let the user hide if only 1 file open
}
});
menu.add(item);
JMenu unhide = new JMenu("Unhide");
ActionListener unhideListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
//System.out.println("unhide " + e);
File from = (File) e.getActionCommand();
String filename = from.getName();
if (!filename.endsWith(".x")) {
System.err.println("error while trying to unhide a file");
} else if (!filename.exists()) {
System.err.println("file no longer exists");
} else {
File to = new File(from.getPath(),
filename.substring(0, filename.length() - 2));
if (!from.renameTo(to)) {
System.err.println("problem while unhiding");
}
}
rebuildMenu();
}
};
for (int i = 0; i < hiddenCount; i++) {
item = new JMenuItem(hiddenNames[i]);
item.setActionCommand(hiddenFiles[i]);
item.addActionListener(unhideListener);
hidden.add(item);
}
menu.add(unhide);
menu.addSeparator();
ActionListener jumpListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
//System.out.println("jump to " + e.getActionCommand());
System.out.println("jump to " + e);
}
};
for (int i = 0; i < fileCount; i++) {
item = new JMenuItem(names[i]);
//item.setActionCommand(files[i]);
item.addActionListener(jumpListener);
menu.add(item);
}
}
public Dimension getPreferredSize() {
return getMinimumSize();
}

View File

@@ -70,8 +70,8 @@ _ fix command keys for menus (broken since switching to swing)
_ option for having multiple files open
X need ui for tabs from casey
_ tabbed interface for multiple files
_ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;action=display;num=1052077800;start=0
X tabbed interface for multiple files
X http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;action=display;num=1052077800;start=0
_ "new text java/pde file" menu item