##// END OF EJS Templates
Removed unused that from widget manager
Jonathan Frederic -
Show More
@@ -1,130 +1,129 b''
1 1 //----------------------------------------------------------------------------
2 2 // Copyright (C) 2013 The IPython Development Team
3 3 //
4 4 // Distributed under the terms of the BSD License. The full license is in
5 5 // the file COPYING, distributed as part of this software.
6 6 //----------------------------------------------------------------------------
7 7
8 8 //============================================================================
9 9 // WidgetModel, WidgetView, and WidgetManager
10 10 //============================================================================
11 11 /**
12 12 * Base Widget classes
13 13 * @module IPython
14 14 * @namespace IPython
15 15 * @submodule widget
16 16 */
17 17
18 18 (function () {
19 19 "use strict";
20 20
21 21 // Use require.js 'define' method so that require.js is intelligent enough to
22 22 // syncronously load everything within this file when it is being 'required'
23 23 // elsewhere.
24 24 define(["components/underscore/underscore-min",
25 25 "components/backbone/backbone-min",
26 26 ], function (underscore, backbone) {
27 27
28 28 //--------------------------------------------------------------------
29 29 // WidgetManager class
30 30 //--------------------------------------------------------------------
31 31 var WidgetManager = function () {
32 32 this.comm_manager = null;
33 33 this.widget_model_types = {};
34 34 this.widget_view_types = {};
35 35 this._model_instances = {};
36 36
37 var that = this;
38 37 Backbone.sync = function (method, model, options, error) {
39 38 var result = model._handle_sync(method, options);
40 39 if (options.success) {
41 40 options.success(result);
42 41 }
43 42 };
44 43 };
45 44
46 45
47 46 WidgetManager.prototype.attach_comm_manager = function (comm_manager) {
48 47 this.comm_manager = comm_manager;
49 48
50 49 // Register already register widget model types with the comm manager.
51 50 for (var widget_model_name in this.widget_model_types) {
52 51 this.comm_manager.register_target(widget_model_name, $.proxy(this._handle_com_open, this));
53 52 }
54 53 };
55 54
56 55
57 56 WidgetManager.prototype.register_widget_model = function (widget_model_name, widget_model_type) {
58 57 // Register the widget with the comm manager. Make sure to pass this object's context
59 58 // in so `this` works in the call back.
60 59 if (this.comm_manager !== null) {
61 60 this.comm_manager.register_target(widget_model_name, $.proxy(this._handle_com_open, this));
62 61 }
63 62 this.widget_model_types[widget_model_name] = widget_model_type;
64 63 };
65 64
66 65
67 66 WidgetManager.prototype.register_widget_view = function (widget_view_name, widget_view_type) {
68 67 this.widget_view_types[widget_view_name] = widget_view_type;
69 68 };
70 69
71 70
72 71 WidgetManager.prototype.get_msg_cell = function (msg_id) {
73 72 if (IPython.notebook !== undefined && IPython.notebook !== null) {
74 73 return IPython.notebook.get_msg_cell(msg_id);
75 74 }
76 75 };
77 76
78 77
79 78 WidgetManager.prototype.get_model = function (widget_id) {
80 79 var model = this._model_instances[widget_id];
81 80 if (model !== undefined && model.id == widget_id) {
82 81 return model;
83 82 }
84 83 return null;
85 84 };
86 85
87 86
88 87 WidgetManager.prototype.get_kernel = function () {
89 88 if (this.comm_manager === null) {
90 89 return null;
91 90 } else {
92 91 return this.comm_manager.kernel;
93 92 }
94 93 };
95 94
96 95
97 96 WidgetManager.prototype.on_create_widget = function (callback) {
98 97 this._create_widget_callback = callback;
99 98 };
100 99
101 100
102 101 WidgetManager.prototype._handle_create_widget = function (widget_model) {
103 102 if (this._create_widget_callback) {
104 103 try {
105 104 this._create_widget_callback(widget_model);
106 105 } catch (e) {
107 106 console.log("Exception in WidgetManager callback", e, widget_model);
108 107 }
109 108 }
110 109 };
111 110
112 111
113 112 WidgetManager.prototype._handle_com_open = function (comm, msg) {
114 113 var widget_type_name = msg.content.target_name;
115 114 var widget_model = new this.widget_model_types[widget_type_name](this, comm.comm_id, comm);
116 115 this._model_instances[comm.comm_id] = widget_model;
117 116 this._handle_create_widget(widget_model);
118 117 };
119 118
120 119 //--------------------------------------------------------------------
121 120 // Init code
122 121 //--------------------------------------------------------------------
123 122 IPython.WidgetManager = WidgetManager;
124 123 if (IPython.widget_manager === undefined || IPython.widget_manager === null) {
125 124 IPython.widget_manager = new WidgetManager();
126 125 }
127 126
128 127 return IPython.widget_manager;
129 128 });
130 129 }()); No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now