Commit dbf25593 authored by Koen van der Veen's avatar Koen van der Veen
Browse files

change actionName to be Enum

parent d8b0ec8f
Showing with 101 additions and 79 deletions
+101 -79
......@@ -4,6 +4,8 @@ memri.xcodeproj/xcuserdata/
xcuserdata
memri.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/
builds/
#########################
# .gitignore file for Xcode4 and Xcode5 Source projects
#
......
......@@ -20,6 +20,7 @@
5D1A3E6B2408086800A0583B /* Session_v1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D1A3E6A2408086800A0583B /* Session_v1.swift */; };
5D1A3E6D24080BD800A0583B /* empty_session.json in Resources */ = {isa = PBXBuildFile; fileRef = 5D1A3E6C2408099900A0583B /* empty_session.json */; };
5D1A3E6E24080BDA00A0583B /* empty_session.json in Resources */ = {isa = PBXBuildFile; fileRef = 5D1A3E6C2408099900A0583B /* empty_session.json */; };
5D228B042432275600464506 /* ActionDescription.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D228B032432275600464506 /* ActionDescription.swift */; };
5D2934F023FEA1CD0073E25F /* DataStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D2934EF23FEA1CD0073E25F /* DataStore.swift */; };
5D38DE11240576D200FF9B70 /* PodAPITest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D38DE10240576D200FF9B70 /* PodAPITest.swift */; };
5D38DE132405775400FF9B70 /* api.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5D38DE122405775400FF9B70 /* api.swift */; };
......@@ -151,6 +152,7 @@
5D1A3E68240807C100A0583B /* SessionTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionTest.swift; sourceTree = "<group>"; };
5D1A3E6A2408086800A0583B /* Session_v1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Session_v1.swift; sourceTree = "<group>"; };
5D1A3E6C2408099900A0583B /* empty_session.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = empty_session.json; sourceTree = "<group>"; };
5D228B032432275600464506 /* ActionDescription.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionDescription.swift; sourceTree = "<group>"; };
5D2934EF23FEA1CD0073E25F /* DataStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataStore.swift; sourceTree = "<group>"; };
5D38DE10240576D200FF9B70 /* PodAPITest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PodAPITest.swift; sourceTree = "<group>"; };
5D38DE122405775400FF9B70 /* api.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = api.swift; sourceTree = "<group>"; };
......@@ -388,6 +390,7 @@
children = (
5DFB0CBE24179FA6002FBDE7 /* Session.swift */,
5D38DE18240577BA00FF9B70 /* SessionView.swift */,
5D228B032432275600464506 /* ActionDescription.swift */,
);
path = view;
sourceTree = "<group>";
......@@ -746,6 +749,7 @@
5D493FDE23FC15FF0034692B /* RichTextEditor.swift in Sources */,
5D3D961F24164B240004040E /* CodeExtended.swift in Sources */,
5DD28B772417BAF900CE9F6A /* ThumbnailRenderer.swift in Sources */,
5D228B042432275600464506 /* ActionDescription.swift in Sources */,
5D3D9621241675100004040E /* util.swift in Sources */,
5DD1E9B323FD7E59007BDF7B /* TopNavigation.swift in Sources */,
5DFB0CBF24179FA6002FBDE7 /* Session.swift in Sources */,
......
......@@ -243,43 +243,43 @@ public class Main: ObservableObject {
let params = action.actionArgs
switch action.actionName {
case "back":
case .back:
back()
case "add":
case .add:
let item = Note(value: params[0].value)
add(item)
case "openView":
case .openView:
if let item = item {
openView(item)
} else {
let param0 = params[0].value as! SessionView
openView(param0)
}
case "toggleEdit":
case .toggleEdit:
toggleEditMode()
case "toggleFilterPanel":
case .toggleFilterPanel:
toggleFilterPanel()
case "star":
case .star:
star()
case "showStarred":
case .showStarred:
showStarred()
case "showContextPane":
case .showContextPane:
openContextPane() // TODO @Jess
case "openContextView":
case .openContextView:
break
case "share":
case .share:
shareNote()
case "addToList":
case .addToList:
addToList()
case "duplicateNote":
case .duplicateNote:
duplicateNote()
case "noteTimeline":
case .noteTimeline:
noteTimeline()
case "starredNotes":
case .starredNotes:
starredNotes()
case "allNotes":
case .allNotes:
allNotes()
case "exampleUnpack":
case .exampleUnpack:
let (_, _) = (params[0].value, params[1].value) as! (String, Int)
break
default:
......@@ -358,7 +358,7 @@ public class Main: ObservableObject {
}
let starButton = self.currentView.filterButtons!.filter{$0.actionName == "showStarred"}[0] // HACK
let starButton = self.currentView.filterButtons!.filter{$0.actionName == .showStarred}[0] // HACK
toggleColor(object: starButton, color1: .gray, color2: .systemYellow)
// If showing starred items, return to normal view
......
......@@ -61,7 +61,7 @@ struct ListRenderer: Renderer {
// var renderConfig: RenderConfig = RenderConfig()
var renderConfig: RenderConfig = ListConfig(press:
ActionDescription(icon: nil, title: nil, actionName: "openView", actionArgs: []))
ActionDescription(icon: nil, title: nil, actionName: .openView, actionArgs: []))
func setState(_ state:RenderState) -> Bool { return false }
......
......@@ -27,7 +27,7 @@ struct ThumbnailRenderer: View {
var options2: [ActionDescription]=[]
var editMode: Bool=false
// var renderConfig: RenderConfig=RenderConfig()
var renderConfig: RenderConfig = ListConfig(press: ActionDescription(icon: nil, title: nil, actionName: "openView", actionArgs: [])
var renderConfig: RenderConfig = ListConfig(press: ActionDescription(icon: nil, title: nil, actionName: .openView, actionArgs: [])
)
var cols: Int = 3
......
......@@ -15,7 +15,7 @@ var config = Realm.Configuration(
// Set the new schema version. This must be greater than the previously used
// version (if you've never set a schema version before, the version is 0).
schemaVersion: 8,
schemaVersion: 12,
// Set the block which will be called automatically when opening a Realm with
// a schema version lower than the one set above
......
//
// ActionDescription.swift
// memri
//
// Created by Koen van der Veen on 30/03/2020.
// Copyright © 2020 memri. All rights reserved.
//
import Foundation
import Combine
import SwiftUI
public enum ActionName: String, Codable {
case back, add, openView, toggleEdit, toggleFilterPanel, star, showStarred, showContextPane, showOverlay, openContextView, share,
addToPanel, duplicate, schedule, addToList, duplicateNote, noteTimeline, starredNotes, allNotes, exampleUnpack, noop
}
public class ActionDescription: Decodable, Identifiable {
public var id = UUID()
var color: UIColor = .gray
var icon: String = ""
var title: String = ""
var actionName: ActionName = .noop
var actionArgs: [AnyCodable] = []
public convenience required init(from decoder: Decoder) throws{
self.init()
jsonErrorHandling(decoder) {
self.icon = try decoder.decodeIfPresent("icon") ?? self.icon
self.title = try decoder.decodeIfPresent("title") ?? self.title
self.actionName = try decoder.decodeIfPresent("actionName") ?? self.actionName
self.actionArgs = try decoder.decodeIfPresent("actionArgs") ?? self.actionArgs
let colorString = try decoder.decodeIfPresent("color") ?? ""
switch colorString{
case "gray": self.color = .gray
case "yellow","systemYellow": self.color = .systemYellow
default: self.color = .gray
}
// we manually set the objects for the actionArgs key, since it has a somewhat dynamic value
switch self.actionName{
case .add:
break
// self.actionArgs[0] = AnyCodable(try DataItem(from: self.actionArgs[0].value))
case .openView:
break
// TODO make this work
// self.actionArgs[0] = AnyCodable(try! SessionView(from: self.actionArgs[0].value))
default:
break
}
}
}
public convenience init(icon: String?=nil, title: String?=nil, actionName: ActionName?=nil, actionArgs: [AnyCodable]?=nil){
self.init()
self.icon = icon ?? self.icon
self.title = title ?? self.title
self.actionName = actionName ?? self.actionName
self.actionArgs = actionArgs ?? self.actionArgs
}
public class func from_json(_ file: String, ext: String = "json") throws -> ActionDescription {
let jsonData = try jsonDataFromFile(file, ext)
let description: ActionDescription = try! JSONDecoder().decode(ActionDescription.self, from: jsonData)
return description
}
}
......@@ -108,7 +108,7 @@ public class Session: ObservableObject, Decodable, Equatable {
var backButton: ActionDescription? {
if self.currentViewIndex > 0 {
return ActionDescription(icon: "chevron.left", actionName: "back")
return ActionDescription(icon: "chevron.left", actionName: .back)
}else{
return nil
}
......
......@@ -3,63 +3,6 @@ import Combine
import SwiftUI
public class ActionDescription: Decodable, Identifiable {
public var id = UUID()
var color: UIColor = .gray
var icon: String = ""
var title: String = ""
var actionName: String = ""
var actionArgs: [AnyCodable] = []
public convenience required init(from decoder: Decoder) throws{
self.init()
jsonErrorHandling(decoder) {
self.icon = try decoder.decodeIfPresent("icon") ?? self.icon
self.title = try decoder.decodeIfPresent("title") ?? self.title
self.actionName = try decoder.decodeIfPresent("actionName") ?? self.actionName
self.actionArgs = try decoder.decodeIfPresent("actionArgs") ?? self.actionArgs
let colorString = try decoder.decodeIfPresent("color") ?? ""
switch colorString{
case "gray": self.color = .gray
case "yellow","systemYellow": self.color = .systemYellow
default: self.color = .gray
}
// we manually set the objects for the actionArgs key, since it has a somewhat dynamic value
switch self.actionName{
case "add":
// self.actionArgs[0] = AnyCodable(try DataItem(from: self.actionArgs[0].value))
1+1
case "openView":
// TODO make this work
1+1
// self.actionArgs[0] = AnyCodable(try! SessionView(from: self.actionArgs[0].value))
default:
break
}
}
}
public convenience init(icon: String?=nil, title: String?=nil, actionName: String?=nil, actionArgs: [AnyCodable]?=nil){
self.init()
self.icon = icon ?? self.icon
self.title = title ?? self.title
self.actionName = actionName ?? self.actionName
self.actionArgs = actionArgs ?? self.actionArgs
}
public class func from_json(_ file: String, ext: String = "json") throws -> ActionDescription {
let jsonData = try jsonDataFromFile(file, ext)
let description: ActionDescription = try! JSONDecoder().decode(ActionDescription.self, from: jsonData)
return description
}
}
public class SessionView: ObservableObject, Decodable{
@Published public var searchResult: SearchResult = SearchResult()
@Published public var title: String? = nil
......
......@@ -92,7 +92,7 @@
{
"icon": "increase.indent",
"title": "Show Timeline",
"actionName": "!!!!!!!<CHANGED TO PREVENT CRASH FOR S&T>!!!!!",
"actionName": "noop",
"actionArgs": [{
"rendererName": "timeline",
"renderConfig": {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment