Skip to content

Commit 2e32e07

Browse files
committed
Implement the editor, and basic framework for the app
1 parent de5a276 commit 2e32e07

20 files changed

Lines changed: 5302 additions & 14 deletions

Applications/ycode/AppController.m

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
#import "AppController.h"
12+
#import "YCodeWindowController.h"
1213

1314
@implementation AppController
1415

@@ -47,31 +48,95 @@ - (void) awakeFromNib
4748

4849
- (void) applicationDidFinishLaunching: (NSNotification *)aNotif
4950
{
50-
// Uncomment if your application is Renaissance-based
51-
// [NSBundle loadGSMarkupNamed: @"Main" owner: self];
51+
// Create and show the main window
52+
if (!windowController) {
53+
windowController = [[YCodeWindowController alloc] init];
54+
}
55+
56+
[windowController showWindow:self];
57+
[[windowController window] makeKeyAndOrderFront:self];
5258
}
5359

5460
- (BOOL) applicationShouldTerminate: (id)sender
5561
{
56-
return YES;
62+
// Check if there are unsaved changes in open projects
63+
if (windowController && [windowController project]) {
64+
// TODO: Check for unsaved changes
65+
NSAlert *alert = [[NSAlert alloc] init];
66+
[alert setMessageText:@"Do you want to save your changes before closing?"];
67+
[alert addButtonWithTitle:@"Save"];
68+
[alert addButtonWithTitle:@"Don't Save"];
69+
[alert addButtonWithTitle:@"Cancel"];
70+
71+
NSInteger result = [alert runModal];
72+
RELEASE(alert);
73+
74+
if (result == NSAlertThirdButtonReturn) {
75+
return NO; // Cancel
76+
} else if (result == NSAlertFirstButtonReturn) {
77+
// Save before quitting
78+
// TODO: Implement save functionality
79+
}
80+
}
81+
82+
return YES;
5783
}
5884

5985
- (void) applicationWillTerminate: (NSNotification *)aNotif
6086
{
87+
// Clean up
88+
if (windowController) {
89+
[windowController closeProject];
90+
}
6191
}
6292

6393
- (BOOL) application: (NSApplication *)application
6494
openFile: (NSString *)fileName
6595
{
66-
return NO;
96+
if (!windowController) {
97+
windowController = [[YCodeWindowController alloc] init];
98+
[windowController showWindow:self];
99+
}
100+
101+
// Check if it's a project file
102+
NSString *extension = [fileName pathExtension];
103+
if ([extension isEqualToString:@"xcodeproj"] || [extension isEqualToString:@"pcproj"]) {
104+
[windowController openProject:fileName];
105+
return YES;
106+
}
107+
108+
return NO;
67109
}
68110

69111
- (void) showPrefPanel: (id)sender
70112
{
113+
// TODO: Implement preferences panel
114+
NSAlert *alert = [[NSAlert alloc] init];
115+
[alert setMessageText:@"Preferences"];
116+
[alert setInformativeText:@"Preferences panel not yet implemented"];
117+
[alert runModal];
118+
RELEASE(alert);
71119
}
72120

73121
- (IBAction) openProject: (id)sender
74122
{
123+
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
124+
[openPanel setCanChooseFiles:YES];
125+
[openPanel setCanChooseDirectories:YES];
126+
[openPanel setAllowsMultipleSelection:NO];
127+
[openPanel setAllowedFileTypes:@[@"xcodeproj", @"pcproj"]];
128+
[openPanel setMessage:@"Choose a project to open"];
129+
130+
if ([openPanel runModal] == NSModalResponseOK) {
131+
NSString *projectPath = [[openPanel URL] path];
132+
133+
if (!windowController) {
134+
windowController = [[YCodeWindowController alloc] init];
135+
[windowController showWindow:self];
136+
}
137+
138+
[windowController openProject:projectPath];
139+
}
75140
}
76141

77142
@end

Applications/ycode/GNUmakefile

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ PACKAGE_NAME = Ycode
2727
APP_NAME = Ycode
2828
Ycode_APPLICATION_ICON =
2929

30+
#
31+
# Libraries and Frameworks
32+
#
33+
Ycode_GUI_LIBS += -lXCode
34+
Ycode_FRAMEWORK_DIRS += ../XCode
35+
36+
# Additional include directories
37+
ADDITIONAL_INCLUDE_DIRS += -I../XCode
38+
3039

3140
#
3241
# Resource files
@@ -44,7 +53,14 @@ YCodeDocumentController.h \
4453
YCTreeView.h \
4554
YCEditorView.h \
4655
YCInspectorView.h \
47-
YCodeWindowController.h
56+
YCodeWindowController.h \
57+
YCodeProject.h \
58+
YCodeProjectNavigatorController.h \
59+
YCodeProjectNavigatorItem.h \
60+
YCodeEditorController.h \
61+
YCodeEditorDocument.h \
62+
YCodeSyntaxHighlighter.h \
63+
YCodeBuildSystem.h
4864

4965
#
5066
# Objective-C Class files
@@ -55,7 +71,14 @@ YCodeDocumentController.m \
5571
YCTreeView.m \
5672
YCEditorView.m \
5773
YCInspectorView.m \
58-
YCodeWindowController.m
74+
YCodeWindowController.m \
75+
YCodeProject.m \
76+
YCodeProjectNavigatorController.m \
77+
YCodeProjectNavigatorItem.m \
78+
YCodeEditorController.m \
79+
YCodeEditorDocument.m \
80+
YCodeSyntaxHighlighter.m \
81+
YCodeBuildSystem.m
5982

