Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/file/FileUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,11 @@ define(function (require, exports, module) {
}

/**
* @private
* Get the file name without the extension.
* @param {string} filename File name of a file or directory
* @return {string} Returns the file name without the extension
*/
function _getFilenameWithoutExtension(filename) {
function getFilenameWithoutExtension(filename) {
var index = filename.lastIndexOf(".");
return index === -1 ? filename : filename.slice(0, index);
}
Expand All @@ -452,8 +451,8 @@ define(function (require, exports, module) {
cmpNames;

if (brackets.platform === "win") {
filename1 = _getFilenameWithoutExtension(filename1);
filename2 = _getFilenameWithoutExtension(filename2);
filename1 = getFilenameWithoutExtension(filename1);
filename2 = getFilenameWithoutExtension(filename2);
}
cmpNames = filename1.toLocaleLowerCase().localeCompare(filename2.toLocaleLowerCase(), undefined, {numeric: true});

Expand Down Expand Up @@ -516,6 +515,7 @@ define(function (require, exports, module) {
exports.getDirectoryPath = getDirectoryPath;
exports.getBaseName = getBaseName;
exports.getRelativeFilename = getRelativeFilename;
exports.getFilenameWithoutExtension = getFilenameWithoutExtension;
exports.getFileExtension = getFileExtension;
exports.getSmartFileExtension = getSmartFileExtension;
exports.compareFilenames = compareFilenames;
Expand Down
21 changes: 18 additions & 3 deletions src/view/ThemeManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,26 @@ define(function (require, exports, module) {
options = options || {};
var fileName = file.name;

// Portip: If no options.name or options.title is provided, then we will rely solely on
// the name of the file to be unique
// If no options.name is provided, then we derive the name of the theme from whichever we find
// first, the options.title or the filename.
if (!options.name) {
if (options.title) {
options.name = options.title;
} else {
// Remove the file extension when the filename is used as the theme name. This is to
// follow CodeMirror conventions where themes are just a CSS file and the filename
// (without the extension) is used to build CSS rules. Also handle removing .min
// in case the ".min" is part of the file name.
options.name = FileUtils.getFilenameWithoutExtension(fileName).replace(/\.min$/, "");
}

// We do a bit of string treatment here to make sure we generate theme names that can be
// used as a CSS class name by CodeMirror.
options.name = options.name.toLocaleLowerCase().replace(/[\W]/g, '-');
}

this.file = file;
this.name = options.name || (options.title || fileName.replace(/.[\w]+$/gi, '')).toLocaleLowerCase().replace(/[\W]/g, '-');
this.name = options.name;
this.displayName = options.title || toDisplayName(fileName);
this.dark = options.theme !== undefined && options.theme.dark === true;
}
Expand Down