瀏覽代碼

text files

Marino Faggiana 7 年之前
父節點
當前提交
7ab64a9334
共有 4 個文件被更改,包括 49 次插入104 次删除
  1. 25 7
      iOSClient/Main/CCDetail.m
  2. 1 8
      iOSClient/Main/CCMain.m
  3. 4 42
      iOSClient/Text/NCText.storyboard
  4. 19 47
      iOSClient/Text/NCText.swift

+ 25 - 7
iOSClient/Main/CCDetail.m

@@ -37,6 +37,7 @@
     
     UIToolbar *_toolbar;
     
+    UIBarButtonItem *_buttonModifyTxt;
     UIBarButtonItem *_buttonAction;
     UIBarButtonItem *_buttonShare;
     UIBarButtonItem *_buttonDelete;
@@ -47,6 +48,7 @@
     BOOL _reload;
     
     NSMutableOrderedSet *_dataSourceDirectoryID;
+    NSString *_fileNameExtension;
 }
 @end
 
@@ -180,11 +182,16 @@
     UIBarButtonItem *fixedSpaceMini = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
     fixedSpaceMini.width = 25;
     
+    _buttonModifyTxt = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetModify"] style:UIBarButtonItemStylePlain target:self action:@selector(modifyTxtButtonPressed:)];
     _buttonAction = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetOpenIn"] style:UIBarButtonItemStylePlain target:self action:@selector(actionButtonPressed:)];
     _buttonShare  = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetShare"] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonPressed:)];
     _buttonDelete = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteButtonPressed:)];
     
-    [_toolbar setItems:[NSArray arrayWithObjects: flexible, _buttonDelete, fixedSpaceMini, _buttonShare, fixedSpaceMini, _buttonAction,  nil]];
+    if ([_fileNameExtension isEqualToString:@"TXT"])
+        [_toolbar setItems:[NSArray arrayWithObjects: _buttonModifyTxt, flexible, _buttonDelete, fixedSpaceMini, _buttonShare, fixedSpaceMini, _buttonAction,  nil]];
+    else
+        [_toolbar setItems:[NSArray arrayWithObjects: flexible, _buttonDelete, fixedSpaceMini, _buttonShare, fixedSpaceMini, _buttonAction,  nil]];
+    
     [_toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
     
     _toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
@@ -230,9 +237,9 @@
     
     if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_document]) {
         
-        NSString *ext = [[self.metadataDetail.fileNamePrint pathExtension] lowercaseString];
+        _fileNameExtension = [[self.metadataDetail.fileNamePrint pathExtension] uppercaseString];
         
-        if ([ext isEqualToString:@"pdf"]) {
+        if ([_fileNameExtension isEqualToString:@"PDF"]) {
             
             self.edgesForExtendedLayout = UIRectEdgeBottom;
             [self viewPDF:@""];
@@ -313,7 +320,6 @@
         [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
     }
     
-    NSString *ext = [CCUtility getExtension:self.metadataDetail.fileNamePrint];
     NSURL *url = [NSURL fileURLWithPath:fileName];
 
     WKPreferences *wkPreferences = [[WKPreferences alloc] init];
@@ -327,7 +333,7 @@
     [self.webView setBackgroundColor:[UIColor whiteColor]];
     [self.webView setOpaque:NO];
     
-    if ( [ext isEqualToString:@"CSS"] || [ext isEqualToString:@"PY"] || [ext isEqualToString:@"XML"] || [ext isEqualToString:@"JS"] ) {
+    if ( [_fileNameExtension isEqualToString:@"CSS"] || [_fileNameExtension isEqualToString:@"PY"] || [_fileNameExtension isEqualToString:@"XML"] || [_fileNameExtension isEqualToString:@"JS"] ) {
         
         NSMutableURLRequest *headRequest = [NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]];
         [headRequest setHTTPMethod:@"HEAD"];
@@ -346,7 +352,7 @@
             [self.webView  loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"20",@"Sans-Serif",dataFile] baseURL:nil];
         }
         
-    } else if ([ext isEqualToString:@"TXT"] ) {
+    } else if ([_fileNameExtension isEqualToString:@"TXT"]) {
         
         NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
         NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:nil delegateQueue:nil];
@@ -1037,8 +1043,20 @@
 #pragma mark ===== ButtonPressed =====
 #pragma --------------------------------------------------------------------------------------------
 
+- (void)modifyTxtButtonPressed:(UIBarButtonItem *)sender
+{
+    UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"NCText" bundle:nil] instantiateViewControllerWithIdentifier:@"NCText"];
+    
+    NCText *viewController = (NCText *)navigationController.topViewController;
+    
+    viewController.metadata = self.metadataDetail;
+    
+    [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
+    [self presentViewController:navigationController animated:YES completion:nil];
+}
+
 - (void)actionButtonPressed:(UIBarButtonItem *)sender
