Skip to content

Commit

Permalink
Add --readonly option to cot command (close #1099)a
Browse files Browse the repository at this point in the history
  • Loading branch information
1024jp committed Jan 19, 2025
1 parent adf126d commit dc70b3f
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

- 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 `--readonly` (`-r`) option to the `cot` command-line tool to open documents as read-only.
- Introduce the new AppleScript parameter `editable` to document objects.


Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ <h2>Use with options</h2>
</thead>
<tbody>
<tr><th><code>-w</code>, <code>--wait</code></th><td>Wait for opened file to be closed before returning to a prompt.</td></tr>
<tr><th><code>-r</code>, <code>--readonly</code></th><td>Open documents as <a href="howto_readonly.html">read-only</a>.</td></tr>
<tr><th><code>-n</code>, <code>--new</code></th><td>Create a new blank document.</td></tr>
<tr><th><code>-s</code>, <code>--syntax</code></th><td>Set specific syntax to opened document.</td></tr>
<tr><th><code>-l</code>, <code>--line</code> <code>&lt;line&gt;</code></th><td>Jump to specific line in opened document. <code>&lt;line&gt;</code> is an integer specifying the number of line.</td></tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</head>

<body>
<a name="howto_readonly"></a>

<h1>Make read-only documents in CotEditor on Mac</h1>

Expand All @@ -25,11 +26,14 @@ <h2>Preventing from being edited</h2>

<ul>
<li>To prevent a document from being edited, do one of the following:<ul>
<li>choose Format &gt; Prevent Editing.</li>
<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>
<li>To open a document as read-only, do one of the following:<ul>
<li>Choose File &gt; Open, and select the “Open as read-only” checkbox in the Open dialog.</li>
<li>From the <a href="about_cot.html">cot command-line tool</a>, open documents with the <code>--readonly</code> (<code>-r</code>) option.</li>
</ul></li>

<li>To allow editing a document being prevented from editing, choose Format &gt; Allow Editing.</li>
</ul>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ <h2>オプションとともに使う</h2>
</thead>
<tbody>
<tr><th><code>-w</code>, <code>--wait</code></th><td>開いたファイルが閉じるまでコマンドの終了を待ちます。</td></tr>
<tr><th><code>-r</code>, <code>--readonly</code></th><td>書類を<a href="howto_readonly.html">読み出し専用</a>として開きます。</td></tr>
<tr><th><code>-n</code>, <code>--new</code></th><td>空の新規書類を開きます。</td></tr>
<tr><th><code>-s</code>, <code>--syntax</code></th><td>開いた書類に任意のシンタックスをセットします。</td></tr>
<tr><th><code>-l</code>, <code>--line</code> <code>&lt;line&gt;</code></th><td>開いた書類の指定した行に移動します。<code>&lt;line&gt;</code>は行を指定する整数型です。</td></tr>
Expand All @@ -62,7 +63,7 @@ <h2>オプションとともに使う</h2>
</tbody>
</table>

<p><code>--line</code>オプションと<code>--column</code>は負の値を指定することもできます。そのとき、<code>--line</code>オプションの場合は書類の末尾から、<code>--column</code>オプションの場合は行の末尾からカウントがされます</p>
<p><code>--line</code>オプションと<code>--column</code>は負の値を指定することもできます。そのとき、<code>--line</code>オプションの場合は書類の末尾から、<code>--column</code>オプションの場合は行の末尾からカウントされます</p>

<h2></h2>
<p><code>cot</code>コマンド単体でCotEditorが起動します。</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</head>

<body>
<a name="howto_readonly"></a>

<h1>MacのCotEditorで読み出し専用の書類にする</h1>

Expand All @@ -29,7 +30,10 @@ <h2>編集不可にする</h2>
<li>AppleScriptで<code>document</code>オブジェクトの<code>editable</code>プロパティを<code>false</code>にします。</li>
</ul></li>

<li>書類を読み出し専用で開くには、「ファイル」 > 「開く」を選択し、「開く」ダイアログの「読み出し専用で開く」チェックボックスを有効にする。</li>
<li>書類を読み出し専用で開くには、以下のいずれかの操作を行います:<ul>
<li>「ファイル」 > 「開く」を選択し、「開く」ダイアログの「読み出し専用で開く」チェックボックスを有効にする。</li>
<li><a href="about_cot.html">cotコマンドラインツール</a><code>--readonly</code> (<code>-r</code>)オプションを付けて書類を開きます。</li>
</ul></li>

<li>編集不可の書類をふたたび編集可能にするには、「フォーマット」>「編集可能にする」と選択します。</li>
</ul>
Expand Down
22 changes: 16 additions & 6 deletions CotEditor/Resources/cot
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Created by 1024jp on 2015-08-12.
------------------------------------------------------------------------------
© 2015-2024 1024jp
© 2015-2025 1024jp
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -34,7 +34,7 @@ from subprocess import Popen, PIPE, CalledProcessError


# meta data
__version__ = '2.10.1'
__version__ = '5.1.0'
__description__ = 'command-line utility for CotEditor.'


Expand Down Expand Up @@ -262,6 +262,11 @@ def parse_args():
default=False,
help="do not bring the application to the foreground"
)
parser.add_argument('-r', '--readonly',
action='store_true',
default=False,
help="open the document as read-only"
)
parser.add_argument('-n', '--new',
action='store_true',
default=False,
Expand Down Expand Up @@ -358,15 +363,20 @@ def main(args, stdin):
# launch
app.launch(background=args.background)

if app.tell('number of documents') == '0':
return

# set read-only
if args.readonly:
for index in range(document_count):
app.tell_document('set editable to false', index + 1)

# set syntax
if args.syntax is not None and document_count > 0:
if args.syntax is not None:
for index in range(document_count):
app.tell_document('set coloring style to "{}"'.format(args.syntax),
index + 1)

if app.tell('number of documents') == '0':
return

# jump to location
if args.line is not None or args.column is not None:
app.tell_document('jump to line {} column {}'.format(
Expand Down

0 comments on commit dc70b3f

Please sign in to comment.