diff --git a/index.html b/index.html index d864754..cba17fb 100644 --- a/index.html +++ b/index.html @@ -49,6 +49,16 @@ Replace: +
+ Case: + +
Extension Options:
diff --git a/model.js b/model.js index d800ce3..b4d815b 100644 --- a/model.js +++ b/model.js @@ -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 @@ -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) { @@ -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, @@ -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) { @@ -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); @@ -454,6 +493,7 @@ function model(callback) { setPrefix: setPrefix, setPostfix: setPostfix, setFindReplace: setFindReplace, + setChangeCase: setChangeCase, executeRename: executeRename, setSelection: setSelection, toggleSelection: toggleSelection, diff --git a/settings.js b/settings.js index d3a9246..15103ea 100644 --- a/settings.js +++ b/settings.js @@ -31,6 +31,7 @@ function settings(onLoad) { "prefix", "postfix", "findReplace", + "changeCase", "lowercaseExtensions", "uppercaseExtensions", "haveCustomExtensions", diff --git a/view.js b/view.js index 8f4a132..03bed69 100644 --- a/view.js +++ b/view.js @@ -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"); @@ -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; @@ -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);