Beispiel #1
0
autoScriptEditor ScriptEditor_createFromScript_canBeNull (Editor environment, Script script) {
	try {
		for (long ieditor = 1; ieditor <= theReferencesToAllOpenScriptEditors.size; ieditor ++) {
			ScriptEditor editor = theReferencesToAllOpenScriptEditors.at [ieditor];
			if (MelderFile_equal (& script -> file, & editor -> file)) {
				Editor_raise (editor);
				Melder_appendError (U"The script ", & script -> file, U" is already open and has been moved to the front.");
				if (editor -> dirty)
					Melder_appendError (U"Choose \"Reopen from disk\" if you want to revert to the old version.");
				Melder_flushError ();
				return autoScriptEditor();   // safe null
			}
		}
		autostring32 text = MelderFile_readText (& script -> file);
		autoScriptEditor me = ScriptEditor_createFromText (environment, text.peek());
		MelderFile_copy (& script -> file, & my file);
		Thing_setName (me.peek(), Melder_fileToPath (& script -> file));
		return me;
	} catch (MelderError) {
		Melder_throw (U"Script window not created.");
	}
}
Beispiel #2
0
static void openDocument (TextEditor me, MelderFile file) {
	if (theOpenTextEditors) {
		for (long ieditor = 1; ieditor <= theOpenTextEditors -> size; ieditor ++) {
			TextEditor editor = (TextEditor) theOpenTextEditors -> item [ieditor];
			if (editor != me && MelderFile_equal (file, & editor -> file)) {
				Editor_raise (editor);
				Melder_appendError (U"Text file ", file, U" is already open.");
				forget (me);   // don't forget me before Melder_appendError, because "file" is owned by one of my dialogs
				Melder_flushError ();
				return;
			}
		}
	}
	autostring32 text = MelderFile_readText (file);
	GuiText_setString (my textWidget, text.peek());
	/*
	 * GuiText_setString has invoked the changeCallback,
	 * which has set `my dirty` to `true`. Fix this.
	 */
	my dirty = false;
	MelderFile_copy (file, & my file);
	Thing_setName (me, Melder_fileToPath (file));
}
Beispiel #3
0
ScriptEditor ScriptEditor_createFromScript (Editor environment, Script script) {
	try {
		if (theScriptEditors) {
			for (long ieditor = 1; ieditor <= theScriptEditors -> size; ieditor ++) {
				ScriptEditor editor = (ScriptEditor) theScriptEditors -> item [ieditor];
				if (MelderFile_equal (& script -> file, & editor -> file)) {
					editor -> raise ();
					Melder_error_ ("The script ", & script -> file, " is already open and has been moved to the front.");
					if (editor -> dirty)
						Melder_error_ ("Choose \"Reopen from disk\" if you want to revert to the old version.");
					Melder_flushError (NULL);
					return NULL;   // safe NULL
				}
			}
		}
		autostring text = MelderFile_readText (& script -> file);
		autoScriptEditor me = ScriptEditor_createFromText (environment, text.peek());
		MelderFile_copy (& script -> file, & my file);
		Thing_setName (me.peek(), Melder_fileToPath (& script -> file));
		return me.transfer();
	} catch (MelderError) {
		Melder_throw ("Script window not created.");
	}
}