From 74a48b2668fe01bb3eac6bbff43c93eec560d2ac Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Wed, 30 Mar 2016 20:16:34 +0200 Subject: [PATCH] Restructure module layout --- hsfm.cabal | 53 ++++++++++--------- .../Error.hs => HSFM/FileSystem/Errors.hs} | 4 +- .../FileSystem/FileOperations.hs} | 19 +++---- .../FileSystem/FileType.hs} | 12 ++--- src/{ => HSFM}/GUI/Gtk.hs | 6 +-- src/{ => HSFM}/GUI/Gtk/Callbacks.hs | 23 ++++---- src/{ => HSFM}/GUI/Gtk/Callbacks.hs-boot | 4 +- src/{ => HSFM}/GUI/Gtk/Data.hs | 6 +-- src/{ => HSFM}/GUI/Gtk/Dialogs.hs | 8 +-- src/{ => HSFM}/GUI/Gtk/Icons.hs | 2 +- src/{ => HSFM}/GUI/Gtk/MyGUI.hs | 4 +- src/{ => HSFM}/GUI/Gtk/MyView.hs | 18 +++---- src/{ => HSFM}/GUI/Gtk/Utils.hs | 9 ++-- src/{IO/Utils.hs => HSFM/Utils/IO.hs} | 2 +- src/{ => HSFM/Utils}/MyPrelude.hs | 2 +- 15 files changed, 89 insertions(+), 83 deletions(-) rename src/{IO/Error.hs => HSFM/FileSystem/Errors.hs} (98%) rename src/{IO/File.hs => HSFM/FileSystem/FileOperations.hs} (96%) rename src/{Data/DirTree.hs => HSFM/FileSystem/FileType.hs} (98%) rename src/{ => HSFM}/GUI/Gtk.hs (93%) rename src/{ => HSFM}/GUI/Gtk/Callbacks.hs (96%) rename src/{ => HSFM}/GUI/Gtk/Callbacks.hs-boot (92%) rename src/{ => HSFM}/GUI/Gtk/Data.hs (96%) rename src/{ => HSFM}/GUI/Gtk/Dialogs.hs (98%) rename src/{ => HSFM}/GUI/Gtk/Icons.hs (98%) rename src/{ => HSFM}/GUI/Gtk/MyGUI.hs (98%) rename src/{ => HSFM}/GUI/Gtk/MyView.hs (96%) rename src/{ => HSFM}/GUI/Gtk/Utils.hs (96%) rename src/{IO/Utils.hs => HSFM/Utils/IO.hs} (97%) rename src/{ => HSFM/Utils}/MyPrelude.hs (96%) diff --git a/hsfm.cabal b/hsfm.cabal index 90dfe1b..e2163be 100644 --- a/hsfm.cabal +++ b/hsfm.cabal @@ -12,31 +12,34 @@ category: Desktop build-type: Simple cabal-version: >=1.10 -data-files: data/Gtk/builder.xml +data-files: + LICENSE + data/Gtk/builder.xml data/Gtk/icons/error.png data/Gtk/icons/gtk-directory.png data/Gtk/icons/gtk-file.png data/Gtk/icons/hsfm.png hsfm.cabal - LICENSE library - exposed-modules: Data.DirTree - IO.Utils - IO.File - IO.Error - MyPrelude + exposed-modules: + HSFM.FileSystem.Errors + HSFM.FileSystem.FileOperations + HSFM.FileSystem.FileType + HSFM.Utils.IO + HSFM.Utils.MyPrelude - build-depends: base >= 4.7, + build-depends: + base >= 4.7, bytestring, - data-default, containers, + data-default, filepath >= 1.3.0.0, hinotify, + hpath, mtl >= 2.2, old-locale >= 1, - hpath, process, safe, stm, @@ -54,29 +57,31 @@ library "-with-rtsopts=-N" executable hsfm-gtk - main-is: GUI/Gtk.hs - other-modules: GUI.Gtk.Callbacks - GUI.Gtk.Data - GUI.Gtk.Dialogs - GUI.Gtk.Icons - GUI.Gtk.MyGUI - GUI.Gtk.MyView - GUI.Gtk.Utils - MyPrelude + main-is: HSFM/GUI/Gtk.hs + other-modules: + HSFM.GUI.Gtk.Callbacks + HSFM.GUI.Gtk.Data + HSFM.GUI.Gtk.Dialogs + HSFM.GUI.Gtk.Icons + HSFM.GUI.Gtk.MyGUI + HSFM.GUI.Gtk.MyView + HSFM.GUI.Gtk.Utils + HSFM.Utils.MyPrelude - build-depends: hsfm, + build-depends: + Cabal >= 1.22.0.0, base >= 4.7, bytestring, - Cabal >= 1.22.0.0, containers, data-default, - gtk3 >= 0.14.1, - glib >= 0.13, filepath >= 1.3.0.0, + glib >= 0.13, + gtk3 >= 0.14.1, hinotify, + hpath, + hsfm, mtl >= 2.2, old-locale >= 1, - hpath, process, safe, stm, diff --git a/src/IO/Error.hs b/src/HSFM/FileSystem/Errors.hs similarity index 98% rename from src/IO/Error.hs rename to src/HSFM/FileSystem/Errors.hs index d0a4cc9..8c6d9b9 100644 --- a/src/IO/Error.hs +++ b/src/HSFM/FileSystem/Errors.hs @@ -20,7 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. {-# LANGUAGE DeriveDataTypeable #-} -- |Provides error handling. -module IO.Error where +module HSFM.FileSystem.Errors where import Control.Applicative @@ -44,7 +44,7 @@ import Foreign.C.Error getErrno , Errno ) -import IO.Utils +import HSFM.Utils.IO import System.FilePath ( equalFilePath diff --git a/src/IO/File.hs b/src/HSFM/FileSystem/FileOperations.hs similarity index 96% rename from src/IO/File.hs rename to src/HSFM/FileSystem/FileOperations.hs index 56295f3..89786bd 100644 --- a/src/IO/File.hs +++ b/src/HSFM/FileSystem/FileOperations.hs @@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -- It would be nicer to pass states around, but the filesystem state changes -- too quickly and cannot be relied upon. Lazy implementations of filesystem -- trees have been tried as well, but they can introduce subtle bugs. -module IO.File where +module HSFM.FileSystem.FileOperations where import Control.Applicative @@ -41,7 +41,6 @@ import Control.Monad ( unless ) -import Data.DirTree import Data.Foldable ( for_ @@ -56,8 +55,10 @@ import HPath , Fn ) import qualified HPath as P -import IO.Error -import IO.Utils +import HSFM.FileSystem.Errors +import HSFM.FileSystem.FileType +import HSFM.Utils.IO +import HSFM.Utils.MyPrelude import System.FilePath ( () @@ -186,7 +187,7 @@ copyDir cm from@(_ :/ Dir fromn (FileInfo { fileMode = fmode })) throwSameFile fromp' destdirp' createDestdir destdirp fmode - destdir <- Data.DirTree.readFileWithFileInfo destdirp + destdir <- HSFM.FileSystem.FileType.readFileWithFileInfo destdirp contents <- readDirectoryContents' (fullPath from) @@ -208,8 +209,8 @@ copyDir cm from@(_ :/ Dir fromn (FileInfo { fileMode = fmode })) createDirectory destdir' fmode Replace -> do whenM (doesDirectoryExist destdir') - (deleteDirRecursive =<< Data.DirTree.readFileWithFileInfo - destdir) + (deleteDirRecursive =<< + HSFM.FileSystem.FileType.readFileWithFileInfo destdir) createDirectory destdir' fmode copyDir _ _ _ = throw $ InvalidOperation "wrong input type" @@ -234,7 +235,7 @@ recreateSymlink cm symf@(_ :/ SymLink {}) createSymbolicLink sympoint (P.fromAbs symname) where delOld symname = do - f <- Data.DirTree.readFileWithFileInfo symname + f <- HSFM.FileSystem.FileType.readFileWithFileInfo symname unless (failed . file $ f) (easyDelete f) recreateSymlink _ _ _ = throw $ InvalidOperation "wrong input type" @@ -463,7 +464,7 @@ moveFile cm from to@(_ :/ Dir {}) = do easyDelete from where delOld to = do - to' <- Data.DirTree.readFileWithFileInfo to + to' <- HSFM.FileSystem.FileType.readFileWithFileInfo to unless (failed . file $ to') (easyDelete to') moveFile _ _ _ = throw $ InvalidOperation "wrong input type" diff --git a/src/Data/DirTree.hs b/src/HSFM/FileSystem/FileType.hs similarity index 98% rename from src/Data/DirTree.hs rename to src/HSFM/FileSystem/FileType.hs index 70d68e5..fd998e2 100644 --- a/src/Data/DirTree.hs +++ b/src/HSFM/FileSystem/FileType.hs @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -- -- It doesn't allow to represent the whole filesystem, since that's only -- possible through IO laziness, which introduces too much internal state. -module Data.DirTree where +module HSFM.FileSystem.FileType where import Control.Applicative @@ -95,7 +95,7 @@ import HPath , pattern Path ) import qualified HPath as P -import MyPrelude +import HSFM.Utils.MyPrelude import Safe ( atDef @@ -488,7 +488,7 @@ readFile :: (Path Abs -> IO a) -> Path Abs -> IO (AnchoredFile a) readFile ff fp = readWith ff fp readFileWithFileInfo :: Path Abs -> IO (AnchoredFile FileInfo) -readFileWithFileInfo = Data.DirTree.readFile getFileInfo +readFileWithFileInfo = HSFM.FileSystem.FileType.readFile getFileInfo -- |Build a list of AnchoredFile, given the path to a directory, filling -- the free variables via `getFileInfo`. This includes the "." and ".." @@ -512,7 +512,7 @@ readDirectoryContentsWith :: (Path Abs -> IO [Path Fn]) -> IO [AnchoredFile a] readDirectoryContentsWith getfiles ff p = do files <- getfiles p - fcs <- mapM (\x -> Data.DirTree.readFile ff $ p P. x) files + fcs <- mapM (\x -> HSFM.FileSystem.FileType.readFile ff $ p P. x) files return $ removeNonexistent fcs @@ -622,12 +622,12 @@ isSocketC _ = False -- |Go up one directory in the filesystem hierarchy. goUp :: AnchoredFile FileInfo -> IO (AnchoredFile FileInfo) goUp af@(Path "" :/ _) = return af -goUp (bp :/ _) = Data.DirTree.readFile getFileInfo bp +goUp (bp :/ _) = HSFM.FileSystem.FileType.readFile getFileInfo bp -- |Go up one directory in the filesystem hierarchy. goUp' :: Path Abs -> IO (AnchoredFile FileInfo) -goUp' fp = Data.DirTree.readFile getFileInfo $ P.dirname fp +goUp' fp = HSFM.FileSystem.FileType.readFile getFileInfo $ P.dirname fp -- |Get the contents of a directory. diff --git a/src/GUI/Gtk.hs b/src/HSFM/GUI/Gtk.hs similarity index 93% rename from src/GUI/Gtk.hs rename to src/HSFM/GUI/Gtk.hs index 434fbc6..50dab99 100644 --- a/src/GUI/Gtk.hs +++ b/src/HSFM/GUI/Gtk.hs @@ -22,9 +22,9 @@ module Main where import Graphics.UI.Gtk -import GUI.Gtk.Data -import GUI.Gtk.MyGUI -import GUI.Gtk.MyView +import HSFM.GUI.Gtk.Data +import HSFM.GUI.Gtk.MyGUI +import HSFM.GUI.Gtk.MyView import Safe ( headDef diff --git a/src/GUI/Gtk/Callbacks.hs b/src/HSFM/GUI/Gtk/Callbacks.hs similarity index 96% rename from src/GUI/Gtk/Callbacks.hs rename to src/HSFM/GUI/Gtk/Callbacks.hs index c9a30f8..b342701 100644 --- a/src/GUI/Gtk/Callbacks.hs +++ b/src/HSFM/GUI/Gtk/Callbacks.hs @@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. {-# OPTIONS_HADDOCK ignore-exports #-} -module GUI.Gtk.Callbacks where +module HSFM.GUI.Gtk.Callbacks where import Control.Applicative @@ -43,20 +43,20 @@ 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 -import GUI.Gtk.MyView -import GUI.Gtk.Utils import qualified HPath as P -import IO.Error -import IO.File -import IO.Utils +import HSFM.FileSystem.Errors +import HSFM.FileSystem.FileOperations +import HSFM.FileSystem.FileType +import HSFM.GUI.Gtk.Data +import HSFM.GUI.Gtk.Dialogs +import HSFM.GUI.Gtk.MyView +import HSFM.GUI.Gtk.Utils +import HSFM.Utils.IO import System.FilePath ( isAbsolute @@ -217,7 +217,7 @@ open :: [Item] -> MyGUI -> MyView -> IO () open [item] mygui myview = withErrorDialog $ case item of ADirOrSym r -> do - nv <- Data.DirTree.readFileWithFileInfo $ fullPath r + nv <- HSFM.FileSystem.FileType.readFileWithFileInfo $ fullPath r refreshView' mygui myview nv r -> void $ openFile r @@ -325,7 +325,8 @@ renameF [item] mygui myview = withErrorDialog $ do for_ pmfn $ \fn -> do let cmsg = "Really rename \"" ++ P.fromAbs (fullPath item) ++ "\"" ++ " to \"" ++ P.fromAbs (anchor item P. fn) ++ "\"?" - withConfirmationDialog cmsg $ IO.File.renameFile item fn + withConfirmationDialog cmsg $ + HSFM.FileSystem.FileOperations.renameFile item fn renameF _ _ _ = withErrorDialog . throw $ InvalidOperation "Operation not supported on multiple files" diff --git a/src/GUI/Gtk/Callbacks.hs-boot b/src/HSFM/GUI/Gtk/Callbacks.hs-boot similarity index 92% rename from src/GUI/Gtk/Callbacks.hs-boot rename to src/HSFM/GUI/Gtk/Callbacks.hs-boot index 5733f78..090e377 100644 --- a/src/GUI/Gtk/Callbacks.hs-boot +++ b/src/HSFM/GUI/Gtk/Callbacks.hs-boot @@ -17,9 +17,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. --} -module GUI.Gtk.Callbacks where +module HSFM.GUI.Gtk.Callbacks where -import GUI.Gtk.Data +import HSFM.GUI.Gtk.Data setCallbacks :: MyGUI -> MyView -> IO () diff --git a/src/GUI/Gtk/Data.hs b/src/HSFM/GUI/Gtk/Data.hs similarity index 96% rename from src/GUI/Gtk/Data.hs rename to src/HSFM/GUI/Gtk/Data.hs index aea1503..d810357 100644 --- a/src/GUI/Gtk/Data.hs +++ b/src/HSFM/GUI/Gtk/Data.hs @@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. {-# OPTIONS_HADDOCK ignore-exports #-} -module GUI.Gtk.Data where +module HSFM.GUI.Gtk.Data where import Control.Concurrent.MVar @@ -29,9 +29,9 @@ import Control.Concurrent.STM ( TVar ) -import Data.DirTree import Graphics.UI.Gtk -import IO.File +import HSFM.FileSystem.FileOperations +import HSFM.FileSystem.FileType import System.INotify ( INotify diff --git a/src/GUI/Gtk/Dialogs.hs b/src/HSFM/GUI/Gtk/Dialogs.hs similarity index 98% rename from src/GUI/Gtk/Dialogs.hs rename to src/HSFM/GUI/Gtk/Dialogs.hs index 4837cf6..9880064 100644 --- a/src/GUI/Gtk/Dialogs.hs +++ b/src/HSFM/GUI/Gtk/Dialogs.hs @@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. {-# OPTIONS_HADDOCK ignore-exports #-} -module GUI.Gtk.Dialogs where +module HSFM.GUI.Gtk.Dialogs where import Control.Applicative @@ -60,9 +60,9 @@ import Distribution.Verbosity silent ) import Graphics.UI.Gtk -import GUI.Gtk.Data -import IO.Error -import IO.File +import HSFM.FileSystem.Errors +import HSFM.FileSystem.FileOperations +import HSFM.GUI.Gtk.Data import Paths_hsfm ( getDataFileName diff --git a/src/GUI/Gtk/Icons.hs b/src/HSFM/GUI/Gtk/Icons.hs similarity index 98% rename from src/GUI/Gtk/Icons.hs rename to src/HSFM/GUI/Gtk/Icons.hs index 8568b1c..b95c271 100644 --- a/src/GUI/Gtk/Icons.hs +++ b/src/HSFM/GUI/Gtk/Icons.hs @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. {-# OPTIONS_HADDOCK ignore-exports #-} -- |Module for Gtk icon handling. -module GUI.Gtk.Icons where +module HSFM.GUI.Gtk.Icons where import Data.Maybe diff --git a/src/GUI/Gtk/MyGUI.hs b/src/HSFM/GUI/Gtk/MyGUI.hs similarity index 98% rename from src/GUI/Gtk/MyGUI.hs rename to src/HSFM/GUI/Gtk/MyGUI.hs index 90f46c3..78988d3 100644 --- a/src/GUI/Gtk/MyGUI.hs +++ b/src/HSFM/GUI/Gtk/MyGUI.hs @@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. {-# OPTIONS_HADDOCK ignore-exports #-} -module GUI.Gtk.MyGUI where +module HSFM.GUI.Gtk.MyGUI where import Control.Concurrent.STM @@ -26,7 +26,7 @@ import Control.Concurrent.STM newTVarIO ) import Graphics.UI.Gtk -import GUI.Gtk.Data +import HSFM.GUI.Gtk.Data import Paths_hsfm ( getDataFileName diff --git a/src/GUI/Gtk/MyView.hs b/src/HSFM/GUI/Gtk/MyView.hs similarity index 96% rename from src/GUI/Gtk/MyView.hs rename to src/HSFM/GUI/Gtk/MyView.hs index 5966647..155ce86 100644 --- a/src/GUI/Gtk/MyView.hs +++ b/src/HSFM/GUI/Gtk/MyView.hs @@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. {-# OPTIONS_HADDOCK ignore-exports #-} -module GUI.Gtk.MyView where +module HSFM.GUI.Gtk.MyView where import Control.Applicative @@ -36,7 +36,6 @@ import Control.Concurrent.STM newTVarIO , readTVarIO ) -import Data.DirTree import Data.Foldable ( for_ @@ -48,13 +47,14 @@ import Data.Maybe , fromMaybe ) import Graphics.UI.Gtk -import {-# SOURCE #-} GUI.Gtk.Callbacks (setCallbacks) -import GUI.Gtk.Data -import GUI.Gtk.Icons -import GUI.Gtk.Utils +import {-# SOURCE #-} HSFM.GUI.Gtk.Callbacks (setCallbacks) import qualified HPath as P -import IO.File -import IO.Utils +import HSFM.FileSystem.FileOperations +import HSFM.FileSystem.FileType +import HSFM.GUI.Gtk.Data +import HSFM.GUI.Gtk.Icons +import HSFM.GUI.Gtk.Utils +import HSFM.Utils.IO import System.FilePath ( isAbsolute @@ -196,7 +196,7 @@ refreshView mygui myview mfp = case mfp of Just fp -> do let mdir = fromMaybe (fromJust $ P.parseAbs "/") (P.parseAbs fp) - cdir <- Data.DirTree.readFileWithFileInfo mdir + cdir <- HSFM.FileSystem.FileType.readFileWithFileInfo mdir refreshView' mygui myview cdir Nothing -> refreshView' mygui myview =<< getCurrentDir myview diff --git a/src/GUI/Gtk/Utils.hs b/src/HSFM/GUI/Gtk/Utils.hs similarity index 96% rename from src/GUI/Gtk/Utils.hs rename to src/HSFM/GUI/Gtk/Utils.hs index cbe5adf..80fa784 100644 --- a/src/GUI/Gtk/Utils.hs +++ b/src/HSFM/GUI/Gtk/Utils.hs @@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. {-# OPTIONS_HADDOCK ignore-exports #-} -module GUI.Gtk.Utils where +module HSFM.GUI.Gtk.Utils where import Control.Applicative @@ -29,7 +29,6 @@ import Control.Concurrent.STM ( readTVarIO ) -import Data.DirTree import Data.Maybe ( catMaybes @@ -40,8 +39,8 @@ import Data.Traversable forM ) import Graphics.UI.Gtk -import GUI.Gtk.Data - +import HSFM.FileSystem.FileType +import HSFM.GUI.Gtk.Data @@ -109,7 +108,7 @@ fileListStore :: AnchoredFile FileInfo -- ^ current dir -> MyView -> IO (ListStore Item) fileListStore dt myview = do - cs <- Data.DirTree.getContents dt + cs <- HSFM.FileSystem.FileType.getContents dt listStoreNew cs diff --git a/src/IO/Utils.hs b/src/HSFM/Utils/IO.hs similarity index 97% rename from src/IO/Utils.hs rename to src/HSFM/Utils/IO.hs index 45ed50f..b211a99 100644 --- a/src/IO/Utils.hs +++ b/src/HSFM/Utils/IO.hs @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. {-# OPTIONS_HADDOCK ignore-exports #-} -- |Random and general IO utilities. -module IO.Utils where +module HSFM.Utils.IO where import Control.Concurrent.STM diff --git a/src/MyPrelude.hs b/src/HSFM/Utils/MyPrelude.hs similarity index 96% rename from src/MyPrelude.hs rename to src/HSFM/Utils/MyPrelude.hs index 95fb59a..bd7c4dd 100644 --- a/src/MyPrelude.hs +++ b/src/HSFM/Utils/MyPrelude.hs @@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. --} -module MyPrelude where +module HSFM.Utils.MyPrelude where import Data.Default