Permalink
Browse files

refresh cabal packages view when executable is installed

  • Loading branch information...
1 parent f61fb9f commit 22b3936e7cf3083417d9f67d4f91530afad390b2 @JPMoresmau committed Nov 23, 2012
@@ -28,12 +28,29 @@
private List<CabalPackageRef> installed=null;
private List<CabalPackageRef> all=null;
+ /** singleton **/
+ private static CabalPackageHelper instance;
+ public static synchronized CabalPackageHelper getInstance(){
+ if (instance==null || instance.getCabalPath()==null || !instance.getCabalPath().equals( CabalImplementationManager.getCabalExecutable() )){
+ instance=new CabalPackageHelper( CabalImplementationManager.getCabalExecutable() );
+ }
+ return instance;
+ }
- public CabalPackageHelper( final String cabalPath ) {
+ private CabalPackageHelper( final String cabalPath ) {
super();
this.cabalPath = cabalPath;
}
+ public void clear(){
+ installed=null;
+ all=null;
+ }
+
+
+ public String getCabalPath() {
+ return cabalPath;
+ }
public boolean hasInstalledVersion(final String name,final String version) throws IOException{
String s=getLastInstalledVersion(name);
@@ -19,6 +19,7 @@
import net.sf.eclipsefp.haskell.debug.core.internal.launch.AbstractHaskellLaunchDelegate;
import net.sf.eclipsefp.haskell.ui.HaskellUIPlugin;
import net.sf.eclipsefp.haskell.ui.internal.util.UITexts;
+import net.sf.eclipsefp.haskell.ui.views.CabalPackagesView;
import net.sf.eclipsefp.haskell.util.FileUtil;
import net.sf.eclipsefp.haskell.util.ProcessRunner;
import org.eclipse.core.runtime.CoreException;
@@ -127,6 +128,9 @@ public void run() {
@Override
public void run() {
+ /** refresh the cabal packages view **/
+ CabalPackagesView.refresh();
+
File f=new File(fBinDir,FileUtil.makeExecutableName( c.exeName ));
if (f.exists()){
// set preference
@@ -50,10 +50,12 @@
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.part.ViewPart;
@@ -65,6 +67,26 @@
public class CabalPackagesView extends ViewPart {
public static final String ID="net.sf.eclipsefp.haskell.ui.views.CabalPackagesView";
+ public static void refresh(){
+ /** clear cache **/
+ CabalPackageHelper.getInstance().clear();
+ Display.getDefault().asyncExec( new Runnable(){
+ @Override
+ public void run() {
+
+ IWorkbenchPage p=HaskellUIPlugin.getActivePage();
+ IViewPart part=p.findView( ID );
+ if (part instanceof CabalPackagesView){
+ CabalPackagesView v=((CabalPackagesView)part);
+ /** only if we show the installed packages **/
+ if (v.onlyInstalled){
+ v.refreshJob.schedule();
+ }
+ }
+ }
+ });
+ }
+
private CabalPackageHelper helper;
private Button bAll;
@@ -243,9 +265,7 @@ public boolean select( final Viewer viewer, final Object parentElement, final Ob
lMore.setText("<a>"+ UITexts.cabalPackagesView_info_more +"</a>");
lMore.setEnabled( false );
-
-
- helper=new CabalPackageHelper( CabalImplementationManager.getCabalExecutable() );
+ helper=CabalPackageHelper.getInstance();
refreshJob.schedule();

0 comments on commit 22b3936

Please sign in to comment.