[gitg] Do not use arrays as properties
- From: Alberto Fanjul <albfan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Do not use arrays as properties
- Date: Thu, 2 May 2019 02:22:11 +0000 (UTC)
commit f689d8b32db79ad99000d2fb7e3c706bb7e4fbfb
Author: jonykalavera <mr jony gmail com>
Date: Sat Apr 6 15:50:54 2019 +0200
Do not use arrays as properties
gitg/commit/gitg-commit.vala | 16 ++++++-------
gitg/gitg-dash-view.vala | 6 ++---
gitg/gitg-ref-action-delete.vala | 4 ++--
gitg/gitg-ref-action-push.vala | 4 ++--
gitg/gitg-ui-elements.vala | 17 ++++++-------
gitg/gitg-window.vala | 4 ++--
gitg/history/gitg-history.vala | 2 +-
libgitg-ext/gitg-ext-user-query.vala | 33 ++++++++++++++++----------
libgitg/gitg-commit-model.vala | 23 ++++++++++++++----
libgitg/gitg-diff-view-file-renderer-text.vala | 2 +-
libgitg/gitg-diff-view-file-selectable.vala | 23 ++++++++----------
libgitg/gitg-diff-view.vala | 21 +++++++---------
libgitg/gitg-repository-list-box.vala | 21 +++++++---------
tests/gitg/application-mock.vala | 9 +++----
14 files changed, 98 insertions(+), 87 deletions(-)
---
diff --git a/gitg/commit/gitg-commit.vala b/gitg/commit/gitg-commit.vala
index 5555cec1..e7ff51c8 100644
--- a/gitg/commit/gitg-commit.vala
+++ b/gitg/commit/gitg-commit.vala
@@ -1299,7 +1299,7 @@ namespace GitgCommit
private async void stage_unstage_selection(bool staging) throws Error
{
- var selection = d_main.diff_view.selection;
+ var selection = d_main.diff_view.get_selection();
var stage = application.repository.stage;
foreach (var pset in selection)
@@ -1317,7 +1317,7 @@ namespace GitgCommit
private async void discard_selection() throws Error
{
- var selection = d_main.diff_view.selection;
+ var selection = d_main.diff_view.get_selection();
var stage = application.repository.stage;
foreach (var pset in selection)
@@ -1337,10 +1337,10 @@ namespace GitgCommit
q.message = secondary;
q.message_type = Gtk.MessageType.QUESTION;
- q.responses = new GitgExt.UserQueryResponse[] {
+ q.set_responses(new GitgExt.UserQueryResponse[] {
new GitgExt.UserQueryResponse(_("_Cancel"), Gtk.ResponseType.CANCEL),
new GitgExt.UserQueryResponse(_("Discard"), Gtk.ResponseType.OK),
- };
+ });
q.default_response = Gtk.ResponseType.OK;
@@ -1503,10 +1503,10 @@ namespace GitgCommit
q.message = secondary;
q.message_type = Gtk.MessageType.QUESTION;
- q.responses = new GitgExt.UserQueryResponse[] {
+ q.set_responses(new GitgExt.UserQueryResponse[] {
new GitgExt.UserQueryResponse(_("_Cancel"), Gtk.ResponseType.CANCEL),
new GitgExt.UserQueryResponse(_("Discard"), Gtk.ResponseType.OK)
- };
+ });
q.default_response = Gtk.ResponseType.OK;
@@ -1618,10 +1618,10 @@ namespace GitgCommit
q.message = secondary;
q.message_type = Gtk.MessageType.QUESTION;
- q.responses = new GitgExt.UserQueryResponse[] {
+ q.set_responses(new GitgExt.UserQueryResponse[] {
new GitgExt.UserQueryResponse(_("_Cancel"), Gtk.ResponseType.CANCEL),
new GitgExt.UserQueryResponse(primary, Gtk.ResponseType.OK)
- };
+ });
q.default_response = Gtk.ResponseType.OK;
q.default_is_destructive = true;
diff --git a/gitg/gitg-dash-view.vala b/gitg/gitg-dash-view.vala
index f6853edf..1448cfd4 100644
--- a/gitg/gitg-dash-view.vala
+++ b/gitg/gitg-dash-view.vala
@@ -178,7 +178,7 @@ class DashView : Gtk.Grid, GitgExt.UIElement, GitgExt.Activity, GitgExt.Selectab
remove_button.show();
remove_button.clicked.connect(() => {
- foreach (var sel in d_repository_list_box.selection)
+ foreach (var sel in d_repository_list_box.get_selection())
{
sel.request_remove();
}
@@ -449,10 +449,10 @@ class DashView : Gtk.Grid, GitgExt.UIElement, GitgExt.Activity, GitgExt.Selectab
q.message_type = Gtk.MessageType.QUESTION;
q.message_use_markup = true;
- q.responses = new GitgExt.UserQueryResponse[] {
+ q.set_responses(new GitgExt.UserQueryResponse[] {
new GitgExt.UserQueryResponse(_("_Cancel"), Gtk.ResponseType.CANCEL),
new GitgExt.UserQueryResponse(_("Create repository"), Gtk.ResponseType.OK)
- };
+ });
q.default_response = Gtk.ResponseType.OK;
diff --git a/gitg/gitg-ref-action-delete.vala b/gitg/gitg-ref-action-delete.vala
index 9475b615..d25337ad 100644
--- a/gitg/gitg-ref-action-delete.vala
+++ b/gitg/gitg-ref-action-delete.vala
@@ -84,10 +84,10 @@ class RefActionDelete : GitgExt.UIElement, GitgExt.Action, GitgExt.RefAction, Ob
query.message = (_("Are you sure that you want to permanently delete the remote
branch %s?")).printf(name);
}
- query.responses = new GitgExt.UserQueryResponse[] {
+ query.set_responses(new GitgExt.UserQueryResponse[] {
new GitgExt.UserQueryResponse(_("Cancel"), Gtk.ResponseType.CANCEL),
new GitgExt.UserQueryResponse(_("Delete"), Gtk.ResponseType.OK)
- };
+ });
query.default_response = Gtk.ResponseType.OK;
query.response.connect(on_response);
diff --git a/gitg/gitg-ref-action-push.vala b/gitg/gitg-ref-action-push.vala
index 0d5e7b2a..9ff91417 100644
--- a/gitg/gitg-ref-action-push.vala
+++ b/gitg/gitg-ref-action-push.vala
@@ -133,10 +133,10 @@ class RefActionPush : GitgExt.UIElement, GitgExt.Action, GitgExt.RefAction, Obje
query.title = (_("Push branch %s")).printf(branch_name);
query.message = (_("Are you sure that you want to push the branch %s?")).printf(branch_name);
- query.responses = new GitgExt.UserQueryResponse[] {
+ query.set_responses(new GitgExt.UserQueryResponse[] {
new GitgExt.UserQueryResponse(_("Cancel"), Gtk.ResponseType.CANCEL),
new GitgExt.UserQueryResponse(_("Push"), Gtk.ResponseType.OK)
- };
+ });
query.default_response = Gtk.ResponseType.OK;
query.response.connect(on_response);
diff --git a/gitg/gitg-ui-elements.vala b/gitg/gitg-ui-elements.vala
index 236a6e9b..429ddf88 100644
--- a/gitg/gitg-ui-elements.vala
+++ b/gitg/gitg-ui-elements.vala
@@ -51,19 +51,16 @@ public class UIElements<T> : Object
}
}
- public T[] available_elements
+ public T[] get_available_elements()
{
- owned get
- {
- var ret = new T[0];
-
- foreach (var elem in d_available_elements)
- {
- ret += (T)elem;
- }
+ var ret = new T[0];
- return ret;
+ foreach (var elem in d_available_elements)
+ {
+ ret += (T)elem;
}
+
+ return ret;
}
public void update()
diff --git a/gitg/gitg-window.vala b/gitg/gitg-window.vala
index 42c489d7..1aeb9b9c 100644
--- a/gitg/gitg-window.vala
+++ b/gitg/gitg-window.vala
@@ -144,7 +144,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
return false;
}
- var elems = d_activities.available_elements;
+ var elems = d_activities.get_available_elements();
i--;
if (i >= elems.length)
@@ -1092,7 +1092,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
dlg.set_default_response(query.default_response);
- foreach (var response in query.responses)
+ foreach (var response in query.get_responses())
{
var button = dlg.add_button(response.text, response.response_type);
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index 95833869..a2172357 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -1087,7 +1087,7 @@ namespace GitgHistory
}
}
- d_commit_list_model.permanent_lanes = permanent;
+ d_commit_list_model.set_permanent_lanes(permanent);
d_commit_list_model.set_include(include.to_array());
d_commit_list_model.reload();
}
diff --git a/libgitg-ext/gitg-ext-user-query.vala b/libgitg-ext/gitg-ext-user-query.vala
index 7935c3a4..c4044221 100644
--- a/libgitg-ext/gitg-ext-user-query.vala
+++ b/libgitg-ext/gitg-ext-user-query.vala
@@ -38,7 +38,16 @@ public class UserQuery : Object
public string message { get; set; }
public Gtk.MessageType message_type { get; set; }
public Gtk.ResponseType default_response { get; set; default = Gtk.ResponseType.CLOSE; }
- public UserQueryResponse[] responses { get; set; }
+ public UserQueryResponse[] _responses;
+
+ public UserQueryResponse[] get_responses() {
+ return _responses;
+ }
+
+ public void set_responses(UserQueryResponse[] value) {
+ _responses = value;
+ }
+
public bool default_is_destructive { get; set; }
public bool message_use_markup { get; set; }
@@ -52,21 +61,21 @@ public class UserQuery : Object
var l = va_list();
var resps = new UserQueryResponse[0];
- while (true) {
- string? text = l.arg();
+ while (true) {
+ string? text = l.arg();
- if (text == null) {
- break;
- }
+ if (text == null) {
+ break;
+ }
- resps += new UserQueryResponse(text, l.arg());
- }
+ resps += new UserQueryResponse(text, l.arg());
+ }
- responses = resps;
+ set_responses(resps);
- if (resps.length > 0) {
- default_response = resps[resps.length - 1].response_type;
- }
+ if (resps.length > 0) {
+ default_response = resps[resps.length - 1].response_type;
+ }
}
}
diff --git a/libgitg/gitg-commit-model.vala b/libgitg/gitg-commit-model.vala
index 7964e51a..e473dc52 100644
--- a/libgitg/gitg-commit-model.vala
+++ b/libgitg/gitg-commit-model.vala
@@ -113,7 +113,15 @@ namespace Gitg
}
}
- public Ggit.OId[] permanent_lanes { get; set; }
+ private Ggit.OId[] _permanent_lanes;
+
+ public Ggit.OId[] get_permanent_lanes() {
+ return _permanent_lanes;
+ }
+
+ public void set_permanent_lanes(Ggit.OId[] value) {
+ _permanent_lanes = value;
+ }
public signal void started();
public signal void update(uint added);
@@ -173,7 +181,7 @@ namespace Gitg
{
cancel();
- if (d_repository == null || d_include.length == 0)
+ if (d_repository == null || get_include().length == 0)
{
return;
}
@@ -218,12 +226,17 @@ namespace Gitg
public void set_include(Ggit.OId[] ids)
{
- d_include = ids;
+ this.d_include = ids;
+ }
+
+ public Ggit.OId[] get_include()
+ {
+ return this.d_include;
}
public void set_exclude(Ggit.OId[] ids)
{
- d_exclude = ids;
+ this.d_exclude = ids;
}
private void notify_batch(owned SourceFunc? finishedcb)
@@ -302,7 +315,7 @@ namespace Gitg
var wait_elapsed = wait_elapsed_initial;
- var permlanes = permanent_lanes;
+ var permlanes = get_permanent_lanes();
ThreadFunc<void*> run = () => {
if (d_walker == null)
diff --git a/libgitg/gitg-diff-view-file-renderer-text.vala b/libgitg/gitg-diff-view-file-renderer-text.vala
index d35e5a67..ee545ddf 100644
--- a/libgitg/gitg-diff-view-file-renderer-text.vala
+++ b/libgitg/gitg-diff-view-file-renderer-text.vala
@@ -139,7 +139,7 @@ class Gitg.DiffViewFileRendererText : Gtk.SourceView, DiffSelectable, DiffViewFi
return ret;
}
- var selected = d_selectable.selected_lines;
+ var selected = d_selectable.get_selected_lines();
for (var i = 0; i < selected.length; i++)
{
diff --git a/libgitg/gitg-diff-view-file-selectable.vala b/libgitg/gitg-diff-view-file-selectable.vala
index afbec967..369d7ae6 100644
--- a/libgitg/gitg-diff-view-file-selectable.vala
+++ b/libgitg/gitg-diff-view-file-selectable.vala
@@ -45,24 +45,21 @@ class Gitg.DiffViewFileSelectable : Object
get; private set;
}
- public int[] selected_lines
+ public int[] get_selected_lines()
{
- owned get
- {
- var ret = new int[0];
- Gtk.TextIter iter;
-
- var buffer = source_view.buffer as Gtk.SourceBuffer;
+ var ret = new int[0];
+ Gtk.TextIter iter;
- buffer.get_start_iter(out iter);
+ var buffer = source_view.buffer as Gtk.SourceBuffer;
- while (buffer.forward_iter_to_source_mark(ref iter, d_selection_category))
- {
- ret += iter.get_line();
- }
+ buffer.get_start_iter(out iter);
- return ret;
+ while (buffer.forward_iter_to_source_mark(ref iter, d_selection_category))
+ {
+ ret += iter.get_line();
}
+
+ return ret;
}
public DiffViewFileSelectable(Gtk.SourceView source_view)
diff --git a/libgitg/gitg-diff-view.vala b/libgitg/gitg-diff-view.vala
index f4076f5b..8680f44b 100644
--- a/libgitg/gitg-diff-view.vala
+++ b/libgitg/gitg-diff-view.vala
@@ -648,24 +648,21 @@ public class Gitg.DiffView : Gtk.Grid
auto_change_expanded(true);
}
- public PatchSet[] selection
+ public PatchSet[] get_selection()
{
- owned get
+ var ret = new PatchSet[0];
+
+ foreach (var file in d_grid_files.get_children())
{
- var ret = new PatchSet[0];
+ var sel = (file as Gitg.DiffViewFile).renderer as DiffSelectable;
- foreach (var file in d_grid_files.get_children())
+ if (sel != null && sel.has_selection && sel.selection.patches.length != 0)
{
- var sel = (file as Gitg.DiffViewFile).renderer as DiffSelectable;
-
- if (sel != null && sel.has_selection && sel.selection.patches.length != 0)
- {
- ret += sel.selection;
- }
+ ret += sel.selection;
}
-
- return ret;
}
+
+ return ret;
}
private void update_hide_show_options(Gdk.Window window, int ex, int ey)
diff --git a/libgitg/gitg-repository-list-box.vala b/libgitg/gitg-repository-list-box.vala
index df7ca63f..48cf5dfa 100644
--- a/libgitg/gitg-repository-list-box.vala
+++ b/libgitg/gitg-repository-list-box.vala
@@ -610,24 +610,21 @@ namespace Gitg
return row;
}
- public Row[] selection
+ public Row[] get_selection()
{
- owned get
+ var ret = new Row[0];
+
+ foreach (var row in get_children())
{
- var ret = new Row[0];
+ var r = (Row)row;
- foreach (var row in get_children())
+ if (r.selected)
{
- var r = (Row)row;
-
- if (r.selected)
- {
- ret += r;
- }
+ ret += r;
}
-
- return ret;
}
+
+ return ret;
}
public bool has_selection
diff --git a/tests/gitg/application-mock.vala b/tests/gitg/application-mock.vala
index b8265e24..58df8b95 100644
--- a/tests/gitg/application-mock.vala
+++ b/tests/gitg/application-mock.vala
@@ -94,12 +94,13 @@ class Gitg.Test.Application : Gitg.Test.Repository, GitgExt.Application
assert_inteq(expected.query.default_response, query.default_response);
assert_booleq(expected.query.default_is_destructive, query.default_is_destructive);
assert_booleq(expected.query.message_use_markup, query.message_use_markup);
- assert_inteq(expected.query.responses.length, query.responses.length);
+ var responses = expected.query.get_responses();
+ assert_inteq(responses.length, responses.length);
- for (var i = 0; i < expected.query.responses.length; i++)
+ for (var i = 0; i < responses.length; i++)
{
- assert_inteq(expected.query.responses[i].response_type,
query.responses[i].response_type);
- assert_streq(expected.query.responses[i].text, query.responses[i].text);
+ assert_inteq(responses[i].response_type, query.get_responses()[i].response_type);
+ assert_streq(responses[i].text, query.get_responses()[i].text);
}
return expected.response;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]