Ext.define("IceCap.controller.Emulator", {
	extend: "Ext.app.ViewController",

	alias: "controller.icecap.controller.emulator",

	onNewSession: function() {

		var i_controller = this;
		var i_view = i_controller.getView();

		var i_tabpanel = i_view.getTabArea();

		var i_icecapPanel = Ext.widget("icecap-panel", {
			title: "Icecap",
			closable: true,
			theme: i_view.getTheme()
		});

		var i_active = i_tabpanel.add(i_icecapPanel);
		i_tabpanel.setActiveTab(i_active);
	},

	onAddWebContainer: function(o_data) {

		var i_controller = this;
		var i_view = i_controller.getView();

		var i_tabpanel = i_view.getTabArea();

		var i_webcontainer = Ext.widget("icecap-webcontainer", {
			src: o_data.cmd || o_data.url || o_data.src,
			title: o_data.cmdTitle || o_data.title,
			closable: true
		});

		var i_active = i_tabpanel.add(i_webcontainer);
		i_tabpanel.setActiveTab(i_active);
	},

	onStateNotify: function() {

		var i_controller = this;
		var i_view = i_controller.getView();

		i_view.fireEvent("stateupdate", i_view);
	}
});
