-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix display artifacts with long paths
... as a view with the hierarchical subfolders in the project tree. Fixes: #79
- Loading branch information
1 parent
c62fb73
commit c9fa766
Showing
5 changed files
with
114 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import * as path from 'path'; | ||
|
||
import { isChildOf } from '../qbsutils'; | ||
|
||
import { QbsProtocolSourceArtifactData } from '../protocol/qbsprotocolsourceartifactdata'; | ||
|
||
export class QbsFolderData { | ||
private readonly folders: QbsFolderData[] | ||
private readonly sources: QbsProtocolSourceArtifactData[] | ||
|
||
public constructor( | ||
allSources: QbsProtocolSourceArtifactData[], | ||
private readonly fsPath: string) { | ||
|
||
this.folders = allSources | ||
.map(artifactData => { | ||
return path.dirname(artifactData.getFilePath() || ""); | ||
}) | ||
.filter(fsPath => { | ||
if (fsPath && (fsPath.length > 0)) | ||
return isChildOf(fsPath, this.fsPath); | ||
}) | ||
.map(fsPath => { | ||
const parts = path.relative(this.fsPath, fsPath).split(path.sep); | ||
return (parts.length > 0) ? path.join(this.fsPath, parts[0]) : ""; | ||
}).filter((fsPath, index, self) => { | ||
return (fsPath && (index === self.indexOf(fsPath))); | ||
}).map(fsPath => { | ||
return new QbsFolderData(allSources, fsPath); | ||
}); | ||
|
||
this.sources = allSources.filter(artifactData => { | ||
const fsPath = artifactData.getFilePath(); | ||
if (fsPath) | ||
return (path.normalize(path.dirname(fsPath)) === path.normalize(this.fsPath)); | ||
}); | ||
} | ||
|
||
public getFolders(): QbsFolderData[] { return this.folders; } | ||
public getSources(): QbsProtocolSourceArtifactData[] { return this.sources; } | ||
public getPath(): string { return this.fsPath; } | ||
public getName(): string { return path.basename(this.fsPath); } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import * as vscode from 'vscode'; | ||
|
||
import { QbsBaseNode } from './qbsbasenode'; | ||
import { QbsFolderData } from './qbsfolderdata'; | ||
import { QbsProtocolSourceArtifactData } from '../protocol/qbsprotocolsourceartifactdata'; | ||
import { QbsSourceArtifactNode } from './qbssourceartifactnode'; | ||
|
||
enum QbsFolderNodeIcon { | ||
Folder = 'folder', | ||
} | ||
|
||
/** The data type encapsulates the Qbs files folder object to display in the project tree. */ | ||
export class QbsFolderNode extends QbsBaseNode { | ||
private readonly name: string | ||
private readonly folders: QbsFolderData[] | ||
private readonly sources: QbsProtocolSourceArtifactData[] | ||
|
||
public constructor( | ||
resourcesPath: string, | ||
showDisabledNodes: boolean, | ||
folderData: QbsFolderData, | ||
private readonly isEnabled: boolean) { | ||
super(resourcesPath, showDisabledNodes); | ||
|
||
const name = folderData.getName(); | ||
if (!name) | ||
throw new Error('Unable to create folder node because the name is undefined'); | ||
this.name = name; | ||
|
||
this.folders = folderData.getFolders(); | ||
this.sources = folderData.getSources(); | ||
} | ||
|
||
public getTreeItem(): vscode.TreeItem { | ||
const item = new vscode.TreeItem(this.getLabel(), vscode.TreeItemCollapsibleState.Collapsed); | ||
item.id = this.uuid; | ||
item.iconPath = new vscode.ThemeIcon(QbsFolderNodeIcon.Folder); | ||
return item; | ||
} | ||
|
||
public getChildren(): QbsBaseNode[] { | ||
return [ | ||
...this.folders.map(folderData => new QbsFolderNode( | ||
this.resourcesPath, this.showDisabledNodes, folderData, this.isEnabled)), | ||
...this.sources.map(artifactData => new QbsSourceArtifactNode( | ||
this.resourcesPath, this.showDisabledNodes, artifactData, this.isEnabled)) | ||
]; | ||
} | ||
|
||
private getLabel(): string { return QbsBaseNode.createLabel(this.name, this.isEnabled); } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters