 |
| View previous topic :: View next topic |
| Author |
Message |
leon_pegg
Joined: 12 Jun 2006 Posts: 113 Location: hemel / UK
|
Posted: Thu Aug 31, 2006 2:01 pm Post subject: Dev Inspector Update |
|
|
I have made a mod to the dev inspector so that all signals of widgets are shown including inhereted ones
all you need to do is replace methods.php with this one
| Code: |
<?php
/**
* Method (constant/signal/...) list
*
* @author Christian Weiske <cweiske@cweiske.de>
*/
class Dev_Inspector_Methods extends GtkTreeView
{
protected $strClass = null;
protected $strTab = 'Methods';
protected $bToplevelOnly = false;
public function __construct($dispatcher)
{
$this->dispatcher = $dispatcher;
$modelInfo = new GtkListStore(Gtk::TYPE_STRING, Gtk::TYPE_STRING);
parent::__construct($modelInfo);
$cell_renderer = new GtkCellRendererText();
$this->append_column(new GtkTreeViewColumn('', $cell_renderer, 'markup', 0));
$this->get_column(0)->set_sort_column_id(1);
$this->set_search_column(1);
$this->get_model()->set_sort_column_id(1, Gtk::SORT_ASCENDING);
$this->set_headers_visible(false);
$this->drag_source_set(Gdk::BUTTON1_MASK, array(), Gdk::ACTION_COPY | Gdk::ACTION_MOVE);
$this->drag_source_add_text_targets();
$this->connect('drag-begin' , array($this, 'onDragBegin'));
$this->connect('drag-data-get', array($this, 'onGetDragData'));
$this->connect('button-release-event', array($this, 'onButtonRelease'));
}//public function __construct()
/**
* Returns the data at the end of a DnD operation
* that shall go into the target application.
*/
public function onGetDragData($widget, $context, $selection, $info, $time)
{
list($model, $iter) = $widget->get_selection()->get_selected();
if (!$iter) {
$context->drag_abort($time);
return;
}
$strMethod = $model->get_value($iter, 1);
$strClass = $this->getClass();
switch (strtolower($this->getTab())) {
case 'methods':
$rMethod = new ReflectionMethod($strClass, $strMethod);
$strPrefix = $rMethod->isStatic() ? $strClass . '::' : '';
if ($strMethod == '__construct' || $strMethod == $strClass) {
$strMethod = $strClass;
$strPrefix = 'new ';
}
$selection->set_text($strPrefix . $strMethod . '(' . self::getMethodParameterString($rMethod, false) . ')' . ";");
break;
case 'constants':
$selection->set_text($strClass . '::' . $strMethod);
break;
default:
$context->drag_abort($time);
break;
}
}//function onGetDragData($widget, $context, $selection, $info, $time)
/**
* When a drag begins, we want to set DnD icon to reflect
* the contents of the row being dragged.
*/
public function onDragBegin($widget, $context)
{
list($model, $iter) = $this->get_selection()->get_selected();
if (!$iter) {
return;
}
$this->drag_source_set_icon(
GdkColormap::get_system(),
//FIXME: create pixmap with contents that really will be dropped
$this->create_row_drag_icon(
$this->get_model()->get_path($iter)
)
);
}//public function onDragBegin($widget, $context)
/**
* What happens when a mouse button is released on
* the list?
* We show a popup context menu for custom methods.
*/
public function onButtonRelease($widget, $event)
{
if ($event->button == 3 && $this->getTab() == 'Methods' && $this->getClass() !== null) {
list($model, $iter) = $widget->get_selection()->get_selected();
if (!$iter) {
return;
}
$strMethod = $model->get_value($iter, 1);
$rMethod = new ReflectionMethod($this->getClass(), $strMethod);
if ($rMethod->isUserDefined()) {
$menu = new GtkMenu();
$menu->add(new GtkMenuItem(
$rMethod->getFileName()
. '#' . $rMethod->getStartLine()
. '-' . $rMethod->getEndLine()
));
$arComment = explode("\n", $rMethod->getDocComment());
foreach ($arComment as $n => $strLine) {
$arComment[$n] = str_replace('_', '__', trim($strLine));
}
$menu->add(new GtkMenuItem(implode("\n", $arComment)));
$menu->show_all();
$menu->popup();
}
}
}//public function onButtonRelease($widget, $event)
public function onSelectClass($strClass)
{
if ($strClass == $this->getClass()) {
return;
}
$this->setClass($strClass);
$this->loadList();
}//public function onSelectClass($strClass)
public function onSelectTab($strTab)
{
$this->setTab($strTab);
$this->loadList();
}//public function onSelectTab($strTab)
public function onSetToplevelOnly($bToplevelOnly)
{
$this->setToplevelOnly($bToplevelOnly);
$this->loadList();
}//public function onSetToplevelOnly($bToplevelOnly)
public static function getReflectionFunction($strTitle)
{
return 'get' . str_replace(' ', '', $strTitle);
}//protected static function getReflectionFunction($strTitle)
function getSignals($strClass){
$classes = $this->getParentClasses($strClass);
eval("\$gtype = $strClass::gtype;");
$return = @GObject::signal_list_names($gtype);
foreach ($classes as $class){
eval("\$gtype = $class::gtype;");
$arData = @GObject::signal_list_names($gtype);
$return = array_merge($return,$arData);
}
return $return;
}
/**
* Load the list data for the given class
*/
protected function loadList()
{
$class = $this->getClass();
if ($class === null) {
// echo "No class selected\n";
return;
}
$this->dispatcher->onBeginLongAction();
//gtknotebook is somehow buggy right now
$page_title = $this->getTab();
$model = $this->get_model();
$model->clear();
if ($page_title == 'Signals') {
//why can't I do "$classname::gtype"?
if (substr($class, 0, 3) == 'Gtk' && $class != 'Gtk') {
//eval("\$gtype = $class::gtype;");
//$arData = @GObject::signal_list_names($gtype);
$arData = $this->getSignals($class);
if (!is_array($arData)) {
$arData = array();
}
} else {
$arData = array();
}
} else {
$func = $this->getReflectionFunction($page_title);
$r = new ReflectionClass($class);
//fill the model
$arData = $r->$func();
}
switch (strtolower($this->getTab())) {
case 'methods':
$this->loadListMethods($arData);
break;
case 'properties':
$this->loadListObjects($arData);
break;
case 'constants':
$this->loadListConstants($arData);
break;
case 'signals':
$this->loadListSignals($arData);
break;
default:
$this->loadListNormal($arData);
break;
}
$this->dispatcher->onEndLongAction();
}//protected function loadList()
protected function loadListMethods($arData)
{
if ($this->getToplevelOnly()) {
//remove methods that are defined in parent classes
$strParentClass = get_parent_class($this->getClass());
if ($strParentClass !== false) {
$arParentMethods = get_class_methods($strParentClass);
foreach ($arData as $id => $data) {
if (in_array($data->name, $arParentMethods) && $data->name !== '__construct') {
unset($arData[$id]);
}
}
}
}
$model = $this->get_model();
foreach ($arData as $key => $data) {
$strParam = self::getMethodParameterString($data);
$strFileInfo = ' ' . $data->getFilename() . '#' . $data->getStartLine() . '-' . $data->getEndLine();
$strModifier = $data->isPublic() ? 'public ' : '';
$strModifier .= $data->isPrivate() ? 'private ' : '';
$strModifier .= $data->isProtected() ? 'protected ' : '';
$strModifier .= $data->isStatic() ? 'static ' : '';
$strModifier .= $data->isAbstract() ? 'abstract ' : '';
$strModifier .= $data->isFinal() ? 'final ' : '';
$strAppend = $data->isUserDefined() ? '*' : '';
$model->append(array(
'<span foreground="#00A">' . $strModifier . '</span>' . $data->name . '<span foreground="#F00">(</span>' . $strParam . '<span foreground="#F00">)</span>' . $strAppend,
$data->name
));
}
}//protected function loadListMethods($arData)
protected function loadListObjects($arData)
{
$model = $this->get_model();
foreach ($arData as $key => $data) {
$model->append(array(
$data->name,
$data->name
));
}
}//protected function loadListObjects($arData)
protected function loadListConstants($arData)
{
$model = $this->get_model();
foreach ($arData as $key => $data) {
$model->append(array(
$key . ' (' . $data . ')',
$key
));
}
}//protected function loadListConstants($arData)
protected function loadListSignals($arData)
{
$model = $this->get_model();
foreach ($arData as $key => $data) {
$model->append(array(
$data,
$data
));
}
}//protected function loadListSignals($arData)
protected function loadListNormal($arData)
{
$model = $this->get_model();
foreach ($arData as $key => $data) {
$model->append(array(
$key . ' (' . $data . ')',
$key
));
}
}//protected function loadListNormal($arData)
/**
* Creates and returns an array with parent classes to the given classname.
*
* @param string $strClass The class name
* @return array Array of strings with all the parent class names (class itself NOT)
*/
protected static function getParentClasses($strClass)
{
$arParentClasses = array();
while (($strClass = get_parent_class($strClass)) !== false) {
$arParentClasses[] = $strClass;
}
return $arParentClasses;
}//protected staticfunction getParentClasses($strClass)
protected static function getMethodParameterString($rMethod, $bPangoTags = true)
{
$strParam = '';
$nReqParameter = $rMethod->getNumberOfRequiredParameters();
if ($rMethod->getNumberOfParameters() > 0) {
$bOptional = false;
foreach ($rMethod->getParameters() as $id => $parameter) {
if ($id > 0) {
$strParam .= ', ';
}
if ($nReqParameter == $id) {
$bOptional = true;
$strParam .= '[';
}
try {
$class = $parameter->getClass();
} catch (ReflectionException $e) {
echo $e->getMessage() . "\r\n";
$class = null;
}
$strClass = '';
if ($class !== null) {
if ($bPangoTags) {
$strClass = '<span foreground="#00F">' . $class->getName() . '</span> ';
} else {
$strClass = $class->getName() . ' ';
}
}
if ($bPangoTags) {
$strParam .= $strClass . '<span foreground="#A00">' . $parameter->getName() . '</span>';
} else {
$strParam .= $strClass . '$' . $parameter->getName();
}
}
if ($bOptional) {
$strParam .= ']';
}
}
return $strParam;
}//protected static function getMethodParameterString($rMethod, $bPangoTags = true)
public function setClass($strClass)
{
$this->strClass = $strClass;
}//public function setClass($strClass)
public function getClass()
{
return $this->strClass;
}//public function getClass()
public function setTab($strTab)
{
$this->strTab = $strTab;
}//public function setTab($strClass)
public function getTab()
{
return $this->strTab;
}//public function getTab()
public function setToplevelOnly($bToplevelOnly)
{
$this->bToplevelOnly = $bToplevelOnly;
}//public function setToplevelOnly($bToplevelOnly)
public function getToplevelOnly()
{
return $this->bToplevelOnly;
}//public function getToplevelOnly()
}//class Dev_Inspector_Methods extends GtkTreeView
?>
|
hope someone finds this usefull |
|
| Back to top |
|
 |
cweiske
Joined: 08 Dec 2005 Posts: 454 Location: Leipzig/Germany
|
Posted: Thu Aug 31, 2006 3:10 pm Post subject: |
|
|
| leon, I released a new version that shows inherited signals. I modified the code a bit to show the parent signals only if the user wishes this by enabling the "o" button. |
|
| Back to top |
|
 |
leon_pegg
Joined: 12 Jun 2006 Posts: 113 Location: hemel / UK
|
Posted: Thu Aug 31, 2006 3:12 pm Post subject: |
|
|
| ok thanks just updated |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
 |