summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXDialog.c
diff options
context:
space:
mode:
authorculler <culler>2019-04-17 14:05:33 (GMT)
committerculler <culler>2019-04-17 14:05:33 (GMT)
commit7eaee2f2e59cbbb043964d94313d3f22a6d877a5 (patch)
tree234a219579591d68652019df28397ade8a81a33e /macosx/tkMacOSXDialog.c
parent9b521b370e0520f6a489be15b65269a33761501a (diff)
downloadtk-7eaee2f2e59cbbb043964d94313d3f22a6d877a5.zip
tk-7eaee2f2e59cbbb043964d94313d3f22a6d877a5.tar.gz
tk-7eaee2f2e59cbbb043964d94313d3f22a6d877a5.tar.bz2
Mitigate future merge conflict headaches.
Diffstat (limited to 'macosx/tkMacOSXDialog.c')
-rw-r--r--macosx/tkMacOSXDialog.c408
1 files changed, 269 insertions, 139 deletions
diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c
index c3778f1..a7997f2 100644
--- a/macosx/tkMacOSXDialog.c
+++ b/macosx/tkMacOSXDialog.c
@@ -22,31 +22,39 @@
#else
#define modalOK NSModalResponseOK
#define modalCancel NSModalResponseCancel
-#endif
+#endif // MAC_OS_X_VERSION_MIN_REQUIRED < 1090
#define modalOther -1
#define modalError -2
-/*Vars for filtering in "open file" and "save file" dialogs.*/
-typedef struct {
- bool doFileTypes; // show the accessory view which displays the filter menu
- bool preselectFilter; // a filter was selected by the typevariable
- bool userHasSelectedFilter; // The user has changed the filter in the accessory view
-
- NSMutableArray *fileTypeNames; // array of names, e.g. "Text document"
- NSMutableArray *fileTypeExtensions; // array of allowed extensions per name, e.g. "txt", "doc"
- NSMutableArray *fileTypeLabels; // displayed string, e.g. "Text document (.txt, .doc)"
- NSMutableArray *fileTypeAllowsAll; // boolean if the all pattern (*.*) is included
-
- NSMutableArray *allowedExtensions; // set of all allowed extensions
- bool allowedExtensionsAllowAll; // set of all allowed extensions includes *.*
+/*
+ * Vars for filtering in "open file" and "save file" dialogs.
+ */
- NSUInteger fileTypeIndex; // index of currently selected filter
+typedef struct {
+ bool doFileTypes; /* Show the accessory view which
+ * displays the filter menu */
+ bool preselectFilter; /* A filter was selected by the
+ * typevariable. */
+ bool userHasSelectedFilter; /* The user has changed the filter in
+ * the accessory view. */
+ NSMutableArray *fileTypeNames; /* Array of names, e.g. "Text
+ * document". */
+ NSMutableArray *fileTypeExtensions; /* Array of allowed extensions per
+ * name, e.g. "txt", "doc". */
+ NSMutableArray *fileTypeLabels; /* Displayed string, e.g. "Text
+ * document (.txt, .doc)". */
+ NSMutableArray *fileTypeAllowsAll; /* Boolean if the all pattern (*.*) is
+ * included. */
+ NSMutableArray *allowedExtensions; /* Set of all allowed extensions. */
+ bool allowedExtensionsAllowAll; /* Set of all allowed extensions
+ * includes *.* */
+ NSUInteger fileTypeIndex; /* Index of currently selected
+ * filter. */
} filepanelFilterInfo;
-filepanelFilterInfo filterInfo;
-
-NSOpenPanel *openpanel;
-NSSavePanel *savepanel;
+static filepanelFilterInfo filterInfo;
+static NSOpenPanel *openpanel;
+static NSSavePanel *savepanel;
static const char *const colorOptionStrings[] = {
"-initialcolor", "-parent", "-title", NULL
@@ -166,10 +174,15 @@ static const short alertNativeButtonIndexAndTypeToButtonIndex[][3] = {
};
/*
- * Construct a file URL from directory and filename. Either may
- * be nil. If both are nil, returns nil.
+ * Construct a file URL from directory and filename. Either may be nil. If both
+ * are nil, returns nil.
*/
-static NSURL *getFileURL(NSString *directory, NSString *filename) {
+
+static NSURL *
+getFileURL(
+ NSString *directory,
+ NSString *filename)
+{
NSURL *url = nil;
if (directory) {
url = [NSURL fileURLWithPath:directory isDirectory:YES];
@@ -229,7 +242,6 @@ static NSURL *getFileURL(NSString *directory, NSString *filename) {
}
}
-
- (void) tkAlertDidEnd: (NSAlert *) alert returnCode: (NSInteger) returnCode
contextInfo: (void *) contextInfo
{
@@ -272,12 +284,18 @@ static NSURL *getFileURL(NSString *directory, NSString *filename) {
if ([[filterInfo.fileTypeAllowsAll objectAtIndex:filterInfo.fileTypeIndex] boolValue]) {
[openpanel setAllowsOtherFileTypes:YES];
- /* setAllowsOtherFileTypes might have no effect; it's inherited from the
- * NSSavePanel, where it has the effect that it does not append an extension
- * Setting the allowed file types to nil allows selecting any file */
+
+ /*
+ * setAllowsOtherFileTypes might have no effect; it's inherited from
+ * the NSSavePanel, where it has the effect that it does not append an
+ * extension. Setting the allowed file types to nil allows selecting
+ * any file.
+ */
+
[openpanel setAllowedFileTypes:nil];
} else {
- NSMutableArray *allowedtypes = [filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex];
+ NSMutableArray *allowedtypes =
+ [filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex];
[openpanel setAllowedFileTypes:allowedtypes];
[openpanel setAllowsOtherFileTypes:NO];
}
@@ -293,7 +311,8 @@ static NSURL *getFileURL(NSString *directory, NSString *filename) {
[savepanel setAllowsOtherFileTypes:YES];
[savepanel setAllowedFileTypes:nil];
} else {
- NSMutableArray *allowedtypes = [filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex];
+ NSMutableArray *allowedtypes =
+ [filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex];
[savepanel setAllowedFileTypes:allowedtypes];
[savepanel setAllowsOtherFileTypes:NO];
}
@@ -384,6 +403,7 @@ Tk_ChooseColorObjCmd(
[colorPanel _setUseModalAppearance:YES];
if (title) {
NSString *s = [[NSString alloc] initWithUTF8String:title];
+
[colorPanel setTitle:s];
[s release];
}
@@ -415,9 +435,17 @@ end:
return result;
}
-/* dissect the -filetype nested lists and store the information
- * in the filterInfo structure */
-int parseFileFilters(Tcl_Interp *interp, Tcl_Obj *fileTypesPtr, Tcl_Obj *typeVariablePtr) {
+/*
+ * Dissect the -filetype nested lists and store the information in the
+ * filterInfo structure.
+ */
+
+static int
+parseFileFilters(
+ Tcl_Interp *interp,
+ Tcl_Obj *fileTypesPtr,
+ Tcl_Obj *typeVariablePtr)
+{
if (!fileTypesPtr) {
filterInfo.doFileTypes = false;
@@ -425,6 +453,7 @@ int parseFileFilters(Tcl_Interp *interp, Tcl_Obj *fileTypesPtr, Tcl_Obj *typeVar
}
FileFilterList fl;
+
TkInitFileFilters(&fl);
if (TkGetFileFilters(interp, &fl, fileTypesPtr, 0) != TCL_OK) {
TkFreeFileFilters(&fl);
@@ -445,11 +474,12 @@ int parseFileFilters(Tcl_Interp *interp, Tcl_Obj *fileTypesPtr, Tcl_Obj *typeVar
if (filterInfo.doFileTypes) {
for (FileFilter *filterPtr = fl.filters; filterPtr;
filterPtr = filterPtr->next) {
- NSString * name = [[NSString alloc] initWithUTF8String: filterPtr -> name];
+ NSString *name = [[NSString alloc] initWithUTF8String: filterPtr->name];
+
[filterInfo.fileTypeNames addObject:name];
[name release];
- NSMutableArray * clauseextensions = [NSMutableArray array];
- NSMutableArray * displayextensions = [NSMutableArray array];
+ NSMutableArray *clauseextensions = [NSMutableArray array];
+ NSMutableArray *displayextensions = [NSMutableArray array];
bool allowsAll = NO;
for (FileFilterClause *clausePtr = filterPtr->clauses; clausePtr;
@@ -460,7 +490,7 @@ int parseFileFilters(Tcl_Interp *interp, Tcl_Obj *fileTypesPtr, Tcl_Obj *typeVar
const char *str = globPtr->pattern;
while (*str && (*str == '*' || *str == '.')) {
str++;
- }
+ }
if (*str) {
NSString *extension = [[NSString alloc] initWithUTF8String:str];
if (![filterInfo.allowedExtensions containsObject:extension]) {
@@ -472,7 +502,10 @@ int parseFileFilters(Tcl_Interp *interp, Tcl_Obj *fileTypesPtr, Tcl_Obj *typeVar
[extension release];
} else {
- // it is the all pattern (*, .* or *.*)
+ /*
+ * It is the all pattern (*, .* or *.*)
+ */
+
allowsAll = YES;
filterInfo.allowedExtensionsAllowAll = YES;
[displayextensions addObject:@"*"];
@@ -482,27 +515,39 @@ int parseFileFilters(Tcl_Interp *interp, Tcl_Obj *fileTypesPtr, Tcl_Obj *typeVar
[filterInfo.fileTypeExtensions addObject:clauseextensions];
[filterInfo.fileTypeAllowsAll addObject:[NSNumber numberWithBool:allowsAll]];
- NSMutableString * label = [[NSMutableString alloc] initWithString:name];
+ NSMutableString *label = [[NSMutableString alloc] initWithString:name];
[label appendString:@" ("];
[label appendString:[displayextensions componentsJoinedByString:@", "]];
[label appendString:@")"];
[filterInfo.fileTypeLabels addObject:label];
[label release];
-
}
- /* Check if the typevariable exists and matches one of the names */
+ /*
+ * Check if the typevariable exists and matches one of the names.
+ */
+
filterInfo.preselectFilter = false;
filterInfo.userHasSelectedFilter = false;
if (typeVariablePtr) {
- /* extract the variable content as a NSString */
- Tcl_Obj *selectedFileTypeObj = Tcl_ObjGetVar2(interp, typeVariablePtr, NULL, TCL_GLOBAL_ONLY);
+ /*
+ * Extract the variable content as a NSString.
+ */
+
+ Tcl_Obj *selectedFileTypeObj = Tcl_ObjGetVar2(interp,
+ typeVariablePtr, NULL, TCL_GLOBAL_ONLY);
+
+ /*
+ * Check that the typevariable exists.
+ */
- /* check that the typevariable exists */
if (selectedFileTypeObj != NULL) {
- const char *selectedFileType = Tcl_GetString(selectedFileTypeObj);
- NSString *selectedFileTypeStr = [[NSString alloc] initWithUTF8String:selectedFileType];
- NSUInteger index = [filterInfo.fileTypeNames indexOfObject:selectedFileTypeStr];
+ const char *selectedFileType =
+ Tcl_GetString(selectedFileTypeObj);
+ NSString *selectedFileTypeStr =
+ [[NSString alloc] initWithUTF8String:selectedFileType];
+ NSUInteger index =
+ [filterInfo.fileTypeNames indexOfObject:selectedFileTypeStr];
if (index != NSNotFound) {
filterInfo.fileTypeIndex = index;
@@ -517,17 +562,24 @@ int parseFileFilters(Tcl_Interp *interp, Tcl_Obj *fileTypesPtr, Tcl_Obj *typeVar
return TCL_OK;
}
-bool filterCompatible(NSString *extension, int filterIndex) {
- NSMutableArray *allowedExtensions = [filterInfo.fileTypeExtensions objectAtIndex: filterIndex];
+static bool
+filterCompatible(
+ NSString *extension,
+ int filterIndex)
+{
+ NSMutableArray *allowedExtensions =
+ [filterInfo.fileTypeExtensions objectAtIndex: filterIndex];
+
+ /*
+ * If this contains the all pattern, accept any extension.
+ */
- /* If this contains the all pattern, accept any extension */
if ([[filterInfo.fileTypeAllowsAll objectAtIndex:filterIndex] boolValue]) {
return true;
}
return [allowedExtensions containsObject: extension];
}
-
/*
*----------------------------------------------------------------------
@@ -631,13 +683,16 @@ Tk_GetOpenFileObjCmd(
if (title) {
[openpanel setTitle:title];
- /* From OSX 10.11, the title string is silently ignored in the open panel.
- * Prepend the title to the message in this case
- * NOTE should be conditional on OSX version, but
- * -mmacosx-version-min does not revert this behaviour*/
+ /*
+ * From OSX 10.11, the title string is silently ignored in the open
+ * panel. Prepend the title to the message in this case. NOTE should
+ * be conditional on OSX version, but -mmacosx-version-min does not
+ * revert this behaviour
+ */
if (message) {
- NSString *fullmessage = [[NSString alloc] initWithFormat:@"%@\n%@",title,message];
+ NSString *fullmessage =
+ [[NSString alloc] initWithFormat:@"%@\n%@", title, message];
[message release];
[title release];
message = fullmessage;
@@ -658,15 +713,20 @@ Tk_GetOpenFileObjCmd(
}
if (filterInfo.doFileTypes) {
- NSView *accessoryView = [[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 300, 32.0)];
- NSTextField *label = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 60, 22)];
+ NSView *accessoryView = [[NSView alloc]
+ initWithFrame:NSMakeRect(0.0, 0.0, 300, 32.0)];
+ NSTextField *label = [[NSTextField alloc]
+ initWithFrame:NSMakeRect(0, 0, 60, 22)];
+
[label setEditable:NO];
[label setStringValue:@"Filter:"];
[label setBordered:NO];
[label setBezeled:NO];
[label setDrawsBackground:NO];
- NSPopUpButton *popupButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(50.0, 2, 240, 22.0) pullsDown:NO];
+ NSPopUpButton *popupButton = [[NSPopUpButton alloc]
+ initWithFrame:NSMakeRect(50.0, 2, 240, 22.0) pullsDown:NO];
+
[popupButton addItemsWithTitles:filterInfo.fileTypeLabels];
[popupButton setAction:@selector(selectFormat:)];
@@ -674,10 +734,16 @@ Tk_GetOpenFileObjCmd(
[accessoryView addSubview:popupButton];
if (filterInfo.preselectFilter) {
- /* A specific filter was selected from the typevariable. Select it and
- * open the accessory view */
+ /*
+ * A specific filter was selected from the typevariable. Select it
+ * and open the accessory view.
+ */
+
[popupButton selectItemAtIndex:filterInfo.fileTypeIndex];
- /* on OSX > 10.11, the optons are not visible by default. Ergo allow all file types
+
+ /*
+ * On OSX > 10.11, the options are not visible by default. Ergo
+ * allow all file types
[openpanel setAllowedFileTypes:filterInfo.fileTypeExtensions[filterInfo.fileTypeIndex]];
*/
[openpanel setAllowedFileTypes:filterInfo.allowedExtensions];
@@ -693,7 +759,10 @@ Tk_GetOpenFileObjCmd(
[openpanel setAccessoryView:accessoryView];
} else {
- /* No filters are given. Allow picking all files */
+ /*
+ * No filters are given. Allow picking all files.
+ */
+
[openpanel setAllowsOtherFileTypes:YES];
}
@@ -711,20 +780,24 @@ Tk_GetOpenFileObjCmd(
parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
if (haveParentOption && parent && ![parent attachedSheet]) {
parentIsKey = [parent isKeyWindow];
- if (directory || filename ) {
- NSURL * fileURL = getFileURL(directory, filename);
+ if (directory || filename) {
+ NSURL *fileURL = getFileURL(directory, filename);
+
[openpanel setDirectoryURL:fileURL];
}
[openpanel beginSheetModalForWindow:parent
- completionHandler:^(NSInteger returnCode)
- { [NSApp tkFilePanelDidEnd:openpanel
+ completionHandler:^(NSInteger returnCode) {
+ [NSApp tkFilePanelDidEnd:openpanel
returnCode:returnCode
- contextInfo:callbackInfo ]; } ];
- modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:openpanel];
+ contextInfo:callbackInfo ];
+ }];
+ modalReturnCode = cmdObj ? modalOther :
+ [NSApp runModalForWindow:openpanel];
} else {
- if (directory || filename ) {
- NSURL * fileURL = getFileURL(directory, filename);
+ if (directory || filename) {
+ NSURL *fileURL = getFileURL(directory, filename);
+
[openpanel setDirectoryURL:fileURL];
}
@@ -737,38 +810,50 @@ Tk_GetOpenFileObjCmd(
[parent makeKeyWindow];
}
- if ((typeVariablePtr && (modalReturnCode == NSOKButton)) &&
- filterInfo.doFileTypes) {
+ if ((typeVariablePtr && (modalReturnCode == NSOKButton))
+ && filterInfo.doFileTypes) {
/*
- * The -typevariable must be set to the selected file type, if the dialog was not cancelled
+ * The -typevariable must be set to the selected file type, if the
+ * dialog was not cancelled.
*/
+
NSUInteger selectedFilterIndex = filterInfo.fileTypeIndex;
NSString *selectedFilter = NULL;
+
if (filterInfo.userHasSelectedFilter) {
selectedFilterIndex = filterInfo.fileTypeIndex;
selectedFilter = [filterInfo.fileTypeNames objectAtIndex:selectedFilterIndex];
} else {
- /* Difficult case: the user has not touched the filter settings, but we must
- * return something in the typevariable. First check if the preselected type is compatible
- * with the selected file, otherwise choose the first compatible type from the list,
- * finally fall back to the empty string */
+ /*
+ * Difficult case: the user has not touched the filter settings,
+ * but we must return something in the typevariable. First check if
+ * the preselected type is compatible with the selected file,
+ * otherwise choose the first compatible type from the list,
+ * finally fall back to the empty string.
+ */
+
NSURL *selectedFile;
+
if (multiple) {
- // Use the first file in the case of multiple selection
- // Anyway it is not overly useful here
+ /*
+ * Use the first file in the case of multiple selection.
+ * Anyway it is not overly useful here.
+ */
selectedFile = [[openpanel URLs] objectAtIndex:0];
} else {
selectedFile = [openpanel URL];
}
NSString *extension = [selectedFile pathExtension];
+
if (filterInfo.preselectFilter &&
- filterCompatible(extension, filterInfo.fileTypeIndex)) {
+ filterCompatible(extension, filterInfo.fileTypeIndex)) {
selectedFilterIndex = filterInfo.fileTypeIndex; // The preselection from the typevariable
selectedFilter = [filterInfo.fileTypeNames objectAtIndex:selectedFilterIndex];
} else {
// scan the list
NSUInteger i;
+
for (i = 0; i < [filterInfo.fileTypeNames count]; i++) {
if (filterCompatible(extension, i)) {
selectedFilterIndex = i;
@@ -780,19 +865,17 @@ Tk_GetOpenFileObjCmd(
} else {
selectedFilter = @"";
}
-
}
}
Tcl_ObjSetVar2(interp, typeVariablePtr, NULL,
- Tcl_NewStringObj([selectedFilter UTF8String], -1), TCL_GLOBAL_ONLY);
+ Tcl_NewStringObj([selectedFilter UTF8String], -1),
+ TCL_GLOBAL_ONLY);
}
-
end:
return result;
}
-
/*
*----------------------------------------------------------------------
@@ -807,6 +890,7 @@ Tk_GetOpenFileObjCmd(
*
* Side effects:
* See user documentation.
+ *
*----------------------------------------------------------------------
*/
@@ -828,7 +912,7 @@ Tk_GetSaveFileObjCmd(
NSString *directory = nil, *filename = nil, *defaultType = nil;
NSString *message = nil, *title = nil;
NSWindow *parent;
- savepanel = [NSSavePanel savePanel];
+ savepanel = [NSSavePanel savePanel];
NSInteger modalReturnCode = modalError;
BOOL parentIsKey = NO;
@@ -906,13 +990,17 @@ Tk_GetSaveFileObjCmd(
if (title) {
[savepanel setTitle:title];
- /* From OSX 10.11, the title string is silently ignored, if the save panel is a sheet.
- * Prepend the title to the message in this case
- * NOTE should be conditional on OSX version, but
- * -mmacosx-version-min does not revert this behaviour*/
+ /*
+ * From OSX 10.11, the title string is silently ignored, if the save
+ * panel is a sheet. Prepend the title to the message in this case.
+ * NOTE: should be conditional on OSX version, but -mmacosx-version-min
+ * does not revert this behaviour.
+ */
+
if (haveParentOption) {
if (message) {
- NSString *fullmessage = [[NSString alloc] initWithFormat:@"%@\n%@",title,message];
+ NSString *fullmessage =
+ [[NSString alloc] initWithFormat:@"%@\n%@",title,message];
[message release];
[title release];
message = fullmessage;
@@ -932,15 +1020,20 @@ Tk_GetSaveFileObjCmd(
}
if (filterInfo.doFileTypes) {
- NSView *accessoryView = [[NSView alloc] initWithFrame:NSMakeRect(0.0, 0.0, 300, 32.0)];
- NSTextField *label = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 60, 22)];
+ NSView *accessoryView = [[NSView alloc]
+ initWithFrame:NSMakeRect(0.0, 0.0, 300, 32.0)];
+ NSTextField *label = [[NSTextField alloc]
+ initWithFrame:NSMakeRect(0, 0, 60, 22)];
+
[label setEditable:NO];
[label setStringValue:NSLocalizedString(@"Format:", nil)];
[label setBordered:NO];
[label setBezeled:NO];
[label setDrawsBackground:NO];
- NSPopUpButton *popupButton = [[NSPopUpButton alloc] initWithFrame:NSMakeRect(50.0, 2, 340, 22.0) pullsDown:NO];
+ NSPopUpButton *popupButton = [[NSPopUpButton alloc]
+ initWithFrame:NSMakeRect(50.0, 2, 340, 22.0) pullsDown:NO];
+
[popupButton addItemsWithTitles:filterInfo.fileTypeLabels];
[popupButton selectItemAtIndex:filterInfo.fileTypeIndex];
[popupButton setAction:@selector(saveFormat:)];
@@ -953,10 +1046,14 @@ Tk_GetSaveFileObjCmd(
[savepanel setAllowedFileTypes:[filterInfo.fileTypeExtensions objectAtIndex:filterInfo.fileTypeIndex]];
[savepanel setAllowsOtherFileTypes:filterInfo.allowedExtensionsAllowAll];
} else if (defaultType) {
- /* If no filetypes are given, defaultextension is an alternative way
- * to specify the attached extension. Just propose this extension,
- * but don't display an accessory view */
+ /*
+ * If no filetypes are given, defaultextension is an alternative way to
+ * specify the attached extension. Just propose this extension, but
+ * don't display an accessory view.
+ */
+
NSMutableArray *AllowedFileTypes = [NSMutableArray array];
+
[AllowedFileTypes addObject:defaultType];
[savepanel setAllowedFileTypes:AllowedFileTypes];
[savepanel setAllowsOtherFileTypes:YES];
@@ -978,27 +1075,39 @@ Tk_GetSaveFileObjCmd(
parent = TkMacOSXDrawableWindow(((TkWindow *) tkwin)->window);
if (haveParentOption && parent && ![parent attachedSheet]) {
- parentIsKey = [parent isKeyWindow];
- if (directory) {
+ parentIsKey = [parent isKeyWindow];
+ if (directory) {
[savepanel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
}
- /*check for file name, otherwise set to empty string; crashes with uncaught exception if set to nil*/
+
+ /*
+ * Check for file name, otherwise set to empty string; crashes with
+ * uncaught exception if set to nil.
+ */
+
if (filename) {
[savepanel setNameFieldStringValue:filename];
} else {
[savepanel setNameFieldStringValue:@""];
}
[savepanel beginSheetModalForWindow:parent
- completionHandler:^(NSInteger returnCode)
- { [NSApp tkFilePanelDidEnd:savepanel
+ completionHandler:^(NSInteger returnCode) {
+ [NSApp tkFilePanelDidEnd:savepanel
returnCode:returnCode
- contextInfo:callbackInfo ]; } ];
- modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:savepanel];
+ contextInfo:callbackInfo];
+ }];
+ modalReturnCode = cmdObj ? modalOther :
+ [NSApp runModalForWindow:savepanel];
} else {
if (directory) {
[savepanel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
}
- /*check for file name, otherwise set to empty string; crashes with uncaught exception if set to nil*/
+
+ /*
+ * Check for file name, otherwise set to empty string; crashes with
+ * uncaught exception if set to nil.
+ */
+
if (filename) {
[savepanel setNameFieldStringValue:filename];
} else {
@@ -1013,16 +1122,20 @@ Tk_GetSaveFileObjCmd(
[parent makeKeyWindow];
}
- if ((typeVariablePtr && (modalReturnCode == NSOKButton)) && filterInfo.doFileTypes) {
+ if (typeVariablePtr && (modalReturnCode == NSOKButton)
+ && filterInfo.doFileTypes) {
/*
- * The -typevariable must be set to the selected file type, if the dialog was not cancelled
+ * The -typevariable must be set to the selected file type, if the
+ * dialog was not cancelled.
*/
- NSString * selectedFilter = [filterInfo.fileTypeNames objectAtIndex:filterInfo.fileTypeIndex];
+
+ NSString *selectedFilter =
+ [filterInfo.fileTypeNames objectAtIndex:filterInfo.fileTypeIndex];
Tcl_ObjSetVar2(interp, typeVariablePtr, NULL,
- Tcl_NewStringObj([selectedFilter UTF8String], -1), TCL_GLOBAL_ONLY);
+ Tcl_NewStringObj([selectedFilter UTF8String], -1),
+ TCL_GLOBAL_ONLY);
}
-
end:
return result;
}
@@ -1130,7 +1243,12 @@ Tk_ChooseDirectoryObjCmd(
callbackInfo->cmdObj = cmdObj;
callbackInfo->interp = interp;
callbackInfo->multiple = 0;
- /*check for directory value, set to root if not specified; otherwise crashes with exception because of nil string parameter*/
+
+ /*
+ * Check for directory value, set to root if not specified; otherwise
+ * crashes with exception because of nil string parameter.
+ */
+
if (!directory) {
directory = @"/";
}
@@ -1139,10 +1257,11 @@ Tk_ChooseDirectoryObjCmd(
parentIsKey = [parent isKeyWindow];
[panel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
[panel beginSheetModalForWindow:parent
- completionHandler:^(NSInteger returnCode)
- { [NSApp tkFilePanelDidEnd:panel
- returnCode:returnCode
- contextInfo:callbackInfo ]; } ];
+ completionHandler:^(NSInteger returnCode) {
+ [NSApp tkFilePanelDidEnd:panel
+ returnCode:returnCode
+ contextInfo:callbackInfo];
+ }];
modalReturnCode = cmdObj ? modalOther : [NSApp runModalForWindow:panel];
} else {
[panel setDirectoryURL:[NSURL fileURLWithPath:directory isDirectory:YES]];
@@ -1201,11 +1320,12 @@ TkAboutDlg(void)
*/
NSString *version = @"Tcl " TCL_PATCH_LEVEL " & Tk " TCL_PATCH_LEVEL;
- NSString *url = @"www.tcl-lang.org";
+ NSString *url = @"www.tcl-lang.org";
NSTextView *credits = [[NSTextView alloc] initWithFrame:NSMakeRect(0,0,300,300)];
NSFont *font = [NSFont systemFontOfSize:[NSFont systemFontSize]];
NSDictionary *textAttributes = [NSDictionary dictionaryWithObject:font
forKey:NSFontAttributeName];
+
[credits insertText: [[NSAttributedString alloc]
initWithString:[NSString stringWithFormat: @"\n"
"Tcl and Tk are distributed under a modified BSD license: "
@@ -1219,11 +1339,13 @@ TkAboutDlg(void)
"%1$C 1998-2000 Jim Ingham & Ray Johnson\n\n"
"%1$C 1998-2000 Scriptics Inc.\n\n"
"%1$C 1996-1997 Sun Microsystems Inc.", 0xA9, year]
- attributes:textAttributes]
- replacementRange:NSMakeRange(0,0)];
+ attributes:textAttributes]
+ replacementRange:NSMakeRange(0,0)];
[credits setDrawsBackground:NO];
[credits setEditable:NO];
- NSAlert *about = [[NSAlert alloc] init];
+
+ NSAlert *about = [[NSAlert alloc] init];
+
[[about window] setTitle:@"About Tcl & Tk"];
[about setMessageText: version];
[about setInformativeText:url];
@@ -1378,7 +1500,8 @@ Tk_MessageBoxObjCmd(
*/
if (Tcl_GetIndexFromObjStruct(interp, objv[indexDefaultOption + 1],
- alertButtonStrings, sizeof(char *), "-default value", TCL_EXACT, &index) != TCL_OK) {
+ alertButtonStrings, sizeof(char *), "-default value",
+ TCL_EXACT, &index) != TCL_OK) {
goto end;
}
@@ -1399,7 +1522,7 @@ Tk_MessageBoxObjCmd(
[alert setAlertStyle:alertStyles[iconIndex]];
i = 0;
while (i < 3 && alertButtonNames[typeIndex][i]) {
- [alert addButtonWithTitle:(NSString*)alertButtonNames[typeIndex][i++]];
+ [alert addButtonWithTitle:(NSString*) alertButtonNames[typeIndex][i++]];
}
buttons = [alert buttons];
for (NSButton *b in buttons) {
@@ -1428,10 +1551,11 @@ Tk_MessageBoxObjCmd(
parentIsKey = [parent isKeyWindow];
#if MAC_OS_X_VERSION_MIN_REQUIRED > 1090
[alert beginSheetModalForWindow:parent
- completionHandler:^(NSModalResponse returnCode)
- { [NSApp tkAlertDidEnd:alert
- returnCode:returnCode
- contextInfo:callbackInfo ]; } ];
+ completionHandler:^(NSModalResponse returnCode) {
+ [NSApp tkAlertDidEnd:alert
+ returnCode:returnCode
+ contextInfo:callbackInfo];
+ }];
#else
[alert beginSheetModalForWindow:parent
modalDelegate:NSApp
@@ -1471,7 +1595,10 @@ typedef struct FontchooserData {
Tk_Window parent;
} FontchooserData;
-enum FontchooserEvent { FontchooserClosed, FontchooserSelection };
+enum FontchooserEvent {
+ FontchooserClosed,
+ FontchooserSelection
+};
static void FontchooserEvent(int kind);
static Tcl_Obj * FontchooserCget(FontchooserData *fcdPtr,
@@ -1563,8 +1690,8 @@ enum FontchooserOption {
*
* FontchooserEvent --
*
- * This processes events generated by user interaction with the
- * font panel.
+ * This processes events generated by user interaction with the font
+ * panel.
*
* Results:
* None.
@@ -1623,9 +1750,8 @@ FontchooserEvent(
*
* FontchooserCget --
*
- * Helper for the FontchooserConfigure command to return the
- * current value of any of the options (which may be NULL in
- * the structure)
+ * Helper for the FontchooserConfigure command to return the current value
+ * of any of the options (which may be NULL in the structure).
*
* Results:
* Tcl object of option value.
@@ -1688,8 +1814,8 @@ FontchooserCget(
*
* FontchooserConfigureCmd --
*
- * Implementation of the 'tk fontchooser configure' ensemble command.
- * See the user documentation for what it does.
+ * Implementation of the 'tk fontchooser configure' ensemble command. See
+ * the user documentation for what it does.
*
* Results:
* See the user documentation.
@@ -1822,7 +1948,8 @@ FontchooserConfigureCmd(
[fm setSelectedAttributes:fontPanelFontAttributes
isMultiple:NO];
if ([fp isVisible]) {
- TkSendVirtualEvent(fcdPtr->parent, "TkFontchooserFontChanged", NULL);
+ TkSendVirtualEvent(fcdPtr->parent,
+ "TkFontchooserFontChanged", NULL);
}
break;
case FontchooserCmd:
@@ -1850,9 +1977,9 @@ FontchooserConfigureCmd(
*
* FontchooserShowCmd --
*
- * Implements the 'tk fontchooser show' ensemble command. The
- * per-interp configuration data for the dialog is held in an interp
- * associated structure.
+ * Implements the 'tk fontchooser show' ensemble command. The per-interp
+ * configuration data for the dialog is held in an interp associated
+ * structure.
*
* Results:
* See the user documentation.
@@ -1878,8 +2005,10 @@ FontchooserShowCmd(
Tk_CreateEventHandler(fcdPtr->parent, StructureNotifyMask,
FontchooserParentEventHandler, fcdPtr);
}
+
NSFontManager *fm = [NSFontManager sharedFontManager];
NSFontPanel *fp = [fm fontPanel:YES];
+
if ([fp delegate] != NSApp) {
[fp setDelegate:NSApp];
}
@@ -1897,8 +2026,8 @@ FontchooserShowCmd(
*
* FontchooserHideCmd --
*
- * Implementation of the 'tk fontchooser hide' ensemble. See the
- * user documentation for details.
+ * Implementation of the 'tk fontchooser hide' ensemble. See the user
+ * documentation for details.
*
* Results:
* See the user documentation.
@@ -1917,6 +2046,7 @@ FontchooserHideCmd(
Tcl_Obj *const objv[])
{
NSFontPanel *fp = [[NSFontManager sharedFontManager] fontPanel:NO];
+
if ([fp isVisible]) {
[fp orderOut:NSApp];
}
@@ -1997,8 +2127,8 @@ DeleteFontchooserData(
*
* TkInitFontchooser --
*
- * Associate the font chooser configuration data with the Tcl
- * interpreter. There is one font chooser per interp.
+ * Associate the font chooser configuration data with the Tcl interpreter.
+ * There is one font chooser per interp.
*
* Results:
* None.