@@ -28,41 +28,54 @@ const expandFolders = async (folders) => {
2828}
2929
3030const activate = ( context ) => {
31- let disposable = commands . registerCommand (
32- "vscode-textmate.openProject" ,
33- async ( ) => {
31+ context . subscriptions . push (
32+ commands . registerCommand ( "vscode-textmate.openProject" , async ( ) => {
3433 const settings = workspace . getConfiguration ( "vscode-textmate" )
35- // let recentProjects = settings.get("recentProjects") || []
36- let recentProjects = context . globalState . get ( "recentProjects" ) || [ ]
37- const folders = settings . get ( "projectFolders" ) || [ ]
34+
35+ const currentFolders = workspace ?. workspaceFolders ?. map (
36+ ( f ) => f . uri ?. path ,
37+ )
38+ let recentFolders = (
39+ context . globalState . get ( "recentFolders" ) || [ ]
40+ ) . filter ( ( p ) => ! currentFolders . includes ( p ) )
41+
3842 const iconPath = new ThemeIcon ( "folder" )
39- const currentWorkspaceFolder = workspace ?. workspaceFolders ?. [ 0 ] ?. uri ?. path
40- const projects = ( await expandFolders ( folders ) )
41- . sort ( ( a , b ) => {
42- if ( currentWorkspaceFolder && currentWorkspaceFolder === a ) return - 1
43- if ( recentProjects . indexOf ( a ) > recentProjects . indexOf ( b ) ) return 1
44- return - 1
45- } )
46- . reverse ( )
47- . flatMap ( ( pathname ) => {
48- const entries = [ ]
49- if ( recentProjects . indexOf ( pathname ) > - 1 )
50- entries . push ( { label : "Recent" , kind : QuickPickItemKind . Separator } )
5143
52- entries . push ( {
44+ const favoritesFolders = (
45+ await expandFolders ( settings . get ( "projectFolders" ) || [ ] )
46+ )
47+ . flat ( )
48+ . filter ( ( p ) => ! recentFolders . includes ( p ) )
49+ . filter ( ( p ) => ! currentFolders . includes ( p ) )
50+ . sort ( ( a , b ) =>
51+ path
52+ . basename ( a )
53+ . toLowerCase ( )
54+ . localeCompare ( path . basename ( b ) . toLowerCase ( ) ) ,
55+ )
56+
57+ const items = [ ]
58+ const addItems = ( label , pathnames ) => {
59+ if ( pathnames . length === 0 ) return
60+ items . push ( { label, kind : QuickPickItemKind . Separator } )
61+ pathnames . forEach ( ( pathname ) =>
62+ items . push ( {
5363 label : path . basename ( pathname ) ,
5464 description : path . dirname ( pathname ) ,
5565 pathname,
5666 iconPath,
57- } )
67+ } ) ,
68+ )
69+ }
5870
59- return entries
60- } )
71+ addItems ( "Recent" , recentFolders )
72+ addItems ( "Favorites" , favoritesFolders )
73+ addItems ( "Current" , currentFolders )
6174
62- projects . push ( { label : ADD } )
63- console . debug ( { projects } )
75+ items . push ( { label : ADD } )
76+ console . debug ( { recentFolders , favoritesFolders , currentFolders } )
6477
65- const pick = await window . showQuickPick ( projects , {
78+ const pick = await window . showQuickPick ( items , {
6679 title : "Open Recent Project" ,
6780 matchOnDescription : true ,
6881 matchOnDetail : true ,
@@ -88,12 +101,9 @@ const activate = (context) => {
88101 }
89102 } else if ( pick . pathname ) {
90103 const pathname = pick . pathname //path.join(pick.detail, pick.label)
91- recentProjects = recentProjects . filter (
92- ( x , i ) => x !== pathname && i < 10 ,
93- )
94- recentProjects . push ( pathname )
95- // settings.update("recentProjects", recentProjects, true)
96- context . globalState . update ( "recentProjects" , recentProjects )
104+ recentFolders = recentFolders . filter ( ( x , i ) => x !== pathname && i < 10 )
105+ recentFolders . push ( pathname )
106+ context . globalState . update ( "recentFolders" , recentFolders )
97107
98108 const uri = Uri . file ( pathname )
99109 if ( ! workspace . workspaceFolders ) {
@@ -104,9 +114,8 @@ const activate = (context) => {
104114 } )
105115 }
106116 }
107- } ,
117+ } ) ,
108118 )
109- context . subscriptions . push ( disposable )
110119}
111120
112121const deactivate = ( ) => { }
0 commit comments