2016-05-07 8 views
2

スクリプト可能なMacアプリでText Suiteを使用しようとしています。Cocoa Scripting:テキストスイートの統合

私がCocoa Scripting Guideで見つけた小さなドキュメントは、NSTextStorageを使用することを示しています。しかし、Sdefとコーディング面の両方で、残りの仕組みをどのように設定する必要があるのか​​は説明していません。

特に、私は、テキストスイートをより豊富なコマンドで使用するときと、そうでないときにスクリプト定義をどのように伝えるのかと思います。私が見ている問題は、Text Suiteがtextという名前の独自のタイプを宣言していることです。しかし、これは既にプレーンテキストにも使われている定義済みの型です。

私は、Sdefエディタのテキストセレクタで、要素のプロパティと、同じ型のSdefに2つの "text"を選択することになります。意味私は文字スイートをサポートするテキストを扱うプロパティとそうでないものとの間でSdefを区別することはできません。たとえ自分のコードが常にNSTextStorageを使用するとは限りません。

私はすべてのスクリプト可能なプロパティをクラスNSTextStorageのオブジェクトに格納する必要があるということですか?それ以外の場合、ユーザーは任意のテキストプロパティで拡張Text Suiteコマンドを使用することを期待できますが、NSTextStorageの代わりにNSStringを使用すると実行時エラーが発生します。

しかし、アプリケーションの名前のように単純なプレーンテキスト文字列を返すだけの単純なプロパティの場合、Text Suiteをサポートするのは難しいでしょうか?

これはどうすればいいですか?私がリッチテキストサポートの価値があると思われるプロパティについてのみNSTextStorageを使用しているため、ユーザーがText Suiteを使用できるときにはユーザーに理解させてもらいますか?どのように他の人がこれを解決するのですか

更新

が、私は単に私のSdef(私はSdefエディタがそのファイルのサブメニューの下に「NSTextSuite」として提供しています1を使用しています)にテキストSuiteを追加するときというtextを返すすべてのプロパティが判明(エラー-10000を引き起こす)動作を停止します。 Text Suiteのエントリーを他のアプリのエントリーと比較したところ、明らかな違いはありません。

テキストスイートを追加すると、「テキスト」タイプのプロパティを持つすべてのプロパティが破損するのはなぜですか?

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE dictionary SYSTEM "file://localhost/System/Library/DTDs/sdef.dtd"> 
<dictionary title="Demo Terminology"> 
    <suite name="Demo Suite" code="Demo" description="Demo suite"> 
     <class name="application" code="capp" description="The application&apos;s top-level scripting object."> 
      <cocoa class="NSApplication"/> 
      <property name="demo text" code="DeTx" description="A text prop for testing" type="text"> 
       <cocoa key="testText"/> 
      </property> 
     </class> 
    </suite> 
    <suite name="Text Suite" code="????" description="A set of basic classes for text processing."> 
     <cocoa name="NSTextSuite"/> 
     <class name="text" code="ctxt" description="Rich (styled) text" plural="text"> 
      <cocoa class="NSTextStorage"/> 
      <element type="paragraph"> 
       <cocoa key="paragraphs"/> 
      </element> 
      <element type="word"> 
       <cocoa key="words"/> 
      </element> 
      <element type="character"> 
       <cocoa key="characters"/> 
      </element> 
      <element type="attribute run"> 
       <cocoa key="attributeRuns"/> 
      </element> 
      <element type="attachment"> 
       <cocoa key="attachments"/> 
      </element> 
      <property name="color" code="colr" description="The color of the first character." type="color"> 
       <cocoa key="foregroundColor"/> 
      </property> 
      <property name="font" code="font" description="The name of the font of the first character." type="text"> 
       <cocoa key="fontName"/> 
      </property> 
      <property name="size" code="ptsz" description="The size in points of the first character." type="number"> 
       <cocoa key="fontSize"/> 
      </property> 
     </class> 
     <class name="attachment" code="atts" description="Represents an inline text attachment. This class is used mainly for make commands." inherits="text"> 
      <cocoa class="NSAttachmentTextStorage"/> 
      <!-- This property should be deprecated like all the other path-centric properties, and replaced with a type="file" property. --> 
      <property name="file name" code="atfn" description="The path to the file for the attachment" type="text"> 
       <cocoa key="filename"/> 
      </property> 
     </class> 
     <class name="paragraph" code="cpar" description="This subdivides the text into paragraphs." inherits="text"> 
      <cocoa class="NSTextStorage"/> 
     </class> 
     <class name="word" code="cwor" description="This subdivides the text into words." inherits="text"> 
      <cocoa class="NSTextStorage"/> 
     </class> 
     <class name="character" code="cha " description="This subdivides the text into characters." inherits="text"> 
      <cocoa class="NSTextStorage"/> 
     </class> 
     <class name="attribute run" code="catr" description="This subdivides the text into chunks that all have the same attributes." inherits="text"> 
      <cocoa class="NSTextStorage"/> 
     </class> 
    </suite> 
    <suite name="Standard Suite" code="????" description="Common classes and commands for most applications."> 
     <cocoa name="NSCoreSuite"/> 
     <class name="color" code="colr" description="A color."> 
      <cocoa class="NSColor"/> 
     </class> 
    </suite> 
</dictionary> 

エラー-10000になります。このスクリプトを実行する:あなたは私がやっているものを見ることができるように、次は何

は省略Sdefです

tell application "Demo" 
    demo text 
end tell 

私は「削除した場合Text Suite "をSdefから削除すると、コードはエラーなく実行されます。

答えて

2

Sdef Editorが提供するText Suiteのように見えますが、Cocoa Scriptingフレームワークを使用するアプリケーションでは使用できません。 "TextEdit.app"が使用するテクニックにも適応できません。テキストクラスには、Text Suiteのテキストクラスを使用するプロパティタイプで使用されるid( "text.ctxt")が割り当てられます。

代わりに、 "スケッチ"サンプルコードのものを使用する必要があります。それはタイプを "テキスト"から "リッチテキスト"に改名することで、私が質問したタイプの名前の競合の問題を解決します。

「古典的な」アプリケーションでは、プレーンテキストとリッチテキストの両方のプロパティに「テキスト」タイプが使用されていますが、これは新しいCocoa Scriptingフレームワークに依存する最新のアプリケーションでは不可能です。

1

私はラインで発生したSDEFにエラーがあると信じて:

<cocoa name="NSTextSuite" /> 

タグがあなたのコード内のクラスや変数を参照するために使用されます。フレームワーク、afaikにNSTextSuiteという名前のクラスはありません。テキストスイートの定義は、次のようになります。

<suite name="Text Suite" code="????" description="..."> 
    <class name="rich text" plural="rich text" code="ctxt" description="Rich (styled) text." inherits="item" hidden="yes" > 
     <cocoa class="NSTextStorage"/> 
     <type type="text"/> 
     ... 
+0

右。あなたが提案するのは、現代のSketchアプリケーションサンプルが使用するものと、私が動作することがわかったものです。 Sdefエディタが提供するSdefは、私の質問で見られるもので、明らかに悪い選択です。 –

+0

Thomas、コードラインの1つが正しく字下げされていないとわかったので、私は自分の答えを修正しました。私は今までSdef Editiorを使っていませんでした。私は単純な古いテキストXMLエディタを使い、DTDを使ってXMLを検証します。 –