-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3e08ea2
commit 378d611
Showing
5 changed files
with
187 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Git, IGitExtension } from './tokens'; | ||
import * as fileStyle from './style/BrowserFile'; | ||
import { DirListing, FileBrowser } from '@jupyterlab/filebrowser'; | ||
import { Contents } from '@jupyterlab/services'; | ||
import { DocumentRegistry } from '@jupyterlab/docregistry'; | ||
import { ITranslator } from '@jupyterlab/translation'; | ||
|
||
const statusStyles: Map<Git.StatusCode, string> = new Map([ | ||
// note: the classes cannot repeat, | ||
// otherwise the assignments will be overwritten | ||
['M', fileStyle.modified], | ||
['A', fileStyle.added], | ||
['D', fileStyle.deleted], | ||
['R', fileStyle.renamed], | ||
['C', fileStyle.copied], | ||
['U', fileStyle.updated], | ||
['?', fileStyle.untracked], | ||
['!', fileStyle.ignored] | ||
]); | ||
|
||
class GitListingRenderer extends DirListing.Renderer { | ||
constructor(private gitExtension: IGitExtension) { | ||
super(); | ||
} | ||
|
||
updateItemNode( | ||
node: HTMLElement, | ||
model: Contents.IModel, | ||
fileType?: DocumentRegistry.IFileType, | ||
translator?: ITranslator | ||
) { | ||
super.updateItemNode(node, model, fileType, translator); | ||
const file = this.gitExtension.getFile(model.path); | ||
let status_code: Git.StatusCode = null; | ||
if (file) { | ||
status_code = file.status === 'staged' ? file.x : file.y; | ||
} | ||
|
||
for (const [otherStatus, className] of statusStyles.entries()) { | ||
if (status_code === otherStatus) { | ||
node.classList.add(className); | ||
} else { | ||
node.classList.remove(className); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export function substituteListingRenderer( | ||
extension: IGitExtension, | ||
fileBrowser: FileBrowser | ||
): void { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
const listing: DirListing = fileBrowser._listing; | ||
const renderer = new GitListingRenderer(extension); | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
listing._renderer = renderer; | ||
} |
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,100 @@ | ||
import { style } from 'typestyle'; | ||
|
||
export const modified = style({ | ||
$nest: { | ||
'&:not(.jp-mod-selected)': { | ||
$nest: { | ||
'.jp-DirListing-itemText': { | ||
color: 'var(--md-blue-700)' | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
export const updated = style({ | ||
$nest: { | ||
'&:not(.jp-mod-selected)': { | ||
$nest: { | ||
'.jp-DirListing-itemText': { | ||
color: 'var(--md-cyan-700)' | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
export const renamed = style({ | ||
$nest: { | ||
'&:not(.jp-mod-selected)': { | ||
$nest: { | ||
'.jp-DirListing-itemText': { | ||
color: 'var(--md-purple-700)' | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
export const copied = style({ | ||
$nest: { | ||
'&:not(.jp-mod-selected)': { | ||
$nest: { | ||
'.jp-DirListing-itemText': { | ||
color: 'var(--md-indigo-700)' | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
export const untracked = style({ | ||
$nest: { | ||
'&:not(.jp-mod-selected)': { | ||
$nest: { | ||
'.jp-DirListing-itemText': { | ||
color: 'var(--md-red-700)' | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
export const added = style({ | ||
$nest: { | ||
'&:not(.jp-mod-selected)': { | ||
$nest: { | ||
'.jp-DirListing-itemText': { | ||
color: 'var(--md-green-700)' | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
export const ignored = style({ | ||
$nest: { | ||
'&:not(.jp-mod-selected)': { | ||
$nest: { | ||
'.jp-DirListing-itemText': { | ||
color: 'var(--md-grey-700)' | ||
} | ||
} | ||
} | ||
} | ||
}); | ||
|
||
export const deleted = style({ | ||
$nest: { | ||
'&:not(.jp-mod-selected)': { | ||
$nest: { | ||
'.jp-DirListing-itemText': { | ||
color: 'var(--md-grey-700)' | ||
} | ||
} | ||
}, | ||
'.jp-DirListing-itemText': { | ||
textDecoration: 'line-through' | ||
} | ||
} | ||
}); |
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