Skip to content

Commit 9e8fa57

Browse files
committed
Allow reverting of tab content
Adds UI logic to allow reverting of tab content by pressing Ctrl-Shift-R or by clicking the 'Revert' SimpleAction menu item on the EditorHeader menu that opens from the upside-down triangle that's on the right edge of the tabs bar of the IDE. Similar to arduino#5345 but option is added to the tabs bar menu and for better clarity is called 'Revert' not 'Refresh'.
1 parent 89539b1 commit 9e8fa57

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

Diff for: app/src/processing/app/Editor.java

+54
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,60 @@ public void updateTitle() {
18671867
}
18681868

18691869

1870+
/**
1871+
* Handles the user pressing Ctrl-Shift-R or clicking the Revert SimpleAction
1872+
* menu item on the EditorHeader menu that opens from the upside-down
1873+
* triangle that's on the right edge of the tabs bar of the IDE, which
1874+
* reverts / reloads the file in the current tab.
1875+
*/
1876+
public void handleRevertTab() {
1877+
1878+
EditorTab tab = getCurrentTab();
1879+
if (tab == null) {
1880+
throw new IllegalStateException();
1881+
}
1882+
1883+
SketchFile fileInTab = tab.getSketchFile();
1884+
if (fileInTab == null) {
1885+
throw new IllegalStateException();
1886+
}
1887+
1888+
// As of Processing 1.0.10, this always happens immediately.
1889+
// http://dev.processing.org/bugs/show_bug.cgi?id=1456
1890+
1891+
toFront();
1892+
1893+
if (!fileInTab.fileExists()) {
1894+
JOptionPane.showMessageDialog(
1895+
this,
1896+
I18n.format(
1897+
tr("Unable to revert \"{0}\" as it does not exist."),
1898+
fileInTab.getFileName()),
1899+
tr("Unable to Revert"),
1900+
JOptionPane.ERROR_MESSAGE);
1901+
return;
1902+
}
1903+
1904+
String prompt = I18n.format(
1905+
sketch.isModified()
1906+
? tr("Modifications detected to \"{0}\". Revert anyway?")
1907+
: tr("Revert \"{0}\"?"),
1908+
fileInTab.getFileName());
1909+
1910+
int result = JOptionPane.showConfirmDialog(this, prompt, tr("Revert"),
1911+
JOptionPane.OK_CANCEL_OPTION,
1912+
JOptionPane.QUESTION_MESSAGE);
1913+
1914+
switch (result) {
1915+
case JOptionPane.CANCEL_OPTION: // Cancel clicked
1916+
case JOptionPane.CLOSED_OPTION: // Escape key pressed
1917+
return;
1918+
}
1919+
1920+
tab.reload();
1921+
}
1922+
1923+
18701924
/**
18711925
* Actually handle the save command. If 'immediately' is set to false,
18721926
* this will happen in another thread so that the message area

Diff for: app/src/processing/app/EditorHeader.java

+6
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public class Actions {
9494
public final Action renameTab = new SimpleAction(tr("Rename"),
9595
() -> editor.getSketchController().handleRenameCode());
9696

97+
public final Action revertTab = new SimpleAction(tr("Revert"),
98+
Keys.ctrlShift(KeyEvent.VK_R),
99+
() -> editor.handleRevertTab());
100+
97101
public final Action deleteTab = new SimpleAction(tr("Delete"), () -> {
98102
try {
99103
editor.getSketchController().handleDeleteCode();
@@ -113,6 +117,7 @@ public class Actions {
113117
// Normally, this happens automatically for any actions bound to menu
114118
// items, but only for menus attached to a window, not for popup menus.
115119
Keys.bind(EditorHeader.this, newTab);
120+
Keys.bind(EditorHeader.this, revertTab);
116121
Keys.bind(EditorHeader.this, prevTab);
117122
Keys.bind(EditorHeader.this, nextTab);
118123

@@ -315,6 +320,7 @@ public void rebuildMenu() {
315320

316321
menu.add(new JMenuItem(actions.newTab));
317322
menu.add(new JMenuItem(actions.renameTab));
323+
menu.add(new JMenuItem(actions.revertTab));
318324
menu.add(new JMenuItem(actions.deleteTab));
319325
menu.addSeparator();
320326
menu.add(new JMenuItem(actions.prevTab));

0 commit comments

Comments
 (0)