LIB/GTK: add move menuitem and implement creating new files
This commit is contained in:
parent
c98db302ba
commit
71a2cb90be
@ -2,6 +2,11 @@
|
|||||||
<!-- Generated with glade 3.19.0 -->
|
<!-- Generated with glade 3.19.0 -->
|
||||||
<interface>
|
<interface>
|
||||||
<requires lib="gtk+" version="3.16"/>
|
<requires lib="gtk+" version="3.16"/>
|
||||||
|
<object class="GtkImage" id="image1">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="stock">gtk-edit</property>
|
||||||
|
</object>
|
||||||
<object class="GtkMenu" id="rcMenu">
|
<object class="GtkMenu" id="rcMenu">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
@ -23,6 +28,15 @@
|
|||||||
<property name="use_stock">True</property>
|
<property name="use_stock">True</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkImageMenuItem" id="rcFileNew">
|
||||||
|
<property name="label">gtk-new</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="separatormenuitem2">
|
<object class="GtkSeparatorMenuItem" id="separatormenuitem2">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
@ -47,6 +61,15 @@
|
|||||||
<property name="use_stock">True</property>
|
<property name="use_stock">True</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkImageMenuItem" id="rcFileMove">
|
||||||
|
<property name="label">Move</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="image">image1</property>
|
||||||
|
<property name="use_stock">False</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkImageMenuItem" id="rcFilePaste">
|
<object class="GtkImageMenuItem" id="rcFilePaste">
|
||||||
<property name="label">gtk-paste</property>
|
<property name="label">gtk-paste</property>
|
||||||
@ -66,6 +89,11 @@
|
|||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
<object class="GtkImage" id="image2">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="stock">gtk-edit</property>
|
||||||
|
</object>
|
||||||
<object class="GtkApplicationWindow" id="rootWin">
|
<object class="GtkApplicationWindow" id="rootWin">
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<child>
|
<child>
|
||||||
@ -105,6 +133,15 @@
|
|||||||
<property name="use_stock">True</property>
|
<property name="use_stock">True</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkImageMenuItem" id="menubarFileNew">
|
||||||
|
<property name="label">gtk-new</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>
|
||||||
@ -152,6 +189,15 @@
|
|||||||
<property name="use_stock">True</property>
|
<property name="use_stock">True</property>
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkImageMenuItem" id="menubarEditMove">
|
||||||
|
<property name="label">Move</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="image">image2</property>
|
||||||
|
<property name="use_stock">False</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkImageMenuItem" id="menubarEditPaste">
|
<object class="GtkImageMenuItem" id="menubarEditPaste">
|
||||||
<property name="label">gtk-paste</property>
|
<property name="label">gtk-paste</property>
|
||||||
|
@ -171,10 +171,14 @@ startMainWindow startdir = do
|
|||||||
"menubarFileOpen"
|
"menubarFileOpen"
|
||||||
menubarFileExecute <- builderGetObject builder castToImageMenuItem
|
menubarFileExecute <- builderGetObject builder castToImageMenuItem
|
||||||
"menubarFileExecute"
|
"menubarFileExecute"
|
||||||
|
menubarFileNew <- builderGetObject builder castToImageMenuItem
|
||||||
|
"menubarFileNew"
|
||||||
menubarEditCut <- builderGetObject builder castToImageMenuItem
|
menubarEditCut <- builderGetObject builder castToImageMenuItem
|
||||||
"menubarEditCut"
|
"menubarEditCut"
|
||||||
menubarEditCopy <- builderGetObject builder castToImageMenuItem
|
menubarEditCopy <- builderGetObject builder castToImageMenuItem
|
||||||
"menubarEditCopy"
|
"menubarEditCopy"
|
||||||
|
menubarEditMove <- builderGetObject builder castToImageMenuItem
|
||||||
|
"menubarEditMove"
|
||||||
menubarEditPaste <- builderGetObject builder castToImageMenuItem
|
menubarEditPaste <- builderGetObject builder castToImageMenuItem
|
||||||
"menubarEditPaste"
|
"menubarEditPaste"
|
||||||
menubarEditDelete <- builderGetObject builder castToImageMenuItem
|
menubarEditDelete <- builderGetObject builder castToImageMenuItem
|
||||||
@ -191,10 +195,14 @@ startMainWindow startdir = do
|
|||||||
"rcFileOpen"
|
"rcFileOpen"
|
||||||
rcFileExecute <- builderGetObject builder castToImageMenuItem
|
rcFileExecute <- builderGetObject builder castToImageMenuItem
|
||||||
"rcFileExecute"
|
"rcFileExecute"
|
||||||
|
rcFileNew <- builderGetObject builder castToImageMenuItem
|
||||||
|
"rcFileNew"
|
||||||
rcFileCut <- builderGetObject builder castToImageMenuItem
|
rcFileCut <- builderGetObject builder castToImageMenuItem
|
||||||
"rcFileCut"
|
"rcFileCut"
|
||||||
rcFileCopy <- builderGetObject builder castToImageMenuItem
|
rcFileCopy <- builderGetObject builder castToImageMenuItem
|
||||||
"rcFileCopy"
|
"rcFileCopy"
|
||||||
|
rcFileMove <- builderGetObject builder castToImageMenuItem
|
||||||
|
"rcFileMove"
|
||||||
rcFilePaste <- builderGetObject builder castToImageMenuItem
|
rcFilePaste <- builderGetObject builder castToImageMenuItem
|
||||||
"rcFilePaste"
|
"rcFilePaste"
|
||||||
rcFileDelete <- builderGetObject builder castToImageMenuItem
|
rcFileDelete <- builderGetObject builder castToImageMenuItem
|
||||||
|
@ -85,10 +85,10 @@ setCallbacks mygui myview = do
|
|||||||
_ <- treeView mygui `on` keyPressEvent $ tryEvent $ do
|
_ <- treeView mygui `on` keyPressEvent $ tryEvent $ do
|
||||||
[Control] <- eventModifier
|
[Control] <- eventModifier
|
||||||
"h" <- fmap glibToString eventKeyName
|
"h" <- fmap glibToString eventKeyName
|
||||||
mcdir <- liftIO $ getFirstRow myview
|
cdir <- liftIO $ getCurrentDir myview
|
||||||
liftIO $ modifyTVarIO (settings mygui)
|
liftIO $ modifyTVarIO (settings mygui)
|
||||||
(\x -> x { showHidden = not . showHidden $ x})
|
(\x -> x { showHidden = not . showHidden $ x})
|
||||||
>> (refreshTreeView' mygui myview =<< goUp mcdir)
|
>> (refreshTreeView' mygui myview cdir)
|
||||||
_ <- treeView mygui `on` keyPressEvent $ tryEvent $ do
|
_ <- treeView mygui `on` keyPressEvent $ tryEvent $ do
|
||||||
[Alt] <- eventModifier
|
[Alt] <- eventModifier
|
||||||
"Up" <- fmap glibToString eventKeyName
|
"Up" <- fmap glibToString eventKeyName
|
||||||
@ -117,10 +117,14 @@ setCallbacks mygui myview = do
|
|||||||
liftIO $ withRow mygui myview open
|
liftIO $ withRow mygui myview open
|
||||||
_ <- menubarFileExecute mygui `on` menuItemActivated $
|
_ <- menubarFileExecute mygui `on` menuItemActivated $
|
||||||
liftIO $ withRow mygui myview execute
|
liftIO $ withRow mygui myview execute
|
||||||
|
_ <- menubarFileNew mygui `on` menuItemActivated $
|
||||||
|
liftIO $ newFile mygui myview
|
||||||
|
|
||||||
-- menubar-edit
|
-- menubar-edit
|
||||||
_ <- menubarEditCopy mygui `on` menuItemActivated $
|
_ <- menubarEditCopy mygui `on` menuItemActivated $
|
||||||
liftIO $ withRow mygui myview copyInit
|
liftIO $ withRow mygui myview copyInit
|
||||||
|
_ <- menubarEditMove mygui `on` menuItemActivated $
|
||||||
|
liftIO $ withRow mygui myview moveInit
|
||||||
_ <- menubarEditPaste mygui `on` menuItemActivated $
|
_ <- menubarEditPaste mygui `on` menuItemActivated $
|
||||||
liftIO $ operationFinal mygui myview
|
liftIO $ operationFinal mygui myview
|
||||||
_ <- menubarEditDelete mygui `on` menuItemActivated $
|
_ <- menubarEditDelete mygui `on` menuItemActivated $
|
||||||
@ -144,8 +148,12 @@ setCallbacks mygui myview = do
|
|||||||
liftIO $ withRow mygui myview open
|
liftIO $ withRow mygui myview open
|
||||||
_ <- rcFileExecute mygui `on` menuItemActivated $
|
_ <- rcFileExecute mygui `on` menuItemActivated $
|
||||||
liftIO $ withRow mygui myview execute
|
liftIO $ withRow mygui myview execute
|
||||||
|
_ <- rcFileNew mygui `on` menuItemActivated $
|
||||||
|
liftIO $ newFile mygui myview
|
||||||
_ <- rcFileCopy mygui `on` menuItemActivated $
|
_ <- rcFileCopy mygui `on` menuItemActivated $
|
||||||
liftIO $ withRow mygui myview copyInit
|
liftIO $ withRow mygui myview copyInit
|
||||||
|
_ <- rcFileMove mygui `on` menuItemActivated $
|
||||||
|
liftIO $ withRow mygui myview moveInit
|
||||||
_ <- rcFilePaste mygui `on` menuItemActivated $
|
_ <- rcFilePaste mygui `on` menuItemActivated $
|
||||||
liftIO $ operationFinal mygui myview
|
liftIO $ operationFinal mygui myview
|
||||||
_ <- rcFileDelete mygui `on` menuItemActivated $
|
_ <- rcFileDelete mygui `on` menuItemActivated $
|
||||||
@ -221,7 +229,7 @@ copyInit row mygui myview =
|
|||||||
operationFinal :: MyGUI -> MyView -> IO ()
|
operationFinal :: MyGUI -> MyView -> IO ()
|
||||||
operationFinal mygui myview = withErrorDialog $ do
|
operationFinal mygui myview = withErrorDialog $ do
|
||||||
op <- readTVarIO (operationBuffer myview)
|
op <- readTVarIO (operationBuffer myview)
|
||||||
cdir <- goUp =<< getFirstRow myview
|
cdir <- getCurrentDir myview
|
||||||
case op of
|
case op of
|
||||||
FMove (MP1 s) -> do
|
FMove (MP1 s) -> do
|
||||||
let cmsg = "Really move \"" ++ fullPath s
|
let cmsg = "Really move \"" ++ fullPath s
|
||||||
@ -249,8 +257,19 @@ operationFinal mygui myview = withErrorDialog $ do
|
|||||||
-- * 'sortedModel' reads
|
-- * 'sortedModel' reads
|
||||||
upDir :: MyGUI -> MyView -> IO ()
|
upDir :: MyGUI -> MyView -> IO ()
|
||||||
upDir mygui myview = withErrorDialog $ do
|
upDir mygui myview = withErrorDialog $ do
|
||||||
cdir <- goUp =<< getFirstRow myview
|
cdir <- getCurrentDir myview
|
||||||
rawModel' <- readTVarIO $ rawModel myview
|
rawModel' <- readTVarIO $ rawModel myview
|
||||||
sortedModel' <- readTVarIO $ sortedModel myview
|
sortedModel' <- readTVarIO $ sortedModel myview
|
||||||
nv <- goUp cdir
|
nv <- goUp cdir
|
||||||
refreshTreeView' mygui myview nv
|
refreshTreeView' mygui myview nv
|
||||||
|
|
||||||
|
|
||||||
|
-- |Go up one directory and visualize it in the treeView.
|
||||||
|
newFile :: MyGUI -> MyView -> IO ()
|
||||||
|
newFile mygui myview = withErrorDialog $ do
|
||||||
|
cdir <- getCurrentDir myview
|
||||||
|
mfn <- fileChooserDialog
|
||||||
|
maybe (return ()) (\fn -> do
|
||||||
|
createFile cdir fn
|
||||||
|
refreshTreeView' mygui myview cdir
|
||||||
|
) mfn
|
||||||
|
@ -47,16 +47,20 @@ data MyGUI = MkMyGUI {
|
|||||||
, menubarFileQuit :: ImageMenuItem
|
, menubarFileQuit :: ImageMenuItem
|
||||||
, menubarFileOpen :: ImageMenuItem
|
, menubarFileOpen :: ImageMenuItem
|
||||||
, menubarFileExecute :: ImageMenuItem
|
, menubarFileExecute :: ImageMenuItem
|
||||||
|
, menubarFileNew :: ImageMenuItem
|
||||||
, menubarEditCut :: ImageMenuItem
|
, menubarEditCut :: ImageMenuItem
|
||||||
, menubarEditCopy :: ImageMenuItem
|
, menubarEditCopy :: ImageMenuItem
|
||||||
|
, menubarEditMove :: ImageMenuItem
|
||||||
, menubarEditPaste :: ImageMenuItem
|
, menubarEditPaste :: ImageMenuItem
|
||||||
, menubarEditDelete :: ImageMenuItem
|
, menubarEditDelete :: ImageMenuItem
|
||||||
, menubarHelpAbout :: ImageMenuItem
|
, menubarHelpAbout :: ImageMenuItem
|
||||||
, rcMenu :: Menu
|
, rcMenu :: Menu
|
||||||
, rcFileOpen :: ImageMenuItem
|
, rcFileOpen :: ImageMenuItem
|
||||||
, rcFileExecute :: ImageMenuItem
|
, rcFileExecute :: ImageMenuItem
|
||||||
|
, rcFileNew :: ImageMenuItem
|
||||||
, rcFileCut :: ImageMenuItem
|
, rcFileCut :: ImageMenuItem
|
||||||
, rcFileCopy :: ImageMenuItem
|
, rcFileCopy :: ImageMenuItem
|
||||||
|
, rcFileMove :: ImageMenuItem
|
||||||
, rcFilePaste :: ImageMenuItem
|
, rcFilePaste :: ImageMenuItem
|
||||||
, rcFileDelete :: ImageMenuItem
|
, rcFileDelete :: ImageMenuItem
|
||||||
, urlBar :: Entry
|
, urlBar :: Entry
|
||||||
|
@ -158,3 +158,26 @@ withErrorDialog io = do
|
|||||||
(\_ -> return ())
|
(\_ -> return ())
|
||||||
r
|
r
|
||||||
|
|
||||||
|
|
||||||
|
-- |Asks the user which directory copy mode he wants via dialog popup
|
||||||
|
-- and returns 'DirCopyMode'.
|
||||||
|
fileChooserDialog :: IO (Maybe String)
|
||||||
|
fileChooserDialog = do
|
||||||
|
chooserDialog <- messageDialogNew Nothing
|
||||||
|
[DialogDestroyWithParent]
|
||||||
|
MessageQuestion
|
||||||
|
ButtonsNone
|
||||||
|
"Enter filename"
|
||||||
|
entry <- entryNew
|
||||||
|
cbox <- dialogGetActionArea chooserDialog
|
||||||
|
dialogAddButton chooserDialog "Create" (ResponseUser 0)
|
||||||
|
dialogAddButton chooserDialog "Cancel" (ResponseUser 1)
|
||||||
|
boxPackStart (castToBox cbox) entry PackNatural 5
|
||||||
|
widgetShowAll chooserDialog
|
||||||
|
rID <- dialogRun chooserDialog
|
||||||
|
ret <- case rID of
|
||||||
|
-- TODO: make this more safe
|
||||||
|
ResponseUser 0 -> Just <$> entryGetText entry
|
||||||
|
ResponseUser 1 -> return Nothing
|
||||||
|
widgetDestroy chooserDialog
|
||||||
|
return ret
|
||||||
|
@ -125,6 +125,12 @@ getFirstRow myview = do
|
|||||||
treeModelGetRow rawModel' iter
|
treeModelGetRow rawModel' iter
|
||||||
|
|
||||||
|
|
||||||
|
-- |Currently unsafe. Gets the current directory via `getFirstRow` and `goUp`.
|
||||||
|
getCurrentDir :: MyView
|
||||||
|
-> IO (AnchoredFile FileInfo)
|
||||||
|
getCurrentDir myview = getFirstRow myview >>= goUp
|
||||||
|
|
||||||
|
|
||||||
-- |Re-reads the current directory or the given one and updates the TreeView.
|
-- |Re-reads the current directory or the given one and updates the TreeView.
|
||||||
--
|
--
|
||||||
-- The operation may fail with:
|
-- The operation may fail with:
|
||||||
|
@ -63,6 +63,7 @@ data FmIOException = FileDoesNotExist String
|
|||||||
| NotAFile String
|
| NotAFile String
|
||||||
| NotADir String
|
| NotADir String
|
||||||
| DestinationInSource String String
|
| DestinationInSource String String
|
||||||
|
| FileDoesExist String
|
||||||
| DirDoesExist String
|
| DirDoesExist String
|
||||||
| IsSymlink String
|
| IsSymlink String
|
||||||
deriving (Show, Typeable)
|
deriving (Show, Typeable)
|
||||||
@ -87,6 +88,11 @@ throwNotAbsolute :: FilePath -> IO ()
|
|||||||
throwNotAbsolute fp = unless (isAbsolute fp) (throw $ PathNotAbsolute fp)
|
throwNotAbsolute fp = unless (isAbsolute fp) (throw $ PathNotAbsolute fp)
|
||||||
|
|
||||||
|
|
||||||
|
throwFileDoesExist :: FilePath -> IO ()
|
||||||
|
throwFileDoesExist fp =
|
||||||
|
whenM (doesFileExist fp) (throw $ FileDoesExist fp)
|
||||||
|
|
||||||
|
|
||||||
throwDirDoesExist :: FilePath -> IO ()
|
throwDirDoesExist :: FilePath -> IO ()
|
||||||
throwDirDoesExist fp =
|
throwDirDoesExist fp =
|
||||||
whenM (doesDirectoryExist fp) (throw $ DirDoesExist fp)
|
whenM (doesDirectoryExist fp) (throw $ DirDoesExist fp)
|
||||||
|
@ -75,6 +75,19 @@ import System.Posix.Files
|
|||||||
, readSymbolicLink
|
, readSymbolicLink
|
||||||
, fileAccess
|
, fileAccess
|
||||||
, getFileStatus
|
, getFileStatus
|
||||||
|
, groupReadMode
|
||||||
|
, groupWriteMode
|
||||||
|
, otherReadMode
|
||||||
|
, otherWriteMode
|
||||||
|
, ownerReadMode
|
||||||
|
, ownerWriteMode
|
||||||
|
, touchFile
|
||||||
|
, unionFileModes
|
||||||
|
)
|
||||||
|
import System.Posix.IO
|
||||||
|
(
|
||||||
|
closeFd
|
||||||
|
, createFile
|
||||||
)
|
)
|
||||||
import System.Process
|
import System.Process
|
||||||
(
|
(
|
||||||
@ -374,3 +387,27 @@ executeFile :: AnchoredFile FileInfo -- ^ program
|
|||||||
executeFile prog@(_ :/ RegFile {}) args
|
executeFile prog@(_ :/ RegFile {}) args
|
||||||
= Just <$> spawnProcess (fullPath prog) args
|
= Just <$> spawnProcess (fullPath prog) args
|
||||||
executeFile _ _ = return Nothing
|
executeFile _ _ = return Nothing
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
---------------------
|
||||||
|
--[ File Creation ]--
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
|
||||||
|
createFile :: AnchoredFile FileInfo -> FileName -> IO ()
|
||||||
|
createFile _ "." = return ()
|
||||||
|
createFile _ ".." = return ()
|
||||||
|
createFile (SADir td) fn = do
|
||||||
|
let fullp = fullPath td </> fn
|
||||||
|
throwFileDoesExist fullp
|
||||||
|
let uf = unionFileModes
|
||||||
|
mode = ownerWriteMode
|
||||||
|
`uf` ownerReadMode
|
||||||
|
`uf` groupWriteMode
|
||||||
|
`uf` groupReadMode
|
||||||
|
`uf` otherWriteMode
|
||||||
|
`uf` otherReadMode
|
||||||
|
fd <- System.Posix.IO.createFile fullp mode
|
||||||
|
closeFd fd
|
||||||
|
Loading…
Reference in New Issue
Block a user