public bool TableViewWriteToPasteboard(NSTableView aTableView, NSIndexSet aRows, NSPasteboard aPasteboard) { Console.WriteLine("TableViewWriteToPasteboard::" + aRows.Count); iDraggedBookmarks = new List <Bookmark>(); uint index = aRows.FirstIndex; while (index != FoundationFramework.NSNotFound) { iDraggedBookmarks.Add(iBookmarks[(int)index].CastAs <BookmarkData>().Bookmark); index = aRows.IndexGreaterThanIndex(index); } // add a token to the pasteboard PasteboardViewDragDataBookmarks token = new PasteboardViewDragDataBookmarks(); NSData tokenData = NSKeyedArchiver.ArchivedDataWithRootObject(token); token.Release(); aPasteboard.DeclareTypesOwner(NSArray.ArrayWithObject(PasteboardViewDragDataBookmarks.PboardType), null); aPasteboard.SetDataForType(tokenData, PasteboardViewDragDataBookmarks.PboardType); iDragging = true; return(true); }
public void AwakeFromNib() { // set appearance of view TextFieldTitle.TextColor = NSColor.WhiteColor; TextFieldTitle.Font = FontManager.FontLarge; ViewTable.RowHeight = 60.0f; ViewTable.BackgroundColor = NSColor.ClearColor; NSTableColumn textColumn = ViewTable.TableColumns[1].CastAs <NSTableColumn>(); NSTextFieldCell textCell = textColumn.DataCell.CastAs <NSTextFieldCell>(); textCell.TextColor = NSColor.WhiteColor; textCell.Font = FontManager.FontSemiLarge; // setup model eventing iBookmarkManager.EventBookmarkAdded += ModelChanged; iBookmarkManager.EventBookmarkRemoved += ModelChanged; iBookmarkManager.EventBookmarksChanged += ModelChanged; ModelChanged(this, EventArgs.Empty); // setup drag/drop ViewTable.DataSource = this; ViewTable.SetDraggingSourceOperationMaskForLocal(NSDragOperation.NSDragOperationMove | NSDragOperation.NSDragOperationDelete, true); NSArray dragTypes = NSArray.ArrayWithObject(PasteboardViewDragDataBookmarks.PboardType); ViewTable.RegisterForDraggedTypes(dragTypes); // setup delegate - if this is done in IB, the methods can be called // before awakeFromNib which causes complications ViewTable.Delegate = this; ViewTable.DeselectAll(this); }
public static void SetFrames(NSViewAnimation aAnimation, Id aTarget, NSRect aStart, NSRect aEnd) { NSDictionary animDict = NSDictionary.DictionaryWithObjectsAndKeys(aTarget, NSViewAnimation.NSViewAnimationTargetKey, NSValue.ValueWithRect(aStart), NSViewAnimation.NSViewAnimationStartFrameKey, NSValue.ValueWithRect(aEnd), NSViewAnimation.NSViewAnimationEndFrameKey, null); aAnimation.ViewAnimations = NSArray.ArrayWithObject(animDict); }
private bool setToPasteboard(IntPtr handle) { if (handle == IntPtr.Zero) { return(false); } generalPasteboard.ClearContents(); generalPasteboard.WriteObjects(NSArray.ArrayWithObject(handle)); return(true); }
private IntPtr getFromPasteboard(IntPtr @class) { NSArray classArray = NSArray.ArrayWithObject(@class); if (!generalPasteboard.CanReadObjectForClasses(classArray, null)) { return(IntPtr.Zero); } var result = generalPasteboard.ReadObjectsForClasses(classArray, null); var objects = result?.ToArray(); return(objects?.Length > 0 ? objects[0] : IntPtr.Zero); }
public override string GetText() { NSArray classArray = NSArray.ArrayWithObject(Class.Get("NSString")); if (GeneralPasteboard.CanReadObjectForClasses(classArray, null)) { var result = GeneralPasteboard.ReadObjectsForClasses(classArray, null); var objects = result?.ToArray() ?? new IntPtr[0]; if (objects.Length > 0 && objects[0] != IntPtr.Zero) { return(Cocoa.FromNSString(objects[0])); } } return(string.Empty); }
public override void SetText(string selectedText) { generalPasteboard.ClearContents(); generalPasteboard.WriteObjects(NSArray.ArrayWithObject(Cocoa.ToNSString(selectedText))); }
public static Process[] GetProcesses() { // spin up the objective-c runtime ObjectiveCRuntime.LoadFramework("Cocoa"); ObjectiveCRuntime.Initialize(); NSAutoreleasePool pool = new NSAutoreleasePool(); // Create our process NSTask getPSTask = new NSTask(); NSPipe getPSStandardOut = new NSPipe(); getPSTask.StandardOutput = getPSStandardOut; getPSTask.LaunchPath = @"/bin/ps"; // add some arguments NSString getPSargumentString = new NSString("-ax"); NSArray getPSarguments = NSArray.ArrayWithObject(getPSargumentString); getPSTask.Arguments = getPSarguments; // We have liftoff getPSTask.Launch(); getPSTask.WaitUntilExit(); // Parse the output NSData getPSoutput = getPSStandardOut.FileHandleForReading.ReadDataToEndOfFile; NSString getPSoutString = new NSString(getPSoutput, NSStringEncoding.NSUTF8StringEncoding); // Split the string of output in to a list of processes string[] getPSsplitString = getPSoutString.ToString().Split(Environment.NewLine.ToCharArray()); // Remove the first and last line of the output string[] processListAsStrings = new string[getPSsplitString.Length - 2]; for (int x = 1; x < getPSsplitString.Length - 1; x++) { processListAsStrings[x - 1] = getPSsplitString[x]; } Process[] processes = new Process[processListAsStrings.Length]; for (int i = 0; i < processes.Length; i++) { string cleanString = RemoveExtraSpaces(processListAsStrings[i]); string[] processDetails = cleanString.Split(' '); Int32 procID = Convert.ToInt32(processDetails[0]); string procName = string.Empty; for (int j = 4; j < processDetails.Length; j++) { if (j == 4) { procName = procName + processDetails[j]; } else { procName = procName + " " + processDetails[j]; } } //Console.WriteLine(procID.ToString() + procName); processes[i] = new Process(procID, procName); } // Dipose our Objective-C objects, gotta love reference counting pool.Release(); return(processes); }