Skip to content

Commit 3fb3f3f

Browse files
committed
Passing the torch, so done with this
1 parent 27e6ec7 commit 3fb3f3f

2 files changed

Lines changed: 135 additions & 94 deletions

File tree

app/src/processing/app/ui/ComposeTopBar.kt

Lines changed: 127 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ import androidx.compose.ui.text.style.TextAlign
1818
import androidx.compose.ui.unit.IntOffset
1919
import androidx.compose.ui.unit.dp
2020
import processing.app.Base
21-
import processing.app.Language
22-
import processing.app.Preferences
23-
import processing.app.UpdateCheck
24-
import javax.swing.JMenuItem
25-
import javax.swing.JPopupMenu
2621
import java.awt.Color as AwtColor
22+
import processing.app.Platform
23+
import java.awt.event.ActionEvent
24+
import javax.swing.AbstractAction
25+
import javax.swing.JComponent
26+
import javax.swing.JMenu
27+
import javax.swing.KeyStroke
28+
import javax.swing.event.MenuEvent
2729

2830
fun awtToCompose(c: AwtColor): Color {
2931
return Color(c.red, c.green, c.blue, c.alpha)
@@ -45,14 +47,14 @@ fun TopBar(panel: ComposePanel, base: Base, editor: Editor) {
4547
val textColor = themeColorOrFallback("toolbar.rollover.color", AwtColor(0, 0, 0))
4648

4749
val items = listOf(
48-
TopBarItemData("File") { p, b, e, x, y ->
49-
showMenuPopup(p, b, e, x, y)
50+
TopBarItemData("File") { p, _, e, x, y ->
51+
showFilePopup(p, e, x, y)
5052
},
51-
TopBarItemData("Edit") { p, b, e, x, y ->
52-
//showMenuPopup(p, b, e, x, y)
53+
TopBarItemData("Edit") { p, _, e, x, y ->
54+
showEditPopup(p, e, x, y)
5355
},
54-
TopBarItemData("Sketch") { p, b, e, x, y ->
55-
//showMenuPopup(p, b, e, x, y)
56+
TopBarItemData("Sketch") { p, _, e, x, y ->
57+
showSketchPopup(p, e, x, y)
5658
},
5759
TopBarItemData("Debug") { p, b, e, x, y ->
5860
//showMenuPopup(p, b, e, x, y)
@@ -63,8 +65,8 @@ fun TopBar(panel: ComposePanel, base: Base, editor: Editor) {
6365
TopBarItemData("Help") { p, b, e, x, y ->
6466
//showMenuPopup(p, b, e, x, y)
6567
},
66-
TopBarItemData("Develop") { p, b, e, x, y ->
67-
showDevelopPopup(p, b, x, y)
68+
TopBarItemData("Develop") { p, _, e, x, y ->
69+
showDevelopPopup(p, e, x, y)
6870
}
6971
)
7072

@@ -128,112 +130,148 @@ private fun TopBarItem(
128130

129131

130132
///pop up menus///
131-
private fun showDevelopPopup(panel: ComposePanel, base: Base, x: Int, y: Int) {
132-
val popup = JPopupMenu()
133-
134-
val updatesItem = JMenuItem("Check for Updates")
135-
updatesItem.addActionListener {
136-
Preferences.unset("update.last")
137-
Preferences.setInteger("update.beta_welcome", 0)
138-
UpdateCheck(base)
139-
}
140133

141-
popup.add(updatesItem)
142-
popup.show(panel, x, y)
134+
private fun showFilePopup(panel: ComposePanel, editor: Editor, x: Int, y: Int) {
135+
val menu = editor.buildFileMenu()
136+
showPopupFromMenu(panel, menu, x, y)
143137
}
144138

145-
private fun showMenuPopup(panel: ComposePanel, base: Base, editor: Editor, x: Int, y: Int) {
146-
val popup = JPopupMenu()
147-
148-
val fileNew = Toolkit.newJMenuItem(Language.text("menu.file.new"), 'N'.code);
149-
fileNew.addActionListener {
150-
base.handleNew()
151-
}
152-
popup.add(fileNew);
153-
154-
val fileOpen = Toolkit.newJMenuItem(Language.text("menu.file.open"), 'O'.code);
155-
fileOpen.addActionListener {
156-
base.handleOpenPrompt();
157-
}
158-
popup.add(fileOpen);
159-
160-
val fileSketchbook = Toolkit.newJMenuItemShift(Language.text("menu.file.sketchbook"), 'K'.code);
161-
fileSketchbook.addActionListener {
162-
base.showSketchbookFrame()
163-
}
164-
popup.add(fileSketchbook);
165-
166-
val fileExamples = Toolkit.newJMenuItemShift(Language.text("menu.file.examples"), 'O'.code);
167-
fileExamples.addActionListener {
168-
base.showExamplesFrame()
169-
}
170-
popup.add(fileExamples);
171-
172-
val fileClose = Toolkit.newJMenuItem(Language.text("menu.file.close"), 'W'.code);
173-
fileClose.addActionListener {
174-
base.handleClose(editor, false);
175-
}
176-
popup.add(fileClose);
177139

178-
val fileSave = Toolkit.newJMenuItem(Language.text("menu.file.save"), 'S'.code)
179-
fileSave.addActionListener {
180-
editor.handleSave(false);
181-
}
182-
popup.add(fileSave);
140+
private fun showEditPopup(panel: ComposePanel, editor: Editor, x: Int, y: Int) {
141+
val method = editor.javaClass.superclass.getDeclaredMethod("buildEditMenu")
142+
method.isAccessible = true
143+
val menu = method.invoke(editor) as JMenu
144+
showPopupFromMenu(panel, menu, x, y)
145+
}
183146

184-
val fileSaveAs = Toolkit.newJMenuItemShift(Language.text("menu.file.save_as"), 'S'.code);
185-
fileSaveAs.addActionListener {
186-
editor.handleSaveAs();
187-
}
188-
popup.add(fileSaveAs);
147+
private fun showSketchPopup(panel: ComposePanel, editor: Editor, x: Int, y: Int) {
148+
val menu = editor.buildSketchMenu()
149+
showPopupFromMenu(panel, menu, x, y)
150+
}
189151

190-
val filePageSetup = Toolkit.newJMenuItemShift(Language.text("menu.file.page_setup"), 'P'.code);
191-
filePageSetup.addActionListener {
192-
editor.handlePageSetup();
193-
}
194-
popup.add(filePageSetup);
152+
private fun showDevelopPopup(panel: ComposePanel, editor: Editor, x: Int, y: Int) {
153+
editor.buildDevelopMenu()
195154

196-
val filePrint = Toolkit.newJMenuItem(Language.text("menu.file.print"), 'P'.code);
197-
filePrint.addActionListener {
198-
editor.handlePrint();
199-
}
200-
popup.add(filePrint);
155+
val field = editor.javaClass.superclass.getDeclaredField("developMenu")
156+
field.isAccessible = true
157+
val menu = field.get(editor) as JMenu
201158

159+
showPopupFromMenu(panel, menu, x, y)
160+
}
202161

203-
// UNDER MAC OS ONLY SECTION /// - will have to deal with this.
204-
val filePreferences = Toolkit.newJMenuItem(Language.text("menu.file.preferences"), ','.code);
205-
filePreferences.addActionListener {
206-
base.handlePrefs()
207-
}
208-
popup.add(filePreferences);
162+
private fun showPopupFromMenu(panel: ComposePanel, menu: JMenu, x: Int, y: Int) {
163+
val popup = menu.popupMenu
209164

210-
val fileQuit = Toolkit.newJMenuItem(Language.text("menu.file.quit"), 'Q'.code);
211-
fileQuit.addActionListener {
212-
base.handleQuit()
165+
fun refreshTopBar() {
166+
javax.swing.SwingUtilities.invokeLater {
167+
panel.revalidate()
168+
panel.repaint()
169+
}
213170
}
214-
popup.add(fileQuit);
215171

216-
//^^^ UNDER MAC OS ONLY SECTION ^^^/////
172+
popup.addPopupMenuListener(object : javax.swing.event.PopupMenuListener {
173+
override fun popupMenuWillBecomeVisible(e: javax.swing.event.PopupMenuEvent?) = Unit // nothing needed right before the popup becomes visible
217174

175+
override fun popupMenuWillBecomeInvisible(e: javax.swing.event.PopupMenuEvent?) { // called when the popup closes normally
176+
refreshTopBar() //redraw top bar
177+
}
218178

179+
override fun popupMenuCanceled(e: javax.swing.event.PopupMenuEvent?) { // called when the popup is canceled, like clicking away
180+
refreshTopBar() //redrawing...
181+
}
182+
})
219183

184+
val event = MenuEvent(menu)
185+
menu.menuListeners.forEach { it.menuSelected(event) }
220186
popup.show(panel, x, y)
221187
}
222188

189+
///^^^ pop up menus ^^^////
223190

224191

225192

226-
///^^^ pop up menus ^^^////
227-
193+
//keyboard shortcuts do not work right now unless the dropdown is opened, this did not fix that.
194+
//but it still has potential to be reworked.
195+
196+
//private fun bindShortcuts(editor: Editor, base: Base) {
197+
// val root = editor.rootPane
198+
//
199+
// val input = root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
200+
// val actions = root.actionMap
201+
//
202+
// fun bind(name: String, key: KeyStroke?, action: () -> Unit) {
203+
// if (key == null) return
204+
// input.put(key, name)
205+
// actions.put(name, object : AbstractAction() {
206+
// override fun actionPerformed(e: ActionEvent?) {
207+
// action()
208+
// }
209+
// })
210+
// }
211+
//
212+
// bind("new", Toolkit.getKeyStrokeExt("menu.file.new")) {
213+
// base.handleNew()
214+
// }
215+
//
216+
// bind("open", Toolkit.getKeyStrokeExt("menu.file.open")) {
217+
// base.handleOpenPrompt()
218+
// }
219+
//
220+
// bind("close", Toolkit.getKeyStrokeExt("menu.file.close")) {
221+
// base.handleClose(editor, false)
222+
// }
223+
//
224+
// bind("save", Toolkit.getKeyStrokeExt("menu.file.save")) {
225+
// editor.handleSave(false)
226+
// }
227+
//
228+
// bind("saveAs", Toolkit.getKeyStrokeExt("menu.file.save_as")) {
229+
// editor.handleSaveAs()
230+
// }
231+
//
232+
// bind("print", Toolkit.getKeyStrokeExt("menu.file.print")) {
233+
// editor.handlePrint()
234+
// }
235+
//
236+
// bind("pageSetup", Toolkit.getKeyStrokeExt("menu.file.page_setup")) {
237+
// editor.handlePageSetup()
238+
// }
239+
//
240+
// if (!Platform.isMacOS()) {
241+
// bind("prefs", Toolkit.getKeyStrokeExt("menu.file.preferences")) {
242+
// base.handlePrefs()
243+
// }
244+
//
245+
// bind("quit", Toolkit.getKeyStrokeExt("menu.file.quit")) {
246+
// base.handleQuit()
247+
// }
248+
// }
249+
//}
228250

229251

230252
fun mountTopBar(panel: ComposePanel, base: Base, editor: Editor) {
231253
val awtBg = Theme.getColor("toolbar.gradient.top") ?: AwtColor(107, 160, 204)
232254
panel.background = awtBg
233255

256+
// bindShortcuts(editor, base)
257+
234258
panel.setContent {
235259
TopBar(panel, base, editor)
236260
}
237261
}
238262

239263

264+
265+
//Hi, so...
266+
//line 1050 in editor.java, is the tool menu, so inside your function call editor.getToolMenu() to access the drop down stuff there
267+
//without manually re-entering everything!
268+
//the class is public so you should get away with copying and pasting the showSketchPopup and replace the names and what
269+
//its calling obvi
270+
271+
//then line 1085 in editor.java, is the Help menu. This should be built the same way as showSketchPopup as well!
272+
//good luck! if you happen to feel up to it Debug is the last one, but I have no idea where that is.
273+
274+
275+
276+
277+

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -668,14 +668,17 @@ public void updateTheme() {
668668
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
669669

670670

671+
//I FOUND MY FUNCTION IN HERE TO CALL ****
672+
671673
protected void buildMenuBar() {
672674
JMenuBar menubar = new JMenuBar();
673-
fileMenu = buildFileMenu();
675+
fileMenu = buildFileMenu(); //here is the file menu call
674676
menubar.add(fileMenu);
675-
menubar.add(buildEditMenu());
676-
menubar.add(buildSketchMenu());
677+
menubar.add(buildEditMenu()); //here is the edit menu call
678+
menubar.add(buildSketchMenu()); //here is the sketch menu call
677679

678680
// For 3.0a4 move mode menu to the left of the Tool menu
681+
679682
JMenu modeMenu = buildModeMenu();
680683
if (modeMenu != null) {
681684
menubar.add(modeMenu);
@@ -1046,7 +1049,7 @@ public void sketchChanged() { }
10461049

10471050
public JMenu getToolMenu() {
10481051
return toolsMenu;
1049-
}
1052+
} //TOOL MENU CODE!!!!!1
10501053

10511054

10521055
/**
@@ -1079,7 +1082,7 @@ public JMenu buildModeMenu() {
10791082
}
10801083

10811084

1082-
abstract public JMenu buildHelpMenu();
1085+
abstract public JMenu buildHelpMenu(); //HELP MENU CODE!!!!
10831086

10841087
public void buildDevelopMenu(){
10851088
developMenu = new JMenu(Language.text("menu.develop"));

0 commit comments

Comments
 (0)