<commit_before>/**
 * Dialog_Window is a base class for implementing dialog windows.
 *
 * It sits between Util.Window, a low-level class for creating popup windows,
 * and UI.Dialog, which defines all sorts of callbacks for creating specific
 * parts of the window, and is quite crusty.
 *
 * Constructing a Dialog_Window object does not actually open a window. To do
 * that, call its open() method.
 */
UI.Dialog_Window = function Dialog_Window(loki, options) {
	this.loki = loki;
	this.window = null;
	
	options = options || {};
	this._dialog_uri = options.dialog_uri || this.get_default_dialog_uri();
	this._initial_width = options.width || 600;
	this._initial_height = options.height || 300;
	this._style_sheets = options.style_sheets || [];
	this._root_id = options.root_id || 'root';
	
	this._constructed = false;
};

Util.OOP.mixin(UI.Dialog_Window, {
	/**
	 * Opens the dialog window.
	 *
	 * If the dialog's window does not yet exist, or has been closed, it will
	 * be created, and the dialog object's construct() method will be called to
	 * fill in the dialog's elements.
	 *
	 * Once the window is opened (or if it was already open), any arguments
	 * passed to open() will be passed to the populate() method, which should
	 * fill in the dialog's elements appropriately. If the dialog has any
	 * input, textarea, or select elements with an "autofocus" attribute,
	 * that element will be given focus.
	 *
	 * If the dialog window was already open when this method was called, it
	 * will be brought into focus.
	 */
	open: function open_dialog_window() {
		var self = this;
		var open_args = Util.Array.from(arguments);
		
		// make sure subclasses have defined the right stuff:
		if (typeof(this.construct) != 'function') {
			throw new Error('This dialog implementation is invalid: ' +
				'it has no construct() method.');
		}
		if (typeof(this.populate) != 'function') {
			throw new Error('This dialog implementation is invalid: ' +
				'it has no populate() method.');
		}
		
		function construct_dialog() {
			if (self._constructed) {
				// already done this
				return;
			}
			self._constructed = true;
			
			self.document = self.window.document;
			self.body = self.window.document.body;
			
			self.root = self.document.createElement('DIV');
			self.root.id = self._root_id;
			self.body.appendChild(self.root);
			
			Util.Array.for_each(self._style_sheets, function (sheet_uri) {
				Util.Document.append_style_sheet(self.document,
					self.loki.settings.base_uri + sheet_uri);
			});
			
			self.construct();
			self.populate.apply(self, open_args);
			self._form_autofocus();
		}
		
		if (this.window && !this.window.closed) {
			// the window is already open
			this.populate.apply(this, open_args);
			this.window.focus();
			this._form_autofocus();
		} else {
			var display = Util.Object.clone(UI.Dialog_Window._display_options);
			display.width = this._initial_width;
			display.height = this._initial_height;
			
			this._populated = false;
			this.window = Util.Window.open(this._dialog_uri,
				{display: display});
			if (!this.window) {
				// popup blocked
				return false;<commit_msg>Missed a spot in a renaming.<commit_after>/**
 * Dialog_Window is a base class for implementing dialog windows.
 *
 * It sits between Util.Window, a low-level class for creating popup windows,
 * and UI.Dialog, which defines all sorts of callbacks for creating specific
 * parts of the window, and is quite crusty.
 *
 * Constructing a Dialog_Window object does not actually open a window. To do
 * that, call its open() method.
 */
UI.Dialog_Window = function Dialog_Window(loki, options) {
	this.loki = loki;
	this.window = null;
	
	options = options || {};
	this._dialog_uri = options.dialog_uri || this.get_default_dialog_uri();
	this._initial_width = options.width || 600;
	this._initial_height = options.height || 300;
	this._style_sheets = options.style_sheets || [];
	this._root_id = options.root_id || 'root';
	
	this._constructed = false;
};

Util.OOP.mixin(UI.Dialog_Window, {
	/**
	 * Opens the dialog window.
	 *
	 * If the dialog's window does not yet exist, or has been closed, it will
	 * be created, and the dialog object's construct() method will be called to
	 * fill in the dialog's elements.
	 *
	 * Once the window is opened (or if it was already open), any arguments
	 * passed to open() will be passed to the populate() method, which should
	 * fill in the dialog's elements appropriately. If the dialog has any
	 * input, textarea, or select elements with an "autofocus" attribute,
	 * that element will be given focus.
	 *
	 * If the dialog window was already open when this method was called, it
	 * will be brought into focus.
	 */
	open: function open_dialog_window() {
		var self = this;
		var open_args = Util.Array.from(arguments);
		
		// make sure subclasses have defined the right stuff:
		if (typeof(this.construct) != 'function') {
			throw new Error('This dialog implementation is invalid: ' +
				'it has no construct() method.');
		}
		if (typeof(this.populate) != 'function') {
			throw new Error('This dialog implementation is invalid: ' +
				'it has no populate() method.');
		}
		
		function construct_dialog() {
			if (self._constructed) {
				// already done this
				return;
			}
			self._constructed = true;
			
			self.document = self.window.document;
			self.body = self.window.document.body;
			
			self.root = self.document.createElement('DIV');
			self.root.id = self._root_id;
			self.body.appendChild(self.root);
			
			Util.Array.for_each(self._style_sheets, function (sheet_uri) {
				Util.Document.append_style_sheet(self.document,
					self.loki.settings.base_uri + sheet_uri);
			});
			
			self.construct();
			self.populate.apply(self, open_args);
			self._form_autofocus();
		}
		
		if (this.window && !this.window.closed) {
			// the window is already open
			this.populate.apply(this, open_args);
			this.window.focus();
			this._form_autofocus();
		} else {
			var display = Util.Object.clone(UI.Dialog_Window._display_options);
			display.width = this._initial_width;
			display.height = this._initial_height;
			
			this._constructed = false;
			this.window = Util.Window.open(this._dialog_uri,
				{display: display});
			if (!this.window) {
				// popup blocked
				return false;
{'fraction_non_alphanumeric': 0.11252586344103135, 'fraction_numerical': 0.0019099156453923284, 'mean_word_length': 3.4725978647686833, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2934834', 'n_tokens_mistral': 2156, 'n_tokens_neox': 1860, 'n_words': 596}