Debian Codegraph @

sys/UiFile.cpp

raw symbols SCIP
1 /* UiFile.cpp
2 *
3 * Copyright (C) 1992-2018,2022,2023 Paul Boersma
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "UiP.h"cxx . . $ `<file>/sys/UiP.h`/
20 #include "ScriptEditor.h"cxx . . $ `<file>/sys/ScriptEditor.h`/
21
22 static void UiFile_initcxx . . $ UiFile_init(5b217538d6eecf62). (UiFormcxx . . $ UiForm# me, GuiWindowcxx . . $ GuiWindow# parent, conststring32cxx . . $ conststring32# title) {
23 mycxx . . $ `melder/melder.h:44:9`! d_dialogParentcxx . . $ structUiForm#d_dialogParent. = parent;
24 Thing_setNamecxx . . $ Thing_setName(b5a42e5e01c267b5). (me, title);
25 }
26
27 MelderFilecxx . . $ MelderFile# UiFile_getFilecxx . . $ UiFile_getFile(fbc6b61177245f1d). (UiFormcxx . . $ UiForm# me) {
28 return & mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structUiForm#file.;
29 }
30
31 /********** READING A FILE **********/
32
33 autoUiFormcxx . . $ autoUiForm# UiInfile_createcxx . . $ UiInfile_create(50b46b1e7e1cbcb). (GuiWindowcxx . . $ GuiWindow# parent, Editorcxx . . $ Editor# optionalEditor, conststring32cxx . . $ conststring32# title,
34 UiCallbackcxx . . $ UiCallback# okCallback, void *okClosure,
35 conststring32cxx . . $ conststring32# invokingButtonTitle, conststring32cxx . . $ conststring32# helpTitle, bool allowMultipleFiles)
36 {
37 autoUiFormcxx . . $ autoUiForm# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (UiForm);
38 mycxx . . $ `melder/melder.h:44:9`! optionalEditorcxx . . $ structUiForm#optionalEditor. = optionalEditor;
39 mycxx . . $ `melder/melder.h:44:9`! okCallbackcxx . . $ structUiForm#okCallback. = okCallback;
40 mycxx . . $ `melder/melder.h:44:9`! buttonClosurecxx . . $ structUiForm#buttonClosure. = okClosure;
41 mycxx . . $ `melder/melder.h:44:9`! invokingButtonTitlecxx . . $ structUiForm#invokingButtonTitle. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (invokingButtonTitle);
42 mycxx . . $ `melder/melder.h:44:9`! helpTitlecxx . . $ structUiForm#helpTitle. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (helpTitle);
43 mycxx . . $ `melder/melder.h:44:9`! allowMultipleFilescxx . . $ structUiForm#allowMultipleFiles. = allowMultipleFiles;
44 UiFile_initcxx . . $ UiFile_init(5b217538d6eecf62). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), parent, title);
45 return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
46 }
47
48 void UiInfile_docxx . . $ UiInfile_do(b4388889c5fb10c0). (UiFormcxx . . $ UiForm# me) {
49 try {
50 autoStringSetcxx . . $ autoStringSet# infileNames = GuiFileSelect_getInfileNamescxx . . $ GuiFileSelect_getInfileNames(5a0c946482488abf). (mycxx . . $ `melder/melder.h:44:9`! d_dialogParentcxx . . $ structUiForm#d_dialogParent., mycxx . . $ `melder/melder.h:44:9`! namecxx . . $ structThing#name..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), mycxx . . $ `melder/melder.h:44:9`! allowMultipleFilescxx . . $ structUiForm#allowMultipleFiles.);
51 for (integercxx . . $ integer# ifile = 1; ifile <= infileNames->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).sizecxx . . $ CollectionOf#size.; ifile ++) {
52 SimpleStringcxx . . $ SimpleString# infileName = infileNames->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ifile];
53 Melder_pathToFilecxx . . $ Melder_pathToFile(82691f2ee21fbb13). (infileName -> stringcxx . . $ structSimpleString#string..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), & mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structUiForm#file.);
54 UiHistory_writecxx . . $ UiHistory_write(ff00d524ab0355ec). (U"\n");
55 UiHistory_write_colonizecxx . . $ UiHistory_write_colonize(ff00d524ab0355ec). (mycxx . . $ `melder/melder.h:44:9`! invokingButtonTitlecxx . . $ structUiForm#invokingButtonTitle..getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
56 UiHistory_writecxx . . $ UiHistory_write(ff00d524ab0355ec). (U" \"");
57 UiHistory_write_expandQuotescxx . . $ UiHistory_write_expandQuotes(ff00d524ab0355ec). (infileName -> stringcxx . . $ structSimpleString#string..getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
58 UiHistory_writecxx . . $ UiHistory_write(ff00d524ab0355ec). (U"\"");
59 structMelderFilecxx . . $ structMelderFile# file { };
60 MelderFile_copycxx . . $ MelderFile_copy(b298201f6d539a65). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structUiForm#file., & file);
61 try {
62 mycxx . . $ `melder/melder.h:44:9`! okCallbackcxx . . $ structUiForm#okCallback. (me, 0, nullptr, nullptr, nullptr, mycxx . . $ `melder/melder.h:44:9`! invokingButtonTitlecxx . . $ structUiForm#invokingButtonTitle..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), false, mycxx . . $ `melder/melder.h:44:9`! buttonClosurecxx . . $ structUiForm#buttonClosure., mycxx . . $ `melder/melder.h:44:9`! optionalEditorcxx . . $ structUiForm#optionalEditor.);
63 } catch (MelderErrorcxx . . $ MelderError#) {
64 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"File ", & file, U" not finished.");
65 }
66 }
67 } catch (MelderErrorcxx . . $ MelderError#) {
68 Melder_flushErrorcxx . . $ Melder_flushError(49f6e7a06ebc5aa8). ();
69 }
70 }
71
72 /********** WRITING A FILE **********/
73
74 autoUiFormcxx . . $ autoUiForm# UiOutfile_createcxx . . $ UiOutfile_create(b3c832b012a1002d). (GuiWindowcxx . . $ GuiWindow# parent, Editorcxx . . $ Editor# optionalEditor, conststring32cxx . . $ conststring32# title,
75 UiCallbackcxx . . $ UiCallback# okCallback, void *okClosure, conststring32cxx . . $ conststring32# invokingButtonTitle, conststring32cxx . . $ conststring32# helpTitle)
76 {
77 autoUiFormcxx . . $ autoUiForm# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (UiForm);
78 mycxx . . $ `melder/melder.h:44:9`! optionalEditorcxx . . $ structUiForm#optionalEditor. = optionalEditor;
79 mycxx . . $ `melder/melder.h:44:9`! okCallbackcxx . . $ structUiForm#okCallback. = okCallback;
80 mycxx . . $ `melder/melder.h:44:9`! buttonClosurecxx . . $ structUiForm#buttonClosure. = okClosure;
81 mycxx . . $ `melder/melder.h:44:9`! invokingButtonTitlecxx . . $ structUiForm#invokingButtonTitle. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (invokingButtonTitle);
82 mycxx . . $ `melder/melder.h:44:9`! helpTitlecxx . . $ structUiForm#helpTitle. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (helpTitle);
83 UiFile_initcxx . . $ UiFile_init(5b217538d6eecf62). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), parent, title);
84 mycxx . . $ `melder/melder.h:44:9`! allowExecutionHookcxx . . $ structUiForm#allowExecutionHook. = theAllowExecutionHookHintcxx . . $ theAllowExecutionHookHint.;
85 mycxx . . $ `melder/melder.h:44:9`! allowExecutionClosurecxx . . $ structUiForm#allowExecutionClosure. = theAllowExecutionClosureHintcxx . . $ theAllowExecutionClosureHint.;
86 return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
87 }
88
89 static void commonOutfileCallbackcxx . . $ commonOutfileCallback(744a0abd3c8513c). (UiFormcxx . . $ UiForm# sendingForm, integercxx . . $ integer# narg, Stackelcxx . . $ Stackel# args, conststring32cxx . . $ conststring32# sendingString,
90 Interpretercxx . . $ Interpreter# interpreter, conststring32cxx . . $ conststring32# /* invokingButtonTitle */, bool /* modified */, void *closure, Editorcxx . . $ Editor# /* optionalEditor */)
91 {
92 EditorCommandcxx . . $ EditorCommand# command = (EditorCommandcxx . . $ EditorCommand#) closure;
93 command -> commandCallbackcxx . . $ structEditorCommand#commandCallback. (cxx . . $ MelderCallback#`operator()`(e7ade0e2880b4e44).command -> sendercxx . . $ structEditorCommand#sender., command, sendingForm, narg, args, sendingString, interpreter);
94 }
95
96 autoUiFormcxx . . $ autoUiForm# UiOutfile_createEcxx . . $ UiOutfile_createE(4a101de89d32d0cd). (EditorCommandcxx . . $ EditorCommand# cmd, conststring32cxx . . $ conststring32# title, conststring32cxx . . $ conststring32# invokingButtonTitle, conststring32cxx . . $ conststring32# helpTitle) {
97 Editorcxx . . $ Editor# editor = cmd -> d_editorcxx . . $ structEditorCommand#d_editor.;
98 autoUiFormcxx . . $ autoUiForm# dia = UiOutfile_createcxx . . $ UiOutfile_create(b3c832b012a1002d). (editor -> windowFormcxx . . $ structEditor#windowForm., editor, title, commonOutfileCallbackcxx . . $ commonOutfileCallback(744a0abd3c8513c)., cmd, invokingButtonTitle, helpTitle);
99 dia ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). commandcxx . . $ structUiForm#command. = cmd;
100 return diacxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
101 }
102
103 autoUiFormcxx . . $ autoUiForm# UiInfile_createEcxx . . $ UiInfile_createE(4a101de89d32d0cd). (EditorCommandcxx . . $ EditorCommand# cmd, conststring32cxx . . $ conststring32# title, conststring32cxx . . $ conststring32# invokingButtonTitle, conststring32cxx . . $ conststring32# helpTitle) {
104 Editorcxx . . $ Editor# editor = cmd -> d_editorcxx . . $ structEditorCommand#d_editor.;
105 autoUiFormcxx . . $ autoUiForm# dia = UiInfile_createcxx . . $ UiInfile_create(50b46b1e7e1cbcb). (editor -> windowFormcxx . . $ structEditor#windowForm., editor, title, commonOutfileCallbackcxx . . $ commonOutfileCallback(744a0abd3c8513c)., cmd, invokingButtonTitle, helpTitle, false);
106 dia ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). commandcxx . . $ structUiForm#command. = cmd;
107 return diacxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
108 }
109
110 void UiOutfile_docxx . . $ UiOutfile_do(dd78e4d327935865). (UiFormcxx . . $ UiForm# me, conststring32cxx . . $ conststring32# defaultName) {
111 autostring32cxx . . $ autostring32# outfileName = GuiFileSelect_getOutfileNamecxx . . $ GuiFileSelect_getOutfileName(575be6c40acafffe). (mycxx . . $ `melder/melder.h:44:9`! d_dialogParentcxx . . $ structUiForm#d_dialogParent., mycxx . . $ `melder/melder.h:44:9`! namecxx . . $ structThing#name..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), defaultName);
112 if (! outfileName)
113 return; // cancelled
114 if (mycxx . . $ `melder/melder.h:44:9`! allowExecutionHookcxx . . $ structUiForm#allowExecutionHook. && ! mycxx . . $ `melder/melder.h:44:9`! allowExecutionHookcxx . . $ structUiForm#allowExecutionHook. (mycxx . . $ `melder/melder.h:44:9`! allowExecutionClosurecxx . . $ structUiForm#allowExecutionClosure.)) {
115 Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (U"Dialog “", mycxx . . $ `melder/melder.h:44:9`! namecxx . . $ structThing#name..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"” cancelled.");
116 return;
117 }
118 Melder_pathToFilecxx . . $ Melder_pathToFile(82691f2ee21fbb13). (outfileName.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), & mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structUiForm#file.);
119 structMelderFilecxx . . $ structMelderFile# file { };
120 MelderFile_copycxx . . $ MelderFile_copy(b298201f6d539a65). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structUiForm#file., & file); // save, because okCallback could destroy me
121 UiHistory_writecxx . . $ UiHistory_write(ff00d524ab0355ec). (U"\n");
122 UiHistory_write_colonizecxx . . $ UiHistory_write_colonize(ff00d524ab0355ec). (mycxx . . $ `melder/melder.h:44:9`! invokingButtonTitlecxx . . $ structUiForm#invokingButtonTitle..getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
123 try {
124 mycxx . . $ `melder/melder.h:44:9`! okCallbackcxx . . $ structUiForm#okCallback. (me, 0, nullptr, nullptr, nullptr, mycxx . . $ `melder/melder.h:44:9`! invokingButtonTitlecxx . . $ structUiForm#invokingButtonTitle..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), false, mycxx . . $ `melder/melder.h:44:9`! buttonClosurecxx . . $ structUiForm#buttonClosure., mycxx . . $ `melder/melder.h:44:9`! optionalEditorcxx . . $ structUiForm#optionalEditor.);
125 } catch (MelderErrorcxx . . $ MelderError#) {
126 Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (U"File ", & file, U" not finished.");
127 }
128 UiHistory_writecxx . . $ UiHistory_write(ff00d524ab0355ec). (U" \"");
129 UiHistory_writecxx . . $ UiHistory_write(ff00d524ab0355ec). (outfileName.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
130 UiHistory_writecxx . . $ UiHistory_write(ff00d524ab0355ec). (U"\"");
131 }
132
133 /* End of file UiFile.cpp */