Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for readonly note #206

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Evernote.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@
"show_stacks": true,
"open_single_result": true,
"tab_prefix": "Evernote: ",
"warn_on_close": true
"warn_on_close": true,
"readonly_content_class": "evernote.sublime.readonly"
}
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ If you like this plugin and would like to support its development please conside
* **Send a note to Evernote:** converts the markdown document in the current view into rich text and sends it to your Evernote. You will be able to choose a title, tags and the notebook where to store it.
* **Open a note from Evernote**: shows panels to choose a note from a notebook or by searching, converts the note to markdown and presents it in a view.
* **Update note**: when editing the markdown of an opened note you can save it back to Evernote (again in rich text). You can also delete a note directly from ST.
* **Full two-way metadata support**: you can set and change the note's title, notebook and tag just by providing a YAML metadata header in your markdown source.
* **Full two-way metadata support**: you can set and change the note's title, notebook, tags and readonly attribute just by providing a YAML metadata header in your markdown source.
* **Attachments**: can insert, list, delete and open attachments.
* **Clip to note**: saves the current selection as code snippets to a new note.

Expand Down Expand Up @@ -77,9 +77,9 @@ If you need to reconfigure the plugin go to `Preferences > Package Settings > Ev


> **PLEASE NOTE**
>
>
> The authentication method makes use of the Developer Token which is unique to your account and grants read-write access to your Evernote.
> This token will be saved in your user settings in the `Evernote.sublime-settings` file so make sure you do not share this publicly!
> This token will be saved in your user settings in the `Evernote.sublime-settings` file so make sure you do not share this publicly!


## Commands
Expand All @@ -100,7 +100,7 @@ you can also overwrite the standard "save" bindings for Evernote notes as follow
{ "keys": ["ctrl+s"], "command": "send_to_evernote", "context": [{"key": "evernote_note"}, {"key": "evernote_has_guid", "operator": "equal", "operand": false}] },
```

you would still be able to save the note as a file by using the `File > Save` menu.
you would still be able to save the note as a file by using the `File > Save` menu.

You can also restrict your bindings to views showing Evernote notes by adding

Expand Down Expand Up @@ -213,7 +213,8 @@ A markdown source can start with a metadata block like the following:
---
title: My Note's Title
tags: misc, sublime
notebook: My Notebook
notebook: My Notebook
readonly: True/False
---
```

Expand All @@ -223,7 +224,7 @@ The `tags` field can be an unquoted list or a json list such as `["my long tag",

If the `evernote_autocomplete` is true, the list of notebooks and tags will be offered as autocompletion in the metadata block.

**PLEASE NOTE**: the format for the metadata is currently rather restricted and it is just a small subset of YAML. The only recognised keys are `title`, `tags` and `notebook`, the others will be ignored and can be discarded (for example if you edit the note from other clients).
**PLEASE NOTE**: the format for the metadata is currently rather restricted and it is just a small subset of YAML. The only recognised keys are `title`, `tags`, `notebook` and `readonly`, the others will be ignored and can be discarded (for example if you edit the note from other clients).

# Equations

Expand Down Expand Up @@ -259,6 +260,7 @@ Setting | Purpose
`tab_prefix` | a string used as a prefix in tabs for notes (default `"Evernote: "`)
`wiki_tables` | enable Wiki table syntax (default `false`)
`debug` | enables logging in the console
`readonly_content_class` | custom the `note.attributes.contentClass` to make the note be readonly, the default value is `evernote.sublime.readonly`


# Acknowledgements
Expand Down Expand Up @@ -294,7 +296,7 @@ The plugin has been made possible by the contribution of several people:

If you think your name should be here, let us know!

Also thanks to our first donor, Matthew Baltrusitis!
Also thanks to our first donor, Matthew Baltrusitis!

Libraries (some adapted to work with Evernote formats):

Expand Down
17 changes: 13 additions & 4 deletions sublime_evernote.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ def extract_metadata(text):
title: %s
tags: %s
notebook: %s
readonly: %s
---

"""


def metadata_header(title="", tags=[], notebook="", **kw):
return METADATA_HEADER % (title, json.dumps(tags, ensure_ascii=False), notebook)
def metadata_header(title="", tags=[], notebook="", readonly=False, **kw):
return METADATA_HEADER % (title, json.dumps(tags, ensure_ascii=False), notebook, readonly)

def set_view_metadata(view, note, reset_modified=True):
view.settings().set("$evernote", True)
Expand Down Expand Up @@ -528,6 +529,12 @@ def populate_note(self, note, contents):
LOG(tags)
note.tagNames = tags
note.content = content
attributes = Types.NoteAttributes()
if meta.get("readonly") == 'True':
attributes.contentClass = self.settings.get('readonly_content_class') or 'evernote.sublimetext.readonly'
else:
attributes.contentClass = None
note.attributes = attributes
if "notebook" in meta:
notebooks = self.get_notebooks()
for nb in notebooks:
Expand Down Expand Up @@ -887,7 +894,7 @@ def do_open_note(self, guid, convert=True, **unk_args):
# tags = [noteStore.getTag(self.token(), guid).name for guid in (note.tagGuids or [])]
# tags = [self.tag_from_guid(guid) for guid in (note.tagGuids or [])]
tags = noteStore.getNoteTagNames(self.token(), note.guid)
meta = metadata_header(note.title, tags, nb_name)
meta = metadata_header(note.title, tags, nb_name, note.attributes.contentClass is not None)
body_start = note.content.find('<en-note')
if body_start < 0:
body_start = 0
Expand All @@ -904,7 +911,8 @@ def do_open_note(self, guid, convert=True, **unk_args):
if parts["metadata"].get("title") == note.title and \
"tags" in parts["metadata"] and \
set(parts["metadata"].get("tags")) == set(tags) and \
parts["metadata"].get("notebook") == nb_name:
parts["metadata"].get("notebook") == nb_name and \
parts["metadata"].get("readonly") is not None:
meta = ""
else:
LOG("Overridding metadata")
Expand Down Expand Up @@ -1336,6 +1344,7 @@ def is_enabled(self, **kw):
title: $3
notebook: $1
tags:$2
readonly: False
---

$0
Expand Down