Пример #1
0
		public async Task PerformActionOnDocument (DocumentReference docRef, UIViewController fromController, UIBarButtonItem fromButton)
		{
			try {
				
				if (docRef == null)
					return;

				var ad = this;

				if (ad.DismissSheetsAndPopovers ())
					return;

				NSObject[] items = new NSObject[0];
				UIActivity[] aa = new UIActivity[0];

				try {

					var d = (await docRef.Open ()) as TextDocument;

					if (d != null) {
						items = await d.GetActivityItemsAsync (fromController);
						aa = await d.GetActivitiesAsync (fromController);
					}

					await docRef.Close ();
									
				} catch (Exception ex) {
					Debug.WriteLine (ex);
				}

				if (items.Length > 0) {
					var tcs = new TaskCompletionSource<bool> ();
					var a = new UIActivityViewController (items, aa);
					a.ModalPresentationStyle = UIModalPresentationStyle.Popover;

					a.CompletionHandler = (x,success) => {
						Console.WriteLine ("COMPLETE {0} {1}", x, success);
						tcs.SetResult (success);
					};

					if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
						if (a.PopoverPresentationController != null) {
							try {
								a.PopoverPresentationController.BarButtonItem = fromButton;
							} catch (Exception) {
								a.PopoverPresentationController.SourceView = fromController.View;
							}
						}
					}

					fromController.PresentViewController (a, true, null);

					await tcs.Task;
				}

			} catch (Exception ex) {
				Console.WriteLine ("Perform Act of Doc Failed: " + ex);
			}

		
		}
Пример #2
0
			public void AddToMRU (IFileSystem fs, DocumentReference docRef)
			{
				var key = Tuple.Create (fs.Id, docRef.File.Path);

				var i = entries.IndexOf (key);

				if (i == 0) {
					// OK
					return;
				} else if (i > 0) {
					entries.RemoveAt (i);
				}
				entries.Insert (0, key);


				Console.WriteLine ("SAVE MRU {0}", entries);

				if (ios9) {
					var icon = UIApplicationShortcutIcon.FromType (UIApplicationShortcutIconType.Compose);
					var newItems = entries.Take (3).Select (e => {
						var fsId = e.Item1;
						var path = e.Item2;
						var name = System.IO.Path.GetFileNameWithoutExtension (path);
						var userInfo = new NSDictionary<NSString, NSObject> (
							keys: new[] {new NSString("fsId"), new NSString("path")},
							values: new NSObject[] {new NSString(fsId), new NSString(path)});						
						var item = new UIMutableApplicationShortcutItem("open", "Open " + name, "", icon, userInfo);
						return item;
					}).ToArray ();
					UIApplication.SharedApplication.ShortcutItems = newItems;
				}
			}
Пример #3
0
		public async Task AddAndOpenDocRef (DocumentReference dr)
		{
			var fileDir = Path.GetDirectoryName (dr.File.Path);
			if (fileDir == "/")
				fileDir = "";

			var dl = CurrentDocumentListController;

			if (dl.Directory != fileDir) {

				await CreateDocListHierarchy (fileDir, true);
				dl = CurrentDocumentListController;

			}

			dl.InsertDocument (0, dr);

			await OpenDocument (0, true);
		}
Пример #4
0
		public virtual async Task<UIImage> GenerateThumbnailAsync (DocumentReference docRef, Praeclarum.Graphics.SizeF size, Theme theme)
		{
			UIImage r = null;

			IDocument doc = null;
			LocalFileAccess local = null;
			var opened = false;

			//
			// Draw the document
			//
			try {
				local = await docRef.File.BeginLocalAccess ();
				var f = local.LocalPath;

				doc = App.CreateDocument (f);
				await doc.OpenAsync ();
				opened = true;

//				Console.WriteLine ("GenerateThumbnail: " + docRef.File.Path + " " + docRef.File.ModifiedTime);

				r = await GenerateDocumentThumbnailAsync (doc, size, theme);

			} catch (Exception ex) {
				Debug.WriteLine ("FAILED to genenerate thumbnail for {0}, {1}", docRef.File.Path, ex.Message);
//				Debug.WriteLine (ex);
			}

			if (opened) {
				try {
					await doc.CloseAsync ();					
				} catch (Exception ex) {
					Console.WriteLine (ex);
				}
			}

			if (local != null) {
				try {
					await local.End ();
				} catch (Exception ex) {
					Console.WriteLine (ex);
				}
			}

			return r;
		}
