Skip to content

Commit

Permalink
2.5.0 - Mini Power Up Release
Browse files Browse the repository at this point in the history
  • Loading branch information
Lains committed Jul 21, 2020
1 parent c2ad09a commit c6d4a55
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 150 deletions.
8 changes: 8 additions & 0 deletions data/com.github.lainsce.quilter.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
<content_attribute id="money-gambling">none</content_attribute>
</content_rating>
<releases>
<release version="2.5.0" date="2020-07-24">
<description>
<p>Release: Power Up</p>
<ul>
<li>Fix: Many file operation fixes both in backend and in UI.</li>
</ul>
</description>
</release>
<release version="2.2.4" date="2020-04-24">
<description>
<p>Release: Just What You Needed</p>
Expand Down
247 changes: 118 additions & 129 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ namespace Quilter {

statusbar = new Widgets.StatusBar (edit_view_content.buffer);
sidebar = new Widgets.SideBar (this);
sidebar.row_selected.connect (on_sidebar_row_selected);
sidebar.save_as.connect (() => on_save_as ());
searchbar = new Widgets.SearchBar (this);

Expand Down Expand Up @@ -413,9 +412,6 @@ namespace Quilter {
}

update_title ();
if (Quilter.Application.gsettings.get_string("current-file") != "") {
on_sidebar_row_selected (sidebar.get_selected_row ());
}

Gtk.Adjustment eadj = edit_view.get_vadjustment ();
Gtk.Adjustment padj = preview_view.get_vadjustment ();
Expand Down Expand Up @@ -671,131 +667,124 @@ namespace Quilter {
}
}

private void on_create_new () {
var dialog = new Services.DialogUtils.Dialog ();
dialog.transient_for = this;

dialog.response.connect ((response_id) => {
switch (response_id) {
case Gtk.ResponseType.OK:
debug ("User saves the file.");
unowned Widgets.SideBarBox? row = sidebar.get_selected_row ();
if (row != null && row.path != null) {
on_save ();
} else {
on_save_as ();
}

edit_view_content.modified = false;
dialog.close ();
break;
case Gtk.ResponseType.NO:
edit_view_content.modified = false;
dialog.close ();
break;
case Gtk.ResponseType.CANCEL:
case Gtk.ResponseType.CLOSE:
case Gtk.ResponseType.DELETE_EVENT:
dialog.close ();
return;
default:
assert_not_reached ();
}
});


if (edit_view_content.modified) {
dialog.run ();
}

debug ("Creating new document");
on_save ();
sidebar.add_file (Services.FileManager.get_temp_document_path ());
edit_view_content.text = "";
edit_view_content.modified = true;
on_save ();
}

private void on_open () {
string contents;
string path = Services.FileManager.open (out contents);

edit_view_content.text = contents;

if (path == Quilter.Application.gsettings.get_string("current-file")) {
sidebar.delete_row ();
sidebar.add_file (path);
} else {
sidebar.add_file (path);
}
}

private void on_save () {
unowned Widgets.SideBarBox? row = sidebar.get_selected_row ();
if (row != null) {
try {
Services.FileManager.save_file (row.path ?? Services.FileManager.get_temp_document_path (), edit_view_content.text);
edit_view_content.modified = false;
} catch (Error e) {
warning ("Unexpected error during save: " + e.message);
}
}
}

private void on_save_as () {
unowned Widgets.SideBarBox? row = sidebar.get_selected_row ();
if (row != null) {
try {

string path;
Services.FileManager.save_as (edit_view_content.text, out path);
edit_view_content.modified = false;

for (int i = 0; i < Quilter.Application.gsettings.get_strv("last-files").length; i++) {
if (Quilter.Application.gsettings.get_strv("last-files")[i] != null) {
sidebar.delete_row_with_name ();
sidebar.add_file (path);
} else {
sidebar.delete_row ();
sidebar.add_file (path);
}
}
} catch (Error e) {
warning ("Unexpected error during save: " + e.message);
}
}
}

