Ext.define("Ext.ux.form.field.FileEditor", {

	extend: "Ext.form.field.Text",

	alias: [
		"widget.ux.form.field.fileeditor",
		"widget.field.fileeditor"
	],

	requires: [
		"Ext.ux.file.view.Editor"
	],

	triggers: {
		edit: {
			cls: "pf-edit",
			handler: "onEditClick",
			weight: 1,
			scope: "this"
		}
	},

	config: {
		fileExtension: [
			{
				"ext": "*",
				"desc": "All Files (*.*)"
			}
		]
	},

	initComponent: function() {

		var i_self = this;
		i_self.callParent(arguments);
	},

	onEditClick: function() {

		var i_self = this;

		var value = i_self.getValue();

		if (value) {

			var i_window = Ext.widget("window", {
				width: 800,
				height: 600,
				modal: true,
				layout: "fit"
			});

			var i_editor = Ext.widget("file.editor", {
				file: value,
				useOwner: true,
				allowNew: false,
				allowOpen: false,
				fileExtension: i_self.getFileExtension(),
				listeners: {
					filesave: {
						fn: function(i_editor, s_file) {

							i_self.setValue(s_file);

							i_window.close();
						}
					}
				}
			});

			i_window.add(i_editor);

			i_window.show();
		}
	}
});
