Compare commits

...

23 Commits

Author SHA1 Message Date
8a86a99413 Update install instructions 2024-09-16 21:42:15 -04:00
Cassidy James Blaede
b8f4ea365c Add tooltips with keyboard shortcuts 2018-12-24 08:47:20 -05:00
7d364e0a27 Add links to the app on Write.as / AppCenter 2018-12-21 13:47:02 -05:00
eee4191db9 Bump version to 1.0.2 2018-12-20 14:40:42 -05:00
95dc0eb8cb Fix build_fontoption signature 2018-12-20 14:39:21 -05:00
8312087ec9 Reflect current font in menu on app load
Previously, "Serif" would be selected in the menu when the app first
loaded, no matter what the actual setting was.
2018-12-20 14:39:11 -05:00
2a7a5041c3 Remove unused light / dark mode icon 2018-12-20 14:38:38 -05:00
2c93de931b Fix null darkmode_switch
This fixes issues with Ctrl+T and the switch not reflecting correct
state when starting up -- previously, darkmode_switch was initialized in
construct_toolbar() as a local variable.
2018-12-20 14:36:32 -05:00
Cassidy James Blaede
5b1e88c995 Initial ModeSwitch work 2018-12-20 14:36:09 -05:00
Cassidy James Blaede
4c2be78f58 Resolve TODO 2018-12-20 13:19:59 -05:00
Cassidy James Blaede
d10d4081a2 Use Gtk.TextView.left_margin and right_margin instead of CSS padding 2018-12-20 13:19:27 -05:00
e680afb059 Update screenshots
Screenshots here and on https://write.as were taken on elementaryOS
Juno.

This closes #12
2018-12-20 13:19:06 -05:00
ac04997301 Change social-info OARS value to 'moderate'
This closes #11
2018-12-17 14:59:24 -05:00
Cassidy James Blaede
58e67738b7 Add tooltip to publish button
It wasn't clear what this button did without pushing it, at which point my note contents were uploaded to the Internet.
2018-12-17 14:59:06 -05:00
cccffacf55 Mention writeas-gtk is libre, not gratis 2018-12-17 14:57:40 -05:00
708de8f0ae Bump version to 1.0.1 2018-12-14 16:33:07 -05:00
0436c4ae95 Fix deprecated cursor-color property 2018-12-14 00:48:33 -05:00
7a12af3c11 Fix font errors and spacing in GTK 3.20+ 2018-12-14 00:42:04 -05:00
f0d601f98c Increase default font size to 16px 2018-12-14 00:41:35 -05:00
78a23713cf Don't show errors loading draft
This particularly prevents the initial error all users will see when the
app first loads.

TODO: implement something more elegant.
2018-12-14 00:31:05 -05:00
9ba47ba191 Change Travis builds to deb-packaging branch 2018-10-02 18:05:56 -04:00
67b6198b5e Revert "Change ID to com.github.writeas.writeas-gtk"
This reverts commit 4c784b32c8.
2018-09-30 21:56:09 -04:00
c0c8775c3a Revert "Fix more missing com.github.writeas.writeas-gtk IDs"
This reverts commit c3b0a35a2e.
2018-09-30 21:55:22 -04:00
21 changed files with 395 additions and 47 deletions

View File

@ -35,4 +35,4 @@ script:
branches:
only:
- master
- deb-packaging

View File

