check_php_modules(); $this->prefs = &new phpmole_prefs; $this->prefs->load(APPDIR . "config/Preferences"); $this->prefs->load_user_prefs(); $class = "GladeXML"; if (substr(PHP_OS, 0, 3) == 'WIN') $class = "phpglade"; $this->glade = &new $class(APPDIR .'glade/phpide.glade'); $this->langs = &new phpide_languages(); $this->transports = &new phpide_transports(); $this->module_manager = &new phpide_modules(); /* standard dialogs */ $this->dialogs["ok"] = &new phpide_Dialog_Generic(dirname(__FILE__) ."/ok_dialog.glade"); $this->dialogs["ok_cancel"] = &new phpide_Dialog_Generic(dirname(__FILE__) ."/ok_cancel_dialog.glade"); $this->dialogs["yes_no"] = &new phpide_Dialog_Generic(dirname(__FILE__) ."/yes_no_dialog.glade"); $this->dialogs["password"] = &new phpmole_password_dialog(); $this->dialogs["new_file"] = &new phpmole_new_file_dialog(); $this->dialogs["config"] = &new phpmole_config_dialog(); $this->dialogs["about"] = &new phpmole_about_dialog(); // GLOBAL VARS $gx,$window,$nb,$bookmark_tree $this->window = $this->glade->get_widget("winMain"); //$this->window->connect('destroy', array(&$this,'quit')); $this->window->connect('delete-event', array(&$this,'quit')); $this->window->connect('configure_event', array(&$this,'callback_configure_event')); // glade bug hack $tb = $this->glade->get_widget("maintoolbar"); $tb->set_button_relief(GTK_RELIEF_NONE); // Window Resizing $w=600;$h=450; $x=0;$y=0; if ($this->prefs->get("geometry/save_win_size")) { $w = $this->prefs->get("geometry/width"); $h = $this->prefs->get("geometry/height"); $x = $this->prefs->get("geometry/position_x"); $y = $this->prefs->get("geometry/position_y"); } $this->window->set_default_size($w,$h); if ($x & $y) $this->window->set_uposition($x,$y); if (!$this->_error_message) $this->window->show(); // $this->window->connect("configure_event", array(&$this,"window_resized")); // hide show the buttons etc. $this->document_items_sensitive = 1; $this->bind_auto_text_items(); $this->disable_document_items(); $this->rebuild_recent(); // Which layout if (!$this->prefs->get("geometry/layout")) $this->prefs->set("geometry/layout","1"); $this->window->set_title( APPNAME ); $this->layout_holder = $this->glade->get_widget("layout_holder"); // Load the interface if (file_exists(APPDIR ."glade/interface_". $this->prefs->get("geometry/layout"). ".glade")) { $this->interface_glade = &new GladeXML(APPDIR ."glade/interface_". $this->prefs->get("geometry/layout"). ".glade"); } else { $this->interface_glade = &new GladeXML(APPDIR ."glade/interface_1.glade"); } $interface_window = $this->interface_glade->get_widget("window"); $this->interface = $this->interface_glade->get_widget("interface"); $interface_window->remove($this->interface); $this->layout_holder->add($this->interface); //$this->drag_window = &new GtkWindow(GTK_WINDOW_POPUP); $this->edit_pane = $this->interface_glade->get_widget("edit_pane"); $this->edit_pane_parent = $this->interface_glade->get_widget("edit_pane_parent"); $this->editor_frame_event = $this->interface_glade->get_widget("editor_frame_event"); $this->module_frame = $this->interface_glade->get_widget("module_frame"); $this->module_frame_event = $this->interface_glade->get_widget("module_frame_event"); $this->module_frame_event->connect("button_press_event", array(&$this,"free_module_frame")); $this->module_frame_visable = 1; if ($this->prefs->get("geometry/hide_module_frame")) { $this->hide_module_frame(); } else { $this->show_module_frame(); } if ($this->prefs->get("geometry/hide_tree_frame")) { $this->hide_tree_frame(); } else { $this->show_tree_frame(); } $this->module_manager->load(); $this->bind_actions(); //gtk::timeout_add(15000, 'dummy_timer'); Gtk::main(); } function bind_actions() { $menu_handlers = array( "on_winMain_draw", "on_new_bookmark_activate", // new Project "on_new_activate", "on_open_file_activate", "on_open_previous1_activate", "on_save_activate", "on_save_as_activate", "on_reload_activate", "on_close_activate", "on_close_all_activate", "on_undo", "on_redo", "on_cut", "on_copy", "on_paste", "on_select_all", "on_find_activate", "on_find_again_activate", "on_replace_activate", "on_configuration_activate", "on_scintilla_config", "on_language_settings_activate", "on_show_white_space_activate", "on_show_line_breaks_activate", "on_complete_word_activate", "on_help_php_gtk_activate", "on_help_php_activate", "on_help_gtk_activate", "on_phpmole_home_page_activate", "on_report_or_view_bugs_activate", "on_Run_clicked" ); $obj = array(&$this->module_manager,"menu_emit"); foreach($menu_handlers as $menu_handler) $this->glade->signal_connect_object( $menu_handler , $obj ,$menu_handler); /* locally handled */ foreach( array( "configuration", "view_module_frame", "view_tree_frame", "about", "goto_line_key_press", "find_box_key_press", "open_file", "open_newfile", "save_all" ) as $menu_handler) { $obj = array(&$this,$menu_handler."_activate"); $this->glade->signal_connect( "on_".$menu_handler."_activate",$obj ); } $obj = array(&$this,"quit"); $this->glade->signal_connect_object( "on_exit_activate", $obj); } /* AUTO TEXT */ function bind_auto_text_items() { if (!file_exists(APPDIR . "autotext")) return; $dh = opendir(APPDIR . "autotext"); while (($file = readdir($dh)) !== FALSE) { if ($file{0} == ".") continue; if (is_dir(APPDIR . "autotext/{$file}")) continue; $this->bind_auto_text($file); } } function bind_auto_text($filename) { $lines = file(APPDIR."autotext/$filename"); $label = trim($lines[0]); $base = $this->glade->get_widget("auto_text_menu"); $this->extra_document_items[$filename] = &new GtkMenuItem($label); $this->extra_document_items[$filename]->show(); $this->extra_document_items[$filename]->connect_object('activate', array(&$this,"add_auto_text"),$filename); $base->append($this->extra_document_items[$filename]); } function add_auto_text($filename) { // whats the active document? $lines = file(APPDIR."autotext/$filename"); $lines[0] = ''; $this->module_manager->send_to_editor('insert_text', implode('',$lines)); } function configuration_activate() { $this->dialogs["config"]->show(); } function load_document($bookmarkid, $URL,$force=NULL) { // ask the document manager to load the file //echo "\nCALLING LOAD $bookmarkid, $URL\n"; $this->add_to_recent($URL); $this->transports->load_document($bookmarkid, $URL,$force); $this->langs->load_document($bookmarkid, $URL); $this->window->set_title( APPNAME . " - " . $URL); //$this->langs->parse($bookmarkid, $URL); // then loop through the modules //echo "CHECKING FOR DATA?\n"; if (@$this->transports->documents[$URL]) $this->enable_document_items(); $this->module_manager->load_document($bookmarkid, $URL,$force); } function add_to_recent($URL) { $ar = $this->prefs->get_array("history/recent"); if (in_array($URL,$ar)) return; $ar[] = $URL; $this->prefs->set_array("history/recent",$ar); $remove_list = $this->prefs->prune_array( "history/recent", $this->prefs->get("history/mru_size")); foreach($remove_list as $rURL) if (@$this->recent_items[$rURL] && ($rURL != $URL)) { $this->recent_items[$rURL]->destroy(); unset($this->recent_items[$rURL]); } $this->prefs->save_user_prefs(); $this->add_recent_item($URL); } function add_recent_item($URL) { if (@$this->recent_items[$URL]) return; $base = $this->glade->get_widget("open_recent_menu"); $this->recent_items[$URL] = &new GtkMenuItem($URL); $this->recent_items[$URL]->show(); $this->recent_items[$URL]->connect_object('activate', array(&$this,"load_document"),-1,$URL); $base->append($this->recent_items[$URL]); } function rebuild_recent() { $ar = $this->prefs->get_array("history/recent"); foreach($ar as $k=>$URL) $this->add_recent_item($URL); } function save_document() { // ask the document manager to load the file // then loop through the modules //echo "ATTEMPTING TO SAVE"; $URLar = $this->module_manager->broadcast_get("get_active_document"); if (!$URLar) return; list($bookmarkid, $URL) = $URLar; $this->module_manager->broadcast("save_document",array($bookmarkid, $URL)); $this->transports->save_document($bookmarkid, $URL); $this->langs->parse($bookmarkid, $URL); $this->module_manager->broadcast("post_save_document",array($bookmarkid, $URL)); } function reload_document() { $URLar = $this->module_manager->get_active_document(); if (!$URLar) return; echo "RELOAD DOC " . serialize($URLar); list($bookmarkid, $URL) = $URLar; $this->load_document($bookmarkid, $URL,1); } function save_all_activate() { $ar = $this->module_manager->broadcast_get("get_all_documents"); for ($i=0;$i< count($ar); $i++) { list($bookmarkid,$URL) = $ar[$i]; echo "SAVING $bookmarkid,$URL\n"; $this->module_manager->broadcast("save_document",array($bookmarkid, $URL)); $this->transports->save_document($bookmarkid, $URL); $this->langs->parse($bookmarkid, $URL); $this->module_manager->broadcast("post_save_document",array($bookmarkid, $URL)); } } function dummy_timer () { // echo "AutoSave!??\n"; $dat = getrusage(); foreach ($dat as $k => $v) //echo "$k => $v \n"; //echo "\n\n"; return true; } /* Breaking and freeing of the module area - Note : this is not really how this should be done. the modular design is supposed to mean that you should not show/hide elements, but rather flip to another interface design- - this involves removing all the interface elements from the interface and reloading them into the new interface. */ function free_module_frame($widget,$event) { return; // not ready yet! $this->break_apart_edit_page(); $this->edit_pane_parent->add($this->editor_frame_event); $this->editor_frame_event->show(); $this->module_window = &new GtkWindow(GTK_WINDOW_DIALOG); $this->module_window->add($this->module_frame); $this->module_window->show(); $this->module_frame->show(); //$this->module_frame_event->add($this->module_frame); } function break_apart_edit_pane() { $this->editor_frame_event->hide(); $this->edit_pane->hide(); $this->edit_pane->remove($this->editor_frame_event); $this->edit_pane_parent->remove($this->edit_pane); $this->module_frame->hide(); $this->module_frame_event->hide(); $this->module_frame_event->remove($this->module_frame); } function rebuild_edit_pane() { $this->module_frame_event->add($this->module_frame); $this->module_frame_event->show(); $this->module_frame->show(); $this->edit_pane_parent->add($this->edit_pane); $this->edit_pane->add($this->editor_frame_event); $this->edit_pane->show(); $this->editor_frame_event->show(); } function hide_module_frame() { $this->toggle_active("btn_view_module_frame", FALSE); $this->toggle_active("menu_view_module_frame", FALSE); $this->prefs->set("geometry/hide_module_frame", 1); if (!$this->module_frame_visable) return; $this->module_frame_visable = 0; $this->break_apart_edit_pane(); $this->edit_pane_parent->add($this->editor_frame_event); $this->editor_frame_event->show(); //$this->module_frame->hide(); //$this->edit_pane->set_position( $this->window->allocation->height ); } function show_module_frame() { $this->toggle_active("btn_view_module_frame", TRUE); $this->toggle_active("menu_view_module_frame", TRUE); $this->prefs->set("geometry/hide_module_frame", 0); if ($this->module_frame_visable) return; $this->module_frame_visable = 1; $this->editor_frame_event->hide(); $this->edit_pane_parent->remove($this->editor_frame_event); $this->rebuild_edit_pane(); //echo "SHOW SETTING TO TRUE"; //$this->module_frame->show(); //$this->edit_pane->set_position( $this->window->allocation->height / 2 ); } function view_module_frame_activate($widget) { if (@$this->in_module_showhide) return; $this->in_module_showhide=1; $pref = (int) $this->prefs->get("geometry/hide_module_frame"); if (!$pref) { $this->hide_module_frame(); } else { $this->show_module_frame(); } $this->in_module_showhide=0; } function hide_tree_frame() { $this->toggle_active("btn_view_tree_frame",TRUE); $this->toggle_active("menu_view_tree_frame", TRUE); $w = $this->interface_glade->get_widget("interface"); $w->set_position( 200 ); } function show_tree_frame() { $this->toggle_active("btn_view_tree_frame", FALSE); $this->toggle_active("menu_view_tree_frame", FALSE); $w = $this->interface_glade->get_widget("interface"); $w->set_position( 0 ); } function toggle_active($widgetname, $value) { $w = $this->glade->get_widget($widgetname); if (!$w) return; //echo "SET: $widgetname $value"; $w->set_active($value); } function get_active($widgetname) { $w = $this->glade->get_widget($widgetname); if (!$w) return; //echo "SET: $widgetname $value"; return $w->active; } function view_tree_frame_activate($widget) { if (@$this->in_tree_showhide) return; $this->in_tree_showhide =1; $pref = (int) $this->prefs->get("geometry/hide_tree_frame"); $this->prefs->set("geometry/hide_tree_frame", !$pref); if (!$pref) { $this->hide_tree_frame(); } else { $this->show_tree_frame(); } $this->in_tree_showhide =0; } var $document_items = array( "save_as", "save_all", "close_all", "menu_close", "menu_undo", "menu_redo", "menu_cut", "menu_copy", "menu_paste", "menu_select_all", "menu_find", "menu_find_again", "menu_replace", "menu_find_again", "comment_code", "uncomment_code", "autocomplete", "show_white_space", "show_line_breaks", "show_folding", "change_language", "btnSave", "btnSaveAll", "btnClose", "btnReload", "btnUndo", "btnRedo", "btnRun", "btnRedo", "find_box", "btnSearch", "goto_line" //"btnRun", ); function disable_document_items() { if (!$this->document_items_sensitive) return; $this->document_items_sensitive = 0; $this->document_set_sensitive(FALSE); } function enable_document_items() { if ($this->document_items_sensitive) return; $this->document_items_sensitive = 1; $this->document_set_sensitive(TRUE); } var $extra_document_items = array(); // associative array of extra widgets that are frozen when no document is open function document_set_sensitive($value) { foreach($this->document_items as $widgetname) { $w = $this->glade->get_widget($widgetname); $w->set_sensitive($value); } foreach($this->extra_document_items as $widgetname=>$w) $w->set_sensitive($value); } function about_activate() { $this->dialogs["about"]->show(); } /* *--------------------------------------------------- * CALLBACKS *--------------------------------------------------- */ function goto_line_key_press_activate($widget,$event) { if($event->keyval==GDK_KEY_Return) $this->module_manager->broadcast("goto_line",$widget->get_text()); } function find_box_key_press_activate($widget,$event) { if($event->keyval==GDK_KEY_Return) $this->module_manager->broadcast("search_ok_pressed",$widget->get_text()); } function open_newfile_activate($widget) { $this->open_file_activate(NULL, "Create A New File"); } function open_file_activate($widget,$title = "Open File") { $dialog = &new GtkFileSelection($title); if ($path = getenv("HOME")) $dialog->set_filename($path."/"); $ok = $dialog->ok_button; $ok->connect("pressed", array(&$this, "open_file_ok_pressed"), $dialog); $cancel = $dialog->cancel_button; $cancel->connect_object("pressed", array(&$dialog, "destroy")); $dialog->show(); } function open_file_ok_pressed($widget,&$window) { $f = $window->get_filename(); $window->destroy(); if (!$f || (substr($f, -1) == "/")) { $this->dialogs["ok"]->show("Invalid file specified: $f"); return; } $url = "file:$f"; $bm = $this->module_manager->broadcast("get_bookmark_from_url", $url); $this->load_document($bm, $url); } function quit() { if ( $this->prefs->get( "geometry/save_win_size" ) ) { $this->prefs->set( "geometry/width", $this->window->allocation->width ); $this->prefs->set( "geometry/height", $this->window->allocation->height ); $this->prefs->set( "geometry/position_x",$this->window->window->x); $this->prefs->set( "geometry/position_y", $this->window->window->y ); } $this->prefs->save_user_prefs(); gtk::main_quit(); echo "QUIT"; exit; } function callback_configure_event($window) { $w = $window->window; list($pixmap,$mask) = Gdk::pixmap_create_from_xpm($w, NULL, dirname(__FILE__).'/phpmole.xpm'); $w->set_icon($w, $pixmap,$mask); } /* *--------------------------------------------------- * Check modules have loaded *--------------------------------------------------- */ function check_php_modules() { $modules = array( "dba" => array("dba_open", "the DBA extension is recommend for the help system, as it is faster than parsing the xml files"), "xml" => array("xml_parser_create", "XML extension is used in the help browser to read dev help xml files if you do not have the dba module"), "imagick" => array("imagick_create", "The Image Magick extension is used to resize images for thumbnails etc. more information is available is available on the pear website (PECL) http://pear.php.net/manual/en/pecl.imagick.php"), "pcntl" => array("pcntl_fork", "The pcntl extension is used by the 'run button' to start fork processes in the background"), "sockets" => array("socket_connect", "The socket extension is used to connect to the debuggers"), "curl" => array("curl_close", "The curl extension is used by the help viewer and the midgard backend"), "imap" => array("imap_open", "The imap extension is used by the experimental imap transport (for reading emails), dont worry about it, unless you plan hacking phpmoles imap transport"), "mysql" => array("mysql_connect", "The mysql extension is used by the experimental database transport (although it should support any database as it uses PEAR:DB)"), ); $gtk_modules = array( "gladexml" =>"Glade is required, you may have installed php-gtk incorrectly", "gtkscintilla" =>"Scintilla extension is required, compile php-gtk with --enable-scintilla", "gtkhtml" => "The help viewer and WYSIWYG html editor will not work as you do not have the gtkhtml widget, compile php-gtk with --enable-gtkhtml", "gdkpixbuf" =>"The pixbuf module is used by the image browser and the midgard image details tab." ); $this->_error_message = ""; foreach($modules as $module=>$ar) { /* hammer and nail method of finding modules !*/ if (!function_exists($ar[0])) @dl("{$module}.so"); if (!function_exists($ar[0])) @dl("php_{$module}.dll"); if (!function_exists($ar[0])) @dl("{$module}.dll"); if (!function_exists($ar[0])) @dl("php_{$module}.so"); if (!function_exists($ar[0])) $this->_error_message .= "\nFailed to find PHP extension $module\n{$ar[1]}\n"; } foreach($gtk_modules as $module=>$desc) if (!class_exists($module)) $this->_error_message .= "\nFailed to find PHP-GTK extension $module\n$desc\n"; if (!$this->_error_message) return; $this->_warning = &new GtkWindow(); $this->_warning->set_usize(400,400); $ok = &new GtkButton("OK"); $text = &new GtkText(); $vbox = &new Gtkvbox(); $this->_warning->add( $vbox ); $vbox->pack_start( $text, TRUE, TRUE, 4); $vbox->pack_start( $ok, FALSE, FALSE , 0); $text->insert_text("Warning PHP Extensions Missing\n\n".$this->_error_message,0); $this->_warning->show_all(); $ok->connect_object('clicked',array(&$this,'hide_warning')); } function hide_warning() { $this->_warning->hide(); $this->window->show(); } } ?>