Page MenuHomeMusing Studio

No OneTemporary

diff --git a/.gitignore b/.gitignore
index ca6cfcb..3b2ab93 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,13 @@
*.swp
*~
build
+_build/
+.flatpak-builder/
.ninja_*
build.ninja
data/writeas
+
+# Files generated by gb
+pkg/
+bin/
diff --git a/.travis.yml b/.travis.yml
index a2ba685..0d4ddf1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,27 +1,41 @@
---
-
-language: node_js
-
-node_js:
- - lts/*
-
-sudo: required
-
-services:
- - docker
-
-addons:
- apt:
- sources:
- - ubuntu-toolchain-r-test
- packages:
- - libstdc++-5-dev
-
-install:
- - npm i -g @elementaryos/houston
-
-script:
- - houston ci
+language: c
notifications:
email: false
+
+matrix:
+ include:
+ - language: node_js
+ node_js:
+ - lts/*
+ sudo: required
+ before_install: []
+ services:
+ - docker
+ addons:
+ apt:
+ sources:
+ - ubuntu-toolchain-r-test
+ packages:
+ - libstdc++-5-dev
+ install:
+ - npm i -g @elementaryos/houston
+ script:
+ - houston ci
+ language: c
+ services:
+ - docker
+ sudo: required
+ before_install:
+ - ls
+ - docker pull christopherdavis/elementary-flatpak-writeas:latest
+ - docker run --privileged -v "$(pwd)":/build/writeas/writeas-gtk -it -d --name flatpak christopherdavis/elementary-flatpak-writeas bash
+ - docker exec flatpak chmod +x /usr/bin/fusermount
+ addons: []
+ install: []
+ script:
+ - docker exec flatpak flatpak-builder --stop-at=writeas-gtk app /build/writeas/writeas-gtk/flatpak/com.abunchtell.WriteAsDesktop.json
+ - docker exec flatpak flatpak-builder --run app meson _build /build/writeas/writeas-gtk --prefix=/app -Dauto_build_cli=true
+ - docker exec flatpak flatpak-builder --run app ninja -C _build install
+ - docker exec flatpak flatpak-builder --finish-only app /build/writeas/writeas-gtk/flatpak/com.abunchtell.WriteAsDesktop.json
diff --git a/data/writeas-gtk.appdata.xml.in b/data/com.abunchtell.WriteAsDesktop.appdata.xml.in
similarity index 99%
rename from data/writeas-gtk.appdata.xml.in
rename to data/com.abunchtell.WriteAsDesktop.appdata.xml.in
index 7107478..d9a0081 100644
--- a/data/writeas-gtk.appdata.xml.in
+++ b/data/com.abunchtell.WriteAsDesktop.appdata.xml.in
@@ -1,114 +1,114 @@
<?xml version="1.0" encoding="UTF-8" ?>
<component type="desktop-application">
<id>@app_id@</id>
<project_license>GPL-3.0+</project_license>
<metadata_license>CC0</metadata_license>
<name>Write.as</name>
<summary>Publish a thought in seconds</summary>
<description>
<p>Write.as is a simple writing tool and publishing platform. There's no sign up — just open the app, write something, and publish.</p>
<p>Published posts get a secret, unique link on Write.as that you can share with anyone, or keep to yourself. In either case, you remain private because we don't collect personal information about you.</p>
<ul>
<li>Simple, distraction-free editor built for your words</li>
<li>Instantly launches to a blank page or your last draft</li>
<li>Writing automatically saves as you type</li>
<li>Work on a single local draft, then publish or save as another file when you're finished</li>
<li>Choose from three different fonts: serif, sans-serif, or monospace</li>
<li>Dark mode on platforms that support it</li>
<li>Publish to Write.as and share your post (<a href="https://write.as/l23z7d6yb0dd5v4c.md">example</a>)</li>
<li>Manage published posts with the built-in command-line interface</li>
</ul>
</description>
<developer_name>Write.as</developer_name>
<url type="homepage">https://write.as/</url>
<url type="help">https://write.as/contact</url>
<url type="bugtracker">https://github.com/writeas/writeas-gtk/issues</url>
<update_contact>hello@write.as</update_contact>
<provides>
- <binary>@app_id@</binary>
+ <binary>@exec@</binary>
</provides>
<screenshots>
<screenshot type="default">
<caption>The Write.as editor.</caption>
<image type="source">https://write.as/img/screens/gtk/serif.png</image>
</screenshot>
<screenshot>
<caption>The Write.as editor in dark mode.</caption>
<image type="source">https://write.as/img/screens/gtk/serif-dark.png</image>
</screenshot>
<screenshot>
<image type="source">https://write.as/img/screens/gtk/sans.png</image>
</screenshot>
<screenshot>
<image type="source">https://write.as/img/screens/gtk/monospace.png</image>
</screenshot>
</screenshots>
<content_rating type="oars-1.1">
<content_attribute id="violence-cartoon">none</content_attribute>
<content_attribute id="violence-fantasy">none</content_attribute>
<content_attribute id="violence-realistic">none</content_attribute>
<content_attribute id="violence-bloodshed">none</content_attribute>
<content_attribute id="violence-sexual">none</content_attribute>
<content_attribute id="violence-desecration">none</content_attribute>
<content_attribute id="violence-slavery">none</content_attribute>
<content_attribute id="violence-worship">none</content_attribute>
<content_attribute id="drugs-alcohol">none</content_attribute>
<content_attribute id="drugs-narcotics">none</content_attribute>
<content_attribute id="drugs-tobacco">none</content_attribute>
<content_attribute id="sex-nudity">none</content_attribute>
<content_attribute id="sex-themes">none</content_attribute>
<content_attribute id="sex-homosexuality">none</content_attribute>
<content_attribute id="sex-prostitution">none</content_attribute>
<content_attribute id="sex-adultery">none</content_attribute>
<content_attribute id="sex-appearance">none</content_attribute>
<content_attribute id="language-profanity">none</content_attribute>
<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">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>
<content_attribute id="money-purchasing">none</content_attribute>
<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>
<ul>
<li>Auto-saving single draft</li>
<li>Dark mode on platforms that support it</li>
<li>Choose between three fonts</li>
<li>Save draft as another file</li>
<li>Publish anonymously to Write.as</li>
</ul>
</description>
</release>
</releases>
<custom>
<value key="x-appcenter-suggested-price">25</value>
</custom>
</component>
diff --git a/data/writeas-gtk.desktop.in b/data/com.abunchtell.WriteAsDesktop.desktop.in
similarity index 93%
rename from data/writeas-gtk.desktop.in
rename to data/com.abunchtell.WriteAsDesktop.desktop.in
index 0ec22b5..0ec54e7 100644
--- a/data/writeas-gtk.desktop.in
+++ b/data/com.abunchtell.WriteAsDesktop.desktop.in
@@ -1,12 +1,12 @@
[Desktop Entry]
Type=Application
Name=Write.as
Comment=Publish a thought in seconds.
-Exec=@app_id@
+Exec=@exec@
Icon=@app_id@
Terminal=false
MimeType=
Categories=GTK;Office;Publishing;
Keywords=blog;text;editor;publish;
StartupNotify=true
diff --git a/data/icons/128/writeas-gtk.png b/data/icons/128/com.abunchtell.WriteAsDesktop.png
similarity index 100%
rename from data/icons/128/writeas-gtk.png
rename to data/icons/128/com.abunchtell.WriteAsDesktop.png
diff --git a/data/icons/16/writeas-gtk.png b/data/icons/16/com.abunchtell.WriteAsDesktop.png
similarity index 100%
rename from data/icons/16/writeas-gtk.png
rename to data/icons/16/com.abunchtell.WriteAsDesktop.png
diff --git a/data/icons/24/writeas-gtk.png b/data/icons/24/com.abunchtell.WriteAsDesktop.png
similarity index 100%
rename from data/icons/24/writeas-gtk.png
rename to data/icons/24/com.abunchtell.WriteAsDesktop.png
diff --git a/data/icons/32/writeas-gtk.png b/data/icons/32/com.abunchtell.WriteAsDesktop.png
similarity index 100%
rename from data/icons/32/writeas-gtk.png
rename to data/icons/32/com.abunchtell.WriteAsDesktop.png
diff --git a/data/icons/48/writeas-gtk.png b/data/icons/48/com.abunchtell.WriteAsDesktop.png
similarity index 100%
rename from data/icons/48/writeas-gtk.png
rename to data/icons/48/com.abunchtell.WriteAsDesktop.png
diff --git a/data/icons/64/writeas-gtk.png b/data/icons/64/com.abunchtell.WriteAsDesktop.png
similarity index 100%
rename from data/icons/64/writeas-gtk.png
rename to data/icons/64/com.abunchtell.WriteAsDesktop.png
diff --git a/data/meson.build b/data/meson.build
index 73b7444..82d7659 100644
--- a/data/meson.build
+++ b/data/meson.build
@@ -1,24 +1,25 @@
icon_sizes = ['16', '24', '32', '48', '64', '128']
foreach i : icon_sizes
install_data(
- join_paths('icons', i, meson.project_name() + '.png'),
+ join_paths('icons', i, 'com.abunchtell.WriteAsDesktop.png'),
install_dir: join_paths(get_option('datadir'), 'icons', 'hicolor', i + 'x' + i, 'apps'),
rename: '@0@.png'.format(app_id)
)
endforeach
data_conf = configuration_data()
data_conf.set('app_id', app_id)
+data_conf.set('exec', executable)
configure_file(
- input: 'writeas-gtk.desktop.in',
+ input: 'com.abunchtell.WriteAsDesktop.desktop.in',
output: '@0@.desktop'.format(app_id),
configuration: data_conf,
install_dir: join_paths(get_option('datadir'), 'applications')
)
configure_file(
- input: 'writeas-gtk.appdata.xml.in',
+ input: 'com.abunchtell.WriteAsDesktop.appdata.xml.in',
output: '@0@.appdata.xml'.format(app_id),
configuration: data_conf,
install_dir: join_paths(get_option('datadir'), 'metainfo')
)
diff --git a/debian/control b/debian/control
index a849fba..8e65d76 100644
--- a/debian/control
+++ b/debian/control
@@ -1,18 +1,18 @@
Source: com.github.writeas.writeas-gtk
Section: x11
Priority: extra
Maintainer: Write.as <hello@write.as>
-Build-Depends: meson,
+Build-Depends: meson (>= 0.48),
debhelper (>= 9),
libgtk-3-dev,
libgtksourceview-3.0-dev,
valac (>= 0.36),
golang-go,
gb
Standards-Version: 3.9.3
Package: com.github.writeas.writeas-gtk
Architecture: any
Depends: ${misc:Depends}, ${shlibs:Depends}
Recommends: fonts-open-sans, fonts-hack-ttf
Description: A distraction free and private writing tool, with built-in publishing.
diff --git a/debian/rules b/debian/rules
index d3fbd4c..176ce5e 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,33 +1,31 @@
#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.
# This file was extended to incorporate a Meson/Ninja build system.
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
%:
dh $@
override_dh_auto_clean:
rm -rf debian/build
override_dh_auto_configure:
mkdir -p debian/build
- cd debian/build && meson --prefix=/usr ../.. -Dplatform=elementary
+ cd debian/build && meson --prefix=/usr ../.. -Dplatform=elementary -Dauto_build_cli=true
override_dh_auto_build:
- cd debian/build && ninja -v && ninja build
+ cd debian/build && ninja -v
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
- mkdir -p debian/com.github.writeas.writeas-gtk/usr/bin
- cp bin/writeas debian/com.github.writeas.writeas-gtk/usr/bin/
diff --git a/flatpak/com.abunchtell.WriteAsDesktop.json b/flatpak/com.abunchtell.WriteAsDesktop.json
new file mode 100644
index 0000000..29110ce
--- /dev/null
+++ b/flatpak/com.abunchtell.WriteAsDesktop.json
@@ -0,0 +1,110 @@
+{
+ "app-id": "com.abunchtell.WriteAsDesktop",
+ "base": "io.elementary.BaseApp",
+ "base-version": "juno",
+ "runtime": "org.gnome.Platform",
+ "runtime-version": "3.32",
+ "sdk": "org.gnome.Sdk",
+ "sdk-extensions": [
+ "org.freedesktop.Sdk.Extension.golang"
+ ],
+ "command": "writeas-gtk",
+ "finish-args": [
+ "--socket=wayland",
+ "--share=ipc",
+ "--socket=x11",
+ "--device=dri",
+ "--share=network",
+ "--filesystem=~/.writeas:rw"
+ ],
+ "build-options": {
+ "append-path": "/usr/lib/sdk/golang/bin/",
+ "build-args" : [
+ "--share=network"
+ ],
+ "env": {
+ "GOROOT": "/usr/lib/sdk/golang/"
+ }
+ },
+ "modules": [
+ {
+ "name": "gb",
+ "buildsystem": "simple",
+ "build-commands": [
+ "/usr/lib/sdk/golang/enable.sh; env GOPATH=\"$(pwd)\" go build github.com/constabulary/gb/cmd/gb",
+ "install -Dm0755 -t /app/bin gb"
+ ],
+ "sources": [
+ {
+ "type": "git",
+ "url": "https://github.com/pkg/errors.git",
+ "dest": "src/github.com/pkg/errors"
+ },
+ {
+ "type": "git",
+ "url": "https://github.com/constabulary/gb.git",
+ "dest": "src/github.com/constabulary/gb"
+ }
+ ]
+ },
+ {
+ "name": "gtksourceview3",
+ "config-opts" : [
+ "--disable-Werror"
+ ],
+ "sources": [
+ {
+ "type": "git",
+ "url": "https://gitlab.gnome.org/GNOME/gtksourceview.git",
+ "branch": "gnome-3-24"
+ }
+ ]
+ },
+ {
+ "name": "wl-clipboard",
+ "buildsystem": "meson",
+ "sources": [
+ {
+ "type": "git",
+ "url": "https://github.com/bugaevc/wl-clipboard.git"
+ }
+ ]
+ },
+ {
+ "name": "libXmu",
+ "config-opts": [
+ "--disable-static",
+ "--disable-docs"
+ ],
+ "sources": [
+ {
+ "type": "archive",
+ "url": "https://www.x.org/releases/individual/lib/libXmu-1.1.2.tar.bz2",
+ "sha256": "756edc7c383254eef8b4e1b733c3bf1dc061b523c9f9833ac7058378b8349d0b"
+ }
+ ]
+ },
+ {
+ "name": "xclip",
+ "sources": [
+ {
+ "type": "git",
+ "url": "https://github.com/astrand/xclip.git"
+ }
+ ]
+ },
+ {
+ "name": "writeas-gtk",
+ "buildsystem": "meson",
+ "config-opts": [
+ "-Dauto_build_cli=true"
+ ],
+ "sources": [
+ {
+ "type": "git",
+ "url": "https://github.com/writeas/writeas-gtk.git"
+ }
+ ]
+ }
+ ]
+}
diff --git a/meson.build b/meson.build
index 00b1074..c424f86 100644
--- a/meson.build
+++ b/meson.build
@@ -1,29 +1,32 @@
project('writeas-gtk', ['vala', 'c'],
version: '1.0.2',
license: 'GPL',
- meson_version: '>=0.46.0')
+ meson_version: '>=0.48.0')
i18n = import('i18n')
build_platform = get_option('platform')
if build_platform == 'elementary'
app_id = 'com.github.writeas.writeas-gtk'
+ executable = 'com.github.writeas.writeas-gtk'
else
- app_id = 'writeas-gtk'
+ app_id = 'com.abunchtell.WriteAsDesktop'
+ executable = 'writeas-gtk'
endif
+
conf = configuration_data()
conf.set_quoted('GETTEXT_PACKAGE', app_id)
conf.set_quoted('APP_ID', app_id)
conf.set_quoted('BUILD_PLATFORM', build_platform)
config_h = configure_file(output: 'config.h', configuration: conf)
config_h_dir = include_directories('.')
-run_target('build', command: 'meson/build-cli.sh')
+cli_build_script = find_program('meson/build-cli.sh')
subdir('data')
subdir('src')
subdir('fonts/lora')
meson.add_install_script('meson/post_install.py')
diff --git a/meson/build-cli.sh b/meson/build-cli.sh
index 023c655..2dfc7a2 100755
--- a/meson/build-cli.sh
+++ b/meson/build-cli.sh
@@ -1,7 +1,12 @@
#!/bin/bash
exec_name=writeas
echo "Building $exec_name CLI..."
+cd $1 &&
gb build github.com/writeas/writeas-cli/cmd/writeas &&
+mv bin/writeas $3/$2 &&
+# Cleanup
+rm -rf bin/ &&
+rm -rf pkg/ &&
echo "Success."
diff --git a/meson_options.txt b/meson_options.txt
index 29bd56e..113c1f9 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1 +1,2 @@
option('platform', type: 'combo', choices: ['default', 'elementary'], value: 'default')
+option('auto_build_cli', type: 'boolean', value: 'false')
diff --git a/src/application.vala b/src/application.vala
index 848daa9..c77e3c9 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -1,44 +1,44 @@
/*
Copyright © 2018 Write.as
This file is part of the Write.as GTK desktop app.
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 <https://www.gnu.org/licenses/>.
*/
extern const string APP_ID;
extern const string BUILD_PLATFORM;
public class WriteAs.Application : Gtk.Application {
construct {
this.flags |= ApplicationFlags.HANDLES_OPEN;
Intl.setlocale(LocaleCategory.ALL, "");
Intl.textdomain("write.as");
- application_id = APP_ID + ".desktop";
+ application_id = APP_ID;
}
public override void activate() {
if (get_windows().length() == 0)
new WriteAs.MainWindow(this).show_all();
}
public override void open(File[] files, string hint) {
activate(); // ensure we have a window open.
}
public static int main(string[] args) {
return new WriteAs.Application().run(args);
}
}
diff --git a/src/meson.build b/src/meson.build
index 75de727..48de256 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -1,11 +1,29 @@
-executable(app_id,
+if get_option('auto_build_cli')
+ gb = find_program('gb')
+
+ cli_target = custom_target('build-cli',
+ build_by_default: true,
+ output: 'writeas',
+ install: true,
+ install_dir: get_option('bindir'),
+ console: true,
+ command: [
+ cli_build_script,
+ '@SOURCE_ROOT@',
+ '@OUTPUT@',
+ meson.build_root()
+ ]
+ )
+endif
+
+executable(executable,
'application.vala',
'window.vala',
'Granite/Accels.vala',
'Granite/ModeSwitch.vala',
c_args: ['-include', 'config.h'],
link_args: '-lm',
dependencies: [dependency('gtk+-3.0'), dependency('gtksourceview-3.0')],
install: true
)
diff --git a/src/window.vala b/src/window.vala
index fe91c6a..b109df2 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -1,419 +1,416 @@
/*
Copyright © 2018 Write.as
This file is part of the Write.as GTK desktop app.
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 <https://www.gnu.org/licenses/>.
*/
public class WriteAs.MainWindow : Gtk.ApplicationWindow {
private Gtk.TextView canvas;
private Gtk.HeaderBar header;
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.2";
private int font_size = 16;
private bool dark_mode = false;
private string font = "Lora, 'Palatino Linotype',"
+ "'Book Antiqua', 'New York', 'DejaVu serif', serif";
private string fontstyle = "serif";
private bool text_changed = false;
private bool is_initializing = true;
construct {
header = new Gtk.HeaderBar();
header.title = "Write.as";
construct_toolbar();
build_keyboard_shortcuts();
var scrolled = new Gtk.ScrolledWindow(null, null);
canvas = new Gtk.SourceView();
canvas.wrap_mode = Gtk.WrapMode.WORD_CHAR;
scrolled.add(canvas);
add(scrolled);
size_allocate.connect((_) => {adjust_text_style();});
canvas.event_after.connect((evt) => {
// TODO This word count algorithm may be quite naive
// and could do improvement.
var word_count = canvas.buffer.text.split(" ").length;
header.subtitle = ngettext("%i word","%i words",word_count).printf(word_count);
text_changed = true;
});
Timeout.add_full(Priority.DEFAULT_IDLE, 100/*ms*/, () => {
if (!text_changed) return Source.CONTINUE;
var text = canvas.buffer.text;
// This happens sometimes for some reason, but it's difficult to debug.
if (text == "") return Source.CONTINUE;
try {
draft_file().replace_contents(text.data, null, false,
FileCreateFlags.PRIVATE | FileCreateFlags.REPLACE_DESTINATION,
null);
text_changed = false;
} catch (Error err) {/* We'll try again anyways. */}
return Source.CONTINUE;
});
adjust_text_style(false);
}
public MainWindow(Gtk.Application app) {
stdout.printf("writeas-gtk v%s\n", version);
set_application(app);
icon_name = APP_ID;
init_folder();
try {
open_file(draft_file());
} catch (Error err) {}
restore_styles();
set_default_size(800, 600);
is_initializing = false;
}
private static void init_folder() {
var home = File.new_for_path(get_data_dir());
try {
home.make_directory();
} catch (Error e) {
stderr.printf("Create data dir: %s\n", e.message);
}
}
private static string get_data_dir() {
return Environment.get_home_dir() + "/" + data_dir;
}
private static File draft_file() {
var home = File.new_for_path(get_data_dir());
return home.get_child("draft.txt");
}
private static bool supports_dark_theme() {
var theme = Gtk.Settings.get_default().gtk_theme_name;
foreach (var datapath in Environment.get_system_data_dirs()) {
var path = File.new_for_path(Path.build_filename(datapath, "themes", theme));
if (path.get_child("gtk-dark.css").query_exists()) return true;
try {
var enumerator = path.enumerate_children("standard::*", 0);
FileInfo info = null;
while ((info = enumerator.next_file()) != null) {
var fullpath = path.get_child(info.get_name()).get_child("gtk-dark.css");
if (fullpath.query_exists()) return true;
}
} catch (Error err) {/* Might be missing something, but no biggy. */}
}
return false;
}
private void construct_toolbar() {
header.show_close_button = true;
set_titlebar(header);
var icon_size = Gtk.IconSize.SMALL_TOOLBAR;
if (BUILD_PLATFORM == "elementary") {
icon_size = Gtk.IconSize.LARGE_TOOLBAR;
}
var publish_button = new Gtk.Button.from_icon_name("document-send",
icon_size);
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();
canvas.grab_focus();
});
header.pack_end(publish_button);
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_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_switch);
var fonts = new Gtk.MenuButton();
fonts.tooltip_text = _("Change document font");
fonts.image = new Gtk.Image.from_icon_name("font-x-generic", icon_size);
fonts.popup = new Gtk.Menu();
header.pack_start(fonts);
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");
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 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();
option.activate.connect(() => {
this.font = families;
this.fontstyle = fontstyle;
adjust_text_style(!is_initializing);
canvas.grab_focus();
});
var styles = option.get_style_context();
var provider = new Gtk.CssProvider();
try {
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() {
canvas.grab_focus();
}
private KeyFile theme = new KeyFile();
private void restore_styles() {
try {
loaded_theme = true;
theme.load_from_file(get_data_dir() + "/prefs.ini", KeyFileFlags.NONE);
dark_mode = theme.get_boolean("Theme", "darkmode");
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... */}
}
private Gtk.CssProvider cur_styles = null;
// So the theme isn't read before it's saved.
private bool loaded_theme = false;
private void adjust_text_style(bool save_theme = true) {
try {
if (cur_styles != null)
Gtk.StyleContext.remove_provider_for_screen(Gdk.Screen.get_default(), cur_styles);
var padding = canvas.get_allocated_width()*0.10;
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);
}
}
private void theme_save() {
if (!loaded_theme) return;
theme.set_boolean("Theme", "darkmode", dark_mode);
theme.set_integer("Theme", "fontsize", font_size);
theme.set_string("Post", "font", font);
theme.set_string("Post", "fontstyle", fontstyle);
try {
theme.save_to_file(get_data_dir() + "/prefs.ini");
} catch (FileError err) {/* Oh well. */}
}
private string publish() {
try {
if (text_changed) {;
draft_file().replace_contents(canvas.buffer.text.data, null, false,
FileCreateFlags.PRIVATE | FileCreateFlags.REPLACE_DESTINATION,
null);
text_changed = false;
}
var cmd = "sh -c 'cat ~/" + data_dir + "/draft.txt | writeas --md --font %s --user-agent \"writeas-gtk v" + version + "\"'";
cmd = cmd.printf(fontstyle);
string stdout, stderr;
int status;
Process.spawn_command_line_sync(cmd,
out stdout, out stderr, out status);
// Open it in the browser
if (status == 0) {
var browser = AppInfo.get_default_for_uri_scheme("https");
var urls = new List<string>();
urls.append(stdout.strip());
browser.launch_uris(urls, null);
}
return stderr.strip();
} catch (Error err) {
return err.message;
}
}
/* --- */
private void build_keyboard_shortcuts() {
/* These operations are not exposed to the UI as buttons,
as most people are very familiar with them and they are not the
focus of this app. */
var accels = new Gtk.AccelGroup();
// App operations
accels.connect(Gdk.Key.W, Gdk.ModifierType.CONTROL_MASK,
Gtk.AccelFlags.VISIBLE | Gtk.AccelFlags.LOCKED,
(g,a,k,m) => quit());
accels.connect(Gdk.Key.Q, Gdk.ModifierType.CONTROL_MASK,
Gtk.AccelFlags.VISIBLE | Gtk.AccelFlags.LOCKED,
(g,a,k,m) => quit());
// File operations
accels.connect(Gdk.Key.S, Gdk.ModifierType.CONTROL_MASK,
Gtk.AccelFlags.VISIBLE | Gtk.AccelFlags.LOCKED,
(g,a,k,m) => save_as());
accels.connect(Gdk.Key.S,
Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.SHIFT_MASK,
Gtk.AccelFlags.VISIBLE | Gtk.AccelFlags.LOCKED,
(g,a,k,m) => save_as());
// Adjust text size
accels.connect(Gdk.Key.minus, Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE | Gtk.AccelFlags.LOCKED, (g,a,k,m) => {
if (font_size < 3) {
return false;
}
if (font_size <= 10) {
font_size -= 1;
} else {
font_size -= 2;
}
adjust_text_style(true);
return true;
});
accels.connect(Gdk.Key.equal, Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE | Gtk.AccelFlags.LOCKED, (g,a,k,m) => {
if (font_size < 10) {
font_size += 1;
} else {
font_size += 2;
}
adjust_text_style(true);
return true;
});
// 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_switch.active = !darkmode_switch.active;
return true;
});
// Publish with Ctrl+Enter
accels.connect(Gdk.Key.Return, Gdk.ModifierType.CONTROL_MASK, Gtk.AccelFlags.VISIBLE | Gtk.AccelFlags.LOCKED, (g,a,k,m) => {
canvas.buffer.text += "\n\n" + publish();
return true;
});
add_accel_group(accels);
}
private bool save_as() {
try {
var file = prompt_file(Gtk.FileChooserAction.SAVE, _("Save as"));
file.replace_contents(canvas.buffer.text.data, null, false,
FileCreateFlags.PRIVATE | FileCreateFlags.REPLACE_DESTINATION,
null);
} catch (Error e) {
// It's fine...
}
return true;
}
private File prompt_file(Gtk.FileChooserAction mode, string action)
throws UserCancellable {
- var file_chooser = new Gtk.FileChooserDialog(action, this, mode,
- _("Cancel"), Gtk.ResponseType.CANCEL,
- action, Gtk.ResponseType.ACCEPT);
-
+ var file_chooser = new Gtk.FileChooserNative(action, this, mode,
+ _("Save"), _("Cancel"));
file_chooser.select_multiple = false;
var filter = new Gtk.FileFilter();
filter.add_mime_type("text/plain");
file_chooser.set_filter(filter);
var resp = file_chooser.run();
- file_chooser.close();
if (resp == Gtk.ResponseType.ACCEPT) {
return file_chooser.get_file();
} else {
- throw new UserCancellable.USER_CANCELLED("FileChooserDialog");
+ throw new UserCancellable.USER_CANCELLED("FileChooserNative");
}
}
public void open_file(File file) throws Error {
uint8[] text;
file.load_contents(null, out text, null);
canvas.buffer.text = (string) text;
}
private bool quit() {
this.close();
return true;
}
}
errordomain WriteAs.UserCancellable {USER_CANCELLED}

File Metadata

Mime Type
text/x-diff
Expires
Fri, Dec 5, 12:14 AM (1 d, 13 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3524945

Event Timeline