WorkbenchViewController
@objcMembers open class WorkbenchViewController: UIViewController
View controller for editing a workspace.
-
Set of
UIStateValue
values representing the workbench state.Declaration
Swift
public typealias UIState = Set<UIStateValue>
-
Underlying type for a UI state value.
Declaration
Swift
public typealias UIStateValue = Int
-
State indicating the trash can is open.
Declaration
Swift
public let stateTrashCanOpen = WorkbenchViewController.newUIStateValue()
-
State indicating the trash can is highlighted
Declaration
Swift
public let stateTrashCanHighlighted = WorkbenchViewController.newUIStateValue()
-
State indicating the toolbox category is open.
Declaration
Swift
public let stateCategoryOpen = WorkbenchViewController.newUIStateValue()
-
State indicating a text field is being edited.
Declaration
Swift
public let stateEditingTextField = WorkbenchViewController.newUIStateValue()
-
State indicating a block is currently being dragged.
Declaration
Swift
public let stateDraggingBlock = WorkbenchViewController.newUIStateValue()
-
State indicating a popover is being presented.
Declaration
Swift
public let statePresentingPopover = WorkbenchViewController.newUIStateValue()
-
State indicating the user panned the workspace.
Declaration
Swift
public let stateDidPanWorkspace = WorkbenchViewController.newUIStateValue()
-
State indicating the user tapped the workspace.
Declaration
Swift
public let stateDidTapWorkspace = WorkbenchViewController.newUIStateValue()
-
The main workspace view controller
Declaration
Swift
public private(set) lazy var workspaceViewController: WorkspaceViewController =
-
The trash can view.
Declaration
Swift
open fileprivate(set) lazy var trashCanView: TrashCanView =
-
The undo button
Declaration
Swift
open fileprivate(set) lazy var undoButton: UIButton =
-
The redo button
Declaration
Swift
open fileprivate(set) lazy var redoButton: UIButton =
-
The toolbox category view controller.
Declaration
Swift
open fileprivate(set) lazy var toolboxCategoryViewController: ToolboxCategoryViewController =
-
The layout engine to use for all views
Declaration
Swift
public final let engine: LayoutEngine
-
The layout builder to create layout hierarchies
Declaration
Swift
public final let layoutBuilder: LayoutBuilder
-
The factory for creating blocks under this workbench. Any block added to the workbench should be able to be re-created using this factory.
Declaration
Swift
public final let blockFactory: BlockFactory
-
The factory for creating views
Declaration
Swift
public final let viewFactory: ViewFactory
-
The style of workbench
Declaration
Swift
public final let style: Style
-
The main workspace.
Declaration
Swift
open var workspace: Workspace?
-
The toolbox that has been loaded via
loadToolbox(:)
Declaration
Swift
open var toolbox: Toolbox?
-
The
NameManager
that controls the variables in this workbench’s scope.Declaration
Swift
public let variableNameManager: NameManager
-
Coordinator that handles logic for managing procedure functionality
Declaration
Swift
public var procedureCoordinator: ProcedureCoordinator?
-
Displays (
true
) or hides (false
) a trash can. By default, this value is set totrue
.Declaration
Swift
open var enableTrashCan: Bool = true
-
If
true
, blocks dragged into trash are kept in memory and can be recalled by tapping the trash can. Iffalse
, blocks are not kept in memory and tapping the trash can is disabled. Defaults tofalse
.Declaration
Swift
open var keepTrashedBlocks: Bool = false
-
Enables or disables pinch zooming of the workspace. Defaults to
true
.Declaration
Swift
open var allowZoom: Bool
-
Enables or disables the ability to undo/redo actions in the workspace. Defaults to
true
.Declaration
Swift
open var allowUndoRedo: Bool = true
-
Enables or disables the
interactivePopGestureRecognizer
onself.navigationController
(i.e. the backswipe gesture onUINavigationController
). Defaults tofalse
.Declaration
Swift
open var allowInteractivePopGestureRecognizer: Bool = false
-
The background color to use for the main workspace.
Declaration
Swift
public var workspaceBackgroundColor: UIColor?
-
Flag for whether the toolbox drawer should stay visible once it has been opened (
true
) or if it should automatically close itself when the user does something else (false
). By default, this value is set tofalse
.Declaration
Swift
open var toolboxDrawerStaysOpen: Bool = false
-
A set containing all active states of the UI.
Declaration
Swift
open fileprivate(set) var state = WorkbenchViewController.UIState()
-
The delegate for events that occur in the workbench
Declaration
Swift
open weak var delegate: WorkbenchViewControllerDelegate?
-
Controller for listing the toolbox categories
Declaration
Swift
open fileprivate(set) lazy var toolboxCategoryListViewController:
-
Controller for managing the trash can workspace
Declaration
Swift
open fileprivate(set) lazy var trashCanViewController: TrashCanViewController =
-
Flag determining if this view controller should be recording events for undo/redo purposes.
Declaration
Swift
open fileprivate(set) var shouldRecordEvents = true
-
Stack of events to run when applying
undo
actions. The events are sorted in chronological order, where the first event toundo
is at the end of the array.Declaration
Swift
open var undoStack = [BlocklyEvent]()
-
Stack of events to run when applying
redo
actions. The events are sorted in reverse chronological order, where the first event toredo
is at the end of the array.Declaration
Swift
open var redoStack = [BlocklyEvent]()
-
The pan gesture recognizer attached to the main workspace.
Declaration
Swift
public var workspacePanGesetureRecognizer: UIPanGestureRecognizer!
-
The tap gesture recognizer attached to the main workspace.
Declaration
Swift
public private(set) lazy var workspaceTapGestureRecognizer: UITapGestureRecognizer =
-
Creates the workbench with defaults for
self.engine
,self.layoutBuilder
,self.viewFactory
.Declaration
Swift
public init(style: Style)
-
Creates the workbench.
Declaration
Swift
public init( style: Style, engine: LayoutEngine, layoutBuilder: LayoutBuilder, blockFactory: BlockFactory, viewFactory: ViewFactory, variableNameManager: NameManager, procedureCoordinator: ProcedureCoordinator)
-
Automatically creates a
WorkspaceLayout
andWorkspaceLayoutCoordinator
for a given workspace (using both theself.engine
andself.layoutBuilder
instances). The workspace is then rendered into the view controller.Note
All blocks inworkspace
must have correspondingBlockBuilder
objects inself.blockFactory
, based on their associated block name. This is needed for things like handling undo/redo and automatic creation of variable blocks.Throws
BlocklyError
: Thrown if an associatedWorkspaceLayout
could not be created for the workspace, or if no correspondingBlockBuilder
could be found inself.blockFactory
for at least one of the blocks inworkspace
.Declaration
Swift
open func loadWorkspace(_ workspace: Workspace) throws
-
Automatically creates a
WorkspaceLayout
andWorkspaceLayoutCoordinator
for a given workspace (using both theself.engine
andself.layoutBuilder
instances). The workspace is then rendered into the view controller.Note
All blocks inworkspace
must have correspondingBlockBuilder
objects inself.blockFactory
, based on their associated block name. This is needed for things like handling undo/redo and automatic creation of variable blocks.Throws
BlocklyError
: Thrown if an associatedWorkspaceLayout
could not be created for the workspace, or if no correspondingBlockBuilder
could be found inself.blockFactory
for at least one of the blocks inworkspace
.Declaration
Swift
open func loadWorkspace(_ workspace: Workspace, connectionManager: ConnectionManager) throws
-
Automatically creates a
ToolboxLayout
for a givenToolbox
(using both theself.engine
andself.layoutBuilder
instances) and loads it into the view controller.Note
All blocks defined by categories intoolbox
must have correspondingBlockBuilder
objects inself.blockFactory
, based on their associated block name. This is needed for things like handling undo/redo and automatic creation of variable blocks.Throws
BlocklyError
: Thrown if an associatedToolboxLayout
could not be created for the toolbox, or if no correspondingBlockBuilder
could be found inself.blockFactory
for at least one of the blocks specified intoolbox
.Declaration
Swift
open func loadToolbox(_ toolbox: Toolbox) throws
-
Refreshes the UI based on the current version of
self.workspace
andself.toolbox
.Declaration
Swift
open func refreshView()
-
Creates a new
UIStateValue
. Subclasses may call this to create additional state values that should be handled byWorkbenchViewController
.Declaration
Swift
public static func newUIStateValue() -> UIStateValue
Return Value
A unique
UIStateValue
. -
Adds an individual UI state value to the current state of the workbench. Generally, this call should be matched by a future call to
removeUIStateValue(_:animated:)
.See
To change the behavior of how the state value is added to the current state, seeWorkbenchViewControllerDelegate.workbenchViewController(_:shouldKeepStates:forStateValue:)
.Declaration
Swift
public func addUIStateValue(_ stateValue: UIStateValue, animated: Bool = true)
-
Removes a UI state value from the current state of the workbench. This call should have matched a previous call to
addUIStateValue(_:animated:)
.Declaration
Swift
public func removeUIStateValue(_ stateValue: UIStateValue, animated: Bool = true)
-
Declaration
Swift
open func eventManager(_ eventManager: EventManager, didFireEvent event: BlocklyEvent)
-
Updates the workbench based on a
BlocklyEvent
.Declaration
Swift
open func update(fromEvent event: BlocklyEvent, runForward: Bool)
-
Updates the workbench based on a
BlocklyEvent.Create
.Declaration
Swift
open func update(fromCreateEvent event: BlocklyEvent.Create, runForward: Bool)
-
Updates the workbench based on a
BlocklyEvent.Delete
.Declaration
Swift
open func update(fromDeleteEvent event: BlocklyEvent.Delete, runForward: Bool)
-
Updates the workbench based on a
BlocklyEvent.Move
.Declaration
Swift
open func update(fromMoveEvent event: BlocklyEvent.Move, runForward: Bool)
-
Updates the workbench based on a
BlocklyEvent.Change
.Declaration
Swift
open func update(fromChangeEvent event: BlocklyEvent.Change, runForward: Bool)
-
Declaration
Swift
open func workspaceViewController( _ workspaceViewController: WorkspaceViewController, didAddBlockView blockView: BlockView)
-
Declaration
Swift
open func workspaceViewController( _ workspaceViewController: WorkspaceViewController, didRemoveBlockView blockView: BlockView)
-
Declaration
Swift
open func workspaceViewController( _ workspaceViewController: WorkspaceViewController, willPresentViewController viewController: UIViewController)
-
Declaration
Swift
open func workspaceViewControllerDismissedViewController( _ workspaceViewController: WorkspaceViewController)
-
Adds a copy of a given block to the trash.
Declaration
Swift
public func addBlockToTrash(_ block: Block)
-
Adds custom gesture recognizers to a block view. It is automatically called by
WorkbenchViewController
when a block view is added to the workspace.Subclasses may override this to add custom gesture tracking to a block view. The default implementation does nothing.
Declaration
Swift
open func addGestureTracking(forBlockView blockView: BlockView)
-
Removes all gesture recognizers and any on-going gesture data from a block view.
Declaration
Swift
open func removeGestureTracking(forBlockView blockView: BlockView)
-
Declaration
Swift
public func toolboxCategoryListViewController( _ controller: ToolboxCategoryListViewController, didSelectCategory category: Toolbox.Category)
-
Declaration
Swift
public func toolboxCategoryListViewControllerDidDeselectCategory( _ controller: ToolboxCategoryListViewController)
-
Highlights a block in the workspace.
Declaration
Swift
public func highlightBlock(blockUUID: String)
-
Unhighlights a block in the workspace.
- Paramater blockUUID: The UUID of the block to unhighlight.
Declaration
Swift
public func unhighlightBlock(blockUUID: String)
-
Unhighlights all blocks in the workspace.
Declaration
Swift
public func unhighlightAllBlocks()
-
Automatically adjusts the workspace’s scroll view to bring a given
Block
into view.Declaration
Swift
public func scrollBlockIntoView( blockUUID: String, location: WorkspaceView.Location = .anywhere, animated: Bool)
-
Sets the content offset of the workspace’s scroll view so that a specific location in the workspace is visible.
Declaration
Swift
public func setViewport(to location: WorkspaceView.Location, animated: Bool)
-
Pan gesture event handler for a block view inside
self.workspaceView
.Declaration
Swift
open func blocklyPanGestureRecognizer( _ gesture: BlocklyPanGestureRecognizer, didTouchBlock block: BlockView, touch: UITouch, touchState: BlocklyPanGestureRecognizer.TouchState)