Skip to content

Commit

Permalink
Improved management of package.properties file (#123) (fix #117, fix #…
Browse files Browse the repository at this point in the history
…119)

An uncompressed mimetype file at the beginning of the oxt files has been added. It is supposed to help with the recognition of the oxt file type on Apple platforms.

Updating the package.properties file will be done either through the CheckBoxTreeViewer or through the text editor. Changing one will change the other. The loading of this window has been optimized (a few seconds).

Files and directories that are symbolic links are now visible in the CheckBoxTreeViewer (ie: no more filtering) and taken into account in the build of oxt archives. This allows to benefit from a single source for the location of libraries and therefore easier updates.
  • Loading branch information
prrvchr authored Dec 23, 2024
1 parent 567c54c commit 67437ab
Show file tree
Hide file tree
Showing 27 changed files with 683 additions and 309 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/docs/loeclipse-doc/help/html/api/
/java/jodconnector.jar
/site.tar.gz
/.metadata/
1 change: 1 addition & 0 deletions core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Export-Package: org.libreoffice.ide.eclipse.core,
org.libreoffice.ide.eclipse.core.editors.registry,
org.libreoffice.ide.eclipse.core.editors.syntax,
org.libreoffice.ide.eclipse.core.editors.utils,
org.libreoffice.ide.eclipse.core.export,
org.libreoffice.ide.eclipse.core.gui,
org.libreoffice.ide.eclipse.core.gui.rows,
org.libreoffice.ide.eclipse.core.i18n,
Expand Down
2 changes: 1 addition & 1 deletion core/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
target="${java_target}" source="${java_source}"
debug="${debug}"
classpathref="core.dependencies.path"
excludes="**/unittests/**"/>
excludes="**/unittests/**, **Test*"/>
</target>

