GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Coding-iOS/Coding_iOS/Controllers/FileEditViewController.m at master · wxhui/Coding-iOS Expand file tree/ Copy pathFileEditViewController.mMore file actions 263 lines (234 loc) · 9.45 KB / Copy pathFileEditViewController.mFile metadata and controls263 lines (234 loc) · 9.45 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 // // FileEditViewController.m // Coding_iOS // // Created by Ease on 15/8/24. // Copyright (c) 2015年 Coding. All rights reserved. // #import "FileEditViewController.h" #import "Coding_NetAPIManager.h" #import "WebContentManager.h" #import "EaseMarkdownTextView.h" #import "WebViewController.h" @interface FileEditViewController ()<UIWebViewDelegate> @property (strong, nonatomic) UISegmentedControl *segmentedControl; @property (assign, nonatomic) NSInteger curIndex; @property (strong, nonatomic) UIWebView *preview; @property (strong, nonatomic) UIActivityIndicatorView *activityIndicator; @property (strong, nonatomic) UITextView *editView; @property (strong, nonatomic) NSString *content; @property (strong, nonatomic) Project *curProject; @end @implementation FileEditViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. [self requestFileContent]; } - (void)setCurFile:(ProjectFile *)curFile{ _curFile = curFile; _curProject = [Project new]; _curProject.id = _curFile.project_id; } - (void)requestFileContent{ [self.view beginLoading]; __weak typeof(self) weakSelf = self; [[Coding_NetAPIManager sharedManager] request_FileContent:self.curFile andBlock:^(id data, NSError *error) { [weakSelf.view endLoading]; if (data) { weakSelf.content = data; [weakSelf configContent]; }else{ if (error.code == 1304) { [weakSelf.view configBlankPage:EaseBlankPageTypeFileDleted hasData:NO hasError:NO reloadButtonBlock:nil]; }else{ [weakSelf.view configBlankPage:EaseBlankPageTypeView hasData:NO hasError:(error != nil) reloadButtonBlock:^(id sender) { [weakSelf requestFileContent]; }]; } } }]; } - (BOOL)fileIsMD{ return [_curFile.fileType isEqualToString:@"md"]; } - (void)configContent{ if ([self fileIsMD]) { if (!_segmentedControl) { _segmentedControl = ({ UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:@[@"编辑", @"预览"]]; [segmentedControl setWidth:80 forSegmentAtIndex:0]; [segmentedControl setWidth:80 forSegmentAtIndex:1]; [segmentedControl setTitleTextAttributes:@{ NSFontAttributeName: [UIFont boldSystemFontOfSize:16], NSForegroundColorAttributeName: [UIColor colorWithHexString:@"0x28303b"] } forState:UIControlStateSelected]; [segmentedControl setTitleTextAttributes:@{ NSFontAttributeName: [UIFont boldSystemFontOfSize:16], NSForegroundColorAttributeName: [UIColor whiteColor] } forState:UIControlStateNormal]; [segmentedControl addTarget:self action:@selector(segmentedControlSelected:) forControlEvents:UIControlEventValueChanged]; segmentedControl; }); self.navigationItem.titleView = _segmentedControl; } self.curIndex = 0; }else{ self.title = _curFile.name; [self loadEditView]; } [self.navigationItem setRightBarButtonItem:[UIBarButtonItem itemWithBtnTitle:@"保存" target:self action:@selector(saveBtnClicked)] animated:YES]; self.navigationItem.rightBarButtonItem.enabled = NO; [[[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIKeyboardWillChangeFrameNotification object:nil] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(NSNotification *aNotification) { if (self.editView) { NSDictionary* userInfo = [aNotification userInfo]; CGRect keyboardEndFrame = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; self.editView.contentInset = UIEdgeInsetsMake(0, 0, CGRectGetHeight(keyboardEndFrame), 0); self.editView.scrollIndicatorInsets = self.editView.contentInset; } }]; } #pragma mark UISegmentedControl - (void)segmentedControlSelected:(id)sender{ UISegmentedControl *segmentedControl = (UISegmentedControl *)sender; self.curIndex = segmentedControl.selectedSegmentIndex; if (self.curIndex == 0) { [_editView becomeFirstResponder]; }else{ [_editView resignFirstResponder]; } } #pragma mark index_view - (void)setCurIndex:(NSInteger)curIndex{ _curIndex = curIndex; if (_segmentedControl.selectedSegmentIndex != curIndex) { [_segmentedControl setSelectedSegmentIndex:_curIndex]; } if (_curIndex == 0) { [self loadEditView]; }else{ [self loadPreview]; } } - (void)loadEditView{ if (!_editView) { if ([self fileIsMD]) { _editView = ({ EaseMarkdownTextView *mdView = [[EaseMarkdownTextView alloc] initWithFrame:self.view.bounds]; mdView.curProject = _curProject; mdView; }); }else{ _editView = [[UITextView alloc] initWithFrame:self.view.bounds]; } _editView.backgroundColor = [UIColor clearColor]; _editView.textColor = [UIColor colorWithHexString:@"0x666666"]; _editView.font = [UIFont systemFontOfSize:16]; _editView.textContainerInset = UIEdgeInsetsMake(15, kPaddingLeftWidth - 5, 8, kPaddingLeftWidth - 5); _editView.text = _content; [self.view addSubview:_editView]; [_editView mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.view); }]; @weakify(self); [_editView.rac_textSignal subscribeNext:^(NSString *content) { @strongify(self); self.navigationItem.rightBarButtonItem.enabled = ![self.content isEqualToString:content]; }]; } _editView.hidden = NO; _preview.hidden = YES; } - (void)loadPreview{ if (!_preview) { _preview = [[UIWebView alloc] initWithFrame:self.view.bounds]; _preview.delegate = self; _preview.backgroundColor = [UIColor clearColor]; _preview.opaque = NO; _preview.scalesPageToFit = YES; //webview加载指示 _activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleGray]; _activityIndicator.hidesWhenStopped = YES; [_preview addSubview:_activityIndicator]; [self.view addSubview:_preview]; [_preview mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(self.view); }]; [_activityIndicator mas_makeConstraints:^(MASConstraintMaker *make) { make.center.equalTo(_preview); }]; } _preview.hidden = NO; _editView.hidden = YES; [self previewLoadMDData]; } - (void)previewLoadMDData{ NSString *mdStr = self.editView.text; [_activityIndicator startAnimating]; @weakify(self); [[Coding_NetAPIManager sharedManager] request_MDHtmlStr_WithMDStr:mdStr inProject:self.curProject andBlock:^(id data, NSError *error) { @strongify(self); NSString *htmlStr = data? data : error.description; NSString *contentStr = [WebContentManager markdownPatternedWithContent:htmlStr]; [self.preview loadHTMLString:contentStr baseURL:nil]; }]; } #pragma mark nav_btn - (void)saveBtnClicked{ NSString *edit_content = _editView.text; if ([self fileIsMD]) { edit_content = [edit_content aliasedString]; } [[Coding_NetAPIManager sharedManager] request_EditFile:_curFile withContent:edit_content andBlock:^(id data, NSError *error) { if (data) { if (self.completeBlock) { self.completeBlock(data); } [self.navigationController popViewControllerAnimated:YES]; } }]; } #pragma mark UIWebViewDelegate - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ DebugLog(@"strLink=[%@]",request.URL.absoluteString); NSString *strLink = request.URL.absoluteString; if ([strLink rangeOfString:@"about:blank"].location != NSNotFound) { return YES; } else { [self analyseLinkStr:strLink]; return NO; } } - (void)webViewDidStartLoad:(UIWebView *)webView{ [_activityIndicator startAnimating]; } - (void)webViewDidFinishLoad:(UIWebView *)webView{ [_activityIndicator stopAnimating]; } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{ if([error code] == NSURLErrorCancelled) return; else{ DebugLog(@"%@", error.description); [NSObject showError:error]; } } #pragma mark analyseLinkStr - (void)analyseLinkStr:(NSString *)linkStr { if (linkStr.length <= 0) { return; } UIViewController *vc = [BaseViewController analyseVCFromLinkStr:linkStr]; if (vc) { [self.navigationController pushViewController:vc animated:YES]; }else{ // 跳转去网页 WebViewController *webVc = [WebViewController webVCWithUrlStr:linkStr]; [self.navigationController pushViewController:webVc animated:YES]; } } @end |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |