* merge with HEAD
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.ui/plugin.properties b/tcl/plugins/org.eclipse.dltk.tcl.ui/plugin.properties
index dc33648..47ddd66 100644
--- a/tcl/plugins/org.eclipse.dltk.tcl.ui/plugin.properties
+++ b/tcl/plugins/org.eclipse.dltk.tcl.ui/plugin.properties
@@ -47,7 +47,7 @@
# Preference pages
-TclPreferencePage=DLTK > Tcl
+TclPreferencePage=Tcl
TclManPagesPreferencePage=Man pages
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.ui/plugin.xml b/tcl/plugins/org.eclipse.dltk.tcl.ui/plugin.xml
index 43d8825..dae86fb 100644
--- a/tcl/plugins/org.eclipse.dltk.tcl.ui/plugin.xml
+++ b/tcl/plugins/org.eclipse.dltk.tcl.ui/plugin.xml
@@ -155,6 +155,9 @@
icon="icons/tcl_obj.gif"
id="org.eclipse.dltk.tcl.ui.editor.TclEditor"
name="DLTK Tcl Editor">
+ <contentTypeBinding
+ contentTypeId="org.eclipse.dltk.tclContentType">
+ </contentTypeBinding>
</editor>
</extension>
<extension
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/TclUILanguageToolkit.java b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/TclUILanguageToolkit.java
index 6debda1..0830ca0 100644
--- a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/TclUILanguageToolkit.java
+++ b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/TclUILanguageToolkit.java
@@ -15,6 +15,7 @@
import org.eclipse.dltk.tcl.core.TclLanguageToolkit;
import org.eclipse.dltk.ui.IDLTKUILanguageToolkit;
import org.eclipse.dltk.ui.ScriptElementLabels;
+import org.eclipse.dltk.ui.viewsupport.ScriptUILabelProvider;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.preference.IPreferenceStore;
@@ -77,5 +78,10 @@
public String getEditorID(Object inputElement) {
return "org.eclipse.dltk.tcl.ui.editor.TclEditor";
}
-
+ public String getInterpreterContainerID() {
+ return "org.eclipse.dltk.tcl.launching.INTERPRETER_CONTAINER";
+ }
+ public ScriptUILabelProvider createScripUILabelProvider() {
+ return null;
+ }
}
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/ManPageFolder.java b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/ManPageFolder.java
new file mode 100644
index 0000000..ae90449
--- /dev/null
+++ b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/ManPageFolder.java
@@ -0,0 +1,126 @@
+/**
+ *
+ */
+package org.eclipse.dltk.tcl.internal.ui.documentation;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+public class ManPageFolder {
+ private String path;
+ private HashMap pages = new HashMap();
+
+ public ManPageFolder(String path) {
+ super();
+ this.path = path;
+ }
+
+ public void addPage(String keyword, String file) {
+ pages.put(keyword, file);
+ }
+
+ public boolean verify() {
+ if (path == null)
+ return false;
+ File file = new File(path);
+ if (file.exists() && file.isDirectory())
+ return true;
+ return false;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public HashMap getPages() {
+ return pages;
+ }
+
+
+
+ public boolean equals(Object obj) {
+ if (!(obj instanceof ManPageFolder))
+ return false;
+ if (obj == this)
+ return true;
+ ManPageFolder f = (ManPageFolder) obj;
+ if (!f.path.equals(this.path))
+ return false;
+ if (!f.pages.equals(this.pages))
+ return false;
+ return true;
+ }
+
+ public static List readXML(String data) throws IOException {
+ // Wrapper the stream for efficient parsing
+ InputStream stream = new ByteArrayInputStream(data.getBytes());
+
+ // Do the parsing and obtain the top-level node
+ Element config = null;
+ try {
+ DocumentBuilder parser = DocumentBuilderFactory.newInstance()
+ .newDocumentBuilder();
+ parser.setErrorHandler(new DefaultHandler());
+ config = parser.parse(new InputSource(stream)).getDocumentElement();
+ } catch (SAXException e) {
+ throw new IOException("Bad XML format");
+ } catch (ParserConfigurationException e) {
+ stream.close();
+ throw new IOException("Bad XML format");
+ } finally {
+ stream.close();
+ }
+
+ if (!config.getNodeName().equalsIgnoreCase("manPages")) {
+ throw new RuntimeException("Bad top level node");
+ }
+
+ List folders = new ArrayList();
+
+ NodeList list = config.getChildNodes();
+ int length = list.getLength();
+ for (int i = 0; i < length; ++i) {
+ Node node = list.item(i);
+ short type = node.getNodeType();
+ if (type == Node.ELEMENT_NODE
+ && node.getNodeName().equalsIgnoreCase("location")) {
+ Element location = (Element) node;
+ String path = location.getAttribute("path");
+ ManPageFolder folder = new ManPageFolder(path);
+ NodeList locationChilds = location.getChildNodes();
+ int pages = locationChilds.getLength();
+ for (int j = 0; j < pages; ++j) {
+ node = locationChilds.item(j);
+ type = node.getNodeType();
+ if (type == Node.ELEMENT_NODE
+ && node.getNodeName().equalsIgnoreCase("page")) {
+ Element word = (Element) node;
+ String kw = word.getAttribute("keyword");
+ String file = word.getAttribute("file");
+ folder.addPage(kw, file);
+ }
+ }
+ folders.add(folder);
+ }
+ }
+
+ return folders;
+ }
+
+}
\ No newline at end of file
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/ManPagesLocationsBlock.java b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/ManPagesLocationsBlock.java
index 8791493..0503f67 100644
--- a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/ManPagesLocationsBlock.java
+++ b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/ManPagesLocationsBlock.java
@@ -9,34 +9,56 @@
*******************************************************************************/
package org.eclipse.dltk.tcl.internal.ui.documentation;
-
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.FileFilter;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
-import org.eclipse.dltk.tcl.core.TclPlugin;
import org.eclipse.dltk.tcl.ui.TclPreferenceConstants;
-import org.eclipse.dltk.ui.viewsupport.StorageLabelProvider;
-import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.dltk.ui.DLTKPluginImages;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.viewers.IBaseLabelProvider;
import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ListViewer;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -45,230 +67,241 @@
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Label;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
-
/**
* Control used to edit the libraries associated with a Interpreter install
*/
-public class ManPagesLocationsBlock implements SelectionListener, ISelectionChangedListener {
-
+public class ManPagesLocationsBlock implements SelectionListener,
+ ISelectionChangedListener {
+
/**
* Attribute name for the last path used to open a file/directory chooser
* dialog.
*/
protected static final String LAST_PATH_SETTING = "LAST_PATH_SETTING"; //$NON-NLS-1$
-
+
/**
* the prefix for dialog setting pertaining to this block
*/
protected static final String DIALOG_SETTINGS_PREFIX = "ManPagesLocationsBlock"; //$NON-NLS-1$
-
+
protected boolean fInCallback = false;
-
+
protected File fHome;
-
- //widgets
- protected ListViewer fLocationsViewer;
- private Button fUpButton;
- private Button fDownButton;
+
+ // widgets
+ protected TreeViewer fLocationsViewer;
+ private Button fClearButton;
private Button fRemoveButton;
private Button fAddButton;
protected Button fDefaultButton;
private ManLocationsContentProvider fLocationsContentProvider;
-
+
private PreferencePage fPage;
-
+
private IPreferenceStore fStore;
-
+
public ManPagesLocationsBlock(IPreferenceStore store, PreferencePage page) {
fPage = page;
fStore = store;
}
-
- protected IBaseLabelProvider getLabelProvider () {
- return new StorageLabelProvider();
+
+ protected IBaseLabelProvider getLabelProvider() {
+ return new LabelProvider() {
+
+ public Image getImage(Object element) {
+ if (element instanceof ManPageFolder) {
+ return DLTKPluginImages.DESC_OBJS_LIBRARY.createImage();
+ }
+ return DLTKPluginImages.DESC_OBJS_INFO_OBJ.createImage();
+ }
+
+ public String getText(Object element) {
+ if (element instanceof ManPageFolder) {
+ ManPageFolder folder = (ManPageFolder) element;
+ return folder.getPath();
+ }
+ return super.getText(element);
+ }
+
+ };
}
+
+ private List folders = null;
+
+ private String getFoldersAsXML() {
+ if (folders == null)
+ return null;
+
+ // Create the Document and the top-level node
+ DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder docBuilder;
+ try {
+ docBuilder = dfactory.newDocumentBuilder();
+ } catch (ParserConfigurationException e1) {
+ e1.printStackTrace();
+ return null;
+ }
+ Document doc = docBuilder.newDocument();
+
+ Element topElement = doc.createElement("manPages");
+ doc.appendChild(topElement);
+
+ for (Iterator iterator = folders.iterator(); iterator.hasNext();) {
+ ManPageFolder f = (ManPageFolder) iterator.next();
+ Element location = doc.createElement("location");
+ topElement.appendChild(location);
+ location.setAttribute("path", f.getPath());
+ for (Iterator iterator2 = f.getPages().keySet().iterator(); iterator2
+ .hasNext();) {
+ String name = (String) iterator2.next();
+ String file = (String) f.getPages().get(name);
+ Element page = doc.createElement("page");
+ location.appendChild(page);
+ page.setAttribute("keyword", name);
+ page.setAttribute("file", file);
+ }
+ }
+
- private class ManLocationsContentProvider implements IStructuredContentProvider {
-
- private Viewer fViewer;
-
- private File[] fLocations = new File[0];
+ ByteArrayOutputStream s = new ByteArrayOutputStream();
+
+ try {
+ TransformerFactory factory = TransformerFactory.newInstance();
+ Transformer transformer;
+ transformer = factory.newTransformer();
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
+
+ DOMSource source = new DOMSource(doc);
+ StreamResult outputTarget = new StreamResult(s);
+ transformer.transform(source, outputTarget);
+ } catch (TransformerConfigurationException e) {
+ e.printStackTrace();
+ } catch (TransformerException e) {
+ e.printStackTrace();
+ }
+
+ String result = null;
+ try {
+ result = s.toString("UTF8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+
+ return result; //$NON-NLS-1$
+ }
+
+
+
+ private class ManLocationsContentProvider implements ITreeContentProvider {
+
+ public Object[] getChildren(Object parentElement) {
+ if (parentElement instanceof ManPageFolder) {
+ ManPageFolder folder = (ManPageFolder) parentElement;
+ String[] ch = new String[folder.getPages().size()];
+ int i = 0;
+ for (Iterator iterator = folder.getPages().keySet().iterator(); iterator
+ .hasNext();) {
+ String kw = (String) iterator.next();
+ String file = (String) folder.getPages().get(kw);
+ ch[i++] = kw + " (" + file + ")";
+ }
+ return ch;
+ }
+ return new Object[0];
+ }
+
+ public Object getParent(Object element) {
+ return null;
+ }
+
+ public boolean hasChildren(Object element) {
+ if (element instanceof ManPageFolder)
+ return true;
+ return false;
+ }
public Object[] getElements(Object inputElement) {
- return fLocations;
+ if (folders == null)
+ return new Object[0];
+ return folders.toArray(new Object[folders.size()]);
}
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- fViewer = viewer;
- }
-
- public void setLocations (File[] locs) {
- fLocations = new File[locs.length];
- for (int i = 0; i < locs.length; i++) {
- fLocations[i] = new File(locs[i].getAbsolutePath());
- }
- fViewer.refresh();
}
- public File[] getLocations() {
- return fLocations;
- }
-
- /**
- * Returns the list of locations in the given selection.
- */
- private Set getSelectedLocations(IStructuredSelection selection) {
- Set locs= new HashSet();
- for (Iterator iter= selection.iterator(); iter.hasNext();) {
- Object element= iter.next();
- if (element instanceof File) {
- locs.add(element);
- }
- }
- return locs;
- }
-
- /**
- * Move the locations of the given selection up.
- */
- public void up(IStructuredSelection selection) {
- Set locations= getSelectedLocations(selection);
- for (int i= 0; i < fLocations.length - 1; i++) {
- if (locations.contains(fLocations[i + 1])) {
- File temp= fLocations[i];
- fLocations[i]= fLocations[i + 1];
- fLocations[i + 1]= temp;
- }
- }
- fViewer.refresh();
- fViewer.setSelection(selection);
- }
-
- /**
- * Move the locations of the given selection down.
- */
- public void down(IStructuredSelection selection) {
- Set locations= getSelectedLocations(selection);
- for (int i= fLocations.length - 1; i > 0; i--) {
- if (locations.contains(fLocations[i - 1])) {
- File temp= fLocations[i];
- fLocations[i]= fLocations[i - 1];
- fLocations[i - 1]= temp;
- }
- }
- fViewer.refresh();
- fViewer.setSelection(selection);
- }
-
- /**
- * Remove the locations contained in the given selection.
- */
- public void remove(IStructuredSelection selection) {
- List newLocations = new ArrayList();
- for (int i = 0; i < fLocations.length; i++) {
- newLocations.add(fLocations[i]);
- }
- Iterator iterator = selection.iterator();
- while (iterator.hasNext()) {
- Object element = iterator.next();
- if (element instanceof File) {
- newLocations.remove(element);
- }
- }
- fLocations = (File[]) newLocations.toArray(new File[newLocations.size()]);
- fViewer.refresh();
- }
-
- /**
- * Add the given locations before the selection, or after the existing locations
- * if the selection is empty.
- */
- public void add(File[] locs, IStructuredSelection selection) {
- List newLocations = new ArrayList(fLocations.length + locs.length);
- for (int i = 0; i < fLocations.length; i++) {
- newLocations.add(fLocations[i]);
- }
- List toAdd = new ArrayList(locs.length);
- for (int i = 0; i < locs.length; i++) {
- toAdd.add(new File(locs[i].getAbsolutePath()));
- }
- if (selection.isEmpty()) {
- newLocations.addAll(toAdd);
- } else {
- Object element= selection.getFirstElement();
- File firstLoc = (File) element;
- int index = newLocations.indexOf(firstLoc);
- newLocations.addAll(index, toAdd);
- }
- fLocations= (File[]) newLocations.toArray(new File[newLocations.size()]);
- fViewer.refresh();
- fViewer.setSelection(new StructuredSelection(locs), true);
- }
-
};
-
+
/**
* Creates and returns the source lookup control.
*
- * @param parent the parent widget of this control
+ * @param parent
+ * the parent widget of this control
*/
public Control createControl(Composite parent) {
Font font = parent.getFont();
-
+
Composite comp = new Composite(parent, SWT.NONE);
GridLayout topLayout = new GridLayout();
topLayout.numColumns = 2;
topLayout.marginHeight = 0;
topLayout.marginWidth = 0;
- comp.setLayout(topLayout);
+ comp.setLayout(topLayout);
GridData gd = new GridData(GridData.FILL_BOTH);
comp.setLayoutData(gd);
-
- fLocationsViewer= new ListViewer(comp);
+
+ fLocationsViewer = new TreeViewer(comp);
gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = 6;
fLocationsViewer.getControl().setLayoutData(gd);
- fLocationsContentProvider= new ManLocationsContentProvider();
+ fLocationsContentProvider = new ManLocationsContentProvider();
+ fLocationsViewer.setSorter(new ViewerSorter());
fLocationsViewer.setContentProvider(fLocationsContentProvider);
fLocationsViewer.setLabelProvider(getLabelProvider());
fLocationsViewer.setInput(this);
fLocationsViewer.addSelectionChangedListener(this);
-
+
Composite pathButtonComp = new Composite(comp, SWT.NONE);
GridLayout pathButtonLayout = new GridLayout();
pathButtonLayout.marginHeight = 0;
pathButtonLayout.marginWidth = 0;
pathButtonComp.setLayout(pathButtonLayout);
- gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL);
+ gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING
+ | GridData.HORIZONTAL_ALIGN_FILL);
pathButtonComp.setLayoutData(gd);
pathButtonComp.setFont(font);
-
- fAddButton= createPushButton(pathButtonComp, "Add");
+
+ fAddButton = createPushButton(pathButtonComp, "Add folder...");
fAddButton.addSelectionListener(this);
-
- fRemoveButton= createPushButton(pathButtonComp, "Remove");
+
+ fRemoveButton = createPushButton(pathButtonComp, "Remove");
fRemoveButton.addSelectionListener(this);
-
- fUpButton= createPushButton(pathButtonComp, "Up");
- fUpButton.addSelectionListener(this);
-
- fDownButton= createPushButton(pathButtonComp, "Down");
- fDownButton.addSelectionListener(this);
-
+
+ fClearButton = createPushButton(pathButtonComp, "Remove All");
+ fClearButton.addSelectionListener(this);
+
return comp;
}
-
/**
- * Creates and returns a button
+ * Creates and returns a button
*
- * @param parent parent widget
- * @param label label
+ * @param parent
+ * parent widget
+ * @param label
+ * label
* @return Button
*/
protected Button createPushButton(Composite parent, String label) {
@@ -276,62 +309,55 @@
button.setFont(parent.getFont());
button.setText(label);
setButtonLayoutData(button);
- return button;
+ return button;
}
-
- protected void setButtonLayoutData(Button button) {
+
+ protected void setButtonLayoutData(Button button) {
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
- int widthHint = 100;
+ int widthHint = 80;
Point minSize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
data.widthHint = Math.max(widthHint, minSize.x);
button.setLayoutData(data);
}
-
+
/**
- * Create some empty space
+ * Create some empty space
*/
protected void createVerticalSpacer(Composite comp, int colSpan) {
Label label = new Label(comp, SWT.NONE);
GridData gd = new GridData();
gd.horizontalSpan = colSpan;
label.setLayoutData(gd);
- }
-
+ }
+
/**
- * Updates buttons and status based on current libraries
+ * Updates buttons and status based on current mans
*/
public void update() {
updateButtons();
- IStatus status = Status.OK_STATUS;
-
- File[] locs = fLocationsContentProvider.getLocations();
- for (int i = 0; i < locs.length; i++) {
- IStatus st = validateLocation (locs[i]);
- if (!st.isOK()) {
- status = st;
- break;
+
+ if (folders != null) {
+ for (Iterator iterator = folders.iterator(); iterator.hasNext();) {
+ ManPageFolder v = (ManPageFolder) iterator.next();
+ if (!v.verify()) {
+ iterator.remove();
+ }
}
}
-
+
fLocationsViewer.refresh();
-
- updatePageStatus (status);
+
+ updatePageStatus(Status.OK_STATUS);
}
-
- public void setDefaults () {
- String res = fStore.getDefaultString(TclPreferenceConstants.DOC_MAN_PAGES_LOCATIONS);
+
+ public void setDefaults() {
+ String res = fStore
+ .getDefaultString(TclPreferenceConstants.DOC_MAN_PAGES_LOCATIONS);
fStore.setValue(TclPreferenceConstants.DOC_MAN_PAGES_LOCATIONS, res);
initialize();
}
-
- protected IStatus validateLocation (File location) {
- if (location.isDirectory())
- return Status.OK_STATUS;
- else
- return new Status(Status.ERROR, TclPlugin.PLUGIN_ID, 0, "Location should be a directory!", null);
- }
-
- protected void updatePageStatus (IStatus status) {
+
+ protected void updatePageStatus(IStatus status) {
if (fPage == null)
return;
fPage.setValid(status.isOK());
@@ -340,89 +366,175 @@
else
fPage.setErrorMessage(null);
}
-
- public void initialize () {
- String value = fStore.getString(TclPreferenceConstants.DOC_MAN_PAGES_LOCATIONS);
- String[] names = value.split(">");
- ArrayList files = new ArrayList (names.length);
- for (int i = 0; i < names.length; i++) {
- if (names[i].trim().length() == 0)
- continue;
- File f = new File (names[i]);
- files.add(f);
- }
- fLocationsContentProvider.setLocations((File[])files.toArray(new File[files.size()]));
+
+ public void initialize() {
+ String value = fStore
+ .getString(TclPreferenceConstants.DOC_MAN_PAGES_LOCATIONS);
+ try {
+ this.folders = ManPageFolder.readXML(value);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
update();
}
-
+
/**
* Saves settings
*/
- public void performApply() {
- File[] locs = fLocationsContentProvider.getLocations();
- StringBuffer buf = new StringBuffer();
- for (int i = 0; i < locs.length; i++) {
- buf.append(locs[i].getAbsolutePath());
- buf.append(">");
- }
- String value = buf.toString();
- fStore.setValue(TclPreferenceConstants.DOC_MAN_PAGES_LOCATIONS, value);
- }
-
- /* (non-Javadoc)
+ public void performApply() {
+ String xml = this.getFoldersAsXML();
+ if (xml != null)
+ fStore
+ .setValue(TclPreferenceConstants.DOC_MAN_PAGES_LOCATIONS,
+ xml);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
public void widgetSelected(SelectionEvent e) {
- Object source= e.getSource();
- if (source == fUpButton) {
- fLocationsContentProvider.up((IStructuredSelection) fLocationsViewer.getSelection());
- } else if (source == fDownButton) {
- fLocationsContentProvider.down((IStructuredSelection) fLocationsViewer.getSelection());
+ Object source = e.getSource();
+ if (source == fClearButton) {
+ folders.clear();
} else if (source == fRemoveButton) {
- fLocationsContentProvider.remove((IStructuredSelection) fLocationsViewer.getSelection());
+ IStructuredSelection selection = (IStructuredSelection) fLocationsViewer
+ .getSelection();
+ Object[] array = selection.toArray();
+ for (int i = 0; i < array.length; i++) {
+ if (array[i] instanceof ManPageFolder) {
+ for (Iterator iterator = folders.iterator(); iterator
+ .hasNext();) {
+ ManPageFolder f = (ManPageFolder) iterator.next();
+ if (f == array[i]) {
+ iterator.remove();
+ break;
+ }
+ }
+ }
+ }
} else if (source == fAddButton) {
- add((IStructuredSelection) fLocationsViewer.getSelection());
- }
-
+ add();
+ }
+
update();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
*/
- public void widgetDefaultSelected(SelectionEvent e) {}
-
-
- private void add(IStructuredSelection selection) {
- File locs = add();
- if (locs == null)
- return;
- fLocationsContentProvider.add(new File[] {locs}, selection);
- update ();
+ public void widgetDefaultSelected(SelectionEvent e) {
}
-
+
/**
* Open the file selection dialog, and add the return locations.
*/
- protected File add() {
- DirectoryDialog dialog = new DirectoryDialog(fLocationsViewer.getControl().getShell());
- dialog.setMessage("Select directory directly containing .html files with man pages");
+ protected void add() {
+ DirectoryDialog dialog = new DirectoryDialog(fLocationsViewer
+ .getControl().getShell());
+ dialog.setMessage("Select directory to search into");
String result = dialog.open();
- if (result != null) {;
- File file = new File(result);
- if (file != null) {
- if (!validateLocation(file).isOK()) {
- ErrorDialog errDlg = new ErrorDialog(fLocationsViewer.getControl().getShell(), "Error", "It is not correct location", validateLocation(file), 0);
- errDlg.open();
- return null;
+ if (result != null) {
+ final File file = new File(result);
+ if (this.folders == null)
+ this.folders = new ArrayList();
+ if (file != null && file.isDirectory()) {
+ ProgressMonitorDialog dialog2 = new ProgressMonitorDialog(null);
+ try {
+ dialog2.run(true, true, new IRunnableWithProgress() {
+ public void run(IProgressMonitor monitor) {
+ monitor.beginTask("Searching for man pages", 1);
+ performSearch(file);
+ monitor.done();
+ }
+
+ });
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
- return file;
+
}
}
- return null;
}
- /* (non-Javadoc)
+ private void performSearch(File dir) {
+ if (!dir.isDirectory())
+ return;
+
+ String name = dir.getName();
+
+ if (name.equals("TkLib") || name.equals("TclLib")
+ || name.equals("Keywords") || name.equals("UserCmd"))
+ return;
+
+ File[] childs = dir.listFiles(new FileFilter() {
+
+ public boolean accept(File file) {
+ if (file.isDirectory())
+ return true;
+ if (file.getName().startsWith("contents.htm"))
+ return true;
+ return false;
+ }
+
+ });
+ for (int i = 0; i < childs.length; i++) {
+ if (childs[i].isDirectory()) {
+ performSearch(childs[i]);
+ }
+ if (childs[i].getName().startsWith("contents.htm")) {
+ ManPageFolder folder = new ManPageFolder(dir.getAbsolutePath());
+ parseContentsFile(childs[i], folder);
+ if (folder.getPages().size() > 0 && !folders.contains(folder)) {
+ this.folders.add(folder);
+ }
+ }
+ }
+ }
+
+ private void parseContentsFile(File c, ManPageFolder folder) {
+ FileReader reader;
+ try {
+ reader = new FileReader(c);
+ } catch (FileNotFoundException e) {
+ return;
+ }
+ StringBuffer buf = new StringBuffer();
+ while (true) {
+ char cbuf[] = new char[1024];
+ try {
+ int read = reader.read(cbuf);
+ if (read >= 0) {
+ buf.append(cbuf, 0, read);
+ } else
+ break;
+ } catch (IOException e) {
+ break;
+ }
+ }
+ String result = buf.toString();
+ Pattern pattern = Pattern.compile(
+ "<a\\s+href=\"([a-zA-Z_0-9]+\\.html?)\"\\s*>(\\w+)</a>",
+ Pattern.CASE_INSENSITIVE);
+ Matcher matcher = pattern.matcher(result);
+ while (matcher.find()) {
+ String file = matcher.group(1);
+ if (file.equalsIgnoreCase("Copyright.htm"))
+ continue;
+ String word = matcher.group(2);
+ folder.addPage(word, file);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
* @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
*/
public void selectionChanged(SelectionChangedEvent event) {
@@ -433,32 +545,26 @@
* Refresh the enable/disable state for the buttons.
*/
private void updateButtons() {
- IStructuredSelection selection = (IStructuredSelection) fLocationsViewer.getSelection();
- fRemoveButton.setEnabled(!selection.isEmpty());
- boolean enableUp = true,
- enableDown = true;
- Object[] libraries = fLocationsContentProvider.getElements(null);
- if (selection.isEmpty() || libraries.length == 0) {
- enableUp = false;
- enableDown = false;
- } else {
- Object first = libraries[0];
- Object last = libraries[libraries.length - 1];
- for (Iterator iter= selection.iterator(); iter.hasNext();) {
- Object element= iter.next();
- Object lib;
- lib = element;
- if (lib == first) {
- enableUp = false;
- }
- if (lib == last) {
- enableDown = false;
- }
- }
- }
- fUpButton.setEnabled(enableUp);
- fDownButton.setEnabled(enableDown);
- }
-
+ fClearButton.setEnabled(folders != null && folders.size() > 0);
+ IStructuredSelection selection = (IStructuredSelection) fLocationsViewer
+ .getSelection();
+ boolean canRemove = true;
+ if (folders == null)
+ canRemove = false;
+ else {
+ List list = selection.toList();
+ for (Iterator iterator = list.iterator(); iterator.hasNext();) {
+ Object o = (Object) iterator.next();
+ if (!folders.contains(o))
+ canRemove = false;
+ break;
+ }
+ if (selection.isEmpty())
+ canRemove = false;
+ }
+
+ fRemoveButton.setEnabled(canRemove);
+ }
+
}
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/TclManPagesDocumentationProvider.java b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/TclManPagesDocumentationProvider.java
index 50094b1..00ddbfa 100644
--- a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/TclManPagesDocumentationProvider.java
+++ b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/documentation/TclManPagesDocumentationProvider.java
@@ -10,21 +10,29 @@
package org.eclipse.dltk.tcl.internal.ui.documentation;
import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
import java.io.Reader;
+import java.io.StringReader;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
import org.eclipse.dltk.core.IMember;
import org.eclipse.dltk.tcl.internal.ui.TclUI;
import org.eclipse.dltk.tcl.ui.TclPreferenceConstants;
import org.eclipse.dltk.ui.documentation.IScriptDocumentationProvider;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
public class TclManPagesDocumentationProvider implements
IScriptDocumentationProvider {
- private IManPagesLocation[] locations;
-
- private int oldHash = -1;
+ private List folders = null;
public Reader getInfo(IMember element, boolean lookIntoParents,
boolean lookIntoExternal) {
@@ -32,35 +40,51 @@
}
public Reader getInfo(String content) {
- initalizeLocations();
- for (int i = 0; i < locations.length; i++) {
- IManPagesLocation loc = locations[i];
- Reader reader = loc.getHtmlInfo(content);
- if (reader != null) { // TODO: what if several results there are?
- return reader;
+ initalizeLocations(false);
+
+ if (folders != null) {
+ for (Iterator iterator = folders.iterator(); iterator.hasNext();) {
+ ManPageFolder f = (ManPageFolder) iterator.next();
+ HashMap pages = f.getPages();
+ String ans = (String) pages.get(content);
+ if (ans != null) {
+ IPath filePath = new Path(f.getPath()).append(ans);
+ File file = filePath.toFile();
+ if (file != null && file.isFile()) {
+ try {
+ return new FileReader(file);
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
+ break;
+ }
}
}
+
return null;
}
- private void initalizeLocations() {
+ private void initalizeLocations(boolean force) {
+ if (!force && this.folders != null)
+ return;
+
+ TclUI.getDefault().getPreferenceStore().addPropertyChangeListener(
+ new IPropertyChangeListener() {
+
+ public void propertyChange(PropertyChangeEvent event) {
+ initalizeLocations(true);
+ }
+
+ });
+
String value = TclUI.getDefault().getPreferenceStore().getString(
TclPreferenceConstants.DOC_MAN_PAGES_LOCATIONS);
-
- if (locations == null || value.hashCode() != oldHash) {
- oldHash = value.hashCode();
- final String[] locs = value.split(">");
- final List list = new ArrayList();
- for (int i = 0; i < locs.length; i++) {
- File file = new File(locs[i].trim());
- if (file.isDirectory()) {
- list.add(new HtmlManPagesLocation(file));
- }
- }
-
- locations = (IManPagesLocation[]) list
- .toArray(new IManPagesLocation[list.size()]);
+ try {
+ this.folders = ManPageFolder.readXML(value);
+ } catch (IOException e) {
+ e.printStackTrace();
}
}
}
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/editor/TclEditor.java b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/editor/TclEditor.java
index 72b23ca..bd3aae2 100644
--- a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/editor/TclEditor.java
+++ b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/editor/TclEditor.java
@@ -23,7 +23,7 @@
import org.eclipse.dltk.tcl.ui.TclPreferenceConstants;
import org.eclipse.dltk.tcl.ui.text.TclPartitions;
import org.eclipse.dltk.ui.PreferenceConstants;
-import org.eclipse.dltk.ui.actions.IDLTKEditorActionDefinitionIds;
+import org.eclipse.dltk.ui.actions.IScriptEditorActionDefinitionIds;
import org.eclipse.dltk.ui.text.ScriptTextTools;
import org.eclipse.dltk.ui.text.folding.IFoldingStructureProvider;
import org.eclipse.jface.action.Action;
@@ -78,7 +78,7 @@
Action action = new TextOperationAction(DLTKEditorMessages
.getBundleForConstructedKeys(),
"Comment.", this, ITextOperationTarget.PREFIX); //$NON-NLS-1$
- action.setActionDefinitionId(IDLTKEditorActionDefinitionIds.COMMENT);
+ action.setActionDefinitionId(IScriptEditorActionDefinitionIds.COMMENT);
setAction("Comment", action); //$NON-NLS-1$
markAsStateDependentAction("Comment", true); //$NON-NLS-1$
@@ -86,7 +86,7 @@
action = new TextOperationAction(DLTKEditorMessages
.getBundleForConstructedKeys(),
"Uncomment.", this, ITextOperationTarget.STRIP_PREFIX); //$NON-NLS-1$
- action.setActionDefinitionId(IDLTKEditorActionDefinitionIds.UNCOMMENT);
+ action.setActionDefinitionId(IScriptEditorActionDefinitionIds.UNCOMMENT);
setAction("Uncomment", action); //$NON-NLS-1$
markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
@@ -94,7 +94,7 @@
action = new ToggleCommentAction(DLTKEditorMessages
.getBundleForConstructedKeys(), "ToggleComment.", this); //$NON-NLS-1$
action
- .setActionDefinitionId(IDLTKEditorActionDefinitionIds.TOGGLE_COMMENT);
+ .setActionDefinitionId(IScriptEditorActionDefinitionIds.TOGGLE_COMMENT);
setAction("ToggleComment", action); //$NON-NLS-1$
markAsStateDependentAction("ToggleComment", true); //$NON-NLS-1$
configureToggleCommentAction();
@@ -131,7 +131,7 @@
return TclUI.getDefault().getPreferenceStore();
}
- protected ScriptTextTools getTextTools() {
+ public ScriptTextTools getTextTools() {
return TclUI.getDefault().getTextTools();
}
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/navigation/ElementsView.java b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/navigation/ElementsView.java
index ae97b37..044566a 100644
--- a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/navigation/ElementsView.java
+++ b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/navigation/ElementsView.java
@@ -42,7 +42,6 @@
import org.eclipse.dltk.internal.ui.filters.IFilterElementNameProvider;
import org.eclipse.dltk.tcl.core.TclLanguageToolkit;
import org.eclipse.dltk.tcl.core.TclNature;
-import org.eclipse.dltk.tcl.core.TclPlugin;
import org.eclipse.dltk.tcl.internal.ui.TclUI;
import org.eclipse.dltk.ui.DLTKPluginImages;
import org.eclipse.dltk.ui.ModelElementSorter;
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/preferences/PreviewFile.txt b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/preferences/PreviewFile.txt
index 90cba6f..1d4275c 100644
--- a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/preferences/PreviewFile.txt
+++ b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/preferences/PreviewFile.txt
@@ -1,28 +1,21 @@
-# Print the contents of a global array on stdout.
-#
-# RCS: @(#) $Id: PreviewFile.txt,v 1.1 2007/02/22 08:40:13 asobolev Exp $
-#
-# Copyright (c) 1991-1993 The Regents of the University of California.
-# Copyright (c) 1994 Sun Microsystems, Inc.
-#
-# See the file "license.terms" for information on usage and redistribution
-# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+###############################################################################
+# Copyright (c) 2005, 2007 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
#
-proc parray {a {pattern *}} {
- upvar 1 $a array
- if {![array exists array]} {
- error "\"$a\" isn't an array"
- }
- set maxl 0
- foreach name [lsort [array names array $pattern]] {
- if {[string length $name] > $maxl} {
- set maxl [string length $name]
- }
- }
- set maxl [expr {$maxl + [string length $a] + 2}]
- foreach name [lsort [array names array $pattern]] {
- set nameString [format %s(%s) $a $name]
- puts stdout [format "%-*s = %s" $maxl $nameString $array($name)]
- }
+###############################################################################
+
+namespace eval myNamespace {
+ proc myproc ( a { b 20 } } {
+ upvar 1 $a array
+ s = [string length $a]
+ puts $array
+ set t 2.4
+ set s "Alfa"
+ return [expr { s + b }]
+ }
}
+
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/text/TclSourceViewerConfiguration.java b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/text/TclSourceViewerConfiguration.java
index 30f6010..ee8a21b 100644
--- a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/text/TclSourceViewerConfiguration.java
+++ b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/text/TclSourceViewerConfiguration.java
@@ -16,6 +16,7 @@
import org.eclipse.dltk.ui.CodeFormatterConstants;
import org.eclipse.dltk.ui.text.AbstractScriptScanner;
import org.eclipse.dltk.ui.text.IColorManager;
+import org.eclipse.dltk.ui.text.ScriptPresentationReconciler;
import org.eclipse.dltk.ui.text.ScriptSourceViewerConfiguration;
import org.eclipse.dltk.ui.text.SingleTokenScriptScanner;
import org.eclipse.dltk.ui.text.completion.ContentAssistProcessor;
@@ -60,7 +61,6 @@
public String[] getIndentPrefixes(ISourceViewer sourceViewer,
String contentType) {
- // TODO: what's a shit this method returns?
return new String[] { "\t", " " }; //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -108,7 +108,7 @@
public IPresentationReconciler getPresentationReconciler(
ISourceViewer sourceViewer) {
- PresentationReconciler reconciler = new PresentationReconciler();
+ PresentationReconciler reconciler = new ScriptPresentationReconciler();
reconciler
.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/text/TclTextTools.java b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/text/TclTextTools.java
index 4352b96..77ea985 100644
--- a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/text/TclTextTools.java
+++ b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/internal/ui/text/TclTextTools.java
@@ -9,6 +9,8 @@
*******************************************************************************/
package org.eclipse.dltk.tcl.internal.ui.text;
+import org.eclipse.dltk.internal.ui.editor.semantic.highlighting.PositionUpdater;
+import org.eclipse.dltk.internal.ui.editor.semantic.highlighting.SemanticHighlighting;
import org.eclipse.dltk.tcl.ui.text.TclPartitions;
import org.eclipse.dltk.ui.text.ScriptSourceViewerConfiguration;
import org.eclipse.dltk.ui.text.ScriptTextTools;
@@ -42,4 +44,14 @@
return fPartitionScanner;
}
+
+ public SemanticHighlighting[] getSemanticHighlightings() {
+ return new SemanticHighlighting[0];
+ }
+
+
+ public PositionUpdater getSemanticPositionUpdater() {
+ return null;
+ }
+
}
diff --git a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/ui/TclPreferenceConstants.java b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/ui/TclPreferenceConstants.java
index ccb7c92..0481c58 100644
--- a/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/ui/TclPreferenceConstants.java
+++ b/tcl/plugins/org.eclipse.dltk.tcl.ui/src/org/eclipse/dltk/tcl/ui/TclPreferenceConstants.java
@@ -402,7 +402,7 @@
TclPreferenceConstants.EDITOR_VARIABLE_COLOR,
new RGB(200, 0, 0));
- store.setDefault(TclPreferenceConstants.DOC_MAN_PAGES_LOCATIONS, "");
+ store.setDefault(TclPreferenceConstants.DOC_MAN_PAGES_LOCATIONS, "<manPages></manPages>");
store.setDefault(
TclPreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_BOLD, false);