-{    
+{
     NSString *filePath;
     
     if ([self.metadataDetail.fileNamePrint length] == 0) return;

+ 1 - 8
iOSClient/Main/CCMain.m

@@ -919,16 +919,9 @@
     
         case k_returnCreateFileText: {
             
-            // remove file Untitled.txt
-            //[[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, NSLocalizedString(@"_untitled_txt_", nil)] error:nil];
-            
             UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"NCText" bundle:nil] instantiateViewControllerWithIdentifier:@"NCText"];
             
-            NCText *viewController = (NCText *)navigationController.topViewController;
-            
-            viewController.delegate = self;
-            viewController.serverUrl = _serverUrl;
-            viewController.titleMain = _titleMain;
+            //NCText *viewController = (NCText *)navigationController.topViewController;
             
             [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
             [self presentViewController:navigationController animated:YES completion:nil];

+ 4 - 42
iOSClient/Text/NCText.storyboard

@@ -18,11 +18,11 @@
                         <viewControllerLayoutGuide type="bottom" id="5fD-Qb-N57"/>
                     </layoutGuides>
                     <view key="view" contentMode="scaleToFill" id="skk-fU-Vk6">
-                        <rect key="frame" x="0.0" y="64" width="375" height="559"/>
+                        <rect key="frame" x="0.0" y="64" width="375" height="603"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
                             <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" keyboardDismissMode="interactive" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="pmg-g2-Fbs">
-                                <rect key="frame" x="0.0" y="0.0" width="375" height="559"/>
+                                <rect key="frame" x="0.0" y="0.0" width="375" height="603"/>
                                 <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                                 <fontDescription key="fontDescription" type="system" pointSize="14"/>
                                 <textInputTraits key="textInputTraits"/>
@@ -37,31 +37,7 @@
                         </constraints>
                     </view>
                     <extendedEdge key="edgesForExtendedLayout"/>
-                    <toolbarItems>
-                        <barButtonItem image="actionSheetModify" id="EDN-Il-Q37">
-                            <connections>
-                                <action selector="modifyButtonTapped:" destination="oRF-nm-GrS" id="Vh4-tN-fXC"/>
-                            </connections>
-                        </barButtonItem>
-                        <barButtonItem style="plain" systemItem="flexibleSpace" id="7D3-Jp-G8Q"/>
-                        <barButtonItem image="actionSheetDelete" id="40X-Vo-Hy2">
-                            <connections>
-                                <action selector="deleteButtonTapped:" destination="oRF-nm-GrS" id="U2y-hT-dOQ"/>
-                            </connections>
-                        </barButtonItem>
-                        <barButtonItem width="25" style="plain" systemItem="fixedSpace" id="l83-dY-K62"/>
-                        <barButtonItem image="actionSheetShare" id="6og-yq-pNL">
-                            <connections>
-                                <action selector="shareButtonTapped:" destination="oRF-nm-GrS" id="qaW-VY-Ziw"/>
-                            </connections>
-                        </barButtonItem>
-                        <barButtonItem width="25" style="plain" systemItem="fixedSpace" id="Mgf-az-QKC"/>
-                        <barButtonItem image="actionSheetOpenIn" id="2Kw-LQ-ehq">
-                            <connections>
-                                <action selector="openInButtonTapped:" destination="oRF-nm-GrS" id="74a-js-ncE"/>
-                            </connections>
-                        </barButtonItem>
-                    </toolbarItems>
+                    <toolbarItems/>
                     <navigationItem key="navigationItem" id="LYL-SD-Ayv">
                         <barButtonItem key="leftBarButtonItem" title="Item" id="brk-EO-iNZ">
                             <connections>
@@ -76,11 +52,7 @@
                     </navigationItem>
                     <connections>
                         <outlet property="cancelButton" destination="brk-EO-iNZ" id="8gM-f2-AtV"/>
-                        <outlet property="deleteButton" destination="40X-Vo-Hy2" id="0ru-ri-tqi"/>
-                        <outlet property="modifyButton" destination="EDN-Il-Q37" id="0yP-N0-ObG"/>
                         <outlet property="nextButton" destination="Hyb-2c-5Hb" id="Zmo-Th-UUq"/>
-                        <outlet property="openInButton" destination="2Kw-LQ-ehq" id="aS5-0P-URL"/>
-                        <outlet property="shareButton" destination="6og-yq-pNL" id="s0f-fp-NLP"/>
                         <outlet property="textView" destination="pmg-g2-Fbs" id="T5E-gh-UZ6"/>
                     </connections>
                 </viewController>
@@ -91,7 +63,7 @@
         <!--Navigation Controller-->
         <scene sceneID="lyP-Qo-Lgl">
             <objects>
-                <navigationController storyboardIdentifier="NCText" automaticallyAdjustsScrollViewInsets="NO" toolbarHidden="NO" id="zKl-U9-avf" sceneMemberID="viewController">
+                <navigationController storyboardIdentifier="NCText" automaticallyAdjustsScrollViewInsets="NO" id="zKl-U9-avf" sceneMemberID="viewController">
                     <extendedEdge key="edgesForExtendedLayout"/>
                     <toolbarItems/>
                     <navigationBar key="navigationBar" contentMode="scaleToFill" id="UIP-td-6cq">
@@ -99,10 +71,6 @@
                         <autoresizingMask key="autoresizingMask"/>
                     </navigationBar>
                     <nil name="viewControllers"/>
-                    <toolbar key="toolbar" opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="d3Q-mu-6g7">
-                        <rect key="frame" x="0.0" y="623" width="375" height="44"/>
-                        <autoresizingMask key="autoresizingMask"/>
-                    </toolbar>
                     <connections>
                         <segue destination="oRF-nm-GrS" kind="relationship" relationship="rootViewController" id="gPZ-9Y-e4E"/>
                     </connections>
@@ -112,10 +80,4 @@
             <point key="canvasLocation" x="10" y="-197"/>
         </scene>
     </scenes>
-    <resources>
-        <image name="actionSheetDelete" width="25" height="25"/>
-        <image name="actionSheetModify" width="25" height="25"/>
-        <image name="actionSheetOpenIn" width="25" height="25"/>
-        <image name="actionSheetShare" width="25" height="25"/>
-    </resources>
 </document>

+ 19 - 47
iOSClient/Text/NCText.swift

@@ -14,18 +14,10 @@ class NCText: UIViewController, UITextViewDelegate {
     @IBOutlet weak var nextButton: UIBarButtonItem!
     @IBOutlet weak var textView: UITextView!
     
-    @IBOutlet weak var modifyButton: UIBarButtonItem!
-    @IBOutlet weak var openInButton: UIBarButtonItem!
-    @IBOutlet weak var shareButton: UIBarButtonItem!
-    @IBOutlet weak var deleteButton: UIBarButtonItem!
-
     let appDelegate = UIApplication.shared.delegate as! AppDelegate
     
-    weak var delegate: CCMain?
-    var fileName: String?
-    var loadText: String? = ""
-    var serverUrl: String = ""
-    var titleMain: String = ""
+    var metadata: tableMetadata?
+    var loadText: String?
     
     override func viewDidLoad() {
         
@@ -42,30 +34,16 @@ class NCText: UIViewController, UITextViewDelegate {
         cancelButton.title = NSLocalizedString("_cancel_", comment: "")
         nextButton.title = NSLocalizedString("_next_", comment: "")
         
-        if let fileName = fileName {
+        if let metadata = metadata {
             
-            let path = "\(appDelegate.directoryUser!)/\(fileName)"
-            loadText = try? String(contentsOfFile: path, encoding: String.Encoding.utf8)
-            if loadText == nil {
-                loadText = ""
-            }
-            textView.isUserInteractionEnabled = false
+            let path = "\(appDelegate.directoryUser!)/\(metadata.fileID)"
             
-        } else {
-            
-            self.fileName =  NSLocalizedString("_untitled_txt_", comment: "")
-            modifyButton.tintColor = UIColor.clear
-            modifyButton = nil
-            openInButton.tintColor = UIColor.clear
-            openInButton = nil
-            shareButton.tintColor = UIColor.clear
-            shareButton = nil
-            deleteButton.tintColor = UIColor.clear
-            deleteButton = nil
-            
-            textView.isUserInteractionEnabled = true
-            textView.becomeFirstResponder()
+            loadText = try? String(contentsOfFile: path, encoding: String.Encoding.utf8)
+            textView.text = loadText
         }
+        
+        textView.isUserInteractionEnabled = true
+        textView.becomeFirstResponder()
     }
 
     override func viewWillAppear(_ animated: Bool) {
@@ -100,25 +78,19 @@ class NCText: UIViewController, UITextViewDelegate {
     
     @IBAction func nextButtonTapped(_ sender: AnyObject) {
         
-        let formViewController = CreateFormUploadFile.init(self.titleMain, serverUrl: self.serverUrl, text: self.textView.text, fileName: self.fileName!)
-        self.navigationController?.pushViewController(formViewController, animated: true)
-    }
-    
-    @IBAction func modifyButtonTapped(_ sender: AnyObject) {
+        if let metadata = metadata {
+            
+            //let formViewController = CreateFormUploadFile.init(self.titleMain, serverUrl: self.serverUrl, text: self.textView.text, fileName: self.fileName!)
+            //self.navigationController?.pushViewController(formViewController, animated: true)
+            
+        } else {
+            
+            let formViewController = CreateFormUploadFile.init(NSLocalizedString("_untitled_txt_", comment: ""), serverUrl: appDelegate.activeMain.serverUrl, text: self.textView.text, fileName: NSLocalizedString("_untitled_txt_", comment: ""))
+            self.navigationController?.pushViewController(formViewController, animated: true)
+        }
         
-        textView.isUserInteractionEnabled = true
-        textView.becomeFirstResponder()
-    }
-    
-    @IBAction func openInButtonTapped(_ sender: AnyObject) {
         
-    }
-    
-    @IBAction func shareButtonTapped(_ sender: AnyObject) {
         
-    }
-    
-    @IBAction func deleteButtonTapped(_ sender: AnyObject) {
         
     }
 }