mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-01 13:14:16 +08:00
216 lines
8.3 KiB
HTML
216 lines
8.3 KiB
HTML
---
|
|
layout: docs
|
|
title: FocusedContentStore
|
|
edit_url: "https://github.com/nylas/N1/blob/master/src/flux/stores/focused-content-store.coffee"
|
|
---
|
|
|
|
<h2>Summary</h2>
|
|
|
|
<div class="markdown-from-sourecode">
|
|
<p><p>The FocusedContentStore provides access to the objects currently selected
|
|
or otherwise focused in the window. Normally, focus would be maintained internally
|
|
by components that show models. The FocusedContentStore makes the concept of
|
|
selection public so that you can observe focus changes and trigger your own changes
|
|
to focus.</p>
|
|
<p>Since <a href='focusedcontentstore.html'>FocusedContentStore</a> is a Flux-compatible Store, you do not call setters
|
|
on it directly. Instead, use <a href='Actions.html#setFocus'>Actions::setFocus</a> or
|
|
<a href='Actions.html#setCursorPosition'>Actions::setCursorPosition</a> to set focus. The FocusedContentStore observes
|
|
these models, changes it's state, and broadcasts to it's observers.</p>
|
|
<p>Note: The <a href='focusedcontentstore.html'>FocusedContentStore</a> triggers when a focused model is changed, even if
|
|
it's ID has not. For example, if the user has a <a href='thread.html'>Thread</a> selected and removes a tag,
|
|
<a href='focusedcontentstore.html'>FocusedContentStore</a> will trigger so you can fetch the new version of the
|
|
<a href='thread.html'>Thread</a>. If you observe the <a href='focusedcontentstore.html'>FocusedContentStore</a> properly, you should always
|
|
have the latest version of the the selected object.</p>
|
|
<p><strong>Standard Collections</strong>:</p>
|
|
<ul>
|
|
<li>thread</li>
|
|
<li>file</li>
|
|
</ul>
|
|
<p><strong>Example: Observing the Selected Thread</strong></p>
|
|
<pre><code class="lang-coffeescript"><span class="hljs-variable">@unsubscribe</span> = FocusedContentStore.<span class="hljs-function">listen</span>(<span class="hljs-variable">@_onFocusChanged</span>, @)
|
|
|
|
...
|
|
|
|
# Called when focus has changed, or when the focused model has been modified.
|
|
<span class="hljs-attribute">_onFocusChanged</span>: ->
|
|
thread = FocusedContentStore.<span class="hljs-function">focused</span>(<span class="hljs-string">'thread'</span>)
|
|
if thread
|
|
console.<span class="hljs-function">log</span>(<span class="hljs-string">"#{thread.subject} is selected!"</span>)
|
|
else
|
|
console.<span class="hljs-function">log</span>(<span class="hljs-string">"No thread is selected!"</span>)
|
|
</code></pre>
|
|
</p>
|
|
</div>
|
|
|
|
<ul>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
<h3>Instance Methods</h3>
|
|
|
|
<h4 id=focused class="function-name">
|
|
focused(<span class="args"><span class="arg">collection</span></span>) <a href="#focused" class="link"></a>
|
|
</h4>
|
|
|
|
<div class="function-description markdown-from-sourecode">
|
|
<p></p>
|
|
</div>
|
|
|
|
<strong>Parameters</strong>
|
|
<table class="arguments">
|
|
<tr>
|
|
<th>Argument</th>
|
|
<th>Description</th>
|
|
</tr>
|
|
<tr>
|
|
<td style="width:15%;">
|
|
<em>collection</em>
|
|
</td>
|
|
<td class="markdown-from-sourecode">
|
|
|
|
<p>The <a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string'>String</a> name of a collection. Standard collections are listed above.</p>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<strong>Returns</strong>
|
|
<table class="arguments">
|
|
<tr>
|
|
<th>Return Values</th>
|
|
</tr>
|
|
<tr><td class="markdown-from-sourecode"><p>Returns the focused <a href='model.html'>Model</a> in the collection specified,
|
|
or undefined if no item is focused.</p>
|
|
</td></tr>
|
|
</table>
|
|
<h4 id=focusedId class="function-name">
|
|
focusedId(<span class="args"><span class="arg">collection</span></span>) <a href="#focusedId" class="link"></a>
|
|
</h4>
|
|
|
|
<div class="function-description markdown-from-sourecode">
|
|
<p></p>
|
|
</div>
|
|
|
|
<strong>Parameters</strong>
|
|
<table class="arguments">
|
|
<tr>
|
|
<th>Argument</th>
|
|
<th>Description</th>
|
|
</tr>
|
|
<tr>
|
|
<td style="width:15%;">
|
|
<em>collection</em>
|
|
</td>
|
|
<td class="markdown-from-sourecode">
|
|
|
|
<p>The <a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string'>String</a> name of a collection. Standard collections are listed above.</p>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<strong>Returns</strong>
|
|
<table class="arguments">
|
|
<tr>
|
|
<th>Return Values</th>
|
|
</tr>
|
|
<tr><td class="markdown-from-sourecode"><p>Returns the ID of the focused <a href='model.html'>Model</a> in the collection specified,
|
|
or undefined if no item is focused.</p>
|
|
</td></tr>
|
|
</table>
|
|
<h4 id=keyboardCursor class="function-name">
|
|
keyboardCursor(<span class="args"><span class="arg">collection</span></span>) <a href="#keyboardCursor" class="link"></a>
|
|
</h4>
|
|
|
|
<div class="function-description markdown-from-sourecode">
|
|
<p></p>
|
|
</div>
|
|
|
|
<strong>Parameters</strong>
|
|
<table class="arguments">
|
|
<tr>
|
|
<th>Argument</th>
|
|
<th>Description</th>
|
|
</tr>
|
|
<tr>
|
|
<td style="width:15%;">
|
|
<em>collection</em>
|
|
</td>
|
|
<td class="markdown-from-sourecode">
|
|
|
|
<p>The <a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string'>String</a> name of a collection. Standard collections are listed above.</p>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<strong>Returns</strong>
|
|
<table class="arguments">
|
|
<tr>
|
|
<th>Return Values</th>
|
|
</tr>
|
|
<tr><td class="markdown-from-sourecode"><p>Returns the <a href='model.html'>Model</a> the keyboard is currently focused on
|
|
in the collection specified. Keyboard focus is not always separate from
|
|
primary focus (selection). You can use <a href='#keyboardCursorEnabled'>keyboardCursorEnabled</a> to determine
|
|
whether keyboard focus is enabled.</p>
|
|
</td></tr>
|
|
</table>
|
|
<h4 id=keyboardCursorId class="function-name">
|
|
keyboardCursorId(<span class="args"><span class="arg">collection</span></span>) <a href="#keyboardCursorId" class="link"></a>
|
|
</h4>
|
|
|
|
<div class="function-description markdown-from-sourecode">
|
|
<p></p>
|
|
</div>
|
|
|
|
<strong>Parameters</strong>
|
|
<table class="arguments">
|
|
<tr>
|
|
<th>Argument</th>
|
|
<th>Description</th>
|
|
</tr>
|
|
<tr>
|
|
<td style="width:15%;">
|
|
<em>collection</em>
|
|
</td>
|
|
<td class="markdown-from-sourecode">
|
|
|
|
<p>The <a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string'>String</a> name of a collection. Standard collections are listed above.</p>
|
|
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<strong>Returns</strong>
|
|
<table class="arguments">
|
|
<tr>
|
|
<th>Return Values</th>
|
|
</tr>
|
|
<tr><td class="markdown-from-sourecode"><p>Returns the ID of the <a href='model.html'>Model</a> the keyboard is currently focused on
|
|
in the collection specified. Keyboard focus is not always separate from
|
|
primary focus (selection). You can use <a href='#keyboardCursorEnabled'>keyboardCursorEnabled</a> to determine
|
|
whether keyboard focus is enabled.</p>
|
|
</td></tr>
|
|
</table>
|
|
<h4 id=keyboardCursorEnabled class="function-name">
|
|
keyboardCursorEnabled(<span class="args"></span>) <a href="#keyboardCursorEnabled" class="link"></a>
|
|
</h4>
|
|
|
|
<div class="function-description markdown-from-sourecode">
|
|
<p></p>
|
|
</div>
|
|
|
|
|
|
<strong>Returns</strong>
|
|
<table class="arguments">
|
|
<tr>
|
|
<th>Return Values</th>
|
|
</tr>
|
|
<tr><td class="markdown-from-sourecode"><p>Returns a <a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/boolean'>Boolean</a> - <code>true</code> if the keyboard cursor concept applies in
|
|
the current <a href='workspacestore.html'>WorkspaceStore</a> layout mode. The keyboard cursor is currently only
|
|
enabled in <code>list</code> mode.</p>
|
|
</td></tr>
|
|
</table>
|