# HG changeset patch # User Frank Benoit # Date 1208099978 -7200 # Node ID fc7a8f537871043d399ee881e2ad1fc78ffed058 # Parent 63a7769cce5771b1bd7bd02b84a217b386c11446 Open/Save with experimental runner factory. diff -r 63a7769cce57 -r fc7a8f537871 jface/Librarian.d --- 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); } } }