Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7cbac52

Browse files
简单修改代码
1 parent 7dd0511 commit 7cbac52

File tree

10 files changed

+348
-28
lines changed

10 files changed

+348
-28
lines changed

‎Coding_iOS.xcodeproj/project.pbxproj‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
4E2DB34C1BA6AEB4002F27C4 /* coding_emoji_gif_07@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4E2DB3451BA6AEB4002F27C4 /* coding_emoji_gif_07@2x.png */; };
145145
4E2DB34D1BA6AEB4002F27C4 /* coding_emoji_gif_01@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 4E2DB3461BA6AEB4002F27C4 /* coding_emoji_gif_01@2x.png */; };
146146
4E2ECEAD1BD4D51000CB6EC9 /* ProjectTransferSettingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E2ECEAC1BD4D51000CB6EC9 /* ProjectTransferSettingViewController.m */; };
147+
4E2F6A571C437D1D00A25502 /* EditCodeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E2F6A561C437D1D00A25502 /* EditCodeViewController.m */; };
147148
4E35A99F1A3EC47E00CE35F1 /* FileViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E35A99E1A3EC47E00CE35F1 /* FileViewController.m */; };
148149
4E38CF5F1A7A28AF005536C0 /* CodeBranchTagButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E38CF5E1A7A28AF005536C0 /* CodeBranchTagButton.m */; };
149150
4E38CF621A7B7C99005536C0 /* CodeBranchOrTag.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E38CF611A7B7C99005536C0 /* CodeBranchOrTag.m */; };
@@ -1243,6 +1244,8 @@
12431244
4E2DB3461BA6AEB4002F27C4 /* coding_emoji_gif_01@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "coding_emoji_gif_01@2x.png"; sourceTree = "<group>"; };
12441245
4E2ECEAB1BD4D51000CB6EC9 /* ProjectTransferSettingViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProjectTransferSettingViewController.h; sourceTree = "<group>"; };
12451246
4E2ECEAC1BD4D51000CB6EC9 /* ProjectTransferSettingViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProjectTransferSettingViewController.m; sourceTree = "<group>"; };
1247+
4E2F6A551C437D1D00A25502 /* EditCodeViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EditCodeViewController.h; sourceTree = "<group>"; };
1248+
4E2F6A561C437D1D00A25502 /* EditCodeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EditCodeViewController.m; sourceTree = "<group>"; };
12461249
4E35A99D1A3EC47E00CE35F1 /* FileViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FileViewController.h; sourceTree = "<group>"; };
12471250
4E35A99E1A3EC47E00CE35F1 /* FileViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FileViewController.m; sourceTree = "<group>"; };
12481251
4E38CF5D1A7A28AF005536C0 /* CodeBranchTagButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CodeBranchTagButton.h; sourceTree = "<group>"; };
@@ -4183,6 +4186,8 @@
41834186
8E59F1091A021053009A905F /* CodeListViewController.m */,
41844187
8E59F10B1A02188D009A905F /* CodeViewController.h */,
41854188
8E59F10C1A02188D009A905F /* CodeViewController.m */,
4189+
4E2F6A551C437D1D00A25502 /* EditCodeViewController.h */,
4190+
4E2F6A561C437D1D00A25502 /* EditCodeViewController.m */,
41864191
4EA6791E1A15AB9F001A0324 /* FileListViewController.h */,
41874192
4EA6791F1A15AB9F001A0324 /* FileListViewController.m */,
41884193
4E15C7CE1A26D2F000FB8DAD /* FolderToMoveViewController.h */,
@@ -6254,6 +6259,7 @@
62546259
4EA6790D1A1461DC001A0324 /* ProjectFolder.m in Sources */,
62556260
8EF643BC19FF7E2900F7EEB0 /* ProjectActivityListCell.m in Sources */,
62566261
4E996BC91ABA754600C704F1 /* JDStatusBarStyle.m in Sources */,
6262+
4E2F6A571C437D1D00A25502 /* EditCodeViewController.m in Sources */,
62576263
8EF83F9419EB78CC00E86DE7 /* SettingTextViewController.m in Sources */,
62586264
4ED618181C3A6CA50017946C /* LocationCell.m in Sources */,
62596265
8EA6D1B019E240C40076D59C /* Comment.m in Sources */,

