Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
logging-scratch-gui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Goessmann
logging-scratch-gui
Commits
3bd97f47
Commit
3bd97f47
authored
8 years ago
by
Paul Kaplan
Browse files
Options
Downloads
Patches
Plain Diff
Listen to translate and zoom functions and store values based on target id
parent
40eeabdd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/containers/blocks.jsx
+45
-0
45 additions, 0 deletions
src/containers/blocks.jsx
with
45 additions
and
0 deletions
src/containers/blocks.jsx
+
45
−
0
View file @
3bd97f47
...
...
@@ -6,6 +6,15 @@ const VM = require('scratch-vm');
const
BlocksComponent
=
require
(
'
../components/blocks/blocks.jsx
'
);
const
addFunctionListener
=
(
object
,
property
,
callback
)
=>
{
const
oldFn
=
object
[
property
];
object
[
property
]
=
function
()
{
const
result
=
oldFn
.
apply
(
this
,
arguments
);
callback
.
apply
(
this
,
result
);
return
result
;
};
};
class
Blocks
extends
React
.
Component
{
constructor
(
props
)
{
super
(
props
);
...
...
@@ -19,14 +28,24 @@ class Blocks extends React.Component {
'
onBlockGlowOff
'
,
'
onVisualReport
'
,
'
onWorkspaceUpdate
'
,
'
onWorkspaceMetricsChange
'
,
'
setBlocks
'
]);
this
.
state
=
{
workspaceMetrics
:
{}};
}
componentDidMount
()
{
const
workspaceConfig
=
defaultsDeep
({},
Blocks
.
defaultOptions
,
this
.
props
.
options
);
this
.
workspace
=
this
.
ScratchBlocks
.
inject
(
this
.
blocks
,
workspaceConfig
);
// @todo change this when blockly supports UI events
addFunctionListener
(
this
.
workspace
,
'
translate
'
,
this
.
onWorkspaceMetricsChange
);
addFunctionListener
(
this
.
workspace
,
'
zoom
'
,
this
.
onWorkspaceMetricsChange
);
this
.
attachVM
();
}
shouldComponentUpdate
()
{
return
false
;
}
componentWillUnmount
()
{
this
.
detachVM
();
this
.
workspace
.
dispose
();
...
...
@@ -52,6 +71,19 @@ class Blocks extends React.Component {
this
.
props
.
vm
.
off
(
'
VISUAL_REPORT
'
,
this
.
onVisualReport
);
this
.
props
.
vm
.
off
(
'
workspaceUpdate
'
,
this
.
onWorkspaceUpdate
);
}
onWorkspaceMetricsChange
()
{
const
target
=
this
.
props
.
vm
.
editingTarget
;
if
(
target
&&
target
.
id
)
{
const
workspaceMetrics
=
Object
.
assign
({},
this
.
state
.
workspaceMetrics
,
{
[
target
.
id
]:
{
scrollX
:
this
.
workspace
.
scrollX
,
scrollY
:
this
.
workspace
.
scrollY
,
scale
:
this
.
workspace
.
scale
}
});
this
.
setState
({
workspaceMetrics
});
}
}
onScriptGlowOn
(
data
)
{
this
.
workspace
.
glowStack
(
data
.
id
,
true
);
}
...
...
@@ -68,12 +100,25 @@ class Blocks extends React.Component {
this
.
workspace
.
reportValue
(
data
.
id
,
data
.
value
);
}
onWorkspaceUpdate
(
data
)
{
if
(
this
.
props
.
vm
.
editingTarget
&&
!
this
.
state
.
workspaceMetrics
[
this
.
props
.
vm
.
editingTarget
.
id
])
{
this
.
onWorkspaceMetricsChange
();
}
this
.
ScratchBlocks
.
Events
.
disable
();
this
.
workspace
.
clear
();
const
dom
=
this
.
ScratchBlocks
.
Xml
.
textToDom
(
data
.
xml
);
this
.
ScratchBlocks
.
Xml
.
domToWorkspace
(
dom
,
this
.
workspace
);
this
.
ScratchBlocks
.
Events
.
enable
();
this
.
workspace
.
toolbox_
.
refreshSelection
();
if
(
this
.
props
.
vm
.
editingTarget
&&
this
.
state
.
workspaceMetrics
[
this
.
props
.
vm
.
editingTarget
.
id
])
{
const
{
scrollX
,
scrollY
,
scale
}
=
this
.
state
.
workspaceMetrics
[
this
.
props
.
vm
.
editingTarget
.
id
];
this
.
workspace
.
scrollX
=
scrollX
;
this
.
workspace
.
scrollY
=
scrollY
;
this
.
workspace
.
scale
=
scale
;
this
.
workspace
.
resize
();
}
}
setBlocks
(
blocks
)
{
this
.
blocks
=
blocks
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment