├── DataText.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── mini.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── mini.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── DataText.xcscheme │ └── xcschememanagement.plist ├── DataText ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── appicon016.png │ │ ├── appicon032.png │ │ ├── appicon128.png │ │ ├── appicon256.png │ │ └── appicon512.png │ ├── Contents.json │ ├── icon_bool.imageset │ │ ├── Contents.json │ │ └── icon_bool.png │ ├── icon_center.imageset │ │ ├── Contents.json │ │ └── icon_center.png │ ├── icon_date.imageset │ │ ├── Contents.json │ │ └── icon_date.png │ ├── icon_int-1.imageset │ │ ├── Contents.json │ │ └── icon_int.png │ ├── icon_int.imageset │ │ ├── Contents.json │ │ └── icon_int.png │ ├── icon_left.imageset │ │ ├── Contents.json │ │ └── icon_left.png │ ├── icon_new.imageset │ │ ├── Contents.json │ │ └── icon_new.png │ ├── icon_open.imageset │ │ ├── Contents.json │ │ └── icon_open.png │ ├── icon_real-1.imageset │ │ ├── Contents.json │ │ └── icon_real.png │ ├── icon_real.imageset │ │ ├── Contents.json │ │ └── icon_real.png │ ├── icon_right.imageset │ │ ├── Contents.json │ │ └── icon_right.png │ ├── icon_save.imageset │ │ ├── Contents.json │ │ └── icon_save.png │ ├── icon_text-1.imageset │ │ ├── Contents.json │ │ └── icon_text.png │ ├── icon_text.imageset │ │ ├── Contents.json │ │ └── icon_text.png │ └── icon_time.imageset │ │ ├── Contents.json │ │ └── icon_time.png ├── Base.lproj │ └── Main.storyboard ├── BaseTableCell.xib ├── BoolTableCell.swift ├── BoolTableCell.xib ├── DataSchema.swift ├── DataTable.swift ├── Document.swift ├── Info.plist ├── MyTextField.swift ├── NumericTableCell.xib ├── Sample.table ├── TableController.swift ├── TableView.swift ├── Utils.swift └── ViewController.swift ├── Readme.md └── ToDo.txt /DataText.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3D40FAA41E492A8200AA93D9 /* TableController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D40FAA31E492A8200AA93D9 /* TableController.swift */; }; 11 | 3D40FAA61E492CBA00AA93D9 /* DataTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D40FAA51E492CBA00AA93D9 /* DataTable.swift */; }; 12 | 3D40FAA81E492DB000AA93D9 /* DataSchema.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D40FAA71E492DB000AA93D9 /* DataSchema.swift */; }; 13 | 3D40FAAD1E49366400AA93D9 /* BaseTableCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3D40FAA91E49366400AA93D9 /* BaseTableCell.xib */; }; 14 | 3D40FAAE1E49366500AA93D9 /* BoolTableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D40FAAA1E49366400AA93D9 /* BoolTableCell.swift */; }; 15 | 3D40FAAF1E49366500AA93D9 /* BoolTableCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3D40FAAB1E49366400AA93D9 /* BoolTableCell.xib */; }; 16 | 3D40FAB01E49366500AA93D9 /* NumericTableCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3D40FAAC1E49366400AA93D9 /* NumericTableCell.xib */; }; 17 | 3D40FAB21E494DF400AA93D9 /* Sample.table in Resources */ = {isa = PBXBuildFile; fileRef = 3D40FAB11E494DF400AA93D9 /* Sample.table */; }; 18 | 3D40FAB41E495ADB00AA93D9 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D40FAB31E495ADB00AA93D9 /* Utils.swift */; }; 19 | 3DE17FE01E4D3DEC00AAE794 /* TableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DE17FDF1E4D3DEC00AAE794 /* TableView.swift */; }; 20 | 3DE17FE21E4D543300AAE794 /* MyTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DE17FE11E4D543300AAE794 /* MyTextField.swift */; }; 21 | 3DEFC2011E4803F400BC143C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DEFC2001E4803F400BC143C /* AppDelegate.swift */; }; 22 | 3DEFC2031E4803F400BC143C /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DEFC2021E4803F400BC143C /* ViewController.swift */; }; 23 | 3DEFC2051E4803F400BC143C /* Document.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DEFC2041E4803F400BC143C /* Document.swift */; }; 24 | 3DEFC2071E4803F400BC143C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3DEFC2061E4803F400BC143C /* Assets.xcassets */; }; 25 | 3DEFC20A1E4803F400BC143C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3DEFC2081E4803F400BC143C /* Main.storyboard */; }; 26 | /* End PBXBuildFile section */ 27 | 28 | /* Begin PBXFileReference section */ 29 | 3D40FAA31E492A8200AA93D9 /* TableController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableController.swift; sourceTree = ""; wrapsLines = 0; }; 30 | 3D40FAA51E492CBA00AA93D9 /* DataTable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataTable.swift; sourceTree = ""; wrapsLines = 0; }; 31 | 3D40FAA71E492DB000AA93D9 /* DataSchema.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataSchema.swift; sourceTree = ""; }; 32 | 3D40FAA91E49366400AA93D9 /* BaseTableCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BaseTableCell.xib; sourceTree = ""; }; 33 | 3D40FAAA1E49366400AA93D9 /* BoolTableCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BoolTableCell.swift; sourceTree = ""; }; 34 | 3D40FAAB1E49366400AA93D9 /* BoolTableCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BoolTableCell.xib; sourceTree = ""; }; 35 | 3D40FAAC1E49366400AA93D9 /* NumericTableCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NumericTableCell.xib; sourceTree = ""; }; 36 | 3D40FAB11E494DF400AA93D9 /* Sample.table */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Sample.table; sourceTree = ""; }; 37 | 3D40FAB31E495ADB00AA93D9 /* Utils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = ""; }; 38 | 3D539B451E490C0000ACB662 /* Readme.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Readme.md; sourceTree = ""; }; 39 | 3D539B461E490D5100ACB662 /* ToDo.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = ToDo.txt; sourceTree = ""; }; 40 | 3DE17FDF1E4D3DEC00AAE794 /* TableView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableView.swift; sourceTree = ""; wrapsLines = 0; }; 41 | 3DE17FE11E4D543300AAE794 /* MyTextField.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MyTextField.swift; sourceTree = ""; wrapsLines = 0; }; 42 | 3DEFC1FD1E4803F300BC143C /* DataText.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DataText.app; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | 3DEFC2001E4803F400BC143C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 44 | 3DEFC2021E4803F400BC143C /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; wrapsLines = 0; }; 45 | 3DEFC2041E4803F400BC143C /* Document.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Document.swift; sourceTree = ""; wrapsLines = 0; }; 46 | 3DEFC2061E4803F400BC143C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 47 | 3DEFC2091E4803F400BC143C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 48 | 3DEFC20B1E4803F500BC143C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 49 | /* End PBXFileReference section */ 50 | 51 | /* Begin PBXFrameworksBuildPhase section */ 52 | 3DEFC1FA1E4803F100BC143C /* Frameworks */ = { 53 | isa = PBXFrameworksBuildPhase; 54 | buildActionMask = 2147483647; 55 | files = ( 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | /* End PBXFrameworksBuildPhase section */ 60 | 61 | /* Begin PBXGroup section */ 62 | 3DEFC1F41E4803F100BC143C = { 63 | isa = PBXGroup; 64 | children = ( 65 | 3D539B451E490C0000ACB662 /* Readme.md */, 66 | 3D539B461E490D5100ACB662 /* ToDo.txt */, 67 | 3DEFC1FF1E4803F300BC143C /* DataText */, 68 | 3DEFC1FE1E4803F300BC143C /* Products */, 69 | ); 70 | sourceTree = ""; 71 | }; 72 | 3DEFC1FE1E4803F300BC143C /* Products */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 3DEFC1FD1E4803F300BC143C /* DataText.app */, 76 | ); 77 | name = Products; 78 | sourceTree = ""; 79 | }; 80 | 3DEFC1FF1E4803F300BC143C /* DataText */ = { 81 | isa = PBXGroup; 82 | children = ( 83 | 3DEFC20B1E4803F500BC143C /* Info.plist */, 84 | 3DEFC2001E4803F400BC143C /* AppDelegate.swift */, 85 | 3DEFC2021E4803F400BC143C /* ViewController.swift */, 86 | 3D40FAA31E492A8200AA93D9 /* TableController.swift */, 87 | 3DE17FDF1E4D3DEC00AAE794 /* TableView.swift */, 88 | 3DE17FE11E4D543300AAE794 /* MyTextField.swift */, 89 | 3D40FAA51E492CBA00AA93D9 /* DataTable.swift */, 90 | 3D40FAA71E492DB000AA93D9 /* DataSchema.swift */, 91 | 3DEFC2041E4803F400BC143C /* Document.swift */, 92 | 3D40FAB31E495ADB00AA93D9 /* Utils.swift */, 93 | 3D40FAA91E49366400AA93D9 /* BaseTableCell.xib */, 94 | 3D40FAAC1E49366400AA93D9 /* NumericTableCell.xib */, 95 | 3D40FAAB1E49366400AA93D9 /* BoolTableCell.xib */, 96 | 3D40FAAA1E49366400AA93D9 /* BoolTableCell.swift */, 97 | 3DEFC2081E4803F400BC143C /* Main.storyboard */, 98 | 3DEFC2061E4803F400BC143C /* Assets.xcassets */, 99 | 3D40FAB11E494DF400AA93D9 /* Sample.table */, 100 | ); 101 | path = DataText; 102 | sourceTree = ""; 103 | }; 104 | /* End PBXGroup section */ 105 | 106 | /* Begin PBXNativeTarget section */ 107 | 3DEFC1FC1E4803F100BC143C /* DataText */ = { 108 | isa = PBXNativeTarget; 109 | buildConfigurationList = 3DEFC20E1E4803F500BC143C /* Build configuration list for PBXNativeTarget "DataText" */; 110 | buildPhases = ( 111 | 3DEFC1F91E4803F100BC143C /* Sources */, 112 | 3DEFC1FA1E4803F100BC143C /* Frameworks */, 113 | 3DEFC1FB1E4803F100BC143C /* Resources */, 114 | ); 115 | buildRules = ( 116 | ); 117 | dependencies = ( 118 | ); 119 | name = DataText; 120 | productName = DataText; 121 | productReference = 3DEFC1FD1E4803F300BC143C /* DataText.app */; 122 | productType = "com.apple.product-type.application"; 123 | }; 124 | /* End PBXNativeTarget section */ 125 | 126 | /* Begin PBXProject section */ 127 | 3DEFC1F51E4803F100BC143C /* Project object */ = { 128 | isa = PBXProject; 129 | attributes = { 130 | LastSwiftUpdateCheck = 0800; 131 | LastUpgradeCheck = 0800; 132 | ORGANIZATIONNAME = Armonia; 133 | TargetAttributes = { 134 | 3DEFC1FC1E4803F100BC143C = { 135 | CreatedOnToolsVersion = 8.0; 136 | DevelopmentTeam = 5F3M8Z38CD; 137 | ProvisioningStyle = Automatic; 138 | }; 139 | }; 140 | }; 141 | buildConfigurationList = 3DEFC1F81E4803F100BC143C /* Build configuration list for PBXProject "DataText" */; 142 | compatibilityVersion = "Xcode 3.2"; 143 | developmentRegion = English; 144 | hasScannedForEncodings = 0; 145 | knownRegions = ( 146 | en, 147 | Base, 148 | ); 149 | mainGroup = 3DEFC1F41E4803F100BC143C; 150 | productRefGroup = 3DEFC1FE1E4803F300BC143C /* Products */; 151 | projectDirPath = ""; 152 | projectRoot = ""; 153 | targets = ( 154 | 3DEFC1FC1E4803F100BC143C /* DataText */, 155 | ); 156 | }; 157 | /* End PBXProject section */ 158 | 159 | /* Begin PBXResourcesBuildPhase section */ 160 | 3DEFC1FB1E4803F100BC143C /* Resources */ = { 161 | isa = PBXResourcesBuildPhase; 162 | buildActionMask = 2147483647; 163 | files = ( 164 | 3DEFC2071E4803F400BC143C /* Assets.xcassets in Resources */, 165 | 3D40FAAD1E49366400AA93D9 /* BaseTableCell.xib in Resources */, 166 | 3D40FAB01E49366500AA93D9 /* NumericTableCell.xib in Resources */, 167 | 3D40FAAF1E49366500AA93D9 /* BoolTableCell.xib in Resources */, 168 | 3D40FAB21E494DF400AA93D9 /* Sample.table in Resources */, 169 | 3DEFC20A1E4803F400BC143C /* Main.storyboard in Resources */, 170 | ); 171 | runOnlyForDeploymentPostprocessing = 0; 172 | }; 173 | /* End PBXResourcesBuildPhase section */ 174 | 175 | /* Begin PBXSourcesBuildPhase section */ 176 | 3DEFC1F91E4803F100BC143C /* Sources */ = { 177 | isa = PBXSourcesBuildPhase; 178 | buildActionMask = 2147483647; 179 | files = ( 180 | 3D40FAA41E492A8200AA93D9 /* TableController.swift in Sources */, 181 | 3DEFC2031E4803F400BC143C /* ViewController.swift in Sources */, 182 | 3D40FAA81E492DB000AA93D9 /* DataSchema.swift in Sources */, 183 | 3D40FAA61E492CBA00AA93D9 /* DataTable.swift in Sources */, 184 | 3DE17FE01E4D3DEC00AAE794 /* TableView.swift in Sources */, 185 | 3DE17FE21E4D543300AAE794 /* MyTextField.swift in Sources */, 186 | 3DEFC2011E4803F400BC143C /* AppDelegate.swift in Sources */, 187 | 3D40FAAE1E49366500AA93D9 /* BoolTableCell.swift in Sources */, 188 | 3DEFC2051E4803F400BC143C /* Document.swift in Sources */, 189 | 3D40FAB41E495ADB00AA93D9 /* Utils.swift in Sources */, 190 | ); 191 | runOnlyForDeploymentPostprocessing = 0; 192 | }; 193 | /* End PBXSourcesBuildPhase section */ 194 | 195 | /* Begin PBXVariantGroup section */ 196 | 3DEFC2081E4803F400BC143C /* Main.storyboard */ = { 197 | isa = PBXVariantGroup; 198 | children = ( 199 | 3DEFC2091E4803F400BC143C /* Base */, 200 | ); 201 | name = Main.storyboard; 202 | sourceTree = ""; 203 | }; 204 | /* End PBXVariantGroup section */ 205 | 206 | /* Begin XCBuildConfiguration section */ 207 | 3DEFC20C1E4803F500BC143C /* Debug */ = { 208 | isa = XCBuildConfiguration; 209 | buildSettings = { 210 | ALWAYS_SEARCH_USER_PATHS = NO; 211 | CLANG_ANALYZER_NONNULL = YES; 212 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 213 | CLANG_CXX_LIBRARY = "libc++"; 214 | CLANG_ENABLE_MODULES = YES; 215 | CLANG_ENABLE_OBJC_ARC = YES; 216 | CLANG_WARN_BOOL_CONVERSION = YES; 217 | CLANG_WARN_CONSTANT_CONVERSION = YES; 218 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 219 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 220 | CLANG_WARN_EMPTY_BODY = YES; 221 | CLANG_WARN_ENUM_CONVERSION = YES; 222 | CLANG_WARN_INFINITE_RECURSION = YES; 223 | CLANG_WARN_INT_CONVERSION = YES; 224 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 225 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 226 | CLANG_WARN_UNREACHABLE_CODE = YES; 227 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 228 | CODE_SIGN_IDENTITY = "-"; 229 | COPY_PHASE_STRIP = NO; 230 | DEBUG_INFORMATION_FORMAT = dwarf; 231 | ENABLE_STRICT_OBJC_MSGSEND = YES; 232 | ENABLE_TESTABILITY = YES; 233 | GCC_C_LANGUAGE_STANDARD = gnu99; 234 | GCC_DYNAMIC_NO_PIC = NO; 235 | GCC_NO_COMMON_BLOCKS = YES; 236 | GCC_OPTIMIZATION_LEVEL = 0; 237 | GCC_PREPROCESSOR_DEFINITIONS = ( 238 | "DEBUG=1", 239 | "$(inherited)", 240 | ); 241 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 242 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 243 | GCC_WARN_UNDECLARED_SELECTOR = YES; 244 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 245 | GCC_WARN_UNUSED_FUNCTION = YES; 246 | GCC_WARN_UNUSED_VARIABLE = YES; 247 | MACOSX_DEPLOYMENT_TARGET = 10.12; 248 | MTL_ENABLE_DEBUG_INFO = YES; 249 | ONLY_ACTIVE_ARCH = YES; 250 | SDKROOT = macosx; 251 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 252 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 253 | }; 254 | name = Debug; 255 | }; 256 | 3DEFC20D1E4803F500BC143C /* Release */ = { 257 | isa = XCBuildConfiguration; 258 | buildSettings = { 259 | ALWAYS_SEARCH_USER_PATHS = NO; 260 | CLANG_ANALYZER_NONNULL = YES; 261 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 262 | CLANG_CXX_LIBRARY = "libc++"; 263 | CLANG_ENABLE_MODULES = YES; 264 | CLANG_ENABLE_OBJC_ARC = YES; 265 | CLANG_WARN_BOOL_CONVERSION = YES; 266 | CLANG_WARN_CONSTANT_CONVERSION = YES; 267 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 268 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 269 | CLANG_WARN_EMPTY_BODY = YES; 270 | CLANG_WARN_ENUM_CONVERSION = YES; 271 | CLANG_WARN_INFINITE_RECURSION = YES; 272 | CLANG_WARN_INT_CONVERSION = YES; 273 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 274 | CLANG_WARN_SUSPICIOUS_MOVES = YES; 275 | CLANG_WARN_UNREACHABLE_CODE = YES; 276 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 277 | CODE_SIGN_IDENTITY = "-"; 278 | COPY_PHASE_STRIP = NO; 279 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 280 | ENABLE_NS_ASSERTIONS = NO; 281 | ENABLE_STRICT_OBJC_MSGSEND = YES; 282 | GCC_C_LANGUAGE_STANDARD = gnu99; 283 | GCC_NO_COMMON_BLOCKS = YES; 284 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 285 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 286 | GCC_WARN_UNDECLARED_SELECTOR = YES; 287 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 288 | GCC_WARN_UNUSED_FUNCTION = YES; 289 | GCC_WARN_UNUSED_VARIABLE = YES; 290 | MACOSX_DEPLOYMENT_TARGET = 10.12; 291 | MTL_ENABLE_DEBUG_INFO = NO; 292 | SDKROOT = macosx; 293 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 294 | }; 295 | name = Release; 296 | }; 297 | 3DEFC20F1E4803F500BC143C /* Debug */ = { 298 | isa = XCBuildConfiguration; 299 | buildSettings = { 300 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 301 | COMBINE_HIDPI_IMAGES = YES; 302 | DEVELOPMENT_TEAM = 5F3M8Z38CD; 303 | INFOPLIST_FILE = DataText/Info.plist; 304 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 305 | PRODUCT_BUNDLE_IDENTIFIER = Armonia.DataText; 306 | PRODUCT_NAME = "$(TARGET_NAME)"; 307 | SWIFT_VERSION = 3.0; 308 | }; 309 | name = Debug; 310 | }; 311 | 3DEFC2101E4803F500BC143C /* Release */ = { 312 | isa = XCBuildConfiguration; 313 | buildSettings = { 314 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 315 | COMBINE_HIDPI_IMAGES = YES; 316 | DEVELOPMENT_TEAM = 5F3M8Z38CD; 317 | INFOPLIST_FILE = DataText/Info.plist; 318 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 319 | PRODUCT_BUNDLE_IDENTIFIER = Armonia.DataText; 320 | PRODUCT_NAME = "$(TARGET_NAME)"; 321 | SWIFT_VERSION = 3.0; 322 | }; 323 | name = Release; 324 | }; 325 | /* End XCBuildConfiguration section */ 326 | 327 | /* Begin XCConfigurationList section */ 328 | 3DEFC1F81E4803F100BC143C /* Build configuration list for PBXProject "DataText" */ = { 329 | isa = XCConfigurationList; 330 | buildConfigurations = ( 331 | 3DEFC20C1E4803F500BC143C /* Debug */, 332 | 3DEFC20D1E4803F500BC143C /* Release */, 333 | ); 334 | defaultConfigurationIsVisible = 0; 335 | defaultConfigurationName = Release; 336 | }; 337 | 3DEFC20E1E4803F500BC143C /* Build configuration list for PBXNativeTarget "DataText" */ = { 338 | isa = XCConfigurationList; 339 | buildConfigurations = ( 340 | 3DEFC20F1E4803F500BC143C /* Debug */, 341 | 3DEFC2101E4803F500BC143C /* Release */, 342 | ); 343 | defaultConfigurationIsVisible = 0; 344 | defaultConfigurationName = Release; 345 | }; 346 | /* End XCConfigurationList section */ 347 | }; 348 | rootObject = 3DEFC1F51E4803F100BC143C /* Project object */; 349 | } 350 | -------------------------------------------------------------------------------- /DataText.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DataText.xcodeproj/project.xcworkspace/xcuserdata/mini.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText.xcodeproj/project.xcworkspace/xcuserdata/mini.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /DataText.xcodeproj/xcuserdata/mini.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /DataText.xcodeproj/xcuserdata/mini.xcuserdatad/xcschemes/DataText.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /DataText.xcodeproj/xcuserdata/mini.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | DataText.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 3DEFC1FC1E4803F100BC143C 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /DataText/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // DataText 4 | // 5 | // Created by Mac Mini on 2/5/17. 6 | // Copyright © 2017 Armonia. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | /* Common definitions */ 12 | 13 | typealias Parameters = Dictionary 14 | typealias DataRecord = Dictionary 15 | typealias DataResults = [DataRecord] 16 | 17 | 18 | /* App delegate */ 19 | 20 | @NSApplicationMain 21 | class AppDelegate: NSObject, NSApplicationDelegate { 22 | 23 | var firstWindow = true 24 | var lastTable: URL? // Save for reopening next time 25 | 26 | override init() { 27 | print("Hello!") 28 | super.init() 29 | 30 | } 31 | 32 | func applicationDidFinishLaunching(_ aNotification: Notification) { 33 | // Three possible states: last file, no file, open file 34 | // print("App did finish loading") 35 | lastTable = UserDefaults.standard.url(forKey: "lastTable") 36 | let app = aNotification.object as! NSApplication 37 | 38 | if let vc = app.mainWindow?.contentViewController as? ViewController { 39 | if lastTable == nil { 40 | vc.loadSampleTable() 41 | } else { 42 | // Already loaded as first Document 43 | } 44 | } else { 45 | print("VC not loaded yet") 46 | } 47 | } 48 | 49 | func applicationWillTerminate(_ aNotification: Notification) { 50 | print("Goodbye!") 51 | } 52 | 53 | func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { 54 | return true 55 | } 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /DataText/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "16x16", 5 | "idiom" : "mac", 6 | "filename" : "appicon016.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "idiom" : "mac", 11 | "size" : "16x16", 12 | "scale" : "2x" 13 | }, 14 | { 15 | "size" : "32x32", 16 | "idiom" : "mac", 17 | "filename" : "appicon032.png", 18 | "scale" : "1x" 19 | }, 20 | { 21 | "idiom" : "mac", 22 | "size" : "32x32", 23 | "scale" : "2x" 24 | }, 25 | { 26 | "size" : "128x128", 27 | "idiom" : "mac", 28 | "filename" : "appicon128.png", 29 | "scale" : "1x" 30 | }, 31 | { 32 | "idiom" : "mac", 33 | "size" : "128x128", 34 | "scale" : "2x" 35 | }, 36 | { 37 | "size" : "256x256", 38 | "idiom" : "mac", 39 | "filename" : "appicon256.png", 40 | "scale" : "1x" 41 | }, 42 | { 43 | "idiom" : "mac", 44 | "size" : "256x256", 45 | "scale" : "2x" 46 | }, 47 | { 48 | "size" : "512x512", 49 | "idiom" : "mac", 50 | "filename" : "appicon512.png", 51 | "scale" : "1x" 52 | }, 53 | { 54 | "idiom" : "mac", 55 | "size" : "512x512", 56 | "scale" : "2x" 57 | } 58 | ], 59 | "info" : { 60 | "version" : 1, 61 | "author" : "xcode" 62 | } 63 | } -------------------------------------------------------------------------------- /DataText/Assets.xcassets/AppIcon.appiconset/appicon016.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/AppIcon.appiconset/appicon016.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/AppIcon.appiconset/appicon032.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/AppIcon.appiconset/appicon032.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/AppIcon.appiconset/appicon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/AppIcon.appiconset/appicon128.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/AppIcon.appiconset/appicon256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/AppIcon.appiconset/appicon256.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/AppIcon.appiconset/appicon512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/AppIcon.appiconset/appicon512.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_bool.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icon_bool.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_bool.imageset/icon_bool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/icon_bool.imageset/icon_bool.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_center.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icon_center.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_center.imageset/icon_center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/icon_center.imageset/icon_center.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_date.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icon_date.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_date.imageset/icon_date.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/icon_date.imageset/icon_date.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_int-1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icon_int.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_int-1.imageset/icon_int.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/icon_int-1.imageset/icon_int.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_int.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icon_int.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_int.imageset/icon_int.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/icon_int.imageset/icon_int.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_left.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icon_left.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_left.imageset/icon_left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/icon_left.imageset/icon_left.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_new.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icon_new.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_new.imageset/icon_new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/icon_new.imageset/icon_new.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_open.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icon_open.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_open.imageset/icon_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/icon_open.imageset/icon_open.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_real-1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icon_real.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_real-1.imageset/icon_real.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/icon_real-1.imageset/icon_real.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_real.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icon_real.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_real.imageset/icon_real.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/icon_real.imageset/icon_real.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_right.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icon_right.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_right.imageset/icon_right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/icon_right.imageset/icon_right.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_save.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icon_save.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_save.imageset/icon_save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/icon_save.imageset/icon_save.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_text-1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icon_text.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_text-1.imageset/icon_text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/icon_text-1.imageset/icon_text.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_text.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icon_text.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_text.imageset/icon_text.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/icon_text.imageset/icon_text.png -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_time.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "icon_time.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /DataText/Assets.xcassets/icon_time.imageset/icon_time.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kuyawa/DataText/e782f143d56133de0f4b7121fd24d34fab9aa1e9/DataText/Assets.xcassets/icon_time.imageset/icon_time.png -------------------------------------------------------------------------------- /DataText/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | Default 527 | 528 | 529 | 530 | 531 | 532 | 533 | Left to Right 534 | 535 | 536 | 537 | 538 | 539 | 540 | Right to Left 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | Default 552 | 553 | 554 | 555 | 556 | 557 | 558 | Left to Right 559 | 560 | 561 | 562 | 563 | 564 | 565 | Right to Left 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 871 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 947 | 958 | 959 | 960 | 961 | 962 | 973 | 984 | 995 | 996 | 997 | 998 | 999 | 1010 | 1021 | 1032 | 1043 | 1054 | 1065 | 1076 | 1087 | 1098 | 1109 | 1117 | 1128 | 1129 | 1130 | 1131 | 1132 | 1133 | 1134 | 1135 | 1136 | 1137 | 1138 | 1139 | 1140 | 1141 | 1142 | 1143 | 1144 | 1145 | 1146 | 1147 | 1148 | 1149 | 1150 | 1151 | 1152 | 1153 | 1154 | 1155 | 1156 | 1157 | 1158 | 1159 | 1160 | 1161 | -------------------------------------------------------------------------------- /DataText/BaseTableCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /DataText/BoolTableCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // BoolTableCell.swift 3 | // DataBrowserPG 4 | // 5 | // Created by Mac Mini on 1/16/17. 6 | // Copyright © 2017 Armonia. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | class BoolTableCell: NSTableCellView { 12 | 13 | @IBOutlet weak var checkbox : NSButton! 14 | 15 | var checked: Bool { 16 | get { return checkbox.state == 1 } 17 | set { checkbox.state = newValue ? 1 : 0 } 18 | } 19 | 20 | /* 21 | override func draw(_ dirtyRect: NSRect) { 22 | super.draw(dirtyRect) 23 | 24 | // Drawing code here. 25 | } 26 | */ 27 | } 28 | -------------------------------------------------------------------------------- /DataText/BoolTableCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /DataText/DataSchema.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DataSchema.swift 3 | // DataText 4 | // 5 | // Created by Mac Mini on 2/6/17. 6 | // Copyright © 2017 Armonia. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | 12 | import Foundation 13 | 14 | // Primitive types 15 | enum FieldTypePrimitive: String { 16 | case Text, Integer, Real, Blob 17 | } 18 | 19 | // For use in formatting tables 20 | enum FieldTypeBase: String { 21 | case Text, Integer, Real, Date, Time, Bool, Binary 22 | } 23 | 24 | // SQL Data types 25 | enum FieldType: String { 26 | case String, Text, Varchar, NVarchar, Character, NChar, Clob, Uuid, 27 | Int, Integer, TinyInt, SmallInt, MediumInt, BigInt, Uint, Int2, Int8, Serial, BigSerial, 28 | Real, Double, Float, Number, Numeric, Decimal, Money, 29 | Date, Datetime, Time, Timestamp, 30 | Boolean, Bool, 31 | Binary, Blob 32 | } 33 | 34 | class DataSchema: NSObject { 35 | var tableName = "" 36 | var fields = [TableField]() 37 | var indexes = [TableIndexes]() 38 | 39 | 40 | func parseFields(_ cols: DataResults) { 41 | fields.removeAll() 42 | 43 | for item in cols { 44 | let field = TableField() 45 | field.ordinal = item["ordinal"] as! Int 46 | field.name = item["name"] as! String 47 | let len = item["length"] as! Int 48 | let dec = item["decimals"] as! Int 49 | let (base, type, length, decs, width) = parseType(item["type"] as! String) 50 | field.base = base 51 | field.type = type 52 | field.length = length 53 | field.decimals = decs 54 | field.width = width 55 | field.isNull = item["isnull"] as! Bool //String == "YES" 56 | field.defValue = item["default"] as! String 57 | field.autoInc = item["autoinc"] as! Bool 58 | if len > length { field.length = len } 59 | if len > width { field.width = len } 60 | if dec > decs { field.decimals = dec } 61 | 62 | fields.append(field) 63 | } 64 | } 65 | 66 | func parseType(_ field: String) -> (FieldTypeBase, FieldType, Int, Int, Int) { 67 | let text = field.uppercased() 68 | var base = FieldTypeBase.Text 69 | var type = FieldType.Varchar 70 | var length = 1 71 | let decs = 0 72 | var width = 0 73 | 74 | // Type 75 | if text.hasPrefix("CHARACTER VAR") { type = .Varchar; base = .Text; length = 40; width = 200 } 76 | else if text.hasPrefix("VARCHAR") { type = .Varchar; base = .Text; length = 40; width = 200 } 77 | else if text.hasPrefix("NVARCHAR") { type = .NVarchar; base = .Text; length = 40; width = 200 } 78 | else if text.hasPrefix("CHARACTER") { type = .Character; base = .Text; length = 40; width = 200 } 79 | else if text.hasPrefix("TEXT") { type = .Text; base = .Text; length = 80; width = 400 } 80 | else if text.hasPrefix("INTEGER") { type = .Integer; base = .Integer; length = 12; width = 80 } 81 | else if text.hasPrefix("BIGINT") { type = .BigInt; base = .Integer; length = 12; width = 80 } 82 | else if text.hasPrefix("SMALLINT") { type = .SmallInt; base = .Integer; length = 12; width = 80 } 83 | else if text.hasPrefix("MONEY") { type = .Money; base = .Real; length = 12; width = 80 } 84 | else if text.hasPrefix("REAL") { type = .Real; base = .Real; length = 12; width = 80 } 85 | else if text.hasPrefix("DOUBLE") { type = .Double; base = .Real; length = 12; width = 80 } 86 | else if text.hasPrefix("NUMERIC") { type = .Numeric; base = .Real; length = 12; width = 80 } 87 | else if text.hasPrefix("TIMESTAMP") { type = .Timestamp; base = .Date; length = 20; width = 200 } 88 | else if text.hasPrefix("DATETIME") { type = .Datetime; base = .Date; length = 20; width = 200 } 89 | else if text.hasPrefix("DATE") { type = .Date; base = .Date; length = 20; width = 100 } 90 | else if text.hasPrefix("BOOLEAN") { type = .Boolean; base = .Bool; length = 20; width = 60 } 91 | else if text.hasPrefix("BINARY") { type = .Binary; base = .Binary; length = 40; width = 60 } 92 | else if text.hasPrefix("BLOB") { type = .Binary; base = .Binary; length = 40; width = 60 } 93 | else if text.hasPrefix("UUID") { type = .Uuid; base = .Text; length = 40; width = 300 } 94 | else { type = .Text; base = .Text; length = 80 } 95 | // Types: Point? Multipoint? Linestring? 96 | 97 | return (base, type, length, decs, width) 98 | } 99 | 100 | func getField(_ name: String) -> TableField? { 101 | for field in fields { 102 | if field.name == name { return field } 103 | } 104 | 105 | return nil 106 | } 107 | 108 | } 109 | 110 | enum CellAlign { case left, center, right } 111 | 112 | class TableField: NSObject { 113 | var ordinal = 0 114 | var name = "Field" 115 | var base = FieldTypeBase.Text 116 | var type = FieldType.Text 117 | var length = 20 118 | var decimals = 0 119 | var width = 100 // Used in table columns 120 | var defValue = "" 121 | var isNull = true 122 | var autoInc = false 123 | var primary = false 124 | var align = CellAlign.left 125 | } 126 | 127 | // TODO: indexes? 128 | class TableIndexes: NSObject { 129 | var name = "" 130 | } 131 | 132 | 133 | // End 134 | -------------------------------------------------------------------------------- /DataText/DataTable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DataTable.swift 3 | // DataText 4 | // 5 | // Created by Mac Mini on 2/6/17. 6 | // Copyright © 2017 Armonia. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | class DataTable { 12 | 13 | var url: URL? 14 | var name = "" 15 | var schema = DataSchema() 16 | var records = DataResults() 17 | 18 | var text: String { 19 | get { 20 | let text = rowsToText() 21 | print("Get Text: \n\(text)") 22 | return text 23 | } 24 | set { 25 | // Load table records from text 26 | print("Set Text: \n\(newValue)") 27 | textToRows(newValue) 28 | } 29 | } 30 | 31 | // From text to records 32 | 33 | func textToRows(_ text: String) { 34 | //print("Parsing...") 35 | if text.isEmpty { return } 36 | 37 | let lines = text.components(separatedBy: "\n") 38 | let count = lines.count 39 | var head = "" 40 | var dash = "" 41 | 42 | var useFields = false 43 | 44 | if count > 0 { head = lines[0] } // First row is head 45 | if count > 1 { dash = lines[1] } // Second row is dashes 46 | if !dash.isEmpty && dash.characters.count > 3 && dash.hasPrefix("[ --") { 47 | useFields = true 48 | } 49 | 50 | if useFields { 51 | getFields(head) // if has header in line 0, use fields from header 52 | getRecords(lines, start: 2) // data starts in line 2 53 | } else { 54 | setFields(head) // if no header, assign column1, column2 ... columnN 55 | getRecords(lines, start: 0) // data starts in line 0 56 | } 57 | 58 | //print("Fields: ", schema.fields.map{ $0.name }) 59 | //print("Records: ", records) 60 | } 61 | 62 | func getFields(_ head: String) { 63 | let parts = head.subtext(from: 1, to: -1).components(separatedBy: "|") 64 | //print(parts) 65 | 66 | for (index, item) in parts.enumerated() { 67 | let field = TableField() 68 | if item.hasPrefix(" ") { 69 | field.align = CellAlign.right 70 | } 71 | field.ordinal = index 72 | field.length = item.characters.count - 2 // minus two padding spaces 73 | field.name = item.trimmingCharacters(in: .whitespaces) 74 | field.width = field.length * 8 // pixels for column width 75 | 76 | schema.fields.append(field) 77 | } 78 | } 79 | 80 | func setFields(_ head: String) { 81 | let parts = head.components(separatedBy: "|") 82 | 83 | for index in 0.. String{ 161 | var text = "" 162 | 163 | // TODO: Calc max width by fields on max row cell 164 | 165 | // Head from fields 166 | var head = "[" 167 | var dash = "[" 168 | 169 | for (index, field) in schema.fields.enumerated() { 170 | var name = field.name 171 | let line = "-".times(field.length) 172 | 173 | if field.align == .right { name = name.padLeft(field.length) } 174 | else { name = name.padRight(field.length) } 175 | 176 | head += " " + name + " " 177 | dash += " " + line + " " 178 | 179 | if index < schema.fields.count - 1 { 180 | head += "|" 181 | dash += "|" 182 | } 183 | } 184 | 185 | head += "]\n" 186 | dash += "]\n" 187 | 188 | // Body from records 189 | var body = "" 190 | 191 | for record in records { 192 | var row = "[" 193 | 194 | for (index, field) in schema.fields.enumerated() { 195 | // Convert by type, switch? 196 | var cellText = String(describing: record[field.name]!) 197 | 198 | if field.align == .right { cellText = cellText.padLeft(field.length) } 199 | else { cellText = cellText.padRight(field.length) } 200 | 201 | row += " " + cellText + " " 202 | 203 | if index < schema.fields.count - 1 { 204 | row += "|" 205 | } 206 | } 207 | 208 | body += row + "]\n" 209 | } 210 | 211 | text += head 212 | text += dash 213 | text += body 214 | 215 | return text 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /DataText/Document.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Document.swift 3 | // DataText 4 | // 5 | // Created by Mac Mini on 2/5/17. 6 | // Copyright © 2017 Armonia. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | class Document: NSDocument { 12 | 13 | var windowController: NSWindowController? 14 | //var textView: NSTextView? 15 | //var table: DataTable? 16 | var content: String = "" // From:to table.text 17 | 18 | override init() { 19 | super.init() 20 | Swift.print("Doc init") 21 | 22 | let app = NSApp.delegate as! AppDelegate 23 | if app.firstWindow { 24 | app.firstWindow = false 25 | openLastTable() 26 | } 27 | } 28 | 29 | override func close() { 30 | Swift.print("Close: ", self.fileURL) 31 | saveLastTableUrl() 32 | super.close() 33 | } 34 | 35 | override class func autosavesInPlace() -> Bool { 36 | return true 37 | } 38 | 39 | // Open last table 40 | func openLastTable() { 41 | Swift.print("Open last table") 42 | if let url = UserDefaults.standard.url(forKey: "lastTable") { 43 | let app = NSApp.delegate as! AppDelegate 44 | app.lastTable = url 45 | Swift.print("Opening file: ", url) 46 | try? self.read(from: url, ofType: "table") 47 | self.fileURL = url 48 | } 49 | } 50 | 51 | // Save last table url in UserDefaults 52 | func saveLastTableUrl() { 53 | Swift.print("Save last table url") 54 | if let url = self.fileURL { 55 | UserDefaults.standard.set(url, forKey: "lastTable") 56 | Swift.print("Saving url: ", url) 57 | } 58 | } 59 | 60 | // Open 61 | override func read(from data: Data, ofType typeName: String) throws { 62 | //Swift.print("Open: ", typeName) 63 | //Swift.print("File: ", self.fileURL) 64 | 65 | if let text = String(data: data, encoding: .utf8) { 66 | content = text 67 | //Swift.print("Text: \n", text) 68 | } else { 69 | Swift.print("Error reading file") 70 | throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil) 71 | } 72 | } 73 | 74 | // Save 75 | override func data(ofType typeName: String) throws -> Data { 76 | Swift.print("Save: ", typeName) 77 | 78 | /* 79 | guard let text = textView?.string else { 80 | debugPrint("No text for saving?") 81 | throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil) 82 | } 83 | */ 84 | 85 | guard let viewController = windowController?.contentViewController as? ViewController else { 86 | Swift.print("No text for saving?") 87 | throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil) 88 | } 89 | 90 | let text = viewController.tableController.table.text 91 | 92 | // TODO: Somewhere save fileURL to UserDefaults 93 | Swift.print("Saving text to ", self.fileURL) 94 | 95 | if let data = text.data(using: .utf8) { 96 | return data 97 | } else { 98 | Swift.print("No data for saving?") 99 | throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil) 100 | } 101 | } 102 | 103 | 104 | // Assign content to view 105 | override func makeWindowControllers() { 106 | // Returns the Storyboard that contains your Document window. 107 | let storyboard = NSStoryboard(name: "Main", bundle: nil) 108 | let windowController = storyboard.instantiateController(withIdentifier: "Document Window Controller") as! NSWindowController 109 | self.addWindowController(windowController) 110 | 111 | // Custom code 112 | self.windowController = windowController 113 | //Swift.print("WC added") 114 | 115 | if let viewController = windowController.contentViewController as? ViewController { 116 | //textView = viewController.textView 117 | //textView?.string = content 118 | //self.table = viewController.tableController.table 119 | viewController.tableController.load(content) 120 | viewController.showRecordCount() 121 | //Swift.print("TextView added") 122 | } 123 | } 124 | 125 | /* 126 | override func save(_ sender: Any?) { 127 | //saveUserDefault() 128 | Swift.print("Save: ", self.fileURL) 129 | super.save(sender) 130 | } 131 | */ 132 | 133 | /* 134 | override func awakeFromNib() { 135 | debugPrint("Awakening...") 136 | } 137 | 138 | override func windowControllerDidLoadNib(_ windowController: NSWindowController) { 139 | super.windowControllerDidLoadNib(windowController) 140 | debugPrint("WC Loaded") 141 | if let vc = windowController.contentViewController as? ViewController { 142 | debugPrint("VC Loaded") 143 | textView = vc.textView 144 | textView?.string = content 145 | } else { 146 | debugPrint("VC not loaded yet") 147 | } 148 | } 149 | 150 | override func read(from url: URL, ofType typeName: String) throws { 151 | do { 152 | content = try String(contentsOf: url, encoding: .utf8) 153 | } catch { 154 | debugPrint("Error: ", error) 155 | throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil) 156 | } 157 | } 158 | 159 | override func write(to url: URL, ofType typeName: String) throws { 160 | do { 161 | try textView?.string?.write(to: url, atomically: false, encoding: .utf8) 162 | } catch { 163 | debugPrint("Error: ", error) 164 | throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil) 165 | } 166 | } 167 | */ 168 | } 169 | 170 | -------------------------------------------------------------------------------- /DataText/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDocumentTypes 8 | 9 | 10 | CFBundleTypeExtensions 11 | 12 | table 13 | 14 | CFBundleTypeIconFile 15 | 16 | CFBundleTypeName 17 | DocumentType 18 | CFBundleTypeOSTypes 19 | 20 | table 21 | 22 | CFBundleTypeRole 23 | Editor 24 | NSDocumentClass 25 | $(PRODUCT_MODULE_NAME).Document 26 | 27 | 28 | CFBundleExecutable 29 | $(EXECUTABLE_NAME) 30 | CFBundleIconFile 31 | 32 | CFBundleIdentifier 33 | $(PRODUCT_BUNDLE_IDENTIFIER) 34 | CFBundleInfoDictionaryVersion 35 | 6.0 36 | CFBundleName 37 | $(PRODUCT_NAME) 38 | CFBundlePackageType 39 | APPL 40 | CFBundleShortVersionString 41 | 1.0 42 | CFBundleVersion 43 | 1 44 | LSApplicationCategoryType 45 | public.app-category.utilities 46 | LSMinimumSystemVersion 47 | $(MACOSX_DEPLOYMENT_TARGET) 48 | NSHumanReadableCopyright 49 | Copyright © 2017 Armonia. All rights reserved. 50 | NSMainStoryboardFile 51 | Main 52 | NSPrincipalClass 53 | NSApplication 54 | 55 | 56 | -------------------------------------------------------------------------------- /DataText/MyTextField.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MyTextField.swift 3 | // DataText 4 | // 5 | // Created by Mac Mini on 2/9/17. 6 | // Copyright © 2017 Armonia. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import Foundation 11 | 12 | class MyTextField: NSTextField, NSTextFieldDelegate { 13 | // The worst sourcery ever 14 | // Needed to know when a cell was being entered even if not edited 15 | // So we could trap on key up and select same column but prev/next row 16 | /* 17 | override func validateProposedFirstResponder(_ responder: NSResponder, for event: NSEvent?) -> Bool { 18 | if let cellId = superview?.identifier, 19 | let tableController = (superview?.superview?.superview as? TableView)?.delegate as? TableController { 20 | tableController.activeColumnId = cellId 21 | return true 22 | } 23 | 24 | return super.validateProposedFirstResponder(responder, for: event) 25 | } 26 | */ 27 | 28 | override func becomeFirstResponder() -> Bool { 29 | //Swift.print("becomeFirstResponder") 30 | let ok = super.becomeFirstResponder() 31 | 32 | guard let cellId = superview?.identifier else { 33 | Swift.print("No cellId") 34 | return ok 35 | } 36 | 37 | guard let tableController = (superview?.superview?.superview as? NSTableView)?.delegate as? TableController else { 38 | Swift.print("No tableController ", superview?.superview?.superview?.className) 39 | return ok 40 | } 41 | 42 | //Swift.print("Assigned ", cellId) 43 | tableController.activeColumnId = cellId 44 | tableController.isEditing = true 45 | 46 | return ok 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /DataText/NumericTableCell.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /DataText/Sample.table: -------------------------------------------------------------------------------- 1 | [ Id | Name | Phone | Salary | Hired | Active ] 2 | [ ------ | -------------------- | ---------------- | ----------- | ----------- | ------ ] 3 | [ 1001 | Taylor Swift | 555-TAYSWIFT | 25425.95 | 2015-01-01 | x ] 4 | [ 1002 | Megan Fox | 800-MEGANFOX | 19750.95 | 2016-07-15 | x ] 5 | [ 1003 | John Travolta | 555-TRAVOLTA | 64545.95 | 2015-08-22 | x ] 6 | [ 1004 | Jack Nicholson | 555-JACKNICK | 52772.95 | 2014-12-10 | ] 7 | -------------------------------------------------------------------------------- /DataText/TableController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TableController.swift 3 | // DataText 4 | // 5 | // Created by Mac Mini on 2/6/17. 6 | // Copyright © 2017 Armonia. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import Foundation 11 | 12 | // removed delegates: NSTextFieldDelegate, NSControlTextEditingDelegate 13 | class TableController: NSObject, NSTableViewDataSource, NSTableViewDelegate { 14 | 15 | var table = DataTable() 16 | var tableView : NSTableView? 17 | var activeColumnId = "" 18 | var activeColumn = 0 19 | var activeRow = 0 20 | var isEditing = false 21 | 22 | 23 | func load(_ text: String) { 24 | // Text sent from Document.content on opening file 25 | table.text = text 26 | makeTable() 27 | reload() 28 | } 29 | 30 | func loadSample() { 31 | let url = Bundle.main.url(forResource: "Sample", withExtension: "table") 32 | let text = try? String(contentsOf: url!) 33 | table.text = text ?? "" 34 | makeTable() 35 | reload() 36 | } 37 | 38 | /* 39 | func save() { 40 | // TODO: parse table.records into text and send to Document.save 41 | } 42 | */ 43 | 44 | func getSchema() { 45 | //fields = table.fields() 46 | //print("Fields schema: ", fields) 47 | //schema.parseFields(fields) 48 | } 49 | 50 | func getRecords() { 51 | //records = table.records 52 | //print("Records: ", records) 53 | } 54 | 55 | func clear() { 56 | clearRows() 57 | clearColumns() 58 | } 59 | 60 | func clearRows() { 61 | if let last = tableView?.numberOfRows { 62 | //let range = NSRange(location: 0, length: last) 63 | let all = IndexSet(integersIn: 0 ..< last) 64 | tableView?.removeRows(at: all, withAnimation: .slideUp) 65 | } 66 | } 67 | 68 | func clearColumns() { 69 | if let view = tableView { 70 | for col in view.tableColumns { 71 | view.removeTableColumn(col) 72 | } 73 | } 74 | } 75 | 76 | func makeTable() { 77 | //print("Make table") 78 | guard let tableView = tableView else { print("No tableView"); return } 79 | 80 | clearRows() 81 | clearColumns() 82 | 83 | var nib = NSNib(nibNamed: "BaseTableCell", bundle: .main) 84 | 85 | for field in table.schema.fields { 86 | let name = field.name 87 | var size = field.width 88 | if size < 80 { size = 80 } // Min 89 | if size > 300 { size = 300 } // Max 90 | 91 | let col = NSTableColumn(identifier: name) 92 | col.headerCell.title = name 93 | col.headerCell.alignment = .center 94 | col.width = CGFloat(size) 95 | if col.width < 1.0 { col.width = 100.0 } 96 | col.isEditable = true 97 | tableView.addTableColumn(col) 98 | 99 | switch field.base { 100 | case .Text : nib = NSNib(nibNamed: "BaseTableCell" , bundle: .main) 101 | case .Integer : nib = NSNib(nibNamed: "NumericTableCell", bundle: .main) 102 | case .Real : nib = NSNib(nibNamed: "NumericTableCell", bundle: .main) 103 | case .Date : nib = NSNib(nibNamed: "BaseTableCell" , bundle: .main) // TODO: Date table cell 104 | case .Time : nib = NSNib(nibNamed: "BaseTableCell" , bundle: .main) // TODO: Date table cell 105 | case .Bool : nib = NSNib(nibNamed: "BoolTableCell" , bundle: .main) 106 | case .Binary : nib = NSNib(nibNamed: "BaseTableCell" , bundle: .main) // Deprecated, use urls 107 | } 108 | 109 | tableView.register(nib, forIdentifier: name) 110 | } 111 | 112 | tableView.usesAlternatingRowBackgroundColors = true 113 | tableView.columnAutoresizingStyle = .uniformColumnAutoresizingStyle 114 | tableView.delegate = self 115 | tableView.dataSource = self 116 | tableView.target = self 117 | tableView.font = NSFont.monospacedDigitSystemFont(ofSize: 12.0, weight: NSFontWeightRegular) 118 | } 119 | 120 | func reload() { 121 | tableView?.reloadData() 122 | } 123 | 124 | func refresh() { 125 | clear() 126 | makeTable() 127 | reload() 128 | } 129 | 130 | // Make an array [0,1,2,..nCols] of indexes 131 | func getColIndexes() -> IndexSet { 132 | let count = table.schema.fields.count 133 | let cols = IndexSet(integersIn: 0.. DataRecord { 139 | var record = DataRecord() 140 | 141 | for field in table.schema.fields { 142 | record[field.name] = "" 143 | } 144 | 145 | return record 146 | } 147 | 148 | func insertRecord() { 149 | // TODO: Insert below current line, reorder line numbers 150 | let line = newRecord() 151 | table.records.append(line) 152 | let last = table.records.count - 1 153 | let cols: IndexSet = getColIndexes() 154 | tableView?.insertRows(at: [last], withAnimation: .slideDown) 155 | tableView?.reloadData(forRowIndexes: [last], columnIndexes: cols) 156 | tableView?.scrollRowToVisible(last) 157 | tableView?.selectRowIndexes([last], byExtendingSelection: false) 158 | } 159 | 160 | func removeRecord() { 161 | guard let selected = tableView?.selectedRow else { return } 162 | guard selected.inRange(0, table.records.count-1) else { return } 163 | table.records.remove(at: selected) 164 | tableView?.removeRows(at: [selected], withAnimation: .slideUp) 165 | var last = selected 166 | if last == table.records.count { last -= 1 } // last row removed, select previous 167 | tableView?.selectRowIndexes([last], byExtendingSelection: false) 168 | //let cols : IndexSet = [0,1,2,3,4] 169 | //tableView.reloadData(forRowIndexes: [selected], columnIndexes: cols) 170 | } 171 | 172 | func duplicateRecord() { 173 | guard let selected = tableView?.selectedRow else { return } 174 | guard selected.inRange(0, table.records.count-1) else { return } 175 | let line = table.records[selected] 176 | table.records.append(line) 177 | let last = table.records.count - 1 178 | let cols: IndexSet = getColIndexes() 179 | tableView?.insertRows(at: [last], withAnimation: .slideDown) 180 | tableView?.reloadData(forRowIndexes: [last], columnIndexes: cols) 181 | tableView?.scrollRowToVisible(last) 182 | tableView?.selectRowIndexes([last], byExtendingSelection: false) 183 | } 184 | 185 | func insertColumn() { 186 | print("Insert column...") 187 | guard let tableView = tableView else { print("No tableView"); return } 188 | 189 | var nib = NSNib(nibNamed: "BaseTableCell", bundle: .main) 190 | 191 | let n = table.schema.fields.count 192 | let field = TableField() 193 | field.name = "Column\(n+1)" 194 | field.base = .Text 195 | field.ordinal = n 196 | field.length = 20 197 | field.width = 100 198 | table.schema.fields.append(field) 199 | print("Col name: ", field.name) 200 | 201 | // Update records, add new column 202 | for (index, _) in table.records.enumerated() { 203 | table.records[index][field.name] = "" 204 | } 205 | 206 | let col = NSTableColumn(identifier: field.name) 207 | col.headerCell.title = field.name 208 | col.headerCell.alignment = .center 209 | col.width = CGFloat(field.width) 210 | col.isEditable = true 211 | tableView.addTableColumn(col) 212 | 213 | switch field.base { 214 | case .Text : nib = NSNib(nibNamed: "BaseTableCell" , bundle: .main) 215 | case .Integer : nib = NSNib(nibNamed: "NumericTableCell", bundle: .main) 216 | case .Real : nib = NSNib(nibNamed: "NumericTableCell", bundle: .main) 217 | case .Date : nib = NSNib(nibNamed: "BaseTableCell" , bundle: .main) // TODO: Date table cell 218 | case .Time : nib = NSNib(nibNamed: "BaseTableCell" , bundle: .main) // TODO: Date table cell 219 | case .Bool : nib = NSNib(nibNamed: "BoolTableCell" , bundle: .main) 220 | case .Binary : nib = NSNib(nibNamed: "BaseTableCell" , bundle: .main) // DEPRECATED, use URLs 221 | } 222 | 223 | tableView.register(nib, forIdentifier: field.name) 224 | activeColumnId = field.name 225 | } 226 | 227 | func removeColumn() { 228 | // TODO: Check if column has data, warn user data will be deleted 229 | print("Remove column...") 230 | guard let tableView = tableView else { print("No tableView"); return } 231 | guard let column = tableView.tableColumns.last else { print("No columns"); return } 232 | let columnId = column.identifier 233 | guard let field = table.schema.getField(columnId) else { print("No field"); return } 234 | 235 | tableView.removeTableColumn(column) 236 | guard let index = table.schema.fields.index(of: field) else { print("No index"); return } 237 | table.schema.fields.remove(at: index) 238 | refresh() 239 | } 240 | 241 | func alignLeft() { 242 | print("Align left ", activeColumnId) 243 | guard let column = tableView!.tableColumn(withIdentifier: activeColumnId) else { return } 244 | guard let field = table.schema.getField(activeColumnId) else { return } 245 | guard let cell = column.dataCell as? NSTextFieldCell else { return } 246 | 247 | field.align = .left 248 | cell.alignment = .left 249 | 250 | refresh() 251 | print("Left aligned") 252 | } 253 | 254 | func alignCenter() { 255 | // TODO: 256 | print("Align center ", activeColumnId) 257 | } 258 | 259 | func alignRight() { 260 | print("Align right ", activeColumnId) 261 | guard let column = tableView!.tableColumn(withIdentifier: activeColumnId) else { print("No col"); return } 262 | guard let field = table.schema.getField(activeColumnId) else { print("No fld"); return } 263 | guard let cell = column.dataCell as? NSTextFieldCell else { print("No cell"); return } 264 | 265 | field.align = .right 266 | cell.alignment = .right 267 | 268 | refresh() 269 | print("Right aligned") 270 | } 271 | 272 | func changeDataText() { 273 | print("Type Text") 274 | guard let field = table.schema.getField(activeColumnId) else { return } 275 | field.type = .Text 276 | field.base = .Text 277 | // TODO: Align left 278 | refresh() 279 | } 280 | 281 | func changeDataInt() { 282 | print("Type Int") 283 | guard let field = table.schema.getField(activeColumnId) else { return } 284 | field.type = .Int 285 | field.base = .Integer 286 | // TODO: Align right 287 | refresh() 288 | } 289 | 290 | func changeDataReal() { 291 | print("Type Real") 292 | guard let field = table.schema.getField(activeColumnId) else { return } 293 | field.type = .Real 294 | field.base = .Real 295 | // TODO: Align right 296 | refresh() 297 | } 298 | 299 | func changeDataDate() { 300 | print("Type Date") 301 | guard let field = table.schema.getField(activeColumnId) else { return } 302 | field.type = .Date 303 | field.base = .Date 304 | // TODO: Align left 305 | refresh() 306 | } 307 | 308 | func changeDataTime() { 309 | print("Type Time") 310 | guard let field = table.schema.getField(activeColumnId) else { return } 311 | field.type = .Time 312 | field.base = .Time 313 | // TODO: Align left 314 | refresh() 315 | } 316 | 317 | func changeDataBool() { 318 | print("Type Bool") 319 | guard let field = table.schema.getField(activeColumnId) else { return } 320 | field.type = .Bool 321 | field.base = .Bool 322 | // TODO: Make check control 323 | refresh() 324 | } 325 | 326 | 327 | // Not used 328 | func onEditCell(_ sender: NSTextField) { 329 | guard let cellId = sender.superview?.identifier else { return } 330 | print("Edited cell \(cellId):", sender.stringValue) 331 | 332 | if let row = tableView?.selectedRow, row > -1 { 333 | // on cell type, if string, number or bool 334 | table.records[row][cellId] = sender.stringValue 335 | activeColumnId = cellId 336 | activeColumn = tableView!.column(withIdentifier: cellId) 337 | activeRow = tableView!.selectedRow 338 | } 339 | } 340 | 341 | func onCheckCell(_ sender: NSButton) { 342 | guard let cellId = sender.superview?.identifier else { return } 343 | //print("Edited check \(cellId):", sender.state) 344 | 345 | if let row = tableView?.selectedRow, row > -1 { 346 | // on cell type, if string, number or bool 347 | table.records[row][cellId] = (sender.state == 1) 348 | //print("Updated record source") 349 | } 350 | } 351 | 352 | // Edit cell up on arrow up 353 | func editCellUp() { 354 | guard tableView != nil else { return } 355 | 356 | let row = tableView!.selectedRow 357 | //let col = activeColumn 358 | let col = tableView!.column(withIdentifier: activeColumnId) 359 | print("Edit cell up ", row, col, activeColumnId) 360 | 361 | guard row > 0, col > -1 else { return } 362 | 363 | tableView!.editColumn(col, row: row-1, with: nil, select: true) 364 | tableView!.selectRowIndexes([row-1], byExtendingSelection: false) 365 | } 366 | 367 | // Edit cell down on arrow down 368 | func editCellDown() { 369 | guard tableView != nil else { return } 370 | 371 | let row = tableView!.selectedRow 372 | //let col = activeColumn 373 | let col = tableView!.column(withIdentifier: activeColumnId) 374 | print("Edit cell down ", row, col, activeColumnId) 375 | 376 | guard row > -1, col > -1 else { return } 377 | 378 | if row < tableView!.numberOfRows-1 { 379 | tableView!.editColumn(col, row: row+1, with: nil, select: true) 380 | tableView!.selectRowIndexes([row+1], byExtendingSelection: false) 381 | } 382 | } 383 | 384 | // Cell editing 385 | /* 386 | override func controlTextDidEndEditing(_ obj: Notification) { 387 | print("Control end editing") 388 | guard tableView != nil else { return } 389 | 390 | let textField = (obj.object as! NSTextField) 391 | activeColumnId = (textField.superview?.identifier)! 392 | activeColumn = tableView!.column(withIdentifier: activeColumnId) 393 | activeRow = tableView!.selectedRow 394 | 395 | if activeRow > -1 { 396 | // on cell type, if string, number or bool 397 | table.records[activeRow][activeColumnId] = textField.stringValue 398 | } 399 | 400 | } 401 | */ 402 | 403 | // Column Move 404 | func tableViewColumnDidMove(_ notification: Notification) { 405 | // Change field.order 406 | let oldPos = notification.userInfo?["NSOldColumn"] as! Int 407 | let newPos = notification.userInfo?["NSNewColumn"] as! Int 408 | let cellId = table.schema.fields[oldPos].name 409 | for field in table.schema.fields { 410 | if field.ordinal >= newPos { 411 | field.ordinal = field.ordinal + 1 412 | } 413 | if field.name == cellId { 414 | field.ordinal = newPos 415 | } 416 | } 417 | 418 | // TODO: Reorder array on ordinal 419 | 420 | print("ColumnDidMove ", oldPos, newPos) 421 | } 422 | 423 | // Column Resize 424 | func tableViewColumnDidResize(_ notification: Notification) { 425 | // Change field.length and field width 426 | let column = notification.userInfo?["NSTableColumn"] as! NSTableColumn 427 | let columnId = column.identifier 428 | let oldWidth = notification.userInfo?["NSOldWidth"] as! Int 429 | let newWidth = column.width 430 | print("ColumnDidResize ", columnId, oldWidth, newWidth) 431 | 432 | if let field = table.schema.getField(columnId) { 433 | field.width = Int(newWidth) 434 | field.length = Int(field.width / 8) // Aprox ratio between char length and pixel width 435 | print("New field length ", field.length) 436 | } 437 | } 438 | 439 | // Column header click 440 | func tableView(_ tableView: NSTableView, mouseDownInHeaderOf tableColumn: NSTableColumn) { 441 | activeColumnId = tableColumn.identifier 442 | print("Column clicked: ", activeColumnId) 443 | } 444 | 445 | 446 | 447 | // Table data source 448 | func numberOfRows(in tableView: NSTableView) -> Int { 449 | return table.records.count 450 | } 451 | 452 | func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { 453 | let item = table.records[row] 454 | let cellId = (tableColumn?.identifier)! 455 | var text = "" 456 | 457 | if item[cellId] != nil { 458 | text = (item[cellId] as AnyObject).debugDescription! 459 | //text = item[cellId] as! String 460 | 461 | switch item[cellId] { 462 | case let value as String : text = value 463 | case let value as Int : text = String(value) 464 | case let value as Double : text = String(value) 465 | case let value as NSNumber : text = String(describing: value) 466 | default: text = "\(item[cellId]!)" 467 | } 468 | 469 | } 470 | 471 | if let cell = tableView.make(withIdentifier: cellId, owner: self) as? NSTableCellView { 472 | if let field = table.schema.getField(cellId) { 473 | if field.type == .Bool { 474 | let boolVal = item[cellId] as? Bool ?? false 475 | let boolCell = cell as! BoolTableCell 476 | boolCell.checked = boolVal 477 | boolCell.checkbox?.target = self 478 | boolCell.checkbox?.action = #selector(TableController.onCheckCell(_:)) // EDITION 479 | } else { 480 | cell.textField?.stringValue = text 481 | cell.textField?.target = self 482 | //cell.textField?.delegate = self 483 | cell.textField?.action = #selector(TableController.onEditCell(_:)) // EDITION 484 | switch field.align { 485 | case .left : cell.textField?.alignment = .left 486 | case .center : cell.textField?.alignment = .center 487 | case .right : cell.textField?.alignment = .right 488 | } 489 | } 490 | } 491 | return cell 492 | } 493 | 494 | return nil 495 | } 496 | 497 | } 498 | 499 | 500 | // END 501 | -------------------------------------------------------------------------------- /DataText/TableView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TableView.swift 3 | // DataText 4 | // 5 | // Created by Mac Mini on 2/9/17. 6 | // Copyright © 2017 Armonia. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import Foundation 11 | 12 | 13 | // NOT USED. REMOVE. 14 | class TableView: NSTableView, NSTableViewDelegate { 15 | 16 | /* 17 | override func keyUp(with event: NSEvent) { 18 | Swift.print("Key up in table") 19 | 20 | if let tc = (self.delegate as? TableController) { 21 | switch event.keyCode { 22 | case 126 /* up */ : tc.editCellUp() 23 | case 125 /* dn */ : tc.editCellDown() 24 | default : super.keyUp(with: event) 25 | } 26 | } 27 | } 28 | */ 29 | 30 | /* 31 | func tableView(_ tableView: NSTableView, shouldEdit tableColumn: NSTableColumn?, row: Int) -> Bool { 32 | return true 33 | } 34 | */ 35 | /* 36 | func tableView(_ tableView: NSTableView, shouldEdit tableColumn: NSTableColumn?, row: Int) -> Bool { 37 | Swift.print("Should edit column?") 38 | if let cellId = tableColumn?.identifier { 39 | let tc = tableView.delegate as! TableController 40 | tc.activeColumnId = cellId 41 | Swift.print("OK ", cellId) 42 | } 43 | return true 44 | } 45 | */ 46 | 47 | 48 | // From here down they're not being called 49 | 50 | override func textDidEndEditing(_ notification: Notification) { 51 | Swift.print("Text did end editing") 52 | } 53 | 54 | override func controlTextDidEndEditing(_ obj: Notification) { 55 | Swift.print("ControlTextDidEndEditing") 56 | } 57 | 58 | override func controlTextDidChange(_ obj: Notification) { 59 | Swift.print("controlTextDidChange") 60 | } 61 | 62 | override func controlTextDidBeginEditing(_ obj: Notification) { 63 | Swift.print("controlTextDidBeginEditing") 64 | } 65 | 66 | override func textShouldBeginEditing(_ textObject: NSText) -> Bool { 67 | Swift.print("textShouldBeginEditing") 68 | return true 69 | } 70 | 71 | override func textDidChange(_ notification: Notification) { 72 | Swift.print("textDidChange") 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /DataText/Utils.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Utils.swift 3 | // DataText 4 | // 5 | // Created by Mac Mini on 2/6/17. 6 | // Copyright © 2017 Armonia. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import Foundation 11 | 12 | 13 | extension String { 14 | 15 | // To numbers 16 | 17 | func toDouble() -> Double { 18 | var text = self.replacingOccurrences(of: "$", with: "") 19 | text = text.replacingOccurrences(of: ",", with: "") 20 | if let value = NumberFormatter().number(from: text)?.doubleValue { 21 | return value 22 | } 23 | return 0.0 24 | } 25 | 26 | func toInteger() -> Int { 27 | if let value = NumberFormatter().number(from: self)?.intValue { 28 | return value 29 | } 30 | return 0 31 | } 32 | 33 | // Attributed 34 | 35 | func strikethrough() -> NSAttributedString { 36 | let fancy = [NSStrikethroughStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue] 37 | let text = NSAttributedString(string: self, attributes: fancy) 38 | return text 39 | } 40 | 41 | func colored(_ color: NSColor) -> NSMutableAttributedString { 42 | let fancy = [NSForegroundColorAttributeName: color] 43 | let text = NSMutableAttributedString(string: self, attributes: fancy) 44 | return text 45 | } 46 | 47 | // Padding 48 | 49 | func padRight(_ n: Int) -> String { 50 | var text = self 51 | let size = self.characters.count 52 | var pad = n - size 53 | 54 | if pad < 0 { pad = size } 55 | 56 | for _ in 0.. String { 64 | var text = self 65 | let size = self.characters.count 66 | var pad = n - size 67 | 68 | if pad < 0 { pad = size } 69 | 70 | for _ in 0.. String { 79 | return String(repeating: self, count: n) 80 | } 81 | 82 | // Substring 83 | 84 | func subtext(from pos: Int) -> String { 85 | guard pos >= 0 else { return "" } 86 | if pos > self.characters.count { return "" } 87 | let first = self.index(self.startIndex, offsetBy: pos) 88 | let text = self.substring(from: first) 89 | return text 90 | } 91 | 92 | func subtext(to pos: Int) -> String { 93 | var end = pos 94 | if pos > self.characters.count { end = self.characters.count } 95 | if pos < 0 { end = self.characters.count + pos } 96 | let last = self.index(self.startIndex, offsetBy: end) 97 | let text = self.substring(to: last) 98 | return text 99 | } 100 | 101 | func subtext(from ini: Int, to end: Int) -> String { 102 | guard ini >= 0 else { return "" } 103 | var fin = end 104 | if end < 0 { fin = self.characters.count + end } 105 | if ini > self.characters.count { return "" } 106 | if end > self.characters.count { fin = self.characters.count } 107 | let first = self.index(self.startIndex, offsetBy: ini) 108 | let last = self.index(self.startIndex, offsetBy: fin) 109 | let range = first ..< last 110 | let text = self.substring(with: range) 111 | 112 | return text 113 | } 114 | 115 | // Regex 116 | 117 | func match(_ pattern: String) -> Bool { 118 | guard self.characters.count > 0 else { return false } 119 | if let first = self.range(of: pattern, options: .regularExpression) { 120 | let match = self.substring(with: first) 121 | return !match.isEmpty 122 | } 123 | 124 | return false 125 | } 126 | 127 | func matchFirst(_ pattern: String) -> String { 128 | guard self.characters.count > 0 else { return "" } 129 | if let first = self.range(of: pattern, options: .regularExpression) { 130 | let match = self.substring(with: first) 131 | return match 132 | } 133 | 134 | return "" 135 | } 136 | 137 | func matchAll(_ pattern: String) -> [String] { 138 | var matches = [String]() 139 | guard self.characters.count > 0 else { return matches } 140 | let all = NSRange(location: 0, length: self.characters.count) 141 | 142 | do { 143 | let regex = try NSRegularExpression(pattern: pattern, options: []) 144 | let results = regex.matches(in: self, options: [], range: all) 145 | 146 | for item in results { 147 | let first = item.rangeAt(1) 148 | let range = self.rangeIndex(first) 149 | let match = self.substring(with: range) 150 | 151 | matches.append(match) 152 | } 153 | } catch { 154 | print(error) 155 | } 156 | 157 | return matches 158 | } 159 | 160 | // Painful conversion from a Range to a Range 161 | func rangeIndex(_ range: NSRange) -> Range { 162 | let index1 = self.utf16.index(self.utf16.startIndex, offsetBy: range.location, limitedBy: self.utf16.endIndex) 163 | let index2 = self.utf16.index(index1!, offsetBy: range.length, limitedBy: self.utf16.endIndex) 164 | let bound1 = String.Index(index1!, within: self)! 165 | let bound2 = String.Index(index2!, within: self)! 166 | let result = Range(uncheckedBounds: (bound1, bound2)) 167 | 168 | return result 169 | } 170 | 171 | } 172 | 173 | 174 | extension Date { 175 | 176 | static func fromString(_ text: String) -> Date? { 177 | // No format? use default 178 | return fromString(text, format: "yyyy-MM-dd HH:mm:ss") 179 | } 180 | 181 | static func fromString(_ text: String, format: String) -> Date? { 182 | if !text.isEmpty { 183 | let formatter = DateFormatter() 184 | formatter.dateFormat = format 185 | if let date = formatter.date(from: text) { 186 | return date 187 | } 188 | } 189 | 190 | return nil 191 | } 192 | 193 | } 194 | 195 | 196 | extension Int { 197 | 198 | // Inclusive 199 | func inRange(_ min: Int, _ max: Int) -> Bool { 200 | if self >= min && self <= max { return true } 201 | return false 202 | } 203 | 204 | func plural(_ text: String) -> String { 205 | let word = text + (self == 1 ? "" : "s") 206 | return("\(self) \(word)") 207 | } 208 | 209 | } 210 | 211 | extension Double { 212 | 213 | // Accept 123.00 - 1,234.00 and $123.00 214 | static func fromText(_ text: String) -> Double? { 215 | var num = text.replacingOccurrences(of: ",", with: "") 216 | num = num.replacingOccurrences(of: "$", with: "") 217 | if let value = Double(num) { return value } 218 | 219 | return nil 220 | } 221 | } 222 | 223 | 224 | // End 225 | -------------------------------------------------------------------------------- /DataText/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // DataText 4 | // 5 | // Created by Mac Mini on 2/5/17. 6 | // Copyright © 2017 Armonia. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | 12 | class ViewController: NSViewController { 13 | 14 | enum TabPanel { 15 | case Browse, Schema, Text 16 | } 17 | 18 | var currentTab = TabPanel.Browse 19 | var currentColumn = 0 20 | var tableController = TableController() 21 | 22 | @IBOutlet var textView : NSTextView! 23 | @IBOutlet weak var textStatus : NSTextField! 24 | @IBOutlet weak var tableView : NSTableView! 25 | 26 | @IBAction func onInsertRecord(_ sender: AnyObject) { 27 | tableController.insertRecord() 28 | showRecordCount() 29 | } 30 | 31 | @IBAction func onRemoveRecord(_ sender: AnyObject) { 32 | tableController.removeRecord() 33 | showRecordCount() 34 | } 35 | 36 | @IBAction func onDuplicateRecord(_ sender: AnyObject) { 37 | tableController.duplicateRecord() 38 | showRecordCount() 39 | } 40 | 41 | @IBAction func onInsertColumn(_ sender: AnyObject) { 42 | tableController.insertColumn() 43 | } 44 | 45 | @IBAction func onRemoveColumn(_ sender: AnyObject) { 46 | tableController.removeColumn() 47 | } 48 | 49 | @IBAction func onAlignLeft(_ sender: AnyObject) { 50 | tableController.alignLeft() 51 | } 52 | 53 | @IBAction func onAlignCenter(_ sender: AnyObject) { 54 | tableController.alignCenter() 55 | } 56 | 57 | @IBAction func onAlignRight(_ sender: AnyObject) { 58 | tableController.alignRight() 59 | } 60 | 61 | @IBAction func onChangeDataText(_ sender: AnyObject) { 62 | tableController.changeDataText() 63 | } 64 | 65 | @IBAction func onChangeDataInt(_ sender: AnyObject) { 66 | tableController.changeDataInt() 67 | } 68 | 69 | @IBAction func onChangeDataReal(_ sender: AnyObject) { 70 | tableController.changeDataReal() 71 | } 72 | 73 | @IBAction func onChangeDataDate(_ sender: AnyObject) { 74 | tableController.changeDataDate() 75 | } 76 | 77 | @IBAction func onChangeDataTime(_ sender: AnyObject) { 78 | tableController.changeDataTime() 79 | } 80 | 81 | @IBAction func onChangeDataBool(_ sender: AnyObject) { 82 | tableController.changeDataBool() 83 | } 84 | 85 | override func keyUp(with event: NSEvent) { 86 | //print("View key pressed: ", event.keyCode) 87 | 88 | if tableController.isEditing { 89 | switch event.keyCode { 90 | case 126 /* up */ : tableController.editCellUp() 91 | case 125 /* dn */ : tableController.editCellDown() 92 | case 53 /* esc */ : tableController.isEditing = false 93 | case 36 /* enter */ : tableController.isEditing = false 94 | default : super.keyUp(with: event) 95 | } 96 | } else { 97 | super.keyUp(with: event) 98 | } 99 | } 100 | 101 | override func viewDidLoad() { 102 | super.viewDidLoad() 103 | initialize() 104 | } 105 | 106 | override var representedObject: Any? { 107 | didSet { 108 | // Update the view, if already loaded. 109 | } 110 | } 111 | 112 | func initialize() { 113 | tableController.tableView = tableView 114 | //print("Ready") 115 | } 116 | 117 | func loadTable(_ url: URL) { 118 | //print("VC Load table: ", url) 119 | // TODO: Use document loader? 120 | let text = try? String(contentsOf: url, encoding: .utf8) 121 | tableController.load(text ?? "") 122 | showRecordCount() 123 | } 124 | 125 | func loadSampleTable() { 126 | //print("VC Load sample table") 127 | tableController.loadSample() 128 | showRecordCount() 129 | } 130 | 131 | /* 132 | func prepareTable() { 133 | tableController = TableController() 134 | tableController.tableView = tableView 135 | tableController.getSchema() // tablename.schema 136 | tableController.getRecords() // tablename.table 137 | tableController.makeTable() 138 | tableController.reload() 139 | //tableController.onSelection(selectTable) 140 | showRecordCount() 141 | } 142 | */ 143 | 144 | func showRecordCount() { 145 | let count = tableController.table.records.count 146 | let word = count == 1 ? "record" : "records" 147 | showStatus("\(count) \(word)") 148 | } 149 | 150 | func showStatus(_ text: String) { 151 | textStatus.stringValue = text 152 | } 153 | 154 | 155 | } 156 | 157 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # DataText 1.0 2 | 3 | A simple data editor without the need for a database manager, just open any table document and save it anywhere you want. The table can be edited with any text editor since the format is in plain text. 4 | 5 | Here is some sample data: 6 | 7 | ``` 8 | [ Id | Name | Phone | Salary | Hired | Active ] 9 | [ ------ | -------------------- | ---------------- | ----------- | ----------- | ------ ] 10 | [ 1001 | Taylor Swift | 555-TAYSWIFT | 25425.95 | 2015-01-01 | true ] 11 | [ 1002 | Megan Fox | 800-MEGANFOX | 19750.95 | 2016-07-15 | false ] 12 | [ 1003 | John Travolta | 555-TRAVOLTA | 64545.95 | 2015-08-22 | true ] 13 | [ 1004 | Jesse James | 555-BLACKJACK | 52772.95 | 2014-12-10 | false ] 14 | [ 1005 | John Dillinger | 900-DILLINGER | 145320.95 | 2010-12-24 | false ] 15 | ``` 16 | 17 | ### Screenshot: 18 | 19 | ![Screenshot](https://raw.githubusercontent.com/kuyawa/Gallery/master/DataText/Screenshot.jpg) 20 | 21 | ### ToDo: 22 | 23 | Finish schema editor to save column type, size, alignment and position. 24 | 25 | This data editor is awesome! 26 | -------------------------------------------------------------------------------- /ToDo.txt: -------------------------------------------------------------------------------- 1 | TODO: 2 | 3 | - allow to rename column headers 4 | - allow to change column type and column alignment 5 | - save schema as .schema file and load if available 6 | - allow to open file from OS 7 | 8 | -------------------------------------------------- 9 | 10 | 11 | x app Icon 12 | x select multiple rows 13 | x allow to add/remove columns, warn before removing cols unless empty col 14 | x cmd + add record 15 | x cmd - remove record 16 | x cmd D duplicate record 17 | x allow to add multiple records at once with some values 18 | x insert records 19 | x records will be deleted directly 20 | ? add isDeleted field to every row 21 | ? if isDeleted set row background to light gray 22 | ? if isDeleted do not save record, skip it 23 | ? first column should always be delete marker 24 | 25 | x file toolbar: new, open, save, duplicate 26 | ~ table toolbar: add col, del col, schema editor 27 | x on update grid, update underlying records 28 | x table editor, allow to modify cells 29 | x new document: new table, four columns, one row 30 | x tableController class 31 | x readme 32 | --------------------------------------------------------------------------------