Skip to content

Instantly share code, notes, and snippets.

@rednoah
Last active November 23, 2016 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rednoah/931cf412b28a25eddfca47c40628ad56 to your computer and use it in GitHub Desktop.
Save rednoah/931cf412b28a25eddfca47c40628ad56 to your computer and use it in GitHub Desktop.
FileBot History Dialog with Revert Action (Terminal UI)
#!/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