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
2 changes: 2 additions & 0 deletions res/gtk/connection-view.blp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ template $PsequelConnectionView : Adw.Bin {

[start]
$PsequelConnectionSidebar sidebar {
window: bind template.window;
width-request: 300;
}

[end]
$PsequelConnectionForm form {
window: bind template.window;
}
}

Expand Down
6 changes: 3 additions & 3 deletions res/gtk/query-view.blp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ template $PsequelQueryView : Adw.Bin {
icon-name: "library-symbolic";
title: "Structure";
child: $PsequelTableStructure {

window: bind template.window;
};
}

Expand All @@ -248,7 +248,7 @@ template $PsequelQueryView : Adw.Bin {
title: "Data";
icon-name: "object-rows-symbolic";
child: $PsequelTableData {
window: bind template.window;
};
}

Expand All @@ -257,7 +257,7 @@ template $PsequelQueryView : Adw.Bin {
icon-name: "terminal-symbolic";
title: "Query";
child: $PsequelQueryEditor {
window: bind template.window;
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions res/gtk/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ template $PsequelWindow : Adw.ApplicationWindow {
StackPage {
name: "connection-view";
child: $PsequelConnectionView {

window: bind template;
};
}

StackPage {
name: "query-view";
child: $PsequelQueryView {

window: bind template;
};
}
}
Expand Down
13 changes: 9 additions & 4 deletions src/application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace Psequel {

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

load_user_data ();
Expand Down Expand Up @@ -145,7 +145,6 @@ namespace Psequel {
window.present ();
}


private void on_preferences_action () {

if (this.preference == null) {
Expand All @@ -158,12 +157,18 @@ namespace Psequel {
this.preference.present ();
}

/**
* Create a window and inject resources.
*
* Because child widget is created before window, signals can only be connect when window is init.
* This result to another event to notify window is ready and widget should setup signals
*/
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;
window.signals = (owned) signals;
window.query_service = (owned) query_service;
app_signals.window_ready ();

return window;
Expand Down
1 change: 1 addition & 0 deletions src/services/signal.vala
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace Psequel {
*/
public class AppSignals : Object {

/** Signal emit when window is created and {@link WindowSignals} can be used. */
public signal void window_ready ();

public AppSignals () {
Expand Down
34 changes: 15 additions & 19 deletions src/ui/connection/connection_form.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ namespace Psequel {
private unowned QueryService query_service;
private unowned WindowSignals signals;

/** Binded in blueprints file */
public Window window { get; set; }

private Connection _conn;
public Connection mapped_conn {
get {
Expand All @@ -21,39 +24,33 @@ namespace Psequel {

public ConnectionSidebar sidebar { get; set; }

public ConnectionForm (ConnectionView parent) {
Object ();
public ConnectionForm (Window window) {
Object (window: window);
}

construct {
debug ("[CONTRUCT] %s", this.name);

// Create group to maped the entry widget to connection data.
this.binddings = new BindingGroup ();
set_up_bindings (binddings);
setup_signals ();

ResourceManager.instance ().app_signals.window_ready.connect (setup_signals);
}

private void setup_signals () {

// 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 = window.signals;

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

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

query_service = window.query_service;
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 Expand Up @@ -92,7 +89,6 @@ namespace Psequel {

debug ("Emit database_connected");
signals.database_connected ();

} catch (PsequelError err) {
var dialog = create_dialog ("Connection error", err.message);
dialog.present ();
Expand Down
25 changes: 12 additions & 13 deletions src/ui/connection/connection_recent.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,33 @@ namespace Psequel {
{ "export", on_export_connection },
};

/** Binded in blueprints file */
public Window window { get; set; }
private Application app;

/* This is null ultil window ready event, which after contruct block */
private unowned WindowSignals signals;
private unowned ObservableArrayList<Connection> model;


public ConnectionSidebar (ConnectionView parent) {
Object ();
public ConnectionSidebar (Window window) {
Object (window: window);
}

construct {
debug ("[CONTRUCT] %s", this.name);

this.app = ResourceManager.instance ().app;
this.model = ResourceManager.instance ().recent_connections;

setup_signals ();
with (ResourceManager.instance ()) {
this.app = app;
this.model = recent_connections;
app_signals.window_ready.connect (setup_signals);
}
}

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

private void setup_action () {
Expand Down
8 changes: 3 additions & 5 deletions src/ui/connection/connection_view.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ namespace Psequel {
[GtkTemplate (ui = "/me/ppvan/psequel/gtk/connection-view.ui")]
public class ConnectionView : Adw.Bin {

public void hello () {
debug ("Hello");
}
public Window window {get; set;}

public ConnectionView (Application app) {
Object ();

sidebar = new ConnectionSidebar (this);
form = new ConnectionForm (this);
sidebar = new ConnectionSidebar (window);
form = new ConnectionForm (window);
}

// Connect event.
Expand Down
13 changes: 5 additions & 8 deletions src/ui/query/query_editor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,27 @@ namespace Psequel {
private LanguageManager lang_manager;
private StyleSchemeManager style_manager;

/** Binded in blueprints file */
public Window window { get; set; }

public class QueryEditor () {
Object ();
}

construct {
debug ("[CONTRUCT] %s", this.name);
debug ("Contruct view");

lang_manager = LanguageManager.get_default ();
style_manager = StyleSchemeManager.get_default ();

default_setttings ();
setup_signals ();
ResourceManager.instance ().app_signals.window_ready.connect (setup_signals);
}

private void setup_signals () {
ResourceManager.instance ().app_signals.window_ready.connect (() => {
query_service = get_parrent_window (this).query_service;
});
query_service = window.query_service;
}


void default_setttings () {

var lang = lang_manager.get_language ("sql");
Expand All @@ -58,6 +56,7 @@ namespace Psequel {
query_results.show_loading ();
int64 exec_time = 0;
var relation = yield query_service.exec_query (query, out exec_time);

query_results.show_result (relation);

update_status (relation, exec_time);
Expand All @@ -66,7 +65,6 @@ namespace Psequel {
}
}


[GtkCallback]
private void run_query_cb (Gtk.Button btn) {

Expand All @@ -79,7 +77,6 @@ namespace Psequel {
debug ("Exec query: %s", text);

run_query.begin (text);

}

private void update_status (Relation relation, int64 exec_time) {
Expand Down
11 changes: 4 additions & 7 deletions src/ui/query/query_view.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ namespace Psequel {
public const string TABLE_STRUCTURE = "structure-view";
public const string QUERY_EDITOR = "query-editor";

public Window window {get; set;}
private unowned QueryService query_service;
private unowned WindowSignals signals;

private SchemaService schema_service;

private ObservableArrayList<Schema> schemas;
Expand Down Expand Up @@ -45,8 +47,8 @@ namespace Psequel {
tbname_filter = new Gtk.StringFilter (exp);
vname_filter = new Gtk.StringFilter (exp);

setup_signals ();
set_up_schema ();
ResourceManager.instance ().app_signals.window_ready.connect (setup_signals);
}


Expand Down Expand Up @@ -149,12 +151,8 @@ namespace Psequel {
}

private void setup_signals () {
// 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 = window.signals;

signals.database_connected.connect (() => {
debug ("Handle database_connected.");
Expand All @@ -168,7 +166,6 @@ namespace Psequel {

schema_service = new SchemaService (query_service);
schemas = new ObservableArrayList<Schema> ();
});
}

[GtkCallback]
Expand Down
7 changes: 4 additions & 3 deletions src/ui/query/table_data_view.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Psequel {
[GtkTemplate (ui = "/me/ppvan/psequel/gtk/table-data-view.ui")]
public class TableData : Gtk.Box {

public Window window {get; set;}
private unowned WindowSignals signals;
private QueryService query_service;

Expand All @@ -26,7 +27,7 @@ namespace Psequel {
var setting = ResourceManager.instance ().settings;
setting.bind ("query-limit", this, "query-limit", SettingsBindFlags.DEFAULT);

setup_signals ();
ResourceManager.instance ().app_signals.window_ready.connect (setup_signals);
}


Expand Down Expand Up @@ -74,7 +75,7 @@ namespace Psequel {
// signals can only be connected after the window is ready.
// because widget access window to get signals.
ResourceManager.instance ().app_signals.window_ready.connect (() => {
signals = get_parrent_window (this).signals;
signals = window.signals;

signals.table_selected_changed.connect ((tbname) => {
this.tbname = tbname;
Expand All @@ -92,7 +93,7 @@ namespace Psequel {
this.schema = schema;
});

query_service = get_parrent_window (this).query_service;
query_service = window.query_service;
});
}

Expand Down
Loading