[gnome-todo] task-list-view: Done button has maximum width



commit 4c94c2a8e8dd4d2085a6204adbd460b97a74eff7
Author: Yetizone <andreii lisita gmail com>
Date:   Mon Feb 5 19:03:41 2018 +0200

    task-list-view: Done button has maximum width
    
    This patch adds a maximum width to the Done button in
    the task list view.
    
    A subclass of the GtkButton is created. This class is
    named GtdDoneButton. In this class the get_preferred_width()
    method is overrided by gtd_row_get_preferred_width_with_max()
    from gtd-commons.
    
    The type of the Done button is changed in list-view.ui from
    GtkButton to GtdDoneButton and also the halign(center) property
    is added.

 data/ui/list-view.ui          |  3 ++-
 src/gtd-task-list-view.c      |  2 ++
 src/gtd-types.h               |  1 +
 src/meson.build               |  1 +
 src/widgets/gtd-done-button.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 src/widgets/gtd-done-button.h | 29 +++++++++++++++++++++++++++++
 6 files changed, 77 insertions(+), 1 deletion(-)
---
diff --git a/data/ui/list-view.ui b/data/ui/list-view.ui
index a38f742..7856045 100644
--- a/data/ui/list-view.ui
+++ b/data/ui/list-view.ui
@@ -106,13 +106,14 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkButton" id="done_button">
+                  <object class="GtdDoneButton" id="done_button">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">True</property>
                     <property name="tooltip_text" translatable="yes">Show or hide completed tasks</property>
                     <property name="border_width">12</property>
                     <property name="relief">none</property>
+                    <property name="halign">center</property>
                     <signal name="clicked" handler="gtd_task_list_view__done_button_clicked" 
object="GtdTaskListView" swapped="no" />
                     <child>
                       <object class="GtkBox" id="done_button_box">
diff --git a/src/gtd-task-list-view.c b/src/gtd-task-list-view.c
index 9103cb3..2bafaa2 100644
--- a/src/gtd-task-list-view.c
+++ b/src/gtd-task-list-view.c
@@ -19,6 +19,7 @@
 #define G_LOG_DOMAIN "GtdTaskListView"
 
 #include "gtd-dnd-row.h"
+#include "gtd-done-button.h"
 #include "gtd-edit-pane.h"
 #include "gtd-empty-list-widget.h"
 #include "gtd-task-list-view.h"
@@ -1523,6 +1524,7 @@ gtd_task_list_view_class_init (GtdTaskListViewClass *klass)
   g_type_ensure (GTD_TYPE_TASK_ROW);
   g_type_ensure (GTD_TYPE_DND_ROW);
   g_type_ensure (GTD_TYPE_EMPTY_LIST_WIDGET);
+  g_type_ensure (GTD_TYPE_DONE_BUTTON);
 
   /**
    * GtdTaskListView::color:
diff --git a/src/gtd-types.h b/src/gtd-types.h
index 3becbd5..d2caeeb 100644
--- a/src/gtd-types.h
+++ b/src/gtd-types.h
@@ -27,6 +27,7 @@ G_BEGIN_DECLS
 
 typedef struct _GtdActivatable          GtdActivatable;
 typedef struct _GtdApplication          GtdApplication;
+typedef struct _GtdDoneButton           GtdDoneButton;
 typedef struct _GtdInitialSetupWindow   GtdInitialSetupWindow;
 typedef struct _GtdListView             GtdListView;
 typedef struct _GtdManager              GtdManager;
diff --git a/src/meson.build b/src/meson.build
index 943dcb0..c46beaa 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -58,6 +58,7 @@ sources = files(
   'views/gtd-list-selector-list.c',
   'views/gtd-list-selector-list-item.c',
   'views/gtd-list-selector-panel.c',
+  'widgets/gtd-done-button.c',
   'widgets/gtd-expandable-entry.c',
   'gtd-application.c',
   'gtd-dnd-row.c',
diff --git a/src/widgets/gtd-done-button.c b/src/widgets/gtd-done-button.c
new file mode 100644
index 0000000..c6a86f8
--- /dev/null
+++ b/src/widgets/gtd-done-button.c
@@ -0,0 +1,42 @@
+/* gtd-done-button.c
+ *
+ * Copyright (C) 2018 Andrei Lisita <andreii lisita gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gtd-done-button.h"
+#include "gtd-rows-common-private.h"
+
+#include <gtk/gtk.h>
+
+struct _GtdDoneButton
+{
+  GtkButton           parent;
+};
+
+G_DEFINE_TYPE (GtdDoneButton, gtd_done_button, GTK_TYPE_BUTTON)
+
+static void
+gtd_done_button_class_init (GtdDoneButtonClass *klass)
+{
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+  widget_class->get_preferred_width = gtd_row_get_preferred_width_with_max;
+}
+
+static void
+gtd_done_button_init (GtdDoneButton *self)
+{
+}
diff --git a/src/widgets/gtd-done-button.h b/src/widgets/gtd-done-button.h
new file mode 100644
index 0000000..651c043
--- /dev/null
+++ b/src/widgets/gtd-done-button.h
@@ -0,0 +1,29 @@
+/* gtd-done-button.h
+ *
+ * Copyright (C) 2018 Andrei Lisita <andreii lisita gmail com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GTD_TYPE_DONE_BUTTON (gtd_done_button_get_type())
+
+G_DECLARE_FINAL_TYPE (GtdDoneButton, gtd_done_button, GTD, DONE_BUTTON, GtkButton)
+
+G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]