mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-25 09:52:19 +01:00
workbench switcher
This commit is contained in:
parent
117c5475ed
commit
d94ab88563
14 changed files with 83 additions and 27 deletions
|
|
@ -20,6 +20,7 @@ import { PatternLinearOperation } from "./features/patternLinear/patternLinear.o
|
|||
import { PatternRadialOperation } from "./features/patternRadial/patternRadial.operation"
|
||||
//imports of action type commands
|
||||
import { GetVolume } from './actions/getVolume/getVolume.action';
|
||||
import {GiCubes} from "react-icons/gi";
|
||||
|
||||
|
||||
export const ModelerWorkspace: WorkbenchConfig = {
|
||||
|
|
@ -55,5 +56,6 @@ export const ModelerWorkspace: WorkbenchConfig = {
|
|||
"CYLINDER", "BOX", "CONE", "SPHERE", "TORUS", "-",
|
||||
"HOLE_TOOL", "-", 'GET_VOLUME',
|
||||
]
|
||||
}
|
||||
},
|
||||
icon: GiCubes
|
||||
}
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
import { WorkbenchConfig } from "cad/workbench/workbenchService";
|
||||
import {WorkbenchConfig} from "cad/workbench/workbenchService";
|
||||
|
||||
//imports of feature history type commands
|
||||
import { smTabOperation } from "./features/smTab/smTab.operation";
|
||||
import { smFlangeOperation } from "./features/smFlange/smFlange.operation";
|
||||
import {smTabOperation} from "./features/smTab/smTab.operation";
|
||||
import {smFlangeOperation} from "./features/smFlange/smFlange.operation";
|
||||
import {SiKaufland} from "react-icons/si";
|
||||
|
||||
|
||||
//imports of action type commands
|
||||
|
|
@ -27,5 +28,6 @@ export const sheetMetalWorkspace: WorkbenchConfig = {
|
|||
"HOLE_TOOL", "-",
|
||||
"SM_TAB","SM_FLANGE"
|
||||
]
|
||||
}
|
||||
},
|
||||
icon: SiKaufland
|
||||
}
|
||||
14
package-lock.json
generated
14
package-lock.json
generated
|
|
@ -25,7 +25,7 @@
|
|||
"react": "^16.13.1",
|
||||
"react-color": "^2.19.3",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-icons": "^4.2.0",
|
||||
"react-icons": "^4.4.0",
|
||||
"react-toastify": "^5.5.0",
|
||||
"sprintf": "0.1.5",
|
||||
"three": "^0.118.3"
|
||||
|
|
@ -12046,9 +12046,9 @@
|
|||
}
|
||||
},
|
||||
"node_modules/react-icons": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/react-icons/-/react-icons-4.2.0.tgz",
|
||||
"integrity": "sha512-rmzEDFt+AVXRzD7zDE21gcxyBizD/3NqjbX6cmViAgdqfJ2UiLer8927/QhhrXQV7dEj/1EGuOTPp7JnLYVJKQ==",
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/react-icons/-/react-icons-4.4.0.tgz",
|
||||
"integrity": "sha512-fSbvHeVYo/B5/L4VhB7sBA1i2tS8MkT0Hb9t2H1AVPkwGfVHLJCqyr2Py9dKMxsyM63Eng1GkdZfbWj+Fmv8Rg==",
|
||||
"peerDependencies": {
|
||||
"react": "*"
|
||||
}
|
||||
|
|
@ -25715,9 +25715,9 @@
|
|||
}
|
||||
},
|
||||
"react-icons": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/react-icons/-/react-icons-4.2.0.tgz",
|
||||
"integrity": "sha512-rmzEDFt+AVXRzD7zDE21gcxyBizD/3NqjbX6cmViAgdqfJ2UiLer8927/QhhrXQV7dEj/1EGuOTPp7JnLYVJKQ==",
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/react-icons/-/react-icons-4.4.0.tgz",
|
||||
"integrity": "sha512-fSbvHeVYo/B5/L4VhB7sBA1i2tS8MkT0Hb9t2H1AVPkwGfVHLJCqyr2Py9dKMxsyM63Eng1GkdZfbWj+Fmv8Rg==",
|
||||
"requires": {}
|
||||
},
|
||||
"react-is": {
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@
|
|||
"react": "^16.13.1",
|
||||
"react-color": "^2.19.3",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-icons": "^4.2.0",
|
||||
"react-icons": "^4.4.0",
|
||||
"react-toastify": "^5.5.0",
|
||||
"sprintf": "0.1.5",
|
||||
"three": "^0.118.3",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import React, {useContext} from 'react';
|
||||
import {AppContext} from "../dom/components/AppContext";
|
||||
import {isMenuAction} from "cad/dom/menu/menuPlugin";
|
||||
|
||||
export function ActionButtonBehavior({children, actionId}) {
|
||||
|
||||
|
|
@ -21,7 +22,16 @@ export function ActionButtonBehavior({children, actionId}) {
|
|||
'data-action-id': actionId,
|
||||
onClick: e => {
|
||||
canceled = true;
|
||||
actionService.run(actionId, e);
|
||||
let data;
|
||||
if (isMenuAction(actionId)) {
|
||||
data = {
|
||||
x: e.pageX,
|
||||
y: e.pageY
|
||||
}
|
||||
} else {
|
||||
data = e;
|
||||
}
|
||||
actionService.run(actionId, data);
|
||||
},
|
||||
onMouseEnter: e => {
|
||||
updateCoords(e);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import * as ActionHelpers from './actionHelpers'
|
||||
import {AiOutlineExport} from "react-icons/ai";
|
||||
import {CurrentWorkbenchIcon} from "cad/workbench/CurrentWorkbenchIcon";
|
||||
|
||||
export default [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,13 +11,12 @@ export const HeadsUpToolbar = connect(streams => combine(
|
|||
streams.ui.toolbars.headsUpQuickActions).map(([actions, showTitles, quickActions]) => ({actions, showTitles, quickActions})))(
|
||||
function HeadsUpToolbar({actions, showTitles, quickActions}) {
|
||||
return <Toolbar flat>
|
||||
<div className={ls.mainActions}>
|
||||
<ToolbarActionButtons actions={actions} showTitles={showTitles}/>
|
||||
</div>
|
||||
|
||||
<div className={ls.quickButtons}>
|
||||
{quickActions.map(actionId => <ConnectedActionButton size='small' key={actionId} actionId={actionId} />)}
|
||||
</div>
|
||||
<div className={ls.mainActions}>
|
||||
<ToolbarActionButtons actions={actions} showTitles={showTitles}/>
|
||||
</div>
|
||||
</Toolbar>
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
flex-direction: column;
|
||||
justify-content: space-evenly;
|
||||
flex: 0 0;
|
||||
border-left: 1px solid #8e8e8e;
|
||||
padding-left: 3px;
|
||||
border-right: 1px solid #8e8e8e;
|
||||
padding-right: 3px;
|
||||
& > * {
|
||||
font-size: 16px;
|
||||
padding: 5px 2px;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,9 @@ function MenuHolder({menus}) {
|
|||
}
|
||||
|
||||
function ActionMenu({actions, keymap, ...menuState}) {
|
||||
if (!Array.isArray(actions)) {
|
||||
actions = actions();
|
||||
}
|
||||
return <Menu {...menuState}>
|
||||
{actions.map((action, index) => {
|
||||
if (action === '-') {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import constraintGlobalActions from "../../sketcher/actions/constraintGlobalActi
|
|||
import generalToolActions from "../../sketcher/actions/generalToolActions";
|
||||
import sketcherControlActions from "./sketcherControlActions";
|
||||
import {ApplicationContext} from "context";
|
||||
import {WorkbenchConfig} from "cad/workbench/workbenchService";
|
||||
import {RiCompasses2Line} from "react-icons/ri";
|
||||
|
||||
export default function (ctx: ApplicationContext) {
|
||||
|
||||
|
|
@ -53,10 +53,9 @@ export default function (ctx: ApplicationContext) {
|
|||
ui: {
|
||||
toolbar: SKETCHER_MODE_HEADS_UP_ACTIONS,
|
||||
toolbarStyle: 'compact'
|
||||
}
|
||||
},
|
||||
icon: RiCompasses2Line
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
const SKETCHER_PREFIX = 'sketcher.';
|
||||
|
|
|
|||
8
web/app/cad/workbench/CurrentWorkbenchIcon.tsx
Normal file
8
web/app/cad/workbench/CurrentWorkbenchIcon.tsx
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import React from "react";
|
||||
import {useStream} from "ui/effects";
|
||||
|
||||
export function CurrentWorkbenchIcon() {
|
||||
const currentWorkbench = useStream(ctx => ctx.workbenchService.currentWorkbench$);
|
||||
const Icon = currentWorkbench.icon;
|
||||
return <Icon />;
|
||||
}
|
||||
|
|
@ -19,7 +19,7 @@ export function activate(ctx) {
|
|||
['ShowSketches', {label: 'sketches'}], ['DeselectAll', {label: null}], ['ToggleCameraMode', {label: null}]
|
||||
];
|
||||
|
||||
streams.ui.toolbars.headsUpQuickActions.value = ['Save', 'StlExport'];
|
||||
streams.ui.toolbars.headsUpQuickActions.value = ['Save', 'StlExport', 'menu.workbenches'];
|
||||
|
||||
ctx.actionService.registerActions(CoreActions);
|
||||
ctx.actionService.registerActions(OperationActions);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import {ApplicationContext} from "context";
|
||||
import {WorkbenchService} from "cad/workbench/workbenchService";
|
||||
import {CurrentWorkbenchIcon} from "cad/workbench/CurrentWorkbenchIcon";
|
||||
|
||||
|
||||
declare module 'context' {
|
||||
interface CoreContext {
|
||||
interface ApplicationContext {
|
||||
|
||||
workbenchService: WorkbenchService;
|
||||
}
|
||||
|
|
@ -15,6 +16,20 @@ export const WorkbenchPlugin = {
|
|||
activate(ctx: ApplicationContext) {
|
||||
|
||||
ctx.workbenchService = new WorkbenchService(ctx);
|
||||
|
||||
ctx.services.menu.registerMenus([
|
||||
{
|
||||
id: 'workbenches',
|
||||
label: 'workbenches',
|
||||
icon: CurrentWorkbenchIcon,
|
||||
|
||||
info: 'switch workbench',
|
||||
actions: () => {
|
||||
const workbenches = ctx.workbenchService.workbenches$.value;
|
||||
return Object.keys(workbenches).filter(w => w !== 'sketcher').map(w => 'workbench.switch.' + workbenches[w].workbenchId)
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import {state} from "lstream";
|
|||
import {Index} from "gems/indexType";
|
||||
import {ApplicationContext, CoreContext} from "context";
|
||||
import {ActionRef} from "cad/dom/uiPlugin";
|
||||
import {IconDeclaration} from "cad/icons/IconDeclaration";
|
||||
import {CurrentWorkbenchIcon} from "cad/workbench/CurrentWorkbenchIcon";
|
||||
|
||||
export class WorkbenchService {
|
||||
|
||||
|
|
@ -21,7 +23,7 @@ export class WorkbenchService {
|
|||
ctx.uiService.streams.toolbars.headsUp.next(workbenchConfig.ui.toolbar);
|
||||
const toolbarStyle = workbenchConfig.ui.toolbarStyle || 'large'
|
||||
ctx.uiService.streams.toolbars.headsUpShowTitles.next(toolbarStyle === "large");
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
getWorkbenchConfig(workbenchId: string): WorkbenchConfig {
|
||||
|
|
@ -39,6 +41,20 @@ export class WorkbenchService {
|
|||
...workbenches,
|
||||
[workbenchConfig.workbenchId]: workbenchConfig
|
||||
}));
|
||||
|
||||
this.ctx.actionService.registerAction(
|
||||
{
|
||||
id: 'workbench.switch.' + workbenchConfig.workbenchId,
|
||||
appearance: {
|
||||
icon: workbenchConfig.icon,
|
||||
label: workbenchConfig.workbenchId,
|
||||
info: 'switches to ' + workbenchConfig.workbenchId,
|
||||
},
|
||||
invoke: (ctx) => {
|
||||
this.switchWorkbench(workbenchConfig.workbenchId);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
switchWorkbench(workbenchId: string) {
|
||||
|
|
@ -65,4 +81,5 @@ export interface WorkbenchConfig {
|
|||
features: OperationDescriptor<any>[];
|
||||
actions: ActionDefinition<any>[];
|
||||
ui: WorkbenchUIConfig;
|
||||
icon: IconDeclaration
|
||||
}
|
||||
Loading…
Reference in a new issue