Saving Custom Attributes [SOLVED, sort of...]
Saving Custom Attributes [SOLVED, sort of...]
- Subject: Saving Custom Attributes [SOLVED, sort of...]
- From: Alexander Griekspoor <email@hidden>
- Date: Sat, 19 Apr 2003 15:47:56 +0200
Hello!
Just wanted you to know that I found a solution for saving my custom
attributes that I like to share with you. As said, a number of people
asked the same question, and now I experienced the radio silence
covering this subject myself as well.
I managed to work around the problem, and therefore it isn't the nicest
solution. If anyone knows a better way, I'd be happy to hear!
I discovered that archiving the textstorage - which is an attributable
string in the end - using NSArchiver, preserves the custom attributes I
added to it. So the most easy thing to do, would be to save the
document as serialized data. Unfortunately, that would create a "new"
file format, and in addition, would prevent other apps from reading it.
So what I do now is to determine whether the documents has any custom
attributes. If so, I save the document as rtfd, and in addition I
serialize the textstorage and save it inside the created rtfd
directory. This way, the user sees one file (and rtfd document), which
can still be opened in any other app that reads rtfds (except that it
discards my custom attributes). But, when I open an rtfd document in my
TextEdit variant, it checks whether the serialized textstorage is
present, and if so, it unarchives this and uses it as the documents
textstorage:
[text setAttributedString: [NSUnarchiver unarchiveObjectWithFile:
[NSString stringWithFormat: @"%@/IEMarkings.data",
fileName]]];
Advantages:
- Preservation of custom attributes
- No custom file format
- Document still readable by other apps
Disadvantages:
- RTF files become RTFD files
- Text is included twice, so the document can become up to twice as big
in filesize.
For me, this solution is good enough, but of course saving the custom
attributes as proper rtf attributes would be the official way to go...
So a last request, if anyone can chime in and tell me how to do this,
many thanks in advance!
Regards,
Alex
>
FROM: Unknown
>
DATE: 2003-04-15 01:19
>
>
Hi!
>
>
What would be the way to save custom attributes from an attributed
>
string in an rtf / rtfd file?
>
I found a couple of threads in the archives with people asking the
>
same question, but none received an answer.
>
I'm extending TextEdit to support theme coding of texts. Therefore, I
>
want to append custom attributes to the text which are displayed and
>
marked when the theme is clicked in a tableview.
>
I've managed to get it working as desired, BUT the custom attributes
>
are not saved to disk.
>
Using the NSForegroundColor attribute is not an option as multiple
>
themes can apply to a single piece of text. What would it take to make
>
the custom attributes be saved in RTF files, and even more important,
>
where do I start?
>
>
Many thanks in advance for your help!!!
>
Regards, Alex
*********************************************************
** Alexander Griekspoor **
*********************************************************
The Netherlands Cancer Institute
Department of Tumorbiology (H4)
Plesmanlaan 121, 1066 CX, Amsterdam
Tel: + 31 20 - 512 2023
Fax: + 31 20 - 512 2029
E-mail: a.<EMAIL REMOVED>
Web:
http://www.mekentosj.com
LabAssistant - Get your life organized!
http://www.mekentosj.com/labassistant
*********************************************************
_______________________________________________
cocoa-dev mailing list | <EMAIL REMOVED>
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.