Skip to content

Commit 0a67bf0

Browse files
committed
WIP
1 parent ba5a4ad commit 0a67bf0

13 files changed

Lines changed: 106 additions & 8 deletions

SubEthaEdit-Mac/SEEPlainTextEditorTopBarViewController.xib

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<outlet property="symbolPopUpButton" destination="57S-Gg-lfW" id="Edc-kB-OMb"/>
1616
<outlet property="view" destination="ROy-l3-d1g" id="hu4-z4-zY2"/>
1717
<outlet property="waitPipeIconImageView" destination="YRN-nX-AOm" id="f39-fg-mTK"/>
18+
<outlet property="workspaceButton" destination="LA7-TJ-3JV" id="lK4-cD-QSN"/>
1819
<outlet property="writtenByTextField" destination="W31-AX-oex" id="X2i-0o-Wk0"/>
1920
</connections>
2021
</customObject>
@@ -81,10 +82,22 @@
8182
<action selector="toggleDocumentInfoLabel:" target="-2" id="wmk-us-0AU"/>
8283
</connections>
8384
</textField>
85+
<button id="LA7-TJ-3JV">
86+
<rect key="frame" x="0.0" y="-1" width="19" height="19"/>
87+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
88+
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="NSFolder" imagePosition="only" alignment="center" borderStyle="border" transparent="YES" imageScaling="proportionallyDown" inset="2" id="XJc-wJ-CbM">
89+
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
90+
<font key="font" metaFont="system"/>
91+
</buttonCell>
92+
<connections>
93+
<action selector="workspaceButtonAction:" target="-2" id="0bN-uG-lEc"/>
94+
</connections>
95+
</button>
8496
</subviews>
8597
</customView>
8698
</objects>
8799
<resources>
100+
<image name="NSFolder" width="32" height="32"/>
88101
<image name="ToolbarSplitTwoPanes" width="13" height="13"/>
89102
<image name="WaitPipe" width="13" height="12"/>
90103
</resources>

SubEthaEdit-Mac/Source/PlainTextDocument.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ extern NSString * const PlainTextDocumentUserDidChangeSelectionNotification;
3838
extern NSString * const PlainTextDocumentDefaultParagraphStyleDidChangeNotification;
3939
extern NSString * const PlainTextDocumentDidChangeDisplayNameNotification;
4040
extern NSString * const PlainTextDocumentDidChangeDocumentModeNotification;
41+
extern NSString * const PlainTextDocumentWorkspaceDidChangeNotification;
4142

4243
extern NSString * const WrittenByUserIDAttributeName;
4344
extern NSString * const ChangedByUserIDAttributeName;

SubEthaEdit-Mac/Source/PlainTextDocument.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,17 @@
9797
@"PlainTextDocumentDidChangeTextStorageNotification";
9898
NSString * const PlainTextDocumentDefaultParagraphStyleDidChangeNotification =
9999
@"PlainTextDocumentDefaultParagraphStyleDidChangeNotification";
100+
NSString * const PlainTextDocumentWorkspaceDidChangeNotification =
101+
@"PlainTextDocumentWorkspaceDidChangeNotification";
100102
NSString * const PlainTextDocumentDidSaveNotification =
101103
@"PlainTextDocumentDidSaveNotification";
102104
NSString * const PlainTextDocumentDidSaveShouldReloadWebPreviewNotification =
103105
@"PlainTextDocumentDidSaveShouldReloadWebPreviewNotification";
104106
NSString * const WrittenByUserIDAttributeName = @"WrittenByUserID";
105107
NSString * const ChangedByUserIDAttributeName = @"ChangedByUserID";
106108

109+
static void * PlainTextDocumentWorkspaceObservationContext = &PlainTextDocumentWorkspaceObservationContext;
110+
107111
// Something that's used by our override of -shouldCloseWindowController:delegate:shouldCloseSelector:contextInfo: down below.
108112
@interface PlainTextDocumentShouldCloseContext : NSObject {
109113
@public
@@ -307,6 +311,8 @@ - (void)TCM_initHelper {
307311
I_undoManager = [(UndoManager *)[UndoManager alloc] initWithDocument:self];
308312
[[[self session] loggingState] setInitialTextStorageDictionaryRepresentation:[self textStorageDictionaryRepresentation]];
309313
[[[self session] loggingState] handleOperation:[SelectionOperation selectionOperationWithRange:NSMakeRange(0,0) userID:[TCMMMUserManager myUserID]]];
314+
315+
[self addObserver:self forKeyPath:@"workspace" options:0 context:PlainTextDocumentWorkspaceObservationContext];
310316

311317
}
312318

@@ -774,6 +780,9 @@ - (void)dealloc {
774780
}
775781

776782
[[NSNotificationCenter defaultCenter] removeObserver:self];
783+
784+
[self removeObserver:self forKeyPath:@"workspace" context:PlainTextDocumentWorkspaceObservationContext];
785+
777786
if (I_flags.isAnnounced) {
778787
[[TCMMMPresenceManager sharedInstance] concealSession:[self session]];
779788
}
@@ -883,6 +892,14 @@ - (void)presentScheduledAlertForWindow:(NSWindow *)window {
883892
action(window);
884893
}
885894

895+
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
896+
if (context == PlainTextDocumentWorkspaceObservationContext) {
897+
[[NSNotificationCenter defaultCenter] postNotificationName:PlainTextDocumentWorkspaceDidChangeNotification object:self];
898+
} else {
899+
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
900+
}
901+
}
902+
886903
#pragma mark - Encoding
887904

