Skip to content

Commit 40d95be

Browse files
authored
Merge pull request gitx#7 from nanotech/f/remember-text-prefs
Remember text substitution preferences
2 parents 9883dbc + cb8ff64 commit 40d95be

File tree

5 files changed

+114
-2
lines changed

5 files changed

+114
-2
lines changed

Classes/Views/GitXTextView.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// GitXTextView.h
3+
// GitX
4+
//
5+
// Created by NanoTech on 2016-12-14.
6+
//
7+
8+
#import <Cocoa/Cocoa.h>
9+
10+
/** A text view that remembers text substitution preferences. */
11+
@interface GitXTextView : NSTextView
12+
@end

Classes/Views/GitXTextView.m

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//
2+
// GitXTextView.m
3+
// GitX
4+
//
5+
// Created by NanoTech on 2016-12-14.
6+
//
7+
8+
#import "GitXTextView.h"
9+
10+
static NSString *AutomaticDashSubstitutionEnabledKey = @"GitXTextViewAutomaticDashSubstitutionEnabled";
11+
static NSString *AutomaticDataDetectionEnabledKey = @"GitXTextViewAutomaticDataDetectionEnabled";
12+
static NSString *AutomaticLinkDetectionEnabledKey = @"GitXTextViewAutomaticLinkDetectionEnabled";
13+
static NSString *AutomaticQuoteSubstitutionEnabled = @"GitXTextViewAutomaticQuoteSubstitutionEnabled";
14+
static NSString *AutomaticSpellingCorrectionEnabledKey = @"GitXTextViewAutomaticSpellingCorrectionEnabled";
15+
static NSString *AutomaticTextReplacementEnabledKey = @"GitXTextViewAutomaticTextReplacementEnabled";
16+
static NSString *SmartInsertDeleteEnabledKey = @"GitXTextViewSmartInsertDeleteEnabled"; // "Smart Copy/Paste"
17+
18+
@implementation GitXTextView
19+
20+
+ (void)initialize
21+
{
22+
if (self != [GitXTextView class]) return;
23+
24+
// Matches the commit message text view properties in PBGitCommitView.xib
25+
[[NSUserDefaults standardUserDefaults] registerDefaults:@{
26+
AutomaticDashSubstitutionEnabledKey : @(NO),
27+
AutomaticDataDetectionEnabledKey : @(NO),
28+
AutomaticLinkDetectionEnabledKey : @(YES),
29+
AutomaticQuoteSubstitutionEnabled : @(NO),
30+
AutomaticSpellingCorrectionEnabledKey : @(NO),
31+
AutomaticTextReplacementEnabledKey : @(NO),
32+
SmartInsertDeleteEnabledKey : @(YES),
33+
}];
34+
}
35+
36+
- (void)awakeFromNib
37+
{
38+
[super awakeFromNib];
39+
40+
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
41+
super.automaticDashSubstitutionEnabled = [defaults boolForKey:AutomaticDashSubstitutionEnabledKey];
42+
super.automaticDataDetectionEnabled = [defaults boolForKey:AutomaticDataDetectionEnabledKey];
43+
super.automaticLinkDetectionEnabled = [defaults boolForKey:AutomaticLinkDetectionEnabledKey];
44+
super.automaticQuoteSubstitutionEnabled = [defaults boolForKey:AutomaticQuoteSubstitutionEnabled];
45+
super.automaticSpellingCorrectionEnabled = [defaults boolForKey:AutomaticSpellingCorrectionEnabledKey];
46+
super.automaticTextReplacementEnabled = [defaults boolForKey:AutomaticTextReplacementEnabledKey];
47+
super.smartInsertDeleteEnabled = [defaults boolForKey:SmartInsertDeleteEnabledKey];
48+
}
49+
50+
- (void)setAutomaticDashSubstitutionEnabled:(BOOL)enabled
51+
{
52+
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:AutomaticDashSubstitutionEnabledKey];
53+
[super setAutomaticDashSubstitutionEnabled:enabled];
54+
}
55+
56+
- (void)setAutomaticDataDetectionEnabled:(BOOL)enabled
57+
{
58+
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:AutomaticDataDetectionEnabledKey];
59+
[super setAutomaticDataDetectionEnabled:enabled];
60+
}
61+
62+
- (void)setAutomaticLinkDetectionEnabled:(BOOL)enabled
63+
{
64+
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:AutomaticLinkDetectionEnabledKey];
65+
[super setAutomaticLinkDetectionEnabled:enabled];
66+
}
67+
68+
- (void)setAutomaticQuoteSubstitutionEnabled:(BOOL)enabled
69+
{
70+
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:AutomaticQuoteSubstitutionEnabled];
71+
[super setAutomaticQuoteSubstitutionEnabled:enabled];
72+
}
73+
74+
- (void)setAutomaticSpellingCorrectionEnabled:(BOOL)enabled
75+
{
76+
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:AutomaticSpellingCorrectionEnabledKey];
77+
[super setAutomaticSpellingCorrectionEnabled:enabled];
78+
}
79+
80+
- (void)setAutomaticTextReplacementEnabled:(BOOL)enabled
81+
{
82+
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:AutomaticTextReplacementEnabledKey];
83+
[super setAutomaticTextReplacementEnabled:enabled];
84+
}
85+
86+
- (void)setSmartInsertDeleteEnabled:(BOOL)enabled
87+
{
88+
[[NSUserDefaults standardUserDefaults] setBool:enabled forKey:SmartInsertDeleteEnabledKey];
89+
[super setSmartInsertDeleteEnabled:enabled];
90+
}
91+
92+
@end

