Skip to content

Proposal: Opening/Closing Mechanism for Zip Files #1947

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

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ protected void internalAdd(Widget widget, Object parentElementOrTreePath,
}
assertElementsNotNull(parent, elements);
}
internalRefresh(parent);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import org.eclipse.core.filesystem.ZipFileUtil;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.OperationCanceledException;
Expand Down Expand Up @@ -270,7 +272,7 @@ private static String getLocation(IResource resource) {

private boolean containsLinkedResource(IResource[] resources) {
for (IResource resource : resources) {
if (resource != null && resource.isLinked()) { // paranoia code, can not be null
if (resource != null && resource.isLinked() && !ZipFileUtil.isOpenZipFile(resource.getLocationURI())) { // paranoia code, can not be null
return true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion bundles/org.eclipse.ui.editors/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Export-Package:
org.eclipse.ui.internal.editors.text.codemining.annotation;x-internal:=true,
org.eclipse.ui.internal.texteditor;x-internal:=true,
org.eclipse.ui.internal.texteditor.stickyscroll;x-internal:=true,
org.eclipse.ui.texteditor
org.eclipse.ui.texteditor,
org.eclipse.ui.editors.zip
Require-Bundle:
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
org.eclipse.core.expressions;bundle-version="[3.9.0,4.0.0)",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions bundles/org.eclipse.ui.editors/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ PreferencePages.Annotations= Annotations
PreferencePages.QuickDiff= Quick Diff
PreferencePages.Accessibility= Accessibility
PreferencePages.Spelling= Spelling
Editors.ZipFileEditor = Open Zip File

lastSaveReferenceProvider.label= Version on &Disk

Expand Down
13 changes: 13 additions & 0 deletions bundles/org.eclipse.ui.editors/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,19 @@
/>
</editor>
</extension>

<extension
point="org.eclipse.ui.editors">
<editor
default="true"
name="%Editors.ZipFileEditor"
icon="$nl$/icons/full/obj16/zip_file_open.png"
class="org.eclipse.ui.editors.zip.ZipFileEditor"
id="ZipFileEditor">
<contentTypeBinding contentTypeId="zipfile"/>
</editor>
</extension>

<extension
point="org.eclipse.ui.preferencePages">
<page
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* 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.editors.zip;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

import org.eclipse.core.runtime.CoreException;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ZipFileTransformer;

import org.eclipse.jface.dialogs.MessageDialog;

import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.part.FileEditorInput;

import org.eclipse.ui.editors.text.TextEditor;

/**
* @since 3.18
*/
public class ZipFileEditor extends TextEditor {

@Override
protected void doSetInput(IEditorInput input) throws CoreException {
super.doSetInput(input);
IWorkbenchPartSite site= getSite();
Shell shell= site.getShell();
if (input instanceof FileEditorInput fileEditorInput) {
IFile file= fileEditorInput.getFile();
openAndRefresh(file, shell);
}
Display display= shell.getDisplay();
display.asyncExec(() -> {
site.getPage().closeEditor(this, false);
});
}

@Override
public void createPartControl(Composite parent) {
return;
}

public static void openAndRefresh(IFile file, Shell shell) {
try {
ZipFileTransformer.openZipFile(file, true);
} catch (CoreException e) {
MessageDialog.openError(shell, "Error opening zip file", e.getMessage()); //$NON-NLS-1$
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;

import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.filesystem.ZipFileUtil;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.Assert;
Expand Down Expand Up @@ -319,7 +320,7 @@ private boolean canDelete(List<? extends IResource> resources) {
private boolean containsLinkedResource(List<? extends IResource> resources) {
for (int i = 0; i < resources.size(); i++) {
IResource resource = resources.get(i);
if (resource.isLinked()) {
if (resource.isLinked() && !ZipFileUtil.isOpenZipFile(resource.getLocationURI())) {
return true;
}
}
Expand Down Expand Up @@ -389,7 +390,7 @@ private boolean confirmDeleteNonProjects(List<? extends IResource> resources) {
if (resources.size() == 1) {
title = IDEWorkbenchMessages.DeleteResourceAction_title1;
IResource resource = resources.get(0);
if (resource.isLinked()) {
if (resource.isLinked() && !ZipFileUtil.isOpenZipFile(resource.getLocationURI())) {
msg = NLS
.bind(
IDEWorkbenchMessages.DeleteResourceAction_confirmLinkedResource1,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion bundles/org.eclipse.ui.ide/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ DecoratorSpecificContentType.label = File Icons Based On Content Analysis
DecoratorSpecificContentType.description = Displays an icon based on the examination of the contents of a file. This yields a more precise answer than one derived simply from the file name.
DecoratorSpecificResourceFilterType.label = Containers with Resource Filters
DecoratorSpecificResourceFilterType.description = Displays an icon based on the presence of resource filters on a container.
DecoratorZipFile.label = Zip Files
DecoratorZipFile.description = Adds an icon decoration to linked zip files.
OpenWorkspaceFileAction.label = Open Reso&urce...
SelectWorkingSetsAction.label = &Working Sets
SelectWorkingSetsAction.tooltip = Modify window working set
Expand Down Expand Up @@ -201,7 +203,9 @@ command.copyMarkerResourceQualifiedName.name=Copy Resource Qualified Name To Cli
command.copyMarkerResourceQualifiedName.label=Resource Qualified Name
command.copyMarkerResourceQualifiedName.description=Copies markers resource qualified name to the clipboard
command.copyMarkerResourceQualifiedName.mnemonic=Q

command.name.openZipFile=Open Zip File
command.name.closeZipFile=Close Zip File
filesystem.file.zip=Zip file

command.showInQuickMenu.name= Show In...
command.showInQuickMenu.description = Open the Show In menu
Expand Down
79 changes: 77 additions & 2 deletions bundles/org.eclipse.ui.ide/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,21 @@

<extension
point="org.eclipse.ui.decorators">
<decorator
adaptable="true"
state="true"
label="%DecoratorZipFile.label"
class="org.eclipse.ui.internal.ide.ZipFileDecorator"
id="org.eclipse.ui.ZipFileDecorator">
<description>
%DecoratorZipFile.description
</description>
<enablement>
<objectClass
name="org.eclipse.core.resources.IResource">
</objectClass>
</enablement>
</decorator>
<decorator
lightweight="true"
adaptable="true"
Expand Down Expand Up @@ -1089,7 +1104,17 @@
id="org.eclipse.ui.ide.markers.copyMarkerResourceQualifiedName"
name="%command.copyMarkerResourceQualifiedName.name"
defaultHandler="org.eclipse.ui.internal.views.markers.CopyMarkerResourceQualifiedNameHandler">
</command>
</command>
<command
id="org.eclipse.ui.commands.openZipFile"
name="%command.name.openZipFile"
defaultHandler="org.eclipse.ui.ide.fileSystem.zip.OpenZipFileHandler">
</command>
<command
id="org.eclipse.ui.commands.closeZipFile"
name="%command.name.closeZipFile"
defaultHandler="org.eclipse.ui.ide.fileSystem.zip.CloseZipFileHandler">
</command>
</extension>

<extension
Expand Down Expand Up @@ -2190,6 +2215,50 @@
</visibleWhen>
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
<command
commandId="org.eclipse.ui.commands.openZipFile"
label="%command.name.openZipFile"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="activeMenuSelection">
<iterate
ifEmpty="false">
<adapt
type="org.eclipse.core.resources.IFile">
<or>
<test
property="org.eclipse.core.resources.zipFile"
value="true">
</test>
</or>
</adapt>
</iterate>
</with>
</visibleWhen>
</command>
<command
commandId="org.eclipse.ui.commands.closeZipFile"
label="%command.name.closeZipFile"
style="push">
<visibleWhen
checkEnabled="false">
<with
variable="activeMenuSelection">
<iterate
ifEmpty="false">
<adapt
type="org.eclipse.core.internal.resources.VirtualZipFolder">
</adapt>
</iterate>
</with>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.handlers">
Expand Down Expand Up @@ -2718,5 +2787,11 @@
markerType="org.eclipse.core.resources.noExplicitEncoding">
</markerResolutionGenerator>
</extension>

<extension
point="org.eclipse.ui.ide.filesystemSupport">
<filesystemContributor
class="org.eclipse.ui.ide.fileSystem.zip.ZipFileSystemContributor"
label="%filesystem.file.zip"
scheme="zip"/>
</extension>
</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*******************************************************************************
* 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.net.URISyntaxException;

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.core.runtime.CoreException;
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;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;

/**
* This class represents a handler for closing an opened zip file.
*
* @since 3.23
*/
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 structuredSelection)) {
return null;
}
if (!(structuredSelection.getFirstElement() instanceof IFolder folder)) {
return null;
}
try {
ZipFileTransformer.closeZipFile(folder);
} catch (CoreException | URISyntaxException e) {
IDEWorkbenchPlugin.log(e.getMessage(), e);
MessageDialog.openError(shell, "Error closing zip file", e.getMessage()); //$NON-NLS-1$
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*******************************************************************************
* 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.IFile;
import org.eclipse.core.resources.ZipFileTransformer;
import org.eclipse.core.runtime.CoreException;
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;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;

/**
* This class represents a handler for opening zip files.
*
* @since 3.23
*/
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);
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (!(selection instanceof IStructuredSelection structuredSelection)) {
return null;
}
if (!(structuredSelection.getFirstElement() instanceof IFile file)) {
return null;
}
try {
ZipFileTransformer.openZipFile(file, true);
} catch (CoreException e) {
IDEWorkbenchPlugin.log(e.getMessage(), e);
MessageDialog.openError(shell, "Error opening zip file", e.getMessage()); //$NON-NLS-1$
}
return null;
}
}
Loading