Skip to content

Commit

Permalink
SCDoc.prepareHelpForURL: if already running, wait for first instance …
Browse files Browse the repository at this point in the history
…to finish. Also, don't render undocumented class if we don't have to
  • Loading branch information
lijon committed Mar 30, 2011
1 parent c7cb41a commit b7c1a9c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions SCClassLibrary/Common/GUI/HelpBrowser.sc
Expand Up @@ -25,6 +25,10 @@ HelpBrowser {
}

goTo {|url|
//FIXME: if we first show the browser with HelpBrowser.instance.goTo, it will initialize it and goHome,
//so we get two instances of the routines below running!
//at least now SCDoc.prepareHelpForURL avoids being run more than one at the same time,
//but perhaps the interface for opening the helpbrowser on a specific URL (without changing homeUrl) should be improved.
var done = false, progress = [">---","->--","-->-","--->"];
var r = Routine {
block {|break|
Expand Down
30 changes: 24 additions & 6 deletions SCClassLibrary/SCDoc/SCDoc.sc
Expand Up @@ -11,6 +11,7 @@ SCDoc {
classvar progressTopic = nil, progressBar = nil, closeButton = nil;
classvar new_classes = nil;
classvar didRun = false;
classvar isProcessing = false;

*helpSourceDir_ {|path|
helpSourceDir = path.standardizePath;
Expand Down Expand Up @@ -558,23 +559,34 @@ SCDoc {

*prepareHelpForURL {|url,doYield=false|
var proto, path, anchor;
var subtarget, src;
var subtarget, src, c;

var needMetaData = Set["Browse","Search","Overviews/Documents","Overviews/Classes","Overviews/Methods"];

doWait = doYield;

if(isProcessing) {
"SCDoc: prepareHelpForURL already running.. waiting for the first to finish.".warn;
c = Condition.new;
Routine {
while {0.5.wait; isProcessing};
c.unhang;
}.play(AppClock);
c.hang;
};
isProcessing = true;

// parse URL
#proto, path, anchor = url.findRegexp("(^\\w+://)?([^#]+)(#.*)?")[1..].flop[1];
if(proto.isEmpty) {proto="file://"};
if(proto!="file://") {^url}; // just pass through remote url's
if(proto!="file://") {isProcessing = false; ^url}; // just pass through remote url's

this.findHelpSourceDirs;

// sync non-schelp files once every session
if(didRun.not) {
this.syncNonHelpFiles;
didRun = true;
this.syncNonHelpFiles;
};

// strip to subfolder/basename (like Classes/SinOsc)
Expand All @@ -586,6 +598,7 @@ SCDoc {
if(doc_map.isNil) {
this.getAllMetaData;
};
isProcessing = false;
^url;
};

Expand All @@ -609,7 +622,6 @@ SCDoc {

// create a simple stub if class was undocumented
if(src.isNil and: {subtarget.dirname=="Classes"}) {
this.postProgress("Undocumented class, generating stub and template");
this.makeClassTemplate(subtarget.basename,path);
};

Expand All @@ -618,26 +630,32 @@ SCDoc {
this.postProgress("Parsing"+src);
p.parseFile(src);
r.render(p,path,subtarget.dirname);
isProcessing = false;
^url;
} {
this.postProgress("Broken link:"+url);
isProcessing = false;
^"file://"++helpTargetDir++"/BrokenLink.html#"++url;
};
} {
if(src.notNil and: {("test"+src.escapeChar($ )+"-nt"+path.escapeChar($ )).systemCmd==0}) {
// target file and helpsource exists, and helpsource is newer than target
p.parseFile(src);
r.render(p,path,subtarget.dirname);
isProcessing = false;
^url;
};
};

isProcessing = false;
^url;
}

*makeClassTemplate {|name,path|
var class = name.asSymbol.asClass;
var n, m, cats, methodstemplate, f;
if(class.notNil) {
f = class.filenameSymbol.asString.escapeChar($ );
if(class.notNil and: {("test"+f+"-nt"+path.escapeChar($ )+"-o ! -e"+path.escapeChar($ )).systemCmd==0}) {
this.postProgress("Undocumented class, generating stub and template");
n = List.new;
n.add((tag:\class, text:name));
n.add((tag:\summary, text:""));
Expand Down

0 comments on commit b7c1a9c

Please sign in to comment.