links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Find a keyword in a workspace
Last updated at 12:51 pm UTC on 4 October 2019
Task: Identify the project with a workspace which contains a particular keyword

Solution: The script writes a list of all workspaces to the Transcript which have a text containing the search term. If you put the cursor into one of these lines in the Transcript and execute 'do it' the project with the workspace which has the search term is opened.

searchTerm := 'Robert'.

projects := Project allMorphicProjects.

wsDataCollection := OrderedCollection new.

projects do: [:proj | | windows workspaces cellData |  
	windows := proj world submorphs select:  [:sm | sm isKindOf: SystemWindow].
	workspaces := (windows select: [:m | m model class =Workspace]).
        workspaces do: [:ws | cellData := Dictionary new.
	cellData at: 'label' put: ws label.
	cellData at: 'ws' put: ws.
	cellData at: 'project' put: proj. 
	wsDataCollection add: cellData.]

Transcript clear.
pname := ''.

(wsDataCollection asSortedCollection: [:a :b | (a at: 'project') name < (b at: 'project') name]) do: 
[:cell | (cell at: 'label') = 'Workspace' ifFalse: 
	  ["pname = (cell at: 'project') name ifFalse: [pname := (cell at: 'project') name. Transcript cr]."
	   ((cell at: 'ws') paneMorphs first text asString includesSubstring: searchTerm) ifTrue: 
	   [Transcript show: '(Project named: ''', (cell at: 'project')  name, ''') enter.', ' "' ,(cell at: 'label'),'"'; cr]