Compare commits
No commits in common. "main" and "1.8.2-1-beta" have entirely different histories.
main
...
1.8.2-1-be
7
.eslintignore
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
npm node_modules
|
||||
build
|
||||
*.js
|
||||
*.json
|
||||
*.md
|
||||
*.css
|
||||
LICENSE
|
||||
150
.eslintrc
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"env": {
|
||||
"node": true
|
||||
},
|
||||
"plugins": [
|
||||
"@typescript-eslint"
|
||||
],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended",
|
||||
"plugin:@typescript-eslint/recommended"
|
||||
],
|
||||
"parserOptions": {
|
||||
"sourceType": "module"
|
||||
},
|
||||
"rules": {
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": [
|
||||
"error",
|
||||
{
|
||||
"args": "none"
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/ban-ts-comment": "off",
|
||||
"no-prototype-builtins": "off",
|
||||
"@typescript-eslint/no-empty-function": "off",
|
||||
"brace-style": [
|
||||
"error",
|
||||
"1tbs",
|
||||
{
|
||||
"allowSingleLine": true
|
||||
}
|
||||
],
|
||||
"consistent-return": "off",
|
||||
"quotes": [
|
||||
"error",
|
||||
"single",
|
||||
{
|
||||
"avoidEscape": true
|
||||
}
|
||||
],
|
||||
"@typescript-eslint/ban-types": [
|
||||
"error",
|
||||
{
|
||||
"types": {
|
||||
"Function": false
|
||||
},
|
||||
"extendDefaults": true
|
||||
}
|
||||
],
|
||||
"no-mixed-spaces-and-tabs": "error",
|
||||
"indent": [
|
||||
"error",
|
||||
"tab",
|
||||
{
|
||||
"SwitchCase": 1
|
||||
}
|
||||
],
|
||||
"arrow-parens": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"eol-last": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"func-call-spacing": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"comma-dangle": [
|
||||
"error",
|
||||
"always-multiline"
|
||||
],
|
||||
"no-multi-spaces": "error",
|
||||
"no-trailing-spaces": "error",
|
||||
"no-whitespace-before-property": "off",
|
||||
"semi": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"semi-style": [
|
||||
"error",
|
||||
"last"
|
||||
],
|
||||
"space-in-parens": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"block-spacing": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"object-curly-spacing": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"eqeqeq": [
|
||||
"error",
|
||||
"always",
|
||||
{
|
||||
"null": "ignore"
|
||||
}
|
||||
],
|
||||
"spaced-comment": [
|
||||
"error",
|
||||
"always",
|
||||
{
|
||||
"markers": [
|
||||
"!"
|
||||
]
|
||||
}
|
||||
],
|
||||
"yoda": "error",
|
||||
"prefer-destructuring": [
|
||||
"error",
|
||||
{
|
||||
"object": false,
|
||||
"array": false
|
||||
}
|
||||
],
|
||||
"operator-assignment": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"no-useless-computed-key": "error",
|
||||
"no-unneeded-ternary": [
|
||||
"error",
|
||||
{
|
||||
"defaultAssignment": false
|
||||
}
|
||||
],
|
||||
"no-invalid-regexp": "error",
|
||||
"no-constant-condition": [
|
||||
"error",
|
||||
{
|
||||
"checkLoops": false
|
||||
}
|
||||
],
|
||||
"no-duplicate-imports": "error",
|
||||
"no-extra-semi": "error",
|
||||
"dot-notation": "error",
|
||||
"no-useless-escape": [
|
||||
"error"
|
||||
]
|
||||
}
|
||||
}
|
||||
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
|
|
@ -30,7 +30,7 @@ If applicable, add screenshots to help explain your problem.
|
|||
|
||||
**Plugin information**
|
||||
- Version: [e.g. v1.7.30]
|
||||
- [ ] Beta version
|
||||
- [ ] Beta version (If it is the beta version also add the beta label)
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
|
|
|
|||
30
.github/workflows/label-beta.yml
vendored
|
|
@ -1,30 +0,0 @@
|
|||
name: Label Beta Issues
|
||||
|
||||
on:
|
||||
issues:
|
||||
types: [opened, edited]
|
||||
|
||||
jobs:
|
||||
label-beta:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Check for Beta Version checkbox
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const betaChecked = context.payload.issue.body.includes("- [x] Beta version");
|
||||
|
||||
if (betaChecked) {
|
||||
const issue_number = context.payload.issue.number;
|
||||
const labels = context.payload.issue.labels.map(label => label.name);
|
||||
|
||||
if (!labels.includes('beta')) {
|
||||
await github.rest.issues.addLabels({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issue_number,
|
||||
labels: ['beta']
|
||||
});
|
||||
}
|
||||
}
|
||||
36
.github/workflows/release.yaml
vendored
|
|
@ -1,20 +1,13 @@
|
|||
# https://github.com/SilentVoid13/Templater/blob/master/.github/workflows/release.yml
|
||||
name: Plugin release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "[0-9]+.[0-9]+.[0-9]+"
|
||||
|
||||
permissions:
|
||||
id-token: write
|
||||
contents: write
|
||||
attestations: write
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
|
@ -22,13 +15,9 @@ jobs:
|
|||
submodules: recursive
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Fetch all branches
|
||||
run: git fetch --all
|
||||
|
||||
- name: Extract branch name
|
||||
run: |
|
||||
BRANCH_NAME=$(git name-rev --name-only $GITHUB_SHA | sed 's|^remotes/origin/||' | sed 's|^origin/||')
|
||||
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
|
||||
id: extract_branch
|
||||
run: echo "BRANCH_NAME=$(git branch -r --contains ${GITHUB_SHA} | grep -v 'detached' | sed 's|origin/||' | xargs)" >> $GITHUB_ENV
|
||||
|
||||
# Checkout the main branch to update manifest.json
|
||||
- name: Checkout main branch to update manifest
|
||||
|
|
@ -47,31 +36,20 @@ jobs:
|
|||
git config --local user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git config --local user.name "github-actions[bot]"
|
||||
git add manifest.json
|
||||
git commit -m "Update manifest.json to version $VERSION" || echo "No changes to commit"
|
||||
git commit -m "Update manifest.json to version $VERSION"
|
||||
git push origin main
|
||||
|
||||
|
||||
- name: Ensure HEAD is at updated main commit
|
||||
# Switch back to the branch that triggered the workflow
|
||||
- name: Checkout original branch
|
||||
run: |
|
||||
git fetch origin
|
||||
git checkout main
|
||||
git reset --hard origin/main
|
||||
git checkout ${{ env.BRANCH_NAME }}
|
||||
git pull origin ${{ env.BRANCH_NAME }}
|
||||
|
||||
- name: npm build
|
||||
run: |
|
||||
npm install
|
||||
npm run fn-build --if-present
|
||||
|
||||
- name: Generate artifact attestation for main.js
|
||||
uses: actions/attest@v4
|
||||
with:
|
||||
subject-path: 'main.js'
|
||||
|
||||
- name: Generate artifact attestation for styles.css
|
||||
uses: actions/attest@v4
|
||||
with:
|
||||
subject-path: 'styles.css'
|
||||
|
||||
- name: Create Plugin release
|
||||
uses: ncipollo/release-action@v1.12.0
|
||||
with:
|
||||
|
|
|
|||
|
|
@ -3,9 +3,6 @@
|
|||
Folder notes is a plugin for the note taking app [Obsidian](https://obsidian.md/) that lets you attach notes to folders so that you can click on the name of a folder to open the note like in the app [Notion](https://www.notion.so/).
|
||||
This plugin has some unique features that separate it from similar "Folder note" plugins like opening folder notes through the path, creating folder notes for every existing folder, templater/template support and more.
|
||||
|
||||
Support the development of the plugin
|
||||
|
||||
<a href='https://ko-fi.com/D1D1GHGSI' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi2.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
|
||||
## Documentation & download link
|
||||
The plugin can be downloaded by clicking on https://obsidian.md/plugins?id=folder-notes and then on install. If you need help with the plugin or want to know what the features are that the plugin has then you can find the documentation at https://lostpaul.github.io/obsidian-folder-notes/.
|
||||
|
||||
|
|
@ -13,7 +10,8 @@ The plugin can be downloaded by clicking on https://obsidian.md/plugins?id=folde
|
|||
|
||||
The easiest option is to install the [BRAT plugin](https://obsidian.md/plugins?id=obsidian42-brat) and then to follow the following guide: https://tfthacker.com/brat-quick-guide & use this link https://github.com/LostPaul/obsidian-folder-notes to install the beta version.
|
||||
|
||||
Join the Discord server to chat about the beta and to also get the beta user role.
|
||||
## Support the development of the plugin
|
||||
|
||||
<a href='https://ko-fi.com/D1D1GHGSI' target='_blank'><img height='36' style='border:0px;height:36px;' src='https://storage.ko-fi.com/cdn/kofi2.png?v=3' border='0' alt='Buy Me a Coffee at ko-fi.com' /></a>
|
||||
|
||||
## Discord server
|
||||
[For regular updates on Folder Notes and my other plugins, join the Discord server to get notified and participate in discussions.](https://discord.gg/4UQEDfQmuH)
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
# Command palette commands
|
||||
|
||||
## Use this file as the folder note for its parent folder
|
||||
## Make current active note a folder note for the folder of the active note
|
||||
The note that's currently in focus will be the new folder note for the parent folder of the file.
|
||||
## Make a folder with this file as its folder note
|
||||
## Create folder note with a new folder for the active note in the current folder
|
||||
This command creates a new folder and uses the current file that is in focus as the folder note. The new folder will be in the same folder as the folder the file was in.
|
||||
## Create {type} folder note for this folder
|
||||
## Create {type} folder note for current folder of active note
|
||||
Create a new folder note for the folder of the current file that is in focus. The plugin will not use the file in focus but instead a completely new file.
|
||||
## Delete this folder's linked note
|
||||
Delete the folder note (only the file itself) of the parent folder of the currently focused file.
|
||||
## Open this folder's linked note
|
||||
Open the folder note of the parent folder of the currently focused file.
|
||||
## Delete folder note of current folder of active note
|
||||
Delete the file of the folder note that is for the folder which the current file in focus is in.
|
||||
## Open folder note of current folder of active note
|
||||
Open the folder note of the folder that the current file in focus is in.
|
||||
## Insert folder overview
|
||||
Insert a folder overview in a note. [Click here to know more about a folder overview](./Folder%20overview.md).
|
||||
## Edit folder overview
|
||||
Edit the default settings or an already created folder overview in the right view. [Click here to know more about a folder overview](./Folder%20overview.md).
|
||||
## Create folder note from selection
|
||||
## Create folder note from selected text
|
||||
Create a new file, a new folder and the file as the folder note. The text that has been selected will be the name of the folder note and the folder.
|
||||
|
|
@ -1,19 +1,17 @@
|
|||
# Exclude folders
|
||||
The exclude folder feature can be found in the plugin settings under the tab "Exclude folders". Depending on what you exclude a folder from you for example can't open a folder note, the file/folder names don't sync, it doesn't show up in the folder overview and more.
|
||||
The exclude folder feature can be found in the plugin settings under the tab "Exclude folders".
|
||||
## Exclude only one folder
|
||||
To only exclude the folder itself and not the sub folders also you have to click on the edit icon and disable include subfolders in the settings.
|
||||
|
||||
## How to exclude a folder?
|
||||
### Directly in the settings
|
||||
Click on the plus icon, then click on the text input, search a folder name and then select the folder you want to exclude from the list.
|
||||

|
||||

|
||||
### Through the file explorer
|
||||
Click on a folder and then use the context menu and click on "exclude folder from folder notes". The plugin will then apply the [default exclude folder settings](#Default settings) and add it to the excluded folders list.
|
||||

|
||||
## Exclude a folder and their subfolders
|
||||
To exclude a folder and its subfolders you have to do the same steps as in how to exclude only one folder but enable include subfolders in the settings of an excluded folder.
|
||||
## Exclude multiple folders (with a pattern)
|
||||
The pattern only looks at the names of the folders and nothing else. You have two options to exclude folders with a pattern and the first option is to use * before and after the string. The second option is to use a [regex](https://en.wikipedia.org/wiki/Regular_expression).
|
||||
The pattern only looks at the names of the folders and nothing else. You have to options to exclude folders with a pattern and the first option is to use * before and after the string. The second option is to use a [regex](https://en.wikipedia.org/wiki/Regular_expression).
|
||||
|
||||
To use a regex you have to add "{regex}" at the beginning of the string and everything after it is going to be a regex that matches the folder names.
|
||||
|
||||
|
|
@ -32,7 +30,4 @@ Test* => matches the name
|
|||
Open the exclude folders settings tab and click on a edit button if you've already excluded folders or added patterns to exclude folders.
|
||||

|
||||
## Default settings
|
||||
To edit the default settings for new excluded folders/patterns you just have to click on one of the "Manage" buttons in the settings that are next to "Exclude folder/pattern default settings".
|
||||
|
||||
## Whitelisted folders
|
||||
The whitelisted folders overwrite the already excluded folders with options that are the opposite from the excluded folders. For example when you add a pattern to exclude all folders, select to disable opening of folders and then add one specific folder to the whitelist and select "open folder ..." you can only open the specific folder and not all the other folder notes.
|
||||
To edit the default settings for new excluded folders/patterns you just have to click on one of the "Manage" buttons in the settings that are next to "Exclude folder/pattern default settings".
|
||||
|
|
@ -2,9 +2,5 @@
|
|||
|
||||
## Create folder note
|
||||
This command creates a new folder and uses the file you clicked on as the folder note. The new folder will be in the same folder as the folder the file was in.
|
||||
|
||||

|
||||
## Turn into folder note for "{folderName}"
|
||||
This command will attach the file to the folder it's in. For example file "test" that is in the folder "test2" will be the new folder note for the folder "test2".
|
||||
|
||||

|
||||
This command will attach the file to the folder it's in. For example file "test" that is in the folder "test2" will be the new folder note for the folder "test2".
|
||||
|
|
@ -1,14 +1,10 @@
|
|||
# Folder context menu commands
|
||||
|
||||
|
||||
## Exclude folder from folder notes
|
||||
This will add the folder to the excluded folder list. [Click here to find more about excluded folders out.](Exclude%20folders.md)
|
||||
## Create {type} folder note
|
||||
This command will create a folder note of the file type you selected and depending on your settings the folder note will be in the folder itself or in the parent folder of the folder.
|
||||
## Delete folder note
|
||||
The folder note from the folder you clicked on gets deleted. (Only the file and note the folder itself)
|
||||
The folder note from the folder you clicked on gets deleted.
|
||||
## Open folder note
|
||||
Opens folder notes in the currently active tab or if you have the setting "open folder note in a new tab by default" enabled the note opens in a new tab.
|
||||
|
||||
## Copy Obsidian URL
|
||||
Copies the Obsidian URL of the file which is linked to the folder and it can be used in other programs to directly open the file.
|
||||
Opens folder notes in the currently active tab or if you have the setting "open folder note in a new tab by default" enabled the note opens in a new tab.
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
# File explorer settings
|
||||
### Hide folder note
|
||||
Hide files in the file explorer which are linked to folders
|
||||
### Disable click-to-open folder note on mobile
|
||||
Disable the option to open folder notes by tapping on the folder name of a folder with a folder note in the file explorer. With that option enabled it's only possible to open folder notes with the command palette oder the context menu.
|
||||
|
||||
### Open folder notes by only clicking directly on the folder name
|
||||
With this option enabled you can only open a folder note by clicking when doing so exactly on the folder name and not on the whitespace around it. When you also have "Disable folder collapsing" enabled folders also won't collapse when you click on a folder name.
|
||||
|
||||
### Disable folder collapsing
|
||||
Stop folders with folder notes from collapsing when click directly on the folder name or on the whitespace around it. Except when you click on the collapse icon you can still collapse folders.
|
||||
|
||||
### Use submenus
|
||||
When this option is enabled and you use the context menu for folder/files at first you can only see "Folder Note Commands" in the menu and you have to hover over it to see all options.
|
||||
|
||||
## Style settings
|
||||
|
||||
### Highlight folder in the file explorer
|
||||
Normally only the file gets highlighted in the explorer but when you enable this option the folder of a folder note gets also highlighted.
|
||||
|
||||
### Hide collapse icon
|
||||
Hide the collapse icon next to a folder name for a folder with a folder note or also for every folder with no files.
|
||||
|
||||
### Underline the name of folder note
|
||||
Underline the names of folders with folder notes in the file explorer.
|
||||
|
||||
### Bold the name of folder notes
|
||||
Bold folders in the file explorer that have a folder note.
|
||||
|
||||
### Cursive the name of folder notes
|
||||
Make folder with folder notes in the file explorer cursive.
|
||||
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
# General settings
|
||||
### Folder note name template
|
||||
The entered text is going to be the name of all folder notes and when file name matches this text it becomes a folder note. {{folder_name}} is a placeholder for the name of the folder linked to the file. If you change the text every existing folder note which matched the old text won't be a folder note anymore and you have to use the button "Rename existing folder notes" to rename all folder notes.
|
||||
|
||||
### Supported file types
|
||||
Only the file types you select will be selected will be recognized as folder notes. This means you that a file that matches the name of a folder and normally would be a folder note but has an extension that isn't included in the supported file types list won't be a folder note and you can't open it by click on the folder name.
|
||||
|
||||
### Template path
|
||||
When you don't have templater installed & enabled you can choose any file in your vault as a template. But if you have templater enabled you first have to choose the folder where your templates are located, in the settings of the templater plugin. You can also use the core templates plugin for applying templates to new folder notes.
|
||||
|
||||
### Storage location
|
||||
Choose if the folder notes should be stored in the folder they're linked to or in the parent folder of the folder they're linked to. If you switch the storage method all existing folder won't be recognized as folder notes anymore until you click on the switch button and the location of old folder note files gets changed.
|
||||
|
||||
## Folder note behavior
|
||||
### Confirm folder note deletion
|
||||
When enabled a modal pops up when you try to delete folder note using the context menu.
|
||||
### Open folder note in a new tab by default
|
||||
When enabled every folder note opens in a new tab unless it is already open in the currently focused file in the editor and if the subsetting "focus existing tab instead of creating a new one" is also enabled every folder note only has one tab open. If you have different tab open than of a folder note you want to open and the folder note already has a tab open it'll switch to it.
|
||||
|
||||
## Integration & Compatibility
|
||||
### Enable [front matter title plugin](https://github.com/snezhig/obsidian-front-matter-title) integration
|
||||
Applies the changes made to the files names in the frontmatter also to the folder names in the file explorer & the path for folders with folder notes. This is also requires to enable the auto update setting in the file explorer & path settings of the folder notes plugin.
|
||||
|
||||
## Session & Persistence
|
||||
|
||||
### Persist tab after restart
|
||||
Open the same tab you had open in the plugin settings before restarting Obsidian.
|
||||
### Persist tab during session only
|
||||
Open the same tab after closing the plugin settings and opening it again but if "Persist tab after restart" is disabled it won't open the same tab again after restarting Obsidian.
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
# Path settings
|
||||
The "path" is the file path above a note in the editor.
|
||||
|
||||

|
||||
### Open folder note through path
|
||||
Open a folder note by click on a folder name in the path when it has a folder note linked to it.
|
||||
|
||||
### Open sidebar when opening a folder note through path
|
||||
Disable/enable if the left sidebar should also open when you open a folder note through the path.
|
||||
|
||||
### Auto update folder name in the path ([front matter title plugin only](https://github.com/snezhig/obsidian-front-matter-title))
|
||||
Automatically update the folder name in the path when the front matter title plugin is enabled and the title for a folder note is changed in the front matter. This will not change the file name, only the displayed name in the path.
|
||||
|
||||
## Style settings
|
||||
|
||||
### Underline folder in the path
|
||||
Underline every folder with a folder note in the path.
|
||||
|
||||
### Bold folders in the path
|
||||
Bold every folder with a folder note in the path.
|
||||
### Cursive folders in the path
|
||||
Make every folder with a folder note in the path cursive.
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
# Folder overview
|
||||
[The folder overview feature can be installed as a standalone plugin and works without the folder notes plugin by clicking on this.](https://obsidian.md/plugins?id=folder-overview)
|
||||
**Don't install "folder notes" & the "folder overview" plugin instead only install the folder notes plugin otherwise you can't enable both and there can be other bugs.**
|
||||
|
||||
This page will be updated soon and there also will be new features.
|
||||
This feature/plugin creates a code block
|
||||
|
||||
This feature/plugin creates a [code block](https://help.obsidian.md/Editing+and+formatting/Basic+formatting+syntax#Code+blocks) that provides an overview of your entire vault or specific folders. Instructions for creating or editing a folder overview, along with additional guidance, can be found further down the page.
|
||||
Currently there are two styles available: **file explorer** & **list style**, with more coming soon. The **overview updates** itself **automatically** when you create, delete or modify a file. You can also integrate it into **templates**, as explained further down below this page.
|
||||
|
|
@ -10,71 +11,13 @@ Additionally, you can **customize** the overview by selecting **specific file ty
|
|||
There are two options to create a folder overview in a note
|
||||
|
||||
- Use the command "Insert folder overview" from the [command palette](https://help.obsidian.md/Plugins/Command+palette)
|
||||
- On desktop right click and click on the option "Insert folder overview"
|
||||
- On desktop right click and click on the option "Create folder overview"
|
||||
## Edit overview
|
||||
If the overview shows no files or folders yet you can just click on the button that says "Edit overview". But if there are already files/folders you can use the command "Edit folder overview" from the [command palette](https://help.obsidian.md/Plugins/Command+palette) or click on the button as showed in the video below.
|
||||
If the overview shows no files or folders yet you can just click on the button that says "Edit overview". But if there are already files/folders it's a bit more complicated than the button and to then edit the overview you have to hover over the overview and click on the "Edit this block" button on the right top corner of the overview with only an icon.
|
||||
|
||||
The video below shows the steps explained in the text.
|
||||

|
||||
|
||||
## Default settings
|
||||
To edit the default values for new folder overviews you can either use the command "Edit folder overview" or open the plugins settings tab and then the folder overview tab to the edit the default settings. This won't change the settings of already existing folder overviews.
|
||||
|
||||
|
||||

|
||||
(On the left is the plugin settings tab and the right the view you see when you use the "Edit folder overview" command)
|
||||
|
||||
## FAQ
|
||||
### How can I use this in a template?
|
||||
|
||||
Just create the folder overview as normal in a template and then change the settings to be what you want to use as a default for the files you apply the templates to. It also doesn't matter that the id of the overview in the template will be the same as the id of the overview that gets created when the template has been used.
|
||||
|
||||
### What's the id in the code block for?
|
||||
They're there to differentiate the overviews from each other so that you can use "Edit folder overview" command to edit the overviews from one file (there can be multiple overviews in one file). It's especially useful on mobile because the button to edit the code block on mobile is quite small.
|
||||
|
||||
### How can I make the links appear in the graph view?
|
||||
[Edit the folder overview](#edit-overview) and then enable "Use actual links" to let the links appear in the graph view. The file will be then edited under the code block and there will be another list added which is hidden by default. You can choose to either hide the code block or the list under it in the folder overview settings. The list of links under the code block will also be visible in other apps that support markdown.
|
||||
|
||||

|
||||

|
||||
|
||||
## Settings
|
||||
|
||||
### Auto sync
|
||||
When this is enabled and you rename/create/delete a file/folder which is a children of the selected folder the overview will automatically update.
|
||||
### Title
|
||||
The title is above the overview when you enable "Show the title". You can use variables like this: {{variableName}} which will be replaced with something and the list of variables you can use is below this text.
|
||||
|
||||
| Variable | Explanation | Example |
|
||||
| ------------------ | ------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- |
|
||||
| folderName | The name of the folder depending on what folder you choose to display | Folder1 |
|
||||
| folderPath | The path of the choosen folder | Folder1/Folder2 |
|
||||
| fileName | The name of the file where the overview is located in | File1 |
|
||||
| filePath | The path of the file where the overview is located in | Folder1/File1 |
|
||||
| fmtpFileName | The changed file name using the [front matter title plugin](https://github.com/snezhig/obsidian-front-matter-title) | Real file name: 1234, changed name: File1 |
|
||||
| properties.<name\> | Choose any property from a file | properties.name => File1<br>properties.date => e.g. 01.01.2001 |
|
||||
|
||||
### Folder path
|
||||
The overview will show the children of the selected folder.
|
||||
|
||||
When you leave the path empty it will use the parent folder of where the overview is located in. The same is true for "File's parent folder path". If you're using the folder notes plugin and have the storage location set to parent folder you'll need to use "Path of folder linked to the file" to show the children of the folder which is linked to the file. Otherwise if you would for example have the overview located in "File1" which is linked to "Folder1" it would choose all the files/folders of the vault.
|
||||
|
||||
### Use actual links
|
||||
This allows the links of the overview to show up in the grap view, see [How can I make the links appear in the graph view?](#how-can-i-make-the-links-appear-in-the-graph-view?).
|
||||
|
||||
#### Hide link list/folder overview
|
||||
Either hide the code block or the list under it. When you hide the link list every list item will have a span item added to it. It looks like on the image at [How can I make the links appear in the graph view?](#how-can-i-make-the-links-appear-in-the-graph-view?).
|
||||
|
||||
### Include types
|
||||
Only the file types which are selected here will show up in the overview.
|
||||
|
||||
### Show folder notes
|
||||
Show the file itself which is linked to one folder.
|
||||
|
||||
### File depth
|
||||
Limit the depth of files/folders which are shown in the overview. When it is at depth one only the first level files/folders will be shown. When you can't see the childrens of folder the name won't be shown except when you enable ["Show folder names of folders that appear empty in the folder overview"](#show-folder-names-of-folders-that-appear-empty-in-the-folder-overview) or the folder has a file linked to it.
|
||||
|
||||
### Sort files by
|
||||
Choose the order of files and folders.
|
||||
|
||||
### Show folder names of folders that appear empty in the folder overview
|
||||
When folders don't have any childrens they don't show up until you enable this setting but they also don't show up until you set the "File depth" setting until the level of the children of a folder. For example you can see "Folder1" at level 2 and their children at level 3 and the folder name gets shown at level 3 or when you enable this setting.
|
||||
To edit the settings for a new folder overview that hasn't been created yet you have to open the plugin settings and go to the folder overview tab and click on the manage button.
|
||||

|
||||
|
|
|
|||
|
|
@ -3,6 +3,20 @@
|
|||
## How to install the plugin
|
||||
The plugin can be downloaded by clicking on [https://obsidian.md/plugins?id=folder-notes](https://obsidian.md/plugins?id=folder-notes) and then on install.
|
||||
## Basic features
|
||||
### Create folder overview
|
||||
Find more out about the folder overview feature on the [folder overview page](./Folder%20overview.md)
|
||||
|
||||
To create a folder overview in a note either use the command "Insert folder overview" or on pc right click and select "create folder overview"
|
||||
|
||||
{: style="max-width: 40%;max-height: 40%"}
|
||||
|
||||
The folder overview with the default settings looks like this with one note
|
||||
|
||||

|
||||
|
||||
To edit the folder overview click on the little icon on the right that is shown when hovering over the codeblock
|
||||
|
||||

|
||||
|
||||
### Create folder note
|
||||
|
||||
|
|
@ -16,7 +30,7 @@ On PC either use ctrl or strg (depending on your settings) and then click on a f
|
|||
|
||||
Open the [command palette](https://help.obsidian.md/Plugins/Command+palette) and then type "folder notes" and select the command you need.
|
||||
|
||||

|
||||

|
||||
|
||||
### Open folder note
|
||||
|
||||
|
|
@ -30,17 +44,7 @@ The second option is to open one file of the files from the folder from which yo
|
|||
|
||||
The last option and the option that is only available to desktop users is to use alt or ctrl and click on the folder name. When you don't hold ctrl/alt and click on a folder name the folder gets collapsed as normal. To use this option you first have to enable it in the plugin settings under the tab general.
|
||||
|
||||

|
||||

|
||||
|
||||
### Create folder overview
|
||||
Find more out about the folder overview feature on the [folder overview page](./Folder%20overview.md)
|
||||
|
||||
To create a folder overview in a note either use the command "Insert folder overview" or on pc right click and select "create folder overview"
|
||||
|
||||
{: style="max-width: 40%;max-height: 40%"}
|
||||
|
||||
The folder overview with the default settings looks like this with one note
|
||||
|
||||

|
||||
To find out how to edit the folder overview have a look at [folder overview page](./Folder%20overview.md)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
# Troubleshooting
|
||||
## Folder with folder note still collapses
|
||||
Issue: You've "Disable folder collapsing" enabled, click on a folder name that has folder note linked to it and it still collapses.
|
||||
|
||||
Possible cause & solution: You've "auto-reveal current file" enabled and need to disable it in order to make this feature work.
|
||||
|
||||

|
||||
BIN
docs/docs/assets/ngkJjEcxUUTkX6eB4mSs.png
Normal file
|
After Width: | Height: | Size: 51 KiB |
|
Before Width: | Height: | Size: 19 KiB |
|
Before Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 47 KiB |
|
Before Width: | Height: | Size: 102 KiB |
|
Before Width: | Height: | Size: 88 KiB |
|
|
@ -1,32 +1,30 @@
|
|||
# Overview
|
||||
Folder Notes is a plugin for the note-taking app [Obsidian](https://obsidian.md/) that allows you to attach notes directly to folders. This lets you open a note by clicking on a folder name—similar to the functionality found in [Notion](https://www.notion.so/).
|
||||
|
||||
Unlike other “folder note” plugins, Folder Notes offers several unique features, including support for custom file types, templating, and advanced folder handling options.
|
||||
|
||||
Folder notes is a plugin for the note taking app [Obsidian](https://obsidian.md/) that lets you attach notes to folders so that you can click on the name of a folder to open the note like in the app [Notion](https://www.notion.so/).
|
||||
This plugin has some unique features that separate it from similar "Folder note" plugins like opening folder notes through the path, creating folder notes for every existing folder, templater/template support and more.
|
||||
## Features
|
||||
- Open folder notes through the file explorer/path by clicking on folder names
|
||||
- Only open folder notes through alt or ctrl + mouse click
|
||||
- Excalidraw, Canvas, ... folder notes unlimited file type folder notes
|
||||
- Sync folder note name with the folder name
|
||||
- Automatically create folder notes when creating folders
|
||||
- Turn every folder into a folder note
|
||||
- Folder overview code block with default settings in settings from the plugin
|
||||
- Hide folder notes in the file explorer
|
||||
- Underline, bold and cursive folder names in the file explorer/path option
|
||||
- Stop collapsing of folders (with folder notes) in the file explorer
|
||||
- Only open folder note through the folder name and the rest collapses the folder
|
||||
- Front matter title plugin support
|
||||
- Exclude folders with regex, path and a pattern with \*
|
||||
## Get started
|
||||
|
||||
Read the [Getting started page](Getting%20started.md) for further details and the pages under the "Features" category explain every feature in detail.
|
||||
## Features
|
||||
- Open folder notes by clicking folder names in the file explorer or path
|
||||
- Optional modifier key (Alt or Ctrl + click) to open folder notes
|
||||
- Full support for any file type as folder notes (e.g., Excalidraw, Canvas, etc.)
|
||||
- Automatically sync folder note names with their folder names
|
||||
- Auto-create a folder note when a new folder is created
|
||||
- Convert all existing folders into folder notes
|
||||
- Use a folder-overview code block with configurable default settings
|
||||
- Option to hide folder notes from the file explorer
|
||||
- Style folder names (underline, bold, italic) in the file explorer or path
|
||||
- Prevent automatic collapsing of folders that have folder notes
|
||||
- Choose to only open the folder note when clicking the folder name; other clicks collapse the folder
|
||||
- Front matter title plugin support
|
||||
- Exclude specific folders using regex, path, or wildcard patterns (`*`)
|
||||
Read the [Getting started page](Getting%20started.md) for further details.
|
||||
|
||||
## Credits
|
||||
Thank you to everyone who has created a plugin that inspired me and I took code from.
|
||||
- Template suggester, created by [SilentVoid13](https://github.com/SilentVoid13) and [Liamcain](https://github.com/liamcain) (their plugins: [Templater](https://github.com/SilentVoid13/Templater/), [Periodic notes](https://github.com/liamcain/obsidian-periodic-notes))
|
||||
- Apply template to note, first seen in [https://github.com/mgmeyers/obsidian-kanban/](https://github.com/mgmeyers/obsidian-kanban/) from [Mgmeyers](https://github.com/mgmeyers)
|
||||
- Folder underline, inspired from [https://github.com/aidenlx/alx-folder-note](https://github.com/aidenlx/alx-folder-note)
|
||||
- Stop folders from collapsing, the basic idea from [https://github.com/alangrainger/obsidian-folder-notes](https://github.com/alangrainger/obsidian-folder-notes)
|
||||
- Stop folders from collapsing, the basic idea from [https://github.com/alangrainger/obsidian-folder-notes](https://github.com/alangrainger/obsidian-folder-notes) and some code lines
|
||||
- The basic idea is from [https://github.com/xpgo/obsidian-folder-note-plugin](https://github.com/xpgo/obsidian-folder-note-plugin)
|
||||
|
||||
## Support the development of the plugin
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@ site_name: Obsidian folder notes
|
|||
theme:
|
||||
name: material
|
||||
logo: assets/2023_Obsidian_logo.svg.png
|
||||
features:
|
||||
- navigation.expand
|
||||
palette:
|
||||
- media: "(prefers-color-scheme: light)"
|
||||
scheme: default
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ esbuild.build({
|
|||
'@lezer/common',
|
||||
'@lezer/highlight',
|
||||
'@lezer/lr',
|
||||
"f:/Obsidian/test/.obsidian/plugins/obsidian-folder-notes/node_modules/obsidian",
|
||||
...builtins],
|
||||
format: 'cjs',
|
||||
watch: !prod,
|
||||
|
|
|
|||
|
|
@ -1,177 +0,0 @@
|
|||
import obsidianmd from "eslint-plugin-obsidianmd";
|
||||
import tseslint from "typescript-eslint";
|
||||
|
||||
export default [
|
||||
{
|
||||
files: ["**/*.ts"],
|
||||
languageOptions: {
|
||||
parser: tseslint.parser,
|
||||
parserOptions: {
|
||||
sourceType: "module"
|
||||
}
|
||||
},
|
||||
ignores: [
|
||||
"**/node_modules/**",
|
||||
"**/dist/**",
|
||||
],
|
||||
plugins: {
|
||||
"@typescript-eslint": tseslint.plugin,
|
||||
obsidianmd
|
||||
},
|
||||
rules: {
|
||||
"obsidianmd/no-tfile-tfolder-cast": "error",
|
||||
"obsidianmd/rule-custom-message": [
|
||||
"error",
|
||||
{
|
||||
"no-console": {
|
||||
messages: {
|
||||
"Unexpected console statement. Only these console methods are allowed: warn, error, debug.": "Avoid unnecessary logging to console. See https://docs.obsidian.md/Plugins/Releasing/Plugin+guidelines#Avoid+unnecessary+logging+to+console",
|
||||
},
|
||||
options: [{ allow: ["warn", "error", "debug"] }],
|
||||
}
|
||||
}
|
||||
],
|
||||
"no-unused-vars": "off",
|
||||
"quotes": [
|
||||
"error",
|
||||
"single",
|
||||
{
|
||||
"avoidEscape": true
|
||||
}
|
||||
],
|
||||
"no-mixed-spaces-and-tabs": "error",
|
||||
"indent": [
|
||||
"error",
|
||||
"tab",
|
||||
{
|
||||
"SwitchCase": 1
|
||||
}
|
||||
],
|
||||
"arrow-parens": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"eol-last": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"func-call-spacing": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"comma-dangle": [
|
||||
"error",
|
||||
"always-multiline"
|
||||
],
|
||||
"no-multi-spaces": "error",
|
||||
"no-trailing-spaces": "error",
|
||||
"no-whitespace-before-property": "off",
|
||||
"semi": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"semi-style": [
|
||||
"error",
|
||||
"last"
|
||||
],
|
||||
"space-in-parens": [
|
||||
"error",
|
||||
"never"
|
||||
],
|
||||
"block-spacing": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"object-curly-spacing": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"eqeqeq": [
|
||||
"error",
|
||||
"always",
|
||||
{
|
||||
"null": "ignore"
|
||||
}
|
||||
],
|
||||
"spaced-comment": [
|
||||
"error",
|
||||
"always",
|
||||
{
|
||||
"markers": [
|
||||
"!"
|
||||
]
|
||||
}
|
||||
],
|
||||
"yoda": "error",
|
||||
"prefer-destructuring": [
|
||||
"error",
|
||||
{
|
||||
"object": true,
|
||||
"array": false
|
||||
}
|
||||
],
|
||||
"operator-assignment": [
|
||||
"error",
|
||||
"always"
|
||||
],
|
||||
"no-useless-computed-key": "error",
|
||||
"no-unneeded-ternary": [
|
||||
"error",
|
||||
{
|
||||
"defaultAssignment": false
|
||||
}
|
||||
],
|
||||
"no-invalid-regexp": "error",
|
||||
"no-constant-condition": [
|
||||
"error",
|
||||
{
|
||||
"checkLoops": false
|
||||
}
|
||||
],
|
||||
"no-duplicate-imports": "error",
|
||||
"no-extra-semi": "error",
|
||||
"dot-notation": "error",
|
||||
"no-useless-escape": "error",
|
||||
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
|
||||
'@typescript-eslint/no-explicit-any': 'warn',
|
||||
'@typescript-eslint/consistent-type-imports': 'error',
|
||||
'@typescript-eslint/consistent-type-definitions': [
|
||||
'error',
|
||||
'interface'],
|
||||
'@typescript-eslint/explicit-function-return-type': 'warn',
|
||||
'@typescript-eslint/ban-ts-comment': 'warn',
|
||||
'array-bracket-spacing': [
|
||||
'error', 'never'],
|
||||
'linebreak-style': [
|
||||
'error',
|
||||
'unix'
|
||||
],
|
||||
'no-nested-ternary': 'error',
|
||||
'no-shadow': 'error',
|
||||
'no-return-await': 'error',
|
||||
'no-else-return': 'error',
|
||||
'no-empty-function': 'warn',
|
||||
'complexity': [
|
||||
'warn',
|
||||
15
|
||||
],
|
||||
'max-len': [
|
||||
'warn', {
|
||||
code: 110,
|
||||
ignoreComments: true,
|
||||
}
|
||||
],
|
||||
'no-inline-comments': 'warn',
|
||||
'no-magic-numbers': [
|
||||
'warn', {
|
||||
ignore: [0, 1],
|
||||
enforceConst: true,
|
||||
ignoreTypeIndexes: true,
|
||||
ignoreEnums: true,
|
||||
ignoreNumericLiteralTypes: true,
|
||||
ignoreClassFieldInitialValues: true,
|
||||
}
|
||||
],
|
||||
}
|
||||
}
|
||||
];
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "folder-notes",
|
||||
"name": "Folder notes beta",
|
||||
"version": "1.8.20-1-beta",
|
||||
"version": "1.8.1-2-beta",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Create notes within folders that can be accessed without collapsing the folder, similar to the functionality offered in Notion.",
|
||||
"author": "Lost Paul",
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"id": "folder-notes",
|
||||
"name": "Folder notes",
|
||||
"version": "1.8.26",
|
||||
"minAppVersion": "1.4.10",
|
||||
"version": "1.7.35",
|
||||
"minAppVersion": "0.15.0",
|
||||
"description": "Create notes within folders that can be accessed without collapsing the folder, similar to the functionality offered in Notion.",
|
||||
"author": "Lost Paul",
|
||||
"authorUrl": "https://github.com/LostPaul",
|
||||
"fundingUrl": "https://ko-fi.com/paul305844",
|
||||
"helpUrl": "https://lostpaul.github.io/obsidian-folder-notes/",
|
||||
"isDesktopOnly": false
|
||||
}
|
||||
}
|
||||
11409
package-lock.json
generated
13
package.json
|
|
@ -10,28 +10,23 @@
|
|||
"fv-build": "tsc -noEmit -skipLibCheck && node ./src/obsidian-folder-overview/esbuild.config.mjs production",
|
||||
"version": "node version-bump.mjs && git add manifest.json versions.json",
|
||||
"folder-overview": "node ./src/obsidian-folder-overview/esbuild.config.mjs",
|
||||
|
||||
"fv-dev": "npm run folder-overview"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "Lost Paul",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^8.57.1",
|
||||
"@types/node": "^16.11.6",
|
||||
"@typescript-eslint/eslint-plugin": "^8.60.0",
|
||||
"@typescript-eslint/parser": "^8.60.0",
|
||||
"@typescript-eslint/eslint-plugin": "5.29.0",
|
||||
"@typescript-eslint/parser": "5.29.0",
|
||||
"builtin-modules": "3.3.0",
|
||||
"esbuild": "0.14.47",
|
||||
"eslint": "^10.4.1",
|
||||
"eslint-plugin-obsidianmd": "^0.3.0",
|
||||
"front-matter-plugin-api-provider": "^0.1.4-alpha",
|
||||
"globals": "^16.3.0",
|
||||
"jiti": "^2.5.1",
|
||||
"obsidian": "latest",
|
||||
"obsidian-typings": "^2.2.0",
|
||||
"tslib": "2.4.0",
|
||||
"typescript": "^6.0.3",
|
||||
"typescript-eslint": "^8.38.0"
|
||||
"typescript": "4.7.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@popperjs/core": "^2.11.6"
|
||||
|
|
|
|||
607
src/Commands.ts
|
|
@ -1,38 +1,11 @@
|
|||
import {
|
||||
TFolder,
|
||||
Notice,
|
||||
TFile,
|
||||
Platform,
|
||||
type App,
|
||||
type Menu,
|
||||
type TAbstractFile,
|
||||
type Editor,
|
||||
type MarkdownView,
|
||||
type MarkdownFileInfo,
|
||||
} from 'obsidian';
|
||||
import type FolderNotesPlugin from './main';
|
||||
import {
|
||||
getFolderNote,
|
||||
createFolderNote,
|
||||
deleteFolderNote,
|
||||
turnIntoFolderNote,
|
||||
openFolderNote,
|
||||
extractFolderName,
|
||||
detachFolderNote,
|
||||
} from './functions/folderNoteFunctions';
|
||||
import { App, TFolder, Menu, TAbstractFile, Notice, TFile, Editor, MarkdownView, Platform, stringifyYaml } from 'obsidian';
|
||||
import FolderNotesPlugin from './main';
|
||||
import { getFolderNote, createFolderNote, deleteFolderNote, turnIntoFolderNote, openFolderNote, extractFolderName, detachFolderNote } from './functions/folderNoteFunctions';
|
||||
import { ExcludedFolder } from './ExcludeFolders/ExcludeFolder';
|
||||
import { getFolderPathFromString, getFileExplorerActiveFolder } from './functions/utils';
|
||||
import {
|
||||
deleteExcludedFolder,
|
||||
getDetachedFolder,
|
||||
getExcludedFolder,
|
||||
} from './ExcludeFolders/functions/folderFunctions';
|
||||
import {
|
||||
hideFolderNoteInFileExplorer,
|
||||
showFolderNoteInFileExplorer,
|
||||
} from './functions/styleFunctions';
|
||||
import { addExcludedFolder, deleteExcludedFolder, getDetachedFolder, getExcludedFolder } from './ExcludeFolders/functions/folderFunctions';
|
||||
import { applyCSSClassesToFolder } from './functions/styleFunctions';
|
||||
|
||||
type MarkdownEditorContext = MarkdownView | MarkdownFileInfo;
|
||||
|
||||
|
||||
export class Commands {
|
||||
|
|
@ -42,33 +15,28 @@ export class Commands {
|
|||
this.plugin = plugin;
|
||||
this.app = app;
|
||||
}
|
||||
registerCommands(): void {
|
||||
registerCommands() {
|
||||
this.editorCommands();
|
||||
this.fileCommands();
|
||||
this.regularCommands();
|
||||
}
|
||||
|
||||
regularCommands(): void {
|
||||
regularCommands() {
|
||||
this.plugin.addCommand({
|
||||
id: 'turn-into-folder-note',
|
||||
name: 'Use this file as the folder note for its parent folder',
|
||||
checkCallback: (checking: boolean) => {
|
||||
name: 'Make current active note a folder note for the folder of the active note',
|
||||
callback: () => {
|
||||
const file = this.app.workspace.getActiveFile();
|
||||
if (!(file instanceof TFile)) return false;
|
||||
if (!(file instanceof TFile)) return;
|
||||
const folder = file.parent;
|
||||
if (!folder || !(folder instanceof TFolder)) return false;
|
||||
// Only show if file is NOT in the root folder
|
||||
if (folder.path === '' || folder.path === '/') return false;
|
||||
if (!(folder instanceof TFolder)) return;
|
||||
const folderNote = getFolderNote(this.plugin, folder.path);
|
||||
if (folderNote instanceof TFile && folderNote === file) return false;
|
||||
if (checking) return true;
|
||||
void turnIntoFolderNote(this.plugin, file, folder, folderNote);
|
||||
turnIntoFolderNote(this.plugin, file, folder, folderNote);
|
||||
},
|
||||
});
|
||||
|
||||
this.plugin.addCommand({
|
||||
id: 'create-folder-note',
|
||||
name: 'Make a folder with this file as its folder note',
|
||||
name: 'Create folder note with a new folder for the active note in the current folder',
|
||||
callback: async () => {
|
||||
const file = this.app.workspace.getActiveFile();
|
||||
if (!(file instanceof TFile)) return;
|
||||
|
|
@ -79,30 +47,27 @@ export class Commands {
|
|||
if (this.plugin.app.vault.getAbstractFileByPath(newPath)) {
|
||||
return new Notice('Folder already exists');
|
||||
}
|
||||
const automaticallyCreateFolderNote =
|
||||
this.plugin.settings.autoCreate;
|
||||
const automaticallyCreateFolderNote = this.plugin.settings.autoCreate;
|
||||
this.plugin.settings.autoCreate = false;
|
||||
void this.plugin.saveSettings();
|
||||
this.plugin.saveSettings();
|
||||
await this.plugin.app.vault.createFolder(newPath);
|
||||
const folder = this.plugin.app.vault.getAbstractFileByPath(newPath);
|
||||
if (!(folder instanceof TFolder)) return;
|
||||
await createFolderNote(this.plugin, folder.path, true, '.' + file.extension, false, file);
|
||||
createFolderNote(this.plugin, folder.path, true, '.' + file.extension, false, file);
|
||||
this.plugin.settings.autoCreate = automaticallyCreateFolderNote;
|
||||
void this.plugin.saveSettings();
|
||||
this.plugin.saveSettings();
|
||||
},
|
||||
});
|
||||
|
||||
this.plugin.addCommand({
|
||||
id: 'create-folder-note-for-current-folder',
|
||||
name: 'Create Markdown folder note for this folder',
|
||||
checkCallback: (checking) => {
|
||||
name: 'Create markdown folder note for current folder of active note',
|
||||
callback: () => {
|
||||
const file = this.app.workspace.getActiveFile();
|
||||
if (!(file instanceof TFile)) return false;
|
||||
if (!(file instanceof TFile)) return;
|
||||
const folder = file.parent;
|
||||
if (!(folder instanceof TFolder)) return false;
|
||||
if (folder.path === '' || folder.path === '/') return false;
|
||||
if (checking) return true;
|
||||
void createFolderNote(this.plugin, folder.path, true, '.md', false);
|
||||
if (!(folder instanceof TFolder)) return;
|
||||
createFolderNote(this.plugin, folder.path, true, '.md', false);
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -110,15 +75,13 @@ export class Commands {
|
|||
if (fileType === 'md') return;
|
||||
this.plugin.addCommand({
|
||||
id: `create-${fileType}-folder-note-for-current-folder`,
|
||||
name: `Create ${fileType} folder note for this folder`,
|
||||
checkCallback: (checking) => {
|
||||
name: `Create ${fileType} folder note for current folder of active note`,
|
||||
callback: () => {
|
||||
const file = this.app.workspace.getActiveFile();
|
||||
if (!(file instanceof TFile)) return false;
|
||||
if (!(file instanceof TFile)) return;
|
||||
const folder = file.parent;
|
||||
if (!(folder instanceof TFolder)) return false;
|
||||
if (folder.path === '' || folder.path === '/') return false;
|
||||
if (checking) return true;
|
||||
void createFolderNote(this.plugin, folder.path, true, '.' + fileType, false);
|
||||
if (!(folder instanceof TFolder)) return;
|
||||
createFolderNote(this.plugin, folder.path, true, '.' + fileType, false);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
|
@ -128,7 +91,7 @@ export class Commands {
|
|||
id: `create-${type}-folder-note-for-active-file-explorer-folder`,
|
||||
name: `Create ${type} folder note for current active folder in file explorer`,
|
||||
checkCallback: (checking: boolean) => {
|
||||
const folder = getFileExplorerActiveFolder(this.plugin);
|
||||
const folder = getFileExplorerActiveFolder();
|
||||
if (!folder) return false;
|
||||
// Is there already a folder note for the active folder?
|
||||
const folderNote = getFolderNote(this.plugin, folder.path);
|
||||
|
|
@ -137,24 +100,23 @@ export class Commands {
|
|||
|
||||
// Everything is fine and not checking, let's create the folder note.
|
||||
const ext = '.' + fileType;
|
||||
const { path } = folder;
|
||||
void createFolderNote(this.plugin, path, true, ext, false);
|
||||
const path = folder.path;
|
||||
createFolderNote(this.plugin, path, true, ext, false);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
this.plugin.addCommand({
|
||||
id: 'delete-folder-note-for-current-folder',
|
||||
name: 'Delete this folder\'s linked note',
|
||||
checkCallback: (checking) => {
|
||||
name: 'Delete folder note of current folder of active note',
|
||||
callback: () => {
|
||||
const file = this.app.workspace.getActiveFile();
|
||||
if (!(file instanceof TFile)) return false;
|
||||
if (!(file instanceof TFile)) return;
|
||||
const folder = file.parent;
|
||||
if (!(folder instanceof TFolder)) return false;
|
||||
if (!(folder instanceof TFolder)) return;
|
||||
const folderNote = getFolderNote(this.plugin, folder.path);
|
||||
if (!(folderNote instanceof TFile)) return false;
|
||||
if (checking) return true;
|
||||
void deleteFolderNote(this.plugin, folderNote, true);
|
||||
if (!(folderNote instanceof TFile)) return;
|
||||
deleteFolderNote(this.plugin, folderNote, true);
|
||||
},
|
||||
});
|
||||
|
||||
|
|
@ -162,7 +124,7 @@ export class Commands {
|
|||
id: 'delete-folder-note-of-active-file-explorer-folder',
|
||||
name: 'Delete folder note of current active folder in file explorer',
|
||||
checkCallback: (checking: boolean) => {
|
||||
const folder = getFileExplorerActiveFolder(this.plugin);
|
||||
const folder = getFileExplorerActiveFolder();
|
||||
if (!folder) return false;
|
||||
// Is there any folder note for the active folder?
|
||||
const folderNote = getFolderNote(this.plugin, folder.path);
|
||||
|
|
@ -170,28 +132,27 @@ export class Commands {
|
|||
if (checking) return true;
|
||||
|
||||
// Everything is fine and not checking, let's delete the folder note.
|
||||
void deleteFolderNote(this.plugin, folderNote, true);
|
||||
deleteFolderNote(this.plugin, folderNote, true);
|
||||
},
|
||||
});
|
||||
this.plugin.addCommand({
|
||||
id: 'open-folder-note-for-current-folder',
|
||||
name: 'Open this folder\'s linked note',
|
||||
checkCallback: (checking) => {
|
||||
name: 'Open folder note of current folder of active note',
|
||||
callback: () => {
|
||||
const file = this.app.workspace.getActiveFile();
|
||||
if (!(file instanceof TFile)) return false;
|
||||
if (!(file instanceof TFile)) return;
|
||||
const folder = file.parent;
|
||||
if (!(folder instanceof TFolder)) return false;
|
||||
if (!(folder instanceof TFolder)) return;
|
||||
const folderNote = getFolderNote(this.plugin, folder.path);
|
||||
if (!(folderNote instanceof TFile)) return false;
|
||||
if (checking) return true;
|
||||
void openFolderNote(this.plugin, folderNote);
|
||||
if (!(folderNote instanceof TFile)) return;
|
||||
openFolderNote(this.plugin, folderNote);
|
||||
},
|
||||
});
|
||||
this.plugin.addCommand({
|
||||
id: 'open-folder-note-of-active-file-explorer-folder',
|
||||
name: 'Open folder note of current active folder in file explorer',
|
||||
checkCallback: (checking: boolean) => {
|
||||
const folder = getFileExplorerActiveFolder(this.plugin);
|
||||
const folder = getFileExplorerActiveFolder();
|
||||
if (!folder) return false;
|
||||
// Is there any folder note for the active folder?
|
||||
const folderNote = getFolderNote(this.plugin, folder.path);
|
||||
|
|
@ -199,23 +160,49 @@ export class Commands {
|
|||
if (checking) return true;
|
||||
|
||||
// Everything is fine and not checking, let's open the folder note.
|
||||
void openFolderNote(this.plugin, folderNote);
|
||||
openFolderNote(this.plugin, folderNote);
|
||||
},
|
||||
});
|
||||
this.plugin.addCommand({
|
||||
id: 'insert-folder-overview-fn',
|
||||
name: 'Insert folder overview',
|
||||
editorCheckCallback: (checking: boolean, editor: Editor) => {
|
||||
const line = editor.getCursor().line;
|
||||
const lineText = editor.getLine(line);
|
||||
if (lineText.trim() === '' || lineText.trim() === '>') {
|
||||
if (!checking) {
|
||||
const json = Object.assign({}, this.plugin.settings.defaultOverview);
|
||||
json.id = crypto.randomUUID();
|
||||
const yaml = stringifyYaml(json);
|
||||
if (lineText.trim() === '') {
|
||||
editor.replaceSelection(`\`\`\`folder-overview\n${yaml}\`\`\`\n`);
|
||||
} else if (lineText.trim() === '>') {
|
||||
// add > to the beginning of each line
|
||||
const lines = yaml.split('\n');
|
||||
const newLines = lines.map((line) => {
|
||||
return `> ${line}`;
|
||||
});
|
||||
editor.replaceSelection(`\`\`\`folder-overview\n${newLines.join('\n')}\`\`\`\n`);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
});
|
||||
|
||||
this.plugin.addCommand({
|
||||
id: 'create-folder-note-from-selected-text',
|
||||
name: 'Create folder note from selection',
|
||||
editorCheckCallback: (checking: boolean, editor: Editor, view: MarkdownEditorContext) => {
|
||||
name: 'Create folder note from selected text',
|
||||
editorCheckCallback: (checking: boolean, editor: Editor, view: MarkdownView) => {
|
||||
const text = editor.getSelection().trim();
|
||||
const { file } = view;
|
||||
const file = view.file;
|
||||
if (!(file instanceof TFile)) return false;
|
||||
if (text && text.trim() !== '') {
|
||||
if (checking) { return true; }
|
||||
const blacklist = ['*', '\\', '"', '/', '<', '>', '?', '|', ':'];
|
||||
for (const char of blacklist) {
|
||||
if (text.includes(char)) {
|
||||
// eslint-disable-next-line max-len
|
||||
new Notice('File name cannot contain any of the following characters: * " \\ / < > : | ?');
|
||||
return false;
|
||||
}
|
||||
|
|
@ -231,33 +218,26 @@ export class Commands {
|
|||
if (folder instanceof TFolder) {
|
||||
new Notice('Folder note already exists');
|
||||
return false;
|
||||
} else {
|
||||
this.plugin.app.vault.createFolder(text);
|
||||
createFolderNote(this.plugin, text, false);
|
||||
}
|
||||
void this.plugin.app.vault.createFolder(text);
|
||||
void createFolderNote(this.plugin, text, false);
|
||||
|
||||
} else {
|
||||
const folderFullPath = folderPath + '/' + text;
|
||||
folder = this.plugin.app.vault.getAbstractFileByPath(folderFullPath);
|
||||
folder = this.plugin.app.vault.getAbstractFileByPath(folderPath + '/' + text);
|
||||
if (folder instanceof TFolder) {
|
||||
new Notice('Folder note already exists');
|
||||
return false;
|
||||
}
|
||||
if (this.plugin.settings.storageLocation === 'parentFolder') {
|
||||
if (
|
||||
this.app.vault.getAbstractFileByPath(
|
||||
folderPath + '/' + text + this.plugin.settings.folderNoteType,
|
||||
)
|
||||
) {
|
||||
if (this.app.vault.getAbstractFileByPath(folderPath + '/' + text + this.plugin.settings.folderNoteType)) {
|
||||
new Notice('File already exists');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
void this.plugin.app.vault.createFolder(folderPath + '/' + text);
|
||||
void createFolderNote(this.plugin, folderPath + '/' + text, false);
|
||||
this.plugin.app.vault.createFolder(folderPath + '/' + text);
|
||||
createFolderNote(this.plugin, folderPath + '/' + text, false);
|
||||
}
|
||||
|
||||
const { folderNoteName } = this.plugin.settings;
|
||||
const fileName = folderNoteName.replace('{{folder_name}}', text);
|
||||
const fileName = this.plugin.settings.folderNoteName.replace('{{folder_name}}', text);
|
||||
if (fileName !== text) {
|
||||
editor.replaceSelection(`[[${fileName}]]`);
|
||||
} else {
|
||||
|
|
@ -270,44 +250,52 @@ export class Commands {
|
|||
});
|
||||
}
|
||||
|
||||
fileCommands(): void {
|
||||
this.plugin.registerEvent(
|
||||
// eslint-disable-next-line complexity
|
||||
this.app.workspace.on('file-menu', (menu: Menu, file: TAbstractFile) => {
|
||||
let folder: TAbstractFile | TFolder | null = file.parent;
|
||||
if (file instanceof TFile) {
|
||||
if (this.plugin.settings.storageLocation === 'insideFolder') {
|
||||
folder = file.parent;
|
||||
} else {
|
||||
const { folderNoteName } = this.plugin.settings;
|
||||
const fileName = extractFolderName(folderNoteName, file.basename);
|
||||
if (fileName) {
|
||||
if (file.parent?.path === '' || file.parent?.path === '/') {
|
||||
folder = this.plugin.app.vault.getAbstractFileByPath(fileName);
|
||||
} else {
|
||||
folder = this.plugin.app.vault.getAbstractFileByPath(
|
||||
file.parent?.path + '/' + fileName,
|
||||
);
|
||||
}
|
||||
fileCommands() {
|
||||
this.plugin.registerEvent(this.app.workspace.on('file-menu', (menu: Menu, file: TAbstractFile) => {
|
||||
let folder: TAbstractFile | TFolder | null = file.parent;
|
||||
if (file instanceof TFile) {
|
||||
if (this.plugin.settings.storageLocation === 'insideFolder') {
|
||||
folder = file.parent;
|
||||
} else {
|
||||
const fileName = extractFolderName(this.plugin.settings.folderNoteName, file.basename);
|
||||
if (fileName) {
|
||||
if (file.parent?.path === '' || file.parent?.path === '/') {
|
||||
folder = this.plugin.app.vault.getAbstractFileByPath(fileName);
|
||||
} else {
|
||||
folder = this.plugin.app.vault.getAbstractFileByPath(file.parent?.path + '/' + fileName);
|
||||
}
|
||||
}
|
||||
|
||||
if (folder instanceof TFolder) {
|
||||
const folderNote = getFolderNote(this.plugin, folder.path);
|
||||
const excludedFolder = getExcludedFolder(this.plugin, folder.path, true);
|
||||
if (folderNote?.path === file.path && !excludedFolder?.detached) { return; }
|
||||
} else if (file.parent instanceof TFolder) {
|
||||
folder = file.parent;
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
const addFolderNoteActions = (folderMenu: Menu): void => {
|
||||
if (file instanceof TFile) {
|
||||
folderMenu.addItem((item) => {
|
||||
item.setTitle('Create folder note');
|
||||
item.setIcon('edit');
|
||||
item.onClick(async () => {
|
||||
if (folder instanceof TFolder) {
|
||||
const folderNote = getFolderNote(this.plugin, folder.path);
|
||||
const excludedFolder = getExcludedFolder(this.plugin, folder.path, true);
|
||||
if (folderNote?.path === file.path && !excludedFolder?.detached) { return; }
|
||||
} else if (file.parent instanceof TFolder) {
|
||||
folder = file.parent;
|
||||
}
|
||||
}
|
||||
|
||||
menu.addItem(async (item) => {
|
||||
if (Platform.isDesktop && !Platform.isTablet && this.plugin.settings.useSubmenus) {
|
||||
item
|
||||
.setTitle('Folder Note Commands')
|
||||
.setIcon('folder-edit');
|
||||
}
|
||||
let subMenu: Menu;
|
||||
if (!Platform.isDesktopApp || !Platform.isDesktop || Platform.isTablet || !this.plugin.settings.useSubmenus) {
|
||||
subMenu = menu;
|
||||
item.setDisabled(true);
|
||||
} else {
|
||||
// @ts-ignore
|
||||
subMenu = item.setSubmenu() as Menu;
|
||||
}
|
||||
if (file instanceof TFile) {
|
||||
// @ts-ignore
|
||||
subMenu.addItem((item) => {
|
||||
item.setTitle('Create folder note')
|
||||
.setIcon('edit')
|
||||
.onClick(async () => {
|
||||
if (!folder) return;
|
||||
let newPath = folder.path + '/' + file.basename;
|
||||
if (folder.path === '' || folder.path === '/') {
|
||||
|
|
@ -316,217 +304,185 @@ export class Commands {
|
|||
if (this.plugin.app.vault.getAbstractFileByPath(newPath)) {
|
||||
return new Notice('Folder already exists');
|
||||
}
|
||||
const automaticallyCreateFolderNote =
|
||||
this.plugin.settings.autoCreate;
|
||||
const automaticallyCreateFolderNote = this.plugin.settings.autoCreate;
|
||||
this.plugin.settings.autoCreate = false;
|
||||
void this.plugin.saveSettings();
|
||||
this.plugin.saveSettings();
|
||||
await this.plugin.app.vault.createFolder(newPath);
|
||||
const newFolder = this.plugin.app.vault
|
||||
.getAbstractFileByPath(newPath);
|
||||
const newFolder = this.plugin.app.vault.getAbstractFileByPath(newPath);
|
||||
if (!(newFolder instanceof TFolder)) return;
|
||||
await createFolderNote(
|
||||
this.plugin,
|
||||
newFolder.path,
|
||||
true,
|
||||
'.' + file.extension,
|
||||
false,
|
||||
file,
|
||||
);
|
||||
await createFolderNote(this.plugin, newFolder.path, true, '.' + file.extension, false, file);
|
||||
this.plugin.settings.autoCreate = automaticallyCreateFolderNote;
|
||||
void this.plugin.saveSettings();
|
||||
this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
if (getFolderPathFromString(file.path) === '') return;
|
||||
|
||||
if (!(folder instanceof TFolder)) return;
|
||||
|
||||
if (folder.path === '' || folder.path === '/') return;
|
||||
|
||||
folderMenu.addItem((item) => {
|
||||
item.setTitle(`Turn into folder note for ${folder?.name}`);
|
||||
item.setIcon('edit');
|
||||
item.onClick(() => {
|
||||
});
|
||||
if (getFolderPathFromString(file.path) === '') return;
|
||||
if (!(folder instanceof TFolder)) return;
|
||||
subMenu.addItem((item) => {
|
||||
item.setTitle(`Turn into folder note for ${folder?.name}`)
|
||||
.setIcon('edit')
|
||||
.onClick(() => {
|
||||
if (!folder || !(folder instanceof TFolder)) return;
|
||||
const folderNote = getFolderNote(this.plugin, folder.path);
|
||||
void turnIntoFolderNote(this.plugin, file, folder, folderNote);
|
||||
turnIntoFolderNote(this.plugin, file, folder, folderNote);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (!(file instanceof TFolder)) return;
|
||||
|
||||
const excludedFolder = getExcludedFolder(this.plugin, file.path, false);
|
||||
const detachedExcludedFolder = getDetachedFolder(this.plugin, file.path);
|
||||
|
||||
if (excludedFolder && !excludedFolder.hideInSettings) {
|
||||
// I'm not sure if I'm ever going to add this because of the possibility that a folder got more than one excluded
|
||||
// menu.addItem((item) => {
|
||||
// item.setTitle('Manage excluded folder');
|
||||
// item.setIcon('settings-2');
|
||||
// item.onClick(() => {
|
||||
// if (excludedFolder instanceof ExcludedFolder) {
|
||||
// new ExcludedFolderSettings(this.plugin.app, this.plugin, excludedFolder).open();
|
||||
// } else if (excludedFolder instanceof ExcludePattern) {
|
||||
// new PatternSettings(this.plugin.app, this.plugin, excludedFolder).open();
|
||||
// }
|
||||
// });
|
||||
// });
|
||||
|
||||
folderMenu.addItem((item) => {
|
||||
item.setTitle('Remove folder from excluded folders');
|
||||
item.setIcon('trash');
|
||||
item.onClick(() => {
|
||||
this.plugin.settings.excludeFolders =
|
||||
this.plugin.settings.excludeFolders.filter(
|
||||
(excluded) =>
|
||||
(excluded.path !== file.path) || excluded.detached,
|
||||
);
|
||||
void this.plugin.saveSettings(true);
|
||||
});
|
||||
}
|
||||
if (!(file instanceof TFolder)) return;
|
||||
const excludedFolder = getExcludedFolder(this.plugin, file.path, false);
|
||||
const detachedExcludedFolder = getDetachedFolder(this.plugin, file.path);
|
||||
if (excludedFolder && !excludedFolder.hideNote) {
|
||||
// I'm not sure if I'm ever going to add this because of the possibility that a folder got more than one excluded
|
||||
// subMenu.addItem((item) => {
|
||||
// item.setTitle('Manage excluded folder')
|
||||
// .setIcon('settings-2')
|
||||
// .onClick(() => {
|
||||
// console.log('excludedFolder', excludedFolder)
|
||||
// console.log('2', getExcludedFolder(this.plugin, file.path, false))
|
||||
// if (excludedFolder instanceof ExcludedFolder) {
|
||||
// new ExcludedFolderSettings(this.plugin.app, this.plugin, excludedFolder).open();
|
||||
// } else if (excludedFolder instanceof ExcludePattern) {
|
||||
// new PatternSettings(this.plugin.app, this.plugin, excludedFolder).open();
|
||||
// }
|
||||
// })
|
||||
// })
|
||||
subMenu.addItem((item) => {
|
||||
item.setTitle('Remove folder from excluded folders')
|
||||
.setIcon('trash')
|
||||
.onClick(() => {
|
||||
this.plugin.settings.excludeFolders = this.plugin.settings.excludeFolders.filter(
|
||||
(folder) => (folder.path !== file.path) || folder.detached);
|
||||
this.plugin.saveSettings(true);
|
||||
new Notice('Successfully removed folder from excluded folders');
|
||||
});
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (detachedExcludedFolder) {
|
||||
folderMenu.addItem((item) => {
|
||||
item.setTitle('Remove folder from detached folders');
|
||||
item.setIcon('trash');
|
||||
item.onClick(() => {
|
||||
void deleteExcludedFolder(this.plugin, detachedExcludedFolder);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (detachedExcludedFolder) {
|
||||
subMenu.addItem((item) => {
|
||||
item.setTitle('Remove folder from detached folders')
|
||||
.setIcon('trash')
|
||||
.onClick(() => {
|
||||
deleteExcludedFolder(this.plugin, detachedExcludedFolder);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (detachedExcludedFolder) { return; }
|
||||
|
||||
folderMenu.addItem((item) => {
|
||||
item.setTitle('Exclude folder from folder notes');
|
||||
item.setIcon('x-circle');
|
||||
item.onClick(() => {
|
||||
const newExcludedFolder = new ExcludedFolder(
|
||||
file.path,
|
||||
this.plugin.settings.excludeFolders.length,
|
||||
undefined,
|
||||
this.plugin,
|
||||
);
|
||||
this.plugin.settings.excludeFolders.push(newExcludedFolder);
|
||||
void this.plugin.saveSettings(true);
|
||||
});
|
||||
// return;
|
||||
}
|
||||
subMenu.addItem((item) => {
|
||||
item.setTitle('Exclude folder from folder notes')
|
||||
.setIcon('x-circle')
|
||||
.onClick(() => {
|
||||
const excludedFolder = new ExcludedFolder(file.path, this.plugin.settings.excludeFolders.length, undefined, this.plugin);
|
||||
this.plugin.settings.excludeFolders.push(excludedFolder);
|
||||
this.plugin.saveSettings(true);
|
||||
new Notice('Successfully excluded folder from folder notes');
|
||||
});
|
||||
});
|
||||
if (!(file instanceof TFolder)) return;
|
||||
const folderNote = getFolderNote(this.plugin, file.path);
|
||||
if (folderNote instanceof TFile && !detachedExcludedFolder) {
|
||||
subMenu.addItem((item) => {
|
||||
item.setTitle('Delete folder note')
|
||||
.setIcon('trash')
|
||||
.onClick(() => {
|
||||
deleteFolderNote(this.plugin, folderNote, true);
|
||||
});
|
||||
});
|
||||
|
||||
if (!(file instanceof TFolder)) return;
|
||||
|
||||
const folderNote = getFolderNote(this.plugin, file.path);
|
||||
|
||||
if (folderNote instanceof TFile && !detachedExcludedFolder) {
|
||||
folderMenu.addItem((item) => {
|
||||
item.setTitle('Delete folder note');
|
||||
item.setIcon('trash');
|
||||
item.onClick(() => {
|
||||
void deleteFolderNote(this.plugin, folderNote, true);
|
||||
subMenu.addItem((item) => {
|
||||
item.setTitle('Open folder note')
|
||||
.setIcon('chevron-right-square')
|
||||
.onClick(() => {
|
||||
openFolderNote(this.plugin, folderNote);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
folderMenu.addItem((item) => {
|
||||
item.setTitle('Open folder note');
|
||||
item.setIcon('chevron-right-square');
|
||||
item.onClick(() => {
|
||||
void openFolderNote(this.plugin, folderNote);
|
||||
});
|
||||
});
|
||||
|
||||
folderMenu.addItem((item) => {
|
||||
item.setTitle('Detach folder note');
|
||||
item.setIcon('unlink');
|
||||
item.onClick(() => {
|
||||
subMenu.addItem((item) => {
|
||||
item.setTitle('Detach folder note')
|
||||
.setIcon('unlink')
|
||||
.onClick(() => {
|
||||
detachFolderNote(this.plugin, folderNote);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
folderMenu.addItem((item) => {
|
||||
item.setTitle('Copy Obsidian URL');
|
||||
item.setIcon('link');
|
||||
item.onClick(() => {
|
||||
subMenu.addItem((item) => {
|
||||
item.setTitle('Copy Obsidian URL')
|
||||
.setIcon('link')
|
||||
.onClick(() => {
|
||||
// @ts-ignore
|
||||
this.app.copyObsidianUrl(folderNote);
|
||||
});
|
||||
});
|
||||
|
||||
if (this.plugin.settings.hideFolderNote) {
|
||||
if (excludedFolder?.showFolderNote) {
|
||||
folderMenu.addItem((item) => {
|
||||
item.setTitle('Hide folder note in explorer');
|
||||
item.setIcon('eye-off');
|
||||
item.onClick(() => {
|
||||
hideFolderNoteInFileExplorer(file.path, this.plugin);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
folderMenu.addItem((item) => {
|
||||
item.setTitle('Show folder note in explorer');
|
||||
item.setIcon('eye');
|
||||
item.onClick(() => {
|
||||
showFolderNoteInFileExplorer(file.path, this.plugin);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
folderMenu.addItem((item) => {
|
||||
item.setTitle('Create Markdown folder note');
|
||||
item.setIcon('edit');
|
||||
item.onClick(() => {
|
||||
void createFolderNote(this.plugin, file.path, true, '.md');
|
||||
});
|
||||
});
|
||||
|
||||
this.plugin.settings.supportedFileTypes.forEach((fileType) => {
|
||||
if (fileType === 'md') return;
|
||||
folderMenu.addItem((item) => {
|
||||
item.setTitle(`Create ${fileType} folder note`);
|
||||
item.setIcon('edit');
|
||||
item.onClick(() => {
|
||||
void createFolderNote(this.plugin, file.path, true, '.' + fileType);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (
|
||||
Platform.isDesktop &&
|
||||
!Platform.isTablet &&
|
||||
this.plugin.settings.useSubmenus
|
||||
) {
|
||||
menu.addItem(async (item) => {
|
||||
item.setTitle('Folder note commands').setIcon('folder-edit');
|
||||
let subMenu: Menu = item.setSubmenu();
|
||||
addFolderNoteActions(subMenu);
|
||||
});
|
||||
|
||||
if (this.plugin.settings.hideFolderNote) {
|
||||
if (excludedFolder?.hideNote) {
|
||||
subMenu.addItem((item) => {
|
||||
item.setTitle('Hide folder note in explorer')
|
||||
.setIcon('eye-off')
|
||||
.onClick(() => {
|
||||
this.plugin.settings.excludeFolders = this.plugin.settings.excludeFolders.filter(
|
||||
(folder) => (folder.path !== file.path) && folder.hideNote);
|
||||
this.plugin.saveSettings(false);
|
||||
applyCSSClassesToFolder(file.path, this.plugin);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
subMenu.addItem((item) => {
|
||||
item.setTitle('Show folder note in explorer')
|
||||
.setIcon('eye')
|
||||
.onClick(() => {
|
||||
const excludedFolder = new ExcludedFolder(file.path, this.plugin.settings.excludeFolders.length, undefined, this.plugin);
|
||||
excludedFolder.hideNote = true;
|
||||
excludedFolder.subFolders = false;
|
||||
excludedFolder.disableSync = false;
|
||||
excludedFolder.disableAutoCreate = false;
|
||||
excludedFolder.disableFolderNote = false;
|
||||
excludedFolder.enableCollapsing = false;
|
||||
excludedFolder.excludeFromFolderOverview = false;
|
||||
excludedFolder.hideInSettings = true;
|
||||
addExcludedFolder(this.plugin, excludedFolder, false);
|
||||
applyCSSClassesToFolder(file.path, this.plugin);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
addFolderNoteActions(menu);
|
||||
subMenu.addItem((item) => {
|
||||
item.setTitle('Create markdown folder note')
|
||||
.setIcon('edit')
|
||||
.onClick(() => {
|
||||
createFolderNote(this.plugin, file.path, true, '.md');
|
||||
});
|
||||
});
|
||||
|
||||
this.plugin.settings.supportedFileTypes.forEach((fileType) => {
|
||||
if (fileType === 'md') return;
|
||||
subMenu.addItem((item) => {
|
||||
item.setTitle(`Create ${fileType} folder note`)
|
||||
.setIcon('edit')
|
||||
.onClick(() => {
|
||||
createFolderNote(this.plugin, file.path, true, '.' + fileType);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}));
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
editorCommands(): void {
|
||||
// eslint-disable-next-line max-len
|
||||
this.plugin.registerEvent(this.plugin.app.workspace.on('editor-menu', (menu: Menu, editor: Editor, view: MarkdownEditorContext) => {
|
||||
editorCommands() {
|
||||
this.plugin.registerEvent(this.plugin.app.workspace.on('editor-menu', (menu: Menu, editor: Editor, view: MarkdownView) => {
|
||||
const text = editor.getSelection().trim();
|
||||
if (!text || text.trim() === '') return;
|
||||
menu.addItem((item) => {
|
||||
item.setTitle('Create folder note')
|
||||
.setIcon('edit')
|
||||
.onClick(() => {
|
||||
const { file } = view;
|
||||
const file = view.file;
|
||||
if (!(file instanceof TFile)) return;
|
||||
const blacklist = ['*', '\\', '"', '/', '<', '>', '?', '|', ':'];
|
||||
for (const char of blacklist) {
|
||||
if (text.includes(char)) {
|
||||
// eslint-disable-next-line max-len
|
||||
new Notice('File name cannot contain any of the following characters: * " \\ / < > : | ?');
|
||||
return;
|
||||
}
|
||||
|
|
@ -535,40 +491,29 @@ export class Commands {
|
|||
new Notice('File name cannot end with a dot');
|
||||
return;
|
||||
}
|
||||
|
||||
let folder: TAbstractFile | null;
|
||||
const folderPath = getFolderPathFromString(file.path);
|
||||
const { folderNoteName } = this.plugin.settings;
|
||||
const fileName = folderNoteName.replace('{{folder_name}}', text);
|
||||
const fileName = this.plugin.settings.folderNoteName.replace('{{folder_name}}', text);
|
||||
if (folderPath === '') {
|
||||
folder = this.plugin.app.vault.getAbstractFileByPath(text);
|
||||
if (folder instanceof TFolder) {
|
||||
return new Notice('Folder note already exists');
|
||||
} else {
|
||||
this.plugin.app.vault.createFolder(text);
|
||||
createFolderNote(this.plugin, text, false);
|
||||
}
|
||||
void this.plugin.app.vault.createFolder(text);
|
||||
void createFolderNote(this.plugin, text, false);
|
||||
|
||||
} else {
|
||||
folder = this.plugin.app.vault.getAbstractFileByPath(
|
||||
folderPath + '/' + text,
|
||||
);
|
||||
folder = this.plugin.app.vault.getAbstractFileByPath(folderPath + '/' + text);
|
||||
if (folder instanceof TFolder) {
|
||||
return new Notice('Folder note already exists');
|
||||
}
|
||||
if (this.plugin.settings.storageLocation === 'parentFolder') {
|
||||
if (
|
||||
this.app.vault.getAbstractFileByPath(
|
||||
folderPath +
|
||||
'/' +
|
||||
fileName +
|
||||
this.plugin.settings.folderNoteType,
|
||||
)
|
||||
) {
|
||||
if (this.app.vault.getAbstractFileByPath(folderPath + '/' + fileName + this.plugin.settings.folderNoteType)) {
|
||||
return new Notice('File already exists');
|
||||
}
|
||||
}
|
||||
void this.plugin.app.vault.createFolder(folderPath + '/' + text);
|
||||
void createFolderNote(this.plugin, folderPath + '/' + text, false);
|
||||
this.plugin.app.vault.createFolder(folderPath + '/' + text);
|
||||
createFolderNote(this.plugin, folderPath + '/' + text, false);
|
||||
}
|
||||
if (fileName !== text) {
|
||||
editor.replaceSelection(`[[${fileName}]]`);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type FolderNotesPlugin from '../main';
|
||||
import FolderNotesPlugin from '../main';
|
||||
export class ExcludedFolder {
|
||||
type: string;
|
||||
id: string;
|
||||
|
|
@ -12,9 +12,9 @@ export class ExcludedFolder {
|
|||
position: number;
|
||||
excludeFromFolderOverview: boolean;
|
||||
hideInSettings: boolean;
|
||||
detached: boolean = false;
|
||||
detached: boolean;
|
||||
detachedFilePath?: string;
|
||||
showFolderNote: boolean;
|
||||
hideNote: boolean;
|
||||
constructor(path: string, position: number, id: string | undefined, plugin: FolderNotesPlugin) {
|
||||
this.type = 'folder';
|
||||
this.id = id || crypto.randomUUID();
|
||||
|
|
@ -25,10 +25,9 @@ export class ExcludedFolder {
|
|||
this.disableFolderNote = plugin.settings.excludeFolderDefaultSettings.disableFolderNote;
|
||||
this.enableCollapsing = plugin.settings.excludeFolderDefaultSettings.enableCollapsing;
|
||||
this.position = position;
|
||||
// eslint-disable-next-line max-len
|
||||
this.excludeFromFolderOverview = plugin.settings.excludeFolderDefaultSettings.excludeFromFolderOverview;
|
||||
this.string = '';
|
||||
this.hideInSettings = false;
|
||||
this.showFolderNote = plugin.settings.excludeFolderDefaultSettings.showFolderNote;
|
||||
this.hideNote = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type FolderNotesPlugin from '../main';
|
||||
import FolderNotesPlugin from '../main';
|
||||
export class ExcludePattern {
|
||||
type: string;
|
||||
id: string;
|
||||
|
|
@ -12,15 +12,10 @@ export class ExcludePattern {
|
|||
enableCollapsing: boolean;
|
||||
excludeFromFolderOverview: boolean;
|
||||
hideInSettings: boolean;
|
||||
detached: boolean = false;
|
||||
detached: boolean;
|
||||
detachedFilePath?: string;
|
||||
showFolderNote: boolean;
|
||||
constructor(
|
||||
pattern: string,
|
||||
position: number,
|
||||
id: string | undefined,
|
||||
plugin: FolderNotesPlugin,
|
||||
) {
|
||||
hideNote: boolean;
|
||||
constructor(pattern: string, position: number, id: string | undefined, plugin: FolderNotesPlugin) {
|
||||
this.type = 'pattern';
|
||||
this.id = id || crypto.randomUUID();
|
||||
this.string = pattern;
|
||||
|
|
@ -30,10 +25,8 @@ export class ExcludePattern {
|
|||
this.disableAutoCreate = plugin.settings.excludePatternDefaultSettings.disableAutoCreate;
|
||||
this.disableFolderNote = plugin.settings.excludePatternDefaultSettings.disableFolderNote;
|
||||
this.enableCollapsing = plugin.settings.excludePatternDefaultSettings.enableCollapsing;
|
||||
// eslint-disable-next-line max-len
|
||||
this.excludeFromFolderOverview = plugin.settings.excludePatternDefaultSettings.excludeFromFolderOverview;
|
||||
this.path = '';
|
||||
this.hideInSettings = false;
|
||||
this.showFolderNote = plugin.settings.excludePatternDefaultSettings.showFolderNote;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,17 @@
|
|||
import type FolderNotesPlugin from '../main';
|
||||
import FolderNotesPlugin from '../main';
|
||||
export class WhitelistedFolder {
|
||||
type: string;
|
||||
id: string;
|
||||
path: string;
|
||||
string: string;
|
||||
subFolders: boolean;
|
||||
enableSync: boolean = false;
|
||||
enableAutoCreate: boolean = false;
|
||||
enableFolderNote: boolean = false;
|
||||
disableCollapsing: boolean = false;
|
||||
showInFolderOverview: boolean = false;
|
||||
hideInFileExplorer: boolean = false;
|
||||
enableSync: boolean;
|
||||
enableAutoCreate: boolean;
|
||||
enableFolderNote: boolean;
|
||||
enableCollapsing: boolean;
|
||||
showInFolderOverview: boolean;
|
||||
position: number;
|
||||
hideInSettings: boolean = false;
|
||||
hideInSettings: boolean;
|
||||
constructor(path: string, position: number, id: string | undefined, plugin: FolderNotesPlugin) {
|
||||
this.type = 'folder';
|
||||
this.id = id || crypto.randomUUID();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type FolderNotesPlugin from '../main';
|
||||
import FolderNotesPlugin from '../main';
|
||||
export class WhitelistedPattern {
|
||||
type: string;
|
||||
id: string;
|
||||
|
|
@ -6,19 +6,13 @@ export class WhitelistedPattern {
|
|||
path: string;
|
||||
position: number;
|
||||
subFolders: boolean;
|
||||
enableSync: boolean = false;
|
||||
enableAutoCreate: boolean = false;
|
||||
enableFolderNote: boolean = false;
|
||||
disableCollapsing: boolean = false;
|
||||
showInFolderOverview: boolean = false;
|
||||
hideInFileExplorer: boolean = false;
|
||||
hideInSettings: boolean = false;
|
||||
constructor(
|
||||
pattern: string,
|
||||
position: number,
|
||||
id: string | undefined,
|
||||
plugin: FolderNotesPlugin,
|
||||
) {
|
||||
enableSync: boolean;
|
||||
enableAutoCreate: boolean;
|
||||
enableFolderNote: boolean;
|
||||
enableCollapsing: boolean;
|
||||
showInFolderOverview: boolean;
|
||||
hideInSettings: boolean;
|
||||
constructor(pattern: string, position: number, id: string | undefined, plugin: FolderNotesPlugin) {
|
||||
this.type = 'pattern';
|
||||
this.id = id || crypto.randomUUID();
|
||||
this.subFolders = plugin.settings.excludePatternDefaultSettings.subFolders;
|
||||
|
|
|
|||
|
|
@ -1,39 +1,29 @@
|
|||
import type FolderNotesPlugin from '../../main';
|
||||
import FolderNotesPlugin from '../../main';
|
||||
import { getFolderNameFromPathString, getFolderPathFromString } from '../../functions/utils';
|
||||
import type { ExcludedFolder } from '../ExcludeFolder';
|
||||
import { ExcludedFolder } from '../ExcludeFolder';
|
||||
import { ExcludePattern } from '../ExcludePattern';
|
||||
import { Platform, Setting } from 'obsidian';
|
||||
import { FolderSuggest } from '../../suggesters/FolderSuggester';
|
||||
import type { SettingsTab } from '../../settings/SettingsTab';
|
||||
import { SettingsTab } from '../../settings/SettingsTab';
|
||||
import ExcludedFolderSettings from '../modals/ExcludeFolderSettings';
|
||||
import {
|
||||
updatePattern,
|
||||
getExcludedFoldersByPattern,
|
||||
addExcludePatternListItem,
|
||||
} from './patternFunctions';
|
||||
import { updatePattern, getExcludedFoldersByPattern, addExcludePatternListItem } from './patternFunctions';
|
||||
import { getWhitelistedFolder } from './whitelistFolderFunctions';
|
||||
import type { WhitelistedFolder } from '../WhitelistFolder';
|
||||
import type { WhitelistedPattern } from '../WhitelistPattern';
|
||||
import { WhitelistedFolder } from '../WhitelistFolder';
|
||||
import { WhitelistedPattern } from '../WhitelistPattern';
|
||||
|
||||
function combineExcluded(
|
||||
plugin: FolderNotesPlugin,
|
||||
path: string,
|
||||
includeDetached: boolean,
|
||||
pathOnly?: boolean,
|
||||
): Array<ExcludedFolder | ExcludePattern> {
|
||||
export function getExcludedFolder(plugin: FolderNotesPlugin, path: string, includeDetached: boolean, pathOnly?: boolean, ignoreWhitelist?: boolean) {
|
||||
let excludedFolder = {} as ExcludedFolder | ExcludePattern | undefined;
|
||||
const whitelistedFolder = getWhitelistedFolder(plugin, path) as WhitelistedFolder | WhitelistedPattern | undefined;
|
||||
const folderName = getFolderNameFromPathString(path);
|
||||
const matchedPatterns = pathOnly ? [] : getExcludedFoldersByPattern(plugin, folderName);
|
||||
const excludedByPath = getExcludedFoldersByPath(plugin, path);
|
||||
let combined = [...matchedPatterns, ...excludedByPath];
|
||||
if (!includeDetached) combined = combined.filter((f) => !f.detached);
|
||||
return combined;
|
||||
}
|
||||
let matchedPatterns = getExcludedFoldersByPattern(plugin, folderName);
|
||||
const excludedFolders = getExcludedFoldersByPath(plugin, path);
|
||||
if (pathOnly) { matchedPatterns = []; }
|
||||
let combinedExcludedFolders = [...matchedPatterns, ...excludedFolders];
|
||||
|
||||
if (!includeDetached) {
|
||||
combinedExcludedFolders = combinedExcludedFolders.filter((f) => !f.detached);
|
||||
}
|
||||
|
||||
function aggregateFlags(
|
||||
combinedExcludedFolders: Array<ExcludedFolder | ExcludePattern>,
|
||||
): Partial<ExcludedFolder> | undefined {
|
||||
if (combinedExcludedFolders.length === 0) return undefined;
|
||||
const result: Partial<ExcludedFolder> = {};
|
||||
const propertiesToCopy: (keyof ExcludedFolder)[] = [
|
||||
'disableAutoCreate',
|
||||
'disableFolderNote',
|
||||
|
|
@ -42,49 +32,34 @@ function aggregateFlags(
|
|||
'excludeFromFolderOverview',
|
||||
'detached',
|
||||
'hideInSettings',
|
||||
'hideNote',
|
||||
'id',
|
||||
'showFolderNote',
|
||||
];
|
||||
for (const matchedFolder of combinedExcludedFolders) {
|
||||
for (const property of propertiesToCopy) {
|
||||
const value = (matchedFolder as Partial<ExcludedFolder>)[property];
|
||||
if (value === true) {
|
||||
(result)[property] = true as never;
|
||||
} else if (!value) {
|
||||
(result)[property] = false as never;
|
||||
}
|
||||
|
||||
if (combinedExcludedFolders.length > 0) {
|
||||
for (const matchedFolder of combinedExcludedFolders) {
|
||||
propertiesToCopy.forEach((property) => {
|
||||
if (matchedFolder[property] === true) {
|
||||
(excludedFolder as any)[property] = true;
|
||||
} else if (!matchedFolder[property]) {
|
||||
(excludedFolder as any)[property] = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
excludedFolder = undefined;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function applyWhitelistOverrides(
|
||||
excluded: Partial<ExcludedFolder>,
|
||||
whitelisted: WhitelistedFolder | WhitelistedPattern,
|
||||
): Partial<ExcludedFolder> {
|
||||
const out: Partial<ExcludedFolder> = { ...excluded };
|
||||
if (out.disableAutoCreate !== undefined) {
|
||||
out.disableAutoCreate = !whitelisted.enableAutoCreate;
|
||||
}
|
||||
if (out.disableFolderNote !== undefined) {
|
||||
out.disableFolderNote = !whitelisted.enableFolderNote;
|
||||
}
|
||||
if (out.disableSync !== undefined) {
|
||||
out.disableSync = !whitelisted.enableSync;
|
||||
}
|
||||
out.enableCollapsing = !whitelisted.disableCollapsing;
|
||||
if (out.excludeFromFolderOverview !== undefined) {
|
||||
out.excludeFromFolderOverview = !whitelisted.showInFolderOverview;
|
||||
}
|
||||
out.showFolderNote = !whitelisted.hideInFileExplorer;
|
||||
return out;
|
||||
}
|
||||
if (excludedFolder?.detached) { ignoreWhitelist = true; }
|
||||
|
||||
function defaultExcludedIfEmpty(
|
||||
value: Partial<ExcludedFolder> | undefined,
|
||||
): ExcludedFolder | undefined {
|
||||
if (value && Object.keys(value).length === 0) {
|
||||
return {
|
||||
if (whitelistedFolder && excludedFolder && !ignoreWhitelist) {
|
||||
excludedFolder.disableAutoCreate ? excludedFolder.disableAutoCreate = !whitelistedFolder.enableAutoCreate : '';
|
||||
excludedFolder.disableFolderNote ? excludedFolder.disableFolderNote = !whitelistedFolder.enableFolderNote : '';
|
||||
excludedFolder.disableSync ? excludedFolder.disableSync = !whitelistedFolder.enableSync : '';
|
||||
excludedFolder.enableCollapsing = whitelistedFolder.enableCollapsing;
|
||||
excludedFolder.excludeFromFolderOverview ? excludedFolder.excludeFromFolderOverview = !whitelistedFolder.showInFolderOverview : '';
|
||||
} else if (excludedFolder && Object.keys(excludedFolder).length === 0) {
|
||||
excludedFolder = {
|
||||
type: 'folder',
|
||||
id: '',
|
||||
path: '',
|
||||
|
|
@ -98,155 +73,95 @@ function defaultExcludedIfEmpty(
|
|||
excludeFromFolderOverview: false,
|
||||
hideInSettings: false,
|
||||
detached: false,
|
||||
showFolderNote: false,
|
||||
hideNote: false,
|
||||
};
|
||||
}
|
||||
return value as ExcludedFolder | undefined;
|
||||
|
||||
return excludedFolder;
|
||||
}
|
||||
|
||||
export function getExcludedFolder(
|
||||
plugin: FolderNotesPlugin,
|
||||
path: string,
|
||||
includeDetached: boolean,
|
||||
pathOnly?: boolean,
|
||||
ignoreWhitelist?: boolean,
|
||||
): ExcludedFolder | ExcludePattern | undefined {
|
||||
const combined = combineExcluded(plugin, path, includeDetached, pathOnly);
|
||||
let excluded = aggregateFlags(combined);
|
||||
|
||||
const whitelist = getWhitelistedFolder(
|
||||
plugin,
|
||||
path,
|
||||
);
|
||||
|
||||
let skipWhitelist = ignoreWhitelist ?? false;
|
||||
if (excluded?.detached) skipWhitelist = true;
|
||||
|
||||
if (whitelist && excluded && !skipWhitelist) {
|
||||
excluded = applyWhitelistOverrides(excluded, whitelist);
|
||||
}
|
||||
|
||||
return defaultExcludedIfEmpty(excluded) as ExcludedFolder | ExcludePattern | undefined;
|
||||
}
|
||||
|
||||
export function getDetachedFolder(
|
||||
plugin: FolderNotesPlugin,
|
||||
path: string,
|
||||
): ExcludedFolder | undefined {
|
||||
export function getDetachedFolder(plugin: FolderNotesPlugin, path: string) {
|
||||
return plugin.settings.excludeFolders.find((f) => f.path === path && f.detached);
|
||||
}
|
||||
|
||||
export function getExcludedFolderByPath(
|
||||
plugin: FolderNotesPlugin,
|
||||
path: string,
|
||||
): ExcludedFolder | undefined {
|
||||
|
||||
export function getExcludedFolderByPath(plugin: FolderNotesPlugin, path: string) {
|
||||
return plugin.settings.excludeFolders.find((excludedFolder) => {
|
||||
if (path.trim() === '' || !excludedFolder.path) { return false; }
|
||||
if (excludedFolder.path === path) { return true; }
|
||||
if (!excludedFolder.subFolders) { return false; }
|
||||
const excludedFolderPath = excludedFolder.path.includes('/')
|
||||
? excludedFolder.path
|
||||
: `${excludedFolder.path}/`;
|
||||
const excludedFolderPath = excludedFolder.path.includes('/') ? excludedFolder.path : excludedFolder.path + '/';
|
||||
let folderPath = getFolderPathFromString(path);
|
||||
folderPath = folderPath.includes('/') ? folderPath : `${folderPath}/`;
|
||||
folderPath = folderPath.includes('/') ? folderPath : folderPath + '/';
|
||||
|
||||
if (folderPath.includes('/') || folderPath.includes('\\')) {
|
||||
return folderPath.startsWith(excludedFolderPath) || folderPath === excludedFolderPath;
|
||||
} else {
|
||||
return folderPath === excludedFolderPath;
|
||||
}
|
||||
return folderPath === excludedFolderPath;
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
export function getExcludedFoldersByPath(
|
||||
plugin: FolderNotesPlugin,
|
||||
path: string,
|
||||
): ExcludedFolder[] {
|
||||
export function getExcludedFoldersByPath(plugin: FolderNotesPlugin, path: string) {
|
||||
return plugin.settings.excludeFolders.filter((excludedFolder) => {
|
||||
if (path.trim() === '' || !excludedFolder.path) { return false; }
|
||||
if (excludedFolder.path === path) { return true; }
|
||||
if (!excludedFolder.subFolders) { return false; }
|
||||
const excludedFolderPath = excludedFolder.path.includes('/')
|
||||
? excludedFolder.path
|
||||
: `${excludedFolder.path}/`;
|
||||
const excludedFolderPath = excludedFolder.path.includes('/') ? excludedFolder.path : excludedFolder.path + '/';
|
||||
let folderPath = getFolderPathFromString(path);
|
||||
folderPath = folderPath.includes('/') ? folderPath : `${folderPath}/`;
|
||||
folderPath = folderPath.includes('/') ? folderPath : folderPath + '/';
|
||||
|
||||
if (folderPath.includes('/') || folderPath.includes('\\')) {
|
||||
return folderPath.startsWith(excludedFolderPath) || folderPath === excludedFolderPath;
|
||||
} else {
|
||||
return folderPath === excludedFolderPath;
|
||||
}
|
||||
return folderPath === excludedFolderPath;
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
export function addExcludedFolder(
|
||||
plugin: FolderNotesPlugin,
|
||||
excludedFolder: ExcludedFolder,
|
||||
reloadStyles = true,
|
||||
): void {
|
||||
export function addExcludedFolder(plugin: FolderNotesPlugin, excludedFolder: ExcludedFolder, reloadStyles = true) {
|
||||
plugin.settings.excludeFolders.push(excludedFolder);
|
||||
void plugin.saveSettings(reloadStyles);
|
||||
plugin.saveSettings(reloadStyles);
|
||||
}
|
||||
|
||||
export async function deleteExcludedFolder(
|
||||
plugin: FolderNotesPlugin,
|
||||
excludedFolder: ExcludedFolder,
|
||||
): Promise<void> {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter(
|
||||
(folder) => folder.id !== excludedFolder.id || folder.type === 'pattern',
|
||||
);
|
||||
await plugin.saveSettings(true);
|
||||
export async function deleteExcludedFolder(plugin: FolderNotesPlugin, excludedFolder: ExcludedFolder) {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter((folder) => folder.id !== excludedFolder.id || folder.type === 'pattern');
|
||||
plugin.saveSettings(true);
|
||||
resyncArray(plugin);
|
||||
}
|
||||
|
||||
export function updateExcludedFolder(
|
||||
plugin: FolderNotesPlugin,
|
||||
excludedFolder: ExcludePattern,
|
||||
newExcludeFolder: ExcludePattern,
|
||||
): void {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter(
|
||||
(folder) => folder.id !== excludedFolder.id,
|
||||
);
|
||||
export function updateExcludedFolder(plugin: FolderNotesPlugin, excludedFolder: ExcludePattern, newExcludeFolder: ExcludePattern) {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter((folder) => folder.id !== excludedFolder.id);
|
||||
addExcludedFolder(plugin, newExcludeFolder);
|
||||
}
|
||||
|
||||
export function resyncArray(plugin: FolderNotesPlugin): void {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.sort(
|
||||
(a, b) => a.position - b.position,
|
||||
);
|
||||
export function resyncArray(plugin: FolderNotesPlugin) {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.sort((a, b) => a.position - b.position);
|
||||
plugin.settings.excludeFolders.forEach((folder, index) => {
|
||||
folder.position = index;
|
||||
});
|
||||
void plugin.saveSettings();
|
||||
plugin.saveSettings();
|
||||
}
|
||||
|
||||
export function addExcludeFolderListItem(
|
||||
settings: SettingsTab,
|
||||
containerEl: HTMLElement,
|
||||
excludedFolder: ExcludedFolder,
|
||||
): void {
|
||||
const { plugin } = settings;
|
||||
|
||||
export function addExcludeFolderListItem(settings: SettingsTab, containerEl: HTMLElement, excludedFolder: ExcludedFolder) {
|
||||
const plugin: FolderNotesPlugin = settings.plugin;
|
||||
const setting = new Setting(containerEl);
|
||||
setting.setClass('fn-exclude-folder-list');
|
||||
setting.addSearch((cb) => {
|
||||
new FolderSuggest(
|
||||
cb.inputEl,
|
||||
plugin,
|
||||
false,
|
||||
false
|
||||
);
|
||||
// @ts-ignore
|
||||
cb.containerEl.addClass('fn-exclude-folder-path');
|
||||
cb.setPlaceholder('Folder path');
|
||||
cb.setValue(excludedFolder.path || '');
|
||||
cb.onChange((value) => {
|
||||
if (value.startsWith('{regex}') || value.includes('*')) {
|
||||
deleteExcludedFolder(plugin, excludedFolder);
|
||||
const pattern = new ExcludePattern(
|
||||
value,
|
||||
plugin.settings.excludeFolders.length,
|
||||
undefined,
|
||||
plugin,
|
||||
);
|
||||
const pattern = new ExcludePattern(value, plugin.settings.excludeFolders.length, undefined, plugin);
|
||||
addExcludedFolder(plugin, pattern);
|
||||
addExcludePatternListItem(settings, containerEl, pattern);
|
||||
setting.clear();
|
||||
|
|
@ -274,9 +189,7 @@ export function addExcludeFolderListItem(
|
|||
if (excludedFolder.position === 0) { return; }
|
||||
excludedFolder.position -= 1;
|
||||
updateExcludedFolder(plugin, excludedFolder, excludedFolder);
|
||||
const oldExcludedFolder = plugin.settings.excludeFolders.find(
|
||||
(folder) => folder.position === excludedFolder.position,
|
||||
);
|
||||
const oldExcludedFolder = plugin.settings.excludeFolders.find((folder) => folder.position === excludedFolder.position);
|
||||
if (oldExcludedFolder) {
|
||||
oldExcludedFolder.position += 1;
|
||||
if (oldExcludedFolder.type === 'pattern') {
|
||||
|
|
@ -299,9 +212,7 @@ export function addExcludeFolderListItem(
|
|||
excludedFolder.position += 1;
|
||||
|
||||
updateExcludedFolder(plugin, excludedFolder, excludedFolder);
|
||||
const oldExcludedFolder = plugin.settings.excludeFolders.find(
|
||||
(folder) => folder.position === excludedFolder.position,
|
||||
);
|
||||
const oldExcludedFolder = plugin.settings.excludeFolders.find((folder) => folder.position === excludedFolder.position);
|
||||
if (oldExcludedFolder) {
|
||||
oldExcludedFolder.position -= 1;
|
||||
if (oldExcludedFolder.type === 'pattern') {
|
||||
|
|
|
|||
|
|
@ -1,100 +1,83 @@
|
|||
import type FolderNotesPlugin from '../../main';
|
||||
import type { ExcludePattern } from '../ExcludePattern';
|
||||
import FolderNotesPlugin from '../../main';
|
||||
import { ExcludePattern } from '../ExcludePattern';
|
||||
import { Setting, Platform } from 'obsidian';
|
||||
import type { SettingsTab } from '../../settings/SettingsTab';
|
||||
import { SettingsTab } from '../../settings/SettingsTab';
|
||||
import { addExcludedFolder, resyncArray, updateExcludedFolder } from './folderFunctions';
|
||||
import PatternSettings from '../modals/PatternSettings';
|
||||
|
||||
const REGEX_PREFIX = '{regex}';
|
||||
const STAR = '*';
|
||||
const INDEX_START = 0;
|
||||
const SLICE_START_ONE = 1;
|
||||
const SLICE_EXCLUDE_LAST = -1;
|
||||
|
||||
function matchesPatternSpec(raw: string | undefined, folderName: string): boolean {
|
||||
if (!raw) return false;
|
||||
const string = raw.trim();
|
||||
const isRegex = string.startsWith(REGEX_PREFIX);
|
||||
const hasStartStar = string.startsWith(STAR);
|
||||
const hasEndStar = string.endsWith(STAR);
|
||||
if (!isRegex && !(hasStartStar || hasEndStar)) return false;
|
||||
|
||||
if (isRegex) {
|
||||
const body = string.replace(REGEX_PREFIX, '').trim();
|
||||
if (body === '') return false;
|
||||
try {
|
||||
return new RegExp(body).test(folderName);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasStartStar && hasEndStar) {
|
||||
const inner = string.slice(SLICE_START_ONE, SLICE_EXCLUDE_LAST);
|
||||
return folderName.includes(inner);
|
||||
}
|
||||
if (hasStartStar) {
|
||||
const suffix = string.slice(SLICE_START_ONE);
|
||||
return folderName.endsWith(suffix);
|
||||
}
|
||||
if (hasEndStar) {
|
||||
const prefix = string.slice(INDEX_START, SLICE_EXCLUDE_LAST);
|
||||
return folderName.startsWith(prefix);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function updatePattern(
|
||||
plugin: FolderNotesPlugin,
|
||||
pattern: ExcludePattern,
|
||||
newPattern: ExcludePattern,
|
||||
): void {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter(
|
||||
(folder) => folder.id !== pattern.id,
|
||||
);
|
||||
export function updatePattern(plugin: FolderNotesPlugin, pattern: ExcludePattern, newPattern: ExcludePattern) {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter((folder) => folder.id !== pattern.id);
|
||||
addExcludedFolder(plugin, newPattern);
|
||||
}
|
||||
|
||||
export async function deletePattern(
|
||||
plugin: FolderNotesPlugin,
|
||||
pattern: ExcludePattern,
|
||||
): Promise<void> {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter(
|
||||
(folder) => folder.id !== pattern.id || folder.type === 'folder',
|
||||
);
|
||||
await plugin.saveSettings(true);
|
||||
export function deletePattern(plugin: FolderNotesPlugin, pattern: ExcludePattern) {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter((folder) => folder.id !== pattern.id || folder.type === 'folder');
|
||||
plugin.saveSettings(true);
|
||||
resyncArray(plugin);
|
||||
}
|
||||
|
||||
export function getExcludedFoldersByPattern(
|
||||
plugin: FolderNotesPlugin,
|
||||
folderName: string,
|
||||
): ExcludePattern[] {
|
||||
return plugin.settings.excludeFolders
|
||||
.filter((s) => s.type === 'pattern')
|
||||
.filter((pattern) => matchesPatternSpec(pattern.string, folderName)) as ExcludePattern[];
|
||||
export function getExcludedFoldersByPattern(plugin: FolderNotesPlugin, folderName: string): ExcludePattern[] {
|
||||
return plugin.settings.excludeFolders.filter((s) => s.type === 'pattern').filter((pattern) => {
|
||||
if (!pattern.string) { return false; }
|
||||
const string = pattern.string.trim();
|
||||
if (!string.startsWith('{regex}') && !(string.startsWith('*') || string.endsWith('*'))) { return false; }
|
||||
const regex = string.replace('{regex}', '').trim();
|
||||
if (string.startsWith('{regex}') && regex === '') { return false; }
|
||||
if (regex !== undefined && string.startsWith('{regex}')) {
|
||||
const match = new RegExp(regex).exec(folderName);
|
||||
if (match) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.startsWith('*') && string.endsWith('*')) {
|
||||
if (folderName.includes(string.slice(1, -1))) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.startsWith('*')) {
|
||||
if (folderName.endsWith(string.slice(1))) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.endsWith('*')) {
|
||||
if (folderName.startsWith(string.slice(0, -1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function getExcludedFolderByPattern(
|
||||
plugin: FolderNotesPlugin,
|
||||
folderName: string,
|
||||
): ExcludePattern | undefined {
|
||||
return (
|
||||
plugin.settings.excludeFolders
|
||||
.filter((s) => s.type === 'pattern')
|
||||
.find((pattern) => matchesPatternSpec(pattern.string, folderName))
|
||||
) as ExcludePattern | undefined;
|
||||
export function getExcludedFolderByPattern(plugin: FolderNotesPlugin, folderName: string): ExcludePattern | undefined{
|
||||
return plugin.settings.excludeFolders.filter((s) => s.type === 'pattern').find((pattern) => {
|
||||
if (!pattern.string) { return false; }
|
||||
const string = pattern.string.trim();
|
||||
if (!string.startsWith('{regex}') && !(string.startsWith('*') || string.endsWith('*'))) { return false; }
|
||||
const regex = string.replace('{regex}', '').trim();
|
||||
if (string.startsWith('{regex}') && regex === '') { return false; }
|
||||
if (regex !== undefined && string.startsWith('{regex}')) {
|
||||
const match = new RegExp(regex).exec(folderName);
|
||||
if (match) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.startsWith('*') && string.endsWith('*')) {
|
||||
if (folderName.includes(string.slice(1, -1))) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.startsWith('*')) {
|
||||
if (folderName.endsWith(string.slice(1))) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.endsWith('*')) {
|
||||
if (folderName.startsWith(string.slice(0, -1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function addExcludePatternListItem(
|
||||
settings: SettingsTab,
|
||||
containerEl: HTMLElement,
|
||||
pattern: ExcludePattern,
|
||||
): void {
|
||||
const { plugin } = settings;
|
||||
export function addExcludePatternListItem(settings: SettingsTab, containerEl: HTMLElement, pattern: ExcludePattern) {
|
||||
const plugin: FolderNotesPlugin = settings.plugin;
|
||||
const setting = new Setting(containerEl);
|
||||
setting.setClass('fn-exclude-folder-list');
|
||||
setting.addSearch((cb) => {
|
||||
// @ts-ignore
|
||||
cb.containerEl.addClass('fn-exclude-folder-path');
|
||||
cb.setPlaceholder('Pattern');
|
||||
cb.setValue(pattern.string);
|
||||
|
|
@ -119,18 +102,11 @@ export function addExcludePatternListItem(
|
|||
if (pattern.position === 0) { return; }
|
||||
pattern.position -= 1;
|
||||
updatePattern(plugin, pattern, pattern);
|
||||
const oldPattern = plugin.settings.excludeFolders.find(
|
||||
(folder) => folder.position === pattern.position,
|
||||
);
|
||||
const oldPattern = plugin.settings.excludeFolders.find((folder) => folder.position === pattern.position);
|
||||
if (oldPattern) {
|
||||
oldPattern.position += 1;
|
||||
if (oldPattern.type === 'pattern') {
|
||||
const pat = oldPattern as ExcludePattern;
|
||||
updatePattern(
|
||||
plugin,
|
||||
pat,
|
||||
pat,
|
||||
);
|
||||
updatePattern(plugin, oldPattern, oldPattern);
|
||||
} else {
|
||||
updateExcludedFolder(plugin, oldPattern, oldPattern);
|
||||
}
|
||||
|
|
@ -149,18 +125,11 @@ export function addExcludePatternListItem(
|
|||
pattern.position += 1;
|
||||
|
||||
updatePattern(plugin, pattern, pattern);
|
||||
const oldPattern = plugin.settings.excludeFolders.find(
|
||||
(folder) => folder.position === pattern.position,
|
||||
);
|
||||
const oldPattern = plugin.settings.excludeFolders.find((folder) => folder.position === pattern.position);
|
||||
if (oldPattern) {
|
||||
oldPattern.position -= 1;
|
||||
if (oldPattern.type === 'pattern') {
|
||||
const pat = oldPattern as ExcludePattern;
|
||||
updatePattern(
|
||||
plugin,
|
||||
pat,
|
||||
pat,
|
||||
);
|
||||
updatePattern(plugin, oldPattern, oldPattern);
|
||||
} else {
|
||||
updateExcludedFolder(plugin, oldPattern, oldPattern);
|
||||
}
|
||||
|
|
@ -174,7 +143,7 @@ export function addExcludePatternListItem(
|
|||
cb.setIcon('trash-2');
|
||||
cb.setTooltip('Delete pattern');
|
||||
cb.onClick(() => {
|
||||
void deletePattern(plugin, pattern);
|
||||
deletePattern(plugin, pattern);
|
||||
setting.clear();
|
||||
setting.settingEl.remove();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,22 +1,16 @@
|
|||
import type FolderNotesPlugin from '../../main';
|
||||
import FolderNotesPlugin from '../../main';
|
||||
import { getFolderNameFromPathString, getFolderPathFromString } from '../../functions/utils';
|
||||
import type { WhitelistedFolder } from '../WhitelistFolder';
|
||||
import { WhitelistedFolder } from '../WhitelistFolder';
|
||||
import { WhitelistedPattern } from '../WhitelistPattern';
|
||||
import { Setting, ButtonComponent } from 'obsidian';
|
||||
import { Setting, Platform, ButtonComponent } from 'obsidian';
|
||||
import { FolderSuggest } from '../../suggesters/FolderSuggester';
|
||||
import type { SettingsTab } from '../../settings/SettingsTab';
|
||||
import { SettingsTab } from '../../settings/SettingsTab';
|
||||
import WhitelistFolderSettings from '../modals/WhitelistFolderSettings';
|
||||
import {
|
||||
updateWhitelistedPattern,
|
||||
getWhitelistedFoldersByPattern,
|
||||
addWhitelistedPatternListItem,
|
||||
} from './whitelistPatternFunctions';
|
||||
import { updateWhitelistedPattern, getWhitelistedFoldersByPattern, addWhitelistedPatternListItem } from './whitelistPatternFunctions';
|
||||
Platform.isMobileApp;
|
||||
|
||||
export function getWhitelistedFolder(
|
||||
plugin: FolderNotesPlugin,
|
||||
path: string,
|
||||
): WhitelistedFolder | WhitelistedPattern | undefined {
|
||||
let whitelistedFolder: Partial<WhitelistedFolder> | undefined = {};
|
||||
export function getWhitelistedFolder(plugin: FolderNotesPlugin, path: string) {
|
||||
let whitelistedFolder = {} as WhitelistedFolder | WhitelistedPattern | undefined;
|
||||
const folderName = getFolderNameFromPathString(path);
|
||||
const matchedPatterns = getWhitelistedFoldersByPattern(plugin, folderName);
|
||||
const whitelistedFolders = getWhitelistedFoldersByPath(plugin, path);
|
||||
|
|
@ -31,30 +25,21 @@ export function getWhitelistedFolder(
|
|||
if (combinedWhitelistedFolders.length > 0) {
|
||||
for (const matchedFolder of combinedWhitelistedFolders) {
|
||||
propertiesToCopy.forEach((property) => {
|
||||
const value = (matchedFolder as Partial<WhitelistedFolder>)[property];
|
||||
if (value === true) {
|
||||
(whitelistedFolder as Partial<WhitelistedFolder>)[property] = true as never;
|
||||
} else if (!value) {
|
||||
(whitelistedFolder as Partial<WhitelistedFolder>)[property] = false as never;
|
||||
if (matchedFolder[property] === true) {
|
||||
(whitelistedFolder as any)[property] = true;
|
||||
} else if (!matchedFolder[property]) {
|
||||
(whitelistedFolder as any)[property] = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
whitelistedFolder
|
||||
&& Object.keys(whitelistedFolder).length === 0
|
||||
) {
|
||||
whitelistedFolder = undefined;
|
||||
}
|
||||
if ((whitelistedFolder instanceof Object) && Object.keys(whitelistedFolder).length === 0) { whitelistedFolder = undefined; }
|
||||
|
||||
return whitelistedFolder as WhitelistedFolder | WhitelistedPattern | undefined;
|
||||
return whitelistedFolder;
|
||||
}
|
||||
|
||||
export function getWhitelistedFolderByPath(
|
||||
plugin: FolderNotesPlugin,
|
||||
path: string,
|
||||
): WhitelistedFolder | WhitelistedPattern | undefined {
|
||||
export function getWhitelistedFolderByPath(plugin: FolderNotesPlugin, path: string) {
|
||||
return plugin.settings.whitelistFolders.find((whitelistedFolder) => {
|
||||
if (whitelistedFolder.path === path) { return true; }
|
||||
if (!whitelistedFolder.subFolders) { return false; }
|
||||
|
|
@ -62,10 +47,7 @@ export function getWhitelistedFolderByPath(
|
|||
});
|
||||
}
|
||||
|
||||
export function getWhitelistedFoldersByPath(
|
||||
plugin: FolderNotesPlugin,
|
||||
path: string,
|
||||
): Array<WhitelistedFolder | WhitelistedPattern> {
|
||||
export function getWhitelistedFoldersByPath(plugin: FolderNotesPlugin, path: string) {
|
||||
return plugin.settings.whitelistFolders.filter((whitelistedFolder) => {
|
||||
if (whitelistedFolder.path === path) { return true; }
|
||||
if (!whitelistedFolder.subFolders) { return false; }
|
||||
|
|
@ -73,77 +55,52 @@ export function getWhitelistedFoldersByPath(
|
|||
});
|
||||
}
|
||||
|
||||
export function addWhitelistedFolder(
|
||||
plugin: FolderNotesPlugin,
|
||||
whitelistedFolder: WhitelistedFolder | WhitelistedPattern,
|
||||
): void {
|
||||
export function addWhitelistedFolder(plugin: FolderNotesPlugin, whitelistedFolder: WhitelistedFolder) {
|
||||
plugin.settings.whitelistFolders.push(whitelistedFolder);
|
||||
void plugin.saveSettings(true);
|
||||
plugin.saveSettings(true);
|
||||
}
|
||||
|
||||
export async function deleteWhitelistedFolder(
|
||||
plugin: FolderNotesPlugin,
|
||||
whitelistedFolder: WhitelistedFolder | WhitelistedPattern,
|
||||
): Promise<void> {
|
||||
plugin.settings.whitelistFolders = plugin.settings.whitelistFolders.filter(
|
||||
(folder) => folder.id !== whitelistedFolder.id || folder.type === 'pattern',
|
||||
);
|
||||
await plugin.saveSettings(true);
|
||||
export function deleteWhitelistedFolder(plugin: FolderNotesPlugin, whitelistedFolder: WhitelistedFolder) {
|
||||
plugin.settings.whitelistFolders = plugin.settings.whitelistFolders.filter((folder) => folder.id !== whitelistedFolder.id || folder.type === 'pattern');
|
||||
plugin.saveSettings(true);
|
||||
resyncArray(plugin);
|
||||
}
|
||||
|
||||
export function updateWhitelistedFolder(
|
||||
plugin: FolderNotesPlugin,
|
||||
whitelistedFolder: WhitelistedFolder,
|
||||
newWhitelistFolder: WhitelistedFolder,
|
||||
): void {
|
||||
plugin.settings.whitelistFolders = plugin.settings.whitelistFolders.filter(
|
||||
(folder) => folder.id !== whitelistedFolder.id,
|
||||
);
|
||||
export function updateWhitelistedFolder(plugin: FolderNotesPlugin, whitelistedFolder: WhitelistedFolder, newWhitelistFolder: WhitelistedFolder) {
|
||||
plugin.settings.whitelistFolders = plugin.settings.whitelistFolders.filter((folder) => folder.id !== whitelistedFolder.id);
|
||||
addWhitelistedFolder(plugin, newWhitelistFolder);
|
||||
}
|
||||
|
||||
export function resyncArray(plugin: FolderNotesPlugin): void {
|
||||
plugin.settings.whitelistFolders = plugin.settings.whitelistFolders.sort(
|
||||
(a, b) => a.position - b.position,
|
||||
);
|
||||
export function resyncArray(plugin: FolderNotesPlugin) {
|
||||
plugin.settings.whitelistFolders = plugin.settings.whitelistFolders.sort((a, b) => a.position - b.position);
|
||||
plugin.settings.whitelistFolders.forEach((folder, index) => {
|
||||
folder.position = index;
|
||||
});
|
||||
void plugin.saveSettings();
|
||||
plugin.saveSettings();
|
||||
}
|
||||
|
||||
export function addWhitelistFolderListItem(
|
||||
settings: SettingsTab,
|
||||
containerEl: HTMLElement,
|
||||
whitelistedFolder: WhitelistedFolder,
|
||||
): void {
|
||||
const { plugin } = settings;
|
||||
|
||||
export function addWhitelistFolderListItem(settings: SettingsTab, containerEl: HTMLElement, whitelistedFolder: WhitelistedFolder) {
|
||||
const plugin: FolderNotesPlugin = settings.plugin;
|
||||
const setting = new Setting(containerEl);
|
||||
setting.setClass('fn-exclude-folder-list');
|
||||
|
||||
const inputContainer = setting.settingEl.createDiv({
|
||||
cls: 'fn-whitelist-folder-input-container',
|
||||
});
|
||||
const inputContainer = setting.settingEl.createDiv({ cls: 'fn-whitelist-folder-input-container' });
|
||||
const SearchComponent = new Setting(inputContainer);
|
||||
SearchComponent.addSearch((cb) => {
|
||||
new FolderSuggest(
|
||||
cb.inputEl,
|
||||
plugin,
|
||||
true,
|
||||
true
|
||||
);
|
||||
// @ts-ignore
|
||||
cb.containerEl.addClass('fn-exclude-folder-path');
|
||||
cb.setPlaceholder('Folder path');
|
||||
cb.setValue(whitelistedFolder.path);
|
||||
cb.onChange((value) => {
|
||||
if (value.startsWith('{regex}') || value.includes('*')) {
|
||||
void deleteWhitelistedFolder(plugin, whitelistedFolder);
|
||||
const pattern = new WhitelistedPattern(
|
||||
value,
|
||||
plugin.settings.whitelistFolders.length,
|
||||
undefined,
|
||||
plugin,
|
||||
);
|
||||
deleteWhitelistedFolder(plugin, whitelistedFolder);
|
||||
const pattern = new WhitelistedPattern(value, plugin.settings.whitelistFolders.length, undefined, plugin);
|
||||
addWhitelistedFolder(plugin, pattern);
|
||||
addWhitelistedPatternListItem(settings, containerEl, pattern);
|
||||
setting.clear();
|
||||
|
|
@ -170,9 +127,7 @@ export function addWhitelistFolderListItem(
|
|||
if (whitelistedFolder.position === 0) { return; }
|
||||
whitelistedFolder.position -= 1;
|
||||
updateWhitelistedFolder(plugin, whitelistedFolder, whitelistedFolder);
|
||||
const oldWhitelistedFolder = plugin.settings.whitelistFolders.find(
|
||||
(folder) => folder.position === whitelistedFolder.position,
|
||||
);
|
||||
const oldWhitelistedFolder = plugin.settings.whitelistFolders.find((folder) => folder.position === whitelistedFolder.position);
|
||||
if (oldWhitelistedFolder) {
|
||||
oldWhitelistedFolder.position += 1;
|
||||
if (oldWhitelistedFolder.type === 'pattern') {
|
||||
|
|
@ -194,9 +149,7 @@ export function addWhitelistFolderListItem(
|
|||
whitelistedFolder.position += 1;
|
||||
|
||||
updateWhitelistedFolder(plugin, whitelistedFolder, whitelistedFolder);
|
||||
const oldWhitelistedFolder = plugin.settings.whitelistFolders.find(
|
||||
(folder) => folder.position === whitelistedFolder.position,
|
||||
);
|
||||
const oldWhitelistedFolder = plugin.settings.whitelistFolders.find((folder) => folder.position === whitelistedFolder.position);
|
||||
if (oldWhitelistedFolder) {
|
||||
oldWhitelistedFolder.position -= 1;
|
||||
if (oldWhitelistedFolder.type === 'pattern') {
|
||||
|
|
@ -213,7 +166,7 @@ export function addWhitelistFolderListItem(
|
|||
.setIcon('trash-2')
|
||||
.setTooltip('Delete excluded folder')
|
||||
.onClick(() => {
|
||||
void deleteWhitelistedFolder(plugin, whitelistedFolder);
|
||||
deleteWhitelistedFolder(plugin, whitelistedFolder);
|
||||
setting.clear();
|
||||
setting.settingEl.remove();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,110 +1,89 @@
|
|||
import type FolderNotesPlugin from '../../main';
|
||||
import FolderNotesPlugin from '../../main';
|
||||
import { Setting } from 'obsidian';
|
||||
import type { SettingsTab } from '../../settings/SettingsTab';
|
||||
import { SettingsTab } from '../../settings/SettingsTab';
|
||||
import { resyncArray } from './folderFunctions';
|
||||
import WhitelistPatternSettings from '../modals/WhitelistPatternSettings';
|
||||
import type { WhitelistedPattern } from '../WhitelistPattern';
|
||||
import { WhitelistedPattern } from '../WhitelistPattern';
|
||||
import { addWhitelistedFolder, updateWhitelistedFolder } from './whitelistFolderFunctions';
|
||||
|
||||
const REGEX_PREFIX = '{regex}';
|
||||
const STAR = '*';
|
||||
const SLICE_START_ONE = 1;
|
||||
const SLICE_EXCLUDE_LAST = -1;
|
||||
|
||||
function matchesPatternSpec(raw: string | undefined, folderName: string): boolean {
|
||||
if (!raw) return false;
|
||||
const string = raw.trim();
|
||||
const isRegex = string.startsWith(REGEX_PREFIX);
|
||||
const hasStartStar = string.startsWith(STAR);
|
||||
const hasEndStar = string.endsWith(STAR);
|
||||
if (!isRegex && !(hasStartStar || hasEndStar)) return false;
|
||||
|
||||
if (isRegex) {
|
||||
const body = string.replace(REGEX_PREFIX, '').trim();
|
||||
if (body === '') return false;
|
||||
try {
|
||||
return new RegExp(body).test(folderName);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasStartStar && hasEndStar) {
|
||||
const inner = string.slice(SLICE_START_ONE, SLICE_EXCLUDE_LAST);
|
||||
return folderName.includes(inner);
|
||||
}
|
||||
if (hasStartStar) {
|
||||
const suffix = string.slice(SLICE_START_ONE);
|
||||
return folderName.endsWith(suffix);
|
||||
}
|
||||
if (hasEndStar) {
|
||||
const prefix = string.slice(0, SLICE_EXCLUDE_LAST);
|
||||
return folderName.startsWith(prefix);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function updateWhitelistedPattern(
|
||||
plugin: FolderNotesPlugin,
|
||||
pattern: WhitelistedPattern,
|
||||
newPattern: WhitelistedPattern,
|
||||
): void {
|
||||
plugin.settings.whitelistFolders = plugin.settings.whitelistFolders.filter(
|
||||
(folder) => folder.id !== pattern.id,
|
||||
);
|
||||
export function updateWhitelistedPattern(plugin: FolderNotesPlugin, pattern: WhitelistedPattern, newPattern: WhitelistedPattern) {
|
||||
plugin.settings.whitelistFolders = plugin.settings.whitelistFolders.filter((folder) => folder.id !== pattern.id);
|
||||
addWhitelistedFolder(plugin, newPattern);
|
||||
}
|
||||
|
||||
export async function deletePattern(
|
||||
plugin: FolderNotesPlugin,
|
||||
pattern: WhitelistedPattern,
|
||||
): Promise<void> {
|
||||
plugin.settings.whitelistFolders = plugin.settings.whitelistFolders.filter(
|
||||
(folder) => folder.id !== pattern.id || folder.type === 'folder',
|
||||
);
|
||||
await plugin.saveSettings(true);
|
||||
export function deletePattern(plugin: FolderNotesPlugin, pattern: WhitelistedPattern) {
|
||||
plugin.settings.whitelistFolders = plugin.settings.whitelistFolders.filter((folder) => folder.id !== pattern.id || folder.type === 'folder');
|
||||
plugin.saveSettings(true);
|
||||
resyncArray(plugin);
|
||||
}
|
||||
|
||||
export function getWhitelistedFolderByPattern(
|
||||
plugin: FolderNotesPlugin,
|
||||
folderName: string,
|
||||
): WhitelistedPattern | undefined {
|
||||
return (
|
||||
plugin.settings.whitelistFolders
|
||||
.filter((s) => s.type === 'pattern')
|
||||
.find((pattern) => matchesPatternSpec(pattern.string, folderName))
|
||||
) as WhitelistedPattern | undefined;
|
||||
export function getWhitelistedFolderByPattern(plugin: FolderNotesPlugin, folderName: string) {
|
||||
return plugin.settings.whitelistFolders.filter((s) => s.type === 'pattern').find((pattern) => {
|
||||
if (!pattern.string) { return false; }
|
||||
const string = pattern.string.trim();
|
||||
if (!string.startsWith('{regex}') && !(string.startsWith('*') || string.endsWith('*'))) { return false; }
|
||||
const regex = string.replace('{regex}', '').trim();
|
||||
if (string.startsWith('{regex}') && regex === '') { return false; }
|
||||
if (regex !== undefined && string.startsWith('{regex}')) {
|
||||
const match = new RegExp(regex).exec(folderName);
|
||||
if (match) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.startsWith('*') && string.endsWith('*')) {
|
||||
if (folderName.includes(string.slice(1, -1))) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.startsWith('*')) {
|
||||
if (folderName.endsWith(string.slice(1))) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.endsWith('*')) {
|
||||
if (folderName.startsWith(string.slice(0, -1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function getWhitelistedFoldersByPattern(
|
||||
plugin: FolderNotesPlugin,
|
||||
folderName: string,
|
||||
): WhitelistedPattern[] {
|
||||
return (
|
||||
plugin.settings.whitelistFolders
|
||||
.filter((s) => s.type === 'pattern')
|
||||
.filter((pattern) => matchesPatternSpec(pattern.string, folderName))
|
||||
) as WhitelistedPattern[];
|
||||
export function getWhitelistedFoldersByPattern(plugin: FolderNotesPlugin, folderName: string) {
|
||||
return plugin.settings.whitelistFolders.filter((s) => s.type === 'pattern').filter((pattern) => {
|
||||
if (!pattern.string) { return false; }
|
||||
const string = pattern.string.trim();
|
||||
if (!string.startsWith('{regex}') && !(string.startsWith('*') || string.endsWith('*'))) { return false; }
|
||||
const regex = string.replace('{regex}', '').trim();
|
||||
if (string.startsWith('{regex}') && regex === '') { return false; }
|
||||
if (regex !== undefined && string.startsWith('{regex}')) {
|
||||
const match = new RegExp(regex).exec(folderName);
|
||||
if (match) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.startsWith('*') && string.endsWith('*')) {
|
||||
if (folderName.includes(string.slice(1, -1))) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.startsWith('*')) {
|
||||
if (folderName.endsWith(string.slice(1))) {
|
||||
return true;
|
||||
}
|
||||
} else if (string.endsWith('*')) {
|
||||
if (folderName.startsWith(string.slice(0, -1))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function addWhitelistedPatternListItem(
|
||||
settings: SettingsTab,
|
||||
containerEl: HTMLElement,
|
||||
pattern: WhitelistedPattern,
|
||||
): void {
|
||||
const { plugin } = settings;
|
||||
export function addWhitelistedPatternListItem(settings: SettingsTab, containerEl: HTMLElement, pattern: WhitelistedPattern) {
|
||||
const plugin: FolderNotesPlugin = settings.plugin;
|
||||
const setting = new Setting(containerEl);
|
||||
setting.setClass('fn-exclude-folder-list');
|
||||
setting.addSearch((cb) => {
|
||||
// @ts-ignore
|
||||
cb.containerEl.addClass('fn-exclude-folder-path');
|
||||
cb.setPlaceholder('Pattern');
|
||||
cb.setValue(pattern.string);
|
||||
cb.onChange((value) => {
|
||||
const exists = plugin.settings.whitelistFolders.some(
|
||||
(folder) => folder.string === value,
|
||||
);
|
||||
if (exists) { return; }
|
||||
if (plugin.settings.whitelistFolders.find((folder) => folder.string === value)) { return; }
|
||||
pattern.string = value;
|
||||
updateWhitelistedPattern(plugin, pattern, pattern);
|
||||
});
|
||||
|
|
@ -124,17 +103,11 @@ export function addWhitelistedPatternListItem(
|
|||
if (pattern.position === 0) { return; }
|
||||
pattern.position -= 1;
|
||||
updateWhitelistedPattern(plugin, pattern, pattern);
|
||||
const oldPattern = plugin.settings.whitelistFolders.find(
|
||||
(folder) => folder.position === pattern.position,
|
||||
);
|
||||
const oldPattern = plugin.settings.whitelistFolders.find((folder) => folder.position === pattern.position);
|
||||
if (oldPattern) {
|
||||
oldPattern.position += 1;
|
||||
if (oldPattern.type === 'pattern') {
|
||||
updateWhitelistedPattern(
|
||||
plugin,
|
||||
oldPattern as WhitelistedPattern,
|
||||
oldPattern as WhitelistedPattern,
|
||||
);
|
||||
updateWhitelistedPattern(plugin, oldPattern, oldPattern);
|
||||
} else {
|
||||
updateWhitelistedFolder(plugin, oldPattern, oldPattern);
|
||||
}
|
||||
|
|
@ -153,17 +126,11 @@ export function addWhitelistedPatternListItem(
|
|||
pattern.position += 1;
|
||||
|
||||
updateWhitelistedPattern(plugin, pattern, pattern);
|
||||
const oldPattern = plugin.settings.whitelistFolders.find(
|
||||
(folder) => folder.position === pattern.position,
|
||||
);
|
||||
const oldPattern = plugin.settings.whitelistFolders.find((folder) => folder.position === pattern.position);
|
||||
if (oldPattern) {
|
||||
oldPattern.position -= 1;
|
||||
if (oldPattern.type === 'pattern') {
|
||||
updateWhitelistedPattern(
|
||||
plugin,
|
||||
oldPattern as WhitelistedPattern,
|
||||
oldPattern as WhitelistedPattern,
|
||||
);
|
||||
updateWhitelistedPattern(plugin, oldPattern, oldPattern);
|
||||
} else {
|
||||
updateWhitelistedFolder(plugin, oldPattern, oldPattern);
|
||||
}
|
||||
|
|
@ -176,7 +143,7 @@ export function addWhitelistedPatternListItem(
|
|||
cb.setIcon('trash-2');
|
||||
cb.setTooltip('Delete pattern');
|
||||
cb.onClick(() => {
|
||||
void deletePattern(plugin, pattern);
|
||||
deletePattern(plugin, pattern);
|
||||
setting.clear();
|
||||
setting.settingEl.remove();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { Modal, Setting, type App } from 'obsidian';
|
||||
import type FolderNotesPlugin from '../../main';
|
||||
import type { ExcludedFolder } from 'src/ExcludeFolders/ExcludeFolder';
|
||||
import { updateCSSClassesForFolder } from 'src/functions/styleFunctions';
|
||||
import { App, Modal, Setting } from 'obsidian';
|
||||
import FolderNotesPlugin from '../../main';
|
||||
import { ExcludedFolder } from 'src/ExcludeFolders/ExcludeFolder';
|
||||
export default class ExcludedFolderSettings extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
app: App;
|
||||
|
|
@ -12,10 +11,10 @@ export default class ExcludedFolderSettings extends Modal {
|
|||
this.app = app;
|
||||
this.excludedFolder = excludedFolder;
|
||||
}
|
||||
onOpen(): void {
|
||||
onOpen() {
|
||||
this.display();
|
||||
}
|
||||
display(): void {
|
||||
display() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
contentEl.createEl('h2', { text: 'Excluded folder settings' });
|
||||
|
|
@ -28,7 +27,7 @@ export default class ExcludedFolderSettings extends Modal {
|
|||
.onChange(async (value) => {
|
||||
this.excludedFolder.subFolders = value;
|
||||
await this.plugin.saveSettings(true);
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
|
|
@ -40,7 +39,7 @@ export default class ExcludedFolderSettings extends Modal {
|
|||
.onChange(async (value) => {
|
||||
this.excludedFolder.disableSync = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
|
|
@ -52,21 +51,7 @@ export default class ExcludedFolderSettings extends Modal {
|
|||
.onChange(async (value) => {
|
||||
this.excludedFolder.excludeFromFolderOverview = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
.setName('Show folder note in the file explorer')
|
||||
.setDesc('Choose if the folder note should be shown in the file explorer')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.excludedFolder.showFolderNote)
|
||||
.onChange(async (value) => {
|
||||
this.excludedFolder.showFolderNote = value;
|
||||
updateCSSClassesForFolder(this.excludedFolder.path, this.plugin);
|
||||
await this.plugin.saveSettings();
|
||||
this.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
|
|
@ -78,7 +63,7 @@ export default class ExcludedFolderSettings extends Modal {
|
|||
.onChange(async (value) => {
|
||||
this.excludedFolder.disableAutoCreate = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
|
|
@ -91,7 +76,7 @@ export default class ExcludedFolderSettings extends Modal {
|
|||
this.excludedFolder.disableFolderNote = value;
|
||||
await this.plugin.saveSettings(true);
|
||||
this.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
if (!this.excludedFolder.disableFolderNote) {
|
||||
|
|
@ -104,12 +89,12 @@ export default class ExcludedFolderSettings extends Modal {
|
|||
.onChange(async (value) => {
|
||||
this.excludedFolder.enableCollapsing = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
onClose(): void {
|
||||
}
|
||||
onClose() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { Modal, Setting, type App } from 'obsidian';
|
||||
import type FolderNotesPlugin from '../../main';
|
||||
import type { ExcludePattern } from 'src/ExcludeFolders/ExcludePattern';
|
||||
import { refreshAllFolderStyles } from 'src/functions/styleFunctions';
|
||||
import { App, Modal, Setting } from 'obsidian';
|
||||
import FolderNotesPlugin from '../../main';
|
||||
import { ExcludePattern } from 'src/ExcludeFolders/ExcludePattern';
|
||||
|
||||
export default class PatternSettings extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
|
|
@ -13,19 +12,16 @@ export default class PatternSettings extends Modal {
|
|||
this.app = app;
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
onOpen(): void {
|
||||
onOpen() {
|
||||
this.display();
|
||||
}
|
||||
|
||||
display(): void {
|
||||
display() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
contentEl.createEl('h2', { text: 'Pattern settings' });
|
||||
|
||||
new Setting(contentEl)
|
||||
.setName('Disable folder name sync')
|
||||
|
||||
.setDesc('Choose if the folder name should be renamed when the file name has been changed')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
|
|
@ -33,12 +29,11 @@ export default class PatternSettings extends Modal {
|
|||
.onChange(async (value) => {
|
||||
this.pattern.disableSync = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
.setName('Disable auto creation of folder notes in this folder')
|
||||
// eslint-disable-next-line max-len
|
||||
.setDesc('Choose if a folder note should be created when a new folder is created that matches this pattern')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
|
|
@ -46,7 +41,7 @@ export default class PatternSettings extends Modal {
|
|||
.onChange(async (value) => {
|
||||
this.pattern.disableAutoCreate = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
|
|
@ -58,21 +53,7 @@ export default class PatternSettings extends Modal {
|
|||
.onChange(async (value) => {
|
||||
this.pattern.excludeFromFolderOverview = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
.setName('Show folder note in the file explorer')
|
||||
.setDesc('Choose if the folder note should be shown in the file explorer')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.pattern.showFolderNote)
|
||||
.onChange(async (value) => {
|
||||
this.pattern.showFolderNote = value;
|
||||
await this.plugin.saveSettings();
|
||||
refreshAllFolderStyles(true, this.plugin);
|
||||
this.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
|
|
@ -85,7 +66,7 @@ export default class PatternSettings extends Modal {
|
|||
this.pattern.disableFolderNote = value;
|
||||
await this.plugin.saveSettings(true);
|
||||
this.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
if (!this.pattern.disableFolderNote) {
|
||||
|
|
@ -98,12 +79,12 @@ export default class PatternSettings extends Modal {
|
|||
.onChange(async (value) => {
|
||||
this.pattern.enableCollapsing = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
onClose(): void {
|
||||
}
|
||||
onClose() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Modal, Setting, type App } from 'obsidian';
|
||||
import type FolderNotesPlugin from '../../main';
|
||||
import type { WhitelistedFolder } from '../WhitelistFolder';
|
||||
import { App, Modal, Setting } from 'obsidian';
|
||||
import FolderNotesPlugin from '../../main';
|
||||
import { WhitelistedFolder } from '../WhitelistFolder';
|
||||
export default class WhitelistFolderSettings extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
app: App;
|
||||
|
|
@ -11,12 +11,10 @@ export default class WhitelistFolderSettings extends Modal {
|
|||
this.app = app;
|
||||
this.whitelistedFolder = whitelistedFolder;
|
||||
}
|
||||
|
||||
onOpen(): void {
|
||||
onOpen() {
|
||||
this.display();
|
||||
}
|
||||
|
||||
display(): void {
|
||||
display() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
contentEl.createEl('h2', { text: 'Whitelisted folder settings' });
|
||||
|
|
@ -29,12 +27,11 @@ export default class WhitelistFolderSettings extends Modal {
|
|||
.onChange(async (value) => {
|
||||
this.whitelistedFolder.subFolders = value;
|
||||
await this.plugin.saveSettings(true);
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
.setName('Enable folder name sync')
|
||||
|
||||
.setDesc('Choose if the name of a folder note should be renamed when the folder name is changed')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
|
|
@ -42,7 +39,7 @@ export default class WhitelistFolderSettings extends Modal {
|
|||
.onChange(async (value) => {
|
||||
this.whitelistedFolder.enableSync = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
|
|
@ -54,19 +51,7 @@ export default class WhitelistFolderSettings extends Modal {
|
|||
.onChange(async (value) => {
|
||||
this.whitelistedFolder.showInFolderOverview = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
.setName('Hide folder note in file explorer')
|
||||
.setDesc('Choose if the folder note should be hidden in the file explorer')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.whitelistedFolder.hideInFileExplorer)
|
||||
.onChange(async (value) => {
|
||||
this.whitelistedFolder.hideInFileExplorer = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
|
|
@ -77,7 +62,7 @@ export default class WhitelistFolderSettings extends Modal {
|
|||
.onChange(async (value) => {
|
||||
this.whitelistedFolder.enableAutoCreate = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
|
|
@ -91,25 +76,25 @@ export default class WhitelistFolderSettings extends Modal {
|
|||
this.whitelistedFolder.enableFolderNote = value;
|
||||
await this.plugin.saveSettings(true);
|
||||
this.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
if (this.whitelistedFolder.enableFolderNote) {
|
||||
new Setting(contentEl)
|
||||
.setName('Don\'t collapse folder when opening folder note')
|
||||
.setName('Collapse folder when opening folder note')
|
||||
.setDesc('Choose if the folder should be collapsed when the folder note is opened')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.whitelistedFolder.disableCollapsing)
|
||||
.setValue(this.whitelistedFolder.enableCollapsing)
|
||||
.onChange(async (value) => {
|
||||
this.whitelistedFolder.disableCollapsing = value;
|
||||
this.whitelistedFolder.enableCollapsing = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
onClose(): void {
|
||||
onClose() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Modal, Setting, type App } from 'obsidian';
|
||||
import type FolderNotesPlugin from '../../main';
|
||||
import type { WhitelistedPattern } from '../WhitelistPattern';
|
||||
import { App, Modal, Setting } from 'obsidian';
|
||||
import FolderNotesPlugin from '../../main';
|
||||
import { WhitelistedPattern } from '../WhitelistPattern';
|
||||
|
||||
export default class WhitelistPatternSettings extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
|
|
@ -12,18 +12,15 @@ export default class WhitelistPatternSettings extends Modal {
|
|||
this.app = app;
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
onOpen(): void {
|
||||
onOpen() {
|
||||
this.display();
|
||||
}
|
||||
|
||||
display(): void {
|
||||
display() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
contentEl.createEl('h2', { text: 'Whitelisted pattern settings' });
|
||||
new Setting(contentEl)
|
||||
.setName('Enable folder name sync')
|
||||
|
||||
.setDesc('Choose if the name of a folder note should be renamed when the folder name is changed')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
|
|
@ -31,7 +28,7 @@ export default class WhitelistPatternSettings extends Modal {
|
|||
.onChange(async (value) => {
|
||||
this.pattern.enableSync = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
|
|
@ -42,7 +39,7 @@ export default class WhitelistPatternSettings extends Modal {
|
|||
.onChange(async (value) => {
|
||||
this.pattern.enableAutoCreate = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
|
|
@ -54,7 +51,7 @@ export default class WhitelistPatternSettings extends Modal {
|
|||
.onChange(async (value) => {
|
||||
this.pattern.showInFolderOverview = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
|
|
@ -68,25 +65,25 @@ export default class WhitelistPatternSettings extends Modal {
|
|||
this.pattern.enableFolderNote = value;
|
||||
await this.plugin.saveSettings(true);
|
||||
this.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
if (this.pattern.enableFolderNote) {
|
||||
new Setting(contentEl)
|
||||
.setName('Don\'t collapse folder when opening folder note')
|
||||
.setName('Collapse folder when opening folder note')
|
||||
.setDesc('Choose if the folder should be collapsed when the folder note is opened')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(this.pattern.disableCollapsing)
|
||||
.setValue(this.pattern.enableCollapsing)
|
||||
.onChange(async (value) => {
|
||||
this.pattern.disableCollapsing = value;
|
||||
this.pattern.enableCollapsing = value;
|
||||
await this.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
onClose(): void {
|
||||
}
|
||||
onClose() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
import { Modal, Setting, type App } from 'obsidian';
|
||||
import type { SettingsTab } from 'src/settings/SettingsTab';
|
||||
import type FolderNotesPlugin from '../../main';
|
||||
import { App, Modal, Setting } from 'obsidian';
|
||||
import { SettingsTab } from 'src/settings/SettingsTab';
|
||||
import FolderNotesPlugin from '../../main';
|
||||
import { WhitelistedFolder } from '../WhitelistFolder';
|
||||
import {
|
||||
addWhitelistFolderListItem,
|
||||
addWhitelistedFolder,
|
||||
} from '../functions/whitelistFolderFunctions';
|
||||
import { addWhitelistFolderListItem, addWhitelistedFolder } from '../functions/whitelistFolderFunctions';
|
||||
import { addWhitelistedPatternListItem } from '../functions/whitelistPatternFunctions';
|
||||
|
||||
export default class WhitelistedFoldersSettings extends Modal {
|
||||
|
|
@ -18,8 +15,7 @@ export default class WhitelistedFoldersSettings extends Modal {
|
|||
this.settingsTab = settingsTab;
|
||||
this.app = settingsTab.app;
|
||||
}
|
||||
|
||||
onOpen(): void {
|
||||
onOpen() {
|
||||
|
||||
const { contentEl } = this;
|
||||
contentEl.createEl('h2', { text: 'Manage whitelisted folders' });
|
||||
|
|
@ -32,31 +28,22 @@ export default class WhitelistedFoldersSettings extends Modal {
|
|||
cb.setClass('add-exclude-folder');
|
||||
cb.setTooltip('Add whitelisted folder');
|
||||
cb.onClick(() => {
|
||||
const whitelistedFolder = new WhitelistedFolder(
|
||||
'', this.plugin.settings.whitelistFolders.length,
|
||||
undefined, this.plugin,
|
||||
);
|
||||
addWhitelistFolderListItem(
|
||||
this.plugin.settingsTab, contentEl, whitelistedFolder,
|
||||
);
|
||||
const whitelistedFolder = new WhitelistedFolder('', this.plugin.settings.whitelistFolders.length, undefined, this.plugin);
|
||||
addWhitelistFolderListItem(this.plugin.settingsTab, contentEl, whitelistedFolder);
|
||||
addWhitelistedFolder(this.plugin, whitelistedFolder);
|
||||
this.settingsTab.renderSettingsPage(this.settingsTab.plugin.settings.settingsTab);
|
||||
this.settingsTab.display();
|
||||
});
|
||||
});
|
||||
|
||||
this.plugin.settings.whitelistFolders
|
||||
.sort((a, b) => a.position - b.position)
|
||||
.forEach((whitelistedFolder) => {
|
||||
if (whitelistedFolder.string?.trim() !== '' &&
|
||||
whitelistedFolder.path?.trim() === '') {
|
||||
addWhitelistedPatternListItem(this.settingsTab, contentEl, whitelistedFolder);
|
||||
} else {
|
||||
addWhitelistFolderListItem(this.settingsTab, contentEl, whitelistedFolder);
|
||||
}
|
||||
});
|
||||
this.plugin.settings.whitelistFolders.sort((a, b) => a.position - b.position).forEach((whitelistedFolder) => {
|
||||
if (whitelistedFolder.string?.trim() !== '' && whitelistedFolder.path?.trim() === '') {
|
||||
addWhitelistedPatternListItem(this.settingsTab, contentEl, whitelistedFolder);
|
||||
} else {
|
||||
addWhitelistFolderListItem(this.settingsTab, contentEl, whitelistedFolder);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onClose(): void {
|
||||
onClose() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,20 @@
|
|||
export class CustomEventEmitter {
|
||||
private events: { [key: string]: Array<(data?: unknown) => void> } = {};
|
||||
private events: { [key: string]: Array<(data?: any) => void> } = {};
|
||||
|
||||
on(event: string, listener: (data?: unknown) => void): void {
|
||||
on(event: string, listener: (data?: any) => void) {
|
||||
if (!this.events[event]) {
|
||||
this.events[event] = [];
|
||||
}
|
||||
this.events[event].push(listener);
|
||||
}
|
||||
|
||||
off(event: string, listener: (data?: unknown) => void): void {
|
||||
off(event: string, listener: (data?: any) => void) {
|
||||
if (!this.events[event]) return;
|
||||
|
||||
this.events[event] = this.events[event].filter((l) => l !== listener);
|
||||
}
|
||||
|
||||
emit(event: string, data?: unknown): void {
|
||||
emit(event: string, data?: any) {
|
||||
if (!this.events[event]) return;
|
||||
|
||||
this.events[event].forEach((listener) => listener(data));
|
||||
|
|
|
|||
|
|
@ -1,41 +1,20 @@
|
|||
import type FolderNotesPlugin from 'src/main';
|
||||
import {
|
||||
type Listener,
|
||||
type Events,
|
||||
type ApiInterface,
|
||||
type DeferInterface,
|
||||
type ListenerRef,
|
||||
type EventDispatcherInterface,
|
||||
getDefer,
|
||||
} from 'front-matter-plugin-api-provider';
|
||||
import { type App, TFile, TFolder } from 'obsidian';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
import { getDefer, Listener, Events, ApiInterface, DeferInterface, ListenerRef, EventDispatcherInterface } from 'front-matter-plugin-api-provider';
|
||||
import { App, TFile, TFolder } from 'obsidian';
|
||||
import { getFolder, getFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
|
||||
interface UpdateData {
|
||||
id: string;
|
||||
result: boolean;
|
||||
path: string;
|
||||
pathOnly: boolean;
|
||||
breadcrumb?: HTMLElement;
|
||||
}
|
||||
|
||||
interface WrappedUpdateData {
|
||||
data: UpdateData;
|
||||
}
|
||||
|
||||
export class FrontMatterTitlePluginHandler {
|
||||
plugin: FolderNotesPlugin;
|
||||
app!: App;
|
||||
app: App;
|
||||
api: ApiInterface | null = null;
|
||||
deffer: DeferInterface | null = null;
|
||||
modifiedFolders: Map<string, TFolder> = new Map();
|
||||
eventRef: ListenerRef<'manager:update'> | null = null;
|
||||
dispatcher: EventDispatcherInterface<Events> | null = null;
|
||||
eventRef: ListenerRef<'manager:update'>;
|
||||
dispatcher: EventDispatcherInterface<Events>;
|
||||
constructor(plugin: FolderNotesPlugin) {
|
||||
this.plugin = plugin;
|
||||
this.app = plugin.app;
|
||||
|
||||
(async (): Promise<void> => {
|
||||
(async () => {
|
||||
this.deffer = getDefer(this.app);
|
||||
if (this.deffer.isPluginReady()) {
|
||||
this.api = this.deffer.getApi();
|
||||
|
|
@ -47,41 +26,39 @@ export class FrontMatterTitlePluginHandler {
|
|||
await this.deffer.awaitFeatures();
|
||||
}
|
||||
}
|
||||
if (plugin.settings.frontMatterTitle.enabled) {
|
||||
const dispatcher = this.api?.getEventDispatcher();
|
||||
if (dispatcher) {
|
||||
this.dispatcher = dispatcher;
|
||||
}
|
||||
const event: Listener<Events, 'manager:update'> = {
|
||||
name: 'manager:update',
|
||||
cb: (data): void => {
|
||||
this.fmptUpdateFileName(data as unknown as UpdateData, true);
|
||||
},
|
||||
};
|
||||
// Keep ref to remove listener
|
||||
const ref = dispatcher?.addListener(event);
|
||||
if (ref) {
|
||||
this.eventRef = ref;
|
||||
}
|
||||
// this.plugin.app.vault.getFiles().forEach((file) => {
|
||||
// this.handleRename({ id: '', result: false, path: file.path }, false);
|
||||
// });
|
||||
plugin.updateAllBreadcrumbs();
|
||||
const dispatcher = this.api?.getEventDispatcher();
|
||||
if (dispatcher) {
|
||||
this.dispatcher = dispatcher;
|
||||
}
|
||||
const event: Listener<Events, 'manager:update'> = {
|
||||
name: 'manager:update',
|
||||
cb: (data) => {
|
||||
this.handleRename(data as any, true);
|
||||
},
|
||||
};
|
||||
// Keep ref to remove listener
|
||||
const ref = dispatcher?.addListener(event);
|
||||
if (ref) {
|
||||
this.eventRef = ref;
|
||||
}
|
||||
// this.plugin.app.vault.getFiles().forEach((file) => {
|
||||
// this.handleRename({ id: '', result: false, path: file.path }, false);
|
||||
// });
|
||||
this.plugin.updateBreadcrumbs();
|
||||
})();
|
||||
}
|
||||
|
||||
deleteEvent(): void {
|
||||
if (this.eventRef && this.dispatcher) {
|
||||
deleteEvent() {
|
||||
if (this.eventRef) {
|
||||
this.dispatcher.removeListener(this.eventRef);
|
||||
}
|
||||
}
|
||||
async fmptUpdateFileName(data: UpdateData, isEvent: boolean): Promise<void> {
|
||||
const hasNestedData = 'data' in (data as unknown as Record<string, unknown>);
|
||||
const actualData: UpdateData = hasNestedData
|
||||
? (data as unknown as WrappedUpdateData).data
|
||||
: data;
|
||||
const file = this.app.vault.getAbstractFileByPath(actualData.path);
|
||||
async handleRename(data: {
|
||||
id: string;
|
||||
result: boolean;
|
||||
path: string;
|
||||
}, isEvent: boolean) {
|
||||
if ((data as any).data) data = (data as any).data;
|
||||
const file = this.app.vault.getAbstractFileByPath(data.path);
|
||||
if (!(file instanceof TFile)) { return; }
|
||||
|
||||
const resolver = this.api?.getResolverFactory()?.createResolver('#feature-id#');
|
||||
|
|
@ -92,19 +69,12 @@ export class FrontMatterTitlePluginHandler {
|
|||
const folderNote = getFolderNote(this.plugin, folder.path);
|
||||
if (!folderNote) { return; }
|
||||
if (folderNote !== file) { return; }
|
||||
if (!actualData.pathOnly) {
|
||||
this.plugin.changeFolderNameInExplorer(folder, newName);
|
||||
}
|
||||
|
||||
const { breadcrumb } = actualData;
|
||||
if (breadcrumb) {
|
||||
this.plugin.changeFolderNameInPath(folder, newName, breadcrumb);
|
||||
}
|
||||
|
||||
if (isEvent) {
|
||||
this.plugin.updateAllBreadcrumbs();
|
||||
this.plugin.changeName(folder, newName, true);
|
||||
} else {
|
||||
this.plugin.changeName(folder, newName, false);
|
||||
}
|
||||
|
||||
if (newName) {
|
||||
folder.newName = newName;
|
||||
this.modifiedFolders.set(folder.path, folder);
|
||||
|
|
@ -115,12 +85,13 @@ export class FrontMatterTitlePluginHandler {
|
|||
|
||||
}
|
||||
|
||||
async fmptUpdateFolderName(data: UpdateData, _replacePath: boolean): Promise<void> {
|
||||
const hasNestedData = 'data' in (data as unknown as Record<string, unknown>);
|
||||
const actualData: UpdateData = hasNestedData
|
||||
? (data as unknown as WrappedUpdateData).data
|
||||
: data;
|
||||
const folder = this.app.vault.getAbstractFileByPath(actualData.path);
|
||||
async handleRenameFolder(data: {
|
||||
id: string;
|
||||
result: boolean;
|
||||
path: string;
|
||||
}, isEvent: boolean) {
|
||||
if ((data as any).data) data = (data as any).data;
|
||||
const folder = this.app.vault.getAbstractFileByPath(data.path);
|
||||
if (!(folder instanceof TFolder)) { return; }
|
||||
const folderNote = getFolderNote(this.plugin, folder.path);
|
||||
if (!folderNote) { return; }
|
||||
|
|
@ -129,35 +100,12 @@ export class FrontMatterTitlePluginHandler {
|
|||
const newName = resolver?.resolve(folderNote?.path ?? '');
|
||||
if (!newName) return;
|
||||
|
||||
if (!actualData.pathOnly) {
|
||||
this.plugin.changeFolderNameInExplorer(folder, newName);
|
||||
if (isEvent) {
|
||||
this.plugin.changeName(folder, newName, true);
|
||||
} else {
|
||||
this.plugin.changeName(folder, newName, false);
|
||||
}
|
||||
|
||||
const { breadcrumb } = actualData;
|
||||
if (breadcrumb) {
|
||||
this.plugin.changeFolderNameInPath(folder, newName, breadcrumb);
|
||||
}
|
||||
|
||||
folder.newName = newName;
|
||||
this.modifiedFolders.set(folder.path, folder);
|
||||
}
|
||||
|
||||
async getNewFolderName(folder: TFolder): Promise<string | null> {
|
||||
if (this.modifiedFolders.has(folder.path)) {
|
||||
const modifiedFolder = this.modifiedFolders.get(folder.path);
|
||||
if (modifiedFolder) {
|
||||
return modifiedFolder.newName;
|
||||
}
|
||||
}
|
||||
const folderNote = getFolderNote(this.plugin, folder.path);
|
||||
if (!folderNote) return null;
|
||||
const resolver = this.api?.getResolverFactory()?.createResolver('#feature-id#');
|
||||
return resolver?.resolve(folderNote?.path ?? '') ?? null;
|
||||
}
|
||||
|
||||
async getNewFileName(file: TFile): Promise<string | null> {
|
||||
const resolver = this.api?.getResolverFactory()?.createResolver('#feature-id#');
|
||||
const changedName = resolver?.resolve(file?.path ?? '');
|
||||
return changedName ?? null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import { Keymap, Platform } from 'obsidian';
|
||||
import type FolderNotesPlugin from 'src/main';
|
||||
import { getFolderNote, getFolderNoteFolder } from 'src/functions/folderNoteFunctions';
|
||||
import { handleViewHeaderClick } from './handleClick';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
import { getFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
import { handleFolderClick, handleViewHeaderClick } from './handleClick';
|
||||
import { getExcludedFolder } from 'src/ExcludeFolders/functions/folderFunctions';
|
||||
import { updateCSSClassesForFolder } from 'src/functions/styleFunctions';
|
||||
import { applyCSSClassesToFolder } from 'src/functions/styleFunctions';
|
||||
|
||||
let fileExplorerMutationObserver: MutationObserver | null = null;
|
||||
|
||||
export function registerFileExplorerObserver(plugin: FolderNotesPlugin): void {
|
||||
export function registerFileExplorerObserver(plugin: FolderNotesPlugin) {
|
||||
// Run once on initial layout
|
||||
plugin.app.workspace.onLayoutReady(() => {
|
||||
initializeFolderNoteFeatures(plugin);
|
||||
|
|
@ -25,29 +25,32 @@ export function registerFileExplorerObserver(plugin: FolderNotesPlugin): void {
|
|||
const titleContainer = activeLeaf.querySelector('.view-header-title-container');
|
||||
if (!(titleContainer instanceof HTMLElement)) return;
|
||||
|
||||
updateFolderNamesInPath(plugin, titleContainer);
|
||||
}),
|
||||
updateBreadcrumbs(plugin, titleContainer);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function unregisterFileExplorerObserver(): void {
|
||||
export function unregisterFileExplorerObserver() {
|
||||
if (fileExplorerMutationObserver) {
|
||||
fileExplorerMutationObserver.disconnect();
|
||||
fileExplorerMutationObserver = null;
|
||||
}
|
||||
}
|
||||
|
||||
function initializeFolderNoteFeatures(plugin: FolderNotesPlugin): void {
|
||||
initializeAllFolderTitles(plugin);
|
||||
observeFolderTitleMutations(plugin);
|
||||
function initializeFolderNoteFeatures(plugin: FolderNotesPlugin) {
|
||||
const explorer = document.querySelector('.workspace-leaf-content[data-type="file-explorer"] .nav-files-container');
|
||||
if (!explorer) return;
|
||||
|
||||
initializeAllFolderTitles(explorer, plugin);
|
||||
observeFolderTitleMutations(explorer, plugin);
|
||||
}
|
||||
|
||||
function initializeBreadcrumbs(plugin: FolderNotesPlugin): void {
|
||||
const titleContainers = activeDocument.querySelectorAll('.view-header-title-container');
|
||||
function initializeBreadcrumbs(plugin: FolderNotesPlugin) {
|
||||
const titleContainers = document.querySelectorAll('.view-header-title-container');
|
||||
if (!titleContainers.length) return;
|
||||
titleContainers.forEach((container) => {
|
||||
if (!(container.instanceOf(HTMLElement))) return;
|
||||
scheduleIdle(() => updateFolderNamesInPath(plugin, container), { timeout: 1000 });
|
||||
if (!(container instanceof HTMLElement)) return;
|
||||
scheduleIdle(() => updateBreadcrumbs(plugin, container), { timeout: 1000 });
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -55,35 +58,37 @@ function initializeBreadcrumbs(plugin: FolderNotesPlugin): void {
|
|||
* Observes the File Explorer for newly added folder elements and applies plugin logic (e.g., styles, event listeners)
|
||||
* automatically when folders are created, expanded, or when the File Explorer view is reopened.
|
||||
*/
|
||||
function observeFolderTitleMutations(plugin: FolderNotesPlugin): void {
|
||||
function observeFolderTitleMutations(container: Element, plugin: FolderNotesPlugin) {
|
||||
if (fileExplorerMutationObserver) {
|
||||
fileExplorerMutationObserver.disconnect();
|
||||
}
|
||||
fileExplorerMutationObserver = new MutationObserver((mutations) => {
|
||||
for (const mutation of mutations) {
|
||||
for (const node of Array.from(mutation.addedNodes)) {
|
||||
if (!(node.instanceOf(HTMLElement))) continue;
|
||||
processAddedFolders(node, plugin);
|
||||
if (!(node instanceof HTMLElement)) continue;
|
||||
processAddedFolderNodes(node, plugin);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fileExplorerMutationObserver.observe(document, { childList: true, subtree: true });
|
||||
fileExplorerMutationObserver.observe(container, { childList: true, subtree: true });
|
||||
}
|
||||
|
||||
function initializeAllFolderTitles(plugin: FolderNotesPlugin): void {
|
||||
const allTitles = activeDocument.querySelectorAll('.nav-folder-title-content');
|
||||
function initializeAllFolderTitles(container: Element, plugin: FolderNotesPlugin) {
|
||||
const allTitles = container.querySelectorAll('.nav-folder-title-content');
|
||||
for (const title of Array.from(allTitles)) {
|
||||
const folderTitle = title as HTMLElement;
|
||||
const folderEl = folderTitle.closest('.nav-folder-title');
|
||||
if (!folderEl) continue;
|
||||
|
||||
const folderPath = folderEl.getAttribute('data-path') || '';
|
||||
setupFolderTitle(folderTitle, plugin, folderPath);
|
||||
setTimeout(() => {
|
||||
setupFolderTitle(folderTitle, plugin, folderPath);
|
||||
}, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
function processAddedFolders(node: HTMLElement, plugin: FolderNotesPlugin): void {
|
||||
function processAddedFolderNodes(node: HTMLElement, plugin: FolderNotesPlugin) {
|
||||
const titles: HTMLElement[] = [];
|
||||
if (node.matches('.nav-folder-title-content')) {
|
||||
titles.push(node);
|
||||
|
|
@ -95,40 +100,37 @@ function processAddedFolders(node: HTMLElement, plugin: FolderNotesPlugin): void
|
|||
titles.forEach((folderTitle) => {
|
||||
const folderEl = folderTitle.closest('.nav-folder-title');
|
||||
const folderPath = folderEl?.getAttribute('data-path') || '';
|
||||
const RETRY_TIMEOUT = 50;
|
||||
if (!folderEl || !folderPath) {
|
||||
window.setTimeout(() => {
|
||||
setTimeout(() => {
|
||||
const retryFolderEl = folderTitle.closest('.nav-folder-title');
|
||||
const retryFolderPath = retryFolderEl?.getAttribute('data-path') || '';
|
||||
if (retryFolderEl && retryFolderPath) {
|
||||
setupFolderTitle(folderTitle, plugin, retryFolderPath);
|
||||
}
|
||||
}, RETRY_TIMEOUT);
|
||||
}, 50);
|
||||
return;
|
||||
}
|
||||
setupFolderTitle(folderTitle, plugin, folderPath);
|
||||
});
|
||||
}
|
||||
|
||||
async function setupFolderTitle(
|
||||
folderTitle: HTMLElement,
|
||||
plugin: FolderNotesPlugin,
|
||||
folderPath: string,
|
||||
): Promise<void> {
|
||||
async function setupFolderTitle(folderTitle: HTMLElement, plugin: FolderNotesPlugin, folderPath: string) {
|
||||
if (folderTitle.dataset.initialized === 'true') return;
|
||||
if (!folderPath) return;
|
||||
if (Platform.isMobile && plugin.settings.disableOpenFolderNoteOnClick) return;
|
||||
|
||||
folderTitle.dataset.initialized = 'true';
|
||||
await updateCSSClassesForFolder(folderPath, plugin);
|
||||
await applyCSSClassesToFolder(folderPath, plugin);
|
||||
|
||||
if (plugin.settings.frontMatterTitle.enabled) {
|
||||
plugin.fmtpHandler?.fmptUpdateFolderName(
|
||||
{ id: '', result: false, path: folderPath, pathOnly: false },
|
||||
false,
|
||||
);
|
||||
plugin.fmtpHandler?.handleRenameFolder({ id: '', result: false, path: folderPath }, false);
|
||||
}
|
||||
|
||||
if (Platform.isMobile && plugin.settings.disableOpenFolderNoteOnClick) return;
|
||||
folderTitle.addEventListener('auxclick', (event: MouseEvent) => {
|
||||
if (event.button === 1) handleFolderClick(event, plugin);
|
||||
}, { capture: true });
|
||||
|
||||
folderTitle.onclick = (event: MouseEvent) => handleFolderClick(event, plugin);
|
||||
|
||||
plugin.registerDomEvent(folderTitle, 'pointerover', (event: MouseEvent) => {
|
||||
plugin.hoveredElement = folderTitle;
|
||||
|
|
@ -158,83 +160,39 @@ async function setupFolderTitle(
|
|||
});
|
||||
}
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
async function updateFolderNamesInPath(
|
||||
plugin: FolderNotesPlugin,
|
||||
titleContainer: HTMLElement,
|
||||
): Promise<void> {
|
||||
const titleParent = titleContainer.querySelector('.view-header-title-parent');
|
||||
async function updateBreadcrumbs(plugin: FolderNotesPlugin, titleContainer: HTMLElement) {
|
||||
const headers = titleContainer.querySelectorAll('span.view-header-breadcrumb');
|
||||
let path = '';
|
||||
const TRAILING_SLASH_LENGTH = 1;
|
||||
|
||||
if (titleParent?.childNodes.length === 0) {
|
||||
titleContainer.classList.remove('hide-folder-note-title-in-path');
|
||||
}
|
||||
|
||||
for (const breadcrumb of Array.from(titleParent?.childNodes ?? [])) {
|
||||
if (!(breadcrumb instanceof HTMLElement)) continue;
|
||||
if (breadcrumb.classList.contains('view-header-breadcrumb-separator')) {
|
||||
if (breadcrumb.nextSibling === null) {
|
||||
breadcrumb.classList.add('is-last-separator');
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
path += breadcrumb.getAttribute('old-name') ?? (breadcrumb).innerText.trim();
|
||||
headers.forEach(async (breadcrumb: HTMLElement) => {
|
||||
path += breadcrumb.getAttribute('old-name') ?? (breadcrumb as HTMLElement).innerText.trim();
|
||||
path += '/';
|
||||
const folderPath = path.slice(0, -TRAILING_SLASH_LENGTH);
|
||||
const folderPath = path.slice(0, -1);
|
||||
if (plugin.settings.frontMatterTitle.enabled) {
|
||||
plugin.fmtpHandler?.handleRenameFolder({ id: '', result: false, path: folderPath }, false);
|
||||
}
|
||||
|
||||
const excludedFolder = getExcludedFolder(plugin, folderPath, true);
|
||||
if (excludedFolder?.disableFolderNote) return;
|
||||
const folderNote = getFolderNote(plugin, folderPath);
|
||||
const viewHeaderTitle = titleContainer.querySelector('.view-header-title');
|
||||
if (folderNote) breadcrumb.classList.add('has-folder-note');
|
||||
|
||||
if (viewHeaderTitle && folderNote) {
|
||||
const filePath = path + (viewHeaderTitle as HTMLElement).innerText.trim() + '.md';
|
||||
const file = plugin.app.vault.getAbstractFileByPath(
|
||||
filePath);
|
||||
const folder = getFolderNoteFolder(plugin, folderNote, file?.name ?? '');
|
||||
if (folder && file && file.path === folderNote?.path && file.parent?.path !== '/') {
|
||||
viewHeaderTitle.parentElement?.classList.add('hide-folder-note-title-in-path');
|
||||
viewHeaderTitle.classList.add('path-is-folder-note');
|
||||
} else {
|
||||
viewHeaderTitle.parentElement?.classList.remove('hide-folder-note-title-in-path');
|
||||
viewHeaderTitle.classList.remove('path-is-folder-note');
|
||||
}
|
||||
}
|
||||
if (!folderNote) {
|
||||
breadcrumb.classList.remove('has-folder-note');
|
||||
breadcrumb.removeAttribute('data-path');
|
||||
continue;
|
||||
}
|
||||
breadcrumb.classList.add('has-folder-note');
|
||||
breadcrumb?.setAttribute('data-path', path.slice(0, -TRAILING_SLASH_LENGTH));
|
||||
|
||||
breadcrumb?.setAttribute('data-path', path.slice(0, -1));
|
||||
if (!breadcrumb.onclick) {
|
||||
breadcrumb.addEventListener('click', (e) => {
|
||||
handleViewHeaderClick(e, plugin);
|
||||
handleViewHeaderClick(e as MouseEvent, plugin);
|
||||
}, { capture: true });
|
||||
}
|
||||
|
||||
if (plugin.settings.frontMatterTitle.enabled) {
|
||||
plugin.fmtpHandler?.fmptUpdateFolderName(
|
||||
{ id: '', result: false, path: folderPath, pathOnly: true, breadcrumb: breadcrumb },
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Schedules a callback to run when the browser is idle, or after a timeout as a fallback.
|
||||
// - callback: The function to execute when idle or after the timeout.
|
||||
// - options: Optional object with a 'timeout' property (in milliseconds).
|
||||
function scheduleIdle(callback: () => void, options?: { timeout: number }): void {
|
||||
const DEFAULT_IDLE_TIMEOUT = 200;
|
||||
function scheduleIdle(callback: () => void, options?: { timeout: number }) {
|
||||
if ('requestIdleCallback' in window) {
|
||||
const windowWithIdle = window as Window & {
|
||||
requestIdleCallback: (callback: () => void, options?: { timeout: number }) => void
|
||||
};
|
||||
windowWithIdle.requestIdleCallback(callback, options);
|
||||
(window as any).requestIdleCallback(callback, options);
|
||||
} else {
|
||||
globalThis.setTimeout(callback, options?.timeout || DEFAULT_IDLE_TIMEOUT);
|
||||
setTimeout(callback, options?.timeout || 200);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type FolderNotesPlugin from 'src/main';
|
||||
import { EditableFileView, TFolder, type App } from 'obsidian';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
import { App, EditableFileView, TFolder } from 'obsidian';
|
||||
import { getFolder, getFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
export class TabManager {
|
||||
plugin: FolderNotesPlugin;
|
||||
|
|
@ -9,18 +9,19 @@ export class TabManager {
|
|||
this.app = plugin.app;
|
||||
}
|
||||
|
||||
resetTabs(): void {
|
||||
resetTabs() {
|
||||
if (!this.isEnabled()) return;
|
||||
|
||||
this.app.workspace.iterateAllLeaves((leaf) => {
|
||||
if (!(leaf.view instanceof EditableFileView)) return;
|
||||
const file = leaf.view?.file;
|
||||
if (!file) return;
|
||||
// @ts-ignore
|
||||
leaf.tabHeaderInnerTitleEl.setText(file.basename);
|
||||
});
|
||||
}
|
||||
|
||||
updateTabs(): void {
|
||||
updateTabs() {
|
||||
if (!this.isEnabled()) return;
|
||||
this.app.workspace.iterateAllLeaves((leaf) => {
|
||||
if (!(leaf.view instanceof EditableFileView)) return;
|
||||
|
|
@ -28,11 +29,12 @@ export class TabManager {
|
|||
if (!file) return;
|
||||
const folder = getFolder(this.plugin, file);
|
||||
if (!folder) return;
|
||||
// @ts-ignore
|
||||
leaf.tabHeaderInnerTitleEl.setText(folder.name);
|
||||
});
|
||||
}
|
||||
|
||||
updateTab(folderPath: string): void {
|
||||
updateTab(folderPath: string) {
|
||||
if (!this.isEnabled()) return;
|
||||
|
||||
const folder = this.app.vault.getAbstractFileByPath(folderPath);
|
||||
|
|
@ -46,12 +48,13 @@ export class TabManager {
|
|||
const file = leaf.view?.file;
|
||||
if (!file) return;
|
||||
if (file.path === folderNote.path) {
|
||||
// @ts-ignore
|
||||
leaf.tabHeaderInnerTitleEl.setText(folder.name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
isEnabled(): boolean {
|
||||
isEnabled() {
|
||||
if (this.plugin.settings.folderNoteName === '{{folder_name}}') return false;
|
||||
return this.plugin.settings.tabManagerEnabled;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,81 +1,102 @@
|
|||
import { Keymap, Platform, type TFile } from 'obsidian';
|
||||
import type FolderNotesPlugin from 'src/main';
|
||||
import { Keymap, Platform } from 'obsidian';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
import { openFolderNote, createFolderNote, getFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
import { getExcludedFolder } from 'src/ExcludeFolders/functions/folderFunctions';
|
||||
import {
|
||||
addCSSClassToFileExplorerEl,
|
||||
removeCSSClassFromFileExplorerEL,
|
||||
} from 'src/functions/styleFunctions';
|
||||
import { addCSSClassToTitleEL, removeCSSClassFromEL } from 'src/functions/styleFunctions';
|
||||
|
||||
|
||||
|
||||
export async function handleViewHeaderClick(
|
||||
event: MouseEvent,
|
||||
plugin: FolderNotesPlugin,
|
||||
): Promise<void> {
|
||||
if (!plugin.settings.openFolderNoteOnClickInPath) return;
|
||||
export async function handleViewHeaderClick(event: MouseEvent, plugin: FolderNotesPlugin) {
|
||||
event.stopImmediatePropagation();
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (!(event.target instanceof HTMLElement)) return;
|
||||
if (!plugin.settings.openFolderNoteOnClickInPath) return;
|
||||
|
||||
const folderPath = event.target.getAttribute('data-path');
|
||||
if (!folderPath) { return; }
|
||||
|
||||
if (await isExcludedFolder(event, plugin, folderPath)) return;
|
||||
const excludedFolder = getExcludedFolder(plugin, folderPath, true);
|
||||
if (excludedFolder?.disableFolderNote) {
|
||||
event.target.onclick = null;
|
||||
event.target.click();
|
||||
return;
|
||||
} else if (excludedFolder?.enableCollapsing || plugin.settings.enableCollapsing) {
|
||||
event.target.onclick = null;
|
||||
event.target.click();
|
||||
}
|
||||
|
||||
const folderNote = getFolderNote(plugin, folderPath);
|
||||
if (folderNote) {
|
||||
await openFolderNote(plugin, folderNote, event).then(() =>
|
||||
handleFolderNoteReveal(plugin, folderNote),
|
||||
);
|
||||
await openFolderNote(plugin, folderNote, event).then(async () => {
|
||||
// @ts-ignore
|
||||
const fileExplorerPlugin = plugin.app.internalPlugins.getEnabledPluginById('file-explorer');
|
||||
if (fileExplorerPlugin && Platform.isMobile && plugin.settings.openSidebar.mobile) {
|
||||
setTimeout(() => { fileExplorerPlugin.revealInFolder(folderNote); }, 200);
|
||||
} else if (fileExplorerPlugin && Platform.isDesktop && plugin.settings.openSidebar.desktop) {
|
||||
fileExplorerPlugin.revealInFolder(folderNote);
|
||||
}
|
||||
});
|
||||
return;
|
||||
} else if (event.altKey || Keymap.isModEvent(event) === 'tab') {
|
||||
if (await handleFolderNoteCreation(event, plugin, folderPath)) return;
|
||||
if ((plugin.settings.altKey && event.altKey) || (plugin.settings.ctrlKey && Keymap.isModEvent(event) === 'tab')) {
|
||||
await createFolderNote(plugin, folderPath, true, undefined, true);
|
||||
addCSSClassToTitleEL(folderPath, 'has-folder-note', plugin);
|
||||
removeCSSClassFromEL(folderPath, 'has-not-folder-note', plugin);
|
||||
return;
|
||||
}
|
||||
}
|
||||
(event.target).onclick = null;
|
||||
(event.target).click();
|
||||
event.target.onclick = null;
|
||||
event.target.click();
|
||||
}
|
||||
|
||||
async function isExcludedFolder(
|
||||
event: MouseEvent,
|
||||
plugin: FolderNotesPlugin,
|
||||
folderPath: string,
|
||||
): Promise<boolean> {
|
||||
export async function handleFolderClick(event: MouseEvent, plugin: FolderNotesPlugin) {
|
||||
|
||||
if (!(event.target instanceof HTMLElement)) return;
|
||||
if (!event || !event.target) return;
|
||||
|
||||
if (!event.shiftKey) {
|
||||
event.stopImmediatePropagation();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
const folderPath = event.target.parentElement?.getAttribute('data-path');
|
||||
if (!folderPath) { return; }
|
||||
|
||||
const excludedFolder = getExcludedFolder(plugin, folderPath, true);
|
||||
if (excludedFolder?.disableFolderNote) {
|
||||
(event.target as HTMLElement).onclick = null;
|
||||
(event.target as HTMLElement).click();
|
||||
return true;
|
||||
event.target.onclick = null;
|
||||
event.target.click();
|
||||
return;
|
||||
} else if (excludedFolder?.enableCollapsing || plugin.settings.enableCollapsing) {
|
||||
(event.target as HTMLElement).onclick = null;
|
||||
(event.target as HTMLElement).click();
|
||||
event.target.onclick = null;
|
||||
event.target.click();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async function handleFolderNoteReveal(plugin: FolderNotesPlugin, folderNote: TFile): Promise<void> {
|
||||
const fileExplorerPlugin = plugin.app.internalPlugins.getEnabledPluginById('file-explorer');
|
||||
if (fileExplorerPlugin && Platform.isMobile && plugin.settings.openSidebar.mobile) {
|
||||
const OPEN_SIDEBAR_DELAY = 200;
|
||||
window.setTimeout(() => { fileExplorerPlugin.revealInFolder(folderNote); }, OPEN_SIDEBAR_DELAY);
|
||||
} else if (fileExplorerPlugin && Platform.isDesktop && plugin.settings.openSidebar.desktop) {
|
||||
fileExplorerPlugin.revealInFolder(folderNote);
|
||||
}
|
||||
}
|
||||
const folderNote = getFolderNote(plugin, folderPath);
|
||||
|
||||
async function handleFolderNoteCreation(
|
||||
event: MouseEvent,
|
||||
plugin: FolderNotesPlugin,
|
||||
folderPath: string,
|
||||
): Promise<boolean> {
|
||||
const usedCtrl = Platform.isMacOS ? event.metaKey : event.ctrlKey;
|
||||
if ((plugin.settings.altKey && event.altKey) ||
|
||||
(usedCtrl && Keymap.isModEvent(event) === 'tab')) {
|
||||
await createFolderNote(plugin, folderPath, true, undefined, true);
|
||||
addCSSClassToFileExplorerEl(folderPath, 'has-folder-note', false, plugin);
|
||||
removeCSSClassFromFileExplorerEL(folderPath, 'has-not-folder-note', false, plugin);
|
||||
return true;
|
||||
if (folderNote) {
|
||||
if (plugin.settings.openByClick) {
|
||||
return openFolderNote(plugin, folderNote, event);
|
||||
} else if (plugin.settings.openWithCtrl && Keymap.isModEvent(event) === 'tab') {
|
||||
return openFolderNote(plugin, folderNote, event);
|
||||
} else if (plugin.settings.openWithAlt && event.altKey) {
|
||||
return openFolderNote(plugin, folderNote, event);
|
||||
} else {
|
||||
if (plugin.settings.enableCollapsing) return;
|
||||
event.target.parentElement?.click();
|
||||
return;
|
||||
}
|
||||
} else if (event.altKey || Keymap.isModEvent(event) === 'tab') {
|
||||
if ((plugin.settings.altKey && event.altKey) || (plugin.settings.ctrlKey && Keymap.isModEvent(event) === 'tab')) {
|
||||
await createFolderNote(plugin, folderPath, true, undefined, true);
|
||||
addCSSClassToTitleEL(folderPath, 'has-folder-note', plugin);
|
||||
removeCSSClassFromEL(folderPath, 'has-not-folder-note', plugin);
|
||||
return;
|
||||
}
|
||||
} else if (!folderNote) {
|
||||
if (plugin.settings.enableCollapsing) return;
|
||||
return event.target.parentElement?.click();
|
||||
}
|
||||
return false;
|
||||
|
||||
event.target.onclick = null;
|
||||
event.target.click();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,18 @@
|
|||
import { TFolder, TFile, type TAbstractFile } from 'obsidian';
|
||||
import type FolderNotesPlugin from 'src/main';
|
||||
import {
|
||||
createFolderNote,
|
||||
getFolder,
|
||||
getFolderNote,
|
||||
turnIntoFolderNote,
|
||||
} from 'src/functions/folderNoteFunctions';
|
||||
import { TAbstractFile, TFolder, TFile } from 'obsidian';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
import { createFolderNote, getFolder, getFolderNote, turnIntoFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
import { getExcludedFolder } from 'src/ExcludeFolders/functions/folderFunctions';
|
||||
import {
|
||||
removeCSSClassFromFileExplorerEL,
|
||||
addCSSClassToFileExplorerEl,
|
||||
} from 'src/functions/styleFunctions';
|
||||
import { isFileInAttachmentFolder } from '@app/functions/utils';
|
||||
import { removeCSSClassFromEL, addCSSClassToTitleEL } from 'src/functions/styleFunctions';
|
||||
|
||||
export async function handleCreate(file: TAbstractFile, plugin: FolderNotesPlugin): Promise<void> {
|
||||
export async function handleCreate(file: TAbstractFile, plugin: FolderNotesPlugin) {
|
||||
if (!plugin.app.workspace.layoutReady) return;
|
||||
|
||||
const folder = file.parent;
|
||||
if (folder instanceof TFolder) {
|
||||
if (plugin.isEmptyFolderNoteFolder(folder) && getFolderNote(plugin, folder.path)) {
|
||||
addCSSClassToFileExplorerEl(folder.path, 'only-has-folder-note', true, plugin);
|
||||
if (plugin.isEmptyFolderNoteFolder(folder)) {
|
||||
addCSSClassToTitleEL(folder.path, 'only-has-folder-note', plugin);
|
||||
} else {
|
||||
removeCSSClassFromFileExplorerEL(folder.path, 'only-has-folder-note', true, plugin);
|
||||
removeCSSClassFromEL(folder.path, 'only-has-folder-note', plugin);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -32,7 +23,7 @@ export async function handleCreate(file: TAbstractFile, plugin: FolderNotesPlugi
|
|||
}
|
||||
}
|
||||
|
||||
async function handleFileCreation(file: TFile, plugin: FolderNotesPlugin): Promise<void> {
|
||||
async function handleFileCreation(file: TFile, plugin: FolderNotesPlugin) {
|
||||
const folder = getFolder(plugin, file);
|
||||
|
||||
if (!(folder instanceof TFolder) && plugin.settings.autoCreateForFiles) {
|
||||
|
|
@ -40,19 +31,14 @@ async function handleFileCreation(file: TFile, plugin: FolderNotesPlugin): Promi
|
|||
const newFolder = await plugin.app.fileManager.createNewFolder(file.parent);
|
||||
turnIntoFolderNote(plugin, file, newFolder);
|
||||
} else if (folder instanceof TFolder) {
|
||||
if (folder.children.length >= 1) {
|
||||
removeCSSClassFromFileExplorerEL(folder.path, 'fn-empty-folder', false, plugin);
|
||||
}
|
||||
|
||||
const detachedFolder = getExcludedFolder(plugin, folder.path, true);
|
||||
if (detachedFolder) { return; }
|
||||
const folderNote = getFolderNote(plugin, folder.path);
|
||||
|
||||
if (folderNote && folderNote.path === file.path) {
|
||||
addCSSClassToFileExplorerEl(folder.path, 'has-folder-note', false, plugin);
|
||||
addCSSClassToFileExplorerEl(file.path, 'is-folder-note', false, plugin);
|
||||
} else if (plugin.settings.autoCreateForFiles && !isFileInAttachmentFolder(plugin, file)) {
|
||||
if (!plugin.settings.supportedFileTypes.includes(file.extension)) { return; }
|
||||
addCSSClassToTitleEL(folder.path, 'has-folder-note', plugin);
|
||||
addCSSClassToTitleEL(file.path, 'is-folder-note', plugin);
|
||||
} else if (plugin.settings.autoCreateForFiles) {
|
||||
if (!file.parent) { return; }
|
||||
const newFolder = await plugin.app.fileManager.createNewFolder(file.parent);
|
||||
turnIntoFolderNote(plugin, file, newFolder);
|
||||
|
|
@ -60,13 +46,12 @@ async function handleFileCreation(file: TFile, plugin: FolderNotesPlugin): Promi
|
|||
}
|
||||
}
|
||||
|
||||
async function handleFolderCreation(folder: TFolder, plugin: FolderNotesPlugin): Promise<void> {
|
||||
async function handleFolderCreation(folder: TFolder, plugin: FolderNotesPlugin) {
|
||||
let openFile = plugin.settings.autoCreateFocusFiles;
|
||||
|
||||
const attachmentFolderPath = plugin.app.vault.getConfig('attachmentFolderPath') as string;
|
||||
const cleanAttachmentFolderPath = attachmentFolderPath?.replace('./', '') || '';
|
||||
const attachmentsAreInRootFolder = attachmentFolderPath === './' || attachmentFolderPath === '';
|
||||
addCSSClassToFileExplorerEl(folder.path, 'fn-empty-folder', false, plugin);
|
||||
|
||||
if (!plugin.settings.autoCreateForAttachmentFolder) {
|
||||
if (!attachmentsAreInRootFolder && cleanAttachmentFolderPath === folder.name) return;
|
||||
|
|
@ -80,6 +65,6 @@ async function handleFolderCreation(folder: TFolder, plugin: FolderNotesPlugin):
|
|||
const folderNote = getFolderNote(plugin, folder.path);
|
||||
if (folderNote) return;
|
||||
|
||||
void createFolderNote(plugin, folder.path, openFile, undefined, true);
|
||||
addCSSClassToFileExplorerEl(folder.path, 'has-folder-note', false, plugin);
|
||||
createFolderNote(plugin, folder.path, openFile, undefined, true);
|
||||
addCSSClassToTitleEL(folder.path, 'has-folder-note', plugin);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,39 +1,32 @@
|
|||
import { TFolder, TFile, type TAbstractFile } from 'obsidian';
|
||||
import type FolderNotesPlugin from 'src/main';
|
||||
import { TAbstractFile, TFolder, TFile } from 'obsidian';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
import { getFolderNote, getFolder, deleteFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
import {
|
||||
removeCSSClassFromFileExplorerEL,
|
||||
addCSSClassToFileExplorerEl,
|
||||
hideFolderNoteInFileExplorer,
|
||||
} from 'src/functions/styleFunctions';
|
||||
import { removeCSSClassFromEL, addCSSClassToTitleEL } from 'src/functions/styleFunctions';
|
||||
import { getFolderPathFromString } from 'src/functions/utils';
|
||||
|
||||
export function handleDelete(file: TAbstractFile, plugin: FolderNotesPlugin): void {
|
||||
export function handleDelete(file: TAbstractFile, plugin: FolderNotesPlugin) {
|
||||
const folder = plugin.app.vault.getAbstractFileByPath(getFolderPathFromString(file.path));
|
||||
if (folder instanceof TFolder) {
|
||||
if (plugin.isEmptyFolderNoteFolder(folder) && getFolderNote(plugin, folder.path)) {
|
||||
addCSSClassToFileExplorerEl(folder.path, 'only-has-folder-note', true, plugin);
|
||||
if (plugin.isEmptyFolderNoteFolder(folder)) {
|
||||
addCSSClassToTitleEL(folder.path, 'only-has-folder-note', plugin);
|
||||
} else {
|
||||
removeCSSClassFromFileExplorerEL(folder.path, 'only-has-folder-note', true, plugin);
|
||||
removeCSSClassFromEL(folder.path, 'only-has-folder-note', plugin);
|
||||
}
|
||||
}
|
||||
|
||||
if (file instanceof TFile) {
|
||||
const folderNoteFolder = getFolder(plugin, file);
|
||||
if (!folderNoteFolder) { return; }
|
||||
const folderNote = getFolderNote(plugin, folderNoteFolder.path);
|
||||
const folder = getFolder(plugin, file);
|
||||
if (!folder) { return; }
|
||||
const folderNote = getFolderNote(plugin, folder.path);
|
||||
if (folderNote) { return; }
|
||||
removeCSSClassFromFileExplorerEL(folderNoteFolder.path, 'has-folder-note', false, plugin);
|
||||
removeCSSClassFromFileExplorerEL(
|
||||
folderNoteFolder.path, 'only-has-folder-note', true, plugin,
|
||||
);
|
||||
hideFolderNoteInFileExplorer(folderNoteFolder.path, plugin);
|
||||
removeCSSClassFromEL(folder.path, 'has-folder-note', plugin);
|
||||
removeCSSClassFromEL(folder.path, 'only-has-folder-note', plugin);
|
||||
}
|
||||
|
||||
if (!(file instanceof TFolder)) { return; }
|
||||
const folderNote = getFolderNote(plugin, file.path);
|
||||
if (!folderNote) { return; }
|
||||
removeCSSClassFromFileExplorerEL(folderNote.path, 'is-folder-note', false, plugin);
|
||||
removeCSSClassFromEL(folderNote.path, 'is-folder-note', plugin);
|
||||
if (!plugin.settings.syncDelete) { return; }
|
||||
deleteFolderNote(plugin, folderNote, false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,230 +1,109 @@
|
|||
import { TFile, TFolder, Notice, type TAbstractFile } from 'obsidian';
|
||||
import type FolderNotesPlugin from 'src/main';
|
||||
import {
|
||||
extractFolderName, getFolderNote, getFolderNoteFolder,
|
||||
} from '../functions/folderNoteFunctions';
|
||||
import {
|
||||
getExcludedFolder, addExcludedFolder,
|
||||
updateExcludedFolder, deleteExcludedFolder, getDetachedFolder,
|
||||
} from '../ExcludeFolders/functions/folderFunctions';
|
||||
import { TFile, TFolder, TAbstractFile, Notice } from 'obsidian';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
import { extractFolderName, getFolderNote, getFolderNoteFolder } from '../functions/folderNoteFunctions';
|
||||
import { getExcludedFolder, addExcludedFolder, updateExcludedFolder, deleteExcludedFolder, getDetachedFolder } from '../ExcludeFolders/functions/folderFunctions';
|
||||
import { ExcludedFolder } from 'src/ExcludeFolders/ExcludeFolder';
|
||||
import {
|
||||
removeCSSClassFromFileExplorerEL, addCSSClassToFileExplorerEl,
|
||||
markFileAsFolderNote, unmarkFileAsFolderNote,
|
||||
unmarkFolderAsFolderNote, markFolderWithFolderNoteClasses,
|
||||
hideFolderNoteInFileExplorer, removeActiveFolder, setActiveFolder,
|
||||
} from 'src/functions/styleFunctions';
|
||||
import {
|
||||
getFolderPathFromString, removeExtension, getFileNameFromPathString,
|
||||
} from 'src/functions/utils';
|
||||
import { removeCSSClassFromEL, addCSSClassToTitleEL } from 'src/functions/styleFunctions';
|
||||
import { getFolderPathFromString, removeExtension, getFileNameFromPathString } from 'src/functions/utils';
|
||||
|
||||
export function handleRename(
|
||||
file: TAbstractFile,
|
||||
oldPath: string,
|
||||
plugin: FolderNotesPlugin,
|
||||
): void {
|
||||
let folder = file.parent;
|
||||
export function handleRename(file: TAbstractFile, oldPath: string, plugin: FolderNotesPlugin) {
|
||||
const folder = file.parent;
|
||||
const oldFolder = plugin.app.vault.getAbstractFileByPath(getFolderPathFromString(oldPath));
|
||||
|
||||
const isRename = (file.parent?.path === getFolderPathFromString(oldPath));
|
||||
if (folder instanceof TFolder) {
|
||||
if (plugin.isEmptyFolderNoteFolder(folder) && getFolderNote(plugin, folder.path)) {
|
||||
addCSSClassToFileExplorerEl(folder.path, 'only-has-folder-note', true, plugin);
|
||||
if (plugin.isEmptyFolderNoteFolder(folder)) {
|
||||
addCSSClassToTitleEL(folder.path, 'only-has-folder-note', plugin);
|
||||
} else {
|
||||
removeCSSClassFromFileExplorerEL(folder.path, 'only-has-folder-note', true, plugin);
|
||||
removeCSSClassFromEL(folder.path, 'only-has-folder-note', plugin);
|
||||
}
|
||||
}
|
||||
|
||||
if (oldFolder instanceof TFolder) {
|
||||
if (plugin.isEmptyFolderNoteFolder(oldFolder) && getFolderNote(plugin, oldFolder.path)) {
|
||||
addCSSClassToFileExplorerEl(oldFolder.path, 'only-has-folder-note', true, plugin);
|
||||
if (plugin.isEmptyFolderNoteFolder(oldFolder)) {
|
||||
addCSSClassToTitleEL(oldFolder.path, 'only-has-folder-note', plugin);
|
||||
} else {
|
||||
removeCSSClassFromFileExplorerEL(oldFolder.path, 'only-has-folder-note', true, plugin);
|
||||
removeCSSClassFromEL(oldFolder.path, 'only-has-folder-note', plugin);
|
||||
}
|
||||
}
|
||||
|
||||
if (file instanceof TFolder) {
|
||||
folder = file;
|
||||
plugin.tabManager.updateTab(folder.path);
|
||||
updateExcludedFolderPath(folder, oldPath, plugin);
|
||||
if (isFolderRename(folder, oldPath)) {
|
||||
handleFolderRename(folder, oldPath, plugin);
|
||||
return;
|
||||
plugin.tabManager.updateTab(file.path);
|
||||
updateExcludedFolderPath(file, oldPath, plugin);
|
||||
if (isRename) {
|
||||
return handleFolderRename(file, oldPath, plugin);
|
||||
} else {
|
||||
return handleFolderMove(file, oldPath, plugin);
|
||||
}
|
||||
return handleFolderMove(folder, oldPath, plugin);
|
||||
|
||||
} else if (file instanceof TFile) {
|
||||
if (isFileRename(file, oldPath)) {
|
||||
handleFileRename(file, oldPath, plugin);
|
||||
return;
|
||||
}
|
||||
handleFileMove(file, oldPath, plugin);
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function isFileRename(file: TFile, oldPath: string): boolean {
|
||||
const oldFolderPath = getFolderPathFromString(oldPath);
|
||||
const newFolderPath = file.parent?.path;
|
||||
const oldName = getFileNameFromPathString(oldPath);
|
||||
const newName = file.name;
|
||||
|
||||
return oldFolderPath === newFolderPath && oldName !== newName;
|
||||
}
|
||||
|
||||
|
||||
function isFolderRename(folder: TFolder, oldPath: string): boolean {
|
||||
const oldName = getFileNameFromPathString(oldPath);
|
||||
const newName = folder.name;
|
||||
const oldParent = getFolderPathFromString(oldPath);
|
||||
const newParent = folder.parent?.path;
|
||||
|
||||
return oldParent === newParent && oldName !== newName;
|
||||
}
|
||||
|
||||
export function handleFolderMove(file: TFolder, oldPath: string, plugin: FolderNotesPlugin): void {
|
||||
if (plugin.settings.storageLocation === 'insideFolder') { return; }
|
||||
if (!plugin.settings.syncMove) { return; }
|
||||
const folderNote = getFolderNote(plugin, oldPath, plugin.settings.storageLocation);
|
||||
if (!(file instanceof TFolder) || !folderNote) return;
|
||||
const newFolder = plugin.app.vault.getAbstractFileByPath(file.path);
|
||||
if (!(newFolder instanceof TFolder)) return;
|
||||
let newPath = folderNote.path;
|
||||
|
||||
if (newFolder.path === '/') {
|
||||
newPath = folderNote.name;
|
||||
} else {
|
||||
newPath = `${newFolder.parent?.path}/${folderNote.name}`;
|
||||
}
|
||||
|
||||
plugin.app.fileManager.renameFile(folderNote, newPath);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
export async function handleFileMove(
|
||||
file: TFile,
|
||||
oldPath: string,
|
||||
plugin: FolderNotesPlugin,
|
||||
): Promise<void> {
|
||||
const { folderName, oldFileName, newFolder, excludedFolder, oldFolder, folderNote } = getArgs(
|
||||
plugin, file, oldPath,
|
||||
);
|
||||
|
||||
const isFolderNoteInNewFolder = folderName === newFolder?.name;
|
||||
const fileMovedFromOldFolderNote = oldFolder && oldFolder.name === oldFileName
|
||||
&& newFolder?.path !== oldFolder.path;
|
||||
|
||||
// this is for turning files into folder notes for folders that already have a folder note
|
||||
// e.g. Turn into folder note for "Folder name"
|
||||
const isFileWithExistingNote = folderName === newFolder?.name && folderNote;
|
||||
|
||||
if (isFileWithExistingNote) {
|
||||
renameExistingFolderNote(
|
||||
file, oldPath, plugin, excludedFolder, oldFolder,
|
||||
);
|
||||
} else if (isFolderNoteInNewFolder) {
|
||||
if (excludedFolder?.disableFolderNote) { return; }
|
||||
markFileAsFolderNote(file, plugin);
|
||||
if (newFolder instanceof TFolder) {
|
||||
markFolderWithFolderNoteClasses(newFolder, plugin);
|
||||
if (plugin.app.workspace.getActiveFile()?.path === file.path) {
|
||||
removeActiveFolder(plugin);
|
||||
setActiveFolder(newFolder.path, plugin);
|
||||
}
|
||||
}
|
||||
if (oldFolder instanceof TFolder) {
|
||||
hideFolderNoteInFileExplorer(oldFolder.path, plugin);
|
||||
unmarkFolderAsFolderNote(oldFolder, plugin);
|
||||
}
|
||||
} else if (fileMovedFromOldFolderNote) {
|
||||
unmarkFileAsFolderNote(file, plugin);
|
||||
if (oldFolder instanceof TFolder) {
|
||||
removeActiveFolder(plugin);
|
||||
hideFolderNoteInFileExplorer(oldFolder.path, plugin);
|
||||
unmarkFolderAsFolderNote(oldFolder, plugin);
|
||||
if (isRename) {
|
||||
return handleFileRename(file, oldPath, plugin);
|
||||
} else {
|
||||
return handleFileMove(file, oldPath, plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function handleFolderMove(file: TFolder, oldPath: string, plugin: FolderNotesPlugin) {
|
||||
// Soon
|
||||
// Will be useful to move folder notes along with the folder
|
||||
// When the folder note is in the parent folder
|
||||
}
|
||||
|
||||
function getArgs(plugin: FolderNotesPlugin, file: TFile, oldPath: string): {
|
||||
folderName: string;
|
||||
oldFileName: string;
|
||||
newFolder: TAbstractFile | null;
|
||||
excludedFolder: ExcludedFolder | undefined;
|
||||
oldFolder: TAbstractFile | null;
|
||||
folderNote: TFile | null | undefined;
|
||||
} {
|
||||
const folderName = extractFolderName(plugin.settings.folderNoteName, file.basename)
|
||||
|| file.basename;
|
||||
export async function handleFileMove(file: TFile, oldPath: string, plugin: FolderNotesPlugin) {
|
||||
const folderName = extractFolderName(plugin.settings.folderNoteName, file.basename) || file.basename;
|
||||
const oldFileName = removeExtension(getFileNameFromPathString(oldPath));
|
||||
const newFolder = getFolderNoteFolder(plugin, file, file.basename);
|
||||
const folderNote = getFolderNote(plugin, oldPath, plugin.settings.storageLocation, file);
|
||||
let excludedFolder = getExcludedFolder(plugin, newFolder?.path || '', true);
|
||||
const oldFolder = getFolderNoteFolder(plugin, oldPath, oldFileName);
|
||||
const folderNote = getFolderNote(plugin, oldPath, plugin.settings.storageLocation, file);
|
||||
|
||||
return {
|
||||
folderName,
|
||||
oldFileName,
|
||||
newFolder,
|
||||
excludedFolder,
|
||||
oldFolder,
|
||||
folderNote,
|
||||
};
|
||||
}
|
||||
// file has been moved into position where it can be a folder note!
|
||||
if (folderName === newFolder?.name && folderNote) {
|
||||
let excludedFolderExisted = true;
|
||||
let disabledSync = false;
|
||||
|
||||
function renameExistingFolderNote(
|
||||
file: TFile, oldPath: string, plugin: FolderNotesPlugin,
|
||||
excludedFolder: ExcludedFolder | undefined,
|
||||
oldFolder: TAbstractFile | null,
|
||||
): void {
|
||||
let excludedFolderExisted = true;
|
||||
let disabledSync = false;
|
||||
|
||||
if (!excludedFolder) {
|
||||
excludedFolderExisted = false;
|
||||
excludedFolder = new ExcludedFolder(
|
||||
oldFolder?.path || '',
|
||||
plugin.settings.excludeFolders.length,
|
||||
undefined,
|
||||
plugin,
|
||||
);
|
||||
addExcludedFolder(plugin, excludedFolder);
|
||||
} else if (!excludedFolder.disableSync) {
|
||||
disabledSync = false;
|
||||
excludedFolder.disableSync = true;
|
||||
updateExcludedFolder(plugin, excludedFolder, excludedFolder);
|
||||
}
|
||||
plugin.app.fileManager.renameFile(file, oldPath).then(() => {
|
||||
if (!excludedFolder) { return; }
|
||||
if (!excludedFolderExisted) {
|
||||
deleteExcludedFolder(plugin, excludedFolder);
|
||||
} else if (!disabledSync) {
|
||||
excludedFolder.disableSync = false;
|
||||
if (!excludedFolder) {
|
||||
excludedFolderExisted = false;
|
||||
excludedFolder = new ExcludedFolder(oldFolder?.path || '', plugin.settings.excludeFolders.length, undefined, plugin);
|
||||
addExcludedFolder(plugin, excludedFolder);
|
||||
} else if (!excludedFolder.disableSync) {
|
||||
disabledSync = false;
|
||||
excludedFolder.disableSync = true;
|
||||
updateExcludedFolder(plugin, excludedFolder, excludedFolder);
|
||||
}
|
||||
});
|
||||
return plugin.app.fileManager.renameFile(file, oldPath).then(() => {
|
||||
if (!excludedFolder) { return; }
|
||||
if (!excludedFolderExisted) {
|
||||
deleteExcludedFolder(plugin, excludedFolder);
|
||||
} else if (!disabledSync) {
|
||||
excludedFolder.disableSync = false;
|
||||
updateExcludedFolder(plugin, excludedFolder, excludedFolder);
|
||||
}
|
||||
});
|
||||
} else if (oldFolder && oldFolder.name === oldFileName && newFolder?.path !== oldFolder.path) {
|
||||
// the note has been moved somewhere and is no longer a folder note
|
||||
// cleanup css on the folder and note
|
||||
removeCSSClassFromEL(oldFolder.path, 'has-folder-note', plugin);
|
||||
removeCSSClassFromEL(file.path, 'is-folder-note', plugin);
|
||||
removeCSSClassFromEL(oldPath, 'is-folder-note', plugin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
export async function handleFolderRename(
|
||||
file: TFolder, oldPath: string, plugin: FolderNotesPlugin,
|
||||
): Promise<void> {
|
||||
export async function handleFolderRename(file: TFolder, oldPath: string, plugin: FolderNotesPlugin) {
|
||||
const fileName = plugin.settings.folderNoteName.replace('{{folder_name}}', file.name);
|
||||
const oldFileName = plugin.settings.folderNoteName
|
||||
.replace('{{folder_name}}', getFileNameFromPathString(oldPath));
|
||||
const oldFileName = plugin.settings.folderNoteName.replace('{{folder_name}}', getFileNameFromPathString(oldPath));
|
||||
|
||||
if (fileName === oldFileName) { return; }
|
||||
|
||||
|
||||
const folderNote = getFolderNote(plugin, oldPath);
|
||||
if (!(folderNote instanceof TFile)) return;
|
||||
|
||||
|
||||
const excludedFolder = getExcludedFolder(plugin, file.path, true);
|
||||
if (excludedFolder?.disableSync && !folderNote) {
|
||||
return removeCSSClassFromFileExplorerEL(file.path, 'has-folder-note', false, plugin);
|
||||
return removeCSSClassFromEL(file.path, 'has-folder-note', plugin);
|
||||
}
|
||||
|
||||
if (!plugin.settings.syncFolderName) { return; }
|
||||
|
|
@ -250,70 +129,58 @@ export async function handleFolderRename(
|
|||
plugin.app.fileManager.renameFile(folderNote, newPath);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
export async function handleFileRename(
|
||||
file: TFile,
|
||||
oldPath: string,
|
||||
plugin: FolderNotesPlugin,
|
||||
): Promise<void> {
|
||||
export async function handleFileRename(file: TFile, oldPath: string, plugin: FolderNotesPlugin) {
|
||||
const oldFileName = removeExtension(getFileNameFromPathString(oldPath));
|
||||
const newFileName = file.basename;
|
||||
if (oldFileName === newFileName) { return; }
|
||||
|
||||
const oldFolder = getFolderNoteFolder(plugin, oldPath, oldFileName);
|
||||
const folderName = extractFolderName(plugin.settings.folderNoteName, file.basename)
|
||||
|| file.basename;
|
||||
const oldFolderName = extractFolderName(plugin.settings.folderNoteName, oldFileName)
|
||||
|| oldFileName;
|
||||
const folderName = extractFolderName(plugin.settings.folderNoteName, file.basename) || file.basename;
|
||||
const oldFolderName = extractFolderName(plugin.settings.folderNoteName, oldFileName) || oldFileName;
|
||||
const newFolder = getFolderNoteFolder(plugin, file, file.basename);
|
||||
const excludedFolder = getExcludedFolder(plugin, newFolder?.path || '', true);
|
||||
const detachedExcludedFolder = getDetachedFolder(plugin, newFolder?.path || '');
|
||||
const folderNote = getFolderNote(plugin, oldPath, plugin.settings.storageLocation, file);
|
||||
|
||||
// Handle folder note creation
|
||||
if (shouldCreateFolderNote(excludedFolder, folderName, newFolder, detachedExcludedFolder)) {
|
||||
if (newFolder) {
|
||||
handleFolderNoteCreation(file, newFolder, plugin);
|
||||
}
|
||||
if (!excludedFolder?.disableFolderNote && folderName === newFolder?.name && !detachedExcludedFolder) {
|
||||
addCSSClassToTitleEL(file.path, 'is-folder-note', plugin);
|
||||
addCSSClassToTitleEL(newFolder.path, 'has-folder-note', plugin);
|
||||
return;
|
||||
} else if (excludedFolder?.disableFolderNote || (folderName !== newFolder?.name)) {
|
||||
removeCSSClassFromEL(file.path, 'is-folder-note', plugin);
|
||||
removeCSSClassFromEL(newFolder?.path || '', 'has-folder-note', plugin);
|
||||
}
|
||||
|
||||
if (excludedFolder?.disableSync || !plugin.settings.syncFolderName) { return; }
|
||||
|
||||
|
||||
if (folderName === newFolder?.name) {
|
||||
addCSSClassToTitleEL(file.path, 'is-folder-note', plugin);
|
||||
removeCSSClassFromEL(oldFolder?.path, 'has-folder-note', plugin);
|
||||
addCSSClassToTitleEL(newFolder.path, 'has-folder-note', plugin);
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle folder note removal
|
||||
if (shouldRemoveFolderNoteClasses(excludedFolder, folderName, newFolder)) {
|
||||
handleFolderNoteRemoval(file, newFolder, plugin);
|
||||
}
|
||||
|
||||
// Early return if sync is disabled
|
||||
if (excludedFolder?.disableSync || !plugin.settings.syncFolderName) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle same folder rename
|
||||
if (folderName === newFolder?.name && newFolder) {
|
||||
handleSameFolderRename(file, newFolder, oldFolder, plugin);
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle folder rename on file rename
|
||||
if (shouldRenameFolderOnFileRename(oldFolderName, oldFolder, newFolder, folderNote)) {
|
||||
return renameFolderOnFileRename(file, oldPath, oldFolder!, plugin);
|
||||
// file matched folder name before rename
|
||||
// file hasnt moved just renamed
|
||||
// Need to rename the folder
|
||||
if (!oldFolder) return;
|
||||
if (oldFolderName === oldFolder.name && newFolder?.path === oldFolder.path) {
|
||||
return renameFolderOnFileRename(file, oldPath, oldFolder, plugin);
|
||||
} else if (folderNote && oldFolderName === oldFolder.name) {
|
||||
return renameFolderOnFileRename(file, oldPath, oldFolder, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
async function renameFolderOnFileRename(
|
||||
file: TFile,
|
||||
oldPath: string,
|
||||
oldFolder: TAbstractFile,
|
||||
plugin: FolderNotesPlugin,
|
||||
): Promise<void> {
|
||||
async function renameFolderOnFileRename(file: TFile, oldPath: string, oldFolder: TAbstractFile, plugin: FolderNotesPlugin) {
|
||||
const newFolderName = extractFolderName(plugin.settings.folderNoteName, file.basename);
|
||||
if (!newFolderName) {
|
||||
removeCSSClassFromFileExplorerEL(oldFolder.path, 'has-folder-note', false, plugin);
|
||||
removeCSSClassFromFileExplorerEL(file.path, 'is-folder-note', false, plugin);
|
||||
removeCSSClassFromEL(oldFolder.path, 'has-folder-note', plugin);
|
||||
removeCSSClassFromEL(file.path, 'is-folder-note', plugin);
|
||||
return;
|
||||
} else if (newFolderName === oldFolder.name) {
|
||||
addCSSClassToFileExplorerEl(oldFolder.path, 'has-folder-note', false, plugin);
|
||||
addCSSClassToFileExplorerEl(file.path, 'is-folder-note', false, plugin);
|
||||
addCSSClassToTitleEL(oldFolder.path, 'has-folder-note', plugin);
|
||||
addCSSClassToTitleEL(file.path, 'is-folder-note', plugin);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -335,19 +202,14 @@ async function renameFolderOnFileRename(
|
|||
|
||||
if (plugin.app.vault.getAbstractFileByPath(newFolderPath)) {
|
||||
await plugin.app.fileManager.renameFile(file, oldPath);
|
||||
new Notice('A folder with the same name already exists');
|
||||
return;
|
||||
return new Notice('A folder with the same name already exists');
|
||||
}
|
||||
plugin.app.fileManager.renameFile(oldFolder, newFolderPath);
|
||||
}
|
||||
|
||||
function updateExcludedFolderPath(
|
||||
folder: TFolder,
|
||||
oldPath: string,
|
||||
plugin: FolderNotesPlugin,
|
||||
): void {
|
||||
function updateExcludedFolderPath(folder: TFolder, oldPath: string, plugin: FolderNotesPlugin) {
|
||||
const excludedFolders = plugin.settings.excludeFolders.filter(
|
||||
(excludedFolder) => excludedFolder.path?.includes(oldPath),
|
||||
(excludedFolder) => excludedFolder.path?.includes(oldPath)
|
||||
);
|
||||
|
||||
excludedFolders.forEach((excludedFolder) => {
|
||||
|
|
@ -366,68 +228,3 @@ function updateExcludedFolderPath(
|
|||
});
|
||||
plugin.saveSettings();
|
||||
}
|
||||
|
||||
|
||||
function shouldCreateFolderNote(
|
||||
excludedFolder: ExcludedFolder | undefined,
|
||||
folderName: string,
|
||||
newFolder: TAbstractFile | null,
|
||||
detachedExcludedFolder: ExcludedFolder | undefined,
|
||||
): boolean {
|
||||
return !excludedFolder?.disableFolderNote
|
||||
&& folderName === (newFolder)?.name
|
||||
&& !detachedExcludedFolder;
|
||||
}
|
||||
|
||||
function shouldRemoveFolderNoteClasses(
|
||||
excludedFolder: ExcludedFolder | undefined,
|
||||
folderName: string,
|
||||
newFolder: TAbstractFile | null,
|
||||
): boolean {
|
||||
return excludedFolder?.disableFolderNote || (folderName !== (newFolder)?.name);
|
||||
}
|
||||
|
||||
function handleFolderNoteCreation(
|
||||
file: TFile,
|
||||
newFolder: TAbstractFile,
|
||||
plugin: FolderNotesPlugin,
|
||||
): void {
|
||||
addCSSClassToFileExplorerEl(file.path, 'is-folder-note', false, plugin);
|
||||
addCSSClassToFileExplorerEl(newFolder.path, 'has-folder-note', false, plugin);
|
||||
}
|
||||
|
||||
function handleFolderNoteRemoval(
|
||||
file: TFile,
|
||||
newFolder: TAbstractFile | null,
|
||||
plugin: FolderNotesPlugin,
|
||||
): void {
|
||||
removeCSSClassFromFileExplorerEL(file.path, 'is-folder-note', false, plugin);
|
||||
removeCSSClassFromFileExplorerEL(newFolder?.path || '', 'has-folder-note', false, plugin);
|
||||
}
|
||||
|
||||
function handleSameFolderRename(
|
||||
file: TFile,
|
||||
newFolder: TAbstractFile,
|
||||
oldFolder: TAbstractFile | null,
|
||||
plugin: FolderNotesPlugin,
|
||||
): void {
|
||||
addCSSClassToFileExplorerEl(file.path, 'is-folder-note', false, plugin);
|
||||
removeCSSClassFromFileExplorerEL(oldFolder?.path, 'has-folder-note', false, plugin);
|
||||
addCSSClassToFileExplorerEl(newFolder.path, 'has-folder-note', false, plugin);
|
||||
}
|
||||
|
||||
function shouldRenameFolderOnFileRename(
|
||||
oldFolderName: string,
|
||||
oldFolder: TAbstractFile | null,
|
||||
newFolder: TAbstractFile | null,
|
||||
folderNote: TFile | null | undefined,
|
||||
): boolean {
|
||||
if (!oldFolder) return false;
|
||||
|
||||
const oldFolderAsFolder = oldFolder;
|
||||
const newFolderAsFolder = newFolder;
|
||||
|
||||
return (oldFolderName === oldFolderAsFolder.name
|
||||
&& newFolderAsFolder?.path === oldFolderAsFolder.path)
|
||||
|| (folderNote !== null && oldFolderName === oldFolderAsFolder.name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ export class ListComponent {
|
|||
emitter: CustomEventEmitter;
|
||||
containerEl: HTMLElement;
|
||||
controlEl: HTMLElement;
|
||||
emptyStateEl!: HTMLElement;
|
||||
emptyStateEl: HTMLElement;
|
||||
listEl: HTMLElement;
|
||||
values!: string[];
|
||||
values: string[];
|
||||
defaultValues: string[];
|
||||
constructor(containerEl: HTMLElement, values: string[] = [], defaultValues: string[] = []) {
|
||||
this.emitter = new CustomEventEmitter();
|
||||
|
|
@ -18,19 +18,19 @@ export class ListComponent {
|
|||
this.defaultValues = defaultValues;
|
||||
}
|
||||
|
||||
on(event: string, listener: (data?: unknown) => void): void {
|
||||
on(event: string, listener: (data?: any) => void) {
|
||||
this.emitter.on(event, listener);
|
||||
}
|
||||
|
||||
off(event: string, listener: (data?: unknown) => void): void {
|
||||
off(event: string, listener: (data?: any) => void) {
|
||||
this.emitter.off(event, listener);
|
||||
}
|
||||
|
||||
private emit(event: string, data?: unknown): void {
|
||||
private emit(event: string, data?: any) {
|
||||
this.emitter.emit(event, data);
|
||||
}
|
||||
|
||||
setValues(values: string[]): void {
|
||||
setValues(values: string[]) {
|
||||
this.removeElements();
|
||||
this.values = values;
|
||||
if (values.length !== 0) {
|
||||
|
|
@ -41,63 +41,47 @@ export class ListComponent {
|
|||
this.emit('update', this.values);
|
||||
}
|
||||
|
||||
removeElements(): void {
|
||||
removeElements() {
|
||||
this.listEl.empty();
|
||||
}
|
||||
|
||||
addElement(value: string): void {
|
||||
addElement(value: string) {
|
||||
this.listEl.createSpan('setting-hotkey', (span) => {
|
||||
if (value.toLocaleLowerCase() === 'md') {
|
||||
const markdown = 'markdown';
|
||||
span.innerText = markdown;
|
||||
span.innerText = 'markdown';
|
||||
} else {
|
||||
span.innerText = value;
|
||||
}
|
||||
span.setAttribute('extension', value);
|
||||
|
||||
const removeSpan = span.createEl('span', { cls: 'ofn-list-item-remove setting-hotkey-icon' });
|
||||
// eslint-disable-next-line max-len
|
||||
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-x"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>';
|
||||
const svgElement = removeSpan.createEl('span', { cls: 'ofn-list-item-remove-icon' });
|
||||
const parser = new DOMParser();
|
||||
const svgDoc = parser.parseFromString(svg, 'image/svg+xml');
|
||||
const svgNode = svgDoc.documentElement;
|
||||
if (svgNode) {
|
||||
svgElement.appendChild(activeDocument.importNode(svgNode, true));
|
||||
}
|
||||
removeSpan.onClickEvent(() => {
|
||||
svgElement.innerHTML = svg;
|
||||
removeSpan.onClickEvent((e) => {
|
||||
this.removeValue(value);
|
||||
span.remove();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async addValue(value: string): Promise<void> {
|
||||
async addValue(value: string) {
|
||||
this.values.push(value);
|
||||
this.addElement(value);
|
||||
this.emit('add', value);
|
||||
this.emit('update', this.values);
|
||||
}
|
||||
|
||||
addResetButton(): this {
|
||||
// eslint-disable-next-line max-len
|
||||
addResetButton() {
|
||||
const resetButton = this.controlEl.createEl('span', { cls: 'clickable-icon setting-restore-hotkey-button' });
|
||||
// eslint-disable-next-line max-len
|
||||
const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="svg-icon lucide-rotate-ccw"><path d="M3 2v6h6"></path><path d="M3 13a9 9 0 1 0 3-7.7L3 8"></path></svg>';
|
||||
const svgElement = resetButton.createEl('span', { cls: 'ofn-list-item-remove-icon' });
|
||||
const parser = new DOMParser();
|
||||
const svgDoc = parser.parseFromString(svg, 'image/svg+xml');
|
||||
const svgNode = svgDoc.documentElement;
|
||||
if (svgNode) {
|
||||
svgElement.appendChild(activeDocument.importNode(svgNode, true));
|
||||
}
|
||||
resetButton.onClickEvent(() => {
|
||||
resetButton.innerHTML = svg;
|
||||
resetButton.onClickEvent((e) => {
|
||||
this.setValues(this.defaultValues);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
removeValue(value: string): void {
|
||||
removeValue(value: string) {
|
||||
this.values = this.values.filter((v) => v !== value);
|
||||
this.listEl.find(`[extension='${value}']`).remove();
|
||||
this.emit('remove', value);
|
||||
|
|
|
|||
|
|
@ -1,46 +1,19 @@
|
|||
import type { WorkspaceLeaf, App, TFile } from 'obsidian';
|
||||
import { WorkspaceLeaf, App } from 'obsidian';
|
||||
|
||||
interface ExcalidrawPlugin {
|
||||
setExcalidrawView(leaf: WorkspaceLeaf): void;
|
||||
openDrawing(file: TFile): void;
|
||||
getBlankDrawing(): Promise<string>;
|
||||
}
|
||||
|
||||
export async function openExcalidrawView(
|
||||
app: App,
|
||||
file: TFile,
|
||||
): Promise<void> {
|
||||
const { excalidraw, excalidrawEnabled } = await getExcalidrawPlugin(app);
|
||||
if (excalidrawEnabled && excalidraw) {
|
||||
excalidraw.openDrawing(file);
|
||||
export async function openExcalidrawView(leaf: WorkspaceLeaf) {
|
||||
const { excalidraw, excalidrawEnabled } = await getExcalidrawPlugin(this.app);
|
||||
if (excalidrawEnabled) {
|
||||
excalidraw.setExcalidrawView(leaf);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getDefaultTemplate(app: App): Promise<string> {
|
||||
const { excalidraw, excalidrawEnabled } = await getExcalidrawPlugin(app);
|
||||
if (excalidrawEnabled && excalidraw) {
|
||||
return excalidraw.getBlankDrawing();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
export async function getExcalidrawPlugin(
|
||||
app: App,
|
||||
): Promise<{ excalidraw: ExcalidrawPlugin | null; excalidrawEnabled: boolean }> {
|
||||
const { plugins: pluginManager } = app as App & {
|
||||
plugins: {
|
||||
plugins: Record<string, unknown>;
|
||||
enabledPlugins: Set<string>;
|
||||
};
|
||||
};
|
||||
const excalidraw = (
|
||||
pluginManager.plugins[
|
||||
'obsidian-excalidraw-plugin'
|
||||
] as unknown as ExcalidrawPlugin | undefined
|
||||
export async function getExcalidrawPlugin(app: App) {
|
||||
const excalidraw = (app as any).plugins.plugins['obsidian-excalidraw-plugin'];
|
||||
const excalidrawEnabled = (app as any).plugins.enabledPlugins.has(
|
||||
'obsidian-excalidraw-plugin'
|
||||
);
|
||||
const excalidrawEnabled = pluginManager.enabledPlugins.has('obsidian-excalidraw-plugin');
|
||||
return {
|
||||
excalidraw: excalidraw ?? null,
|
||||
excalidraw,
|
||||
excalidrawEnabled,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,72 +1,48 @@
|
|||
/* eslint-disable complexity */
|
||||
/* eslint-disable max-len */
|
||||
import type FolderNotesPlugin from '../main';
|
||||
import FolderNotesPlugin from '../main';
|
||||
import ExistingFolderNoteModal from '../modals/ExistingNote';
|
||||
import { applyTemplate } from '../template';
|
||||
import {
|
||||
TFolder,
|
||||
TFile,
|
||||
Keymap,
|
||||
type TAbstractFile,
|
||||
type MarkdownView,
|
||||
type WorkspaceLeaf,
|
||||
} from 'obsidian';
|
||||
import { TFolder, TFile, TAbstractFile, Keymap } from 'obsidian';
|
||||
import DeleteConfirmationModal from '../modals/DeleteConfirmation';
|
||||
import {
|
||||
addExcludedFolder,
|
||||
deleteExcludedFolder,
|
||||
getDetachedFolder,
|
||||
getExcludedFolder,
|
||||
updateExcludedFolder,
|
||||
} from '../ExcludeFolders/functions/folderFunctions';
|
||||
import { addExcludedFolder, deleteExcludedFolder, getDetachedFolder, getExcludedFolder, updateExcludedFolder } from '../ExcludeFolders/functions/folderFunctions';
|
||||
import { ExcludedFolder } from '../ExcludeFolders/ExcludeFolder';
|
||||
import { getDefaultTemplate, openExcalidrawView } from './excalidraw';
|
||||
import { openExcalidrawView } from './excalidraw';
|
||||
import { AskForExtensionModal } from 'src/modals/AskForExtension';
|
||||
import {
|
||||
addCSSClassToFileExplorerEl,
|
||||
removeCSSClassFromFileExplorerEL,
|
||||
removeActiveFolder,
|
||||
setActiveFolder,
|
||||
updateCSSClassesForFolderNote,
|
||||
} from 'src/functions/styleFunctions';
|
||||
import {
|
||||
getFolderNameFromPathString,
|
||||
getFolderPathFromString,
|
||||
removeExtension,
|
||||
} from 'src/functions/utils';
|
||||
import { getEl, addCSSClassToTitleEL, removeCSSClassFromEL } from 'src/functions/styleFunctions';
|
||||
import { getFolderNameFromPathString, getFolderPathFromString, removeExtension } from 'src/functions/utils';
|
||||
|
||||
const defaultExcalidrawTemplate = `---
|
||||
|
||||
excalidraw-plugin: parsed
|
||||
tags: [excalidraw]
|
||||
|
||||
---
|
||||
==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠==
|
||||
|
||||
|
||||
%%
|
||||
# Drawing
|
||||
\`\`\`json
|
||||
{'type":"excalidraw","version":2,"source":"https://github.com/zsviczian/obsidian-excalidraw-plugin/releases/tag/1.9.20","elements":[],"appState":{"gridSize":null,"viewBackgroundColor":"#ffffff'}}
|
||||
\`\`\`
|
||||
%%`;
|
||||
|
||||
export async function createFolderNote(
|
||||
plugin: FolderNotesPlugin,
|
||||
folderPath: string,
|
||||
openFile: boolean,
|
||||
extension?: string,
|
||||
displayModal?: boolean,
|
||||
preexistingNote?: TFile,
|
||||
): Promise<void> {
|
||||
let {
|
||||
leaf,
|
||||
fileName,
|
||||
folderNote,
|
||||
folderNoteType,
|
||||
detachedFolder,
|
||||
path,
|
||||
} = getArgs(plugin, folderPath, extension, preexistingNote);
|
||||
export async function createFolderNote(plugin: FolderNotesPlugin, folderPath: string, openFile: boolean, extension?: string, displayModal?: boolean, preexistingNote?: TFile) {
|
||||
const leaf = plugin.app.workspace.getLeaf(false);
|
||||
const folderName = getFolderNameFromPathString(folderPath);
|
||||
const fileName = plugin.settings.folderNoteName.replace('{{folder_name}}', folderName);
|
||||
let folderNote = getFolderNote(plugin, folderPath);
|
||||
if (preexistingNote) {
|
||||
folderNote = preexistingNote;
|
||||
}
|
||||
let folderNoteType = extension ?? plugin.settings.folderNoteType;
|
||||
const detachedFolder = getDetachedFolder(plugin, folderPath);
|
||||
let path = '';
|
||||
|
||||
if (folderNoteType === '.excalidraw') {
|
||||
folderNoteType = '.md';
|
||||
extension = '.excalidraw';
|
||||
} else if (folderNoteType === '.ask') {
|
||||
if (plugin.askModalCurrentlyOpen) return;
|
||||
return new AskForExtensionModal(
|
||||
plugin,
|
||||
folderPath,
|
||||
openFile,
|
||||
folderNoteType,
|
||||
displayModal,
|
||||
preexistingNote,
|
||||
).open();
|
||||
return new AskForExtensionModal(plugin, folderPath, openFile, folderNoteType, displayModal, preexistingNote).open();
|
||||
}
|
||||
|
||||
if (plugin.settings.storageLocation === 'parentFolder') {
|
||||
|
|
@ -83,7 +59,27 @@ export async function createFolderNote(
|
|||
}
|
||||
|
||||
if (detachedFolder && folderNote?.extension !== extension && folderNote) {
|
||||
await handleTurnNoteIntoFolderNote(plugin, folderNote, detachedFolder, folderPath, fileName);
|
||||
deleteExcludedFolder(plugin, detachedFolder);
|
||||
removeCSSClassFromEL(folderNote?.path, 'is-folder-note', plugin);
|
||||
const folder = plugin.app.vault.getAbstractFileByPath(folderPath) as TFolder;
|
||||
if (!folderNote || folderNote.basename !== fileName) return;
|
||||
let count = 1;
|
||||
let newName = removeExtension(folderNote.path) + ` (${count}).${folderNote.path.split('.').pop()}`;
|
||||
while (count < 100 && plugin.app.vault.getAbstractFileByPath(newName)) {
|
||||
count++;
|
||||
newName = removeExtension(folderNote.path) + ` (${count}).${folderNote.path.split('.').pop()}`;
|
||||
}
|
||||
const [excludedFolder, excludedFolderExisted, disabledSync] = await tempDisableSync(plugin, folder);
|
||||
|
||||
await plugin.app.fileManager.renameFile(folderNote, newName).then(() => {
|
||||
if (!excludedFolder) return;
|
||||
if (!excludedFolderExisted) {
|
||||
deleteExcludedFolder(plugin, excludedFolder);
|
||||
} else if (!disabledSync) {
|
||||
excludedFolder.disableSync = false;
|
||||
updateExcludedFolder(plugin, excludedFolder, excludedFolder);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (!extension) {
|
||||
|
|
@ -91,193 +87,80 @@ export async function createFolderNote(
|
|||
}
|
||||
|
||||
if (!folderNote) {
|
||||
folderNote = await handleCreateFolderNote(plugin, folderNoteType, openFile, leaf, folderNote, path, extension);
|
||||
let content = '';
|
||||
if (extension !== '.md' && extension) {
|
||||
if (plugin.settings.templatePath && folderNoteType.split('.').pop() === plugin.settings.templatePath.split('.').pop()) {
|
||||
const templateFile = plugin.app.vault.getAbstractFileByPath(plugin.settings.templatePath);
|
||||
if (templateFile instanceof TFile) {
|
||||
if (['md', 'canvas', 'txt'].includes(templateFile.extension)) {
|
||||
content = await plugin.app.vault.read(templateFile);
|
||||
if (extension === '.excalidraw' && !content.includes('==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠==')) {
|
||||
content = defaultExcalidrawTemplate;
|
||||
}
|
||||
} else {
|
||||
return plugin.app.vault.readBinary(templateFile).then(async (data) => {
|
||||
folderNote = await plugin.app.vault.createBinary(path, data);
|
||||
if (openFile) {
|
||||
await leaf.openFile(folderNote);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (plugin.settings.folderNoteType === '.excalidraw' || extension === '.excalidraw') {
|
||||
content = defaultExcalidrawTemplate;
|
||||
} else if (plugin.settings.folderNoteType === '.canvas') {
|
||||
content = '{}';
|
||||
}
|
||||
}
|
||||
|
||||
folderNote = await plugin.app.vault.create(path, content);
|
||||
} else {
|
||||
await plugin.app.fileManager.renameFile(folderNote, path);
|
||||
}
|
||||
|
||||
if (openFile) {
|
||||
if (plugin.app.workspace.getActiveFile()?.path === path) {
|
||||
removeActiveFolder(plugin);
|
||||
if (plugin.activeFolderDom) {
|
||||
plugin.activeFolderDom.removeClass('fn-is-active');
|
||||
plugin.activeFolderDom = null;
|
||||
}
|
||||
|
||||
const folder = getFolder(plugin, folderNote);
|
||||
if (!folder) { return; }
|
||||
|
||||
setActiveFolder(folder.path, plugin);
|
||||
plugin.activeFolderDom = getEl(folder.path, plugin);
|
||||
if (plugin.activeFolderDom) plugin.activeFolderDom.addClass('fn-is-active');
|
||||
}
|
||||
await leaf.openFile(folderNote);
|
||||
if (plugin.settings.folderNoteType === '.excalidraw' || extension === '.excalidraw') {
|
||||
openExcalidrawView(plugin.app, folderNote);
|
||||
openExcalidrawView(leaf);
|
||||
}
|
||||
}
|
||||
|
||||
const matchingExtension =
|
||||
extension?.split('.').pop() ===
|
||||
plugin.settings.templatePath.split('.').pop();
|
||||
const matchingExtension = extension?.split('.').pop() === plugin.settings.templatePath.split('.').pop();
|
||||
if (folderNote && matchingExtension && plugin.settings.folderNoteType !== '.excalidraw') {
|
||||
applyTemplate(plugin, folderNote, leaf, plugin.settings.templatePath);
|
||||
}
|
||||
|
||||
const folder = plugin.app.vault.getAbstractFileByPath(folderPath);
|
||||
if (!(folder instanceof TFolder)) return;
|
||||
addCSSClassToFileExplorerEl(path, 'is-folder-note', false, plugin, true);
|
||||
addCSSClassToFileExplorerEl(folder.path, 'has-folder-note', false, plugin);
|
||||
addCSSClassToTitleEL(path, 'is-folder-note', plugin, true);
|
||||
addCSSClassToTitleEL(folder.path, 'has-folder-note', plugin);
|
||||
}
|
||||
|
||||
function getArgs(
|
||||
plugin: FolderNotesPlugin,
|
||||
folderPath: string,
|
||||
extension?: string,
|
||||
preexistingNote?: TFile,
|
||||
): {
|
||||
leaf: WorkspaceLeaf;
|
||||
fileName: string;
|
||||
folderNote: TFile | null | undefined;
|
||||
folderNoteType: string;
|
||||
detachedFolder: ExcludedFolder | undefined;
|
||||
path: string | '';
|
||||
} {
|
||||
const leaf = plugin.app.workspace.getLeaf(false);
|
||||
const folderName = getFolderNameFromPathString(folderPath);
|
||||
const fileName = plugin.settings.folderNoteName.replace('{{folder_name}}', folderName);
|
||||
let folderNote = getFolderNote(plugin, folderPath);
|
||||
if (preexistingNote) {
|
||||
folderNote = preexistingNote;
|
||||
}
|
||||
let folderNoteType = extension ?? plugin.settings.folderNoteType;
|
||||
const detachedFolder = getDetachedFolder(plugin, folderPath);
|
||||
let path = '';
|
||||
|
||||
return {
|
||||
leaf,
|
||||
fileName,
|
||||
folderNote,
|
||||
folderNoteType,
|
||||
detachedFolder,
|
||||
path,
|
||||
};
|
||||
}
|
||||
|
||||
async function handleCreateFolderNote(plugin: FolderNotesPlugin, folderNoteType: string, openFile: boolean, leaf: WorkspaceLeaf, folderNote: TFile | null | undefined, path: string, extension?: string): Promise<TFile> {
|
||||
let content = '';
|
||||
if (extension !== '.md' && extension) {
|
||||
if (
|
||||
plugin.settings.templatePath &&
|
||||
folderNoteType.split('.').pop() ===
|
||||
plugin.settings.templatePath.split('.').pop()
|
||||
) {
|
||||
const templateFile = plugin.app.vault.getAbstractFileByPath(
|
||||
plugin.settings.templatePath,
|
||||
);
|
||||
if (templateFile instanceof TFile) {
|
||||
if (['md', 'canvas', 'txt'].includes(templateFile.extension)) {
|
||||
content = await plugin.app.vault.read(templateFile);
|
||||
if (
|
||||
extension === '.excalidraw' &&
|
||||
!content.includes(
|
||||
'==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this activeDocument. ⚠==',
|
||||
)
|
||||
) {
|
||||
content = await getDefaultTemplate(plugin.app);
|
||||
}
|
||||
} else {
|
||||
plugin.app.vault.readBinary(templateFile).then(async (data) => {
|
||||
folderNote = await plugin.app.vault.createBinary(path, data);
|
||||
if (openFile) {
|
||||
await leaf.openFile(folderNote);
|
||||
}
|
||||
return folderNote;
|
||||
});
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
plugin.settings.folderNoteType === '.excalidraw' ||
|
||||
extension === '.excalidraw'
|
||||
) {
|
||||
content = await getDefaultTemplate(plugin.app);
|
||||
} else if (plugin.settings.folderNoteType === '.canvas') {
|
||||
content = '{}';
|
||||
}
|
||||
}
|
||||
|
||||
folderNote = await plugin.app.vault.create(path, content);
|
||||
return folderNote;
|
||||
}
|
||||
|
||||
async function handleTurnNoteIntoFolderNote(
|
||||
plugin: FolderNotesPlugin,
|
||||
folderNote: TFile,
|
||||
detachedFolder: ExcludedFolder,
|
||||
folderPath: string,
|
||||
fileName: string,
|
||||
): Promise<void> {
|
||||
deleteExcludedFolder(plugin, detachedFolder);
|
||||
removeCSSClassFromFileExplorerEL(folderNote?.path, 'is-folder-note', false, plugin);
|
||||
const folder = plugin.app.vault.getAbstractFileByPath(folderPath);
|
||||
if (!(folder instanceof TFolder)) return;
|
||||
if (!folderNote || folderNote.basename !== fileName) return;
|
||||
let count = 1;
|
||||
const baseName = removeExtension(folderNote.path);
|
||||
const ext = folderNote.path.split('.').pop();
|
||||
let newName = `${baseName} (${count}).${ext}`;
|
||||
const MAX_FOLDER_NOTE_RENAME_ATTEMPTS = 100;
|
||||
|
||||
while (
|
||||
count < MAX_FOLDER_NOTE_RENAME_ATTEMPTS &&
|
||||
plugin.app.vault.getAbstractFileByPath(newName)
|
||||
) {
|
||||
count++;
|
||||
newName = `${baseName} (${count}).${ext}`;
|
||||
}
|
||||
const [
|
||||
excludedFolder,
|
||||
excludedFolderExisted,
|
||||
disabledSync,
|
||||
] = await tempDisableSync(plugin, folder);
|
||||
|
||||
await plugin.app.fileManager.renameFile(folderNote, newName).then(() => {
|
||||
if (!excludedFolder) return;
|
||||
if (!excludedFolderExisted) {
|
||||
deleteExcludedFolder(plugin, excludedFolder);
|
||||
} else if (!disabledSync) {
|
||||
excludedFolder.disableSync = false;
|
||||
updateExcludedFolder(plugin, excludedFolder, excludedFolder);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export async function turnIntoFolderNote(
|
||||
plugin: FolderNotesPlugin,
|
||||
file: TFile,
|
||||
folder: TFolder,
|
||||
folderNote?: TFile | null | TAbstractFile,
|
||||
skipConfirmation?: boolean,
|
||||
): Promise<void> {
|
||||
const { extension } = file;
|
||||
export async function turnIntoFolderNote(plugin: FolderNotesPlugin, file: TFile, folder: TFolder, folderNote?: TFile | null | TAbstractFile, skipConfirmation?: boolean) {
|
||||
const extension = file.extension;
|
||||
const detachedExcludedFolder = getDetachedFolder(plugin, folder.path);
|
||||
|
||||
if (folderNote) {
|
||||
if (
|
||||
plugin.settings.showRenameConfirmation &&
|
||||
!skipConfirmation &&
|
||||
!detachedExcludedFolder
|
||||
) {
|
||||
if (plugin.settings.showRenameConfirmation && !skipConfirmation && !detachedExcludedFolder) {
|
||||
return new ExistingFolderNoteModal(plugin.app, plugin, file, folder, folderNote).open();
|
||||
}
|
||||
removeCSSClassFromFileExplorerEL(folderNote.path, 'is-folder-note', false, plugin);
|
||||
removeCSSClassFromEL(folderNote.path, 'is-folder-note', plugin);
|
||||
|
||||
const [
|
||||
excludedFolder,
|
||||
excludedFolderExisted,
|
||||
disabledSync,
|
||||
] = await tempDisableSync(plugin, folder);
|
||||
|
||||
const CTIME_SLICE_START = 10;
|
||||
const RANDOM_SUFFIX_MAX = 1000;
|
||||
const randomSuffix = Math.floor(Math.random() * RANDOM_SUFFIX_MAX);
|
||||
const ctimeSuffix = file.stat.ctime.toString().slice(CTIME_SLICE_START);
|
||||
const newPath = `${folder.path}/${folder.name} (${ctimeSuffix}${randomSuffix}).${extension}`;
|
||||
const [excludedFolder, excludedFolderExisted, disabledSync] = await tempDisableSync(plugin, folder);
|
||||
|
||||
const newPath = `${folder.path}/${folder.name} (${file.stat.ctime.toString().slice(10) + Math.floor(Math.random() * 1000)}).${extension}`;
|
||||
plugin.app.fileManager.renameFile(folderNote, newPath).then(() => {
|
||||
if (!excludedFolder) return;
|
||||
if (!excludedFolderExisted) {
|
||||
|
|
@ -303,39 +186,30 @@ export async function turnIntoFolderNote(
|
|||
}
|
||||
|
||||
if (detachedExcludedFolder) {
|
||||
void deleteExcludedFolder(plugin, detachedExcludedFolder);
|
||||
deleteExcludedFolder(plugin, detachedExcludedFolder);
|
||||
}
|
||||
|
||||
await plugin.app.fileManager.renameFile(file, path);
|
||||
void addCSSClassToFileExplorerEl(path, 'is-folder-note', false, plugin, true);
|
||||
void addCSSClassToFileExplorerEl(folder.path, 'has-folder-note', false, plugin);
|
||||
addCSSClassToTitleEL(path, 'is-folder-note', plugin, true);
|
||||
addCSSClassToTitleEL(folder.path, 'has-folder-note', plugin);
|
||||
|
||||
removeActiveFolder(plugin);
|
||||
setActiveFolder(folder.path, plugin);
|
||||
if (plugin.activeFolderDom) {
|
||||
plugin.activeFolderDom.removeClass('fn-is-active');
|
||||
plugin.activeFolderDom = null;
|
||||
}
|
||||
|
||||
plugin.activeFolderDom = getEl(folder.path, plugin);
|
||||
if (plugin.activeFolderDom) plugin.activeFolderDom.addClass('fn-is-active');
|
||||
}
|
||||
|
||||
export async function tempDisableSync(
|
||||
plugin: FolderNotesPlugin,
|
||||
folder: TFolder,
|
||||
): Promise<
|
||||
[
|
||||
excludedFolder: ExcludedFolder | undefined,
|
||||
excludedFolderExisted: boolean,
|
||||
disabledSync: boolean
|
||||
]
|
||||
> {
|
||||
export async function tempDisableSync(plugin: FolderNotesPlugin, folder: TFolder): Promise<[excludedFolder: ExcludedFolder | undefined, excludedFolderExisted: boolean, disabledSync: boolean]> {
|
||||
let excludedFolder = getExcludedFolder(plugin, folder.path, false);
|
||||
let excludedFolderExisted = true;
|
||||
let disabledSync = false;
|
||||
|
||||
if (!excludedFolder) {
|
||||
excludedFolderExisted = false;
|
||||
excludedFolder = new ExcludedFolder(
|
||||
folder.path,
|
||||
plugin.settings.excludeFolders.length,
|
||||
undefined,
|
||||
plugin,
|
||||
);
|
||||
excludedFolder = new ExcludedFolder(folder.path, plugin.settings.excludeFolders.length, undefined, plugin);
|
||||
excludedFolder.disableSync = true;
|
||||
addExcludedFolder(plugin, excludedFolder);
|
||||
} else if (!excludedFolder.disableSync) {
|
||||
|
|
@ -347,60 +221,22 @@ export async function tempDisableSync(
|
|||
return [excludedFolder, excludedFolderExisted, disabledSync];
|
||||
}
|
||||
|
||||
export async function openFolderNote(
|
||||
plugin: FolderNotesPlugin,
|
||||
file: TAbstractFile,
|
||||
evt?: MouseEvent,
|
||||
): Promise<void> {
|
||||
const { path } = file;
|
||||
const focusExistingTab = plugin.settings.focusExistingTab && plugin.settings.openInNewTab;
|
||||
const activeFilePath = plugin.app.workspace.getActiveFile()?.path;
|
||||
|
||||
// If already active and not opening in new tab, do nothing
|
||||
if (activeFilePath === path && !(Keymap.isModEvent(evt) === 'tab')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to find an existing tab with this file open
|
||||
let foundLeaf = null;
|
||||
if (focusExistingTab && file instanceof TFile) {
|
||||
plugin.app.workspace.iterateAllLeaves((leaf) => {
|
||||
if (
|
||||
leaf.getViewState().type === 'markdown' &&
|
||||
(leaf.view as MarkdownView).file?.path === path
|
||||
) {
|
||||
foundLeaf = leaf;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (foundLeaf) {
|
||||
plugin.app.workspace.setActiveLeaf(foundLeaf, { focus: true });
|
||||
} else {
|
||||
const shouldOpenInNewTab = Keymap.isModEvent(evt) || plugin.settings.openInNewTab;
|
||||
const leaf = plugin.app.workspace.getLeaf(shouldOpenInNewTab);
|
||||
if (file instanceof TFile) {
|
||||
await leaf.openFile(file);
|
||||
}
|
||||
export async function openFolderNote(plugin: FolderNotesPlugin, file: TAbstractFile, evt?: MouseEvent) {
|
||||
const path = file.path;
|
||||
if (plugin.app.workspace.getActiveFile()?.path === path && !(Keymap.isModEvent(evt) === 'tab')) { return; }
|
||||
const leaf = plugin.app.workspace.getLeaf(Keymap.isModEvent(evt) || plugin.settings.openInNewTab);
|
||||
if (file instanceof TFile) {
|
||||
await leaf.openFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteFolderNote(
|
||||
plugin: FolderNotesPlugin,
|
||||
file: TFile,
|
||||
displayModal: boolean,
|
||||
): Promise<void> {
|
||||
export async function deleteFolderNote(plugin: FolderNotesPlugin, file: TFile, displayModal: boolean) {
|
||||
if (plugin.settings.showDeleteConfirmation && displayModal) {
|
||||
return new DeleteConfirmationModal(plugin.app, plugin, file).open();
|
||||
}
|
||||
const folder = getFolder(plugin, file);
|
||||
if (!folder) return;
|
||||
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter(
|
||||
(excludedFolder) => (excludedFolder.path !== folder.path) || !excludedFolder.showFolderNote);
|
||||
plugin.saveSettings(false);
|
||||
|
||||
removeCSSClassFromFileExplorerEL(folder.path, 'has-folder-note', false, plugin);
|
||||
removeCSSClassFromEL(folder.path, 'has-folder-note', plugin);
|
||||
switch (plugin.settings.deleteFilesAction) {
|
||||
case 'trash':
|
||||
await plugin.app.vault.trash(file, true);
|
||||
|
|
@ -414,7 +250,7 @@ export async function deleteFolderNote(
|
|||
}
|
||||
}
|
||||
|
||||
export function extractFolderName(template: string, changedFileName: string): string | null {
|
||||
export function extractFolderName(template: string, changedFileName: string) {
|
||||
const [prefix, suffix] = template.split('{{folder_name}}');
|
||||
if (prefix.trim() === '' && suffix.trim() === '') {
|
||||
return changedFileName;
|
||||
|
|
@ -430,70 +266,58 @@ export function extractFolderName(template: string, changedFileName: string): st
|
|||
return null;
|
||||
}
|
||||
|
||||
function findFolderNoteFile(
|
||||
plugin: FolderNotesPlugin,
|
||||
path: string,
|
||||
primaryType: string,
|
||||
): TFile | null {
|
||||
let folderNote = plugin.app.vault.getAbstractFileByPath(path + primaryType);
|
||||
if (
|
||||
folderNote instanceof TFile &&
|
||||
plugin.settings.supportedFileTypes.includes(primaryType.replace('.', ''))
|
||||
) {
|
||||
return folderNote;
|
||||
export function getFolderNote(plugin: FolderNotesPlugin, folderPath: string, storageLocation?: string, file?: TFile, oldFolderNoteName?: string) {
|
||||
if (!folderPath) return null;
|
||||
const folder = {
|
||||
path: folderPath,
|
||||
name: getFolderNameFromPathString(folderPath),
|
||||
};
|
||||
const folderNoteName = oldFolderNoteName ?? plugin.settings.folderNoteName;
|
||||
|
||||
let fileName = folderNoteName.replace('{{folder_name}}', folder.name);
|
||||
if (file) {
|
||||
fileName = folderNoteName.replace('{{folder_name}}', file.basename);
|
||||
}
|
||||
|
||||
const supportedFileTypes = plugin.settings.supportedFileTypes.filter(
|
||||
(type) => type !== primaryType.replace('.', ''),
|
||||
);
|
||||
|
||||
for (let type of supportedFileTypes) {
|
||||
if (type === 'excalidraw' || type === '.excalidraw') {
|
||||
type = '.md';
|
||||
}
|
||||
if (!type.startsWith('.')) {
|
||||
type = '.' + type;
|
||||
}
|
||||
folderNote = plugin.app.vault.getAbstractFileByPath(path + type);
|
||||
if (folderNote instanceof TFile) {
|
||||
return folderNote;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getFolderNote(
|
||||
plugin: FolderNotesPlugin,
|
||||
folderPath: string,
|
||||
storageLocation?: string,
|
||||
file?: TFile,
|
||||
oldFolderNoteName?: string,
|
||||
): TFile | null | undefined {
|
||||
const folder = getFolderInfo(folderPath);
|
||||
if (!folder) return null;
|
||||
|
||||
let fileName = resolveFileName(plugin, folder, file, oldFolderNoteName);
|
||||
if (!fileName) return null;
|
||||
|
||||
adjustFolderPathForStorage(folder, folderPath, plugin, storageLocation);
|
||||
if ((plugin.settings.storageLocation === 'parentFolder' || storageLocation === 'parentFolder') && storageLocation !== 'insideFolder') {
|
||||
folder.path = getFolderPathFromString(folderPath);
|
||||
}
|
||||
|
||||
const path = buildFullPath(folder, fileName);
|
||||
const primaryType = normalizeFolderNoteType(plugin.settings.folderNoteType);
|
||||
|
||||
return findFolderNoteFile(plugin, path, primaryType);
|
||||
let path = `${folder.path}/${fileName}`;
|
||||
folder.path === '/' ? path = fileName : path = `${folder.path}/${fileName}`;
|
||||
|
||||
|
||||
let folderNoteType = plugin.settings.folderNoteType;
|
||||
if (folderNoteType === '.excalidraw') {
|
||||
folderNoteType = '.md';
|
||||
}
|
||||
|
||||
let folderNote = plugin.app.vault.getAbstractFileByPath(path + folderNoteType);
|
||||
if (folderNote instanceof TFile) {
|
||||
return folderNote;
|
||||
} else {
|
||||
const supportedFileTypes = plugin.settings.supportedFileTypes.filter((type) => type !== plugin.settings.folderNoteType.replace('.', ''));
|
||||
for (let type of supportedFileTypes) {
|
||||
if (type === 'excalidraw' || type === '.excalidraw') {
|
||||
type = '.md';
|
||||
}
|
||||
if (!type.startsWith('.')) {
|
||||
type = '.' + type;
|
||||
}
|
||||
folderNote = plugin.app.vault.getAbstractFileByPath(path + type);
|
||||
if (folderNote instanceof TFile) {
|
||||
return folderNote;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function detachFolderNote(plugin: FolderNotesPlugin, file: TFile): void {
|
||||
export function detachFolderNote(plugin: FolderNotesPlugin, file: TFile) {
|
||||
const folder = getFolder(plugin, file);
|
||||
if (!folder) return;
|
||||
const excludedFolder = new ExcludedFolder(
|
||||
folder.path,
|
||||
plugin.settings.excludeFolders.length,
|
||||
undefined,
|
||||
plugin,
|
||||
);
|
||||
excludedFolder.showFolderNote = true;
|
||||
const excludedFolder = new ExcludedFolder(folder.path, plugin.settings.excludeFolders.length, undefined, plugin);
|
||||
excludedFolder.hideInSettings = true;
|
||||
excludedFolder.disableFolderNote = true;
|
||||
excludedFolder.disableSync = true;
|
||||
|
|
@ -502,32 +326,19 @@ export function detachFolderNote(plugin: FolderNotesPlugin, file: TFile): void {
|
|||
excludedFolder.detached = true;
|
||||
excludedFolder.detachedFilePath = file.path;
|
||||
addExcludedFolder(plugin, excludedFolder);
|
||||
void updateCSSClassesForFolderNote(file.path, plugin);
|
||||
}
|
||||
|
||||
|
||||
export function getFolder(
|
||||
plugin: FolderNotesPlugin,
|
||||
file: TFile,
|
||||
storageLocation?: string,
|
||||
): TFolder | TAbstractFile | null {
|
||||
export function getFolder(plugin: FolderNotesPlugin, file: TFile, storageLocation?: string) {
|
||||
if (!file) return null;
|
||||
let folderName = extractFolderName(plugin.settings.folderNoteName, file.basename);
|
||||
if (
|
||||
plugin.settings.folderNoteName === file.basename &&
|
||||
plugin.settings.storageLocation === 'insideFolder'
|
||||
) {
|
||||
if (plugin.settings.folderNoteName === file.basename && plugin.settings.storageLocation === 'insideFolder') {
|
||||
folderName = file.parent?.name ?? '';
|
||||
}
|
||||
if (!folderName) return null;
|
||||
let folderPath = getFolderPathFromString(file.path);
|
||||
let folder: TFolder | TAbstractFile | null = null;
|
||||
|
||||
if (
|
||||
(plugin.settings.storageLocation === 'parentFolder' ||
|
||||
storageLocation === 'parentFolder') &&
|
||||
storageLocation !== 'insideFolder'
|
||||
) {
|
||||
if ((plugin.settings.storageLocation === 'parentFolder' || storageLocation === 'parentFolder') && storageLocation !== 'insideFolder') {
|
||||
if (folderPath.trim() === '' || folderPath === '/') {
|
||||
folderPath = folderName;
|
||||
} else {
|
||||
|
|
@ -537,16 +348,11 @@ export function getFolder(
|
|||
} else {
|
||||
folder = plugin.app.vault.getAbstractFileByPath(folderPath);
|
||||
}
|
||||
|
||||
if (!folder) { return null; }
|
||||
return folder;
|
||||
}
|
||||
|
||||
export function getFolderNoteFolder(
|
||||
plugin: FolderNotesPlugin,
|
||||
folderNote: TFile | string,
|
||||
fileName: string,
|
||||
): TFolder | TAbstractFile | null {
|
||||
export function getFolderNoteFolder(plugin: FolderNotesPlugin, folderNote: TFile | string, fileName: string) {
|
||||
if (!folderNote) return null;
|
||||
let filePath = '';
|
||||
if (typeof folderNote === 'string') {
|
||||
|
|
@ -556,13 +362,6 @@ export function getFolderNoteFolder(
|
|||
filePath = folderNote.path;
|
||||
}
|
||||
const folderName = extractFolderName(plugin.settings.folderNoteName, fileName);
|
||||
if (!plugin.settings.folderNoteName.includes('{{folder_name}}') && plugin.settings.storageLocation === 'insideFolder') {
|
||||
if (folderNote instanceof TFile) {
|
||||
return folderNote.parent;
|
||||
}
|
||||
const file = plugin.app.vault.getAbstractFileByPath(filePath);
|
||||
return file instanceof TFile ? file.parent : null;
|
||||
}
|
||||
if (!folderName) return null;
|
||||
let folderPath = getFolderPathFromString(filePath);
|
||||
if (plugin.settings.storageLocation === 'parentFolder') {
|
||||
|
|
@ -578,46 +377,3 @@ export function getFolderNoteFolder(
|
|||
if (!folder) { return null; }
|
||||
return folder;
|
||||
}
|
||||
|
||||
function getFolderInfo(folderPath: string): { path: string; name: string } | null {
|
||||
if (!folderPath) return null;
|
||||
return {
|
||||
path: folderPath,
|
||||
name: getFolderNameFromPathString(folderPath),
|
||||
};
|
||||
}
|
||||
|
||||
function resolveFileName(
|
||||
plugin: FolderNotesPlugin,
|
||||
folder: { path: string; name: string },
|
||||
file?: TFile,
|
||||
oldFolderNoteName?: string,
|
||||
): string | null {
|
||||
const templateName = oldFolderNoteName ?? plugin.settings.folderNoteName;
|
||||
if (!templateName) return null;
|
||||
const nameSource = file ? file.basename : folder.name;
|
||||
return templateName.replace('{{folder_name}}', nameSource);
|
||||
}
|
||||
|
||||
function adjustFolderPathForStorage(
|
||||
folder: { path: string; name: string },
|
||||
folderPath: string,
|
||||
plugin: FolderNotesPlugin,
|
||||
storageLocation?: string,
|
||||
): void {
|
||||
if (
|
||||
(plugin.settings.storageLocation === 'parentFolder' ||
|
||||
storageLocation === 'parentFolder') &&
|
||||
storageLocation !== 'insideFolder'
|
||||
) {
|
||||
folder.path = getFolderPathFromString(folderPath);
|
||||
}
|
||||
}
|
||||
|
||||
function buildFullPath(folder: { path: string }, fileName: string): string {
|
||||
return folder.path === '/' ? fileName : `${folder.path}/${fileName}`;
|
||||
}
|
||||
|
||||
function normalizeFolderNoteType(type: string): string {
|
||||
return type === '.excalidraw' ? '.md' : type;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,253 +1,156 @@
|
|||
import { TFile, TFolder } from 'obsidian';
|
||||
import type FolderNotesPlugin from '../main';
|
||||
import {
|
||||
getDetachedFolder,
|
||||
getExcludedFolder,
|
||||
addExcludedFolder,
|
||||
} from 'src/ExcludeFolders/functions/folderFunctions';
|
||||
import FolderNotesPlugin from '../main';
|
||||
import { getDetachedFolder, getExcludedFolder } from 'src/ExcludeFolders/functions/folderFunctions';
|
||||
import { getFolder, getFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
import { getFileExplorer } from './utils';
|
||||
import { ExcludedFolder } from 'src/ExcludeFolders/ExcludeFolder';
|
||||
import type FolderOverviewPlugin from 'src/obsidian-folder-overview/src/main';
|
||||
import FolderOverviewPlugin from 'src/obsidian-folder-overview/src/main';
|
||||
|
||||
/**
|
||||
* @description Refreshes the CSS classes for all folder notes in the file explorer.
|
||||
*/
|
||||
export function refreshAllFolderStyles(forceReload = false, plugin: FolderNotesPlugin): void {
|
||||
const fileExplorer = getFileExplorer(plugin);
|
||||
if (!fileExplorer) { return; }
|
||||
if (plugin.activeFileExplorer === fileExplorer && !forceReload) { return; }
|
||||
plugin.activeFileExplorer = fileExplorer;
|
||||
export function loadFileClasses(forceReload = false, plugin: FolderNotesPlugin) {
|
||||
if (plugin.activeFileExplorer === getFileExplorer(plugin) && !forceReload) { return; }
|
||||
plugin.activeFileExplorer = getFileExplorer(plugin);
|
||||
plugin.app.vault.getAllLoadedFiles().forEach(async (file) => {
|
||||
if (file instanceof TFolder) {
|
||||
await updateCSSClassesForFolder(file.path, plugin);
|
||||
if (!(file instanceof TFolder)) { return; }
|
||||
const folderNote = getFolderNote(plugin, file.path);
|
||||
if (!folderNote) {
|
||||
removeCSSClassFromEL(file?.path, 'has-folder-note', plugin);
|
||||
removeCSSClassFromEL(file?.path, 'only-has-folder-note', plugin);
|
||||
plugin.isEmptyFolderNoteFolder(file);
|
||||
return;
|
||||
}
|
||||
|
||||
const excludedFolder = getExcludedFolder(plugin, file.path, true);
|
||||
// cleanup after ourselves
|
||||
// Incase settings have changed
|
||||
if (excludedFolder?.disableFolderNote) {
|
||||
removeCSSClassFromEL(folderNote.path, 'is-folder-note', plugin);
|
||||
removeCSSClassFromEL(file.path, 'has-folder-note', plugin);
|
||||
removeCSSClassFromEL(file?.path, 'only-has-folder-note', plugin);
|
||||
} else {
|
||||
if (!excludedFolder?.hideNote) {
|
||||
addCSSClassToTitleEL(folderNote.path, 'is-folder-note', plugin);
|
||||
}
|
||||
addCSSClassesToFolder(file, plugin);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Updates the CSS classes for a specific folder in the file explorer.
|
||||
*/
|
||||
// eslint-disable-next-line complexity
|
||||
export async function updateCSSClassesForFolder(
|
||||
folderPath: string,
|
||||
plugin: FolderNotesPlugin,
|
||||
): Promise<void> {
|
||||
|
||||
export async function applyCSSClassesToFolder(folderPath: string, plugin: FolderNotesPlugin) {
|
||||
const folder = plugin.app.vault.getAbstractFileByPath(folderPath);
|
||||
if (!folder || !(folder instanceof TFolder)) { return; }
|
||||
|
||||
const folderNote = getFolderNote(plugin, folder.path);
|
||||
const detachedFolderNote = getDetachedFolder(plugin, folder.path);
|
||||
|
||||
if (folder.children.length === 0) {
|
||||
addCSSClassToFileExplorerEl(folder.path, 'fn-empty-folder', false, plugin);
|
||||
}
|
||||
|
||||
if (!folderNote || detachedFolderNote) {
|
||||
removeCSSClassFromFileExplorerEL(folder?.path, 'has-folder-note', false, plugin);
|
||||
removeCSSClassFromFileExplorerEL(folder?.path, 'only-has-folder-note', true, plugin);
|
||||
removeCSSClassFromFileExplorerEL(folderNote?.path, 'is-folder-note', false, plugin);
|
||||
removeCSSClassFromEL(folder?.path, 'has-folder-note', plugin);
|
||||
removeCSSClassFromEL(folder?.path, 'only-has-folder-note', plugin);
|
||||
return;
|
||||
}
|
||||
|
||||
const excludedFolder = getExcludedFolder(plugin, folder.path, true);
|
||||
|
||||
if (excludedFolder?.disableFolderNote) {
|
||||
removeCSSClassFromFileExplorerEL(folderNote.path, 'is-folder-note', false, plugin);
|
||||
removeCSSClassFromFileExplorerEL(folder.path, 'has-folder-note', false, plugin);
|
||||
removeCSSClassFromFileExplorerEL(folder?.path, 'only-has-folder-note', true, plugin);
|
||||
removeCSSClassFromEL(folderNote.path, 'is-folder-note', plugin);
|
||||
removeCSSClassFromEL(folder.path, 'has-folder-note', plugin);
|
||||
removeCSSClassFromEL(folder?.path, 'only-has-folder-note', plugin);
|
||||
} else {
|
||||
markFolderWithFolderNoteClasses(folder, plugin);
|
||||
if (excludedFolder?.showFolderNote) {
|
||||
addCSSClassToFileExplorerEl(folder.path, 'show-folder-note-in-explorer', true, plugin);
|
||||
unmarkFileAsFolderNote(folderNote, plugin);
|
||||
return;
|
||||
if (!excludedFolder?.hideNote) {
|
||||
addCSSClassToFolderNote(folderNote, plugin);
|
||||
}
|
||||
if (plugin.isEmptyFolderNoteFolder(folder) && getFolderNote(plugin, folder.path)) {
|
||||
addCSSClassToFileExplorerEl(folder.path, 'only-has-folder-note', true, plugin);
|
||||
addCSSClassesToFolder(folder, plugin);
|
||||
if (plugin.isEmptyFolderNoteFolder(folder)) {
|
||||
addCSSClassToTitleEL(folder.path, 'only-has-folder-note', plugin);
|
||||
} else {
|
||||
removeCSSClassFromFileExplorerEL(folder.path, 'only-has-folder-note', true, plugin);
|
||||
removeCSSClassFromEL(folder.path, 'only-has-folder-note', plugin);
|
||||
}
|
||||
}
|
||||
|
||||
markFolderAndNoteWithClasses(folderNote, folder, plugin);
|
||||
addCSSClassesToBothFolderAndNote(folderNote, folder, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Updates the CSS classes for a folder note file in the file explorer and then also updates the folder it belongs to.
|
||||
*/
|
||||
export async function updateCSSClassesForFolderNote(
|
||||
filePath: string,
|
||||
plugin: FolderNotesPlugin,
|
||||
): Promise<void> {
|
||||
export async function applyCSSClassesToFolderNote(filePath: string, plugin: FolderNotesPlugin) {
|
||||
const file = plugin.app.vault.getAbstractFileByPath(filePath);
|
||||
if (!file || !(file instanceof TFile)) { return; }
|
||||
|
||||
const folder = getFolder(plugin, file);
|
||||
if (!folder || !(folder instanceof TFolder)) { return; }
|
||||
|
||||
updateCSSClassesForFolder(folder.path, plugin);
|
||||
applyCSSClassesToFolder(folder.path, plugin);
|
||||
|
||||
}
|
||||
|
||||
export function markFolderAndNoteWithClasses(
|
||||
file: TFile,
|
||||
folder: TFolder,
|
||||
plugin: FolderNotesPlugin,
|
||||
): void {
|
||||
markFileAsFolderNote(file, plugin);
|
||||
markFolderWithFolderNoteClasses(folder, plugin);
|
||||
export function addCSSClassesToBothFolderAndNote(file: TFile, folder: TFolder, plugin: FolderNotesPlugin) {
|
||||
addCSSClassToFolderNote(file, plugin);
|
||||
addCSSClassesToFolder(folder, plugin);
|
||||
}
|
||||
|
||||
export function clearFolderAndNoteClasses(
|
||||
folder: TFolder,
|
||||
file: TFile,
|
||||
plugin: FolderNotesPlugin,
|
||||
): void {
|
||||
unmarkFileAsFolderNote(file, plugin);
|
||||
clearFolderNoteClassesFromFolder(folder, plugin);
|
||||
export function removeCSSClassesFromBothFolderAndNote(folder: TFolder, file: TFile, plugin: FolderNotesPlugin) {
|
||||
removeCSSClassFromFolderNote(file, plugin);
|
||||
removeCSSClassesFromFolder(folder, plugin);
|
||||
}
|
||||
|
||||
export function markFolderWithFolderNoteClasses(folder: TFolder, plugin: FolderNotesPlugin): void {
|
||||
addCSSClassToFileExplorerEl(folder.path, 'has-folder-note', false, plugin);
|
||||
if (plugin.isEmptyFolderNoteFolder(folder) && getFolderNote(plugin, folder.path)) {
|
||||
addCSSClassToFileExplorerEl(folder.path, 'only-has-folder-note', true, plugin);
|
||||
export function addCSSClassesToFolder(folder: TFolder, plugin: FolderNotesPlugin) {
|
||||
addCSSClassToTitleEL(folder.path, 'has-folder-note', plugin);
|
||||
if (plugin.isEmptyFolderNoteFolder(folder)) {
|
||||
addCSSClassToTitleEL(folder.path, 'only-has-folder-note', plugin);
|
||||
} else {
|
||||
removeCSSClassFromFileExplorerEL(folder.path, 'only-has-folder-note', true, plugin);
|
||||
removeCSSClassFromEL(folder.path, 'only-has-folder-note', plugin);
|
||||
}
|
||||
}
|
||||
|
||||
export function markFileAsFolderNote(file: TFile, plugin: FolderNotesPlugin): void {
|
||||
addCSSClassToFileExplorerEl(file.path, 'is-folder-note', false, plugin);
|
||||
export function addCSSClassToFolderNote(file: TFile, plugin: FolderNotesPlugin) {
|
||||
addCSSClassToTitleEL(file.path, 'is-folder-note', plugin);
|
||||
}
|
||||
|
||||
export function unmarkFileAsFolderNote(file: TFile, plugin: FolderNotesPlugin): void {
|
||||
removeCSSClassFromFileExplorerEL(file.path, 'is-folder-note', false, plugin);
|
||||
export function removeCSSClassFromFolderNote(file: TFile, plugin: FolderNotesPlugin) {
|
||||
removeCSSClassFromEL(file.path, 'is-folder-note', plugin);
|
||||
}
|
||||
|
||||
export function unmarkFolderAsFolderNote(folder: TFolder, plugin: FolderNotesPlugin): void {
|
||||
removeCSSClassFromFileExplorerEL(folder.path, 'has-folder-note', false, plugin);
|
||||
removeCSSClassFromFileExplorerEL(folder.path, 'only-has-folder-note', true, plugin);
|
||||
export function removeCSSClassesFromFolder(folder: TFolder, plugin: FolderNotesPlugin) {
|
||||
removeCSSClassFromEL(folder.path, 'has-folder-note', plugin);
|
||||
removeCSSClassFromEL(folder.path, 'only-has-folder-note', plugin);
|
||||
}
|
||||
|
||||
export function clearFolderNoteClassesFromFolder(folder: TFolder, plugin: FolderNotesPlugin): void {
|
||||
removeCSSClassFromFileExplorerEL(folder.path, 'has-folder-note', false, plugin);
|
||||
removeCSSClassFromFileExplorerEL(folder.path, 'only-has-folder-note', true, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param path Can be a folder or file path
|
||||
* @returns nothing
|
||||
*/
|
||||
export async function addCSSClassToFileExplorerEl(
|
||||
path: string,
|
||||
cssClass: string,
|
||||
parent = false,
|
||||
plugin: FolderNotesPlugin,
|
||||
waitForCreate = false,
|
||||
count = 0,
|
||||
): Promise<void> {
|
||||
const fileExplorerItem = getFileExplorerElement(path, plugin);
|
||||
const MAX_RETRIES = 5;
|
||||
const RETRY_DELAY = 500;
|
||||
|
||||
export async function addCSSClassToTitleEL(path: string, cssClass: string, plugin: FolderNotesPlugin, waitForCreate = false, count = 0) {
|
||||
const fileExplorerItem = getEl(path, plugin);
|
||||
if (!fileExplorerItem) {
|
||||
if (waitForCreate && count < MAX_RETRIES) {
|
||||
await new Promise((r) => window.setTimeout(r, RETRY_DELAY));
|
||||
addCSSClassToFileExplorerEl(path, cssClass, parent, plugin, waitForCreate, count + 1);
|
||||
if (waitForCreate && count < 5) {
|
||||
// sleep for a second for the file-explorer event to catch up
|
||||
// this is annoying as in most scanarios our plugin recieves the event before file explorer
|
||||
// If we could guarrantee load order it wouldn't be an issue but we can't
|
||||
// realise this is racey and needs to be fixed.
|
||||
await new Promise((r) => setTimeout(r, 500));
|
||||
addCSSClassToTitleEL(path, cssClass, plugin, waitForCreate, count + 1);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (parent) {
|
||||
const parentElement = fileExplorerItem?.parentElement;
|
||||
if (parentElement) {
|
||||
parentElement.addClass(cssClass);
|
||||
}
|
||||
} else {
|
||||
fileExplorerItem.addClass(cssClass);
|
||||
activeDocument.querySelectorAll(`[data-path='${CSS.escape(path)}']`).forEach((item) => {
|
||||
item.addClass(cssClass);
|
||||
});
|
||||
}
|
||||
fileExplorerItem.addClass(cssClass);
|
||||
const viewHeaderItems = document.querySelectorAll(`[data-path='${CSS.escape(path)}']`);
|
||||
viewHeaderItems.forEach((item) => {
|
||||
item.addClass(cssClass);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param path Can be a folder or file path
|
||||
* @param cssClass The CSS class to remove from the file explorer element
|
||||
* @returns nothing
|
||||
*/
|
||||
export function removeCSSClassFromFileExplorerEL(
|
||||
path: string | undefined,
|
||||
cssClass: string,
|
||||
parent: boolean,
|
||||
plugin: FolderNotesPlugin,
|
||||
): void {
|
||||
export function removeCSSClassFromEL(path: string | undefined, cssClass: string, plugin: FolderNotesPlugin) {
|
||||
if (!path) return;
|
||||
const fileExplorerItem = getFileExplorerElement(path, plugin);
|
||||
activeDocument.querySelectorAll(`[data-path='${CSS.escape(path)}']`).forEach((item) => {
|
||||
const fileExplorerItem = getEl(path, plugin);
|
||||
const viewHeaderItems = document.querySelectorAll(`[data-path='${CSS.escape(path)}']`);
|
||||
viewHeaderItems.forEach((item) => {
|
||||
item.removeClass(cssClass);
|
||||
});
|
||||
if (!fileExplorerItem) { return; }
|
||||
if (parent) {
|
||||
const parentElement = fileExplorerItem?.parentElement;
|
||||
if (parentElement) {
|
||||
parentElement.removeClass(cssClass);
|
||||
}
|
||||
return;
|
||||
}
|
||||
fileExplorerItem.removeClass(cssClass);
|
||||
|
||||
}
|
||||
|
||||
export function getFileExplorerElement(
|
||||
path: string,
|
||||
plugin: FolderNotesPlugin | FolderOverviewPlugin,
|
||||
): HTMLElement | null {
|
||||
export function getEl(path: string, plugin: FolderNotesPlugin | FolderOverviewPlugin): HTMLElement | null {
|
||||
const fileExplorer = getFileExplorer(plugin);
|
||||
if (!fileExplorer?.view?.fileItems) { return null; }
|
||||
if (!fileExplorer) { return null; }
|
||||
if (!fileExplorer.view) { return null; }
|
||||
if (!fileExplorer.view.fileItems) { return null; }
|
||||
const fileExplorerItem = fileExplorer.view.fileItems?.[path];
|
||||
return fileExplorerItem?.selfEl ?? fileExplorerItem?.titleEl ?? null;
|
||||
}
|
||||
|
||||
export function showFolderNoteInFileExplorer(path: string, plugin: FolderNotesPlugin): void {
|
||||
const excludedFolder = new ExcludedFolder(
|
||||
path,
|
||||
plugin.settings.excludeFolders.length,
|
||||
undefined,
|
||||
plugin,
|
||||
);
|
||||
excludedFolder.subFolders = false;
|
||||
excludedFolder.disableSync = false;
|
||||
excludedFolder.disableAutoCreate = false;
|
||||
excludedFolder.disableFolderNote = false;
|
||||
excludedFolder.enableCollapsing = false;
|
||||
excludedFolder.excludeFromFolderOverview = false;
|
||||
excludedFolder.hideInSettings = true;
|
||||
excludedFolder.showFolderNote = true;
|
||||
addExcludedFolder(plugin, excludedFolder, false);
|
||||
addCSSClassToFileExplorerEl(path, 'show-folder-note-in-explorer', true, plugin);
|
||||
updateCSSClassesForFolder(path, plugin);
|
||||
}
|
||||
|
||||
export function hideFolderNoteInFileExplorer(folderPath: string, plugin: FolderNotesPlugin): void {
|
||||
plugin.settings.excludeFolders = plugin.settings.excludeFolders.filter(
|
||||
(folder) => (folder.path !== folderPath) || !folder.showFolderNote);
|
||||
plugin.saveSettings(false);
|
||||
removeCSSClassFromFileExplorerEL(folderPath, 'show-folder-note-in-explorer', true, plugin);
|
||||
updateCSSClassesForFolder(folderPath, plugin);
|
||||
}
|
||||
|
||||
export function setActiveFolder(folderPath: string, plugin: FolderNotesPlugin): void {
|
||||
const fileExplorerItem = getFileExplorerElement(folderPath, plugin);
|
||||
if (fileExplorerItem) {
|
||||
fileExplorerItem.addClass('fn-is-active');
|
||||
plugin.activeFolderDom = fileExplorerItem;
|
||||
}
|
||||
}
|
||||
|
||||
export function removeActiveFolder(plugin: FolderNotesPlugin): void {
|
||||
if (plugin.activeFolderDom) {
|
||||
plugin.activeFolderDom.removeClass('fn-is-active');
|
||||
plugin.activeFolderDom?.removeClass('has-focus');
|
||||
plugin.activeFolderDom = null;
|
||||
}
|
||||
if (!fileExplorerItem) { return null; }
|
||||
if (fileExplorerItem.selfEl) return fileExplorerItem.selfEl;
|
||||
return fileExplorerItem.titleEl;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,20 @@
|
|||
import { TFolder, TFile, View, type TAbstractFile } from 'obsidian';
|
||||
import type { FileExplorerWorkspaceLeaf, FileExplorerView } from 'src/globals';
|
||||
import { TFolder, TFile, View } from 'obsidian';
|
||||
import { FileExplorerWorkspaceLeaf, FileExplorerView } from 'src/globals';
|
||||
import { getFolderNote } from './folderNoteFunctions';
|
||||
import type FolderNotesPlugin from 'src/main';
|
||||
import type { FileTreeItem } from 'obsidian-typings';
|
||||
import type FolderOverviewPlugin from 'src/obsidian-folder-overview/src/main';
|
||||
|
||||
function isFileExplorerWorkspaceLeaf(leaf: unknown): leaf is FileExplorerWorkspaceLeaf {
|
||||
const tabHeaderEl = (leaf as { tabHeaderEl?: HTMLElement | null } | null)?.tabHeaderEl;
|
||||
return tabHeaderEl?.dataset?.type === 'file-explorer';
|
||||
}
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
import { FileExplorerLeaf } from 'obsidian-typings';
|
||||
import FolderOverviewPlugin from 'src/obsidian-folder-overview/src/main';
|
||||
|
||||
export function getFileNameFromPathString(path: string): string {
|
||||
return path.substring(path.lastIndexOf('/') >= 0 ? path.lastIndexOf('/') + 1 : 0);
|
||||
}
|
||||
|
||||
export function getFolderNameFromPathString(path: string): string {
|
||||
const PARENT_FOLDER_INDEX = -2;
|
||||
const LAST_FOLDER_INDEX = -1;
|
||||
if (path.endsWith('.md') || path.endsWith('.canvas')) {
|
||||
return path.split('/').slice(PARENT_FOLDER_INDEX)[0];
|
||||
return path.split('/').slice(-2)[0];
|
||||
} else {
|
||||
return path.split('/').slice(-1)[0];
|
||||
}
|
||||
return path.split('/').slice(LAST_FOLDER_INDEX)[0];
|
||||
}
|
||||
|
||||
export function removeExtension(name: string): string {
|
||||
|
|
@ -36,76 +30,46 @@ export function getFolderPathFromString(path: string): string {
|
|||
const folderPath = path.substring(0, subString);
|
||||
if (folderPath === '') {
|
||||
return '/';
|
||||
} else {
|
||||
return folderPath;
|
||||
}
|
||||
return folderPath;
|
||||
|
||||
}
|
||||
|
||||
export function getParentFolderPath(path: string): string {
|
||||
return getFolderPathFromString(getFolderPathFromString(path));
|
||||
return this.getFolderPathFromString(this.getFolderPathFromString(path));
|
||||
}
|
||||
|
||||
export function getFileExplorer(
|
||||
plugin: FolderNotesPlugin | FolderOverviewPlugin,
|
||||
): FileExplorerWorkspaceLeaf | undefined {
|
||||
let leaf = plugin.app.workspace.getLeavesOfType('file-explorer')[0];
|
||||
|
||||
if (!leaf) { return undefined; }
|
||||
|
||||
/* make.md plugin integration */
|
||||
if ((leaf.containerEl?.lastChild as HTMLElement)?.dataset?.type === 'mk-path-view') {
|
||||
plugin.app.workspace.iterateAllLeaves((x) => {
|
||||
if (isFileExplorerWorkspaceLeaf(x)) {
|
||||
leaf = x;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return isFileExplorerWorkspaceLeaf(leaf) ? leaf : undefined;
|
||||
export function getFileExplorer(plugin: FolderNotesPlugin | FolderOverviewPlugin) {
|
||||
return plugin.app.workspace.getLeavesOfType('file-explorer')[0] as any as FileExplorerWorkspaceLeaf;
|
||||
}
|
||||
|
||||
export function getFileExplorerView(plugin: FolderNotesPlugin): FileExplorerView | undefined {
|
||||
return getFileExplorer(plugin)?.view;
|
||||
export function getFileExplorerView(plugin: FolderNotesPlugin) {
|
||||
return getFileExplorer(plugin).view;
|
||||
}
|
||||
|
||||
export function getFocusedItem(plugin: FolderNotesPlugin): FileTreeItem | null {
|
||||
const fileExplorer = getFileExplorer(plugin);
|
||||
if (!fileExplorer) { return null; }
|
||||
const { focusedItem } = fileExplorer.view.tree;
|
||||
export function getFocusedItem(plugin: FolderNotesPlugin) {
|
||||
const fileExplorer = getFileExplorer(plugin) as any as FileExplorerLeaf;
|
||||
const focusedItem = fileExplorer.view.tree.focusedItem;
|
||||
return focusedItem;
|
||||
}
|
||||
|
||||
export function getFileExplorerActiveFolder(plugin: FolderNotesPlugin): TFolder | null {
|
||||
export function getFileExplorerActiveFolder(): TFolder | null {
|
||||
// Check if the active view is a file explorer.
|
||||
const view = plugin.app.workspace.getActiveViewOfType(View);
|
||||
const view = this.app.workspace.getActiveViewOfType(View);
|
||||
if (view?.getViewType() !== 'file-explorer') return null;
|
||||
// Check if there is a focused or active item in the file explorer.
|
||||
const fe = view as FileExplorerView;
|
||||
const activeFileOrFolder =
|
||||
fe.tree.focusedItem?.file ?? fe.activeDom?.file;
|
||||
if (!(activeFileOrFolder instanceof TFolder)) return null;
|
||||
return activeFileOrFolder;
|
||||
return activeFileOrFolder as TFolder;
|
||||
}
|
||||
|
||||
export function getFileExplorerActiveFolderNote(plugin: FolderNotesPlugin): TFile | null {
|
||||
const folder = getFileExplorerActiveFolder(plugin);
|
||||
export function getFileExplorerActiveFolderNote(): TFile | null {
|
||||
const folder = getFileExplorerActiveFolder();
|
||||
if (!folder) return null;
|
||||
// Is there any folder note for the active folder?
|
||||
const folderNote = getFolderNote(plugin, folder.path);
|
||||
const folderNote = getFolderNote(this.plugin, folder.path);
|
||||
if (!(folderNote instanceof TFile)) return null;
|
||||
return folderNote;
|
||||
}
|
||||
|
||||
|
||||
export function getAttachmentFolderPath(plugin: FolderNotesPlugin): string {
|
||||
const attachmentFolderPath = plugin.app.vault.getConfig('attachmentFolderPath') as string;
|
||||
const cleanAttachmentFolderPath = attachmentFolderPath?.replace('./', '') || '';
|
||||
return cleanAttachmentFolderPath;
|
||||
}
|
||||
|
||||
export function isFileInAttachmentFolder(plugin: FolderNotesPlugin, file: TAbstractFile): boolean {
|
||||
const attachmentFolderPath = getAttachmentFolderPath(plugin);
|
||||
if (!attachmentFolderPath) return false;
|
||||
return file.path.startsWith(attachmentFolderPath + '/')
|
||||
|| file.path.includes('/' + attachmentFolderPath + '/');
|
||||
}
|
||||
|
|
|
|||
4
src/globals.d.ts
vendored
|
|
@ -1,4 +1,4 @@
|
|||
import type { TAbstractFile, TFile, TFolder, View, WorkspaceLeaf } from 'obsidian';
|
||||
import { TAbstractFile, TFile, TFolder, View, WorkspaceLeaf } from 'obsidian';
|
||||
|
||||
declare module 'obsidian' {
|
||||
interface Setting {
|
||||
|
|
@ -40,6 +40,7 @@ interface FileItem {
|
|||
el: HTMLDivElement;
|
||||
file: TFile;
|
||||
fileExplorer: FileExplorerView;
|
||||
info: any;
|
||||
selfEl: HTMLDivElement;
|
||||
innerEl: HTMLDivElement;
|
||||
}
|
||||
|
|
@ -47,6 +48,7 @@ interface FileItem {
|
|||
interface FolderItem {
|
||||
el: HTMLDivElement;
|
||||
fileExplorer: FileExplorerView;
|
||||
info: any;
|
||||
selfEl: HTMLDivElement;
|
||||
innerEl: HTMLDivElement;
|
||||
file: TFolder;
|
||||
|
|
|
|||
580
src/main.ts
|
|
@ -1,116 +1,89 @@
|
|||
import {
|
||||
type App, type TAbstractFile,
|
||||
type MarkdownPostProcessorContext,
|
||||
type WorkspaceLeaf,
|
||||
Plugin, TFile, TFolder,
|
||||
parseYaml, Notice, Keymap,
|
||||
requireApiVersion, Platform, debounce,
|
||||
} from 'obsidian';
|
||||
import {
|
||||
type FolderNotesSettings, DEFAULT_SETTINGS, SettingsTab,
|
||||
} from './settings/SettingsTab';
|
||||
import { FolderOverview, type defaultOverviewSettings } from './obsidian-folder-overview/src/FolderOverview';
|
||||
|
||||
import { Plugin, TFile, TFolder, TAbstractFile, MarkdownPostProcessorContext, parseYaml, Notice, Keymap, WorkspaceLeaf, requireApiVersion } from 'obsidian';
|
||||
import { DEFAULT_SETTINGS, FolderNotesSettings, SettingsTab } from './settings/SettingsTab';
|
||||
import { Commands } from './Commands';
|
||||
import type { FileExplorerWorkspaceLeaf } from './globals';
|
||||
import {
|
||||
registerFileExplorerObserver, unregisterFileExplorerObserver,
|
||||
} from './events/MutationObserver';
|
||||
import { FileExplorerWorkspaceLeaf } from './globals';
|
||||
import { handleFolderClick } from './events/handleClick';
|
||||
import { registerFileExplorerObserver, unregisterFileExplorerObserver } from './events/MutationObserver';
|
||||
import { handleRename } from './events/handleRename';
|
||||
import {
|
||||
getFolderNote, getFolder, openFolderNote, createFolderNote,
|
||||
} from './functions/folderNoteFunctions';
|
||||
import { getFolderNote, getFolder, openFolderNote } from './functions/folderNoteFunctions';
|
||||
import { handleCreate } from './events/handleCreate';
|
||||
import { FrontMatterTitlePluginHandler } from './events/FrontMatterTitle';
|
||||
import { FolderOverviewSettings } from './obsidian-folder-overview/src/modals/Settings';
|
||||
import { FolderOverview } from './obsidian-folder-overview/src/FolderOverview';
|
||||
import { TabManager } from './events/TabManager';
|
||||
import './functions/ListComponent';
|
||||
import { handleDelete } from './events/handleDelete';
|
||||
import {
|
||||
addCSSClassToFileExplorerEl, getFileExplorerElement, removeCSSClassFromFileExplorerEL,
|
||||
refreshAllFolderStyles, setActiveFolder, removeActiveFolder,
|
||||
} from './functions/styleFunctions';
|
||||
import { addCSSClassToTitleEL, getEl, loadFileClasses } from './functions/styleFunctions';
|
||||
import { getExcludedFolder } from './ExcludeFolders/functions/folderFunctions';
|
||||
import { getFileExplorer } from './functions/utils';
|
||||
import { FileExplorerView, InternalPlugin } from 'obsidian-typings';
|
||||
import { getFocusedItem } from './functions/utils';
|
||||
import { FOLDER_OVERVIEW_VIEW, FolderOverviewView } from './obsidian-folder-overview/src/view';
|
||||
import { registerOverviewCommands } from './obsidian-folder-overview/src/Commands';
|
||||
import { updateOverviewView, updateViewDropdown } from './obsidian-folder-overview/src/main';
|
||||
import { FvIndexDB } from './obsidian-folder-overview/src/utils/IndexDB';
|
||||
import { updateAllOverviews } from './obsidian-folder-overview/src/utils/functions';
|
||||
|
||||
interface FileExplorerPluginLike extends Plugin {
|
||||
revealInFolder: (file: TAbstractFile) => void;
|
||||
}
|
||||
|
||||
interface DragManagerLike {
|
||||
draggable?: {
|
||||
file?: TAbstractFile;
|
||||
type?: string;
|
||||
} | null;
|
||||
setAction(action: string): void;
|
||||
}
|
||||
|
||||
interface ClipboardManagerLike {
|
||||
app: App & {
|
||||
dragManager?: DragManagerLike;
|
||||
};
|
||||
handleDragOver: (evt: DragEvent, ...args: unknown[]) => void;
|
||||
handleDrop: (evt: DragEvent, ...args: unknown[]) => void;
|
||||
}
|
||||
|
||||
interface EditModeLike {
|
||||
clipboardManager: ClipboardManagerLike;
|
||||
}
|
||||
|
||||
interface ViewWithEditModes {
|
||||
editMode?: EditModeLike;
|
||||
sourceMode?: EditModeLike;
|
||||
}
|
||||
|
||||
interface ActiveEditorLike {
|
||||
editMode?: EditModeLike;
|
||||
}
|
||||
|
||||
type LegacySettingsData = Partial<FolderNotesSettings> & {
|
||||
allowWhitespaceCollapsing?: boolean;
|
||||
defaultOverview?: defaultOverviewSettings;
|
||||
};
|
||||
|
||||
export default class FolderNotesPlugin extends Plugin {
|
||||
settings!: FolderNotesSettings;
|
||||
settingsTab!: SettingsTab;
|
||||
activeFolderDom!: HTMLElement | null;
|
||||
activeFileExplorer!: FileExplorerWorkspaceLeaf;
|
||||
observer: MutationObserver;
|
||||
settings: FolderNotesSettings;
|
||||
settingsTab: SettingsTab;
|
||||
activeFolderDom: HTMLElement | null;
|
||||
activeFileExplorer: FileExplorerWorkspaceLeaf;
|
||||
fmtpHandler: FrontMatterTitlePluginHandler | null = null;
|
||||
hoveredElement: HTMLElement | null = null;
|
||||
mouseEvent: MouseEvent | null = null;
|
||||
hoverLinkTriggered = false;
|
||||
tabManager!: TabManager;
|
||||
tabManager: TabManager;
|
||||
settingsOpened = false;
|
||||
askModalCurrentlyOpen = false;
|
||||
fvIndexDB!: FvIndexDB;
|
||||
|
||||
async onload(): Promise<void> {
|
||||
console.debug('loading folder notes plugin');
|
||||
private fileExplorerPlugin!: InternalPlugin;
|
||||
private fileExplorerView!: FileExplorerView;
|
||||
|
||||
async onload() {
|
||||
console.log('loading folder notes plugin');
|
||||
await this.loadSettings();
|
||||
this.settingsTab = new SettingsTab(this.app, this);
|
||||
this.addSettingTab(this.settingsTab);
|
||||
await this.saveSettings();
|
||||
this.fvIndexDB = new FvIndexDB(this);
|
||||
this.saveSettings();
|
||||
|
||||
// Add CSS Classes
|
||||
this.addSettingCssClasses();
|
||||
document.body.classList.add('folder-notes-plugin');
|
||||
if (this.settings.hideFolderNote) { document.body.classList.add('hide-folder-note'); }
|
||||
if (this.settings.hideCollapsingIconForEmptyFolders) { document.body.classList.add('fn-hide-empty-collapse-icon'); }
|
||||
if (this.settings.underlineFolder) { document.body.classList.add('folder-note-underline'); }
|
||||
if (this.settings.boldName) { document.body.classList.add('folder-note-bold'); }
|
||||
if (this.settings.cursiveName) { document.body.classList.add('folder-note-cursive'); }
|
||||
if (this.settings.boldNameInPath) { document.body.classList.add('folder-note-bold-path'); }
|
||||
if (this.settings.cursiveNameInPath) { document.body.classList.add('folder-note-cursive-path'); }
|
||||
if (this.settings.underlineFolderInPath) { document.body.classList.add('folder-note-underline-path'); }
|
||||
if (this.settings.stopWhitespaceCollapsing) { document.body.classList.add('fn-whitespace-stop-collapsing'); }
|
||||
if (this.settings.hideCollapsingIcon) { document.body.classList.add('fn-hide-collapse-icon'); }
|
||||
if (!this.settings.highlightFolder) { document.body.classList.add('disable-folder-highlight'); }
|
||||
if (requireApiVersion('1.7.2')) {
|
||||
document.body.classList.add('version-1-7-2');
|
||||
}
|
||||
|
||||
new Commands(this.app, this).registerCommands();
|
||||
registerOverviewCommands(this);
|
||||
|
||||
this.app.workspace.onLayoutReady(() => this.onLayoutReady());
|
||||
this.app.workspace.onLayoutReady(this.onLayoutReady.bind(this));
|
||||
|
||||
// this.observer.observe(document.body, {
|
||||
// childList: true,
|
||||
// subtree: true,
|
||||
// });
|
||||
|
||||
if (!this.settings.persistentSettingsTab.afterRestart) {
|
||||
this.settings.settingsTab = 'general';
|
||||
}
|
||||
|
||||
this.registerDomEvent(window, 'keydown', (event: KeyboardEvent) => {
|
||||
const { hoveredElement } = this;
|
||||
if (event.key === 'Enter') {
|
||||
const folderNote = getFolderNote(this, getFocusedItem(this)?.file?.path || '');
|
||||
if (!folderNote) return;
|
||||
openFolderNote(this, folderNote);
|
||||
}
|
||||
|
||||
const hoveredElement = this.hoveredElement;
|
||||
if (this.hoverLinkTriggered) return;
|
||||
if (!hoveredElement) return;
|
||||
if (!Keymap.isModEvent(event)) return;
|
||||
|
|
@ -132,8 +105,15 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
this.hoverLinkTriggered = true;
|
||||
});
|
||||
|
||||
this.registerEvent(this.app.workspace.on('file-open', (openFile: TFile | null) => {
|
||||
removeActiveFolder(this);
|
||||
this.registerEvent(this.app.vault.on('create', (file: TAbstractFile) => {
|
||||
handleCreate(file, this);
|
||||
}));
|
||||
|
||||
this.registerEvent(this.app.workspace.on('file-open', async (openFile: TFile | null) => {
|
||||
if (this.activeFolderDom) {
|
||||
this.activeFolderDom.removeClass('fn-is-active');
|
||||
this.activeFolderDom = null;
|
||||
}
|
||||
|
||||
if (!openFile || !openFile.basename) { return; }
|
||||
|
||||
|
|
@ -144,300 +124,74 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
const folderNote = getFolderNote(this, folder.path);
|
||||
if (!folderNote) { return; }
|
||||
if (folderNote.path !== openFile.path) { return; }
|
||||
setActiveFolder(folder.path, this);
|
||||
}));
|
||||
|
||||
this.registerEvent(this.app.vault.on('create', (file: TAbstractFile) => {
|
||||
handleCreate(file, this).catch((err) => {
|
||||
console.error(err); new Notice('Error handling file creation');
|
||||
});
|
||||
this.handleVaultChange();
|
||||
this.activeFolderDom = getEl(folder.path, this);
|
||||
if (this.activeFolderDom) this.activeFolderDom.addClass('fn-is-active');
|
||||
}));
|
||||
|
||||
this.registerEvent(this.app.vault.on('rename', (file: TAbstractFile, oldPath: string) => {
|
||||
handleRename(file, oldPath, this);
|
||||
this.handleVaultChange();
|
||||
}));
|
||||
|
||||
this.registerEvent(this.app.vault.on('delete', (file: TAbstractFile) => {
|
||||
handleDelete(file, this);
|
||||
this.handleVaultChange();
|
||||
}));
|
||||
|
||||
this.registerMarkdownCodeBlockProcessor(
|
||||
'folder-overview',
|
||||
(source: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) => {
|
||||
this.handleOverviewBlock(source, el, ctx);
|
||||
},
|
||||
);
|
||||
this.registerMarkdownCodeBlockProcessor('folder-overview', (source: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) => {
|
||||
this.handleOverviewBlock(source, el, ctx);
|
||||
});
|
||||
}
|
||||
|
||||
addSettingCssClasses(): void {
|
||||
activeDocument.body.classList.add('folder-notes-plugin');
|
||||
if (this.settings.hideFolderNote) { activeDocument.body.classList.add('hide-folder-note'); }
|
||||
if (this.settings.hideCollapsingIconForEmptyFolders) {
|
||||
activeDocument.body.classList.add('fn-hide-empty-collapse-icon');
|
||||
}
|
||||
if (this.settings.hideFolderNoteNameInPath) {
|
||||
activeDocument.body.classList.add('folder-note-hide-name-path');
|
||||
}
|
||||
if (this.settings.underlineFolder) {
|
||||
activeDocument.body.classList.add('folder-note-underline');
|
||||
}
|
||||
if (this.settings.boldName) { activeDocument.body.classList.add('folder-note-bold'); }
|
||||
if (this.settings.cursiveName) { activeDocument.body.classList.add('folder-note-cursive'); }
|
||||
if (this.settings.boldNameInPath) {
|
||||
activeDocument.body.classList.add('folder-note-bold-path');
|
||||
}
|
||||
if (this.settings.cursiveNameInPath) {
|
||||
activeDocument.body.classList.add('folder-note-cursive-path');
|
||||
}
|
||||
if (this.settings.underlineFolderInPath) {
|
||||
activeDocument.body.classList.add('folder-note-underline-path');
|
||||
}
|
||||
if (this.settings.stopWhitespaceCollapsing) {
|
||||
activeDocument.body.classList.add('fn-whitespace-stop-collapsing');
|
||||
}
|
||||
if (this.settings.hideCollapsingIcon) {
|
||||
activeDocument.body.classList.add('fn-hide-collapse-icon');
|
||||
}
|
||||
if (this.settings.ignoreAttachmentFolder) {
|
||||
activeDocument.body.classList.add('fn-ignore-attachment-folder');
|
||||
}
|
||||
if (!this.settings.highlightFolder) {
|
||||
activeDocument.body.classList.add('disable-folder-highlight');
|
||||
}
|
||||
|
||||
if (requireApiVersion('1.7.2')) {
|
||||
activeDocument.body.classList.add('version-1-7-2');
|
||||
}
|
||||
}
|
||||
|
||||
onLayoutReady(): void {
|
||||
if (!this._loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
onLayoutReady() {
|
||||
registerFileExplorerObserver(this);
|
||||
|
||||
const fileExplorer = getFileExplorer(this);
|
||||
// @ts-expect-error use internal API
|
||||
const infinityScroll = fileExplorer?.view?.tree?.infinityScroll;
|
||||
|
||||
if (infinityScroll) {
|
||||
// increase infinity scroll buffer to show hidden folder notes
|
||||
// Issue: https://github.com/LostPaul/obsidian-folder-notes/issues/274
|
||||
infinityScroll.rootMargin = 1.5;
|
||||
}
|
||||
|
||||
this.registerView(FOLDER_OVERVIEW_VIEW, (leaf: WorkspaceLeaf) => {
|
||||
return new FolderOverviewView(leaf, this);
|
||||
});
|
||||
|
||||
this.app.workspace.on('layout-change', () => {
|
||||
this.tabManager.updateTabs();
|
||||
});
|
||||
|
||||
if (this.app.plugins.getPlugin('obsidian-front-matter-title-plugin')) {
|
||||
if (this.settings.frontMatterTitle.enabled) {
|
||||
this.fmtpHandler = new FrontMatterTitlePluginHandler(this);
|
||||
}
|
||||
this.tabManager = new TabManager(this);
|
||||
this.tabManager.updateTabs();
|
||||
|
||||
this.registerDomEvent(activeDocument, 'click', (evt: MouseEvent) => {
|
||||
this.handleFileExplorerClick(evt);
|
||||
}, true);
|
||||
|
||||
// Handle middle mouse button clicks
|
||||
this.registerDomEvent(activeDocument, 'auxclick', (evt: MouseEvent) => {
|
||||
const rightClick = 2;
|
||||
if (evt.button === rightClick) return;
|
||||
this.handleFileExplorerClick(evt);
|
||||
}, true);
|
||||
|
||||
const fileExplorerPlugin = this.app.internalPlugins.getEnabledPluginById('file-explorer');
|
||||
if (fileExplorerPlugin) {
|
||||
const fileExplorer = fileExplorerPlugin as unknown as FileExplorerPluginLike;
|
||||
const originalRevealInFolder =
|
||||
(fileExplorer.revealInFolder as unknown as FileExplorerPluginLike['revealInFolder'])
|
||||
.bind(fileExplorer);
|
||||
fileExplorer.revealInFolder = (file: TAbstractFile): void => {
|
||||
if (file instanceof TFile) {
|
||||
const folder = getFolder(this, file);
|
||||
if (folder instanceof TFolder) {
|
||||
const folderNote = getFolderNote(this, folder.path);
|
||||
if (!folderNote || folderNote.path !== file.path) {
|
||||
originalRevealInFolder(file);
|
||||
return;
|
||||
}
|
||||
activeDocument.body.classList.remove('hide-folder-note');
|
||||
originalRevealInFolder(folder);
|
||||
const FOLDER_REVEAL_DELAY = 100;
|
||||
window.setTimeout(() => {
|
||||
activeDocument.body.classList.add('hide-folder-note');
|
||||
}, FOLDER_REVEAL_DELAY);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (file instanceof TFolder || file instanceof TFile) {
|
||||
originalRevealInFolder(file);
|
||||
return;
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const leaf = this.app.workspace.getLeavesOfType('markdown').first();
|
||||
const view = leaf?.view;
|
||||
|
||||
if (!view) { return; }
|
||||
|
||||
const viewWithEditModes = view as ViewWithEditModes;
|
||||
const activeEditor = this.app.workspace.activeEditor as ActiveEditorLike | undefined;
|
||||
const editMode = viewWithEditModes.editMode ?? viewWithEditModes.sourceMode
|
||||
?? activeEditor?.editMode;
|
||||
|
||||
// @ts-ignore
|
||||
const editMode = view.editMode ?? view.sourceMode ?? this.app.workspace.activeEditor?.editMode;
|
||||
if (!editMode) { return; }
|
||||
|
||||
const { clipboardManager } = editMode;
|
||||
const clipboardProto = Object.getPrototypeOf(clipboardManager) as ClipboardManagerLike;
|
||||
// @ts-ignore
|
||||
const originalHandleDragOver = editMode.clipboardManager.constructor.prototype.handleDragOver;
|
||||
|
||||
const originalHandleDragOver =
|
||||
clipboardProto.handleDragOver as unknown as ClipboardManagerLike['handleDragOver'];
|
||||
const originalHandleDrop =
|
||||
clipboardProto.handleDrop as unknown as ClipboardManagerLike['handleDrop'];
|
||||
const folderNotePlugin = this;
|
||||
clipboardProto.handleDragOver = function (evt: DragEvent, ...args: unknown[]): void {
|
||||
const { dragManager } = (this as ClipboardManagerLike).app;
|
||||
const draggable = dragManager?.draggable;
|
||||
|
||||
if (draggable?.file instanceof TFolder) {
|
||||
const folderNote = getFolderNote(folderNotePlugin, draggable.file.path);
|
||||
if (folderNote) {
|
||||
dragManager.setAction(
|
||||
window.i18next.t('interface.drag-and-drop.insert-link-here'),
|
||||
);
|
||||
return;
|
||||
}
|
||||
// @ts-ignore
|
||||
editMode.clipboardManager.constructor.prototype.handleDragOver = function (evt, ...args) {
|
||||
const { draggable } = this.app.dragManager;
|
||||
if (draggable && draggable.file instanceof TFolder && getFolderNote(this, draggable.file.path)) {
|
||||
this.app.dragManager.setAction(window.i18next.t('interface.drag-and-drop.insert-link-here'));
|
||||
} else {
|
||||
originalHandleDragOver.call(this, evt, ...args);
|
||||
}
|
||||
|
||||
return originalHandleDragOver.call(this, evt, ...args);
|
||||
};
|
||||
|
||||
clipboardProto.handleDrop = function (evt: DragEvent, ...args: unknown[]): void {
|
||||
const { dragManager } = (this as ClipboardManagerLike).app;
|
||||
const draggable = dragManager?.draggable;
|
||||
|
||||
if (draggable?.file instanceof TFolder) {
|
||||
const folderNote = getFolderNote(folderNotePlugin, draggable.file.path);
|
||||
if (folderNote) {
|
||||
// @ts-ignore
|
||||
const originalHandleDrop = editMode.clipboardManager.constructor.prototype.handleDrop;
|
||||
// @ts-ignore
|
||||
editMode.clipboardManager.constructor.prototype.handleDrop = function (evt, ...args) {
|
||||
const { draggable } = this.app.dragManager;
|
||||
if (draggable && draggable.file instanceof TFolder && getFolderNote(this, draggable.file.path)) {
|
||||
const folderNote = getFolderNote(this, draggable.file.path);
|
||||
if (draggable?.type === 'folder' && draggable.file instanceof TFolder && folderNote) {
|
||||
draggable.file = folderNote;
|
||||
draggable.type = 'file';
|
||||
}
|
||||
}
|
||||
|
||||
return originalHandleDrop.call(this, evt, ...args);
|
||||
};
|
||||
|
||||
if (this.settings.fvGlobalSettings.autoUpdateLinks) {
|
||||
this.fvIndexDB.init(false);
|
||||
}
|
||||
}
|
||||
|
||||
handleVaultChange(): void {
|
||||
if (!this.settings.fvGlobalSettings.autoUpdateLinks) return;
|
||||
const DEBOUNCE_DELAY = 2000;
|
||||
debounce(() => {
|
||||
void updateAllOverviews(this);
|
||||
}, DEBOUNCE_DELAY, true)();
|
||||
}
|
||||
|
||||
handleFileExplorerClick(evt: MouseEvent): void {
|
||||
const target = evt.target as HTMLElement;
|
||||
if (evt.shiftKey) return;
|
||||
if (this.isMobileClickDisabled()) return;
|
||||
|
||||
const { folderTitleEl, onlyClickedOnFolderTitle } = this.getFolderTitleInfo(target);
|
||||
if (!folderTitleEl) return;
|
||||
if (this.shouldIgnoreClickByWhitespaceOrCollapse(target, onlyClickedOnFolderTitle)) return;
|
||||
|
||||
const folderPath = this.getValidFolderPath(folderTitleEl);
|
||||
if (!folderPath) return;
|
||||
|
||||
const usedCtrl = this.isCtrlUsed(evt);
|
||||
const folderNote = getFolderNote(this, folderPath);
|
||||
|
||||
if (!folderNote && this.shouldCreateNote(evt, usedCtrl)) {
|
||||
this.createNoteAndMark(folderPath);
|
||||
return;
|
||||
}
|
||||
if (!(folderNote instanceof TFile)) return;
|
||||
if (!this.shouldOpenNote(usedCtrl, evt)) return;
|
||||
|
||||
if (!this.settings.enableCollapsing || usedCtrl) {
|
||||
evt.preventDefault();
|
||||
evt.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
void openFolderNote(this, folderNote, evt);
|
||||
}
|
||||
|
||||
private isMobileClickDisabled(): boolean {
|
||||
return Platform.isMobile && this.settings.disableOpenFolderNoteOnClick;
|
||||
}
|
||||
|
||||
private getFolderTitleInfo(target: HTMLElement): {
|
||||
folderTitleEl: HTMLElement | null;
|
||||
onlyClickedOnFolderTitle: boolean;
|
||||
} {
|
||||
const folderTitleEl = target.closest('.nav-folder-title');
|
||||
const onlyClickedOnFolderTitle = !!target.closest('.nav-folder-title-content');
|
||||
return {
|
||||
folderTitleEl: folderTitleEl instanceof HTMLElement ? folderTitleEl : null,
|
||||
onlyClickedOnFolderTitle,
|
||||
};
|
||||
}
|
||||
|
||||
private shouldIgnoreClickByWhitespaceOrCollapse(
|
||||
target: HTMLElement,
|
||||
onlyClickedOnFolderTitle: boolean,
|
||||
): boolean {
|
||||
if (!this.settings.stopWhitespaceCollapsing && !onlyClickedOnFolderTitle) return true;
|
||||
if (target.closest('.collapse-icon')) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private getValidFolderPath(folderTitleEl: HTMLElement): string | null {
|
||||
const folderPath = folderTitleEl.getAttribute('data-path');
|
||||
if (!folderPath) return null;
|
||||
const excludedFolder = getExcludedFolder(this, folderPath, true);
|
||||
if (excludedFolder?.disableFolderNote) return null;
|
||||
return folderPath;
|
||||
}
|
||||
|
||||
private isCtrlUsed(evt: MouseEvent): boolean {
|
||||
return Platform.isMacOS ? evt.metaKey : evt.ctrlKey;
|
||||
}
|
||||
|
||||
private shouldCreateNote(evt: MouseEvent, usedCtrl: boolean): boolean {
|
||||
const isTabMod = Keymap.isModEvent(evt) === 'tab';
|
||||
if (!(evt.altKey || isTabMod)) return false;
|
||||
return (this.settings.altKey && evt.altKey) || (usedCtrl && this.settings.ctrlKey);
|
||||
}
|
||||
|
||||
private createNoteAndMark(folderPath: string): void {
|
||||
void createFolderNote(this, folderPath, true, undefined, true);
|
||||
void addCSSClassToFileExplorerEl(folderPath, 'has-folder-note', false, this);
|
||||
void removeCSSClassFromFileExplorerEL(folderPath, 'has-not-folder-note', false, this);
|
||||
}
|
||||
|
||||
private shouldOpenNote(usedCtrl: boolean, evt: MouseEvent): boolean {
|
||||
if (this.settings.openWithCtrl && !usedCtrl) return false;
|
||||
if (this.settings.openWithAlt && !evt.altKey) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
handleOverviewBlock(source: string, el: HTMLElement, ctx: MarkdownPostProcessorContext): void {
|
||||
handleOverviewBlock(source: string, el: HTMLElement, ctx: MarkdownPostProcessorContext) {
|
||||
const observer = new MutationObserver(() => {
|
||||
const editButton = el.parentElement?.childNodes.item(1);
|
||||
if (editButton) {
|
||||
|
|
@ -445,14 +199,7 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
e.stopImmediatePropagation();
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
new FolderOverviewSettings(
|
||||
this.app,
|
||||
this,
|
||||
parseYaml(source) as defaultOverviewSettings,
|
||||
ctx,
|
||||
el,
|
||||
this.settings.defaultOverview,
|
||||
).open();
|
||||
new FolderOverviewSettings(this.app, this, parseYaml(source), ctx, el, this.settings.defaultOverview).open();
|
||||
}, { capture: true });
|
||||
}
|
||||
});
|
||||
|
|
@ -464,35 +211,21 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
|
||||
try {
|
||||
if (this.app.workspace.layoutReady) {
|
||||
const { defaultOverview } = this.settings;
|
||||
const folderOverview = new FolderOverview(
|
||||
this,
|
||||
ctx,
|
||||
source,
|
||||
el,
|
||||
defaultOverview,
|
||||
);
|
||||
void folderOverview.create(this, el, ctx);
|
||||
const folderOverview = new FolderOverview(this, ctx, source, el, this.settings.defaultOverview);
|
||||
folderOverview.create(this, parseYaml(source), el, ctx);
|
||||
} else {
|
||||
this.app.workspace.onLayoutReady(() => {
|
||||
const folderOverview = new FolderOverview(
|
||||
this,
|
||||
ctx,
|
||||
source,
|
||||
el,
|
||||
this.settings.defaultOverview,
|
||||
);
|
||||
void folderOverview.create(this, el, ctx);
|
||||
const folderOverview = new FolderOverview(this, ctx, source, el, this.settings.defaultOverview);
|
||||
folderOverview.create(this, parseYaml(source), el, ctx);
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line max-len
|
||||
new Notice('Error creating folder overview (folder notes plugin) - check console for more details');
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
async activateOverviewView(): Promise<void> {
|
||||
async activateOverviewView() {
|
||||
const { workspace } = this.app;
|
||||
|
||||
let leaf: WorkspaceLeaf | null = null;
|
||||
|
|
@ -506,69 +239,49 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
}
|
||||
|
||||
if (!leaf) return;
|
||||
void workspace.revealLeaf(leaf);
|
||||
workspace.revealLeaf(leaf);
|
||||
}
|
||||
|
||||
updateOverviewView: typeof updateOverviewView = updateOverviewView;
|
||||
updateViewDropdown: typeof updateViewDropdown = updateViewDropdown;
|
||||
updateOverviewView = updateOverviewView;
|
||||
updateViewDropdown = updateViewDropdown;
|
||||
|
||||
isEmptyFolderNoteFolder(folder: TFolder): boolean {
|
||||
let attachmentFolderPath = this.app.vault.getConfig('attachmentFolderPath') as string;
|
||||
const attachmentFolderPath = this.app.vault.getConfig('attachmentFolderPath') as string;
|
||||
const cleanAttachmentFolderPath = attachmentFolderPath?.replace('./', '') || '';
|
||||
const attachmentsAreInRootFolder = attachmentFolderPath === './'
|
||||
|| attachmentFolderPath === '';
|
||||
const attachmentsAreInRootFolder = attachmentFolderPath === './' || attachmentFolderPath === '';
|
||||
const threshold = this.settings.storageLocation === 'insideFolder' ? 1 : 0;
|
||||
if (folder.children.length === 0) {
|
||||
void addCSSClassToFileExplorerEl(folder.path, 'fn-empty-folder', false, this);
|
||||
addCSSClassToTitleEL(folder.path, 'fn-empty-folder', this);
|
||||
}
|
||||
attachmentFolderPath = `${folder.path}/${cleanAttachmentFolderPath}`;
|
||||
|
||||
if (folder.children.length === threshold) {
|
||||
void addCSSClassToFileExplorerEl(folder.path, 'fn-empty-folder', false, this);
|
||||
return true;
|
||||
} else if (folder.children.length > threshold) {
|
||||
if (attachmentsAreInRootFolder) {
|
||||
return false;
|
||||
} else if (
|
||||
this.app.vault.getAbstractFileByPath(attachmentFolderPath) instanceof TFolder
|
||||
) {
|
||||
const attachmentFolder = this.app.vault.getAbstractFileByPath(attachmentFolderPath);
|
||||
if (
|
||||
attachmentFolder instanceof TFolder &&
|
||||
folder.children.length <= threshold + 1
|
||||
) {
|
||||
void addCSSClassToFileExplorerEl(folder.path, 'fn-empty-folder', false, this);
|
||||
void addCSSClassToFileExplorerEl(
|
||||
folder.path, 'fn-has-attachment-folder',
|
||||
false, this,
|
||||
);
|
||||
void addCSSClassToFileExplorerEl(
|
||||
folder.path, 'fn-has-attachment-folder',
|
||||
true, this,
|
||||
);
|
||||
} else if (this.settings.ignoreAttachmentFolder && this.app.vault.getAbstractFileByPath(`${folder.path}/${cleanAttachmentFolderPath}`)) {
|
||||
const folderPath = `${folder.path}/${cleanAttachmentFolderPath}`;
|
||||
const attachmentFolder = this.app.vault.getAbstractFileByPath(folderPath);
|
||||
if (attachmentFolder instanceof TFolder && folder.children.length <= threshold + 1) {
|
||||
if (!folder.collapsed) {
|
||||
getEl(folder.path, this)?.click();
|
||||
}
|
||||
}
|
||||
return folder.children.length <= threshold + 1;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
async changeFolderNameInExplorer(
|
||||
folder: TFolder,
|
||||
newName: string | null | undefined,
|
||||
waitForCreate = false,
|
||||
count = 0,
|
||||
): Promise<void> {
|
||||
const MAX_RETRY_COUNT = 5;
|
||||
const RETRY_DELAY_MS = 500;
|
||||
if (!newName) newName = folder.name;
|
||||
let fileExplorerItem = getFileExplorerElement(folder.path, this);
|
||||
async changeName(folder: TFolder, name: string | null | undefined, replacePath: boolean, waitForCreate = false, count = 0) {
|
||||
if (!name) name = folder.name;
|
||||
let fileExplorerItem = getEl(folder.path, this);
|
||||
if (!fileExplorerItem) {
|
||||
if (waitForCreate && count < MAX_RETRY_COUNT) {
|
||||
await new Promise<void>((resolve) => window.setTimeout(resolve, RETRY_DELAY_MS));
|
||||
void this.changeFolderNameInExplorer(folder, newName, waitForCreate, count + 1);
|
||||
if (waitForCreate && count < 5) {
|
||||
await new Promise((r) => setTimeout(r, 500));
|
||||
this.changeName(folder, name, replacePath, waitForCreate, count + 1);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
|
|
@ -577,32 +290,20 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
fileExplorerItem = fileExplorerItem?.querySelector('div.nav-folder-title-content');
|
||||
if (!fileExplorerItem) { return; }
|
||||
if (this.settings.frontMatterTitle.explorer && this.settings.frontMatterTitle.enabled) {
|
||||
(fileExplorerItem).innerText = newName;
|
||||
(fileExplorerItem).setAttribute('old-name', folder.name);
|
||||
fileExplorerItem.innerText = name;
|
||||
fileExplorerItem.setAttribute('old-name', folder.name);
|
||||
} else {
|
||||
(fileExplorerItem).innerText = folder.name;
|
||||
(fileExplorerItem).removeAttribute('old-name');
|
||||
fileExplorerItem.innerText = folder.name;
|
||||
fileExplorerItem.removeAttribute('old-name');
|
||||
}
|
||||
if (replacePath) {
|
||||
this.updateBreadcrumbs();
|
||||
}
|
||||
}
|
||||
|
||||
async changeFolderNameInPath(
|
||||
folder: TFolder,
|
||||
newName: string | null | undefined,
|
||||
breadcrumb: HTMLElement,
|
||||
): Promise<void> {
|
||||
if (!newName) newName = folder.name;
|
||||
|
||||
breadcrumb.textContent = folder.newName || folder.name;
|
||||
breadcrumb.setAttribute('old-name', folder.name);
|
||||
breadcrumb.setAttribute('data-path', folder.path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates all folder names in the path above the note editor
|
||||
*/
|
||||
updateAllBreadcrumbs(remove?: boolean): void {
|
||||
updateBreadcrumbs(remove?: boolean) {
|
||||
if (!this.settings.frontMatterTitle.path && !remove) { return; }
|
||||
const viewHeaderItems = activeDocument.querySelectorAll('span.view-header-breadcrumb');
|
||||
const viewHeaderItems = document.querySelectorAll('span.view-header-breadcrumb');
|
||||
const files = this.app.vault.getAllLoadedFiles().filter((file) => file instanceof TFolder);
|
||||
viewHeaderItems.forEach((item) => {
|
||||
if (!item.hasAttribute('data-path')) { return; }
|
||||
|
|
@ -620,20 +321,29 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
});
|
||||
}
|
||||
|
||||
onunload(): void {
|
||||
reloadHandlers() {
|
||||
document.querySelectorAll('div.nav-folder-title-content')
|
||||
.forEach((element: HTMLElement) => {
|
||||
if (element.onclick) return;
|
||||
element.onclick = (event: MouseEvent) => handleFolderClick(event, this);
|
||||
});
|
||||
}
|
||||
|
||||
onunload() {
|
||||
console.log('unloading folder notes plugin');
|
||||
unregisterFileExplorerObserver();
|
||||
activeDocument.body.classList.remove('folder-notes-plugin');
|
||||
activeDocument.body.classList.remove('folder-note-underline');
|
||||
activeDocument.body.classList.remove('hide-folder-note');
|
||||
activeDocument.body.classList.remove('fn-whitespace-stop-collapsing');
|
||||
removeActiveFolder(this);
|
||||
document.body.classList.remove('folder-notes-plugin');
|
||||
document.body.classList.remove('folder-note-underline');
|
||||
document.body.classList.remove('hide-folder-note');
|
||||
document.body.classList.remove('fn-whitespace-stop-collapsing');
|
||||
if (this.activeFolderDom) { this.activeFolderDom.removeClass('is-active'); }
|
||||
if (this.fmtpHandler) {
|
||||
this.fmtpHandler.deleteEvent();
|
||||
}
|
||||
}
|
||||
|
||||
async loadSettings(): Promise<void> {
|
||||
const data = await this.loadData() as LegacySettingsData | null;
|
||||
async loadSettings() {
|
||||
const data = await this.loadData();
|
||||
if (data) {
|
||||
if (data.allowWhitespaceCollapsing === true) {
|
||||
data.stopWhitespaceCollapsing = false;
|
||||
|
|
@ -650,18 +360,16 @@ export default class FolderNotesPlugin extends Plugin {
|
|||
}
|
||||
|
||||
if (!data) { return; }
|
||||
const overview = data.defaultOverview;
|
||||
const overview = (data as any).defaultOverview;
|
||||
if (!overview) { return; }
|
||||
this.settings.defaultOverview = Object.assign(
|
||||
{}, DEFAULT_SETTINGS.defaultOverview, overview,
|
||||
);
|
||||
this.settings.defaultOverview = Object.assign({}, DEFAULT_SETTINGS.defaultOverview, overview);
|
||||
}
|
||||
|
||||
async saveSettings(reloadStyles?: boolean): Promise<void> {
|
||||
async saveSettings(reloadStyles?: boolean) {
|
||||
await this.saveData(this.settings);
|
||||
// cleanup any css if we need too
|
||||
if ((!this.settingsOpened || reloadStyles === true) && reloadStyles !== false) {
|
||||
refreshAllFolderStyles(true, this);
|
||||
loadFileClasses(true, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Modal, Setting, Notice, type App, type SettingTab } from 'obsidian';
|
||||
import type FolderNotesPlugin from '../main';
|
||||
import type { ListComponent } from 'src/functions/ListComponent';
|
||||
import { App, Modal, Setting, Notice, SettingTab } from 'obsidian';
|
||||
import FolderNotesPlugin from '../main';
|
||||
import { ListComponent } from 'src/functions/ListComponent';
|
||||
|
||||
export default class AddSupportedFileModal extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
|
|
@ -16,8 +16,7 @@ export default class AddSupportedFileModal extends Modal {
|
|||
this.list = list;
|
||||
this.settingsTab = settingsTab;
|
||||
}
|
||||
|
||||
onOpen(): void {
|
||||
onOpen() {
|
||||
const { contentEl } = this;
|
||||
// close when user presses enter
|
||||
contentEl.addEventListener('keydown', (e) => {
|
||||
|
|
@ -35,10 +34,10 @@ export default class AddSupportedFileModal extends Modal {
|
|||
if (value.trim() !== '') {
|
||||
this.name = value.trim();
|
||||
}
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
onClose(): void {
|
||||
async onClose() {
|
||||
if (this.name.toLocaleLowerCase() === 'markdown') {
|
||||
this.name = 'md';
|
||||
}
|
||||
|
|
@ -47,16 +46,13 @@ export default class AddSupportedFileModal extends Modal {
|
|||
contentEl.empty();
|
||||
this.settingsTab.display();
|
||||
} else if (this.plugin.settings.supportedFileTypes.includes(this.name.toLowerCase())) {
|
||||
new Notice('This extension is already supported');
|
||||
return;
|
||||
return new Notice('This extension is already supported');
|
||||
} else {
|
||||
// Run async operations without returning a Promise from onClose
|
||||
void (async (): Promise<void> => {
|
||||
await this.list.addValue(this.name.toLowerCase());
|
||||
this.settingsTab.display();
|
||||
await this.plugin.saveSettings();
|
||||
contentEl.empty();
|
||||
})();
|
||||
// @ts-ignore
|
||||
await this.list.addValue(this.name.toLowerCase());
|
||||
this.settingsTab.display();
|
||||
this.plugin.saveSettings();
|
||||
contentEl.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { FuzzySuggestModal, type TFile } from 'obsidian';
|
||||
import type FolderNotesPlugin from 'src/main';
|
||||
import { FuzzySuggestModal, TFile } from 'obsidian';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
import { createFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
export class AskForExtensionModal extends FuzzySuggestModal<string> {
|
||||
plugin: FolderNotesPlugin;
|
||||
|
|
@ -8,14 +8,7 @@ export class AskForExtensionModal extends FuzzySuggestModal<string> {
|
|||
openFile: boolean;
|
||||
useModal: boolean | undefined;
|
||||
existingNote: TFile | undefined;
|
||||
constructor(
|
||||
plugin: FolderNotesPlugin,
|
||||
folderPath: string,
|
||||
openFile: boolean,
|
||||
extension: string,
|
||||
useModal?: boolean,
|
||||
existingNote?: TFile,
|
||||
) {
|
||||
constructor(plugin: FolderNotesPlugin, folderPath: string, openFile: boolean, extension: string, useModal?: boolean, existingNote?: TFile) {
|
||||
super(plugin.app);
|
||||
this.plugin = plugin;
|
||||
this.folderPath = folderPath;
|
||||
|
|
@ -23,30 +16,19 @@ export class AskForExtensionModal extends FuzzySuggestModal<string> {
|
|||
this.openFile = openFile;
|
||||
this.useModal = useModal;
|
||||
this.existingNote = existingNote;
|
||||
plugin.askModalCurrentlyOpen = true;
|
||||
}
|
||||
|
||||
getItems(): string[] {
|
||||
return this.plugin.settings.supportedFileTypes.filter(
|
||||
(item) => item.toLowerCase() !== '.ask',
|
||||
);
|
||||
return this.plugin.settings.supportedFileTypes.filter((item) => item.toLowerCase() !== '.ask');
|
||||
}
|
||||
|
||||
getItemText(item: string): string {
|
||||
return item;
|
||||
}
|
||||
|
||||
onChooseItem(item: string, _evt: MouseEvent | KeyboardEvent): void {
|
||||
this.plugin.askModalCurrentlyOpen = false;
|
||||
onChooseItem(item: string, evt: MouseEvent | KeyboardEvent) {
|
||||
this.extension = '.' + item;
|
||||
void createFolderNote(
|
||||
this.plugin,
|
||||
this.folderPath,
|
||||
this.openFile,
|
||||
this.extension,
|
||||
this.useModal,
|
||||
this.existingNote,
|
||||
);
|
||||
createFolderNote(this.plugin, this.folderPath, this.openFile, this.extension, this.useModal, this.existingNote);
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Modal, Platform, type App, type TFile } from 'obsidian';
|
||||
import type FolderNotesPlugin from '../main';
|
||||
import { App, Modal, TFile, Platform } from 'obsidian';
|
||||
import FolderNotesPlugin from '../main';
|
||||
import { deleteFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
export default class DeleteConfirmationModal extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
|
|
@ -11,25 +11,21 @@ export default class DeleteConfirmationModal extends Modal {
|
|||
this.app = app;
|
||||
this.file = file;
|
||||
}
|
||||
onOpen(): void {
|
||||
onOpen() {
|
||||
const { contentEl, plugin } = this;
|
||||
const modalTitle = contentEl.createDiv({ cls: 'fn-modal-title' });
|
||||
const modalContent = contentEl.createDiv({ cls: 'fn-modal-content' });
|
||||
modalTitle.createEl('h2', { text: 'Delete folder note' });
|
||||
// eslint-disable-next-line max-len
|
||||
modalContent.createEl('p', { text: `Are you sure you want to delete the folder note '${this.file.name}' ?` });
|
||||
switch (plugin.settings.deleteFilesAction) {
|
||||
case 'trash':
|
||||
modalContent.createEl('p', { text: 'It will be moved to your system trash.' });
|
||||
break;
|
||||
case 'obsidianTrash':
|
||||
// eslint-disable-next-line max-len
|
||||
modalContent.createEl('p', { text: 'It will be moved to your Obsidian trash, which is located in the ".trash" hidden folder in your vault.' });
|
||||
break;
|
||||
case 'delete':
|
||||
modalContent
|
||||
.createEl('p', { text: 'It will be permanently deleted.' })
|
||||
.setCssStyles({ color: 'red' });
|
||||
modalContent.createEl('p', { text: 'It will be permanently deleted.' }).setCssStyles({ color: 'red' });
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -50,10 +46,7 @@ export default class DeleteConfirmationModal extends Modal {
|
|||
plugin.saveSettings();
|
||||
});
|
||||
} else {
|
||||
const confirmButton = buttonContainer.createEl('button', {
|
||||
text: 'Delete and don\'t ask again',
|
||||
cls: 'mod-destructive',
|
||||
});
|
||||
const confirmButton = buttonContainer.createEl('button', { text: 'Delete and don\'t ask again', cls: 'mod-destructive' });
|
||||
confirmButton.addEventListener('click', async () => {
|
||||
plugin.settings.showDeleteConfirmation = false;
|
||||
plugin.saveSettings();
|
||||
|
|
@ -62,25 +55,19 @@ export default class DeleteConfirmationModal extends Modal {
|
|||
});
|
||||
}
|
||||
|
||||
const deleteButton = buttonContainer.createEl('button', {
|
||||
text: 'Delete',
|
||||
cls: 'mod-warning',
|
||||
});
|
||||
const deleteButton = buttonContainer.createEl('button', { text: 'Delete', cls: 'mod-warning' });
|
||||
deleteButton.addEventListener('click', async () => {
|
||||
this.close();
|
||||
deleteFolderNote(plugin, this.file, false);
|
||||
});
|
||||
deleteButton.focus();
|
||||
|
||||
const cancelButton = buttonContainer.createEl('button', {
|
||||
text: 'Cancel',
|
||||
cls: 'mod-cancel',
|
||||
});
|
||||
const cancelButton = buttonContainer.createEl('button', { text: 'Cancel', cls: 'mod-cancel' });
|
||||
cancelButton.addEventListener('click', async () => {
|
||||
this.close();
|
||||
});
|
||||
}
|
||||
onClose(): void {
|
||||
onClose() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,5 @@
|
|||
import {
|
||||
Modal,
|
||||
Setting,
|
||||
Platform,
|
||||
type App,
|
||||
type TFile,
|
||||
type TFolder,
|
||||
type TAbstractFile,
|
||||
} from 'obsidian';
|
||||
import type FolderNotesPlugin from '../main';
|
||||
import { App, Modal, Setting, TFile, Platform, TFolder, TAbstractFile } from 'obsidian';
|
||||
import FolderNotesPlugin from '../main';
|
||||
import { turnIntoFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
export default class ExistingFolderNoteModal extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
|
|
@ -15,13 +7,7 @@ export default class ExistingFolderNoteModal extends Modal {
|
|||
file: TFile;
|
||||
folder: TFolder;
|
||||
folderNote: TAbstractFile;
|
||||
constructor(
|
||||
app: App,
|
||||
plugin: FolderNotesPlugin,
|
||||
file: TFile,
|
||||
folder: TFolder,
|
||||
folderNote: TAbstractFile,
|
||||
) {
|
||||
constructor(app: App, plugin: FolderNotesPlugin, file: TFile, folder: TFolder, folderNote: TAbstractFile) {
|
||||
super(app);
|
||||
this.plugin = plugin;
|
||||
this.app = app;
|
||||
|
|
@ -29,26 +15,22 @@ export default class ExistingFolderNoteModal extends Modal {
|
|||
this.folder = folder;
|
||||
this.folderNote = folderNote;
|
||||
}
|
||||
onOpen(): void {
|
||||
onOpen() {
|
||||
const { contentEl } = this;
|
||||
contentEl.createEl('h2', { text: 'A folder note for this folder already exists' });
|
||||
const setting = new Setting(contentEl);
|
||||
// eslint-disable-next-line max-len
|
||||
setting.infoEl.createEl('p', { text: 'Are you sure you want to turn the note into a folder note and rename the existing folder note?' });
|
||||
|
||||
setting.infoEl.parentElement?.classList.add('fn-delete-confirmation-modal');
|
||||
|
||||
// Create a container for the buttons and the checkbox
|
||||
// eslint-disable-next-line max-len
|
||||
const buttonContainer = setting.infoEl.createEl('div', { cls: 'fn-delete-confirmation-modal-buttons' });
|
||||
if (Platform.isMobileApp) {
|
||||
const confirmButton = buttonContainer.createEl('button', {
|
||||
text: 'Rename and don\'t ask again',
|
||||
});
|
||||
const confirmButton = buttonContainer.createEl('button', { text: 'Rename and don\'t ask again' });
|
||||
confirmButton.classList.add('mod-warning', 'fn-confirmation-modal-button');
|
||||
confirmButton.addEventListener('click', () => {
|
||||
confirmButton.addEventListener('click', async () => {
|
||||
this.plugin.settings.showRenameConfirmation = false;
|
||||
void this.plugin.saveSettings();
|
||||
this.plugin.saveSettings();
|
||||
this.close();
|
||||
turnIntoFolderNote(this.plugin, this.file, this.folder, this.folderNote, true);
|
||||
});
|
||||
|
|
@ -69,19 +51,19 @@ export default class ExistingFolderNoteModal extends Modal {
|
|||
}
|
||||
const button = buttonContainer.createEl('button', { text: 'Rename' });
|
||||
button.classList.add('mod-warning', 'fn-confirmation-modal-button');
|
||||
button.addEventListener('click', () => {
|
||||
void this.plugin.saveSettings();
|
||||
button.addEventListener('click', async () => {
|
||||
this.plugin.saveSettings();
|
||||
this.close();
|
||||
turnIntoFolderNote(this.plugin, this.file, this.folder, this.folderNote, true);
|
||||
});
|
||||
button.focus();
|
||||
const cancelButton = buttonContainer.createEl('button', { text: 'Cancel' });
|
||||
cancelButton.addEventListener('click', () => {
|
||||
cancelButton.addEventListener('click', async () => {
|
||||
this.close();
|
||||
});
|
||||
|
||||
}
|
||||
onClose(): void {
|
||||
onClose() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Modal, Setting, type App, type TFolder } from 'obsidian';
|
||||
import type FolderNotesPlugin from '../main';
|
||||
import { App, Modal, Setting, TFolder } from 'obsidian';
|
||||
import FolderNotesPlugin from '../main';
|
||||
export default class FolderNameModal extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
app: App;
|
||||
|
|
@ -10,8 +10,7 @@ export default class FolderNameModal extends Modal {
|
|||
this.app = app;
|
||||
this.folder = folder;
|
||||
}
|
||||
|
||||
onOpen(): void {
|
||||
onOpen() {
|
||||
const { contentEl } = this;
|
||||
// close when user presses enter
|
||||
contentEl.addEventListener('keydown', (e) => {
|
||||
|
|
@ -27,25 +26,14 @@ export default class FolderNameModal extends Modal {
|
|||
.setValue(this.folder.name.replace(this.plugin.settings.folderNoteType, ''))
|
||||
.onChange(async (value) => {
|
||||
if (value.trim() !== '') {
|
||||
const parentPath = this.folder.path.slice(
|
||||
0,
|
||||
this.folder.path.lastIndexOf('/') + 1,
|
||||
);
|
||||
const newFolderPath = parentPath + value.trim();
|
||||
if (
|
||||
!this.app.vault.getAbstractFileByPath(newFolderPath)
|
||||
) {
|
||||
this.plugin.app.fileManager.renameFile(
|
||||
this.folder,
|
||||
newFolderPath,
|
||||
);
|
||||
if (!this.app.vault.getAbstractFileByPath(this.folder.path.slice(0, this.folder.path.lastIndexOf('/') + 1) + value.trim())) {
|
||||
this.plugin.app.fileManager.renameFile(this.folder, this.folder.path.slice(0, this.folder.path.lastIndexOf('/') + 1) + value.trim());
|
||||
}
|
||||
}
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
onClose(): void {
|
||||
onClose() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Modal, type App, type TFolder } from 'obsidian';
|
||||
import type FolderNotesPlugin from '../main';
|
||||
import { App, Modal, TFolder } from 'obsidian';
|
||||
import FolderNotesPlugin from '../main';
|
||||
export default class NewFolderNameModal extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
app: App;
|
||||
|
|
@ -10,8 +10,7 @@ export default class NewFolderNameModal extends Modal {
|
|||
this.app = app;
|
||||
this.folder = folder;
|
||||
}
|
||||
|
||||
onOpen(): void {
|
||||
onOpen() {
|
||||
const { contentEl } = this;
|
||||
|
||||
contentEl.addEventListener('keydown', (e) => {
|
||||
|
|
@ -37,7 +36,7 @@ export default class NewFolderNameModal extends Modal {
|
|||
},
|
||||
});
|
||||
|
||||
textarea.addEventListener('focus', function () {
|
||||
textarea.addEventListener('focus', function() {
|
||||
this.select();
|
||||
});
|
||||
|
||||
|
|
@ -50,32 +49,23 @@ export default class NewFolderNameModal extends Modal {
|
|||
this.close();
|
||||
});
|
||||
|
||||
const cancelButton = buttonContainer.createEl('button', {
|
||||
text: 'Cancel',
|
||||
cls: 'mod-cancel',
|
||||
});
|
||||
const cancelButton = buttonContainer.createEl('button', { text: 'Cancel', cls: 'mod-cancel' });
|
||||
cancelButton.addEventListener('click', () => {
|
||||
this.close();
|
||||
});
|
||||
}
|
||||
|
||||
onClose(): void {
|
||||
onClose() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
|
||||
saveFolderName(): void {
|
||||
saveFolderName() {
|
||||
const textarea = this.contentEl.querySelector('textarea');
|
||||
if (textarea) {
|
||||
const newName = textarea.value.trim();
|
||||
if (newName.trim() !== '') {
|
||||
const folderBasePath = this.folder.path.slice(
|
||||
0,
|
||||
this.folder.path.lastIndexOf('/') + 1,
|
||||
);
|
||||
const newFolderPath = folderBasePath + newName.trim();
|
||||
if (!this.app.vault.getAbstractFileByPath(newFolderPath)) {
|
||||
this.plugin.app.fileManager.renameFile(this.folder, newFolderPath);
|
||||
if (!this.app.vault.getAbstractFileByPath(this.folder.path.slice(0, this.folder.path.lastIndexOf('/') + 1) + newName.trim())) {
|
||||
this.plugin.app.fileManager.renameFile(this.folder, this.folder.path.slice(0, this.folder.path.lastIndexOf('/') + 1) + newName.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit f047859cc9a7f1c04ad35ecdc440a31a300bc6c2
|
||||
Subproject commit e512c581db4234fc643f9400f39eec3f51a627c2
|
||||
|
|
@ -1,17 +1,14 @@
|
|||
import {
|
||||
addExcludeFolderListItem,
|
||||
addExcludedFolder,
|
||||
} from 'src/ExcludeFolders/functions/folderFunctions';
|
||||
import { addExcludeFolderListItem, addExcludedFolder } from 'src/ExcludeFolders/functions/folderFunctions';
|
||||
import { ExcludedFolder } from 'src/ExcludeFolders/ExcludeFolder';
|
||||
import { addExcludePatternListItem } from 'src/ExcludeFolders/functions/patternFunctions';
|
||||
import { Setting } from 'obsidian';
|
||||
import type { SettingsTab } from './SettingsTab';
|
||||
import { SettingsTab } from './SettingsTab';
|
||||
import ExcludedFolderSettings from 'src/ExcludeFolders/modals/ExcludeFolderSettings';
|
||||
import PatternSettings from 'src/ExcludeFolders/modals/PatternSettings';
|
||||
import WhitelistedFoldersSettings from 'src/ExcludeFolders/modals/WhitelistedFoldersSettings';
|
||||
// import ExcludedFoldersWhitelist from 'src/ExcludeFolders/modals/WhitelistModal';
|
||||
|
||||
export async function renderExcludeFolders(settingsTab: SettingsTab): Promise<void> {
|
||||
export async function renderExcludeFolders(settingsTab: SettingsTab) {
|
||||
const containerEl = settingsTab.settingsPage;
|
||||
const manageExcluded = new Setting(containerEl)
|
||||
.setHeading()
|
||||
|
|
@ -28,12 +25,9 @@ export async function renderExcludeFolders(settingsTab: SettingsTab): Promise<vo
|
|||
'Use * after the folder name to exclude folders that start with the folder name.',
|
||||
);
|
||||
manageExcluded.setDesc(desc3);
|
||||
|
||||
manageExcluded.infoEl.appendText('The regexes and wildcards are only for the folder name, not the path.');
|
||||
manageExcluded.infoEl.createEl('br');
|
||||
|
||||
manageExcluded.infoEl.appendText('If you want to switch to a folder path delete the pattern first.');
|
||||
|
||||
manageExcluded.infoEl.style.color = settingsTab.app.vault.getConfig('accentColor') as string || '#7d5bed';
|
||||
|
||||
|
||||
|
|
@ -54,11 +48,7 @@ export async function renderExcludeFolders(settingsTab: SettingsTab): Promise<vo
|
|||
cb.setButtonText('Manage');
|
||||
cb.setCta();
|
||||
cb.onClick(async () => {
|
||||
new ExcludedFolderSettings(
|
||||
settingsTab.app,
|
||||
settingsTab.plugin,
|
||||
settingsTab.plugin.settings.excludeFolderDefaultSettings,
|
||||
).open();
|
||||
new ExcludedFolderSettings(settingsTab.app, settingsTab.plugin, settingsTab.plugin.settings.excludeFolderDefaultSettings).open();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -68,11 +58,7 @@ export async function renderExcludeFolders(settingsTab: SettingsTab): Promise<vo
|
|||
cb.setButtonText('Manage');
|
||||
cb.setCta();
|
||||
cb.onClick(async () => {
|
||||
new PatternSettings(
|
||||
settingsTab.app,
|
||||
settingsTab.plugin,
|
||||
settingsTab.plugin.settings.excludePatternDefaultSettings,
|
||||
).open();
|
||||
new PatternSettings(settingsTab.app, settingsTab.plugin, settingsTab.plugin.settings.excludePatternDefaultSettings).open();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -85,29 +71,18 @@ export async function renderExcludeFolders(settingsTab: SettingsTab): Promise<vo
|
|||
cb.setClass('add-exclude-folder');
|
||||
cb.setTooltip('Add excluded folder');
|
||||
cb.onClick(() => {
|
||||
const excludedFolder = new ExcludedFolder(
|
||||
'',
|
||||
settingsTab.plugin.settings.excludeFolders.length,
|
||||
undefined,
|
||||
settingsTab.plugin,
|
||||
);
|
||||
const excludedFolder = new ExcludedFolder('', settingsTab.plugin.settings.excludeFolders.length, undefined, settingsTab.plugin);
|
||||
addExcludeFolderListItem(settingsTab, containerEl, excludedFolder);
|
||||
addExcludedFolder(settingsTab.plugin, excludedFolder);
|
||||
settingsTab.renderSettingsPage(settingsTab.plugin.settings.settingsTab);
|
||||
settingsTab.display();
|
||||
});
|
||||
});
|
||||
|
||||
settingsTab.plugin.settings.excludeFolders
|
||||
.filter((folder) => !folder.hideInSettings)
|
||||
.sort((a, b) => a.position - b.position)
|
||||
.forEach((excludedFolder) => {
|
||||
if (
|
||||
excludedFolder.string?.trim() !== '' &&
|
||||
excludedFolder.path?.trim() === ''
|
||||
) {
|
||||
addExcludePatternListItem(settingsTab, containerEl, excludedFolder);
|
||||
} else {
|
||||
addExcludeFolderListItem(settingsTab, containerEl, excludedFolder);
|
||||
}
|
||||
});
|
||||
settingsTab.plugin.settings.excludeFolders.filter((folder) => !folder.hideInSettings).sort((a, b) => a.position - b.position).forEach((excludedFolder) => {
|
||||
if (excludedFolder.string?.trim() !== '' && excludedFolder.path?.trim() === '') {
|
||||
addExcludePatternListItem(settingsTab, containerEl, excludedFolder);
|
||||
} else {
|
||||
addExcludeFolderListItem(settingsTab, containerEl, excludedFolder);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
/* eslint-disable max-len */
|
||||
import { Setting } from 'obsidian';
|
||||
import type { SettingsTab } from './SettingsTab';
|
||||
export async function renderFileExplorer(settingsTab: SettingsTab): Promise<void> {
|
||||
import { SettingsTab } from './SettingsTab';
|
||||
export async function renderFileExplorer(settingsTab: SettingsTab) {
|
||||
const containerEl = settingsTab.settingsPage;
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Hide folder note')
|
||||
.setDesc('Hide the folder note file from appearing in the file explorer')
|
||||
.setDesc('Hide the folder note in the file explorer')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.hideFolderNote)
|
||||
|
|
@ -14,61 +13,59 @@ export async function renderFileExplorer(settingsTab: SettingsTab): Promise<void
|
|||
settingsTab.plugin.settings.hideFolderNote = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
if (value) {
|
||||
activeDocument.body.classList.add('hide-folder-note');
|
||||
document.body.classList.add('hide-folder-note');
|
||||
} else {
|
||||
activeDocument.body.classList.remove('hide-folder-note');
|
||||
document.body.classList.remove('hide-folder-note');
|
||||
}
|
||||
settingsTab.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
const setting2 = new Setting(containerEl)
|
||||
.setName('Disable click-to-open folder note on mobile')
|
||||
.setDesc('Prevents folder notes from opening when tapping the folder name or surrounding area on mobile devices. They can now only be opened via the context menu or a command.')
|
||||
.setName('Don\'t open folder notes by clicking on the name (on mobile)')
|
||||
.setDesc('Folder notes don\'t open when clicking on the name of the folder (on mobile)')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.disableOpenFolderNoteOnClick)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.disableOpenFolderNoteOnClick = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
setting2.infoEl.appendText('Requires a restart to take effect');
|
||||
const setting2AccentColor = settingsTab.app.vault.getConfig('accentColor') as string || '#7d5bed';
|
||||
setting2.infoEl.style.color = setting2AccentColor;
|
||||
setting2.infoEl.style.color = settingsTab.app.vault.getConfig('accentColor') as string || '#7d5bed';
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Open folder notes by only clicking directly on the folder name')
|
||||
.setDesc('Only allow folder notes to open when clicking directly on the folder name in the file explorer')
|
||||
.setName('Only open folder notes through the name')
|
||||
.setDesc('Only open folder notes in the file explorer by clicking on the folder name')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(!settingsTab.plugin.settings.stopWhitespaceCollapsing)
|
||||
.onChange(async (value) => {
|
||||
if (!value) {
|
||||
activeDocument.body.classList.add('fn-whitespace-stop-collapsing');
|
||||
document.body.classList.add('fn-whitespace-stop-collapsing');
|
||||
} else {
|
||||
activeDocument.body.classList.remove('fn-whitespace-stop-collapsing');
|
||||
document.body.classList.remove('fn-whitespace-stop-collapsing');
|
||||
}
|
||||
settingsTab.plugin.settings.stopWhitespaceCollapsing = !value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
const disableSetting = new Setting(containerEl);
|
||||
disableSetting.setName('Disable folder collapsing');
|
||||
disableSetting.setDesc('When enabled, folders in the file explorer will only collapse when clicking the collapse icon next to the folder name, not when clicking near a folder name when it has a folder note.');
|
||||
disableSetting.setDesc('Disable the ability to collapse folders by clicking exactly on the folder name');
|
||||
disableSetting.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(!settingsTab.plugin.settings.enableCollapsing)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.enableCollapsing = !value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
disableSetting.infoEl.appendText('Requires a restart to take effect');
|
||||
const accentColor = settingsTab.app.vault.getConfig('accentColor') as string || '#7d5bed';
|
||||
disableSetting.infoEl.style.color = accentColor;
|
||||
disableSetting.infoEl.style.color = settingsTab.app.vault.getConfig('accentColor') as string || '#7d5bed';
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Use submenus')
|
||||
|
|
@ -80,13 +77,13 @@ export async function renderFileExplorer(settingsTab: SettingsTab): Promise<void
|
|||
settingsTab.plugin.settings.useSubmenus = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
if (settingsTab.plugin.settings.frontMatterTitle.enabled) {
|
||||
new Setting(containerEl)
|
||||
.setName('Auto update folder name in the file explorer (front matter title plugin only)')
|
||||
.setDesc('Automatically update the folder name in the file explorer when the front matter title plugin is enabled and the title for a folder note is changed in the front matter. This will not change the file name, only the displayed name in the file explorer.')
|
||||
.setName('Change folder name in the file explorer')
|
||||
.setDesc('Automatically rename a folder name in the file explorer when the folder note is renamed')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.frontMatterTitle.explorer)
|
||||
|
|
@ -94,17 +91,9 @@ export async function renderFileExplorer(settingsTab: SettingsTab): Promise<void
|
|||
settingsTab.plugin.settings.frontMatterTitle.explorer = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.plugin.app.vault.getFiles().forEach((file) => {
|
||||
settingsTab.plugin.fmtpHandler?.fmptUpdateFileName(
|
||||
{
|
||||
id: '',
|
||||
result: false,
|
||||
path: file.path,
|
||||
pathOnly: false,
|
||||
},
|
||||
false,
|
||||
);
|
||||
settingsTab.plugin.fmtpHandler?.handleRename({ id: '', result: false, path: file.path }, false);
|
||||
});
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -112,19 +101,19 @@ export async function renderFileExplorer(settingsTab: SettingsTab): Promise<void
|
|||
|
||||
new Setting(containerEl)
|
||||
.setName('Highlight folder in the file explorer')
|
||||
.setDesc('Highlight the folder in the file explorer when it has a folder note and the folder note is open in the editor')
|
||||
.setDesc('Highlight the folder name in the file explorer when you click on a folder that has a folder note')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.highlightFolder)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.highlightFolder = value;
|
||||
if (!value) {
|
||||
activeDocument.body.classList.add('disable-folder-highlight');
|
||||
document.body.classList.add('disable-folder-highlight');
|
||||
} else {
|
||||
activeDocument.body.classList.remove('disable-folder-highlight');
|
||||
document.body.classList.remove('disable-folder-highlight');
|
||||
}
|
||||
await settingsTab.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
|
|
@ -135,14 +124,14 @@ export async function renderFileExplorer(settingsTab: SettingsTab): Promise<void
|
|||
.setValue(settingsTab.plugin.settings.hideCollapsingIcon)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.hideCollapsingIcon = value;
|
||||
if (value) {
|
||||
activeDocument.body.classList.add('fn-hide-collapse-icon');
|
||||
} else {
|
||||
activeDocument.body.classList.remove('fn-hide-collapse-icon');
|
||||
}
|
||||
await settingsTab.plugin.saveSettings();
|
||||
if (value) {
|
||||
document.body.classList.add('fn-hide-collapse-icon');
|
||||
} else {
|
||||
document.body.classList.remove('fn-hide-collapse-icon');
|
||||
}
|
||||
settingsTab.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
|
|
@ -155,29 +144,24 @@ export async function renderFileExplorer(settingsTab: SettingsTab): Promise<void
|
|||
settingsTab.plugin.settings.hideCollapsingIconForEmptyFolders = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
if (value) {
|
||||
activeDocument.body.classList.add('fn-hide-empty-collapse-icon');
|
||||
document.body.classList.add('fn-hide-empty-collapse-icon');
|
||||
} else {
|
||||
activeDocument.body.classList.remove('fn-hide-empty-collapse-icon');
|
||||
document.body.classList.remove('fn-hide-empty-collapse-icon');
|
||||
}
|
||||
settingsTab.display();
|
||||
},
|
||||
}
|
||||
));
|
||||
|
||||
if (settingsTab.plugin.settings.hideCollapsingIcon) {
|
||||
new Setting(containerEl)
|
||||
.setName('Hide collapse icon also when only the attachment folder is in the same folder')
|
||||
.setName('Hide collapse icon also when the attachment folder is in the same folder')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.ignoreAttachmentFolder)
|
||||
.onChange(async (value) => {
|
||||
if (value) {
|
||||
activeDocument.body.classList.add('fn-ignore-attachment-folder');
|
||||
} else {
|
||||
activeDocument.body.classList.remove('fn-ignore-attachment-folder');
|
||||
}
|
||||
settingsTab.plugin.settings.ignoreAttachmentFolder = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -190,46 +174,46 @@ export async function renderFileExplorer(settingsTab: SettingsTab): Promise<void
|
|||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.underlineFolder = value;
|
||||
if (value) {
|
||||
activeDocument.body.classList.add('folder-note-underline');
|
||||
document.body.classList.add('folder-note-underline');
|
||||
} else {
|
||||
activeDocument.body.classList.remove('folder-note-underline');
|
||||
document.body.classList.remove('folder-note-underline');
|
||||
}
|
||||
await settingsTab.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Bold the name of folder notes')
|
||||
.setDesc('Make the folder name bold in the file explorer when it has a folder note')
|
||||
.setDesc('Make the folder name bold in the file explorer')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.boldName)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.boldName = value;
|
||||
if (value) {
|
||||
activeDocument.body.classList.add('folder-note-bold');
|
||||
document.body.classList.add('folder-note-bold');
|
||||
} else {
|
||||
activeDocument.body.classList.remove('folder-note-bold');
|
||||
document.body.classList.remove('folder-note-bold');
|
||||
}
|
||||
await settingsTab.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Cursive the name of folder notes')
|
||||
.setDesc('Make the folder name cursive in the file explorer when it has a folder note')
|
||||
.setDesc('Make the folder name cursive in the file explorer')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.cursiveName)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.cursiveName = value;
|
||||
if (value) {
|
||||
activeDocument.body.classList.add('folder-note-cursive');
|
||||
document.body.classList.add('folder-note-cursive');
|
||||
} else {
|
||||
activeDocument.body.classList.remove('folder-note-cursive');
|
||||
document.body.classList.remove('folder-note-cursive');
|
||||
}
|
||||
await settingsTab.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,51 +1,11 @@
|
|||
import { Setting } from 'obsidian';
|
||||
import type { SettingsTab } from './SettingsTab';
|
||||
import { SettingsTab } from './SettingsTab';
|
||||
import { createOverviewSettings } from 'src/obsidian-folder-overview/src/settings';
|
||||
|
||||
export async function renderFolderOverview(settingsTab: SettingsTab): Promise<void> {
|
||||
export async function renderFolderOverview(settingsTab: SettingsTab) {
|
||||
const { plugin } = settingsTab;
|
||||
const defaultOverviewSettings = plugin.settings.defaultOverview;
|
||||
const overviewSettings = plugin.settings.defaultOverview;
|
||||
const containerEl = settingsTab.settingsPage;
|
||||
containerEl.createEl('p', { text: 'Edit the default settings for folder overviews', cls: 'setting-item-description' });
|
||||
|
||||
containerEl.createEl('h3', { text: 'Global settings' });
|
||||
new Setting(containerEl)
|
||||
.setName('Auto-update links without opening the overview')
|
||||
// eslint-disable-next-line max-len
|
||||
.setDesc('If enabled, the links that appear in the graph view will be updated even when you don\'t have the overview open somewhere.')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(plugin.settings.fvGlobalSettings.autoUpdateLinks)
|
||||
.onChange(async (value) => {
|
||||
plugin.settings.fvGlobalSettings.autoUpdateLinks = value;
|
||||
await plugin.saveSettings();
|
||||
if (value) {
|
||||
plugin.fvIndexDB.init(true);
|
||||
} else {
|
||||
plugin.fvIndexDB.active = false;
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
containerEl.createEl('h3', { text: 'Overviews default settings' });
|
||||
const pEl = containerEl.createEl('p', {
|
||||
text: 'Edit the default settings for new folder overviews, ',
|
||||
cls: 'setting-item-description',
|
||||
});
|
||||
const span = createSpan({ text: "this won't apply to already existing overviews.", cls: '' });
|
||||
const accentColor = (settingsTab.app.vault.getConfig('accentColor') as string) || '#7d5bed';
|
||||
span.setAttr('style', `color: ${accentColor};`);
|
||||
pEl.appendChild(span);
|
||||
|
||||
void createOverviewSettings(
|
||||
containerEl,
|
||||
defaultOverviewSettings,
|
||||
plugin,
|
||||
plugin.settings.defaultOverview,
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
settingsTab.display,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
settingsTab,
|
||||
);
|
||||
createOverviewSettings(containerEl, overviewSettings, plugin, plugin.settings.defaultOverview, settingsTab.display, undefined, undefined, undefined, settingsTab);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,17 @@
|
|||
|
||||
/* eslint-disable max-len */
|
||||
import { Setting, Platform } from 'obsidian';
|
||||
import type { SettingsTab } from './SettingsTab';
|
||||
import { SettingsTab } from './SettingsTab';
|
||||
import { ListComponent } from '../functions/ListComponent';
|
||||
import AddSupportedFileModal from '../modals/AddSupportedFileType';
|
||||
import { FrontMatterTitlePluginHandler } from '../events/FrontMatterTitle';
|
||||
import ConfirmationModal from './modals/CreateFnForEveryFolder';
|
||||
import { TemplateSuggest } from '../suggesters/TemplateSuggester';
|
||||
import { refreshAllFolderStyles } from '../functions/styleFunctions';
|
||||
import { loadFileClasses } from '../functions/styleFunctions';
|
||||
import BackupWarningModal from './modals/BackupWarning';
|
||||
import RenameFolderNotesModal from './modals/RenameFns';
|
||||
|
||||
let debounceTimer: number | undefined;
|
||||
let debounceTimer: NodeJS.Timeout;
|
||||
|
||||
// eslint-disable-next-line complexity
|
||||
export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
||||
export async function renderGeneral(settingsTab: SettingsTab) {
|
||||
const containerEl = settingsTab.settingsPage;
|
||||
const nameSetting = new Setting(containerEl)
|
||||
.setName('Folder note name template')
|
||||
|
|
@ -27,9 +24,8 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
settingsTab.plugin.settings.folderNoteName = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
|
||||
window.clearTimeout(debounceTimer);
|
||||
const FOLDER_NOTE_NAME_DEBOUNCE_MS = 2000;
|
||||
debounceTimer = window.setTimeout(() => {
|
||||
clearTimeout(debounceTimer);
|
||||
debounceTimer = setTimeout(() => {
|
||||
if (!value.includes('{{folder_name}}')) {
|
||||
if (!settingsTab.showFolderNameInTabTitleSetting) {
|
||||
settingsTab.display();
|
||||
|
|
@ -41,8 +37,8 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
settingsTab.showFolderNameInTabTitleSetting = false;
|
||||
}
|
||||
}
|
||||
}, FOLDER_NOTE_NAME_DEBOUNCE_MS);
|
||||
}),
|
||||
}, 2000);
|
||||
})
|
||||
)
|
||||
.addButton((button) =>
|
||||
button
|
||||
|
|
@ -54,17 +50,17 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
'Rename all existing folder notes',
|
||||
'When you click on "Confirm" all existing folder notes will be renamed to the new folder note name.',
|
||||
settingsTab.renameFolderNotes,
|
||||
[settingsTab.plugin.settings.oldFolderNoteName ?? '{{folder_name}}'])
|
||||
[])
|
||||
.open();
|
||||
}),
|
||||
})
|
||||
);
|
||||
nameSetting.infoEl.appendText('Requires a restart to take effect');
|
||||
nameSetting.infoEl.style.color = settingsTab.app.vault.getConfig('accentColor') as string || '#7d5bed';
|
||||
|
||||
if (!settingsTab.plugin.settings.folderNoteName.includes('{{folder_name}}')) {
|
||||
new Setting(containerEl)
|
||||
.setName('Display folder name in tab title')
|
||||
.setDesc('Use the actual folder name in the tab title instead of the custom folder note name (e.g., "folder note").')
|
||||
.setName('Display Folder Name in Tab Title')
|
||||
.setDesc('Use the actual folder name in the tab title instead of the custom folder note name (e.g., "Folder Note").')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.tabManagerEnabled)
|
||||
|
|
@ -78,51 +74,34 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
settingsTab.plugin.settings.tabManagerEnabled = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Default file type for new folder notes')
|
||||
.setDesc('Choose the default file type (canvas, Markdown, ...) used when creating new folder notes.')
|
||||
.setDesc('Choose the default file type (canvas, markdown, ...) used when creating new folder notes.')
|
||||
.addDropdown((dropdown) => {
|
||||
dropdown.addOption('.ask', 'Ask for file type');
|
||||
dropdown.addOption('.ask', 'ask for file type');
|
||||
settingsTab.plugin.settings.supportedFileTypes.forEach((type) => {
|
||||
if (type === '.md' || type === 'md') {
|
||||
dropdown.addOption('.md', 'Markdown');
|
||||
dropdown.addOption('.md', 'markdown');
|
||||
} else {
|
||||
dropdown.addOption('.' + type, type);
|
||||
}
|
||||
});
|
||||
|
||||
if (
|
||||
!settingsTab.plugin.settings.supportedFileTypes.includes(
|
||||
settingsTab.plugin.settings.folderNoteType.replace('.', ''),
|
||||
) &&
|
||||
settingsTab.plugin.settings.folderNoteType !== '.ask'
|
||||
) {
|
||||
if (!settingsTab.plugin.settings.supportedFileTypes.includes(settingsTab.plugin.settings.folderNoteType.replace('.', '')) && settingsTab.plugin.settings.folderNoteType !== '.ask') {
|
||||
settingsTab.plugin.settings.folderNoteType = '.md';
|
||||
void settingsTab.plugin.saveSettings();
|
||||
}
|
||||
|
||||
let defaultType = settingsTab.plugin.settings.folderNoteType.startsWith('.')
|
||||
? settingsTab.plugin.settings.folderNoteType
|
||||
: '.' + settingsTab.plugin.settings.folderNoteType;
|
||||
if (
|
||||
!settingsTab.plugin.settings.supportedFileTypes.includes(
|
||||
defaultType.replace('.', ''),
|
||||
)
|
||||
) {
|
||||
defaultType = '.ask';
|
||||
settingsTab.plugin.settings.folderNoteType = defaultType;
|
||||
settingsTab.plugin.saveSettings();
|
||||
}
|
||||
const defaultType = settingsTab.plugin.settings.folderNoteType.startsWith('.') ? settingsTab.plugin.settings.folderNoteType : '.' + settingsTab.plugin.settings.folderNoteType;
|
||||
|
||||
dropdown
|
||||
.setValue(defaultType)
|
||||
.onChange(async (value: string) => {
|
||||
settingsTab.plugin.settings.folderNoteType = value as '.md' | '.canvas' | '.ask';
|
||||
void settingsTab.plugin.saveSettings();
|
||||
void settingsTab.display();
|
||||
.onChange(async (value: '.md' | '.canvas') => {
|
||||
settingsTab.plugin.settings.folderNoteType = value;
|
||||
settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -130,31 +109,21 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
setting0.setName('Supported file types');
|
||||
const desc0 = document.createDocumentFragment();
|
||||
desc0.append(
|
||||
'Specify which file types are allowed as folder notes. Applies to both new and existing folders. Adding many types may affect performance.',
|
||||
'Specify which file types are allowed as folder notes. Applies to both new and existing folders. Adding many types may affect performance.'
|
||||
);
|
||||
setting0.setDesc(desc0);
|
||||
const list = new ListComponent(
|
||||
setting0.settingEl,
|
||||
settingsTab.plugin.settings.supportedFileTypes || [],
|
||||
['md', 'canvas'],
|
||||
);
|
||||
list.on('update', (values: unknown) => {
|
||||
settingsTab.plugin.settings.supportedFileTypes = values as string[];
|
||||
void settingsTab.plugin.saveSettings();
|
||||
void settingsTab.display();
|
||||
const list = new ListComponent(setting0.settingEl, settingsTab.plugin.settings.supportedFileTypes || [], ['md', 'canvas']);
|
||||
list.on('update', async (values: string[]) => {
|
||||
settingsTab.plugin.settings.supportedFileTypes = values;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
});
|
||||
|
||||
if (
|
||||
!settingsTab.plugin.settings.supportedFileTypes.includes('md') ||
|
||||
!settingsTab.plugin.settings.supportedFileTypes.includes('canvas') ||
|
||||
!settingsTab.plugin.settings.supportedFileTypes.includes('excalidraw')
|
||||
) {
|
||||
if (!settingsTab.plugin.settings.supportedFileTypes.includes('md') || !settingsTab.plugin.settings.supportedFileTypes.includes('canvas') || !settingsTab.plugin.settings.supportedFileTypes.includes('excalidraw')) {
|
||||
setting0.addDropdown((dropdown) => {
|
||||
const options = [
|
||||
{ value: 'md', label: 'Markdown' },
|
||||
{ value: 'canvas', label: 'Canvas' },
|
||||
{ value: 'base', label: 'Bases' },
|
||||
{ value: 'excalidraw', label: 'Excalidraw' },
|
||||
{ value: 'excalidraw', label: 'excalidraw' },
|
||||
{ value: 'custom', label: 'Custom extension' },
|
||||
];
|
||||
|
||||
|
|
@ -167,16 +136,11 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
dropdown.setValue('+');
|
||||
dropdown.onChange(async (value) => {
|
||||
if (value === 'custom') {
|
||||
return new AddSupportedFileModal(
|
||||
settingsTab.app,
|
||||
settingsTab.plugin,
|
||||
settingsTab,
|
||||
list,
|
||||
).open();
|
||||
return new AddSupportedFileModal(settingsTab.app, settingsTab.plugin, settingsTab, list as ListComponent).open();
|
||||
}
|
||||
await list.addValue(value.toLowerCase());
|
||||
void settingsTab.display();
|
||||
void settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
settingsTab.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
|
|
@ -185,13 +149,8 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
.setButtonText('Add custom file type')
|
||||
.setCta()
|
||||
.onClick(async () => {
|
||||
new AddSupportedFileModal(
|
||||
settingsTab.app,
|
||||
settingsTab.plugin,
|
||||
settingsTab,
|
||||
list,
|
||||
).open();
|
||||
}),
|
||||
new AddSupportedFileModal(settingsTab.app, settingsTab.plugin, settingsTab, list as ListComponent).open();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -202,11 +161,7 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
.addSearch((cb) => {
|
||||
new TemplateSuggest(cb.inputEl, settingsTab.plugin);
|
||||
cb.setPlaceholder('Template path');
|
||||
const templateFile = settingsTab.plugin.app.vault.getAbstractFileByPath(
|
||||
settingsTab.plugin.settings.templatePath,
|
||||
);
|
||||
const templateName = templateFile?.name.replace('.md', '') || '';
|
||||
cb.setValue(templateName);
|
||||
cb.setValue(settingsTab.plugin.app.vault.getAbstractFileByPath(settingsTab.plugin.settings.templatePath)?.name.replace('.md', '') || '');
|
||||
cb.onChange(async (value) => {
|
||||
if (value.trim() === '') {
|
||||
settingsTab.plugin.settings.templatePath = '';
|
||||
|
|
@ -227,15 +182,12 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
.addOption('insideFolder', 'Inside the folder')
|
||||
.addOption('parentFolder', 'In the parent folder')
|
||||
.setValue(settingsTab.plugin.settings.storageLocation)
|
||||
.onChange(async (value: string) => {
|
||||
if (value !== 'insideFolder' && value !== 'parentFolder' && value !== 'vaultFolder') {
|
||||
return;
|
||||
}
|
||||
.onChange(async (value: 'insideFolder' | 'parentFolder' | 'vaultFolder') => {
|
||||
settingsTab.plugin.settings.storageLocation = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
refreshAllFolderStyles(undefined, settingsTab.plugin);
|
||||
}),
|
||||
loadFileClasses(undefined, settingsTab.plugin);
|
||||
})
|
||||
)
|
||||
.addButton((button) =>
|
||||
button
|
||||
|
|
@ -253,9 +205,9 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
'Switch storage location',
|
||||
'When you click on "Confirm" all folder notes will be moved to the new storage location.',
|
||||
settingsTab.switchStorageLocation,
|
||||
[oldStorageLocation],
|
||||
[oldStorageLocation]
|
||||
).open();
|
||||
}),
|
||||
})
|
||||
);
|
||||
storageLocation.infoEl.appendText('Requires a restart to take effect');
|
||||
storageLocation.infoEl.style.color = settingsTab.app.vault.getConfig('accentColor') as string || '#7d5bed';
|
||||
|
|
@ -270,23 +222,23 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.syncDelete = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
},
|
||||
),
|
||||
}
|
||||
)
|
||||
);
|
||||
new Setting(containerEl)
|
||||
.setName('Move folder notes when moving the folder')
|
||||
.setDesc('Move the folder note file along with the folder when it is moved')
|
||||
.setDesc('Move the folder note when moving the folder')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.syncMove)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.syncMove = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
if (Platform.isDesktopApp) {
|
||||
settingsTab.settingsPage.createEl('h3', { text: 'Keyboard shortcuts' });
|
||||
settingsTab.settingsPage.createEl('h3', { text: 'Keyboard Shortcuts' });
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Key for creating folder note')
|
||||
|
|
@ -294,11 +246,10 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
.addDropdown((dropdown) => {
|
||||
if (!Platform.isMacOS) {
|
||||
dropdown.addOption('ctrl', 'Ctrl + Click');
|
||||
dropdown.addOption('alt', 'Alt + Click');
|
||||
} else {
|
||||
dropdown.addOption('ctrl', 'Cmd + Click');
|
||||
dropdown.addOption('alt', 'Option + Click');
|
||||
}
|
||||
dropdown.addOption('alt', 'Alt + Click');
|
||||
dropdown.setValue(settingsTab.plugin.settings.ctrlKey ? 'ctrl' : 'alt');
|
||||
dropdown.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.ctrlKey = value === 'ctrl';
|
||||
|
|
@ -312,14 +263,13 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
.setName('Key for opening folder note')
|
||||
.setDesc('Select the combination to open a folder note')
|
||||
.addDropdown((dropdown) => {
|
||||
dropdown.addOption('click', 'Mouse click');
|
||||
dropdown.addOption('click', 'Mouse Click');
|
||||
if (!Platform.isMacOS) {
|
||||
dropdown.addOption('ctrl', 'Ctrl + Click');
|
||||
dropdown.addOption('alt', 'Alt + Click');
|
||||
} else {
|
||||
dropdown.addOption('ctrl', 'Cmd + Click');
|
||||
dropdown.addOption('alt', 'Option + Click');
|
||||
}
|
||||
dropdown.addOption('alt', 'Alt + Click');
|
||||
if (settingsTab.plugin.settings.openByClick) {
|
||||
dropdown.setValue('click');
|
||||
} else if (settingsTab.plugin.settings.openWithCtrl) {
|
||||
|
|
@ -349,7 +299,7 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
settingsTab.plugin.settings.showDeleteConfirmation = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
|
|
@ -360,9 +310,8 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
dropdown.addOption('obsidianTrash', 'Move to Obsidian trash (.trash folder)');
|
||||
dropdown.addOption('delete', 'Delete permanently');
|
||||
dropdown.setValue(settingsTab.plugin.settings.deleteFilesAction);
|
||||
dropdown.onChange(async (value) => {
|
||||
const v = value as 'trash' | 'delete' | 'obsidianTrash';
|
||||
settingsTab.plugin.settings.deleteFilesAction = v;
|
||||
dropdown.onChange(async (value: 'trash' | 'delete' | 'obsidianTrash') => {
|
||||
settingsTab.plugin.settings.deleteFilesAction = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
});
|
||||
|
|
@ -379,27 +328,12 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
settingsTab.plugin.settings.openInNewTab = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
setting3.infoEl.appendText('Requires a restart to take effect');
|
||||
setting3.infoEl.style.color = settingsTab.app.vault.getConfig('accentColor') as string || '#7d5bed';
|
||||
}
|
||||
|
||||
if (settingsTab.plugin.settings.openInNewTab) {
|
||||
new Setting(containerEl)
|
||||
.setName('Focus existing tab instead of creating a new one')
|
||||
.setDesc('If a folder note is already open in a tab, focus that tab instead of creating a new one.')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.focusExistingTab)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.focusExistingTab = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Sync folder name')
|
||||
.setDesc('Automatically rename the folder note when the folder name is changed')
|
||||
|
|
@ -410,7 +344,7 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
settingsTab.plugin.settings.syncFolderName = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
settingsTab.settingsPage.createEl('h4', { text: 'Automation settings' });
|
||||
|
|
@ -436,7 +370,7 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
settingsTab.plugin.settings.autoCreate = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
if (settingsTab.plugin.settings.autoCreate) {
|
||||
|
|
@ -450,12 +384,12 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
settingsTab.plugin.settings.autoCreateFocusFiles = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Auto-create for attachment folders')
|
||||
.setDesc('Also automatically create folder notes for attachment folders (e.g., "attachments", "media", etc.).')
|
||||
.setDesc('Also automatically create folder notes for attachment folders (e.g., "Attachments", "Media", etc.).')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.autoCreateForAttachmentFolder)
|
||||
|
|
@ -463,7 +397,7 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
settingsTab.plugin.settings.autoCreateForAttachmentFolder = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -477,16 +411,16 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
settingsTab.plugin.settings.autoCreateForFiles = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
settingsTab.settingsPage.createEl('h3', { text: 'Integration & compatibility' });
|
||||
settingsTab.settingsPage.createEl('h3', { text: 'Integration & Compatibility' });
|
||||
|
||||
const desc1 = document.createDocumentFragment();
|
||||
|
||||
const link = activeDocument.createElement('a');
|
||||
const link = document.createElement('a');
|
||||
link.href = 'https://github.com/snezhig/obsidian-front-matter-title';
|
||||
link.textContent = 'Front matter title plugin';
|
||||
link.textContent = 'front matter title plugin';
|
||||
link.target = '_blank';
|
||||
|
||||
desc1.append(
|
||||
|
|
@ -505,34 +439,24 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
settingsTab.plugin.settings.frontMatterTitle.enabled = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
if (value) {
|
||||
settingsTab.plugin.fmtpHandler =
|
||||
new FrontMatterTitlePluginHandler(settingsTab.plugin);
|
||||
settingsTab.plugin.fmtpHandler = new FrontMatterTitlePluginHandler(settingsTab.plugin);
|
||||
} else {
|
||||
if (settingsTab.plugin.fmtpHandler) {
|
||||
settingsTab.plugin.updateAllBreadcrumbs(true);
|
||||
settingsTab.plugin.updateBreadcrumbs(true);
|
||||
}
|
||||
settingsTab.plugin.app.vault.getFiles().forEach((file) => {
|
||||
void settingsTab.plugin.fmtpHandler?.fmptUpdateFileName(
|
||||
{
|
||||
id: '',
|
||||
result: false,
|
||||
path: file.path,
|
||||
pathOnly: false,
|
||||
},
|
||||
false,
|
||||
);
|
||||
settingsTab.plugin.fmtpHandler?.handleRename({ id: '', result: false, path: file.path }, false);
|
||||
});
|
||||
settingsTab.plugin.fmtpHandler?.deleteEvent();
|
||||
settingsTab.plugin.fmtpHandler =
|
||||
new FrontMatterTitlePluginHandler(settingsTab.plugin);
|
||||
settingsTab.plugin.fmtpHandler = null;
|
||||
}
|
||||
settingsTab.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
fmtpSetting.infoEl.appendText('Requires a restart to take effect');
|
||||
fmtpSetting.infoEl.style.color = settingsTab.app.vault.getConfig('accentColor') as string || '#7d5bed';
|
||||
|
||||
settingsTab.settingsPage.createEl('h3', { text: 'Session & persistence' });
|
||||
settingsTab.settingsPage.createEl('h3', { text: 'Session & Persistence' });
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Persist tab after restart')
|
||||
|
|
@ -544,7 +468,7 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
settingsTab.plugin.settings.persistentSettingsTab.afterRestart = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
|
|
@ -557,6 +481,6 @@ export async function renderGeneral(settingsTab: SettingsTab): Promise<void> {
|
|||
settingsTab.plugin.settings.persistentSettingsTab.afterChangingTab = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
/* eslint-disable max-len */
|
||||
import { Setting } from 'obsidian';
|
||||
import type { SettingsTab } from './SettingsTab';
|
||||
export async function renderPath(settingsTab: SettingsTab): Promise<void> {
|
||||
import { SettingsTab } from './SettingsTab';
|
||||
export async function renderPath(settingsTab: SettingsTab) {
|
||||
const containerEl = settingsTab.settingsPage;
|
||||
new Setting(containerEl)
|
||||
.setName('Open folder note through path')
|
||||
|
|
@ -13,53 +12,49 @@ export async function renderPath(settingsTab: SettingsTab): Promise<void> {
|
|||
settingsTab.plugin.settings.openFolderNoteOnClickInPath = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
settingsTab.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
if (settingsTab.plugin.settings.openFolderNoteOnClickInPath) {
|
||||
new Setting(containerEl)
|
||||
.setName('Open sidebar when opening a folder note through path (mobile only)')
|
||||
.setDesc('Open the sidebar when opening a folder note through the path on mobile')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.openSidebar.mobile)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.openSidebar.mobile = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
}),
|
||||
);
|
||||
new Setting(containerEl)
|
||||
.setName('Open sidebar when opening a folder note through path (Mobile only)')
|
||||
.setDesc('Open the sidebar when opening a folder note through the path on mobile')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.openSidebar.mobile)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.openSidebar.mobile = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Open sidebar when opening a folder note through path (desktop only)')
|
||||
.setDesc('Open the sidebar when opening a folder note through the path on desktop')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.openSidebar.desktop)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.openSidebar.desktop = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
}),
|
||||
);
|
||||
}
|
||||
new Setting(containerEl)
|
||||
.setName('Open sidebar when opening a folder note through path (Desktop only)')
|
||||
.setDesc('Open the sidebar when opening a folder note through the path on desktop')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.openSidebar.desktop)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.openSidebar.desktop = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
})
|
||||
);
|
||||
|
||||
if (settingsTab.plugin.settings.frontMatterTitle.enabled) {
|
||||
new Setting(containerEl)
|
||||
.setName('Auto update folder name in the path (front matter title plugin only)')
|
||||
.setDesc('Automatically update the folder name in the path when the front matter title plugin is enabled and the title for a folder note is changed in the front matter. This will not change the file name, only the displayed name in the path.')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.frontMatterTitle.path)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.frontMatterTitle.path = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
if (value) {
|
||||
settingsTab.plugin.updateAllBreadcrumbs();
|
||||
} else {
|
||||
settingsTab.plugin.updateAllBreadcrumbs(true);
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
new Setting(containerEl)
|
||||
.setName('Change folder name in the path')
|
||||
.setDesc('Automatically rename a folder name in the path above a note when the folder note is renamed')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.frontMatterTitle.path)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.frontMatterTitle.path = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
if (value) {
|
||||
settingsTab.plugin.updateBreadcrumbs();
|
||||
} else {
|
||||
settingsTab.plugin.updateBreadcrumbs(true);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
settingsTab.settingsPage.createEl('h3', { text: 'Style settings' });
|
||||
|
||||
|
|
@ -72,58 +67,45 @@ export async function renderPath(settingsTab: SettingsTab): Promise<void> {
|
|||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.underlineFolderInPath = value;
|
||||
if (value) {
|
||||
activeDocument.body.classList.add('folder-note-underline-path');
|
||||
document.body.classList.add('folder-note-underline-path');
|
||||
} else {
|
||||
activeDocument.body.classList.remove('folder-note-underline-path');
|
||||
document.body.classList.remove('folder-note-underline-path');
|
||||
}
|
||||
await settingsTab.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Bold folders in the path')
|
||||
.setDesc('Make the folder name bold in the path above a note when it has a folder note')
|
||||
.setDesc('Make the folder name bold in the path above a note')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.boldNameInPath)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.boldNameInPath = value;
|
||||
if (value) {
|
||||
activeDocument.body.classList.add('folder-note-bold-path');
|
||||
document.body.classList.add('folder-note-bold-path');
|
||||
} else {
|
||||
activeDocument.body.classList.remove('folder-note-bold-path');
|
||||
document.body.classList.remove('folder-note-bold-path');
|
||||
}
|
||||
await settingsTab.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Cursive the name of folder notes in the path')
|
||||
.setDesc('Make the folder name cursive in the path above a note when it has a folder note')
|
||||
.setDesc('Make the folder name cursive in the path above a note')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.cursiveNameInPath)
|
||||
.onChange(async (value) => {
|
||||
settingsTab.plugin.settings.cursiveNameInPath = value;
|
||||
if (value) {
|
||||
activeDocument.body.classList.add('folder-note-cursive-path');
|
||||
document.body.classList.add('folder-note-cursive-path');
|
||||
} else {
|
||||
activeDocument.body.classList.remove('folder-note-cursive-path');
|
||||
document.body.classList.remove('folder-note-cursive-path');
|
||||
}
|
||||
await settingsTab.plugin.saveSettings();
|
||||
}),
|
||||
);
|
||||
|
||||
new Setting(containerEl)
|
||||
.setName('Hide folder note name in the path')
|
||||
.setDesc('Only show the folder name in the path and hide the folder note name.')
|
||||
.addToggle((toggle) =>
|
||||
toggle
|
||||
.setValue(settingsTab.plugin.settings.hideFolderNoteNameInPath)
|
||||
.onChange(async (value) => {
|
||||
activeDocument.body.classList.toggle('folder-note-hide-name-path', value);
|
||||
settingsTab.plugin.settings.hideFolderNoteNameInPath = value;
|
||||
await settingsTab.plugin.saveSettings();
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,17 @@
|
|||
import {
|
||||
Notice, PluginSettingTab, TFile,
|
||||
TFolder, type App, type MarkdownPostProcessorContext,
|
||||
} from 'obsidian';
|
||||
import type FolderNotesPlugin from '../main';
|
||||
import type { ExcludePattern } from 'src/ExcludeFolders/ExcludePattern';
|
||||
import type { ExcludedFolder } from 'src/ExcludeFolders/ExcludeFolder';
|
||||
import { App, Notice, PluginSettingTab, TFile, TFolder, MarkdownPostProcessorContext } from 'obsidian';
|
||||
import FolderNotesPlugin from '../main';
|
||||
import { ExcludePattern } from 'src/ExcludeFolders/ExcludePattern';
|
||||
import { ExcludedFolder } from 'src/ExcludeFolders/ExcludeFolder';
|
||||
import { extractFolderName, getFolderNote } from '../functions/folderNoteFunctions';
|
||||
import type { defaultOverviewSettings } from '../obsidian-folder-overview/src/FolderOverview';
|
||||
import { overviewSettings } from '../obsidian-folder-overview/src/FolderOverview';
|
||||
import { renderGeneral } from './GeneralSettings';
|
||||
import { renderFileExplorer } from './FileExplorerSettings';
|
||||
import { renderPath } from './PathSettings';
|
||||
import { renderFolderOverview } from './FolderOverviewSettings';
|
||||
import { renderExcludeFolders } from './ExcludedFoldersSettings';
|
||||
import { getFolderPathFromString } from '../functions/utils';
|
||||
import type { WhitelistedFolder } from 'src/ExcludeFolders/WhitelistFolder';
|
||||
import type { WhitelistedPattern } from 'src/ExcludeFolders/WhitelistPattern';
|
||||
import { WhitelistedFolder } from 'src/ExcludeFolders/WhitelistFolder';
|
||||
import { WhitelistedPattern } from 'src/ExcludeFolders/WhitelistPattern';
|
||||
|
||||
export interface FolderNotesSettings {
|
||||
syncFolderName: boolean;
|
||||
|
|
@ -36,7 +33,6 @@ export interface FolderNotesSettings {
|
|||
underlineFolderInPath: boolean;
|
||||
openFolderNoteOnClickInPath: boolean;
|
||||
openInNewTab: boolean;
|
||||
focusExistingTab: boolean;
|
||||
oldFolderNoteName: string | undefined;
|
||||
folderNoteName: string;
|
||||
newFolderNoteName: string;
|
||||
|
|
@ -44,7 +40,7 @@ export interface FolderNotesSettings {
|
|||
disableFolderHighlighting: boolean;
|
||||
storageLocation: 'insideFolder' | 'parentFolder' | 'vaultFolder';
|
||||
syncDelete: boolean;
|
||||
defaultOverview: defaultOverviewSettings;
|
||||
defaultOverview: overviewSettings;
|
||||
useSubmenus: boolean;
|
||||
syncMove: boolean;
|
||||
frontMatterTitle: {
|
||||
|
|
@ -77,12 +73,7 @@ export interface FolderNotesSettings {
|
|||
persistentSettingsTab: {
|
||||
afterRestart: boolean;
|
||||
afterChangingTab: boolean;
|
||||
},
|
||||
firstTimeInsertOverview: boolean;
|
||||
fvGlobalSettings: {
|
||||
autoUpdateLinks: boolean;
|
||||
}
|
||||
hideFolderNoteNameInPath: boolean;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
||||
|
|
@ -104,7 +95,6 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
|||
underlineFolderInPath: true,
|
||||
openFolderNoteOnClickInPath: true,
|
||||
openInNewTab: false,
|
||||
focusExistingTab: false,
|
||||
oldFolderNoteName: undefined,
|
||||
folderNoteName: '{{folder_name}}',
|
||||
folderNoteType: '.md',
|
||||
|
|
@ -132,13 +122,6 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
|||
alwaysCollapse: false,
|
||||
autoSync: true,
|
||||
allowDragAndDrop: true,
|
||||
hideLinkList: true,
|
||||
hideFolderOverview: false,
|
||||
useActualLinks: false,
|
||||
fmtpIntegration: false,
|
||||
titleSize: 1,
|
||||
isInCallout: false,
|
||||
useWikilinks: true,
|
||||
},
|
||||
useSubmenus: true,
|
||||
syncMove: true,
|
||||
|
|
@ -148,7 +131,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
|||
path: true,
|
||||
},
|
||||
settingsTab: 'general',
|
||||
supportedFileTypes: ['md', 'canvas', 'base'],
|
||||
supportedFileTypes: ['md', 'canvas'],
|
||||
boldName: false,
|
||||
boldNameInPath: false,
|
||||
cursiveName: false,
|
||||
|
|
@ -171,7 +154,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
|||
string: '',
|
||||
hideInSettings: false,
|
||||
detached: false,
|
||||
showFolderNote: false,
|
||||
hideNote: false,
|
||||
},
|
||||
excludePatternDefaultSettings: {
|
||||
type: 'pattern',
|
||||
|
|
@ -187,7 +170,7 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
|||
string: '',
|
||||
hideInSettings: false,
|
||||
detached: false,
|
||||
showFolderNote: false,
|
||||
hideNote: false,
|
||||
},
|
||||
hideCollapsingIcon: false,
|
||||
hideCollapsingIconForEmptyFolders: false,
|
||||
|
|
@ -203,19 +186,14 @@ export const DEFAULT_SETTINGS: FolderNotesSettings = {
|
|||
afterRestart: true,
|
||||
afterChangingTab: true,
|
||||
},
|
||||
firstTimeInsertOverview: true,
|
||||
fvGlobalSettings: {
|
||||
autoUpdateLinks: false,
|
||||
},
|
||||
hideFolderNoteNameInPath: false,
|
||||
};
|
||||
|
||||
export class SettingsTab extends PluginSettingTab {
|
||||
plugin!: FolderNotesPlugin;
|
||||
app!: App;
|
||||
excludeFolders!: ExcludedFolder[];
|
||||
plugin: FolderNotesPlugin;
|
||||
app: App;
|
||||
excludeFolders: ExcludedFolder[];
|
||||
settingsPage!: HTMLElement;
|
||||
showFolderNameInTabTitleSetting!: boolean;
|
||||
showFolderNameInTabTitleSetting: boolean;
|
||||
constructor(app: App, plugin: FolderNotesPlugin) {
|
||||
super(app, plugin);
|
||||
}
|
||||
|
|
@ -241,39 +219,29 @@ export class SettingsTab extends PluginSettingTab {
|
|||
id: 'path',
|
||||
},
|
||||
};
|
||||
|
||||
renderSettingsPage(tabId: string): void {
|
||||
renderSettingsPage(tabId: string) {
|
||||
this.settingsPage.empty();
|
||||
switch (tabId.toLocaleLowerCase()) {
|
||||
case this.TABS.GENERAL.id:
|
||||
void renderGeneral(this);
|
||||
renderGeneral(this);
|
||||
break;
|
||||
case this.TABS.FOLDER_OVERVIEW.id:
|
||||
void renderFolderOverview(this);
|
||||
renderFolderOverview(this);
|
||||
break;
|
||||
case this.TABS.EXCLUDE_FOLDERS.id:
|
||||
void renderExcludeFolders(this);
|
||||
renderExcludeFolders(this);
|
||||
break;
|
||||
case this.TABS.FILE_EXPLORER.id:
|
||||
void renderFileExplorer(this);
|
||||
renderFileExplorer(this);
|
||||
break;
|
||||
case this.TABS.PATH.id:
|
||||
void renderPath(this);
|
||||
renderPath(this);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
display(
|
||||
contentEl?: HTMLElement,
|
||||
yaml?: defaultOverviewSettings,
|
||||
plugin?: FolderNotesPlugin,
|
||||
defaultSettings?: boolean,
|
||||
display?: CallableFunction,
|
||||
el?: HTMLElement,
|
||||
ctx?: MarkdownPostProcessorContext,
|
||||
file?: TFile | null,
|
||||
settingsTab?: this,
|
||||
): void {
|
||||
display(contentEl?: HTMLElement, yaml?: overviewSettings, plugin?: FolderNotesPlugin, defaultSettings?: boolean, display?: CallableFunction, el?: HTMLElement, ctx?: MarkdownPostProcessorContext, file?: TFile | null, settingsTab?: this) {
|
||||
plugin = this?.plugin ?? plugin;
|
||||
if (plugin) {
|
||||
plugin.settingsOpened = true;
|
||||
|
|
@ -290,19 +258,16 @@ export class SettingsTab extends PluginSettingTab {
|
|||
for (const [tabId, tabInfo] of Object.entries(settingsTab.TABS)) {
|
||||
const tabEl = tabBar.createEl('div', { cls: 'fn-settings-tab' });
|
||||
tabEl.createEl('div', { cls: 'fn-settings-tab-name', text: tabInfo.name });
|
||||
if (
|
||||
plugin &&
|
||||
plugin.settings.settingsTab.toLocaleLowerCase() ===
|
||||
tabId.toLocaleLowerCase()
|
||||
) {
|
||||
if (plugin && plugin.settings.settingsTab.toLocaleLowerCase() === tabId.toLocaleLowerCase()) {
|
||||
tabEl.addClass('fn-settings-tab-active');
|
||||
}
|
||||
tabEl.addEventListener('click', () => {
|
||||
for (const child of Array.from(tabBar.children)) {
|
||||
(child as HTMLElement).classList.remove('fn-settings-tab-active');
|
||||
// @ts-ignore
|
||||
for (const tabEl of tabBar.children) {
|
||||
tabEl.removeClass('fn-settings-tab-active');
|
||||
if (!plugin) { return; }
|
||||
plugin.settings.settingsTab = tabId.toLocaleLowerCase();
|
||||
void plugin.saveSettings();
|
||||
plugin.saveSettings();
|
||||
}
|
||||
tabEl.addClass('fn-settings-tab-active');
|
||||
if (!settingsTab) { return; }
|
||||
|
|
@ -319,47 +284,39 @@ export class SettingsTab extends PluginSettingTab {
|
|||
}
|
||||
}
|
||||
|
||||
renameFolderNotes(): void {
|
||||
renameFolderNotes() {
|
||||
new Notice('Starting to update folder notes...');
|
||||
const oldTemplate = this.plugin.settings.oldFolderNoteName ?? '{{folder_name}}';
|
||||
|
||||
for (const folder of this.app.vault.getAllLoadedFiles()) {
|
||||
if (folder instanceof TFolder) {
|
||||
const folderNote = getFolderNote(
|
||||
this.plugin,
|
||||
folder.path,
|
||||
undefined,
|
||||
undefined,
|
||||
oldTemplate,
|
||||
);
|
||||
const folderNote = getFolderNote(this.plugin, folder.path, undefined, undefined, oldTemplate);
|
||||
if (!(folderNote instanceof TFile)) { continue; }
|
||||
|
||||
const folderName = extractFolderName(oldTemplate, folderNote.basename) ?? '';
|
||||
const newFolderNoteName = this.plugin.settings.folderNoteName
|
||||
.replace('{{folder_name}}', folderName);
|
||||
const newFolderNoteName = this.plugin.settings.folderNoteName.replace('{{folder_name}}', folderName);
|
||||
let newPath = '';
|
||||
|
||||
if (this.plugin.settings.storageLocation === 'parentFolder') {
|
||||
if (getFolderPathFromString(folder.path).trim() === '/') {
|
||||
newPath = `${newFolderNoteName}.${folderNote.extension}`;
|
||||
} else {
|
||||
|
||||
newPath = `${folderNote.parent?.path}/${newFolderNoteName}.${folderNote.extension}`;
|
||||
}
|
||||
} else if (this.plugin.settings.storageLocation === 'insideFolder') {
|
||||
newPath = `${folder.path}/${newFolderNoteName}.${folderNote.extension}`;
|
||||
}
|
||||
|
||||
void this.app.fileManager.renameFile(folderNote, newPath);
|
||||
this.app.fileManager.renameFile(folderNote, newPath);
|
||||
}
|
||||
}
|
||||
|
||||
this.plugin.settings.oldFolderNoteName = this.plugin.settings.folderNoteName;
|
||||
void this.plugin.saveSettings();
|
||||
this.plugin.saveSettings();
|
||||
new Notice('Finished updating folder notes');
|
||||
}
|
||||
|
||||
switchStorageLocation(oldMethod: string): void {
|
||||
switchStorageLocation(oldMethod: string) {
|
||||
new Notice('Starting to switch storage location...');
|
||||
this.app.vault.getAllLoadedFiles().forEach((file) => {
|
||||
if (file instanceof TFolder) {
|
||||
|
|
@ -372,14 +329,14 @@ export class SettingsTab extends PluginSettingTab {
|
|||
} else {
|
||||
newPath = `${getFolderPathFromString(file.path)}/${folderNote.name}`;
|
||||
}
|
||||
void this.plugin.app.fileManager.renameFile(folderNote, newPath);
|
||||
this.plugin.app.fileManager.renameFile(folderNote, newPath);
|
||||
} else if (this.plugin.settings.storageLocation === 'insideFolder') {
|
||||
if (getFolderPathFromString(folderNote.path) === file.path) {
|
||||
return;
|
||||
} else {
|
||||
const newPath = `${file.path}/${folderNote.name}`;
|
||||
this.plugin.app.fileManager.renameFile(folderNote, newPath);
|
||||
}
|
||||
const newPath = `${file.path}/${folderNote.name}`;
|
||||
void this.plugin.app.fileManager.renameFile(folderNote, newPath);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,14 @@
|
|||
import { Modal, ButtonComponent } from 'obsidian';
|
||||
import type FolderNotesPlugin from 'src/main';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
|
||||
export default class BackupWarningModal extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
title: string;
|
||||
desc: string;
|
||||
callback: (oldMethod: string) => void;
|
||||
args: [string];
|
||||
callback: (...args: any[]) => void;
|
||||
args: any[];
|
||||
|
||||
constructor(
|
||||
plugin: FolderNotesPlugin,
|
||||
title: string,
|
||||
description: string,
|
||||
callback: (oldMethod: string) => void,
|
||||
args: [string],
|
||||
) {
|
||||
constructor(plugin: FolderNotesPlugin, title: string, description: string, callback: (...args: any[]) => void, args: any[] = []) {
|
||||
super(plugin.app);
|
||||
this.plugin = plugin;
|
||||
this.title = title;
|
||||
|
|
@ -23,7 +17,7 @@ export default class BackupWarningModal extends Modal {
|
|||
this.desc = description;
|
||||
}
|
||||
|
||||
onOpen(): void {
|
||||
onOpen() {
|
||||
this.modalEl.addClass('fn-backup-warning-modal');
|
||||
const { contentEl } = this;
|
||||
|
||||
|
|
@ -31,8 +25,9 @@ export default class BackupWarningModal extends Modal {
|
|||
|
||||
contentEl.createEl('p', { text: this.desc });
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
contentEl.createEl('p', { text: 'Make sure to backup your vault before using this feature.' }).addClass('fn-warning-text');
|
||||
this.insertCustomHtml();
|
||||
|
||||
contentEl.createEl('p', { text: 'Make sure to backup your vault before using this feature.' }).style.color = '#fb464c';
|
||||
|
||||
const buttonContainer = contentEl.createDiv({ cls: 'fn-modal-button-container' });
|
||||
const confirmButton = new ButtonComponent(buttonContainer);
|
||||
|
|
@ -50,7 +45,11 @@ export default class BackupWarningModal extends Modal {
|
|||
});
|
||||
}
|
||||
|
||||
onClose(): void {
|
||||
insertCustomHtml(): void {
|
||||
|
||||
}
|
||||
|
||||
onClose() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { Modal, Setting, TFolder, Notice, type App, type ButtonComponent } from 'obsidian';
|
||||
import type FolderNotesPlugin from '../../main';
|
||||
import { App, ButtonComponent, Modal, Setting, TFolder, Notice } from 'obsidian';
|
||||
import FolderNotesPlugin from '../../main';
|
||||
import { createFolderNote, getFolderNote } from 'src/functions/folderNoteFunctions';
|
||||
import { getTemplatePlugins } from 'src/template';
|
||||
import { getExcludedFolder } from 'src/ExcludeFolders/functions/folderFunctions';
|
||||
export default class ConfirmationModal extends Modal {
|
||||
plugin: FolderNotesPlugin;
|
||||
app: App;
|
||||
folder!: TFolder;
|
||||
folder: TFolder;
|
||||
extension: string;
|
||||
constructor(app: App, plugin: FolderNotesPlugin) {
|
||||
super(app);
|
||||
|
|
@ -14,8 +14,7 @@ export default class ConfirmationModal extends Modal {
|
|||
this.app = app;
|
||||
this.extension = plugin.settings.folderNoteType;
|
||||
}
|
||||
|
||||
onOpen(): void {
|
||||
onOpen() {
|
||||
this.modalEl.addClass('fn-confirmation-modal');
|
||||
let templateFolderPath: string;
|
||||
const { templateFolder, templaterPlugin } = getTemplatePlugins(this.plugin.app);
|
||||
|
|
@ -23,29 +22,19 @@ export default class ConfirmationModal extends Modal {
|
|||
templateFolderPath = '';
|
||||
}
|
||||
if (templaterPlugin) {
|
||||
templateFolderPath = (
|
||||
templaterPlugin as unknown as {
|
||||
plugin?: { settings?: { templates_folder?: string } }
|
||||
}
|
||||
).plugin?.settings?.templates_folder as string;
|
||||
} else if (templateFolder) {
|
||||
templateFolderPath = templaterPlugin.plugin?.settings?.templates_folder as string;
|
||||
} else {
|
||||
templateFolderPath = templateFolder;
|
||||
}
|
||||
|
||||
const { contentEl } = this;
|
||||
contentEl.createEl('h2', { text: 'Create folder note for every folder' });
|
||||
const setting = new Setting(contentEl);
|
||||
// eslint-disable-next-line max-len
|
||||
setting.infoEl.createEl('p', { text: 'Make sure to backup your vault before using this feature.' }).addClass('fn-warning-text');
|
||||
// eslint-disable-next-line max-len
|
||||
setting.infoEl.createEl('p', { text: 'Make sure to backup your vault before using this feature.' }).style.color = '#fb464c';
|
||||
setting.infoEl.createEl('p', { text: 'This feature will create a folder note for every folder in your vault.' });
|
||||
// eslint-disable-next-line max-len
|
||||
setting.infoEl.createEl('p', { text: 'Every folder that already has a folder note will be ignored.' });
|
||||
setting.infoEl.createEl('p', { text: 'Every excluded folder will be ignored.' });
|
||||
if (
|
||||
!this.plugin.settings.templatePath ||
|
||||
this.plugin.settings.templatePath?.trim() === ''
|
||||
) {
|
||||
if (!this.plugin.settings.templatePath || this.plugin.settings.templatePath?.trim() === '') {
|
||||
new Setting(contentEl)
|
||||
.setName('Folder note file extension')
|
||||
.setDesc('Choose the file extension for the folder notes.')
|
||||
|
|
@ -57,7 +46,7 @@ export default class ConfirmationModal extends Modal {
|
|||
cb.onChange(async (value) => {
|
||||
this.extension = value;
|
||||
});
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
new Setting(contentEl)
|
||||
|
|
@ -66,24 +55,17 @@ export default class ConfirmationModal extends Modal {
|
|||
cb.setCta();
|
||||
cb.buttonEl.focus();
|
||||
cb.onClick(async () => {
|
||||
if (
|
||||
this.plugin.settings.templatePath &&
|
||||
this.plugin.settings.templatePath.trim() !== ''
|
||||
) {
|
||||
if (this.plugin.settings.templatePath && this.plugin.settings.templatePath.trim() !== '') {
|
||||
this.extension = '.' + this.plugin.settings.templatePath.split('.').pop();
|
||||
}
|
||||
if (this.extension === '.ask') {
|
||||
return new Notice('Please choose a file extension');
|
||||
}
|
||||
this.close();
|
||||
const folders = this.app.vault
|
||||
.getAllLoadedFiles()
|
||||
.filter((file) => file.parent instanceof TFolder);
|
||||
const folders = this.app.vault.getAllLoadedFiles().filter((file) => file.parent instanceof TFolder);
|
||||
for (const folder of folders) {
|
||||
if (folder instanceof TFolder) {
|
||||
const excludedFolder = getExcludedFolder(
|
||||
this.plugin, folder.path, true,
|
||||
);
|
||||
const excludedFolder = getExcludedFolder(this.plugin, folder.path, true);
|
||||
if (excludedFolder) continue;
|
||||
if (folder.path === templateFolderPath) continue;
|
||||
const folderNote = getFolderNote(this.plugin, folder.path);
|
||||
|
|
@ -100,8 +82,7 @@ export default class ConfirmationModal extends Modal {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
onClose(): void {
|
||||
onClose() {
|
||||
const { contentEl } = this;
|
||||
contentEl.empty();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,33 +1,27 @@
|
|||
import BackupWarningModal from './BackupWarning';
|
||||
import type FolderNotesPlugin from 'src/main';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
import { Setting } from 'obsidian';
|
||||
|
||||
export default class RenameFolderNotesModal extends BackupWarningModal {
|
||||
constructor(
|
||||
plugin: FolderNotesPlugin,
|
||||
title: string,
|
||||
description: string,
|
||||
callback: (oldMethod: string) => void,
|
||||
args: [string],
|
||||
) {
|
||||
constructor(plugin: FolderNotesPlugin, title: string, description: string, callback: (...args: any[]) => void, args: any[] = []) {
|
||||
super(plugin, title, description, callback, args);
|
||||
}
|
||||
|
||||
insertCustomHtml(): void {
|
||||
const { contentEl } = this;
|
||||
new Setting(contentEl)
|
||||
.setName('Old folder note name')
|
||||
.setName('Old Folder Note Name')
|
||||
.setDesc('Every folder note that matches this name will be renamed to the new folder note name.')
|
||||
.addText((text) => text
|
||||
.setPlaceholder('Enter the old folder note name')
|
||||
.setValue(this.plugin.settings.oldFolderNoteName || '')
|
||||
.onChange(async (value) => {
|
||||
this.plugin.settings.oldFolderNoteName = value;
|
||||
}),
|
||||
})
|
||||
);
|
||||
|
||||
new Setting(contentEl)
|
||||
.setName('New folder note name')
|
||||
.setName('New Folder Note Name')
|
||||
.setDesc('Every folder note that matches the old folder note name will be renamed to this name.')
|
||||
.addText((text) => text
|
||||
.setPlaceholder('Enter the new folder note name')
|
||||
|
|
@ -35,7 +29,7 @@ export default class RenameFolderNotesModal extends BackupWarningModal {
|
|||
.onChange(async (value) => {
|
||||
this.plugin.settings.folderNoteName = value;
|
||||
this.plugin.settingsTab.display();
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,22 @@
|
|||
import { AbstractInputSuggest, type TAbstractFile, TFile } from 'obsidian';
|
||||
import type FolderNotesPlugin from '../main';
|
||||
// Credits go to Liam's Periodic Notes Plugin: https://github.com/liamcain/obsidian-periodic-notes and https://github.com/SilentVoid13/Templater
|
||||
|
||||
import { TAbstractFile, TFile } from 'obsidian';
|
||||
import { TextInputSuggest } from './Suggest';
|
||||
import FolderNotesPlugin from '../main';
|
||||
export enum FileSuggestMode {
|
||||
TemplateFiles,
|
||||
ScriptFiles,
|
||||
}
|
||||
|
||||
export class FileSuggest extends AbstractInputSuggest<TFile> {
|
||||
plugin: FolderNotesPlugin;
|
||||
|
||||
export class FileSuggest extends TextInputSuggest<TFile> {
|
||||
constructor(
|
||||
public inputEl: HTMLInputElement,
|
||||
plugin: FolderNotesPlugin,
|
||||
public inputEl: HTMLInputElement,
|
||||
plugin: FolderNotesPlugin
|
||||
) {
|
||||
super(plugin.app, inputEl);
|
||||
this.plugin = plugin;
|
||||
super(inputEl, plugin);
|
||||
}
|
||||
|
||||
|
||||
get_error_msg(mode: FileSuggestMode): string {
|
||||
switch (mode) {
|
||||
case FileSuggestMode.TemplateFiles:
|
||||
|
|
|
|||
|
|
@ -1,23 +1,21 @@
|
|||
// Credits go to Liam's Periodic Notes Plugin: https://github.com/liamcain/obsidian-periodic-notes and https://github.com/SilentVoid13/Templater
|
||||
|
||||
import { AbstractInputSuggest, TFolder, type TAbstractFile } from 'obsidian';
|
||||
import type FolderNotesPlugin from '../main';
|
||||
import { TAbstractFile, TFolder } from 'obsidian';
|
||||
import { TextInputSuggest } from './Suggest';
|
||||
import FolderNotesPlugin from '../main';
|
||||
export enum FileSuggestMode {
|
||||
TemplateFiles,
|
||||
ScriptFiles,
|
||||
}
|
||||
|
||||
export class FolderSuggest extends AbstractInputSuggest<TFolder> {
|
||||
plugin: FolderNotesPlugin;
|
||||
|
||||
export class FolderSuggest extends TextInputSuggest<TFolder> {
|
||||
constructor(
|
||||
public inputEl: HTMLInputElement,
|
||||
plugin: FolderNotesPlugin,
|
||||
public inputEl: HTMLInputElement,
|
||||
plugin: FolderNotesPlugin,
|
||||
private whitelistSuggester: boolean,
|
||||
public folder?: TFolder,
|
||||
) {
|
||||
super(plugin.app, inputEl);
|
||||
this.plugin = plugin;
|
||||
super(inputEl, plugin);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -37,18 +35,13 @@ export class FolderSuggest extends AbstractInputSuggest<TFolder> {
|
|||
if (this.folder) {
|
||||
files = this.folder.children;
|
||||
} else {
|
||||
const MAX_FILE_SUGGESTIONS = 100;
|
||||
files = this.plugin.app.vault.getAllLoadedFiles().slice(0, MAX_FILE_SUGGESTIONS);
|
||||
files = this.plugin.app.vault.getAllLoadedFiles().slice(0,100);
|
||||
}
|
||||
files.forEach((folder: TAbstractFile) => {
|
||||
if (
|
||||
folder instanceof TFolder &&
|
||||
folder.path.toLowerCase().contains(lower_input_str) &&
|
||||
(
|
||||
!this.plugin.settings.excludeFolders.find(
|
||||
(f) => f.path === folder.path,
|
||||
) || this.whitelistSuggester
|
||||
)
|
||||
folder.path.toLowerCase().contains(lower_input_str) &&
|
||||
(!this.plugin.settings.excludeFolders.find((f) => f.path === folder.path) || this.whitelistSuggester)
|
||||
) {
|
||||
folders.push(folder);
|
||||
}
|
||||
|
|
|
|||
206
src/suggesters/Suggest.ts
Normal file
|
|
@ -0,0 +1,206 @@
|
|||
// Credits go to Liam's Periodic Notes Plugin: https://github.com/liamcain/obsidian-periodic-notes and https://github.com/SilentVoid13/Templater
|
||||
|
||||
|
||||
import { ISuggestOwner, Scope } from 'obsidian';
|
||||
import { createPopper, Instance as PopperInstance } from '@popperjs/core';
|
||||
import FolderNotesPlugin from 'src/main';
|
||||
|
||||
const wrapAround = (value: number, size: number): number => {
|
||||
return ((value % size) + size) % size;
|
||||
};
|
||||
|
||||
class Suggest<T> {
|
||||
private owner: ISuggestOwner<T>;
|
||||
private values: T[];
|
||||
private suggestions: HTMLDivElement[];
|
||||
private selectedItem: number;
|
||||
private containerEl: HTMLElement;
|
||||
plugin: FolderNotesPlugin;
|
||||
|
||||
constructor(
|
||||
owner: ISuggestOwner<T>,
|
||||
containerEl: HTMLElement,
|
||||
scope: Scope
|
||||
) {
|
||||
this.owner = owner;
|
||||
this.containerEl = containerEl;
|
||||
|
||||
containerEl.on(
|
||||
'click',
|
||||
'.suggestion-item',
|
||||
this.onSuggestionClick.bind(this)
|
||||
);
|
||||
containerEl.on(
|
||||
'mousemove',
|
||||
'.suggestion-item',
|
||||
this.onSuggestionMouseover.bind(this)
|
||||
);
|
||||
|
||||
scope.register([], 'ArrowUp', (event) => {
|
||||
if (!event.isComposing) {
|
||||
this.setSelectedItem(this.selectedItem - 1, true);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
scope.register([], 'ArrowDown', (event) => {
|
||||
if (!event.isComposing) {
|
||||
this.setSelectedItem(this.selectedItem + 1, true);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
scope.register([], 'Enter', (event) => {
|
||||
if (!event.isComposing) {
|
||||
this.useSelectedItem(event);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onSuggestionClick(event: MouseEvent, el: HTMLDivElement): void {
|
||||
event.preventDefault();
|
||||
|
||||
const item = this.suggestions.indexOf(el);
|
||||
this.setSelectedItem(item, false);
|
||||
this.useSelectedItem(event);
|
||||
}
|
||||
|
||||
onSuggestionMouseover(_event: MouseEvent, el: HTMLDivElement): void {
|
||||
const item = this.suggestions.indexOf(el);
|
||||
this.setSelectedItem(item, false);
|
||||
}
|
||||
|
||||
setSuggestions(values: T[]) {
|
||||
this.containerEl.empty();
|
||||
const suggestionEls: HTMLDivElement[] = [];
|
||||
|
||||
values.forEach((value) => {
|
||||
const suggestionEl = this.containerEl.createDiv('suggestion-item');
|
||||
this.owner.renderSuggestion(value, suggestionEl);
|
||||
suggestionEls.push(suggestionEl);
|
||||
});
|
||||
|
||||
this.values = values;
|
||||
this.suggestions = suggestionEls;
|
||||
this.setSelectedItem(0, false);
|
||||
}
|
||||
|
||||
useSelectedItem(event: MouseEvent | KeyboardEvent) {
|
||||
const currentValue = this.values[this.selectedItem];
|
||||
if (currentValue) {
|
||||
this.owner.selectSuggestion(currentValue, event);
|
||||
}
|
||||
}
|
||||
|
||||
setSelectedItem(selectedIndex: number, scrollIntoView: boolean) {
|
||||
const normalizedIndex = wrapAround(
|
||||
selectedIndex,
|
||||
this.suggestions.length
|
||||
);
|
||||
const prevSelectedSuggestion = this.suggestions[this.selectedItem];
|
||||
const selectedSuggestion = this.suggestions[normalizedIndex];
|
||||
|
||||
prevSelectedSuggestion?.removeClass('is-selected');
|
||||
selectedSuggestion?.addClass('is-selected');
|
||||
|
||||
this.selectedItem = normalizedIndex;
|
||||
|
||||
if (scrollIntoView) {
|
||||
selectedSuggestion.scrollIntoView(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class TextInputSuggest<T> implements ISuggestOwner<T> {
|
||||
protected inputEl: HTMLInputElement | HTMLTextAreaElement;
|
||||
|
||||
private popper: PopperInstance;
|
||||
private scope: Scope;
|
||||
private suggestEl: HTMLElement;
|
||||
private suggest: Suggest<T>;
|
||||
plugin: FolderNotesPlugin;
|
||||
|
||||
constructor(inputEl: HTMLInputElement | HTMLTextAreaElement, plugin: FolderNotesPlugin) {
|
||||
this.inputEl = inputEl;
|
||||
this.plugin = plugin;
|
||||
this.scope = new Scope();
|
||||
|
||||
this.suggestEl = createDiv('suggestion-container');
|
||||
const suggestion = this.suggestEl.createDiv('suggestion');
|
||||
this.suggest = new Suggest(this, suggestion, this.scope);
|
||||
|
||||
this.scope.register([], 'Escape', this.close.bind(this));
|
||||
|
||||
this.inputEl.addEventListener('input', this.onInputChanged.bind(this));
|
||||
this.inputEl.addEventListener('focus', this.onInputChanged.bind(this));
|
||||
this.inputEl.addEventListener('blur', this.close.bind(this));
|
||||
this.suggestEl.on(
|
||||
'mousedown',
|
||||
'.suggestion-container',
|
||||
(event: MouseEvent) => {
|
||||
event.preventDefault();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
onInputChanged(): void {
|
||||
const inputStr = this.inputEl.value;
|
||||
const suggestions = this.getSuggestions(inputStr);
|
||||
|
||||
if (!suggestions) {
|
||||
this.close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (suggestions.length > 0) {
|
||||
this.suggest.setSuggestions(suggestions);
|
||||
// @ts-ignore
|
||||
this.open(app.dom.appContainerEl, this.inputEl);
|
||||
} else {
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
||||
open(container: HTMLElement, inputEl: HTMLElement): void {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
this.plugin.app.keymap.pushScope(this.scope);
|
||||
|
||||
container.appendChild(this.suggestEl);
|
||||
this.popper = createPopper(inputEl, this.suggestEl, {
|
||||
placement: 'bottom-start',
|
||||
modifiers: [
|
||||
{
|
||||
name: 'sameWidth',
|
||||
enabled: true,
|
||||
fn: ({ state, instance }) => {
|
||||
// Note: positioning needs to be calculated twice -
|
||||
// first pass - positioning it according to the width of the popper
|
||||
// second pass - position it with the width bound to the reference element
|
||||
// we need to early exit to avoid an infinite loop
|
||||
const targetWidth = `${state.rects.reference.width}px`;
|
||||
if (state.styles.popper.width === targetWidth) {
|
||||
return;
|
||||
}
|
||||
state.styles.popper.width = targetWidth;
|
||||
instance.update();
|
||||
},
|
||||
phase: 'beforeWrite',
|
||||
requires: ['computeStyles'],
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
close(): void {
|
||||
this.plugin.app.keymap.popScope(this.scope);
|
||||
|
||||
this.suggest.setSuggestions([]);
|
||||
if (this.popper) this.popper.destroy();
|
||||
this.suggestEl.detach();
|
||||
}
|
||||
|
||||
abstract getSuggestions(inputStr: string): T[];
|
||||
abstract renderSuggestion(item: T, el: HTMLElement): void;
|
||||
abstract selectSuggestion(item: T): void;
|
||||
}
|
||||
|
|
@ -1,24 +1,15 @@
|
|||
import { TFile, TFolder, Vault, AbstractInputSuggest, type TAbstractFile } from 'obsidian';
|
||||
import type FolderNotesPlugin from '../main';
|
||||
import { TAbstractFile, TFile, TFolder, Vault, AbstractInputSuggest } from 'obsidian';
|
||||
import FolderNotesPlugin from '../main';
|
||||
import { getTemplatePlugins } from 'src/template';
|
||||
|
||||
interface TemplateSuggestion {
|
||||
path: string;
|
||||
name: string;
|
||||
parent?: {
|
||||
path: string;
|
||||
} | null;
|
||||
}
|
||||
|
||||
export enum FileSuggestMode {
|
||||
TemplateFiles,
|
||||
ScriptFiles,
|
||||
TemplateFiles,
|
||||
ScriptFiles,
|
||||
}
|
||||
|
||||
export class TemplateSuggest extends AbstractInputSuggest<TemplateSuggestion> {
|
||||
export class TemplateSuggest extends AbstractInputSuggest<TFile> {
|
||||
constructor(
|
||||
public inputEl: HTMLInputElement,
|
||||
public plugin: FolderNotesPlugin,
|
||||
public inputEl: HTMLInputElement,
|
||||
public plugin: FolderNotesPlugin
|
||||
) {
|
||||
super(plugin.app, inputEl);
|
||||
}
|
||||
|
|
@ -33,39 +24,24 @@ export class TemplateSuggest extends AbstractInputSuggest<TemplateSuggestion> {
|
|||
}
|
||||
}
|
||||
|
||||
getSuggestions(input_str: string): TemplateSuggestion[] {
|
||||
getSuggestions(input_str: string): TFile[] {
|
||||
const { templateFolder, templaterPlugin } = getTemplatePlugins(this.app);
|
||||
|
||||
let files: TemplateSuggestion[] = [];
|
||||
let files: TFile[] = [];
|
||||
const lower_input_str = input_str.toLowerCase();
|
||||
|
||||
if ((!templateFolder || templateFolder.trim() === '') && !templaterPlugin) {
|
||||
files = this.plugin.app.vault.getFiles().filter((file) =>
|
||||
file.path.toLowerCase().includes(lower_input_str),
|
||||
file.path.toLowerCase().includes(lower_input_str)
|
||||
);
|
||||
} else {
|
||||
let folder: TFolder | TAbstractFile | null = null;
|
||||
let folder: TFolder;
|
||||
if (templaterPlugin) {
|
||||
folder = this.plugin.app.vault.getAbstractFileByPath(
|
||||
(templaterPlugin as unknown as {
|
||||
plugin?: { settings?: { templates_folder?: string } }
|
||||
}).plugin?.settings?.templates_folder as string,
|
||||
);
|
||||
if (!(folder instanceof TFolder)) {
|
||||
return [
|
||||
{
|
||||
path: '',
|
||||
name:
|
||||
'You need to set the Templates folder in the Templater settings first.',
|
||||
},
|
||||
];
|
||||
}
|
||||
} else if (templateFolder) {
|
||||
folder = this.plugin.app.vault.getAbstractFileByPath(templateFolder);
|
||||
}
|
||||
|
||||
if (!(folder instanceof TFolder)) {
|
||||
return [];
|
||||
templaterPlugin.plugin?.settings?.templates_folder as string
|
||||
) as TFolder;
|
||||
} else {
|
||||
folder = this.plugin.app.vault.getAbstractFileByPath(templateFolder) as TFolder;
|
||||
}
|
||||
|
||||
Vault.recurseChildren(folder, (file: TAbstractFile) => {
|
||||
|
|
@ -79,7 +55,7 @@ export class TemplateSuggest extends AbstractInputSuggest<TemplateSuggestion> {
|
|||
}
|
||||
|
||||
|
||||
renderSuggestion(file: TemplateSuggestion, el: HTMLElement): void {
|
||||
renderSuggestion(file: TFile, el: HTMLElement): void {
|
||||
const { templateFolder, templaterPlugin } = getTemplatePlugins(this.app);
|
||||
|
||||
if ((!templateFolder || templateFolder.trim() === '') && !templaterPlugin) {
|
||||
|
|
@ -90,11 +66,11 @@ export class TemplateSuggest extends AbstractInputSuggest<TemplateSuggestion> {
|
|||
}
|
||||
|
||||
|
||||
selectSuggestion(file: TemplateSuggestion): void {
|
||||
selectSuggestion(file: TFile): void {
|
||||
this.inputEl.value = file.name.replace('.md', '');
|
||||
this.inputEl.trigger('input');
|
||||
this.plugin.settings.templatePath = file.path;
|
||||
void this.plugin.saveSettings();
|
||||
this.plugin.saveSettings();
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,46 +1,12 @@
|
|||
import { TFile, WorkspaceLeaf, type App } from 'obsidian';
|
||||
import type FolderNotesPlugin from './main';
|
||||
|
||||
interface TemplatesPlugin {
|
||||
enabled: boolean;
|
||||
instance: {
|
||||
options: {
|
||||
folder: string;
|
||||
};
|
||||
insertTemplate: (templateFile: TFile) => Promise<void>;
|
||||
};
|
||||
}
|
||||
|
||||
interface TemplaterPlugin {
|
||||
settings?: {
|
||||
empty_file_template?: string;
|
||||
template_folder?: string;
|
||||
};
|
||||
templater?: {
|
||||
write_template_to_file: (templateFile: TFile, targetFile: TFile) => Promise<void>;
|
||||
};
|
||||
}
|
||||
|
||||
interface TemplatePluginReturn {
|
||||
templatesPlugin: TemplatesPlugin | null;
|
||||
templatesEnabled: boolean;
|
||||
templaterPlugin: TemplaterPlugin['templater'] | null;
|
||||
templaterEnabled: boolean;
|
||||
templaterEmptyFileTemplate?: string;
|
||||
templateFolder?: string;
|
||||
}
|
||||
import { TFile, App, WorkspaceLeaf } from 'obsidian';
|
||||
import FolderNotesPlugin from './main';
|
||||
|
||||
export async function applyTemplate(
|
||||
plugin: FolderNotesPlugin,
|
||||
file: TFile,
|
||||
leaf?: WorkspaceLeaf | null,
|
||||
templatePath?: string,
|
||||
): Promise<void> {
|
||||
const fileContent = await plugin.app.vault.read(file).catch((err) => {
|
||||
console.error(`Error reading file ${file.path}:`, err);
|
||||
});
|
||||
if (fileContent !== '') return;
|
||||
|
||||
templatePath?: string
|
||||
) {
|
||||
const templateFile = templatePath
|
||||
? plugin.app.vault.getAbstractFileByPath(templatePath)
|
||||
: null;
|
||||
|
|
@ -54,22 +20,21 @@ export async function applyTemplate(
|
|||
templaterPlugin,
|
||||
} = getTemplatePlugins(plugin.app);
|
||||
const templateContent = await plugin.app.vault.read(templateFile);
|
||||
// eslint-disable-next-line max-len
|
||||
if (templateContent.includes('==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this activeDocument. ⚠==')) {
|
||||
if (templateContent.includes('==⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠==')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prioritize Templater if both plugins are enabled
|
||||
if (templaterEnabled && templaterPlugin) {
|
||||
if (templaterEnabled) {
|
||||
return await templaterPlugin.write_template_to_file(templateFile, file);
|
||||
} else if (templatesEnabled && templatesPlugin) {
|
||||
} else if (templatesEnabled) {
|
||||
if (leaf instanceof WorkspaceLeaf) {
|
||||
await leaf.openFile(file);
|
||||
}
|
||||
return await templatesPlugin.instance.insertTemplate(templateFile);
|
||||
} else {
|
||||
await plugin.app.vault.modify(file, templateContent);
|
||||
}
|
||||
await plugin.app.vault.modify(file, templateContent);
|
||||
|
||||
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
|
@ -77,37 +42,23 @@ export async function applyTemplate(
|
|||
}
|
||||
}
|
||||
|
||||
export function getTemplatePlugins(app: App): TemplatePluginReturn {
|
||||
const appAsUnknown = app as unknown as {
|
||||
internalPlugins: {
|
||||
plugins: {
|
||||
templates: TemplatesPlugin;
|
||||
};
|
||||
};
|
||||
plugins: {
|
||||
plugins: {
|
||||
'templater-obsidian': TemplaterPlugin;
|
||||
};
|
||||
enabledPlugins: Set<string>;
|
||||
};
|
||||
};
|
||||
|
||||
const templatesPlugin = appAsUnknown.internalPlugins.plugins.templates;
|
||||
const templatesEnabled = templatesPlugin?.enabled ?? false;
|
||||
const templaterPlugin = appAsUnknown.plugins.plugins['templater-obsidian'];
|
||||
const templaterEnabled = appAsUnknown.plugins.enabledPlugins.has('templater-obsidian');
|
||||
export function getTemplatePlugins(app: App) {
|
||||
const templatesPlugin = (app as any).internalPlugins.plugins.templates;
|
||||
const templatesEnabled = templatesPlugin.enabled;
|
||||
const templaterPlugin = (app as any).plugins.plugins['templater-obsidian'];
|
||||
const templaterEnabled = (app as any).plugins.enabledPlugins.has('templater-obsidian');
|
||||
|
||||
const templaterEmptyFileTemplate =
|
||||
templaterPlugin && templaterPlugin.settings?.empty_file_template;
|
||||
|
||||
const templateFolder = templatesEnabled
|
||||
? templatesPlugin.instance.options.folder
|
||||
: templaterPlugin?.settings?.template_folder;
|
||||
: templaterPlugin?.settings.template_folder;
|
||||
|
||||
return {
|
||||
templatesPlugin: templatesPlugin || null,
|
||||
templatesPlugin,
|
||||
templatesEnabled,
|
||||
templaterPlugin: templaterPlugin?.templater || null,
|
||||
templaterPlugin: templaterPlugin?.templater,
|
||||
templaterEnabled,
|
||||
templaterEmptyFileTemplate,
|
||||
templateFolder,
|
||||
|
|
|
|||
244
styles.css
|
|
@ -1,40 +1,36 @@
|
|||
/* ==========================================================================
|
||||
General States & Utilities
|
||||
========================================================================== */
|
||||
|
||||
.hide,
|
||||
.hide-folder .folder-name,
|
||||
.hide-folder-note .is-folder-note {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* make.md plugin integration */
|
||||
.hide-folder-note .mk-tree-node > .mk-tree-wrapper > .dropzone > .mk-tree-item.is-folder-note {
|
||||
opacity: 40%;
|
||||
.fn-whitespace-stop-collapsing .nav-folder-title-content {
|
||||
flex-grow: 1 !important;
|
||||
display: flex;
|
||||
padding-bottom: 4px !important;
|
||||
padding-top: 4px !important;
|
||||
}
|
||||
|
||||
.pointer-cursor,
|
||||
.has-folder-note .nav-folder-title-content:hover,
|
||||
.has-folder-note.view-header-breadcrumb:hover,
|
||||
.nav-folder-collapse-indicator:hover,
|
||||
.fn-delete-confirmation-modal-buttons span:hover,
|
||||
.fn-delete-confirmation-modal-buttons input:hover {
|
||||
cursor: pointer !important;
|
||||
.version-1-7-2.fn-whitespace-stop-collapsing .nav-files-container .collapse-icon {
|
||||
padding-top: 4px !important;
|
||||
}
|
||||
|
||||
.hide-folder-note :not(.show-folder-note-in-explorer):not(.fn-has-attachment-folder).only-has-folder-note .nav-folder-children {
|
||||
display: none !important;
|
||||
.mod-rtl .fn-whitespace-stop-collapsing .nav-folder-title-content {
|
||||
padding-left: 8px !important;
|
||||
}
|
||||
|
||||
|
||||
.fn-warning-text {
|
||||
color: #fb464c
|
||||
.fn-whitespace-stop-collapsing .nav-folder-title {
|
||||
padding-bottom: 0 !important;
|
||||
padding-top: 0 !important;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Tree Items
|
||||
========================================================================== */
|
||||
body:not(.mod-rtl).fn-whitespace-stop-collapsing .nav-folder-title {
|
||||
padding-right: 0 !important;
|
||||
}
|
||||
|
||||
.mod-rtl.fn-whitespace-stop-collapsing .nav-folder-title {
|
||||
padding-left: 0 !important;
|
||||
}
|
||||
|
||||
.fn-whitespace-stop-collapsing .nav-folder-collapse-indicator {
|
||||
margin-top: 4px !important;
|
||||
}
|
||||
|
||||
body:not(.is-grabbing) .tree-item-self.fn-is-active:hover,
|
||||
body:not(.disable-folder-highlight) .tree-item-self.fn-is-active {
|
||||
|
|
@ -43,17 +39,36 @@ body:not(.disable-folder-highlight) .tree-item-self.fn-is-active {
|
|||
font-weight: var(--nav-item-weight-active);
|
||||
}
|
||||
|
||||
.has-folder-note .nav-folder-title-content:hover,
|
||||
.has-folder-note.view-header-breadcrumb:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* ==========================================================================
|
||||
Exclude Folder Settings
|
||||
========================================================================== */
|
||||
.hide {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.hide-folder-note .is-folder-note {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.hide-folder .folder-name {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.nav-folder-collapse-indicator:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.fn-excluded-folder-heading {
|
||||
margin-top: 0 !important;
|
||||
border-top: 1px solid var(--background-modifier-border);
|
||||
}
|
||||
|
||||
.add-exclude-folder-item,
|
||||
.add-exclude-folder-item {
|
||||
padding-bottom: 0 !important;
|
||||
}
|
||||
|
||||
.fn-exclude-folder-list {
|
||||
padding-bottom: 0 !important;
|
||||
}
|
||||
|
|
@ -76,10 +91,7 @@ body:not(.disable-folder-highlight) .tree-item-self.fn-is-active {
|
|||
width: 100%;
|
||||
}
|
||||
|
||||
|
||||
/* ==========================================================================
|
||||
Modal Styles
|
||||
========================================================================== */
|
||||
/* Modal styles */
|
||||
|
||||
.fn-backup-warning-modal .fn-modal-button-container {
|
||||
display: flex;
|
||||
|
|
@ -91,13 +103,9 @@ body:not(.disable-folder-highlight) .tree-item-self.fn-is-active {
|
|||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.fn-confirmation-modal .setting-item {
|
||||
border-top: 0 !important;
|
||||
padding-top: 0 !important;
|
||||
}
|
||||
|
||||
:not(.is-phone) .fn-confirmation-modal-button {
|
||||
margin-right: 0.7rem;
|
||||
|
||||
}
|
||||
|
||||
:not(.is-phone) .fn-delete-confirmation-modal-buttons {
|
||||
|
|
@ -106,6 +114,11 @@ body:not(.disable-folder-highlight) .tree-item-self.fn-is-active {
|
|||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.fn-delete-confirmation-modal-buttons span:hover,
|
||||
.fn-delete-confirmation-modal-buttons input:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
:not(.is-phone) .fn-delete-confirmation-modal-buttons .fn-confirmation-modal-button {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
|
@ -124,24 +137,19 @@ body:not(.disable-folder-highlight) .tree-item-self.fn-is-active {
|
|||
margin-top: 10px;
|
||||
}
|
||||
|
||||
|
||||
/* ==========================================================================
|
||||
Folder Overview
|
||||
========================================================================== */
|
||||
/* Folder overview */
|
||||
|
||||
.folder-overview-container.fv-remove-edit-button .folder-overview-edit-button {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.cm-line:has(.fv-link-list-item),
|
||||
li:has(.fv-link-list-item),
|
||||
.el-ul:has(.fv-link-list-item),
|
||||
.cm-line:has(.fv-link-list-start),
|
||||
.cm-line:has(.fv-link-list-end),
|
||||
.fv-hide-overview {
|
||||
display: none !important;
|
||||
.fn-folder-overview-collapse-icon {
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
.fn-has-no-files .collapse-icon {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.folder-overview-list {
|
||||
margin-top: 0 !important;
|
||||
|
|
@ -154,6 +162,7 @@ li:has(.fv-link-list-item),
|
|||
display: flex;
|
||||
}
|
||||
|
||||
|
||||
.folder-overview-list::marker {
|
||||
color: var(--text-faint);
|
||||
}
|
||||
|
|
@ -168,17 +177,12 @@ li:has(.fv-link-list-item),
|
|||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
|
||||
.folder-overview-grid-item {
|
||||
flex: 1 1 auto;
|
||||
margin: 0 1.2rem 1.2rem 0;
|
||||
}
|
||||
|
||||
.folder-overview-grid-item-article article {
|
||||
padding: 15px;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
padding: 15px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.folder-overview-grid-item-article a {
|
||||
|
|
@ -200,9 +204,52 @@ li:has(.fv-link-list-item),
|
|||
}
|
||||
|
||||
|
||||
/* ==========================================================================
|
||||
File Explorer & Path Styling
|
||||
========================================================================== */
|
||||
.folder-overview-grid-item {
|
||||
flex: 1 1 auto;
|
||||
margin-right: 1.200rem;
|
||||
margin-bottom: 1.200rem;
|
||||
}
|
||||
|
||||
.fn-confirmation-modal .setting-item {
|
||||
border-top: 0 !important;
|
||||
padding-top: 0 !important;
|
||||
}
|
||||
|
||||
.pointer-cursor {
|
||||
cursor: pointer !important;
|
||||
}
|
||||
|
||||
|
||||
/* Setting tab style */
|
||||
.fn-settings-tab-bar {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
padding-bottom: 1rem;
|
||||
}
|
||||
|
||||
.fn-settings-tab {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: var(--size-4-2);
|
||||
padding: 10px;
|
||||
border: 1px solid var(--background-modifier-border)
|
||||
}
|
||||
|
||||
.fn-settings-tab-active {
|
||||
background-color: var(--color-accent);
|
||||
color: var(--text-on-accent);
|
||||
}
|
||||
|
||||
.fn-settings-tab-name {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.fn-settings-tab-icon {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
/* File explorer & path styles */
|
||||
|
||||
.folder-note-underline .has-folder-note .nav-folder-title-content {
|
||||
text-decoration-line: underline;
|
||||
|
|
@ -227,66 +274,16 @@ li:has(.fv-link-list-item),
|
|||
.folder-note-cursive-path .has-folder-note.view-header-breadcrumb {
|
||||
font-style: italic;
|
||||
}
|
||||
.folder-note-hide-name-path .hide-folder-note-title-in-path .is-last-separator,
|
||||
.folder-note-hide-name-path .hide-folder-note-title-in-path .path-is-folder-note {
|
||||
|
||||
.fn-hide-collapse-icon .has-folder-note.only-has-folder-note .tree-item-icon {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
/* Collapse Icon Handling */
|
||||
|
||||
.fn-folder-overview-collapse-icon {
|
||||
display: block !important;
|
||||
}
|
||||
|
||||
.fn-has-no-files .collapse-icon,
|
||||
.fn-hide-collapse-icon .has-folder-note.only-has-folder-note .tree-item-icon,
|
||||
body.fn-hide-collapse-icon.fn-ignore-attachment-folder .only-has-folder-note .fn-empty-folder.fn-has-attachment-folder .tree-item-icon,
|
||||
body.fn-hide-collapse-icon .only-has-folder-note .fn-empty-folder:not(.fn-has-attachment-folder) .tree-item-icon,
|
||||
body.fn-hide-empty-collapse-icon :not(.only-has-folder-note) > .fn-empty-folder:not(.fn-has-attachment-folder) .tree-item-icon,
|
||||
body.fn-hide-collapse-icon.only-has-folder-note:not(.is-collapsed):not(.show-folder-note-in-explorer)>.nav-folder-children {
|
||||
.fn-hide-empty-collapse-icon .fn-empty-folder .tree-item-icon {
|
||||
display: none;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ==========================================================================
|
||||
Settings Tabs
|
||||
========================================================================== */
|
||||
|
||||
.fn-settings-tab-bar {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
padding-bottom: 1rem;
|
||||
}
|
||||
|
||||
.fn-settings-tab {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: var(--size-4-2);
|
||||
padding: 10px;
|
||||
border: 1px solid var(--background-modifier-border);
|
||||
}
|
||||
|
||||
.fn-settings-tab-active {
|
||||
background-color: var(--color-accent);
|
||||
color: var(--text-on-accent);
|
||||
}
|
||||
|
||||
.fn-settings-tab-name {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.fn-settings-tab-icon {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
|
||||
/* ==========================================================================
|
||||
Suggestion Container
|
||||
========================================================================== */
|
||||
|
||||
.fn-suggestion-container {
|
||||
position: absolute;
|
||||
overflow: hidden;
|
||||
|
|
@ -302,11 +299,12 @@ body.fn-hide-collapse-icon.only-has-folder-note:not(.is-collapsed):not(.show-fol
|
|||
}
|
||||
|
||||
|
||||
/* ==========================================================================
|
||||
Whitelist Folder Input (Desktop & Mobile)
|
||||
========================================================================== */
|
||||
/* Mobile style overrides */
|
||||
.is-phone .fn-overview-folder-path .setting-item-control{
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Default Desktop Layout */
|
||||
/* Default desktop layout */
|
||||
.fn-whitelist-folder-input-container {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
|
|
@ -318,9 +316,9 @@ body.fn-hide-collapse-icon.only-has-folder-note:not(.is-collapsed):not(.show-fol
|
|||
.fn-whitelist-folder-input-container input {
|
||||
flex-grow: 1;
|
||||
width: auto;
|
||||
margin-right: 8px;
|
||||
height: 40px;
|
||||
box-sizing: border-box;
|
||||
margin-right: 8px;
|
||||
height: 40px; /* Ensure consistent height */
|
||||
}
|
||||
|
||||
.fn-whitelist-folder-buttons {
|
||||
|
|
@ -332,12 +330,12 @@ body.fn-hide-collapse-icon.only-has-folder-note:not(.is-collapsed):not(.show-fol
|
|||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* Mobile Overrides */
|
||||
/* Mobile-specific layout */
|
||||
@media (max-width: 768px) {
|
||||
.fn-whitelist-folder-input-container {
|
||||
display: block;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
text-align: center; /* Center elements vertically when stacked */
|
||||
}
|
||||
|
||||
.fn-whitelist-folder-input-container input {
|
||||
|
|
@ -352,8 +350,4 @@ body.fn-hide-collapse-icon.only-has-folder-note:not(.is-collapsed):not(.show-fol
|
|||
align-items: center;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.is-phone .fn-overview-folder-path .setting-item-control {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"ignoreDeprecations": "6.0",
|
||||
"baseUrl": ".",
|
||||
"inlineSourceMap": true,
|
||||
"inlineSources": true,
|
||||
"module": "node16",
|
||||
"module": "ESNext",
|
||||
"target": "ES6",
|
||||
"allowJs": true,
|
||||
"noImplicitAny": true,
|
||||
"moduleResolution": "node16",
|
||||
"moduleResolution": "node",
|
||||
"importHelpers": true,
|
||||
"isolatedModules": true,
|
||||
"strictNullChecks": true,
|
||||
|
|
@ -18,10 +17,7 @@
|
|||
"ES6",
|
||||
"ES7",
|
||||
"ES2021"
|
||||
],
|
||||
"paths": {
|
||||
"@app/*": ["./src/*"]
|
||||
}
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"**/*.ts"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
/* eslint-disable no-undef */
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
|
||||
const targetVersion = process.env.npm_package_version;
|
||||
|
|
|
|||