-
Notifications
You must be signed in to change notification settings - Fork 129
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
Showing
7 changed files
with
234 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as React from 'react'; | ||
import { IExtensionService, IStatusBarItem } from 'mo'; | ||
import { IExtension } from 'mo/model/extension'; | ||
import { statusBarService } from 'mo/services'; | ||
import { Icon } from 'mo/components/icon'; | ||
|
||
function init() { | ||
const problems: IStatusBarItem = { | ||
id: 'MoProblems', | ||
sortIndex: 1, | ||
name: 'Problems', | ||
}; | ||
|
||
const notifications: IStatusBarItem = { | ||
id: 'MoNotification', | ||
sortIndex: 1, | ||
name: 'Notification', | ||
render: () => <Icon type="bell" />, | ||
}; | ||
|
||
statusBarService.appendLeftItem(problems); | ||
statusBarService.appendRightItem(notifications); | ||
|
||
statusBarService.onClick(function (e, item) { | ||
console.log('statusBarService:', e, item); | ||
}); | ||
} | ||
|
||
export const ExtendStatusBar: IExtension = { | ||
activate(extensionCtx: IExtensionService) { | ||
init(); | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1,28 +1,45 @@ | ||
import { EventBus } from 'mo/common/event'; | ||
import { observable } from 'mo/common/observable'; | ||
import { container, inject, injectable } from 'tsyringe'; | ||
import * as React from 'react'; | ||
import { injectable } from 'tsyringe'; | ||
|
||
export interface IStatusBarItem {} | ||
export interface IStatusBarItem extends HTMLElementProps { | ||
id: string; | ||
sortIndex: number; | ||
onClick?(e: React.MouseEvent, item?: IStatusBarItem); | ||
render?: () => ReactNode; | ||
name?: string; | ||
} | ||
|
||
export interface IStatusBar { | ||
data: IStatusBarItem[]; | ||
onClick: (event: React.MouseEvent<any, any>) => void; | ||
render?: () => React.ReactNode | JSX.Element; | ||
rightItems: IStatusBarItem[]; | ||
leftItems: IStatusBarItem[]; | ||
onClick?: (e: React.MouseEvent, item: IStatusBarItem) => void; | ||
} | ||
|
||
/** | ||
* The activity bar event definition | ||
*/ | ||
export enum StatusBarEvent { | ||
/** | ||
* Selected an activity bar | ||
*/ | ||
onClick = 'statusBar.onClick', | ||
/** | ||
* Activity bar data changed | ||
*/ | ||
DataChanged = 'statusBar.data', | ||
} | ||
|
||
@observable() | ||
@injectable() | ||
export class StatusBarModel implements IStatusBar { | ||
public data: IStatusBarItem[] = []; | ||
|
||
constructor(@inject('StatusBarData') data: IStatusBarItem[] = []) { | ||
this.data = data; | ||
} | ||
public leftItems: IStatusBarItem[] = []; | ||
public rightItems: IStatusBarItem[] = []; | ||
|
||
public render!: () => React.ReactNode; | ||
|
||
public onClick = (event: React.MouseEvent) => { | ||
console.log('onClick:', event); | ||
public onClick = (e: React.MouseEvent, item: IStatusBarItem) => { | ||
EventBus.emit(StatusBarEvent.onClick, e, item); | ||
}; | ||
} | ||
|
||
container.register('StatusBarData', { useValue: [] }); |
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,28 @@ | ||
import { classNames, getBEMElement } from 'mo/common/className'; | ||
import { IStatusBarItem } from 'mo/model/workbench/statusBar'; | ||
import * as React from 'react'; | ||
import { memo } from 'react'; | ||
import { statusBarClassName } from './statusBar'; | ||
|
||
function StatusItem(props: IStatusBarItem) { | ||
const itemClassName = getBEMElement(statusBarClassName, 'item'); | ||
|
||
const { className, onClick, name, render, ...extra } = props; | ||
|
||
const clsName = classNames(itemClassName, className); | ||
const events = { | ||
onClick: function (e: React.MouseEvent) { | ||
onClick?.(e, props); | ||
}, | ||
}; | ||
|
||
return ( | ||
<div className={clsName} {...extra}> | ||
<a tabIndex={-1} title={name} {...events}> | ||
{render ? render() : name} | ||
</a> | ||
</div> | ||
); | ||
} | ||
|
||
export default memo(StatusItem); |
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 |
---|---|---|
@@ -1,10 +1,59 @@ | ||
@import 'mo/style/common'; | ||
|
||
#{$statusBar} { | ||
align-items: center; | ||
bottom: 0; | ||
display: flex; | ||
height: 22px; | ||
justify-content: center; | ||
position: absolute; | ||
text-align: center; | ||
width: 100%; | ||
z-index: 1; | ||
|
||
&__left-items, | ||
&__right-items { | ||
display: flex; | ||
height: 100%; | ||
} | ||
|
||
&__left-items { | ||
flex-grow: 1; | ||
|
||
> :first-child { | ||
margin-left: 7px; | ||
} | ||
} | ||
|
||
&__right-items { | ||
direction: rtl; | ||
|
||
> :last-child { | ||
margin-right: 7px; | ||
} | ||
} | ||
|
||
&__item { | ||
height: 100%; | ||
|
||
a { | ||
align-items: center; | ||
cursor: pointer; | ||
display: flex; | ||
height: 100%; | ||
outline-width: 0; | ||
overflow: hidden; | ||
padding: 0 5px; | ||
text-overflow: ellipsis; | ||
white-space: pre; | ||
} | ||
|
||
&:hover { | ||
background-color: rgba(255, 255, 255, 0.12); | ||
} | ||
|
||
.codicon { | ||
font-size: 14px; | ||
} | ||
} | ||
} |