X-Git-Url: http://git.euphorik.ch/?p=master-thesis.git;a=blobdiff_plain;f=Parasitemia%2FParasitemiaUI%2FGUI.fs;h=d30cb662924c9b8a363b2b781e25deda0c6431cc;hp=efe01c39f1ed8c87ad0df638ec22657b430b10c3;hb=97c24aa168f06f507fdff79429038d78a2c33326;hpb=f765276ea9abd8be286a17fae45509dde749812b diff --git a/Parasitemia/ParasitemiaUI/GUI.fs b/Parasitemia/ParasitemiaUI/GUI.fs index efe01c3..d30cb66 100644 --- a/Parasitemia/ParasitemiaUI/GUI.fs +++ b/Parasitemia/ParasitemiaUI/GUI.fs @@ -403,26 +403,24 @@ let run (defaultConfig: Config) (fileToOpen: string option) = state.FilePath <- previousFilePath MessageBox.Show(sprintf "The document cannot be loaded from '%s'" state.FilePath, "Error loading the document", MessageBoxButton.OK, MessageBoxImage.Error) |> ignore - txtPatient.TextChanged.AddHandler(fun obj args -> state.PatientID <- txtPatient.Text) - - menuExit.Click.AddHandler(fun obj args -> - askSaveCurrent () - mainWindow.Root.Close()) - - menuSaveFile.Click.AddHandler(fun obj args -> saveCurrentDocument ()) - menuSaveAsFile.Click.AddHandler(fun obj args -> saveCurrentDocumentAsNewFile ()) - - menuLoadFile.Click.AddHandler(fun obj args -> - // TODO: if current state not saved and not empty, ask to save it. + let askLoadFile () = let dialog = OpenFileDialog(Filter = PiaZ.filter) let res = dialog.ShowDialog() if res.HasValue && res.Value - then loadFile dialog.FileName) + then loadFile dialog.FileName - menuNewFile.Click.AddHandler(fun obj args -> + let newFile () = askSaveCurrent () state.Reset() - updateGUI()) + updateGUI() + + txtPatient.TextChanged.AddHandler(fun obj args -> state.PatientID <- txtPatient.Text) + + menuExit.Click.AddHandler(fun obj args -> mainWindow.Root.Close()) + menuSaveFile.Click.AddHandler(fun obj args -> saveCurrentDocument ()) + menuSaveAsFile.Click.AddHandler(fun obj args -> saveCurrentDocumentAsNewFile ()) + menuLoadFile.Click.AddHandler(fun obj args -> askLoadFile ()) + menuNewFile.Click.AddHandler(fun obj args -> newFile ()) menuAddSourceImage.Click.AddHandler(fun obj args -> let dialog = OpenFileDialog(Filter = "Image Files|*.png;*.jpg;*.tif;*.tiff", Multiselect = true) @@ -461,6 +459,8 @@ let run (defaultConfig: Config) (fileToOpen: string option) = menuAbout.Click.AddHandler(fun obj args -> About.showWindow mainWindow.Root) + mainWindow.Root.Closing.AddHandler(fun obj args -> askSaveCurrent ()) + // Zoom on the current image. let adjustCurrentImageBorders (deltaX: float) (deltaY: float) = borderCurrentImage.BorderThickness <- @@ -544,11 +544,30 @@ let run (defaultConfig: Config) (fileToOpen: string option) = args.Handled <- true) // Shortcuts. + // Save. mainWindow.Root.InputBindings.Add( Input.KeyBinding( FSharp.ViewModule.FunCommand((fun obj -> saveCurrentDocument ()), (fun obj -> true)), Input.KeyGesture(Input.Key.S, Input.ModifierKeys.Control))) |> ignore + // Save as. + mainWindow.Root.InputBindings.Add( + Input.KeyBinding( + FSharp.ViewModule.FunCommand((fun obj -> saveCurrentDocumentAsNewFile ()), (fun obj -> true)), + Input.KeyGesture(Input.Key.S, Input.ModifierKeys.Control ||| Input.ModifierKeys.Shift))) |> ignore + + // Open. + mainWindow.Root.InputBindings.Add( + Input.KeyBinding( + FSharp.ViewModule.FunCommand((fun obj -> askLoadFile ()), (fun obj -> true)), + Input.KeyGesture(Input.Key.O, Input.ModifierKeys.Control))) |> ignore + + // New file. + mainWindow.Root.InputBindings.Add( + Input.KeyBinding( + FSharp.ViewModule.FunCommand((fun obj -> newFile ()), (fun obj -> true)), + Input.KeyGesture(Input.Key.N, Input.ModifierKeys.Control))) |> ignore + // Viewport preview. scrollViewCurrentImage.ScrollChanged.AddHandler(fun obj args -> updateViewportPreview ())