Skip to content

Commit 4b31e63

Browse files
committed
feat: tab bar working prototype
1 parent f2b6994 commit 4b31e63

File tree

9 files changed

+581
-0
lines changed

9 files changed

+581
-0
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
define(function (require, exports, module) {
2+
3+
const WorkspaceManager = require("view/WorkspaceManager");
4+
const DocumentManager = require("document/DocumentManager");
5+
const ViewUtils = require("utils/ViewUtils");
6+
const WorkingSetView = require("project/WorkingSetView");
7+
const FileUtils = require("file/FileUtils");
8+
9+
10+
/**
11+
* Shows the tab bar, when its hidden.
12+
* Its only shown when tab bar is enabled and there is atleast one working file
13+
*
14+
* @param {$.Element} $tabBar - The tab bar element
15+
*/
16+
function _showTabBar($tabBar) {
17+
if ($tabBar) {
18+
$tabBar.show();
19+
// when we add/remove something from the editor, the editor shifts up/down which leads to blank space
20+
// so we need to recompute the layout to make sure things are in the right place
21+
WorkspaceManager.recomputeLayout(true);
22+
}
23+
}
24+
25+
/**
26+
* Hides the tab bar.
27+
* Its hidden when tab bar feature is disabled or there are no working files
28+
*
29+
* @param {$.Element} $tabBar - The tab bar element
30+
*/
31+
function _hideTabBar($tabBar) {
32+
if ($tabBar) {
33+
$tabBar.hide();
34+
WorkspaceManager.recomputeLayout(true);
35+
}
36+
}
37+
38+
39+
/**
40+
* Entry is a single object that comes from MainViewManager's getWorkingSet
41+
* We extract the required data from the entry
42+
*
43+
* @param {Object} entry - A single file entry from MainViewManager.getWorkingSet()
44+
* @returns {Object} - the required data
45+
*/
46+
function _getRequiredDataFromEntry(entry) {
47+
return {
48+
path: entry.fullPath,
49+
name: entry.name,
50+
isFile: entry.isFile,
51+
isDirty: entry.isDirty,
52+
isPinned: entry.isPinned,
53+
displayName: entry.name // Initialize displayName with name, it will be updated if duplicates are found
54+
};
55+
}
56+
57+
/**
58+
* checks whether a file is dirty or not
59+
*
60+
* @param {File} file - the file to check
61+
* @return {boolean} true if the file is dirty, false otherwise
62+
*/
63+
function _isFileModified(file) {
64+
const doc = DocumentManager.getOpenDocumentForPath(file.fullPath);
65+
return doc && doc.isDirty;
66+
}
67+
68+
69+
/**
70+
* Returns a jQuery object containing the file icon for a given file
71+
*
72+
* @param {Object} fileData - The file data object
73+
* @returns {jQuery} jQuery object containing the file icon
74+
*/
75+
function _getFileIcon(fileData) {
76+
const $link = $("<a href='#' class='mroitem'></a>").html(
77+
ViewUtils.getFileEntryDisplay({ name: fileData.name })
78+
);
79+
WorkingSetView.useIconProviders({
80+
fullPath: fileData.path,
81+
name: fileData.name,
82+
isFile: true
83+
}, $link);
84+
return $link.children().first();
85+
}
86+
87+
88+
/**
89+
* Checks for duplicate file names in the working set and updates displayName accordingly
90+
* if duplicate file names are found, we update the displayName to include the directory
91+
*
92+
* @param {Array} workingSet - The working set to check for duplicates
93+
*/
94+
function _handleDuplicateFileNames(workingSet) {
95+
// Create a map to track filename occurrences
96+
const fileNameCount = {};
97+
98+
// First, count occurrences of each filename
99+
workingSet.forEach(entry => {
100+
if (!fileNameCount[entry.name]) {
101+
fileNameCount[entry.name] = 1;
102+
} else {
103+
fileNameCount[entry.name]++;
104+
}
105+
});
106+
107+
// Then, update the displayName for files with duplicate names
108+
workingSet.forEach(entry => {
109+
if (fileNameCount[entry.name] > 1) {
110+
// Get the parent directory name
111+
const path = entry.path;
112+
const parentDir = FileUtils.getDirectoryPath(path);
113+
114+
// Get just the directory name, not the full path
115+
const dirName = parentDir.split("/");
116+
// Get the parent directory name (second-to-last part of the path)
117+
const parentDirName = dirName[dirName.length - 2] || "";
118+
119+
// Set the display name to include the parent directory
120+
entry.displayName = parentDirName + "/" + entry.name;
121+
} else {
122+
entry.displayName = entry.name;
123+
}
124+
});
125+
}
126+
127+
128+
module.exports = {
129+
_showTabBar,
130+
_hideTabBar,
131+
_getRequiredDataFromEntry,
132+
_isFileModified,
133+
_getFileIcon,
134+
_handleDuplicateFileNames
135+
};
136+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div id="tab-bar-container" class="tab-bar-container">
2+
<div id="phoenix-tab-bar" class="phoenix-tab-bar">
3+
4+
</div>
5+
</div>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div id="tab-bar-container" class="tab-bar-container">
2+
<div id="phoenix-tab-bar-2" class="phoenix-tab-bar">
3+
4+
</div>
5+
</div>

0 commit comments

Comments
 (0)