PreviousUpNext

15.4.1327  src/lib/tk/src/toolkit/tests+examples/filer_ex.pkg

## filer_ex.pkg
## (C) 1999, Bremen Institute for Safe Systems, Universitaet Bremen
## Author: ludi

# Compiled by:
#     src/lib/tk/src/toolkit/tests+examples/sources.sublib



# ***************************************************************************
# Complete example instantiation of class macro filer
# **************************************************************************


package filer_ex

: (weak)  api {
                 go:  Void -> Void;
          }
{
    package options {

        fun icons_path ()    = winix__premicrothread::path::cat (tk::get_lib_path(),
                                             "icons/filer/example");
        icons_size      = (24, 24);
        fun root ()          = NULL; #  THE "/home/ludi" 
        default_pattern = NULL; #  THE ".*.sml" 
        package clipboard        = clipboard_g ( Part = String;);

        filetypes
            =
            [{ ext     => [""],
              display => THE { comment     => "Default filetype",
                              icon        => "default_Icon.gif",
                              preview     => NULL,
                              file_to_obj => THE winix__premicrothread::path::make_path_from_dir_and_file }},
                                      #  example for a default filetype 

                 /* the empty string in the extensions list sets the     *
                  * default filetype;                                    *
                  * if there is no default filetype, unmatched files are *
                  * displayed as "Unknown filetype" with the system icon */

             { ext     => ["pkg"],
              display => THE { comment     => "Standard ML file",
                              icon        => "sml_Icon.gif",
                              preview     => NULL,
                              file_to_obj => THE winix__premicrothread::path::make_path_from_dir_and_file }},
             { ext     =>["gif"],
              display => THE { comment     => "GIF - image",
                              icon        => "gif_Icon.gif",
                              preview     => NULL,
                              file_to_obj => THE winix__premicrothread::path::make_path_from_dir_and_file }},
             { ext     => ["ps"],
              display => THE { comment     => "PostScript file",
                              icon        => "ps_Icon.gif",
                              preview     =>
                                 THE (\\ { dir, file } =>
                                      { winix__premicrothread::process::bin_sh'
                                         ("ghostview " $
                                          winix__premicrothread::path::make_path_from_dir_and_file
                                            { dir  => (if (not_null (root()) )
                                                         winix__premicrothread::path::cat
                                                           (the (root()),
                                                            dir);
                                                     else dir;fi),
                                             file } + "&_"); ();}
                                       except _ => (); end; end ),
                              file_to_obj => THE winix__premicrothread::path::make_path_from_dir_and_file }},
             { ext     => ["html"],
              display => THE { comment     => "HTML document",
                              icon        => "html_Icon.gif",
                              preview     =>
                                THE (\\ { dir, file } =>
                                      { winix__premicrothread::process::bin_sh'
                                         ("netscape -raise -remote 'openFile(" +
                                          winix__premicrothread::path::make_path_from_dir_and_file
                                            { dir  => (if (not_null (root()) )
                                                         winix__premicrothread::path::cat
                                                           (the (root()),
                                                            dir);
                                                     else dir;fi),
                                             file } + ")' &"); ();}
                                       except _ => (); end; end),
                              file_to_obj => THE winix__premicrothread::path::make_path_from_dir_and_file } } ];

        package conf= filer_default_config;     # filer_default_config  is from   src/lib/tk/src/toolkit/filer_default_config.pkg

    };           #  package options 

    include package   tk;

    package example = filer_g (package options = options;);

                                                                                my 
    txt_id = make_widget_id();

    fun dropped ev
        =
        if (options::clipboard::is_empty ev)
             ();
        else
              add_trait txt_id [ACTIVE TRUE];
              insert_text_end txt_id
                            (options::clipboard::get ev + " dropped\n");
              add_trait txt_id [ACTIVE FALSE];
        fi;

    fun fate sel
        =
        {   add_trait txt_id [ACTIVE TRUE];
            case sel
              
                 THE (THE f, THE d)
                     => 
                     insert_text_end  txt_id  ("Dir " + d + ", file " + f + " selected.\n");
                 _   =>
                     insert_text_end  txt_id  "Not a lot selected.\n";
            esac;

            add_trait txt_id [ACTIVE FALSE];
        };

    fun go ()
        = 
        { add_trait txt_id [ACTIVE TRUE];
         example::file_select fate;};
                                                                                my
    drop_window
        =
        make_window {
            window_id    => make_window_id (),
            traits   => [WINDOW_TITLE "Drop field"],
            event_callbacks => [],
            init     => \\ () => (); end ,
            subwidgets  => PACKED [TEXT_WIDGET { widget_id      => txt_id,
                                             scrollbars => AT_RIGHT,
                                             live_text   => empty_livetext,
                                             packing_hints   => [],
                                             traits    => [HEIGHT 5,
                                                           ACTIVE FALSE],
                                             event_callbacks   =>
                                               [EVENT_CALLBACK (ENTER, dropped)] },
                                    BUTTON { widget_id => make_widget_id(),
                                            packing_hints => [],
                                            traits  =>
                                              [TEXT "Start Filer",
                                               CALLBACK go],
                                            event_callbacks => [] },
                                    BUTTON { widget_id => make_widget_id(),
                                            packing_hints => [],
                                            traits  => [ TEXT "Quit",
                                                         CALLBACK (\\ _ => exit_tcl(); end  ) ],
                                            event_callbacks => [] }
                                  ]
        };

    fun go ()
        =
        start_tcl [ drop_window ];

}; #  package FilerEx 


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext