Last active
November 23, 2016 18:37
-
-
Save rednoah/931cf412b28a25eddfca47c40628ad56 to your computer and use it in GitHub Desktop.
FileBot History Dialog with Revert Action (Terminal UI)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env filebot -script | |
@Grab(group='com.googlecode.lanterna', module='lanterna', version='3.0.0-beta3') | |
import com.googlecode.lanterna.* | |
import com.googlecode.lanterna.screen.* | |
import com.googlecode.lanterna.terminal.* | |
import com.googlecode.lanterna.gui2.* | |
import com.googlecode.lanterna.gui2.table.* | |
import com.googlecode.lanterna.gui2.dialogs.* | |
// Setup terminal and screen layers | |
Terminal terminal = new DefaultTerminalFactory().createTerminal() | |
Screen screen = new TerminalScreen(terminal) | |
MultiWindowTextGUI gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLACK)) | |
// Create panel to hold components | |
Table<File> table = new Table<File>("Source Path", "Destination Path") | |
HistorySpooler.getInstance().getCompleteHistory().getRenameMap().each{ k, v -> | |
if (v.exists()) { | |
table.getTableModel().addRow(k, v) | |
} | |
} | |
table.setSelectAction{ | |
new ActionListDialogBuilder() | |
.setTitle("Action") | |
.addAction("Revert") { | |
try { | |
List<File> data = table.getTableModel().getRow(table.getSelectedRow()) | |
StandardRenameAction.revert(data[1], data[0]) | |
table.getTableModel().removeRow(table.getSelectedRow()) | |
} catch (Exception e) { | |
MessageDialog.showMessageDialog(gui, e.class.name, e.message) | |
} | |
} | |
.build() | |
.showDialog(gui) | |
} | |
// Create window to hold the panel | |
BasicWindow window = new BasicWindow() | |
window.setHints([Window.Hint.CENTERED]) | |
window.setTitle("History") | |
window.setComponent(table) | |
screen.startScreen() | |
gui.addWindowAndWait(window) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment