Skip to content

Commit

Permalink
ADDED sorting of entity-list by path and file name
Browse files Browse the repository at this point in the history
ADDED some code for a entity filter dialog. Very much work in progress.
  • Loading branch information
ksterker committed Jun 1, 2011
1 parent fe9d0aa commit cea9a6e
Show file tree
Hide file tree
Showing 7 changed files with 536 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/mapedit/Makefile.am
@@ -1,17 +1,20 @@
## Process this file with automake to produce Makefile.in

EXTRA_DIST = \
entity-filter.glade \
entity-properties.glade \
grid-properties.glade \
zone-properties.glade

noinst_PROGRAMS = mapedit

noinst_HEADERS = \
entity-filter.glade.h \
entity-properties.glade.h \
grid-properties.glade.h \
gui_entity_dialog.h \
gui_entity_list.h \
gui_filter_dialog.h \
gui_grid.h \
gui_grid_dialog.h \
gui_mapedit.h \
Expand All @@ -33,6 +36,7 @@ noinst_HEADERS = \
mapedit_SOURCES = \
gui_entity_dialog.cc \
gui_entity_list.cc \
gui_filter_dialog.cc \
gui_grid.cc \
gui_grid_dialog.cc \
gui_mapedit.cc \
Expand All @@ -51,6 +55,7 @@ mapedit_SOURCES = \
map_renderer.cc

# just for the dependency
gui_filter_dialog.cc : entity-filter.glade.h
gui_entity_dialog.cc : entity-properties.glade.h
gui_grid_dialog.cc : grid-properties.glade.h
gui_zone_dialog.cc : zone-properties.glade.h
Expand Down
193 changes: 193 additions & 0 deletions src/mapedit/entity-filter.glade
@@ -0,0 +1,193 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkDialog" id="filter-dialog">
<property name="width_request">320</property>
<property name="height_request">600</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Entity Filter</property>
<property name="default_width">320</property>
<property name="default_height">796</property>
<property name="type_hint">utility</property>
<property name="skip_taskbar_hint">True</property>
<property name="skip_pager_hint">True</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkRadioButton" id="rb_filter_off">
<property name="label" translatable="yes">Show All</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="yalign">0.44999998807907104</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area1">
<property name="height_request">0</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">start</property>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="rb_filter_tag">
<property name="label" translatable="yes">Show Tagged</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<property name="group">rb_filter_off</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="left_padding">20</property>
<child>
<object class="GtkScrolledWindow" id="scrolledwindow1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">never</property>
<property name="vscrollbar_policy">automatic</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="filter_view">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">filter_model</property>
<property name="enable_search">False</property>
<property name="fixed_height_mode">True</property>
<property name="show_expanders">False</property>
<child>
<object class="GtkTreeViewColumn" id="filter_column">
<property name="sizing">fixed</property>
<property name="fixed_width">32</property>
<child>
<object class="GtkCellRendererToggle" id="filter_renderer">
<property name="width">32</property>
</object>
<attributes>
<attribute name="active">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="tag_column">
<property name="sizing">fixed</property>
<property name="title" translatable="yes">Tag</property>
<property name="expand">True</property>
<property name="clickable">True</property>
<property name="sort_column_id">1</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext1"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="column_count">
<property name="sizing">fixed</property>
<property name="fixed_width">64</property>
<property name="title" translatable="yes">Count</property>
<property name="clickable">True</property>
<property name="sort_indicator">True</property>
<property name="sort_order">descending</property>
<property name="sort_column_id">2</property>
<child>
<object class="GtkCellRendererText" id="cellrenderertext2">
<property name="width">64</property>
<property name="xalign">1</property>
<property name="alignment">right</property>
</object>
<attributes>
<attribute name="text">2</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkRadioButton" id="rb_filter_matching">
<property name="label" translatable="yes">Show Matching </property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_action_appearance">False</property>
<property name="relief">none</property>
<property name="active">True</property>
<property name="draw_indicator">True</property>
<property name="group">rb_filter_off</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkListStore" id="filter_model">
<columns>
<!-- column-name filter -->
<column type="gboolean"/>
<!-- column-name tag -->
<column type="gchararray"/>
<!-- column-name count -->
<column type="guint"/>
</columns>
<data>
<row>
<col id="0">True</col>
<col id="1" translatable="yes">Test</col>
<col id="2">45</col>
</row>
</data>
</object>
</interface>
35 changes: 35 additions & 0 deletions src/mapedit/gui_entity_list.cc
Expand Up @@ -39,6 +39,7 @@
#include "gui_mapview.h"
#include "gui_entity_list.h"
#include "gui_entity_dialog.h"
#include "gui_filter_dialog.h"

