Browse Source

Configured entryListView

newfile
Markus Koch 5 years ago
parent
commit
02ac6dc595
  1. 35
      glade/mainWindow.glade
  2. 68
      src/mainwindow.c
  3. 2
      src/mainwindow.h

35
glade/mainWindow.glade

@ -4,15 +4,13 @@
<requires lib="gtk+" version="3.20"/>
<object class="GtkListStore" id="entryListStore">
<columns>
<!-- column-name test1 -->
<column type="test"/>
<!-- column-name vfg1 -->
<column type="vfg"/>
<!-- column-name Title -->
<column type="gchararray"/>
<!-- column-name Date -->
<column type="gchararray"/>
<!-- column-name Tags -->
<column type="gchararray"/>
</columns>
<data>
<row/>
<row/>
</data>
</object>
<object class="GtkTextBuffer" id="entryTextBuffer">
<property name="text" translatable="yes">Test text for debugging.</property>
@ -122,23 +120,32 @@
<property name="orientation">vertical</property>
<property name="wide_handle">True</property>
<child>
<object class="GtkTreeView" id="entryListView">
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">entryListStore</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="entryListSelection"/>
<property name="shadow_type">in</property>
<property name="propagate_natural_height">True</property>
<child>
<object class="GtkTreeView" id="entryListView">
<property name="height_request">300</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">entryListStore</property>
<child internal-child="selection">
<object class="GtkTreeSelection" id="entryListSelection"/>
</child>
</object>
</child>
</object>
<packing>
<property name="resize">False</property>
<property name="resize">True</property>
<property name="shrink">True</property>
</packing>
</child>
<child>
<object class="GtkTextView" id="entryText">
<property name="width_request">640</property>
<property name="height_request">480</property>
<property name="height_request">320</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">False</property>

68
src/mainwindow.c

@ -1,5 +1,69 @@
#include "mainwindow.h"
enum {
COL_TITLE = 0,
COL_DATE,
COL_TAGS,
COL_COUNT
};
static void mainWindow_test_treeView(struct mainWindow *mainWindow)
{
GtkCellRenderer *renderer;
GtkTreeIter iter;
GtkTreeSortable *sortable;
GtkTreeViewColumn *col;
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes(mainWindow->entryListView, -1, "Title", renderer,
"text", COL_TITLE, NULL);
col = gtk_tree_view_get_column(mainWindow->entryListView, COL_TITLE);
gtk_tree_view_column_set_resizable(col, 1);
gtk_tree_view_column_set_sort_column_id(col, COL_TITLE);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes(mainWindow->entryListView, -1, "Date", renderer,
"text", COL_DATE, NULL);
col = gtk_tree_view_get_column(mainWindow->entryListView, COL_DATE);
gtk_tree_view_column_set_resizable(col, 1);
gtk_tree_view_column_set_sort_column_id(col, COL_DATE);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes(mainWindow->entryListView, -1, "Tags", renderer,
"text", COL_TAGS, NULL);
col = gtk_tree_view_get_column(mainWindow->entryListView, COL_TAGS);
gtk_tree_view_column_set_resizable(col, 1);
gtk_tree_view_column_set_sort_column_id(col, COL_TAGS);
/*gtk_tree_sortable_set_sort_func(sortable, COL_DATE, mainWindow_sort_date_compare_func,
GINT_TO_POINTER(COL_DATE), NULL);*/
/*
* Code just for debugging - some test values
*/
gtk_list_store_append(mainWindow->entryListStore, &iter);
gtk_list_store_set (mainWindow->entryListStore, &iter,
COL_TITLE, "ZA Test entry longer title",
COL_DATE, "2016-05-12",
COL_TAGS, "X",
-1);
gtk_list_store_append(mainWindow->entryListStore, &iter);
gtk_list_store_set (mainWindow->entryListStore, &iter,
COL_TITLE, "baz",
COL_DATE, "2016-11-22",
COL_TAGS, "A",
-1);
gtk_list_store_append(mainWindow->entryListStore, &iter);
gtk_list_store_set (mainWindow->entryListStore, &iter,
COL_TITLE, "Foo",
COL_DATE, "1998-12-03",
COL_TAGS, "F",
-1);
sortable = GTK_TREE_SORTABLE(mainWindow->entryListStore);
gtk_tree_sortable_set_sort_column_id(sortable, COL_DATE, GTK_SORT_DESCENDING);
}
struct mainWindow *mainWindow_new()
{
GtkBuilder *builder;
@ -14,10 +78,14 @@ struct mainWindow *mainWindow_new()
mainWindow->dateStart = GTK_WIDGET(gtk_builder_get_object(builder, "dateStart"));
mainWindow->dateEnd = GTK_WIDGET(gtk_builder_get_object(builder, "dateEnd"));
mainWindow->entryText = GTK_WIDGET(gtk_builder_get_object(builder, "entryText"));
mainWindow->entryListView = GTK_TREE_VIEW(gtk_builder_get_object(builder, "entryListView"));
mainWindow->entryListStore = GTK_LIST_STORE(gtk_builder_get_object(builder, "entryListStore"));
gtk_builder_connect_signals(builder, NULL);
g_object_unref(G_OBJECT(builder));
mainWindow_test_treeView(mainWindow);
return mainWindow;
}

2
src/mainwindow.h

@ -11,6 +11,8 @@ struct mainWindow {
GtkWidget *dateStart;
GtkWidget *dateEnd;
GtkWidget *entryText;
GtkTreeView *entryListView;
GtkListStore *entryListStore;
};
struct mainWindow *mainWindow_new();

Loading…
Cancel
Save