├── .gitignore ├── BSMultipleDocumentsWindowController.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── pierre.xcuserdatad │ │ ├── UserInterfaceState.xcuserstate │ │ └── WorkspaceSettings.xcsettings └── xcuserdata │ └── pierre.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── BSMultipleDocumentsWindowController.xcscheme │ └── xcschememanagement.plist ├── BSMultipleDocumentsWindowController ├── BSDocument.h ├── BSDocument.m ├── BSDocumentController.h ├── BSDocumentController.m ├── BSMultipleDocumentsWindow.h ├── BSMultipleDocumentsWindow.m ├── BSMultipleDocumentsWindowController.h ├── BSMultipleDocumentsWindowController.m ├── BSPersistentDocument.h └── BSPersistentDocument.m ├── README.mdown ├── Sample Application ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ └── MainMenu.xib ├── Document.h ├── Document.m ├── DocumentViewController.h ├── DocumentViewController.m ├── DocumentViewController.xib ├── DocumentsContainerViewController.h ├── DocumentsContainerViewController.m ├── DocumentsContainerViewController.xib ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── MultipleDocumentsWindowController.h ├── MultipleDocumentsWindowController.m ├── MultipleDocumentsWindowController.xib └── main.m └── Screenshot.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.xccheckout 3 | 4 | *.xcuserstate 5 | -------------------------------------------------------------------------------- /BSMultipleDocumentsWindowController.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 8F1BC5641BC9752100B648DE /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F1BC5631BC9752100B648DE /* AppDelegate.m */; }; 11 | 8F1BC5671BC9752700B648DE /* Document.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F1BC5661BC9752700B648DE /* Document.m */; }; 12 | 8F1BC56B1BC9752B00B648DE /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F1BC5691BC9752B00B648DE /* main.m */; }; 13 | 8F1BC56D1BC9752F00B648DE /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8F1BC56C1BC9752F00B648DE /* Images.xcassets */; }; 14 | 8F1BC5731BC9753200B648DE /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8F1BC5701BC9753200B648DE /* MainMenu.xib */; }; 15 | 8F1BC57E1BC9758C00B648DE /* BSDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F1BC5751BC9758C00B648DE /* BSDocument.m */; }; 16 | 8F1BC57F1BC9758C00B648DE /* BSDocumentController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F1BC5771BC9758C00B648DE /* BSDocumentController.m */; }; 17 | 8F1BC5801BC9758C00B648DE /* BSMultipleDocumentsWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F1BC5791BC9758C00B648DE /* BSMultipleDocumentsWindow.m */; }; 18 | 8F1BC5811BC9758C00B648DE /* BSMultipleDocumentsWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F1BC57B1BC9758C00B648DE /* BSMultipleDocumentsWindowController.m */; }; 19 | 8F1BC5821BC9758C00B648DE /* BSPersistentDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F1BC57D1BC9758C00B648DE /* BSPersistentDocument.m */; }; 20 | 8F1BC5871BC97E1F00B648DE /* DocumentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F1BC5851BC97E1F00B648DE /* DocumentViewController.m */; }; 21 | 8F1BC5881BC97E1F00B648DE /* DocumentViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8F1BC5861BC97E1F00B648DE /* DocumentViewController.xib */; }; 22 | 8F1BC58C1BC980AF00B648DE /* MultipleDocumentsWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F1BC58A1BC980AF00B648DE /* MultipleDocumentsWindowController.m */; }; 23 | 8F1BC58D1BC980AF00B648DE /* MultipleDocumentsWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8F1BC58B1BC980AF00B648DE /* MultipleDocumentsWindowController.xib */; }; 24 | 8F1BC5911BC987E800B648DE /* DocumentsContainerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8F1BC58F1BC987E800B648DE /* DocumentsContainerViewController.m */; }; 25 | 8F1BC5921BC987E800B648DE /* DocumentsContainerViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 8F1BC5901BC987E800B648DE /* DocumentsContainerViewController.xib */; }; 26 | /* End PBXBuildFile section */ 27 | 28 | /* Begin PBXFileReference section */ 29 | 8F1BC5371BC9748700B648DE /* BSMultipleDocumentsWindowController.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = BSMultipleDocumentsWindowController.app; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | 8F1BC5621BC9752100B648DE /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 31 | 8F1BC5631BC9752100B648DE /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 32 | 8F1BC5651BC9752700B648DE /* Document.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Document.h; sourceTree = ""; }; 33 | 8F1BC5661BC9752700B648DE /* Document.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Document.m; sourceTree = ""; }; 34 | 8F1BC5681BC9752B00B648DE /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | 8F1BC5691BC9752B00B648DE /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 36 | 8F1BC56C1BC9752F00B648DE /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 37 | 8F1BC5711BC9753200B648DE /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; 38 | 8F1BC5741BC9758C00B648DE /* BSDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BSDocument.h; sourceTree = ""; }; 39 | 8F1BC5751BC9758C00B648DE /* BSDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BSDocument.m; sourceTree = ""; }; 40 | 8F1BC5761BC9758C00B648DE /* BSDocumentController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BSDocumentController.h; sourceTree = ""; }; 41 | 8F1BC5771BC9758C00B648DE /* BSDocumentController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BSDocumentController.m; sourceTree = ""; }; 42 | 8F1BC5781BC9758C00B648DE /* BSMultipleDocumentsWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BSMultipleDocumentsWindow.h; sourceTree = ""; }; 43 | 8F1BC5791BC9758C00B648DE /* BSMultipleDocumentsWindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BSMultipleDocumentsWindow.m; sourceTree = ""; }; 44 | 8F1BC57A1BC9758C00B648DE /* BSMultipleDocumentsWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BSMultipleDocumentsWindowController.h; sourceTree = ""; }; 45 | 8F1BC57B1BC9758C00B648DE /* BSMultipleDocumentsWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BSMultipleDocumentsWindowController.m; sourceTree = ""; }; 46 | 8F1BC57C1BC9758C00B648DE /* BSPersistentDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BSPersistentDocument.h; sourceTree = ""; }; 47 | 8F1BC57D1BC9758C00B648DE /* BSPersistentDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BSPersistentDocument.m; sourceTree = ""; }; 48 | 8F1BC5831BC976BB00B648DE /* README.mdown */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.mdown; sourceTree = ""; }; 49 | 8F1BC5841BC97E1F00B648DE /* DocumentViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentViewController.h; sourceTree = ""; }; 50 | 8F1BC5851BC97E1F00B648DE /* DocumentViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DocumentViewController.m; sourceTree = ""; }; 51 | 8F1BC5861BC97E1F00B648DE /* DocumentViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DocumentViewController.xib; sourceTree = ""; }; 52 | 8F1BC5891BC980AF00B648DE /* MultipleDocumentsWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MultipleDocumentsWindowController.h; sourceTree = ""; }; 53 | 8F1BC58A1BC980AF00B648DE /* MultipleDocumentsWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MultipleDocumentsWindowController.m; sourceTree = ""; }; 54 | 8F1BC58B1BC980AF00B648DE /* MultipleDocumentsWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MultipleDocumentsWindowController.xib; sourceTree = ""; }; 55 | 8F1BC58E1BC987E800B648DE /* DocumentsContainerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentsContainerViewController.h; sourceTree = ""; }; 56 | 8F1BC58F1BC987E800B648DE /* DocumentsContainerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DocumentsContainerViewController.m; sourceTree = ""; }; 57 | 8F1BC5901BC987E800B648DE /* DocumentsContainerViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DocumentsContainerViewController.xib; sourceTree = ""; }; 58 | /* End PBXFileReference section */ 59 | 60 | /* Begin PBXFrameworksBuildPhase section */ 61 | 8F1BC5341BC9748700B648DE /* Frameworks */ = { 62 | isa = PBXFrameworksBuildPhase; 63 | buildActionMask = 2147483647; 64 | files = ( 65 | ); 66 | runOnlyForDeploymentPostprocessing = 0; 67 | }; 68 | /* End PBXFrameworksBuildPhase section */ 69 | 70 | /* Begin PBXGroup section */ 71 | 8F1BC52E1BC9748700B648DE = { 72 | isa = PBXGroup; 73 | children = ( 74 | 8F1BC5831BC976BB00B648DE /* README.mdown */, 75 | 8F1BC5601BC974BB00B648DE /* Sample Application */, 76 | 8F1BC5391BC9748700B648DE /* BSMultipleDocumentsWindowController */, 77 | 8F1BC5381BC9748700B648DE /* Products */, 78 | ); 79 | sourceTree = ""; 80 | }; 81 | 8F1BC5381BC9748700B648DE /* Products */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | 8F1BC5371BC9748700B648DE /* BSMultipleDocumentsWindowController.app */, 85 | ); 86 | name = Products; 87 | sourceTree = ""; 88 | }; 89 | 8F1BC5391BC9748700B648DE /* BSMultipleDocumentsWindowController */ = { 90 | isa = PBXGroup; 91 | children = ( 92 | 8F1BC5741BC9758C00B648DE /* BSDocument.h */, 93 | 8F1BC5751BC9758C00B648DE /* BSDocument.m */, 94 | 8F1BC5761BC9758C00B648DE /* BSDocumentController.h */, 95 | 8F1BC5771BC9758C00B648DE /* BSDocumentController.m */, 96 | 8F1BC5781BC9758C00B648DE /* BSMultipleDocumentsWindow.h */, 97 | 8F1BC5791BC9758C00B648DE /* BSMultipleDocumentsWindow.m */, 98 | 8F1BC57A1BC9758C00B648DE /* BSMultipleDocumentsWindowController.h */, 99 | 8F1BC57B1BC9758C00B648DE /* BSMultipleDocumentsWindowController.m */, 100 | 8F1BC57C1BC9758C00B648DE /* BSPersistentDocument.h */, 101 | 8F1BC57D1BC9758C00B648DE /* BSPersistentDocument.m */, 102 | ); 103 | path = BSMultipleDocumentsWindowController; 104 | sourceTree = ""; 105 | }; 106 | 8F1BC5601BC974BB00B648DE /* Sample Application */ = { 107 | isa = PBXGroup; 108 | children = ( 109 | 8F1BC5621BC9752100B648DE /* AppDelegate.h */, 110 | 8F1BC5631BC9752100B648DE /* AppDelegate.m */, 111 | 8F1BC5651BC9752700B648DE /* Document.h */, 112 | 8F1BC5661BC9752700B648DE /* Document.m */, 113 | 8F1BC58E1BC987E800B648DE /* DocumentsContainerViewController.h */, 114 | 8F1BC58F1BC987E800B648DE /* DocumentsContainerViewController.m */, 115 | 8F1BC5901BC987E800B648DE /* DocumentsContainerViewController.xib */, 116 | 8F1BC5841BC97E1F00B648DE /* DocumentViewController.h */, 117 | 8F1BC5851BC97E1F00B648DE /* DocumentViewController.m */, 118 | 8F1BC5861BC97E1F00B648DE /* DocumentViewController.xib */, 119 | 8F1BC56C1BC9752F00B648DE /* Images.xcassets */, 120 | 8F1BC5701BC9753200B648DE /* MainMenu.xib */, 121 | 8F1BC5891BC980AF00B648DE /* MultipleDocumentsWindowController.h */, 122 | 8F1BC58A1BC980AF00B648DE /* MultipleDocumentsWindowController.m */, 123 | 8F1BC58B1BC980AF00B648DE /* MultipleDocumentsWindowController.xib */, 124 | 8F1BC5611BC9750C00B648DE /* Supporting Files */, 125 | ); 126 | path = "Sample Application"; 127 | sourceTree = ""; 128 | }; 129 | 8F1BC5611BC9750C00B648DE /* Supporting Files */ = { 130 | isa = PBXGroup; 131 | children = ( 132 | 8F1BC5681BC9752B00B648DE /* Info.plist */, 133 | 8F1BC5691BC9752B00B648DE /* main.m */, 134 | ); 135 | name = "Supporting Files"; 136 | sourceTree = ""; 137 | }; 138 | /* End PBXGroup section */ 139 | 140 | /* Begin PBXNativeTarget section */ 141 | 8F1BC5361BC9748700B648DE /* BSMultipleDocumentsWindowController */ = { 142 | isa = PBXNativeTarget; 143 | buildConfigurationList = 8F1BC55A1BC9748700B648DE /* Build configuration list for PBXNativeTarget "BSMultipleDocumentsWindowController" */; 144 | buildPhases = ( 145 | 8F1BC5331BC9748700B648DE /* Sources */, 146 | 8F1BC5341BC9748700B648DE /* Frameworks */, 147 | 8F1BC5351BC9748700B648DE /* Resources */, 148 | ); 149 | buildRules = ( 150 | ); 151 | dependencies = ( 152 | ); 153 | name = BSMultipleDocumentsWindowController; 154 | productName = BSMultipleDocumentsWindowController; 155 | productReference = 8F1BC5371BC9748700B648DE /* BSMultipleDocumentsWindowController.app */; 156 | productType = "com.apple.product-type.application"; 157 | }; 158 | /* End PBXNativeTarget section */ 159 | 160 | /* Begin PBXProject section */ 161 | 8F1BC52F1BC9748700B648DE /* Project object */ = { 162 | isa = PBXProject; 163 | attributes = { 164 | LastUpgradeCheck = 0640; 165 | ORGANIZATIONNAME = "Houdah Software s.à r.l."; 166 | TargetAttributes = { 167 | 8F1BC5361BC9748700B648DE = { 168 | CreatedOnToolsVersion = 6.4; 169 | }; 170 | }; 171 | }; 172 | buildConfigurationList = 8F1BC5321BC9748700B648DE /* Build configuration list for PBXProject "BSMultipleDocumentsWindowController" */; 173 | compatibilityVersion = "Xcode 3.2"; 174 | developmentRegion = English; 175 | hasScannedForEncodings = 0; 176 | knownRegions = ( 177 | en, 178 | Base, 179 | ); 180 | mainGroup = 8F1BC52E1BC9748700B648DE; 181 | productRefGroup = 8F1BC5381BC9748700B648DE /* Products */; 182 | projectDirPath = ""; 183 | projectRoot = ""; 184 | targets = ( 185 | 8F1BC5361BC9748700B648DE /* BSMultipleDocumentsWindowController */, 186 | ); 187 | }; 188 | /* End PBXProject section */ 189 | 190 | /* Begin PBXResourcesBuildPhase section */ 191 | 8F1BC5351BC9748700B648DE /* Resources */ = { 192 | isa = PBXResourcesBuildPhase; 193 | buildActionMask = 2147483647; 194 | files = ( 195 | 8F1BC58D1BC980AF00B648DE /* MultipleDocumentsWindowController.xib in Resources */, 196 | 8F1BC56D1BC9752F00B648DE /* Images.xcassets in Resources */, 197 | 8F1BC5921BC987E800B648DE /* DocumentsContainerViewController.xib in Resources */, 198 | 8F1BC5731BC9753200B648DE /* MainMenu.xib in Resources */, 199 | 8F1BC5881BC97E1F00B648DE /* DocumentViewController.xib in Resources */, 200 | ); 201 | runOnlyForDeploymentPostprocessing = 0; 202 | }; 203 | /* End PBXResourcesBuildPhase section */ 204 | 205 | /* Begin PBXSourcesBuildPhase section */ 206 | 8F1BC5331BC9748700B648DE /* Sources */ = { 207 | isa = PBXSourcesBuildPhase; 208 | buildActionMask = 2147483647; 209 | files = ( 210 | 8F1BC5671BC9752700B648DE /* Document.m in Sources */, 211 | 8F1BC5801BC9758C00B648DE /* BSMultipleDocumentsWindow.m in Sources */, 212 | 8F1BC5911BC987E800B648DE /* DocumentsContainerViewController.m in Sources */, 213 | 8F1BC5811BC9758C00B648DE /* BSMultipleDocumentsWindowController.m in Sources */, 214 | 8F1BC57F1BC9758C00B648DE /* BSDocumentController.m in Sources */, 215 | 8F1BC5871BC97E1F00B648DE /* DocumentViewController.m in Sources */, 216 | 8F1BC56B1BC9752B00B648DE /* main.m in Sources */, 217 | 8F1BC5641BC9752100B648DE /* AppDelegate.m in Sources */, 218 | 8F1BC5821BC9758C00B648DE /* BSPersistentDocument.m in Sources */, 219 | 8F1BC58C1BC980AF00B648DE /* MultipleDocumentsWindowController.m in Sources */, 220 | 8F1BC57E1BC9758C00B648DE /* BSDocument.m in Sources */, 221 | ); 222 | runOnlyForDeploymentPostprocessing = 0; 223 | }; 224 | /* End PBXSourcesBuildPhase section */ 225 | 226 | /* Begin PBXVariantGroup section */ 227 | 8F1BC5701BC9753200B648DE /* MainMenu.xib */ = { 228 | isa = PBXVariantGroup; 229 | children = ( 230 | 8F1BC5711BC9753200B648DE /* Base */, 231 | ); 232 | name = MainMenu.xib; 233 | sourceTree = ""; 234 | }; 235 | /* End PBXVariantGroup section */ 236 | 237 | /* Begin XCBuildConfiguration section */ 238 | 8F1BC5581BC9748700B648DE /* Debug */ = { 239 | isa = XCBuildConfiguration; 240 | buildSettings = { 241 | ALWAYS_SEARCH_USER_PATHS = NO; 242 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 243 | CLANG_CXX_LIBRARY = "libc++"; 244 | CLANG_ENABLE_MODULES = YES; 245 | CLANG_ENABLE_OBJC_ARC = YES; 246 | CLANG_WARN_BOOL_CONVERSION = YES; 247 | CLANG_WARN_CONSTANT_CONVERSION = YES; 248 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 249 | CLANG_WARN_EMPTY_BODY = YES; 250 | CLANG_WARN_ENUM_CONVERSION = YES; 251 | CLANG_WARN_INT_CONVERSION = YES; 252 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 253 | CLANG_WARN_UNREACHABLE_CODE = YES; 254 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 255 | CODE_SIGN_IDENTITY = "-"; 256 | COPY_PHASE_STRIP = NO; 257 | DEBUG_INFORMATION_FORMAT = dwarf; 258 | ENABLE_STRICT_OBJC_MSGSEND = YES; 259 | GCC_C_LANGUAGE_STANDARD = gnu99; 260 | GCC_DYNAMIC_NO_PIC = NO; 261 | GCC_NO_COMMON_BLOCKS = YES; 262 | GCC_OPTIMIZATION_LEVEL = 0; 263 | GCC_PREPROCESSOR_DEFINITIONS = ( 264 | "DEBUG=1", 265 | "$(inherited)", 266 | ); 267 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 268 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 269 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 270 | GCC_WARN_UNDECLARED_SELECTOR = YES; 271 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 272 | GCC_WARN_UNUSED_FUNCTION = YES; 273 | GCC_WARN_UNUSED_VARIABLE = YES; 274 | MACOSX_DEPLOYMENT_TARGET = 10.10; 275 | MTL_ENABLE_DEBUG_INFO = YES; 276 | ONLY_ACTIVE_ARCH = YES; 277 | SDKROOT = macosx; 278 | }; 279 | name = Debug; 280 | }; 281 | 8F1BC5591BC9748700B648DE /* Release */ = { 282 | isa = XCBuildConfiguration; 283 | buildSettings = { 284 | ALWAYS_SEARCH_USER_PATHS = NO; 285 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 286 | CLANG_CXX_LIBRARY = "libc++"; 287 | CLANG_ENABLE_MODULES = YES; 288 | CLANG_ENABLE_OBJC_ARC = YES; 289 | CLANG_WARN_BOOL_CONVERSION = YES; 290 | CLANG_WARN_CONSTANT_CONVERSION = YES; 291 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 292 | CLANG_WARN_EMPTY_BODY = YES; 293 | CLANG_WARN_ENUM_CONVERSION = YES; 294 | CLANG_WARN_INT_CONVERSION = YES; 295 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 296 | CLANG_WARN_UNREACHABLE_CODE = YES; 297 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 298 | CODE_SIGN_IDENTITY = "-"; 299 | COPY_PHASE_STRIP = NO; 300 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 301 | ENABLE_NS_ASSERTIONS = NO; 302 | ENABLE_STRICT_OBJC_MSGSEND = YES; 303 | GCC_C_LANGUAGE_STANDARD = gnu99; 304 | GCC_NO_COMMON_BLOCKS = YES; 305 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 306 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 307 | GCC_WARN_UNDECLARED_SELECTOR = YES; 308 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 309 | GCC_WARN_UNUSED_FUNCTION = YES; 310 | GCC_WARN_UNUSED_VARIABLE = YES; 311 | MACOSX_DEPLOYMENT_TARGET = 10.10; 312 | MTL_ENABLE_DEBUG_INFO = NO; 313 | SDKROOT = macosx; 314 | }; 315 | name = Release; 316 | }; 317 | 8F1BC55B1BC9748700B648DE /* Debug */ = { 318 | isa = XCBuildConfiguration; 319 | buildSettings = { 320 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 321 | COMBINE_HIDPI_IMAGES = YES; 322 | INFOPLIST_FILE = "$(SRCROOT)/Sample Application/Info.plist"; 323 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 324 | PRODUCT_NAME = "$(TARGET_NAME)"; 325 | }; 326 | name = Debug; 327 | }; 328 | 8F1BC55C1BC9748700B648DE /* Release */ = { 329 | isa = XCBuildConfiguration; 330 | buildSettings = { 331 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 332 | COMBINE_HIDPI_IMAGES = YES; 333 | INFOPLIST_FILE = "$(SRCROOT)/Sample Application/Info.plist"; 334 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 335 | PRODUCT_NAME = "$(TARGET_NAME)"; 336 | }; 337 | name = Release; 338 | }; 339 | /* End XCBuildConfiguration section */ 340 | 341 | /* Begin XCConfigurationList section */ 342 | 8F1BC5321BC9748700B648DE /* Build configuration list for PBXProject "BSMultipleDocumentsWindowController" */ = { 343 | isa = XCConfigurationList; 344 | buildConfigurations = ( 345 | 8F1BC5581BC9748700B648DE /* Debug */, 346 | 8F1BC5591BC9748700B648DE /* Release */, 347 | ); 348 | defaultConfigurationIsVisible = 0; 349 | defaultConfigurationName = Release; 350 | }; 351 | 8F1BC55A1BC9748700B648DE /* Build configuration list for PBXNativeTarget "BSMultipleDocumentsWindowController" */ = { 352 | isa = XCConfigurationList; 353 | buildConfigurations = ( 354 | 8F1BC55B1BC9748700B648DE /* Debug */, 355 | 8F1BC55C1BC9748700B648DE /* Release */, 356 | ); 357 | defaultConfigurationIsVisible = 0; 358 | }; 359 | /* End XCConfigurationList section */ 360 | }; 361 | rootObject = 8F1BC52F1BC9748700B648DE /* Project object */; 362 | } 363 | -------------------------------------------------------------------------------- /BSMultipleDocumentsWindowController.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /BSMultipleDocumentsWindowController.xcodeproj/project.xcworkspace/xcuserdata/pierre.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gloubibou/BSMultipleDocumentsWindowController/ec01294458d17292bea4bdcb56d9fa0d916a6cc8/BSMultipleDocumentsWindowController.xcodeproj/project.xcworkspace/xcuserdata/pierre.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /BSMultipleDocumentsWindowController.xcodeproj/project.xcworkspace/xcuserdata/pierre.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges 6 | 7 | SnapshotAutomaticallyBeforeSignificantChanges 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /BSMultipleDocumentsWindowController.xcodeproj/xcuserdata/pierre.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /BSMultipleDocumentsWindowController.xcodeproj/xcuserdata/pierre.xcuserdatad/xcschemes/BSMultipleDocumentsWindowController.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 77 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 96 | 102 | 103 | 104 | 105 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /BSMultipleDocumentsWindowController.xcodeproj/xcuserdata/pierre.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | BSMultipleDocumentsWindowController.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 8F1BC5361BC9748700B648DE 16 | 17 | primary 18 | 19 | 20 | 8F1BC54F1BC9748700B648DE 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /BSMultipleDocumentsWindowController/BSDocument.h: -------------------------------------------------------------------------------- 1 | // 2 | // BSDocument.h 3 | // HoudahSpot 4 | // 5 | // Created by Pierre Bernard on 26/06/15. 6 | // Copyright (c) 2012 Sasmito Adibowo. Creative Commons Attribution-ShareAlike 3.0 Unported License. 7 | // Copyright (c) 2014-2015 Houdah Software s.à r.l. Creative Commons Attribution-ShareAlike 3.0 Unported License. 8 | // 9 | // Based upon http://cutecoder.org/programming/window-multiple-documents/ 10 | // 11 | 12 | @import Cocoa; 13 | 14 | 15 | @interface BSDocument : NSDocument 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /BSMultipleDocumentsWindowController/BSDocument.m: -------------------------------------------------------------------------------- 1 | // 2 | // BSDocument.m 3 | // HoudahSpot 4 | // 5 | // Created by Pierre Bernard on 26/06/15. 6 | // Copyright (c) 2012 Sasmito Adibowo. Creative Commons Attribution-ShareAlike 3.0 Unported License. 7 | // Copyright (c) 2014-2015 Houdah Software s.à r.l. Creative Commons Attribution-ShareAlike 3.0 Unported License. 8 | // 9 | // Based upon http://cutecoder.org/programming/window-multiple-documents/ 10 | // 11 | 12 | #import "BSDocument.h" 13 | 14 | #import "BSMultipleDocumentsWindowController.h" 15 | 16 | 17 | @interface BSDocument () 18 | 19 | @end 20 | 21 | 22 | @implementation BSDocument 23 | 24 | // Handle closeAll: windows (cmd-opt-w) 25 | - (void)shouldCloseWindowController:(BSMultipleDocumentsWindowController *)windowController 26 | delegate:(id)delegate 27 | shouldCloseSelector:(SEL)shouldCloseSelector 28 | contextInfo:(void *)contextInfo 29 | { 30 | [windowController closeAllDocumentsWithDelegate:delegate 31 | didCloseAllSelector:shouldCloseSelector 32 | contextInfo:contextInfo]; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /BSMultipleDocumentsWindowController/BSDocumentController.h: -------------------------------------------------------------------------------- 1 | // 2 | // BSDocumentController.h 3 | // HoudahSpot 4 | // 5 | // Created by Pierre Bernard on 12/05/14. 6 | // Copyright (c) 2012 Sasmito Adibowo. Creative Commons Attribution-ShareAlike 3.0 Unported License. 7 | // Copyright (c) 2014-2015 Houdah Software s.à r.l. Creative Commons Attribution-ShareAlike 3.0 Unported License. 8 | // 9 | // Based upon http://cutecoder.org/programming/window-multiple-documents/ 10 | // 11 | 12 | @import Cocoa; 13 | 14 | 15 | @interface BSDocumentController : NSDocumentController 16 | 17 | - (IBAction)newDocumentTab:(id)sender; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /BSMultipleDocumentsWindowController/BSDocumentController.m: -------------------------------------------------------------------------------- 1 | // 2 | // BSDocumentController.m 3 | // HoudahSpot 4 | // 5 | // Created by Pierre Bernard on 12/05/14. 6 | // Copyright (c) 2012 Sasmito Adibowo. Creative Commons Attribution-ShareAlike 3.0 Unported License. 7 | // Copyright (c) 2014-2015 Houdah Software s.à r.l. Creative Commons Attribution-ShareAlike 3.0 Unported License. 8 | // 9 | // Based upon http://cutecoder.org/programming/window-multiple-documents/ 10 | // 11 | 12 | #import "BSDocumentController.h" 13 | 14 | #import "BSMultipleDocumentsWindowController.h" 15 | 16 | 17 | @interface BSDocumentController () 18 | 19 | @end 20 | 21 | 22 | @implementation BSDocumentController 23 | 24 | #pragma mark - 25 | #pragma mark Action methods 26 | 27 | - (IBAction)newDocumentTab:(id)sender 28 | { 29 | BSMultipleDocumentsWindowController *multipleDocumentsWindowController = nil;; 30 | NSWindowController *windowController = [[NSApp mainWindow] windowController]; 31 | 32 | if ([windowController isKindOfClass:[BSMultipleDocumentsWindowController class]]) { 33 | multipleDocumentsWindowController = (id)windowController; 34 | } 35 | 36 | BOOL makeWindow = (multipleDocumentsWindowController == nil); 37 | 38 | NSError *error = nil; 39 | NSDocument *document = [self openUntitledDocumentAndDisplay:makeWindow error:&error]; 40 | 41 | if (document == nil) { 42 | if (error != nil) { 43 | [self presentError:error]; 44 | } 45 | 46 | return; 47 | } 48 | 49 | if ((! makeWindow) && ([document conformsToProtocol:@protocol(BSMultipleDocumentsDocument)])) { 50 | [multipleDocumentsWindowController addDocument:(NSDocument < BSMultipleDocumentsDocument > *)document]; 51 | } 52 | } 53 | 54 | #pragma mark - 55 | #pragma mark Instance methods 56 | 57 | - (void)closeAllDocumentsWithDelegate:(id)delegate 58 | didCloseAllSelector:(SEL)didCloseAllSelector 59 | contextInfo:(void *)contextInfo 60 | { 61 | NSArray *documents = [self documents]; 62 | 63 | if ([documents count] > 0) { 64 | NSDocument *lastDocument = [documents lastObject]; 65 | 66 | void (^didCloseCallback)(BOOL) = ^void (BOOL didClose) { 67 | if (didClose) { 68 | [self closeAllDocumentsWithDelegate:delegate didCloseAllSelector:didCloseAllSelector contextInfo:contextInfo]; 69 | } 70 | else { 71 | [BSDocumentController documentController:self 72 | didCloseAll:NO 73 | delegate:delegate 74 | didCloseAllSelector:didCloseAllSelector 75 | contextInfo:contextInfo]; 76 | } 77 | }; 78 | 79 | [lastDocument canCloseDocumentWithDelegate:self 80 | shouldCloseSelector:@selector(document:shouldClose:contextInfo:) 81 | contextInfo:(void *)CFBridgingRetain([didCloseCallback copy])]; 82 | } 83 | else { 84 | [BSDocumentController documentController:self 85 | didCloseAll:YES 86 | delegate:delegate 87 | didCloseAllSelector:didCloseAllSelector 88 | contextInfo:contextInfo]; 89 | } 90 | } 91 | 92 | - (void)document:(NSDocument *)document 93 | shouldClose:(BOOL)shouldClose 94 | contextInfo:(void *)contextInfo 95 | { 96 | if (shouldClose) { 97 | // work on a copy of the window controllers array so that the doc can mutate its own array. 98 | NSArray *windowControllers = [document.windowControllers copy]; 99 | 100 | for (BSMultipleDocumentsWindowController *windowController in windowControllers) { 101 | if ([windowController isKindOfClass:[BSMultipleDocumentsWindowController class]]) { 102 | [windowController removeDocument : document]; 103 | } 104 | } 105 | 106 | [document close]; 107 | } 108 | 109 | void (^didClose)(BOOL) = CFBridgingRelease(contextInfo); 110 | 111 | didClose(shouldClose); 112 | } 113 | 114 | #pragma mark - 115 | #pragma mark Class methods 116 | 117 | + (void)documentController:(BSDocumentController *)documentController 118 | didCloseAll:(BOOL)didCloseAll 119 | delegate:(id)delegate 120 | didCloseAllSelector:(SEL)didCloseAllSelector 121 | contextInfo:(void *)contextInfo 122 | { 123 | if ((delegate != nil) && (didCloseAllSelector != NULL)) { 124 | typedef void (*MethodType)(id, SEL, BSDocumentController *, BOOL, void *); 125 | 126 | MethodType methodToCall = (MethodType)[delegate methodForSelector : didCloseAllSelector]; 127 | 128 | methodToCall(delegate, didCloseAllSelector, documentController, didCloseAll, contextInfo); 129 | } 130 | } 131 | 132 | @end 133 | -------------------------------------------------------------------------------- /BSMultipleDocumentsWindowController/BSMultipleDocumentsWindow.h: -------------------------------------------------------------------------------- 1 | // 2 | // BSMultipleDocumentsWindow.h 3 | // HoudahSpot 4 | // 5 | // Created by Pierre Bernard on 04/08/14. 6 | // Copyright (c) 2012 Sasmito Adibowo. Creative Commons Attribution-ShareAlike 3.0 Unported License. 7 | // Copyright (c) 2014-2015 Houdah Software s.à r.l. Creative Commons Attribution-ShareAlike 3.0 Unported License. 8 | // 9 | // Based upon http://cutecoder.org/programming/window-multiple-documents/ 10 | // 11 | 12 | @import Cocoa; 13 | 14 | 15 | @interface BSMultipleDocumentsWindow : NSWindow 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /BSMultipleDocumentsWindowController/BSMultipleDocumentsWindow.m: -------------------------------------------------------------------------------- 1 | // 2 | // BSMultipleDocumentsWindow.m 3 | // HoudahSpot 4 | // 5 | // Created by Pierre Bernard on 04/08/14. 6 | // Copyright (c) 2012 Sasmito Adibowo. Creative Commons Attribution-ShareAlike 3.0 Unported License. 7 | // Copyright (c) 2014-2015 Houdah Software s.à r.l. Creative Commons Attribution-ShareAlike 3.0 Unported License. 8 | // 9 | // Based upon http://cutecoder.org/programming/window-multiple-documents/ 10 | // 11 | 12 | #import "BSMultipleDocumentsWindow.h" 13 | 14 | #import "BSMultipleDocumentsWindowController.h" 15 | 16 | 17 | @implementation BSMultipleDocumentsWindow 18 | 19 | - (IBAction)performClose:(id)sender 20 | { 21 | [NSApp sendAction:@selector(closeTab:) to:[self windowController] from:self]; 22 | } 23 | 24 | - (IBAction)performCloseWindow:(id)sender 25 | { 26 | [NSApp sendAction:@selector(closeAllTabs:) to:[self windowController] from:self]; 27 | } 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /BSMultipleDocumentsWindowController/BSMultipleDocumentsWindowController.h: -------------------------------------------------------------------------------- 1 | // 2 | // BSMultipleDocumentsWindowController.h 3 | // HoudahSpot 4 | // 5 | // Created by Pierre Bernard on 12/05/14. 6 | // Copyright (c) 2012 Sasmito Adibowo. Creative Commons Attribution-ShareAlike 3.0 Unported License. 7 | // Copyright (c) 2014-2015 Houdah Software s.à r.l. Creative Commons Attribution-ShareAlike 3.0 Unported License. 8 | // 9 | // Based upon http://cutecoder.org/programming/window-multiple-documents/ 10 | // 11 | 12 | @import Cocoa; 13 | 14 | 15 | extern NSString *const BSDocumentNeedsWindowNotificationName; 16 | 17 | extern NSString *const BSMultipleDocumentsSelectedDocumentChangedNotificationName; 18 | extern NSString *const BSMultipleDocumentsWindowControllerWillCloseNotificationName; 19 | 20 | 21 | extern const struct BSMultipleDocumentsWindowControllerAttributes { 22 | __unsafe_unretained NSString *documentViewControllers; 23 | __unsafe_unretained NSString *selectedDocumentViewController; 24 | } BSMultipleDocumentsWindowControllerAttributes; 25 | 26 | 27 | @protocol BSMultipleDocumentsDocument; 28 | @protocol BSDocumentViewController; 29 | 30 | 31 | @interface BSMultipleDocumentsWindowController : NSWindowController 32 | 33 | @property (nonatomic, copy, readonly) NSArray *documentViewControllers; 34 | @property (nonatomic, strong, readonly) NSViewController *selectedDocumentViewController; 35 | 36 | - (void)addDocument:(NSDocument *)document; 37 | - (void)removeDocument:(NSDocument *)document; 38 | 39 | - (void)selectDocumentAtIndex:(NSInteger)index; 40 | - (void)closeDocumentAtIndex:(NSUInteger)index; 41 | 42 | - (void)synchronizeTitleWithDocumentViewController:(NSViewController *)documentViewController; 43 | 44 | - (IBAction)closeTab:(id)sender; 45 | - (IBAction)closeAllTabs:(id)sender; 46 | 47 | - (IBAction)selectNextTab:(id)sender; 48 | - (IBAction)selectPreviousTab:(id)sender; 49 | 50 | // API used for rearranging tabs. Documents are not closed in the process 51 | - (void)moveDocumentAtIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex; 52 | - (void)removeDocumentAtIndex:(NSUInteger)index; 53 | 54 | - (void)insertDocument:(NSDocument *)document 55 | viewController:(NSViewController *)documentViewController 56 | atIndex:(NSUInteger)index; 57 | 58 | - (void)closeAllDocumentsWithDelegate:(id)delegate 59 | didCloseAllSelector:(SEL)didCloseAllSelector 60 | contextInfo:(void *)contextInfo; 61 | 62 | @end 63 | 64 | 65 | @protocol BSDocumentViewController 66 | 67 | @property (nonatomic, weak) NSDocument *document; 68 | @property (nonatomic, weak) BSMultipleDocumentsWindowController *multipleDocumentsWindowController; 69 | 70 | - (NSString *)titleForDocumentDisplayName:(NSString *)displayName; 71 | 72 | @end 73 | 74 | 75 | @protocol BSMultipleDocumentsDocument 76 | 77 | - (NSViewController *)makeViewController; 78 | 79 | @end 80 | -------------------------------------------------------------------------------- /BSMultipleDocumentsWindowController/BSMultipleDocumentsWindowController.m: -------------------------------------------------------------------------------- 1 | // 2 | // BSMultipleDocumentsWindowController.m 3 | // HoudahSpot 4 | // 5 | // Created by Pierre Bernard on 12/05/14. 6 | // Copyright (c) 2012 Sasmito Adibowo. Creative Commons Attribution-ShareAlike 3.0 Unported License. 7 | // Copyright (c) 2014-2015 Houdah Software s.à r.l. Creative Commons Attribution-ShareAlike 3.0 Unported License. 8 | // 9 | // Based upon http://cutecoder.org/programming/window-multiple-documents/ 10 | // 11 | 12 | #import "BSMultipleDocumentsWindowController.h" 13 | 14 | 15 | @interface BSMultipleDocumentsWindowController () 16 | 17 | @property (nonatomic, strong, readonly) NSMutableSet *documents; 18 | 19 | @property (nonatomic, copy) NSArray *documentViewControllers; 20 | @property (nonatomic, strong) NSViewController *selectedDocumentViewController; 21 | 22 | @end 23 | 24 | 25 | NSString *const BSDocumentNeedsWindowNotificationName = @"BSDocumentNeedsWindowNotification"; 26 | 27 | NSString *const BSMultipleDocumentsSelectedDocumentChangedNotificationName = @"BSMultipleDocumentsSelectedDocumentChangedNotification"; 28 | NSString *const BSMultipleDocumentsWindowControllerWillCloseNotificationName = @"BSMultipleDocumentsWindowControllerWillCloseNotification"; 29 | 30 | 31 | const struct BSMultipleDocumentsWindowControllerAttributes BSMultipleDocumentsWindowControllerAttributes = { 32 | .documentViewControllers = @"documentViewControllers", .selectedDocumentViewController = @"selectedDocumentViewController", 33 | }; 34 | 35 | 36 | @implementation BSMultipleDocumentsWindowController 37 | 38 | #pragma mark - 39 | #pragma mark Initialization 40 | 41 | - (id)initWithCoder:(NSCoder *)coder 42 | { 43 | self = [super initWithCoder:coder]; 44 | 45 | if (self) { 46 | _documents = [NSMutableSet set]; 47 | _documentViewControllers = [NSArray array]; 48 | _selectedDocumentViewController = nil; 49 | } 50 | 51 | return self; 52 | } 53 | 54 | - (id)initWithWindow:(NSWindow *)window 55 | { 56 | self = [super initWithWindow:window]; 57 | 58 | if (self) { 59 | _documents = [NSMutableSet set]; 60 | _documentViewControllers = [NSArray array]; 61 | _selectedDocumentViewController = nil; 62 | } 63 | 64 | return self; 65 | } 66 | 67 | - (void)windowDidLoad 68 | { 69 | [super windowDidLoad]; 70 | 71 | NSWindow *window = [self window]; 72 | NSButton *closeButton = [window standardWindowButton:NSWindowCloseButton]; 73 | 74 | [closeButton setTarget:self]; 75 | [closeButton setAction:@selector(closeAllTabs:)]; 76 | 77 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 78 | 79 | [notificationCenter addObserver:self 80 | selector:@selector(multipleDocumentsWindowWillCloseNotification:) 81 | name:NSWindowWillCloseNotification 82 | object:window]; 83 | } 84 | 85 | #pragma mark - 86 | #pragma mark Finalization 87 | 88 | - (void)dealloc 89 | { 90 | NSWindow *window = [self window]; 91 | NSButton *closeButton = [window standardWindowButton:NSWindowCloseButton]; 92 | 93 | [closeButton setTarget:nil]; 94 | } 95 | 96 | #pragma mark - 97 | #pragma mark Accessors 98 | 99 | - (void)setSelectedDocumentViewController:(NSViewController *)selectedDocumentViewController 100 | { 101 | [_selectedDocumentViewController.document removeWindowController:self]; 102 | 103 | _selectedDocumentViewController = selectedDocumentViewController; 104 | 105 | [selectedDocumentViewController.document addWindowController:self]; 106 | 107 | [self synchronizeTitleWithDocumentViewController:selectedDocumentViewController]; 108 | 109 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 110 | 111 | [notificationCenter postNotificationName:BSMultipleDocumentsSelectedDocumentChangedNotificationName object:self]; 112 | } 113 | 114 | #pragma mark - 115 | #pragma mark Instance methods 116 | 117 | - (void)addDocument:(NSDocument *)document 118 | { 119 | [self insertDocument:document viewController:nil atIndex:[self.documentViewControllers count]]; 120 | } 121 | 122 | - (void)removeDocument:(NSDocument *)document 123 | { 124 | NSArray *documentViewControllers = self.documentViewControllers; 125 | NSUInteger count = [documentViewControllers count]; 126 | 127 | for (NSUInteger index = 0; index < count; index++) { 128 | NSViewController *documentViewController = [documentViewControllers objectAtIndex:index]; 129 | 130 | if (documentViewController.document == document) { 131 | [self removeDocumentAtIndex:index]; 132 | 133 | documentViewController.document = nil; 134 | } 135 | } 136 | } 137 | 138 | - (void)insertDocument:(NSDocument *)document 139 | viewController:(NSViewController *)documentViewController 140 | atIndex:(NSUInteger)index; 141 | { 142 | NSMutableSet *documents = self.documents; 143 | 144 | if ([documents containsObject:document]) { 145 | return; 146 | } 147 | 148 | if (documentViewController == nil) { 149 | documentViewController = [document makeViewController]; 150 | 151 | NSAssert(documentViewController != nil, @"Must return a fresh view controller from -[NSDocument makeViewController]"); 152 | } 153 | 154 | documentViewController.document = document; 155 | documentViewController.multipleDocumentsWindowController = self; 156 | 157 | NSWindow *window = [self window]; 158 | 159 | [document setWindow:window]; 160 | 161 | [documents addObject:document]; 162 | 163 | NSMutableArray *documentViewControllers = [self.documentViewControllers mutableCopy]; 164 | 165 | [documentViewControllers insertObject:documentViewController atIndex:index]; 166 | 167 | self.documentViewControllers = documentViewControllers; 168 | self.selectedDocumentViewController = documentViewController; 169 | } 170 | 171 | - (void)selectDocumentAtIndex:(NSInteger)index 172 | { 173 | NSArray *documentViewControllers = self.documentViewControllers; 174 | 175 | if ((index > -1) && (index < [documentViewControllers count])) { 176 | NSViewController *documentViewController = [documentViewControllers objectAtIndex:index]; 177 | 178 | self.selectedDocumentViewController = documentViewController; 179 | } 180 | else { 181 | self.selectedDocumentViewController = nil; 182 | } 183 | } 184 | 185 | - (void)closeDocumentAtIndex:(NSUInteger)index 186 | { 187 | NSArray *documentViewControllers = self.documentViewControllers; 188 | NSViewController *documentViewController = [documentViewControllers objectAtIndex:index]; 189 | NSDocument *document = documentViewController.document; 190 | 191 | [document canCloseDocumentWithDelegate:self shouldCloseSelector:@selector(document:shouldClose:contextInfo:) contextInfo:NULL]; 192 | } 193 | 194 | - (void)removeDocumentAtIndex:(NSUInteger)index 195 | { 196 | NSMutableArray *documentViewControllers = [self.documentViewControllers mutableCopy]; 197 | NSViewController *documentViewController = [documentViewControllers objectAtIndex:index]; 198 | NSDocument *document = documentViewController.document; 199 | 200 | [document removeWindowController:self]; 201 | 202 | NSMutableSet *documents = self.documents; 203 | 204 | [documents removeObject:document]; 205 | 206 | [documentViewControllers removeObjectAtIndex:index]; 207 | 208 | self.documentViewControllers = documentViewControllers; 209 | 210 | documentViewController.multipleDocumentsWindowController = nil; 211 | 212 | if ([documentViewControllers count] == 0) { 213 | [super close]; 214 | } 215 | else { 216 | NSInteger previousIndex = MAX(0, (NSInteger)index - 1); 217 | NSViewController *previousDocumentViewController = [documentViewControllers objectAtIndex:previousIndex]; 218 | 219 | [self setSelectedDocumentViewController:previousDocumentViewController]; 220 | } 221 | } 222 | 223 | - (void)moveDocumentAtIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex 224 | { 225 | NSMutableArray *documentViewControllers = [self.documentViewControllers mutableCopy]; 226 | NSViewController *documentViewController = [documentViewControllers objectAtIndex:fromIndex]; 227 | 228 | [documentViewControllers removeObjectAtIndex:fromIndex]; 229 | [documentViewControllers insertObject:documentViewController atIndex:toIndex]; 230 | 231 | self.documentViewControllers = documentViewControllers; 232 | } 233 | 234 | - (void)synchronizeTitleWithDocumentViewController:(NSViewController *)documentViewController 235 | { 236 | NSDocument *document = documentViewController.document; 237 | 238 | if (document == nil) { 239 | return; 240 | } 241 | 242 | NSString *displayName = [document displayName]; 243 | NSString *title = [documentViewController titleForDocumentDisplayName:displayName]; 244 | 245 | documentViewController.title = title; 246 | 247 | if (documentViewController == self.selectedDocumentViewController) { 248 | [self synchronizeWindowTitleWithDocumentName]; 249 | } 250 | } 251 | 252 | - (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName 253 | { 254 | NSViewController *selectedDocumentViewController = self.selectedDocumentViewController; 255 | NSString *title = [selectedDocumentViewController titleForDocumentDisplayName:displayName]; 256 | 257 | return title; 258 | } 259 | 260 | - (void)close 261 | { 262 | // Called by -[NSDocument close] 263 | NSDocument *document = self.selectedDocumentViewController.document; 264 | 265 | [self removeDocument:document]; 266 | } 267 | 268 | - (void)multipleDocumentsWindowWillCloseNotification:(NSNotification *)notification 269 | { 270 | NSWindow *window = self.window; 271 | 272 | if (notification.object != window) { 273 | return; 274 | } 275 | 276 | [window endEditingFor:nil]; 277 | 278 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 279 | 280 | [notificationCenter removeObserver:self name:NSWindowWillCloseNotification object:window]; 281 | 282 | for (NSViewController *documentViewController in self.documentViewControllers) { 283 | NSDocument *document = documentViewController.document; 284 | 285 | documentViewController.document = nil; 286 | documentViewController.multipleDocumentsWindowController = nil; 287 | 288 | [document removeWindowController:self]; 289 | [document close]; 290 | } 291 | 292 | self.documentViewControllers = [NSArray array]; 293 | 294 | [self.documents removeAllObjects]; 295 | 296 | [notificationCenter postNotificationName:BSMultipleDocumentsWindowControllerWillCloseNotificationName object:self]; 297 | } 298 | 299 | - (id)supplementalTargetForAction:(SEL)action sender:(id)sender 300 | { 301 | id target = [super supplementalTargetForAction:action sender:sender]; 302 | 303 | if (target != nil) { 304 | return target; 305 | } 306 | 307 | NSViewController *selectedDocumentViewController = self.selectedDocumentViewController; 308 | 309 | if (selectedDocumentViewController != nil) { 310 | target = [NSApp targetForAction:action to:selectedDocumentViewController from:sender]; 311 | 312 | if (![target respondsToSelector:action]) { 313 | target = [target supplementalTargetForAction:action sender:sender]; 314 | } 315 | 316 | if ([target respondsToSelector:action]) { 317 | return target; 318 | } 319 | } 320 | 321 | return nil; 322 | } 323 | 324 | #pragma mark - 325 | #pragma mark Action methods 326 | 327 | - (IBAction)closeTab:(id)sender 328 | { 329 | NSDocument *document = self.selectedDocumentViewController.document; 330 | 331 | [document canCloseDocumentWithDelegate:self shouldCloseSelector:@selector(document:shouldClose:contextInfo:) contextInfo:NULL]; 332 | } 333 | 334 | - (IBAction)closeAllTabs:(id)sender 335 | { 336 | SEL didCloseAllSelector = @selector(windowController:didCloseAll:contextInfo:); 337 | 338 | [self closeAllDocumentsWithDelegate:self didCloseAllSelector:didCloseAllSelector contextInfo:NULL]; 339 | } 340 | 341 | - (void)closeAllDocumentsWithDelegate:(id)delegate didCloseAllSelector:(SEL)didCloseAllSelector contextInfo:(void *)contextInfo 342 | { 343 | NSArray *documentViewControllers = self.documentViewControllers; 344 | 345 | if ([documentViewControllers count] > 0) { 346 | NSViewController *documentViewController = [documentViewControllers lastObject]; 347 | NSDocument *document = documentViewController.document; 348 | 349 | void (^didCloseCallback)(BOOL) = ^void(BOOL didClose) { 350 | if (didClose) { 351 | [self closeAllDocumentsWithDelegate:delegate didCloseAllSelector:didCloseAllSelector contextInfo:contextInfo]; 352 | } 353 | else { 354 | [BSMultipleDocumentsWindowController windowController:self 355 | didCloseAll:NO 356 | delegate:delegate 357 | didCloseAllSelector:didCloseAllSelector 358 | contextInfo:contextInfo]; 359 | } 360 | }; 361 | 362 | [document canCloseDocumentWithDelegate:self 363 | shouldCloseSelector:@selector(document:shouldClose:contextInfo:) 364 | contextInfo:(void *)CFBridgingRetain([didCloseCallback copy])]; 365 | } 366 | else { 367 | [BSMultipleDocumentsWindowController windowController:self 368 | didCloseAll:YES 369 | delegate:delegate 370 | didCloseAllSelector:didCloseAllSelector 371 | contextInfo:contextInfo]; 372 | } 373 | } 374 | 375 | - (void)document:(NSDocument *)document shouldClose:(BOOL)shouldClose contextInfo:(void *)contextInfo 376 | { 377 | if (shouldClose) { 378 | [self removeDocument:document]; 379 | 380 | [document close]; 381 | } 382 | 383 | if (contextInfo != NULL) { 384 | void (^didClose)(BOOL) = CFBridgingRelease(contextInfo); 385 | 386 | didClose(shouldClose); 387 | } 388 | } 389 | 390 | - (void)windowController:(BSMultipleDocumentsWindowController *)windowController didCloseAll:(BOOL)didCloseAll contextInfo:(void *)contextInfo 391 | { 392 | if (didCloseAll) { 393 | // [self close]; 394 | } 395 | } 396 | 397 | - (IBAction)selectNextTab:(id)sender 398 | { 399 | NSArray *documentViewControllers = self.documentViewControllers; 400 | NSUInteger documentCount = [documentViewControllers count]; 401 | NSViewController *selectedDocumentViewController = self.selectedDocumentViewController; 402 | NSUInteger selectedDocumentIndex = [documentViewControllers indexOfObject:selectedDocumentViewController]; 403 | 404 | if (selectedDocumentIndex == NSNotFound) { 405 | selectedDocumentIndex = 0; 406 | } 407 | 408 | selectedDocumentIndex = (selectedDocumentIndex + 1) % documentCount; 409 | 410 | [self selectDocumentAtIndex:selectedDocumentIndex]; 411 | } 412 | 413 | - (IBAction)selectPreviousTab:(id)sender; 414 | { 415 | NSArray *documentViewControllers = self.documentViewControllers; 416 | NSUInteger documentCount = [documentViewControllers count]; 417 | NSViewController *selectedDocumentViewController = self.selectedDocumentViewController; 418 | NSUInteger selectedDocumentIndex = [documentViewControllers indexOfObject:selectedDocumentViewController]; 419 | 420 | if (selectedDocumentIndex == NSNotFound) { 421 | selectedDocumentIndex = 0; 422 | } 423 | 424 | selectedDocumentIndex = (selectedDocumentIndex + documentCount - 1) % documentCount; 425 | 426 | [self selectDocumentAtIndex:selectedDocumentIndex]; 427 | } 428 | 429 | - (BOOL)validateMenuItem:(NSMenuItem *)menuItem 430 | { 431 | SEL action = menuItem.action; 432 | 433 | if (action == @selector(selectNextTab:) || 434 | action == @selector(selectPreviousTab:)) { 435 | NSArray *documentViewControllers = self.documentViewControllers; 436 | NSUInteger documentCount = [documentViewControllers count]; 437 | 438 | return (documentCount > 1); 439 | } 440 | 441 | return YES; 442 | } 443 | 444 | #pragma mark - 445 | #pragma mark Class methods 446 | 447 | + (void)windowController:(BSMultipleDocumentsWindowController *)windowController 448 | didCloseAll:(BOOL)didCloseAll 449 | delegate:(id)delegate 450 | didCloseAllSelector:(SEL)didCloseAllSelector 451 | contextInfo:(void *)contextInfo 452 | { 453 | if ((delegate != nil) && (didCloseAllSelector != NULL)) { 454 | typedef void (*MethodType)(id, SEL, BSMultipleDocumentsWindowController *, BOOL, void *); 455 | 456 | MethodType methodToCall = (MethodType)[delegate methodForSelector : didCloseAllSelector]; 457 | 458 | methodToCall(delegate, didCloseAllSelector, windowController, didCloseAll, contextInfo); 459 | } 460 | } 461 | 462 | @end 463 | -------------------------------------------------------------------------------- /BSMultipleDocumentsWindowController/BSPersistentDocument.h: -------------------------------------------------------------------------------- 1 | // 2 | // BSPersistentDocument.h 3 | // HoudahSpot 4 | // 5 | // Created by Pierre Bernard on 26/06/15. 6 | // Copyright (c) 2012 Sasmito Adibowo. Creative Commons Attribution-ShareAlike 3.0 Unported License. 7 | // Copyright (c) 2014-2015 Houdah Software s.à r.l. Creative Commons Attribution-ShareAlike 3.0 Unported License. 8 | // 9 | // Based upon http://cutecoder.org/programming/window-multiple-documents/ 10 | // 11 | 12 | @import Cocoa; 13 | 14 | 15 | @interface BSPersistentDocument : NSPersistentDocument 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /BSMultipleDocumentsWindowController/BSPersistentDocument.m: -------------------------------------------------------------------------------- 1 | // 2 | // BSPersistentDocument.m 3 | // HoudahSpot 4 | // 5 | // Created by Pierre Bernard on 26/06/15. 6 | // Copyright (c) 2012 Sasmito Adibowo. Creative Commons Attribution-ShareAlike 3.0 Unported License. 7 | // Copyright (c) 2014-2015 Houdah Software s.à r.l. Creative Commons Attribution-ShareAlike 3.0 Unported License. 8 | // 9 | // Based upon http://cutecoder.org/programming/window-multiple-documents/ 10 | // 11 | 12 | #import "BSPersistentDocument.h" 13 | 14 | #import "BSMultipleDocumentsWindowController.h" 15 | 16 | 17 | @interface BSPersistentDocument () 18 | 19 | @end 20 | 21 | 22 | @implementation BSPersistentDocument 23 | 24 | // Handle closeAll: windows (cmd-opt-w) 25 | - (void)shouldCloseWindowController:(BSMultipleDocumentsWindowController *)windowController 26 | delegate:(id)delegate 27 | shouldCloseSelector:(SEL)shouldCloseSelector 28 | contextInfo:(void *)contextInfo 29 | { 30 | [windowController closeAllDocumentsWithDelegate:delegate 31 | didCloseAllSelector:shouldCloseSelector 32 | contextInfo:contextInfo]; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /README.mdown: -------------------------------------------------------------------------------- 1 | ## BSMultipleDocumentsWindowController 2 | 3 | When you look into AppKit’s document architecture, you’ll see that although a document may be represented with more than one windows, the inverse is not true. There is only a setDocument: method in NSWindowController which implies that a window can only handle one document. 4 | 5 | BSMultipleDocumentsWindowController extends the document architecture to allow for one window to represent multiple documents. This allows for tabbed window interface. A window can now hold one or more tabs. Each showing a document. Closing a document removes the tab. Closing the window closes all documents. 6 | 7 | This code was developped for [HoudahSpot 4.0](https://www.houdah.com/houdahSpot/). HoudahSpot is a file search tool that is built upon Spotlight. It uses the Core Data document architecture to manage multiple windows and persist searches. HoudahSpot 4.0 added tabbed windows. 8 | 9 | In HoudahSpot the BSMultipleDocumentsWindowController is paired with a [MMTabBarView](https://github.com/ajin/MMTabBarView.git). This implements a tab bar that closely matches the ones seen in Finder, Safari, or Xcode. 10 | 11 | The seed for this project comes from a blog post by Sasmito Adibowo: [One NSWindow handling multiple NSDocument instances](http://cutecoder.org/programming/window-multiple-documents/). 12 | 13 | 14 | ![Screenshot of sample application](./Screenshot.jpg) 15 | 16 | 17 | 18 | ## Overview 19 | 20 | - Document subclasses override makeWindowControllers to post a notification rather than create a window for the document 21 | - Document subclasses implement makeViewController to provide a view rather than a window 22 | - A notification handler takes care of creating the window to host document views 23 | - BSMultipleDocumentsWindowController manages the list of documents and document view controllers 24 | - BSMultipleDocumentsWindowController tracks the selected document 25 | - NSWindowController is attached to the selected document and shows title, dirty state, etc. 26 | - BSMultipleDocumentsWindow makes sure that the Close menu item closes a single tab and that the Close button closes all tabs 27 | - BSMultipleDocumentsWindowController checks documents for changes before closing tabs 28 | 29 | 30 | ## Installation 31 | 32 | Follow the lead of the sample application. 33 | 34 | 1. Copy the BS*.h and BS*.m files to your project 35 | 2. Make your document class a subclass of either BSDocument or BSPersistentDocument 36 | 3. Create a view controller conforming to the BSDocumentViewController protocol 37 | 4. Make your document class conform to the BSMultipleDocumentsDocument protocol 38 | 5. Make your window controller a subclass of BSMultipleDocumentsWindowController 39 | 6. Make your window an instance of BSMultipleDocumentsWindow 40 | 7. Override -[NSDocument makeWindowController] to post a BSDocumentNeedsWindowNotificationName notification 41 | 9. Instanatiate BSDocumentController in the application's main nib or in your application delegate's applicationWillFinishLaunching: method 42 | 9. Handle BSDocumentNeedsWindowNotificationName in your application delegate 43 | 10. Set up menu items for creating and closing windows and tabs 44 | 11. Provide UI to host the document view controllers. The sample application uses a NSTabView managed by a DocumentsContainerViewController 45 | 46 | 47 | ## License 48 | 49 | Copyright (c) 2012 Sasmito Adibowo. [Creative Commons Attribution-ShareAlike 3.0 Unported License](https://creativecommons.org/licenses/by-sa/3.0/us/). 50 | Copyright (c) 2014-2015 Houdah Software s.à r.l. [Creative Commons Attribution-ShareAlike 3.0 Unported License](https://creativecommons.org/licenses/by-sa/3.0/us/). 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /Sample Application/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // BSMultipleDocumentsWindowController 4 | // 5 | // Created by Pierre Bernard on 10/10/15. 6 | // Copyright (c) 2015 Houdah Software s.à r.l. All rights reserved. 7 | // 8 | 9 | @import Cocoa; 10 | 11 | 12 | @interface AppDelegate : NSObject 13 | 14 | 15 | @end 16 | 17 | -------------------------------------------------------------------------------- /Sample Application/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // BSMultipleDocumentsWindowController 4 | // 5 | // Created by Pierre Bernard on 10/10/15. 6 | // Copyright (c) 2015 Houdah Software s.à r.l. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | #import "BSDocumentController.h" 12 | #import "BSMultipleDocumentsWindowController.h" 13 | #import "MultipleDocumentsWindowController.h" 14 | 15 | 16 | @interface AppDelegate () 17 | 18 | @property (nonatomic, strong, readonly) NSMutableArray *documentsWindowControllers; 19 | 20 | @end 21 | 22 | 23 | @implementation AppDelegate 24 | 25 | - (instancetype)init 26 | { 27 | self = [super init]; 28 | 29 | if (self != nil) { 30 | _documentsWindowControllers = [NSMutableArray arrayWithCapacity:3]; 31 | } 32 | 33 | return self; 34 | } 35 | 36 | - (void)dealloc 37 | { 38 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 39 | 40 | [notificationCenter removeObserver:self]; 41 | } 42 | 43 | - (void)applicationWillFinishLaunching:(NSNotification *)notification 44 | { 45 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 46 | 47 | [notificationCenter addObserver:self 48 | selector:@selector(documentNeedsWindowNotification:) 49 | name:BSDocumentNeedsWindowNotificationName 50 | object:nil]; 51 | 52 | [notificationCenter addObserver:self 53 | selector:@selector(documentsWindowControllerWillClose:) 54 | name:BSMultipleDocumentsWindowControllerWillCloseNotificationName 55 | object:nil]; 56 | } 57 | 58 | - (void)applicationDidFinishLaunching:(NSNotification *)notification 59 | { 60 | [self openUntitledDocumentIfNeeded]; 61 | } 62 | 63 | - (MultipleDocumentsWindowController *)newDocumentsWindowController 64 | { 65 | MultipleDocumentsWindowController *documentsWindowController = [[MultipleDocumentsWindowController alloc] init]; 66 | NSMutableArray *documentsWindowControllers = self.documentsWindowControllers; 67 | 68 | [documentsWindowControllers addObject:documentsWindowController]; 69 | 70 | return documentsWindowController; 71 | } 72 | 73 | - (void)documentNeedsWindowNotification:(NSNotification *)notification 74 | { 75 | NSDocument *document = notification.object; 76 | MultipleDocumentsWindowController *documentsWindowController = [self newDocumentsWindowController]; 77 | NSWindow *documentsWindow = documentsWindowController.window; 78 | 79 | [documentsWindowController addDocument:document]; 80 | [documentsWindow makeKeyAndOrderFront:self]; 81 | } 82 | 83 | - (void)openUntitledDocumentIfNeeded 84 | { 85 | BSDocumentController *documentController = [BSDocumentController sharedDocumentController]; 86 | 87 | if ([[documentController documents] count] == 0) { 88 | NSError *error = nil; 89 | NSDocument *document = (id)[documentController openUntitledDocumentAndDisplay:YES error:&error]; 90 | 91 | if ((document == nil) && (error != nil)) { 92 | [NSApp presentError:error]; 93 | } 94 | } 95 | } 96 | 97 | - (void)documentsWindowControllerWillClose:(NSNotification *)notification 98 | { 99 | MultipleDocumentsWindowController *documentsWindowController = notification.object; 100 | 101 | if (documentsWindowController == nil) { 102 | return; 103 | } 104 | 105 | NSMutableArray *documentsWindowControllers = self.documentsWindowControllers; 106 | 107 | [documentsWindowControllers removeObject:documentsWindowController]; 108 | } 109 | 110 | @end 111 | -------------------------------------------------------------------------------- /Sample Application/Base.lproj/MainMenu.xib: -------------------------------------------------------------------------------- 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 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | Default 499 | 500 | 501 | 502 | 503 | 504 | 505 | Left to Right 506 | 507 | 508 | 509 | 510 | 511 | 512 | Right to Left 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | Default 524 | 525 | 526 | 527 | 528 | 529 | 530 | Left to Right 531 | 532 | 533 | 534 | 535 | 536 | 537 | Right to Left 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | -------------------------------------------------------------------------------- /Sample Application/Document.h: -------------------------------------------------------------------------------- 1 | // 2 | // Document.h 3 | // BSMultipleDocumentsWindowController 4 | // 5 | // Created by Pierre Bernard on 10/10/15. 6 | // Copyright (c) 2015 Houdah Software s.à r.l. All rights reserved. 7 | // 8 | 9 | #import "BSDocument.h" 10 | #import "BSMultipleDocumentsWindowController.h" 11 | 12 | 13 | @interface Document : BSDocument 14 | 15 | @property (nonatomic, copy) NSString *documentBody; 16 | 17 | - (NSViewController *)makeViewController; 18 | 19 | @end 20 | 21 | -------------------------------------------------------------------------------- /Sample Application/Document.m: -------------------------------------------------------------------------------- 1 | // 2 | // Document.m 3 | // BSMultipleDocumentsWindowController 4 | // 5 | // Created by Pierre Bernard on 10/10/15. 6 | // Copyright (c) 2015 Houdah Software s.à r.l. All rights reserved. 7 | // 8 | 9 | #import "Document.h" 10 | #import "DocumentViewController.h" 11 | 12 | 13 | @interface Document () 14 | 15 | @property (nonatomic, strong) DocumentViewController *documentViewController; 16 | 17 | @end 18 | 19 | 20 | @implementation Document 21 | 22 | - (instancetype)init 23 | { 24 | self = [super init]; 25 | 26 | if (self) { 27 | self.documentBody = [NSString stringWithFormat:@"Created at %@", [NSDate date]]; 28 | } 29 | 30 | return self; 31 | } 32 | 33 | - (void)setDisplayName:(NSString *)displayNameOrNil 34 | { 35 | [super setDisplayName:displayNameOrNil]; 36 | 37 | DocumentViewController *documentViewController = self.documentViewController; 38 | 39 | [documentViewController.multipleDocumentsWindowController synchronizeTitleWithDocumentViewController:documentViewController]; 40 | } 41 | 42 | - (void)makeWindowControllers 43 | { 44 | [[NSNotificationCenter defaultCenter] postNotificationName:BSDocumentNeedsWindowNotificationName object:self]; 45 | } 46 | 47 | - (NSViewController *)makeViewController 48 | { 49 | DocumentViewController *documentViewController = [[DocumentViewController alloc] init]; 50 | 51 | documentViewController.document = self; 52 | 53 | self.documentViewController = documentViewController; 54 | 55 | return documentViewController; 56 | } 57 | 58 | - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError 59 | { 60 | return [[NSData alloc] init]; 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /Sample Application/DocumentViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // DocumentViewController.h 3 | // BSMultipleDocumentsWindowController 4 | // 5 | // Created by Pierre Bernard on 10/10/15. 6 | // Copyright (c) 2015 Houdah Software s.à r.l. All rights reserved. 7 | // 8 | 9 | #import "BSMultipleDocumentsWindowController.h" 10 | 11 | 12 | @interface DocumentViewController : NSViewController 13 | 14 | @property (nonatomic, weak) NSDocument *document; 15 | @property (nonatomic, weak) BSMultipleDocumentsWindowController *multipleDocumentsWindowController; 16 | 17 | - (NSString *)titleForDocumentDisplayName:(NSString *)displayName; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Sample Application/DocumentViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // DocumentViewController.m 3 | // BSMultipleDocumentsWindowController 4 | // 5 | // Created by Pierre Bernard on 10/10/15. 6 | // Copyright (c) 2015 Houdah Software s.à r.l. All rights reserved. 7 | // 8 | 9 | #import "DocumentViewController.h" 10 | 11 | 12 | @interface DocumentViewController () 13 | 14 | 15 | @end 16 | 17 | 18 | @implementation DocumentViewController 19 | 20 | - (instancetype)init 21 | { 22 | self = [super initWithNibName:[[self class] nibName] bundle:nil]; 23 | 24 | if (self != nil) {} 25 | 26 | return self; 27 | } 28 | 29 | - (void)viewDidLoad 30 | { 31 | [super viewDidLoad]; 32 | } 33 | 34 | - (NSString *)titleForDocumentDisplayName:(NSString *)displayName 35 | { 36 | return displayName; 37 | } 38 | 39 | + (NSString *)nibName 40 | { 41 | return NSStringFromClass([self class]); 42 | } 43 | 44 | - (IBAction)markDirty:(id)sender 45 | { 46 | [self.document updateChangeCount:NSChangeDone]; 47 | } 48 | 49 | - (IBAction)markClean:(id)sender 50 | { 51 | [self.document updateChangeCount:NSChangeCleared]; 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /Sample Application/DocumentViewController.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 28 | 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 | -------------------------------------------------------------------------------- /Sample Application/DocumentsContainerViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // DocumentsContainerViewController.h 3 | // BSMultipleDocumentsWindowController 4 | // 5 | // Created by Pierre Bernard on 10/10/15. 6 | // Copyright (c) 2015 Houdah Software s.à r.l. All rights reserved. 7 | // 8 | 9 | #import "MultipleDocumentsWindowController.h" 10 | 11 | 12 | @interface DocumentsContainerViewController : NSViewController 13 | 14 | - (instancetype)initWithDocumentsWindowController:(MultipleDocumentsWindowController *)documentsWindowController; 15 | 16 | @property (nonatomic, strong, readonly) MultipleDocumentsWindowController *documentsWindowController; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Sample Application/DocumentsContainerViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // DocumentsContainerViewController.m 3 | // BSMultipleDocumentsWindowController 4 | // 5 | // Created by Pierre Bernard on 10/10/15. 6 | // Copyright (c) 2015 Houdah Software s.à r.l. All rights reserved. 7 | // 8 | 9 | #import "DocumentsContainerViewController.h" 10 | 11 | 12 | @interface DocumentsContainerViewController () 13 | 14 | @property (nonatomic, weak) IBOutlet NSTabView *tabView; 15 | 16 | @property (nonatomic, assign) BOOL observingDocumentsWindowController; 17 | @property (nonatomic, strong) MultipleDocumentsWindowController *documentsWindowController; 18 | 19 | @end 20 | 21 | 22 | static void *kDocumentViewControllersContext = &kDocumentViewControllersContext; 23 | static void *kSelectedDocumentViewControllerContext = &kSelectedDocumentViewControllerContext; 24 | 25 | 26 | @implementation DocumentsContainerViewController 27 | 28 | - (instancetype)initWithDocumentsWindowController:(MultipleDocumentsWindowController *)documentsWindowController; 29 | { 30 | self = [super initWithNibName:[[self class] nibName] bundle:nil]; 31 | 32 | if (self != nil) { 33 | _documentsWindowController = documentsWindowController; 34 | 35 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 36 | 37 | [notificationCenter addObserver:self 38 | selector:@selector(documentsWindowWillClose:) 39 | name:NSWindowWillCloseNotification 40 | object:documentsWindowController.window]; 41 | } 42 | 43 | return self; 44 | } 45 | 46 | + (NSString *)nibName 47 | { 48 | return NSStringFromClass([self class]); 49 | } 50 | 51 | - (void)viewDidLoad 52 | { 53 | [super viewDidLoad]; 54 | 55 | [self startObservingDocumentsWindowController]; 56 | } 57 | 58 | #pragma mark - 59 | #pragma mark Finalization 60 | 61 | - (void)documentsWindowWillClose:(NSNotification *)notification 62 | { 63 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; 64 | 65 | [notificationCenter removeObserver:self name:NSWindowWillCloseNotification object:notification.object]; 66 | 67 | [self stopObservingDocumentsWindowController]; 68 | 69 | self.documentsWindowController = nil; 70 | self.tabView.delegate = nil; 71 | } 72 | 73 | - (void)dealloc 74 | { 75 | [self stopObservingDocumentsWindowController]; 76 | 77 | self.tabView.delegate = nil; 78 | } 79 | 80 | #pragma mark - 81 | #pragma mark Instance methods 82 | 83 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context 84 | { 85 | if (context == kDocumentViewControllersContext) { 86 | [self updateTabView]; 87 | } 88 | else if (context == kSelectedDocumentViewControllerContext) { 89 | [self updateSelectedTabIndex]; 90 | } 91 | } 92 | 93 | - (void)startObservingDocumentsWindowController 94 | { 95 | if (self.observingDocumentsWindowController) { 96 | return; 97 | } 98 | 99 | self.observingDocumentsWindowController = YES; 100 | 101 | MultipleDocumentsWindowController *documentsWindowController = self.documentsWindowController; 102 | 103 | [documentsWindowController addObserver:self 104 | forKeyPath:BSMultipleDocumentsWindowControllerAttributes.documentViewControllers 105 | options:NSKeyValueObservingOptionInitial 106 | context:kDocumentViewControllersContext]; 107 | [documentsWindowController addObserver:self 108 | forKeyPath:BSMultipleDocumentsWindowControllerAttributes.selectedDocumentViewController 109 | options:NSKeyValueObservingOptionInitial 110 | context:kSelectedDocumentViewControllerContext]; 111 | } 112 | 113 | - (void)stopObservingDocumentsWindowController 114 | { 115 | if (!self.observingDocumentsWindowController) { 116 | return; 117 | } 118 | 119 | self.observingDocumentsWindowController = NO; 120 | 121 | MultipleDocumentsWindowController *documentsWindowController = self.documentsWindowController; 122 | 123 | [documentsWindowController removeObserver:self 124 | forKeyPath:BSMultipleDocumentsWindowControllerAttributes.documentViewControllers 125 | context:kDocumentViewControllersContext]; 126 | [documentsWindowController removeObserver:self 127 | forKeyPath:BSMultipleDocumentsWindowControllerAttributes.selectedDocumentViewController 128 | context:kSelectedDocumentViewControllerContext]; 129 | } 130 | 131 | - (void)updateTabView 132 | { 133 | NSTabView *tabView = self.tabView; 134 | 135 | MultipleDocumentsWindowController *documentsWindowController = self.documentsWindowController; 136 | NSArray *documentViewControllers = documentsWindowController.documentViewControllers; 137 | NSInteger vCount = [documentViewControllers count]; 138 | 139 | NSInteger index = 0; 140 | 141 | for (NSInteger v = 0; v < vCount; v++) { 142 | NSViewController *documentViewController = [documentViewControllers objectAtIndex:v]; 143 | NSInteger tabViewItemIndex = NSNotFound; 144 | 145 | if (v < [tabView.tabViewItems count]) { 146 | NSTabViewItem *tentativeTabViewItem = [tabView tabViewItemAtIndex:v]; 147 | 148 | if (tentativeTabViewItem.viewController == documentViewController) { 149 | tabViewItemIndex = v; 150 | } 151 | } 152 | 153 | if (tabViewItemIndex == NSNotFound) { 154 | tabViewItemIndex = [tabView indexOfTabViewItemWithIdentifier:documentViewController]; 155 | } 156 | 157 | NSTabViewItem *tabViewItem = nil; 158 | 159 | if (tabViewItemIndex != NSNotFound) { 160 | tabViewItem = [tabView tabViewItemAtIndex:tabViewItemIndex]; 161 | } 162 | else { 163 | tabViewItem = [NSTabViewItem tabViewItemWithViewController:documentViewController]; 164 | tabViewItem.identifier = documentViewController; 165 | 166 | // [tabViewItem bind:@"label" toObject:documentViewController withKeyPath:@"title" options:nil]; 167 | 168 | [self addChildViewController:documentViewController]; 169 | } 170 | 171 | if (tabViewItemIndex != index) { 172 | if ((tabViewItemIndex != NSNotFound) && (tabViewItemIndex > index)) { 173 | [tabView removeTabViewItem:tabViewItem]; 174 | } 175 | 176 | [tabView insertTabViewItem:tabViewItem atIndex:index]; 177 | } 178 | 179 | NSString *title = documentViewController.title; 180 | 181 | if (title == nil) { 182 | title = documentViewController.document.displayName; 183 | } 184 | 185 | if (title != nil) { 186 | tabViewItem.label = title; 187 | } 188 | 189 | index++; 190 | } 191 | 192 | while ([tabView.tabViewItems count] > vCount) { 193 | NSTabViewItem *tabViewItem = [tabView tabViewItemAtIndex:vCount]; 194 | NSViewController *documentViewController = tabViewItem.viewController; 195 | 196 | [documentViewController removeFromParentViewController]; 197 | 198 | // [tabViewItem unbind:@"label"]; 199 | [tabView removeTabViewItem:tabViewItem]; 200 | } 201 | } 202 | 203 | - (void)updateSelectedTabIndex 204 | { 205 | MultipleDocumentsWindowController *documentsWindowController = self.documentsWindowController; 206 | NSArray *documentViewControllers = documentsWindowController.documentViewControllers; 207 | 208 | NSViewController *selectedDocumentViewController = documentsWindowController.selectedDocumentViewController; 209 | 210 | NSInteger index = [documentViewControllers indexOfObject:selectedDocumentViewController]; 211 | NSTabView *tabView = self.tabView; 212 | 213 | if (index != NSNotFound) { 214 | if (index < [tabView numberOfTabViewItems]) { 215 | [tabView selectTabViewItemAtIndex:index]; 216 | } 217 | else { 218 | NSLog(@"Error %@", tabView); 219 | } 220 | } 221 | } 222 | 223 | - (id)supplementalTargetForAction:(SEL)action sender:(id)sender 224 | { 225 | id target = [super supplementalTargetForAction:action sender:sender]; 226 | 227 | if (target != nil) { 228 | return target; 229 | } 230 | 231 | NSTabViewItem *selectedTabViewItem = self.tabView.selectedTabViewItem; 232 | NSViewController *childViewController = selectedTabViewItem.viewController; 233 | 234 | if (childViewController != nil) { 235 | target = [NSApp targetForAction:action to:childViewController from:sender]; 236 | 237 | if (![target respondsToSelector:action]) { 238 | target = [target supplementalTargetForAction:action sender:sender]; 239 | } 240 | 241 | if ([target respondsToSelector:action]) { 242 | return target; 243 | } 244 | } 245 | 246 | return nil; 247 | } 248 | 249 | - (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem 250 | { 251 | NSInteger index = [tabView indexOfTabViewItem:tabViewItem]; 252 | 253 | [self.documentsWindowController selectDocumentAtIndex:index]; 254 | } 255 | 256 | - (void)tabView:(NSTabView *)tabView didMoveTabViewItem:(NSTabViewItem *)tabViewItem toIndex:(NSUInteger)toIndex 257 | { 258 | MultipleDocumentsWindowController *documentsWindowController = self.documentsWindowController; 259 | NSArray *documentViewControllers = documentsWindowController.documentViewControllers; 260 | 261 | NSViewController *documentViewController = (id)tabViewItem.viewController; 262 | NSUInteger fromIndex = [documentViewControllers indexOfObject:documentViewController]; 263 | 264 | if (fromIndex != NSNotFound) { 265 | [documentsWindowController moveDocumentAtIndex:fromIndex toIndex:toIndex]; 266 | } 267 | 268 | NSInteger index = [tabView indexOfTabViewItem:tabViewItem]; 269 | 270 | [self.documentsWindowController selectDocumentAtIndex:index]; 271 | } 272 | 273 | - (BOOL)tabView:(NSTabView *)tabView shouldCloseTabViewItem:(NSTabViewItem *)tabViewItem 274 | { 275 | NSInteger index = [tabView indexOfTabViewItem:tabViewItem]; 276 | 277 | if (index == NSNotFound) { 278 | NSLog(@"Cannot close document tab: %@", tabViewItem); 279 | 280 | return YES; 281 | } 282 | 283 | [self.documentsWindowController closeDocumentAtIndex:index]; 284 | 285 | return NO; 286 | } 287 | 288 | - (NSImage *)tabView:(NSTabView *)tabView imageForTabViewItem:(NSTabViewItem *)tabViewItem offset:(NSSize *)offset styleMask:(NSUInteger *)styleMask 289 | { 290 | NSWindow *window = tabView.window; 291 | CGWindowID windowID = (CGWindowID)[window windowNumber]; 292 | CGWindowImageOption imageOptions = kCGWindowImageDefault; 293 | CGWindowListOption singleWindowListOptions = kCGWindowListOptionIncludingWindow; 294 | CGRect imageBounds = CGRectNull; 295 | 296 | CGImageRef windowImage = CGWindowListCreateImage(imageBounds, singleWindowListOptions, windowID, imageOptions); 297 | 298 | if (windowImage != NULL) { 299 | NSImage *image = [[NSImage alloc] initWithCGImage:windowImage size:[window frame].size]; 300 | 301 | [image setCacheMode:NSImageCacheNever]; 302 | 303 | CFRelease(windowImage); 304 | 305 | return image; 306 | } 307 | 308 | return nil; 309 | } 310 | 311 | @end 312 | -------------------------------------------------------------------------------- /Sample Application/DocumentsContainerViewController.xib: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /Sample Application/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "size" : "32x32", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "size" : "32x32", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "size" : "128x128", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "size" : "128x128", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "size" : "256x256", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "size" : "256x256", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "size" : "512x512", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "size" : "512x512", 51 | "scale" : "2x" 52 | } 53 | ], 54 | "info" : { 55 | "version" : 1, 56 | "author" : "xcode" 57 | } 58 | } -------------------------------------------------------------------------------- /Sample Application/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeExtensions 11 | 12 | bsdocument 13 | 14 | CFBundleTypeIconFile 15 | 16 | CFBundleTypeName 17 | DocumentType 18 | CFBundleTypeOSTypes 19 | 20 | ???? 21 | 22 | CFBundleTypeRole 23 | Editor 24 | NSDocumentClass 25 | Document 26 | 27 | 28 | CFBundleExecutable 29 | $(EXECUTABLE_NAME) 30 | CFBundleIconFile 31 | 32 | CFBundleIdentifier 33 | com.houdah.$(PRODUCT_NAME:rfc1034identifier) 34 | CFBundleInfoDictionaryVersion 35 | 6.0 36 | CFBundleName 37 | $(PRODUCT_NAME) 38 | CFBundlePackageType 39 | APPL 40 | CFBundleShortVersionString 41 | 1.0 42 | CFBundleSignature 43 | ???? 44 | CFBundleVersion 45 | 1 46 | LSMinimumSystemVersion 47 | $(MACOSX_DEPLOYMENT_TARGET) 48 | NSHumanReadableCopyright 49 | Copyright © 2014-2015 Houdah Software s.à r.l. All rights reserved. 50 | NSMainNibFile 51 | MainMenu 52 | NSPrincipalClass 53 | NSApplication 54 | 55 | 56 | -------------------------------------------------------------------------------- /Sample Application/MultipleDocumentsWindowController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MultipleDocumentsWindowController.h 3 | // BSMultipleDocumentsWindowController 4 | // 5 | // Created by Pierre Bernard on 10/10/15. 6 | // Copyright (c) 2015 Houdah Software s.à r.l. All rights reserved. 7 | // 8 | 9 | #import "BSMultipleDocumentsWindowController.h" 10 | 11 | 12 | @interface MultipleDocumentsWindowController : BSMultipleDocumentsWindowController 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Sample Application/MultipleDocumentsWindowController.m: -------------------------------------------------------------------------------- 1 | // 2 | // MultipleDocumentsWindowController.m 3 | // BSMultipleDocumentsWindowController 4 | // 5 | // Created by Pierre Bernard on 10/10/15. 6 | // Copyright (c) 2015 Houdah Software s.à r.l. All rights reserved. 7 | // 8 | 9 | #import "MultipleDocumentsWindowController.h" 10 | 11 | #import "DocumentsContainerViewController.h" 12 | 13 | 14 | @interface MultipleDocumentsWindowController () 15 | 16 | @property (nonatomic, weak) IBOutlet NSView *containerView; 17 | 18 | @property (nonatomic, strong) DocumentsContainerViewController *documentsContainerViewController; 19 | 20 | 21 | @end 22 | 23 | 24 | @implementation MultipleDocumentsWindowController 25 | 26 | - (instancetype)init 27 | { 28 | self = [super initWithWindowNibName:[[self class] nibName]]; 29 | 30 | if (self != nil) {} 31 | 32 | return self; 33 | } 34 | 35 | - (void)windowDidLoad 36 | { 37 | [super windowDidLoad]; 38 | 39 | DocumentsContainerViewController *documentsContainerViewController = 40 | [[DocumentsContainerViewController alloc] initWithDocumentsWindowController:self]; 41 | 42 | self.documentsContainerViewController = documentsContainerViewController; 43 | 44 | NSView *containerView = self.containerView; 45 | 46 | [documentsContainerViewController.view setFrame:[containerView bounds]]; 47 | [documentsContainerViewController.view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; 48 | 49 | [containerView addSubview:documentsContainerViewController.view]; 50 | 51 | } 52 | 53 | + (NSString *)nibName 54 | { 55 | return NSStringFromClass([self class]); 56 | } 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /Sample Application/MultipleDocumentsWindowController.xib: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /Sample Application/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // BSMultipleDocumentsWindowController 4 | // 5 | // Created by Pierre Bernard on 10/10/15. 6 | // Copyright (c) 2015 Houdah Software s.à r.l. All rights reserved. 7 | // 8 | 9 | @import Cocoa; 10 | 11 | int main(int argc, const char * argv[]) { 12 | return NSApplicationMain(argc, argv); 13 | } 14 | -------------------------------------------------------------------------------- /Screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gloubibou/BSMultipleDocumentsWindowController/ec01294458d17292bea4bdcb56d9fa0d916a6cc8/Screenshot.jpg --------------------------------------------------------------------------------