Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Relies on #263] Style update #264

Open
wants to merge 15 commits into
base: page-list-upgrade
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,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 /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)
Expand Down
94 changes: 63 additions & 31 deletions cmake/gresource.cmake
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
#

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 ()
6 changes: 6 additions & 0 deletions data/assets.gresource.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/com/github/philip-scott/notes-up">
<file alias="stylesheet.css" compressed="false" preprocess="">stylesheet.css</file>
</gresource>
</gresources>
13 changes: 13 additions & 0 deletions data/stylesheet.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.title-label {
font-size: 1.2em;
font-weight: 700;
}

.preview-label {
opacity:1;
}

.date-time-label {
opacity:0.6;
font-size:0.9em;
}
2 changes: 1 addition & 1 deletion schemas/org.notes.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
</key>

<key name="editor-font" type="s">
<default>"Open Sans 12"</default>
<default>"Open Sans 10"</default>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change to 10?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was more in line with how fonts on the system are sized, I can change it back if you don't like it/don't think it's good.

<summary>Editor font</summary>
<description>The editor's font family and size</description>
</key>
Expand Down
14 changes: 14 additions & 0 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -62,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;

Expand All @@ -88,6 +90,18 @@ public class ENotes.Application : Granite.Application {
if (!running) {
settings = ENotes.Services.Settings.get_instance ();

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/";
DirUtils.create_with_parents (notes_dir, 0766);
Expand Down
14 changes: 8 additions & 6 deletions src/Services/Page.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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<Page> 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<Page>();
Expand All @@ -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);
}
Expand Down
81 changes: 54 additions & 27 deletions src/Widgets/PageItem.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ 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 name_label;
private Gtk.Label preview_label;
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;
Expand All @@ -37,35 +41,49 @@ 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;
name_label = new Gtk.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;

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;
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.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.use_markup = true;
((Gtk.Misc) preview_label).xalign = 0;

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.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);
((Gtk.Misc) date_label).xalign = 0;

var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
separator.hexpand = true;

this.add (grid);
grid.add (line1);
grid.add (line2);
grid.add (name_label);
grid.add (preview_label);
grid.add (date_label);
grid.add (separator);

load_data ();
Expand All @@ -77,8 +95,17 @@ public class ENotes.PageItem : Gtk.ListBoxRow {
}

public void load_data () {
this.line2.label = page.subtitle;
this.line1.label = "<b>" + page.name + "</b>";
time = new DateTime.from_unix_utc (page.modification_date);
//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 = "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;
}
}

5 changes: 5 additions & 0 deletions src/Widgets/Window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ 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");
Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);

headerbar = ENotes.Headerbar.get_instance ();
set_titlebar (headerbar);

Expand Down