1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
/* UiFile.cpp
*
* Copyright (C) 1992-2011 Paul Boersma
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "UiP.h"
#include "Editor.h"
Thing_define (UiFile, Thing) {
// new data:
public:
EditorCommand command;
GuiObject parent;
structMelderFile file;
const wchar *invokingButtonTitle, *helpTitle;
void (*okCallback) (UiForm sendingForm, const wchar *sendingString, Interpreter interpreter, const wchar *invokingButtonTitle, bool modified, void *closure);
void *okClosure;
int shiftKeyPressed;
// overridden methods:
virtual void v_destroy ();
};
void structUiFile :: v_destroy () {
Melder_free (invokingButtonTitle);
UiFile_Parent :: v_destroy ();
}
Thing_implement (UiFile, Thing, 0);
static void UiFile_init (I, GuiObject parent, const wchar_t *title) {
iam (UiFile);
my parent = parent;
Thing_setName (me, title);
}
MelderFile UiFile_getFile (I) {
iam (UiFile);
return & my file;
}
/********** READING A FILE **********/
Thing_define (UiInfile, UiFile) {
// new data:
public:
bool allowMultipleFiles;
};
Thing_implement (UiInfile, UiFile, 0);
UiForm UiInfile_create (GuiObject parent, const wchar *title,
void (*okCallback) (UiForm, const wchar *, Interpreter, const wchar *, bool, void *), void *okClosure,
const wchar *invokingButtonTitle, const wchar *helpTitle, bool allowMultipleFiles)
{
UiInfile me = Thing_new (UiInfile);
my okCallback = okCallback;
my okClosure = okClosure;
my invokingButtonTitle = Melder_wcsdup (invokingButtonTitle);
my helpTitle = helpTitle;
my allowMultipleFiles = allowMultipleFiles;
UiFile_init (me, parent, title);
return (UiForm) me;
}
void UiInfile_do (I) {
iam (UiInfile);
try {
autoSortedSetOfString infileNames = GuiFileSelect_getInfileNames (my parent, my name, my allowMultipleFiles);
for (long ifile = 1; ifile <= infileNames -> size; ifile ++) {
SimpleString infileName = (SimpleString) infileNames -> item [ifile];
Melder_pathToFile (infileName -> string, & my file);
UiHistory_write (L"\n");
UiHistory_write (my invokingButtonTitle);
UiHistory_write (L" ");
UiHistory_write (infileName -> string);
structMelderFile file;
MelderFile_copy (& my file, & file);
try {
my okCallback ((UiForm) me, NULL, NULL, my invokingButtonTitle, false, my okClosure);
} catch (MelderError) {
Melder_throw ("File ", & file, " not finished.");
}
}
} catch (MelderError) {
Melder_flushError (NULL);
}
}
/********** WRITING A FILE **********/
Thing_define (UiOutfile, UiFile) {
// new data:
public:
bool (*allowExecutionHook) (void *closure);
void *allowExecutionClosure; // I am owner (see destroy)
};
Thing_implement (UiOutfile, UiFile, 0);
UiForm UiOutfile_create (GuiObject parent, const wchar_t *title,
void (*okCallback) (UiForm, const wchar *, Interpreter, const wchar *, bool, void *), void *okClosure, const wchar *invokingButtonTitle, const wchar_t *helpTitle)
{
UiOutfile me = Thing_new (UiOutfile);
my okCallback = okCallback;
my okClosure = okClosure;
my invokingButtonTitle = Melder_wcsdup (invokingButtonTitle);
my helpTitle = helpTitle;
UiFile_init (me, parent, title);
my allowExecutionHook = theAllowExecutionHookHint;
my allowExecutionClosure = theAllowExecutionClosureHint;
return (UiForm) me;
}
static void commonOutfileCallback (UiForm sendingForm, const wchar *sendingString, Interpreter interpreter, const wchar *invokingButtonTitle, bool modified, void *closure) {
EditorCommand command = (EditorCommand) closure;
(void) invokingButtonTitle;
(void) modified;
command -> commandCallback (command -> d_editor, command, sendingForm, sendingString, interpreter); therror
}
UiForm UiOutfile_createE (EditorCommand cmd, const wchar_t *title, const wchar_t *invokingButtonTitle, const wchar_t *helpTitle) {
Editor editor = (Editor) cmd -> d_editor;
UiOutfile dia = (UiOutfile) UiOutfile_create (editor -> d_windowForm, title, commonOutfileCallback, cmd, invokingButtonTitle, helpTitle);
dia -> command = cmd;
return (UiForm) dia; // BUG
}
UiForm UiInfile_createE (EditorCommand cmd, const wchar_t *title, const wchar_t *invokingButtonTitle, const wchar_t *helpTitle) {
Editor editor = (Editor) cmd -> d_editor;
UiInfile dia = (UiInfile) UiInfile_create (editor -> d_windowForm, title, commonOutfileCallback, cmd, invokingButtonTitle, helpTitle, false);
dia -> command = cmd;
return (UiForm) dia; // BUG
}
void UiOutfile_do (I, const wchar_t *defaultName) {
iam (UiOutfile);
wchar_t *outfileName = GuiFileSelect_getOutfileName (NULL, my name, defaultName);
if (outfileName == NULL) return; // cancelled
if (my allowExecutionHook && ! my allowExecutionHook (my allowExecutionClosure)) {
Melder_flushError ("Dialog `%s' cancelled.", my name);
return;
}
Melder_pathToFile (outfileName, & my file);
structMelderFile file;
MelderFile_copy (& my file, & file); // save, because okCallback could destroy me
UiHistory_write (L"\n");
UiHistory_write (my invokingButtonTitle);
try {
my okCallback ((UiForm) me, NULL, NULL, my invokingButtonTitle, false, my okClosure);
} catch (MelderError) {
Melder_error_ ("File ", & file, " not finished.");
Melder_flushError (NULL);
}
UiHistory_write (L" ");
UiHistory_write (outfileName);
Melder_free (outfileName);
}
/* End of file UiFile.cpp */
|