diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..66ab87c --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,5 @@ +# These owners will be the default owners for everything in +# the repo. Unless a later match takes precedence, +# @global-owner1 and @global-owner2 will be requested for +# review when someone opens a pull request. +* @rmottola diff --git a/ChangeLog b/ChangeLog index 5c91b6d..5f24604 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,34 @@ +2021-08-18 Riccardo Mottola + + * Modules/Editors/ProjectCenter/PCEditor.m + Turn off ligatures, both when setting up the editor as well as when + loading a file. + +2021-08-18 Riccardo Mottola + + * PCInfoContronoller.m + Center info panel correctly the first time on load. + +2021-08-10 Gregory John Casamento + + * Framework/PCEditorManager.m: Add method -gotoFile:atLine: + * Framework/PCProjectEditor.m: Add method openEditorForFilePath:windowed: + * Framework/PCProjectManager.m: Add method openFileAtPath:windowed: + * Headers/ProjectCenter/PCEditorManager.h + * Headers/ProjectCenter/PCProjectEditor.h + * Headers/ProjectCenter/PCProjectManager.h: Declarations for above methods. + * Modules/Debuggers/ProjectCenter/GDBWrapper.h + * Modules/Debuggers/ProjectCenter/GDBWrapper.m: Add code to pull + "thread-selected" dictionary when the debugger stops by using break/pause + or by using up or down. Code to syncronize editor with where the debugger + has stopped. + * Modules/Debuggers/ProjectCenter/PCDebugger.h + * Modules/Debuggers/ProjectCenter/PCDebugger.m: updateEditor method. This + method makes use of the gotoFile:atLine: method to get the file and show it + in the code editor and go to the line where it has stopped. + * Modules/Editors/ProjectCenter/PCEditor.m: Update internal editor + * Modules/Editors/ProjectCenter/PCEditorView.m: minor bugfixes. + 2021-07-16 Riccardo Mottola * Modules/Debuggers/ProjectCenter/GDBWrapper.h diff --git a/Framework/PCEditorManager.m b/Framework/PCEditorManager.m index 5108b8e..9e890bf 100644 --- a/Framework/PCEditorManager.m +++ b/Framework/PCEditorManager.m @@ -30,10 +30,12 @@ #import #import #import - +#import #import #import +#import + #import "Modules/Preferences/Misc/PCMiscPrefs.h" NSString *PCEditorDidChangeFileNameNotification = @@ -97,15 +99,6 @@ NSString *PCEditorDidResignActiveNotification = selector:@selector(editorDidChangeFileName:) name:PCEditorDidChangeFileNameNotification object:nil]; - - // Debugger - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(debuggerDidHitBreakpoint:) - name:PCProjectBreakpointNotification - object:nil]; - - // Preferences } return self; @@ -542,16 +535,15 @@ NSString *PCEditorDidResignActiveNotification = [_editorsDict setObject:_editor forKey:_newFileName]; } -- (void)debuggerDidHitBreakpoint:(NSNotification *)aNotif +- (void)gotoFile: (NSString *)fileName atLine: (NSUInteger)line { - id object = [aNotif object]; - NSString *filePath = [object objectForKey: @"file"]; - NSString *line = [object objectForKey: @"line"]; - id editor = [self openEditorForFile: filePath - editable: YES - windowed: NO]; - [self orderFrontEditorForFile:filePath]; - [editor scrollToLineNumber: [line integerValue]]; + PCProject *project = [_projectManager rootActiveProject]; + PCProjectEditor *pe = [project projectEditor]; + + id editor = [pe openEditorForFilePath: fileName windowed: NO]; + + // [self orderFrontEditorForFile:fileName]; + [editor scrollToLineNumber: line]; } @end diff --git a/Framework/PCProjectEditor.m b/Framework/PCProjectEditor.m index 989ed18..db10092 100644 --- a/Framework/PCProjectEditor.m +++ b/Framework/PCProjectEditor.m @@ -177,6 +177,54 @@ return NO; } +- (id) openEditorForFilePath: (NSString *)filePath + windowed: (BOOL)windowed +{ + PCProject *activeProject = [[_project projectManager] activeProject]; + NSString *fileName = [filePath lastPathComponent]; + BOOL editable = YES; + id editor = nil; + NSFileManager *mgr = [NSFileManager defaultManager]; + + NSLog(@"PCPE: fileName: %@, filePath: %@, project: %@", + fileName, filePath, [activeProject projectName]); + + if (![mgr fileExistsAtPath: filePath]) + { + return nil; + } + + // Determine if file should be opened for read only + if (![_project isEditableFile:fileName]) + { + editable = NO; + } + + // Set the 'editor' var either by requesting already opened + // editor or by creating the new one. + editor = [self openEditorForFile:filePath + editable:editable + windowed:windowed]; + if (!editor) + { + NSLog(@"We don't have editor for file: %@", fileName); + [self setActiveEditor: nil]; + return nil; + } + + // Category path was changed by user's clicking inside browser. + // That's why new category path must be transfered to editor. + NSString *categoryPath = [NSString stringWithFormat: @"/Classes/%@/", fileName]; + [editor setCategoryPath:categoryPath]; + [self orderFrontEditorForFile:filePath]; + + // Reload last column because editor has just been loaded + [[_project projectBrowser] reloadLastColumnAndNotify:NO]; + [editor fileStructureItemSelected:fileName]; + + return editor; +} + // Called by PCProjectBrowser // categoryPath: // 1. "/Classes/Class.m/- init" diff --git a/Framework/PCProjectManager.m b/Framework/PCProjectManager.m index 0b0a3d8..0bc4358 100644 --- a/Framework/PCProjectManager.m +++ b/Framework/PCProjectManager.m @@ -1124,6 +1124,7 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; // ============================================================================ - (void)openFileAtPath:(NSString *)filePath + windowed:(BOOL)windowed { editorManager = [self editorManager]; @@ -1131,11 +1132,17 @@ NSString *PCActiveProjectDidChangeNotification = @"PCActiveProjectDidChange"; { [editorManager openEditorForFile:filePath editable:YES - windowed:YES]; + windowed:windowed]; [editorManager orderFrontEditorForFile:filePath]; } } +- (void)openFileAtPath:(NSString *)filePath +{ + [self openFileAtPath: filePath windowed: YES]; +} + + - (void)openFile { NSArray *files = nil; diff --git a/Headers/ProjectCenter/PCEditorManager.h b/Headers/ProjectCenter/PCEditorManager.h index 142aebb..e2b6edc 100644 --- a/Headers/ProjectCenter/PCEditorManager.h +++ b/Headers/ProjectCenter/PCEditorManager.h @@ -69,6 +69,7 @@ - (NSArray *)allEditors; - (void)closeActiveEditor:(id)sender; - (void)closeEditorForFile:(NSString *)file; +- (void)gotoFile: (NSString *)fileName atLine: (NSUInteger)line; - (NSArray *)modifiedFiles; - (BOOL)hasModifiedFiles; diff --git a/Headers/ProjectCenter/PCProjectEditor.h b/Headers/ProjectCenter/PCProjectEditor.h index d7d834b..4af6fe7 100644 --- a/Headers/ProjectCenter/PCProjectEditor.h +++ b/Headers/ProjectCenter/PCProjectEditor.h @@ -67,6 +67,9 @@ - (BOOL)editorProvidesBrowserItemsForItem:(NSString *)item; +- (id)openEditorForFilePath:(NSString *)categoryPath + windowed:(BOOL)windowed; + - (id)openEditorForCategoryPath:(NSString *)categoryPath windowed:(BOOL)windowed; diff --git a/Headers/ProjectCenter/PCProjectManager.h b/Headers/ProjectCenter/PCProjectManager.h index 4109b5f..34fdd5a 100644 --- a/Headers/ProjectCenter/PCProjectManager.h +++ b/Headers/ProjectCenter/PCProjectManager.h @@ -164,6 +164,7 @@ extern NSString *PCActiveProjectDidChangeNotification; // Also called by PCAppController - (void)openFileAtPath:(NSString *)filePath; +- (void)openFileAtPath:(NSString *)filePath windowed: (BOOL)windowed; - (void)openFile; - (void)newFile; - (BOOL)saveFile; diff --git a/Modules/Debuggers/ProjectCenter/GDBWrapper.m b/Modules/Debuggers/ProjectCenter/GDBWrapper.m index 33a89ee..86a1245 100644 --- a/Modules/Debuggers/ProjectCenter/GDBWrapper.m +++ b/Modules/Debuggers/ProjectCenter/GDBWrapper.m @@ -379,6 +379,29 @@ [debugger setLastLineNumberParsed: NSNotFound]; } } + + if ([dictionaryName isEqualToString: @"thread-selected"]) + { + NSDictionary *d = [dict objectForKey: @"frame"]; + NSString *fileName; + NSString *lineNum; + + fileName = [d objectForKey:@"fullname"]; + lineNum = [d objectForKey:@"line"]; + + NSLog(@"parsed from GDB thread-selected: %@:%@", fileName, lineNum); + if (fileName != nil && lineNum != nil) + { + [debugger setLastFileNameParsed: fileName]; + [debugger setLastLineNumberParsed: [lineNum intValue]]; + [debugger updateEditor]; + } + else + { + [debugger setLastFileNameParsed: nil]; + [debugger setLastLineNumberParsed: NSNotFound]; + } + } } else { @@ -423,6 +446,7 @@ { [debugger setLastFileNameParsed: fileName]; [debugger setLastLineNumberParsed: [lineNum intValue]]; + [debugger updateEditor]; } else { diff --git a/Modules/Debuggers/ProjectCenter/PCDebugger.h b/Modules/Debuggers/ProjectCenter/PCDebugger.h index f37e309..4e75d9a 100644 --- a/Modules/Debuggers/ProjectCenter/PCDebugger.h +++ b/Modules/Debuggers/ProjectCenter/PCDebugger.h @@ -66,5 +66,6 @@ extern NSString *PCDBDebuggerStartedNotification; - (void) setLastFileNameParsed: (NSString *)fname; - (NSUInteger)lastLineNumberParsed; - (void)setLastLineNumberParsed: (NSUInteger)num; +- (void)updateEditor; @end diff --git a/Modules/Debuggers/ProjectCenter/PCDebugger.m b/Modules/Debuggers/ProjectCenter/PCDebugger.m index 341bd07..8596280 100644 --- a/Modules/Debuggers/ProjectCenter/PCDebugger.m +++ b/Modules/Debuggers/ProjectCenter/PCDebugger.m @@ -33,6 +33,10 @@ #import "PCDebugger.h" #import "PCDebuggerView.h" +#import +#import +#import "PCAppController.h" + #import "Modules/Preferences/EditorFSC/PCEditorFSCPrefs.h" #import "PCDebuggerWrapperProtocol.h" #import "GDBWrapper.h" @@ -306,6 +310,15 @@ NSString *PCDBDebuggerStartedNotification = @"PCDBDebuggerStartedNotification"; lastLineNumberParsed = num; } +- (void) updateEditor +{ + PCAppController *controller = (PCAppController *)[NSApp delegate]; + PCProjectManager *pm = [controller projectManager]; + PCEditorManager *em = [pm editorManager]; + [em gotoFile: lastFileNameParsed + atLine: lastLineNumberParsed]; +} + // kill process - (void) interrupt { diff --git a/Modules/Editors/ProjectCenter/PCEditor.m b/Modules/Editors/ProjectCenter/PCEditor.m index 0ee81ec..18a6a61 100644 --- a/Modules/Editors/ProjectCenter/PCEditor.m +++ b/Modules/Editors/ProjectCenter/PCEditor.m @@ -197,6 +197,7 @@ tSelCol, NSForegroundColorAttributeName, nil]; [ev setSelectedTextAttributes:selAttributes]; + [ev turnOffLigatures:self]; // Activate undo [ev setAllowsUndo: YES]; @@ -345,9 +346,13 @@ textBackground = readOnlyColor; } + textColor = [prefs colorForKey:EditorForegroundColor defaultValue:textColor]; + [attributes setObject:font forKey:NSFontAttributeName]; [attributes setObject:textBackground forKey:NSBackgroundColorAttributeName]; - [attributes setObject:[prefs colorForKey:EditorForegroundColor defaultValue:textColor] forKey:NSForegroundColorAttributeName]; + [attributes setObject:textColor forKey:NSForegroundColorAttributeName]; + [attributes setObject:[NSNumber numberWithInt: 0] // disable ligatures + forKey:NSLigatureAttributeName]; text = [NSString stringWithContentsOfFile:_path]; attributedString = [attributedString initWithString:text attributes:attributes]; @@ -790,7 +795,11 @@ // This is temporary ft = [NSFont userFixedPitchFontOfSize:0.0]; - at = [NSDictionary dictionaryWithObject:ft forKey:NSFontAttributeName]; + at = [NSDictionary dictionaryWithObjectsAndKeys: + ft, NSFontAttributeName, + [NSNumber numberWithInt: 0], NSLigatureAttributeName, + nil]; + as = [[NSAttributedString alloc] initWithString:text attributes:at]; [self setIsEdited:NO]; @@ -985,15 +994,36 @@ if ([object isKindOfClass:[NSTextView class]]) { NSTextView *tv = (NSTextView *)object; - NSArray *selArray; - NSRange lastSelection; - NSRange selRange; - NSUInteger selLine; + NSString *str = [tv string]; + NSRange selection; + NSUInteger selLine = NSNotFound; - selArray = [tv selectedRanges]; - lastSelection = [[selArray lastObject] rangeValue]; - NSLog(@"last selection is %@", [selArray lastObject]); - [[tv string] getLineStart:NULL end:&selLine contentsEnd:NULL forRange:lastSelection]; + // for speed reasons we cache [NSString characterAtIndex:index] + SEL charAtIndexSel = @selector(characterAtIndex:); + unichar (*charAtIndexFunc)(NSString *, SEL, NSUInteger); + charAtIndexFunc = (unichar (*)())[str methodForSelector:charAtIndexSel]; + + selection = [tv selectedRange]; + // now we calculate given the selection the line count, splitting on \n + // calling lineRangeForRange / paragraphForRange does the same thing + // we want to avoid to scan the string twice + { + NSUInteger i; + unichar ch; + NSUInteger nlCount; + + nlCount = 0; + for (i = 0; i < selection.location; i++) + { + // ch = [str characterAtIndex:i]; + ch = (*charAtIndexFunc)(str, charAtIndexSel, i); + if (ch == (unichar)0x000A) // new line + nlCount++; + } + + selLine = nlCount + 1; + } + NSLog(@"%u corresponds to %u", selection.location, selLine); } } @@ -1121,6 +1151,8 @@ { [_intEditorView goToLineNumber:lineNumber]; [_extEditorView goToLineNumber:lineNumber]; + [_intEditorView centerSelectionInVisibleArea: self]; + [_extEditorView centerSelectionInVisibleArea: self]; } @end diff --git a/Modules/Editors/ProjectCenter/PCEditorView.m b/Modules/Editors/ProjectCenter/PCEditorView.m index 7ba2482..2c41b3e 100644 --- a/Modules/Editors/ProjectCenter/PCEditorView.m +++ b/Modules/Editors/ProjectCenter/PCEditorView.m @@ -183,7 +183,7 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start) } } - NSLog(@"index: %i start: %i", index, line_start); + NSLog(@"index: %li start: %li", index, line_start); return line_start > index ? index : line_start; } @@ -311,7 +311,7 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start) if (![wsCharSet characterIsMember:c]) { offset = offset - line_start; - NSLog(@"offset: %i", offset); + NSLog(@"offset: %li", offset); break; } } @@ -328,7 +328,7 @@ static int ComputeIndentingOffset(NSString * string, unsigned int start) // Get offset from BOL of previous line // offset = ComputeIndentingOffset([self string], line_start-1); - NSLog(@"Indent offset: %i", offset); + NSLog(@"Indent offset: %li", offset); // Replace current line whitespaces with new ones indentString = [[NSMutableString alloc] initWithString:@""]; diff --git a/PCAppController.m b/PCAppController.m index f4120b8..0e903b6 100644 --- a/PCAppController.m +++ b/PCAppController.m @@ -64,6 +64,8 @@ - (void)dealloc { + RELEASE(infoController); + RELEASE(projectManager); [super dealloc]; } diff --git a/PCInfoController.m b/PCInfoController.m index fee1c2f..15c15e3 100644 --- a/PCInfoController.m +++ b/PCInfoController.m @@ -37,6 +37,13 @@ infoDict = [NSDictionary dictionaryWithContentsOfFile:file]; RETAIN(infoDict); + + if ([NSBundle loadNibNamed:@"Info" owner:self] == NO) + { + return nil; + } + [versionField setStringValue:[NSString stringWithFormat:@"Version %@", [infoDict objectForKey:@"ApplicationRelease"]]]; + [infoWindow center]; } return self; @@ -56,29 +63,7 @@ - (void)showInfoWindow:(id)sender { - if ([NSBundle loadNibNamed:@"Info" owner:self] == NO) - { -// PCLogError(self, @"error loading Menu NIB file!"); - return; - } - [infoWindow makeKeyAndOrderFront:self]; - [versionField setStringValue:[NSString stringWithFormat:@"Version %@", [infoDict objectForKey:@"ApplicationRelease"]]]; - -/*#if defined(GNUSTEP) - if (!infoWindow) - { - infoWindow = [[GSInfoPanel alloc] initWithDictionary:infoDict]; - } - - [infoWindow setTitle:@"Info"]; - [infoWindow center]; - [infoWindow makeKeyAndOrderFront:self]; -#else - NSRunAlertPanel(@"Info", - @"OPENSTEP has no support for GSInfoPanel", - @"OK",nil,nil,nil); -#endif*/ } @end