@@ -37,7 +37,9 @@ static void setAllowedFileTypes(
3737 NSMutableArray < UTType * > * allowedTypes = [NSMutableArray array ];
3838 for (NSString * ext in extensions ) {
3939 UTType * uttype = [UTType typeWithFilenameExtension : ext ];
40- [allowedTypes addObject :uttype ];
40+ if (uttype ) {
41+ [allowedTypes addObject :uttype ];
42+ }
4143 }
4244 [panel setAllowedContentTypes :allowedTypes ];
4345 } else {
@@ -85,6 +87,41 @@ static filepanelFilterInfo filterInfo;
8587static NSOpenPanel * openpanel ;
8688static NSSavePanel * savepanel ;
8789
90+ /*
91+ * A thread which closes the currently running modal dialog after a timeout.
92+ */
93+
94+ @interface TKPanelMonitor : NSThread {
95+ @private
96+ NSTimeInterval _timeout ;
97+ }
98+
99+ - (id ) initWithTimeout : (NSTimeInterval ) timeout ;
100+
101+ @end
102+
103+ @implementation TKPanelMonitor : NSThread
104+
105+ - (id ) initWithTimeout : (NSTimeInterval ) timeout {
106+ self = [super init ];
107+ if (self ) {
108+ _timeout = timeout ;
109+ return self ;
110+ }
111+ return self ;
112+ }
113+
114+ - (void ) main
115+ {
116+ [NSThread sleepForTimeInterval :_timeout ];
117+ if ([self isCancelled ]) {
118+ [NSThread exit ];
119+ }
120+ [NSApp stopModalWithCode :modalCancel ];
121+ }
122+ @end
123+
124+
88125static const char * const colorOptionStrings [] = {
89126 "-initialcolor" , "-parent" , "-title" , NULL
90127};
@@ -868,7 +905,20 @@ Tk_GetOpenFileObjCmd(
868905 parent = nil ;
869906 parentIsKey = False ;
870907 }
871- modalReturnCode = showOpenSavePanel (openpanel , parent , interp , cmdObj , multiple );
908+ TKPanelMonitor * monitor ;
909+ if (testsAreRunning ) {
910+ /*
911+ * We need the panel to close by itself when running tests.
912+ */
913+
914+ monitor = [[TKPanelMonitor alloc ] initWithTimeout : 1.0 ];
915+ [monitor start ];
916+ }
917+ modalReturnCode = showOpenSavePanel (openpanel , parent , interp , cmdObj ,
918+ multiple );
919+ if (testsAreRunning ) {
920+ [monitor cancel ];
921+ }
872922 if (cmdObj ) {
873923 Tcl_DecrRefCount (cmdObj );
874924 }
0 commit comments