Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the story regarding dialogs #5

Open
ivanperez-keera opened this issue Sep 6, 2017 · 1 comment
Open

Improve the story regarding dialogs #5

ivanperez-keera opened this issue Sep 6, 2017 · 1 comment

Comments

@ivanperez-keera
Copy link
Contributor

Certain reactive constructs like dialogs do not yet integrate well with RVs.

An example, from https://github.com/keera-studios/haskell-titan/blob/develop/titan-gui/src/Controller/Conditions/Buttons.hs#L89, is:

installConditionLoadTrace cenv = void $ do
  btn <- toolButtonActivateField <$> toolBtnLoadTrace (uiBuilder (view cenv))
  btn =:> conditionVMLoadTrace cenv

conditionVMLoadTrace :: CEnv -> IO ()
conditionVMLoadTrace cenv = do
  window <- mainWindow (uiBuilder (view cenv))
  fch <- fileChooserDialogNew (Just "Open Yampa trace") Nothing
                              FileChooserActionOpen
                              [("Cancel", ResponseCancel),
                               ("Load", ResponseAccept)]

  ytrfilt <- fileFilterNew
  fileFilterAddPattern ytrfilt "*.ytr"
  fileFilterSetName ytrfilt "Yampa Trace"
  fileChooserAddFilter fch ytrfilt

  nofilt <- fileFilterNew
  fileFilterAddPattern nofilt "*.*"
  fileFilterSetName nofilt "All Files"
  fileChooserAddFilter fch nofilt

  widgetShow fch
  response <- dialogRun fch
  fp <- case response of
          ResponseCancel -> putStrLn "You cancelled..." >> return Nothing
          ResponseAccept -> do nwf <- fileChooserGetFilename fch
                               case nwf of
                                 Nothing   -> putStrLn "Nothing" >> return Nothing
                                 Just path -> putStrLn ("New file path is:\n" ++ path) >> return (Just path)
          ResponseDeleteEvent -> putStrLn "You closed the dialog window..." >> return Nothing

  widgetDestroy fch
  awhen fp $ \p -> do
    contents <- readFile p
    sendToYampaSocketAsync (extra cenv) (show (LoadTraceFromString contents))

Instead, one could think of this dialog as a sort-of fudget or reactive processor. If synced, it could be described with something like:

(toolButtonActivateField . toolBtnLoadTrace) =>= openFileDialog =>= loadFile  =:> sendNewTrace
@ivanperez-keera
Copy link
Contributor Author

ivanperez-keera commented Sep 6, 2017

I guess what this all means is that we can improve the story for any function of the form:
a -> m b, making it a pair of reactive values (a write end of type a, and a read end of type b)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant