From 0b18f99a02787d4c191bc5ffc8f18d771c1e8343 Mon Sep 17 00:00:00 2001 From: aljelly Date: Fri, 16 Mar 2018 22:56:31 +0000 Subject: [PATCH 01/11] Failed attempt to add css file --- CMakeLists.txt | 4 +- cmake/gresource.cmake | 94 ++++++++++++++++++++++++++------------- data/assets.gresource.xml | 6 +++ data/stylesheet.css | 3 ++ src/Widgets/Window.vala | 4 ++ 5 files changed, 79 insertions(+), 32 deletions(-) create mode 100644 data/assets.gresource.xml create mode 100644 data/stylesheet.css diff --git a/CMakeLists.txt b/CMakeLists.txt index 97d8d10a..8c1e0675 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,8 +139,10 @@ OPTIONS ${GLOBAL_VALAC_OPTIONS} ) -add_executable(com.github.philip-scott.notes-up ${VALA_C} ${generated_resources}) +include (gresource) +glib_compile_resources(GLIB_RESOURCES_ICONS SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/data/assets.gresource.xml) +add_executable(com.github.philip-scott.notes-up ${VALA_C} ${GLIB_RESOURCES_ICONS}) install(TARGETS com.github.philip-scott.notes-up RUNTIME DESTINATION bin) diff --git a/cmake/gresource.cmake b/cmake/gresource.cmake index fd9c76b8..1f47b059 100644 --- a/cmake/gresource.cmake +++ b/cmake/gresource.cmake @@ -1,37 +1,69 @@ -# Used for GResource. # -# resource_dir: Directory where the .gresource.xml is located. -# resource_file: Filename of the .gresource.xml file (just the -# filename, not the complete path). -# output_dir: Directory where the C output file is written. -# output_file: This variable will be set with the complete path of the -# output C file. +# Copyright (C) 2013 Venom authors and contributors +# +# This file is part of Venom. +# +# Venom 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. +# +# Venom 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 Venom. If not, see . +# + +FIND_PROGRAM(GLIB_COMPILE_RESOURCES_EXECUTABLE NAMES glib-compile-resources) +MARK_AS_ADVANCED(GLIB_COMPILE_RESOURCES_EXECUTABLE) + +INCLUDE(CMakeParseArguments) -function (gresource resource_dir resource_file output_dir output_file) - # Get the output file path - get_filename_component (resource_name ${resource_file} NAME_WE) - set (output "${output_dir}/${resource_name}-resources.c") - set (${output_file} ${output} PARENT_SCOPE) +FUNCTION(GLIB_COMPILE_RESOURCES output) + CMAKE_PARSE_ARGUMENTS(ARGS "" "" "SOURCE" ${ARGN}) + SET(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + SET(out_files "") - # Get the dependencies of the gresource - execute_process ( - OUTPUT_VARIABLE _files - WORKING_DIRECTORY ${resource_dir} - COMMAND ${gresources_executable} --generate-dependencies ${resource_file} - ) + FOREACH(src ${ARGS_SOURCE} ${ARGS_UNPARSED_ARGUMENTS}) + SET(in_file "${CMAKE_CURRENT_SOURCE_DIR}/${src}") + GET_FILENAME_COMPONENT(WORKING_DIR ${in_file} PATH) + STRING(REPLACE ".xml" ".c" src ${src}) + SET(out_file "${DIRECTORY}/${src}") + GET_FILENAME_COMPONENT(OUPUT_DIR ${out_file} PATH) + FILE(MAKE_DIRECTORY ${OUPUT_DIR}) + LIST(APPEND out_files "${DIRECTORY}/${src}") - string (REPLACE "\n" ";" files ${_files}) + #FIXME implicit depends currently not working + EXECUTE_PROCESS( + COMMAND + ${GLIB_COMPILE_RESOURCES_EXECUTABLE} + "--generate-dependencies" + ${in_file} + WORKING_DIRECTORY ${WORKING_DIR} + OUTPUT_VARIABLE in_file_dep + ) + STRING(REGEX REPLACE "(\r?\n)" ";" in_file_dep "${in_file_dep}") + SET(in_file_dep_path "") + FOREACH(dep ${in_file_dep}) + LIST(APPEND in_file_dep_path "${WORKING_DIR}/${dep}") + ENDFOREACH(dep ${in_file_dep}) + ADD_CUSTOM_COMMAND( + OUTPUT ${out_file} + WORKING_DIRECTORY ${WORKING_DIR} + COMMAND + ${GLIB_COMPILE_RESOURCES_EXECUTABLE} + ARGS + "--generate-source" + "--target=${out_file}" + ${in_file} + DEPENDS + ${in_file};${in_file_dep_path} + ) + ENDFOREACH(src ${ARGS_SOURCES} ${ARGS_UNPARSED_ARGUMENTS}) + SET(${output} ${out_files} PARENT_SCOPE) +ENDFUNCTION(GLIB_COMPILE_RESOURCES) - set (depends "") - foreach (cur_file ${files}) - list (APPEND depends "${resource_dir}/${cur_file}") - endforeach () - # Command to compile the resources - add_custom_command ( - OUTPUT ${output} - DEPENDS "${resource_dir}/${resource_file}" ${depends} - WORKING_DIRECTORY ${resource_dir} - COMMAND ${gresources_executable} --generate-source --target=${output} ${resource_file} - ) -endfunction () diff --git a/data/assets.gresource.xml b/data/assets.gresource.xml new file mode 100644 index 00000000..9a7ebba2 --- /dev/null +++ b/data/assets.gresource.xml @@ -0,0 +1,6 @@ + + + + stylesheet.css + + diff --git a/data/stylesheet.css b/data/stylesheet.css new file mode 100644 index 00000000..cd802cb4 --- /dev/null +++ b/data/stylesheet.css @@ -0,0 +1,3 @@ +.title-label { + font-size:1em; +} diff --git a/src/Widgets/Window.vala b/src/Widgets/Window.vala index d12bbf2a..87ef7140 100644 --- a/src/Widgets/Window.vala +++ b/src/Widgets/Window.vala @@ -41,6 +41,10 @@ public class ENotes.Window : Gtk.ApplicationWindow { } private void build_ui () { + + var provider = new Gtk.CssProvider (); +provider.load_from_resource ("/com/github/philip-scott/notes-up/stylesheet.css"); + headerbar = ENotes.Headerbar.get_instance (); set_titlebar (headerbar); From 1f13008622e0707fc32c0d015406e573d8fba79d Mon Sep 17 00:00:00 2001 From: aljelly Date: Sat, 17 Mar 2018 04:16:41 +0000 Subject: [PATCH 02/11] Show date/time on note, sort by modified, format time based on system time format --- CMakeLists.txt | 1 + src/Application.vala | 5 +++++ src/Services/ClockSettings.vala | 22 ++++++++++++++++++++++ src/Services/Page.vala | 14 ++++++++------ src/Widgets/PageItem.vala | 25 +++++++++++++++++++++++++ src/Widgets/PagesList.vala | 8 ++++++-- 6 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 src/Services/ClockSettings.vala diff --git a/CMakeLists.txt b/CMakeLists.txt index 97d8d10a..d7945231 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,6 +116,7 @@ vala_precompile(VALA_C src/Styles/modest.vala src/Services/Bookmark.vala + src/Services/ClockSettings.vala src/Services/FileManager.vala src/Services/Notebook.vala src/Services/Image.vala diff --git a/src/Application.vala b/src/Application.vala index 9f3a03f4..7d93808b 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -54,6 +54,8 @@ public enum ENotes.Key { namespace ENotes { public ENotes.Services.Settings settings; public ENotes.Window window; + public ClockSettings clockSettings; + public bool use24HSFormat = false; public string NOTES_DB; public string NOTES_DIR; } @@ -87,6 +89,9 @@ public class ENotes.Application : Granite.Application { public override void activate () { if (!running) { settings = ENotes.Services.Settings.get_instance (); + + clockSettings = new ClockSettings (); + use24HSFormat = (clockSettings.clock_format == "24h"); if (settings.notes_database == "") { // Init databases var notes_dir = GLib.Environment.get_home_dir () + "/.local/share/notes-up/"; diff --git a/src/Services/ClockSettings.vala b/src/Services/ClockSettings.vala new file mode 100644 index 00000000..c2263abc --- /dev/null +++ b/src/Services/ClockSettings.vala @@ -0,0 +1,22 @@ +/*** + BEGIN LICENSE + Copyright (C) 2016 elementary LLC. + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License version 3, as published + by the Free Software Foundation. + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranties of + MERCHANTABILITY, SATISFACTORY QUALITY, 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 + END LICENSE +***/ +public class ClockSettings : Granite.Services.Settings { + + public string clock_format { get; set; } + + public ClockSettings () { + base ("org.gnome.desktop.interface"); + } +} diff --git a/src/Services/Page.vala b/src/Services/Page.vala index 18730726..122ee46d 100644 --- a/src/Services/Page.vala +++ b/src/Services/Page.vala @@ -161,19 +161,19 @@ public class ENotes.PageTable : DatabaseTable { } public Page new_page (int64 notebook_id) { - var stmt = create_stmt ("INSERT INTO Page (notebook_id, name, creation_date, modification_date) " + var stmt = create_stmt ("INSERT INTO Page (notebook_id, name, creation_date, modification_date) " + "VALUES (?, ?, CAST(strftime('%s', 'now') AS INT), CAST(strftime('%s', 'now') AS INT))"); - bind_int (stmt, 1, notebook_id); - bind_text (stmt, 2, _("New Page")); + bind_int (stmt, 1, notebook_id); + bind_text (stmt, 2, _("New Page")); - stmt.step (); + stmt.step (); - return get_page (last_insert_row ()); + return get_page (last_insert_row ()); } public Gee.ArrayList get_pages (int64 notebook_id) { - var stmt = create_stmt ("SELECT id, name, subtitle, data FROM Page Where notebook_id = ?"); + var stmt = create_stmt ("SELECT id, name, subtitle, data, creation_date, modification_date FROM Page Where notebook_id = ?"); bind_int (stmt, 1, notebook_id); var pages = new Gee.ArrayList(); @@ -193,6 +193,8 @@ public class ENotes.PageTable : DatabaseTable { row.name = stmt.column_text (1); row.subtitle = stmt.column_text (2); row.data = stmt.column_text (3); + row.creation_date = stmt.column_int64 (4); + row.modification_date = stmt.column_int64 (5); pages.add (row); } diff --git a/src/Widgets/PageItem.vala b/src/Widgets/PageItem.vala index 9ba19fd9..8c0ea1c7 100644 --- a/src/Widgets/PageItem.vala +++ b/src/Widgets/PageItem.vala @@ -25,6 +25,9 @@ public class ENotes.PageItem : Gtk.ListBoxRow { private Gtk.Grid grid; private Gtk.Label line1; private Gtk.Label line2; + private Gtk.Label line3; + private DateTime time; + private string date_string; public PageItem (ENotes.Page page) { this.page = page; @@ -60,12 +63,25 @@ public class ENotes.PageItem : Gtk.ListBoxRow { line2.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); line2.lines = 3; + line3 = new Gtk.Label (""); + line3.halign = Gtk.Align.START; + line3.margin_left = 8; + line3.margin_right = 8; + line3.margin_bottom = 4; + line3.use_markup = true; + line3.set_line_wrap (true); + line3.ellipsize = Pango.EllipsizeMode.END; + ((Gtk.Misc) line3).xalign = 0; + line3.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); + line3.lines = 3; + var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL); separator.hexpand = true; this.add (grid); grid.add (line1); grid.add (line2); + grid.add (line3); grid.add (separator); load_data (); @@ -77,6 +93,15 @@ public class ENotes.PageItem : Gtk.ListBoxRow { } public void load_data () { + time = new DateTime.from_unix_utc (page.modification_date); + + if (use24HSFormat) { + date_string = time.format ("%H:%M, %a, %e %b %Y"); + } else { + date_string = time.format ("%l:%M %p, %a, %e %b %Y"); + } + date_string = date_string.chug (); + this.line3.label = date_string; this.line2.label = page.subtitle; this.line1.label = "" + page.name + ""; } diff --git a/src/Widgets/PagesList.vala b/src/Widgets/PagesList.vala index 2f78c7d4..83e511d7 100644 --- a/src/Widgets/PagesList.vala +++ b/src/Widgets/PagesList.vala @@ -76,13 +76,16 @@ public class ENotes.PagesList : Gtk.Box { }); listbox.set_sort_func ((row1, row2) => { - int64 a = ((PageItem) row1).page.id; - int64 b = ((PageItem) row2).page.id; + int64 a = ((PageItem) row1).page.modification_date; + int64 b = ((PageItem) row2).page.modification_date; if (a > b) return -1; if (b > a) return 1; return 0; + + // For sorting strings + // return a.collate (b); }); scroll_box.set_size_request (200,250); @@ -291,6 +294,7 @@ public class ENotes.PagesList : Gtk.Box { var page_item = added_pages.get ((int) page.id); page_item.page = page; page_item.load_data (); + listbox.invalidate_sort (); } }); } From 187f5962cdb173da54ca24ad2989923e519d54b1 Mon Sep 17 00:00:00 2001 From: aljelly Date: Sat, 17 Mar 2018 04:42:06 +0000 Subject: [PATCH 03/11] Remove whitespace --- src/Widgets/PagesList.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Widgets/PagesList.vala b/src/Widgets/PagesList.vala index 83e511d7..ced20b32 100644 --- a/src/Widgets/PagesList.vala +++ b/src/Widgets/PagesList.vala @@ -294,7 +294,7 @@ public class ENotes.PagesList : Gtk.Box { var page_item = added_pages.get ((int) page.id); page_item.page = page; page_item.load_data (); - listbox.invalidate_sort (); + listbox.invalidate_sort (); } }); } From 0900b83d6cf39445cee96e1b6d043a543935cbce Mon Sep 17 00:00:00 2001 From: aljelly Date: Sat, 17 Mar 2018 06:14:22 +0000 Subject: [PATCH 04/11] Fix addition of css file, modify app styling, change editor font size --- CMakeLists.txt | 2 +- data/stylesheet.css | 14 +++++++++++++- schemas/org.notes.gschema.xml | 2 +- src/Widgets/PageItem.vala | 30 ++++++++++++++++-------------- src/Widgets/Window.vala | 3 ++- 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e8b9c96..79c7b3aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -141,7 +141,7 @@ OPTIONS ) include (gresource) -glib_compile_resources(GLIB_RESOURCES_ICONS SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/data/assets.gresource.xml) +glib_compile_resources(GLIB_RESOURCES_ICONS SOURCE /data/assets.gresource.xml) add_executable(com.github.philip-scott.notes-up ${VALA_C} ${GLIB_RESOURCES_ICONS}) diff --git a/data/stylesheet.css b/data/stylesheet.css index cd802cb4..c1885428 100644 --- a/data/stylesheet.css +++ b/data/stylesheet.css @@ -1,3 +1,15 @@ .title-label { - font-size:1em; + /* font-size: 1.15em; + font-size: 15px; */ + font-size: 1.2em; + font-weight: 700; +} + +.preview-label { + opacity:1; +} + +.date-time-label { + opacity:0.6; + font-size:0.9em; } diff --git a/schemas/org.notes.gschema.xml b/schemas/org.notes.gschema.xml index 4584ece7..d874b047 100644 --- a/schemas/org.notes.gschema.xml +++ b/schemas/org.notes.gschema.xml @@ -91,7 +91,7 @@ - "Open Sans 12" + "Open Sans 10" Editor font The editor's font family and size diff --git a/src/Widgets/PageItem.vala b/src/Widgets/PageItem.vala index 8c0ea1c7..03d677ba 100644 --- a/src/Widgets/PageItem.vala +++ b/src/Widgets/PageItem.vala @@ -37,43 +37,45 @@ public class ENotes.PageItem : Gtk.ListBoxRow { private void build_ui () { set_activatable (true); + var margin_horizontal = 10; + grid = new Gtk.Grid (); grid.orientation = Gtk.Orientation.VERTICAL; line1 = new Gtk.Label (""); line1.use_markup = true; line1.halign = Gtk.Align.START; - line1.get_style_context ().add_class ("h3"); + line1.get_style_context ().add_class ("title-label"); line1.ellipsize = Pango.EllipsizeMode.END; ((Gtk.Misc) line1).xalign = 0; - line1.margin_top = 4; - line1.margin_left = 8; - line1.margin_right = 8; + line1.margin_top = 10; + line1.margin_left = margin_horizontal; + line1.margin_right = margin_horizontal; line1.margin_bottom = 4; line2 = new Gtk.Label (""); line2.halign = Gtk.Align.START; - line2.margin_left = 8; - line2.margin_right = 8; + line2.margin_left = margin_horizontal; + line2.margin_right = margin_horizontal; line2.margin_bottom = 4; line2.use_markup = true; line2.set_line_wrap (true); line2.ellipsize = Pango.EllipsizeMode.END; ((Gtk.Misc) line2).xalign = 0; - line2.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); - line2.lines = 3; + line2.get_style_context ().add_class ("preview-label"); + line2.lines = 1; line3 = new Gtk.Label (""); line3.halign = Gtk.Align.START; - line3.margin_left = 8; - line3.margin_right = 8; - line3.margin_bottom = 4; + line3.margin_left = margin_horizontal; + line3.margin_right = margin_horizontal; + line3.margin_bottom = 10; line3.use_markup = true; line3.set_line_wrap (true); line3.ellipsize = Pango.EllipsizeMode.END; ((Gtk.Misc) line3).xalign = 0; - line3.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); - line3.lines = 3; + line3.get_style_context ().add_class ("date-time-label"); + line3.lines = 1; var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL); separator.hexpand = true; @@ -103,7 +105,7 @@ public class ENotes.PageItem : Gtk.ListBoxRow { date_string = date_string.chug (); this.line3.label = date_string; this.line2.label = page.subtitle; - this.line1.label = "" + page.name + ""; + this.line1.label = page.name; } } diff --git a/src/Widgets/Window.vala b/src/Widgets/Window.vala index 87ef7140..3a6daec4 100644 --- a/src/Widgets/Window.vala +++ b/src/Widgets/Window.vala @@ -43,7 +43,8 @@ public class ENotes.Window : Gtk.ApplicationWindow { private void build_ui () { var provider = new Gtk.CssProvider (); -provider.load_from_resource ("/com/github/philip-scott/notes-up/stylesheet.css"); + provider.load_from_resource ("/com/github/philip-scott/notes-up/stylesheet.css"); + Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); headerbar = ENotes.Headerbar.get_instance (); set_titlebar (headerbar); From cd1fd53437b44fd144dfd436320fe36d28417bdf Mon Sep 17 00:00:00 2001 From: aljelly Date: Sat, 17 Mar 2018 07:06:19 +0000 Subject: [PATCH 05/11] Remove unnecessary use_markup on date label --- src/Widgets/PageItem.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Widgets/PageItem.vala b/src/Widgets/PageItem.vala index 8c0ea1c7..50ee0296 100644 --- a/src/Widgets/PageItem.vala +++ b/src/Widgets/PageItem.vala @@ -68,7 +68,6 @@ public class ENotes.PageItem : Gtk.ListBoxRow { line3.margin_left = 8; line3.margin_right = 8; line3.margin_bottom = 4; - line3.use_markup = true; line3.set_line_wrap (true); line3.ellipsize = Pango.EllipsizeMode.END; ((Gtk.Misc) line3).xalign = 0; From 0ceffaaf9827e00aad00aeef1477bf94f1b867e5 Mon Sep 17 00:00:00 2001 From: aljelly Date: Sun, 18 Mar 2018 19:04:06 +0000 Subject: [PATCH 06/11] PageList: Removed commented code, restored sorting to original state --- src/Widgets/PagesList.vala | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Widgets/PagesList.vala b/src/Widgets/PagesList.vala index ced20b32..d65cb3d0 100644 --- a/src/Widgets/PagesList.vala +++ b/src/Widgets/PagesList.vala @@ -83,9 +83,6 @@ public class ENotes.PagesList : Gtk.Box { if (b > a) return 1; return 0; - - // For sorting strings - // return a.collate (b); }); scroll_box.set_size_request (200,250); @@ -294,7 +291,6 @@ public class ENotes.PagesList : Gtk.Box { var page_item = added_pages.get ((int) page.id); page_item.page = page; page_item.load_data (); - listbox.invalidate_sort (); } }); } From f1144c5ef065a59765e2f8a8f88b16f46ce729e6 Mon Sep 17 00:00:00 2001 From: aljelly Date: Sun, 18 Mar 2018 19:29:14 +0000 Subject: [PATCH 07/11] PageItem: Change labels to be more descriptive, change date formatting and made translatable --- src/Widgets/PageItem.vala | 92 +++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/src/Widgets/PageItem.vala b/src/Widgets/PageItem.vala index 50ee0296..586f9544 100644 --- a/src/Widgets/PageItem.vala +++ b/src/Widgets/PageItem.vala @@ -23,11 +23,11 @@ public class ENotes.PageItem : Gtk.ListBoxRow { public ENotes.Page page; private Gtk.Grid grid; - private Gtk.Label line1; - private Gtk.Label line2; - private Gtk.Label line3; + private Gtk.Label name_label; + private Gtk.Label preview_label; + private Gtk.Label date_label; private DateTime time; - private string date_string; + private string date_formatted; public PageItem (ENotes.Page page) { this.page = page; @@ -40,47 +40,47 @@ public class ENotes.PageItem : Gtk.ListBoxRow { grid = new Gtk.Grid (); grid.orientation = Gtk.Orientation.VERTICAL; - line1 = new Gtk.Label (""); - line1.use_markup = true; - line1.halign = Gtk.Align.START; - line1.get_style_context ().add_class ("h3"); - line1.ellipsize = Pango.EllipsizeMode.END; - ((Gtk.Misc) line1).xalign = 0; - line1.margin_top = 4; - line1.margin_left = 8; - line1.margin_right = 8; - line1.margin_bottom = 4; - - line2 = new Gtk.Label (""); - line2.halign = Gtk.Align.START; - line2.margin_left = 8; - line2.margin_right = 8; - line2.margin_bottom = 4; - line2.use_markup = true; - line2.set_line_wrap (true); - line2.ellipsize = Pango.EllipsizeMode.END; - ((Gtk.Misc) line2).xalign = 0; - line2.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); - line2.lines = 3; - - line3 = new Gtk.Label (""); - line3.halign = Gtk.Align.START; - line3.margin_left = 8; - line3.margin_right = 8; - line3.margin_bottom = 4; - line3.set_line_wrap (true); - line3.ellipsize = Pango.EllipsizeMode.END; - ((Gtk.Misc) line3).xalign = 0; - line3.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); - line3.lines = 3; + name_label = new Gtk.Label (""); + name_label.use_markup = true; + name_label.halign = Gtk.Align.START; + name_label.get_style_context ().add_class ("h3"); + name_label.ellipsize = Pango.EllipsizeMode.END; + ((Gtk.Misc) name_label).xalign = 0; + name_label.margin_top = 4; + name_label.margin_left = 8; + name_label.margin_right = 8; + name_label.margin_bottom = 4; + + preview_label = new Gtk.Label (""); + preview_label.halign = Gtk.Align.START; + preview_label.margin_left = 8; + preview_label.margin_right = 8; + preview_label.margin_bottom = 4; + preview_label.use_markup = true; + preview_label.set_line_wrap (true); + preview_label.ellipsize = Pango.EllipsizeMode.END; + ((Gtk.Misc) preview_label).xalign = 0; + preview_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); + preview_label.lines = 3; + + date_label = new Gtk.Label (""); + date_label.halign = Gtk.Align.START; + date_label.margin_left = 8; + date_label.margin_right = 8; + date_label.margin_bottom = 4; + date_label.set_line_wrap (true); + date_label.ellipsize = Pango.EllipsizeMode.END; + ((Gtk.Misc) date_label).xalign = 0; + date_label.get_style_context ().add_class (Gtk.STYLE_CLASS_DIM_LABEL); + date_label.lines = 3; var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL); separator.hexpand = true; this.add (grid); - grid.add (line1); - grid.add (line2); - grid.add (line3); + grid.add (name_label); + grid.add (preview_label); + grid.add (date_label); grid.add (separator); load_data (); @@ -95,14 +95,14 @@ public class ENotes.PageItem : Gtk.ListBoxRow { time = new DateTime.from_unix_utc (page.modification_date); if (use24HSFormat) { - date_string = time.format ("%H:%M, %a, %e %b %Y"); + date_formatted = time.format (_("%a, %e %b %y, %H:%M")).strip (); } else { - date_string = time.format ("%l:%M %p, %a, %e %b %Y"); + date_formatted = time.format (_("%a, %e %b %y, %l:%M %p")) .strip (); } - date_string = date_string.chug (); - this.line3.label = date_string; - this.line2.label = page.subtitle; - this.line1.label = "" + page.name + ""; + + this.date_label.label = date_formatted; + this.preview_label.label = page.subtitle; + this.name_label.label = "" + page.name + ""; } } From e58e5a309d9fdbe08d4839541090bcb767de938f Mon Sep 17 00:00:00 2001 From: aljelly Date: Sun, 18 Mar 2018 21:50:14 +0000 Subject: [PATCH 08/11] Remove ClockSettings, read clock format with GLib.Settings instead (not currently working) --- CMakeLists.txt | 1 - src/Application.vala | 19 ++++++++++++++----- src/Services/ClockSettings.vala | 22 ---------------------- src/Widgets/PageItem.vala | 11 ++++++----- 4 files changed, 20 insertions(+), 33 deletions(-) delete mode 100644 src/Services/ClockSettings.vala diff --git a/CMakeLists.txt b/CMakeLists.txt index 5cfa19e4..2252ce7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -117,7 +117,6 @@ vala_precompile(VALA_C src/Styles/modest.vala src/Services/Bookmark.vala - src/Services/ClockSettings.vala src/Services/FileManager.vala src/Services/Notebook.vala src/Services/Image.vala diff --git a/src/Application.vala b/src/Application.vala index 7d93808b..06cf3677 100644 --- a/src/Application.vala +++ b/src/Application.vala @@ -54,8 +54,6 @@ public enum ENotes.Key { namespace ENotes { public ENotes.Services.Settings settings; public ENotes.Window window; - public ClockSettings clockSettings; - public bool use24HSFormat = false; public string NOTES_DB; public string NOTES_DIR; } @@ -64,6 +62,8 @@ public class ENotes.Application : Granite.Application { public const string PROGRAM_NAME = N_("Notes-Up"); public const string COMMENT = N_("Your Markdown Notebook."); public const string ABOUT_STOCK = N_("About Notes"); + private Settings interface_settings; + public string clock_format { get; set; } public bool running = false; @@ -89,9 +89,18 @@ public class ENotes.Application : Granite.Application { public override void activate () { if (!running) { settings = ENotes.Services.Settings.get_instance (); - - clockSettings = new ClockSettings (); - use24HSFormat = (clockSettings.clock_format == "24h"); + + var interface_settings_schema = SettingsSchemaSource.get_default ().lookup ("org.gnome.desktop.interface", true); + if (interface_settings_schema == null || !interface_settings_schema.has_key ("clock_format")) { + info ("No clock settings schema found, using 12 hours as a fallback"); + } else { + interface_settings = new GLib.Settings ("org.gnome.desktop.interface"); + interface_settings.bind ("clock_format", this, "clock_format", GLib.SettingsBindFlags.GET); + + // I'm not sure how to actually get access to the above or if I'm even doing it right + + info (clock_format); + } if (settings.notes_database == "") { // Init databases var notes_dir = GLib.Environment.get_home_dir () + "/.local/share/notes-up/"; diff --git a/src/Services/ClockSettings.vala b/src/Services/ClockSettings.vala deleted file mode 100644 index c2263abc..00000000 --- a/src/Services/ClockSettings.vala +++ /dev/null @@ -1,22 +0,0 @@ -/*** - BEGIN LICENSE - Copyright (C) 2016 elementary LLC. - This program is free software: you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License version 3, as published - by the Free Software Foundation. - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranties of - MERCHANTABILITY, SATISFACTORY QUALITY, 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 - END LICENSE -***/ -public class ClockSettings : Granite.Services.Settings { - - public string clock_format { get; set; } - - public ClockSettings () { - base ("org.gnome.desktop.interface"); - } -} diff --git a/src/Widgets/PageItem.vala b/src/Widgets/PageItem.vala index 586f9544..8f53dafb 100644 --- a/src/Widgets/PageItem.vala +++ b/src/Widgets/PageItem.vala @@ -94,12 +94,13 @@ public class ENotes.PageItem : Gtk.ListBoxRow { public void load_data () { time = new DateTime.from_unix_utc (page.modification_date); - if (use24HSFormat) { - date_formatted = time.format (_("%a, %e %b %y, %H:%M")).strip (); - } else { - date_formatted = time.format (_("%a, %e %b %y, %l:%M %p")) .strip (); - } + //if (ENotes.Application.clock_format == "24h") { + // date_formatted = time.format (_("%a, %e %b %y, %H:%M")).strip (); + //} else { + // date_formatted = time.format (_("%a, %e %b %y, %l:%M %p")).strip (); + //} + date_formatted = "placeholder"; this.date_label.label = date_formatted; this.preview_label.label = page.subtitle; this.name_label.label = "" + page.name + ""; From 33d07e502d9faf35c94fb2e8771cb6114141cbe9 Mon Sep 17 00:00:00 2001 From: aljelly Date: Sun, 18 Mar 2018 21:58:33 +0000 Subject: [PATCH 09/11] Forgot to change page.modification_date back to page.id --- src/Widgets/PagesList.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Widgets/PagesList.vala b/src/Widgets/PagesList.vala index d65cb3d0..2f78c7d4 100644 --- a/src/Widgets/PagesList.vala +++ b/src/Widgets/PagesList.vala @@ -76,8 +76,8 @@ public class ENotes.PagesList : Gtk.Box { }); listbox.set_sort_func ((row1, row2) => { - int64 a = ((PageItem) row1).page.modification_date; - int64 b = ((PageItem) row2).page.modification_date; + int64 a = ((PageItem) row1).page.id; + int64 b = ((PageItem) row2).page.id; if (a > b) return -1; if (b > a) return 1; From fc27fbac7aefdd2b8df92f75ddbbdb02ba6deed3 Mon Sep 17 00:00:00 2001 From: aljelly Date: Sun, 18 Mar 2018 23:09:59 +0000 Subject: [PATCH 10/11] Order the label setting alphabetically, change label margins, set horizontal margins to 12 --- src/Widgets/PageItem.vala | 45 ++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/Widgets/PageItem.vala b/src/Widgets/PageItem.vala index c34e7ca0..abc4d513 100644 --- a/src/Widgets/PageItem.vala +++ b/src/Widgets/PageItem.vala @@ -28,6 +28,7 @@ public class ENotes.PageItem : Gtk.ListBoxRow { private Gtk.Label date_label; private DateTime time; private string date_formatted; + private const int HORIZONTAL_MARGIN = 12; public PageItem (ENotes.Page page) { this.page = page; @@ -37,44 +38,44 @@ public class ENotes.PageItem : Gtk.ListBoxRow { private void build_ui () { set_activatable (true); - var margin_horizontal = 10; - grid = new Gtk.Grid (); grid.orientation = Gtk.Orientation.VERTICAL; name_label = new Gtk.Label (""); - name_label.use_markup = true; - name_label.halign = Gtk.Align.START; - name_label.get_style_context ().add_class ("title-label"); name_label.ellipsize = Pango.EllipsizeMode.END; + name_label.get_style_context ().add_class ("title-label"); + name_label.halign = Gtk.Align.START; + name_label.margin_left = HORIZONTAL_MARGIN; + name_label.margin_right = HORIZONTAL_MARGIN; + name_label.margin_top = 8; + name_label.margin_bottom = 0; // Because the gap between name_label and the below is otherwise uneven compared to the gap between the preview_label and the labe, due to the smaller font-size of the date_label + name_label.use_markup = true; ((Gtk.Misc) name_label).xalign = 0; - name_label.margin_top = 10; - name_label.margin_left = margin_horizontal; - name_label.margin_right = margin_horizontal; - name_label.margin_bottom = 4; preview_label = new Gtk.Label (""); + preview_label.ellipsize = Pango.EllipsizeMode.END; + preview_label.get_style_context ().add_class ("preview-label"); preview_label.halign = Gtk.Align.START; - preview_label.margin_left = margin_horizontal; - preview_label.margin_right = margin_horizontal; - preview_label.margin_bottom = 4; - preview_label.use_markup = true; + preview_label.lines = 2; + preview_label.margin_left = HORIZONTAL_MARGIN; + preview_label.margin_right = HORIZONTAL_MARGIN; + preview_label.margin_top = 3; + preview_label.margin_bottom = 2; preview_label.set_line_wrap (true); - preview_label.ellipsize = Pango.EllipsizeMode.END; + preview_label.use_markup = true; ((Gtk.Misc) preview_label).xalign = 0; - preview_label.get_style_context ().add_class ("preview-label"); - preview_label.lines = 1; date_label = new Gtk.Label (""); + date_label.ellipsize = Pango.EllipsizeMode.END; + date_label.get_style_context ().add_class ("date-time-label"); date_label.halign = Gtk.Align.START; - date_label.margin_left = margin_horizontal; - date_label.margin_right = margin_horizontal; + date_label.lines = 1; + date_label.margin_left = HORIZONTAL_MARGIN; + date_label.margin_right = HORIZONTAL_MARGIN; + date_label.margin_top = 3; date_label.margin_bottom = 10; date_label.set_line_wrap (true); - date_label.ellipsize = Pango.EllipsizeMode.END; ((Gtk.Misc) date_label).xalign = 0; - date_label.get_style_context ().add_class ("date-time-label"); - date_label.lines = 1; var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL); separator.hexpand = true; @@ -101,7 +102,7 @@ public class ENotes.PageItem : Gtk.ListBoxRow { // date_formatted = time.format (_("%a, %e %b %y, %l:%M %p")).strip (); //} - date_formatted = "placeholder"; + date_formatted = "Sat, 18 Mar 2018, 10:40 PM"; this.date_label.label = date_formatted; this.preview_label.label = page.subtitle; this.name_label.label = page.name; From 21029fdc7b1d883156d7a0b2f2a448064fb67c8d Mon Sep 17 00:00:00 2001 From: aljelly Date: Sun, 18 Mar 2018 23:10:56 +0000 Subject: [PATCH 11/11] Remove commented code from stylesheet.css --- data/stylesheet.css | 2 -- 1 file changed, 2 deletions(-) diff --git a/data/stylesheet.css b/data/stylesheet.css index c1885428..911ac7a9 100644 --- a/data/stylesheet.css +++ b/data/stylesheet.css @@ -1,6 +1,4 @@ .title-label { - /* font-size: 1.15em; - font-size: 15px; */ font-size: 1.2em; font-weight: 700; }