Пример #1
0
 _.forEach(fileNames, function (files) {
     if (files.length > 1) {
         var displayPaths = ViewUtils.getDirNamesForDuplicateFiles(files);
         files.forEach(function (file, i) {
             file.subDirStr = displayPaths[i];
         });
     }
 });
Пример #2
0
        /**
         * @private
         * Prepare file list for display
         */
        function _prepFileList(fileInfos) {
            var i, j, firstDupeIndex,
                displayPaths = [],
                dupeList = [];
            
            // Add subdir field to each entry
            fileInfos.forEach(function (fileInfo) {
                fileInfo.subDirStr = "";
            });

            // Add directory path to files with the same name so they can be
            // distinguished in list. Start with list sorted by name.
            fileInfos.sort(_sortFileInfos);

            // For identical names, add a subdir
            for (i = 1; i < fileInfos.length; i++) {
                if (_sortFileInfos(fileInfos[i - 1], fileInfos[i]) === 0) {
                    // Duplicates found
                    firstDupeIndex = i - 1;
                    dupeList.push(fileInfos[i - 1]);
                    dupeList.push(fileInfos[i]);

                    // Lookahead for more dupes
                    while (++i < fileInfos.length &&
                            _sortFileInfos(dupeList[0], fileInfos[i]) === 0) {
                        dupeList.push(fileInfos[i]);
                    }

                    // Get minimum subdir to make each unique
                    displayPaths = ViewUtils.getDirNamesForDuplicateFiles(dupeList);

                    // Add a subdir to each dupe entry
                    for (j = 0; j < displayPaths.length; j++) {
                        fileInfos[firstDupeIndex + j].subDirStr = displayPaths[j];
                    }

                    // Release memory
                    dupeList = [];
                }
            }
            
            // Sort by name again, so paths are sorted
            fileInfos.sort(_sortFileInfos);

            return fileInfos;
        }
Пример #3
0
    /**
     * @private
     * Adds directory names to elements representing passed files in working tree
     * @param {Array.<File>} filesList - list of Files with the same filename
     */
    function _addDirectoryNamesToWorkingTreeFiles(filesList) {
        // filesList must have at least two files in it for this to make sense
        if (filesList.length <= 1) {
            return;
        }

        var displayPaths = ViewUtils.getDirNamesForDuplicateFiles(filesList);

        // Go through open files and add directories to appropriate entries
        $openFilesContainer.find("ul > li").each(function () {
            var $li = $(this);
            var io = filesList.indexOf($li.data(_FILE_KEY));
            if (io !== -1) {
                var dirSplit = displayPaths[io].split("/");
                if (dirSplit.length > 3) {
                    displayPaths[io] = dirSplit[0] + "/\u2026/" + dirSplit[dirSplit.length - 1];
                }

                var $dir = $("<span class='directory'/>").html(" &mdash; " + displayPaths[io]);
                $li.children("a").append($dir);
            }
        });
    }