Module: environment-tools Synopsis: Project Commands Author: Andy Armstrong, Chris Page, Jason Trenouth, Scott McKay Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND /// Project persistence define settings () key-name "Projects"; slot project1 :: = ""; slot project2 :: = ""; slot project3 :: = ""; slot project4 :: = ""; slot project5 :: = ""; slot project6 :: = ""; slot project7 :: = ""; slot project8 :: = ""; slot project9 :: = ""; end settings ; define open generic register-opened-file (filename :: ) => (); define constant $project-history = make(); define function most-recent-project () => (project :: false-or()) let project = $project-history.project1; unless (project = "") as(, project) end end function most-recent-project; define function most-recent-project-setter (project :: ) => (project :: ) register-opened-file(project); unless (project = most-recent-project()) let projects = most-recent-projects(n: 8); let new-projects = concatenate(vector(project), remove(projects, project, test: \=)); most-recent-projects() := new-projects end; project end function most-recent-project-setter; define function most-recent-projects (#key n :: = 9) => (projects :: ) let projects = remove(vector($project-history.project1, $project-history.project2, $project-history.project3, $project-history.project4, $project-history.project5, $project-history.project6, $project-history.project7, $project-history.project8, $project-history.project9), "", test: \=); map(curry(as, ), copy-sequence(projects, end: min(n, size(projects)))) end function most-recent-projects; define function most-recent-projects-setter (projects :: ) => (projects :: ) let project-names = map(curry(as, ), projects); let blanks = 9 - size(project-names); let padded-project-names = if (blanks > 0) concatenate(project-names, make(, fill: "", size: blanks)) else project-names end; $project-history.project1 := padded-project-names[0]; $project-history.project2 := padded-project-names[1]; $project-history.project3 := padded-project-names[2]; $project-history.project4 := padded-project-names[3]; $project-history.project5 := padded-project-names[4]; $project-history.project6 := padded-project-names[5]; $project-history.project7 := padded-project-names[6]; $project-history.project8 := padded-project-names[7]; $project-history.project9 := padded-project-names[8]; projects end function most-recent-projects-setter; tune-in($project-channel, method (message :: ) let project = message.message-project; let filename = project.project-filename; most-recent-project() := filename | project.project-debug-filename; if (project-can-be-debugged?(project) & environment-active-on-opening?()) //--- We switch the active project in a new thread so that //--- 'active-project-setter' doesn't block doing a re-entrant //--- broadcast when it signals . make(, name: "Updating the active project", function: method () with-abort-restart () active-project() := project end end) end end, message-type: ); /// File persistence define settings () key-name "Files"; slot file1 :: = ""; slot file2 :: = ""; slot file3 :: = ""; slot file4 :: = ""; slot file5 :: = ""; slot file6 :: = ""; slot file7 :: = ""; slot file8 :: = ""; slot file9 :: = ""; end settings ; define constant $file-history = make(); define function most-recent-file () => (file :: false-or()) let file = $file-history.file1; unless (file = "") as(, file) end end function most-recent-file; define function most-recent-file-setter (locator :: ) => (file :: ) register-opened-file(locator); unless (locator = most-recent-file()) let files = most-recent-files(n: 8); let new-files = concatenate(vector(locator), remove(files, locator, test: \=)); most-recent-files() := new-files end; locator end function most-recent-file-setter; define function most-recent-files (#key n :: = 9) => (files :: ) let files = remove(vector($file-history.file1, $file-history.file2, $file-history.file3, $file-history.file4, $file-history.file5, $file-history.file6, $file-history.file7, $file-history.file8, $file-history.file9), "", test: \=); map(curry(as, ), copy-sequence(files, end: min(n, size(files)))) end function most-recent-files; define function most-recent-files-setter (files :: ) => (files :: ) let file-names = map(curry(as, ), files); let blanks = 9 - size(file-names); let padded-file-names = if (blanks > 0) concatenate(file-names, make(, fill: "", size: blanks)) else file-names end; $file-history.file1 := padded-file-names[0]; $file-history.file2 := padded-file-names[1]; $file-history.file3 := padded-file-names[2]; $file-history.file4 := padded-file-names[3]; $file-history.file5 := padded-file-names[4]; $file-history.file6 := padded-file-names[5]; $file-history.file7 := padded-file-names[6]; $file-history.file8 := padded-file-names[7]; $file-history.file9 := padded-file-names[8]; files end function most-recent-files-setter; /// Open a project define method frame-open-project (frame :: , object :: ) => () ignore(frame); let project = coerce-project(object); if (project) ensure-project-browser-showing-project(project) else environment-error-message (format-to-string("Project %s does not exist", object), owner: frame) end end method frame-open-project; /// Create a new text or project file define function open-project-file (location :: , #key frame) => () if (frame) frame-open-project(frame, location) else find-project-browser(location) end end function open-project-file; define function create-new-project (#rest args, #key frame :: false-or(), open-new-project? :: = #t) => (projects :: /* of: */) let project-locations = apply(new-project-wizard, args); let projects = make(); // Try to open all the projects. If any fail (in COERCE-PROJECT), we // don't add them to the result sequence or OPEN-PROJECT-FILE them. for (location in project-locations) let project = coerce-project(location); if (project) add!(projects, project); if (open-new-project?) open-project-file(location, frame: frame); end; end; end; projects end function create-new-project; define frame () constant slot frame-project :: false-or() = #f, init-keyword: project:; pane %dialog-new-project-button (frame) make(, label: "Project", id: #"project", activate-callback: exit-dialog); pane %dialog-new-dylan-button (frame) make(, label: "Dylan File", id: #"dylan", activate-callback: exit-dialog); pane %dialog-new-text-button (frame) make(, label: "Text File", id: #"text", activate-callback: exit-dialog); pane %new-project-icon (frame) make(