nstextview

Dragging attachments out of NSTextView

Hi all, I am working on mac mail like feature- 1. dragging a file on body of message being composed and showing it as icon, over it. 2. dropping the icon of file from message body back to desktop or to any folder, so that it gets downloaded in it. I am able to implement the first point using NSTextView and calling method: -(void)setImp...

"Building a Text Editor in 15 Minutes" reference example not working

I am trying to work on NSDocument, so I tried the Building a Text Editor in 15 Minutes example in the Text System Overview reference. I did some changes to code which was suggested, such as used property and synthesize in place of declaring and defining accessor methods. I followed each step written in the reference but could not imple...

Location on screen of location in NSTextView

Hi, I want to get the screen location (NSPoint) of a point in an NSTextView, this should be simple, but by results are always a bit off, the X is perfect, but the Y seems to vary. I've tried a few variations of the code below, but can't get the result I'm after, is the NSClipView screwing it up? NSPoint p = [[self layoutManager] locat...

How to change only font size for the whole styled text in NSTextView

I need to set a text size (for example to 42) of the selected rich text which uses multiple fonts. I imagine I can check attributes of each group of characters, modify the font size and set attributes back, but looking at the floating Font panel it seems like there should be a very easy and straightforward way to accomplish that. Do I ...

Setting text for NSTextView with an NSString variable, considering reference counting

I have the following code in a function in my .m file: desc = [my executeFunction]; // desc is returned by executeFunction data = [desc objectAtIndex:0]; // data is declared in the .h file data2 = [desc objectAtIndex:1]; [myTextField setString:data]; // myTextField is connected to an NSTextView in IB [myTextField setString:da...

NSTextView rounded border / stroke in Cocoa

Hi All I am subclassing NSTextView and over-riding the drawRect method in order to draw an NSBezierPathWithRoundedRect around the textview, however - as it has rounded edges, they interfere with the text in the text view. Is there any way to apply some kind of margin or padding all around the text input area of the NSTextView so that i...

How to get height for NSAttributedString at a fixed width

I want to do some drawing of NSAttributedStrings in fixed-width boxes, but am having trouble calculating the right height they'll take up when drawn. So far, I've tried: Calling - (NSSize) size, but the results are useless (for this purpose), as they'll give whatever width the string desires. Calling - (void)drawWithRect:(NSRect)rect o...

NSTextView determine if NSTextAttachment is present

Hi, in my MyDocument class I need to determine if there is an image in my NSTextView, so I can prevent users from saving documents as RTF although RTF doesn't support images. Could someone point me in the right direction? ...

What's the equivalent "sizeWithFont: " method for the Mac?

I'm familiar with sizeWithFont: for the iPhone. Now I'm trying to build an app for the Mac and need something like that, but I don't know how to do it :/ Here's why I need it: I've got a panel that displays some text, and I want to size it so that it just fits the content (a NSTextView). How would you do it? ...

NSTextField or NSTextView?

Could someone explain to me what are the main differences between NSTextField and NSTextView? I know that NSTextView has more features and is usually used for longer texts, and NSTextField is usually used for one-line plain text fields, but if I understand correctly, NSTextField can be also used with attributed strings and with multiple ...

How can I make the Tab key move focus out of a NSTextView?

I'm using an NSTextView to allow multi-line input. However, due to the nature of my app, users will be more comfortable moving to the next input element when they press TAB. How can I make TAB exit the NSTextView, while keeping the newline behaviour of the Enter key? ...

Multiple undo managers for a text view

Hi, I've a text view that gets its content from an attributed string stored in a model object. I list several of these model objects in a drawer and when the user clicks on one the text view swaps its content. I now need to also swap the undo manager for the text view. I initialise an undo manager on my model object and use undoManager...

NSTextView's adjustScroll method

I'm trying to implement typewriter scrolling in my Cocoa text editor, keeping the insertion point centered vertically in its scrollview. Toward this end, I have subclassed NSClipView to provide a scrollToPointWithoutConstraint method, which scrolls the document to a specified point without calling constrainScrollPoint. This is necessary...

Create hyperlink to some text in NSTextView

I can create a hyperlink to some url in an NSTextView using the "Link Panel". Or I can add a link manually using the NSLinkAttributeName attribute of NSAttributedString. I don't want to make a hyperlink to some external url though, I want to be able to create a hyperlink to some text within the NSTextView. Do you know how in Pages you c...

controlling NSTextView updates to deal with flicker and improve speed

I have a subclassed NSTextView that I am manipulating in a separate thread (using performSelectorOnMainThread:withObject:waitUntilDone:) using selectors replaceCharactersInRange:withString:, setSelectedRange:, and insertText:. I'm experiencing flickering of text, and poor performance as the NSTextView updates the display for each and eve...

How to resize NSTextView according to its content?

Hi all, I am trying to set an attributed string within NSTextView. I want to increase its height based on its content, initially it is set to some default value. So I tried this method: I set content in NSTextView. When we set some content in NSTextView its size automatically increases. So I increased height of its super view that is ...

Bind enabled of NSButton to selection in NSTextView

I have a button that does something to the selected text in NSTextView. If nothing is selected then nothing happens when the button is pressed... so can the enabled property of a button be bound to whether or not some text is selected? ...

How would one make an Xcode style console window?

I am making a Haskell editor with Cocoa, and it would be useful to support some in-application text output. Even better would be supporting some text input. Xcode does all this in its console, which looks like it might be an NSTextView, but not sure if somebody might have done all this before. ...

How to paint background of specific range of text in NSTextView

Hi, This is not a specific bug, its more about not knowing how to do something. I've an NSTextView and I need to paint the background of specific ranges of text when the user clicks on a specific part of the text view. I've tried this but I just get erratic behaviour in the sense that sometimes text loses the foreground color or the ba...

Getting output of a shell script in Cocoa

Is there a way that lets me run a shell script, and display the output in an NSTextView? I do not want any input from the user to the shell script at all, since is is just called to compile a buch of files. The shell script part works fine so far, but I just can't figure out how to run it and show the output in an NSTextView. I know a sh...