-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proposal: Opening/Closing Mechanism for Zip Files
# Proposal: Opening/Closing Mechanism for Zip Files ## Background The Eclipse IDE has no built in functionality to open Zip Files and read or manipulate their content. Because of this, other operations like searching inside of Zip Files or comparing two Zip Files were also not possible. ## Description This PR introduces UI support for accesing the opening/closing mechanism for Zip Files over the UI-menu. It is accessed by right-clicking the Zip File that should be opened and then clicking on "Open Zip File". Closing is accessed the same way but when right-clicking an opened Zip File. Please see #1408 for the PR on the repository **eclipse.platform** for the platform implementation and further information. Co-Authored-By: David Erdös <[email protected]>
- Loading branch information
1 parent
385b30b
commit 1ede745
Showing
6 changed files
with
302 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/fileSystem/zip/CloseZipFileHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Vector Informatik GmbH and others. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the Eclipse | ||
* Public License 2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: Vector Informatik GmbH - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.ui.ide.fileSystem.zip; | ||
|
||
import org.eclipse.core.commands.AbstractHandler; | ||
import org.eclipse.core.commands.ExecutionEvent; | ||
import org.eclipse.core.resources.IFolder; | ||
import org.eclipse.core.resources.ZipFileTransformer; | ||
import org.eclipse.jface.dialogs.MessageDialog; | ||
import org.eclipse.jface.viewers.ISelection; | ||
import org.eclipse.jface.viewers.IStructuredSelection; | ||
import org.eclipse.swt.widgets.Shell; | ||
import org.eclipse.ui.handlers.HandlerUtil; | ||
|
||
/** | ||
* This class represents a handler for closing an opened zip file. | ||
* | ||
* @since 3.132 | ||
*/ | ||
public class CloseZipFileHandler extends AbstractHandler { | ||
|
||
/** | ||
* Executes the handler action, which involves closing an opened zip file. | ||
* | ||
* @param event The event triggering the execution of this handler. | ||
*/ | ||
@Override | ||
public Object execute(ExecutionEvent event) { | ||
Shell shell = HandlerUtil.getActiveShell(event); | ||
ISelection selection = HandlerUtil.getCurrentSelection(event); | ||
|
||
if (!(selection instanceof IStructuredSelection)) { | ||
return null; | ||
} | ||
|
||
Object element = ((IStructuredSelection) selection).getFirstElement(); | ||
|
||
if (!(element instanceof IFolder)) { | ||
return null; | ||
} | ||
try { | ||
ZipFileTransformer.closeZipFile((IFolder) element); | ||
} catch (Exception e) { | ||
MessageDialog.openError(shell, "Error", "Error opening zip file"); //$NON-NLS-1$ //$NON-NLS-2$ | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/fileSystem/zip/OpenZipFileHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Vector Informatik GmbH and others. | ||
* | ||
* This program and the accompanying materials are made available under the terms of the Eclipse | ||
* Public License 2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: Vector Informatik GmbH - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.ui.ide.fileSystem.zip; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.net.URISyntaxException; | ||
|
||
import org.eclipse.core.commands.AbstractHandler; | ||
import org.eclipse.core.commands.ExecutionEvent; | ||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.core.resources.ZipFileTransformer; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.eclipse.jface.dialogs.MessageDialog; | ||
import org.eclipse.jface.dialogs.ProgressMonitorDialog; | ||
import org.eclipse.jface.operation.IRunnableWithProgress; | ||
import org.eclipse.jface.viewers.ISelection; | ||
import org.eclipse.jface.viewers.IStructuredSelection; | ||
import org.eclipse.swt.widgets.Shell; | ||
import org.eclipse.ui.handlers.HandlerUtil; | ||
|
||
/** | ||
* This class represents a handler for opening zip files. | ||
* | ||
* @since 3.132 | ||
*/ | ||
public class OpenZipFileHandler extends AbstractHandler { | ||
|
||
/** | ||
* Executes the handler action, which involves opening a zip file selected by | ||
* the user. | ||
* | ||
* @param event The event triggering the execution of this handler. | ||
*/ | ||
@Override | ||
public Object execute(ExecutionEvent event) { | ||
Shell shell = HandlerUtil.getActiveShell(event); | ||
ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell); | ||
ISelection selection = HandlerUtil.getCurrentSelection(event); | ||
if (!(selection instanceof IStructuredSelection)) { | ||
return null; | ||
} | ||
|
||
Object element = ((IStructuredSelection) selection).getFirstElement(); | ||
|
||
if (!(element instanceof IFile)) { | ||
return null; | ||
} | ||
try { | ||
dialog.run(true, false, new IRunnableWithProgress() { | ||
@Override | ||
public void run(IProgressMonitor monitor) throws InterruptedException { | ||
monitor.beginTask("Opening Zip File", 5); //$NON-NLS-1$ | ||
try { | ||
ZipFileTransformer.openZipFile((IFile) element, monitor, true); | ||
} catch (URISyntaxException | CoreException e) { | ||
throw new InterruptedException(e.getMessage()); | ||
} | ||
monitor.worked(1); | ||
} | ||
}); | ||
} catch (InvocationTargetException e) { | ||
e.printStackTrace(); | ||
} catch (InterruptedException e) { | ||
MessageDialog.openError(shell, "Error opening zip file", e.getMessage()); //$NON-NLS-1$ | ||
} | ||
return null; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...es/org.eclipse.ui.ide/src/org/eclipse/ui/ide/fileSystem/zip/ZipFileSystemContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 IBM Corporation and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.ui.ide.fileSystem.zip; | ||
|
||
import java.io.File; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
import org.eclipse.swt.widgets.FileDialog; | ||
import org.eclipse.swt.widgets.Shell; | ||
import org.eclipse.ui.ide.fileSystem.FileSystemContributor; | ||
|
||
/** | ||
* ZipFileSystemContributor is the zip example of a file system contributor. | ||
* | ||
* @since 3.23 | ||
*/ | ||
public class ZipFileSystemContributor extends FileSystemContributor { | ||
|
||
public ZipFileSystemContributor() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public URI getURI(String pathString) { | ||
try { | ||
if (pathString.startsWith("zip")) //$NON-NLS-1$ | ||
return new URI(pathString); | ||
} catch (URISyntaxException e1) { | ||
return null; | ||
} | ||
if (File.separatorChar != '/') | ||
pathString = pathString.replace(File.separatorChar, '/'); | ||
final int length = pathString.length(); | ||
StringBuffer pathBuf = new StringBuffer(length + 1); | ||
pathBuf.append("file:"); //$NON-NLS-1$ | ||
// There must be a leading slash in a hierarchical URI | ||
if (length > 0 && (pathString.charAt(0) != '/')) | ||
pathBuf.append('/'); | ||
// additional double-slash for UNC paths to distinguish from host | ||
// separator | ||
if (pathString.startsWith("//")) //$NON-NLS-1$ | ||
pathBuf.append('/').append('/'); | ||
pathBuf.append(pathString); | ||
try { | ||
//scheme, host, path, query, fragment | ||
return new URI("zip", null, "/", pathBuf.toString(), null); //$NON-NLS-1$ //$NON-NLS-2$ | ||
} catch (URISyntaxException e) { | ||
return null; | ||
} | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.eclipse.ui.ide.fileSystem.FileSystemContributor#browseFileSystem(java.lang.String, org.eclipse.swt.widgets.Shell) | ||
*/ | ||
@Override | ||
public URI browseFileSystem(String initialPath, Shell shell) { | ||
|
||
FileDialog dialog = new FileDialog(shell); | ||
|
||
if (initialPath.length() > 0) | ||
dialog.setFilterPath(initialPath); | ||
|
||
dialog.setFilterExtensions(new String[] {"*.zip"});//$NON-NLS-1$ | ||
|
||
String selectedFile = dialog.open(); | ||
if (selectedFile == null) | ||
return null; | ||
return getURI(selectedFile); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters