mirror of
https://github.com/mitb-archive/filebot
synced 2025-01-11 13:58:16 -05:00
Try to fix FormatDialog editable issues
This commit is contained in:
parent
67a884f03c
commit
3529f11cc2
@ -73,6 +73,7 @@ import net.filebot.format.BindingException;
|
||||
import net.filebot.format.ExpressionFormat;
|
||||
import net.filebot.format.MediaBindingBean;
|
||||
import net.filebot.mac.MacAppUtilities;
|
||||
import net.filebot.mediainfo.MediaInfo;
|
||||
import net.filebot.util.DefaultThreadFactory;
|
||||
import net.filebot.util.ExceptionUtilities;
|
||||
import net.filebot.util.PreferencesList;
|
||||
@ -313,10 +314,9 @@ public class FormatDialog extends JDialog {
|
||||
|
||||
public void setFormatCode(String text) {
|
||||
editor.setText(text);
|
||||
editor.setEditable(true);
|
||||
editor.requestFocusInWindow();
|
||||
editor.scrollRectToVisible(new Rectangle(0, 0)); // reset scroll
|
||||
editor.setCaretPosition(text.length()); // scroll to end of format
|
||||
editor.requestFocusInWindow();
|
||||
}
|
||||
|
||||
private RSyntaxTextArea createEditor() {
|
||||
@ -733,4 +733,15 @@ public class FormatDialog extends JDialog {
|
||||
firePropertyChange("sample", null, sample);
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
// load all necessarily classes to avoid focus issues with RSyntaxTextArea
|
||||
new RSyntaxTextArea(new RSyntaxDocument(SyntaxConstants.SYNTAX_STYLE_GROOVY));
|
||||
new ExpressionFormat("{n} - {s00e00} - {t}");
|
||||
new MediaInfo();
|
||||
} catch (Throwable e) {
|
||||
debug.log(Level.SEVERE, "Failed to initialize FormatDialog", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -274,17 +274,11 @@ public class RenamePanel extends JComponent {
|
||||
if (evt.getClickCount() == 2) {
|
||||
JList list = (JList) evt.getSource();
|
||||
if (list.getSelectedIndex() >= 0) {
|
||||
try {
|
||||
withWaitCursor(list, () -> {
|
||||
Match<Object, File> match = renameModel.getMatch(list.getSelectedIndex());
|
||||
Map<File, Object> context = renameModel.getMatchContext(match);
|
||||
|
||||
MediaBindingBean sample = new MediaBindingBean(match.getValue(), match.getCandidate(), context);
|
||||
showFormatEditor(sample);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
debug.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}));
|
||||
@ -443,9 +437,7 @@ public class RenamePanel extends JComponent {
|
||||
actionPopup.addSeparator();
|
||||
actionPopup.addDescription(new JLabel("Options:"));
|
||||
|
||||
actionPopup.add(newAction("Edit Format", ResourceManager.getIcon("action.format"), evt -> {
|
||||
showFormatEditor(null);
|
||||
}));
|
||||
actionPopup.add(newAction("Edit Format", ResourceManager.getIcon("action.format"), evt -> showFormatEditor(null)));
|
||||
|
||||
actionPopup.add(newAction("Preferences", ResourceManager.getIcon("action.preferences"), evt -> {
|
||||
String[] modes = new String[] { MATCH_MODE_OPPORTUNISTIC, MATCH_MODE_STRICT };
|
||||
@ -533,31 +525,34 @@ public class RenamePanel extends JComponent {
|
||||
return actionPopup;
|
||||
}
|
||||
|
||||
protected void showFormatEditor(MediaBindingBean lockOnBinding) {
|
||||
// default to Episode mode
|
||||
Mode initMode = Mode.Episode;
|
||||
|
||||
if (lockOnBinding != null) {
|
||||
if (lockOnBinding.getInfoObject() instanceof Episode) {
|
||||
initMode = Mode.Episode;
|
||||
} else if (lockOnBinding.getInfoObject() instanceof Movie) {
|
||||
initMode = Mode.Movie;
|
||||
} else if (lockOnBinding.getInfoObject() instanceof AudioTrack) {
|
||||
initMode = Mode.Music;
|
||||
} else if (lockOnBinding.getInfoObject() instanceof File) {
|
||||
initMode = Mode.File;
|
||||
protected Mode getFormatEditorMode(MediaBindingBean binding) {
|
||||
if (binding != null) {
|
||||
if (binding.getInfoObject() instanceof Episode) {
|
||||
return Mode.Episode;
|
||||
} else if (binding.getInfoObject() instanceof Movie) {
|
||||
return Mode.Movie;
|
||||
} else if (binding.getInfoObject() instanceof AudioTrack) {
|
||||
return Mode.Music;
|
||||
} else if (binding.getInfoObject() instanceof File) {
|
||||
return Mode.File;
|
||||
} else {
|
||||
return; // ignore objects that cannot be formatted
|
||||
throw new IllegalArgumentException("Cannot format class: " + binding.getClass()); // ignore objects that cannot be formatted
|
||||
}
|
||||
} else {
|
||||
}
|
||||
|
||||
try {
|
||||
initMode = Mode.valueOf(persistentLastFormatState.getValue()); // restore previous mode
|
||||
return Mode.valueOf(persistentLastFormatState.getValue()); // restore previous mode
|
||||
} catch (Exception e) {
|
||||
debug.log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
|
||||
return Mode.Episode; // default to Episode mode
|
||||
}
|
||||
|
||||
FormatDialog dialog = new FormatDialog(getWindowAncestor(RenamePanel.this), initMode, lockOnBinding);
|
||||
protected void showFormatEditor(MediaBindingBean binding) {
|
||||
try {
|
||||
withWaitCursor(this, () -> {
|
||||
FormatDialog dialog = new FormatDialog(getWindowAncestor(RenamePanel.this), getFormatEditorMode(binding), binding);
|
||||
dialog.setLocation(getOffsetLocation(dialog.getOwner()));
|
||||
dialog.setVisible(true);
|
||||
|
||||
@ -581,10 +576,14 @@ public class RenamePanel extends JComponent {
|
||||
break;
|
||||
}
|
||||
|
||||
if (lockOnBinding == null) {
|
||||
if (binding == null) {
|
||||
persistentLastFormatState.setValue(dialog.getMode().name());
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
debug.log(Level.WARNING, e::getMessage);
|
||||
}
|
||||
}
|
||||
|
||||
protected final Action clearFilesAction = newAction("Clear All", ResourceManager.getIcon("action.clear"), evt -> {
|
||||
|
Loading…
Reference in New Issue
Block a user