Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
Add "{file_name}" parameters for titles
Browse files Browse the repository at this point in the history
Still needs to be documented somewhere
  • Loading branch information
BrunoReX committed Nov 30, 2013
1 parent 54f3e80 commit 4db8b41
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
2 changes: 1 addition & 1 deletion license.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2012 Bruno Barbieri
Copyright (c) 2012-2013 Bruno Barbieri
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
27 changes: 19 additions & 8 deletions src/io/github/brunorex/JMkvpropedit.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.List;

import javax.swing.*;
import javax.swing.table.*;
import javax.swing.filechooser.*;
Expand Down Expand Up @@ -3930,21 +3931,22 @@ private void setCmdLineGeneral() {
cmdLineGeneral[i] += " --edit info";
cmdLineGeneralOpt[i] += " --edit info";

String newTitle = txtTitleGeneral.getText();

if (chbNumbGeneral.isSelected()) {
int pad = 0;

pad = Integer.parseInt(txtNumbPadGeneral.getText());

String newTitle = txtTitleGeneral.getText();
newTitle = newTitle.replace("{num}", Utils.padNumber(pad, start));
start++;

cmdLineGeneral[i] += " --set title=\"" + Utils.escapeQuotes(newTitle) + "\"";
cmdLineGeneralOpt[i] += " --set title=\"" + Utils.escapeName(newTitle) + "\"";
} else {
cmdLineGeneral[i] += " --set title=\"" + Utils.escapeQuotes(txtTitleGeneral.getText()) + "\"";
cmdLineGeneralOpt[i] += " --set title=\"" + Utils.escapeName(txtTitleGeneral.getText()) + "\"";
start++;
}

newTitle = newTitle.replace("{file_name}", Utils.getFileNameWithoutExt((String) modelFiles.get(i)));

cmdLineGeneral[i] += " --set title=\"" + Utils.escapeQuotes(newTitle) + "\"";
cmdLineGeneralOpt[i] += " --set title=\"" + Utils.escapeName(newTitle) + "\"";

}

if (chbExtraCmdGeneral.isSelected() && !txtExtraCmdGeneral.getText().trim().isEmpty()) {
Expand Down Expand Up @@ -4052,6 +4054,9 @@ private void setCmdLineVideo() {
numStartVideo[i]++;
}

tmpText = tmpText.replace("{file_name}", Utils.getFileNameWithoutExt((String) modelFiles.get(i)));
tmpText2 = tmpText2.replace("{file_name}", Utils.getFileNameWithoutExt((String) modelFiles.get(i)));

cmdLineVideo[j] += tmpText;
cmdLineVideoOpt[j] += tmpText2;
}
Expand Down Expand Up @@ -4155,6 +4160,9 @@ private void setCmdLineAudio() {
numStartAudio[i]++;
}

tmpText = tmpText.replace("{file_name}", Utils.getFileNameWithoutExt((String) modelFiles.get(i)));
tmpText2 = tmpText2.replace("{file_name}", Utils.getFileNameWithoutExt((String) modelFiles.get(i)));

cmdLineAudio[j] += tmpText;
cmdLineAudioOpt[j] += tmpText2;
}
Expand Down Expand Up @@ -4258,6 +4266,9 @@ private void setCmdLineSubtitle() {
numStartSubtitle[i]++;
}

tmpText = tmpText.replace("{file_name}", Utils.getFileNameWithoutExt((String) modelFiles.get(i)));
tmpText2 = tmpText2.replace("{file_name}", Utils.getFileNameWithoutExt((String) modelFiles.get(i)));

cmdLineSubtitle[j] += tmpText;
cmdLineSubtitleOpt[j] += tmpText2;
}
Expand Down
27 changes: 25 additions & 2 deletions src/io/github/brunorex/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@

import java.awt.Component;
import java.awt.event.*;
import java.io.File;
import java.text.*;

import javax.swing.*;
import javax.swing.table.*;
import javax.swing.text.*;
Expand Down Expand Up @@ -184,10 +186,31 @@ public static String padNumber(int pad, int number) {
return formatter.format(number);
}

public static String getPathWithoutExt(String file) {
public static int getDotIndex(String file) {
int dotIndex = file.lastIndexOf(".");

return file.substring(0, dotIndex);
if (dotIndex != -1)
return dotIndex;
else
return file.length();
}

public static int getSeparatorIndex(String file) {
int sepIndex = file.lastIndexOf(File.separator);

if (sepIndex != -1) {
return sepIndex+1;
} else {
return 0;
}
}

public static String getFileNameWithoutExt(String file) {
return file.substring(getSeparatorIndex(file), getDotIndex(file));
}

public static String getPathWithoutExt(String file) {
return file.substring(0, getDotIndex(file));
}

/**
Expand Down

0 comments on commit 4db8b41

Please sign in to comment.