changeset 72:fc7a8f537871

Open/Save with experimental runner factory.
author Frank Benoit <benoit@tionex.de>
date Sun, 13 Apr 2008 17:19:38 +0200
parents 63a7769cce57
children 9ff9b8f7284b
files jface/Librarian.d
diffstat 1 files changed, 33 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/jface/Librarian.d	Sun Apr 13 16:38:16 2008 +0200
+++ b/jface/Librarian.d	Sun Apr 13 17:19:38 2008 +0200
@@ -339,24 +339,8 @@
             library = new Library();
             try {
                 // Launch the Open runnable
-                ModalContext.run(new class(fileName) IRunnableWithProgress {
-                    String fileName_;
-                    this(String a){
-                        fileName_=a;
-                    }
-                    public void run(IProgressMonitor progressMonitor) {
-                        try {
-                            progressMonitor.beginTask("Loading", IProgressMonitor.UNKNOWN);
-                            library.load(fileName_);
-                            progressMonitor.done();
-                            viewer.setInput(library);
-                            refreshView();
-                        } catch (IOException e) {
-                            showError( Format("Can't load file {}\r{}", fileName_, e.msg));
-                        }
-                    }
-                }, true, getStatusLineManager().getProgressMonitor(), getShell()
-                    .getDisplay());
+                ModalContext.run( dgIRunnableWithProgress( &internalOpen, fileName ),
+                    true, getStatusLineManager().getProgressMonitor(), getShell().getDisplay());
             } catch (InterruptedException e) {
             } catch (InvocationTargetException e) {
             } finally {
@@ -365,14 +349,24 @@
             }
         }
     }
-
+    private void internalOpen( IProgressMonitor progressMonitor,String filename ){
+        try {
+            progressMonitor.beginTask("Loading", IProgressMonitor.UNKNOWN);
+            library.load(filename);
+            progressMonitor.done();
+            viewer.setInput(library);
+            refreshView();
+        } catch (IOException e) {
+            showError( Format("Can't load file {}\r{}", filename, e.msg));
+        }
+    }
     /**
     * Creates a new file
     */
     public void newFile() {
         if (checkOverwrite()) {
         library = new Library();
-        viewer.setInput(library);
+            viewer.setInput(library);
         }
     }
 
@@ -384,6 +378,9 @@
         if (fileName is null) {
             fileName = (new SafeSaveDialog(getShell())).open();
         }
+        if (fileName is null) {
+            return;
+        }
         saveFileAs(fileName);
     }
 
@@ -398,23 +395,9 @@
         try {
             auto pm = getStatusLineManager().getProgressMonitor();
             auto disp = getShell().getDisplay();
+            // Launch the Save runnable
+            ModalContext.run( dgIRunnableWithProgress( &internalSave, fileName ), true, pm, disp);
 
-            // Launch the Save runnable
-            ModalContext.run(new class(fileName) IRunnableWithProgress {
-                String filename_;
-                this(String a){
-                    filename_=a;
-                }
-                public void run(IProgressMonitor progressMonitor) {
-                    try {
-                        progressMonitor.beginTask("Saving", -1/+IProgressMonitor.UNKNOWN+/);
-                        library.save(filename_);
-                        progressMonitor.done();
-                    } catch (IOException e) {
-                        showError(Format("Can't save file {}\r{}", library.getFileName(), e.msg ));
-                    }
-                }
-            }, true, pm, disp );
         } catch (InterruptedException e) {
         } catch (InvocationTargetException e) {
         } finally {
@@ -423,11 +406,20 @@
         }
     }
 
+    private void internalSave(IProgressMonitor progressMonitor,String filename ){
+        try {
+            progressMonitor.beginTask("Saving", IProgressMonitor.UNKNOWN );
+            library.save(filename);
+            progressMonitor.done();
+        } catch (IOException e) {
+            showError(Format("Can't save file {}\r{}", library.getFileName(), e.msg ));
+        }
+    }
     /**
-    * Shows an error
-    *
-    * @param msg the error
-    */
+     * Shows an error
+     *
+     * @param msg the error
+     */
     public void showError(String msg) {
         MessageDialog.openError(getShell(), "Error", msg);
     }
@@ -589,7 +581,7 @@
         SafeSaveDialog dlg = new SafeSaveDialog(Librarian.getApp().getShell());
         String fileName = dlg.open();
         if (fileName !is null) {
-        Librarian.getApp().saveFileAs(fileName);
+            Librarian.getApp().saveFileAs(fileName);
         }
     }
 }