Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Attempt at fixing a crash when trying to open the field editor sheet …
…and Accessibility Services are enabled and a certain other Application is running (issue #2220)
  • Loading branch information
dmoagx committed Sep 10, 2015
1 parent 6f00eaa commit fe050df
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
13 changes: 9 additions & 4 deletions Source/SPCustomQuery.m
Expand Up @@ -2441,6 +2441,12 @@ - (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn

// Check if the field can identified bijectively
if ( aTableView == customQueryView ) {

// Nothing is editable while the field editor is running.
// This guards against a special case where accessibility services might
// check if a table field is editable while the sheet is running.
if (fieldEditor) return NO;

NSDictionary *columnDefinition = [cqColumnDefinition objectAtIndex:[[aTableColumn identifier] integerValue]];

// Check if current field is a blob
Expand All @@ -2450,7 +2456,6 @@ - (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn
// Open the editing sheet if required
if ([customQueryView shouldUseFieldEditorForRow:rowIndex column:[[aTableColumn identifier] integerValue] checkWithLock:NULL])
{
if (fieldEditor) SPClear(fieldEditor);
fieldEditor = [[SPFieldEditorController alloc] init];

// Remember edited row for reselecting and setting the scroll view after reload
Expand Down Expand Up @@ -3681,9 +3686,9 @@ - (void)processFieldEditorResult:(id)data contextInfo:(NSDictionary*)contextInfo
}
}

if(fieldEditor) {
SPClear(fieldEditor);
}
// this is a delegate method of the field editor controller. calling release
// now would risk a dealloc while it is still our parent on the stack:
[fieldEditor autorelease], fieldEditor = nil;

// Preserve focus and restore selection indexes if appropriate
[[tableDocumentInstance parentWindow] makeFirstResponder:customQueryView];
Expand Down
8 changes: 4 additions & 4 deletions Source/SPTableContent.m
Expand Up @@ -3363,10 +3363,10 @@ - (void)processFieldEditorResult:(id)data contextInfo:(NSDictionary*)contextInfo
}
}
}

if(fieldEditor) {
SPClear(fieldEditor);
}
// this is a delegate method of the field editor controller. calling release
// now would risk a dealloc while it is still our parent on the stack:
[fieldEditor autorelease], fieldEditor = nil;

[[tableContentView window] makeFirstResponder:tableContentView];

Expand Down
12 changes: 8 additions & 4 deletions Source/SPTableContentDelegate.m
Expand Up @@ -235,6 +235,11 @@ - (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn
#endif
if (tableView == tableContentView) {

// Nothing is editable while the field editor is running.
// This guards against a special case where accessibility services might
// check if a table field is editable while the sheet is running.
if (fieldEditor) return NO;

// Ensure that row is editable since it could contain "(not loaded)" columns together with
// issue that the table has no primary key
NSString *wherePart = [NSString stringWithString:[self argumentForRow:[tableContentView selectedRow]]];
Expand Down Expand Up @@ -303,8 +308,6 @@ - (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn
fieldEncoding = [columnDefinition objectForKey:@"charset_name"];
}

if (fieldEditor) SPClear(fieldEditor);

fieldEditor = [[SPFieldEditorController alloc] init];

[fieldEditor setEditedFieldInfo:[NSDictionary dictionaryWithObjectsAndKeys:
Expand Down Expand Up @@ -709,8 +712,8 @@ - (void)controlTextDidChange:(NSNotification *)notification

/**
* If the user selected a table cell which is a blob field and tried to edit it
* cancel the fieldEditor, display the field editor sheet instead for editing
* and re-enable the fieldEditor after editing.
* cancel the inline edit, display the field editor sheet instead for editing
* and re-enable inline editing after closing the sheet.
*/
- (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)aFieldEditor
{
Expand Down Expand Up @@ -767,6 +770,7 @@ - (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)aFieldEdit
// Cancel editing
[control abortEditing];

NSAssert(fieldEditor == nil, @"Method should not to be called while a field editor sheet is open!");
// Call the field editor sheet
[self tableView:tableContentView shouldEditTableColumn:NSArrayObjectAtIndex([tableContentView tableColumns], column) row:row];

Expand Down

0 comments on commit fe050df

Please sign in to comment.