├── .gitignore ├── LICENSE.txt ├── Prefix.swift ├── README.md ├── README2.md ├── SourceView.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── dev.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── dev.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist └── SourceView ├── AppDelegate.h ├── AppDelegate.m ├── AppDelegate.swift ├── Base.lproj ├── Credits.rtf ├── InfoPlist.strings └── Main.storyboard ├── BaseNode.h ├── BaseNode.m ├── BaseNode.swift ├── ChildEditController.h ├── ChildEditController.m ├── ChildEditController.swift ├── ChildEditViewController.h ├── ChildEditViewController.m ├── ChildEditViewController.swift ├── ChildNode.h ├── ChildNode.m ├── ChildNode.swift ├── FileViewController.h ├── FileViewController.m ├── FileViewController.swift ├── IconViewBox.h ├── IconViewBox.m ├── IconViewBox.swift ├── IconViewController.h ├── IconViewController.m ├── IconViewController.swift ├── Info.plist ├── MyOutlineViewController.h ├── MyOutlineViewController.m ├── MyOutlineViewController.swift ├── MySplitViewController.h ├── MySplitViewController.m ├── MySplitViewController.swift ├── MyWindowController.h ├── MyWindowController.m ├── MyWindowController.swift ├── Outline.dict ├── Prefix.pch ├── PrimaryViewController.h ├── PrimaryViewController.m ├── PrimaryViewController.swift ├── SeparatorView.h ├── SeparatorView.m ├── SeparatorView.swift ├── SourceView.xcodeproj └── project.pbxproj ├── WebViewController.h ├── WebViewController.m ├── WebViewController.swift └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Sample code project: SourceView: Using NSOutlineView with NSTreeController 2 | Version: 9.0 3 | 4 | IMPORTANT: This Apple software is supplied to you by Apple 5 | Inc. ("Apple") in consideration of your agreement to the following 6 | terms, and your use, installation, modification or redistribution of 7 | this Apple software constitutes acceptance of these terms. If you do 8 | not agree with these terms, please do not use, install, modify or 9 | redistribute this Apple software. 10 | 11 | In consideration of your agreement to abide by the following terms, and 12 | subject to these terms, Apple grants you a personal, non-exclusive 13 | license, under Apple's copyrights in this original Apple software (the 14 | "Apple Software"), to use, reproduce, modify and redistribute the Apple 15 | Software, with or without modifications, in source and/or binary forms; 16 | provided that if you redistribute the Apple Software in its entirety and 17 | without modifications, you must retain this notice and the following 18 | text and disclaimers in all such redistributions of the Apple Software. 19 | Neither the name, trademarks, service marks or logos of Apple Inc. may 20 | be used to endorse or promote products derived from the Apple Software 21 | without specific prior written permission from Apple. Except as 22 | expressly stated in this notice, no other rights or licenses, express or 23 | implied, are granted by Apple herein, including but not limited to any 24 | patent rights that may be infringed by your derivative works or by other 25 | works in which the Apple Software may be incorporated. 26 | 27 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE 28 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION 29 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS 30 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND 31 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. 32 | 33 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL 34 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 35 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 36 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, 37 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED 38 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), 39 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE 40 | POSSIBILITY OF SUCH DAMAGE. 41 | 42 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 43 | -------------------------------------------------------------------------------- /Prefix.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix.swift 3 | // SourceView 4 | // 5 | // Created by 開発 on 2016/6/1. 6 | // 7 | // 8 | 9 | import Foundation 10 | 11 | let HTTP_PREFIX = "http://" -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SourceView 2 | 3 | ## Description 4 | 5 | "SourceView" demonstrates how to use NSOutlineView backed by NSTreeController and various other Cocoa classes to produce a Finder-like source view. It also uses NSSplitViewController and a storyboard to organize the various NSViewControllers. 6 | 7 | Among the features demonstrated are - 8 | 9 | - Source outline view using view-based NSOutlineView 10 | - Loading dictionary data from disk using [NSDictionary dictionaryWithContentsOfFile…] to populate the outline view, 11 | - Outline view uses selection highlight style: NSTableViewSelectionHighlightStyleSourceList, which gives is a gradient-style selection. 12 | - Icon view of directories using NSCollectionView, 13 | - Viewing URLs using WebView, 14 | - Outline view drag and drop support for URLs and file system-based objects (from Safari, Finder, etc), 15 | - Factoring or organizing its various NSViews into NSViewControllers. 16 | - Factoring or organizing its various Windows into NSWindowControllers. 17 | - Obtaining file system icons using NSWorkspace, 18 | - NSSplitView controlled by NSSplitViewController sub-pane size management during divider resize, 19 | - Using template images in our buttons such as NSImageNameAddTemplate and NSImageNameRemoveTemplate 20 | 21 | ## Build Requirements 22 | 23 | macOS 10.12 SDK or later 24 | 25 | ## Runtime Requirements 26 | 27 | OS X 10.10 or later 28 | 29 | ## Using the Sample 30 | 31 | The Bookmarks section is determined the external Outline.dict file, read in as a NSDictionary and populated into the NSOutlineView. 32 | You can experiment on your own with adding and removing items in this file. 33 | 34 | 35 | Copyright (C) 2007-2017, Apple Inc. All rights reserved. 36 | -------------------------------------------------------------------------------- /README2.md: -------------------------------------------------------------------------------- 1 | # SourceView 2 | 3 | Translated by OOPer in cooperation with shlab.jp, on 2016/6/2. 4 | 5 | Based on 6 | 7 | 2018-02-15. 8 | 9 | As this is a line-by-line translation from the original sample code, "redistribute the Apple Software in its entirety and without modifications" would apply. See LICENSE.txt . 10 | Some faults caused by my translation may exist. Not all features tested. 11 | You should not contact to Apple or SHLab(jp) about any faults caused by my translation. 12 | 13 | ## Requirements 14 | 15 | ### Build 16 | 17 | OS X 10.13 SDK, Xcode 9.2 18 | -------------------------------------------------------------------------------- /SourceView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 533E9CF01BB1F4B900B904E0 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 533E9CEC1BB1F4B900B904E0 /* Credits.rtf */; }; 11 | 533E9CF11BB1F4B900B904E0 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 533E9CEE1BB1F4B900B904E0 /* InfoPlist.strings */; }; 12 | 5368DCB619DC60AD003019C8 /* Outline.dict in Resources */ = {isa = PBXBuildFile; fileRef = 5368DCB419DC60AD003019C8 /* Outline.dict */; }; 13 | 537D3D971CB571D000CB2D64 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 537D3D961CB571D000CB2D64 /* WebKit.framework */; }; 14 | 53E207331BA0BEB000E45BA6 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 53E207311BA0BEB000E45BA6 /* Main.storyboard */; }; 15 | D787D5762042381F0097DC76 /* MyOutlineViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D787D5752042381F0097DC76 /* MyOutlineViewController.swift */; }; 16 | D787D57B204238B20097DC76 /* IconViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D787D577204238B00097DC76 /* IconViewController.swift */; }; 17 | D787D57C204238B20097DC76 /* WebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D787D578204238B10097DC76 /* WebViewController.swift */; }; 18 | D787D57D204238B20097DC76 /* FileViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D787D579204238B10097DC76 /* FileViewController.swift */; }; 19 | D787D57E204238B20097DC76 /* IconViewBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = D787D57A204238B10097DC76 /* IconViewBox.swift */; }; 20 | D787D583204239100097DC76 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D787D57F2042390F0097DC76 /* AppDelegate.swift */; }; 21 | D787D584204239100097DC76 /* PrimaryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D787D5802042390F0097DC76 /* PrimaryViewController.swift */; }; 22 | D787D585204239100097DC76 /* MyWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D787D581204239100097DC76 /* MyWindowController.swift */; }; 23 | D787D586204239100097DC76 /* MySplitViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D787D582204239100097DC76 /* MySplitViewController.swift */; }; 24 | D787D5892042393F0097DC76 /* ChildNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D787D5872042393F0097DC76 /* ChildNode.swift */; }; 25 | D787D58A2042393F0097DC76 /* BaseNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D787D5882042393F0097DC76 /* BaseNode.swift */; }; 26 | D787D58D204239660097DC76 /* SeparatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D787D58B204239640097DC76 /* SeparatorView.swift */; }; 27 | D787D58E204239660097DC76 /* ChildEditViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D787D58C204239650097DC76 /* ChildEditViewController.swift */; }; 28 | D787D59020423B3C0097DC76 /* Prefix.swift in Sources */ = {isa = PBXBuildFile; fileRef = D787D58F20423B3B0097DC76 /* Prefix.swift */; }; 29 | /* End PBXBuildFile section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | 533E9CEB1BB1F3E700B904E0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = SourceView/Base.lproj/Main.storyboard; sourceTree = ""; }; 33 | 533E9CED1BB1F4B900B904E0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = Base; path = SourceView/Base.lproj/Credits.rtf; sourceTree = ""; }; 34 | 533E9CEF1BB1F4B900B904E0 /* Base */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = Base; path = SourceView/Base.lproj/InfoPlist.strings; sourceTree = ""; }; 35 | 5368DC9319DC604D003019C8 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 36 | 5368DCB419DC60AD003019C8 /* Outline.dict */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Outline.dict; path = SourceView/Outline.dict; sourceTree = ""; }; 37 | 5368DCB919DC60B8003019C8 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = SourceView/Info.plist; sourceTree = ""; }; 38 | 537D3D961CB571D000CB2D64 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; 39 | 8D1107320486CEB800E47090 /* SourceView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SourceView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 40 | D787D571204237640097DC76 /* README2.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = README2.md; sourceTree = ""; }; 41 | D787D572204237650097DC76 /* LICENSE.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE.txt; sourceTree = ""; }; 42 | D787D5752042381F0097DC76 /* MyOutlineViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MyOutlineViewController.swift; path = SourceView/MyOutlineViewController.swift; sourceTree = ""; }; 43 | D787D577204238B00097DC76 /* IconViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = IconViewController.swift; path = SourceView/IconViewController.swift; sourceTree = ""; }; 44 | D787D578204238B10097DC76 /* WebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WebViewController.swift; path = SourceView/WebViewController.swift; sourceTree = ""; }; 45 | D787D579204238B10097DC76 /* FileViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = FileViewController.swift; path = SourceView/FileViewController.swift; sourceTree = ""; }; 46 | D787D57A204238B10097DC76 /* IconViewBox.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = IconViewBox.swift; path = SourceView/IconViewBox.swift; sourceTree = ""; }; 47 | D787D57F2042390F0097DC76 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = SourceView/AppDelegate.swift; sourceTree = ""; }; 48 | D787D5802042390F0097DC76 /* PrimaryViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PrimaryViewController.swift; path = SourceView/PrimaryViewController.swift; sourceTree = ""; }; 49 | D787D581204239100097DC76 /* MyWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MyWindowController.swift; path = SourceView/MyWindowController.swift; sourceTree = ""; }; 50 | D787D582204239100097DC76 /* MySplitViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MySplitViewController.swift; path = SourceView/MySplitViewController.swift; sourceTree = ""; }; 51 | D787D5872042393F0097DC76 /* ChildNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChildNode.swift; path = SourceView/ChildNode.swift; sourceTree = ""; }; 52 | D787D5882042393F0097DC76 /* BaseNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BaseNode.swift; path = SourceView/BaseNode.swift; sourceTree = ""; }; 53 | D787D58B204239640097DC76 /* SeparatorView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SeparatorView.swift; path = SourceView/SeparatorView.swift; sourceTree = ""; }; 54 | D787D58C204239650097DC76 /* ChildEditViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChildEditViewController.swift; path = SourceView/ChildEditViewController.swift; sourceTree = ""; }; 55 | D787D58F20423B3B0097DC76 /* Prefix.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Prefix.swift; sourceTree = ""; }; 56 | /* End PBXFileReference section */ 57 | 58 | /* Begin PBXFrameworksBuildPhase section */ 59 | 8D11072E0486CEB800E47090 /* Frameworks */ = { 60 | isa = PBXFrameworksBuildPhase; 61 | buildActionMask = 2147483647; 62 | files = ( 63 | 537D3D971CB571D000CB2D64 /* WebKit.framework in Frameworks */, 64 | ); 65 | runOnlyForDeploymentPostprocessing = 0; 66 | }; 67 | /* End PBXFrameworksBuildPhase section */ 68 | 69 | /* Begin PBXGroup section */ 70 | 19C28FACFE9D520D11CA2CBB /* Products */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 8D1107320486CEB800E47090 /* SourceView.app */, 74 | ); 75 | name = Products; 76 | sourceTree = ""; 77 | }; 78 | 29B97314FDCFA39411CA2CEA /* TrackIt */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | D787D572204237650097DC76 /* LICENSE.txt */, 82 | 5368DC9319DC604D003019C8 /* README.md */, 83 | D787D571204237640097DC76 /* README2.md */, 84 | 29B97315FDCFA39411CA2CEA /* Sources */, 85 | 29B97317FDCFA39411CA2CEA /* Resources */, 86 | 19C28FACFE9D520D11CA2CBB /* Products */, 87 | ); 88 | name = TrackIt; 89 | sourceTree = ""; 90 | }; 91 | 29B97315FDCFA39411CA2CEA /* Sources */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | D787D58F20423B3B0097DC76 /* Prefix.swift */, 95 | D787D57F2042390F0097DC76 /* AppDelegate.swift */, 96 | D787D581204239100097DC76 /* MyWindowController.swift */, 97 | D787D5802042390F0097DC76 /* PrimaryViewController.swift */, 98 | D787D582204239100097DC76 /* MySplitViewController.swift */, 99 | 5334E6931BA227B300AB44BD /* Master */, 100 | 5334E6921BA2277C00AB44BD /* Detail */, 101 | D787D58C204239650097DC76 /* ChildEditViewController.swift */, 102 | D787D58B204239640097DC76 /* SeparatorView.swift */, 103 | 53663E181177C62800078216 /* Tree Support */, 104 | ); 105 | name = Sources; 106 | sourceTree = ""; 107 | }; 108 | 29B97317FDCFA39411CA2CEA /* Resources */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | 533E9CEC1BB1F4B900B904E0 /* Credits.rtf */, 112 | 533E9CEE1BB1F4B900B904E0 /* InfoPlist.strings */, 113 | 5368DCB419DC60AD003019C8 /* Outline.dict */, 114 | 5368DCB919DC60B8003019C8 /* Info.plist */, 115 | 53E207311BA0BEB000E45BA6 /* Main.storyboard */, 116 | 537D3D961CB571D000CB2D64 /* WebKit.framework */, 117 | ); 118 | name = Resources; 119 | sourceTree = ""; 120 | }; 121 | 5334E6921BA2277C00AB44BD /* Detail */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | D787D57A204238B10097DC76 /* IconViewBox.swift */, 125 | D787D579204238B10097DC76 /* FileViewController.swift */, 126 | D787D577204238B00097DC76 /* IconViewController.swift */, 127 | D787D578204238B10097DC76 /* WebViewController.swift */, 128 | ); 129 | name = Detail; 130 | sourceTree = ""; 131 | }; 132 | 5334E6931BA227B300AB44BD /* Master */ = { 133 | isa = PBXGroup; 134 | children = ( 135 | D787D5752042381F0097DC76 /* MyOutlineViewController.swift */, 136 | ); 137 | name = Master; 138 | sourceTree = ""; 139 | }; 140 | 53663E181177C62800078216 /* Tree Support */ = { 141 | isa = PBXGroup; 142 | children = ( 143 | D787D5882042393F0097DC76 /* BaseNode.swift */, 144 | D787D5872042393F0097DC76 /* ChildNode.swift */, 145 | ); 146 | name = "Tree Support"; 147 | sourceTree = ""; 148 | }; 149 | /* End PBXGroup section */ 150 | 151 | /* Begin PBXNativeTarget section */ 152 | 8D1107260486CEB800E47090 /* SourceView */ = { 153 | isa = PBXNativeTarget; 154 | buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "SourceView" */; 155 | buildPhases = ( 156 | 8D1107290486CEB800E47090 /* Resources */, 157 | 8D11072C0486CEB800E47090 /* Sources */, 158 | 8D11072E0486CEB800E47090 /* Frameworks */, 159 | ); 160 | buildRules = ( 161 | ); 162 | dependencies = ( 163 | ); 164 | name = SourceView; 165 | productInstallPath = "$(HOME)/Applications"; 166 | productName = TrackIt; 167 | productReference = 8D1107320486CEB800E47090 /* SourceView.app */; 168 | productType = "com.apple.product-type.application"; 169 | }; 170 | /* End PBXNativeTarget section */ 171 | 172 | /* Begin PBXProject section */ 173 | 29B97313FDCFA39411CA2CEA /* Project object */ = { 174 | isa = PBXProject; 175 | attributes = { 176 | LastUpgradeCheck = 0900; 177 | TargetAttributes = { 178 | 8D1107260486CEB800E47090 = { 179 | DevelopmentTeam = V7M23Q5387; 180 | LastSwiftMigration = 0920; 181 | }; 182 | }; 183 | }; 184 | buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SourceView" */; 185 | compatibilityVersion = "Xcode 3.2"; 186 | developmentRegion = English; 187 | hasScannedForEncodings = 1; 188 | knownRegions = ( 189 | en, 190 | English, 191 | Base, 192 | ); 193 | mainGroup = 29B97314FDCFA39411CA2CEA /* TrackIt */; 194 | projectDirPath = ""; 195 | projectRoot = ""; 196 | targets = ( 197 | 8D1107260486CEB800E47090 /* SourceView */, 198 | ); 199 | }; 200 | /* End PBXProject section */ 201 | 202 | /* Begin PBXResourcesBuildPhase section */ 203 | 8D1107290486CEB800E47090 /* Resources */ = { 204 | isa = PBXResourcesBuildPhase; 205 | buildActionMask = 2147483647; 206 | files = ( 207 | 5368DCB619DC60AD003019C8 /* Outline.dict in Resources */, 208 | 533E9CF11BB1F4B900B904E0 /* InfoPlist.strings in Resources */, 209 | 533E9CF01BB1F4B900B904E0 /* Credits.rtf in Resources */, 210 | 53E207331BA0BEB000E45BA6 /* Main.storyboard in Resources */, 211 | ); 212 | runOnlyForDeploymentPostprocessing = 0; 213 | }; 214 | /* End PBXResourcesBuildPhase section */ 215 | 216 | /* Begin PBXSourcesBuildPhase section */ 217 | 8D11072C0486CEB800E47090 /* Sources */ = { 218 | isa = PBXSourcesBuildPhase; 219 | buildActionMask = 2147483647; 220 | files = ( 221 | D787D58D204239660097DC76 /* SeparatorView.swift in Sources */, 222 | D787D57D204238B20097DC76 /* FileViewController.swift in Sources */, 223 | D787D5892042393F0097DC76 /* ChildNode.swift in Sources */, 224 | D787D57E204238B20097DC76 /* IconViewBox.swift in Sources */, 225 | D787D584204239100097DC76 /* PrimaryViewController.swift in Sources */, 226 | D787D58E204239660097DC76 /* ChildEditViewController.swift in Sources */, 227 | D787D585204239100097DC76 /* MyWindowController.swift in Sources */, 228 | D787D583204239100097DC76 /* AppDelegate.swift in Sources */, 229 | D787D5762042381F0097DC76 /* MyOutlineViewController.swift in Sources */, 230 | D787D57B204238B20097DC76 /* IconViewController.swift in Sources */, 231 | D787D57C204238B20097DC76 /* WebViewController.swift in Sources */, 232 | D787D59020423B3C0097DC76 /* Prefix.swift in Sources */, 233 | D787D58A2042393F0097DC76 /* BaseNode.swift in Sources */, 234 | D787D586204239100097DC76 /* MySplitViewController.swift in Sources */, 235 | ); 236 | runOnlyForDeploymentPostprocessing = 0; 237 | }; 238 | /* End PBXSourcesBuildPhase section */ 239 | 240 | /* Begin PBXVariantGroup section */ 241 | 533E9CEC1BB1F4B900B904E0 /* Credits.rtf */ = { 242 | isa = PBXVariantGroup; 243 | children = ( 244 | 533E9CED1BB1F4B900B904E0 /* Base */, 245 | ); 246 | name = Credits.rtf; 247 | sourceTree = ""; 248 | }; 249 | 533E9CEE1BB1F4B900B904E0 /* InfoPlist.strings */ = { 250 | isa = PBXVariantGroup; 251 | children = ( 252 | 533E9CEF1BB1F4B900B904E0 /* Base */, 253 | ); 254 | name = InfoPlist.strings; 255 | sourceTree = ""; 256 | }; 257 | 53E207311BA0BEB000E45BA6 /* Main.storyboard */ = { 258 | isa = PBXVariantGroup; 259 | children = ( 260 | 533E9CEB1BB1F3E700B904E0 /* Base */, 261 | ); 262 | name = Main.storyboard; 263 | sourceTree = ""; 264 | }; 265 | /* End PBXVariantGroup section */ 266 | 267 | /* Begin XCBuildConfiguration section */ 268 | C01FCF4B08A954540054247B /* Debug */ = { 269 | isa = XCBuildConfiguration; 270 | buildSettings = { 271 | CLANG_ENABLE_MODULES = YES; 272 | CLANG_ENABLE_OBJC_ARC = YES; 273 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 274 | COMBINE_HIDPI_IMAGES = YES; 275 | GCC_PREFIX_HEADER = SourceView/Prefix.pch; 276 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 277 | GCC_WARN_SIGN_COMPARE = YES; 278 | GCC_WARN_UNDECLARED_SELECTOR = YES; 279 | GCC_WARN_UNUSED_PARAMETER = NO; 280 | INFOPLIST_FILE = SourceView/Info.plist; 281 | INSTALL_PATH = "$(HOME)/Applications"; 282 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 283 | PRODUCT_BUNDLE_IDENTIFIER = "com.example.apple-samplecode.${PRODUCT_NAME:rfc1034identifier}"; 284 | PRODUCT_NAME = SourceView; 285 | SDKROOT = macosx; 286 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 287 | SWIFT_VERSION = 3.0; 288 | WRAPPER_EXTENSION = app; 289 | }; 290 | name = Debug; 291 | }; 292 | C01FCF4C08A954540054247B /* Release */ = { 293 | isa = XCBuildConfiguration; 294 | buildSettings = { 295 | CLANG_ENABLE_MODULES = YES; 296 | CLANG_ENABLE_OBJC_ARC = YES; 297 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 298 | COMBINE_HIDPI_IMAGES = YES; 299 | GCC_FAST_OBJC_DISPATCH = YES; 300 | GCC_OPTIMIZATION_LEVEL = s; 301 | GCC_PREFIX_HEADER = SourceView/Prefix.pch; 302 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 303 | GCC_WARN_SIGN_COMPARE = YES; 304 | GCC_WARN_UNDECLARED_SELECTOR = YES; 305 | GCC_WARN_UNUSED_PARAMETER = NO; 306 | INFOPLIST_FILE = SourceView/Info.plist; 307 | INSTALL_PATH = "$(HOME)/Applications"; 308 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 309 | PRODUCT_BUNDLE_IDENTIFIER = "com.example.apple-samplecode.${PRODUCT_NAME:rfc1034identifier}"; 310 | PRODUCT_NAME = SourceView; 311 | SDKROOT = macosx; 312 | SWIFT_VERSION = 3.0; 313 | WRAPPER_EXTENSION = app; 314 | }; 315 | name = Release; 316 | }; 317 | C01FCF4F08A954540054247B /* Debug */ = { 318 | isa = XCBuildConfiguration; 319 | buildSettings = { 320 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 321 | CLANG_ENABLE_MODULES = YES; 322 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 323 | CLANG_WARN_BOOL_CONVERSION = YES; 324 | CLANG_WARN_COMMA = YES; 325 | CLANG_WARN_CONSTANT_CONVERSION = YES; 326 | CLANG_WARN_EMPTY_BODY = YES; 327 | CLANG_WARN_ENUM_CONVERSION = YES; 328 | CLANG_WARN_INFINITE_RECURSION = YES; 329 | CLANG_WARN_INT_CONVERSION = YES; 330 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 331 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 332 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 333 | CLANG_WARN_STRICT_PROTOTYPES = YES; 334 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 335 | CLANG_WARN_UNREACHABLE_CODE = YES; 336 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 337 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 338 | ENABLE_STRICT_OBJC_MSGSEND = YES; 339 | ENABLE_TESTABILITY = YES; 340 | GCC_FAST_OBJC_DISPATCH = NO; 341 | GCC_NO_COMMON_BLOCKS = YES; 342 | GCC_OPTIMIZATION_LEVEL = 0; 343 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 344 | GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; 345 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; 346 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 347 | GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; 348 | GCC_WARN_SHADOW = YES; 349 | GCC_WARN_UNDECLARED_SELECTOR = YES; 350 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 351 | GCC_WARN_UNKNOWN_PRAGMAS = YES; 352 | GCC_WARN_UNUSED_FUNCTION = YES; 353 | GCC_WARN_UNUSED_LABEL = YES; 354 | GCC_WARN_UNUSED_PARAMETER = NO; 355 | GCC_WARN_UNUSED_VARIABLE = YES; 356 | MACOSX_DEPLOYMENT_TARGET = 10.10; 357 | ONLY_ACTIVE_ARCH = YES; 358 | OTHER_LDFLAGS = "-ObjC"; 359 | RUN_CLANG_STATIC_ANALYZER = YES; 360 | SDKROOT = macosx; 361 | }; 362 | name = Debug; 363 | }; 364 | C01FCF5008A954540054247B /* Release */ = { 365 | isa = XCBuildConfiguration; 366 | buildSettings = { 367 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 368 | CLANG_ENABLE_MODULES = YES; 369 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 370 | CLANG_WARN_BOOL_CONVERSION = YES; 371 | CLANG_WARN_COMMA = YES; 372 | CLANG_WARN_CONSTANT_CONVERSION = YES; 373 | CLANG_WARN_EMPTY_BODY = YES; 374 | CLANG_WARN_ENUM_CONVERSION = YES; 375 | CLANG_WARN_INFINITE_RECURSION = YES; 376 | CLANG_WARN_INT_CONVERSION = YES; 377 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 378 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 379 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 380 | CLANG_WARN_STRICT_PROTOTYPES = YES; 381 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 382 | CLANG_WARN_UNREACHABLE_CODE = YES; 383 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 384 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 385 | ENABLE_STRICT_OBJC_MSGSEND = YES; 386 | GCC_NO_COMMON_BLOCKS = YES; 387 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 388 | GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; 389 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; 390 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 391 | GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; 392 | GCC_WARN_SHADOW = YES; 393 | GCC_WARN_UNDECLARED_SELECTOR = YES; 394 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 395 | GCC_WARN_UNKNOWN_PRAGMAS = YES; 396 | GCC_WARN_UNUSED_FUNCTION = YES; 397 | GCC_WARN_UNUSED_LABEL = YES; 398 | GCC_WARN_UNUSED_PARAMETER = NO; 399 | GCC_WARN_UNUSED_VARIABLE = YES; 400 | MACOSX_DEPLOYMENT_TARGET = 10.10; 401 | OTHER_LDFLAGS = "-ObjC"; 402 | SDKROOT = macosx; 403 | }; 404 | name = Release; 405 | }; 406 | /* End XCBuildConfiguration section */ 407 | 408 | /* Begin XCConfigurationList section */ 409 | C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "SourceView" */ = { 410 | isa = XCConfigurationList; 411 | buildConfigurations = ( 412 | C01FCF4B08A954540054247B /* Debug */, 413 | C01FCF4C08A954540054247B /* Release */, 414 | ); 415 | defaultConfigurationIsVisible = 0; 416 | defaultConfigurationName = Release; 417 | }; 418 | C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SourceView" */ = { 419 | isa = XCConfigurationList; 420 | buildConfigurations = ( 421 | C01FCF4F08A954540054247B /* Debug */, 422 | C01FCF5008A954540054247B /* Release */, 423 | ); 424 | defaultConfigurationIsVisible = 0; 425 | defaultConfigurationName = Release; 426 | }; 427 | /* End XCConfigurationList section */ 428 | }; 429 | rootObject = 29B97313FDCFA39411CA2CEA /* Project object */; 430 | } 431 | -------------------------------------------------------------------------------- /SourceView.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SourceView.xcodeproj/project.xcworkspace/xcuserdata/dev.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ooper-shlab/SourceView-Swift/a2a77468726d1e133db7e866ef3969af12139cbe/SourceView.xcodeproj/project.xcworkspace/xcuserdata/dev.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /SourceView.xcodeproj/xcuserdata/dev.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SourceView.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /SourceView/AppDelegate.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | The sample's application delegate object (NSApplicationDelegate) 7 | */ 8 | 9 | @interface AppDelegate : NSObject 10 | 11 | @end 12 | -------------------------------------------------------------------------------- /SourceView/AppDelegate.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | The sample's application delegate object (NSApplicationDelegate) 7 | */ 8 | 9 | #import "AppDelegate.h" 10 | 11 | @implementation AppDelegate 12 | 13 | // ------------------------------------------------------------------------------- 14 | // applicationShouldTerminateAfterLastWindowClosed:sender 15 | // 16 | // NSApplication delegate method placed here so the sample conveniently quits 17 | // after we close the window. 18 | // ------------------------------------------------------------------------------- 19 | - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender 20 | { 21 | return YES; 22 | } 23 | 24 | @end 25 | -------------------------------------------------------------------------------- /SourceView/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SourceView 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/4/17. 6 | // 7 | // 8 | /* 9 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 10 | See LICENSE.txt for this sample’s licensing information 11 | 12 | Abstract: 13 | The sample's application delegate object (NSApplicationDelegate) 14 | */ 15 | 16 | import Cocoa 17 | 18 | @NSApplicationMain 19 | @objc(AppDelegate) 20 | class AppDelegate: NSObject, NSApplicationDelegate { 21 | 22 | // ------------------------------------------------------------------------------- 23 | // applicationShouldTerminateAfterLastWindowClosed:sender 24 | // 25 | // NSApplication delegate method placed here so the sample conveniently quits 26 | // after we close the window. 27 | // ------------------------------------------------------------------------------- 28 | func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 29 | return true 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /SourceView/Base.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf1\ansi\ansicpg1252\cocoartf1348\cocoasubrtf170 2 | {\fonttbl\f0\fnil\fcharset0 LucidaGrande;} 3 | {\colortbl;\red255\green255\blue255;} 4 | \vieww9000\viewh8400\viewkind0 5 | \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\qc 6 | 7 | \f0\fs20 \cf0 Demonstrates how to use a\ 8 | Finder-like source view with\ 9 | {\field{\*\fldinst{HYPERLINK "http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSOutlineView_Class/Reference/Reference.html"}}{\fldrslt NSOutlineView}} using {\field{\*\fldinst{HYPERLINK "http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTreeController_Class/Reference/Reference.html"}}{\fldrslt NSTreeController}}.\ 10 | } -------------------------------------------------------------------------------- /SourceView/Base.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ooper-shlab/SourceView-Swift/a2a77468726d1e133db7e866ef3969af12139cbe/SourceView/Base.lproj/InfoPlist.strings -------------------------------------------------------------------------------- /SourceView/BaseNode.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | Generic multi-use node object used with NSOutlineView and NSTreeController. 7 | */ 8 | 9 | @interface BaseNode : NSObject 10 | 11 | #define kIconSmallImageSize 16. 12 | #define kIconLargeImageSize 32. 13 | 14 | // default grouping titles 15 | + (NSString *)placesName; 16 | + (NSString *)bookmarksName; 17 | + (NSString *)untitledName; // node with not title set 18 | 19 | @property (strong) NSString *nodeTitle; 20 | @property (nonatomic, strong) NSImage *nodeIcon; 21 | @property (strong) NSMutableArray *children; 22 | @property (strong) NSURL *url; 23 | @property (assign) BOOL isLeaf; 24 | @property (assign) BOOL isBookmark; 25 | @property (assign) BOOL isDirectory; 26 | 27 | @property (readonly) BOOL isSpecialGroup; 28 | @property (readonly) BOOL isSeparator; 29 | 30 | - (instancetype)initLeaf; 31 | 32 | @property (NS_NONATOMIC_IOSONLY, getter=isDraggable, readonly) BOOL draggable; 33 | 34 | - (NSComparisonResult)compare:(BaseNode *)aNode; 35 | 36 | @property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *mutableKeys; 37 | 38 | - (NSDictionary *)dictionaryRepresentation; 39 | - (instancetype)initWithDictionary:(NSDictionary *)dictionary; 40 | 41 | - (void)removeObjectFromChildren:(id)obj; 42 | @property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *descendants; 43 | @property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *allChildLeafs; 44 | @property (NS_NONATOMIC_IOSONLY, readonly, copy) NSArray *groupChildren; 45 | - (BOOL)isDescendantOfOrOneOfNodes:(NSArray *)nodes; 46 | - (BOOL)isDescendantOfNodes:(NSArray *)nodes; 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /SourceView/BaseNode.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | Generic multi-use node object used with NSOutlineView and NSTreeController. 7 | */ 8 | 9 | #import "BaseNode.h" 10 | 11 | #define PLACES_NAME @"PLACES" 12 | #define BOOKMARKS_NAME @"BOOKMARKS" 13 | 14 | 15 | @implementation BaseNode 16 | 17 | // ------------------------------------------------------------------------------- 18 | // init 19 | // ------------------------------------------------------------------------------- 20 | - (instancetype)init 21 | { 22 | self = [super init]; 23 | if (self != nil) 24 | { 25 | self.nodeTitle = @"BaseNode Untitled"; 26 | 27 | self.children = [NSMutableArray array]; 28 | [self setLeaf:NO]; // is container by default 29 | } 30 | return self; 31 | } 32 | 33 | // ------------------------------------------------------------------------------- 34 | // description 35 | // ------------------------------------------------------------------------------- 36 | + (NSString *)description { return @"BaseNode"; } 37 | 38 | // ------------------------------------------------------------------------------- 39 | // String constants 40 | // ------------------------------------------------------------------------------- 41 | + (NSString *)placesName { return @"PLACES"; } 42 | + (NSString *)bookmarksName { return @"BOOKMARKS"; } 43 | + (NSString *)untitledName { return @"Untitled"; } // default name for added folders and leafs 44 | 45 | // ------------------------------------------------------------------------------- 46 | // initLeaf 47 | // ------------------------------------------------------------------------------- 48 | - (instancetype)initLeaf 49 | { 50 | self = [self init]; 51 | if (self != nil) 52 | { 53 | [self setLeaf:YES]; 54 | } 55 | return self; 56 | } 57 | 58 | // ------------------------------------------------------------------------------- 59 | // setLeaf:flag 60 | // ------------------------------------------------------------------------------- 61 | - (void)setLeaf:(BOOL)flag 62 | { 63 | _isLeaf = flag; 64 | if (_isLeaf) 65 | { 66 | self.children = [NSMutableArray arrayWithObject:self]; 67 | } 68 | else 69 | { 70 | self.children = [NSMutableArray array]; 71 | } 72 | } 73 | 74 | // ------------------------------------------------------------------------------- 75 | // isBookmark 76 | // ------------------------------------------------------------------------------- 77 | - (BOOL)isBookmark 78 | { 79 | BOOL isBookmark = NO; 80 | if (self.url != nil) 81 | { 82 | return !self.url.fileURL; 83 | } 84 | return isBookmark; 85 | } 86 | 87 | // ------------------------------------------------------------------------------- 88 | // setIsBookmark:isBookmark 89 | // ------------------------------------------------------------------------------- 90 | - (void)setIsBookmark:(BOOL)isBookmark 91 | { 92 | self.isBookmark = isBookmark; 93 | } 94 | 95 | // ------------------------------------------------------------------------------- 96 | // isDirectory 97 | // ------------------------------------------------------------------------------- 98 | - (BOOL)isDirectory 99 | { 100 | BOOL isDirectory = NO; 101 | 102 | if (self.url != nil) 103 | { 104 | NSNumber *isURLDirectory = nil; 105 | [self.url getResourceValue:&isURLDirectory forKey:NSURLIsDirectoryKey error:nil]; 106 | isDirectory = isURLDirectory.boolValue; 107 | } 108 | 109 | return isDirectory; 110 | } 111 | 112 | // ------------------------------------------------------------------------------- 113 | // setIsBookmark:isBookmark 114 | // ------------------------------------------------------------------------------- 115 | - (void)setIsDirectory:(BOOL)isDirectory 116 | { 117 | self.isDirectory = isDirectory; 118 | } 119 | 120 | // ------------------------------------------------------------------------------- 121 | // compare:aNode 122 | // ------------------------------------------------------------------------------- 123 | - (NSComparisonResult)compare:(BaseNode *)aNode 124 | { 125 | return [self.nodeTitle.lowercaseString compare:aNode.nodeTitle.lowercaseString]; 126 | } 127 | 128 | // ------------------------------------------------------------------------------- 129 | // isSpecialGroup 130 | // ------------------------------------------------------------------------------- 131 | - (BOOL)isSpecialGroup 132 | { 133 | return ([self.nodeTitle isEqualToString:BOOKMARKS_NAME] || [self.nodeTitle isEqualToString:PLACES_NAME]); 134 | } 135 | 136 | // ------------------------------------------------------------------------------- 137 | // isSeparator 138 | // ------------------------------------------------------------------------------- 139 | - (BOOL)isSeparator 140 | { 141 | return (self.nodeIcon == nil && self.nodeTitle.length == 0); 142 | } 143 | 144 | // ------------------------------------------------------------------------------- 145 | // nodeIcon 146 | // ------------------------------------------------------------------------------- 147 | - (NSImage *)nodeIcon 148 | { 149 | NSImage *icon = nil; 150 | if (self.isLeaf) 151 | { 152 | // does it have a URL string? 153 | if (self.url != nil) 154 | { 155 | if (self.isLeaf) 156 | { 157 | if (self.isBookmark) 158 | { 159 | icon = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGenericURLIcon)]; 160 | } 161 | else 162 | { 163 | icon = [[NSWorkspace sharedWorkspace] iconForFile:self.url.path]; 164 | } 165 | } 166 | else 167 | { 168 | icon = [[NSWorkspace sharedWorkspace] iconForFile:self.url.path]; 169 | } 170 | } 171 | else 172 | { 173 | // it's a separator, don't bother with the icon 174 | } 175 | icon.size = NSMakeSize(kIconSmallImageSize, kIconSmallImageSize); 176 | } 177 | else if (!self.isSpecialGroup) 178 | { 179 | // it's a folder, use the folderImage as its icon 180 | icon = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGenericFolderIcon)]; 181 | icon.size = NSMakeSize(kIconSmallImageSize, kIconSmallImageSize); 182 | } 183 | 184 | return icon; 185 | } 186 | 187 | 188 | #pragma mark - Drag and Drop 189 | 190 | // ------------------------------------------------------------------------------- 191 | // removeObjectFromChildren:obj 192 | // 193 | // Recursive method which searches children and children of all sub-nodes 194 | // to remove the given object. 195 | // ------------------------------------------------------------------------------- 196 | - (void)removeObjectFromChildren:(id)obj 197 | { 198 | // remove object from children or the children of any sub-nodes 199 | for (id node in self.children) 200 | { 201 | if (node == obj) 202 | { 203 | [self.children removeObjectIdenticalTo:obj]; 204 | return; 205 | } 206 | 207 | if (![node isLeaf]) 208 | { 209 | [node removeObjectFromChildren:obj]; 210 | } 211 | } 212 | } 213 | 214 | // ------------------------------------------------------------------------------- 215 | // descendants 216 | // 217 | // Generates an array of all descendants. 218 | // ------------------------------------------------------------------------------- 219 | - (NSArray *)descendants 220 | { 221 | NSMutableArray *descendants = [NSMutableArray array]; 222 | id node = nil; 223 | for (node in self.children) 224 | { 225 | [descendants addObject:node]; 226 | 227 | if (![node isLeaf]) 228 | { 229 | [descendants addObjectsFromArray:[node descendants]]; // Recursive - will go down the chain to get all 230 | } 231 | } 232 | return descendants; 233 | } 234 | 235 | // ------------------------------------------------------------------------------- 236 | // allChildLeafs: 237 | // 238 | // Generates an array of all leafs in children and children of all sub-nodes. 239 | // Useful for generating a list of leaf-only nodes. 240 | // ------------------------------------------------------------------------------- 241 | - (NSArray *)allChildLeafs 242 | { 243 | NSMutableArray *childLeafs = [NSMutableArray array]; 244 | id node = nil; 245 | 246 | for (node in self.children) 247 | { 248 | if ([node isLeaf]) 249 | { 250 | [childLeafs addObject:node]; 251 | } 252 | else 253 | { 254 | [childLeafs addObjectsFromArray:[node allChildLeafs]]; // Recursive - will go down the chain to get all 255 | } 256 | } 257 | return childLeafs; 258 | } 259 | 260 | // ------------------------------------------------------------------------------- 261 | // groupChildren 262 | // 263 | // Returns only the children that are group nodes. 264 | // ------------------------------------------------------------------------------- 265 | - (NSArray *)groupChildren 266 | { 267 | NSMutableArray *groupChildren = [NSMutableArray array]; 268 | BaseNode *child; 269 | 270 | for (child in self.children) 271 | { 272 | if (!child.isLeaf) 273 | { 274 | [groupChildren addObject:child]; 275 | } 276 | } 277 | return groupChildren; 278 | } 279 | 280 | // ------------------------------------------------------------------------------- 281 | // isDescendantOfOrOneOfNodes:nodes 282 | // 283 | // Returns YES if self is contained anywhere inside the children or children of 284 | // sub-nodes of the nodes contained inside the given array. 285 | // ------------------------------------------------------------------------------- 286 | - (BOOL)isDescendantOfOrOneOfNodes:(NSArray *)nodes 287 | { 288 | // returns YES if we are contained anywhere inside the array passed in, including inside sub-nodes 289 | id node = nil; 290 | for (node in nodes) 291 | { 292 | if (node == self) 293 | return YES; // we found ourselves 294 | 295 | // check all the sub-nodes 296 | if (![node isLeaf]) 297 | { 298 | if ([self isDescendantOfOrOneOfNodes:[node children]]) 299 | return YES; 300 | } 301 | } 302 | 303 | return NO; 304 | } 305 | 306 | // ------------------------------------------------------------------------------- 307 | // isDescendantOfNodes:nodes 308 | // 309 | // Returns YES if any node in the array passed in is an ancestor of ours. 310 | // ------------------------------------------------------------------------------- 311 | - (BOOL)isDescendantOfNodes:(NSArray *)nodes 312 | { 313 | id node = nil; 314 | for (node in nodes) 315 | { 316 | // check all the sub-nodes 317 | if (![node isLeaf]) 318 | { 319 | if ([self isDescendantOfOrOneOfNodes:[node children]]) 320 | return YES; 321 | } 322 | } 323 | 324 | return NO; 325 | } 326 | 327 | 328 | #pragma mark - Archiving And Copying Support 329 | 330 | // ------------------------------------------------------------------------------- 331 | // mutableKeys: 332 | // 333 | // Override this method to maintain support for archiving and copying. 334 | // ------------------------------------------------------------------------------- 335 | - (NSArray *)mutableKeys 336 | { 337 | return @[ @"nodeTitle", 338 | @"isLeaf", // isLeaf MUST come before children for initWithDictionary: to work 339 | @"children", 340 | @"nodeIcon", 341 | @"urlString", 342 | @"isBookmark"]; 343 | } 344 | 345 | // ------------------------------------------------------------------------------- 346 | // initWithDictionary:dictionary 347 | // ------------------------------------------------------------------------------- 348 | - (instancetype)initWithDictionary:(NSDictionary *)dictionary 349 | { 350 | self = [self init]; 351 | if (self != nil) 352 | { 353 | NSString *key; 354 | for (key in self.mutableKeys) 355 | { 356 | if ([key isEqualToString:@"children"]) 357 | { 358 | if ([dictionary[@"isLeaf"] boolValue]) 359 | self.children = [NSMutableArray arrayWithObject:self]; 360 | else 361 | { 362 | NSArray *dictChildren = dictionary[key]; 363 | NSMutableArray *newChildren = [NSMutableArray array]; 364 | 365 | for (id node in dictChildren) 366 | { 367 | id newNode = [[[self class] alloc] initWithDictionary:node]; 368 | [newChildren addObject:newNode]; 369 | } 370 | self.children = newChildren; 371 | } 372 | } 373 | else 374 | { 375 | [self setValue:dictionary[key] forKey:key]; 376 | } 377 | } 378 | } 379 | return self; 380 | } 381 | 382 | // ------------------------------------------------------------------------------- 383 | // dictionaryRepresentation 384 | // ------------------------------------------------------------------------------- 385 | - (NSDictionary *)dictionaryRepresentation 386 | { 387 | NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; 388 | 389 | for (NSString *key in self.mutableKeys) 390 | { 391 | // convert all children to dictionaries 392 | if ([key isEqualToString:@"children"]) 393 | { 394 | if (!self.isLeaf) 395 | { 396 | NSMutableArray *dictChildren = [NSMutableArray array]; 397 | for (id node in self.children) 398 | { 399 | [dictChildren addObject:[node dictionaryRepresentation]]; 400 | } 401 | 402 | dictionary[key] = dictChildren; 403 | } 404 | } 405 | else if ([self valueForKey:key]) 406 | { 407 | dictionary[key] = [self valueForKey:key]; 408 | } 409 | } 410 | return dictionary; 411 | } 412 | 413 | // ------------------------------------------------------------------------------- 414 | // initWithCoder:coder 415 | // ------------------------------------------------------------------------------- 416 | - (instancetype)initWithCoder:(NSCoder *)coder 417 | { 418 | self = [self init]; 419 | if (self != nil) 420 | { 421 | for (NSString *key in self.mutableKeys) 422 | [self setValue:[coder decodeObjectForKey:key] forKey:key]; 423 | } 424 | return self; 425 | } 426 | 427 | // ------------------------------------------------------------------------------- 428 | // encodeWithCoder:coder 429 | // ------------------------------------------------------------------------------- 430 | - (void)encodeWithCoder:(NSCoder *)coder 431 | { 432 | for (NSString *key in self.mutableKeys) 433 | { 434 | [coder encodeObject:[self valueForKey:key] forKey:key]; 435 | } 436 | } 437 | 438 | // ------------------------------------------------------------------------------- 439 | // copyWithZone:zone 440 | // ------------------------------------------------------------------------------- 441 | - (id)copyWithZone:(NSZone *)zone 442 | { 443 | id newNode = [[[self class] allocWithZone:zone] init]; 444 | 445 | for (NSString *key in self.mutableKeys) 446 | { 447 | [newNode setValue:[self valueForKey:key] forKey:key]; 448 | } 449 | 450 | return newNode; 451 | } 452 | 453 | // ------------------------------------------------------------------------------- 454 | // setNilValueForKey:key 455 | // 456 | // Override this for any non-object values 457 | // ------------------------------------------------------------------------------- 458 | - (void)setNilValueForKey:(NSString *)key 459 | { 460 | if ([key isEqualToString:@"isLeaf"]) 461 | { 462 | self.isLeaf = NO; 463 | } 464 | else 465 | { 466 | [super setNilValueForKey:key]; 467 | } 468 | } 469 | 470 | @end 471 | -------------------------------------------------------------------------------- /SourceView/BaseNode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BaseNode.swift 3 | // SourceView 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/3/29. 6 | // 7 | // 8 | /* 9 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 10 | See LICENSE.txt for this sample’s licensing information 11 | 12 | Abstract: 13 | Generic multi-use node object used with NSOutlineView and NSTreeController. 14 | */ 15 | 16 | import Cocoa 17 | 18 | private let kIconSmallImageSize: CGFloat = 16.0 19 | let kIconLargeImageSize: CGFloat = 32.0 20 | 21 | private let PLACES_NAME = "PLACES" 22 | private let BOOKMARKS_NAME = "BOOKMARKS" 23 | 24 | 25 | @objc(BaseNode) 26 | class BaseNode: NSObject, NSCoding, NSCopying { 27 | 28 | dynamic var nodeTitle: String 29 | //dynamic var nodeIcon: NSImage? 30 | private var _children: [BaseNode] = [] 31 | dynamic var url: URL? 32 | dynamic var isLeaf: Bool = false // is container by default 33 | private var _isBookmark: Bool = false 34 | private var _isDirectory: Bool = false 35 | 36 | // ------------------------------------------------------------------------------- 37 | // init 38 | // ------------------------------------------------------------------------------- 39 | required override init() { 40 | self.nodeTitle = "BaseNode Untitled" 41 | super.init() 42 | } 43 | 44 | // ------------------------------------------------------------------------------- 45 | // description 46 | // ------------------------------------------------------------------------------- 47 | override class func description() -> String { 48 | return "BaseNode" 49 | } 50 | 51 | // ------------------------------------------------------------------------------- 52 | // String constants 53 | // ------------------------------------------------------------------------------- 54 | static let placesName = "PLACES" 55 | static let bookmarksName = "BOOKMARKS" 56 | static let untitledName = "Untitled" // default name for added folders and leafs 57 | 58 | // ------------------------------------------------------------------------------- 59 | // initLeaf 60 | // ------------------------------------------------------------------------------- 61 | @objc(initLeaf) 62 | convenience init(leaf: Void) { 63 | self.init() 64 | self.setLeaf(true) 65 | } 66 | 67 | // ------------------------------------------------------------------------------- 68 | // setLeaf:flag 69 | // ------------------------------------------------------------------------------- 70 | private func setLeaf(_ flag: Bool) { 71 | self.isLeaf = flag 72 | } 73 | 74 | dynamic var children: [BaseNode] { 75 | get { 76 | if self.isLeaf { 77 | return [self] 78 | } else { 79 | return _children 80 | } 81 | } 82 | set { 83 | _children = newValue 84 | } 85 | } 86 | 87 | // ------------------------------------------------------------------------------- 88 | // isBookmark 89 | // ------------------------------------------------------------------------------- 90 | var isBookmark: Bool { 91 | get { 92 | let isBookmark = false 93 | if let url = self.url { 94 | return !url.isFileURL 95 | } 96 | return isBookmark 97 | } 98 | 99 | // ------------------------------------------------------------------------------- 100 | // setIsBookmark:isBookmark 101 | // ------------------------------------------------------------------------------- 102 | set { 103 | self._isBookmark = newValue 104 | } 105 | } 106 | 107 | // ------------------------------------------------------------------------------- 108 | // isDirectory 109 | // ------------------------------------------------------------------------------- 110 | var isDirectory: Bool { 111 | get { 112 | var directory = false 113 | 114 | if let url = self.url { 115 | let resource = try? url.resourceValues(forKeys: [.isDirectoryKey]) 116 | let isURLDirectory = resource?.isDirectory ?? false 117 | directory = isURLDirectory 118 | } 119 | 120 | return directory 121 | } 122 | 123 | // ------------------------------------------------------------------------------- 124 | // setIsBookmark:isBookmark 125 | // ------------------------------------------------------------------------------- 126 | set { 127 | self._isDirectory = newValue 128 | } 129 | } 130 | 131 | // ------------------------------------------------------------------------------- 132 | // compare:aNode 133 | // ------------------------------------------------------------------------------- 134 | func compare(_ aNode: BaseNode) -> ComparisonResult { 135 | return self.nodeTitle.lowercased().compare(aNode.nodeTitle.lowercased()) 136 | } 137 | 138 | // ------------------------------------------------------------------------------- 139 | // isSpecialGroup 140 | // ------------------------------------------------------------------------------- 141 | var isSpecialGroup: Bool { 142 | return (self.nodeTitle == BOOKMARKS_NAME || self.nodeTitle == PLACES_NAME) 143 | } 144 | 145 | // ------------------------------------------------------------------------------- 146 | // isSeparator 147 | // ------------------------------------------------------------------------------- 148 | var isSeparator: Bool { 149 | return (self.nodeIcon == nil && self.nodeTitle.isEmpty) 150 | } 151 | 152 | // ------------------------------------------------------------------------------- 153 | // nodeIcon 154 | // ------------------------------------------------------------------------------- 155 | var nodeIcon: NSImage? { 156 | var icon: NSImage? = nil 157 | if self.isLeaf { 158 | // does it have a URL string? 159 | if let url = self.url { 160 | if self.isLeaf { 161 | if self.isBookmark { 162 | icon = NSWorkspace.shared().icon(forFileType: NSFileTypeForHFSTypeCode(OSType(kGenericURLIcon))) 163 | } else { 164 | icon = NSWorkspace.shared().icon(forFile: url.path) 165 | } 166 | } else { 167 | icon = NSWorkspace.shared().icon(forFile: url.path) 168 | } 169 | } else { 170 | // it's a separator, don't bother with the icon 171 | } 172 | icon?.size = NSMakeSize(kIconSmallImageSize, kIconSmallImageSize) 173 | } else if !self.isSpecialGroup { 174 | // it's a folder, use the folderImage as its icon 175 | icon = NSWorkspace.shared().icon(forFileType: NSFileTypeForHFSTypeCode(OSType(kGenericFolderIcon))) 176 | icon!.size = NSMakeSize(kIconSmallImageSize, kIconSmallImageSize) 177 | } 178 | 179 | return icon 180 | } 181 | 182 | 183 | //MARK: - Drag and Drop 184 | 185 | // ------------------------------------------------------------------------------- 186 | // removeObjectFromChildren:obj 187 | // 188 | // Recursive method which searches children and children of all sub-nodes 189 | // to remove the given object. 190 | // ------------------------------------------------------------------------------- 191 | func removeObjectFromChildren(_ obj: BaseNode) { 192 | // remove object from children or the children of any sub-nodes 193 | for (index, node) in self.children.enumerated() { 194 | if node === obj { 195 | self.children.remove(at: index) 196 | return 197 | } 198 | 199 | if !node.isLeaf { 200 | node.removeObjectFromChildren(obj) 201 | } 202 | } 203 | } 204 | 205 | // ------------------------------------------------------------------------------- 206 | // descendants 207 | // 208 | // Generates an array of all descendants. 209 | // ------------------------------------------------------------------------------- 210 | var descendants: [BaseNode] { 211 | var descendants: [BaseNode] = [] 212 | for node in self.children { 213 | descendants.append(node) 214 | 215 | if !node.isLeaf { 216 | descendants += node.descendants // Recursive - will go down the chain to get all 217 | } 218 | } 219 | return descendants 220 | } 221 | 222 | // ------------------------------------------------------------------------------- 223 | // allChildLeafs: 224 | // 225 | // Generates an array of all leafs in children and children of all sub-nodes. 226 | // Useful for generating a list of leaf-only nodes. 227 | // ------------------------------------------------------------------------------- 228 | var allChildLeafs: [BaseNode] { 229 | var childLeafs: [BaseNode] = [] 230 | 231 | for node in self.children { 232 | if node.isLeaf { 233 | childLeafs.append(node) 234 | } else { 235 | childLeafs += node.allChildLeafs // Recursive - will go down the chain to get all 236 | } 237 | } 238 | return childLeafs 239 | } 240 | 241 | // ------------------------------------------------------------------------------- 242 | // groupChildren 243 | // 244 | // Returns only the children that are group nodes. 245 | // ------------------------------------------------------------------------------- 246 | var groupChildren: [BaseNode] { 247 | var groupChildren: [BaseNode] = [] 248 | 249 | for child in self.children { 250 | if !child.isLeaf { 251 | groupChildren.append(child) 252 | } 253 | } 254 | return groupChildren 255 | } 256 | 257 | // ------------------------------------------------------------------------------- 258 | // isDescendantOfOrOneOfNodes:nodes 259 | // 260 | // Returns YES if self is contained anywhere inside the children or children of 261 | // sub-nodes of the nodes contained inside the given array. 262 | // ------------------------------------------------------------------------------- 263 | func isDescendantOfOrOneOfNodes(_ nodes: [BaseNode]) -> Bool { 264 | // returns YES if we are contained anywhere inside the array passed in, including inside sub-nodes 265 | for node in nodes { 266 | if node === self { 267 | return true // we found ourselves 268 | } 269 | 270 | // check all the sub-nodes 271 | if !node.isLeaf { 272 | if self.isDescendantOfOrOneOfNodes(node.children) { 273 | return true 274 | } 275 | } 276 | } 277 | 278 | return false 279 | } 280 | 281 | // ------------------------------------------------------------------------------- 282 | // isDescendantOfNodes:nodes 283 | // 284 | // Returns YES if any node in the array passed in is an ancestor of ours. 285 | // ------------------------------------------------------------------------------- 286 | func isDescendantOfNodes(_ nodes: [BaseNode]) -> Bool { 287 | for node in nodes { 288 | // check all the sub-nodes 289 | if !node.isLeaf { 290 | if self.isDescendantOfOrOneOfNodes(node.children) { 291 | return true 292 | } 293 | } 294 | } 295 | 296 | return false 297 | } 298 | 299 | 300 | //MARK: - Archiving And Copying Support 301 | 302 | // ------------------------------------------------------------------------------- 303 | // mutableKeys: 304 | // 305 | // Override this method to maintain support for archiving and copying. 306 | // ------------------------------------------------------------------------------- 307 | var mutableKeys: [String] { 308 | return ["nodeTitle", 309 | "isLeaf", // isLeaf MUST come before children for initWithDictionary: to work 310 | "children", 311 | "nodeIcon", 312 | "urlString", 313 | "isBookmark"] 314 | } 315 | 316 | // ------------------------------------------------------------------------------- 317 | // initWithDictionary:dictionary 318 | // ------------------------------------------------------------------------------- 319 | required convenience init(dictionary: [AnyHashable: Any]) { 320 | self.init() 321 | for key in self.mutableKeys { 322 | if key == "children" { 323 | if dictionary["isLeaf"] as! Bool { 324 | self.setLeaf(true) 325 | } else { 326 | let dictChildren = dictionary[key] as! [[AnyHashable: Any]] 327 | var newChildren: [BaseNode] = [] 328 | 329 | for node in dictChildren { 330 | let newNode = type(of: self).init(dictionary: node) 331 | newChildren.append(newNode) 332 | } 333 | self.children = newChildren 334 | } 335 | } else { 336 | self.setValue(dictionary[key], forKey: key) 337 | } 338 | } 339 | } 340 | 341 | // ------------------------------------------------------------------------------- 342 | // dictionaryRepresentation 343 | // ------------------------------------------------------------------------------- 344 | func dictionaryRepresentation() -> [AnyHashable: Any] { 345 | var dictionary: [AnyHashable: Any] = [:] 346 | 347 | for key in self.mutableKeys { 348 | // convert all children to dictionaries 349 | if key == "children" { 350 | if !self.isLeaf { 351 | var dictChildren: [[AnyHashable: Any]] = [] 352 | for node in self.children { 353 | dictChildren.append(node.dictionaryRepresentation()) 354 | } 355 | 356 | dictionary[key] = dictChildren 357 | } 358 | } else if let value = self.value(forKey: key) { 359 | dictionary[key] = value 360 | } 361 | } 362 | return dictionary 363 | } 364 | 365 | // ------------------------------------------------------------------------------- 366 | // initWithCoder:coder 367 | // ------------------------------------------------------------------------------- 368 | required convenience init?(coder: NSCoder) { 369 | self.init() 370 | for key in self.mutableKeys { 371 | self.setValue(coder.decodeObject(forKey: key), forKey: key) 372 | } 373 | } 374 | 375 | // ------------------------------------------------------------------------------- 376 | // encodeWithCoder:coder 377 | // ------------------------------------------------------------------------------- 378 | func encode(with coder: NSCoder) { 379 | for key in self.mutableKeys { 380 | coder.encode(self.value(forKey: key), forKey: key) 381 | } 382 | } 383 | 384 | // ------------------------------------------------------------------------------- 385 | // copyWithZone:zone 386 | // ------------------------------------------------------------------------------- 387 | func copy(with zone: NSZone?) -> Any { 388 | let newNode = type(of: self).init() as BaseNode 389 | 390 | for key in self.mutableKeys { 391 | newNode.setValue(self.value(forKey: key), forKey: key) 392 | } 393 | 394 | return newNode 395 | } 396 | 397 | // ------------------------------------------------------------------------------- 398 | // setNilValueForKey:key 399 | // 400 | // Override this for any non-object values 401 | // ------------------------------------------------------------------------------- 402 | override func setNilValueForKey(_ key: String) { 403 | if key == "isLeaf" { 404 | self.isLeaf = false 405 | } else { 406 | super.setNilValueForKey(key) 407 | } 408 | } 409 | 410 | } 411 | -------------------------------------------------------------------------------- /SourceView/ChildEditController.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | Controller object for the edit sheet panel. 7 | */ 8 | 9 | #import 10 | 11 | @class MyWindowController; 12 | 13 | @interface ChildEditController : NSWindowController 14 | 15 | - (NSDictionary *)edit:(NSDictionary *)startingValues from:(MyWindowController *)sender; 16 | @property (NS_NONATOMIC_IOSONLY, readonly) BOOL wasCancelled; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /SourceView/ChildEditController.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | Controller object for the edit sheet panel. 7 | */ 8 | 9 | #import "ChildEditController.h" 10 | #import "MyWindowController.h" 11 | 12 | @interface ChildEditController () 13 | { 14 | BOOL cancelled; 15 | NSDictionary *savedFields; 16 | 17 | IBOutlet NSButton *doneButton; 18 | IBOutlet NSTextField *nameField; 19 | IBOutlet NSTextField *urlField; 20 | } 21 | @end 22 | 23 | #pragma mark - 24 | 25 | @implementation ChildEditController 26 | 27 | // ------------------------------------------------------------------------------- 28 | // windowNibName 29 | // ------------------------------------------------------------------------------- 30 | - (NSString *)windowNibName 31 | { 32 | return @"ChildEdit"; 33 | } 34 | 35 | // ------------------------------------------------------------------------------- 36 | // edit:startingValues:from 37 | // ------------------------------------------------------------------------------- 38 | - (NSDictionary *)edit:(NSDictionary *)startingValues from:(MyWindowController *)sender 39 | { 40 | cancelled = NO; 41 | 42 | if (startingValues != nil) 43 | { 44 | // we are editing current entry, use its values as the default 45 | savedFields = startingValues; 46 | 47 | nameField.stringValue = startingValues[@"name"]; 48 | urlField.stringValue = startingValues[@"url"]; 49 | } 50 | else 51 | { 52 | // we are adding a new entry, 53 | // make sure the form fields are empty due to the fact that this controller is recycled 54 | // each time the user opens the sheet - 55 | // 56 | nameField.stringValue = @""; 57 | urlField.stringValue = @""; 58 | } 59 | 60 | [nameField becomeFirstResponder]; 61 | 62 | NSWindow *window = [self window]; 63 | [NSApp beginSheet:window modalForWindow:[sender window] modalDelegate:nil didEndSelector:nil contextInfo:nil]; 64 | 65 | // done button enabled only if both edit fields have text 66 | doneButton.enabled = (nameField.stringValue.length > 0 && urlField.stringValue.length > 0); 67 | 68 | [NSApp runModalForWindow:window]; 69 | // sheet is up here... 70 | 71 | [NSApp endSheet:window]; 72 | [window orderOut:self]; 73 | 74 | return savedFields; 75 | } 76 | 77 | // ------------------------------------------------------------------------------- 78 | // done:sender 79 | // ------------------------------------------------------------------------------- 80 | - (IBAction)done:(id)sender 81 | { 82 | NSString *urlStr; 83 | if (![[urlField stringValue] hasPrefix:@"http://"]) 84 | { 85 | urlStr = [NSString stringWithFormat:@"http://%@", [urlField stringValue]]; 86 | } 87 | else 88 | { 89 | urlStr = [urlField stringValue]; 90 | } 91 | savedFields = [NSMutableDictionary dictionaryWithObjectsAndKeys: 92 | [nameField stringValue], @"name", 93 | urlStr, @"url", 94 | nil]; 95 | 96 | [NSApp stopModal]; 97 | } 98 | 99 | // ------------------------------------------------------------------------------- 100 | // cancel:sender 101 | // ------------------------------------------------------------------------------- 102 | - (IBAction)cancel:(id)sender 103 | { 104 | [NSApp stopModal]; 105 | cancelled = YES; 106 | } 107 | 108 | // ------------------------------------------------------------------------------- 109 | // wasCancelled: 110 | // ------------------------------------------------------------------------------- 111 | - (BOOL)wasCancelled 112 | { 113 | return cancelled; 114 | } 115 | 116 | // ------------------------------------------------------------------------------- 117 | // controlTextDidChange:obj 118 | // 119 | // for this to be called, we need to be a delegate to both NSTextFields 120 | // ------------------------------------------------------------------------------- 121 | - (void)controlTextDidChange:(NSNotification *)obj 122 | { 123 | doneButton.enabled = (nameField.stringValue.length > 0 && urlField.stringValue.length > 0); 124 | } 125 | 126 | @end -------------------------------------------------------------------------------- /SourceView/ChildEditController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChildEditController.swift 3 | // SourceView 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/4/6. 6 | // 7 | // 8 | /* 9 | Copyright (C) 2015 Apple Inc. All Rights Reserved. 10 | See LICENSE.txt for this sample’s licensing information 11 | 12 | Abstract: 13 | Controller object for the edit sheet panel. 14 | */ 15 | 16 | import Cocoa 17 | 18 | @objc(ChildEditController) 19 | class ChildEditController: NSWindowController { 20 | 21 | private var cancelled: Bool = false 22 | private var savedFields: [String: String] = [:] 23 | 24 | @IBOutlet private var doneButton: NSButton! 25 | @IBOutlet private var nameField: NSTextField! 26 | @IBOutlet private var urlField: NSTextField! 27 | 28 | //MARK: - 29 | 30 | // ------------------------------------------------------------------------------- 31 | // windowNibName 32 | // ------------------------------------------------------------------------------- 33 | override var windowNibName: String { 34 | return "ChildEdit" 35 | } 36 | 37 | // ------------------------------------------------------------------------------- 38 | // edit:startingValues:from 39 | // ------------------------------------------------------------------------------- 40 | func edit(startingValues: [String: String]?, from sender: MyWindowController) -> [String: String] { 41 | let window = self.window! 42 | cancelled = false 43 | 44 | if startingValues != nil { 45 | // we are editing current entry, use its values as the default 46 | savedFields = startingValues! 47 | 48 | nameField.stringValue = startingValues!["name"]! 49 | urlField.stringValue = startingValues!["url"]! 50 | } else { 51 | // we are adding a new entry, 52 | // make sure the form fields are empty due to the fact that this controller is recycled 53 | // each time the user opens the sheet - 54 | // 55 | nameField.stringValue = "" 56 | urlField.stringValue = "" 57 | } 58 | 59 | nameField.becomeFirstResponder() 60 | 61 | NSApp.beginSheet(window, modalForWindow: sender.window!, modalDelegate: nil, didEndSelector: nil, contextInfo: nil) 62 | 63 | // done button enabled only if both edit fields have text 64 | doneButton.enabled = (!nameField.stringValue.isEmpty && !urlField.stringValue.isEmpty) 65 | 66 | NSApp.runModalForWindow(window) 67 | // sheet is up here... 68 | 69 | NSApp.endSheet(window) 70 | window.orderOut(self) 71 | 72 | return savedFields 73 | } 74 | 75 | // ------------------------------------------------------------------------------- 76 | // done:sender 77 | // ------------------------------------------------------------------------------- 78 | @IBAction func done(_: AnyObject) { 79 | let urlStr: String 80 | if !urlField.stringValue.hasPrefix("http://") { 81 | urlStr = "http://\(urlField.stringValue)" 82 | } else { 83 | urlStr = urlField.stringValue 84 | } 85 | savedFields = [ 86 | "name": nameField.stringValue, 87 | "url": urlStr, 88 | ] 89 | 90 | NSApp.stopModal() 91 | } 92 | 93 | // ------------------------------------------------------------------------------- 94 | // cancel:sender 95 | // ------------------------------------------------------------------------------- 96 | @IBAction func cancel(_: AnyObject) { 97 | NSApp.stopModal() 98 | cancelled = true 99 | } 100 | 101 | // ------------------------------------------------------------------------------- 102 | // wasCancelled: 103 | // ------------------------------------------------------------------------------- 104 | var wasCancelled: Bool { 105 | return cancelled 106 | } 107 | 108 | // ------------------------------------------------------------------------------- 109 | // controlTextDidChange:obj 110 | // 111 | // for this to be called, we need to be a delegate to both NSTextFields 112 | // ------------------------------------------------------------------------------- 113 | override func controlTextDidChange(obj: NSNotification) { 114 | doneButton.enabled = (!nameField.stringValue.isEmpty && !urlField.stringValue.isEmpty) 115 | } 116 | 117 | } -------------------------------------------------------------------------------- /SourceView/ChildEditViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | View controller object for the edit bookmark sheet. 7 | */ 8 | 9 | // keys to use to obtain the name and url values from the returned NSDictionary 10 | #define kName_Key @"name" 11 | #define kURL_Key @"url" 12 | 13 | @interface ChildEditViewController : NSViewController 14 | 15 | @property (nonatomic, strong) NSDictionary *savedValues; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /SourceView/ChildEditViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | View controller object for the edit bookmark sheet. 7 | */ 8 | 9 | #import "ChildEditViewController.h" 10 | 11 | @interface ChildEditViewController () 12 | 13 | @property (nonatomic, weak) IBOutlet NSButton *doneButton; 14 | @property (nonatomic, weak) IBOutlet NSTextField *nameField; 15 | @property (nonatomic, weak) IBOutlet NSTextField *urlField; 16 | 17 | @end 18 | 19 | 20 | #pragma mark - 21 | 22 | @implementation ChildEditViewController 23 | 24 | // ------------------------------------------------------------------------------- 25 | // viewWillAppear 26 | // ------------------------------------------------------------------------------- 27 | - (void)viewWillAppear 28 | { 29 | [super viewWillAppear]; 30 | 31 | self.nameField.stringValue = self.savedValues[kName_Key]; 32 | self.urlField.stringValue = self.savedValues[kURL_Key]; 33 | self.doneButton.enabled = [self doneAllowed]; 34 | } 35 | 36 | // ------------------------------------------------------------------------------- 37 | // doneAllowed 38 | // ------------------------------------------------------------------------------- 39 | - (BOOL)doneAllowed 40 | { 41 | return (self.nameField.stringValue.length > 0 && self.urlField.stringValue.length > 0); 42 | } 43 | 44 | // ------------------------------------------------------------------------------- 45 | // done:sender 46 | // ------------------------------------------------------------------------------- 47 | - (IBAction)done:(id)sender 48 | { 49 | // add the http prefix if the user forgot to 50 | NSString *urlStr; 51 | if (![self.urlField.stringValue hasPrefix:HTTP_PREFIX]) 52 | { 53 | urlStr = [NSString stringWithFormat:@"%@%@", HTTP_PREFIX, self.urlField.stringValue]; 54 | } 55 | else 56 | { 57 | urlStr = self.urlField.stringValue; 58 | } 59 | _savedValues = [NSMutableDictionary dictionaryWithObjectsAndKeys: 60 | self.nameField.stringValue, kName_Key, 61 | [NSURL URLWithString:urlStr], kURL_Key, 62 | nil]; 63 | [self clearValues]; 64 | 65 | [self.view.window.sheetParent endSheet:self.view.window returnCode:NSModalResponseOK]; 66 | } 67 | 68 | // ------------------------------------------------------------------------------- 69 | // clearValues 70 | // ------------------------------------------------------------------------------- 71 | - (void)clearValues 72 | { 73 | self.nameField.stringValue = self.urlField.stringValue = @""; 74 | } 75 | 76 | // ------------------------------------------------------------------------------- 77 | // cancel:sender 78 | // ------------------------------------------------------------------------------- 79 | - (IBAction)cancel:(id)sender 80 | { 81 | [self clearValues]; 82 | [self.view.window.sheetParent endSheet:self.view.window returnCode:NSModalResponseCancel]; 83 | } 84 | 85 | // ------------------------------------------------------------------------------- 86 | // controlTextDidChange:obj 87 | // 88 | // For this to be called, we need to be a delegate to both NSTextFields 89 | // ------------------------------------------------------------------------------- 90 | - (void)controlTextDidChange:(NSNotification *)obj 91 | { 92 | self.doneButton.enabled = [self doneAllowed]; 93 | } 94 | 95 | @end -------------------------------------------------------------------------------- /SourceView/ChildEditViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChildEditViewController.swift 3 | // SourceView 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/10/24. 6 | // 7 | // 8 | /* 9 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 10 | See LICENSE.txt for this sample’s licensing information 11 | 12 | Abstract: 13 | View controller object for the edit bookmark sheet. 14 | */ 15 | import Cocoa 16 | 17 | // keys to use to obtain the name and url values from the returned NSDictionary 18 | let kName_Key = "name" 19 | let kURL_Key = "url" 20 | 21 | @objc(ChildEditViewController) 22 | class ChildEditViewController: NSViewController { 23 | 24 | var savedValues: [String: Any] = [:] 25 | 26 | @IBOutlet private weak var doneButton: NSButton! 27 | @IBOutlet private weak var nameField: NSTextField! 28 | @IBOutlet private weak var urlField: NSTextField! 29 | 30 | 31 | //MARK: - 32 | 33 | // ------------------------------------------------------------------------------- 34 | // viewWillAppear 35 | // ------------------------------------------------------------------------------- 36 | override func viewWillAppear() { 37 | super.viewWillAppear() 38 | 39 | self.nameField.stringValue = self.savedValues[kName_Key] as! String? ?? "" 40 | self.urlField.stringValue = String(describing: self.savedValues[kURL_Key] ?? "") 41 | self.doneButton.isEnabled = self.doneAllowed 42 | } 43 | 44 | // ------------------------------------------------------------------------------- 45 | // doneAllowed 46 | // ------------------------------------------------------------------------------- 47 | private var doneAllowed: Bool { 48 | return (!self.nameField.stringValue.isEmpty && !self.urlField.stringValue.isEmpty) 49 | } 50 | 51 | // ------------------------------------------------------------------------------- 52 | // done:sender 53 | // ------------------------------------------------------------------------------- 54 | @IBAction func done(_: AnyObject) { 55 | let urlStr: String 56 | if !self.urlField.stringValue.hasPrefix(HTTP_PREFIX) { 57 | urlStr = "\(HTTP_PREFIX)\(self.urlField.stringValue)" 58 | } else { 59 | urlStr = self.urlField.stringValue 60 | } 61 | savedValues = [ 62 | kName_Key : self.nameField.stringValue as AnyObject, 63 | kURL_Key : URL(string: urlStr)! as AnyObject 64 | ] 65 | self.clearValues() 66 | 67 | self.view.window?.sheetParent?.endSheet(self.view.window!, returnCode: NSModalResponseOK) 68 | } 69 | 70 | // ------------------------------------------------------------------------------- 71 | // clearValues 72 | // ------------------------------------------------------------------------------- 73 | private func clearValues() { 74 | self.nameField.stringValue = "" 75 | self.urlField.stringValue = "" 76 | } 77 | 78 | // ------------------------------------------------------------------------------- 79 | // cancel:sender 80 | // ------------------------------------------------------------------------------- 81 | @IBAction func cancel(_: AnyObject) { 82 | self.clearValues() 83 | self.view.window?.sheetParent?.endSheet(self.view.window!, returnCode: NSModalResponseCancel) 84 | } 85 | 86 | // ------------------------------------------------------------------------------- 87 | // controlTextDidChange:obj 88 | // 89 | // For this to be called, we need to be a delegate to both NSTextFields 90 | // ------------------------------------------------------------------------------- 91 | override func controlTextDidChange(_ obj: Notification) { 92 | self.doneButton.isEnabled = self.doneAllowed 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /SourceView/ChildNode.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | Generic child node object used with NSOutlineView and NSTreeController. 7 | */ 8 | 9 | #import "BaseNode.h" 10 | 11 | @interface ChildNode : BaseNode 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /SourceView/ChildNode.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | Generic child node object used with NSOutlineView and NSTreeController. 7 | */ 8 | 9 | #import "ChildNode.h" 10 | 11 | @implementation ChildNode 12 | 13 | // ------------------------------------------------------------------------------- 14 | // init 15 | // ------------------------------------------------------------------------------- 16 | - (instancetype)init 17 | { 18 | self = [super init]; 19 | if (self != nil) 20 | { 21 | self.nodeTitle = @""; 22 | } 23 | return self; 24 | } 25 | 26 | // ------------------------------------------------------------------------------- 27 | // description 28 | // ------------------------------------------------------------------------------- 29 | + (NSString *)description 30 | { 31 | return @"ChildNode"; 32 | } 33 | 34 | // ------------------------------------------------------------------------------- 35 | // mutableKeys 36 | // 37 | // Maintain support for archiving and copying. 38 | // ------------------------------------------------------------------------------- 39 | - (NSArray *)mutableKeys 40 | { 41 | return [super.mutableKeys arrayByAddingObjectsFromArray:@[@"description"]]; 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /SourceView/ChildNode.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ChildNode.swift 3 | // SourceView 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/4/5. 6 | // 7 | // 8 | /* 9 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 10 | See LICENSE.txt for this sample’s licensing information 11 | 12 | Abstract: 13 | Generic child node object used with NSOutlineView and NSTreeController. 14 | */ 15 | 16 | import Cocoa 17 | 18 | @objc(ChildNode) 19 | class ChildNode: BaseNode { 20 | 21 | // ------------------------------------------------------------------------------- 22 | // init 23 | // ------------------------------------------------------------------------------- 24 | required init() { 25 | super.init() 26 | self.nodeTitle = "" 27 | } 28 | 29 | // ------------------------------------------------------------------------------- 30 | // description 31 | // ------------------------------------------------------------------------------- 32 | override class func description() -> String { 33 | return "ChildNode" 34 | } 35 | 36 | // ------------------------------------------------------------------------------- 37 | // mutableKeys 38 | // 39 | // Maintain support for archiving and copying. 40 | // ------------------------------------------------------------------------------- 41 | override var mutableKeys: [String] { 42 | return super.mutableKeys + ["description"] 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /SourceView/FileViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | View controller object to host the UI for file information 7 | */ 8 | 9 | @interface FileViewController : NSViewController 10 | 11 | @property (readwrite, strong) NSURL *url; 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /SourceView/FileViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | View controller object to host the UI for file information 7 | */ 8 | 9 | #import "FileViewController.h" 10 | 11 | @interface FileViewController () 12 | 13 | @property (nonatomic, weak) IBOutlet NSImageView *fileIcon; 14 | @property (nonatomic, weak) IBOutlet NSTextField *fileName; 15 | @property (nonatomic, weak) IBOutlet NSTextField *fileSize; 16 | @property (nonatomic, weak) IBOutlet NSTextField *modDate; 17 | @property (nonatomic, weak) IBOutlet NSTextField *creationDate; 18 | @property (nonatomic, weak) IBOutlet NSTextField *fileKindString; 19 | 20 | @end 21 | 22 | #pragma mark - 23 | 24 | @implementation FileViewController 25 | 26 | // ------------------------------------------------------------------------------- 27 | // awakeFromNib 28 | // ------------------------------------------------------------------------------- 29 | - (void)awakeFromNib 30 | { 31 | // listen for changes in the url for this view 32 | [self addObserver: self 33 | forKeyPath:@"url" 34 | options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) 35 | context:nil]; 36 | } 37 | 38 | // ------------------------------------------------------------------------------- 39 | // dealloc 40 | // ------------------------------------------------------------------------------- 41 | - (void)dealloc 42 | { 43 | [self removeObserver:self forKeyPath:@"url"]; 44 | } 45 | 46 | // ------------------------------------------------------------------------------- 47 | // observeValueForKeyPath:ofObject:change:context 48 | // 49 | // Listen for changes in the file url. 50 | // ------------------------------------------------------------------------------- 51 | - (void)observeValueForKeyPath: (NSString *)keyPath 52 | ofObject:(id)object 53 | change:(NSDictionary *)change 54 | context:(void *)context 55 | { 56 | // name 57 | self.fileName.stringValue = [[NSFileManager defaultManager] displayNameAtPath:self.url.path]; 58 | 59 | // icon 60 | NSImage *iconImage = [[NSWorkspace sharedWorkspace] iconForFile:self.url.path]; 61 | iconImage.size = NSMakeSize(64,64); 62 | self.fileIcon.image = iconImage; 63 | 64 | NSDictionary *attr = [[NSFileManager defaultManager] attributesOfItemAtPath:self.url.path error:nil]; 65 | if (attr) 66 | { 67 | // file size 68 | NSNumber *theFileSize = attr[NSFileSize]; 69 | self.fileSize.stringValue = [NSString stringWithFormat:@"%@ KB on disk", theFileSize.stringValue]; 70 | 71 | // creation date 72 | NSDate *fileCreationDate = attr[NSFileCreationDate]; 73 | self.creationDate.stringValue = fileCreationDate.description; 74 | 75 | // mod date 76 | NSDate *fileModDate = attr[NSFileModificationDate]; 77 | self.modDate.stringValue = fileModDate.description; 78 | } 79 | 80 | // kind string 81 | NSString *kindStr; 82 | [self.url getResourceValue:&kindStr forKey:NSURLLocalizedTypeDescriptionKey error:nil]; 83 | if (kindStr != nil) 84 | { 85 | self.fileKindString.stringValue = kindStr; 86 | } 87 | } 88 | 89 | @end 90 | -------------------------------------------------------------------------------- /SourceView/FileViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // FileViewController.swift 3 | // SourceView 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/4/6. 6 | // 7 | // 8 | /* 9 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 10 | See LICENSE.txt for this sample’s licensing information 11 | 12 | Abstract: 13 | View controller object to host the UI for file information 14 | */ 15 | 16 | import Cocoa 17 | 18 | @objc(FileViewController) 19 | class FileViewController: NSViewController { 20 | 21 | var url: URL? 22 | 23 | @IBOutlet private var fileIcon: NSImageView! 24 | @IBOutlet private var fileName: NSTextField! 25 | @IBOutlet private var fileSize: NSTextField! 26 | @IBOutlet private var modDate: NSTextField! 27 | @IBOutlet private var creationDate: NSTextField! 28 | @IBOutlet private var fileKindString: NSTextField! 29 | 30 | //MARK: - 31 | 32 | // ------------------------------------------------------------------------------- 33 | // awakeFromNib 34 | // ------------------------------------------------------------------------------- 35 | override func awakeFromNib() { 36 | // listen for changes in the url for this view 37 | self.addObserver(self, 38 | forKeyPath: "url", 39 | options: [.new, .old], 40 | context: nil) 41 | } 42 | 43 | // ------------------------------------------------------------------------------- 44 | // dealloc 45 | // ------------------------------------------------------------------------------- 46 | deinit { 47 | self.removeObserver(self, forKeyPath: "url") 48 | } 49 | 50 | // ------------------------------------------------------------------------------- 51 | // observeValueForKeyPath:ofObject:change:context 52 | // 53 | // Listen for changes in the file url. 54 | // ------------------------------------------------------------------------------- 55 | override func observeValue(forKeyPath keyPath: String?, 56 | of object: Any?, 57 | change: [NSKeyValueChangeKey : Any]?, 58 | context: UnsafeMutableRawPointer?) 59 | { 60 | if let url = self.url { 61 | let path = url.path 62 | // name 63 | self.fileName.stringValue = FileManager.default.displayName(atPath: path) 64 | 65 | // icon 66 | let iconImage = NSWorkspace.shared().icon(forFile: path) 67 | iconImage.size = NSMakeSize(64, 64) 68 | self.fileIcon.image = iconImage 69 | if let attr = try? FileManager.default.attributesOfItem(atPath: path) { 70 | // file size 71 | let theFileSize = attr[FileAttributeKey.size] as! NSNumber 72 | self.fileSize.stringValue = "\(theFileSize.stringValue) KB on disk" 73 | 74 | // creation date 75 | let fileCreationDate = attr[FileAttributeKey.creationDate] as! Date 76 | self.creationDate.stringValue = fileCreationDate.description 77 | 78 | // mod date 79 | let fileModDate = attr[FileAttributeKey.modificationDate] as! Date 80 | self.modDate.stringValue = fileModDate.description 81 | } 82 | 83 | // kind string 84 | let resource = try? url.resourceValues(forKeys: [.localizedTypeDescriptionKey]) 85 | let kindStr = resource?.localizedTypeDescription 86 | if let str = kindStr { 87 | self.fileKindString.stringValue = str 88 | } 89 | } else { 90 | self.fileName.stringValue = "" 91 | self.fileIcon.image = nil 92 | self.fileSize.stringValue = "" 93 | self.creationDate.stringValue = "" 94 | self.modDate.stringValue = "" 95 | self.fileKindString.stringValue = "" 96 | } 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /SourceView/IconViewBox.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | Custom NSBox subclass for changing mouse down behavior. 7 | */ 8 | 9 | extern NSString *KEY_NAME; 10 | extern NSString *KEY_ICON; 11 | 12 | @interface IconViewBox : NSBox 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /SourceView/IconViewBox.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | Custom NSBox subclass for changing mouse down behavior. 7 | */ 8 | 9 | #import "IconViewBox.h" 10 | 11 | // Key values for the icon view dictionary. 12 | NSString *KEY_NAME = @"name"; 13 | NSString *KEY_ICON = @"icon"; 14 | 15 | @implementation IconViewBox 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /SourceView/IconViewBox.swift: -------------------------------------------------------------------------------- 1 | // 2 | // IconViewBox.swift 3 | // SourceView 4 | // 5 | // Created by 開発 on 2017/7/4. 6 | // 7 | // 8 | /* 9 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 10 | See LICENSE.txt for this sample’s licensing information 11 | 12 | Abstract: 13 | Custom NSBox subclass for changing mouse down behavior. 14 | */ 15 | import Cocoa 16 | 17 | //@interface IconViewBox : NSBox 18 | @objc(IconViewBox) 19 | class IconViewBox: NSBox { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /SourceView/IconViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | View controller object to host the icon collection view. 7 | */ 8 | 9 | // notification for indicating file system content has been received 10 | extern NSString *kReceivedContentNotification; 11 | 12 | @class BaseNode; 13 | 14 | @interface IconViewController : NSViewController 15 | 16 | // This view controller can be populated two ways: 17 | // file system url, or from a BaseNode of internet shortcuts 18 | // 19 | @property (readwrite, strong) NSURL *url; 20 | @property (readwrite, strong) BaseNode *baseNode; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /SourceView/IconViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | View controller object to host the icon collection view. 7 | */ 8 | 9 | #import "IconViewController.h" 10 | #import "IconViewBox.h" 11 | #import "BaseNode.h" 12 | 13 | // notification for indicating file system content has been received 14 | NSString *kReceivedContentNotification = @"ReceivedContentNotification"; 15 | 16 | @interface IconViewController () 17 | 18 | @property (readwrite, strong) NSMutableArray *icons; 19 | 20 | @end 21 | 22 | 23 | #pragma mark - 24 | 25 | @implementation IconViewController 26 | 27 | @synthesize baseNode = _baseNode; 28 | 29 | // ------------------------------------------------------------------------------- 30 | // awakeFromNib 31 | // ------------------------------------------------------------------------------- 32 | - (void)awakeFromNib 33 | { 34 | // Listen for changes in the url for this view. 35 | [self addObserver:self 36 | forKeyPath:@"url" 37 | options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) 38 | context:nil]; 39 | } 40 | 41 | // ------------------------------------------------------------------------------- 42 | // dealloc 43 | // ------------------------------------------------------------------------------- 44 | - (void)dealloc 45 | { 46 | [self removeObserver:self forKeyPath:@"url"]; 47 | } 48 | 49 | // ------------------------------------------------------------------------------- 50 | // setBaseNode:baseNode 51 | // ------------------------------------------------------------------------------- 52 | - (void)setBaseNode:(BaseNode *)baseNode 53 | { 54 | // Our base node has changed, notify ourselves to update our data source. 55 | _baseNode = baseNode; 56 | [self gatherContents:baseNode]; 57 | } 58 | 59 | // ------------------------------------------------------------------------------- 60 | // baseNode 61 | // ------------------------------------------------------------------------------- 62 | - (BaseNode *)baseNode 63 | { 64 | return _baseNode; 65 | } 66 | 67 | // ------------------------------------------------------------------------------- 68 | // updateIcons:iconArray 69 | // 70 | // The incoming object is the NSArray of file system objects to display. 71 | //------------------------------------------------------------------------------- 72 | - (void)updateIcons:(id)iconArray 73 | { 74 | self.icons = iconArray; 75 | 76 | [[NSNotificationCenter defaultCenter] postNotificationName:kReceivedContentNotification object:nil]; 77 | } 78 | 79 | // ------------------------------------------------------------------------------- 80 | // gatherContents:inObject 81 | // 82 | // Gathering the contents and their icons could be expensive. 83 | // This method is being called on a separate thread to avoid blocking the UI. 84 | // ------------------------------------------------------------------------------- 85 | - (void)gatherContents:(id)inObject 86 | { 87 | @autoreleasepool { 88 | 89 | NSMutableArray *contentArray = [[NSMutableArray alloc] init]; 90 | 91 | if ([inObject isKindOfClass:[BaseNode class]]) 92 | { 93 | // We are populating our collection view with a set of internet shortcuts from our baseNode. 94 | // 95 | NSArray *shortcuts = self.baseNode.children; 96 | for (BaseNode *node in shortcuts) 97 | { 98 | // the node's icon was set to a smaller size before, for this collection view we need to make it bigger 99 | NSImage *shortcutIcon = [node.nodeIcon copy]; 100 | shortcutIcon.size = NSMakeSize(kIconLargeImageSize, kIconLargeImageSize); 101 | 102 | [contentArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys: 103 | shortcutIcon, KEY_ICON, 104 | node.nodeTitle, KEY_NAME, 105 | nil]]; 106 | } 107 | } 108 | else 109 | { 110 | // We are populating our collection view with a file system directory URL. 111 | // 112 | NSURL *urlToDirectory = inObject; 113 | NSArray *fileURLs = [[NSFileManager defaultManager] contentsOfDirectoryAtURL:urlToDirectory 114 | includingPropertiesForKeys:@[] 115 | options:0 116 | error:nil]; 117 | if (fileURLs != nil) 118 | { 119 | for (NSURL *element in fileURLs) 120 | { 121 | NSImage *elementIcon = [[NSWorkspace sharedWorkspace] iconForFile:element.path]; 122 | 123 | // only allow visible objects 124 | NSNumber *hiddenFlag = nil; 125 | if ([element getResourceValue:&hiddenFlag forKey:NSURLIsHiddenKey error:nil]) 126 | { 127 | if (!hiddenFlag.boolValue) 128 | { 129 | NSString *elementNameStr = nil; 130 | if ([element getResourceValue:&elementNameStr forKey:NSURLLocalizedNameKey error:nil]) 131 | { 132 | // file system object is visible so add to our array 133 | [contentArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys: 134 | elementIcon, KEY_ICON, 135 | elementNameStr, KEY_NAME, 136 | nil]]; 137 | } 138 | } 139 | } 140 | } 141 | } 142 | } 143 | 144 | // call back on the main thread to update the icons in our view 145 | [self performSelectorOnMainThread:@selector(updateIcons:) withObject:contentArray waitUntilDone:YES]; 146 | } 147 | } 148 | 149 | 150 | #pragma mark - KVO 151 | 152 | // ------------------------------------------------------------------------------- 153 | // observeValueForKeyPath:ofObject:change:context 154 | // 155 | // Listen for changes in the file url. 156 | // Given a url, obtain its contents and add only the invisible items to the collection. 157 | // ------------------------------------------------------------------------------- 158 | - (void)observeValueForKeyPath:(NSString *)keyPath 159 | ofObject:(id)object 160 | change:(NSDictionary *)change 161 | context:(void *)context 162 | { 163 | // build our directory contents on a separate thread, 164 | // some portions are from disk which could get expensive depending on the size 165 | // 166 | [NSThread detachNewThreadSelector: @selector(gatherContents:) 167 | toTarget:self // we are the target 168 | withObject:self.url]; 169 | } 170 | 171 | @end 172 | -------------------------------------------------------------------------------- /SourceView/IconViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // IconViewController.swift 3 | // SourceView 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/4/5. 6 | // 7 | // 8 | /* 9 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 10 | See LICENSE.txt for this sample’s licensing information 11 | 12 | Abstract: 13 | View controller object to host the icon collection view. 14 | */ 15 | 16 | import Cocoa 17 | 18 | // notification for indicating file system content has been received 19 | let kReceivedContentNotification = "ReceivedContentNotification" 20 | 21 | // Key values for the icon view dictionary. 22 | private let KEY_NAME = "name" 23 | private let KEY_ICON = "icon" 24 | 25 | 26 | //MARK: - 27 | 28 | @objc(IconViewController) 29 | class IconViewController: NSViewController { 30 | 31 | // This view controller can be populated two ways: 32 | // file system url, or from a BaseNode of internet shortcuts 33 | // 34 | dynamic var url: URL? 35 | var baseNode: BaseNode? { 36 | didSet {didSetBaseNode(oldValue)} 37 | } 38 | 39 | @objc dynamic var icons: [[String: Any]] = [] 40 | 41 | 42 | //MARK: - 43 | 44 | // ------------------------------------------------------------------------------- 45 | // awakeFromNib 46 | // ------------------------------------------------------------------------------- 47 | override func awakeFromNib() { 48 | // Listen for changes in the url for this view. 49 | //###Neither the receiver, nor anObserver, are retained. 50 | self.addObserver(self, 51 | forKeyPath: "url", 52 | options: [.new, .old], 53 | context: nil) 54 | } 55 | 56 | // ------------------------------------------------------------------------------- 57 | // dealloc 58 | // ------------------------------------------------------------------------------- 59 | deinit { 60 | self.removeObserver(self, forKeyPath: "url") 61 | } 62 | 63 | // ------------------------------------------------------------------------------- 64 | // setBaseNode:baseNode 65 | // ------------------------------------------------------------------------------- 66 | private func didSetBaseNode(_ oldBaseNode: BaseNode?) { 67 | // Our base node has changed, notify ourselves to update our data source. 68 | self.gatherContents(baseNode!) 69 | } 70 | 71 | // ------------------------------------------------------------------------------- 72 | // updateIcons:iconArray 73 | // 74 | // The incoming object is the NSArray of file system objects to display. 75 | //------------------------------------------------------------------------------- 76 | //@objc 77 | private func updateIcons(_ iconArray: [[String: Any]]) { 78 | self.icons = iconArray 79 | 80 | NotificationCenter.default.post(name: Notification.Name(kReceivedContentNotification), object: nil) 81 | } 82 | 83 | // ------------------------------------------------------------------------------- 84 | // gatherContents:inObject 85 | // 86 | // Gathering the contents and their icons could be expensive. 87 | // This method is being called on a separate thread to avoid blocking the UI. 88 | // ------------------------------------------------------------------------------- 89 | private func gatherContents(_ inObject: Any) { 90 | autoreleasepool { 91 | 92 | var contentArray: [[String: Any]] = [] 93 | 94 | if inObject is BaseNode { 95 | // We are populating our collection view with a set of internet shortcuts from our baseNode. 96 | // 97 | let shortcuts = self.baseNode!.children 98 | for node in shortcuts { 99 | // the node's icon was set to a smaller size before, for this collection view we need to make it bigger 100 | var content: [String: Any] = [ 101 | KEY_NAME: node.nodeTitle 102 | ] 103 | if let shortcutIcon = node.nodeIcon?.copy() as! NSImage? { 104 | shortcutIcon.size = NSMakeSize(kIconLargeImageSize, kIconLargeImageSize) 105 | content[KEY_ICON] = shortcutIcon 106 | } 107 | 108 | contentArray.append(content) 109 | } 110 | } else { 111 | // We are populating our collection view with a file system directory URL. 112 | // 113 | let urlToDirectory = inObject as! URL 114 | do { 115 | let fileURLs = try FileManager.default.contentsOfDirectory(at: urlToDirectory, 116 | includingPropertiesForKeys: [], options: []) 117 | for element in fileURLs { 118 | let elementIcon = NSWorkspace.shared().icon(forFile: element.path) 119 | 120 | // only allow visible objects 121 | let resource = try element.resourceValues(forKeys: [.isHiddenKey, .localizedNameKey]) 122 | let isHidden = resource.isHidden! 123 | if !isHidden { 124 | let elementNameStr = resource.localizedName! 125 | // file system object is visible so add to our array 126 | contentArray.append([ 127 | KEY_ICON: elementIcon, 128 | KEY_NAME: elementNameStr 129 | ]) 130 | } 131 | } 132 | } catch _ {} 133 | } 134 | 135 | // call back on the main thread to update the icons in our view 136 | //### Seems DispatchQueue.main.sync does not work as performSelector(onMainThread:with:waitUntilDone:) 137 | //### DispatchQueue.main.async does not `waitUntilDone`, but enough for updating icons... 138 | DispatchQueue.main.async { 139 | self.updateIcons(contentArray) 140 | } 141 | // self.performSelector(onMainThread: #selector(updateIcons(_:)), with: contentArray, waitUntilDone: true) 142 | } 143 | } 144 | 145 | 146 | //MARK: - KVO 147 | 148 | // ------------------------------------------------------------------------------- 149 | // observeValueForKeyPath:ofObject:change:context 150 | // 151 | // Listen for changes in the file url. 152 | // Given a url, obtain its contents and add only the invisible items to the collection. 153 | // ------------------------------------------------------------------------------- 154 | override func observeValue(forKeyPath keyPath: String?, 155 | of object: Any?, 156 | change: [NSKeyValueChangeKey : Any]?, 157 | context: UnsafeMutableRawPointer?) 158 | { 159 | // build our directory contents on a separate thread, 160 | // some portions are from disk which could get expensive depending on the size 161 | // 162 | DispatchQueue.global(qos: .default).async { 163 | self.gatherContents(self.url!) 164 | } 165 | } 166 | 167 | } 168 | -------------------------------------------------------------------------------- /SourceView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 9.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSMinimumSystemVersion 24 | ${MACOSX_DEPLOYMENT_TARGET} 25 | NSAppTransportSecurity 26 | 27 | NSAllowsArbitraryLoads 28 | 29 | 30 | NSMainStoryboardFile 31 | Main 32 | NSPrincipalClass 33 | NSApplication 34 | 35 | 36 | -------------------------------------------------------------------------------- /SourceView/MyOutlineViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | The master view controller containing the NSOutlineView and NSTreeController. 7 | */ 8 | 9 | @interface MyOutlineViewController : NSViewController 10 | 11 | @property (nonatomic, strong) IBOutlet NSTreeController *treeController; 12 | 13 | // Used to instruct which view controller to use as the detail when the outline view item is selected. 14 | - (NSViewController *)viewControllerForSelection:(NSArray *)selection; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /SourceView/MyOutlineViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | The master view controller containing the NSOutlineView and NSTreeController. 7 | */ 8 | 9 | #import "MyOutlineViewController.h" 10 | #import "ChildNode.h" 11 | 12 | #import "IconViewController.h" 13 | #import "ChildEditViewController.h" 14 | #import "FileViewController.h" 15 | #import "WebViewController.h" 16 | 17 | #import "SeparatorView.h" 18 | #import "PrimaryViewController.h" 19 | 20 | #define INITIAL_INFODICT @"Outline" // name of the dictionary file to populate our outline view 21 | 22 | #define ICONVIEW_IDENTIFIER @"IconViewController" // storyboard identifier for the icon view 23 | #define FILEVIEW_IDENTIFIER @"FileViewController" // storyboard identifier for the file view 24 | #define WEBVIEW_IDENTIFIER @"WebViewController" // storyboard identifier for the web view 25 | 26 | #define CHILDEDIT_IDENTIFIER @"ChildEditWindowController" // storyboard identifier the child edit window controller 27 | 28 | #define SEPARATOR_VIEW @"Separator" 29 | 30 | // keys in our disk-based dictionary representing our outline view's data 31 | #define KEY_NAME @"name" 32 | #define KEY_URL @"url" 33 | #define KEY_SEPARATOR @"separator" 34 | #define KEY_GROUP @"group" 35 | #define KEY_FOLDER @"folder" 36 | #define KEY_ENTRIES @"entries" 37 | 38 | #define kNodesPBoardType @"myNodesPBoardType" // drag and drop pasteboard type 39 | 40 | 41 | #pragma mark - 42 | 43 | // ------------------------------------------------------------------------------- 44 | // TreeAdditionObj 45 | // 46 | // This object is used for passing data between the main and secondary thread 47 | // which populates the outline view. 48 | // ------------------------------------------------------------------------------- 49 | @interface TreeAdditionObj : NSObject 50 | 51 | @property (unsafe_unretained, readonly) NSIndexPath *indexPath; 52 | @property (unsafe_unretained, readonly) NSURL *nodeURL; 53 | @property (unsafe_unretained, readonly) NSString *nodeName; 54 | @property (readonly) BOOL selectItsParent; 55 | 56 | @end 57 | 58 | 59 | #pragma mark - 60 | 61 | @implementation TreeAdditionObj 62 | 63 | // ------------------------------------------------------------------------------- 64 | // initWithURL:url:name:select 65 | // ------------------------------------------------------------------------------- 66 | - (instancetype)initWithURL:(NSURL *)url withName:(NSString *)name selectItsParent:(BOOL)select 67 | { 68 | self = [super init]; 69 | 70 | _nodeName = name; 71 | _nodeURL = url; 72 | _selectItsParent = select; 73 | 74 | return self; 75 | } 76 | 77 | @end 78 | 79 | 80 | #pragma mark - 81 | 82 | @interface MyOutlineViewController () 83 | 84 | @property (nonatomic, weak) IBOutlet NSOutlineView *myOutlineView; 85 | @property (nonatomic, weak) IBOutlet NSView *placeHolderView; 86 | 87 | @property (nonatomic, strong) NSArray *dragNodesArray; // used to keep track of dragged nodes 88 | @property (nonatomic, strong) NSMutableArray *contents; // used to keep track of dragged nodes 89 | 90 | @property (nonatomic, strong) IconViewController *iconViewController; 91 | @property (nonatomic, strong) FileViewController *fileViewController; 92 | @property (nonatomic, strong) WebViewController *webViewController; 93 | 94 | @property (nonatomic, strong) NSWindowController *childEditWindowController; 95 | 96 | @end 97 | 98 | 99 | #pragma mark - 100 | 101 | @implementation MyOutlineViewController 102 | 103 | - (void)viewDidLoad 104 | { 105 | [super viewDidLoad]; 106 | 107 | _contents = [[NSMutableArray alloc] init]; 108 | 109 | // load the icon view controller for later use 110 | _iconViewController = [self.storyboard instantiateControllerWithIdentifier:ICONVIEW_IDENTIFIER]; 111 | self.iconViewController.view.translatesAutoresizingMaskIntoConstraints = NO; 112 | 113 | // load the file view controller for later use 114 | _fileViewController = [self.storyboard instantiateControllerWithIdentifier:FILEVIEW_IDENTIFIER]; 115 | self.fileViewController.view.translatesAutoresizingMaskIntoConstraints = NO; 116 | 117 | // load the web view controller for later use 118 | _webViewController = [self.storyboard instantiateControllerWithIdentifier:WEBVIEW_IDENTIFIER]; 119 | self.webViewController.view.translatesAutoresizingMaskIntoConstraints = NO; 120 | 121 | // load the child edit view controller for later use 122 | _childEditWindowController = [self.storyboard instantiateControllerWithIdentifier:CHILDEDIT_IDENTIFIER]; 123 | 124 | [self populateOutlineContents]; 125 | 126 | // scroll to the top in case the outline contents is very long 127 | self.myOutlineView.enclosingScrollView.verticalScroller.floatValue = 0.0; 128 | [self.myOutlineView.enclosingScrollView.contentView scrollToPoint:NSMakePoint(0,0)]; 129 | 130 | // make our outline view appear with gradient selection, and behave like the Finder, iTunes, etc. 131 | self.myOutlineView.selectionHighlightStyle = NSTableViewSelectionHighlightStyleSourceList; 132 | 133 | // drag and drop support 134 | [self.myOutlineView registerForDraggedTypes:@[kNodesPBoardType, // our internal drag type 135 | NSURLPboardType, // single url from pasteboard 136 | NSFilenamesPboardType, // from Safari or Finder 137 | NSFilesPromisePboardType]]; 138 | 139 | // notification to add a folder 140 | [[NSNotificationCenter defaultCenter] addObserver:self 141 | selector:@selector(addFolder:) 142 | name:kAddFolderNotification 143 | object:nil]; 144 | // notification to remove a folder 145 | [[NSNotificationCenter defaultCenter] addObserver:self 146 | selector:@selector(removeFolder:) 147 | name:kRemoveFolderNotification 148 | object:nil]; 149 | 150 | // notification to add a bookmark 151 | [[NSNotificationCenter defaultCenter] addObserver:self 152 | selector:@selector(addBookmark:) 153 | name:kAddBookmarkNotification 154 | object:nil]; 155 | 156 | // notification to edit a bookmark 157 | [[NSNotificationCenter defaultCenter] addObserver:self 158 | selector:@selector(editBookmark:) 159 | name:kEditBookmarkNotification 160 | object:nil]; 161 | } 162 | 163 | // ------------------------------------------------------------------------------- 164 | // dealloc 165 | // ------------------------------------------------------------------------------- 166 | - (void)dealloc 167 | { 168 | [[NSNotificationCenter defaultCenter] removeObserver:self name:kAddFolderNotification object:nil]; 169 | [[NSNotificationCenter defaultCenter] removeObserver:self name:kRemoveFolderNotification object:nil]; 170 | [[NSNotificationCenter defaultCenter] removeObserver:self name:kAddBookmarkNotification object:nil]; 171 | [[NSNotificationCenter defaultCenter] removeObserver:self name:kEditBookmarkNotification object:nil]; 172 | } 173 | 174 | 175 | #pragma mark - Actions 176 | 177 | // ------------------------------------------------------------------------------- 178 | // selectParentFromSelection 179 | // 180 | // Take the currently selected node and select its parent. 181 | // ------------------------------------------------------------------------------- 182 | - (void)selectParentFromSelection 183 | { 184 | if (self.treeController.selectedNodes.count > 0) 185 | { 186 | NSTreeNode *firstSelectedNode = self.treeController.selectedNodes[0]; 187 | NSTreeNode *parentNode = firstSelectedNode.parentNode; 188 | if (parentNode) 189 | { 190 | // select the parent 191 | NSIndexPath *parentIndex = parentNode.indexPath; 192 | [self.treeController setSelectionIndexPath:parentIndex]; 193 | } 194 | else 195 | { 196 | // no parent exists (we are at the top of tree), so make no selection in our outline 197 | NSArray *selectionIndexPaths = self.treeController.selectionIndexPaths; 198 | [self.treeController removeSelectionIndexPaths:selectionIndexPaths]; 199 | } 200 | } 201 | } 202 | 203 | // ------------------------------------------------------------------------------- 204 | // performAddFolder:treeAddition 205 | // ------------------------------------------------------------------------------- 206 | - (void)performAddFolder:(TreeAdditionObj *)treeAddition 207 | { 208 | // NSTreeController inserts objects using NSIndexPath, so we need to calculate this 209 | NSIndexPath *indexPath = nil; 210 | 211 | // if there is no selection, we will add a new group to the end of the contents array 212 | if (self.treeController.selectedObjects.count == 0) 213 | { 214 | // there's no selection so add the folder to the top-level and at the end 215 | indexPath = [NSIndexPath indexPathWithIndex:self.contents.count]; 216 | } 217 | else 218 | { 219 | // get the index of the currently selected node, then add the number its children to the path - 220 | // this will give us an index which will allow us to add a node to the end of the currently selected node's children array. 221 | // 222 | indexPath = self.treeController.selectionIndexPath; 223 | if ([self.treeController.selectedObjects[0] isLeaf]) 224 | { 225 | // user is trying to add a folder on a selected child, 226 | // so deselect child and select its parent for addition 227 | [self selectParentFromSelection]; 228 | } 229 | else 230 | { 231 | indexPath = [indexPath indexPathByAddingIndex:[self.treeController.selectedObjects[0] children].count]; 232 | } 233 | } 234 | 235 | ChildNode *node = [[ChildNode alloc] init]; 236 | node.nodeTitle = treeAddition.nodeName; 237 | 238 | // the user is adding a child node, tell the controller directly 239 | [self.treeController insertObject:node atArrangedObjectIndexPath:indexPath]; 240 | } 241 | 242 | // ------------------------------------------------------------------------------- 243 | // performAddChild:treeAddition 244 | // ------------------------------------------------------------------------------- 245 | - (void)performAddChild:(TreeAdditionObj *)treeAddition 246 | { 247 | if (self.treeController.selectedObjects.count > 0) 248 | { 249 | // we have a selection 250 | if ([self.treeController.selectedObjects[0] isLeaf]) 251 | { 252 | // trying to add a child to a selected leaf node, so select its parent for add 253 | [self selectParentFromSelection]; 254 | } 255 | } 256 | 257 | // find the selection to insert our node 258 | NSIndexPath *indexPath; 259 | if (self.treeController.selectedObjects.count > 0) 260 | { 261 | // we have a selection, insert at the end of the selection 262 | indexPath = self.treeController.selectionIndexPath; 263 | indexPath = [indexPath indexPathByAddingIndex:[self.treeController.selectedObjects[0] children].count]; 264 | } 265 | else 266 | { 267 | // no selection, just add the child to the end of the tree 268 | indexPath = [NSIndexPath indexPathWithIndex:self.contents.count]; 269 | } 270 | 271 | // create a leaf node 272 | ChildNode *node = [[ChildNode alloc] initLeaf];; 273 | node.url = treeAddition.nodeURL; 274 | 275 | if (treeAddition.nodeURL != nil) 276 | { 277 | // the child to insert has a valid URL, use its display name as the node title 278 | if (treeAddition.nodeName) 279 | { 280 | node.nodeTitle = treeAddition.nodeName; 281 | } 282 | else 283 | { 284 | node.nodeTitle = [[NSFileManager defaultManager] displayNameAtPath:node.url.absoluteString]; 285 | } 286 | } 287 | 288 | // the user is adding a child node, tell the controller directly 289 | [self.treeController insertObject:node atArrangedObjectIndexPath:indexPath]; 290 | 291 | // adding a child automatically becomes selected by NSOutlineView, so keep its parent selected 292 | if (treeAddition.selectItsParent) 293 | { 294 | [self selectParentFromSelection]; 295 | } 296 | } 297 | 298 | // ------------------------------------------------------------------------------- 299 | // addChild:url:withName:selectParent 300 | // ------------------------------------------------------------------------------- 301 | - (void)addChild:(NSURL *)url withName:(NSString *)nameStr selectParent:(BOOL)select 302 | { 303 | TreeAdditionObj *treeObjInfo = [[TreeAdditionObj alloc] initWithURL:url 304 | withName:nameStr 305 | selectItsParent:select]; 306 | [self performAddChild:treeObjInfo]; 307 | } 308 | 309 | // ------------------------------------------------------------------------------- 310 | // addEntries:discloseParent: 311 | // ------------------------------------------------------------------------------- 312 | - (void)addEntries:(NSDictionary *)entries discloseParent:(BOOL)discloseParent 313 | { 314 | for (id entry in entries) 315 | { 316 | if ([entry isKindOfClass:[NSDictionary class]]) 317 | { 318 | NSString *urlStr = entry[KEY_URL]; 319 | NSURL *url = [NSURL URLWithString:urlStr]; 320 | if (entry[KEY_SEPARATOR]) 321 | { 322 | // its a separator mark, we treat is as a leaf 323 | [self addChild:nil withName:nil selectParent:YES]; 324 | } 325 | else if (entry[KEY_FOLDER]) 326 | { 327 | // we treat file system folders as a leaf and show its contents in the NSCollectionView 328 | NSString *folderName = entry[KEY_FOLDER]; 329 | [self addChild:url withName:folderName selectParent:YES]; 330 | } 331 | else if (entry[KEY_URL]) 332 | { 333 | // its a leaf item with a URL 334 | NSString *nameStr = entry[KEY_NAME]; 335 | [self addChild:url withName:nameStr selectParent:YES]; 336 | } 337 | else 338 | { 339 | // it's a generic container 340 | NSString *folderName = entry[KEY_GROUP]; 341 | [self addFolderWithName:folderName]; 342 | 343 | // add its children 344 | NSDictionary *newChildren = entry[KEY_ENTRIES]; 345 | [self addEntries:newChildren discloseParent:NO]; 346 | 347 | [self selectParentFromSelection]; 348 | } 349 | } 350 | } 351 | 352 | if (!discloseParent) 353 | { 354 | // inserting children automatically expands its parent, we want to close it 355 | if (self.treeController.selectedNodes.count > 0) 356 | { 357 | NSTreeNode *lastSelectedNode = self.treeController.selectedNodes[0]; 358 | [self.myOutlineView collapseItem:lastSelectedNode]; 359 | } 360 | } 361 | } 362 | 363 | // ------------------------------------------------------------------------------- 364 | // addBookmarksSection 365 | // 366 | // Populate the tree controller from disk-based dictionary (Outline.dict) 367 | // ------------------------------------------------------------------------------- 368 | - (void)addBookmarksSection 369 | { 370 | // add the "Bookmarks" section 371 | [self addFolderWithName:[BaseNode bookmarksName]]; 372 | 373 | // add its content (contant determined our dictionary file) 374 | NSDictionary *initData = [NSDictionary dictionaryWithContentsOfFile: 375 | [[NSBundle mainBundle] pathForResource:INITIAL_INFODICT ofType:@"dict"]]; 376 | NSDictionary *entries = initData[KEY_ENTRIES]; 377 | [self addEntries:entries discloseParent:YES]; 378 | 379 | [self selectParentFromSelection]; 380 | } 381 | 382 | // ------------------------------------------------------------------------------- 383 | // addPlacesSection 384 | // ------------------------------------------------------------------------------- 385 | - (void)addPlacesSection 386 | { 387 | // add the "Places" section 388 | [self addFolderWithName:[BaseNode placesName]]; 389 | 390 | // add its children (contents of the Home directory) 391 | [self addChild:[NSURL fileURLWithPath:NSHomeDirectory()] withName:@"Home" selectParent:YES]; 392 | 393 | NSArray *appsDirectory = NSSearchPathForDirectoriesInDomains(NSApplicationDirectory, NSLocalDomainMask, YES); 394 | [self addChild:[NSURL fileURLWithPath:appsDirectory[0]] withName:nil selectParent:YES]; 395 | 396 | [self selectParentFromSelection]; 397 | } 398 | 399 | // ------------------------------------------------------------------------------- 400 | // populateOutlineContents 401 | // ------------------------------------------------------------------------------- 402 | - (void)populateOutlineContents 403 | { 404 | // hide the outline view - don't show it as we are building the content 405 | [self.myOutlineView setHidden:YES]; 406 | 407 | [self addPlacesSection]; // add the "Places" outline section 408 | [self addBookmarksSection]; // add the "Bookmark" outline content 409 | 410 | // remove the current selection 411 | NSArray *selection = self.treeController.selectionIndexPaths; 412 | [self.treeController removeSelectionIndexPaths:selection]; 413 | 414 | [self.myOutlineView setHidden:NO]; // we are done populating the outline view content, show it again 415 | } 416 | 417 | 418 | #pragma mark - Notifications 419 | 420 | // ------------------------------------------------------------------------------- 421 | // addFolder:folderName 422 | // ------------------------------------------------------------------------------- 423 | - (void)addFolderWithName:(NSString *)folderName 424 | { 425 | TreeAdditionObj *treeObjInfo = [[TreeAdditionObj alloc] initWithURL:nil withName:folderName selectItsParent:NO]; 426 | [self performAddFolder:treeObjInfo]; 427 | } 428 | 429 | // ------------------------------------------------------------------------------- 430 | // addFolder:notif 431 | // 432 | // Notification sent from PrimaryViewController class, to add a folder. 433 | // ------------------------------------------------------------------------------- 434 | - (void)addFolder:(NSNotification *)notif 435 | { 436 | [self addFolderWithName:[BaseNode untitledName]]; 437 | } 438 | 439 | // ------------------------------------------------------------------------------- 440 | // removeFolder:notif 441 | // 442 | // Notification sent from PrimaryViewController class, to remove a folder. 443 | // ------------------------------------------------------------------------------- 444 | - (void)removeFolder:(NSNotification *)notif 445 | { 446 | [self.treeController remove:self]; 447 | } 448 | 449 | // ------------------------------------------------------------------------------- 450 | // addBookmark:notif 451 | // 452 | // Notification sent from PrimaryViewController class, to add a bookmark 453 | // ------------------------------------------------------------------------------- 454 | - (void)addBookmark:(NSNotification *)notif 455 | { 456 | ChildEditViewController *childEditViewController = (ChildEditViewController *)self.childEditWindowController.contentViewController; 457 | childEditViewController.savedValues = @{kName_Key:[BaseNode untitledName], kURL_Key:HTTP_PREFIX}; 458 | 459 | [self.view.window beginSheet:self.childEditWindowController.window completionHandler:^(NSModalResponse returnCode) { 460 | if (returnCode == NSModalResponseOK) 461 | { 462 | NSString *itemStr = childEditViewController.savedValues[kName_Key]; 463 | [self addChild:childEditViewController.savedValues[kURL_Key] 464 | withName:(itemStr.length > 0) ? childEditViewController.savedValues[kName_Key] : [BaseNode untitledName] 465 | selectParent:NO]; // add empty untitled child 466 | } 467 | }]; 468 | } 469 | 470 | // ------------------------------------------------------------------------------- 471 | // editBookmark:notif 472 | // 473 | // Notification sent from PrimaryViewController class, to edit a bookmark 474 | // ------------------------------------------------------------------------------- 475 | - (void)editBookmark:(NSNotification *)notif 476 | { 477 | ChildEditViewController *childEditViewController = (ChildEditViewController *)self.childEditWindowController.contentViewController; 478 | 479 | // get the selected item's name and url 480 | NSArray *selection = self.treeController.selectedObjects; 481 | ChildNode *node = selection[0]; 482 | 483 | if (node.url == nil && !node.isBookmark) 484 | { 485 | // it's a folder or a file-system based object, just allow editing the cell title 486 | NSInteger selectedRow = self.myOutlineView.selectedRow; 487 | [self.myOutlineView editColumn:0 row:selectedRow withEvent:NSApp.currentEvent select:YES]; 488 | } 489 | else 490 | { 491 | childEditViewController.savedValues = @{kName_Key:node.nodeTitle, kURL_Key:node.url}; 492 | [self.view.window beginSheet:self.childEditWindowController.window completionHandler:^(NSModalResponse returnCode) { 493 | if (returnCode == NSModalResponseOK) 494 | { 495 | // create a child node 496 | ChildNode *childNode = [[ChildNode alloc] initLeaf]; 497 | childNode.url = childEditViewController.savedValues[kURL_Key]; 498 | NSString *newNodeStr = childEditViewController.savedValues[kName_Key]; 499 | childNode.nodeTitle = (newNodeStr.length > 0) ? newNodeStr : [BaseNode untitledName]; 500 | 501 | // remove the current selection and replace it with the newly edited child 502 | NSIndexPath *indexPath = self.treeController.selectionIndexPath; 503 | [self.treeController remove:self]; 504 | [self.treeController insertObject:childNode atArrangedObjectIndexPath:indexPath]; 505 | } 506 | }]; 507 | } 508 | } 509 | 510 | 511 | #pragma mark - Managing Views 512 | 513 | // ------------------------------------------------------------------------------- 514 | // viewControllerForSelection:selection 515 | // ------------------------------------------------------------------------------- 516 | - (NSViewController *)viewControllerForSelection:(NSArray *)selection 517 | { 518 | NSViewController *returnViewController = nil; 519 | 520 | if (selection != nil && selection.count == 1) 521 | { 522 | BaseNode *node = [selection[0] representedObject]; 523 | 524 | if (node.url != nil) 525 | { 526 | if (node.isBookmark) 527 | { 528 | // it's a bookmark, 529 | // return a view controller with a web view, retarget with "urlStr" 530 | // 531 | WebView *webView = (WebView *)self.webViewController.view; 532 | webView.mainFrameURL = node.url.absoluteString; // re-target to the new url 533 | 534 | returnViewController = self.webViewController; 535 | } 536 | else 537 | { 538 | // detect if the url is a directory 539 | if (node.isDirectory) 540 | { 541 | // it's a folder 542 | self.iconViewController.url = node.url; 543 | returnViewController = self.iconViewController; 544 | } 545 | else 546 | { 547 | // it's a file 548 | self.fileViewController.url = node.url; 549 | returnViewController = self.fileViewController; 550 | } 551 | } 552 | } 553 | else 554 | { 555 | // it's a non-file system grouping of shortcuts 556 | self.iconViewController.baseNode = node; 557 | returnViewController = self.iconViewController; 558 | } 559 | } 560 | else 561 | { 562 | // no view controller (no selection) 563 | } 564 | 565 | return returnViewController; 566 | } 567 | 568 | 569 | #pragma mark - NSOutlineViewDelegate 570 | 571 | // ------------------------------------------------------------------------------- 572 | // shouldSelectItem:item 573 | // ------------------------------------------------------------------------------- 574 | - (BOOL)outlineView:(NSOutlineView *)outlineView shouldSelectItem:(id)item 575 | { 576 | // don't allow special group nodes (Places and Bookmarks) to be selected 577 | BaseNode *node = [item representedObject]; 578 | return (!node.isSpecialGroup && !node.isSeparator); 579 | } 580 | 581 | // ------------------------------------------------------------------------------- 582 | // viewForTableColumn:tableColumn:item 583 | // ------------------------------------------------------------------------------- 584 | - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item 585 | { 586 | NSTableCellView *result = [outlineView makeViewWithIdentifier:tableColumn.identifier owner:self]; 587 | 588 | BaseNode *node = [item representedObject]; 589 | if (node != nil) 590 | { 591 | if ([self outlineView:outlineView isGroupItem:item]) // is it a special group (not a folder)? 592 | { 593 | // Group items are sections of our outline that can be hidden/shown (i.e. PLACES/BOOKMARKS). 594 | NSString *identifier = outlineView.tableColumns[0].identifier; 595 | result = [outlineView makeViewWithIdentifier:identifier owner:self]; 596 | NSString *value = node.nodeTitle.uppercaseString; 597 | result.textField.stringValue = value; 598 | } 599 | else if (node.isSeparator) 600 | { 601 | // Separators have no title or icon, just use the custom view to draw it. 602 | result = [outlineView makeViewWithIdentifier:@"Separator" owner:self]; 603 | } 604 | else 605 | { 606 | result.textField.stringValue = node.nodeTitle; 607 | result.imageView.image = node.nodeIcon; 608 | 609 | if (node.isLeaf) 610 | { 611 | [result.textField setEditable:YES]; // Just for fun, make leaf title's editable. 612 | } 613 | } 614 | } 615 | 616 | return result; 617 | } 618 | 619 | // ------------------------------------------------------------------------------- 620 | // textShouldEndEditing:fieldEditor 621 | // ------------------------------------------------------------------------------- 622 | - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor 623 | { 624 | // don't allow empty node names 625 | return (fieldEditor.string.length == 0 ? NO : YES); 626 | } 627 | 628 | // ---------------------------------------------------------------------------------------- 629 | // outlineView:isGroupItem:item 630 | // 631 | // Determine if the item should be a special grouping (not a folder but a group with Hide/Show buttons) 632 | // ---------------------------------------------------------------------------------------- 633 | - (BOOL)outlineView:(NSOutlineView *)outlineView isGroupItem:(id)item 634 | { 635 | BaseNode *node = [item representedObject]; 636 | return (node.isSpecialGroup ? YES : NO); 637 | } 638 | 639 | 640 | #pragma mark - NSOutlineView drag and drop 641 | 642 | // ---------------------------------------------------------------------------------------- 643 | // outlineView:writeItems:toPasteboard 644 | // ---------------------------------------------------------------------------------------- 645 | - (BOOL)outlineView:(NSOutlineView *)ov writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard 646 | { 647 | [pboard declareTypes:@[kNodesPBoardType] owner:self]; 648 | 649 | // keep track of this nodes for drag feedback in "validateDrop" 650 | self.dragNodesArray = items; 651 | 652 | return YES; 653 | } 654 | 655 | // ------------------------------------------------------------------------------- 656 | // outlineView:validateDrop:proposedItem:proposedChildrenIndex: 657 | // 658 | // This method is used by NSOutlineView to determine a valid drop target. 659 | // ------------------------------------------------------------------------------- 660 | - (NSDragOperation)outlineView:(NSOutlineView *)ov 661 | validateDrop:(id )info 662 | proposedItem:(id)item 663 | proposedChildIndex:(NSInteger)index 664 | { 665 | NSDragOperation result = NSDragOperationNone; 666 | 667 | if (item == nil) 668 | { 669 | // no item to drop on 670 | result = NSDragOperationGeneric; 671 | } 672 | else 673 | { 674 | BaseNode *node = [item representedObject]; 675 | if (node.isSpecialGroup) 676 | { 677 | // don't allow dragging into special grouped sections (i.e. Places and Bookmarks) 678 | result = NSDragOperationNone; 679 | } 680 | else 681 | { 682 | if (index == -1) 683 | { 684 | // don't allow dropping on a child 685 | result = NSDragOperationNone; 686 | } 687 | else 688 | { 689 | // drop location is a container 690 | result = NSDragOperationMove; 691 | 692 | BaseNode *dropLocation = [item representedObject]; // item we are dropping on 693 | BaseNode *draggedItem = [self.dragNodesArray[0] representedObject]; 694 | 695 | // don't allow an item to drop onto itself, or within it's content 696 | if (dropLocation == draggedItem || 697 | [dropLocation isDescendantOfNodes:@[draggedItem]]) 698 | { 699 | result = NSDragOperationNone; 700 | } 701 | } 702 | } 703 | } 704 | 705 | return result; 706 | } 707 | 708 | // ------------------------------------------------------------------------------- 709 | // handleWebURLDrops:pboard:withIndexPath: 710 | // 711 | // The user is dragging URLs from Safari. 712 | // ------------------------------------------------------------------------------- 713 | - (void)handleWebURLDrops:(NSPasteboard *)pboard withIndexPath:(NSIndexPath *)indexPath 714 | { 715 | NSArray *pbArray = [pboard propertyListForType:@"WebURLsWithTitlesPboardType"]; 716 | NSArray *urlArray = pbArray[0]; 717 | NSArray *nameArray = pbArray[1]; 718 | 719 | for (NSInteger i = (urlArray.count - 1); i >=0; i--) 720 | { 721 | ChildNode *node = [[ChildNode alloc] init]; 722 | 723 | node.isLeaf = YES; 724 | node.nodeTitle = nameArray[i]; 725 | node.url = [NSURL URLWithString:urlArray[i]]; 726 | 727 | [self.treeController insertObject:node atArrangedObjectIndexPath:indexPath]; 728 | } 729 | } 730 | 731 | // ------------------------------------------------------------------------------- 732 | // handleInternalDrops:pboard:withIndexPath: 733 | // 734 | // The user is doing an intra-app drag within the outline view. 735 | // ------------------------------------------------------------------------------- 736 | - (void)handleInternalDrops:(NSPasteboard *)pboard withIndexPath:(NSIndexPath *)indexPath 737 | { 738 | // user is doing an intra app drag within the outline view: 739 | // 740 | NSArray* newNodes = self.dragNodesArray; 741 | 742 | // move the items to their new place 743 | [self.treeController moveNodes:self.dragNodesArray toIndexPath:indexPath]; 744 | 745 | // keep the moved nodes selected 746 | NSMutableArray *indexPathList = [NSMutableArray array]; 747 | for (NSUInteger i = 0; i < newNodes.count; i++) 748 | { 749 | [indexPathList addObject:[newNodes[i] indexPath]]; 750 | } 751 | [self.treeController setSelectionIndexPaths: indexPathList]; 752 | } 753 | 754 | // ------------------------------------------------------------------------------- 755 | // handleFileBasedDrops:pboard:withIndexPath: 756 | // 757 | // The user is dragging file-system based objects (probably from Finder) 758 | // ------------------------------------------------------------------------------- 759 | - (void)handleFileBasedDrops:(NSPasteboard *)pboard withIndexPath:(NSIndexPath *)indexPath 760 | { 761 | NSArray *fileNames = [pboard propertyListForType:NSFilenamesPboardType]; 762 | if (fileNames.count > 0) 763 | { 764 | NSInteger i; 765 | NSInteger count = fileNames.count; 766 | 767 | for (i = (count - 1); i >=0; i--) 768 | { 769 | ChildNode *node = [[ChildNode alloc] init]; 770 | 771 | NSURL *url = [NSURL fileURLWithPath:fileNames[i]]; 772 | NSString *name = [[NSFileManager defaultManager] displayNameAtPath:url.path]; 773 | node.isLeaf = YES; 774 | 775 | node.nodeTitle = name; 776 | node.url = url; 777 | 778 | [self.treeController insertObject:node atArrangedObjectIndexPath:indexPath]; 779 | } 780 | } 781 | } 782 | 783 | // ------------------------------------------------------------------------------- 784 | // handleURLBasedDrops:pboard:withIndexPath: 785 | // 786 | // Handle dropping a raw URL. 787 | // ------------------------------------------------------------------------------- 788 | - (void)handleURLBasedDrops:(NSPasteboard *)pboard withIndexPath:(NSIndexPath *)indexPath 789 | { 790 | NSURL *url = [NSURL URLFromPasteboard:pboard]; 791 | if (url != nil) 792 | { 793 | ChildNode *node = [[ChildNode alloc] init]; 794 | 795 | if (url.isFileURL) 796 | { 797 | // url is file-based, use it's display name 798 | NSString *name = [[NSFileManager defaultManager] displayNameAtPath:url.path]; 799 | node.nodeTitle = name; 800 | node.url = url; 801 | } 802 | else 803 | { 804 | // url is non-file based (probably from Safari) 805 | // 806 | // the url might not end with a valid component name, use the best possible title from the URL 807 | if (url.path.pathComponents.count == 1) 808 | { 809 | if (node.isBookmark) 810 | { 811 | // use the url portion without the prefix 812 | NSRange prefixRange = [url.absoluteString rangeOfString:HTTP_PREFIX]; 813 | NSRange newRange = NSMakeRange(prefixRange.length, url.absoluteString.length- prefixRange.length - 1); 814 | node.nodeTitle = [url.absoluteString substringWithRange:newRange]; 815 | } 816 | else 817 | { 818 | // prefix unknown, just use the url as its title 819 | node.nodeTitle = url.absoluteString; 820 | } 821 | } 822 | else 823 | { 824 | // use the last portion of the URL as its title 825 | node.nodeTitle = url.path.lastPathComponent; 826 | } 827 | 828 | node.url = url; 829 | } 830 | node.isLeaf = YES; 831 | 832 | [self.treeController insertObject:node atArrangedObjectIndexPath:indexPath]; 833 | } 834 | } 835 | 836 | // ------------------------------------------------------------------------------- 837 | // outlineView:acceptDrop:item:childIndex 838 | // 839 | // This method is called when the mouse is released over an outline view that previously decided to allow a drop 840 | // via the validateDrop method. The data source should incorporate the data from the dragging pasteboard at this time. 841 | // 'index' is the location to insert the data as a child of 'item', and are the values previously set in the validateDrop: method. 842 | // 843 | // ------------------------------------------------------------------------------- 844 | - (BOOL)outlineView:(NSOutlineView*)ov acceptDrop:(id )info item:(id)targetItem childIndex:(NSInteger)index 845 | { 846 | // note that "targetItem" is a NSTreeNode proxy 847 | // 848 | BOOL result = NO; 849 | 850 | // find the index path to insert our dropped object(s) 851 | NSIndexPath *indexPath; 852 | if (targetItem != nil) 853 | { 854 | // drop down inside the tree node: 855 | // feth the index path to insert our dropped node 856 | indexPath = [[targetItem indexPath] indexPathByAddingIndex:index]; 857 | } 858 | else 859 | { 860 | // drop at the top root level 861 | if (index == -1) // drop area might be ambibguous (not at a particular location) 862 | indexPath = [NSIndexPath indexPathWithIndex:self.contents.count]; // drop at the end of the top level 863 | else 864 | indexPath = [NSIndexPath indexPathWithIndex:index]; // drop at a particular place at the top level 865 | } 866 | 867 | NSPasteboard *pboard = [info draggingPasteboard]; // get the pasteboard 868 | 869 | // check the dragging type - 870 | if ([pboard availableTypeFromArray:@[kNodesPBoardType]]) 871 | { 872 | // user is doing an intra-app drag within the outline view 873 | [self handleInternalDrops:pboard withIndexPath:indexPath]; 874 | result = YES; 875 | } 876 | else if ([pboard availableTypeFromArray:@[@"WebURLsWithTitlesPboardType"]]) 877 | { 878 | // the user is dragging URLs from Safari 879 | [self handleWebURLDrops:pboard withIndexPath:indexPath]; 880 | result = YES; 881 | } 882 | else if ([pboard availableTypeFromArray:@[NSFilenamesPboardType]]) 883 | { 884 | // the user is dragging file-system based objects (probably from Finder) 885 | [self handleFileBasedDrops:pboard withIndexPath:indexPath]; 886 | result = YES; 887 | } 888 | else if ([pboard availableTypeFromArray:@[NSURLPboardType]]) 889 | { 890 | // handle dropping a raw URL 891 | [self handleURLBasedDrops:pboard withIndexPath:indexPath]; 892 | result = YES; 893 | } 894 | 895 | return result; 896 | } 897 | 898 | @end 899 | -------------------------------------------------------------------------------- /SourceView/MySplitViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | View controller managing our split view interface. 7 | */ 8 | 9 | @interface MySplitViewController : NSSplitViewController 10 | 11 | @end 12 | -------------------------------------------------------------------------------- /SourceView/MySplitViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | View controller managing our split view interface. 7 | */ 8 | 9 | #import "MySplitViewController.h" 10 | #import "MyOutlineViewController.h" 11 | 12 | @interface MySplitViewController () 13 | 14 | @property (nonatomic, strong) NSArray *verticalConstraints; 15 | @property (nonatomic, strong) NSArray *horizontalConstraints; 16 | 17 | @end 18 | 19 | 20 | #pragma mark - 21 | 22 | @implementation MySplitViewController 23 | 24 | // ------------------------------------------------------------------------------- 25 | // viewDidAppear 26 | // ------------------------------------------------------------------------------- 27 | - (void)viewDidAppear 28 | { 29 | [super viewDidAppear]; 30 | 31 | // Note: we keep the left split view item from growing as the window grows by setting its hugging priority to 200, and the right to 199. 32 | // The view with the lowest priority will be the first to take on additional width if the split view grows or shrinks. 33 | // 34 | 35 | // listen for selection changes from the NSOutlineView inside MyOutlineViewController 36 | // note: we start observing after our outline view is populated so we don't receive unnecessary notifications at startup 37 | // 38 | [self.outlineViewController.treeController addObserver:self 39 | forKeyPath:@"selectedObjects" 40 | options:NSKeyValueObservingOptionNew 41 | context:nil]; 42 | } 43 | 44 | - (void)dealloc 45 | { 46 | // done listening for tree controller's selection 47 | [self.outlineViewController.treeController removeObserver:self forKeyPath:@"selectedObjects"]; 48 | } 49 | 50 | 51 | #pragma mark - Detail View Controller Management 52 | 53 | // ------------------------------------------------------------------------------- 54 | // outlineViewController 55 | // ------------------------------------------------------------------------------- 56 | - (MyOutlineViewController *)outlineViewController 57 | { 58 | NSSplitViewItem *leftSplitViewItem = self.splitViewItems[0]; 59 | return (MyOutlineViewController *)leftSplitViewItem.viewController; 60 | } 61 | 62 | // ------------------------------------------------------------------------------- 63 | // detailViewController 64 | // ------------------------------------------------------------------------------- 65 | - (NSViewController *)detailViewController 66 | { 67 | NSSplitViewItem *rightSplitViewItem = self.splitViewItems[1]; 68 | return (NSViewController *)rightSplitViewItem.viewController; 69 | } 70 | 71 | // ------------------------------------------------------------------------------- 72 | // hasChildViewController 73 | // ------------------------------------------------------------------------------- 74 | - (BOOL)hasChildViewController 75 | { 76 | return self.detailViewController.childViewControllers.count > 0; 77 | } 78 | 79 | // ------------------------------------------------------------------------------- 80 | // embedChildViewController:childViewController 81 | // ------------------------------------------------------------------------------- 82 | - (void)embedChildViewController:(NSViewController *)childViewController 83 | { 84 | // to embed a new child view controller we have to add it and its view, then setup auto layout contraints 85 | // 86 | NSViewController *currentDetailVC = [self detailViewController]; 87 | [currentDetailVC addChildViewController:childViewController]; 88 | [currentDetailVC.view addSubview:childViewController.view]; 89 | 90 | NSDictionary *views = @{@"targetView": childViewController.view}; 91 | _horizontalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[targetView]|" 92 | options:0 93 | metrics:0 94 | views:views]; 95 | _verticalConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[targetView]|" 96 | options:0 97 | metrics:0 98 | views:views]; 99 | 100 | [NSLayoutConstraint activateConstraints:self.horizontalConstraints]; 101 | [NSLayoutConstraint activateConstraints:self.verticalConstraints]; 102 | } 103 | 104 | // ------------------------------------------------------------------------------- 105 | // observeValueForKeyPath:ofObject:change:context 106 | // ------------------------------------------------------------------------------- 107 | - (void)observeValueForKeyPath:(NSString *)keyPath 108 | ofObject:(id)object 109 | change:(NSDictionary *)change 110 | context:(void *)context 111 | { 112 | if ([keyPath isEqualToString:@"selectedObjects"]) 113 | { 114 | NSViewController *currentDetailVC = [self detailViewController]; 115 | 116 | NSTreeController *treeController = (NSTreeController *)object; 117 | 118 | // let the outline view controller handle the selection (helps us decide which detail view to use) 119 | NSViewController *vcForDetail = [[self outlineViewController] viewControllerForSelection:treeController.selectedNodes]; 120 | if (vcForDetail != nil) 121 | { 122 | if ([self hasChildViewController] && currentDetailVC.childViewControllers[0] != vcForDetail) 123 | { 124 | // the incoming child view controller is different from the one we currently have, 125 | // remove the old one and add the new one 126 | // 127 | [currentDetailVC removeChildViewControllerAtIndex:0]; 128 | [self.detailViewController.view.subviews[0] removeFromSuperview]; 129 | 130 | [self embedChildViewController:vcForDetail]; 131 | } 132 | else 133 | { 134 | if (![self hasChildViewController]) 135 | { 136 | // we don't have a child view controller so embed the new one 137 | [self embedChildViewController:vcForDetail]; 138 | } 139 | } 140 | } 141 | else 142 | { 143 | // we don't have a child view controller to embed (no selection), so remove current child view controller 144 | if ([self hasChildViewController]) 145 | { 146 | [currentDetailVC removeChildViewControllerAtIndex:0]; 147 | [self.detailViewController.view.subviews[0] removeFromSuperview]; 148 | } 149 | } 150 | } 151 | } 152 | 153 | @end 154 | -------------------------------------------------------------------------------- /SourceView/MySplitViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MySplitViewController.swift 3 | // SourceView 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/10/24. 6 | // 7 | // 8 | /* 9 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 10 | See LICENSE.txt for this sample’s licensing information 11 | 12 | Abstract: 13 | View controller managing our split view interface. 14 | */ 15 | import Cocoa 16 | 17 | @objc(MySplitViewController) 18 | class MySplitViewController: NSSplitViewController { 19 | 20 | private var verticalConstraints: [NSLayoutConstraint] = [] 21 | private var horizontalConstraints: [NSLayoutConstraint] = [] 22 | 23 | 24 | //MARK: - 25 | 26 | // ------------------------------------------------------------------------------- 27 | // viewDidAppear 28 | // ------------------------------------------------------------------------------- 29 | override func viewDidAppear() { 30 | super.viewDidAppear() 31 | 32 | // Note: we keep the left split view item from growing as the window grows by setting its hugging priority to 200, and the right to 199. 33 | // The view with the lowest priority will be the first to take on additional width if the split view grows or shrinks. 34 | // 35 | 36 | // listen for selection changes from the NSOutlineView inside MyOutlineViewController 37 | // note: we start observing after our outline view is populated so we don't receive unnecessary notifications at startup 38 | // 39 | self.outlineViewController.treeController.addObserver(self, 40 | forKeyPath: "selectedObjects", 41 | options: .new, 42 | context: nil) 43 | } 44 | 45 | deinit { 46 | // done listening for tree controller's selection 47 | self.outlineViewController.treeController.removeObserver(self, forKeyPath: "selectedObjects") 48 | } 49 | 50 | 51 | //MARK: - Detail View Controller Management 52 | 53 | // ------------------------------------------------------------------------------- 54 | // outlineViewController 55 | // ------------------------------------------------------------------------------- 56 | private var outlineViewController: MyOutlineViewController { 57 | let leftSplitViewItem = self.splitViewItems[0] 58 | return leftSplitViewItem.viewController as! MyOutlineViewController 59 | } 60 | 61 | // ------------------------------------------------------------------------------- 62 | // detailViewController 63 | // ------------------------------------------------------------------------------- 64 | private var detailViewController: NSViewController { 65 | let rightSplitViewItem = self.splitViewItems[1] 66 | return rightSplitViewItem.viewController 67 | } 68 | 69 | // ------------------------------------------------------------------------------- 70 | // hasChildViewController 71 | // ------------------------------------------------------------------------------- 72 | private var hasChildViewController: Bool { 73 | return !self.detailViewController.childViewControllers.isEmpty 74 | } 75 | 76 | // ------------------------------------------------------------------------------- 77 | // embedChildViewController:childViewController 78 | // ------------------------------------------------------------------------------- 79 | private func embedChildViewController(_ childViewController: NSViewController) { 80 | // to embed a new child view controller we have to add it and its view, then setup auto layout contraints 81 | // 82 | let currentDetailVC = self.detailViewController 83 | currentDetailVC.addChildViewController(childViewController) 84 | currentDetailVC.view.addSubview(childViewController.view) 85 | 86 | let views = ["targetView" : childViewController.view] 87 | horizontalConstraints = NSLayoutConstraint.constraints(withVisualFormat: "H:|[targetView]|", 88 | options: [], 89 | metrics: nil, 90 | views: views) 91 | verticalConstraints = NSLayoutConstraint.constraints(withVisualFormat: "V:|[targetView]|", 92 | options: [], 93 | metrics: nil, 94 | views: views) 95 | 96 | NSLayoutConstraint.activate(self.horizontalConstraints) 97 | NSLayoutConstraint.activate(self.verticalConstraints) 98 | } 99 | 100 | // ------------------------------------------------------------------------------- 101 | // observeValueForKeyPath:ofObject:change:context 102 | // ------------------------------------------------------------------------------- 103 | override func observeValue(forKeyPath keyPath: String?, 104 | of object: Any?, 105 | change: [NSKeyValueChangeKey : Any]?, 106 | context: UnsafeMutableRawPointer?) 107 | { 108 | if keyPath == "selectedObjects" { 109 | let currentDetailVC = self.detailViewController 110 | 111 | let treeController = object as! NSTreeController 112 | 113 | // let the outline view controller handle the selection (helps us decide which detail view to use) 114 | if let vcForDetail = self.outlineViewController.viewControllerForSelection(treeController.selectedNodes) { 115 | if self.hasChildViewController && currentDetailVC.childViewControllers[0] != vcForDetail { 116 | // the incoming child view controller is different from the one we currently have, 117 | // remove the old one and add the new one 118 | // 119 | currentDetailVC.removeChildViewController(at: 0) 120 | self.detailViewController.view.subviews[0].removeFromSuperview() 121 | 122 | self.embedChildViewController(vcForDetail) 123 | } else { 124 | if !self.hasChildViewController { 125 | // we don't have a child view controller so embed the new one 126 | self.embedChildViewController(vcForDetail) 127 | } 128 | } 129 | } else { 130 | // we don't have a child view controller to embed (no selection), so remove current child view controller 131 | if self.hasChildViewController { 132 | currentDetailVC.removeChildViewController(at: 0) 133 | self.detailViewController.view.subviews[0].removeFromSuperview() 134 | } 135 | } 136 | } 137 | } 138 | 139 | } 140 | -------------------------------------------------------------------------------- /SourceView/MyWindowController.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | The primary or main window controller class for this sample. 7 | */ 8 | 9 | @interface MyWindowController : NSWindowController 10 | 11 | @end 12 | -------------------------------------------------------------------------------- /SourceView/MyWindowController.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | The primary or main window controller class for this sample. 7 | */ 8 | 9 | #import "MyWindowController.h" 10 | 11 | @implementation MyWindowController 12 | 13 | - (void)windowDidLoad 14 | { 15 | [super windowDidLoad]; 16 | 17 | // do anything else here at load time 18 | } 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /SourceView/MyWindowController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MyWindowController.swift 3 | // SourceView 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/4/6. 6 | // 7 | // 8 | /* 9 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 10 | See LICENSE.txt for this sample’s licensing information 11 | 12 | Abstract: 13 | The primary or main window controller class for this sample. 14 | */ 15 | 16 | import Cocoa 17 | 18 | @objc(MyWindowController) 19 | class MyWindowController: NSWindowController { 20 | 21 | override func windowDidLoad() { 22 | super.windowDidLoad() 23 | 24 | // do anything else here at load time 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /SourceView/Outline.dict: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | entries 6 | 7 | 8 | 9 | group 10 | Apple Sites 11 | entries 12 | 13 | 14 | name 15 | Apple Inc. 16 | url 17 | http://www.apple.com 18 | 19 | 20 | name 21 | macOS 22 | url 23 | http://www.apple.com/macosx/ 24 | 25 | 26 | name 27 | iTunes 28 | url 29 | http://www.apple.com/itunes/ 30 | 31 | 32 | 33 | group 34 | More 35 | entries 36 | 37 | 38 | name 39 | Apple Store 40 | url 41 | http://store.apple.com/ 42 | 43 | 44 | name 45 | Mac 46 | url 47 | https://www.apple.com/mac/ 48 | 49 | 50 | 51 | 52 | 53 | name 54 | Apple Downloads 55 | url 56 | http://www.apple.com/downloads/ 57 | 58 | 59 | 60 | 61 | 62 | 63 | separator 64 | 65 | 66 | 67 | 68 | group 69 | Google Sites 70 | entries 71 | 72 | 73 | name 74 | Google 75 | url 76 | http://www.google.com 77 | 78 | 79 | name 80 | Google Maps 81 | url 82 | http://www.googlemaps.com 83 | 84 | 85 | name 86 | Google Images 87 | url 88 | http://images.google.com/ 89 | 90 | 91 | 92 | 93 | 94 | group 95 | AT&T 96 | entries 97 | 98 | 99 | name 100 | AT&T 101 | url 102 | http://www.att.com 103 | 104 | 105 | name 106 | iPhone Center 107 | url 108 | http://www.att.com/wireless/iphone 109 | 110 | 111 | name 112 | AT&T Retail 113 | url 114 | https://www.att.com/maps/store-locator.html 115 | 116 | 117 | 118 | 119 | 120 | name 121 | Yahoo! 122 | url 123 | http://www.yahoo.com/ 124 | 125 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /SourceView/Prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | @import Cocoa; 3 | @import Foundation; 4 | #endif 5 | 6 | #define HTTP_PREFIX @"http://" -------------------------------------------------------------------------------- /SourceView/PrimaryViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | View controller containing the lower UI controls and the embedded child view controller (split view controller). 7 | */ 8 | 9 | // notification to instruct MyOutlineViewController to add a folder 10 | extern NSString *kAddFolderNotification; 11 | extern NSString *kRemoveFolderNotification; 12 | extern NSString *kAddBookmarkNotification; 13 | extern NSString *kEditBookmarkNotification; 14 | 15 | @interface PrimaryViewController : NSViewController 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /SourceView/PrimaryViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | View controller containing the lower UI controls and the embedded child view controller (split view controller). 7 | */ 8 | 9 | #import "PrimaryViewController.h" 10 | #import "IconViewController.h" 11 | #import "BaseNode.h" 12 | 13 | // notification to instruct MyOutlineViewController to add a folder 14 | NSString *kAddFolderNotification = @"AddFolderNotification"; 15 | 16 | // notification to instruct MyOutlineViewController to remove a folder 17 | NSString *kRemoveFolderNotification = @"RemoveFolderNotification"; 18 | 19 | // notification to instruct MyOutlineViewController to add a bookmark 20 | NSString *kAddBookmarkNotification = @"AddBookmarkNotification"; 21 | 22 | // notification to instruct MyOutlineViewController to edit a bookmark 23 | NSString *kEditBookmarkNotification = @"EditBookmarkNotification"; 24 | 25 | @interface PrimaryViewController () 26 | 27 | @property (nonatomic, weak) IBOutlet NSProgressIndicator *progIndicator; 28 | @property (nonatomic, weak) IBOutlet NSButton *removeButton; 29 | @property (nonatomic, weak) IBOutlet NSPopUpButton *actionButton; 30 | @property (nonatomic, weak) IBOutlet NSTextField *urlField; 31 | @property (nonatomic, strong) IBOutlet NSMenuItem *editBookmarkMenuItem; 32 | 33 | @end 34 | 35 | #pragma mark - 36 | 37 | @implementation PrimaryViewController 38 | 39 | 40 | // ------------------------------------------------------------------------------- 41 | // viewDidLoad 42 | // ------------------------------------------------------------------------------- 43 | - (void)viewDidLoad 44 | { 45 | // Note: we keep the left split view item from growing as the window grows by setting its hugging priority to 200, 46 | // and the right to 199. The view with the lowest priority will be the first to take on additional width if the 47 | // split view grows or shrinks. 48 | // 49 | [super viewDidLoad]; 50 | 51 | // insert an empty menu item at the beginning of the drown down button's menu and add its image 52 | NSImage *actionImage = [NSImage imageNamed:NSImageNameActionTemplate]; 53 | actionImage.size = NSMakeSize(10,10); 54 | 55 | NSMenuItem *menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; 56 | [self.actionButton.menu insertItem:menuItem atIndex:0]; 57 | menuItem.image = actionImage; 58 | 59 | [self.actionButton.menu setAutoenablesItems:NO]; 60 | 61 | // start off by disabling the Edit... menu item until we are notified of a selection 62 | self.editBookmarkMenuItem.enabled = NO; 63 | 64 | // truncate to the middle if the url is too long to fit 65 | self.urlField.cell.lineBreakMode = NSLineBreakByTruncatingMiddle; 66 | } 67 | 68 | // ------------------------------------------------------------------------------- 69 | // viewWillAppear 70 | // ------------------------------------------------------------------------------- 71 | - (void)viewWillAppear 72 | { 73 | [super viewWillAppear]; 74 | 75 | // listen for selection changes from the NSOutlineView inside MyOutlineViewController 76 | // note: we start observing after our outline view is populated so we don't receive unnecessary notifications at startup 77 | // 78 | [[NSNotificationCenter defaultCenter] addObserver:self 79 | selector:@selector(selectionDidChange:) 80 | name:NSOutlineViewSelectionDidChangeNotification 81 | object:nil]; 82 | 83 | // notification so we know when the icon view controller is done populating its content 84 | [[NSNotificationCenter defaultCenter] addObserver:self 85 | selector:@selector(contentReceived:) 86 | name:kReceivedContentNotification 87 | object:nil]; 88 | } 89 | 90 | // ------------------------------------------------------------------------------- 91 | // dealloc 92 | // ------------------------------------------------------------------------------- 93 | - (void)dealloc 94 | { 95 | [[NSNotificationCenter defaultCenter] removeObserver:self name:NSOutlineViewSelectionDidChangeNotification object:nil]; 96 | [[NSNotificationCenter defaultCenter] removeObserver:self name:kReceivedContentNotification object:nil]; 97 | } 98 | 99 | 100 | #pragma mark - NSNotifications 101 | 102 | // ------------------------------------------------------------------------------- 103 | // contentReceived:notif 104 | // 105 | // Notification sent from IconViewController class, 106 | // indicating the file system content has been received 107 | // ------------------------------------------------------------------------------- 108 | - (void)contentReceived:(NSNotification *)notif 109 | { 110 | self.progIndicator.hidden = YES; 111 | [self.progIndicator stopAnimation:self]; 112 | } 113 | 114 | // ------------------------------------------------------------------------------- 115 | // Listens for changes outline view row selection 116 | // ------------------------------------------------------------------------------- 117 | - (void)selectionDidChange:(NSNotification *)notification 118 | { 119 | // examine the current selection and adjust the UI 120 | // 121 | NSOutlineView *outlineView = notification.object; 122 | NSInteger selectedRow = outlineView.selectedRow; 123 | if (selectedRow == -1) 124 | { 125 | // there is no current selection - no item to display 126 | self.removeButton.enabled = NO; 127 | self.urlField.stringValue = @""; 128 | self.editBookmarkMenuItem.enabled = NO; 129 | } 130 | else 131 | { 132 | // single selection only 133 | self.removeButton.enabled = YES; 134 | 135 | // report the URL to our NSTextField 136 | BaseNode *item = [[outlineView itemAtRow:selectedRow] representedObject]; 137 | 138 | if (item.isBookmark) 139 | { 140 | self.urlField.stringValue = (item.url != nil) ? item.url.absoluteString : @""; 141 | } 142 | else 143 | { 144 | 145 | self.urlField.stringValue = (item.url != nil) ? item.url.path : @""; 146 | } 147 | 148 | // enable the Edit... menu item if the selected node is a bookmark 149 | self.editBookmarkMenuItem.enabled = (item.url != nil) && !item.url.fileURL; 150 | 151 | if (item.isDirectory) 152 | { 153 | // we are populating the detail view controler with contents of a folder on disk 154 | // (may take a while) 155 | self.progIndicator.hidden = NO; 156 | } 157 | } 158 | } 159 | 160 | 161 | #pragma mark - Folders 162 | 163 | // ------------------------------------------------------------------------------- 164 | // addFolderAction:sender: 165 | // ------------------------------------------------------------------------------- 166 | - (IBAction)addFolderAction:(id)sender 167 | { 168 | // post notification to MyOutlineViewController to add a new folder 169 | [[NSNotificationCenter defaultCenter] postNotificationName:kAddFolderNotification object:nil]; 170 | } 171 | 172 | // ------------------------------------------------------------------------------- 173 | // removeFolderAction:sender: 174 | // ------------------------------------------------------------------------------- 175 | - (IBAction)removeFolderAction:(id)sender 176 | { 177 | NSAlert *alert = [[NSAlert alloc] init]; 178 | alert.messageText = NSLocalizedString(@"Are you sure you want to remove this item?", @""); 179 | [alert addButtonWithTitle:NSLocalizedString(@"OK", @"")]; 180 | [alert addButtonWithTitle:NSLocalizedString(@"Cancel", @"")]; 181 | [alert beginSheetModalForWindow:self.view.window completionHandler:^(NSModalResponse returnCode) { 182 | if (returnCode == NSAlertFirstButtonReturn) 183 | { 184 | // post notification to MyOutlineViewController to remove the selected folder 185 | [[NSNotificationCenter defaultCenter] postNotificationName:kRemoveFolderNotification object:nil]; 186 | } 187 | }]; 188 | } 189 | 190 | 191 | #pragma mark - Bookmarks 192 | 193 | // ------------------------------------------------------------------------------- 194 | // addBookmarkAction:sender 195 | // ------------------------------------------------------------------------------- 196 | - (IBAction)addBookmarkAction:(id)sender 197 | { 198 | // post notification to MyOutlineViewController to add a new bookmark 199 | [[NSNotificationCenter defaultCenter] postNotificationName:kAddBookmarkNotification object:nil]; 200 | } 201 | 202 | // ------------------------------------------------------------------------------- 203 | // editChildAction:sender 204 | // ------------------------------------------------------------------------------- 205 | - (IBAction)editBookmarkAction:(id)sender 206 | { 207 | // post notification to MyOutlineViewController to edit a selected bookmark 208 | [[NSNotificationCenter defaultCenter] postNotificationName:kEditBookmarkNotification object:nil]; 209 | } 210 | 211 | @end 212 | -------------------------------------------------------------------------------- /SourceView/PrimaryViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PrimaryViewController.swift 3 | // SourceView 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/10/24. 6 | // 7 | // 8 | /* 9 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 10 | See LICENSE.txt for this sample’s licensing information 11 | 12 | Abstract: 13 | View controller containing the lower UI controls and the embedded child view controller (split view controller). 14 | */ 15 | import Cocoa 16 | 17 | // notification to instruct MyOutlineViewController to add a folder 18 | let kAddFolderNotification = "AddFolderNotification" 19 | // notification to instruct MyOutlineViewController to remove a folder 20 | let kRemoveFolderNotification = "RemoveFolderNotification" 21 | // notification to instruct MyOutlineViewController to add a bookmark 22 | let kAddBookmarkNotification = "AddBookmarkNotification" 23 | // notification to instruct MyOutlineViewController to edit a bookmark 24 | let kEditBookmarkNotification = "EditBookmarkNotification" 25 | 26 | @objc(PrimaryViewController) 27 | class PrimaryViewController: NSViewController { 28 | 29 | @IBOutlet private weak var progIndicator: NSProgressIndicator! 30 | @IBOutlet private weak var removeButton: NSButton! 31 | @IBOutlet private weak var actionButton: NSPopUpButton! 32 | @IBOutlet private weak var urlField: NSTextField! 33 | @IBOutlet private var editBookmarkMenuItem: NSMenuItem! 34 | 35 | //MARK: - 36 | 37 | 38 | // ------------------------------------------------------------------------------- 39 | // viewDidLoad 40 | // ------------------------------------------------------------------------------- 41 | override func viewDidLoad() { 42 | // Note: we keep the left split view item from growing as the window grows by setting its hugging priority to 200, 43 | // and the right to 199. The view with the lowest priority will be the first to take on additional width if the 44 | // split view grows or shrinks. 45 | // 46 | super.viewDidLoad() 47 | 48 | // insert an empty menu item at the beginning of the drown down button's menu and add its image 49 | let actionImage = NSImage(named: NSImageNameActionTemplate)! 50 | actionImage.size = NSMakeSize(10,10) 51 | 52 | let menuItem = NSMenuItem(title: "", action: nil, keyEquivalent: "") 53 | self.actionButton.menu?.insertItem(menuItem, at: 0) 54 | menuItem.image = actionImage 55 | 56 | self.actionButton.menu?.autoenablesItems = false 57 | 58 | // start off by disabling the Edit... menu item until we are notified of a selection 59 | self.editBookmarkMenuItem.isEnabled = false 60 | 61 | // truncate to the middle if the url is too long to fit 62 | self.urlField.cell?.lineBreakMode = .byTruncatingMiddle 63 | } 64 | 65 | // ------------------------------------------------------------------------------- 66 | // viewWillAppear 67 | // ------------------------------------------------------------------------------- 68 | override func viewWillAppear() { 69 | super.viewWillAppear() 70 | 71 | // listen for selection changes from the NSOutlineView inside MyOutlineViewController 72 | // note: we start observing after our outline view is populated so we don't receive unnecessary notifications at startup 73 | // 74 | NotificationCenter.default.addObserver(self, 75 | selector: #selector(self.selectionDidChange(_:)), 76 | name: .NSOutlineViewSelectionDidChange, 77 | object: nil) 78 | 79 | // notification so we know when the icon view controller is done populating its content 80 | NotificationCenter.default.addObserver(self, 81 | selector: #selector(self.contentReceived(_:)), 82 | name: Notification.Name(kReceivedContentNotification), 83 | object: nil) 84 | } 85 | 86 | // ------------------------------------------------------------------------------- 87 | // dealloc 88 | // ------------------------------------------------------------------------------- 89 | deinit { 90 | NotificationCenter.default.removeObserver(self, name: .NSOutlineViewSelectionDidChange, object: nil) 91 | NotificationCenter.default.removeObserver(self, name: Notification.Name(kReceivedContentNotification), object: nil) 92 | } 93 | 94 | 95 | //MARK: - NSNotifications 96 | 97 | // ------------------------------------------------------------------------------- 98 | // contentReceived:notif 99 | // 100 | // Notification sent from IconViewController class, 101 | // indicating the file system content has been received 102 | // ------------------------------------------------------------------------------- 103 | @objc func contentReceived(_ notif: Notification) { 104 | self.progIndicator.isHidden = true 105 | self.progIndicator.stopAnimation(self) 106 | } 107 | 108 | // ------------------------------------------------------------------------------- 109 | // Listens for changes outline view row selection 110 | // ------------------------------------------------------------------------------- 111 | @objc func selectionDidChange(_ notification: Notification) { 112 | // examine the current selection and adjust the UI 113 | // 114 | let outlineView = notification.object as! NSOutlineView 115 | let selectedRow = outlineView.selectedRow 116 | if selectedRow == -1 { 117 | // there is no current selection - no item to display 118 | self.removeButton.isEnabled = false 119 | self.urlField.stringValue = "" 120 | self.editBookmarkMenuItem.isEnabled = false 121 | } else { 122 | // single selection only 123 | self.removeButton.isEnabled = true 124 | 125 | // report the URL to our NSTextField 126 | let item = (outlineView.item(atRow: selectedRow)! as AnyObject).representedObject as! BaseNode 127 | 128 | if item.isBookmark { 129 | self.urlField.stringValue = item.url?.absoluteString ?? "" 130 | } else { 131 | 132 | self.urlField.stringValue = item.url?.path ?? "" 133 | } 134 | 135 | // enable the Edit... menu item if the selected node is a bookmark 136 | self.editBookmarkMenuItem.isEnabled = !(item.url?.isFileURL ?? true) 137 | 138 | if item.isDirectory { 139 | // we are populating the detail view controler with contents of a folder on disk 140 | // (may take a while) 141 | self.progIndicator.isHidden = false 142 | } 143 | } 144 | } 145 | 146 | 147 | //MARK: - Folders 148 | 149 | // ------------------------------------------------------------------------------- 150 | // addFolderAction:sender: 151 | // ------------------------------------------------------------------------------- 152 | @IBAction func addFolderAction(_: AnyObject) { 153 | // post notification to MyOutlineViewController to add a new folder 154 | NotificationCenter.default.post(name: Notification.Name(kAddFolderNotification), object: nil) 155 | } 156 | 157 | // ------------------------------------------------------------------------------- 158 | // removeFolderAction:sender: 159 | // ------------------------------------------------------------------------------- 160 | @IBAction func removeFolderAction(_: AnyObject) { 161 | let alert = NSAlert() 162 | alert.messageText = NSLocalizedString("Are you sure you want to remove this item?", comment: "") 163 | alert.addButton(withTitle: NSLocalizedString("OK", comment: "")) 164 | alert.addButton(withTitle: NSLocalizedString("Cancel", comment: "")) 165 | alert.beginSheetModal(for: self.view.window!) {returnCode in 166 | if returnCode == NSAlertFirstButtonReturn { 167 | // post notification to MyOutlineViewController to remove the selected folder 168 | NotificationCenter.default.post(name: Notification.Name(kRemoveFolderNotification), object: nil) 169 | } 170 | } 171 | } 172 | 173 | 174 | //MARK: - Bookmarks 175 | 176 | // ------------------------------------------------------------------------------- 177 | // addBookmarkAction:sender 178 | // ------------------------------------------------------------------------------- 179 | @IBAction func addBookmarkAction(_: AnyObject) { 180 | // post notification to MyOutlineViewController to add a new bookmark 181 | NotificationCenter.default.post(name: Notification.Name(kAddBookmarkNotification), object: nil) 182 | } 183 | 184 | // ------------------------------------------------------------------------------- 185 | // editChildAction:sender 186 | // ------------------------------------------------------------------------------- 187 | @IBAction func editBookmarkAction(_: AnyObject) { 188 | // post notification to MyOutlineViewController to edit a selected bookmark 189 | NotificationCenter.default.post(name: Notification.Name(kEditBookmarkNotification), object: nil) 190 | } 191 | 192 | } 193 | -------------------------------------------------------------------------------- /SourceView/SeparatorView.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | Custom view to draw a separator. 7 | */ 8 | 9 | @interface SeparatorView : NSView 10 | 11 | @end 12 | -------------------------------------------------------------------------------- /SourceView/SeparatorView.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | Custom view to draw a separator. 7 | */ 8 | 9 | #import "SeparatorView.h" 10 | 11 | @implementation SeparatorView 12 | 13 | - (void)drawRect:(NSRect)dirtyRect 14 | { 15 | // draw the separator 16 | CGFloat lineWidth = dirtyRect.size.width - 2; 17 | CGFloat lineX = 0; 18 | CGFloat lineY = (dirtyRect.size.height - 2) / 2; 19 | lineY += 0.5; 20 | 21 | [[NSColor colorWithDeviceRed:.349 green:.6 blue:.898 alpha:0.6] set]; 22 | NSRectFill(NSMakeRect(dirtyRect.origin.x + lineX, dirtyRect.origin.y + lineY, lineWidth, 1)); 23 | 24 | [[NSColor colorWithDeviceRed:0.976 green:1.0 blue:1.0 alpha:1.0] set]; 25 | NSRectFill(NSMakeRect(dirtyRect.origin.x + lineX, dirtyRect.origin.y + lineY + 1, lineWidth, 1)); 26 | } 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /SourceView/SeparatorView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SeparatorView.swift 3 | // SourceView 4 | // 5 | // Created by 開発 on 2015/10/24. 6 | // 7 | // 8 | /* 9 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 10 | See LICENSE.txt for this sample’s licensing information 11 | 12 | Abstract: 13 | Custom view to draw a separator. 14 | */ 15 | import Cocoa 16 | 17 | @objc(SeparatorView) 18 | class SeparatorView: NSView { 19 | 20 | override func draw(_ dirtyRect: NSRect) { 21 | // draw the separator 22 | let lineWidth = dirtyRect.size.width - 2 23 | let lineX: CGFloat = 0 24 | var lineY = (dirtyRect.size.height - 2) / 2 25 | lineY += 0.5 26 | 27 | NSColor(deviceRed: 0.349, green: 0.6, blue: 0.898, alpha:0.6).set() 28 | NSRectFill(NSMakeRect(dirtyRect.origin.x + lineX, dirtyRect.origin.y + lineY, lineWidth, 1)) 29 | 30 | NSColor(deviceRed: 0.976, green: 1.0, blue: 1.0, alpha: 1.0).set() 31 | NSRectFill(NSMakeRect(dirtyRect.origin.x + lineX, dirtyRect.origin.y + lineY + 1, lineWidth, 1)) 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /SourceView/SourceView.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 532BAD031BA37AC800565C88 /* ChildEditViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 532BAD021BA37AC800565C88 /* ChildEditViewController.m */; }; 11 | 533E9CF01BB1F4B900B904E0 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 533E9CEC1BB1F4B900B904E0 /* Credits.rtf */; }; 12 | 533E9CF11BB1F4B900B904E0 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 533E9CEE1BB1F4B900B904E0 /* InfoPlist.strings */; }; 13 | 534BC1041BA8AC3D00E3766A /* WebViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 534BC1031BA8AC3D00E3766A /* WebViewController.m */; }; 14 | 53512FAB1E7C735E006F6007 /* IconViewBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 53512FAA1E7C735E006F6007 /* IconViewBox.m */; }; 15 | 5368DC9719DC605B003019C8 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 5368DC9519DC605B003019C8 /* AppDelegate.m */; }; 16 | 5368DC9819DC605B003019C8 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 5368DC9619DC605B003019C8 /* main.m */; }; 17 | 5368DC9F19DC6077003019C8 /* MyWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5368DC9D19DC6077003019C8 /* MyWindowController.m */; }; 18 | 5368DCB019DC609A003019C8 /* BaseNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 5368DCAD19DC609A003019C8 /* BaseNode.m */; }; 19 | 5368DCB119DC609A003019C8 /* ChildNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 5368DCAF19DC609A003019C8 /* ChildNode.m */; }; 20 | 5368DCB619DC60AD003019C8 /* Outline.dict in Resources */ = {isa = PBXBuildFile; fileRef = 5368DCB419DC60AD003019C8 /* Outline.dict */; }; 21 | 537D3D971CB571D000CB2D64 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 537D3D961CB571D000CB2D64 /* WebKit.framework */; }; 22 | 5383D4541BA2016900014E51 /* FileViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5383D4501BA2016900014E51 /* FileViewController.m */; }; 23 | 5383D4551BA2016900014E51 /* IconViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5383D4521BA2016900014E51 /* IconViewController.m */; }; 24 | 5383D4581BA20A2D00014E51 /* PrimaryViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5383D4571BA20A2D00014E51 /* PrimaryViewController.m */; }; 25 | 5383D45B1BA2152700014E51 /* MySplitViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5383D45A1BA2152700014E51 /* MySplitViewController.m */; }; 26 | 53E207331BA0BEB000E45BA6 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 53E207311BA0BEB000E45BA6 /* Main.storyboard */; }; 27 | 53E207361BA0BF8600E45BA6 /* MyOutlineViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 53E207351BA0BF8600E45BA6 /* MyOutlineViewController.m */; }; 28 | 53E207391BA0C4AB00E45BA6 /* SeparatorView.m in Sources */ = {isa = PBXBuildFile; fileRef = 53E207381BA0C4AB00E45BA6 /* SeparatorView.m */; }; 29 | /* End PBXBuildFile section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | 532BAD011BA37AC800565C88 /* ChildEditViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ChildEditViewController.h; path = SourceView/ChildEditViewController.h; sourceTree = ""; }; 33 | 532BAD021BA37AC800565C88 /* ChildEditViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ChildEditViewController.m; path = SourceView/ChildEditViewController.m; sourceTree = ""; }; 34 | 533E9CEB1BB1F3E700B904E0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = SourceView/Base.lproj/Main.storyboard; sourceTree = ""; }; 35 | 533E9CED1BB1F4B900B904E0 /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = Base; path = SourceView/Base.lproj/Credits.rtf; sourceTree = ""; }; 36 | 533E9CEF1BB1F4B900B904E0 /* Base */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = Base; path = SourceView/Base.lproj/InfoPlist.strings; sourceTree = ""; }; 37 | 534BC1021BA8AC3D00E3766A /* WebViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebViewController.h; path = SourceView/WebViewController.h; sourceTree = ""; }; 38 | 534BC1031BA8AC3D00E3766A /* WebViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = WebViewController.m; path = SourceView/WebViewController.m; sourceTree = ""; }; 39 | 53512FA91E7C735E006F6007 /* IconViewBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IconViewBox.h; path = SourceView/IconViewBox.h; sourceTree = ""; }; 40 | 53512FAA1E7C735E006F6007 /* IconViewBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = IconViewBox.m; path = SourceView/IconViewBox.m; sourceTree = ""; }; 41 | 5368DC9319DC604D003019C8 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 42 | 5368DC9419DC605B003019C8 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = SourceView/AppDelegate.h; sourceTree = ""; }; 43 | 5368DC9519DC605B003019C8 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AppDelegate.m; path = SourceView/AppDelegate.m; sourceTree = ""; }; 44 | 5368DC9619DC605B003019C8 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = SourceView/main.m; sourceTree = ""; }; 45 | 5368DC9919DC6063003019C8 /* Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Prefix.pch; path = SourceView/Prefix.pch; sourceTree = ""; }; 46 | 5368DC9C19DC6077003019C8 /* MyWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MyWindowController.h; path = SourceView/MyWindowController.h; sourceTree = ""; }; 47 | 5368DC9D19DC6077003019C8 /* MyWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MyWindowController.m; path = SourceView/MyWindowController.m; sourceTree = ""; }; 48 | 5368DCAC19DC609A003019C8 /* BaseNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = BaseNode.h; path = SourceView/BaseNode.h; sourceTree = ""; }; 49 | 5368DCAD19DC609A003019C8 /* BaseNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = BaseNode.m; path = SourceView/BaseNode.m; sourceTree = ""; }; 50 | 5368DCAE19DC609A003019C8 /* ChildNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ChildNode.h; path = SourceView/ChildNode.h; sourceTree = ""; }; 51 | 5368DCAF19DC609A003019C8 /* ChildNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ChildNode.m; path = SourceView/ChildNode.m; sourceTree = ""; }; 52 | 5368DCB419DC60AD003019C8 /* Outline.dict */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Outline.dict; path = SourceView/Outline.dict; sourceTree = ""; }; 53 | 5368DCB919DC60B8003019C8 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = SourceView/Info.plist; sourceTree = ""; }; 54 | 537D3D961CB571D000CB2D64 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; 55 | 5383D44F1BA2016900014E51 /* FileViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileViewController.h; path = SourceView/FileViewController.h; sourceTree = ""; }; 56 | 5383D4501BA2016900014E51 /* FileViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FileViewController.m; path = SourceView/FileViewController.m; sourceTree = ""; }; 57 | 5383D4511BA2016900014E51 /* IconViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = IconViewController.h; path = SourceView/IconViewController.h; sourceTree = ""; }; 58 | 5383D4521BA2016900014E51 /* IconViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = IconViewController.m; path = SourceView/IconViewController.m; sourceTree = ""; }; 59 | 5383D4561BA20A2D00014E51 /* PrimaryViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PrimaryViewController.h; path = SourceView/PrimaryViewController.h; sourceTree = ""; }; 60 | 5383D4571BA20A2D00014E51 /* PrimaryViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PrimaryViewController.m; path = SourceView/PrimaryViewController.m; sourceTree = ""; }; 61 | 5383D4591BA2152700014E51 /* MySplitViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MySplitViewController.h; path = SourceView/MySplitViewController.h; sourceTree = ""; }; 62 | 5383D45A1BA2152700014E51 /* MySplitViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MySplitViewController.m; path = SourceView/MySplitViewController.m; sourceTree = ""; }; 63 | 53E207341BA0BF8600E45BA6 /* MyOutlineViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MyOutlineViewController.h; path = SourceView/MyOutlineViewController.h; sourceTree = ""; }; 64 | 53E207351BA0BF8600E45BA6 /* MyOutlineViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MyOutlineViewController.m; path = SourceView/MyOutlineViewController.m; sourceTree = ""; }; 65 | 53E207371BA0C4AB00E45BA6 /* SeparatorView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SeparatorView.h; path = SourceView/SeparatorView.h; sourceTree = ""; }; 66 | 53E207381BA0C4AB00E45BA6 /* SeparatorView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SeparatorView.m; path = SourceView/SeparatorView.m; sourceTree = ""; }; 67 | 8D1107320486CEB800E47090 /* SourceView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SourceView.app; sourceTree = BUILT_PRODUCTS_DIR; }; 68 | /* End PBXFileReference section */ 69 | 70 | /* Begin PBXFrameworksBuildPhase section */ 71 | 8D11072E0486CEB800E47090 /* Frameworks */ = { 72 | isa = PBXFrameworksBuildPhase; 73 | buildActionMask = 2147483647; 74 | files = ( 75 | 537D3D971CB571D000CB2D64 /* WebKit.framework in Frameworks */, 76 | ); 77 | runOnlyForDeploymentPostprocessing = 0; 78 | }; 79 | /* End PBXFrameworksBuildPhase section */ 80 | 81 | /* Begin PBXGroup section */ 82 | 19C28FACFE9D520D11CA2CBB /* Products */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | 8D1107320486CEB800E47090 /* SourceView.app */, 86 | ); 87 | name = Products; 88 | sourceTree = ""; 89 | }; 90 | 29B97314FDCFA39411CA2CEA /* TrackIt */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | 5368DC9319DC604D003019C8 /* README.md */, 94 | 29B97315FDCFA39411CA2CEA /* Sources */, 95 | 29B97317FDCFA39411CA2CEA /* Resources */, 96 | 19C28FACFE9D520D11CA2CBB /* Products */, 97 | ); 98 | name = TrackIt; 99 | sourceTree = ""; 100 | }; 101 | 29B97315FDCFA39411CA2CEA /* Sources */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 5368DC9919DC6063003019C8 /* Prefix.pch */, 105 | 5368DC9619DC605B003019C8 /* main.m */, 106 | 5368DC9419DC605B003019C8 /* AppDelegate.h */, 107 | 5368DC9519DC605B003019C8 /* AppDelegate.m */, 108 | 5368DC9C19DC6077003019C8 /* MyWindowController.h */, 109 | 5368DC9D19DC6077003019C8 /* MyWindowController.m */, 110 | 5383D4561BA20A2D00014E51 /* PrimaryViewController.h */, 111 | 5383D4571BA20A2D00014E51 /* PrimaryViewController.m */, 112 | 5383D4591BA2152700014E51 /* MySplitViewController.h */, 113 | 5383D45A1BA2152700014E51 /* MySplitViewController.m */, 114 | 5334E6931BA227B300AB44BD /* Master */, 115 | 5334E6921BA2277C00AB44BD /* Detail */, 116 | 532BAD011BA37AC800565C88 /* ChildEditViewController.h */, 117 | 532BAD021BA37AC800565C88 /* ChildEditViewController.m */, 118 | 53E207371BA0C4AB00E45BA6 /* SeparatorView.h */, 119 | 53E207381BA0C4AB00E45BA6 /* SeparatorView.m */, 120 | 53663E181177C62800078216 /* Tree Support */, 121 | ); 122 | name = Sources; 123 | sourceTree = ""; 124 | }; 125 | 29B97317FDCFA39411CA2CEA /* Resources */ = { 126 | isa = PBXGroup; 127 | children = ( 128 | 533E9CEC1BB1F4B900B904E0 /* Credits.rtf */, 129 | 533E9CEE1BB1F4B900B904E0 /* InfoPlist.strings */, 130 | 5368DCB419DC60AD003019C8 /* Outline.dict */, 131 | 5368DCB919DC60B8003019C8 /* Info.plist */, 132 | 53E207311BA0BEB000E45BA6 /* Main.storyboard */, 133 | 537D3D961CB571D000CB2D64 /* WebKit.framework */, 134 | ); 135 | name = Resources; 136 | sourceTree = ""; 137 | }; 138 | 5334E6921BA2277C00AB44BD /* Detail */ = { 139 | isa = PBXGroup; 140 | children = ( 141 | 53512FA91E7C735E006F6007 /* IconViewBox.h */, 142 | 53512FAA1E7C735E006F6007 /* IconViewBox.m */, 143 | 5383D44F1BA2016900014E51 /* FileViewController.h */, 144 | 5383D4501BA2016900014E51 /* FileViewController.m */, 145 | 5383D4511BA2016900014E51 /* IconViewController.h */, 146 | 5383D4521BA2016900014E51 /* IconViewController.m */, 147 | 534BC1021BA8AC3D00E3766A /* WebViewController.h */, 148 | 534BC1031BA8AC3D00E3766A /* WebViewController.m */, 149 | ); 150 | name = Detail; 151 | sourceTree = ""; 152 | }; 153 | 5334E6931BA227B300AB44BD /* Master */ = { 154 | isa = PBXGroup; 155 | children = ( 156 | 53E207341BA0BF8600E45BA6 /* MyOutlineViewController.h */, 157 | 53E207351BA0BF8600E45BA6 /* MyOutlineViewController.m */, 158 | ); 159 | name = Master; 160 | sourceTree = ""; 161 | }; 162 | 53663E181177C62800078216 /* Tree Support */ = { 163 | isa = PBXGroup; 164 | children = ( 165 | 5368DCAC19DC609A003019C8 /* BaseNode.h */, 166 | 5368DCAD19DC609A003019C8 /* BaseNode.m */, 167 | 5368DCAE19DC609A003019C8 /* ChildNode.h */, 168 | 5368DCAF19DC609A003019C8 /* ChildNode.m */, 169 | ); 170 | name = "Tree Support"; 171 | sourceTree = ""; 172 | }; 173 | /* End PBXGroup section */ 174 | 175 | /* Begin PBXNativeTarget section */ 176 | 8D1107260486CEB800E47090 /* SourceView */ = { 177 | isa = PBXNativeTarget; 178 | buildConfigurationList = C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "SourceView" */; 179 | buildPhases = ( 180 | 8D1107290486CEB800E47090 /* Resources */, 181 | 8D11072C0486CEB800E47090 /* Sources */, 182 | 8D11072E0486CEB800E47090 /* Frameworks */, 183 | ); 184 | buildRules = ( 185 | ); 186 | dependencies = ( 187 | ); 188 | name = SourceView; 189 | productInstallPath = "$(HOME)/Applications"; 190 | productName = TrackIt; 191 | productReference = 8D1107320486CEB800E47090 /* SourceView.app */; 192 | productType = "com.apple.product-type.application"; 193 | }; 194 | /* End PBXNativeTarget section */ 195 | 196 | /* Begin PBXProject section */ 197 | 29B97313FDCFA39411CA2CEA /* Project object */ = { 198 | isa = PBXProject; 199 | attributes = { 200 | LastUpgradeCheck = 0900; 201 | TargetAttributes = { 202 | 8D1107260486CEB800E47090 = { 203 | DevelopmentTeam = V7M23Q5387; 204 | }; 205 | }; 206 | }; 207 | buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SourceView" */; 208 | compatibilityVersion = "Xcode 3.2"; 209 | developmentRegion = English; 210 | hasScannedForEncodings = 1; 211 | knownRegions = ( 212 | en, 213 | English, 214 | Base, 215 | ); 216 | mainGroup = 29B97314FDCFA39411CA2CEA /* TrackIt */; 217 | projectDirPath = ""; 218 | projectRoot = ""; 219 | targets = ( 220 | 8D1107260486CEB800E47090 /* SourceView */, 221 | ); 222 | }; 223 | /* End PBXProject section */ 224 | 225 | /* Begin PBXResourcesBuildPhase section */ 226 | 8D1107290486CEB800E47090 /* Resources */ = { 227 | isa = PBXResourcesBuildPhase; 228 | buildActionMask = 2147483647; 229 | files = ( 230 | 5368DCB619DC60AD003019C8 /* Outline.dict in Resources */, 231 | 533E9CF11BB1F4B900B904E0 /* InfoPlist.strings in Resources */, 232 | 533E9CF01BB1F4B900B904E0 /* Credits.rtf in Resources */, 233 | 53E207331BA0BEB000E45BA6 /* Main.storyboard in Resources */, 234 | ); 235 | runOnlyForDeploymentPostprocessing = 0; 236 | }; 237 | /* End PBXResourcesBuildPhase section */ 238 | 239 | /* Begin PBXSourcesBuildPhase section */ 240 | 8D11072C0486CEB800E47090 /* Sources */ = { 241 | isa = PBXSourcesBuildPhase; 242 | buildActionMask = 2147483647; 243 | files = ( 244 | 5368DCB119DC609A003019C8 /* ChildNode.m in Sources */, 245 | 534BC1041BA8AC3D00E3766A /* WebViewController.m in Sources */, 246 | 53512FAB1E7C735E006F6007 /* IconViewBox.m in Sources */, 247 | 5383D4581BA20A2D00014E51 /* PrimaryViewController.m in Sources */, 248 | 5383D4551BA2016900014E51 /* IconViewController.m in Sources */, 249 | 53E207391BA0C4AB00E45BA6 /* SeparatorView.m in Sources */, 250 | 5383D4541BA2016900014E51 /* FileViewController.m in Sources */, 251 | 53E207361BA0BF8600E45BA6 /* MyOutlineViewController.m in Sources */, 252 | 532BAD031BA37AC800565C88 /* ChildEditViewController.m in Sources */, 253 | 5368DCB019DC609A003019C8 /* BaseNode.m in Sources */, 254 | 5368DC9819DC605B003019C8 /* main.m in Sources */, 255 | 5383D45B1BA2152700014E51 /* MySplitViewController.m in Sources */, 256 | 5368DC9719DC605B003019C8 /* AppDelegate.m in Sources */, 257 | 5368DC9F19DC6077003019C8 /* MyWindowController.m in Sources */, 258 | ); 259 | runOnlyForDeploymentPostprocessing = 0; 260 | }; 261 | /* End PBXSourcesBuildPhase section */ 262 | 263 | /* Begin PBXVariantGroup section */ 264 | 533E9CEC1BB1F4B900B904E0 /* Credits.rtf */ = { 265 | isa = PBXVariantGroup; 266 | children = ( 267 | 533E9CED1BB1F4B900B904E0 /* Base */, 268 | ); 269 | name = Credits.rtf; 270 | sourceTree = ""; 271 | }; 272 | 533E9CEE1BB1F4B900B904E0 /* InfoPlist.strings */ = { 273 | isa = PBXVariantGroup; 274 | children = ( 275 | 533E9CEF1BB1F4B900B904E0 /* Base */, 276 | ); 277 | name = InfoPlist.strings; 278 | sourceTree = ""; 279 | }; 280 | 53E207311BA0BEB000E45BA6 /* Main.storyboard */ = { 281 | isa = PBXVariantGroup; 282 | children = ( 283 | 533E9CEB1BB1F3E700B904E0 /* Base */, 284 | ); 285 | name = Main.storyboard; 286 | sourceTree = ""; 287 | }; 288 | /* End PBXVariantGroup section */ 289 | 290 | /* Begin XCBuildConfiguration section */ 291 | C01FCF4B08A954540054247B /* Debug */ = { 292 | isa = XCBuildConfiguration; 293 | buildSettings = { 294 | CLANG_ENABLE_MODULES = YES; 295 | CLANG_ENABLE_OBJC_ARC = YES; 296 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 297 | COMBINE_HIDPI_IMAGES = YES; 298 | GCC_PREFIX_HEADER = SourceView/Prefix.pch; 299 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 300 | GCC_WARN_SIGN_COMPARE = YES; 301 | GCC_WARN_UNDECLARED_SELECTOR = YES; 302 | GCC_WARN_UNUSED_PARAMETER = NO; 303 | INFOPLIST_FILE = SourceView/Info.plist; 304 | INSTALL_PATH = "$(HOME)/Applications"; 305 | PRODUCT_BUNDLE_IDENTIFIER = "com.example.apple-samplecode.${PRODUCT_NAME:rfc1034identifier}"; 306 | PRODUCT_NAME = SourceView; 307 | SDKROOT = macosx; 308 | WRAPPER_EXTENSION = app; 309 | }; 310 | name = Debug; 311 | }; 312 | C01FCF4C08A954540054247B /* Release */ = { 313 | isa = XCBuildConfiguration; 314 | buildSettings = { 315 | CLANG_ENABLE_MODULES = YES; 316 | CLANG_ENABLE_OBJC_ARC = YES; 317 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 318 | COMBINE_HIDPI_IMAGES = YES; 319 | GCC_FAST_OBJC_DISPATCH = YES; 320 | GCC_OPTIMIZATION_LEVEL = s; 321 | GCC_PREFIX_HEADER = SourceView/Prefix.pch; 322 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 323 | GCC_WARN_SIGN_COMPARE = YES; 324 | GCC_WARN_UNDECLARED_SELECTOR = YES; 325 | GCC_WARN_UNUSED_PARAMETER = NO; 326 | INFOPLIST_FILE = SourceView/Info.plist; 327 | INSTALL_PATH = "$(HOME)/Applications"; 328 | PRODUCT_BUNDLE_IDENTIFIER = "com.example.apple-samplecode.${PRODUCT_NAME:rfc1034identifier}"; 329 | PRODUCT_NAME = SourceView; 330 | SDKROOT = macosx; 331 | WRAPPER_EXTENSION = app; 332 | }; 333 | name = Release; 334 | }; 335 | C01FCF4F08A954540054247B /* Debug */ = { 336 | isa = XCBuildConfiguration; 337 | buildSettings = { 338 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 339 | CLANG_ENABLE_MODULES = YES; 340 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 341 | CLANG_WARN_BOOL_CONVERSION = YES; 342 | CLANG_WARN_COMMA = YES; 343 | CLANG_WARN_CONSTANT_CONVERSION = YES; 344 | CLANG_WARN_EMPTY_BODY = YES; 345 | CLANG_WARN_ENUM_CONVERSION = YES; 346 | CLANG_WARN_INFINITE_RECURSION = YES; 347 | CLANG_WARN_INT_CONVERSION = YES; 348 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 349 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 350 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 351 | CLANG_WARN_STRICT_PROTOTYPES = YES; 352 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 353 | CLANG_WARN_UNREACHABLE_CODE = YES; 354 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 355 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 356 | ENABLE_STRICT_OBJC_MSGSEND = YES; 357 | ENABLE_TESTABILITY = YES; 358 | GCC_FAST_OBJC_DISPATCH = NO; 359 | GCC_NO_COMMON_BLOCKS = YES; 360 | GCC_OPTIMIZATION_LEVEL = 0; 361 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 362 | GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; 363 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; 364 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 365 | GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; 366 | GCC_WARN_SHADOW = YES; 367 | GCC_WARN_UNDECLARED_SELECTOR = YES; 368 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 369 | GCC_WARN_UNKNOWN_PRAGMAS = YES; 370 | GCC_WARN_UNUSED_FUNCTION = YES; 371 | GCC_WARN_UNUSED_LABEL = YES; 372 | GCC_WARN_UNUSED_PARAMETER = NO; 373 | GCC_WARN_UNUSED_VARIABLE = YES; 374 | MACOSX_DEPLOYMENT_TARGET = 10.10; 375 | ONLY_ACTIVE_ARCH = YES; 376 | OTHER_LDFLAGS = "-ObjC"; 377 | RUN_CLANG_STATIC_ANALYZER = YES; 378 | SDKROOT = macosx; 379 | }; 380 | name = Debug; 381 | }; 382 | C01FCF5008A954540054247B /* Release */ = { 383 | isa = XCBuildConfiguration; 384 | buildSettings = { 385 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 386 | CLANG_ENABLE_MODULES = YES; 387 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 388 | CLANG_WARN_BOOL_CONVERSION = YES; 389 | CLANG_WARN_COMMA = YES; 390 | CLANG_WARN_CONSTANT_CONVERSION = YES; 391 | CLANG_WARN_EMPTY_BODY = YES; 392 | CLANG_WARN_ENUM_CONVERSION = YES; 393 | CLANG_WARN_INFINITE_RECURSION = YES; 394 | CLANG_WARN_INT_CONVERSION = YES; 395 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 396 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 397 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 398 | CLANG_WARN_STRICT_PROTOTYPES = YES; 399 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 400 | CLANG_WARN_UNREACHABLE_CODE = YES; 401 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 402 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 403 | ENABLE_STRICT_OBJC_MSGSEND = YES; 404 | GCC_NO_COMMON_BLOCKS = YES; 405 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 406 | GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES; 407 | GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; 408 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 409 | GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; 410 | GCC_WARN_SHADOW = YES; 411 | GCC_WARN_UNDECLARED_SELECTOR = YES; 412 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 413 | GCC_WARN_UNKNOWN_PRAGMAS = YES; 414 | GCC_WARN_UNUSED_FUNCTION = YES; 415 | GCC_WARN_UNUSED_LABEL = YES; 416 | GCC_WARN_UNUSED_PARAMETER = NO; 417 | GCC_WARN_UNUSED_VARIABLE = YES; 418 | MACOSX_DEPLOYMENT_TARGET = 10.10; 419 | OTHER_LDFLAGS = "-ObjC"; 420 | SDKROOT = macosx; 421 | }; 422 | name = Release; 423 | }; 424 | /* End XCBuildConfiguration section */ 425 | 426 | /* Begin XCConfigurationList section */ 427 | C01FCF4A08A954540054247B /* Build configuration list for PBXNativeTarget "SourceView" */ = { 428 | isa = XCConfigurationList; 429 | buildConfigurations = ( 430 | C01FCF4B08A954540054247B /* Debug */, 431 | C01FCF4C08A954540054247B /* Release */, 432 | ); 433 | defaultConfigurationIsVisible = 0; 434 | defaultConfigurationName = Release; 435 | }; 436 | C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SourceView" */ = { 437 | isa = XCConfigurationList; 438 | buildConfigurations = ( 439 | C01FCF4F08A954540054247B /* Debug */, 440 | C01FCF5008A954540054247B /* Release */, 441 | ); 442 | defaultConfigurationIsVisible = 0; 443 | defaultConfigurationName = Release; 444 | }; 445 | /* End XCConfigurationList section */ 446 | }; 447 | rootObject = 29B97313FDCFA39411CA2CEA /* Project object */; 448 | } 449 | -------------------------------------------------------------------------------- /SourceView/WebViewController.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | View controller hosting the web view. 7 | */ 8 | 9 | @import WebKit; 10 | 11 | @interface WebViewController : NSViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /SourceView/WebViewController.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | View controller hosting the web view. 7 | */ 8 | 9 | #import "WebViewController.h" 10 | 11 | @interface WebViewController () 12 | 13 | @end 14 | 15 | @implementation WebViewController 16 | 17 | - (void)webView:(WebView *)sender resource:(id)identifier didFailLoadingWithError:(NSError *)error fromDataSource:(WebDataSource *)dataSource 18 | { 19 | if (error != nil) 20 | { 21 | // An error occurred, provide an error message to the user. 22 | NSString *page = error.userInfo[NSURLErrorFailingURLStringErrorKey]; 23 | NSString *errorContent = [NSString stringWithFormat:@"


Error: unable to load page:
'%@'
", page]; 24 | 25 | [((WebView *)sender).mainFrame loadHTMLString:errorContent baseURL:[NSBundle mainBundle].bundleURL]; 26 | } 27 | } 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /SourceView/WebViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // WebViewController.swift 3 | // SourceView 4 | // 5 | // Translated by OOPer in cooperation with shlab.jp, on 2015/10/24. 6 | // 7 | // 8 | /* 9 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 10 | See LICENSE.txt for this sample’s licensing information 11 | 12 | Abstract: 13 | View controller hosting the web view. 14 | */ 15 | 16 | import Cocoa 17 | import WebKit 18 | 19 | @objc(WebViewController) 20 | class WebViewController: NSViewController, WebResourceLoadDelegate { 21 | 22 | func webView(_ sender: WebView!, resource identifier: Any!, didFailLoadingWithError error: Error!, from dataSource: WebDataSource!) { 23 | if let error = error as NSError? { 24 | // An error occurred, provide an error message to the user. 25 | let page = error.userInfo[NSURLErrorFailingURLStringErrorKey] as! String 26 | let errorContent = "


Error: unable to load page:
'\(page)'
" 27 | 28 | sender.mainFrame.loadHTMLString(errorContent, baseURL: Bundle.main.bundleURL) 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /SourceView/main.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2018 Apple Inc. All Rights Reserved. 3 | See LICENSE.txt for this sample’s licensing information 4 | 5 | Abstract: 6 | Main source file for this sample. 7 | */ 8 | 9 | int main(int argc, char *argv[]) 10 | { 11 | return NSApplicationMain(argc, (const char **) argv); 12 | } 13 | --------------------------------------------------------------------------------