private void on_sidebar_row_selected (Widgets.SideBarBox? box) {
if (box != null) {
try {
string file_path = box.path;

Quilter.Application.gsettings.set_string("current-file", box.path);

string text;
GLib.FileUtils.get_contents (file_path, out text);

if (Quilter.Application.gsettings.get_string("current-file") != file_path) {
if (Quilter.Application.gsettings.get_boolean("autosave") == true) {
on_save ();
}
} else if (Quilter.Application.gsettings.get_string("current-file") == _("No Documents Open")) {
return;
}

if (edit_view_content.modified) {
Services.FileManager.save_file (file_path, text);
edit_view_content.modified = false;
}

edit_view_content.text = text;
} catch (Error e) {
warning ("Unexpected error during selection: " + e.message);
}
public void save_last_files () {
string[] rows = {};
foreach (var child in sidebar.column.get_children ()) {
rows += ((Widgets.SideBarBox)child).path;
}

update_title ();
}
Quilter.Application.gsettings.set_strv ("last-files", rows);
}

private void on_create_new () {
var dialog = new Services.DialogUtils.Dialog ();
dialog.transient_for = this;

dialog.response.connect ((response_id) => {
switch (response_id) {
case Gtk.ResponseType.OK:
debug ("User saves the file.");
unowned Widgets.SideBarBox? row = sidebar.get_selected_row ();
if (row != null && row.path != null) {
on_save ();
} else {
on_save_as ();
}

edit_view_content.modified = false;
dialog.close ();
break;
case Gtk.ResponseType.NO:
edit_view_content.modified = false;
dialog.close ();
break;
case Gtk.ResponseType.CANCEL:
case Gtk.ResponseType.CLOSE:
case Gtk.ResponseType.DELETE_EVENT:
dialog.close ();
return;
default:
assert_not_reached ();
}
});


if (edit_view_content.modified) {
dialog.run ();
}

debug ("Creating new document");
on_save ();
sidebar.add_file (Services.FileManager.get_temp_document_path ());
sidebar.is_modified = true;
save_last_files ();
edit_view_content.text = "";
edit_view_content.modified = true;
sidebar.store.clear ();
sidebar.outline_populate ();
sidebar.view.expand_all ();
on_save ();
}

private void on_open () {
string contents;
string path = Services.FileManager.open (out contents);

if (sidebar.column.get_children () != null) {
foreach (var child in sidebar.column.get_children ()) {
if (((Widgets.SideBarBox)child).path == path) {
sidebar.column.select_row (((Widgets.SideBarBox)child));
break;
} else {
sidebar.add_file (path);
sidebar.is_modified = true;
break;
}
}
} else {
sidebar.add_file (path);
sidebar.is_modified = true;
}
edit_view_content.text = contents;
save_last_files ();
sidebar.store.clear ();
sidebar.outline_populate ();
sidebar.view.expand_all ();
}

public void on_save () {
unowned Widgets.SideBarBox? row = sidebar.get_selected_row ();
if (row != null) {
try {
Services.FileManager.save_file (row.path, edit_view_content.text);
edit_view_content.modified = false;
} catch (Error e) {
warning ("Unexpected error during save: " + e.message);
}
}
}

private void on_save_as () {
unowned Widgets.SideBarBox? row = sidebar.get_selected_row ();
if (row != null) {
try {

string path;
Services.FileManager.save_as (edit_view_content.text, out path);
edit_view_content.modified = false;
sidebar.store.clear ();
sidebar.outline_populate ();
sidebar.view.expand_all ();

foreach (var child in sidebar.column.get_children ()) {
if (((Widgets.SideBarBox)child).path == Services.FileManager.get_temp_document_path ()) {
((Widgets.SideBarBox)child).path = path;
break;
}
}
} catch (Error e) {
warning ("Unexpected error during save: " + e.message);
}
}
}
}
}
30 changes: 21 additions & 9 deletions src/Widgets/SideBar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace Quilter.Widgets {
public class SideBar : Gtk.Revealer {
public Gtk.ListBox column;
private Widgets.SideBarBox[] rows;
public Widgets.SideBarBox row;
public Widgets.SideBarBox filebox;
public Widgets.EditView ev;
Expand All @@ -41,6 +42,7 @@ namespace Quilter.Widgets {
private Gtk.Label no_files;
private string[] files;
public Gee.LinkedList<SideBarBox> s_files = null;
public bool is_modified {get; set; default = false;}

public signal void save_as ();
public signal void row_selected (Widgets.SideBarBox box);
Expand Down Expand Up @@ -124,20 +126,30 @@ namespace Quilter.Widgets {
column.set_placeholder (no_files);

for (int i = 0; i < Quilter.Application.gsettings.get_strv("last-files").length; i++) {
var row = add_file (Quilter.Application.gsettings.get_strv("last-files")[i]);
if (Quilter.Application.gsettings.get_strv("last-files")[i] == Quilter.Application.gsettings.get_string("current-file")) {
column.select_row (row);
}
rows += add_file (Quilter.Application.gsettings.get_strv("last-files")[i]);
}

column.row_selected.connect ((row) => {
if (((Widgets.SideBarBox)row) != null) {
row_selected ((Widgets.SideBarBox)row);
column.row_selected.connect ((selected_row) => {
foreach (var row in rows) {
row.file_remove_button.visible = (row == get_selected_row ());
}
});

try {
row = get_selected_row ();
string text = "";
GLib.FileUtils.get_contents (row.path, out text);
Quilter.Application.gsettings.set_string("current-file", row.path);

if (win.edit_view_content.modified) {
Services.FileManager.save_file (row.path, text);
win.edit_view_content.modified = false;
}

column.show_all ();
win.edit_view_content.text = text;
} catch (Error e) {
warning ("Unexpected error during selection: " + e.message);
}
});

files_grid = new Gtk.Grid ();
files_grid.hexpand = false;
Expand Down
3 changes: 2 additions & 1 deletion src/Widgets/SideBarBox.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace Quilter.Widgets {
private Gtk.Label file_label;
public Gtk.Grid file_grid;
public EditView ev;
public Gtk.Button file_remove_button;

private string? _path;
public new string? path {
Expand Down Expand Up @@ -77,7 +78,7 @@ namespace Quilter.Widgets {

var file_icon = new Gtk.Image.from_icon_name ("text-markdown", Gtk.IconSize.DND);

var file_remove_button = new Gtk.Button ();
file_remove_button = new Gtk.Button ();
file_remove_button.always_show_image = true;
file_remove_button.vexpand = false;
file_remove_button.hexpand = true;
Expand Down
Loading

0 comments on commit c6d4a55

Please sign in to comment.