Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
New icon, default mode
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallino16 committed Mar 22, 2021
1 parent 3ff861f commit 2cb35ba
Show file tree
Hide file tree
Showing 25 changed files with 58 additions and 23 deletions.
4 changes: 4 additions & 0 deletions Snip.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
7936F89A24D845B600F09AE7 /* SnipItemsListAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7936F89924D845B600F09AE7 /* SnipItemsListAction.swift */; };
7936F89F24DA02DD00F09AE7 /* TextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7936F89E24DA02DD00F09AE7 /* TextField.swift */; };
7947B90E25FE48C4005BF623 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7947B90D25FE48C4005BF623 /* AppDelegate.swift */; };
794CF88826089E8400408631 /* UserDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 794CF88726089E8400408631 /* UserDefaults.swift */; };
794D27CE24F672E4006E3B3D /* SnipTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 794D27CD24F672E4006E3B3D /* SnipTests.swift */; };
794D27D924F68FF2006E3B3D /* Down in Frameworks */ = {isa = PBXBuildFile; productRef = 794D27D824F68FF2006E3B3D /* Down */; };
794D27DB24F6A19C006E3B3D /* Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 794D27DA24F6A19C006E3B3D /* Data.swift */; };
Expand Down Expand Up @@ -102,6 +103,7 @@
7936F89924D845B600F09AE7 /* SnipItemsListAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnipItemsListAction.swift; sourceTree = "<group>"; };
7936F89E24DA02DD00F09AE7 /* TextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextField.swift; sourceTree = "<group>"; };
7947B90D25FE48C4005BF623 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
794CF88726089E8400408631 /* UserDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaults.swift; sourceTree = "<group>"; };
794D27CB24F672E4006E3B3D /* SnipTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SnipTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
794D27CD24F672E4006E3B3D /* SnipTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SnipTests.swift; sourceTree = "<group>"; };
794D27CF24F672E4006E3B3D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -370,6 +372,7 @@
79284D6E250A23E900210E61 /* Bundle.swift */,
795D51EA252B686C00613D0F /* Binding.swift */,
79EC4826252CA90E00E45AC3 /* EnvironmentValues.swift */,
794CF88726089E8400408631 /* UserDefaults.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -587,6 +590,7 @@
79C612B92506B27F008672BA /* SettingsView.swift in Sources */,
79F07A2524D2F9C700469324 /* CodeActionsTopBar.swift in Sources */,
79956A4B24E58A0900B823E1 /* SyncManager.swift in Sources */,
794CF88826089E8400408631 /* UserDefaults.swift in Sources */,
79E82BA2257E37C0005B2CBD /* CodeMirrorViewController.swift in Sources */,
79AC7AE625F03B3F006431C8 /* SidebarTagView.swift in Sources */,
794DBE92252B454B000DFCF2 /* Theme.swift in Sources */,
Expand Down
20 changes: 10 additions & 10 deletions Snip/Assets.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,61 @@
{
"size" : "16x16",
"idiom" : "mac",
"filename" : "Snip-16.png",
"filename" : "Snip2-16.png",
"scale" : "1x"
},
{
"size" : "16x16",
"idiom" : "mac",
"filename" : "Snip-32.png",
"filename" : "Snip2-32.png",
"scale" : "2x"
},
{
"size" : "32x32",
"idiom" : "mac",
"filename" : "Snip-32.png",
"filename" : "Snip2-32.png",
"scale" : "1x"
},
{
"size" : "32x32",
"idiom" : "mac",
"filename" : "Snip-64.png",
"filename" : "Snip2-64.png",
"scale" : "2x"
},
{
"size" : "128x128",
"idiom" : "mac",
"filename" : "Snip-128.png",
"filename" : "Snip2-128.png",
"scale" : "1x"
},
{
"size" : "128x128",
"idiom" : "mac",
"filename" : "Snip-256.png",
"filename" : "Snip2-256.png",
"scale" : "2x"
},
{
"size" : "256x256",
"idiom" : "mac",
"filename" : "Snip-256.png",
"filename" : "Snip2-256.png",
"scale" : "1x"
},
{
"size" : "256x256",
"idiom" : "mac",
"filename" : "Snip-512.png",
"filename" : "Snip2-512.png",
"scale" : "2x"
},
{
"size" : "512x512",
"idiom" : "mac",
"filename" : "Snip-512.png",
"filename" : "Snip2-512.png",
"scale" : "1x"
},
{
"size" : "512x512",
"idiom" : "mac",
"filename" : "Snip-1024.png",
"filename" : "Snip2-1024.png",
"scale" : "2x"
}
],
Expand Down
Binary file not shown.
Binary file removed Snip/Assets.xcassets/AppIcon.appiconset/Snip-128.png
Binary file not shown.
Binary file not shown.
Binary file removed Snip/Assets.xcassets/AppIcon.appiconset/Snip-32.png
Binary file not shown.
Binary file not shown.
Binary file removed Snip/Assets.xcassets/AppIcon.appiconset/Snip-64.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions Snip/Components/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,19 @@ struct SettingsView: View {
.padding(EdgeInsets(top: 4, leading: 16, bottom: 0, trailing: 16))

HStack {
Text(NSLocalizedString("CD_Theme", comment: ""))
Text(NSLocalizedString("Default_Mode", comment: ""))
.foregroundColor(themeTextColor)
Spacer()
Picker(selection: Binding<Int>(
get: {
let index = /*CodeMode.list().firstIndex(where: { (mode) -> Bool in
mode == self.viewModel.currentMode
}) ?? -1*/ 0
let index = CodeMode.list().firstIndex(where: { (mode) -> Bool in
mode == settings.defaultMode
}) ?? -1
return index
},
set: {
selectedMode = $0
settings.defaultMode = CodeMode.list()[$0]
}),
label: EmptyView()) {
ForEach(0 ..< CodeMode.list().count, id: \.self) {
Expand Down
2 changes: 1 addition & 1 deletion Snip/Components/Sidebar/Sidebar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct Sidebar: View {
VStack() {
Button(action: {
self.expand.toggle()
self.viewModel.onTrigger(.addSnippet(id: nil))
self.viewModel.onTrigger(.addSnippet(id: nil, settings: settings))
}) {
Text(NSLocalizedString("New_Snippet", comment: ""))
.font(.system(size: 14))
Expand Down
3 changes: 2 additions & 1 deletion Snip/Components/Sidebar/SnipItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct SnipItemView<Content: View>: View {

@ObservedObject var viewModel: SnipItemViewModel

@EnvironmentObject var settings: Settings
@EnvironmentObject var appState: AppState

@Environment(\.themePrimaryColor) var themePrimaryColor
Expand Down Expand Up @@ -114,7 +115,7 @@ struct SnipItemView<Content: View>: View {
}

Button(action: {
viewModel.onTrigger(.addSnippet(id: viewModel.snipItem.id))
viewModel.onTrigger(.addSnippet(id: viewModel.snipItem.id, settings: settings))
isExpanded = true
}) {
Text(NSLocalizedString("Add_Snippet", comment: ""))
Expand Down
5 changes: 4 additions & 1 deletion Snip/Components/Sidebar/SnipItemsListAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ struct SnipItemsListAction {
}
}

static func addSnippet(id: String? = nil) -> SnipItemsListAction {
static func addSnippet(id: String? = nil, settings: Settings? = nil) -> SnipItemsListAction {
return .init { current in

let file = SnipItem.file(name: NSLocalizedString("New_Snippet", comment: "").capitalized)
if let settings = settings {
file.mode = settings.defaultMode
}

if let idParentFolder = id {
let snipItem = current.flatternSnippets.first { (snipItem) -> Bool in
Expand Down
24 changes: 24 additions & 0 deletions Snip/Extensions/UserDefaults.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// UserDefaults.swift
// Snip
//
// Created by Junior on 22/03/2021.
// Copyright © 2021 pictarine. All rights reserved.
//

import Foundation


extension UserDefaults {
func setCodableObject<T: Codable>(_ data: T?, forKey defaultName: String) {
let encoded = try? JSONEncoder().encode(data)
set(encoded, forKey: defaultName)
}

func codableObject<T : Codable>(dataType: T.Type, key: String) -> T? {
guard let userDefaultData = data(forKey: key) else {
return nil
}
return try? JSONDecoder().decode(T.self, from: userDefaultData)
}
}
8 changes: 4 additions & 4 deletions Snip/Model/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class Settings: ObservableObject {
}
}

@Published var defaultMode: CodeMode = CodeMode.text {
@Published var defaultMode: Mode = CodeMode.text.mode() {
didSet {
UserDefaults.standard.set(defaultMode.rawValue, forKey: keys.defaultMode.rawValue)
UserDefaults.standard.setCodableObject(defaultMode, forKey: keys.defaultMode.rawValue)
}
}

Expand All @@ -71,8 +71,8 @@ class Settings: ObservableObject {
codeViewTheme = CodeViewTheme(rawValue: activeTheme)
}

if let snipetDefaultMode = UserDefaults.standard.object(forKey: keys.defaultMode.rawValue) as? String {
defaultMode = CodeMode(rawValue: snipetDefaultMode) ?? .text
if let snipetDefaultMode = UserDefaults.standard.codableObject(dataType: Mode.self, key: keys.defaultMode.rawValue) {
defaultMode = snipetDefaultMode
}

if let appTheme = UserDefaults.standard.object(forKey: keys.appTheme.rawValue) as? String {
Expand Down
1 change: 1 addition & 0 deletions Snip/Resources/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

// General options
"App_Theme" = "Application Theme";
"Default_Mode" = "Default Mode";

// Follower program
"Need_You" = "We Need Your Help!";
Expand Down
1 change: 1 addition & 0 deletions Snip/Resources/de.lproj/Localizable_de.strings
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

// General options
"App_Theme" = "Theme";
"Default_Mode" = "Standardmodus";

// Follower program
"Need_You" = "Wir brauchen deine Hilfe!";
Expand Down
1 change: 1 addition & 0 deletions Snip/Resources/en.lproj/Localizable_en.strings
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@

// General options
"App_Theme" = "Application Theme";
"Default_Mode" = "Default Mode";

// Follower program
"Need_You" = "We Need Your Help!";
Expand Down
3 changes: 1 addition & 2 deletions Snip/SnipViewApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ struct SnipViewApp: View {
@EnvironmentObject var appState: AppState
@EnvironmentObject var settings: Settings


var body: some View {
appNavigation
.frame(maxWidth: .infinity, maxHeight: .infinity)
Expand Down Expand Up @@ -65,7 +64,7 @@ struct SnipViewApp: View {
.frame(width: 800, height: 600)
case .settings:
SettingsView(viewModel: SettingsViewModel(isVisible: $settings.shouldOpenSettings))
.frame(width: 800, height: 600)
.frame(width: 800, height: 700)
case .external:
ExternalSnippet(viewModel: ExternalSnippetViewModel(isVisible: $viewModel.snippetManager.hasExternalSnippetQueued,
snipItem: $viewModel.snippetManager.tempSnipItem,
Expand Down

0 comments on commit 2cb35ba

Please sign in to comment.