Discussion:
File Association: Double-click to open the application
(too old to reply)
Neel
2006-07-06 12:20:16 UTC
Permalink
Hi,

I am trying to do file association with my application. I found some
thread related to the same.

http://groups.google.co.in/group/comp.sys.mac.oop.powerplant/browse_thread/thread/a64c4ec656acdaae/9f656a9b4bf6f3d4?q=click+on+file+and+open+application&rnum=9&auth=DQAAAHEAAAABFxdOMV9vO789R3WGUh_VLt1UustK-BRq7OsEqXEwGYw50rLjXQQtXMto7Mr5zGLe8HrS_QDTPPKSOvxr_CO1WlG3mC8veyAbumDBrc8rS1KNV9jDMqtxI8bai3ZAn073ADat12pf8xR4P5KwGt5N0vDlt54bRTvpKG9pBWRfoA

Exactly, My application save file with .SGF xnt, which contains some
xml tags. I can save file anywhere on the local disk.

I checked GetInfo option of one of .SGF file it shows as TextEdit
Document. I am trying to do file association with the same file so if i
double-click on file then my application should start automatically and
read the contents of the file and show.

Menually, when i set "Open with" option of GetInfo and selected my
application as destination, then after double-click it open my
application, now this is something i want to do it programatically.

I have already set my unique creator id, and succesfully set the
application icon. The same id i am setting using
SetFileCreator('PcSL'). Please suggest where did i make mistake.

Here is the snippet of code:
/****************************************************************/
PP_StandardDialogs::LFileDesignator designator;
NavDialogOptions* options = designator.GetDialogOptions();
if (options != nil)
options->dialogOptionFlags=kNavDefaultNavDlogOptions+kNavPreserveSaveFileExtension;

LFileTypeList fileTypeList(fileTypes_All);
designator.SetFileType('TEXT');
designator.SetFileCreator('PcSL');

std::string l_strLocalFName;
GetScanGroupFileName(&l_strLocalFName);

if (designator.AskDesignateFile("\pUntitled.sgf"))
{
string strFullpath;
strFullpath ="";
GetFullPathWithString(outFSSpec, strFullpath);
designator.GetFileSpec(outFSSpec);
if (GetFullPathWithString(outFSSpec, strFullpath))
l_strLocalFName = strFullpath;
}
else
{
return false;
}

if ( l_pobjMacFileIO.Open( (char *)l_strLocalFName.c_str(), "Mw+"))
{
Save(&l_pobjMacFileIO);
SaveConfigurationSettingsInSGF(&l_pobjMacFileIO);
l_pobjMacFileIO.Close();

designator.CompleteSave();
}

/***********************************************************************/
Thanks in advance.
Neel.
David Phillip Oster
2006-07-06 15:20:38 UTC
Permalink
Post by Neel
I am trying to do file association with my application. I found some
thread related to the same.
http://groups.google.co.in/group/comp.sys.mac.oop.powerplant/browse_thread/thr
ead/a64c4ec656acdaae/9f656a9b4bf6f3d4?q=click+on+file+and+open+application&rnu
m=9&auth=DQAAAHEAAAABFxdOMV9vO789R3WGUh_VLt1UustK-BRq7OsEqXEwGYw50rLjXQQtXMto7
Mr5zGLe8HrS_QDTPPKSOvxr_CO1WlG3mC8veyAbumDBrc8rS1KNV9jDMqtxI8bai3ZAn073ADat12p
f8xR4P5KwGt5N0vDlt54bRTvpKG9pBWRfoA
Exactly, My application save file with .SGF xnt, which contains some
xml tags. I can save file anywhere on the local disk.
I reread the discussion liked by the above URL.

*) That archived discussion wasn't about the Finder, it was about the
NavPutFile dialog. Had we been talking about the Finder, we'd have
been discussing how you properly write an Info.plist file.

See:

http://www.google.com/search?q=CFBundleTypeExtensions+site%3Adeveloper.apple.com

*) I apologize for saying, in that discussion, "all uppercase" when I
meant "all lowercase".

*) Today, I'd advise: Make sure your Info.plist includes a
CFBundleDocumentTypes key with an array with dictionaries, each dict
with keys: CFBundleTypeExtensions CFBundleTypeIconFile
CFBundleTypeName CFBundleTypeOSTypes CFBundleTypeRole
LSItemContentTypes