Пример #5
0
		public DocumentEditor (DocumentReference docRef)
		{
			this.docRef = docRef;
		}
Пример #6
0
		void AddDocRef (DocumentReference dr)
		{
			CurrentDocumentListController.InsertDocument (0, dr);
		}
		async Task Rename (DocumentReference docRef, string newName)
		{
			try {
				var oldIndex = Docs.FindIndex (x => x.File.Path == docRef.File.Path);

				var r = await docRef.Rename (newName);

				if (r) {

					Console.WriteLine ("RENAME to {0}: {1}", newName, r);

					if (oldIndex >= 0) {
						await LoadDocs ();
						var newIndex = Docs.FindIndex (x => x.File.Path == docRef.File.Path);
						if (newIndex >= 0 && newIndex != oldIndex) {
							docsView.ShowItem (newIndex, true);
						}
					}
				}
				else {
					alert = new UIAlertView ("Failed to Rename", "You may not have permission.", null, "OK");
					alert.Show ();
				}

//				AppDelegate.Shared.UpdateDocListName (docIndex);

			} catch (Exception ex) {
				Debug.WriteLine (ex);
			}
		}
Пример #8
0
		public DocumentViewerAndEditor (DocumentReference docRef)
			: base (docRef)
		{
			NavigationItem.RightBarButtonItem = EditButtonItem;
		}
		void HandleRenameRequested (DocumentReference docRef, object arg2)
		{
			var name = docRef.Name;
			var dir = Path.GetDirectoryName (docRef.File.Path);
			var c = new TextInputController {
				Title = "Rename " + (docRef.File.IsDirectory ? "Folder" : DocumentAppDelegate.Shared.App.DocumentBaseName),
				InputText = name,
				ValidateFunc = n => DocumentAppDelegate.ValidateNewName (dir, n, docRef.Name),
			};

			var nc = new UINavigationController (c);
			nc.NavigationBar.BarStyle = DocumentAppDelegate.Shared.Theme.NavigationBarStyle;
			nc.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;

			var presenter = this;

			c.Cancelled += (ss, ee) => presenter.DismissViewController (true, null);
			c.Done += async (ss, ee) => {
				presenter.DismissViewController (true, null);

				if (!string.IsNullOrWhiteSpace (c.InputText) && c.InputText != name) {
					await Rename (docRef, c.InputText);
				}
			};

			presenter.PresentViewController (nc, true, null);
		}
		public void InsertDocument (int docIndex, DocumentReference dr)
		{
			if (docIndex < 0)
				return;

			// Watch out in case we already got notified of this insertion
			var existing = docIndex < Docs.Count ? Docs [docIndex] : null;
			if (existing != null && existing.File.Path == dr.File.Path)
				return;

			//
			// Insert it nicely
			//
			Docs.Insert (docIndex, dr);
			items.Insert (docIndex, new DocumentsViewItem (dr));

			try {
				docsView.InsertItems (new[] { docIndex });
			} catch (Exception ex) {
				Debug.WriteLine (ex);				
			}
		}
Пример #11
0
		public DocumentEditor (DocumentReference docRef)
		{
			DocumentReference = docRef;
		}
Пример #12
0
		public DocumentsViewItem (DocumentReference reference)
		{
			Reference = reference;
		}
		async Task<UIImage> GetThumbnail (DocumentReference doc, Theme theme)
		{
			var appDel = DocumentAppDelegate.Shared;
			var Cache = appDel.ThumbnailCache;

			var thumbKey = appDel.GetThumbnailKey (doc.File, theme);

			var thumbImage = await Cache.GetImageAsync (thumbKey, doc.ModifiedTime);

			if (thumbImage == null) {
				thumbImage = await appDel.GenerateThumbnailAsync (doc, ThumbnailSize, theme);
				if (thumbImage != null) {
					await Cache.SetGeneratedImageAsync (thumbKey, thumbImage, saveToDisk: true);
				}
			}

			return thumbImage;
		}