File tree 8 files changed +462
-10
lines changed
eez-studio-ui/_stylesheets
8 files changed +462
-10
lines changed Original file line number Diff line number Diff line change 3643
3643
}
3644
3644
}
3645
3645
}
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
+ }
Original file line number Diff line number Diff line change @@ -552,10 +552,12 @@ export class TreeObjectAdapter {
552
552
553
553
createSelectionContextMenu (
554
554
actions ?: {
555
- pasteSelection : ( ) => void ;
556
- duplicateSelection : ( ) => void ;
555
+ add ?: boolean ;
556
+ pasteSelection ?: ( ) => void ;
557
+ duplicateSelection ?: ( ) => void ;
557
558
} ,
558
- editable ?: boolean
559
+ editable ?: boolean ,
560
+ additionalMenuItems ?: Electron . MenuItem [ ]
559
561
) {
560
562
let menuItems : Electron . MenuItem [ ] = [ ] ;
561
563
@@ -589,7 +591,12 @@ export class TreeObjectAdapter {
589
591
parentObject = this . object ;
590
592
}
591
593
592
- if ( editable && parentObject && canAdd ( parentObject ) ) {
594
+ if (
595
+ editable &&
596
+ parentObject &&
597
+ canAdd ( parentObject ) &&
598
+ ! ( actions ?. add === false )
599
+ ) {
593
600
menuItems . push (
594
601
new MenuItem ( {
595
602
label : "Add" ,
@@ -739,6 +746,17 @@ export class TreeObjectAdapter {
739
746
) ;
740
747
}
741
748
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
+
742
760
if ( menuItems . length > 0 ) {
743
761
const menu = new Menu ( ) ;
744
762
menuItems . forEach ( menuItem => menu . append ( menuItem ) ) ;
Original file line number Diff line number Diff line change @@ -97,6 +97,7 @@ export class PageTabState extends FlowTabState {
97
97
98
98
makeObservable ( this , {
99
99
_transform : observable ,
100
+ transform : computed ,
100
101
frontFace : computed
101
102
} ) ;
102
103
@@ -154,12 +155,20 @@ export class PageTabState extends FlowTabState {
154
155
}
155
156
156
157
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
+ }
157
163
return this . _transform ;
158
164
}
159
165
160
166
set transform ( transform : Transform ) {
161
167
runInAction ( ( ) => {
162
168
this . _transform = transform ;
169
+ if ( this . projectStore . uiStateStore . globalFlowZoom ) {
170
+ this . projectStore . uiStateStore . flowZoom = transform . scale ;
171
+ }
163
172
} ) ;
164
173
}
165
174
@@ -187,7 +196,9 @@ export class PageTabState extends FlowTabState {
187
196
x : state . transform . translate . x ?? 0 ,
188
197
y : state . transform . translate . y ?? 0
189
198
} ,
190
- scale : state . transform . scale ?? 1
199
+ scale : this . projectStore . uiStateStore . globalFlowZoom
200
+ ? this . projectStore . uiStateStore . flowZoom
201
+ : state . transform . scale ?? 1
191
202
} ) ;
192
203
}
193
204
Original file line number Diff line number Diff line change @@ -67,6 +67,10 @@ class ViewState implements IViewState {
67
67
this . flowContext . tabState . resetTransform ( ) ;
68
68
}
69
69
70
+ centerView ( ) {
71
+ this . flowContext . tabState . centerView ( ) ;
72
+ }
73
+
70
74
getResizeHandlers ( ) : IResizeHandler [ ] | undefined {
71
75
const isEditor = this . document && ! this . document . projectStore . runtime ;
72
76
Original file line number Diff line number Diff line change 1
- import { computed , makeObservable } from "mobx" ;
1
+ import { computed , makeObservable , runInAction } from "mobx" ;
2
2
import { intersection } from "lodash" ;
3
+ import { MenuItem } from "@electron/remote" ;
3
4
4
5
import type { Point , Rect } from "eez-studio-shared/geometry" ;
5
6
import type { IDocument } from "project-editor/flow/flow-interfaces" ;
@@ -153,7 +154,67 @@ export class FlowDocument implements IDocument {
153
154
}
154
155
155
156
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
+ ) ;
157
218
}
158
219
159
220
duplicateSelection = ( ) => {
Original file line number Diff line number Diff line change @@ -63,6 +63,16 @@ export abstract class FlowTabState implements IEditorState {
63
63
} ;
64
64
}
65
65
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
+
66
76
abstract get frontFace ( ) : boolean ;
67
77
abstract set frontFace ( value : boolean ) ;
68
78
You can’t perform that action at this time.
0 commit comments