GTK: make file/edit menus useful

This commit is contained in:
Julian Ospald 2015-12-24 14:41:06 +01:00
parent 137956df42
commit e160f340ec
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
4 changed files with 52 additions and 17 deletions

View File

@ -32,6 +32,15 @@
<property name="use_stock">True</property> <property name="use_stock">True</property>
</object> </object>
</child> </child>
<child>
<object class="GtkImageMenuItem" id="menubarFileExecute">
<property name="label">gtk-execute</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
</object>
</child>
<child> <child>
<object class="GtkSeparatorMenuItem" id="separatormenuitem1"> <object class="GtkSeparatorMenuItem" id="separatormenuitem1">
<property name="visible">True</property> <property name="visible">True</property>
@ -62,7 +71,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<object class="GtkImageMenuItem" id="menubarFileCut"> <object class="GtkImageMenuItem" id="menubarEditCut">
<property name="label">gtk-cut</property> <property name="label">gtk-cut</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -71,7 +80,7 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkImageMenuItem" id="menubarFileCopy"> <object class="GtkImageMenuItem" id="menubarEditCopy">
<property name="label">gtk-copy</property> <property name="label">gtk-copy</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -80,7 +89,7 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkImageMenuItem" id="menubarFilePaste"> <object class="GtkImageMenuItem" id="menubarEditPaste">
<property name="label">gtk-paste</property> <property name="label">gtk-paste</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -89,7 +98,7 @@
</object> </object>
</child> </child>
<child> <child>
<object class="GtkImageMenuItem" id="menubarFileDelete"> <object class="GtkImageMenuItem" id="menubarEditDelete">
<property name="label">gtk-delete</property> <property name="label">gtk-delete</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>

View File

@ -151,14 +151,16 @@ startMainWindow startdir = do
"menubarFileQuit" "menubarFileQuit"
menubarFileOpen <- builderGetObject builder castToImageMenuItem menubarFileOpen <- builderGetObject builder castToImageMenuItem
"menubarFileOpen" "menubarFileOpen"
menubarFileCut <- builderGetObject builder castToImageMenuItem menubarFileExecute <- builderGetObject builder castToImageMenuItem
"menubarFileCut" "menubarFileExecute"
menubarFileCopy <- builderGetObject builder castToImageMenuItem menubarEditCut <- builderGetObject builder castToImageMenuItem
"menubarFileCopy" "menubarEditCut"
menubarFilePaste <- builderGetObject builder castToImageMenuItem menubarEditCopy <- builderGetObject builder castToImageMenuItem
"menubarFilePaste" "menubarEditCopy"
menubarFileDelete <- builderGetObject builder castToImageMenuItem menubarEditPaste <- builderGetObject builder castToImageMenuItem
"menubarFileDelete" "menubarEditPaste"
menubarEditDelete <- builderGetObject builder castToImageMenuItem
"menubarEditDelete"
menubarHelpAbout <- builderGetObject builder castToImageMenuItem menubarHelpAbout <- builderGetObject builder castToImageMenuItem
"menubarHelpAbout" "menubarHelpAbout"
urlBar <- builderGetObject builder castToEntry urlBar <- builderGetObject builder castToEntry

View File

@ -79,7 +79,6 @@ setCallbacks mygui myview = do
"Delete" <- fmap glibToString eventKeyName "Delete" <- fmap glibToString eventKeyName
liftIO $ withRow mygui myview del liftIO $ withRow mygui myview del
_ <- treeView mygui `on` rowActivated $ (\_ _ -> withRow mygui myview open) _ <- treeView mygui `on` rowActivated $ (\_ _ -> withRow mygui myview open)
_ <- menubarFileQuit mygui `on` menuItemActivated $ mainQuit
_ <- urlBar mygui `on` entryActivated $ urlGoTo mygui myview _ <- urlBar mygui `on` entryActivated $ urlGoTo mygui myview
_ <- treeView mygui `on` keyPressEvent $ tryEvent $ do _ <- treeView mygui `on` keyPressEvent $ tryEvent $ do
[Control] <- eventModifier [Control] <- eventModifier
@ -93,6 +92,24 @@ setCallbacks mygui myview = do
[Control] <- eventModifier [Control] <- eventModifier
"v" <- fmap glibToString eventKeyName "v" <- fmap glibToString eventKeyName
liftIO $ operationFinal mygui myview liftIO $ operationFinal mygui myview
-- menubar-file
_ <- menubarFileQuit mygui `on` menuItemActivated $ mainQuit
_ <- menubarFileOpen mygui `on` menuItemActivated $
liftIO $ withRow mygui myview open
_ <- menubarFileExecute mygui `on` menuItemActivated $
liftIO $ withRow mygui myview execute
-- menubar-edit
_ <- menubarEditCopy mygui `on` menuItemActivated $
liftIO $ withRow mygui myview copyInit
_ <- menubarEditPaste mygui `on` menuItemActivated $
liftIO $ operationFinal mygui myview
_ <- menubarEditDelete mygui `on` menuItemActivated $
liftIO $ withRow mygui myview del
_ <- menubarEditCut mygui `on` menuItemActivated $
liftIO $ withRow mygui myview moveInit
return () return ()
@ -118,6 +135,12 @@ open row mygui myview = withErrorDialog $
void $ openFile r void $ openFile r
-- |Execute a given file.
execute :: Row -> MyGUI -> MyView -> IO ()
execute row mygui myview = withErrorDialog $
void $ executeFile row []
-- |Supposed to be used with 'withRow'. Deletes a file or directory. -- |Supposed to be used with 'withRow'. Deletes a file or directory.
del :: Row -> MyGUI -> MyView -> IO () del :: Row -> MyGUI -> MyView -> IO ()
del row mygui myview = withErrorDialog $ do del row mygui myview = withErrorDialog $ do

View File

@ -28,10 +28,11 @@ data MyGUI = MkMyGUI {
rootWin :: Window rootWin :: Window
, menubarFileQuit :: ImageMenuItem , menubarFileQuit :: ImageMenuItem
, menubarFileOpen :: ImageMenuItem , menubarFileOpen :: ImageMenuItem
, menubarFileCut :: ImageMenuItem , menubarFileExecute :: ImageMenuItem
, menubarFileCopy :: ImageMenuItem , menubarEditCut :: ImageMenuItem
, menubarFilePaste :: ImageMenuItem , menubarEditCopy :: ImageMenuItem
, menubarFileDelete :: ImageMenuItem , menubarEditPaste :: ImageMenuItem
, menubarEditDelete :: ImageMenuItem
, menubarHelpAbout :: ImageMenuItem , menubarHelpAbout :: ImageMenuItem
, urlBar :: Entry , urlBar :: Entry
, statusBar :: Statusbar , statusBar :: Statusbar