mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 16:26:40 -04:00
Fix lint errors
This commit is contained in:
parent
13c2dd201a
commit
d585916313
4 changed files with 64 additions and 34 deletions
|
@ -33,7 +33,7 @@ from anki.cards import Card
|
||||||
from anki.collection import Config
|
from anki.collection import Config
|
||||||
from anki.hooks import runFilter
|
from anki.hooks import runFilter
|
||||||
from anki.httpclient import HttpClient
|
from anki.httpclient import HttpClient
|
||||||
from anki.models import NotetypeDict, NotetypeId, StockNotetype
|
from anki.models import NotetypeDict, StockNotetype
|
||||||
from anki.notes import Note, NoteId
|
from anki.notes import Note, NoteId
|
||||||
from anki.utils import checksum, is_mac, is_win, namedtmp
|
from anki.utils import checksum, is_mac, is_win, namedtmp
|
||||||
from aqt import AnkiQt, gui_hooks
|
from aqt import AnkiQt, gui_hooks
|
||||||
|
@ -948,10 +948,10 @@ class EditorWebView(AnkiWebView):
|
||||||
clip = self.editor.mw.app.clipboard()
|
clip = self.editor.mw.app.clipboard()
|
||||||
assert clip is not None
|
assert clip is not None
|
||||||
clip.dataChanged.connect(self._on_clipboard_change)
|
clip.dataChanged.connect(self._on_clipboard_change)
|
||||||
self.settings().setAttribute(
|
self.settings().setAttribute( # type: ignore
|
||||||
QWebEngineSettings.WebAttribute.JavascriptCanPaste, True
|
QWebEngineSettings.WebAttribute.JavascriptCanPaste, True
|
||||||
)
|
)
|
||||||
self.settings().setAttribute(
|
self.settings().setAttribute( # type: ignore
|
||||||
QWebEngineSettings.WebAttribute.JavascriptCanAccessClipboard, True
|
QWebEngineSettings.WebAttribute.JavascriptCanAccessClipboard, True
|
||||||
)
|
)
|
||||||
gui_hooks.editor_web_view_did_init(self)
|
gui_hooks.editor_web_view_did_init(self)
|
||||||
|
|
|
@ -707,10 +707,12 @@ async def open_file_picker() -> bytes:
|
||||||
def cb(filename: str | None) -> None:
|
def cb(filename: str | None) -> None:
|
||||||
loop.call_soon_threadsafe(future.set_result, filename)
|
loop.call_soon_threadsafe(future.set_result, filename)
|
||||||
|
|
||||||
|
window = aqt.mw.app.activeWindow()
|
||||||
|
assert window is not None
|
||||||
getFile(
|
getFile(
|
||||||
parent=aqt.mw.app.activeWindow(),
|
parent=window,
|
||||||
title=req.title,
|
title=req.title,
|
||||||
cb=cb,
|
cb=cast(Callable[[Any], None], cb),
|
||||||
filter=f"{req.filter_description} ({' '.join(f'*.{ext}' for ext in req.extensions)})",
|
filter=f"{req.filter_description} ({' '.join(f'*.{ext}' for ext in req.extensions)})",
|
||||||
key=req.key,
|
key=req.key,
|
||||||
)
|
)
|
||||||
|
|
|
@ -43,14 +43,17 @@ impl crate::services::MediaService for Collection {
|
||||||
.into())
|
.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_media_from_path(&mut self, input: AddMediaFromPathRequest) -> error::Result<generic::String> {
|
fn add_media_from_path(
|
||||||
let base_name = Path::new(&input.path).file_name().unwrap_or_default().to_str().unwrap_or_default();
|
&mut self,
|
||||||
|
input: AddMediaFromPathRequest,
|
||||||
|
) -> error::Result<generic::String> {
|
||||||
|
let base_name = Path::new(&input.path)
|
||||||
|
.file_name()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_str()
|
||||||
|
.unwrap_or_default();
|
||||||
let data = std::fs::read(&input.path)?;
|
let data = std::fs::read(&input.path)?;
|
||||||
Ok(self
|
Ok(self.media()?.add_file(base_name, &data)?.to_string().into())
|
||||||
.media()?
|
|
||||||
.add_file(&base_name, &data)?
|
|
||||||
.to_string()
|
|
||||||
.into())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn trash_media_files(&mut self, input: TrashMediaFilesRequest) -> error::Result<()> {
|
fn trash_media_files(&mut self, input: TrashMediaFilesRequest) -> error::Result<()> {
|
||||||
|
@ -80,13 +83,27 @@ impl crate::services::MediaService for Collection {
|
||||||
Ok(files.into_iter().collect::<Vec<_>>().into())
|
Ok(files.into_iter().collect::<Vec<_>>().into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn extract_media_files(
|
||||||
fn extract_media_files(&mut self, html: anki_proto::generic::String) -> error::Result<generic::StringList> {
|
&mut self,
|
||||||
let files = extract_media_refs(&html.val).iter().map(|r| r.fname_decoded.to_string()).collect::<Vec<_>>();
|
html: anki_proto::generic::String,
|
||||||
|
) -> error::Result<generic::StringList> {
|
||||||
|
let files = extract_media_refs(&html.val)
|
||||||
|
.iter()
|
||||||
|
.map(|r| r.fname_decoded.to_string())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
Ok(files.into())
|
Ok(files.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_absolute_media_path(&mut self, path: anki_proto::generic::String) -> error::Result<generic::String> {
|
fn get_absolute_media_path(
|
||||||
Ok(self.media()?.media_folder.join(path.val).to_string_lossy().to_string().into())
|
&mut self,
|
||||||
|
path: anki_proto::generic::String,
|
||||||
|
) -> error::Result<generic::String> {
|
||||||
|
Ok(self
|
||||||
|
.media()?
|
||||||
|
.media_folder
|
||||||
|
.join(path.val)
|
||||||
|
.to_string_lossy()
|
||||||
|
.to_string()
|
||||||
|
.into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
|
|
||||||
import { registerPackage } from "@tslib/runtime-require";
|
import { registerPackage } from "@tslib/runtime-require";
|
||||||
import { filenameToLink, openFilePickerForImageOcclusion, readImageFromClipboard } from "./rich-text-input/data-transfer";
|
import {
|
||||||
|
filenameToLink,
|
||||||
|
openFilePickerForImageOcclusion,
|
||||||
|
readImageFromClipboard,
|
||||||
|
} from "./rich-text-input/data-transfer";
|
||||||
import contextProperty from "$lib/sveltelib/context-property";
|
import contextProperty from "$lib/sveltelib/context-property";
|
||||||
import lifecycleHooks from "$lib/sveltelib/lifecycle-hooks";
|
import lifecycleHooks from "$lib/sveltelib/lifecycle-hooks";
|
||||||
|
|
||||||
|
@ -543,7 +547,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import PreviewButton from "./PreviewButton.svelte";
|
import PreviewButton from "./PreviewButton.svelte";
|
||||||
import { NoteFieldsCheckResponse_State, type Note } from "@generated/anki/notes_pb";
|
import { NoteFieldsCheckResponse_State, type Note } from "@generated/anki/notes_pb";
|
||||||
|
|
||||||
|
|
||||||
$: isIOImageLoaded = false;
|
$: isIOImageLoaded = false;
|
||||||
$: ioImageLoadedStore.set(isIOImageLoaded);
|
$: ioImageLoadedStore.set(isIOImageLoaded);
|
||||||
let imageOcclusionMode: IOMode | undefined;
|
let imageOcclusionMode: IOMode | undefined;
|
||||||
|
@ -552,7 +555,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
async function pickIOImage() {
|
async function pickIOImage() {
|
||||||
imageOcclusionMode = undefined;
|
imageOcclusionMode = undefined;
|
||||||
const filename = await openFilePickerForImageOcclusion();
|
const filename = await openFilePickerForImageOcclusion();
|
||||||
if(!filename) {
|
if (!filename) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setupMaskEditor(filename);
|
setupMaskEditor(filename);
|
||||||
|
@ -564,7 +567,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setupMaskEditor(filename: string) {
|
async function setupMaskEditor(filename: string) {
|
||||||
if(mode == "add") {
|
if (mode == "add") {
|
||||||
setupMaskEditorForNewNote(filename);
|
setupMaskEditorForNewNote(filename);
|
||||||
} else {
|
} else {
|
||||||
setupMaskEditorForExistingNote(filename);
|
setupMaskEditorForExistingNote(filename);
|
||||||
|
@ -596,9 +599,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setupMaskEditorForNewNote(imagePath: string) {
|
async function setupMaskEditorForNewNote(imagePath: string) {
|
||||||
const imageFieldHtml = filenameToLink((await addMediaFromPath({
|
const imageFieldHtml = filenameToLink(
|
||||||
path: imagePath,
|
(
|
||||||
})).val);
|
await addMediaFromPath({
|
||||||
|
path: imagePath,
|
||||||
|
})
|
||||||
|
).val,
|
||||||
|
);
|
||||||
setupMaskEditorInner({
|
setupMaskEditorInner({
|
||||||
html: imageFieldHtml,
|
html: imageFieldHtml,
|
||||||
mode: {
|
mode: {
|
||||||
|
@ -611,25 +618,29 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
async function setupMaskEditorForExistingNote(imagePath: string | null = null) {
|
async function setupMaskEditorForExistingNote(imagePath: string | null = null) {
|
||||||
if (imagePath) {
|
if (imagePath) {
|
||||||
const imageFieldHtml = filenameToLink((await addMediaFromPath({
|
const imageFieldHtml = filenameToLink(
|
||||||
path: imagePath,
|
(
|
||||||
})).val);
|
await addMediaFromPath({
|
||||||
|
path: imagePath,
|
||||||
|
})
|
||||||
|
).val,
|
||||||
|
);
|
||||||
resetIOImage(imagePath, () => {});
|
resetIOImage(imagePath, () => {});
|
||||||
setImageField(imageFieldHtml);
|
setImageField(imageFieldHtml);
|
||||||
}
|
}
|
||||||
setupMaskEditorInner({
|
setupMaskEditorInner({
|
||||||
html: note!.fields[ioFields.image],
|
html: note!.fields[ioFields.image],
|
||||||
mode: {
|
mode: {
|
||||||
kind: "edit",
|
kind: "edit",
|
||||||
noteId: note!.id,
|
noteId: note!.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function setupMaskEditorFromClipboard() {
|
async function setupMaskEditorFromClipboard() {
|
||||||
const path = await readImageFromClipboard();
|
const path = await readImageFromClipboard();
|
||||||
console.log("setupMaskEditorFromClipboard path", path);
|
console.log("setupMaskEditorFromClipboard path", path);
|
||||||
if(path) {
|
if (path) {
|
||||||
setupMaskEditor(path);
|
setupMaskEditor(path);
|
||||||
} else {
|
} else {
|
||||||
alert(tr.editingNoImageFoundOnClipboard());
|
alert(tr.editingNoImageFoundOnClipboard());
|
||||||
|
|
Loading…
Reference in a new issue