Skip to content

Commit

Permalink
1.2.9 - New Icon / Fix persistent old file bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Paulo Galardi committed Sep 18, 2017
1 parent 49050c7 commit f5e3c96
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 5 deletions.
9 changes: 9 additions & 0 deletions data/com.github.lainsce.quilter.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
<url type="homepage">https://github.com/lainsce/quilter/</url>
<url type="bugtracker">https://github.com/lainsce/quilter/issues</url>
<releases>
<release version="1.2.9" date="2017-09-17">
<description>
<p>Release: Resourceful Little Worker</p>
<ul>
<li>Fix the bug that recreates old files when not needed</li>
<li>New icon that matches the brand of Quilter more</li>
</ul>
</description>
</release>
<release version="1.2.8" date="2017-09-06">
<description>
<p>Release: Colors are Nice</p>
Expand Down
Binary file modified data/shot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
com.github.lainsce.quilter (1.2.9) xenial; urgency=low

* Fix the bug that recreates old files when not needed.
* New icon that matches the brand of Quilter more.

-- Lains <[email protected]> Fri, 8 September 2017 20:27:00 -0300

com.github.lainsce.quilter (1.2.8) xenial; urgency=low

* Use colors that make sense for the app.
Expand All @@ -6,7 +13,6 @@ com.github.lainsce.quilter (1.2.8) xenial; urgency=low

-- Lains <[email protected]> Fri, 8 September 2017 20:27:00 -0300


com.github.lainsce.quilter (1.2.7) xenial; urgency=low

* Fix opening a file from outside the app.
Expand Down
20 changes: 18 additions & 2 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,13 @@ namespace Quilter {
this.view.monospace = true;
scroll.add (view);

Services.FileUtils.load_work_file ();
if (settings.last_file != null) {
Services.FileUtils.load_work_file ();
} else {
var home = GLib.Environment.get_home_dir ();
settings.last_file = @"$home/.cache/com.github.lainsce.quilter/temp";
Services.FileUtils.load_tmp_file ();
}

this.key_press_event.connect ((e) => {
uint keycode = e.hardware_keycode;
Expand Down Expand Up @@ -220,7 +226,14 @@ namespace Quilter {
settings.window_width = w;
settings.window_height = h;

Services.FileUtils.save_work_file ();
if (settings.last_file != null) {
Services.FileUtils.save_work_file ();
} else {
var home = GLib.Environment.get_home_dir ();
settings.last_file = @"$home/.cache/com.github.lainsce.quilter/temp";
Services.FileUtils.save_tmp_file ();
}

return false;
}

Expand Down Expand Up @@ -249,12 +262,15 @@ namespace Quilter {

public void new_button_pressed () {
debug ("New button pressed.");
var settings = AppSettings.get_default ();

if (Widgets.SourceView.is_modified = true) {
try {
debug ("Making new file...");
Services.FileUtils.new_document ();
toolbar.subtitle = "New Document";
var home = GLib.Environment.get_home_dir ();
settings.last_file = @"$home/.cache/com.github.lainsce.quilter/temp";
} catch (Error e) {
warning ("Unexpected error: " + e.message);
}
Expand Down
59 changes: 57 additions & 2 deletions src/Services/FileUtils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/

namespace Quilter.Services.FileUtils {
File tmp_file;

public void save_file (File file, uint8[] buffer) throws Error {
var output = new DataOutputStream (file.create(FileCreateFlags.REPLACE_DESTINATION));
long written = 0;
Expand Down Expand Up @@ -46,6 +48,38 @@ namespace Quilter.Services.FileUtils {
}
}

private void load_tmp_file () {
string cache_path = Path.build_filename (Environment.get_user_cache_dir (), "com.github.lainsce.quilter");
var cache_folder = File.new_for_path (cache_path);
if (!cache_folder.query_exists ()) {
try {
cache_folder.make_directory_with_parents ();
} catch (Error e) {
warning ("Error: %s\n", e.message);
}
}

tmp_file = cache_folder.get_child ("temp");

if ( !tmp_file.query_exists () ) {
try {
tmp_file.create (FileCreateFlags.NONE);
} catch (Error e) {
warning ("Error: %s\n", e.message);
}
}

try {
string text;
string filename = tmp_file.get_path ();

GLib.FileUtils.get_contents (filename, out text);
Widgets.SourceView.buffer.text = text;
} catch (Error e) {
warning ("%s", e.message);
}
}

private void save_work_file () {
var settings = AppSettings.get_default ();
var file = File.new_for_path (settings.last_file);
Expand All @@ -71,6 +105,29 @@ namespace Quilter.Services.FileUtils {
}
}

private void save_tmp_file () {
if ( tmp_file.query_exists () ) {
try {
tmp_file.delete();
} catch (Error e) {
warning ("Error: %s\n", e.message);
}

}

Gtk.TextIter start, end;
Widgets.SourceView.buffer.get_bounds (out start, out end);

string buffer = Widgets.SourceView.buffer.get_text (start, end, true);
uint8[] binbuffer = buffer.data;

try {
save_file (tmp_file, binbuffer);
} catch (Error e) {
warning ("Exception found: "+ e.message);
}
}

// File I/O
public bool new_document () throws Error {
if (Widgets.SourceView.is_modified) {
Expand All @@ -97,8 +154,6 @@ namespace Quilter.Services.FileUtils {
if (wanna_save == Gtk.ResponseType.NO) {
debug ("User cancelled the dialog. Remove document from Widgets.SourceView then.");
Widgets.SourceView.buffer.text = "";
var settings = AppSettings.get_default ();
settings.last_file = "";
}
}
return true;
Expand Down

0 comments on commit f5e3c96

Please sign in to comment.