<target name="core.plugin" depends="core.version, core.compile, javadocs">
Expand Down
File renamed without changes
9 changes: 9 additions & 0 deletions core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,13 @@
<configurationType id="org.libreoffice.ide.eclipse.core.launchlibreoffice" />
</shortcut>
</extension>
<extension
point="org.eclipse.ui.exportWizards">
<wizard
category="org.libreoffice.ide.eclipse.core.uno"
class="org.libreoffice.ide.eclipse.core.export.AntScriptExportWizard"
icon="/icons/export_ant.gif"
id="org.libreoffice.ide.eclipse.core.java.antScript"
name="Generate Ant Script File"/>
</extension>
</plugin>
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public boolean visit(IResource pResource) throws CoreException {

boolean visitChildren = false;
if (TypesBuilder.sBuildState == 1) {
if (IResource.FILE == pResource.getType() && "idl".equals(pResource.getFileExtension())) { //$NON-NLS-1$
if (IResource.FILE == pResource.getType() && "idl".equalsIgnoreCase(pResource.getFileExtension())) { //$NON-NLS-1$

TypesBuilder.runIdlcOnFile((IFile) pResource, mProgressMonitor);
if (mProgressMonitor != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public boolean visit(IResourceDelta pDelta) throws CoreException {
&& resPath.toString().startsWith(idlPath.toString())) {
visitChildren = true;
} else {
if (pDelta.getResource() instanceof IFile && resPath.getFileExtension().equals("idl")) { //$NON-NLS-1$
if (pDelta.getResource() instanceof IFile && "idl".equalsIgnoreCase(resPath.getFileExtension())) { //$NON-NLS-1$
visitChildren = false;
mChangedIdl = true;
} else if (pDelta.getResource() instanceof IFile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,22 @@
************************************************************************/
package org.libreoffice.ide.eclipse.core.editors.pack;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ICheckStateProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.layout.GridData;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer;
import org.eclipse.ui.forms.SectionPart;
import org.eclipse.ui.forms.widgets.ExpandableComposite;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.model.WorkbenchContentProvider;
import org.eclipse.ui.model.WorkbenchLabelProvider;
import org.libreoffice.ide.eclipse.core.editors.Messages;
import org.libreoffice.ide.eclipse.core.internal.helpers.UnoidlProjectHelper;
import org.libreoffice.ide.eclipse.core.model.pack.PackagePropertiesModel;
import org.libreoffice.ide.eclipse.core.model.utils.IModelChangedListener;

Expand All @@ -80,6 +75,19 @@ public ContentsSection(PackageFormPage pPage) {

mPage = pPage;
PackagePropertiesModel model = ((PackagePropertiesEditor) mPage.getEditor()).getModel();

Section section = getSection();

section.setText(Messages.getString("ContentsSection.Title")); //$NON-NLS-1$
section.setLayoutData(new GridData(GridData.FILL_BOTH));

mTreeViewer = new ContainerCheckedTreeViewer(section);
// Configure the tree viewer
mTreeViewer.setLabelProvider(new WorkbenchLabelProvider());
WorkbenchContentProvider provider = new WorkbenchContentProvider();
mTreeViewer.setContentProvider(provider);
mTreeViewer.setComparator(new ViewerComparator(String.CASE_INSENSITIVE_ORDER));

model.addChangeListener(new IModelChangedListener() {

@Override
Expand All @@ -94,46 +102,59 @@ public void modelSaved() {
}
});

Section section = getSection();

section.setText(Messages.getString("ContentsSection.Title")); //$NON-NLS-1$
section.setLayoutData(new GridData(GridData.FILL_BOTH));

mTreeViewer = new ContainerCheckedTreeViewer(section);
// Configure the tree viewer
mTreeViewer.setLabelProvider(new WorkbenchLabelProvider());
WorkbenchContentProvider provider = new WorkbenchContentProvider();
mTreeViewer.setContentProvider(provider);
mTreeViewer.addCheckStateListener(new ICheckStateListener() {

@Override
public void checkStateChanged(CheckStateChangedEvent pEvent) {
if (pEvent.getElement() instanceof IAdaptable) {
IResource res = ((IAdaptable) pEvent.getElement()).getAdapter(IResource.class);
if (pEvent.getChecked()) {
model.addResource(res);
} else {
model.removeResource(res);
}
}
}
});

PackagePropertiesEditor editor = (PackagePropertiesEditor) mPage.getEditor();
mTreeViewer.setCheckStateProvider(new ICheckStateProvider() {

@Override
public boolean isChecked(Object pElement) {
if (pElement instanceof IAdaptable) {
IResource res = ((IAdaptable) pElement).getAdapter(IResource.class);
return model.isChecked(res);
}
return false;
}

List<IResource> contents = getContents();
editor.getModel().clearContents();
for (IResource resource : contents) {
editor.getModel().addContent(resource);
@Override
public boolean isGrayed(Object pElement) {
if (pElement instanceof IAdaptable) {
IResource res = ((IAdaptable) pElement).getAdapter(IResource.class);
return model.isGrayed(res);
}
return false;
}

});

mTreeViewer.addFilter(new ViewerFilter() {

@Override
public boolean select(Viewer pViewer, Object pParentElement, Object pElement) {
/*
* Files to exclude: .* Folders to exclude: build, bin
*/
boolean select = true;
if (pElement instanceof IAdaptable) {
IResource resource = ((IAdaptable) pElement).getAdapter(IResource.class);
if (resource != null) {
// FIXME: If we want to be able to see soft link pointing outside
// FIXME: the Package we need to accept resource not contained in package
if (resource.getName().startsWith(".") || //$NON-NLS-1$
resource.getName().equals("build") || //$NON-NLS-1$
resource.getName().equals("bin") || //$NON-NLS-1$
UnoidlProjectHelper.isContainedInPackage(resource)) {
select = false;
resource.getName().equals("bin")) { //$NON-NLS-1$
return false;
}

// Check if the resource is already selected somewhere
Expand All @@ -143,96 +164,23 @@ public boolean select(Viewer pViewer, Object pParentElement, Object pElement) {
if (model.getBasicLibraries().contains(resource)
|| model.getDialogLibraries().contains(resource)
|| model.getDescriptionFiles().containsValue(resource)) {
select = false;
return false;
}
}
}

return select;
return true;
}
});

IEditorInput input = mPage.getEditorInput();
if (input instanceof IFileEditorInput) {
IFileEditorInput fileInput = (IFileEditorInput) input;
mTreeViewer.setInput(fileInput.getFile().getProject());
}

section.setClient(mTreeViewer.getControl());

}

/**
* @return the list of files and folders to add to the package
*/
public List<IResource> getContents() {
ArrayList<IResource> contents = new ArrayList<IResource>();

// Write the selections to the document
Object[] checked = mTreeViewer.getCheckedElements();

for (Object o : checked) {
if (o instanceof IAdaptable) {
IResource res = ((IAdaptable) o).getAdapter(IResource.class);
if (res != null) {
addResourceToContent(contents, res);
}
}
public void setContents() {
// Initialize TreeView
if (mTreeViewer != null) {
mTreeViewer.setInput(mPage.getProject());
}

return contents;
}

/**
* Add a resource to the contents list, but removes all duplicates entries (all files of a selected directory).
*
* @param pContents
* the resource list to update
* @param pResource
* the resource to add
*/
private void addResourceToContent(ArrayList<IResource> pContents, IResource pResource) {
int i = 0;
boolean isSubResource = false;

ArrayList<String> checkedFolderPaths = new ArrayList<String>();

while (i < checkedFolderPaths.size() && !isSubResource) {
String path = pResource.getProjectRelativePath().toString();
if (path.startsWith(checkedFolderPaths.get(i))) {
isSubResource = true;
}
i++;
}

if (!isSubResource && !mTreeViewer.getGrayed(pResource) && pResource.getType() == IResource.FOLDER) {
String path = pResource.getProjectRelativePath().toString();
checkedFolderPaths.add(path);
pContents.add(pResource);
} else if (!isSubResource && !mTreeViewer.getGrayed(pResource)) {
pContents.add(pResource);
}
}

/**
* Updates the section using the new contents.
*
* @param pContents
* the package contents to put in the section
*/
public void setContents(List<IResource> pContents) {
// Split the string into several parts and find the files
if (mPage.getEditorInput() instanceof IFileEditorInput) {
IFileEditorInput input = (IFileEditorInput) mPage.getEditorInput();
IProject prj = input.getFile().getProject();

mTreeViewer.setCheckedElements(new Object[] {});

for (IResource res : pContents) {
if (res.getProject().equals(prj) && res.exists()) {
mTreeViewer.setChecked(res, true);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public class PackageDescriptionSection extends SectionPart {

private static final String P_NAME = "__p_name"; //$NON-NLS-1$
private static final String P_LOCALE = "__p_locale"; //$NON-NLS-1$
private static final int NAME_WIDTH = 200;
private static final int LOCALE_WIDTH = 200;
private static final int NAME_WIDTH = 250;
private static final int LOCALE_WIDTH = 250;

private PackageFormPage mPage;
private TableViewer mTableViewer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@
************************************************************************/
package org.libreoffice.ide.eclipse.core.editors.pack;

import java.util.List;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.forms.IManagedForm;
Expand All @@ -48,6 +46,7 @@
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.libreoffice.ide.eclipse.core.editors.Messages;
import org.libreoffice.ide.eclipse.core.model.pack.PackagePropertiesModel;

/**
* Page displaying the Package properties in a more user friendly way.
Expand Down Expand Up @@ -102,20 +101,13 @@ protected void createFormContent(IManagedForm pManagedForm) {
mLibs = new LibsSection(this);
mDescriptions = new PackageDescriptionSection(this);

// update the model from the source
PackagePropertiesEditor editor = (PackagePropertiesEditor) getEditor();
editor.getModel().setQuiet(true);

editor.loadFromSource();

List<IResource> contents = editor.getModel().getContents();
mContents.setContents(contents);

// Get the Libs and Descriptions properties from the document

mLibs.setLibraries(editor.getModel());

mDescriptions.setDescriptions(editor.getModel().getDescriptionFiles());
editor.getModel().setQuiet(false);
PackagePropertiesModel model = ((PackagePropertiesEditor) getEditor()).getModel();
model.setQuiet(true);
mContents.setContents();
mLibs.setLibraries(model);
mDescriptions.setDescriptions(model.getDescriptionFiles());
model.setQuiet(false);
}
}
Loading

0 comments on commit 67437ab

Please sign in to comment.