[plt-scheme] drscheme extension to save an load a set of tabs

From: Stephen De Gabrielle (spdegabrielle at gmail.com)
Date: Mon Aug 25 15:47:33 EDT 2008

Thanks,

I owe you the double thanks because I used drsync to work out how to do this.

Your feedback is much appreciated;

> Your icon looks good, but it is the wrong size. It should be 32x32. My
haha! I just used a screen grabber to capture part of the screen that
had project written on it
new icon fixed to 32x32  (same technique - but capture from module browser)

> I like your use of pack.ss. I had used shell scripts to package everything up.
I am lazy

> You could:
> * Add scribble documentation.
I just don't have the time for scribble - of course this is an opinion
from ignorance of scribble  - I appear trapped...

> * Put the buttons on the left near the file chooser/browser. Since you
> are performing file operations, this is the logical place to find it.
I can't work out how to do thid (HELP)

> * Upper-case the icon labels and remove the dash.
I Assume You Mean Title Case

> * When loading a project, don't re-load files that are already open.
(added to the to-do list)

> * More clearly state your goals and vision of the plugin. Files
> grouped into a project using this plugin, and the ability to browse
> code dependencies using the module browser, seem to be complementary
> features.
Sorry, at this stage it has been about what I can achieve with the
mimimal effort

> * Save more than 1 project
I need an open-project button that lets me select a file (and save project)

> You could also:
> * Use a different extension that .psp. That is associated to PSP image
> files (on Windows atleast).
suggestions - I have changed to .ss for the moment.

> * Put the project file in the users home dir, use (find-system-path 'home-dir).
done thanks for the tip :)

> * I used the predicate for whether a tab has a file is to apply
> file-path to the tab, rather than asking a tab for its filename and
> checking if it exists.Tabs are created in a state where they aren't
> associated with a file, the only way to associate them with a file is
> by creating a new one or one that already exists (to the best of my
> knowledge at least).
Umm, could you elaborate?

> * A menu in the menubar might be a better place rather than buttons.
yes

> * The button icons don't show up for me, but I see them configured in
> the button.
I can't work out how to get them working. (HELP)

Any help appreciated...

Thanks again,

Stephen


#lang scheme/base
(require (lib "tool.ss" "drscheme")
         mred
         mrlib/switchable-button
         mzlib/unit
         scheme/class)

(provide tool@)

(define tool@
  (unit
    (import drscheme:tool^)
    (export drscheme:tool-exports^)
    (define phase1 void)
    (define phase2 void)

    (define project-icon "project.png")
    (define project-icon-sm "project-sm.png")
    (define home-dir (find-system-path 'home-dir))
    (define saved-tabs-file (string->path "saved-tabs-file.ss"))
    (define saved-tabs-file-path (build-path home-dir saved-tabs-file))
    (define (save x)
      (call-with-output-file saved-tabs-file-path
        (lambda (i) (write x i))
        #:exists 'replace
        ))

    (define (load)
      (for-each (lambda (filename)
                  (drscheme:unit:open-drscheme-window filename))
                (if (file-exists?  saved-tabs-file-path)
                    (call-with-input-file  saved-tabs-file-path
(lambda (i) (read i)))
                    '()
                    )))


    (define (projects-unit-frame-mixin super%)
      (class super%
        (inherit get-button-panel)

        ;; each-tab -> list of files
        (define (get-tab-files)
          (map
           (lambda (tab)
             (let ([editor (send tab get-defs)])
               (when (file-exists? (send editor get-filename))
(path->string (send editor get-filename)))))
           (send this get-tabs)))

        (super-new)

        (inherit register-toolbar-button)

        (define project-icon-bitmap (make-object bitmap%
project-icon-sm 'png/mask))

        (define save-project-button
          (new switchable-button%
               (label "save tabs")
               (parent (make-object vertical-pane% (get-button-panel)))
               (callback (lambda (button) (save (get-tab-files))))
               [bitmap project-icon-bitmap]

               ))
        (register-toolbar-button save-project-button)

        (send (get-button-panel) change-children
              (lambda (_)
                (cons (send save-project-button get-parent)
                      (remq (send save-project-button get-parent) _))))

        (define load-project-button
          (new switchable-button%
               (label "reload tabs")
               (parent (make-object vertical-pane% (get-button-panel)))
               (callback (lambda (button) (load)))
               [bitmap project-icon-bitmap]
               ))
        (register-toolbar-button load-project-button)

        (send (get-button-panel) change-children
              (lambda (_)
                (cons (send load-project-button get-parent)
                      (remq (send load-project-button get-parent) _))))
        ))
    (drscheme:get/extend:extend-unit-frame projects-unit-frame-mixin)
    ))


On Mon, Aug 25, 2008 at 4:59 PM, Grant Rettke <grettke at acm.org> wrote:
> Hi Stephen,
>
>> let me know what you think
>
> Your first run looks good. Here are some thoughts:
>
> Your icon looks good, but it is the wrong size. It should be 32x32. My
> icon in DrSync looks, ok, but not good. I used pov-ray. I wish I had
> an artist at my disposal.
>
> I like your use of pack.ss. I had used shell scripts to package everything up.
>
> I tested out the plugin, it works fine. Inevitably now people will
> tell you "You should...". Here is my contribution :).
>
> You could:
> * Add scribble documentation.
> * Put the buttons on the left near the file chooser/browser. Since you
> are performing file operations, this is the logical place to find it.
> * Upper-case the icon labels and remove the dash.
> * When loading a project, don't re-load files that are already open.
> * More clearly state your goals and vision of the plugin. Files
> grouped into a project using this plugin, and the ability to browse
> code dependencies using the module browser, seem to be complementary
> features.
> * Save more than 1 project
>
> You could also:
> * Use a different extension that .psp. That is associated to PSP image
> files (on Windows atleast).
> * Put the project file in the users home dir, use (find-system-path 'home-dir).
> * I used the predicate for whether a tab has a file is to apply
> file-path to the tab, rather than asking a tab for its filename and
> checking if it exists.Tabs are created in a state where they aren't
> associated with a file, the only way to associate them with a file is
> by creating a new one or one that already exists (to the best of my
> knowledge at least).
> * A menu in the menubar might be a better place rather than buttons.
> * The button icons don't show up for me, but I see them configured in
> the button.
>
> Best wishes,
>
> Grant
>



-- 
Cheers,

Stephen


Posted on the users mailing list.