Skip to content

Commit a8d7619

Browse files
committed
1 parent 7b234cf commit a8d7619

File tree

8 files changed

+462
-10
lines changed

8 files changed

+462
-10
lines changed

packages/eez-studio-ui/_stylesheets/project-editor.less

+41
Original file line numberDiff line numberDiff line change
@@ -3643,3 +3643,44 @@
36433643
}
36443644
}
36453645
}
3646+
3647+
.EezStudio_PageZoomButton {
3648+
padding: 1px 6px;
3649+
3650+
background-color: @selectionBackgroundColor;
3651+
&:hover {
3652+
background-color: @actionHoverColor;
3653+
}
3654+
}
3655+
3656+
.EezStudio_PageZoomButton_DropdownContent {
3657+
font-size: 0.8rem;
3658+
3659+
padding: 0;
3660+
margin: 0;
3661+
3662+
border-radius: 4px;
3663+
overflow: hidden;
3664+
3665+
ul {
3666+
margin: 0;
3667+
padding: 5px;
3668+
3669+
.EezStudio_PageZoomButton_DropdownContent_ZoomInput {
3670+
margin: 4px;
3671+
}
3672+
3673+
li {
3674+
list-style: none;
3675+
cursor: pointer;
3676+
&:hover {
3677+
color: @selectionColor;
3678+
background-color: @selectionBackgroundColor;
3679+
}
3680+
3681+
.form-check {
3682+
margin: 2px 16px;
3683+
}
3684+
}
3685+
}
3686+
}

packages/project-editor/core/objectAdapter.ts

+22-4
Original file line numberDiff line numberDiff line change
@@ -552,10 +552,12 @@ export class TreeObjectAdapter {
552552

553553
createSelectionContextMenu(
554554
actions?: {
555-
pasteSelection: () => void;
556-
duplicateSelection: () => void;
555+
add?: boolean;
556+
pasteSelection?: () => void;
557+
duplicateSelection?: () => void;
557558
},
558-
editable?: boolean
559+
editable?: boolean,
560+
additionalMenuItems?: Electron.MenuItem[]
559561
) {
560562
let menuItems: Electron.MenuItem[] = [];
561563

@@ -589,7 +591,12 @@ export class TreeObjectAdapter {
589591
parentObject = this.object;
590592
}
591593

592-
if (editable && parentObject && canAdd(parentObject)) {
594+
if (
595+
editable &&
596+
parentObject &&
597+
canAdd(parentObject) &&
598+
!(actions?.add === false)
599+
) {
593600
menuItems.push(
594601
new MenuItem({
595602
label: "Add",
@@ -739,6 +746,17 @@ export class TreeObjectAdapter {
739746
);
740747
}
741748

749+
if (additionalMenuItems) {
750+
if (menuItems.length > 0) {
751+
menuItems.push(
752+
new MenuItem({
753+
type: "separator"
754+
})
755+
);
756+
}
757+
menuItems = menuItems.concat(additionalMenuItems);
758+
}
759+
742760
if (menuItems.length > 0) {
743761
const menu = new Menu();
744762
menuItems.forEach(menuItem => menu.append(menuItem));

packages/project-editor/features/page/PageEditor.tsx

+12-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export class PageTabState extends FlowTabState {
9797

9898
makeObservable(this, {
9999
_transform: observable,
100+
transform: computed,
100101
frontFace: computed
101102
});
102103

@@ -154,12 +155,20 @@ export class PageTabState extends FlowTabState {
154155
}
155156

156157
get transform() {
158+
if (this.projectStore.uiStateStore.globalFlowZoom) {
159+
const newTransform = this._transform.clone();
160+
newTransform.scale = this.projectStore.uiStateStore.flowZoom;
161+
return newTransform;
162+
}
157163
return this._transform;
158164
}
159165

160166
set transform(transform: Transform) {
161167
runInAction(() => {
162168
this._transform = transform;
169+
if (this.projectStore.uiStateStore.globalFlowZoom) {
170+
this.projectStore.uiStateStore.flowZoom = transform.scale;
171+
}
163172
});
164173
}
165174

@@ -187,7 +196,9 @@ export class PageTabState extends FlowTabState {
187196
x: state.transform.translate.x ?? 0,
188197
y: state.transform.translate.y ?? 0
189198
},
190-
scale: state.transform.scale ?? 1
199+
scale: this.projectStore.uiStateStore.globalFlowZoom
200+
? this.projectStore.uiStateStore.flowZoom
201+
: state.transform.scale ?? 1
191202
});
192203
}
193204

packages/project-editor/flow/editor/context.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ class ViewState implements IViewState {
6767
this.flowContext.tabState.resetTransform();
6868
}
6969

70+
centerView() {
71+
this.flowContext.tabState.centerView();
72+
}
73+
7074
getResizeHandlers(): IResizeHandler[] | undefined {
7175
const isEditor = this.document && !this.document.projectStore.runtime;
7276

packages/project-editor/flow/editor/flow-document.tsx

+63-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { computed, makeObservable } from "mobx";
1+
import { computed, makeObservable, runInAction } from "mobx";
22
import { intersection } from "lodash";
3+
import { MenuItem } from "@electron/remote";
34

45
import type { Point, Rect } from "eez-studio-shared/geometry";
56
import type { IDocument } from "project-editor/flow/flow-interfaces";
@@ -153,7 +154,67 @@ export class FlowDocument implements IDocument {
153154
}
154155

155156
createContextMenu(objects: TreeObjectAdapter[]) {
156-
return this.flow.createSelectionContextMenu();
157+
return this.flow.createSelectionContextMenu(
158+
{
159+
add: false
160+
},
161+
undefined,
162+
objects.length == 0
163+
? [
164+
new MenuItem({
165+
label: "Center View",
166+
click: async () => {
167+
this.flowContext.viewState.centerView();
168+
}
169+
}),
170+
...(this.projectStore.uiStateStore.globalFlowZoom
171+
? []
172+
: [
173+
new MenuItem({
174+
label: "Set the Same Zoom for All Pages",
175+
click: async () => {
176+
for (const page of this.projectStore
177+
.project.pages) {
178+
if (page != this.flow.object) {
179+
let uiState =
180+
this.projectStore.uiStateStore.getObjectUIState(
181+
page,
182+
"flow-state"
183+
);
184+
185+
if (!uiState) {
186+
uiState = {};
187+
}
188+
189+
uiState.transform = {
190+
translate: {
191+
x: this.flowContext
192+
.viewState.transform
193+
.translate.x,
194+
y: this.flowContext
195+
.viewState.transform
196+
.translate.y
197+
},
198+
scale: this.flowContext
199+
.viewState.transform
200+
.scale
201+
};
202+
203+
runInAction(() => {
204+
this.projectStore.uiStateStore.updateObjectUIState(
205+
page,
206+
"flow-state",
207+
uiState
208+
);
209+
});
210+
}
211+
}
212+
}
213+
})
214+
])
215+
]
216+
: undefined
217+
);
157218
}
158219

159220
duplicateSelection = () => {

packages/project-editor/flow/flow-tab-state.tsx

+10
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ export abstract class FlowTabState implements IEditorState {
6363
};
6464
}
6565

66+
centerView(transform?: Transform) {
67+
if (!transform) {
68+
transform = this.transform;
69+
}
70+
transform.translate = {
71+
x: -this.flow.pageRect.width / 2,
72+
y: -this.flow.pageRect.height / 2
73+
};
74+
}
75+
6676
abstract get frontFace(): boolean;
6777
abstract set frontFace(value: boolean);
6878

0 commit comments

Comments
 (0)