Skip to content

Commit

Permalink
new file dialog fixes, no folder in select qn / todo
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Jun 1, 2024
1 parent 58df0fa commit 4900732
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ public void onFsViewerSelected(String request, File file, final Integer lineNumb
public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) {
dopt.titleText = R.string.quicknote;
dopt.rootFolder = _appSettings.getNotebookDirectory();
dopt.newDirButtonEnable = false;
}
}, fragManager, getActivity(), MarkorFileBrowserFactory.IsMimeText);
return true;
Expand All @@ -303,6 +304,7 @@ public void onFsViewerSelected(String request, File file, final Integer lineNumb
public void onFsViewerConfig(GsFileBrowserOptions.Options dopt) {
dopt.titleText = R.string.todo;
dopt.rootFolder = _appSettings.getNotebookDirectory();
dopt.newDirButtonEnable = false;
}
}, fragManager, getActivity(), MarkorFileBrowserFactory.IsMimeText);
return true;
Expand Down
26 changes: 23 additions & 3 deletions app/src/main/java/net/gsantner/markor/frontend/NewFileDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.documentfile.provider.DocumentFile;
Expand All @@ -48,6 +49,7 @@
import net.gsantner.opoc.util.GsFileUtils;
import net.gsantner.opoc.wrapper.GsAndroidSpinnerOnItemSelectedAdapter;
import net.gsantner.opoc.wrapper.GsCallback;
import net.gsantner.opoc.wrapper.GsTextWatcherAdapter;

import java.io.File;
import java.util.Arrays;
Expand Down Expand Up @@ -231,6 +233,24 @@ private AlertDialog.Builder makeDialog(final File basedir, final boolean allowCr
return TextViewUtils.interpolateSnippet(format, title, "").trim();
};

final @ColorInt int color = titleEdit.getCurrentTextColor();
titleEdit.addTextChangedListener(new GsTextWatcherAdapter() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
try {
final String title = getTitle.callback();
final String ext = extEdit.getText().toString().trim();
final String fn = GsFileUtils.getFilteredFilenameWithoutDisallowedChars(title + ext);
if (new File(basedir, fn).exists()) {
titleEdit.setTextColor(0xffff0000);
} else {
titleEdit.setTextColor(color);
}
} catch (Exception ignored) {
titleEdit.setTextColor(color);
}
}
});

final MarkorContextUtils cu = new MarkorContextUtils(getContext());
dialogBuilder.setNegativeButton(R.string.cancel, (dialogInterface, i) -> dialogInterface.dismiss());
Expand All @@ -242,12 +262,12 @@ private AlertDialog.Builder makeDialog(final File basedir, final boolean allowCr

// Get template string
// -------------------------------------------------------------------------------------
final int ti = templateSpinner.getSelectedItemPosition();
final int ti = templateSpinner.getSelectedItemPosition() - 1;
final String template;
if (ti == 0) {
if (ti < 0) {
template = "";
} else if (ti <= snippets.size()) {
template = GsFileUtils.readTextFileFast(snippets.get(ti - 1).second).first;
template = GsFileUtils.readTextFileFast(snippets.get(ti).second).first;
} else {
template = templates.get(ti - snippets.size()).second;
}
Expand Down

0 comments on commit 4900732

Please sign in to comment.