Skip to content

Commit

Permalink
Add case options; fixes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
jtooker committed Jan 17, 2017
1 parent 51c32bc commit 3659c0f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
Replace:
<input type="text" name="replace" id="replace" />
</div>
<div class="optionLine">
Case:
<select id="caseComboBox">
<option value="unchanged">UnChanGEd</option>
<option value="uppercase">TO UPPER</option>
<option value="lowercase">to lower</option>
<option value="capitalize_words">Capitalize Words</option>
<option value="capitalize_first_letter">Capitalize first letter</option>
</select>
</div>
<div class="optionTitle">
Extension Options:
</div>
Expand Down
40 changes: 40 additions & 0 deletions model.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ function model(callback) {
return typeof f === "function";
}

// private -----------------------------------------------------------------
function capitalizeFirstLetter(text) {
text = text.toLowerCase();

return text.replace(/^./, function (first) {
return first.toUpperCase();
});
}

// private -----------------------------------------------------------------
function capitalizeEachWord(text) {
// http://stackoverflow.com/questions/15150168/
return text.replace(/[^\s]+/g, capitalizeFirstLetter);
}

// private -----------------------------------------------------------------
function calculateName(name) {
var stem; // up to last period
Expand All @@ -49,6 +64,22 @@ function model(callback) {
if (m_settings.usePostfix) {
stem = stem + m_settings.postfix;
}
switch (m_settings.changeCase) {
case "unchanged":
break;
case "uppercase":
stem = stem.toUpperCase();
break;
case "lowercase":
stem = stem.toLowerCase();
break;
case "capitalize_words":
stem = capitalizeEachWord(stem);
break;
case "capitalize_first_letter":
stem = capitalizeFirstLetter(stem);
break;
}

// extension modifications
if (m_settings.lowercaseExtensions) {
Expand Down Expand Up @@ -163,6 +194,7 @@ function model(callback) {
prefix: m_settings.prefix,
usePostfix: m_settings.usePostfix,
postfix: m_settings.postfix,
changeCase: m_settings.changeCase,
lowercaseExtensions: m_settings.lowercaseExtensions,
uppercaseExtensions: m_settings.uppercaseExtensions,
haveCustomExtensions: m_settings.haveCustomExtensions,
Expand Down Expand Up @@ -354,6 +386,12 @@ function model(callback) {
refresh();
}

// private -----------------------------------------------------------------
function setChangeCase(changeCase) {
m_settings.changeCase = changeCase;
refresh();
}

// public ------------------------------------------------------------------
function executeRename() {
m_fileInfos.forEach(function (fileInfo) {
Expand Down Expand Up @@ -423,6 +461,7 @@ function model(callback) {
initializeSetting("usePostfix", true);
initializeSetting("prefix", "");
initializeSetting("postfix", "");
initializeSetting("changeCase", "unchanged");
initializeSetting("lowercaseExtensions", false);
initializeSetting("uppercaseExtensions", false);
initializeSetting("haveCustomExtensions", false);
Expand Down Expand Up @@ -454,6 +493,7 @@ function model(callback) {
setPrefix: setPrefix,
setPostfix: setPostfix,
setFindReplace: setFindReplace,
setChangeCase: setChangeCase,
executeRename: executeRename,
setSelection: setSelection,
toggleSelection: toggleSelection,
Expand Down
1 change: 1 addition & 0 deletions settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function settings(onLoad) {
"prefix",
"postfix",
"findReplace",
"changeCase",
"lowercaseExtensions",
"uppercaseExtensions",
"haveCustomExtensions",
Expand Down
6 changes: 6 additions & 0 deletions view.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
var m_postfixTextInput = document.querySelector("#postfix");
var m_findTextInput = document.querySelector("#find");
var m_replaceTextInput = document.querySelector("#replace");
var m_caseComboBox = document.querySelector("#caseComboBox");
var m_lowerExtCheckbox = document.querySelector("#lowerExtCheckbox");
var m_upperExtCheckbox = document.querySelector("#upperExtCheckbox");
var m_extensionToCheckbox = document.querySelector("#extensionToCheckbox");
Expand Down Expand Up @@ -107,6 +108,7 @@
m_findTextInput.value = options.findAndReplaces[0].find;
m_replaceTextInput.value = options.findAndReplaces[0].replace;
}
m_caseComboBox.value = options.changeCase;
m_lowerExtCheckbox.checked = options.lowercaseExtensions;
m_upperExtCheckbox.checked = options.uppercaseExtensions;
m_extensionToCheckbox.checked = options.haveCustomExtensions;
Expand Down Expand Up @@ -251,6 +253,10 @@
m_findTextInput.onchange = storeFindReplace;
m_replaceTextInput.onchange = storeFindReplace;

m_caseComboBox.onchange = function () {
m_model.setChangeCase(m_caseComboBox.value);
};

m_lowerExtCheckbox.addEventListener("click", storeExtensionOptions);
m_upperExtCheckbox.addEventListener("click", storeExtensionOptions);
m_extensionToCheckbox.addEventListener("click", storeExtensionOptions);
Expand Down

0 comments on commit 3659c0f

Please sign in to comment.