Skip to content
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

PyEditor save actions: auto-update module level __updated__ variable + 1 Bug Fix #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
232 changes: 129 additions & 103 deletions plugins/org.python.pydev.core/src/org/python/pydev/core/FontUtils.java
Original file line number Diff line number Diff line change
@@ -1,103 +1,129 @@
/**
* Copyright (c) 2005-2011 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Eclipse Public License (EPL).
* Please see the license.txt included with this distribution for details.
* Any modifications to this file must keep this entire header intact.
*/
package org.python.pydev.core;

import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.osgi.service.environment.Constants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;

import com.aptana.shared_core.structure.Tuple;

/**
* <p><tt>FontUtils</tt> provides helper methods dealing with
* <tt>Font</tt>s.</p>
*
* @author André Berg
* @version 0.1
*/
public class FontUtils {

/**
* Selects a proper font name and height for various usage cases of monospaced fonts throughout Pydev.
*
* @param usage intended usage. See {@link IFontUsage} for valid values.
* @return a {@link Tuple} containing the font name as {@link String} and the base height as {@link Integer}.
* @throws IllegalArgumentException if <tt>usage</tt> is not found in {@link IFontUsage}.
*/
private static Tuple<String, Integer> getCodeFontNameAndHeight(int usage) throws IllegalArgumentException {
String fontName = "Courier New";
int fontHeight = 10;
if (Platform.getOS().equals(Constants.OS_MACOSX)) {
switch (usage) {
case IFontUsage.STYLED:
fontName = "Monaco";
fontHeight = 11;
break;
case IFontUsage.DIALOG:
// on OS X we need a different font because
// under Mac SWT the bitmap font rasterizer
// doesn't take hinting into account and thus
// makes small fonts rendered as bitmaps unreadable
// see http://aptanastudio.tenderapp.com/discussions/problems/2052-some-dialogs-have-unreadable-small-font-size
fontName = "Courier";
fontHeight = 11;
break;
case IFontUsage.WIDGET:
fontName = "Monaco";
fontHeight = 9;
break;
case IFontUsage.IMAGECACHE:
fontName = "Monaco";
fontHeight = 11;
break;

default:
throw new IllegalArgumentException(
"Invalid usage. See org.python.pydev.core.IFontUsage for valid values.");
}
} else {
switch (usage) {
case IFontUsage.STYLED:
fontName = "Courier New";
fontHeight = 10;
break;
case IFontUsage.DIALOG:
fontName = "Courier New";
fontHeight = 8;
break;
case IFontUsage.WIDGET:
fontName = "Courier New";
fontHeight = 10;
break;
case IFontUsage.IMAGECACHE:
fontName = "Courier New";
fontHeight = 9;
break;

default:
throw new IllegalArgumentException(
"Invalid usage. See org.python.pydev.core.IFontUsage for valid values.");
}
}
return new Tuple<String, Integer>(fontName, fontHeight);
}

public static FontData getFontData(int usage, boolean useDefaultJFaceFontIfPossible) {
if (useDefaultJFaceFontIfPossible) {
FontData[] textFontData = JFaceResources.getTextFont().getFontData();
if (textFontData.length == 1) {
return textFontData[0];
}
}
Tuple<String, Integer> codeFontDetails = FontUtils.getCodeFontNameAndHeight(IFontUsage.IMAGECACHE);
String fontName = codeFontDetails.o1;
int base = codeFontDetails.o2.intValue();
return new FontData(fontName, base, SWT.BOLD);
}
}
/**
* Copyright (c) 2005-2011 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Eclipse Public License (EPL).
* Please see the license.txt included with this distribution for details.
* Any modifications to this file must keep this entire header intact.
*/
package org.python.pydev.core;

import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.osgi.service.environment.Constants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;

import com.aptana.shared_core.structure.Tuple;

/**
* <p><tt>FontUtils</tt> provides helper methods dealing with
* <tt>Font</tt>s.</p>
*
* @author André Berg
* @version 0.2
*/
public class FontUtils {

/**
* Selects a proper font name and height for various usage cases of monospaced fonts throughout Pydev.
*
* @param usage intended usage. See {@link IFontUsage} for valid values.
* @return a {@link Tuple} containing the font name as {@link String} and the base height as {@link Integer}.
* @throws IllegalArgumentException if <tt>usage</tt> is not found in {@link IFontUsage}.
*/
private static Tuple<String, Integer> getCodeFontNameAndHeight(int usage) throws IllegalArgumentException {
String fontName = "Courier New";
int fontHeight = 10;
if (Platform.getOS().equals(Constants.OS_MACOSX)) {
switch (usage) {
case IFontUsage.STYLED:
fontName = "Monaco";
fontHeight = 11;
break;
case IFontUsage.DIALOG:
// on OS X we need a different font because
// under Mac SWT the bitmap font rasterizer
// doesn't take hinting into account and thus
// makes small fonts rendered as bitmaps unreadable
// see http://aptanastudio.tenderapp.com/discussions/problems/2052-some-dialogs-have-unreadable-small-font-size
fontName = "Courier";
fontHeight = 11;
break;
case IFontUsage.WIDGET:
fontName = "Monaco";
fontHeight = 9;
break;
case IFontUsage.IMAGECACHE:
fontName = "Monaco";
fontHeight = 11;
break;
case IFontUsage.SMALLUI:
fontName = "Monaco";
fontHeight = 9;
break;

default:
throw new IllegalArgumentException(
"Invalid usage. See org.python.pydev.core.IFontUsage for valid values.");
}
} else {
switch (usage) {
case IFontUsage.STYLED:
fontName = "Courier New";
fontHeight = 10;
break;
case IFontUsage.DIALOG:
fontName = "Courier New";
fontHeight = 8;
break;
case IFontUsage.WIDGET:
fontName = "Courier New";
fontHeight = 10;
break;
case IFontUsage.IMAGECACHE:
fontName = "Courier New";
fontHeight = 9;
break;
case IFontUsage.SMALLUI:
fontName = "Courier New";
fontHeight = 8;
break;

default:
throw new IllegalArgumentException(
"Invalid usage. See org.python.pydev.core.IFontUsage for valid values.");
}
}
return new Tuple<String, Integer>(fontName, fontHeight);
}


/**
* Calls {@link #getFontData(int, boolean)} with {@link SWT#NONE} for the style param.
* @see {@link #getFontData(int, int, boolean)}
*/
public static FontData getFontData(int usage, boolean useDefaultJFaceFontIfPossible) {
return getFontData(usage, SWT.NONE, useDefaultJFaceFontIfPossible);
}

/**
* Select a monospaced font based on intended usage.
* Can be used to provide a consistend code font size between platforms.
*
* @param usage intended usage. See {@link IFontUsage} for valid values.
* @param style SWT style constants mask
* @param useDefaultJFaceFontIfPossible
* @return {@link FontData} object
*/
public static FontData getFontData(int usage, int style, boolean useDefaultJFaceFontIfPossible) {
if (useDefaultJFaceFontIfPossible) {
FontData[] textFontData = JFaceResources.getTextFont().getFontData();
if (textFontData.length == 1) {
return textFontData[0];
}
}
Tuple<String, Integer> codeFontDetails = FontUtils.getCodeFontNameAndHeight(usage);
String fontName = codeFontDetails.o1;
int base = codeFontDetails.o2.intValue();
return new FontData(fontName, base, style);
}
}
Original file line number Diff line number Diff line change
@@ -1,46 +1,51 @@
/**
* Copyright (c) 2005-2011 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Eclipse Public License (EPL).
* Please see the license.txt included with this distribution for details.
* Any modifications to this file must keep this entire header intact.
*/
package org.python.pydev.core;

/**
* <tt>IFontUsage</tt> is an enum-like interface describing usage cases
* for fonts used throughout Pydev.
* <p>
* It is used primarily by {@link FontUtils} to have all font usages
* in a central place to ease future edits.
* </p>
* <p>
* <table width="100%" border="0">
* <tr><th>value</th><th>used for</th></tr>
* <tr><td>STYLED</td><td>styled text widgets (ex. Editor prefs)</td></tr>
* <tr><td>DIALOG</td><td>modal dialogs (ex. Py2To3)</td></tr>
* <tr><td>WIDGET</td><td>other widgets (ex. Code Coverage view or Comment Blocks prefs)</td></tr>
* <tr><td>IMAGECACHE</td><td>overlaying monospaced text onto images</td></tr>
* </table>
* </p>
*
* @author André Berg
* @version 0.1
*/
public interface IFontUsage {
/**
* used for styled text widgets (ex. Editor prefs)
*/
public static final int STYLED = 0;
/**
* used for modal dialogs (ex. Py2To3 dialog)
*/
public static final int DIALOG = 1;
/**
* used for other widgets (ex. Code Coverage view or Comment Blocks prefs)
*/
public static final int WIDGET = 2;
/**
* used in {@link org.python.pydev.core.bundle.ImageCache ImageCache} for overlaying code text onto images
*/
public static final int IMAGECACHE = 3;
}
/**
* Copyright (c) 2005-2011 by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Eclipse Public License (EPL).
* Please see the license.txt included with this distribution for details.
* Any modifications to this file must keep this entire header intact.
*/
package org.python.pydev.core;

/**
* <tt>IFontUsage</tt> is an enum-like interface describing usage cases
* for fonts used throughout Pydev.
* <p>
* It is used primarily by {@link FontUtils} to have all font usages
* in a central place to ease future edits.
* </p>
* <p>
* <table width="100%" border="0">
* <tr><th>value</th><th>used for</th></tr>
* <tr><td>STYLED</td><td>styled text widgets (ex. Editor prefs)</td></tr>
* <tr><td>DIALOG</td><td>modal dialogs (ex. Py2To3)</td></tr>
* <tr><td>WIDGET</td><td>other widgets (ex. Code Coverage view or Comment Blocks prefs)</td></tr>
* <tr><td>IMAGECACHE</td><td>overlaying monospaced text onto images</td></tr>
* <tr><td>SMALLUI</td><td>for UI layouts where space is at a premium</td></tr>
* </table>
* </p>
*
* @author André Berg
* @version 0.2
*/
public interface IFontUsage {
/**
* used for styled text widgets (ex. Editor prefs)
*/
public static final int STYLED = 0;
/**
* used for modal dialogs (ex. Py2To3 dialog)
*/
public static final int DIALOG = 1;
/**
* used for other widgets (ex. Code Coverage view or Comment Blocks prefs)
*/
public static final int WIDGET = 2;
/**
* used in {@link org.python.pydev.core.bundle.ImageCache ImageCache} for overlaying code text onto images
*/
public static final int IMAGECACHE = 3;
/**
* used for UI layouts where space is at a premium
*/
public static final int SMALLUI = 4;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.python.pydev.core;

import java.awt.Desktop;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.browser.IWebBrowser;
import org.python.pydev.core.log.Log;

/**
* Utils operating system functionality.
*
* @author André Berg
* @version 0.1
*/
public class SystemUtils {

/**
* Open webpage given by URI with the default system browser.
*/
public static void openWebpage(URI uri) {
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(uri);
} catch (Exception e) {
e.printStackTrace();
}
}
}

/**
* Open webpage given by URL with the default system browser.
*/
public static void openWebpage(URL url) {
try {
openWebpage(url.toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
}
}

/**
* Open a webpage in Eclipse's default browser.
*
* @param url URL address of the webpage
* @param id String id for the newly created browser view
*/
public static void openWebpageInEclipse(URL url, String id) {
IWebBrowser browser;
try {
browser = PlatformUI.getWorkbench().getBrowserSupport().createBrowser(id);
browser.openURL(url);
} catch (PartInitException e) {
Log.log(e);
}
}
}

Loading