Skip to content

Commit

Permalink
removed capability to convert by clicking on tif image. because not s…
Browse files Browse the repository at this point in the history
…table
  • Loading branch information
ullmannJan committed Mar 6, 2024
1 parent 3da737b commit 55db384
Showing 1 changed file with 36 additions and 32 deletions.
68 changes: 36 additions & 32 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,38 +157,42 @@ export default class TiffViewerPlugin extends Plugin {
}
})
);

// Context Menu
// Add event listener for contextmenu event on image elements
this.registerDomEvent(document, 'contextmenu', (event) => {
const embedElement = (event.target as HTMLElement).closest('.internal-embed');
if (embedElement) {
const filePath = embedElement.getAttribute('src');
if (filePath && (filePath.endsWith('.tif') || filePath.endsWith('.tiff'))) {
event.preventDefault();
new Menu()
.addItem((item) => item.setTitle('Convert to PNG')
.setIcon('cog')
.onClick(async () => {

// convert image to png
await convertTiffToPng(filePath, this.app, true);
//get editor
const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
if (activeView) {
const editor = activeView.editor;
// replace the link with the new png
// TODO get line number of clicked element and insert beneath
await replaceTiffLink(editor, filePath, null);
}


}))
.showAtPosition({ x: event.pageX, y: event.pageY });
}
}
});


// I dont like this yet
// // add context menu to convert tiff to png by clicking on the file

// this.registerDomEvent(document, 'contextmenu', (event) => {
// const embedElement = (event.target as HTMLElement).closest('.internal-embed');
// if (embedElement && embedElement.classList.contains('mod-generic')
// && embedElement.classList.contains('file-embed')
// && embedElement.classList.contains('internal-embed')
// && embedElement.classList.contains('is-loaded')) {

// const filePath = embedElement.getAttribute('src');
// if (filePath && (filePath.endsWith('.tif') || filePath.endsWith('.tiff'))) {
// event.preventDefault();
// new Menu()
// .addItem((item) => item.setTitle('Convert to PNG')
// .setIcon('cog')
// .onClick(async () => {

// // convert image to png
// await convertTiffToPng(filePath, this.app, true);
// //get editor
// const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
// if (activeView) {
// const editor = activeView.editor;
// // replace the link with the new png
// // TODO get line number of clicked element and insert beneath
// await replaceTiffLink(editor, filePath, null);
// }


// }))
// .showAtPosition({ x: event.pageX, y: event.pageY });
// }
// }
// });

}

Expand Down

0 comments on commit 55db384

Please sign in to comment.