예제 #1
0
        public void shiftLines(NSArray args)
        {
            int firstLine = args.objectAtIndex(0).To<NSNumber>().intValue();
            int lastLine = args.objectAtIndex(1).To<NSNumber>().intValue();
            int delta = args.objectAtIndex(2).To<NSNumber>().intValue();

            NSString tab;
            if (Language != null && !UsesTabs && !NSObject.IsNullOrNil(SpacesText))
                tab = SpacesText;
            else
                tab = NSString.Create("\t");

            NSTextStorage storage = m_textView.Value.textStorage();
            storage.beginEditing();
            try
            {
                Unused.Value = Text;		// make sure m_metrics is up to date

                for (int line = lastLine; line >= firstLine; --line)			// backwards so metrics doesn't get confused by our edits (it won't sync up until we call endEditing)
                {
                    int offset = m_metrics.GetLineOffset(line);
                    if (delta > 0)
                    {
                        storage.replaceCharactersInRange_withString(new NSRange(offset, 0), tab);
                    }
                    else
                    {
                        char ch = storage.string_().characterAtIndex((uint) offset);
                        if (ch == '\t' || ch == ' ')								// need to stop shifting lines left when there is no more whitespace
                            storage.deleteCharactersInRange(new NSRange(offset, 1));
                    }
                }
            }
            finally
            {
                storage.endEditing();
            }

            int firstOffset = m_metrics.GetLineOffset(firstLine);
            int lastOffset = m_metrics.GetLineOffset(lastLine + 1);
            m_textView.Value.setSelectedRange(new NSRange(firstOffset, lastOffset - firstOffset));

            NSArray oldArgs = NSArray.Create(args.objectAtIndex(0), args.objectAtIndex(1), NSNumber.Create(-delta));
            window().windowController().document().undoManager().registerUndoWithTarget_selector_object(this, "shiftLines:", oldArgs);
            window().windowController().document().undoManager().setActionName(NSString.Create("Shift"));
        }
예제 #2
0
        public void toggleComments(NSArray args)
        {
            int firstLine = args.objectAtIndex(0).To<NSNumber>().intValue();
            int lastLine = args.objectAtIndex(1).To<NSNumber>().intValue();
            NSString comment = args.objectAtIndex(2).To<NSString>();
            bool add = args.objectAtIndex(3).To<NSNumber>().boolValue();

            NSTextStorage storage = m_textView.Value.textStorage();
            storage.beginEditing();
            try
            {
                Unused.Value = Text;		// make sure m_metrics is up to date

                for (int line = lastLine; line >= firstLine; --line)			// backwards so metrics doesn't get confused by our edits (it won't sync up until we call endEditing)
                {
                    int offset = m_metrics.GetLineOffset(line);
                    if (add)
                    {
                        if (!DoLineStartsWith(offset, comment))
                            storage.replaceCharactersInRange_withString(new NSRange(offset, 0), comment);
                    }
                    else
                    {
                        if (DoLineStartsWith(offset, comment))
                            storage.deleteCharactersInRange(new NSRange(offset, (int) comment.length()));
                    }
                }
            }
            finally
            {
                storage.endEditing();
            }

            int firstOffset = m_metrics.GetLineOffset(firstLine);
            int lastOffset = m_metrics.GetLineOffset(lastLine + 1);
            m_textView.Value.setSelectedRange(new NSRange(firstOffset, lastOffset - firstOffset));

            NSArray oldArgs = NSArray.Create(args.objectAtIndex(0), args.objectAtIndex(1), args.objectAtIndex(2), NSNumber.Create(!add));
            window().windowController().document().undoManager().registerUndoWithTarget_selector_object(this, "toggleComments:", oldArgs);
            window().windowController().document().undoManager().setActionName(NSString.Create("Toggle Comment"));
        }
예제 #3
0
        //        public void processHandler(NSObject sender)
        //        {
        //            int i = sender.Call("tag").To<int>();
        //            string result = m_entries[i].Handler(m_selection);
        //            if (result != m_selection)
        //            {
        //                NSArray args = NSArray.Create(NSValue.valueWithRange(m_range), NSString.Create(result), NSString.Create(m_entries[i].UndoText));
        //                replaceSelection(args);
        //            }
        //        }
        //        public new bool validateUserInterfaceItem(NSObject item)
        //        {
        //            Selector sel = (Selector) item.Call("action");
        //            
        //            bool valid = false;
        //            if (sel.Name == "processHandler:")
        //            {
        //                int i = item.Call("tag").To<int>();
        //                item.Call("setState:", m_entries[i].State);
        //                valid = m_entries[i].Handler != null;
        //            }
        //            else
        //            if (SuperCall(NSTextView.Class, "respondsToSelector:", new Selector("validateUserInterfaceItem:")).To<bool>())
        //            {
        //                valid = SuperCall(NSTextView.Class, "validateUserInterfaceItem:", item).To<bool>();
        //            }
        //            
        //            return valid;
        //        }
        // args[0] = text range, args[1] = text which will replace the range, args[2] = undo text
        public void replaceSelection(NSArray args)
        {
            NSRange oldRange = args.objectAtIndex(0).To<NSValue>().rangeValue();

            string oldStr;
            string_().getCharacters_range(oldRange, out oldStr);	// TODO: if we can figure out that the selection is a class or method then we should add that to our url
            NSString oldText = NSString.Create(oldStr);

            NSString newText = args.objectAtIndex(1).To<NSString>();
            replaceCharactersInRange_withString(oldRange, newText);

            NSRange newRange = new NSRange(oldRange.location, (int) newText.length());

            NSArray oldArgs = NSArray.Create(NSValue.valueWithRange(newRange), oldText, args.objectAtIndex(2));
            var undoManager = window().windowController().document().undoManager();
            undoManager.registerUndoWithTarget_selector_object(this, "replaceSelection:", oldArgs);
            undoManager.setActionName(args.objectAtIndex(2).To<NSString>());
        }