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
540 changes: 281 additions & 259 deletions res/gtk/connection-form.blp

Large diffs are not rendered by default.

21 changes: 0 additions & 21 deletions res/gtk/connection-recent.blp
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,14 @@ template $PsequelConnectionSidebar : Gtk.Box {
spacing: 4;
hexpand: true;
halign: end;

Button {
styles ["flat", "big-icon", "linked"]
icon-name: "document-export-symbolic";
tooltip-text: "Import Connection";
clicked => $on_import_connection();
}

Button {
styles ["flat", "big-icon", "linked"]
icon-name: "document-import-symbolic";
tooltip-text: "Export Connection";
clicked => $on_export_connection();
}


Button {
tooltip-text: "Add new connection";
styles ["flat"]
icon-name: "plus-large-symbolic";
clicked => $on_add_connection();
}

Button {
tooltip-text: "Remove selected connection";
styles ["flat"]
icon-name: "minus-large-symbolic";
clicked => $on_remove_btn_clicked();
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions res/gtk/query-view.blp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ template $PsequelQueryView : Adw.Bin {

menu primary_menu {
section {

item {
label: _("_New Window");
action: "app.new-window";
}

item {
label: _("_Preferences");
action: "app.preferences";
Expand Down
35 changes: 27 additions & 8 deletions src/application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace Psequel {


private PreferencesWindow preference;
private AppSignals app_signals;

public Application () {
Object (application_id: "me.ppvan.psequel", flags: ApplicationFlags.DEFAULT_FLAGS);
Expand All @@ -37,19 +38,18 @@ namespace Psequel {
ActionEntry[] action_entries = {
{ "about", this.on_about_action },
{ "preferences", this.on_preferences_action },
{ "new-window", this.on_new_window },
{ "quit", this.quit }
};
this.add_action_entries (action_entries, this);
this.set_accels_for_action ("app.quit", {"<primary>q"});
this.set_accels_for_action ("app.quit", { "<primary>q" });
}

public override void activate () {
base.activate ();
var win = this.active_window;
if (win == null) {
win = new Psequel.Window (this);
}
win.present ();

var window = new_window ();
window.present ();
}

public override void startup () {
Expand All @@ -71,9 +71,10 @@ namespace Psequel {
return_if_reached ();
}

query_service = new QueryService (background);
app_signals = new AppSignals ();
app.app_signals = app_signals;
// query_service = new QueryService (background);
table_list = new ObservableArrayList<Relation.Row> ();
signals = new AppSignals ();

load_user_data ();
};
Expand Down Expand Up @@ -103,6 +104,7 @@ namespace Psequel {

/* register needed types, allow me to ref a template inside a template */
private static void ensure_types () {
typeof (WindowSignals).ensure ();
typeof (Psequel.ConnectionView).ensure ();
typeof (Psequel.ConnectionSidebar).ensure ();
typeof (Psequel.ConnectionForm).ensure ();
Expand Down Expand Up @@ -138,6 +140,12 @@ namespace Psequel {
about.present ();
}

private void on_new_window () {
var window = new_window ();
window.present ();
}


private void on_preferences_action () {

if (this.preference == null) {
Expand All @@ -149,5 +157,16 @@ namespace Psequel {
}
this.preference.present ();
}

private Window new_window () {
var signals = new WindowSignals ();
var window = new Window (this);
var query_service = new QueryService (ResourceManager.instance ().background);
window.signals = (owned)signals;
window.query_service = (owned)query_service;
app_signals.window_ready ();

return window;
}
}
}
12 changes: 12 additions & 0 deletions src/models/utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,16 @@ namespace Psequel {
assert_not_reached ();
}
}

public Window get_parrent_window (Gtk.Widget widget) {
var window = widget.get_root ();

if (window is Gtk.Window) {
return (Window) window;
} else {
warning ("Widget %s root is not a window", widget.name);

assert_not_reached ();
}
}
}
1 change: 0 additions & 1 deletion src/services/query_service.vala
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ namespace Psequel {

public async Relation exec_query_params (string query, Variant[] params) throws PsequelError {

debug (params[0].get_string ());

var result = yield exec_query_params_internal (query, params);

Expand Down
5 changes: 1 addition & 4 deletions src/services/resource_manager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ namespace Psequel {
public class ResourceManager : Object {


/**
* Application specific signals.
*/
public AppSignals signals;
public AppSignals app_signals;

/**
* Recent connections info in last sessions.
Expand Down
26 changes: 23 additions & 3 deletions src/services/signal.vala
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
namespace Psequel {

/**
* Application signals to comnicate between components.
* Window signals to comnicate between components.
*/
public class AppSignals {
public class WindowSignals : Object {

/* Target connection in connection list changed */
public signal void selection_changed (Connection conn);

/* Request a db connection by click connect context menu */
public signal void request_database_conn (Connection conn);
/**
* Emit when the table list changed.
*/
Expand All @@ -22,9 +27,24 @@ namespace Psequel {
public signal void request_database (Connection conn);
public signal void database_connected ();
/**
* Should only init onces by the resource manager. Should be single on but i'm lazy
* Tied to one window and created by window.
*/
public WindowSignals () {
Object ();
}

public int number {get; set;}
}

/**
* Application signals.
*/
public class AppSignals : Object {

public signal void window_ready ();

public AppSignals () {
Object ();
}
}
}
32 changes: 21 additions & 11 deletions src/ui/connection/connection_form.vala
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
namespace Psequel {

[GtkTemplate (ui = "/me/ppvan/psequel/gtk/connection-form.ui")]
public class ConnectionForm : Gtk.Box {
public class ConnectionForm : Adw.Bin {

BindingGroup binddings;

private unowned QueryService query_service;
private unowned AppSignals signals;
private unowned WindowSignals signals;

private Connection _conn;
public Connection mapped_conn {
Expand All @@ -26,9 +26,7 @@ namespace Psequel {
}

construct {
// init service
query_service = ResourceManager.instance ().query_service;
signals = ResourceManager.instance ().signals;
debug ("[CONTRUCT] %s", this.name);

// Create group to maped the entry widget to connection data.
this.binddings = new BindingGroup ();
Expand All @@ -37,13 +35,25 @@ namespace Psequel {
}

private void setup_signals () {
ConnectionSidebar.signals.selection_changed.connect ((conn) => {
mapped_conn = conn;
});
ConnectionSidebar.signals.request_database_conn.connect ((conn) => {
mapped_conn = conn;
connect_btn.clicked ();

// signals can only be connected after the window is ready.
// because widget access window to get signals.
ResourceManager.instance ().app_signals.window_ready.connect (() => {
var window = get_parrent_window (this);
signals = window.signals;

signals.selection_changed.connect ((conn) => {
mapped_conn = conn;
});

signals.request_database_conn.connect ((conn) => {
mapped_conn = conn;
connect_btn.clicked ();
});

query_service = window.query_service;
});

}

private void set_up_bindings (BindingGroup group) {
Expand Down
Loading