@@ -3,8 +3,8 @@ local ns = require("AppKit")
33local App = require (" App" )
44local xml = require (" ui.xml" )
55local Workflows = require (" apps.diskmap.models.Workflows" )
6+ local Operations = require (" apps.diskmap.helpers.Operations" )
67local Format = require (" apps.diskmap.helpers.Format" )
7- local CollectorController = require (" apps.diskmap.controllers.CollectorController" )
88local Environment = require (" apps.diskmap.controllers.Environment" )
99local Provider = require (" apps.diskmap.services.Provider" )
1010local Keep = require (" apps.diskmap.flows.Keep" )
@@ -13,7 +13,6 @@ local ScanProgress = require("apps.diskmap.controllers.ScanProgressController")
1313local NavigationController = require (" apps.diskmap.controllers.NavigationController" )
1414local CommandsController = require (" apps.diskmap.controllers.CommandsController" )
1515local Model = require (" data.model" )
16- local SheetController = require (" apps.diskmap.controllers.SheetController" )
1716local PageController = require (" data.pagecontroller" )
1817local Location = require (" data.location" )
1918local Scans = require (" apps.diskmap.models.Scans" )
@@ -32,31 +31,40 @@ function Controller.new(service, launch)
3231 refresh = function () self :updateRows () end ,
3332 changed = function () self :scanChanged () end ,
3433 basketChanged = function () self :basketChanged () end ,
35- openHistory = function () self . env . history : open ( self . window ) end ,
34+ openHistory = function () self : show ( " history " ) end ,
3635 openReview = function (path ) self :openReview (path ) end ,
3736 keep = function (id ) self :keep (id ) end ,
3837 destination = function () return self .destination end ,
3938 access = function () self :grantAccess () end ,
4039 openChanges = function ()
41- if self .env .snapshots and self .env .snapshots .result then self . env . session . changesSheet : open ( self . window , self . env . snapshots . result ) end
40+ if self .env .snapshots and self .env .snapshots .result then self : show ( " snapshotChanges " ) end
4241 end ,
4342 shortcuts = function () return self .shortcuts or {} end ,
4443 command = function (name ) return self .commandActions [name ]() end ,
45- beforeSheet = function () if self .progress then self .progress :close () end end ,
4644 raise = function () if self .window then self .window :show () end end ,
4745 promptParent = function () return self .window end ,
4846 links = CommandsController .links (),
47+ awaitAccess = function (page )
48+ if _G .__headless then return end
49+ local generation = page .generation
50+ local tick = Model .bound (self .env .model , function () page :poll () end )
51+ ns .async (function ()
52+ while page .active and page .generation == generation do
53+ ns .sleep (page .interval )
54+ if page .active and page .generation == generation then tick () end
55+ end
56+ end )
57+ end ,
4958 onboarded = function (granted )
59+ self :show (" overview" )
5060 self .env .session .fullDiskAccess = granted == true
5161 self .env .scan :start ()
52- if self .env .tour :needed (self .env .scan .disk ) then self . env . tour : open ( self . window ) end
62+ if self .env .tour :needed (self .env .scan .disk ) then self : show ( " tour " ) end
5363 end ,
5464 }
5565 self .env = Environment .new (service or launch .service , launch , router )
56- for _ , sheet in pairs (self .env .context .sheets ) do SheetController .attach (sheet , self .env .model ) end
5766 self .navigation = NavigationController .new (function (id ) self :show (id ) end ,
5867 function (location , restoring ) self :go (location , restoring ) end )
59- self .collectorController = CollectorController .new (self .env .context )
6068 self .progress = ScanProgress .new (self .env .scan )
6169 self .commands = CommandsController .new (self .env .model , self .env .service , {
6270 show = function (id , params ) self :show (id , params ) end ,
@@ -69,14 +77,14 @@ function Controller.new(service, launch)
6977 emptyTrash = function () Manage ({app = self .env .context }):manage (" user-trash" ) end ,
7078 navigation = self .navigation ,
7179 review = function () self :openReview () end ,
72- history = function () self . env . history : open ( self . window ) end ,
80+ history = function () self : show ( " history " ) end ,
7381 openFolder = function () self :chooseFolder () end ,
7482 quickLook = function () self :quickLook () end ,
7583 canQuickLook = function () local model = self .page and self .page .request ; return model ~= nil and model .canQuickLook ~= nil and model :canQuickLook () end ,
7684 openScan = function () self :openScan () end ,
7785 compareScan = function () self :compareScan () end ,
7886 exportScan = function () self :exportScan () end ,
79- tour = function () self . env . tour : open ( self . window ) end ,
87+ tour = function () self : show ( " tour " ) end ,
8088 })
8189 self .commandActions = self .commands :actions ()
8290 for name , action in pairs (self .commandActions ) do self .commandActions [name ] = Model .bound (self .env .model , action ) end
@@ -102,19 +110,10 @@ end
102110function Controller :focusSearch ()
103111 if self .window and self .searchField then self .window :focus (self .searchField ) end
104112end
105- -- Opens a resource where its location sends it: a sidebar page, a sheet of
106- -- its own, or its category's list with its row selected. An id that names
107- -- no resource is a page ("updates").
108- function Controller :open (id , filter )
113+ -- Opening a resource always navigates in the window's page history.
114+ function Controller :open (id )
109115 local destination = Locations :destination (id ) or self .env .manifest .pages [id ] and {page = id }
110- if not destination then return end
111- if destination .page then
112- self .env .management :close (); self :show (destination .page )
113- elseif destination .sheet == " sdks" then
114- self .env .management :close (); self .env .sdks :open (self .window , Locations :find (id ))
115- else
116- self .env .management :open (self .window , destination .category , {filter = filter , select = destination .select })
117- end
116+ if destination then self :show (destination .page , destination .params ) end
118117end
119118
120119function Controller :state ()
125124
126125function Controller :subtitle ()
127126 local text = Scans :summary (self .env .scan .disk , self .env .session .capacity ).short or " "
128- local marked = self .env .basket :count ()
129- if marked > 0 then text = text .. " · " .. marked .. " marked for cleanup" end
130127 return text
131128end
132129-- Sidebar sizes come from measured categories and scan-owned inventories.
@@ -152,6 +149,9 @@ function Controller:badges()
152149 badges .projects = require (" apps.diskmap.models.Projects" ):badge ()
153150 local folder = self .env .requests .folder
154151 badges .folder = folder and folder :badge ()
152+ -- Flagged counts its items, as Mail counts a mailbox's unread messages.
153+ local flagged = self .env .basket :count ()
154+ if flagged > 0 then badges .basket = tostring (flagged ) end
155155 return badges
156156end
157157function Controller :updateRows ()
@@ -163,8 +163,6 @@ function Controller:updateRows()
163163 if self .page then self .page :update (self :state ()) end
164164 self .navigation :setBadges (self :badges ())
165165 self .navigation :setWorkflows (self .env :presentWorkflows ())
166- self .env .management :draw ()
167- self .env .sdks :draw ()
168166end
169167-- A kind of work leads nobody who does not do it (#52): its pages appear
170168-- once one of its markers exists (Xcode for Developer, Logic Pro for Music
174172
175173function Controller :basketChanged ()
176174 if self .window then self .window .subtitle = self :subtitle () end
177- self :updateToolbar ()
178- self .collectorController :update ()
175+ self .navigation :setBadges (self :badges ())
179176 if self .page and self .page .marksChanged then self .page :marksChanged () end
180177end
181178
@@ -212,13 +209,11 @@ function Controller:quickLook()
212209 return false
213210end
214211
215- -- A running scan shows in its progress window and nowhere else; the pages
212+ -- A running scan shows in its progress sheet and nowhere else; the pages
216213-- are drawn when it is over.
217214function Controller :scanChanged ()
218215 self :updateToolbar ()
219- local sheetOpen = false
220- for _ , sheet in pairs (self .env .context .sheets ) do if sheet .sheet then sheetOpen = true end end
221- if self .env .model .scan .running and self .window and not sheetOpen then
216+ if self .env .model .scan .running and self .window then
222217 self .progress :show (self .window )
223218 else
224219 self .progress :close ()
@@ -250,12 +245,14 @@ function Controller:show(id, params, restoring)
250245 if self .page then self .page :dispose () end
251246 if request .focus then request :focus (params ) end
252247 local page = PageController .new ({page = entry , ns = ns , viewsDir = " apps/diskmap/views/" ,
253- store = self .env .model , request = request , located = function (where ) self :located (entry , where ) end })
248+ store = self .env .model , request = request , located = function (where ) self :located (entry , where ) end ,
249+ presented = function (data ) self .operations = Operations .forPage (entry .id , data ); self :updateToolbar () end })
254250 self .destination , self .page = id , page
251+ self .charted = request .view == " pages/Breakdown"
255252 page :mount (self .content , self :state ())
256253 self .navigation :select (id )
257- self . collectorController . onBasket = id == " basket "
258- self . collectorController : update ()
254+
255+
259256 self :updateRows ()
260257 end
261258 self .restoring = nil
@@ -321,11 +318,10 @@ function Controller:compareScan(path)
321318 self :show (" overview" )
322319end
323320function Controller :openSettings ()
324- self . env . settings : open ( self . window )
321+ self : show ( " settings " )
325322end
326323-- The marked items are a page: Back and Forward reach it like any other.
327324function Controller :openReview (path )
328- self .env .settings :close ()
329325 self :show (" basket" , {path = path })
330326end
331327-- Window.etlua's data. Its toolbar follows the scan as a SwiftUI toolbar
@@ -336,40 +332,55 @@ function Controller:windowData()
336332 data .subtitle = self :subtitle ()
337333 data .actions = setmetatable ({
338334 search = function (value ) self :search (value ) end ,
339- reclaim = function () self :show ( " cleanup " ) end ,
335+ chartStyle = function () self :toggleChartStyle ( ) end ,
340336 }, {__index = self .commandActions })
337+ data .operations = self .operations or {}
338+ for _ , item in ipairs (data .operations ) do
339+ data .actions [" operation_" .. item .id ] = function ()
340+ if self .page then return self .page .actions [item .action ]() end
341+ end
342+ data .actions [" enabled_" .. item .id ] = function () return not item .disabled end
343+ end
341344 data .navigation = not self .launch .isolated
342345 data .scanning = self .env .scan .job ~= nil
343- data .marked = self .env .basket : count ()
346+ data .charted , data . chartStyle = self .charted , self . env .context . chartStyle
344347 return data
345348end
346- -- The window template is described again only when the scan starts or
347- -- stops, and only its toolbar is applied.
349+ -- Rings or rectangles, for every breakdown page at once.
350+ function Controller :toggleChartStyle ()
351+ local context = self .env .context
352+ context .chartStyle = context .chartStyle == " rectangles" and " rings" or " rectangles"
353+ self :updateToolbar ()
354+ if self .page then self .page :update (self :state ()) end
355+ end
356+
357+ -- Redescription follows page operations, scan state and the Review badge.
358+ -- Progress and hover never rebuild the toolbar.
348359function Controller :updateToolbar ()
349- local scanning , marked = self .env .scan .job ~= nil , self .env .basket :count ()
350- if not self .window or (self .scanning == scanning and self .marked == marked ) then return end
351- self .scanning , self .marked = scanning , marked
360+ local scanning = self .env .scan .job ~= nil
361+ local parts = {}
362+ for _ , item in ipairs (self .operations or {}) do table.insert (parts , table.concat ({item .id , item .title , item .icon , item .action , tostring (item .disabled ), tostring (item .hidden )}, " :" )) end
363+ local operationKey = table.concat (parts , " |" )
364+ local chartKey = tostring (self .charted ) .. self .env .context .chartStyle
365+ if not self .window or (self .scanning == scanning and self .operationKey == operationKey and self .chartKey == chartKey ) then return end
366+ self .operationKey , self .chartKey = operationKey , chartKey
367+ self .scanning = scanning
352368 self .window :updateToolbar (xml .toolbarFile (layout (" Window" ), self :windowData ()))
353369end
354370function Controller :createWindow ()
355371 self .env :prepare ()
356372 local data = self :windowData ()
357- self .scanning , self . marked = data .scanning , data . marked
373+ self .scanning = data .scanning
358374 local cfg , windowRefs = render (" Window" , data )
359375 self .searchField = windowRefs and windowRefs .search
360376 self .shortcuts = self .commands :shortcuts (cfg .commands )
361377 local content , contentRefs = render (" Content" , {actions = {
362- dropToMark = function (paths ) return self .collectorController :dropToMark (paths ) end ,
363378 dropToOpen = function (paths ) return paths [1 ] ~= nil and self :openFolder (paths [1 ]) end ,
364- review = function () self :openReview () end ,
365- pageDrag = function (targeted ) self .collectorController :drag (" page" , targeted ) end ,
366- collectorDrag = function (targeted ) self .collectorController :drag (" collector" , targeted ) end ,
367379 }})
368380 self .navigation :setWorkflows (self .env :presentWorkflows ())
369381 cfg .content = content
370382 if not self .launch .isolated then cfg .sidebar = self .navigation :render () end
371- self .content , self .collector = contentRefs .content , contentRefs
372- self .collectorController .refs = contentRefs
383+ self .content = contentRefs .content
373384 self :basketChanged ()
374385 self .window = ns .Window (cfg )
375386 if self .launch .page then self :go (self .launch .page ) else self :show (" overview" ) end
@@ -402,10 +413,10 @@ function Controller:createWindow()
402413 -- scan and starts the scan once access is granted or declined.
403414 -- The welcome tour follows while the scan runs.
404415
405- if self .env .onboarding :needed () then self . env . onboarding : open ( self . window )
416+ if self .env .onboarding :needed () then self : show ( " onboarding " )
406417 else
407418 self .env .scan :start ()
408- if self .env .tour :needed (self .env .scan .disk ) then self . env . tour : open ( self . window ) end
419+ if self .env .tour :needed (self .env .scan .disk ) then self : show ( " tour " ) end
409420 end
410421 end
411422 local scope = ns .Scope .current ()
@@ -418,10 +429,10 @@ function Controller:createWindow()
418429 end
419430 return self .window
420431end
421- -- The window is going: its page, sheets and running work go with it.
432+ -- The window is going: its page and running work go with it.
422433function Controller :dispose ()
423434 if self .page then self .page :dispose () end
424- self . collectorController : dispose ()
435+
425436 if not self .launch .isolated and not self .launch .secondary then self .env .service .onOpenFiles (nil ) end
426437 self .progress :close ()
427438 self .env :dispose ()
0 commit comments