<commit_before>-- | Condition: the notebook showing the component info will show the page
-- corresponding to the icon selected in the iconview (info, trace)
module Controller.Conditions.InfoSelectionArea
  (installHandlers)
 where

-- External imports
import Control.Monad
import Graphics.UI.Gtk

-- Local imports
import CombinedEnvironment

-- | Selects the appropriate page in the info notebook as the user
-- chooses between basic info and component trace
installHandlers :: CEnv -> IO()
installHandlers cenv = void $ do
  iv <- infoIconView $ uiBuilder $ view cenv
  iv `on` selectionChanged $ condition cenv
  model cenv `onEvent` Initialised $ condition cenv

-- | Shows appropriate page based on current selection
condition :: CEnv -> IO()
condition cenv = do
  iv        <- infoIconView ui
  nb        <- infoSelNotebook ui
  (path, _) <- iconViewGetCursor iv
  let page = case path of { [x] -> x + 1; _ -> 0 }
  
  notebookSetCurrentPage nb page
  -- case path of
  --  [x] -> notebookSetCurrentPage nb (x + 1)
  --  _   -> notebookSetCurrentPage nb 0
 where ui = uiBuilder $ view cenv
<commit_msg>Uses gtk-helpers' notebook-list synchronisation feature to keep notebook in sync<commit_after>-- | Condition: the notebook showing the component info will show the page
-- corresponding to the icon selected in the iconview (info, trace)
module Controller.Conditions.InfoSelectionArea
  (installHandlers)
 where

-- External imports
import Control.Monad
import Data.Maybe
import Graphics.UI.Gtk
import Graphics.UI.Gtk.Helpers.ModelViewNotebookSync

-- Local imports
import CombinedEnvironment

-- | Selects the appropriate page in the info notebook as the user
-- chooses between basic info and component trace
installHandlers :: CEnv -> IO()
installHandlers cenv = void $ do
  iv <- infoIconView $ uiBuilder $ view cenv
  iv `on` selectionChanged $ condition cenv
  model cenv `onEvent` Initialised $ condition cenv

-- | Shows appropriate page based on current selection
condition :: CEnv -> IO()
condition cenv = do

  -- Get widgets
  iv <- infoIconView ui
  nb <- infoSelNotebook ui

  -- Calculate page number and show it
  let pageF = maybe 0 (+1) . listToMaybe
  modelViewNotebookSync iv nb pageF

 where ui = uiBuilder $ view cenv

{'fraction_non_alphanumeric': 0.07654650645304852, 'fraction_numerical': 0.0026702269692923898, 'mean_word_length': 3.6735966735966734, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6880225', 'n_tokens_mistral': 646, 'n_tokens_neox': 619, 'n_words': 259}