-
Notifications
You must be signed in to change notification settings - Fork 318
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 13377aa
Showing
6 changed files
with
141 additions
and
8 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,61 @@ | ||
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([ | ||
['M', fileStyle.modified], | ||
['A', fileStyle.added], | ||
['D', fileStyle.deleted], | ||
['R', fileStyle.modified], | ||
['C', fileStyle.modified], | ||
['U', fileStyle.modified], | ||
['?', 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); | ||
console.log(model.path, 'file status', file?.status); | ||
let status_code: Git.StatusCode = null; | ||
if (file) { | ||
status_code = file.status === 'staged' ? file.x : file.y; | ||
console.log(model.path, 'file x, y', file.x, file.y); | ||
console.log(model.path, 'file status code', status_code); | ||
} | ||
|
||
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,64 @@ | ||
import { style } from 'typestyle'; | ||
|
||
export const modified = style({ | ||
$nest: { | ||
'&:not(.jp-mod-selected)': { | ||
$nest: { | ||
'.jp-DirListing-itemText': { | ||
color: 'var(--md-blue-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
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