SebastianMC / obsidian-custom-sort

Take full control over the order and sorting of folders and notes in File Explorer in Obsidian
GNU General Public License v3.0
255 stars 19 forks source link

Integration with obsidian-icon-folder #60

Closed a-rock-lobster closed 9 months ago

a-rock-lobster commented 1 year ago

Hullo,

I have no idea how feasible or challenging this would be but I thought it would useful if it were possible to specify a file or folder icon (perhaps via the icons name) in the sortspec.

I have been using these icons to help me scan through my list of files. https://github.com/FlorianWoelki/obsidian-icon-folder

For example, one might use the bookmark icon to indicate certain files are book chapters or sections and maybe it would be helpful for them to cluster together (then I imagine alpha-numeric would kick in to order the cluster).

Just a thought.

Thanks for sharing your work,

SebastianMC commented 1 year ago

Hi @a-rock-lobster,

I'm also a user of obsidian-icon-folder and thus I know how it works from UI side, user perspective I've quickly examined internals of that plugin and it looks it exposes the data necessary to group items in File Explorer by the custom sort plugin. So far so good. The potential challenge could be how the user knows the exact name of icon to enter in sortspec YAML. For example, the visually selected icon AlarmLine of the (Ri) pack is internally stored (by the obsidian-icon-folder) under the name RiAlarmLine.

thanks for your suggestion! It looks like it could be turned into a new feature of the custom sort plugin

BTW I'll become unavailable for about two weeks from now, thus not responding in this thread

a-rock-lobster commented 1 year ago

Super, thanks for following up so quickly!

I think that if the icon names are atleast consistant that shouldn't be a problem i.e. if the icon pack name, such as Ri, is always at the front as in your example.

SebastianMC commented 1 year ago

Hi @a-rock-lobster,

I did a deep dive research of how the obsidian-icon-folder works and I found it troublesome to determine if an item display an icon in File Explorer. This is because the icon can be displayed as a result of any of the below conditions:

For me it looks that the integration with obsidian-icon-folder plugin should be done in a fully-fledged fashion, that is handling of all (A), (B), (C) and (D) cases. Partial integration (e.g. ignoring the (D) case) would result in a behavior confusing to the user: s/he sees an icon on an item in Folder Explorer and at the same time the item is ignored by a seemingly correct custom sorting-spec.

In turn, knowing that the custom sorting plugin should correctly recognize (A), (B), (C) and (D) cases means that the logic of obsidian-icon-folder plugin should be reproduced, especially for (D). This is definitely not the way to go.

I will inquiry with the author of obsidian-icon-folder plugin (@FlorianWoelki) if he can expose some simple integration API on his plugin to be consumed by other plugins (like custom sorting). Seeing the long list of open tickets of 'obsidian-icon-folder' doesn't look promising.

Anyways, the next step is to open a new ticket there asking for exposing of the new API for integration.

FlorianWoelki commented 1 year ago

Hi @a-rock-lobster,

I did a deep dive research of how the obsidian-icon-folder works and I found it troublesome to determine if an item display an icon in File Explorer. This is because the icon can be displayed as a result of any of the below conditions:

  • (A) icon configured directly on the folder or file -> handling is easy peasy lemon squeezy

  • (B) icon configured on a parent folder as 'inherit icon' -> handling is easy peasy as well

  • (C) icon configured on some (any) of ancestor folders as 'inherit icon' -> mhm... things are getting not so trivial

  • (D) icon configured in plugin settings 'Custom Icon Rules' via a regexp or string pattern with an additional designation to match folders, files or both -> here begins the horror

For me it looks that the integration with obsidian-icon-folder plugin should be done in a fully-fledged fashion, that is handling of all (A), (B), (C) and (D) cases. Partial integration (e.g. ignoring the (D) case) would result in a behavior confusing to the user: s/he sees an icon on an item in Folder Explorer and at the same time the item is ignored by a seemingly correct custom sorting-spec.

In turn, knowing that the custom sorting plugin should correctly recognize (A), (B), (C) and (D) cases means that the logic of obsidian-icon-folder plugin should be reproduced, especially for (D). This is definitely not the way to go.

