Skip to content

Fix behavior with BPL/DTL editing via Studio #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Link from WebUI to Settings page works properly (#230)
- VSCode Web Views launch in external browser when connecting over unsecured connections (#227)
- DTL/BPL editing through Studio reflected properly in source control

## [2.1.0] - 2023-01-23

Expand Down
12 changes: 6 additions & 6 deletions cls/SourceControl/Git/Extension.cls
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ Method OnSourceMenuContextItem(itemName As %String, menuItemName As %String, ByR
set Enabled = $case(menuItemName,"AddToSC":1,"RemoveFromSC":1,:-1)
} elseif menuItemName = "Revert" {
set Enabled = 1
do ..GetStatus(itemName, .isInSourceControl, .isEditable,.isCheckedOut,.userCheckedOut)
do ..GetStatus(.itemName, .isInSourceControl, .isEditable,.isCheckedOut,.userCheckedOut)
if '(##class(Change).IsUncommitted(##class(Utils).FullExternalName(itemName))) || ($username '= userCheckedOut) {
set Enabled = 0
}
} elseif menuItemName = "Commit" {
set Enabled = 1
do ..GetStatus(itemName, .isInSourceControl, .isEditable,.isCheckedOut,.userCheckedOut)
do ..GetStatus(.itemName, .isInSourceControl, .isEditable,.isCheckedOut,.userCheckedOut)
if '(##class(Change).IsUncommitted(##class(Utils).FullExternalName(itemName))) || ($username '= userCheckedOut) {
set Enabled = 0
}
Expand Down Expand Up @@ -210,7 +210,7 @@ Method OnAfterSave(InternalName As %String, Object As %RegisteredObject = {$$$NU
{
set sc = $$$OK
try {
set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
set InternalName = ##class(Utils).NormalizeInternalName(.InternalName)
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
if ##class(Utils).IsNamespaceInGit() && ..IsInSourceControl(InternalName) {
set filename = ##class(Utils).FullExternalName(InternalName)
Expand Down Expand Up @@ -277,11 +277,11 @@ Method IsReadOnly(InternalName As %String) As %Boolean
/// Check the status of the given item
/// User should be able to edit the item if it is not locked by another user
/// Check if another user has committed any changes to the item and return the status
Method GetStatus(InternalName As %String, ByRef IsInSourceControl As %Boolean, ByRef Editable As %Boolean, ByRef IsCheckedOut As %Boolean, ByRef UserCheckedOut As %String) As %Status
Method GetStatus(ByRef InternalName As %String, ByRef IsInSourceControl As %Boolean, ByRef Editable As %Boolean, ByRef IsCheckedOut As %Boolean, ByRef UserCheckedOut As %String) As %Status
{
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(.InternalName)
set Editable='..IsReadOnly(),IsCheckedOut=1,UserCheckedOut=""
set filename=##class(SourceControl.Git.Utils).FullExternalName(InternalName)
set filename=##class(SourceControl.Git.Utils).FullExternalName(.InternalName)
set IsInSourceControl=(filename'=""&&($$$FileExists(filename)))
if filename="" quit $$$OK
if InternalName="" quit $$$OK
Expand Down
1 change: 1 addition & 0 deletions cls/SourceControl/Git/PackageManagerContext.cls
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ClassMethod ForInternalName(InternalName As %String = "") As SourceControl.Git.P
{
set instance = ..%Get()
set instance.InternalName = InternalName
set InternalName = instance.InternalName
quit instance
}

Expand Down
57 changes: 35 additions & 22 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ ClassMethod AfterUserAction(Type As %Integer, Name As %String, InternalName As %

ClassMethod Revert(InternalName As %String) As %Status
{
set filename = ..FullExternalName(InternalName)
set filename = ..FullExternalName(.InternalName)
do ..RunGitCommand("checkout", .errStream, .outStream, "--", filename)
$$$QuitOnError(##class(SourceControl.Git.Change).RemoveUncommitted(filename,0,1))
$$$QuitOnError(##class(SourceControl.Git.Change).RefreshUncommitted(0,1))
Expand All @@ -272,7 +272,7 @@ ClassMethod Revert(InternalName As %String) As %Status

ClassMethod Commit(InternalName As %String, Message As %String = "example commit message") As %Status
{
set filename = ..FullExternalName(InternalName)
set filename = ..FullExternalName(.InternalName)
set username = ..GitUserName()
set email = ..GitUserEmail()
set author = username_" <"_email_">"
Expand Down Expand Up @@ -430,7 +430,7 @@ ClassMethod NormalizeFolder(folder As %String) As %String

ClassMethod ExternalName(InternalName As %String, ByRef MappingExists As %Boolean) As %String
{
quit ..Name(InternalName,.MappingExists)
quit ..Name(.InternalName,.MappingExists)
}

ClassMethod AddToServerSideSourceControl(InternalName As %String) As %Status
Expand All @@ -454,7 +454,7 @@ ClassMethod AddToSourceControl(InternalName As %String) As %Status
#dim ec as %Status = $$$OK
for i = 1:1:$length(InternalName, ",") {
#dim item as %String = ..NormalizeExtension($piece(InternalName, ",", i))
#dim type as %String = ..Type(item)
#dim type as %String = ..Type(.item)

#dim sc as %Status = ..ExportItem(item,,1,.filenames)
if 'sc {
Expand All @@ -465,7 +465,7 @@ ClassMethod AddToSourceControl(InternalName As %String) As %Status
if (FileInternalName = "") {
continue
}
set FileType = ##class(SourceControl.Git.Utils).Type(FileInternalName)
set FileType = ##class(SourceControl.Git.Utils).Type(.FileInternalName)

set @..#Storage@("items", FileInternalName) = ""
do ..RunGitCommand("add",.errStream,.outStream,filenames(i))
Expand All @@ -491,7 +491,7 @@ ClassMethod RemoveFromGit(InternalName)

ClassMethod DeleteExternalsForItem(InternalName As %String) As %Status
{
#dim type as %String = ..Type(InternalName)
#dim type as %String = ..Type(.InternalName)
#dim ec as %Status = $$$OK
if (type = "prj") || (type = "pkg") || (type = "csp" && ..IsCspFolder(InternalName)) {
// we delete complex items
Expand Down Expand Up @@ -588,7 +588,7 @@ ClassMethod FindTrackedFilesInCSPFolders(InternalName As %String, ByRef trackedF
ClassMethod FindTrackedFiles(InternalName As %String, ByRef trackedFiles As %String) As %Status
{

#dim type as %String = ..Type(InternalName)
#dim type as %String = ..Type(.InternalName)
set InternalName = ..NameWithoutExtension(InternalName)

if (type = "pkg") {
Expand All @@ -604,7 +604,7 @@ ClassMethod FindTrackedFiles(InternalName As %String, ByRef trackedFiles As %Str
/// Description
ClassMethod FindTrackedParent(InternalName As %String, ByRef parentElement As %String) As %Status
{
#dim type as %String = ..Type(InternalName)
#dim type as %String = ..Type(.InternalName)
set isInSourceControl = 0
if type = "cls" {
#define StripExtension(%s) $Piece(%s,".",1,$Length(%s, ".") - 1)
Expand Down Expand Up @@ -638,7 +638,7 @@ ClassMethod RemoveFromServerSideSourceControl(InternalName As %String) As %Statu
for i = 1:1:$length(InternalName, ",") {
#dim item as %String = ..NormalizeExtension($piece(InternalName, ",", i))
#dim tsc as %Status = $$$OK
#dim type as %String = ..Type(InternalName)
#dim type as %String = ..Type(.InternalName)

if $data(@..#Storage@("items", item)) {
kill @..#Storage@("items", item)
Expand All @@ -661,7 +661,7 @@ ClassMethod RemoveFromSourceControl(InternalName As %String, cascadeDelete As %B
}
for i = 1:1:$length(InternalName, ",") {
#dim tsc as %Status = $$$OK
#dim type as %String = ..Type(InternalName)
#dim type as %String = ..Type(.InternalName)

set item = $piece(InternalName, ",", i)
if $data(@..#Storage@("items", ..NormalizeExtension(item))) {
Expand Down Expand Up @@ -726,6 +726,20 @@ ClassMethod Type(InternalName As %String) As %String
}
}

// For an abstract document, use the GetOther() method to try to determine its "real" class
If ##class(%RoutineMgr).UserType(InternalName,.docclass,.doctype) {
// Check for a real abstract document subclass (or GetOther() may not work)
If $classmethod(docclass,"%IsA","%Studio.AbstractDocument") {
// Grab the actual name
Set actualName = $classmethod(docclass,"GetOther",InternalName)
// The actualName is only valid if we get a single .cls as a result
If actualName'[",",$ZCVT($P(actualName,".",$L(actualName,".")),"U")="CLS" {
// We use what GetOther() gives us, thus Demo.Loan.FindRateProcess.bpl becomes Demo.Loan.FindRateProcess.cls
Set InternalName = actualName
}
}
}

quit type
}

Expand All @@ -746,7 +760,7 @@ ClassMethod IsItemInProject(InternalName As %String, projectName As %String) As
// we should check two cases
// direct inclusion
// inclusion in package or csp-folder that contained in project
#dim type as %String = ..Type(InternalName)
#dim type as %String = ..Type(.InternalName)
#dim name as %String = $case(type, "cls": ..NameWithoutExtension(InternalName),
"pkg": $translate(..NameWithoutExtension(InternalName), "/", "."),
"csp": $extract(InternalName, 2, *),
Expand Down Expand Up @@ -874,7 +888,7 @@ ClassMethod IsInSourceControl(InternalName As %String, ByRef sourceControlItem A
// projects for everything
// csp-folders for csp and static files

#dim type as %String = ..Type(InternalName)
#dim type as %String = ..Type(.InternalName)
if type = "cls" {
#define StripExtension(%s) $Piece(%s,".",1,$Length(%s, ".") - 1)
set className = $$$StripExtension(InternalName)
Expand All @@ -898,12 +912,12 @@ ClassMethod IsInSourceControl(InternalName As %String, ByRef sourceControlItem A
quit isInSourceControl
}

ClassMethod FullExternalName(InternalName As %String, ByRef MappingExists As %Boolean) As %String [ CodeMode = expression ]
ClassMethod FullExternalName(ByRef InternalName As %String, ByRef MappingExists As %Boolean) As %String [ CodeMode = expression ]
{
##class(%File).NormalizeFilename(..TempFolder()_..ExternalName(InternalName, .MappingExists))
##class(%File).NormalizeFilename(..TempFolder()_..ExternalName(.InternalName, .MappingExists))
}

ClassMethod NormalizeInternalName(name As %String) As %String
ClassMethod NormalizeInternalName(ByRef name As %String) As %String
{
//Studio passes name of routine with dots as it is in folders
//e.g. Package.SubPackage.Routine.mac has InternalName = /Package/SubPackage/Routine.mac
Expand All @@ -914,12 +928,12 @@ ClassMethod NormalizeInternalName(name As %String) As %String
quit ""
}

set type = ..Type(.name)

if $extract(name) '= "/" {
quit $piece(name,".",1,*-1)_"."_$zconvert($piece(name,".",*),"U")
}

set type = ..Type(name)

if (type = "inc") || (type = "mac") || (type = "int") {
set name = $extract($translate(name, "/", "."), 2, *)
}
Expand Down Expand Up @@ -966,7 +980,7 @@ ClassMethod RemoveRoutineTSH(InternalName As %String) As %Status

ClassMethod DeleteExternalFile(InternalName As %String) As %Status
{
#dim fullName = ##class(Utils).FullExternalName(InternalName)
#dim fullName = ##class(Utils).FullExternalName(.InternalName)
#dim ec as %Status = $$$OK
if ##class(%File).Exists(fullName) {
set ec = ##class(%File).Delete(fullName)
Expand All @@ -979,7 +993,7 @@ ClassMethod DeleteExternalFile(InternalName As %String) As %Status
/// if temp file for InternalName not found return "0,0" in tempFileTSH
ClassMethod GetTempFileAndRoutineTS(InternalName As %String, ByRef tempFileTSH As %String, ByRef routineTSH As %String)
{
#dim filename as %String = ..FullExternalName(InternalName)
#dim filename as %String = ..FullExternalName(.InternalName)
set tempFileTSH = ##class(%File).GetFileDateModified(filename)
set routineTSH = ..RoutineTSH(InternalName)
//file not found or path not found or some other error
Expand Down Expand Up @@ -1031,7 +1045,7 @@ ClassMethod FixProjectCspReferences(projectName As %String) As %Status
/// if <var>force</var> = 1 then imports in any case.
ClassMethod ImportItem(InternalName As %String, force As %Boolean = 0, verbose As %Boolean = 1) As %Status
{
#dim filename as %String = ..FullExternalName(InternalName)
#dim filename as %String = ..FullExternalName(.InternalName)
#dim fileTSH = ##class(%File).GetFileDateModified(filename)
#dim sc as %Status = $$$OK

Expand Down Expand Up @@ -1261,7 +1275,7 @@ ClassMethod ExportRoutinesAux(path As %String, sep As %String = "", level As %In

ClassMethod ExportItem(InternalName As %String, expand As %Boolean = 1, force As %Boolean = 0, ByRef filenames) As %Status
{
#dim type = ..Type(InternalName)
#dim type = ..Type(.InternalName)
if type = "pkg" {
$$$QuitOnError(..ExportRoutinesAux(..NameWithoutExtension(InternalName), ".", 0, force, .filenames))
}elseif type = "prj" && expand {
Expand Down Expand Up @@ -1454,7 +1468,6 @@ ClassMethod GitStatus(ByRef files, IncludeAllFiles = 0)
*/
ClassMethod Name(InternalName As %String, ByRef MappingExists As %Boolean) As %String
{

set MappingExists = -1
set InternalName=##class(%Studio.SourceControl.Interface).normalizeName(InternalName)
set context = ##class(SourceControl.Git.PackageManagerContext).%Get()
Expand Down