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: 0 additions & 2 deletions res/gtk/schema-main.blp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ template $PsequelSchemaMain : Gtk.Box {
icon-name: "terminal-symbolic";
title: "Query";
child: $PsequelQueryEditor {
query-viewmodel: bind template.query-viewmodel;
query-history-viewmodel: bind template.query-viewmodel as <$PsequelQueryViewModel>.query-history-viewmodel;
};
}
}
Expand Down
5 changes: 0 additions & 5 deletions res/gtk/schema-view.blp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ template $PsequelSchemaView : Adw.Bin {

menu: primary_menu;
view-mode: bind sidebar.view-mode;
// selected-table: bind sidebar.selected-table;
// selected-view: bind sidebar.selected-view;
table-viewmodel: bind template.schema-viewmodel as <$PsequelSchemaViewModel>.table-viewmodel;
view-viewmodel: bind template.schema-viewmodel as <$PsequelSchemaViewModel>.view-viewmodel;
query-viewmodel: bind template.schema-viewmodel as <$PsequelSchemaViewModel>.query-viewmodel;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion res/gtk/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ template $PsequelWindow : Adw.ApplicationWindow {
StackPage {
name: "connection-view";
child: $PsequelConnectionView {
request-database => $on_connect_db ();
};
}

Expand Down
27 changes: 19 additions & 8 deletions src/application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -182,24 +182,30 @@ namespace Psequel {
}

private Container create_viewmodels () {
var container = new Container ();

// services
var sql_service = new SQLService (Application.background);
var schema_service = new SchemaService (sql_service);
var repository = new ConnectionRepository (Application.settings);
var navigation = new NavigationService ();

// connection and schemas
var conn_vm = new ConnectionViewModel (repository);
var sche_vm = new SchemaViewModel (sql_service);

// viewmodels
var conn_vm = new ConnectionViewModel (repository, sql_service, navigation);
var sche_vm = new SchemaViewModel (schema_service);
var table_vm = new TableViewModel (sql_service);
var view_vm = new ViewViewModel (sql_service);
var table_structure_vm = new TableStructureViewModel (sql_service);
var view_structure_vm = new ViewStructureViewModel (sql_service);
var table_data_vm = new TableDataViewModel (sql_service);
var view_data_vm = new ViewDataViewModel (sql_service);
var query_history_vm = new QueryHistoryViewModel (sql_service);
var query_vm = new QueryViewModel (query_history_vm);

var navigation = new NavigationService ();

var container = new Container ();
container.register (sql_service);
container.register (schema_service);
container.register (repository);
container.register (navigation);
container.register (conn_vm);
container.register (sche_vm);
container.register (table_vm);
Expand All @@ -208,7 +214,11 @@ namespace Psequel {
container.register (view_structure_vm);
container.register (table_data_vm);
container.register (view_data_vm);
container.register (navigation);
container.register (query_history_vm);
container.register (query_vm);

// events
conn_vm.subcribe (Event.ACTIVE_CONNECTION, sche_vm);

sche_vm.subcribe (Event.SCHEMA_CHANGED, table_vm);
sche_vm.subcribe (Event.SCHEMA_CHANGED, view_vm);
Expand All @@ -217,6 +227,7 @@ namespace Psequel {

table_vm.subcribe (Event.SELECTED_TABLE_CHANGED, table_structure_vm);
table_vm.subcribe (Event.SELECTED_TABLE_CHANGED, table_data_vm);

view_vm.subcribe (Event.SELECTED_VIEW_CHANGED, view_structure_vm);
view_vm.subcribe (Event.SELECTED_VIEW_CHANGED, view_data_vm);

Expand Down
39 changes: 25 additions & 14 deletions src/services/SQLCompletionProvider.vala
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ namespace Psequel {
private Gtk.FilterListModel model;
private Gtk.StringFilter filter;

public QueryViewModel query_viewmodel { get; set; }

private SchemaViewModel schema_viewmodel;
public SQLCompletionProvider () {
base ();
debug ("SQLCompletionProvider");
this.schema_viewmodel = autowire<SchemaViewModel> ();

static_candidates = new List<Model> ();
for (int i = 0; i < PGListerals.KEYWORDS.length; i++) {
Expand All @@ -31,21 +32,19 @@ namespace Psequel {
static_candidates.append (new Model (PGListerals.RESERVED[i], "RESERVED"));
}

/*
Query viewmodel is not set until the query view is created.
*/
dynamic_candidates = new List<Model> ();
this.notify["query-viewmodel"].connect (() => {

dynamic_candidates = new List<Model> ();
query_viewmodel.current_schema.tables.foreach ((table) => {
dynamic_candidates.append (new Model (table.name, "TABLE"));
});

query_viewmodel.current_schema.views.foreach ((view) => {
dynamic_candidates.append (new Model (view.name, "VIEW"));
});
});
// this.notify["query-viewmodel"].connect (() => {

// dynamic_candidates = new List<Model> ();
// query_viewmodel.current_schema.tables.foreach ((table) => {
// dynamic_candidates.append (new Model (table.name, "TABLE"));
// });

// query_viewmodel.current_schema.views.foreach ((view) => {
// dynamic_candidates.append (new Model (view.name, "VIEW"));
// });
// });

var expression = new Gtk.PropertyExpression (typeof (Model), null, "value");
filter = new Gtk.StringFilter (expression);
Expand Down Expand Up @@ -102,6 +101,18 @@ namespace Psequel {

public async GLib.ListModel populate_async (GtkSource.CompletionContext context, GLib.Cancellable? cancellable) {

/*
Query viewmodel is not set until the query view is created.
*/
dynamic_candidates = new List<Model> ();
schema_viewmodel.current_schema.tables.foreach ((table) => {
dynamic_candidates.append (new Model (table.name, "TABLE"));
});

schema_viewmodel.current_schema.views.foreach ((view) => {
dynamic_candidates.append (new Model (view.name, "VIEW"));
});

var candidates = new ObservableList<Model> ();
candidates.append_all (static_candidates);
candidates.append_all (dynamic_candidates);
Expand Down
33 changes: 9 additions & 24 deletions src/ui/Window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Psequel {
public class Window : Adw.ApplicationWindow {

public static Container? temp;
public Container containter {get; construct;}
public Container containter { get; construct; }

const ActionEntry[] ACTIONS = {
{ "import", import_connection },
Expand All @@ -37,7 +37,7 @@ namespace Psequel {

public NavigationService navigation { get; private set; }
public ConnectionViewModel connection_viewmodel { get; construct; }
public SchemaViewModel schema_viewmodel { get; construct; }
public QueryViewModel query_viewmodel { get; private set; }


public Window (Application app, Container container) {
Expand All @@ -48,10 +48,10 @@ namespace Psequel {
}

construct {
this.navigation = containter.find_type (typeof (NavigationService)) as NavigationService;
this.connection_viewmodel = containter.find_type (typeof (ConnectionViewModel)) as ConnectionViewModel;
this.schema_viewmodel = containter.find_type (typeof (SchemaViewModel)) as SchemaViewModel;
this.navigation = autowire<NavigationService> ();
this.connection_viewmodel = autowire<ConnectionViewModel> ();
this.query_viewmodel = autowire<QueryViewModel> ();

debug ("[CONTRUCT] %s", this.name);
Application.settings.bind ("window-width", this, "default-width", SettingsBindFlags.DEFAULT);
Application.settings.bind ("window-height", this, "default-height", SettingsBindFlags.DEFAULT);
Expand All @@ -62,28 +62,13 @@ namespace Psequel {
overlay.add_toast (toast);
}

[GtkCallback]
public async void on_connect_db (Connection conn) {
debug ("Window connect");
connection_viewmodel.is_connectting = true;
try {
yield schema_viewmodel.connect_db (conn);

navigation.navigate (NavigationService.QUERY_VIEW);
} catch (PsequelError err) {
create_dialog ("Connection Error", err.message).present ();
}

connection_viewmodel.is_connectting = false;
}

// Actions:
public void run_query () {
if (schema_viewmodel.query_viewmodel == null) {
if (query_viewmodel == null) {
return;
}

schema_viewmodel.query_viewmodel.run_selected_query.begin ();
query_viewmodel.run_selected_query.begin ();
}

public void import_connection () {
Expand Down Expand Up @@ -156,7 +141,7 @@ namespace Psequel {

unowned var conns = connection_viewmodel.export_connections ();
var content = ValueConverter.serialize_connection (conns);
var bytes = new Bytes.take (content.data); // Move data to byte so it live when out scope
var bytes = new Bytes.take (content.data); // Move data to byte so it live when out scope
var window = (Window) get_parrent_window (this);

try {
Expand Down
5 changes: 2 additions & 3 deletions src/ui/connection/ConnectionSidebar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ namespace Psequel {

selection_model.bind_property ("selected", this, "selected-connection",
DEFAULT | BIDIRECTIONAL, from_selected, to_selected);

}

// On add, create new connection and select it.
Expand Down Expand Up @@ -90,8 +89,8 @@ namespace Psequel {
[GtkChild]
private unowned Gtk.SingleSelection selection_model;

// [GtkChild]
// private unowned Gtk.ListView listview;
// [GtkChild]
// private unowned Gtk.ListView listview;
}

[GtkTemplate (ui = "/me/ppvan/psequel/gtk/connection-row.ui")]
Expand Down
14 changes: 3 additions & 11 deletions src/ui/connection/ConnectionView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ namespace Psequel {
[GtkTemplate (ui = "/me/ppvan/psequel/gtk/connection-view.ui")]
public class ConnectionView : Adw.Bin {



public ConnectionViewModel viewmodel { get; set; }

public signal void request_database (Connection conn);
public ConnectionViewModel viewmodel { get; private set; }

public ConnectionView (Application app) {
Object ();
Expand All @@ -18,10 +14,7 @@ namespace Psequel {
construct {
debug ("[CONTRUCT] %s", this.name);
setup_paned (paned);

debug ("%s", Window.temp.get_type ().name ());
var container = Window.temp as Psequel.Container;
viewmodel = container.find_type (typeof (ConnectionViewModel)) as ConnectionViewModel;
viewmodel = autowire<ConnectionViewModel> ();
}

[GtkCallback]
Expand All @@ -36,8 +29,7 @@ namespace Psequel {

[GtkCallback]
public void active_connection (Connection conn) {
viewmodel.is_connectting = true;
request_database (conn);
viewmodel.active_connection.begin (conn);
}

[GtkCallback]
Expand Down
8 changes: 3 additions & 5 deletions src/ui/schema/QueryEditor.vala
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,16 @@ namespace Psequel {

construct {
debug ("[CONTRUCT] %s", this.name);
default_setttings ();
this.query_viewmodel = autowire<QueryViewModel> ();
this.query_history_viewmodel = autowire<QueryHistoryViewModel> ();

default_setttings ();
selection_model.bind_property ("selected", this, "selected-query", BindingFlags.BIDIRECTIONAL, from_selected, to_selected);
spinner.bind_property ("spinning", run_query_btn, "sensitive", BindingFlags.INVERT_BOOLEAN);

buffer.changed.connect (highlight_current_query);
buffer.cursor_moved.connect (highlight_current_query);

this.notify["query-viewmodel"].connect (() => {
this.provider.query_viewmodel = query_viewmodel;
});

create_action_group ();
setup_paned (paned);
}
Expand Down
8 changes: 4 additions & 4 deletions src/ui/schema/SchemaSidebar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ namespace Psequel {
}

construct {
this.table_viewmodel = (TableViewModel)Window.temp.find_type (typeof (TableViewModel));
this.view_viewmodel = (ViewViewModel)Window.temp.find_type (typeof (ViewViewModel));
this.schema_viewmodel = (SchemaViewModel)Window.temp.find_type (typeof (SchemaViewModel));
this.navigation_service = (NavigationService)Window.temp.find_type (typeof (NavigationService));
this.table_viewmodel = autowire<TableViewModel> ();
this.view_viewmodel = autowire<ViewViewModel> ();
this.schema_viewmodel = autowire<SchemaViewModel> ();
this.navigation_service = autowire<NavigationService> ();

sql_views.bind_property ("visible-child-name", this, "view-mode", DEFAULT);

Expand Down
3 changes: 1 addition & 2 deletions src/ui/schema/SchemaView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ namespace Psequel {

construct {
setup_paned (paned);
var container = Window.temp;
schema_viewmodel = container.find_type (typeof (SchemaViewModel)) as SchemaViewModel;
schema_viewmodel = autowire<SchemaViewModel> ();
}


Expand Down
2 changes: 1 addition & 1 deletion src/ui/schema/TableDataView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Psequel {
}

construct {
tabledata_viewmodel = Window.temp.find_type (typeof (TableDataViewModel)) as TableDataViewModel;
tabledata_viewmodel = autowire<TableDataViewModel> ();
}

[GtkCallback]
Expand Down
2 changes: 1 addition & 1 deletion src/ui/schema/TableStructureView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Psequel {
}

construct {
this.tablestructure_viewmodel = Window.temp.find_type (typeof (TableStructureViewModel)) as TableStructureViewModel;
this.tablestructure_viewmodel = autowire<TableStructureViewModel> ();

this.filter = new Gtk.StringFilter (null);
filter.expression = new Gtk.PropertyExpression (typeof (BaseType), null, "table");
Expand Down
2 changes: 1 addition & 1 deletion src/ui/schema/ViewDataView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Psequel {
}

construct {
viewdata_viewmodel = Window.temp.find_type (typeof (ViewDataViewModel)) as ViewDataViewModel;
viewdata_viewmodel = autowire<ViewDataViewModel> ();
}

[GtkCallback]
Expand Down
2 changes: 1 addition & 1 deletion src/ui/schema/ViewStructureView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Psequel {
}

construct {
this.viewstructure_viewmodel = Window.temp.find_type (typeof (ViewStructureViewModel)) as ViewStructureViewModel;
this.viewstructure_viewmodel = autowire<ViewStructureViewModel> ();

var expresion = new Gtk.PropertyExpression (typeof(BaseType), null, "table");
this.filter = new Gtk.StringFilter (expresion);
Expand Down
1 change: 1 addition & 0 deletions src/utils/Event.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace Psequel {
public const string SCHEMA_CHANGED = "schema-changed";
public const string SELECTED_TABLE_CHANGED = "selected-table-changed";
public const string SELECTED_VIEW_CHANGED = "selected-view-changed";
public const string ACTIVE_CONNECTION = "active-connection";
public string type;
public Object data;

Expand Down
5 changes: 5 additions & 0 deletions src/utils/helpers.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ namespace Psequel {
});
}

public T autowire<T> () {
var container = Window.temp;
return (T)container.find_type (typeof (T));
}

public Adw.MessageDialog create_dialog (string heading, string body) {
var window = Application.app.active_window;
var dialog = new Adw.MessageDialog (window, heading, body);
Expand Down
Loading