module object var $close_all_flag=0; // flag set for close all function phpide_modules () { global $application; $dh = opendir(dirname(__FILE__)); while (($file = readdir($dh)) != NULL) { if ($file[0] == ".") continue; if (!is_dir(dirname(__FILE__) . "/". $file)) continue; if (!file_exists(dirname(__FILE__) . "/$file/module_$file.class")) continue; //echo "Checking module view/$file"; if ($application->prefs->get("module hide/".$file)) continue; //echo "LOADING\n"; $this->modules[] = $file; include(dirname(__FILE__) . "/$file/module_$file.class"); $classname = "module_$file"; //echo "\nsetting mod objects $file to $classname\n"; if (!class_exists($classname)) continue; //debug_echo("creating module $file"); $this->module_objects[$file] = &new $classname(); //echo serialize($this->module_objects[$file]); } } // alot of these should be replace with call_user_method_array or something! function load() { global $application; $spare = $application->interface_glade->get_widget("holder_spare_modules"); //echo "MODULE LOADER:" .serialize($spare); foreach($this->modules as $module) { //echo "LOADING $module\n"; if ($widget = $application->interface_glade->get_widget("holder_".$module)) { if (@$this->module_objects[$module]->widget) $widget->add($this->module_objects[$module]->widget); } elseif ($spare) { if (@$this->module_objects[$module]->widget) { //echo "ATTEMPT TO ADD PAGE"; $label = &new GtkLabel($module); $label->show(); $spare->append_page($this->module_objects[$module]->widget, $label); } } } if ($spare) $spare->set_page(0); } function load_document($bookmarkid, $URL) { // STAGE 1 PRELOAD // normally create widgets etc. $this->broadcast("pre_load_document",array($bookmarkid, $URL)); $this->broadcast("load_document",array($bookmarkid, $URL)); // STAGE 3 POSTLOAD // ensures that editors are loaded into holders! foreach ($this->modules as $module) { if (!@$this->module_objects[$module]) continue; if (!@$this->module_objects[$module]->editor_holders[$URL]) continue; foreach($this->module_objects[$module]->editor_holders[$URL] as $editorname => $notebook) { if ($this->module_objects[$module]->editor_holders[$URL][$editorname]->children()) continue; if (!@$this->module_objects[$editorname]->documents[$URL]) continue; $this->module_objects[$module]->editor_holders[$URL][$editorname]->add( $this->module_objects[$editorname]->documents[$URL]); } } $this->broadcast("post_load_document",array($bookmarkid, $URL)); } function pre_close_document() { global $application; if ($URLarray = $this->broadcast_get("get_active_document")) { if ($this->broadcast_get("get_modify", array($URLarray[0],$URLarray[1]))) { $this->close_option_dialog($URLarray[0],$URLarray[1]); } else { $this->broadcast("close_document",array($URLarray[0],$URLarray[1])); $application->transports->close_document($URLarray[0],$URLarray[1]); $this->broadcast("post_close_document",array($URLarray[0],$URLarray[1])); if ($this->close_all_flag) $this->pre_close_document(); } } else { echo "NO MORE DOCUMENTS"; $this->close_all_flag=0; } } function close_option_dialog($bookmarkid, $URL) { global $application; //echo "CB: CLOSE DIALOG"; $application->dialogs["yes_no"]->set_callbacks( array(&$this,"callback_save_and_close_document"), array(&$this,"callback_force_close_document") ); $application->dialogs["yes_no"]->show( $URL . "\n has changed, \nDo you want to save it?"); } function callback_save_and_close_document() { global $application; //echo "CB: SAVE CLOSE"; $URLarray = $this->broadcast_get("get_active_document"); if (!$URLarray) return; list($bookmarkid,$URL) = $URLarray ; $this->broadcast("save_document",array($bookmarkid,$URL)); $application->transports->save_document($bookmarkid,$URL); $this->broadcast("post_save_document",array($bookmarkid,$URL)); $this->broadcast("close_document",array($bookmarkid,$URL)); $application->transports->close_document($bookmarkid,$URL); while (gtk::events_pending()) gtk::main_iteration(); if ($this->close_all_flag) $this->pre_close_document(); } function callback_force_close_document() { global $application; //echo "CB: FORCE CLOSE"; $URLarray = $this->broadcast_get("get_active_document"); if (!$URLarray) return; list($bookmarkid,$URL) = $URLarray ; $this->broadcast("close_document",array($bookmarkid,$URL)); $application->transports->close_document($bookmarkid,$URL); while (gtk::events_pending()) gtk::main_iteration(); if ($this->close_all_flag) $this->pre_close_document(); } // special - really usefull methods function get_active_document() { return $this->send_module('notebook_editor','get_active_document'); } function get_active_editor() { return $this->send_module('notebook_editor','get_active_editor'); } // saves currently edited data to transports // New master funtcions ! function send_to_editor($method,$args=array()) { $item = $this->get_active_document(); $item[2] = &$args; $module = $this->get_active_editor(); echo serialize($module); return $this->send_module($module,$method,$item); } function broadcast($method,$args=NULL) { foreach ($this->modules as $module) { if (!isset($this->module_objects[$module])) continue; if (method_exists($this->module_objects[$module],$method)) { echo("CALLING $module $method\n"); call_user_func_array(array(&$this->module_objects[$module],$method),$args); } } } function broadcast_get($method,$args=NULL) { foreach ($this->modules as $module) { if (!isset($this->module_objects[$module])) continue; if (method_exists($this->module_objects[$module],$method)) { $ret = call_user_func_array(array(&$this->module_objects[$module],$method) ,$args); if ($ret) return $ret; } } } function send_module($module,$method,$args=array()) { echo ("SEND MODULE : $module, $method ". serialize($args)); if (!$module) return; if (!isset($this->module_objects[$module])) return; if (method_exists($this->module_objects[$module],$method)) { $ret = call_user_func_array(array(&$this->module_objects[$module],$method) ,$args); if ($ret) return $ret; } } function get_editor_modules() { $ret = array(); foreach ($this->modules as $module) { //echo "CHECKING EDITOR IN $module\n"; if (!isset($this->module_objects[$module])) continue; //echo "SET"; if ($this->module_objects[$module]->is_editor) { $ret[$this->module_objects[$module]->is_editor] = $module; //echo "STORING"; } } ksort($ret); //echo "EDITORS: " . serialize($ret); return $ret; } function menu_emit($signal) { global $application; //if (is_object($signal)) $signal = $vars; //echo "MM: MENU EMIT $module : $signal\n"; foreach ($this->modules as $module) { if (!isset($this->module_objects[$module])) continue; if (method_exists($this->module_objects[$module],"menu_emit")) { $this->module_objects[$module]->menu_emit($signal); } } //echo "module: menu emit $signal"; switch ($signal) { case "on_save_activate": $application->save_document(); return; case "on_close_activate": $this->pre_close_document(); break; case "on_close_all_activate": $this->close_all_flag=1; $this->pre_close_document(); break; case "on_language_settings_activate": $application->langs->language_config_dialog->show_dialog(); return; } } } ?>