Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class Jorts.Application : Gtk.Application {
public static bool new_from_clipboard = false;
public static bool show_pref = false;
public static bool reset_settings = false;
public static bool dump_storage = false;

public const string ACTION_PREFIX = "app.";
public const string ACTION_QUIT = "action_quit";
Expand Down Expand Up @@ -164,16 +165,17 @@ Please wait while the app remembers all the things...
/* Either we show all sticky notes, or we load everything lol */
if (manager.open_notes.size > 0) {
foreach (var window in manager.open_notes) {
if (window.visible) { window.present ();}
if (window.visible) {window.present ();}
}
} else {
manager.init_all_notes ();
manager.init ();
}

if (new_note) {manager.create_note (); new_note = false;}
if (new_from_clipboard) {manager.from_clipboard (); new_from_clipboard = false;}
if (show_pref) {action_show_preferences (); show_pref = false;}
if (reset_settings) {action_reset_settings (); reset_settings = false;}
if (dump_storage) {manager.dump (); dump_storage = false;}
}

public static int main (string[] args) {
Expand Down Expand Up @@ -205,7 +207,7 @@ Please wait while the app remembers all the things...

private void action_save () {
debug ("[ACTION] Saving...");
manager.save_to_stash ();
manager.save_all.begin ();
}

private void action_reset_settings () {
Expand Down Expand Up @@ -233,7 +235,8 @@ Please wait while the app remembers all the things...
{"new-note", 'n', OptionFlags.NONE, OptionArg.NONE, ref new_note, "Create a new note", null},
{"new-from-clipboard", 'c', OptionFlags.NONE, OptionArg.NONE, ref new_from_clipboard, "Create a note then paste from clipboard", null},
{"preferences", 'p', OptionFlags.NONE, OptionArg.NONE, ref show_pref, "Show preferences", null},
{"reset-settings", 'r', OptionFlags.NONE, OptionArg.NONE, ref reset_settings, "Reset all settings", null}
{"reset-settings", 'r', OptionFlags.NONE, OptionArg.NONE, ref reset_settings, "Reset all settings", null},
{"dump", 'd', OptionFlags.NONE, OptionArg.NONE, ref dump_storage, "Dump the content of the storage as a pretty JSON", null}
};

// We have to make an extra copy of the array, since .parse assumes
Expand Down
48 changes: 37 additions & 11 deletions src/Objects/NoteData.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@
*/


/* Creation methods:
vanilla
from_json ();
from_random ();

Helper:
to_json ();


*/
/*************************************************/
/**
* An object used to package all data conveniently as needed.
*/
public class Jorts.NoteData : Object {

// Will determine properties (or lack thereof) for any new note
public static string? latest_theme = Jorts.Constants.DEFAULT_THEME;
public static int? latest_zoom = Jorts.Constants.DEFAULT_ZOOM;
public static bool latest_mono = Jorts.Constants.DEFAULT_MONO;

public string title;
public string theme;
public string content;
Expand All @@ -26,6 +25,10 @@ public class Jorts.NoteData : Object {
public int width;
public int height;

/*************************************************/
/**
* Convert into a Json.Object()
*/
public NoteData (string? title = null, string? theme = null, string? content = null,
bool? monospace = null, int? zoom = null, int? width = null, int? height = null)
{
Expand All @@ -39,6 +42,10 @@ public class Jorts.NoteData : Object {
this.height = height ?? Jorts.Constants.DEFAULT_HEIGHT;
}

/*************************************************/
/**
* Parse a node to create an associated NoteData object
*/
public NoteData.from_json (Json.Object node) {
title = node.get_string_member_with_default ("title",(_("Forgot title!")));
theme = node.get_string_member_with_default ("theme",Jorts.Utils.random_theme (null));
Expand All @@ -48,12 +55,31 @@ public class Jorts.NoteData : Object {

// Make sure the values are nothing crazy
if (zoom < Jorts.Constants.ZOOM_MIN) { zoom = Jorts.Constants.ZOOM_MIN;}
else if (zoom > Jorts.Constants.ZOOM_MAX) { zoom = Jorts.Constants.ZOOM_MAX;}
else if (zoom > Jorts.Constants.ZOOM_MAX) { zoom = Jorts.Constants.ZOOM_MAX;}

width = (int)node.get_int_member_with_default ("width",Jorts.Constants.DEFAULT_WIDTH);
height = (int)node.get_int_member_with_default ("height",Jorts.Constants.DEFAULT_HEIGHT);
}

/*************************************************/
/**
* Parse a node to create an associated NoteData object
* We skip last chosen theme, and reuse latest set zoom and whether user prefers monospace
*/
public NoteData.from_random () {
title = title ?? Jorts.Utils.random_title ();
theme = theme ?? Jorts.Utils.random_theme (latest_theme);
content = content ?? "";
monospace = latest_mono;
zoom = latest_zoom;
width = Jorts.Constants.DEFAULT_WIDTH;
height = Jorts.Constants.DEFAULT_HEIGHT;
}

/*************************************************/
/**
* Used for storing NoteData inside disk storage
*/
public Json.Object to_json () {
var builder = new Json.Builder ();

Expand Down
20 changes: 20 additions & 0 deletions src/Objects/Themes.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* 2025 Contributions from the ellie_Commons community (github.com/ellie-commons/)
*/

/*************************************************/
/**
* A register of all themes we have
*/
public enum Jorts.Themes {
BLUEBERRY,
MINT,
Expand Down Expand Up @@ -33,6 +37,22 @@ public enum Jorts.Themes {
}
}

public Themes from_string (string wtf_is_this) {
switch (wtf_is_this.ascii_up ()) {
case "BLUEBERRY": return BLUEBERRY;
case "MINT": return MINT;
case "LIME": return LIME;
case "BANANA": return BANANA;
case "ORANGE": return ORANGE;
case "STRAWBERRY": return STRAWBERRY;
case "BUBBLEGUM": return BUBBLEGUM;
case "GRAPE": return GRAPE;
case "COCOA": return COCOA;
case "SLATE": return SLATE;
default: assert_not_reached ();
}
}

public static Themes[] all () {
return {BLUEBERRY, MINT, LIME, BANANA, ORANGE, STRAWBERRY, BUBBLEGUM, GRAPE, COCOA, SLATE};
}
Expand Down
4 changes: 2 additions & 2 deletions src/Services/Constants.vala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ namespace Jorts.Constants {
// signature theme
const string DEFAULT_THEME = "BLUEBERRY";
const int DAYS_BETWEEN_BACKUPS = 30;
const string FILENAME_STASH = "saved_state.json";
const string FILENAME_BACKUP = "backup_state.json";



// in ms
const int DEBOUNCE = 1000;
Expand Down
109 changes: 0 additions & 109 deletions src/Services/Jason.vala

This file was deleted.

Loading
Loading