Simplify adding tabs to the interface

This commit is contained in:
Timothy Warren 2012-04-04 16:28:18 -04:00
parent c4c4ab3950
commit fb72bd2b14

View File

@ -85,63 +85,17 @@ class DB_tabs extends GTKNotebook {
// 'Databases' Tab // 'Databases' Tab
{ {
$dbs = new Data_Grid(); self::_add_tab($conn, 'Databases', 'Db Name', 'get_dbs');
$db_model = $dbs->get_model();
$db_data = $conn->get_dbs();
if($db_data !== FALSE)
{
foreach($db_data as $d)
{
$db_model->append(null, array($d));
}
$cell_renderer = new GtkCellRendererText();
$dbs->insert_column_with_data_func(0, 'DB Name', $cell_renderer, array(self::$instance, 'add_data_col'));
self::$instance->add_tab('Databases', $dbs);
}
} }
// 'Tables' Tab // 'Tables' Tab
{ {
$tables = new Data_Grid(); self::_add_tab($conn, 'Tables', 'Table Name', 'get_tables');
$table_model = $tables->get_model();
$table_data = $conn->get_tables();
foreach($table_data as $t)
{
$table_model->append(null, array($t));
}
$cell_renderer = new GtkCellRendererText();
$tables->insert_column_with_data_func(0, 'Table Name', $cell_renderer, array(self::$instance, 'add_data_col'));
self::$instance->add_tab('Tables', $tables);
} }
// 'Views' Tab // 'Views' Tab
{ {
$views = new Data_grid(); self::_add_tab($conn, 'Views', 'View Name', 'get_views');
$view_model = $views->get_model();
$view_data = $conn->get_views();
if ($view_data !== FALSE)
{
foreach($view_data as $v)
{
$view_model->append(null, array($v));
}
$cell_renderer = new GtkCellRendererText();
$views->insert_column_with_data_func(0, 'View Name', $cell_renderer, array(self::$instance, 'add_data_col'));
self::$instance->add_tab('Views', $views);
}
} }
@ -170,8 +124,6 @@ class DB_tabs extends GTKNotebook {
return; return;
} }
print_r($data);
$col->set_visible(TRUE); $col->set_visible(TRUE);
$cell->set_property('text', $data); $cell->set_property('text', $data);
} }
@ -188,5 +140,38 @@ class DB_tabs extends GTKNotebook {
self::$instance->remove_page($i); self::$instance->remove_page($i);
} }
} }
// --------------------------------------------------------------------------
/**
* Simplify adding tabs to the Notebook object
*
* @param object $conn
* @param string $tab_name
* @param string $col_name
* @param string $method
* @return void
*/
private static function _add_tab(&$conn, $tab_name, $col_name, $method)
{
$tab = new Data_Grid();
$tab_model = $tab->get_model();
$tab_data = call_user_func_array(array($conn, $method), array());
if($tab_data !== FALSE)
{
foreach($tab_data as $d)
{
$tab_model->append(null, array($d));
}
$cell_renderer = new GtkCellRendererText();
$tab->insert_column_with_data_func(0, $col_name, $cell_renderer, array(self::$instance, 'add_data_col'));
self::$instance->add_tab($tab_name, $tab);
}
}
} }
// End of db_tabs.php // End of db_tabs.php