public TextContextItem(string name, Func<string, string> handler, float sortOrder, string undo, NSAttributedString title)
 {
     Name = name;
     Handler = handler;
     SortOrder = sortOrder;
     UndoText = undo;
     Title = title;
 }
Beispiel #2
0
		private NSData DoWriteWrapped(NSAttributedString str, NSString type)
		{
			NSRange range = new NSRange(0, (int) str.length());
			NSDictionary dict = NSDictionary.dictionaryWithObject_forKey(type, Externs.NSDocumentTypeDocumentAttribute);
			NSError error;
			NSData result = str.dataFromRange_documentAttributes_error(range, dict, out error);
			if (!NSObject.IsNullOrNil(error))
				error.Raise();
			
			return result;
		}
Beispiel #3
0
        private void DoSetString(NSAttributedString value)
        {
            // Unfortunately size is returning a value that is a bit too large so the
            // text isn't vertically centered when it is drawn. Not sure why this is,
            // maybe it's adding in leading, but the leading() method on our font
            // returns 0.0 so we can't use that to try to fix it up...
            NSSize size = value.size();
            size.width += 2*AnnotateView.LeftMargin;
            size.height = 2*AnnotateView.LeftMargin + m_fontHeight;

            DoAdjustFrame(size);
            m_view.SetText(value);
            m_view.setNeedsDisplay(true);
        }
Beispiel #4
0
        public void SetText(NSAttributedString text)
        {
            if (text != m_text)
            {
                if (!NSObject.IsNullOrNil(m_text))
                    m_text.release();

                m_text = text;

                if (!NSObject.IsNullOrNil(m_text))
                    m_text.retain();
            }
        }
Beispiel #5
0
 public new NSMutableAttributedString initWithAttributedString(NSAttributedString attrStr)
 {
     return base.initWithAttributedString(attrStr).To<NSMutableAttributedString>();
 }
Beispiel #6
0
        public FindsForFile(string path, string text, MatchCollection matches)
            : base(NSObject.AllocAndInitInstance("FindsForFile"))
        {
            m_path = NSString.Create(path).Retain();
            m_instances = new FindInstance[matches.Count];

            int i = 0;
            foreach (Match m in matches)
            {
                int index = m.Index;
                int length = m.Length;
                while (index > 0 && text[index - 1] != '\n')
                {
                    --index;
                    ++length;
                }

                while (index + length < text.Length && text[index + length] != '\n')
                    ++length;

                string context = text.Substring(index, length);
                m_instances[i] = new FindInstance(path, context, index, m.Index, m.Length).Retain();
                ++i;
            }

            var attrs = NSDictionary.dictionaryWithObject_forKey(NSNumber.Create(-3.0f), Externs.NSStrokeWidthAttributeName);

            // A normal path like /foo/bar/baz can easily be cut off on the right side
            // thereby hiding the name of the file. Reversing the path makes the filename
            // prominent and still includes the path components which are informative.
            path = path.ReversePath();
            m_styledPath = NSAttributedString.Create(path, attrs).Retain();
        }
Beispiel #7
0
        private static void DoSetAttributes(NSAttributedString text)
        {
            // Nuke the existing attributes (the user may have removed elements from the Styles file).
            foreach (var key in ms_attributes.Keys.ToArray())
            {
                if (key != "text spaces color changed" && key != "text tabs color changed")
                {
                    ms_attributes[key].release();
                    ms_attributes.Remove(key);
                }
            }

            // Copy the attributes from Styles.rtf and put them into ms_attributes.
            string str = text.string_().ToString();

            int offset = 0, line = 1;
            while (offset < str.Length)
            {
                if (char.IsLetter(str[offset]))
                {
                    int i = str.IndexOfAny(new char[]{':', '\r', '\n'}, offset + 1);
                    if (i > 0 && str[i] == ':')
                        DoSetAttribute(text, str, offset, i - offset);
                    else
                        DoWriteError("Expected a colon on line {0} in Styles.rtf", line);
                }
                else if (char.IsWhiteSpace(str[offset]))
                {
                    while (offset < str.Length && (str[offset] == ' ' || str[offset] == '\t'))
                        ++offset;

                    if (offset < str.Length && str[offset] != '\n' && str[offset] != '\r')
                        DoWriteError("Expected a blank line on line {0} in Styles.rtf", line);
                }
                else if (str[offset] != '#')
                {
                    DoWriteError("Expected an element, comment, or blank line on line {0} in Styles.rtf", line);
                }

                offset = DoFindNextLine(str, offset, ref line);
            }

            // We must have a Default style.
            if (!ms_attributes.ContainsKey("Default"))
            {
                DoWriteError("Styles.rtf has no Default element");

                DoChangeAttribute("Default", ms_baseAttrs);
            }
        }
Beispiel #8
0
        private static void DoSetAttribute(NSAttributedString text, string str, int begin, int length)
        {
            string name = str.Substring(begin, length);
            if (name != "text spaces color changed" && name != "text tabs color changed")
            {
                if (ms_attributes.ContainsKey(name))
                    DoWriteError("Styles.rtf defines the {0} element more than once.", name);
            }

            NSDictionary attrs = text.fontAttributesInRange(new NSRange(begin, length));
            DoChangeAttribute(name, attrs);
        }
Beispiel #9
0
        private void DoFindLargestFont(ITextOverlay overlay, NSRect rect)
        {
            float[] candidates = new float[]{12.0f, 14.0f, 18.0f, 24.0f, 36.0f, 48.0f, 64.0f, 72.0f, 06.0f, 144.0f, 288.0f, 0.0f};

            int i = 0;
            while (candidates[i + 1] != 0.0f)
            {
                var attrs = NSMutableDictionary.Create();
                NSFont font = NSFont.fontWithName_size(NSString.Create("Verdana"), candidates[i + 1]);
                attrs.setObject_forKey(font, Externs.NSFontAttributeName);

                attrs.setObject_forKey(overlay.Color, Externs.NSForegroundColorAttributeName);

                NSMutableParagraphStyle style = NSMutableParagraphStyle.Create();
                style.setAlignment(Enums.NSCenterTextAlignment);
                attrs.setObject_forKey(style, Externs.NSParagraphStyleAttributeName);

                var candidate = NSAttributedString.Create(overlay.Text, attrs);
                NSSize size = candidate.size();
                if (size.width <= rect.size.width && size.height <= rect.size.height)
                {
                    m_overlay = candidate.Retain();
                    m_overlaySize = size;
                    ++i;
                }
                else
                {
                    break;
                }
            }
        }
Beispiel #10
0
        private void DoCacheOverlay(ITextOverlay overlay, NSRect rect)
        {
            if (overlay.Text != m_overlayText || rect.size != m_overlayRect.size)
            {
                if (m_overlay != null)
                {
                    m_overlay.release();
                    m_overlay = null;
                }

                DoFindLargestFont(overlay, rect);
                m_overlayText = overlay.Text;
                m_overlayRect = rect;
            }
        }