LIB/GTK: fix file renaming (previously called move)
This commit is contained in:
parent
5455ba1066
commit
3639dec1d3
@ -62,8 +62,8 @@
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem" id="rcFileMove">
|
||||
<property name="label">Move</property>
|
||||
<object class="GtkImageMenuItem" id="rcFileRename">
|
||||
<property name="label">Rename</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="image">image1</property>
|
||||
@ -190,7 +190,7 @@
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImageMenuItem" id="menubarEditMove">
|
||||
<object class="GtkImageMenuItem" id="menubarEditRename">
|
||||
<property name="label">Move</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
|
@ -177,8 +177,8 @@ startMainWindow startdir = do
|
||||
"menubarEditCut"
|
||||
menubarEditCopy <- builderGetObject builder castToImageMenuItem
|
||||
"menubarEditCopy"
|
||||
menubarEditMove <- builderGetObject builder castToImageMenuItem
|
||||
"menubarEditMove"
|
||||
menubarEditRename <- builderGetObject builder castToImageMenuItem
|
||||
"menubarEditRename"
|
||||
menubarEditPaste <- builderGetObject builder castToImageMenuItem
|
||||
"menubarEditPaste"
|
||||
menubarEditDelete <- builderGetObject builder castToImageMenuItem
|
||||
@ -201,8 +201,8 @@ startMainWindow startdir = do
|
||||
"rcFileCut"
|
||||
rcFileCopy <- builderGetObject builder castToImageMenuItem
|
||||
"rcFileCopy"
|
||||
rcFileMove <- builderGetObject builder castToImageMenuItem
|
||||
"rcFileMove"
|
||||
rcFileRename <- builderGetObject builder castToImageMenuItem
|
||||
"rcFileRename"
|
||||
rcFilePaste <- builderGetObject builder castToImageMenuItem
|
||||
"rcFilePaste"
|
||||
rcFileDelete <- builderGetObject builder castToImageMenuItem
|
||||
|
@ -41,6 +41,10 @@ import Control.Monad.IO.Class
|
||||
liftIO
|
||||
)
|
||||
import Data.DirTree
|
||||
import Data.Foldable
|
||||
(
|
||||
for_
|
||||
)
|
||||
import Graphics.UI.Gtk
|
||||
import GUI.Gtk.Data
|
||||
import GUI.Gtk.Dialogs
|
||||
@ -125,16 +129,16 @@ setCallbacks mygui myview = do
|
||||
liftIO $ newFile mygui myview
|
||||
|
||||
-- menubar-edit
|
||||
_ <- menubarEditCut mygui `on` menuItemActivated $
|
||||
liftIO $ withRow mygui myview moveInit
|
||||
_ <- menubarEditCopy mygui `on` menuItemActivated $
|
||||
liftIO $ withRow mygui myview copyInit
|
||||
_ <- menubarEditMove mygui `on` menuItemActivated $
|
||||
liftIO $ withRow mygui myview moveInit
|
||||
_ <- menubarEditRename mygui `on` menuItemActivated $
|
||||
liftIO $ withRow mygui myview renameF
|
||||
_ <- 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
|
||||
|
||||
-- menubar-help
|
||||
_ <- menubarHelpAbout mygui `on` menuItemActivated $
|
||||
@ -156,8 +160,8 @@ setCallbacks mygui myview = do
|
||||
liftIO $ newFile mygui myview
|
||||
_ <- rcFileCopy mygui `on` menuItemActivated $
|
||||
liftIO $ withRow mygui myview copyInit
|
||||
_ <- rcFileMove mygui `on` menuItemActivated $
|
||||
liftIO $ withRow mygui myview moveInit
|
||||
_ <- rcFileRename mygui `on` menuItemActivated $
|
||||
liftIO $ withRow mygui myview renameF
|
||||
_ <- rcFilePaste mygui `on` menuItemActivated $
|
||||
liftIO $ operationFinal mygui myview
|
||||
_ <- rcFileDelete mygui `on` menuItemActivated $
|
||||
@ -271,9 +275,19 @@ upDir mygui myview = withErrorDialog $ do
|
||||
-- |Go up one directory and visualize it in the treeView.
|
||||
newFile :: MyGUI -> MyView -> IO ()
|
||||
newFile mygui myview = withErrorDialog $ do
|
||||
cdir <- getCurrentDir myview
|
||||
mfn <- textInputDialog "Enter file name"
|
||||
maybe (return ()) (\fn -> do
|
||||
for_ mfn $ \fn -> do
|
||||
cdir <- getCurrentDir myview
|
||||
createFile cdir fn
|
||||
refreshTreeView' mygui myview cdir
|
||||
) mfn
|
||||
|
||||
|
||||
renameF :: Row -> MyGUI -> MyView -> IO ()
|
||||
renameF row mygui myview = withErrorDialog $ do
|
||||
mfn <- textInputDialog "Enter new file name"
|
||||
for_ mfn $ \fn -> do
|
||||
let cmsg = "Really rename \"" ++ fullPath row
|
||||
++ "\"" ++ " to \"" ++ anchor row </> fn ++ "\"?"
|
||||
withConfirmationDialog cmsg $ IO.File.renameFile row fn
|
||||
cdir <- getCurrentDir myview
|
||||
refreshTreeView' mygui myview cdir
|
||||
|
@ -50,7 +50,7 @@ data MyGUI = MkMyGUI {
|
||||
, menubarFileNew :: ImageMenuItem
|
||||
, menubarEditCut :: ImageMenuItem
|
||||
, menubarEditCopy :: ImageMenuItem
|
||||
, menubarEditMove :: ImageMenuItem
|
||||
, menubarEditRename :: ImageMenuItem
|
||||
, menubarEditPaste :: ImageMenuItem
|
||||
, menubarEditDelete :: ImageMenuItem
|
||||
, menubarHelpAbout :: ImageMenuItem
|
||||
@ -60,7 +60,7 @@ data MyGUI = MkMyGUI {
|
||||
, rcFileNew :: ImageMenuItem
|
||||
, rcFileCut :: ImageMenuItem
|
||||
, rcFileCopy :: ImageMenuItem
|
||||
, rcFileMove :: ImageMenuItem
|
||||
, rcFileRename :: ImageMenuItem
|
||||
, rcFilePaste :: ImageMenuItem
|
||||
, rcFileDelete :: ImageMenuItem
|
||||
, refreshView :: Button
|
||||
|
@ -81,6 +81,7 @@ import System.Posix.Files
|
||||
, otherWriteMode
|
||||
, ownerReadMode
|
||||
, ownerWriteMode
|
||||
, rename
|
||||
, touchFile
|
||||
, unionFileModes
|
||||
)
|
||||
@ -411,3 +412,22 @@ createFile (SADir td) fn = do
|
||||
`uf` otherReadMode
|
||||
fd <- System.Posix.IO.createFile fullp mode
|
||||
closeFd fd
|
||||
|
||||
|
||||
|
||||
|
||||
---------------------
|
||||
--[ File Renaming ]--
|
||||
---------------------
|
||||
|
||||
|
||||
renameFile :: AnchoredFile FileInfo -> FileName -> IO ()
|
||||
renameFile (_ :/ Failed {}) _ = return ()
|
||||
renameFile _ "." = return ()
|
||||
renameFile _ ".." = return ()
|
||||
renameFile af fn = do
|
||||
let fromf = fullPath af
|
||||
tof = anchor af </> fn
|
||||
throwFileDoesExist tof
|
||||
throwSameFile fromf tof
|
||||
rename fromf tof
|
||||
|
Loading…
Reference in New Issue
Block a user