Skip to content

Commit

Permalink
Moar 1.0.3 goodness and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lainsce committed May 28, 2017
1 parent 37f5b8a commit a7056b5
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 31 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ vala_precompile(VALA_C ${EXEC_NAME}
src/Widgets/Toolbar.vala
src/Widgets/SourceView.vala
src/Constants/Stylesheet.vala
src/Constants/AppSettings.vala
src/Utils/FileUtils.vala
src/Utils/DialogUtils.vala

Expand Down
4 changes: 4 additions & 0 deletions data/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
include (GSettings)

add_schema ("com.github.lainsce.notejot.gschema.xml")

install (FILES icons/32/com.github.lainsce.notejot.svg DESTINATION share/icons/hicolor/32x32/apps)
install (FILES icons/48/com.github.lainsce.notejot.svg DESTINATION share/icons/hicolor/48x48/apps)
install (FILES icons/64/com.github.lainsce.notejot.svg DESTINATION share/icons/hicolor/64x64/apps)
Expand Down
14 changes: 14 additions & 0 deletions data/com.github.lainsce.notejot.gschema.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<schemalist>
<schema id="com.github.lainsce.notejot" path="/com/github/lainsce/notejot/">
<key name="window-x" type="i">
<default>-1</default>
<summary>Window position</summary>
<description>The x axis of window position</description>
</key>
<key name="window-y" type="i">
<default>-1</default>
<summary>Window position</summary>
<description>The y axis of window position</description>
</key>
</schema>
</schemalist>
33 changes: 12 additions & 21 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,21 @@
namespace Notejot {
public class Application : Granite.Application {

private static Notejot.Application app;
private MainWindow window = null;
private Notejot.MainWindow? window = null;

construct {
application_id = "com.github.lainsce.notejot";
program_name = "Notejot";
app_years = "2017";
exec_name = "com.github.lainsce.notejot";
app_launcher = "com.github.lainsce.notejot";
build_version = "1.0.1";
build_version = "1.0.4";
app_icon = "com.github.lainsce.notejot";
main_url = "https://github.com/lainsce/notejot/";
bug_url = "https://github.com/lainsce/notejot/issues";
help_url = "https://github.com/lainsce/notejot/";
about_authors = {"Lains <[email protected]>", null};
about_license_type = Gtk.License.GPL_3_0;
}

protected override void activate () {
if (window != null) {
window.present ();
return;
}

window = new MainWindow ();
window.set_application (this);
window.show_all ();

var quit_action = new SimpleAction ("quit", null);
add_action (quit_action);
Expand All @@ -59,16 +47,19 @@ namespace Notejot {
});
}

protected override void activate () {
if (window == null) {
window = new MainWindow (this);
add_window (window);
window.show_all ();
} else {
window.present ();
}
}

public static int main (string[] args) {
var app = new Notejot.Application ();
return app.run (args);
}

public static Notejot.Application get_instance () {
if (app == null)
app = new Notejot.Application ();

return app;
}
}
}
36 changes: 36 additions & 0 deletions src/Constants/AppSettings.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*-
* Copyright (c) 2017 Lains
*
* This program 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 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace Notejot {
public class AppSettings : Granite.Services.Settings {
public int window_x { get; set; }
public int window_y { get; set; }

private static AppSettings? instance;
public static unowned AppSettings get_default () {
if (instance == null) {
instance = new AppSettings ();
}

return instance;
}

private AppSettings () {
base ("com.github.lainsce.notejot");
}
}
}
27 changes: 24 additions & 3 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ using Granite.Widgets;
namespace Notejot {
public class MainWindow : Gtk.Window {
private Gtk.ScrolledWindow scroll;
private Settings settings;

public Widgets.Toolbar toolbar;
public Widgets.SourceView view;

public MainWindow () {
Object (resizable: false,
public MainWindow (Gtk.Application application) {
Object (application: application,
resizable: false,
title: _("Notejot"),
height_request: 500,
width_request: 500);
Expand All @@ -39,23 +41,42 @@ namespace Notejot {
}

construct {
settings = new Settings ("com.github.lainsce.notejot");

this.get_style_context ().add_class ("rounded");
this.toolbar = new Widgets.Toolbar ();
var header_context = toolbar.get_style_context ();
header_context.add_class ("notejot-window");

this.window_position = Gtk.WindowPosition.CENTER;
this.set_titlebar (toolbar);
this.show_all ();

scroll = new Gtk.ScrolledWindow (null, null);
this.add (scroll);
this.view = new Widgets.SourceView ();
scroll.add (view);

var settings = AppSettings.get_default ();

int x = settings.window_x;
int y = settings.window_y;

if (x != -1 && y != -1) {
move (x, y);
}

Utils.FileUtils.load_tmp_file ();
}

public override bool delete_event (Gdk.EventAny event) {
int x, y;
get_position (out x, out y);

var settings = AppSettings.get_default ();
settings.window_x = x;
settings.window_y = y;

return false;
}
}
}
14 changes: 7 additions & 7 deletions src/Utils/DialogUtils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
*/

namespace Notejot.Utils.DialogUtils {

/**
* Display a choose file dialog: a save dialog, or an open dialog.
*/
public Gtk.FileChooserDialog create_file_chooser (string title,
Gtk.FileChooserAction action) {

// Init the FileChooser, based on what the calling method desires.
var chooser = new Gtk.FileChooserDialog (title, null, action);

chooser.add_button (Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL);
if (action == Gtk.FileChooserAction.OPEN) {
chooser.add_button (Gtk.Stock.OPEN, Gtk.ResponseType.ACCEPT);
Expand All @@ -36,6 +34,7 @@ namespace Notejot.Utils.DialogUtils {
filter.set_filter_name (_("Text files"));
filter.add_pattern ("*.txt");
chooser.add_filter (filter);

filter = new Gtk.FileFilter ();
filter.set_filter_name (_("All files"));
filter.add_pattern ("*");
Expand All @@ -48,13 +47,15 @@ namespace Notejot.Utils.DialogUtils {
var chooser = create_file_chooser (_("Open file"),
Gtk.FileChooserAction.OPEN);
File file = null;

if (chooser.run () == Gtk.ResponseType.ACCEPT)
file = chooser.get_file ();

var filter = new Gtk.FileFilter ();
filter.set_filter_name (_("Text files"));
filter.add_pattern ("*.txt");
chooser.add_filter (filter);

filter = new Gtk.FileFilter ();
filter.set_filter_name (_("All files"));
filter.add_pattern ("*");
Expand All @@ -64,15 +65,14 @@ namespace Notejot.Utils.DialogUtils {
return file;
}

/**
* Display a save dialog and return the selected file.
*/
public File display_save_dialog () {
var chooser = create_file_chooser (_("Save file"),
Gtk.FileChooserAction.SAVE);
File file = null;

if (chooser.run () == Gtk.ResponseType.ACCEPT)
file = chooser.get_file ();

chooser.destroy();
return file;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Utils/FileUtils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace Notejot.Utils.FileUtils {
public void save_file (File file, uint8[] buffer) throws Error {
var output = new DataOutputStream (file.create
(FileCreateFlags.NONE));

long written = 0;
while (written < buffer.length)
written += output.write (buffer[written:buffer.length]);
Expand Down Expand Up @@ -65,8 +66,10 @@ namespace Notejot.Utils.FileUtils {

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;

save_file(tmp_file, binbuffer);
}
}

0 comments on commit a7056b5

Please sign in to comment.