diff --git a/app/src/main/java/net/gsantner/markor/frontend/AttachLinkOrFileDialog.java b/app/src/main/java/net/gsantner/markor/frontend/AttachLinkOrFileDialog.java index f7bbc3715f..f78560f30b 100644 --- a/app/src/main/java/net/gsantner/markor/frontend/AttachLinkOrFileDialog.java +++ b/app/src/main/java/net/gsantner/markor/frontend/AttachLinkOrFileDialog.java @@ -32,6 +32,7 @@ import net.gsantner.markor.frontend.textview.TextViewUtils; import net.gsantner.markor.model.AppSettings; import net.gsantner.markor.util.MarkorContextUtils; +import net.gsantner.opoc.format.GsTextUtils; import net.gsantner.opoc.frontend.GsAudioRecordOmDialog; import net.gsantner.opoc.frontend.filebrowser.GsFileBrowserOptions; import net.gsantner.opoc.util.GsFileUtils; @@ -120,7 +121,7 @@ public static void showInsertImageOrLinkDialog( final AlertDialog dialog = builder.setView(view).create(); // Helper func - final GsCallback.a1 _insertItem = (type) -> insertItem(type, textFormatId, activity, edit, currentFile, dialog); + final GsCallback.a1 _insertItem = (type) -> insertItem(type, textFormatId, activity, edit, currentFile, sel, dialog); // Setup all the various choices final InsertType browseType, okType; @@ -216,14 +217,20 @@ private static void insertItem( final Activity activity, final Editable text, final File currentFile, + @Nullable final int[] region, @Nullable AlertDialog dialog ) { - final int[] sel = TextViewUtils.getSelection(text); + final int[] sel; + if (region != null && region.length > 1 && region[0] >= 0 && region[1] >= 0) { + sel = region; + } else { + sel = TextViewUtils.getSelection(text); + } final AppSettings _appSettings = ApplicationObject.settings(); final File attachmentDir = _appSettings.getAttachmentFolder(currentFile); - // Source, dest to be written when the user hits accept + // Title, path to be written when the user hits accept final GsCallback.a2 insertLink = (title, path) -> { if (TextViewUtils.isNullOrEmpty(path)) { return; @@ -244,7 +251,7 @@ private static void insertItem( newText = newText.replaceFirst("\\|]]$", "]]"); } - if (!text.subSequence(sel[0], sel[1]).equals(newText)) { + if (!newText.equals(text.subSequence(sel[0], sel[1]).toString())) { text.replace(sel[0], sel[1], newText); } @@ -297,13 +304,17 @@ private static void insertItem( } case IMAGE_EDIT: { if (pathEdit != null) { - String filepath = pathEdit.getText().toString().replace("%20", " "); - if (!filepath.startsWith("/")) { - filepath = new File(currentFile.getParent(), filepath).getAbsolutePath(); + final String path = pathEdit.getText().toString().replace("%20", " "); + + final File abs = new File(path).getAbsoluteFile(); + if (abs.isFile()) { + shu.requestPictureEdit(activity, abs); + break; } - File file = new File(filepath); - if (file.exists() && file.isFile()) { - shu.requestPictureEdit(activity, file); + + final File rel = new File(currentFile.getParentFile(), path).getAbsoluteFile(); + if (rel.isFile()) { + shu.requestPictureEdit(activity, rel); } } break; @@ -355,7 +366,7 @@ public static void insertCameraPhoto( final Editable text, final File currentFile ) { - insertItem(InsertType.IMAGE_CAMERA, textFormatId, activity, text, currentFile, null); + insertItem(InsertType.IMAGE_CAMERA, textFormatId, activity, text, currentFile, null, null); } public static void insertGalleryPhoto( @@ -364,7 +375,7 @@ public static void insertGalleryPhoto( final Editable text, final File currentFile ) { - insertItem(InsertType.IMAGE_GALLERY, textFormatId, activity, text, currentFile, null); + insertItem(InsertType.IMAGE_GALLERY, textFormatId, activity, text, currentFile, null, null); } public static void insertAudioRecording( @@ -373,6 +384,6 @@ public static void insertAudioRecording( final Editable text, final File currentFile ) { - insertItem(InsertType.AUDIO_RECORDING, textFormatId, activity, text, currentFile, null); + insertItem(InsertType.AUDIO_RECORDING, textFormatId, activity, text, currentFile, null, null); } } diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java index d5bb4a3934..08786874cc 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserDialog.java @@ -95,7 +95,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa @Override public void onViewCreated(View root, @Nullable Bundle savedInstanceState) { super.onViewCreated(root, savedInstanceState); - Context context = getContext(); + final Context context = getContext(); _recyclerList = root.findViewById(R.id.ui__filesystem_dialog__list); _dialogTitle = root.findViewById(R.id.ui__filesystem_dialog__title_text); @@ -197,7 +197,7 @@ public void onClicked(View view) { break; } case R.id.ui__filesystem_dialog__button_cancel: { - onFsViewerNothingSelected(_dopt.requestId); + onFsViewerCancel(_dopt.requestId); break; } case R.id.ui__filesystem_dialog__new_dir: { @@ -258,9 +258,9 @@ public void onFsViewerMultiSelected(String request, File... files) { } @Override - public void onFsViewerNothingSelected(String request) { + public void onFsViewerCancel(String request) { if (_callback != null) { - _callback.onFsViewerNothingSelected(_dopt.requestId); + _callback.onFsViewerCancel(_dopt.requestId); } dismiss(); } diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java index 1f67b39615..7fdfd993dc 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserFragment.java @@ -160,7 +160,7 @@ public void onClicked(View view) { break; } case R.id.ui__filesystem_dialog__button_cancel: { - onFsViewerNothingSelected(_dopt.requestId); + onFsViewerCancel(_dopt.requestId); break; } @@ -189,9 +189,9 @@ public void onFsViewerMultiSelected(String request, File... files) { } @Override - public void onFsViewerNothingSelected(String request) { + public void onFsViewerCancel(String request) { if (_callback != null) { - _callback.onFsViewerNothingSelected(_dopt.requestId); + _callback.onFsViewerCancel(_dopt.requestId); } } diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserOptions.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserOptions.java index f814f80313..9f46e7d483 100644 --- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserOptions.java +++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserOptions.java @@ -31,7 +31,7 @@ public interface SelectionListener { void onFsViewerMultiSelected(final String request, final File... files); - void onFsViewerNothingSelected(final String request); + void onFsViewerCancel(final String request); void onFsViewerConfig(final Options dopt); @@ -130,7 +130,7 @@ public void onFsViewerMultiSelected(String request, File... files) { } @Override - public void onFsViewerNothingSelected(String request) { + public void onFsViewerCancel(String request) { } @Override diff --git a/app/thirdparty/java/other/writeily/widget/WrWidgetConfigure.java b/app/thirdparty/java/other/writeily/widget/WrWidgetConfigure.java index 555e5de21f..a1f3dcd101 100644 --- a/app/thirdparty/java/other/writeily/widget/WrWidgetConfigure.java +++ b/app/thirdparty/java/other/writeily/widget/WrWidgetConfigure.java @@ -53,7 +53,6 @@ protected void onStop() { // only runs for a valid id private void showWidgetSelectFolderDialog() { - final FragmentManager fragManager = getSupportFragmentManager(); MarkorFileBrowserFactory.showFolderDialog(new GsFileBrowserOptions.SelectionListenerAdapter() { @Override public void onFsViewerSelected(String request, File file, final Integer lineNumber) { @@ -67,7 +66,13 @@ public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) { dopt.titleText = R.string.select_folder; dopt.rootFolder = ApplicationObject.settings().getNotebookDirectory(); } - }, fragManager, this); + + @Override + public void onFsViewerCancel(final String request) { + finish(); + } + + }, getSupportFragmentManager(), this); } public static File getWidgetDirectory(final Context context, int id) {