mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
added "edit" button into ribbon button container
This commit is contained in:
parent
2220c4491b
commit
02da5b598c
@ -39,6 +39,7 @@ import LinkMapWidget from "../widgets/ribbon_widgets/link_map.js";
|
|||||||
import NotePathsWidget from "../widgets/ribbon_widgets/note_paths.js";
|
import NotePathsWidget from "../widgets/ribbon_widgets/note_paths.js";
|
||||||
import SimilarNotesWidget from "../widgets/ribbon_widgets/similar_notes.js";
|
import SimilarNotesWidget from "../widgets/ribbon_widgets/similar_notes.js";
|
||||||
import RightPaneContainer from "../widgets/containers/right_pane_container.js";
|
import RightPaneContainer from "../widgets/containers/right_pane_container.js";
|
||||||
|
import EditButton from "../widgets/buttons/edit_button.js";
|
||||||
|
|
||||||
export default class DesktopLayout {
|
export default class DesktopLayout {
|
||||||
constructor(customWidgets) {
|
constructor(customWidgets) {
|
||||||
@ -128,6 +129,7 @@ export default class DesktopLayout {
|
|||||||
.ribbon(new LinkMapWidget())
|
.ribbon(new LinkMapWidget())
|
||||||
.ribbon(new SimilarNotesWidget())
|
.ribbon(new SimilarNotesWidget())
|
||||||
.ribbon(new NoteInfoWidget())
|
.ribbon(new NoteInfoWidget())
|
||||||
|
.button(new EditButton())
|
||||||
.button(new ButtonWidget()
|
.button(new ButtonWidget()
|
||||||
.icon('bx bx-history')
|
.icon('bx bx-history')
|
||||||
.title("Note Revisions")
|
.title("Note Revisions")
|
||||||
|
@ -40,8 +40,8 @@ class NoteContext extends Component {
|
|||||||
this.notePath = resolvedNotePath;
|
this.notePath = resolvedNotePath;
|
||||||
this.noteId = treeService.getNoteIdFromNotePath(resolvedNotePath);
|
this.noteId = treeService.getNoteIdFromNotePath(resolvedNotePath);
|
||||||
|
|
||||||
this.textPreviewDisabled = false;
|
this.readOnlyTemporarilyDisabled = false;
|
||||||
this.codePreviewDisabled = false;
|
this.readOnlyTemporarilyDisabled = false;
|
||||||
|
|
||||||
this.saveToRecentNotes(resolvedNotePath);
|
this.saveToRecentNotes(resolvedNotePath);
|
||||||
|
|
||||||
@ -177,6 +177,28 @@ class NoteContext extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async isReadOnly() {
|
||||||
|
if (this.readOnlyTemporarilyDisabled) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.note.type !== 'text' && this.note.type !== 'code') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.note.hasLabel('readOnly')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const noteComplement = await this.getNoteComplement();
|
||||||
|
|
||||||
|
const SIZE_LIMIT = this.note.type === 'text' ? 10000 : 30000;
|
||||||
|
|
||||||
|
return noteComplement.content
|
||||||
|
&& noteComplement.content.length > SIZE_LIMIT
|
||||||
|
&& !this.note.hasLabel('autoReadOnlyDisabled');
|
||||||
|
}
|
||||||
|
|
||||||
async entitiesReloadedEvent({loadResults}) {
|
async entitiesReloadedEvent({loadResults}) {
|
||||||
if (loadResults.isNoteReloaded(this.noteId)) {
|
if (loadResults.isNoteReloaded(this.noteId)) {
|
||||||
const note = await froca.getNote(this.noteId);
|
const note = await froca.getNote(this.noteId);
|
||||||
|
31
src/public/app/widgets/buttons/edit_button.js
Normal file
31
src/public/app/widgets/buttons/edit_button.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import ButtonWidget from "./button_widget.js";
|
||||||
|
|
||||||
|
export default class EditButton extends ButtonWidget {
|
||||||
|
isEnabled() {
|
||||||
|
return super.isEnabled() && this.noteContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.icon("bx-edit-alt")
|
||||||
|
.title("Edit this note")
|
||||||
|
.titlePlacement("bottom")
|
||||||
|
.onClick(widget => {
|
||||||
|
this.noteContext.readOnlyTemporarilyDisabled = true;
|
||||||
|
|
||||||
|
this.triggerEvent('readOnlyTemporarilyDisabled', {noteContext: this.noteContext});
|
||||||
|
|
||||||
|
this.refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async refreshWithNote(note) {
|
||||||
|
// can't do this in isEnabled() since isReadOnly is async
|
||||||
|
this.toggleInt(await this.noteContext.isReadOnly());
|
||||||
|
|
||||||
|
console.log("await this.noteContext.isReadOnly()", await this.noteContext.isReadOnly());
|
||||||
|
|
||||||
|
await super.refreshWithNote(note);
|
||||||
|
}
|
||||||
|
}
|
@ -150,26 +150,12 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
|
|||||||
|
|
||||||
let type = note.type;
|
let type = note.type;
|
||||||
|
|
||||||
if (type === 'text' && !this.noteContext.textPreviewDisabled) {
|
if (type === 'text' && await this.noteContext.isReadOnly()) {
|
||||||
const noteComplement = await this.noteContext.getNoteComplement();
|
type = 'read-only-text';
|
||||||
|
|
||||||
if (note.hasLabel('readOnly') ||
|
|
||||||
(noteComplement.content
|
|
||||||
&& noteComplement.content.length > 10000)
|
|
||||||
&& !note.hasLabel('autoReadOnlyDisabled')) {
|
|
||||||
type = 'read-only-text';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'code' && !this.noteContext.codePreviewDisabled) {
|
if (type === 'code' && await this.noteContext.isReadOnly()) {
|
||||||
const noteComplement = await this.noteContext.getNoteComplement();
|
type = 'read-only-code';
|
||||||
|
|
||||||
if (note.hasLabel('readOnly') ||
|
|
||||||
(noteComplement.content
|
|
||||||
&& noteComplement.content.length > 30000)
|
|
||||||
&& !note.hasLabel('autoReadOnlyDisabled')) {
|
|
||||||
type = 'read-only-code';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'text') {
|
if (type === 'text') {
|
||||||
@ -279,13 +265,13 @@ export default class NoteDetailWidget extends NoteContextAwareWidget {
|
|||||||
return this.spacedUpdate.isAllSavedAndTriggerUpdate();
|
return this.spacedUpdate.isAllSavedAndTriggerUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
textPreviewDisabledEvent({noteContext}) {
|
readOnlyTemporarilyDisabledEvent({noteContext}) {
|
||||||
if (this.isNoteContext(noteContext.ntxId)) {
|
if (this.isNoteContext(noteContext.ntxId)) {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
codePreviewDisabledEvent({noteContext}) {
|
readOnlyTemporarilyDisabledEvent({noteContext}) {
|
||||||
if (this.isNoteContext(noteContext.ntxId)) {
|
if (this.isNoteContext(noteContext.ntxId)) {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,6 @@ const TPL = `
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="alert alert-warning no-print edit-code-note-button bx bx-edit-alt"
|
|
||||||
title="Edit this note"></div>
|
|
||||||
|
|
||||||
<pre class="note-detail-read-only-code-content"></pre>
|
<pre class="note-detail-read-only-code-content"></pre>
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
@ -33,12 +30,6 @@ export default class ReadOnlyCodeTypeWidget extends TypeWidget {
|
|||||||
doRender() {
|
doRender() {
|
||||||
this.$widget = $(TPL);
|
this.$widget = $(TPL);
|
||||||
this.$content = this.$widget.find('.note-detail-read-only-code-content');
|
this.$content = this.$widget.find('.note-detail-read-only-code-content');
|
||||||
|
|
||||||
this.$widget.find('.edit-code-note-button').on('click', () => {
|
|
||||||
this.noteContext.codePreviewDisabled = true;
|
|
||||||
|
|
||||||
this.triggerEvent('codePreviewDisabled', {noteContext: this.noteContext});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async doRefresh(note) {
|
async doRefresh(note) {
|
||||||
|
@ -24,7 +24,6 @@ const TPL = `
|
|||||||
padding-left: 24px;
|
padding-left: 24px;
|
||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
font-family: var(--detail-text-font-family);
|
font-family: var(--detail-text-font-family);
|
||||||
position: relative;
|
|
||||||
min-height: 50px;
|
min-height: 50px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,9 +52,6 @@ const TPL = `
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div class="no-print edit-text-note-button bx bx-edit-alt"
|
|
||||||
title="Edit this note"></div>
|
|
||||||
|
|
||||||
<div class="note-detail-readonly-text-content ck-content"></div>
|
<div class="note-detail-readonly-text-content ck-content"></div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@ -68,12 +64,6 @@ export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget {
|
|||||||
|
|
||||||
this.$content = this.$widget.find('.note-detail-readonly-text-content');
|
this.$content = this.$widget.find('.note-detail-readonly-text-content');
|
||||||
|
|
||||||
this.$widget.find('.edit-text-note-button').on('click', () => {
|
|
||||||
this.noteContext.textPreviewDisabled = true;
|
|
||||||
|
|
||||||
this.triggerEvent('textPreviewDisabled', {noteContext: this.noteContext});
|
|
||||||
});
|
|
||||||
|
|
||||||
this.setupImageOpening(true);
|
this.setupImageOpening(true);
|
||||||
|
|
||||||
super.doRender();
|
super.doRender();
|
||||||
|
@ -41,13 +41,13 @@ export default class TypeWidget extends NoteContextAwareWidget {
|
|||||||
|
|
||||||
focus() {}
|
focus() {}
|
||||||
|
|
||||||
textPreviewDisabledEvent({noteContext}) {
|
readOnlyTemporarilyDisabledEvent({noteContext}) {
|
||||||
if (this.isNoteContext(noteContext.ntxId)) {
|
if (this.isNoteContext(noteContext.ntxId)) {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
codePreviewDisabledEvent({noteContext}) {
|
readOnlyTemporarilyDisabledEvent({noteContext}) {
|
||||||
if (this.isNoteContext(noteContext.ntxId)) {
|
if (this.isNoteContext(noteContext.ntxId)) {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user