‎Coding_iOS/Controllers/CodeViewController.m‎

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#import "ProjectCommitsViewController.h"
1313
#import "ProjectViewController.h"
1414
#import "CodeListViewController.h"
15+
#import "EditCodeViewController.h"
1516

1617
@interface CodeViewController ()
1718
@property (strong, nonatomic) UIWebView *webContentView;
@@ -107,7 +108,7 @@ - (void)refreshCodeViewData{
107108
[self.webContentView loadRequest:[NSURLRequest requestWithURL:imageUrl]];
108109
}else if ([_myCodeFile.file.mode isEqualToString:@"file"] ||
109110
[_myCodeFile.file.mode isEqualToString:@"sym_link"]){
110-
NSString *contentStr = [WebContentManager codePatternedWithContent:_myCodeFile];
111+
NSString *contentStr = [WebContentManager codePatternedWithContent:_myCodeFileisEdit:NO];
111112
[self.webContentView loadHTMLString:contentStr baseURL:nil];
112113
}
113114
}
@@ -150,35 +151,58 @@ - (void)configRightNavBtn{
150151
}
151152

152153
- (void)rightNavBtnClicked{
154+
NSMutableArray *actionTitles = @[@"编辑代码", @"查看提交记录", @"退出代码查看"].mutableCopy;
155+
if (!self.myCodeFile.can_edit) {
156+
[actionTitles removeObjectAtIndex:0];
157+
}
153158
__weak typeof(self) weakSelf = self;
154-
[[UIActionSheet bk_actionSheetCustomWithTitle:nil buttonTitles:@[@"查看提交记录", @"退出代码查看"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
155-
switch (index) {
156-
case 0:{
157-
[weakSelf goToCommitsVC];
158-
}
159-
break;
160-
case 1:{
161-
[weakSelf.navigationController.viewControllers enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(UIViewController *obj, NSUInteger idx, BOOL *stop) {
162-
if (![obj isKindOfClass:[CodeViewController class]] &&
163-
![obj isKindOfClass:[CodeListViewController class]] &&
164-
!([obj isKindOfClass:[ProjectViewController class]] && [(ProjectViewController *)obj curType] == ProjectViewTypeCodes)) {
165-
*stop = YES;
166-
[weakSelf.navigationController popToViewController:obj animated:YES];
167-
}
168-
}];
169-
}
170-
break;
171-
default:
172-
break;
173-
}
159+
[[UIActionSheet bk_actionSheetCustomWithTitle:nil buttonTitles:actionTitles destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
160+
[weakSelf actionSheetClicked:sheet index:index];
174161
}] showInView:self.view];
175162
}
176163

164+
- (void)actionSheetClicked:(UIActionSheet *)sheet index:(NSInteger)index{
165+
if (!self.myCodeFile.can_edit) {
166+
index++;
167+
}
168+
if (index == 0) {
169+
[self goToEditVC];
170+
}else if (index == 1){
171+
[self goToCommitsVC];
172+
}else if (index == 2){
173+
[self popOut];
174+
}
175+
}
176+
177+
- (void)goToEditVC{
178+
__weak typeof(self) weakSelf = self;
179+
180+
EditCodeViewController *vc = [EditCodeViewController new];
181+
vc.myProject = _myProject;
182+
vc.myCodeFile = _myCodeFile;
183+
vc.savedSucessBlock = ^{
184+
[weakSelf sendRequest];
185+
};
186+
[self.navigationController pushViewController:vc animated:YES];
187+
}
188+
177189
- (void)goToCommitsVC{
178190
ProjectCommitsViewController *vc = [ProjectCommitsViewController new];
179191
vc.curProject = self.myProject;
180192
vc.curCommits = [Commits commitsWithRef:self.myCodeFile.ref Path:self.myCodeFile.path];
181193
[self.navigationController pushViewController:vc animated:YES];
182194
}
183195

196+
- (void)popOut{
197+
__weak typeof(self) weakSelf = self;
198+
[self.navigationController.viewControllers enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(UIViewController *obj, NSUInteger idx, BOOL *stop) {
199+
if (![obj isKindOfClass:[CodeViewController class]] &&
200+
![obj isKindOfClass:[CodeListViewController class]] &&
201+
!([obj isKindOfClass:[ProjectViewController class]] && [(ProjectViewController *)obj curType] == ProjectViewTypeCodes)) {
202+
*stop = YES;
203+
[weakSelf.navigationController popToViewController:obj animated:YES];
204+
}
205+
}];
206+
}
207+
184208
@end
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// EditCodeViewController.h
3+
// Coding_iOS
4+
//
5+
// Created by Ease on 16/1/11.
6+
// Copyright © 2016年 Coding. All rights reserved.
7+
//
8+
9+
#import "BaseViewController.h"
10+
#import "Projects.h"
11+
#import "CodeFile.h"
12+
13+
@interface EditCodeViewController : BaseViewController
14+
@property (strong, nonatomic) Project *myProject;
15+
@property (strong, nonatomic) CodeFile *myCodeFile;
16+
@property (copy, nonatomic) void(^savedSucessBlock)();
17+
18+
@end
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
//
2+
// EditCodeViewController.m
3+
// Coding_iOS
4+
//
5+
// Created by Ease on 16/1/11.
6+
// Copyright © 2016年 Coding. All rights reserved.
7+
//
8+
9+
#import "EditCodeViewController.h"
10+
#import "Coding_NetAPIManager.h"
11+
#import "WebContentManager.h"
12+
#import "EaseMarkdownTextView.h"
13+
#import "WebViewController.h"
14+
15+
@interface EditCodeViewController ()<UIWebViewDelegate>
16+
@property (strong, nonatomic) UISegmentedControl *segmentedControl;
17+
@property (assign, nonatomic) NSInteger curIndex;
18+
19+
@property (strong, nonatomic) UIWebView *preview;
20+
@property (strong, nonatomic) UIActivityIndicatorView *activityIndicator;
21+
22+
@property (strong, nonatomic) EaseMarkdownTextView *editView;
23+
@end
24+
25+
@implementation EditCodeViewController
26+
27+
- (void)viewDidLoad {
28+
[super viewDidLoad];
29+
// Do any additional setup after loading the view.
30+
if (!_segmentedControl) {
31+
_segmentedControl = ({
32+
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"编辑", @"预览"]];
33+
[segmentedControl setWidth:80 forSegmentAtIndex:0];
34+
[segmentedControl setWidth:80 forSegmentAtIndex:1];
35+
[segmentedControl setTitleTextAttributes:@{
36+
NSFontAttributeName: [UIFont boldSystemFontOfSize:16],
37+
NSForegroundColorAttributeName: [UIColor colorWithHexString:@"0x28303b"]
38+
}
39+
forState:UIControlStateSelected];
40+
[segmentedControl setTitleTextAttributes:@{
41+
NSFontAttributeName: [UIFont boldSystemFontOfSize:16],
42+
NSForegroundColorAttributeName: [UIColor whiteColor]
43+
} forState:UIControlStateNormal];
44+
[segmentedControl addTarget:self action:@selector(segmentedControlSelected:) forControlEvents:UIControlEventValueChanged];
45+
segmentedControl;
46+
});
47+
48+
self.navigationItem.titleView = _segmentedControl;
49+
}
50+
51+
[self.navigationItem setRightBarButtonItem:[UIBarButtonItem itemWithBtnTitle:@"提交" target:self action:@selector(saveBtnClicked)] animated:YES];
52+
self.navigationItem.rightBarButtonItem.enabled = NO;
53+
54+
[[[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIKeyboardWillChangeFrameNotification object:nil] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification *aNotification) {
55+
if (self.editView) {
56+
NSDictionary* userInfo = [aNotification userInfo];
57+
CGRect keyboardEndFrame = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
58+
self.editView.contentInset = UIEdgeInsetsMake(0, 0, CGRectGetHeight(keyboardEndFrame), 0);
59+
self.editView.scrollIndicatorInsets = self.editView.contentInset;
60+
}
61+
}];
62+
self.curIndex = 0;
63+
}
64+
65+
- (void)viewDidAppear:(BOOL)animated{
66+
[super viewDidAppear:animated];
67+
// if (self.curIndex == 0 && self.editView) {
68+
// [self.editView becomeFirstResponder];
69+
// }
70+
}
71+
72+
#pragma mark UISegmentedControl
73+
- (void)segmentedControlSelected:(id)sender{
74+
UISegmentedControl *segmentedControl = (UISegmentedControl *)sender;
75+
self.curIndex = segmentedControl.selectedSegmentIndex;
76+
if (self.curIndex == 0) {
77+
// [_editView becomeFirstResponder];
78+
}else{
79+
[_editView resignFirstResponder];
80+
}
81+
}
82+
83+
#pragma mark index_view
84+
85+
- (void)setCurIndex:(NSInteger)curIndex{
86+
_curIndex = curIndex;
87+
if (_segmentedControl.selectedSegmentIndex != curIndex) {
88+
[_segmentedControl setSelectedSegmentIndex:_curIndex];
89+
}
90+
91+
if (_curIndex == 0) {
92+
[self loadEditView];
93+
}else{
94+
[self loadPreview];
95+
}
96+
}
97+
98+
- (void)loadEditView{
99+
if (!_editView) {
100+
_editView = [[EaseMarkdownTextView alloc] initWithFrame:self.view.bounds];
101+
_editView.curProject = self.myProject;
102+
_editView.backgroundColor = [UIColor clearColor];
103+
_editView.textColor = [UIColor colorWithHexString:@"0x666666"];
104+
_editView.font = [UIFont systemFontOfSize:16];
105+
_editView.textContainerInset = UIEdgeInsetsMake(15, kPaddingLeftWidth - 5, 8, kPaddingLeftWidth - 5);
106+
_editView.placeholder = @"编辑代码";
107+
108+
_editView.text = _myCodeFile.file.data;
109+
[self.view addSubview:_editView];
110+
[_editView mas_makeConstraints:^(MASConstraintMaker *make) {
111+
make.edges.equalTo(self.view);
112+
}];
113+
114+
@weakify(self);
115+
[_editView.rac_textSignal subscribeNext:^(NSString *value) {
116+
@strongify(self);
117+
self.myCodeFile.editData = value;
118+
self.navigationItem.rightBarButtonItem.enabled = ![value isEqualToString:self.myCodeFile.file.data];
119+
}];
120+
}
121+
_editView.hidden = NO;
122+
_preview.hidden = YES;
123+
}
124+
125+
- (void)loadPreview
126+
{
127+
if (!_preview) {
128+
_preview = [[UIWebView alloc] initWithFrame:self.view.bounds];
129+
_preview.delegate = self;
130+
_preview.backgroundColor = [UIColor clearColor];
131+
_preview.opaque = NO;
132+
_preview.scalesPageToFit = YES;
133+
134+
//webview加载指示
135+
_activityIndicator = [[UIActivityIndicatorView alloc]
136+
initWithActivityIndicatorStyle:
137+
UIActivityIndicatorViewStyleGray];
138+
_activityIndicator.hidesWhenStopped = YES;
139+
[_preview addSubview:_activityIndicator];
140+
[self.view addSubview:_preview];
141+
142+
[_preview mas_makeConstraints:^(MASConstraintMaker *make) {
143+
make.edges.equalTo(self.view);
144+
}];
145+
[_activityIndicator mas_makeConstraints:^(MASConstraintMaker *make) {
146+
make.center.equalTo(_preview);
147+
}];
148+
}
149+
_preview.hidden = NO;
150+
_editView.hidden = YES;
151+
[self previewLoadMDData];
152+
}
153+
154+
- (void)previewLoadMDData{
155+
if ([_myCodeFile.file.lang isEqualToString:@"markdown"]) {
156+
NSString *mdStr = self.editView? self.editView.text : _myCodeFile.file.data;
157+
158+
@weakify(self);
159+
[[Coding_NetAPIManager sharedManager] request_MDHtmlStr_WithMDStr:mdStr inProject:self.myProject andBlock:^(id data, NSError *error) {
160+
@strongify(self);
161+
NSString *htmlStr = data? data : error.description;
162+
NSString *contentStr = [WebContentManager markdownPatternedWithContent:htmlStr];
163+
[self.preview loadHTMLString:contentStr baseURL:nil];
164+
}];
165+
}else{
166+
NSString *contentStr = [WebContentManager codePatternedWithContent:_myCodeFile isEdit:YES];
167+
[self.preview loadHTMLString:contentStr baseURL:nil];
168+
}
169+
}
170+
171+
#pragma mark nav_btn
172+
173+
- (void)saveBtnClicked{
174+
if ([_myCodeFile.editData isEqualToString:_myCodeFile.file.data]) {
175+
[NSObject showHudTipStr:@"文件无改动"];
176+
return;
177+
}
178+
[[Coding_NetAPIManager sharedManager] request_EditCodeFile:_myCodeFile withPro:_myProject andBlock:^(id data, NSError *error) {
179+
if (data) {
180+
if (self.savedSucessBlock) {
181+
self.savedSucessBlock();
182+
}
183+
[self.navigationController popViewControllerAnimated:YES];
184+
}
185+
}];
186+
}
187+
188+
#pragma mark UIWebViewDelegate
189+
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
190+
DebugLog(@"strLink=[%@]",request.URL.absoluteString);
191+
192+
NSString *strLink = request.URL.absoluteString;
193+
if ([strLink rangeOfString:@"about:blank"].location != NSNotFound) {
194+
return YES;
195+
} else {
196+
[self analyseLinkStr:strLink];
197+
return NO;
198+
}
199+
}
200+
- (void)webViewDidStartLoad:(UIWebView *)webView{
201+
[_activityIndicator startAnimating];
202+
}
203+
- (void)webViewDidFinishLoad:(UIWebView *)webView{
204+
[_activityIndicator stopAnimating];
205+
}
206+
207+
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
208+
if([error code] == NSURLErrorCancelled)
209+
return;
210+
else{
211+
DebugLog(@"%@", error.description);
212+
[NSObject showError:error];
213+
}
214+
}
215+
216+
#pragma mark analyseLinkStr
217+
- (void)analyseLinkStr:(NSString *)linkStr
218+
{
219+
if (linkStr.length <= 0) {
220+
return;
221+
}
222+
UIViewController *vc = [BaseViewController analyseVCFromLinkStr:linkStr];
223+
if (vc) {
224+
[self.navigationController pushViewController:vc animated:YES];
225+
}else{
226+
// 跳转去网页
227+
WebViewController *webVc = [WebViewController webVCWithUrlStr:linkStr];
228+
[self.navigationController pushViewController:webVc animated:YES];
229+
}
230+
}
231+
@end

‎Coding_iOS/Models/CodeFile.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
@property (nonatomic, assign) BOOL can_edit, isHead;
1616
@property (readwrite, nonatomic, strong) NSString *ref, *path;
1717
@property (readwrite, nonatomic, strong) CodeFile_RealFile *file;
18+
@property (strong, nonatomic) Commit *headCommit;
19+
@property (strong, nonatomic) NSString *editData, *editMessage;
20+
1821
+ (CodeFile *)codeFileWithRef:(NSString *)ref andPath:(NSString *)path;
1922
+ (CodeFile *)codeFileWithMDStr:(NSString *)md_html;
23+
- (NSDictionary *)toEditParams;
2024
@end
2125

2226

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /