Skip to content

Commit

Permalink
string externalization in GHC plugin
Browse files Browse the repository at this point in the history
darcs-hash:20080216165615-34f1c-23dbf656e715d4afb0fa6aca03ef2fe2be06095f.gz
  • Loading branch information
Leif Frenzel committed Feb 16, 2008
1 parent 16820bb commit 1e5000d
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2006-2008 by Leif Frenzel - see http://leiffrenzel.de
// This code is made available under the terms of the Eclipse Public License,
// version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
package net.sf.eclipsefp.haskell.ghccompiler.ui.internal.util;

import org.eclipse.osgi.util.NLS;

/** <p>provides access to the internationalized UI texts.</p>
*
* @author Leif Frenzel
*/
public final class UITexts extends NLS {

// message fields
public static String generalTab_extra;
public static String generalTab_extraMsg;

public static String ghciTab_note;
public static String ghciTab_options;

public static String ghcPreferencePage_desc;
public static String ghcPreferencePage_general;
public static String ghcPreferencePage_language;
public static String ghcPreferencePage_moreOptimization;
public static String ghcPreferencePage_optimization;

public static String levelSelectionDialogField_levelInfo;
public static String levelSelectionDialogField_zeroText;
public static String levelSelectionDialogField_zeroTooltip;

public static String optimizationTab_general;
public static String optimizationTab_individual;
public static String optimizationTab_individualInfo;


private static final String BUNDLE_NAME
= UITexts.class.getPackage().getName() + ".uitexts"; //$NON-NLS-1$

static {
NLS.initializeMessages( BUNDLE_NAME, UITexts.class );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2006-2008 by Leif Frenzel - see http://leiffrenzel.de
# This code is made available under the terms of the Eclipse Public License,
# version 1.0 (EPL). See http://www.eclipse.org/legal/epl-v10.html
generalTab_extra = Extra compiler options
generalTab_extraMsg = Pass these options (please be careful, they are not validated ...)\:

ghciTab_note = If you check this, please make sure that you have configured only options that make sense for GHCi.\nRefer to the GHC manual for more information.
ghciTab_options = Use GHC compiler settings for GHCi

ghcPreferencePage_desc = GHC compiler settings
ghcPreferencePage_general = General
ghcPreferencePage_language = Language Options
ghcPreferencePage_moreOptimization = More Optimization
ghcPreferencePage_optimization = Optimization

levelSelectionDialogField_levelInfo = These options specify convenient "packages" of optimization flags.
levelSelectionDialogField_zeroText = Do not specify an optimization level.
levelSelectionDialogField_zeroTooltip = Do not specify an optimization level.\nPass no -O* option.

optimizationTab_general = General Optimization
optimizationTab_individual = Individual Optimizations
optimizationTab_individualInfo = These are individual optimization settings.\n(more of them are on the next tab).
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.sf.eclipsefp.haskell.ghccompiler.core.IGhcParameters;
import net.sf.eclipsefp.haskell.ghccompiler.core.Util;
import net.sf.eclipsefp.haskell.ghccompiler.core.preferences.IGhcPreferenceNames;

import net.sf.eclipsefp.haskell.ghccompiler.ui.internal.util.UITexts;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
Expand All @@ -22,52 +22,50 @@
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;

/** <p>The tab on the Ghc compiler preference page that displays general
/** <p>The tab on the Ghc compiler preference page that displays general
* information about the ghc compiler installed on the machine (if any).</p>
*
*
* @author Leif Frenzel
*/
public class GeneralTab extends Tab implements IGhcParameters,
public class GeneralTab extends Tab implements IGhcParameters,
IGhcPreferenceNames {

public GeneralTab( final IPreferenceStore store ) {
super( store );
}

// interface methods of Tab
///////////////////////////

@Override
public Control createControl( final Composite parent ) {
Composite composite = new Composite( parent, SWT.NONE );
composite.setLayout( new GridLayout() );

createExecutableField( composite );
createExtraOptionsField( composite );

return composite;
}


// helping methods
//////////////////

private void createExtraOptionsField( final Composite parent ) {
Composite wrapper = new Composite( parent, SWT.NONE );
wrapper.setLayout( new GridLayout( 1, false ) );

Group group = new Group( wrapper, SWT.NONE );
group.setLayout( new GridLayout() );
group.setText( "Extra compiler options" );
group.setText( UITexts.generalTab_extra );
group.setLayoutData( new GridData( GridData.FILL_HORIZONTAL) );

final Button cbActive = new Button( group, SWT.CHECK );
String msg
= "Pass these options (please be careful, they are not validated ...):";
cbActive.setText( msg );
cbActive.setText( UITexts.generalTab_extraMsg );
boolean selected = getPreferenceStore().getBoolean( USE_EXTRA_OPTIONS );
cbActive.setSelection( selected );

final Text text = new Text( group, SWT.BORDER );
text.setText( getPreferenceStore().getString( EXTRA_OPTIONS ) );
text.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
Expand All @@ -77,7 +75,7 @@ public void modifyText( final ModifyEvent event ) {
}
} );
text.setEnabled( selected );

cbActive.addSelectionListener( new SelectionAdapter() {
@Override
public void widgetSelected( final SelectionEvent e ) {
Expand All @@ -90,7 +88,7 @@ public void widgetSelected( final SelectionEvent e ) {

private void createExecutableField( final Composite parent ) {
String labelText = "GHC executable";
ExecutableDialogField dlgField = new ExecutableDialogField( parent,
ExecutableDialogField dlgField = new ExecutableDialogField( parent,
labelText ) {
@Override
protected String createDisplayContent( final String info ) {
Expand All @@ -99,7 +97,7 @@ protected String createDisplayContent( final String info ) {
};

dlgField.setInfo( getPreferenceStore().getString( EXECUTABLE_NAME ) );

dlgField.addDialogFieldListener( new IDialogFieldListener() {
public void infoChanged( final Object newInfo ) {
getPreferenceStore().setValue( EXECUTABLE_NAME, ( String )newInfo );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public GhcCompilerTab( final IPreferenceStore store ) {
///////////////////////////////

DialogField createBooleanField( final Composite parent, final String name ) {
String text = UITexts.getShortDescription( name );
String text = ParamsUITexts.getShortDescription( name );
String tooltip = text + "\n" + name; //$NON-NLS-1$
BooleanDialogField result = new BooleanDialogField( parent, text, tooltip );
result.addDialogFieldListener( new IDialogFieldListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.sf.eclipsefp.haskell.ghccompiler.GhcCompilerPlugin;
import net.sf.eclipsefp.haskell.ghccompiler.core.IGhcParameters;
import net.sf.eclipsefp.haskell.ghccompiler.core.preferences.IGhcPreferenceNames;

import net.sf.eclipsefp.haskell.ghccompiler.ui.internal.util.UITexts;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferencePage;
Expand All @@ -19,39 +19,43 @@
import org.eclipse.ui.IWorkbenchPreferencePage;

/** <p>The preference page for the GHC compiler preferences.</p>
*
*
* @author Leif Frenzel
*/
public class GhcPreferencePage extends PreferencePage
public class GhcPreferencePage extends PreferencePage
implements IWorkbenchPreferencePage,
IGhcPreferenceNames,
IGhcParameters {

private OverlayPreferenceStore overlayStore;
private OverlayPreferenceStore overlayStore;



// interface methods of PreferencePage
//////////////////////////////////////

@Override
protected Control createContents( final Composite parent ) {
TabFolder folder = new TabFolder( parent, SWT.NONE );

Tab generalTab = new GeneralTab( overlayStore );
createTab( folder, "General", generalTab.createControl( folder ) );
String sGeneral = UITexts.ghcPreferencePage_general;
createTab( folder, sGeneral, generalTab.createControl( folder ) );

Tab languageTab = new LanguageTab( overlayStore );
Control languageControl = languageTab.createControl( folder );
createTab( folder, "Language Options", languageControl );
String sLang = UITexts.ghcPreferencePage_language;
createTab( folder, sLang, languageControl );

Tab optimizationTab = new OptimizationTab( overlayStore );
Control optimizationControl = optimizationTab.createControl( folder );
createTab( folder, "Optimization", optimizationControl );
String sOpt = UITexts.ghcPreferencePage_optimization;
createTab( folder, sOpt, optimizationControl );

Tab moreOptimizationTab = new MoreOptimizationTab( overlayStore );
Control moreOptControl = moreOptimizationTab.createControl( folder );
createTab( folder, "More Optimization", moreOptControl );

String sMoreOpt = UITexts.ghcPreferencePage_moreOptimization;
createTab( folder, sMoreOpt, moreOptControl );

Dialog.applyDialogFont( folder );
return folder;
}
Expand All @@ -78,31 +82,31 @@ protected void performDefaults() {
super.performDefaults();
}


// interface methods of IWorkbenchPreferencePage
////////////////////////////////////////////////

public void init( final IWorkbench workbench ) {
setDescription( "GHC compiler settings" );
setDescription( UITexts.ghcPreferencePage_desc );
setPreferenceStore( GhcCompilerPlugin.getDefault().getPreferenceStore() );

overlayStore = createOverlayStore();
overlayStore.load();
overlayStore.startListening();
}


// helping methods
//////////////////
private void createTab( final TabFolder folder,
final String label,

private void createTab( final TabFolder folder,
final String label,
final Control control ) {
TabItem tab = new TabItem( folder, SWT.NONE );
tab.setText( label );
tab.setControl( control );
}

private OverlayPreferenceStore createOverlayStore() {
IPreferenceStore prefStore = getPreferenceStore();
OverlayPreferenceStore store = new OverlayPreferenceStore( prefStore );
Expand All @@ -111,7 +115,7 @@ private OverlayPreferenceStore createOverlayStore() {
addLanguagePrefs( store );
addOptimizationPrefs( store );
addMoreOptimizationPrefs( store );

return store;
}

Expand All @@ -134,15 +138,15 @@ private void addLanguagePrefs( final OverlayPreferenceStore store ) {
store.addBooleanKey( LANG_GENERICS );
store.addBooleanKey( LANG_NO_IMPLICIT_PRELUDE );
}

private void addOptimizationPrefs( final OverlayPreferenceStore store ) {
store.addIntKey( OPTIMIZATION_LEVEL );
// boolean preferences use the parameter as key
store.addBooleanKey( OPT_EXCESS_PRECISION );
store.addBooleanKey( OPT_IGNORE_ASSERTS );
store.addBooleanKey( OPT_NO_STRICTNESS );
store.addBooleanKey( OPT_NO_CPR );
store.addBooleanKey( OPT_UNBOX_STRICT_FIELDS );
store.addBooleanKey( OPT_UNBOX_STRICT_FIELDS );
}

private void addMoreOptimizationPrefs( final OverlayPreferenceStore store ) {
Expand All @@ -156,7 +160,7 @@ private void addMoreOptimizationPrefs( final OverlayPreferenceStore store ) {
store.addBooleanKey( OPT_LET_NO_ESCAPE );
store.addBooleanKey( OPT_OMIT_INTERFACE_PRAGMAS );
store.addBooleanKey( OPT_NO_CSE );
store.addBooleanKey( OPT_NO_PRE_INLINING );
store.addBooleanKey( OPT_NO_PRE_INLINING );
store.addBooleanKey( OPT_NUMBERS_STRICT );
store.addBooleanKey( OPT_USAGESP );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,35 @@
import net.sf.eclipsefp.common.ui.dialog.IDialogFieldListener;
import net.sf.eclipsefp.common.ui.preferences.Tab;
import net.sf.eclipsefp.haskell.ghccompiler.core.preferences.IGhcPreferenceNames;

import net.sf.eclipsefp.haskell.ghccompiler.ui.internal.util.UITexts;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;

/** <p>the single tab on the GHCi preference page (not shown as tab,
/** <p>the single tab on the GHCi preference page (not shown as tab,
* but uses the preference access mechanism of tabs).</p>
*
*
* @author Leif Frenzel
*/
class GhciTab extends Tab implements IGhcPreferenceNames {

GhciTab( final IPreferenceStore store ) {
super( store );
}


// interface methods of Tab
///////////////////////////

@Override
public Control createControl( final Composite parent ) {
Composite composite = new Composite( parent, SWT.NONE );
composite.setLayout( new GridLayout( 1, false ) );

String text = "Use GHC compiler settings for GHCi";


String text = UITexts.ghciTab_options;
BooleanDialogField result = new BooleanDialogField( composite, text );
result.addDialogFieldListener( new IDialogFieldListener() {
public void infoChanged( final Object newInfo ) {
Expand All @@ -43,22 +42,19 @@ public void infoChanged( final Object newInfo ) {
}
} );
result.setInfo( getFromStore( GHCI_USES_GHC_OPTIONS ) );

Label lblNote = new Label( composite, SWT.WRAP );
String note = "If you check this, please make sure that you have "
+ "configured only options that make sense for GHCi.\n"
+ "Refer to the GHC manual for more information.";
lblNote.setText( note );

lblNote.setText( UITexts.ghciTab_note );

return composite;
}


// helping methods
//////////////////

private Boolean getFromStore( final String name ) {
boolean value = getPreferenceStore().getBoolean( name );
return ( value ) ? Boolean.TRUE : Boolean.FALSE;
}
}
}
Loading

0 comments on commit 1e5000d

Please sign in to comment.