888905
- (BOOL)canBeConvertedToEncoding:(NSStringEncoding)encoding {

SubEthaEdit-Mac/Source/PlainTextWindowController.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#import "AppController.h"
2020
#import "SEEEncodingDoctorDialogViewController.h"
2121
#import "SEEDocumentController.h"
22+
#import "SEEWorkspaceDocument.h"
2223
#import "PlainTextWindowControllerTabContext.h"
2324
#import "NSMenuTCMAdditions.h"
2425
#import "PlainTextLoadProgress.h"
@@ -409,7 +410,11 @@ - (IBAction)showWorkspace:(id)sender {
409410

410411
[documentController openWorkspace:self.plainTextDocument.workspace
411412
display:YES
412-
withCompletionHandler:nil];
413+
withCompletionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error) {
414+
if ([document isKindOfClass:[SEEWorkspaceDocument class]]) {
415+
[(SEEWorkspaceDocument *)document selectFileWithURL:self.plainTextDocument.fileURL];
416+
}
417+
}];
413418
}
414419

415420

SubEthaEdit-Mac/Source/SEEFSTree.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ - (instancetype)initWithURL:(NSURL *)anURL;
3535
{
3636
self = [super init];
3737
if (self) {
38-
_root = [[SEEFSTreeNode alloc] initWithURL:anURL];
38+
_root = [[SEEFSTreeNode alloc] initWithURL:anURL parent:nil];
3939

4040
NSArray *pathsToWatch = @[anURL.path];
4141

SubEthaEdit-Mac/Source/SEEFSTreeNode.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
@interface SEEFSTreeNode : NSObject
14-
- (instancetype)initWithURL:(NSURL *)anURL;
14+
- (instancetype)initWithURL:(NSURL *)anURL parent:(SEEFSTreeNode *)aParent;
1515

1616
- (NSString *)name;
1717
- (NSImage *)icon;
@@ -22,6 +22,7 @@
2222

2323
- (SEEFSTreeNode * )nodeForPath:(NSString *)path;
2424
- (SEEFSTreeNode * )nodeForPath:(NSString *)path onlyIfCached:(BOOL)cached;
25+
- (NSIndexPath *)indexPath;
2526
@end
2627

2728

SubEthaEdit-Mac/Source/SEEFSTreeNode.m

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ @interface SEEFSTreeNode ()
2222

2323

2424
@implementation SEEFSTreeNode {
25+
__weak SEEFSTreeNode *parent;
2526
NSURL *url;
2627
NSArray *children;
2728
}
2829

29-
- (instancetype)initWithURL:(NSURL *)anURL
30+
- (instancetype)initWithURL:(NSURL *)anURL parent:(SEEFSTreeNode *)aParent
3031
{
3132
self = [super init];
3233
if (self) {
3334
url = anURL;
35+
parent = aParent;
3436

3537
NSDictionary<NSURLResourceKey, id> *values = [url resourceValuesForKeys:@[NSURLIsDirectoryKey]
3638
error:nil];
@@ -56,7 +58,7 @@ - (NSArray *)children {
5658
error:nil];
5759
NSMutableArray * _children = [NSMutableArray arrayWithCapacity:contents.count];
5860
for (NSURL *url in contents) {
59-
[_children addObject:[[SEEFSTreeNode alloc] initWithURL:url]];
61+
[_children addObject:[[SEEFSTreeNode alloc] initWithURL:url parent:self]];
6062
}
6163
children = [_children sortedArrayUsingComparator:^NSComparisonResult(SEEFSTreeNode *obj1, SEEFSTreeNode *obj2) {
6264
NSComparisonResult result = NSOrderedSame;
@@ -102,7 +104,7 @@ - (SEEFSTreeNode *)nodeNamed:(NSString *)name onlyIfCached:(BOOL)cached{
102104
}
103105

104106
- (SEEFSTreeNode * )nodeForPath:(NSString *)path {
105-
return [self nodeNamed:path onlyIfCached:NO];
107+
return [self nodeForPath:path onlyIfCached:NO];
106108
}
107109

108110
- (SEEFSTreeNode *)nodeForPath:(NSString *)path onlyIfCached:(BOOL)cached {
@@ -129,6 +131,19 @@ - (SEEFSTreeNode *)nodeForPath:(NSString *)path onlyIfCached:(BOOL)cached {
129131
return nil;
130132
}
131133

134+
- (NSIndexPath *)indexPath {
135+
NSIndexPath *indexPath = parent.indexPath;
136+
137+
if (parent) {
138+
NSUInteger ownIndex = [parent.children indexOfObject:self];
139+
indexPath = [indexPath indexPathByAddingIndex:ownIndex];
140+
} else {
141+
indexPath = [NSIndexPath indexPathWithIndex:0];
142+
}
143+
144+
return indexPath;
145+
}
146+
132147
- (void)reload {
133148
[self willChangeValueForKey:@"children"];
134149
children = nil;

SubEthaEdit-Mac/Source/SEEPlainTextEditorTopBarViewController.m

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
#import "PlainTextDocument.h"
99
#import "DocumentMode.h"
1010
#import "BorderedTextField.h"
11+
#import "SEEWorkspaceDocument.h"
1112

1213
@interface SEEPlainTextEditorTopBarViewController () <PopUpButtonDelegate>
1314
@property (nonatomic, strong) IBOutlet BorderedTextField *writtenByTextField;
1415
@property (nonatomic, strong) IBOutlet BorderedTextField *positionTextField;
1516
@property (nonatomic, strong) IBOutlet BorderedTextField *docinfoTextField;
1617
@property (nonatomic, strong) IBOutlet NSButton *splitButton;
1718
@property (nonatomic, strong) IBOutlet NSImageView *waitPipeIconImageView;
19+
@property (nonatomic, strong) IBOutlet NSButton *workspaceButton;
1820
@property (nonatomic, strong) IBOutlet NSView *bottomBarLayerBackedView;
1921
@property (nonatomic, strong) NSMutableSet *registeredNotifications;
2022

@@ -55,10 +57,15 @@ - (instancetype)initWithPlainTextEditor:(PlainTextEditor *)anEditor {
5557
[weakSelf updateSymbolPopUpContent];
5658
[weakSelf adjustLayout];
5759
}]];
60+
[set addObject:[center addObserverForName:PlainTextDocumentWorkspaceDidChangeNotification
61+
object:document queue:mainQueue
62+
usingBlock:^(NSNotification *aNotification) {
63+
[weakSelf updateSymbolPopUpContent];
64+
[weakSelf adjustLayout];
65+
}]];
5866

5967
set;
6068
});
61-
6269
}
6370
return self;
6471
}
@@ -156,16 +163,22 @@ - (void)adjustLayout {
156163
NSRect bounds = self.view.bounds;
157164
CGFloat xPosition = NSMinX(bounds);
158165
BOOL isWaiting = [document isWaiting];
166+
BOOL hasWorkspace = (document.workspace != nil);
159167
BOOL hasSymbols = [[document documentMode] hasSymbols];
160168

161169
BorderedTextField *positionTextField = self.positionTextField;
162170
PopUpButton *symbolPopUpButton = self.symbolPopUpButton;
163171
// document is waiting for some input from a pipe so show an indicator for that
164172
self.waitPipeIconImageView.hidden = !isWaiting;
165-
[positionTextField setHasLeftBorder:isWaiting];
173+
[positionTextField setHasLeftBorder:isWaiting || hasWorkspace];
166174
if (isWaiting) {
167175
xPosition += 19.;
168176
}
177+
178+
self.workspaceButton.hidden = !hasWorkspace;
179+
if (hasWorkspace) {
180+
xPosition += 19.;
181+
}
169182

170183
// if there are no symbols hide the symbols popup
171184
[symbolPopUpButton setHidden:!hasSymbols];
@@ -234,6 +247,18 @@ - (IBAction)splitToggleButtonAction:(id)sender {
234247
[self.editor.windowControllerTabContext toggleEditorSplit];
235248
}
236249

250+
- (IBAction)workspaceButtonAction:(id)sender {
251+
SEEDocumentController * documentController = (SEEDocumentController *)[NSDocumentController sharedDocumentController];
252+
253+
[documentController openWorkspace:self.editor.document.workspace
254+
display:YES
255+
withCompletionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error) {
256+
if ([document isKindOfClass:[SEEWorkspaceDocument class]]) {
257+
[(SEEWorkspaceDocument *)document selectFileWithURL:self.editor.document.fileURL];
258+
}
259+
}];
260+
}
261+
237262
- (IBAction)keyboardActivateSymbolPopUp {
238263
[self.symbolPopUpButton performClick:self.editor];
239264
}

SubEthaEdit-Mac/Source/SEEWorkspaceController.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ -(SEEWorkspace *)workspaceForURL:(NSURL *)url createIfNeeded:(BOOL)create {
5252
if(create && !workspace) {
5353
workspace = [[SEEWorkspace alloc] initWithBaseURL:url];
5454
[workspaces addObject:workspace];
55+
for (NSDocument *document in [self.documentController documents]) {
56+
if([document conformsToProtocol:@protocol(SEEWorkspaceDocument)]) {
57+
[self assignDocumentToWorkspace:(NSDocument<SEEWorkspaceDocument> *)document];
58+
}
59+
}
60+
5561
}
5662
return workspace;
5763
}

SubEthaEdit-Mac/Source/SEEWorkspaceDocument.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313

1414
@interface SEEWorkspaceDocument : NSDocument<SEEWorkspaceDocument>
15+
16+
- (void)selectFileWithURL:(NSURL *)url;
17+
1518
@end
1619

1720

0 commit comments

Comments
 (0)