From dab5151439853f5e11d8501fc35a2a27add32071 Mon Sep 17 00:00:00 2001 From: Christophe Demarey Date: Mon, 8 Jul 2019 16:14:59 +0200 Subject: [PATCH] fixes #342 Cannot open anymore OS folder X. Also move to use a visitor instead of extension methods --- .../MacOSPlatform.extension.st | 6 -- .../OSPlatform.extension.st | 18 ----- .../PhLFileBrowser.class.st | 65 +++++++++++++++++++ src/PharoLauncher-Core/PhLImage.class.st | 2 +- .../PhLProcessWrapper.class.st | 24 ------- .../PhLVirtualMachine.class.st | 2 +- .../UnixPlatform.extension.st | 6 -- .../Win32Platform.extension.st | 6 -- .../PhLFileBrowserTest.class.st | 12 ++++ 9 files changed, 79 insertions(+), 62 deletions(-) delete mode 100644 src/PharoLauncher-Core/MacOSPlatform.extension.st delete mode 100644 src/PharoLauncher-Core/OSPlatform.extension.st create mode 100644 src/PharoLauncher-Core/PhLFileBrowser.class.st delete mode 100644 src/PharoLauncher-Core/UnixPlatform.extension.st create mode 100644 src/PharoLauncher-Tests-Core/PhLFileBrowserTest.class.st diff --git a/src/PharoLauncher-Core/MacOSPlatform.extension.st b/src/PharoLauncher-Core/MacOSPlatform.extension.st deleted file mode 100644 index f7ed1301..00000000 --- a/src/PharoLauncher-Core/MacOSPlatform.extension.st +++ /dev/null @@ -1,6 +0,0 @@ -Extension { #name : #MacOSPlatform } - -{ #category : #'*PharoLauncher-Core' } -MacOSPlatform >> privOpenFileBrowserOn: pathString [ - ^ PhLProcessWrapper command: ('open "{1}"' format: {pathString}) -] diff --git a/src/PharoLauncher-Core/OSPlatform.extension.st b/src/PharoLauncher-Core/OSPlatform.extension.st deleted file mode 100644 index 5f3af505..00000000 --- a/src/PharoLauncher-Core/OSPlatform.extension.st +++ /dev/null @@ -1,18 +0,0 @@ -Extension { #name : #OSPlatform } - -{ #category : #'*PharoLauncher-Core' } -OSPlatform >> openFileBrowserOn: aFileReference [ - "Opens an OS-specific file and directory browser on ==aFileReference==. If aFileReference is a file, opens the browser on its containing directory instead." - | ref | - (aFileReference isNil or: [ aFileReference exists not ]) - ifTrue: [ ^ nil ]. - ref := aFileReference isFile ifTrue: [ aFileReference parent ] ifFalse: [ aFileReference ]. - (ref isNil or: [ ref exists not ]) - ifTrue: [ ^ nil ]. - self privOpenFileBrowserOn: ref pathString -] - -{ #category : #'*PharoLauncher-Core' } -OSPlatform >> privOpenFileBrowserOn: pathString [ - ^ self subclassResponsibility -] diff --git a/src/PharoLauncher-Core/PhLFileBrowser.class.st b/src/PharoLauncher-Core/PhLFileBrowser.class.st new file mode 100644 index 00000000..7dd826ed --- /dev/null +++ b/src/PharoLauncher-Core/PhLFileBrowser.class.st @@ -0,0 +1,65 @@ +" +I'm a simple visitor in charge of opening an operating system browser on the provided path string. +" +Class { + #name : #PhLFileBrowser, + #superclass : #OSPlatformVisitor, + #instVars : [ + 'process', + 'vmPath', + 'launchInALoginShell', + 'imageFile', + 'usePharoSettings', + 'path' + ], + #category : #'PharoLauncher-Core-Model' +} + +{ #category : #'instance creation' } +PhLFileBrowser class >> openOn: aFileReferenceOrPathString [ + + ^ self new + path: aFileReferenceOrPathString; + open. +] + +{ #category : #action } +PhLFileBrowser >> open [ + self visit +] + +{ #category : #accessing } +PhLFileBrowser >> path: aFileReferenceOrPathString [ + "Opens an OS-specific file and directory browser on ==aFileReference==. If aFileReference is a file, opens the browser on its containing directory instead." + | ref | + aFileReferenceOrPathString isNil ifTrue: [ ^ nil ]. + ref := aFileReferenceOrPathString asFileReference. + ref exists ifFalse: [ ^ nil ]. + + ref := ref isFile ifTrue: [ ref parent ] ifFalse: [ ref ]. + (ref isNil or: [ ref exists not ]) + ifTrue: [ ^ nil ]. + + path := ref fullName. +] + +{ #category : #visiting } +PhLFileBrowser >> visitMacOS: aPlatform [ + ^ PhLProcessWrapper new + shellCommand; + addArgument: ('open "{1}"' format: {path}); + runUnwatch +] + +{ #category : #visiting } +PhLFileBrowser >> visitUnix: aPlatform [ + ^ PhLProcessWrapper new + shellCommand; + addArgument: ('xdg-open "{1}"' format: {path}); + runUnwatch +] + +{ #category : #visiting } +PhLFileBrowser >> visitWindows: aPlatform [ + ^ aPlatform privShellExplore: path +] diff --git a/src/PharoLauncher-Core/PhLImage.class.st b/src/PharoLauncher-Core/PhLImage.class.st index d48608d3..4c919a5a 100644 --- a/src/PharoLauncher-Core/PhLImage.class.st +++ b/src/PharoLauncher-Core/PhLImage.class.st @@ -204,7 +204,7 @@ PhLImage >> setLocation: aFile [ { #category : #printing } PhLImage >> showNativeFolder [ - OSPlatform current openFileBrowserOn: file + PhLFileBrowser openOn: file ] { #category : #accessing } diff --git a/src/PharoLauncher-Core/PhLProcessWrapper.class.st b/src/PharoLauncher-Core/PhLProcessWrapper.class.st index 048fdd1b..c686f100 100644 --- a/src/PharoLauncher-Core/PhLProcessWrapper.class.st +++ b/src/PharoLauncher-Core/PhLProcessWrapper.class.st @@ -17,15 +17,6 @@ Class { #category : #'PharoLauncher-Core-Download' } -{ #category : #'execution - public' } -PhLProcessWrapper class >> command: aCommand [ - ^ Smalltalk os isWindows - ifTrue: [ OSWSWinProcess new - shellCommand: aCommand; - run ] - ifFalse: [ OSProcess command: aCommand utf8Encoded asString ] -] - { #category : #testing } PhLProcessWrapper class >> isCommandAvailable: aCommand [ | process | @@ -39,21 +30,6 @@ PhLProcessWrapper class >> isCommandAvailable: aCommand [ do: [ ^ false ] ] -{ #category : #'execution - public' } -PhLProcessWrapper class >> waitForLinuxCommand: aCommand timeout: aDuration [ - | future externalProcess | - - future := [externalProcess := self command: aCommand. - [externalProcess isComplete] - whileFalse: [(Delay forMilliseconds: 50) wait]. ] future. - [ future waitForCompletion: aDuration ] - on: TKTTimeoutException - do: [ :error | - externalProcess isComplete ifFalse: - [ externalProcess sigkill. - PhLProcessTimeOut signal ] ] -] - { #category : #building } PhLProcessWrapper >> addArgument: aString [ arguments add: aString diff --git a/src/PharoLauncher-Core/PhLVirtualMachine.class.st b/src/PharoLauncher-Core/PhLVirtualMachine.class.st index dfb9dfe7..2503bec6 100644 --- a/src/PharoLauncher-Core/PhLVirtualMachine.class.st +++ b/src/PharoLauncher-Core/PhLVirtualMachine.class.st @@ -158,7 +158,7 @@ PhLVirtualMachine >> removeFromSystem [ { #category : #actions } PhLVirtualMachine >> showInFolder [ - OSPlatform current openFileBrowserOn: self vmStore / name + PhLFileBrowser openOn: self vmStore / name ] { #category : #updating } diff --git a/src/PharoLauncher-Core/UnixPlatform.extension.st b/src/PharoLauncher-Core/UnixPlatform.extension.st deleted file mode 100644 index 24393525..00000000 --- a/src/PharoLauncher-Core/UnixPlatform.extension.st +++ /dev/null @@ -1,6 +0,0 @@ -Extension { #name : #UnixPlatform } - -{ #category : #'*PharoLauncher-Core' } -UnixPlatform >> privOpenFileBrowserOn: pathString [ - ^ PhLProcessWrapper command: ('xdg-open "{1}"' format: {pathString}) -] diff --git a/src/PharoLauncher-Core/Win32Platform.extension.st b/src/PharoLauncher-Core/Win32Platform.extension.st index 3079b148..f816048e 100644 --- a/src/PharoLauncher-Core/Win32Platform.extension.st +++ b/src/PharoLauncher-Core/Win32Platform.extension.st @@ -1,11 +1,5 @@ Extension { #name : #Win32Platform } -{ #category : #'*PharoLauncher-Core' } -Win32Platform >> privOpenFileBrowserOn: pathString [ - self privShellExplore: pathString - -] - { #category : #'*PharoLauncher-Core' } Win32Platform >> privShellExecute: lpOperation file: lpFile parameters: lpParameters directory: lpDirectory show: nShowCmd [ diff --git a/src/PharoLauncher-Tests-Core/PhLFileBrowserTest.class.st b/src/PharoLauncher-Tests-Core/PhLFileBrowserTest.class.st new file mode 100644 index 00000000..57dec226 --- /dev/null +++ b/src/PharoLauncher-Tests-Core/PhLFileBrowserTest.class.st @@ -0,0 +1,12 @@ +Class { + #name : #PhLFileBrowserTest, + #superclass : #TestCase, + #category : #'PharoLauncher-Tests-Core' +} + +{ #category : #tests } +PhLFileBrowserTest >> testCanOpenAFileBrowserOnImageFolder [ + | path | + path := Smalltalk image imageDirectory fullName. + PhLFileBrowser openOn: path. +]