private static void GetSourceFile(Action <IRuntimeFileInfo, Passphrase> fileSelected) { NSOpenPanel panel = NSOpenPanel.OpenPanel; PasswordViewController passwordController = new PasswordViewController(); panel.AccessoryView = passwordController.View; panel.Begin(result => { if (result == 0 || panel.Urls.Length == 0) { return; } if (!panel.Urls[0].IsFileUrl) { return; } string filePath = panel.Urls[0].Path; Passphrase generatedPassphrase = passwordController.Passphrase; panel.Close(); ThreadPool.QueueUserWorkItem(delegate { using (new NSAutoreleasePool()) { fileSelected(OS.Current.FileInfo(filePath), generatedPassphrase); }; }); }); }
public static void EncryptFile(ProgressContext progress, Action <string, ProgressContext> failure) { CreatePassphraseViewController passphraseController = new CreatePassphraseViewController { EncryptedFileName = DateTime.Now.ToString("yyyyMMddHHmmss") }; NSOpenPanel open = new NSOpenPanel { AccessoryView = passphraseController.View, AllowsMultipleSelection = false, CanChooseDirectories = false, CanChooseFiles = true, CanSelectHiddenExtension = true, CollectionBehavior = NSWindowCollectionBehavior.Transient, ExtensionHidden = true, Message = "Please select the file you would like to encrypt", Prompt = "Encrypt file", Title = "Encrypt", TreatsFilePackagesAsDirectories = false, }; open.Begin(result => { if (result == 0 || open.Urls.Length == 0) { return; } if (!open.Urls[0].IsFileUrl) { return; } string sourceFilePath = open.Urls[0].Path; open.Close(); IRuntimeFileInfo sourceFile = OS.Current.FileInfo(sourceFilePath); Passphrase passphrase = passphraseController.VerifiedPassphrase; if (passphrase == null) { return; } IRuntimeFileInfo targetFile = GetTargetFileName(sourceFilePath, passphraseController.EncryptedFileName); ThreadPool.QueueUserWorkItem(delegate { using (new NSAutoreleasePool()) { AxCryptFile.EncryptFileWithBackupAndWipe(sourceFile, targetFile, passphrase.DerivedPassphrase, progress); }; }); }); }
public static string OpenFilePanel() { // Open file prompt // Credit user: rjm // http://forums.xamarin.com/discussion/3876/regression-in-nsopenpanel NSOpenPanel openPanel = new NSOpenPanel(); string s = ""; openPanel.Begin(((int result) => { try { if (openPanel.Url != null) { s = openPanel.Url.Path; } } finally { openPanel.Dispose(); } })); return(s); }
static void GetTargetPath(Action <string> directorySelected) { NSOpenPanel panel = NSOpenPanel.OpenPanel; panel.CanChooseFiles = false; panel.CanChooseDirectories = true; panel.Begin(result => { if (result == 0 || panel.Urls.Length == 0) { return; } if (!panel.Urls[0].IsFileUrl) { return; } string filePath = panel.Urls[0].Path; panel.Close(); directorySelected(filePath); }); }
public override void FinishedLaunching(NSObject notification) { /////// /// Glorified Event "Handler" /// for Menu Items (like File, edit and so forth) /////// /// // *************************** // // TODO // - Reimplement SaveAs (command-S) mainWindowController = new MainWindowController(); mainWindowController.Window.MakeKeyAndOrderFront(this); MainWindow winMain = mainWindowController.Window; ///// /// SaveAs File Menu Item ///// miSaveAs.Activated += (object sender, EventArgs e) => { SharedWindowMethods.SaveCurrentSetFilePanel(); }; ///// /// Open File Menu Item ///// miOpen.Activated += (object sender, EventArgs e) => { // Call for openPanel // Credit user: rjm // http://forums.xamarin.com/discussion/3876/regression-in-nsopenpanel NSOpenPanel openPanel = new NSOpenPanel(); openPanel.Begin(((int result) => { try { if (openPanel.Url != null) { // get path var file = openPanel.Url.Path; // open file m_at.OpenFile(System.IO.Path.GetFileName(file), System.IO.Path.GetDirectoryName(file)); // parse open file m_at.InitSet(); // init SetRunner m_sr.Init(m_at.GetSetList()); // update table winMain.tbvSetList.DataSource = new TableViewHandler(m_at.GetSetListTable()); } } finally { openPanel.Dispose(); } })); // refresh window gui winMain.updateGUI(); }; }