PEAR_Frontend_Gtk
[ class tree: PEAR_Frontend_Gtk ] [ index: PEAR_Frontend_Gtk ] [ all elements ]

Source for file DirSelect.php

Documentation is available at DirSelect.php

  1. <?php
  2. /*
  3.   +----------------------------------------------------------------------+
  4.   | PHP Version 4                                                        |
  5.   +----------------------------------------------------------------------+
  6.   | Copyright (c) 1997-2003 The PHP Group                                |
  7.   +----------------------------------------------------------------------+
  8.   | This source file is subject to version 2.02 of the PHP license,      |
  9.   | that is bundled with this package in the file LICENSE, and is        |
  10.   | available at through the world-wide-web at                           |
  11.   | http://www.php.net/license/2_02.txt.                                 |
  12.   | If you did not receive a copy of the PHP license and are unable to   |
  13.   | obtain it through the world-wide-web, please send a note to          |
  14.   | license@php.net so we can mail you a copy immediately.               |
  15.   +----------------------------------------------------------------------+
  16.   | Author: Alan Knowles <alan@akbkhome.com>                             |
  17.   +----------------------------------------------------------------------+
  18.  
  19.   $Id: DirSelect.php,v 1.5 2003/01/04 11:55:55 mj Exp $
  20. */
  21.  
  22. /**
  23.  * Gtk Frontend - Configuration
  24.  *
  25.  * @author Alan Knowles <alan@akbkhome.com>
  26.  */
  27.  
  28.  
  29. class PEAR_Frontend_Gtk_DirSelect {
  30.     var $ui// main interface
  31.     /**
  32.     * The GtkEntry that shows the currently seelcted directory
  33.     *
  34.     * @var object GtkEntry 
  35.     */
  36.     var $entry;
  37.        /**
  38.     * The GtkDialog of the window
  39.     *
  40.     * @var object GtkDialog 
  41.     */
  42.     var $window;
  43.    /**
  44.     * The Top pulldown
  45.     *
  46.     * @var object GtkOptionMenu 
  47.     */
  48.     var $optionMenu;
  49.     /**
  50.     * The full list of directories
  51.     *
  52.     * @var object GtkClist 
  53.     */
  54.     var $cList;
  55.     /**
  56.     * Constructor
  57.     *
  58.     * @param object PEAR_Frontend_Gtk 
  59.     */
  60.     
  61.     function PEAR_Frontend_Gtk_DirSelect(&$ui{
  62.         $this->ui &$ui;
  63.     }
  64.     
  65.      /**
  66.     * Currently active widget to save result into (eg. gtkentry)
  67.     *
  68.     * @var object gtkentry 
  69.     * @access private
  70.     */
  71.     var $_DirSelectActiveWidget = NULL;
  72.     /**
  73.     * Currently active configuration key
  74.     *
  75.     * @var string 
  76.     * @access private
  77.     */
  78.     var $_DirSelectActiveKey = NULL;
  79.     /**
  80.     * Display the Directory selection dialog
  81.     *
  82.     * Displays the directory dialog, fills in the data etc.
  83.     * 
  84.     * @param   object gtkentry   The text entry to fill in on closing
  85.     *
  86.     */
  87.     function onDirSelect($widget,$key{
  88.         // set the title!!
  89.         $this->_DirSelectActiveKey $key;
  90.         $this->_DirSelectActiveWidget &$widget;
  91.         $prompt 'xxx';
  92.         $prompt $this->ui->config->getPrompt($widget->get_data('key'));
  93.         $this->window->set_title($prompt);
  94.         
  95.         $curvalue $widget->get_text();
  96.         // load the pulldown
  97.         $this->_DirSelectSetDir(dirname($curvalue)basename($curvalue));
  98.         $this->entry->set_text($curvalue);
  99.         $this->window->show();
  100.     }
  101.     
  102.     /**
  103.     * Associated array of Row -> directory name
  104.     *
  105.     * It could be possible to get the row string using gtk calls......
  106.     *
  107.     * @var array 
  108.     * @access private
  109.     */
  110.     var $_DirSelectRows = array();
  111.     
  112.     /**
  113.     * Load the directories into the directory list/pulldown etc.
  114.     *
  115.     * Loads the information into the popup / list of directories
  116.     * TODO: Windows A:D: etc. drive support
  117.     *
  118.     * @param  string $directory name of directory to browse
  119.     * @param  string $file      name of file to select in list.
  120.     *
  121.     */
  122.     function _DirSelectSetDir($directory$file='.'{
  123.         $parts explode(DIRECTORY_SEPARATOR$directory);
  124.         $disp = array();
  125.         $i=0;
  126.         $items = array();
  127.         $gtkmenu &new GtkMenu();
  128.         foreach($parts as $dirpart{
  129.             $disp[$dirpart;
  130.             $dir implode(DIRECTORY_SEPARATOR,$disp);
  131.             if (!$dir && DIRECTORY_SEPARATOR == '/'$dir '/';
  132.             if (!$dircontinue;
  133.             $items[$i&new GtkMenuItem($dir);
  134.             $items[$i]->connect_object_after('activate'array(&$this,'_DirSelectSetDir'),$dir);
  135.             $gtkmenu->append($items[$i]);
  136.             $i++;
  137.         }    
  138.         $gtkmenu->set_active($i-1);
  139.         $gtkmenu->show_all();
  140.         $this->optionMenu->set_menu($gtkmenu);
  141.         $base $directory;
  142.         
  143.         $this->cList->select_row(0,0);
  144.         $this->cList->freeze();
  145.         $this->cList->clear();
  146.         
  147.         clearstatcache();
  148.         $dh opendir($base);
  149.         $dirs = array();
  150.         while (($dir readdir($dh)) !== FALSE{
  151.             if (!is_dir($base.DIRECTORY_SEPARATOR.$dir)) continue;
  152.             $dirs[$dir;
  153.         }
  154.         sort($dirs);
  155.         $this->_DirSelectRows = array();
  156.         $sel =0;
  157.         $i=0;
  158.         foreach($dirs as $dir{
  159.             $this->cList->append(array($dir))
  160.             $this->_DirSelectRows[realpath($base.DIRECTORY_SEPARATOR.$dir);
  161.             if ($dir == $file)
  162.                 $sel $i;
  163.             $i++;
  164.         }
  165.         $this->cList->thaw();  
  166.         if ($file != '.'{
  167.             
  168.             $this->cList->select_row($sel,0);
  169.             $this->cList->moveto($i,0,0,0);
  170.             $this->entry->set_text($directory);
  171.         else {
  172.             
  173.             $this->_DirListBlockSel = TRUE;
  174.             $this->cList->select_row(0,0);
  175.             $this->_DirListBlockSel = TRUE;
  176.         }
  177.         
  178.        
  179.     }
  180.     /**
  181.     * Flag to block reselecting of current row after update
  182.     *
  183.     * Introduced to attempt to fix problem that when you double click to open a
  184.     * Directory, after refresh, the clist recieves a select signal on the same rows
  185.     * and hence attemps to select the wrong directory..
  186.     *
  187.     * @var boolean 
  188.     * @access private
  189.     */
  190.     var $_DirListBlockSel = FALSE;
  191.     /**
  192.     * Initial Select Row (not double click)
  193.     *
  194.     * Makes this selected item the 'active directory'
  195.     *
  196.     * @param  string $directory name of directory to browse
  197.     * @param  string $row       selected line
  198.     *
  199.     */
  200.     function onDirListSelectRow($widget,$row{
  201.         
  202.         if ($this->_DirListBlockSel
  203.           
  204.             $this->_DirListBlockSel = FALSE;
  205.             $widget->select_row(0,0);
  206.             return;
  207.         }
  208.         if ($row < 0return;
  209.         $this->entry->set_text(@$this->_DirSelectRows[$row]);
  210.     }
  211.     
  212.     /**
  213.     * Callback when the list of directories is clicked
  214.     *
  215.     * Used to find the double click to open it.
  216.     *
  217.     * @param   object gtkclist 
  218.     * @param   object gdkevent 
  219.     *
  220.     */
  221.  
  222.     function onDirListClick($widget,$event{
  223.         if ($event->type != 5)  return;
  224.         $this->_DirSelectSetDir($this->entry->get_text());
  225.     }
  226.     /**
  227.     * Callback when the cancel/destroy window is pressed
  228.     *
  229.     * has to return TRUE (see the gtk tutorial on destroy events)
  230.     *
  231.     * 
  232.     */
  233.     function onCancel({
  234.         $this->window->hide();
  235.         return TRUE;
  236.     }
  237.     /**
  238.     * Callback when the OK btn is pressed
  239.     *
  240.     * hide window and update original widget.
  241.     *
  242.     */
  243.     
  244.     function onOk(
  245.         if (!$this->_DirSelectActiveWidgetreturn;
  246.         $new$this->entry->get_text();
  247.         $old$this->_DirSelectActiveWidget->get_text();
  248.         
  249.         if ($new != $old{
  250.             $this->_DirSelectActiveWidget->set_text($new);
  251.             $this->ui->_config->NewConfig[$this->_DirSelectActiveKey$new;
  252.             $this->ui->_config->ActivateConfigSave();
  253.         }
  254.         
  255.         $this->_DirSelectActiveWidget = NULL;
  256.         $this->window->hide();
  257.     }
  258. }
  259. ?>

Documentation generated on Mon, 11 Mar 2019 14:28:56 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.