Skip to content

Commit a7fb9a0

Browse files
committed
analyseVCFromLinkStr - 加一种类型:源代码路径的解析
1 parent 4682a95 commit a7fb9a0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Coding_iOS/Controllers/CodeViewController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ - (void)refreshCodeViewData{
114114
#pragma mark UIWebViewDelegate
115115
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
116116
DebugLog(@"strLink=[%@]",request.URL.absoluteString);
117+
UIViewController *vc = [BaseViewController analyseVCFromLinkStr:request.URL.absoluteString];
118+
if (vc) {
119+
[self.navigationController pushViewController:vc animated:YES];
120+
return NO;
121+
}
117122
return YES;
118123
}
119124
- (void)webViewDidStartLoad:(UIWebView *)webView{

Coding_iOS/Controllers/RootControllers/BaseViewController.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#import "CommitFilesViewController.h"
3030
#import "FileViewController.h"
3131
#import "CSTopicDetailVC.h"
32+
#import "CodeViewController.h"
3233

3334
#import "UnReadManager.h"
3435

@@ -155,6 +156,7 @@ + (UIViewController *)analyseVCFromLinkStr:(NSString *)linkStr analyseMethod:(An
155156
NSString *gitMRPRCommitRegexStr = @"/u/([^/]+)/p/([^/]+)/git/(merge|pull|commit)/([^/#]+)";
156157
NSString *conversionRegexStr = @"/user/messages/history/([^/]+)$";
157158
NSString *pp_topicRegexStr = @"/pp/topic/([0-9]+)$";
159+
NSString *codeRegexStr = @"/u/([^/]+)/p/([^/]+)/git/blob/([^/]+)[/]?([^?]*)";
158160
NSString *projectRegexStr = @"/u/([^/]+)/p/([^/]+)";
159161
NSArray *matchedCaptures = nil;
160162

@@ -310,6 +312,18 @@ + (UIViewController *)analyseVCFromLinkStr:(NSString *)linkStr analyseMethod:(An
310312
CSTopicDetailVC *vc = [CSTopicDetailVC new];
311313
vc.topicID = pp_topic_id.integerValue;
312314
analyseVC = vc;
315+
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:codeRegexStr]).count > 0){
316+
NSString *user_global_key = matchedCaptures[1];
317+
NSString *project_name = matchedCaptures[2];
318+
NSString *ref = matchedCaptures[3];
319+
NSString *path = matchedCaptures.count >= 5? matchedCaptures[4]: @"";
320+
321+
Project *curPro = [[Project alloc] init];
322+
curPro.owner_user_name = user_global_key;
323+
curPro.name = project_name;
324+
CodeFile *codeFile = [CodeFile codeFileWithRef:ref andPath:path];
325+
CodeViewController *vc = [CodeViewController codeVCWithProject:curPro andCodeFile:codeFile];
326+
analyseVC = vc;
313327
}else if ((matchedCaptures = [linkStr captureComponentsMatchedByRegex:projectRegexStr]).count > 0){
314328
//项目
315329
NSString *user_global_key = matchedCaptures[1];

0 commit comments

Comments
 (0)