Skip to content

Commit beac2df

Browse files
committed
making Recent static removes half a dozen functions from Base
1 parent c8e9ba1 commit beac2df

File tree

5 files changed

+47
-47
lines changed

5 files changed

+47
-47
lines changed

app/src/processing/app/Base.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public class Base {
9797

9898
private JMenu sketchbookMenu;
9999

100-
private Recent recent;
100+
// private Recent recent;
101101

102102
// Used by handleOpen(), this saves the chooser to remember the directory.
103103
// Doesn't appear to be necessary with the AWT native file dialog.
@@ -277,7 +277,8 @@ public Base(String[] args) throws Exception {
277277
// Needs to happen after the sketchbook folder has been located.
278278
// Also relies on the modes to be loaded so it knows what can be
279279
// marked as an example.
280-
recent = new Recent(this);
280+
// recent = new Recent(this);
281+
Recent.init(this);
281282

282283
String lastModeIdentifier = Preferences.get("mode.last"); //$NON-NLS-1$
283284
if (lastModeIdentifier == null) {
@@ -870,7 +871,7 @@ protected Editor handleOpen(String path, boolean untitled,
870871
if (tab.getFile().equals(file)) {
871872
editor.toFront();
872873
// move back to the top of the recent list
873-
handleRecent(editor);
874+
Recent.handle(editor);
874875
return editor;
875876
}
876877
}
@@ -898,7 +899,7 @@ protected Editor handleOpen(String path, boolean untitled,
898899
// opened successfully, let's go to work
899900
editor.getSketch().setUntitled(untitled);
900901
editors.add(editor);
901-
handleRecent(editor);
902+
Recent.handle(editor);
902903

903904
// now that we're ready, show the window
904905
// (don't do earlier, cuz we might move it based on a window being closed)
@@ -1034,7 +1035,7 @@ public boolean handleClose(Editor editor, boolean modeSwitch) {
10341035
} else { // on OS X, update the default file menu
10351036
editor.setVisible(false);
10361037
editor.dispose();
1037-
defaultFileMenu.insert(getRecentMenu(), 2);
1038+
defaultFileMenu.insert(Recent.getMenu(), 2);
10381039
activeEditor = null;
10391040
editors.remove(editor);
10401041
}
@@ -1159,6 +1160,7 @@ public void populateSketchbookMenu(JMenu menu) {
11591160
}
11601161

11611162

1163+
/*
11621164
public JMenu getRecentMenu() {
11631165
return recent.getMenu();
11641166
}
@@ -1179,13 +1181,12 @@ public void handleRecentRename(Editor editor, String oldPath) {
11791181
}
11801182
11811183
1182-
/**
1183-
* Called before a sketch is renamed so that its old name is
1184-
* no longer in the menu.
1185-
*/
1184+
// Called before a sketch is renamed so that its old name is
1185+
// no longer in the menu.
11861186
public void removeRecent(Editor editor) {
11871187
recent.remove(editor);
11881188
}
1189+
*/
11891190

11901191

11911192
/**

app/src/processing/app/Mode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import processing.app.ui.EditorException;
4141
import processing.app.ui.EditorState;
4242
import processing.app.ui.ExamplesFrame;
43+
import processing.app.ui.Recent;
4344
import processing.app.ui.SketchbookFrame;
4445
import processing.app.ui.Toolkit;
4546
import processing.core.PApplet;
@@ -374,13 +375,13 @@ public void insertToolbarRecentMenu() {
374375
if (toolbarMenu == null) {
375376
rebuildToolbarMenu();
376377
} else {
377-
toolbarMenu.insert(base.getToolbarRecentMenu(), 1);
378+
toolbarMenu.insert(Recent.getToolbarMenu(), 1);
378379
}
379380
}
380381

381382

382383
public void removeToolbarRecentMenu() {
383-
toolbarMenu.remove(base.getToolbarRecentMenu());
384+
toolbarMenu.remove(Recent.getToolbarMenu());
384385
}
385386

386387

app/src/processing/app/Sketch.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import processing.app.ui.Editor;
2727
import processing.app.ui.ProgressFrame;
28+
import processing.app.ui.Recent;
2829
import processing.app.ui.Toolkit;
2930
import processing.core.*;
3031

@@ -952,7 +953,7 @@ public void run() {
952953
// the Recent menu so that it's not sticking around after the rename.
953954
// If untitled, it won't be in the menu, so there's no point.
954955
if (!isUntitled()) {
955-
editor.removeRecent();
956+
Recent.remove(editor);
956957
}
957958

958959
// save the main tab with its new name
@@ -965,7 +966,7 @@ public void run() {
965966
setUntitled(false);
966967

967968
// Add this sketch back using the new name
968-
editor.addRecent();
969+
Recent.handle(editor);
969970

970971
// let Editor know that the save was successful
971972
return true;
@@ -997,7 +998,7 @@ protected void updateInternal(String sketchName, File sketchFolder) {
997998
// System.out.println("modified is now " + modified);
998999
editor.updateTitle();
9991000
editor.getBase().rebuildSketchbookMenus();
1000-
editor.getBase().handleRecentRename(editor,oldPath);
1001+
Recent.handleRename(editor, oldPath);
10011002
// editor.header.rebuild();
10021003
}
10031004

app/src/processing/app/ui/Editor.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public void windowClosing(WindowEvent e) {
182182

183183
public void windowActivated(WindowEvent e) {
184184
base.handleActivated(Editor.this);
185-
fileMenu.insert(base.getRecentMenu(), 2);
185+
fileMenu.insert(Recent.getMenu(), 2);
186186
Toolkit.setMenuMnemsInside(fileMenu);
187187

188188
//sketchMenu.insert(mode.getImportMenu(), 5);
@@ -193,7 +193,7 @@ public void windowActivated(WindowEvent e) {
193193
}
194194

195195
public void windowDeactivated(WindowEvent e) {
196-
fileMenu.remove(base.getRecentMenu());
196+
fileMenu.remove(Recent.getMenu());
197197
// JMenu importMenu = mode.getImportMenu();
198198
// importIndex = sketchMenu.getComponentZOrder(mode.getImportMenu());
199199
// sketchMenu.remove(mode.getImportMenu());
@@ -462,14 +462,14 @@ public EditorState getEditorState() {
462462
}
463463

464464

465-
public void removeRecent() {
466-
base.removeRecent(this);
467-
}
468-
469-
470-
public void addRecent() {
471-
base.handleRecent(this);
472-
}
465+
// public void removeRecent() {
466+
// Recent.remove(this);
467+
// }
468+
//
469+
//
470+
// public void addRecent() {
471+
// Recent.handle(this);
472+
// }
473473

474474

475475
/**

app/src/processing/app/ui/Recent.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,17 @@ public class Recent {
4545
static final String FILENAME = "recent.txt";
4646
static final String VERSION = "2";
4747

48-
Base base;
49-
File file;
50-
/** How many recent sketches to remember. */
51-
int remember;
52-
ArrayList<Record> records;
48+
static Base base;
49+
static File file;
50+
static List<Record> records;
5351
/** actual menu used in the primary menu bar */
54-
JMenu mainMenu;
52+
static JMenu mainMenu;
5553
/** copy of the menu to use in the toolbar */
56-
JMenu toolbarMenu;
54+
static JMenu toolbarMenu;
5755

5856

59-
public Recent(Base base) {
60-
this.base = base;
61-
remember = Preferences.getInteger("recent.count");
57+
static public void init(Base b) {
58+
base = b;
6259
file = Base.getSettingsFile(FILENAME);
6360
mainMenu = new JMenu(Language.text("menu.file.recent"));
6461
toolbarMenu = new JMenu(Language.text("menu.file.open"));
@@ -71,7 +68,7 @@ public Recent(Base base) {
7168
}
7269

7370

74-
protected void load() throws IOException {
71+
static protected void load() throws IOException {
7572
records = new ArrayList<Record>();
7673
if (file.exists()) {
7774
BufferedReader reader = PApplet.createReader(file);
@@ -86,7 +83,7 @@ protected void load() throws IOException {
8683
if (new File(line).exists()) { // don't add ghost entries
8784
records.add(new Record(line));
8885
} else {
89-
Base.log(this, "ghost file: " + line);
86+
Base.log("ghost file: " + line);
9087
}
9188
}
9289
}
@@ -97,7 +94,7 @@ protected void load() throws IOException {
9794
}
9895

9996

100-
protected void save() {
97+
static protected void save() {
10198
PrintWriter writer = PApplet.createWriter(file);
10299
writer.println(VERSION);
103100
for (Record record : records) {
@@ -112,17 +109,17 @@ protected void save() {
112109
}
113110

114111

115-
public JMenu getMenu() {
112+
static public JMenu getMenu() {
116113
return mainMenu;
117114
}
118115

119116

120-
public JMenu getToolbarMenu() {
117+
static public JMenu getToolbarMenu() {
121118
return toolbarMenu;
122119
}
123120

124121

125-
private void updateMenu(JMenu menu) {
122+
static private void updateMenu(JMenu menu) {
126123
menu.removeAll();
127124
String sketchbookPath = Base.getSketchbookFolder().getAbsolutePath();
128125
for (Record rec : records) {
@@ -131,7 +128,7 @@ private void updateMenu(JMenu menu) {
131128
}
132129

133130

134-
private void updateMenuRecord(JMenu menu, final Record rec, String sketchbookPath) {
131+
static private void updateMenuRecord(JMenu menu, final Record rec, String sketchbookPath) {
135132
try {
136133
String recPath = new File(rec.getPath()).getParent();
137134
String purtyPath = null;
@@ -231,7 +228,7 @@ public void actionPerformed(ActionEvent e) {
231228
}
232229

233230

234-
synchronized public void remove(Editor editor) {
231+
synchronized static public void remove(Editor editor) {
235232
int index = findRecord(editor.getSketch().getMainFilePath());
236233
if (index != -1) {
237234
records.remove(index);
@@ -278,12 +275,12 @@ synchronized public void remove(Editor editor) {
278275
* entry on the Recent queue. If the sketch is already in the list, it is
279276
* first removed so it doesn't show up multiple times.
280277
*/
281-
synchronized public void handle(Editor editor) {
278+
synchronized static public void handle(Editor editor) {
282279
if (!editor.getSketch().isUntitled()) {
283280
// If this sketch is already in the menu, remove it
284281
remove(editor);
285282

286-
if (records.size() == remember) {
283+
if (records.size() == Preferences.getInteger("recent.count")) {
287284
records.remove(0); // remove the first entry
288285
}
289286

@@ -299,8 +296,8 @@ synchronized public void handle(Editor editor) {
299296
}
300297

301298
//handles renaming done within processing
302-
synchronized public void handleRename(Editor editor,String oldPath){
303-
if (records.size() == remember) {
299+
synchronized static public void handleRename(Editor editor,String oldPath){
300+
if (records.size() == Preferences.getInteger("recent.count")) {
304301
records.remove(0); // remove the first entry
305302
}
306303
int index = findRecord(oldPath);
@@ -313,7 +310,7 @@ synchronized public void handleRename(Editor editor,String oldPath){
313310
}
314311

315312

316-
int findRecord(String path) {
313+
static int findRecord(String path) {
317314
for (int i = 0; i < records.size(); i++) {
318315
if (path.equals(records.get(i).path)) {
319316
return i;

0 commit comments

Comments
 (0)