-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathXPDocument.h
More file actions
121 lines (98 loc) · 3.78 KB
/
XPDocument.h
File metadata and controls
121 lines (98 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
// GPLv3 License Notice
//
// Copyright (c) 2025 Jeffrey Bergier
//
// This file is part of MathEdit.
// MathEdit is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
// MathEdit is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with MathEdit. If not, see <https://www.gnu.org/licenses/>.
//
#import <AppKit/AppKit.h>
#import "XPCrossPlatform.h"
@class NSDocumentLegacyImplementation;
#ifdef AFF_NSDocumentNone
#define XPDocument NSDocumentLegacyImplementation
// typedef NSDocumentLegacyImplementation XPDocument;
#else
#define XPDocument NSDocument
// typedef NSDocument XPDocument;
#endif
// This is a best effort implementation of NSDocument only for use in OpenStep.
// Its insanely minimal because it won't be used once Mac OS X Ships
#ifdef AFF_FormalProtocolsNone
@interface NSDocumentLegacyImplementation: NSResponder
#else
@interface NSDocumentLegacyImplementation: NSResponder <NSWindowDelegate>
#endif
{
mm_copy NSString *_fileName;
mm_copy NSString *_fileType;
mm_copy NSString *_requiredFileType;
mm_retain NSWindow *_window_42; // Only used in OpenStep
BOOL _isEdited;
}
// MARK: Init
/// Designated Initializer. Inits an "empty" document.
-(id)init;
-(id)initWithContentsOfFile:(NSString*)fileName ofType:(NSString*)fileType;
// MARK: Window Management
-(void)makeWindowControllers;
-(void)showWindows;
-(NSWindow*)windowForSheet;
-(void)setWindow:(NSWindow *)window;
// MARK: Document Properties
/// Default implementation reads file on disk and compares with _rawData property
/// supported values are NSChangeDone (0) and NSChangeCleared (2)
-(void)updateChangeCount:(XPDocumentChangeType)change;
-(BOOL)isDocumentEdited;
-(NSString*)fileName;
-(void)setFileName:(NSString*)fileName;
-(NSString*)fileType;
-(void)setFileType:(NSString*)type;
-(NSString*)displayName;
// MARK: NSObject basics
-(XPUInteger)hash;
-(BOOL)isEqual:(id)object;
// MARK: MUST IMPLEMENT loading methods
// Override to provide data for saving
-(NSData*)dataRepresentationOfType:(NSString*)type;
// Override to convert your model when loading
-(BOOL)loadDataRepresentation:(NSData*)data ofType:(NSString*)type;
// MARK: Data reading and writing
-(BOOL)writeToFile:(NSString*)fileName ofType:(NSString*)type;
-(BOOL)readFromFile:(NSString*)fileName ofType:(NSString*)type;
// MARK: Menu Handling
/// Override to enable and disable menu items, default returns YES
-(IBAction)saveDocument:(id)sender;
-(IBAction)saveDocumentAs:(id)sender;
-(IBAction)saveDocumentTo:(id)sender;
-(IBAction)revertDocumentToSaved:(id)sender;
// MARK: Customizations
-(NSString*)__requiredFileType;
// TODO: Change this to a method -__fileExtension: for the subclass to implement
-(void)__setRequiredFileType:(NSString*)type;
-(BOOL)windowShouldClose:(id)sender;
-(BOOL)validateMenuItem:(NSMenuItem*)menuItem;
// MARK: Panels and Alerts
-(BOOL)__prepareSavePanel:(NSSavePanel*)savePanel;
-(XPInteger)__runModalSavePanel:(NSSavePanel*)savePanel;
-(XPInteger)__runModalSavePanelAndSetFileURL;
-(XPAlertReturn)__runUnsavedChangesAlert;
-(XPAlertReturn)__runRevertToSavedAlert;
@end
// These are methods added so that IF I want to use this legacy
// implementation in modern macOS, NSDocument won't read my
// subclass out of the info.plist and then try to read
// these methods off of it and crash at launch
@interface NSDocumentLegacyImplementation (NSDocumentWontCrash)
+(BOOL)_autosavesInPlace;
+(NSArray*)readableTypes;
@end