@@ -144,10 +144,30 @@ export default {
144144 // returns the _first_ action from actions array which we now construct from
145145 // available mime-types coming from the app-provider and existing actions
146146 $_fileActions_triggerDefaultAction ( resource ) {
147- const actions = this . $_fileActions_getAllAvailableActions ( resource ) . filter (
148- ( action ) => action . canBeDefault
149- )
150- actions [ 0 ] . handler ( resource , actions [ 0 ] . handlerData )
147+ const action = this . $_fileActions_getDefaultAction ( resource )
148+ action . handler ( resource , action . handlerData )
149+ } ,
150+
151+ $_fileActions_getDefaultAction ( resource ) {
152+ const filterCallback = ( action ) =>
153+ action . canBeDefault && action . isEnabled ( { resource, parent : this . currentFolder } )
154+
155+ // first priority: handlers from config
156+ const defaultEditorActions = this . $_fileActions_editorActions . filter ( filterCallback )
157+ if ( defaultEditorActions . length ) {
158+ return defaultEditorActions [ 0 ]
159+ }
160+
161+ // second priority: `/app/open` endpoint of app provider if available
162+ // FIXME: files app should not know anything about the `external apps` app
163+ const externalAppsActions =
164+ this . $_fileActions_loadExternalAppActions ( resource ) . filter ( filterCallback )
165+ if ( externalAppsActions . length ) {
166+ return externalAppsActions [ 0 ]
167+ }
168+
169+ // fallback: system actions
170+ return this . $_fileActions_systemActions . filter ( filterCallback )
151171 } ,
152172
153173 $_fileActions_getAllAvailableActions ( resource ) {
@@ -176,35 +196,40 @@ export default {
176196 return [ ]
177197 }
178198
179- const { app_providers : appProviders = [ ] } = this . mimeTypes . find (
180- ( t ) => t . mime_type === mimeType
181- )
199+ const { app_providers : appProviders = [ ] , default_application : defaultApplication } =
200+ this . mimeTypes . find ( ( t ) => t . mime_type === mimeType )
182201
183202 return appProviders . map ( ( app ) => {
184203 const label = this . $gettext ( 'Open in %{ appName }' )
185204 return {
205+ name : app . name ,
186206 img : app . icon ,
187207 componentType : 'oc-button' ,
188208 class : `oc-files-actions-${ app . name } -trigger` ,
189209 isEnabled : ( ) => true ,
190- canBeDefault : true ,
191- handler : ( ) => {
192- const routeData = this . $router . resolve ( {
193- name : 'external-apps' ,
194- params : { app : app . name , file_id : resource . fileId } ,
195- // public-token retrieval is weak, same as packages/web-app-files/src/index.js:106
196- query : {
197- ...( this . isPublicPage && {
198- 'public-token' : ( this . $route . params . item || '' ) . split ( '/' ) [ 0 ]
199- } )
200- }
201- } )
202- // TODO: Let users configure whether to open in same/new tab (`_blank` vs `_self`)
203- window . open ( routeData . href , '_blank' )
204- } ,
210+ canBeDefault : defaultApplication === app . name ,
211+ handler : ( ) => this . $_fileActions_openLink ( app . name , resource . fileId ) ,
205212 label : ( ) => this . $gettextInterpolate ( label , { appName : app . name } )
206213 }
207214 } )
215+ } ,
216+
217+ $_fileActions_openLink ( appName , resourceId ) {
218+ const routeData = this . $router . resolve ( {
219+ name : 'external-apps' ,
220+ params : {
221+ file_id : resourceId ,
222+ app : appName
223+ } ,
224+ // public-token retrieval is weak, same as packages/web-app-files/src/index.js:106
225+ query : {
226+ ...( this . isPublicPage && {
227+ 'public-token' : ( this . $route . params . item || '' ) . split ( '/' ) [ 0 ]
228+ } )
229+ }
230+ } )
231+ // TODO: Let users configure whether to open in same/new tab (`_blank` vs `_self`)
232+ window . open ( routeData . href , '_blank' )
208233 }
209234 }
210235}
0 commit comments