I will inquiry with the author of obsidian-icon-folder plugin (@FlorianWoelki) if he can expose some simple integration API on his plugin to be consumed by other plugins (like custom sorting). Seeing the long list of open tickets of 'obsidian-icon-folder' doesn't look promising.

Anyways, the next step is to open a new ticket there asking for exposing of the new API for integration.

Hey,

I have currently other priorities, that's why the amount of open issues are quite huge :D However, I was also thinking about that and creating an issue in my repository would make sense.

SebastianMC commented 1 year ago

Hi @FlorianWoelki

here you go with the technical feature request: #155: [Technical feature request] Expose synchronous API function - getting icon name by path of folder or file

At the same time, to proceed with the integration I will employ a simple approach here in File Explorer Custom Sorting plugin: read the basic data of the obsidian-icon-folder plugin - icon names configured directly as strings or in the iconName field of FolderIconObject structure. This integration approach would obviously break upon any related internal change of obsidian-icon-folder plugin, yet for the interim it looks like a viable solution

SebastianMC commented 1 year ago

Hi @a-rock-lobster

the integration is completed and available in the 1.7.0 release of the plugin

For now only the icons configured explicitly (in obsidian-icon-folder) on folders and files are handled, no support for icons visible in result of inheritance or regexp-rules (for details see documentation of the mentioned plugin)

The syntax of sorting spec is based on the new token with-icon:, with or without parameters.

Basic examples:

---
sorting-spec: |
 target-folder: /
 with-icon:
---

The above example will push to the top of vault root folder all files and folders with icons configured via the obsidian-icon-folder plugin, directly on these folders and files. Items with icons will be sorted alphabetically (which is the default for the custom sort plugin)

---
sorting-spec: |
 target-folder: /
 /:files with-icon:
   > modified
---

The above example will push to the top of the vault root folder all files with icons configured via the obsidian-icon-folder plugin, directly on these folders and files. Notes with icons will be sorted by modification date ('freshness')

---
sorting-spec: |
 target-folder: Development
 with-icon: RiNumber9
 /files:folders
 with-icon: RiNumber1
   > advanced modified
 with-icon:
---

The above example is a bit more complex:

Note: to refresh the sorting after adding or removing icons on some folders and files you need to toggle the ribbon icon or issue the sort-on command in Obsidian commands palette

Please let me know if you have further questions.

BTW I'm also curious if you apply icons in your vault(s) via icon inheritance and regexp, or only via direct assignment on a file or folder.

a-rock-lobster commented 1 year ago

Hi @SebastianMC,

This is awesome! Thank you for putting in so much work. It's really appreciated 🙏

I do use some regexp but mostly it's direct assignment. I can imagine a use case when regexp working be nice but the implementation already is super helpful.

Thanks again!

(deleted last after posting because I realised I had gotten confused - still working out the more advanced ways of using the sortspec)

danteali commented 1 year ago

Sorry for commenting on a closed issue but I've just installed the Icon Folder plugin as I saw that you added support.

I could be missing something completely obvious, but in the current version of Icon Folder it looks like it's no longer possible to determine the icon name in the format used by Custom Sort. When I assign an icon it displays the name of the descriptive name of the icon (e.g. Ubuntu (Fab)) instead of the IconPackNumber## which Custom Sort appears to use.

Any idea how I can find the correct icon name to be able to sort on it?

SebastianMC commented 1 year ago

Hi @danteali,

the name of the icon to use in sorting spec comprises the pack short name concatenated with the icon name. For example:

I'm aware that the documentation is still missing for this particular area :-|

This works with the most recent (1.7.0) release of Icon Folder plugin

a-rock-lobster commented 9 months ago

Hi, @SebastianMC

I think that the latest update might have broken the with-icon: support? Atleast, it stopped working after I updated and I haven't been able to find any causes myself.

SebastianMC commented 9 months ago

Hi @a-rock-lobster,

thanks for the report, I will take a look as soon as possible

SebastianMC commented 9 months ago

A bug indeed, fixed in the recent 1.9.2 Please give it a try

a-rock-lobster commented 9 months ago

Looks good to me :) Cheers!