See http://developer.apple.com/macosx/uniformtypeidentifiers.html
for more information on LSItemContentTypes.
Neel
2006-07-14 14:20:26 UTC
Permalink
Hi,

I did make the changes in .plist file,

<key>CFBundleDocumentTypes</key>
<array>
<dict>

<key>CFBundleTypeRole</key>
<string>None</string>

<key>CFBundleTypeExtensions</key>
<array>
<string>sgf</string>
</array>

<key>CFBundleIconFile</key>
<string>Hand.icns</string>

<key>CFBundleTypeOSTypes</key>
<array>
<string>PCSL</string>
</array>

<key>LSItemContentTypes</key>
<array>
<string>.sgf</string>
</array>

</dict>
</array>


Still, my if i double click the .sgf file then application should start
and open the same, but it gets open with TextEdit only. What changes
should i make to open file with my application.
Post by David Phillip Oster
Post by Neel
I am trying to do file association with my application. I found some
thread related to the same.
http://groups.google.co.in/group/comp.sys.mac.oop.powerplant/browse_thread/thr
ead/a64c4ec656acdaae/9f656a9b4bf6f3d4?q=click+on+file+and+open+application&rnu
m=9&auth=DQAAAHEAAAABFxdOMV9vO789R3WGUh_VLt1UustK-BRq7OsEqXEwGYw50rLjXQQtXMto7
Mr5zGLe8HrS_QDTPPKSOvxr_CO1WlG3mC8veyAbumDBrc8rS1KNV9jDMqtxI8bai3ZAn073ADat12p
f8xR4P5KwGt5N0vDlt54bRTvpKG9pBWRfoA
Exactly, My application save file with .SGF xnt, which contains some
xml tags. I can save file anywhere on the local disk.
I reread the discussion liked by the above URL.
*) That archived discussion wasn't about the Finder, it was about the
NavPutFile dialog. Had we been talking about the Finder, we'd have
been discussing how you properly write an Info.plist file.
http://www.google.com/search?q=CFBundleTypeExtensions+site%3Adeveloper.apple.com
*) I apologize for saying, in that discussion, "all uppercase" when I
meant "all lowercase".
*) Today, I'd advise: Make sure your Info.plist includes a
CFBundleDocumentTypes key with an array with dictionaries, each dict
with keys: CFBundleTypeExtensions CFBundleTypeIconFile
CFBundleTypeName CFBundleTypeOSTypes CFBundleTypeRole
LSItemContentTypes
See http://developer.apple.com/macosx/uniformtypeidentifiers.html
for more information on LSItemContentTypes.
David Phillip Oster
2006-07-14 14:46:45 UTC
Permalink
Post by Neel
Hi,
I did make the changes in .plist file,
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>None</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>sgf</string>
</array>
<key>CFBundleIconFile</key>
<string>Hand.icns</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>PCSL</string>
</array>
<key>LSItemContentTypes</key>
<array>
<string>.sgf</string>
</array>
</dict>
</array>
Still, my if i double click the .sgf file then application should start
and open the same, but it gets open with TextEdit only. What changes
should i make to open file with my application.
Replace <string>Editor</string>
David Phillip Oster
2006-07-15 03:27:05 UTC
Permalink
Post by Neel
Hi,
I did make the changes in .plist file,
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>None</string>
<key>CFBundleTypeExtensions</key>
<array>
<string>sgf</string>
</array>
<key>CFBundleIconFile</key>
<string>Hand.icns</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>PCSL</string>
</array>
<key>LSItemContentTypes</key>
<array>
<string>.sgf</string>
</array>
</dict>
</array>
Still, my if i double click the .sgf file then application should start
and open the same, but it gets open with TextEdit only. What changes
should i make to open file with my application.
Pardon me. <key>CFBundleTypeRole</key> <string>None</string> means your
program doesn't open this kind of files. (it may just give them an icon.)

<key>CFBundleTypeRole</key> <string>Viewer</string> -- for basically
read-only access.

<key>CFBundleTypeRole</key> <string>Editor</string> -- for true editing
of such files.
Neel
2006-07-17 12:55:10 UTC
Permalink
Hello David,

I did change in .plist file as Viewer, and compiling the application
again there is no change in the behaviour after double-clicking the
.sgf file, it opens the TextEdit by default.

Do i need to make any changes in the code ( which i had pasted in first
thread itself ) while saving a .sgf file to recognize by my application
which has unique creator id as 'PCSL'.


Thanks in advance.

Loading...