6083
#
6184
# Other sources

Applications/ycode/YCEditorView.h

Lines changed: 139 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,149 @@
2828
#import <Foundation/Foundation.h>
2929
#import <AppKit/AppKit.h>
3030

31-
@interface YCEditorView : NSView
31+
@class YCodeEditorDocument;
32+
@class YCodeSyntaxHighlighter;
33+
@class YCEditorLineNumberView;
34+
35+
@interface YCEditorView : NSView <NSTextViewDelegate>
3236
{
37+
NSScrollView *_scrollView;
38+
NSTextView *_textView;
39+
YCEditorLineNumberView *_lineNumberView;
40+
41+
YCodeEditorDocument *_document;
42+
YCodeSyntaxHighlighter *_syntaxHighlighter;
43+
44+
// Editor settings
45+
NSFont *_font;
46+
NSColor *_textColor;
47+
NSColor *_backgroundColor;
48+
NSColor *_selectionColor;
49+
NSColor *_currentLineColor;
50+
51+
BOOL _showLineNumbers;
52+
BOOL _highlightCurrentLine;
53+
BOOL _autoIndent;
54+
BOOL _syntaxHighlighting;
55+
56+
NSInteger _tabWidth;
57+
BOOL _useSpacesForTabs;
58+
59+
// Find and replace
60+
NSString *_findString;
61+
NSString *_replaceString;
62+
BOOL _caseSensitive;
63+
BOOL _useRegex;
64+
}
65+
66+
/**
67+
* Document association
68+
*/
69+
- (YCodeEditorDocument *)document;
70+
- (void)setDocument:(YCodeEditorDocument *)document;
71+
72+
/**
73+
* Text view access
74+
*/
75+
- (NSTextView *)textView;
76+
- (NSScrollView *)scrollView;
77+
78+
/**
79+
* Content management
80+
*/
81+
- (NSString *)text;
82+
- (void)setText:(NSString *)text;
83+
- (BOOL)hasSelection;
84+
- (NSString *)selectedText;
85+
- (NSRange)selectedRange;
86+
- (void)setSelectedRange:(NSRange)range;
87+
88+
/**
89+
* Editor settings
90+
*/
91+
- (NSFont *)font;
92+
- (void)setFont:(NSFont *)font;
93+
- (NSColor *)textColor;
94+
- (void)setTextColor:(NSColor *)color;
95+
- (NSColor *)backgroundColor;
96+
- (void)setBackgroundColor:(NSColor *)color;
97+
- (BOOL)showLineNumbers;
98+
- (void)setShowLineNumbers:(BOOL)show;
99+
- (BOOL)highlightCurrentLine;
100+
- (void)setHighlightCurrentLine:(BOOL)highlight;
101+
- (NSInteger)tabWidth;
102+
- (void)setTabWidth:(NSInteger)width;
103+
- (BOOL)useSpacesForTabs;
104+
- (void)setUseSpacesForTabs:(BOOL)useSpaces;
105+
106+
/**
107+
* Syntax highlighting
108+
*/
109+
- (BOOL)syntaxHighlighting;
110+
- (void)setSyntaxHighlighting:(BOOL)highlighting;
111+
- (YCodeSyntaxHighlighter *)syntaxHighlighter;
112+
- (void)applySyntaxHighlighting;
113+
114+
/**
115+
* Text operations
116+
*/
117+
- (void)insertText:(NSString *)text;
118+
- (void)insertText:(NSString *)text atLocation:(NSUInteger)location;
119+
- (void)deleteSelectedText;
120+
- (void)selectAll;
121+
- (void)copy;
122+
- (void)cut;
123+
- (void)paste;
33124

125+
/**
126+
* Line operations
127+
*/
128+
- (NSUInteger)currentLineNumber;
129+
- (NSUInteger)totalLineCount;
130+
- (NSRange)rangeOfLine:(NSUInteger)lineNumber;
131+
- (void)goToLine:(NSUInteger)lineNumber;
132+
- (void)selectLine:(NSUInteger)lineNumber;
133+
134+
/**
135+
* Find and replace
136+
*/
137+
- (void)findText:(NSString *)searchText options:(NSStringCompareOptions)options;
138+
- (void)replaceText:(NSString *)searchText withText:(NSString *)replaceText options:(NSStringCompareOptions)options;
139+
- (void)findNext;
140+
- (void)findPrevious;
141+
142+
/**
143+
* Indentation
144+
*/
145+
- (void)indentSelectedLines;
146+
- (void)unindentSelectedLines;
147+
- (void)commentSelectedLines;
148+
- (void)uncommentSelectedLines;
149+
150+
/**
151+
* Folding (basic support)
152+
*/
153+
- (BOOL)canFoldAtLine:(NSUInteger)lineNumber;
154+
- (void)foldAtLine:(NSUInteger)lineNumber;
155+
- (void)unfoldAtLine:(NSUInteger)lineNumber;
156+
157+
@end
158+
159+
/**
160+
* Line number view
161+
*/
162+
@interface YCEditorLineNumberView : NSRulerView
163+
{
164+
YCEditorView *_editorView;
165+
NSColor *_backgroundColor;
166+
NSColor *_textColor;
167+
NSFont *_font;
34168
}
35169

170+
- (instancetype)initWithEditorView:(YCEditorView *)editorView;
171+
- (YCEditorView *)editorView;
172+
- (void)setEditorView:(YCEditorView *)editorView;
173+
36174
@end
37175

38176
#endif // _YCEDITORVIEW_H_

0 commit comments

Comments
 (0)