|
| 1 | +<?xml version="1.0" encoding="UTF-8"?> |
| 2 | +<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2015.1.1 (Build 505U)" ts="2015-12-20 13:40:54"> |
| 3 | +<Class name="WebTerminal.Autocomplete"> |
| 4 | +<Super>Common</Super> |
| 5 | +<TimeChanged>63906,49146.441893</TimeChanged> |
| 6 | +<TimeCreated>63906,49098.662696</TimeCreated> |
| 7 | + |
| 8 | +<Method name="AutocompleteExists"> |
| 9 | +<FormalSpec>namespace:%String</FormalSpec> |
| 10 | +<ReturnType>%Boolean</ReturnType> |
| 11 | +<Implementation><![CDATA[ quit $get(^%WebTerminal.Autocomplete(namespace)) '= "" |
| 12 | +]]></Implementation> |
| 13 | +</Method> |
| 14 | + |
| 15 | +<Method name="GenerateAutocomplete"> |
| 16 | +<Description> |
| 17 | +Generates autocomplete for namespace. Second parameter decides if |
| 18 | +it will be regenerated again. But if namespace equals to "%" - generates |
| 19 | +autocomplete for system classes. Make sure that autocomplete for |
| 20 | +system classes generates one time and forever. |
| 21 | +@param genSystem - Shows if system classes need to be generated. </Description> |
| 22 | +<FormalSpec>namespace:%String,genSystem:%Boolean</FormalSpec> |
| 23 | +<ReturnType>%String</ReturnType> |
| 24 | +<Implementation><![CDATA[ |
| 25 | + set trueNs = $case(genSystem, 1:"%", :namespace) |
| 26 | +
|
| 27 | + do ..SendData("29", ..#ConstClientOutputLocalized) |
| 28 | + do ..SendData(" " _ trueNs _ $C(13, 10)) |
| 29 | +
|
| 30 | + if ('##class(%SYS.Namespace).Exists(namespace)) { |
| 31 | + do ..SendData("30", ..#ConstClientOutputLocalized) |
| 32 | + do ..SendData(" " _ namespace _ $C(13, 10)) |
| 33 | + quit $$$NOTOK |
| 34 | + } |
| 35 | +
|
| 36 | + // get all classes names |
| 37 | + set result = ##class(%ResultSet).%New("%Dictionary.ClassDefinition:Summary") |
| 38 | + do result.Execute() |
| 39 | +
|
| 40 | + /* |
| 41 | + The next COULD BE IMPROVED FOR SPEED, I beleive. |
| 42 | + Generates compressed JSON string of type: |
| 43 | + { |
| 44 | + "class": { |
| 45 | + "%ClassName1": { |
| 46 | + "methodName": 0, |
| 47 | + "propertyName": 0, |
| 48 | + "parameterName": 0, |
| 49 | + ... |
| 50 | + }, |
| 51 | + "ClassName2": { |
| 52 | + ... |
| 53 | + } |
| 54 | + }, |
| 55 | + "global": { |
| 56 | + "^%g1": 0, |
| 57 | + "^g2": 0 |
| 58 | + } |
| 59 | + } |
| 60 | + */ |
| 61 | +
|
| 62 | + do ..SendData($C(13, 10)) |
| 63 | + do ..SendData("32", ..#ConstClientOutputLocalized) |
| 64 | +
|
| 65 | + set ac = "{""class"":{" // string with autocomplete |
| 66 | + set first = "" |
| 67 | + set u = 1 |
| 68 | +
|
| 69 | + while (result.Next()) { // forming autocomplete for each class |
| 70 | +
|
| 71 | + if (genSystem) '= ($Extract(result.Data("Name"), 1) = "%") { |
| 72 | + continue |
| 73 | + } |
| 74 | +
|
| 75 | + set className = result.Data("Name") |
| 76 | +
|
| 77 | + do ..SendData($C(27) _ "[30G" _ u) |
| 78 | + s u = u + 1 |
| 79 | +
|
| 80 | + set ac = ac _ first _ """" _ className _ """:{" |
| 81 | + if (first = "") set first = "," |
| 82 | +
|
| 83 | + set cdefs = ##class(%Dictionary.ClassDefinition).%OpenId(className) |
| 84 | +
|
| 85 | + set countMethods = cdefs.Methods.Count() |
| 86 | + set countParameters = cdefs.Parameters.Count() |
| 87 | + set countProperties = cdefs.Properties.Count() |
| 88 | + set total = countMethods + countParameters + countProperties |
| 89 | + set current = 0 |
| 90 | +
|
| 91 | + for i=1:1:countMethods { |
| 92 | + set current = current + 1 |
| 93 | + set ac = ac _ """" _ cdefs.Methods.GetAt(i).Name _ """:0" |
| 94 | + if (current'=total) set ac = ac _ "," |
| 95 | + } |
| 96 | +
|
| 97 | + for i=1:1:countProperties { |
| 98 | + set current = current + 1 |
| 99 | + set ac = ac _ """" _ cdefs.Properties.GetAt(i).Name _ """:0" |
| 100 | + if (current'=total) set ac = ac _ "," |
| 101 | + } |
| 102 | +
|
| 103 | + for i=1:1:countParameters { |
| 104 | + set current = current + 1 |
| 105 | + set ac = ac _ """" _ cdefs.Parameters.GetAt(i).Name _ """:0" |
| 106 | + if (current'=total) set ac = ac _ "," |
| 107 | + } |
| 108 | +
|
| 109 | + set ac = ac _ "}" |
| 110 | +
|
| 111 | + } |
| 112 | +
|
| 113 | + set ac = ac _ "}" |
| 114 | + if ('genSystem) set ac = ac _ ",""global"":" _ ..getGlobalsJSON() |
| 115 | + set ac = ac _ "}" |
| 116 | +
|
| 117 | + set ^%WebTerminal.Autocomplete(trueNs) = ac |
| 118 | +
|
| 119 | + do ..SendData($C(13, 10)) |
| 120 | + do ..SendData("33", ..#ConstClientOutputLocalized) |
| 121 | + do ..SendData($C(13, 10)) |
| 122 | + //do ..SendData(namespace, ..#ConstClientLoadAutocomplete) |
| 123 | +
|
| 124 | + quit $$$OK |
| 125 | +]]></Implementation> |
| 126 | +</Method> |
| 127 | + |
| 128 | +<Method name="Reset"> |
| 129 | +<Description> |
| 130 | +Returns terminal to default state</Description> |
| 131 | +<ClassMethod>1</ClassMethod> |
| 132 | +<ReturnType>%Status</ReturnType> |
| 133 | +<Implementation><![CDATA[ |
| 134 | + // delete autocompletion files |
| 135 | + kill ^%WebTerminal.Autocomplete |
| 136 | + quit $$$OK |
| 137 | +]]></Implementation> |
| 138 | +</Method> |
| 139 | + |
| 140 | +<Method name="getGlobalsJSON"> |
| 141 | +<ClassMethod>1</ClassMethod> |
| 142 | +<FormalSpec>namespace:%String</FormalSpec> |
| 143 | +<ReturnType>%String</ReturnType> |
| 144 | +<Implementation><![CDATA[ |
| 145 | +
|
| 146 | + set out = "{" |
| 147 | + set rset=##class(%ResultSet).%New("%SYS.GlobalQuery:NameSpaceList") |
| 148 | + set sc=rset.Execute($ZNSPACE,"*",0) |
| 149 | + while (rset.Next()) { |
| 150 | + set out = out _ """" _ $Piece(rset.GetData(1),"(",1) _ """:0," |
| 151 | + } |
| 152 | + set out = $EXTRACT(out,1,$LENGTH(out)-1) _ "}" |
| 153 | +
|
| 154 | + // todo: |
| 155 | + // Set Rset = ##class(%Library.ResultSet).%New("%SYS.GlobalQuery:NameSpaceListChui") |
| 156 | + // s Status=Rset.Execute(NameSpace,Mask,SystemGlobals,.UnavailableDatabases) |
| 157 | +
|
| 158 | + q out |
| 159 | +]]></Implementation> |
| 160 | +</Method> |
| 161 | +</Class> |
| 162 | +</Export> |
0 commit comments