Changeset 72:fc7a8f537871

Show
Ignore:
Timestamp:
04/13/08 11:19:38 (4 years ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

Open/Save with experimental runner factory.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • jface/Librarian.d

    r71 r72  
    340340            try { 
    341341                // Launch the Open runnable 
    342                 ModalContext.run(new class(fileName) IRunnableWithProgress { 
    343                     String fileName_; 
    344                     this(String a){ 
    345                         fileName_=a; 
    346                     } 
    347                     public void run(IProgressMonitor progressMonitor) { 
    348                         try { 
    349                             progressMonitor.beginTask("Loading", IProgressMonitor.UNKNOWN); 
    350                             library.load(fileName_); 
    351                             progressMonitor.done(); 
    352                             viewer.setInput(library); 
    353                             refreshView(); 
    354                         } catch (IOException e) { 
    355                             showError( Format("Can't load file {}\r{}", fileName_, e.msg)); 
    356                         } 
    357                     } 
    358                 }, true, getStatusLineManager().getProgressMonitor(), getShell() 
    359                     .getDisplay()); 
     342                ModalContext.run( dgIRunnableWithProgress( &internalOpen, fileName ), 
     343                    true, getStatusLineManager().getProgressMonitor(), getShell().getDisplay()); 
    360344            } catch (InterruptedException e) { 
    361345            } catch (InvocationTargetException e) { 
     
    366350        } 
    367351    } 
    368  
     352    private void internalOpen( IProgressMonitor progressMonitor,String filename ){ 
     353        try { 
     354            progressMonitor.beginTask("Loading", IProgressMonitor.UNKNOWN); 
     355            library.load(filename); 
     356            progressMonitor.done(); 
     357            viewer.setInput(library); 
     358            refreshView(); 
     359        } catch (IOException e) { 
     360            showError( Format("Can't load file {}\r{}", filename, e.msg)); 
     361        } 
     362    } 
    369363    /** 
    370364    * Creates a new file 
     
    373367        if (checkOverwrite()) { 
    374368        library = new Library(); 
    375         viewer.setInput(library); 
     369            viewer.setInput(library); 
    376370        } 
    377371    } 
     
    384378        if (fileName is null) { 
    385379            fileName = (new SafeSaveDialog(getShell())).open(); 
     380        } 
     381        if (fileName is null) { 
     382            return; 
    386383        } 
    387384        saveFileAs(fileName); 
     
    399396            auto pm = getStatusLineManager().getProgressMonitor(); 
    400397            auto disp = getShell().getDisplay(); 
    401  
    402398            // Launch the Save runnable 
    403             ModalContext.run(new class(fileName) IRunnableWithProgress { 
    404                 String filename_; 
    405                 this(String a){ 
    406                     filename_=a; 
    407                 } 
    408                 public void run(IProgressMonitor progressMonitor) { 
    409                     try { 
    410                         progressMonitor.beginTask("Saving", -1/+IProgressMonitor.UNKNOWN+/); 
    411                         library.save(filename_); 
    412                         progressMonitor.done(); 
    413                     } catch (IOException e) { 
    414                         showError(Format("Can't save file {}\r{}", library.getFileName(), e.msg )); 
    415                     } 
    416                 } 
    417             }, true, pm, disp ); 
     399            ModalContext.run( dgIRunnableWithProgress( &internalSave, fileName ), true, pm, disp); 
     400 
    418401        } catch (InterruptedException e) { 
    419402        } catch (InvocationTargetException e) { 
     
    424407    } 
    425408 
    426     /** 
    427     * Shows an error 
    428     * 
    429     * @param msg the error 
    430     */ 
     409    private void internalSave(IProgressMonitor progressMonitor,String filename ){ 
     410        try { 
     411            progressMonitor.beginTask("Saving", IProgressMonitor.UNKNOWN ); 
     412            library.save(filename); 
     413            progressMonitor.done(); 
     414        } catch (IOException e) { 
     415            showError(Format("Can't save file {}\r{}", library.getFileName(), e.msg )); 
     416        } 
     417    } 
     418    /** 
     419     * Shows an error 
     420     * 
     421     * @param msg the error 
     422     */ 
    431423    public void showError(String msg) { 
    432424        MessageDialog.openError(getShell(), "Error", msg); 
     
    590582        String fileName = dlg.open(); 
    591583        if (fileName !is null) { 
    592         Librarian.getApp().saveFileAs(fileName); 
     584            Librarian.getApp().saveFileAs(fileName); 
    593585        } 
    594586    }