artemy / alfred-jetbrains-projects

Alfred workflow for opening your JetBrains IDEs projects
MIT License
96 stars 16 forks source link

Support removing projects from list #16

Open gaufde opened 5 days ago

gaufde commented 5 days ago

I think it would be really nice to support removing projects from the list directly in Alfred. Currently, I only know how to do that by going to File > Recent Projects > Manage Projects.... However, files that were opened in LightEdit mode do not appear there and they do appear in Alfred (in fact, I'm not really sure how to get rid of them at all.)

artemy commented 1 day ago

What's the use case for this? Is it only about not showing LightEdit mode files? I suppose we can just filter them entirely.

artemy commented 1 day ago

I see that LightEdit entries have a hidden attribute set to true, so I suppose IDE (and Toolbox) exclude them:

        <entry key="$APPLICATION_CONFIG_DIR$/light-edit">
          <value>
            <RecentProjectMetaInfo hidden="true">
              <option name="activationTimestamp" value="1732450057513" />
            </RecentProjectMetaInfo>
          </value>
        </entry>

To filter them out we can do something like this:

Index: recent_projects.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/recent_projects.py b/recent_projects.py
--- a/recent_projects.py    (revision 3323541b98730c7571a72c93e5e8c914e47fd2d1)
+++ b/recent_projects.py    (date 1732451510807)
@@ -107,7 +107,8 @@
 def read_projects_from_file(most_recent_projects_file):
     tree = ElementTree.parse(most_recent_projects_file)
     projects = [t.attrib['key'].replace('$USER_HOME$', "~") for t
-                in tree.findall(".//component[@name='RecentProjectsManager']/option[@name='additionalInfo']/map/entry")]
+                in tree.findall(".//component[@name='RecentProjectsManager']/option[@name='additionalInfo']/map/entry")
+                if t.find("value/RecentProjectMetaInfo[@hidden='true']") is None]
     return reversed(projects)

@@ -140,5 +141,6 @@
         print(f"The projects file for {sys.argv[1]} does not exist.")
         exit(1)

+
 if __name__ == "__main__":  # pragma: nocover
     main()

EDIT: Indeed, LightEdit projects are always set to hidden https://github.com/JetBrains/intellij-community/blob/a2ea418b84f865b9c272a45ec7b8330096bc7ace/platform/platform-impl/src/com/intellij/ide/lightEdit/project/LightEditProjectManager.kt#L71

I tried setting the flag to false and I saw both IDE and Toolbox show them.

gaufde commented 1 day ago

I think you are right that we should hide the LightEdits to be consistent with how JetBrains does it!

What's the use case for this? Is it only about not showing LightEdit mode files? I suppose we can just filter them entirely.

Even with LightEdit mode disabled, I think it would be pretty neat to be able to remove/manage projects using Alfred. Also, I wanted to see if it was even possible. So, I took a stab at creating a user flow that I think would be nice (heavily inspired by what I've seen @zeitlings do in https://github.com/zeitlings/ayai-gpt-nexus). The functionality isn't finished (nor are the tests), but if you press tab to autocomplete an item it should show you an alternate menu of options:

image

or:

image

Here is my branch for this feature: https://github.com/gaufde/alfred-jetbrains-projects/tree/support-removing-projects

artemy commented 18 hours ago

I think you are right that we should hide the LightEdits to be consistent with how JetBrains does it!

Perfect, I'll add support for this

I think it would be pretty neat to be able to remove/manage projects using Alfred

I'm not so keen on writing into another app config files. I have to think about this

gaufde commented 11 hours ago

I'm not so keen on writing into another app config files. I have to think about this

Ah, I understand the hesitation. I did make it so that Alfred would not be able to make any changes if the app in question is running. That should help, but I'm not sure if there are other considerations.

I did manually test deleting sections in the recentProjects file, and it seemed to work pretty well with no adverse effects. I'm not sure that's enough to say anything definitive, but at least I haven't found any major issues.