Mar 08

I have my search functions working again. The problem was that when Gtk was updated, and I updated my code to this I also changed how FilePath’s were passed around to the various methods. I did this to only pass around what was necessary, rather than the full paths, and I never reflected this within my search code! Pretty stupid really, but an easy mistake to make. A mistake that also had a domino effect on the methods that search uses!! So when search was fixed, I had to go through the other methods and update those too!

I edited my openFile method so that, it tries to open the supplied file using “xdg-open”. If that is successful, it returns ExitSuccess, and the function exits. However, if it returns any other type of exit, i.e. ExitFailure Int, it searches a file containg extensions & commands. It searches for the extension of the supplied file. If it’s found it asks the user for a command to run the file with, i.e. .hs files are opened in gedit. If the command that the user enters is successful, it then writes the extension command combo to the file for future use.

I finally figured out how to do a right-click menu, which is pretty good, the code is 90% identical to the file menu code. Originally, following the example I found, the action had to be added to the overall window, but I found that that didn’t work. It has to be added to the ScrolledWindow that the user will be making selections from. This has a couple of benefits: Different menu’s for different parts of the screen.

I still have to try to:

  • Implement Drag and Drop.
  • Expand tree to selected
  • Now that I have the right-click menu, try renaming within the scrolled window.

M

Tagged with:
Mar 05

To start with, I’ve created two types for my program, a StoreRow type and a Browser type, these have enabled me to make my code a bit more readable, and also to decrease the length of my function signatures :D , as some of them spanned 2 lines in my editor. It also allows me to work more freely, as I can pass the respective types around, taking what I need from them where I need it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
data StoreRow = StoreRow {
    name :: String,
    icon :: Pixbuf,
    size :: String,
    lastAccess :: String,
    permissions :: String }
 
data FileBrowser = FileBrowser {
    switch :: ToggleButton,
    location :: Entry,
    treeScroll :: ScrolledWindow,
    dirScroll :: ScrolledWindow,
    fileScroll :: ScrolledWindow,
    treeTree :: TreeView,
    dirTree :: TreeView,
    fileTree :: TreeView,
    treeStore :: TreeStore String,
    dirStore :: ListStore StoreRow,
    fileStore :: ListStore StoreRow }

Secondly, as stated before, I’m using xdg-open to open files, using System.Cmd. I’ve been messing around with it a bit today, and I thought before that if it couldn’t find a default application it still returned ExitSuccess to rawSystem, but, it actually doesn’t so what I plan to do now is, if it doesn’t find an application to open the passed file, pop up an error window, prompting the user to supply a command name to open it with, then write this to a file, along with the extension of the file being opened. Next time it happens, scan through the file, and if a command isn’t found to match the extension, query the user!

Problem solved…. In theory!

I’m going to start documenting the code using Haddock and I’ll upload that later.

M

Tagged with:
preload preload preload