@ -1,10 +1,16 @@
# Write.as GTK App
[![Get the app from Write.as](https://write.as/img/downloadwriteas.png)](https://write.as/apps/desktop)  
[![Get the app on AppCenter](https://write.as/img/appcenter.png)](https://appcenter.elementary.io/com.github.writeas.writeas-gtk)
A Write.as desktop app that targets all freedesktop.org compliant desktops, e.g.
GNU/Linux, FreeBSD, etc; basically everything except Windows, Mac, iOS, and
Android. It lets you compose and publish posts to [Write.as](https://write.as/).
For a UI toolkit it uses GTK, and relies on the [writeas-cli](https://github.com/writeas/writeas-cli) for API calls and post management.
**Write.as GTK is _libre_, not _gratis_, software.** Please try the app free of charge, but [purchase a copy](https://write.as/apps/linux/get) if you continue using it.
## Usage
See the [User Guide](https://code.as/writeas/writeas-gtk/src/branch/master/USER_GUIDE.md).
@ -18,9 +24,9 @@ any FreeDesktop.Org compatible system using:
# Either via pip:
pip3 install meson
# Or, if you need to build the .deb:
sudo add-apt-repository ppa:jonathonf/meson
sudo apt update
sudo apt install meson
sudo apt install meson ninja-build
# You might also need some of these dependencies to successfully build the app:
sudo apt install build-essential valac libgtk-3-dev libgtksourceview-3.0-dev
# Build
meson build && cd build

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -1,10 +1,8 @@
install_data('icons/write-as.png',
install_dir: join_paths(get_option('datadir'), 'icons', 'hicolor', '128x128', 'apps')
)
install_data('icons/writeas-bright-dark.png',
install_dir: join_paths(get_option('datadir'), 'icons', 'hicolor', '16x16', 'actions'))
install_data('com.github.writeas.writeas-gtk.desktop',
install_data('writeas-gtk.desktop',
install_dir: join_paths(get_option('datadir'), 'applications'))
install_data('com.github.writeas.writeas-gtk.appdata.xml',
install_data('writeas-gtk.appdata.xml',
install_dir: join_paths(get_option('datadir'), 'metainfo'))

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<component type="desktop-application">
<id>com.github.writeas.writeas-gtk</id>
<id>writeas-gtk</id>
<project_license>GPL-3.0+</project_license>
<metadata_license>CC0</metadata_license>
<name>Write.as</name>
@ -28,7 +28,7 @@
<update_contact>hello@write.as</update_contact>
<provides>
<binary>com.github.writeas.writeas-gtk</binary>
<binary>writeas-gtk</binary>
</provides>
<screenshots>
@ -69,7 +69,7 @@
<content_attribute id="language-humor">none</content_attribute>
<content_attribute id="language-discrimination">none</content_attribute>
<content_attribute id="social-chat">none</content_attribute>
<content_attribute id="social-info">none</content_attribute>
<content_attribute id="social-info">moderate</content_attribute>
<content_attribute id="social-audio">none</content_attribute>
<content_attribute id="social-location">none</content_attribute>
<content_attribute id="social-contacts">none</content_attribute>
@ -77,6 +77,24 @@
<content_attribute id="money-gambling">none</content_attribute>
</content_rating>
<releases>
<release version="1.0.2" date="2018-12-20">
<description>
<p>This update fixes a few minor visual issues.</p>
<ul>
<li>Fix black bar that appears in the editor on elementary OS</li>
<li>Fix currently-selected font not reflected in menu when app first loads</li>
</ul>
</description>
</release>
<release version="1.0.1" date="2018-12-14">
<description>
<p>GTK updates and fixes.</p>
<ul>
<li>Fix fonts, padding, cursor color</li>
<li>Increase the default font size</li>
</ul>
</description>
</release>
<release version="1.0.0" date="2018-10-01">
<description>
<p>Initial release</p>

14
debian/changelog vendored
View File

@ -1,3 +1,17 @@
writeas-gtk (1.0.2-3) xenial; urgency=medium
* Fix black bar that appears in the editor on elementary OS
* Fix currently-selected font not reflected in menu when app first loads
-- Write.as <hello@write.as> Thu, 20 Dec 2018 14:20:45 -0500
writeas-gtk (1.0.1-2) xenial; urgency=medium
* Fix fonts, padding, cursor color
* Increase the default font size
-- Write.as <hello@write.as> Fri, 14 Dec 2018 15:22:09 -0500
writeas-gtk (1.0.0-1) xenial; urgency=medium
* Initial Release.

4
debian/control vendored
View File

@ -1,4 +1,4 @@
Source: com.github.writeas.writeas-gtk
Source: writeas-gtk
Section: x11
Priority: extra
Maintainer: Write.as <hello@write.as>
@ -9,7 +9,7 @@ Build-Depends: meson,
valac (>= 0.36)
Standards-Version: 3.9.3
Package: com.github.writeas.writeas-gtk
Package: writeas-gtk
Architecture: any
Depends: ${misc:Depends}, ${shlibs:Depends}, writeas-cli
Recommends: fonts-lora, fonts-open-sans, fonts-hack

2
debian/copyright vendored
View File

@ -1,5 +1,5 @@
Format: http://dep.debian.net/deps/dep5
Upstream-Name: com.github.writeas.writeas-gtk
Upstream-Name: writeas-gtk
Source: https://code.as/writeas/writeas-gtk/
Files: *

2
debian/rules vendored
View File

@ -28,4 +28,4 @@ override_dh_auto_test:
cd debian/build && ninja test
override_dh_auto_install:
cd debian/build && DESTDIR=${CURDIR}/debian/com.github.writeas.writeas-gtk ninja install
cd debian/build && DESTDIR=${CURDIR}/debian/writeas-gtk ninja install

View File

@ -1,5 +1,5 @@
project('com.github.writeas.writeas-gtk', ['vala', 'c'],
version: '1.0.0',
project('writeas-gtk', ['vala', 'c'],
version: '1.0.2',
license: 'GPL',
meson_version: '>=0.40.1')

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

After

Width:  |  Height:  |  Size: 49 KiB

136
src/Granite/Accels.vala Normal file
View File

@ -0,0 +1,136 @@
// From https://github.com/elementary/granite/blob/621f2669f6c8940fe32ac9817ddca92e97d27ae0/lib/Widgets/Utils.vala#L79-L192
/*
* Copyright (C) 2012-2017 Granite Developers
*
* This program or library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*/
namespace Granite {
/**
* Converts a {@link Gtk.accelerator_parse} style accel string to a human-readable string.
*
* @param accel an accelerator label like <Control>a or <Super>Right
*
* @return a human-readable string like "Ctrl + A" or "⌘ + →"
*/
public static string accel_to_string (string accel) {
uint accel_key;
Gdk.ModifierType accel_mods;
Gtk.accelerator_parse (accel, out accel_key, out accel_mods);
string[] arr = {};
if (Gdk.ModifierType.SUPER_MASK in accel_mods) {
arr += "";
}
if (Gdk.ModifierType.SHIFT_MASK in accel_mods) {
arr += _("Shift");
}
if (Gdk.ModifierType.CONTROL_MASK in accel_mods) {
arr += _("Ctrl");
}
if (Gdk.ModifierType.MOD1_MASK in accel_mods) {
arr += _("Alt");
}
switch (accel_key) {
case Gdk.Key.Up:
arr += "";
break;
case Gdk.Key.Down:
arr += "";
break;
case Gdk.Key.Left:
arr += "";
break;
case Gdk.Key.Right:
arr += "";
break;
case Gdk.Key.minus:
case Gdk.Key.KP_Subtract:
///TRANSLATORS: This is a non-symbol representation of the "-" key
arr += _("Minus");
break;
case Gdk.Key.KP_Add:
case Gdk.Key.plus:
///TRANSLATORS: This is a non-symbol representation of the "+" key
arr += _("Plus");
break;
case Gdk.Key.KP_Enter:
case Gdk.Key.Return:
arr += _("Enter");
break;
default:
arr += Gtk.accelerator_get_label (accel_key, 0);
break;
}
return string.joinv (" + ", arr);
}
/**
* Takes a description and an array of accels and returns {@link Pango} markup for use in a {@link Gtk.Tooltip}. This method uses {@link Granite.accel_to_string}.
*
* Example:
*
* Description
* Shortcut 1, Shortcut 2
*
* @param a string array of accelerator labels like {"<Control>a", "<Super>Right"}
*
* @param description a standard tooltip text string
*
* @return {@link Pango} markup with the description label on one line and a list of human-readable accels on a new line
*/
public static string markup_accel_tooltip (string[]? accels, string? description = null) {
string[] parts = {};
if (description != null && description != "") {
parts += description;
}
if (accels != null && accels.length > 0) {
string[] unique_accels = {};
for (int i = 0; i < accels.length; i++) {
if (accels[i] == "") {
continue;
}
var accel_string = accel_to_string (accels[i]);
if (!(accel_string in unique_accels)) {
unique_accels += accel_string;
}
}
if (unique_accels.length > 0) {
///TRANSLATORS: This is a delimiter that separates two keyboard shortcut labels like "⌘ + →, Control + A"
var accel_label = string.joinv (_(", "), unique_accels);
var accel_markup = """<span weight="600" size="smaller" alpha="75%">%s</span>""".printf (accel_label);
parts += accel_markup;
}
}
return string.joinv ("\n", parts);
}
}

157
src/Granite/ModeSwitch.vala Normal file
View File

@ -0,0 +1,157 @@
// From https://github.com/elementary/granite/blob/2066b377226cf327cb2d5399b6b40a2d36d47b11/lib/Widgets/ModeSwitch.vala
/*
* Copyright (c) 2018 elementary, Inc. (https://elementary.io)
*
* 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 2 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, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*/
/**
* ModeSwitch is a selection control for choosing between two options that can be described with an icon.
*
* ''Example''<<BR>>
* {{{
* var gtk_settings = Gtk.Settings.get_default ();
*
* var mode_switch = new ModeSwitch.from_icon_name ("display-brightness-symbolic", "weather-clear-night-symbolic");
* mode_switch.primary_icon_tooltip_text = _("Light background");
* mode_switch.secondary_icon_tooltip_text = _("Dark background");
* mode_switch.bind_property ("active", gtk_settings, "gtk_application_prefer_dark_theme");
* }}}
*/
public class Granite.ModeSwitch : Gtk.Grid {
/**
* Whether the {@link Gtk.Switch} widget is pointing to the secondary icon or not.
*/
public bool active { get; set; }
/**
* The {@link GLib.Icon} to use for the primary icon for the switch.
*/
public GLib.Icon primary_icon_gicon { get; construct set; }
/**
* The icon name to use for the primary icon for the switch.
*/
public string primary_icon_name { get; construct set; }
/**
* The contents of the tooltip on the primary icon.
*/
public string primary_icon_tooltip_text { get; set; }
/**
* The {@link GLib.Icon} to use for the secondary icon for the switch.
*/
public GLib.Icon secondary_icon_gicon { get; construct set; }
/**
* The icon name to use for the secondary icon for the switch.
*/
public string secondary_icon_name { get; construct set; }
/**
* The contents of the tooltip on the secondary icon.
*/
public string secondary_icon_tooltip_text { get; set; }
/**
* Constructs a new {@link Granite.ModeSwitch} using {@link GLib.Icon}s.
*
* @param primary_icon_gicon The {@link GLib.Icon} to use for the primary icon for the switch.
* @param secondary_icon_gicon The {@link GLib.Icon} to use for the secondary icon for the switch.
*/
public ModeSwitch (GLib.Icon primary_icon_gicon, GLib.Icon secondary_icon_gicon) {
Object (
primary_icon_gicon: primary_icon_gicon,
secondary_icon_gicon: secondary_icon_gicon
);
}
/**
* Constructs a new {@link Granite.ModeSwitch} from icon names.
*
* @param primary_icon_name The icon name to use for the primary icon for the switch.
* @param secondary_icon_name The icon name to use for the secondary icon for the switch.
*/
public ModeSwitch.from_icon_name (string primary_icon_name, string secondary_icon_name) {
Object (
primary_icon_gicon: new ThemedIcon (primary_icon_name),
secondary_icon_gicon: new ThemedIcon (secondary_icon_name),
primary_icon_name: primary_icon_name,
secondary_icon_name: secondary_icon_name
);
}
construct {
var primary_image = new Gtk.Image ();
primary_image.pixel_size = 16;
var primary_icon_box = new Gtk.EventBox ();
primary_icon_box.add_events (Gdk.EventMask.BUTTON_RELEASE_MASK);
primary_icon_box.add (primary_image);
var mode_switch = new Gtk.Switch ();
mode_switch.valign = Gtk.Align.CENTER;
mode_switch.get_style_context ().add_class ("mode-switch");
var secondary_icon = new Gtk.Image ();
secondary_icon.pixel_size = 16;
var secondary_icon_box = new Gtk.EventBox ();
secondary_icon_box.add_events (Gdk.EventMask.BUTTON_RELEASE_MASK);
secondary_icon_box.add (secondary_icon);
column_spacing = 6;
add (primary_icon_box);
add (mode_switch);
add (secondary_icon_box);
bind_property ("primary-icon-gicon", primary_image, "gicon", GLib.BindingFlags.SYNC_CREATE);
bind_property ("primary-icon-name", primary_image, "icon-name", GLib.BindingFlags.SYNC_CREATE);
bind_property ("primary-icon-tooltip-text", primary_image, "tooltip-text");
bind_property ("secondary-icon-gicon", secondary_icon, "gicon", GLib.BindingFlags.SYNC_CREATE);
bind_property ("secondary-icon-name", secondary_icon, "icon_name", GLib.BindingFlags.SYNC_CREATE);
bind_property ("secondary-icon-tooltip-text", secondary_icon, "tooltip-text");
this.notify["active"].connect (() => {
if (Gtk.StateFlags.DIR_RTL in get_state_flags ()) {
mode_switch.active = !active;
} else {
mode_switch.active = active;
}
});
mode_switch.notify["active"].connect (() => {
if (Gtk.StateFlags.DIR_RTL in get_state_flags ()) {
active = !mode_switch.active;
} else {
active = mode_switch.active;
}
});
primary_icon_box.button_release_event.connect (() => {
active = false;
return Gdk.EVENT_STOP;
});
secondary_icon_box.button_release_event.connect (() => {
active = true;
return Gdk.EVENT_STOP;
});
}
}

View File

@ -22,7 +22,7 @@ public class WriteAs.Application : Gtk.Application {
Intl.setlocale(LocaleCategory.ALL, "");
Intl.textdomain("write.as");
application_id = "com.github.writeas.writeas-gtk.desktop";
application_id = "writeas-gtk.desktop";
}
public override void activate() {

View File

@ -1,6 +1,8 @@
executable('com.github.writeas.writeas-gtk',
executable('writeas-gtk',
'application.vala',
'window.vala',
'Granite/Accels.vala',
'Granite/ModeSwitch.vala',
c_args: ['-include', 'config.h'],
link_args: '-lm',

View File

@ -19,12 +19,15 @@
public class WriteAs.MainWindow : Gtk.ApplicationWindow {
private Gtk.TextView canvas;
private Gtk.HeaderBar header;
private Gtk.ToggleButton darkmode_button;
private Granite.ModeSwitch darkmode_switch;
private Gtk.RadioMenuItem font_serif_option;
private Gtk.RadioMenuItem font_sans_option;
private Gtk.RadioMenuItem font_wrap_option;
private static string data_dir = ".writeas";
private static string version = "1.0.0";
private static string version = "1.0.2";
private int font_size = 12;
private int font_size = 16;
private bool dark_mode = false;
private string font = "Lora, 'Palatino Linotype',"
+ "'Book Antiqua', 'New York', 'DejaVu serif', serif";
@ -83,7 +86,7 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
init_folder();
try {
open_file(draft_file());
} catch (Error err) {canvas.buffer.text = err.message;}
} catch (Error err) {}
restore_styles();
set_default_size(800, 600);
@ -134,6 +137,10 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
var publish_button = new Gtk.Button.from_icon_name("document-send",
Gtk.IconSize.SMALL_TOOLBAR);
publish_button.tooltip_markup = Granite.markup_accel_tooltip (
{"<Ctrl>Return"},
_("Publish to Write.as on the web")
);
publish_button.clicked.connect(() => {
canvas.buffer.text += "\n\n" + publish();
@ -141,24 +148,23 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
});
header.pack_end(publish_button);
darkmode_button = new Gtk.ToggleButton();
darkmode_button.tooltip_text = _("Toggle dark theme");
// NOTE the fallback icon is a bit of a meaning stretch, but it works.
var icon_theme = Gtk.IconTheme.get_default();
darkmode_button.image = new Gtk.Image.from_icon_name(
icon_theme.has_icon("writeas-bright-dark") ?
"writeas-bright-dark" : "weather-clear-night",
Gtk.IconSize.SMALL_TOOLBAR);
darkmode_button.draw_indicator = false;
darkmode_switch = new Granite.ModeSwitch.from_icon_name ("display-brightness-symbolic", "weather-clear-night-symbolic");
darkmode_switch.primary_icon_tooltip_text = ("Light theme");
darkmode_switch.secondary_icon_tooltip_text = ("Dark theme");
darkmode_switch.tooltip_markup = Granite.markup_accel_tooltip (
{"<Ctrl>T"},
_("Toggle light/dark theme")
);
darkmode_switch.valign = Gtk.Align.CENTER;
var settings = Gtk.Settings.get_default();
darkmode_button.toggled.connect(() => {
settings.gtk_application_prefer_dark_theme = darkmode_button.active;
dark_mode = darkmode_button.active;
darkmode_switch.notify["active"].connect(() => {
settings.gtk_application_prefer_dark_theme = darkmode_switch.active;
dark_mode = darkmode_switch.active;
if (!is_initializing) theme_save();
canvas.grab_focus();
});
if (supports_dark_theme()) header.pack_end(darkmode_button);
if (supports_dark_theme()) header.pack_end(darkmode_switch);
var fonts = new Gtk.MenuButton();
fonts.tooltip_text = _("Change document font");
@ -166,16 +172,16 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
fonts.popup = new Gtk.Menu();
header.pack_start(fonts);
build_fontoption(fonts.popup, _("Serif"), "serif", font);
build_fontoption(fonts.popup, _("Sans-serif"), "sans",
font_serif_option = build_fontoption(fonts.popup, _("Serif"), "serif", font);
font_sans_option = build_fontoption(fonts.popup, _("Sans-serif"), "sans",
"'Open Sans', 'Segoe UI', Tahoma, Arial, sans-serif");
build_fontoption(fonts.popup, _("Monospace"), "wrap", "Hack, consolas," +
font_wrap_option = build_fontoption(fonts.popup, _("Monospace"), "wrap", "Hack, consolas," +
"Menlo-Regular, Menlo, Monaco, 'ubuntu mono', monospace");
fonts.popup.show_all();
}
private unowned SList<Gtk.RadioMenuItem>? font_options = null;
private void build_fontoption(Gtk.Menu menu,
private Gtk.RadioMenuItem build_fontoption(Gtk.Menu menu,
string label, string fontstyle, string families) {
var option = new Gtk.RadioMenuItem.with_label(font_options, label);
font_options = option.get_group();
@ -190,13 +196,15 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
var styles = option.get_style_context();
var provider = new Gtk.CssProvider();
try {
provider.load_from_data("* {font: %s;}".printf(families));
provider.load_from_data("* {font-family: %s;}".printf(families));
styles.add_provider(provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
} catch (Error e) {
warning(e.message);
}
menu.add(option);
return option;
}
public override void grab_focus() {
@ -211,12 +219,21 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
theme.load_from_file(get_data_dir() + "/prefs.ini", KeyFileFlags.NONE);
dark_mode = theme.get_boolean("Theme", "darkmode");
darkmode_button.set_active(dark_mode);
darkmode_switch.active = dark_mode;
Gtk.Settings.get_default().gtk_application_prefer_dark_theme = dark_mode;
font_size = theme.get_integer("Theme", "fontsize");
font = theme.get_string("Post", "font");
fontstyle = theme.get_string("Post", "fontstyle");
// Select the current font in the menu
if (fontstyle == "serif") {
font_serif_option.set_active(true);
} else if (fontstyle == "sans") {
font_sans_option.set_active(true);
} else if (fontstyle == "wrap") {
font_wrap_option.set_active(true);
}
adjust_text_style(false);
} catch (Error err) {/* No biggy... */}
}
@ -230,16 +247,16 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
Gtk.StyleContext.remove_provider_for_screen(Gdk.Screen.get_default(), cur_styles);
var padding = canvas.get_allocated_width()*0.10;
var css = ("GtkTextView {font: %s; font-size: %dpx; padding: 20px;" +
" padding-left: %ipx; padding-right: %ipx;" +
" -GtkWidget-cursor-color: #5ac4ee;}").printf(font, font_size,
(int) padding, (int) padding);
var css = ("textview {font-family: %s; font-size: %dpx; padding: 20px 0;" +
" caret-color: #5ac4ee;}").printf(font, font_size);
cur_styles = new Gtk.CssProvider();
cur_styles.load_from_data(css);
Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(),
cur_styles, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
canvas.left_margin = canvas.right_margin = (int) padding;
if (save_theme) theme_save();
} catch (Error e) {
warning(e.message);
@ -337,7 +354,7 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
// Toggle theme with Ctrl+T
accels.connect(Gdk.Key.T, Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE | Gtk.AccelFlags.LOCKED, (g,a,k,m) => {
darkmode_button.set_active(!darkmode_button.get_active());
darkmode_switch.active = !darkmode_switch.active;
return true;
});