|
From: <caw...@us...> - 2007-03-16 13:39:24
|
Revision: 2192
http://svn.sourceforge.net/rubyeclipse/?rev=2192&view=rev
Author: cawilliams
Date: 2007-03-16 06:39:20 -0700 (Fri, 16 Mar 2007)
Log Message:
-----------
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IOpenable.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/Openable.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/codemanipulation/StubUtility.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/EditorUtility.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IOpenable.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IOpenable.java 2007-03-16 13:34:20 UTC (rev 2191)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/IOpenable.java 2007-03-16 13:39:20 UTC (rev 2192)
@@ -170,4 +170,18 @@
* </ul>
*/
public void save(IProgressMonitor progress, boolean force) throws RubyModelException;
+
+ /**
+ * Finds and returns the recommended line separator for this element.
+ * The element's buffer is first searched and the first line separator in this buffer is returned if any.
+ * Otherwise the preference {@link org.eclipse.core.runtime.Platform#PREF_LINE_SEPARATOR}
+ * on this element's project or workspace is returned.
+ * Finally if no such preference is set, the system line separator is returned.
+ *
+ * @return the recommended line separator for this element
+ * @exception RubyModelException if this element does not exist or if an
+ * exception occurs while accessing its corresponding resource.
+ * @since 0.9.0
+ */
+ public String findRecommendedLineSeparator() throws RubyModelException;
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/Openable.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/Openable.java 2007-03-16 13:34:20 UTC (rev 2191)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/Openable.java 2007-03-16 13:39:20 UTC (rev 2192)
@@ -25,6 +25,7 @@
import org.rubypeople.rdt.core.WorkingCopyOwner;
import org.rubypeople.rdt.internal.codeassist.SelectionEngine;
import org.rubypeople.rdt.internal.core.buffer.BufferManager;
+import org.rubypeople.rdt.internal.core.util.Util;
/**
* @author cawilliams
@@ -379,4 +380,10 @@
SelectionEngine engine = new SelectionEngine();
return engine.select(cu, offset, offset + length - 1);
}
+
+ public String findRecommendedLineSeparator() throws RubyModelException {
+ IBuffer buffer = getBuffer();
+ String source = buffer == null ? null : buffer.getContents();
+ return Util.getLineSeparator(source, getRubyProject());
+ }
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/codemanipulation/StubUtility.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/codemanipulation/StubUtility.java 2007-03-16 13:34:20 UTC (rev 2191)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/codemanipulation/StubUtility.java 2007-03-16 13:39:20 UTC (rev 2192)
@@ -5,7 +5,10 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.rubypeople.rdt.core.IOpenable;
+import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.RubyModelException;
public class StubUtility {
@@ -45,4 +48,21 @@
String platformDefault= System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
return Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, platformDefault, scopeContext);
}
+
+ /**
+ * Examines a string and returns the first line delimiter found.
+ */
+ public static String getLineDelimiterUsed(IRubyElement elem) {
+ while (elem != null && !(elem instanceof IOpenable)) {
+ elem= elem.getParent();
+ }
+ if (elem != null) {
+ try {
+ return ((IOpenable) elem).findRecommendedLineSeparator();
+ } catch (RubyModelException exception) {
+ // Use project setting
+ }
+ }
+ return getProjectLineDelimiter(null);
+ }
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/EditorUtility.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/EditorUtility.java 2007-03-16 13:34:20 UTC (rev 2191)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/EditorUtility.java 2007-03-16 13:39:20 UTC (rev 2192)
@@ -262,4 +262,27 @@
return rProject;
}
+ /**
+ * Tests if a CU is currently shown in an editor
+ * @return the IEditorPart if shown, null if element is not open in an editor
+ */
+ public static IEditorPart isOpenInEditor(Object inputElement) {
+ IEditorInput input= null;
+
+ try {
+ input= getEditorInput(inputElement);
+ } catch (RubyModelException x) {
+ RubyPlugin.log(x.getStatus());
+ }
+
+ if (input != null) {
+ IWorkbenchPage p= RubyPlugin.getActivePage();
+ if (p != null) {
+ return p.findEditor(input);
+ }
+ }
+
+ return null;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|