enum
{
Expand Down Expand Up @@ -229,6 +230,24 @@ static void on_refresh_entities (GtkButton * button, gpointer user_data)
list->refresh();
}

// callback for adding new zones
static void on_filter_entities (GtkButton * button, gpointer user_data)
{
GuiFilterDialog *dlg = new GuiFilterDialog (GuiFilterDialog::getFilterModel());
dlg->run();
}

// sort model list by model path and file name
static gint sort_by_path (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer userdata)
{
// get object at selected row
MapEntity *obj_a = (MapEntity*) entity_list_get_object (ENTITY_LIST (model), a);
MapEntity *obj_b = (MapEntity*) entity_list_get_object (ENTITY_LIST (model), b);

// compare the two
return strcmp (obj_a->object()->modelfile().c_str(), obj_b->object()->modelfile().c_str());
}

// ctor
GuiEntityList::GuiEntityList ()
{
Expand All @@ -247,8 +266,14 @@ GuiEntityList::GuiEntityList ()
gtk_widget_set_tooltip_text (GTK_WIDGET(btnRefresh), "Reload list of available entities from file system.");
g_signal_connect (G_OBJECT(btnRefresh), "clicked", G_CALLBACK(on_refresh_entities), this);

GtkWidget *btnFilter = gtk_button_new ();
gtk_button_set_image (GTK_BUTTON(btnFilter), gtk_image_new_from_stock (GTK_STOCK_FIND, GTK_ICON_SIZE_BUTTON));
gtk_widget_set_tooltip_text (GTK_WIDGET(btnFilter), "Filter list of available entities.");
g_signal_connect (G_OBJECT(btnFilter), "clicked", G_CALLBACK(on_filter_entities), this);

GtkWidget *btnPnl = gtk_hbutton_box_new();
gtk_button_box_set_layout (GTK_BUTTON_BOX(btnPnl), GTK_BUTTONBOX_END);
gtk_box_pack_start (GTK_BOX(btnPnl), btnFilter, FALSE, FALSE, 4);
gtk_box_pack_start (GTK_BOX(btnPnl), btnRefresh, FALSE, FALSE, 4);

gtk_box_pack_start (GTK_BOX(Panel), scrollWnd, TRUE, TRUE, 0);
Expand All @@ -269,6 +294,10 @@ GuiEntityList::GuiEntityList ()
// create the (empty) model
GtkListStore *model = (GtkListStore *) g_object_new (TYPE_ENTITY_LIST, NULL);
gtk_tree_view_set_model (TreeView, (GtkTreeModel*) model);

// set custom sorting by path name
gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(model), sort_by_path, NULL, NULL);
gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(model), GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
}

// return mapedit wrapper around given entity
Expand Down Expand Up @@ -387,6 +416,9 @@ void GuiEntityList::setMap (MapData * map)
// create meta data object
MapEntity *obj = new MapEntity (*e, map->getEntityCount (*e));

// update tags of new entity
obj->update_tags();

// get new row
gtk_list_store_append (model, &iter);

Expand Down Expand Up @@ -467,6 +499,9 @@ void GuiEntityList::scanDir (const std::string & datadir, GtkListStore *model)
// create meta data object
MapEntity *ety = new MapEntity (obj);

// update tags of new entity
ety->update_tags();

// get new row
gtk_list_store_append (model, &iter);

Expand Down

0 comments on commit cea9a6e

Please sign in to comment.