coderespawn / dock-spawn

Dock Spawn is a web based dock layout engine that aids in creating flexible user interfaces by enabling panels to be docked on the screen similar to Visual Studio IDE
http://dockspawn.com
MIT License
255 stars 76 forks source link

Loading dock state doesn't work in examples #21

Open skalkin opened 9 years ago

skalkin commented 9 years ago

Here is a modified code of the dock_spawn_demo_simple.dart, the only thing I've changed is added the button that invokes dockManager.loadState(dockManager.saveState()). When user clicks the button, the null pointer exception is raised. Am I using the loadState/saveState methods in the right way?

import 'dart:html';
import 'package:dock_spawn/dock_spawn.dart';

void main() {
  new DockManagerDemo();
}

class DockManagerDemo {
  DockManager dockManager;

  DockManagerDemo() {
    // Convert a div to the dock manager.  Panels can then be docked on to it
    dockManager = new DockManager(query("#my_dock_manager"));
    dockManager.initialize();

    // Let the dock manager element fill in the entire screen
    window.onResize.listen(onResized);
    onResized(null);

    query("#solution_window").children.add(new ButtonElement()
      ..text="Reload"
      ..onClick.listen((_) => dockManager.loadState(dockManager.saveState())));

    // Convert existing elements on the page into "Panels". 
    // They can then be docked on to the dock manager 
    // Panels get a titlebar and a close button, and can also be 
    // converted to a floating dialog box which can be dragged / resized 
    var solution = new PanelContainer(query("#solution_window"), dockManager);
    var output = new PanelContainer(query("#output_window"), dockManager);
    var properties = new PanelContainer(query("#properties_window"), dockManager);
    var toolbox = new PanelContainer(query("#toolbox_window"), dockManager);
    var outline = new PanelContainer(query("#outline_window"), dockManager);
    var problems = new PanelContainer(query("#problems_window"), dockManager);
    var editor1 = new PanelContainer(query("#editor1_window"), dockManager);
    var editor2 = new PanelContainer(query("#editor2_window"), dockManager);

    // Dock the panels on the dock manager
    DockNode documentNode = dockManager.context.model.documentManagerNode;
    DockNode solutionNode = dockManager.dockLeft(documentNode, solution, 0.20);
    DockNode outlineNode = dockManager.dockFill(solutionNode, outline);
    DockNode propertiesNode = dockManager.dockDown(outlineNode, properties, 0.6);
    DockNode outputNode = dockManager.dockDown(documentNode, output, 0.4);
    DockNode problemsNode = dockManager.dockRight(outputNode, problems, 0.40);
    DockNode toolboxNode = dockManager.dockRight(documentNode, toolbox, 0.20);

    DockNode editor1Node = dockManager.dockFill(documentNode, editor1);
    DockNode editor2Node = dockManager.dockFill(documentNode, editor2);
  }

  void onResized(Event event) {
    dockManager.resize(window.innerWidth, window.innerHeight);
  }
}