Classes/Views/PBCommitMessageView.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
// Copyright 2008 Jeff Mesnil (http://jmesnil.net/). All rights reserved.
77
//
88

9-
#import <Cocoa/Cocoa.h>
9+
#import "GitXTextView.h"
1010

1111
@class PBGitRepository;
1212

13-
@interface PBCommitMessageView : NSTextView
13+
@interface PBCommitMessageView : GitXTextView
1414

1515
@property (nonatomic, strong) PBGitRepository *repository;
1616

Classes/Views/PBCommitMessageView.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ @implementation PBCommitMessageView
1515

1616
- (void) awakeFromNib
1717
{
18+
[super awakeFromNib];
19+
1820
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
1921

2022
[defaults addObserver:self

GitX.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
97CF01FB18A6C5BB00E30F2B /* new_file.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 97CF01F818A6C5BB00E30F2B /* new_file.pdf */; };
183183
A2F8D0DF17AAB32500580B84 /* PBGitStash.m in Sources */ = {isa = PBXBuildFile; fileRef = A2F8D0DE17AAB32500580B84 /* PBGitStash.m */; };
184184
A2F8D0EB17AAB95E00580B84 /* PBGitSVStashItem.m in Sources */ = {isa = PBXBuildFile; fileRef = A2F8D0EA17AAB95E00580B84 /* PBGitSVStashItem.m */; };
185+
BF42F1331E025403004769FF /* GitXTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = BF42F1321E025403004769FF /* GitXTextView.m */; };
185186
D87127011229A21C00012334 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D87127001229A21C00012334 /* QuartzCore.framework */; };
186187
D89E9B141218BA260097A90B /* ScriptingBridge.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D89E9AB21218A9DA0097A90B /* ScriptingBridge.framework */; };
187188
D8E3B2B810DC9FB2001096A3 /* ScriptingBridge.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D8E3B2B710DC9FB2001096A3 /* ScriptingBridge.framework */; };
@@ -614,6 +615,8 @@
614615
A2F8D0DE17AAB32500580B84 /* PBGitStash.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitStash.m; sourceTree = "<group>"; };
615616
A2F8D0E917AAB95E00580B84 /* PBGitSVStashItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitSVStashItem.h; sourceTree = "<group>"; };
616617
A2F8D0EA17AAB95E00580B84 /* PBGitSVStashItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitSVStashItem.m; sourceTree = "<group>"; };
618+
BF42F1321E025403004769FF /* GitXTextView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GitXTextView.m; sourceTree = "<group>"; };
619+
BF42F1431E025411004769FF /* GitXTextView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GitXTextView.h; sourceTree = "<group>"; };
617620
D87127001229A21C00012334 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
618621
D89E9AB21218A9DA0097A90B /* ScriptingBridge.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ScriptingBridge.framework; path = System/Library/Frameworks/ScriptingBridge.framework; sourceTree = SDKROOT; };
619622
D8E3B2B710DC9FB2001096A3 /* ScriptingBridge.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ScriptingBridge.framework; path = /System/Library/Frameworks/ScriptingBridge.framework; sourceTree = "<absolute>"; };
@@ -1002,6 +1005,8 @@
10021005
children = (
10031006
4A5D76B414A9A9CC00DF6C68 /* GitXTextFieldCell.h */,
10041007
4A5D76B514A9A9CC00DF6C68 /* GitXTextFieldCell.m */,
1008+
BF42F1431E025411004769FF /* GitXTextView.h */,
1009+
BF42F1321E025403004769FF /* GitXTextView.m */,
10051010
4A5D76B614A9A9CC00DF6C68 /* GLFileView.h */,
10061011
4A5D76B714A9A9CC00DF6C68 /* GLFileView.m */,
10071012
4A5D76B814A9A9CC00DF6C68 /* PBAddRemoteSheet.h */,
@@ -1476,6 +1481,7 @@
14761481
4A5D773914A9A9CC00DF6C68 /* PBSourceViewItem.m in Sources */,
14771482
4A5D777314A9AEB000DF6C68 /* PBSourceViewAction.m in Sources */,
14781483
4A5D777414A9AEB000DF6C68 /* PBSourceViewBadge.m in Sources */,
1484+
BF42F1331E025403004769FF /* GitXTextView.m in Sources */,
14791485
4A5D777514A9AEB000DF6C68 /* PBSourceViewRemote.m in Sources */,
14801486
4AB71FF814B7EDD400F1DFFC /* RJModalRepoSheet.m in Sources */,
14811487
643952771603EF9B00BB7AFF /* PBGitSVSubmoduleItem.m in Sources */,

0 commit comments

Comments
 (0)