Skip to content

Commit 4f77ae3

Browse files
committed
代码 - 查找&创建
1 parent 5ea7c05 commit 4f77ae3

38 files changed

+641
-202
lines changed

Coding_iOS.xcodeproj/project.pbxproj

+54-12
Large diffs are not rendered by default.

Coding_iOS/Controllers/CodeListViewController.m

+37-43
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
#import "CodeViewController.h"
1111
#import "ProjectViewController.h"
1212
#import "ProjectCommitsViewController.h"
13+
#import "ProjectViewController.h"
1314

1415
@interface CodeListViewController ()
15-
16+
@property (strong, nonatomic) ProjectCodeListView *listView;
1617
@end
1718

1819
@implementation CodeListViewController
@@ -23,20 +24,18 @@ - (void)viewDidLoad {
2324
self.title = [[_myCodeTree.path componentsSeparatedByString:@"/"] lastObject];
2425
[self configRightNavBtn];
2526

26-
ProjectCodeListView *listView = [[ProjectCodeListView alloc] initWithFrame:self.view.bounds project:_myProject andCodeTree:_myCodeTree];
27+
_listView = [[ProjectCodeListView alloc] initWithFrame:self.view.bounds project:_myProject andCodeTree:_myCodeTree];
2728
__weak typeof(self) weakSelf = self;
28-
listView.codeTreeFileOfRefBlock = ^(CodeTree_File *curCodeTreeFile, NSString *ref){
29+
_listView.codeTreeFileOfRefBlock = ^(CodeTree_File *curCodeTreeFile, NSString *ref){
2930
[weakSelf goToVCWith:curCodeTreeFile andRef:ref];
3031
};
31-
listView.refChangedBlock = ^(NSString *ref){
32-
weakSelf.myCodeTree.ref = ref;
32+
_listView.codeTreeChangedBlock = ^(CodeTree *tree){
33+
weakSelf.myCodeTree = tree;
3334
};
34-
[self.view addSubview:listView];
35-
[listView mas_makeConstraints:^(MASConstraintMaker *make) {
35+
[self.view addSubview:_listView];
36+
[_listView mas_makeConstraints:^(MASConstraintMaker *make) {
3637
make.edges.equalTo(self.view);
3738
}];
38-
[listView addBranchTagButton];
39-
4039
}
4140

4241
- (void)configRightNavBtn{
@@ -47,44 +46,20 @@ - (void)configRightNavBtn{
4746

4847
- (void)rightNavBtnClicked{
4948
__weak typeof(self) weakSelf = self;
50-
[[UIActionSheet bk_actionSheetCustomWithTitle:nil buttonTitles:@[@"查看提交记录", @"退出代码查看"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
51-
switch (index) {
52-
case 0:{
53-
[weakSelf goToCommitsVC];
54-
}
55-
break;
56-
case 1:{
57-
[weakSelf.navigationController.viewControllers enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(UIViewController *obj, NSUInteger idx, BOOL *stop) {
58-
if (![obj isKindOfClass:[CodeViewController class]] &&
59-
![obj isKindOfClass:[CodeListViewController class]] &&
60-
!([obj isKindOfClass:[ProjectViewController class]] && [(ProjectViewController *)obj curType] == ProjectViewTypeCodes)) {
61-
*stop = YES;
62-
[weakSelf.navigationController popToViewController:obj animated:YES];
63-
}
64-
}];
65-
}
66-
break;
67-
default:
68-
break;
49+
[[UIActionSheet bk_actionSheetCustomWithTitle:nil buttonTitles:@[@"上传图片", @"创建文本文件", @"查看提交记录", @"退出代码查看"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
50+
if (index == 0) {
51+
[weakSelf.listView uploadImageClicked];
52+
}else if (index == 1){
53+
[weakSelf.listView createFileClicked];
54+
}else if (index == 2){
55+
[weakSelf goToCommitsVC];
56+
}else if (index == 3){
57+
[weakSelf popOutCodeVC];
6958
}
7059
}] showInView:self.view];
7160
}
7261

73-
- (void)didReceiveMemoryWarning {
74-
[super didReceiveMemoryWarning];
75-
// Dispose of any resources that can be recreated.
76-
}
77-
78-
/*
79-
#pragma mark - Navigation
80-
81-
// In a storyboard-based application, you will often want to do a little preparation before navigation
82-
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
83-
// Get the new view controller using [segue destinationViewController].
84-
// Pass the selected object to the new view controller.
85-
}
86-
*/
87-
62+
#pragma mark action
8863
- (void)goToVCWith:(CodeTree_File *)codeTreeFile andRef:(NSString *)ref{
8964
DebugLog(@"%@", codeTreeFile.path);
9065
if ([codeTreeFile.mode isEqualToString:@"tree"]) {//文件夹
@@ -97,6 +72,13 @@ - (void)goToVCWith:(CodeTree_File *)codeTreeFile andRef:(NSString *)ref{
9772
CodeFile *nextCodeFile = [CodeFile codeFileWithRef:ref andPath:codeTreeFile.path];
9873
CodeViewController *vc = [CodeViewController codeVCWithProject:_myProject andCodeFile:nextCodeFile];
9974
[self.navigationController pushViewController:vc animated:YES];
75+
}else if ([codeTreeFile.mode isEqualToString:@"git_link"]){
76+
UIViewController *vc = [BaseViewController analyseVCFromLinkStr:codeTreeFile.info.submoduleLink];
77+
if (vc) {
78+
[self.navigationController pushViewController:vc animated:YES];
79+
}else{
80+
[NSObject showHudTipStr:@"有些文件还不支持查看呢_(:з」∠)_"];
81+
}
10082
}else{
10183
[NSObject showHudTipStr:@"有些文件还不支持查看呢_(:з」∠)_"];
10284
}
@@ -109,4 +91,16 @@ - (void)goToCommitsVC{
10991
[self.navigationController pushViewController:vc animated:YES];
11092
}
11193

94+
- (void)popOutCodeVC{
95+
__weak typeof(self) weakSelf = self;
96+
[self.navigationController.viewControllers enumerateObjectsWithOptions:NSEnumerationReverse usingBlock:^(UIViewController *obj, NSUInteger idx, BOOL *stop) {
97+
if (![obj isKindOfClass:[CodeViewController class]] &&
98+
![obj isKindOfClass:[CodeListViewController class]] &&
99+
!([obj isKindOfClass:[ProjectViewController class]] && [(ProjectViewController *)obj curType] == ProjectViewTypeCodes)) {
100+
*stop = YES;
101+
[weakSelf.navigationController popToViewController:obj animated:YES];
102+
}
103+
}];
104+
}
105+
112106
@end

Coding_iOS/Controllers/CodeViewController.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ - (void)configRightNavBtn{
155155

156156
- (void)rightNavBtnClicked{
157157
NSMutableArray *actionTitles = @[@"编辑代码", @"查看提交记录", @"退出代码查看"].mutableCopy;
158-
if (!self.myCodeFile.can_edit) {
158+
if (!self.myCodeFile.can_edit || [self.myCodeFile.file.mode isEqualToString:@"image"]) {
159159
[actionTitles removeObjectAtIndex:0];
160160
}
161161
__weak typeof(self) weakSelf = self;
@@ -165,7 +165,7 @@ - (void)rightNavBtnClicked{
165165
}
166166

167167
- (void)actionSheetClicked:(UIActionSheet *)sheet index:(NSInteger)index{
168-
if (!self.myCodeFile.can_edit) {
168+
if (!self.myCodeFile.can_edit || [self.myCodeFile.file.mode isEqualToString:@"image"]) {
169169
index++;
170170
}
171171
if (index == 0) {

Coding_iOS/Controllers/ProjectViewController.h

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ typedef NS_ENUM(NSInteger, ProjectViewType)
2323
@property (nonatomic, strong) Project *myProject;
2424
@property (nonatomic, assign) NSInteger curIndex;
2525
@property (nonatomic, assign, readonly) ProjectViewType curType;
26-
@property (strong, nonatomic) NSString *codeRef;
2726

2827
+ (ProjectViewController *)codeVCWithCodeRef:(NSString *)codeRef andProject:(Project *)project;
2928

Coding_iOS/Controllers/ProjectViewController.m

+49-21
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ @interface ProjectViewController ()
6161

6262
@property (nonatomic, strong) UIBarButtonItem *screenBar;
6363

64+
@property (strong, nonatomic) CodeTree *myCodeTree;
6465

6566
@end
6667

6768
@implementation ProjectViewController
6869

6970
+ (ProjectViewController *)codeVCWithCodeRef:(NSString *)codeRef andProject:(Project *)project{
7071
ProjectViewController *vc = [self new];
71-
vc.codeRef = codeRef;
72+
vc.myCodeTree = [CodeTree codeTreeWithRef:codeRef andPath:@""];
7273
vc.myProject = project;
7374
if (vc.myProject.is_public.boolValue) {
7475
vc.curIndex = 2;
@@ -77,6 +78,14 @@ + (ProjectViewController *)codeVCWithCodeRef:(NSString *)codeRef andProject:(Pro
7778
}
7879
return vc;
7980
}
81+
82+
- (CodeTree *)myCodeTree{
83+
if (!_myCodeTree) {
84+
_myCodeTree = [CodeTree codeTreeWithRef:@"master" andPath:@""];
85+
}
86+
return _myCodeTree;
87+
}
88+
8089
- (instancetype)init
8190
{
8291
self = [super init];
@@ -85,9 +94,11 @@ - (instancetype)init
8594
}
8695
return self;
8796
}
97+
8898
- (UIView *)getCurContentView{
8999
return [_projectContentDict objectForKey:[NSNumber numberWithInteger:_curIndex]];
90100
}
101+
91102
- (void)saveCurContentView:(UIView *)curContentView{
92103
if (curContentView) {
93104
[_projectContentDict setObject:curContentView forKey:[NSNumber numberWithInteger:_curIndex]];
@@ -188,18 +199,14 @@ - (void)viewWillDisappear:(BOOL)animated {
188199

189200
- (void)refreshToQueryData{
190201
UIView *curView = [self getCurContentView];
191-
if (curView && [curView respondsToSelector:@selector(refreshToQueryData)]) {
192-
[curView performSelector:@selector(refreshToQueryData)];
202+
if (!curView) {
203+
return;
193204
}
194205

195-
196-
if ([curView isKindOfClass:[ProjectTasksView class]]) {
197-
ProjectTasksView *tasksView = (ProjectTasksView *)curView;
198-
[tasksView refreshToQueryData];
199-
}else{
200-
if (curView && [curView respondsToSelector:@selector(reloadData)]) {
201-
[curView performSelector:@selector(reloadData)];
202-
}
206+
if ([curView respondsToSelector:@selector(refreshToQueryData)]) {
207+
[curView performSelector:@selector(refreshToQueryData)];
208+
}else if ([curView respondsToSelector:@selector(reloadData)]){
209+
[curView performSelector:@selector(reloadData)];
203210
}
204211
}
205212

@@ -237,7 +244,7 @@ - (void)configRightBarButtonItemWithViewType:(ProjectViewType)viewType{
237244
action:@selector(navRightBtnClicked)];
238245
}else if (viewType == ProjectViewTypeCodes){
239246
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
240-
[button setImage:[UIImage imageNamed:@"timeBtn_Nav"] forState:UIControlStateNormal];
247+
[button setImage:[UIImage imageNamed:@"moreBtn_Nav"] forState:UIControlStateNormal];
241248
[button addTarget:self action:@selector(navRightBtnClicked) forControlEvents:UIControlEventTouchUpInside];
242249
navRightBtn = [[UIBarButtonItem alloc] initWithCustomView:button];
243250
}
@@ -356,14 +363,13 @@ - (void)refreshWithNewIndex:(NSInteger)newIndex{
356363
break;
357364
case ProjectViewTypeCodes:{
358365
curView = ({
359-
ProjectCodeListView *codeListView = [[ProjectCodeListView alloc] initWithFrame:self.view.bounds project:_myProject andCodeTree:[CodeTree codeTreeWithRef:_codeRef andPath:@""]];
366+
ProjectCodeListView *codeListView = [[ProjectCodeListView alloc] initWithFrame:self.view.bounds project:_myProject andCodeTree:_myCodeTree];
360367
codeListView.codeTreeFileOfRefBlock = ^(CodeTree_File *curCodeTreeFile, NSString *ref){
361368
[weakSelf goToVCWith:curCodeTreeFile andRef:ref];
362369
};
363-
codeListView.refChangedBlock = ^(NSString *ref){
364-
weakSelf.codeRef = ref;
370+
codeListView.codeTreeChangedBlock = ^(CodeTree *tree){
371+
weakSelf.myCodeTree = tree;
365372
};
366-
[codeListView addBranchTagButton];
367373
codeListView;
368374
});
369375
}
@@ -426,6 +432,13 @@ - (void)goToVCWith:(CodeTree_File *)codeTreeFile andRef:(NSString *)ref{
426432
CodeFile *nextCodeFile = [CodeFile codeFileWithRef:ref andPath:codeTreeFile.path];
427433
CodeViewController *vc = [CodeViewController codeVCWithProject:_myProject andCodeFile:nextCodeFile];
428434
[self.navigationController pushViewController:vc animated:YES];
435+
}else if ([codeTreeFile.mode isEqualToString:@"git_link"]){
436+
UIViewController *vc = [BaseViewController analyseVCFromLinkStr:codeTreeFile.info.submoduleLink];
437+
if (vc) {
438+
[self.navigationController pushViewController:vc animated:YES];
439+
}else{
440+
[NSObject showHudTipStr:@"有些文件还不支持查看呢_(:з」∠)_"];
441+
}
429442
}else{
430443
[NSObject showHudTipStr:@"有些文件还不支持查看呢_(:з」∠)_"];
431444
}
@@ -672,18 +685,33 @@ - (void)navRightBtnClicked{
672685
break;
673686
case ProjectViewTypeCodes:
674687
{
675-
//代码提交记录
676-
ProjectCommitsViewController *vc = [ProjectCommitsViewController new];
677-
vc.curProject = self.myProject;
678-
vc.curCommits = [Commits commitsWithRef:self.codeRef? self.codeRef: @"master" Path:@""];
679-
[self.navigationController pushViewController:vc animated:YES];
688+
__weak typeof(self) weakSelf = self;
689+
[[UIActionSheet bk_actionSheetCustomWithTitle:nil buttonTitles:@[@"上传图片", @"创建文本文件", @"查看提交记录"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) {
690+
if (index == 0) {
691+
[(ProjectCodeListView *)[weakSelf getCurContentView] uploadImageClicked];
692+
}else if (index == 1){
693+
[(ProjectCodeListView *)[weakSelf getCurContentView] createFileClicked];
694+
}else if (index == 2){
695+
[weakSelf goToCommitsVC];
696+
}
697+
}] showInView:self.view];
680698
}
681699
break;
682700
default:
683701
break;
684702
}
685703
}
686704

705+
- (void)goToCommitsVC{
706+
//代码提交记录
707+
ProjectCommitsViewController *vc = [ProjectCommitsViewController new];
708+
vc.curProject = self.myProject;
709+
vc.curCommits = [Commits commitsWithRef:self.myCodeTree.ref Path:@""];
710+
[self.navigationController pushViewController:vc animated:YES];
711+
}
712+
713+
714+
687715
- (UIBarButtonItem *)HDCustomNavButtonWithTitle:(NSString *)title imageName:(NSString *)imageName target:(id)targe action:(SEL)action {
688716
UIButton *itemButtom = [UIButton buttonWithType:UIButtonTypeCustom];
689717
UIImage *image = [UIImage imageNamed:imageName];
Loading
Loading
454 Bytes
Loading
626 Bytes
Loading
Loading
Loading
326 Bytes
Loading
454 Bytes
Loading
-1.32 KB
Binary file not shown.
-1.35 KB
Binary file not shown.
-866 Bytes
Loading
271 Bytes
Loading

Coding_iOS/Models/CodeFile.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
@property (readwrite, nonatomic, strong) NSString *ref, *path;
1717
@property (readwrite, nonatomic, strong) CodeFile_RealFile *file;
1818
@property (strong, nonatomic) Commit *headCommit;
19-
@property (strong, nonatomic) NSString *editData, *editMessage;
19+
@property (strong, nonatomic) NSString *editData, *editMessage, *editName;
2020

2121
+ (CodeFile *)codeFileWithRef:(NSString *)ref andPath:(NSString *)path;
2222
+ (CodeFile *)codeFileWithMDStr:(NSString *)md_html;
23+
+ (CodeFile *)codeFileToCommitWithRef:(NSString *)ref andPath:(NSString *)path name:(NSString *)name data:(NSString *)data message:(NSString *)message headCommit:(Commit *)headCommit;
24+
2325
- (NSDictionary *)toEditParams;
26+
- (NSDictionary *)toCreateParams;
2427
@end
2528

2629

@@ -30,4 +33,4 @@
3033
@property (readwrite, nonatomic, strong) Committer *lastCommitter;
3134
@property (nonatomic, assign) BOOL previewed;
3235
@property (nonatomic, assign) NSInteger size;
33-
@end
36+
@end

Coding_iOS/Models/CodeFile.m

+23-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ + (CodeFile *)codeFileWithMDStr:(NSString *)md_html{
2727
codeFile.file = file;
2828
return codeFile;
2929
}
30+
+ (CodeFile *)codeFileToCommitWithRef:(NSString *)ref andPath:(NSString *)path name:(NSString *)name data:(NSString *)data message:(NSString *)message headCommit:(Commit *)headCommit{
31+
CodeFile *codeFile = [self codeFileWithRef:ref andPath:path];
32+
codeFile.editName = name;
33+
codeFile.editData = data;
34+
codeFile.editMessage = message;
35+
codeFile.headCommit = headCommit;
36+
return codeFile;
37+
}
3038
- (NSString *)path{
3139
if (!_path) {
3240
_path = @"";
@@ -45,6 +53,12 @@ - (NSString *)editData{
4553
}
4654
return _editData;
4755
}
56+
- (NSString *)editName{
57+
if (!_editName) {
58+
_editName = _file.name.copy;
59+
}
60+
return _editName;
61+
}
4862
- (NSString *)editMessage{
4963
if (!_editMessage) {
5064
_editMessage = [NSString stringWithFormat:@"update %@", _path];
@@ -58,9 +72,17 @@ - (NSDictionary *)toEditParams{
5872
params[@"lastCommitSha"] = self.headCommit.commitId;
5973
return params;
6074
}
75+
- (NSDictionary *)toCreateParams{
76+
NSMutableDictionary *params = @{}.mutableCopy;
77+
params[@"title"] = self.editName;
78+
params[@"content"] = self.editData;
79+
params[@"message"] = self.editMessage;
80+
params[@"lastCommitSha"] = self.headCommit.commitId;
81+
return params;
82+
}
6183
@end
6284

6385

6486
@implementation CodeFile_RealFile
6587

66-
@end
88+
@end

0 commit comments

Comments
 (0)