Skip to content

Commit

Permalink
Add editable property to document in OSAScript (#1099)
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Jan 19, 2025
1 parent c1a3ebe commit adf126d
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

### New Features

- The new “prevent editing” option that prevents documents from being unintentionally edited.
- Append the nearest unique ancestor folder name to the document title if multiple documents with the same name are opened.
- The new “prevent editing” option that prevents documents from being unintentionally edited.
- Introduce the new AppleScript parameter `editable` to document objects.


### TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ <h2>Preventing from being edited</h2>
<p>CotEditor can temporarily prevent a document from being edited to avoid unintended data modifications while reading. This state is only valid while the document is open in CotEditor and is not saved to the file.</p>

<ul>
<li>To prevent a document from being edited, choose Format &gt; Prevent Editing.</li>
<li>To prevent a document from being edited, do one of the following:<ul>
<li>choose Format &gt; Prevent Editing.</li>
<li>From an AppleScript, set the <code>editable</code> property of the <code>document</code> object to <code>false</code>.</li>
</ul></li>

<li>To open a document as read-only, choose File &gt; Open, and select the “Open as read-only” checkbox in the Open dialog.</li>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ <h3>Document</h3>
<dt><code>text</code></dt>
<dd>The contents of the document. (text)</dd>

<dt><code>editable</code></dt>
<dd>Is the document editable? (boolean) <span class="added">new on CotEditor 5.1</span></dd>

<dt><del><code>length</code></del></dt>
<dd><del>The number of characters of the document in UTF-16. (int)</del> <span class="deprecated">deprecated on CotEditor 4.4</span></dd>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ <h1>Support different CotEditor versions in AppleScript</h1>
<p>This page lists the previous specific changes on AppleScript support in CotEditor.</p>


<article>
<h2>Terminology change on CotEditor 5.1.0</h2>

<section>
<h3>Cotrol the editability of documents</h3>
<p>A new property <code>editable</code> was added to the ‘document’ object.</p>
</section>
</article>


<article>
<h2>Terminology change on CotEditor 5.0.7</h2>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ <h2>編集不可にする</h2>
<p>意図しないデータの変更を避けるために、CotEditorは書類を一時的に編集できないようにすることができます。状態はCotEditorで書類を開いている間のみ有効であり、ファイルには保存されません。</p>

<ul>
<li>書類を編集不可にするには、「フォーマット」>「編集不可にする」と選択します。</li>
<li>書類を編集不可にするには、以下のいずれかの操作を行います:<ul>
<li>「フォーマット」>「編集不可にする」と選択します。</li>
<li>AppleScriptで<code>document</code>オブジェクトの<code>editable</code>プロパティを<code>false</code>にします。</li>
</ul></li>

<li>書類を読み出し専用で開くには、「ファイル」 > 「開く」を選択し、「開く」ダイアログの「読み出し専用で開く」チェックボックスを有効にする。</li>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ <h3>Document</h3>
<dt><code>text</code></dt>
<dd>書類の内容文字列(text型)</dd>

<dt><code>editable</code></dt>
<dd>書類が編集可能かどうか(boolean型)<span class="added">CotEditor 5.1で追加</span></dd>

<dt><del><code>length</code></del></dt>
<dd><del>書類のUTF-16単位の字数(int型)</del><span class="deprecated">CotEditor 4.4で廃止</span></dd>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ <h1>AppleScriptで異なるバージョンのCotEditorに対応する</h1>
<p>このページでは、CotEditorのAppleScript対応における今までの仕様改訂を列挙しています。</p>


<article>
<h2>CotEditor 5.1.0での仕様改訂</h2>

<section>
<h3>書類が編集可能かどうかの操作</h3>
<p>documentオブジェクトに新しく<code>editable</code>プロパティが追加されました。</p>
</section>
</article>


<article>
<h2>CotEditor 5.0.7での仕様改訂</h2>

Expand Down
3 changes: 3 additions & 0 deletions CotEditor/Resources/CotEditor.sdef
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
<contents name="text" code="ctxt" type="attribute run" access="rw" description="The whole text of the document.">
<cocoa key="scriptTextStorage"/>
</contents>
<property name="editable" code="iEdt" type="boolean" access="rw" description="Is the document editable?">
<cocoa key="isEditable"/>
</property>
<property name="coloring style" code="cclr" type="text" access="rw" description="The current syntax name.">
<cocoa key="coloringStyle"/>
</property>
Expand Down
2 changes: 1 addition & 1 deletion CotEditor/Sources/Document/Document.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extension Document: EditorSource {

// MARK: Public Properties

@ObservationIgnored @Published private(set) var isEditable = true { didSet { self.invalidateRestorableState() } }
@ObservationIgnored @Published @objc var isEditable = true { didSet { self.invalidateRestorableState() } }
var isTransient = false // untitled & empty document that was created automatically
nonisolated(unsafe) var isVerticalText = false

Expand Down

0 comments on commit adf126d

Please sign in to comment.