Do not use arrays as properties

This commit is contained in:
jonykalavera 2019-04-06 15:50:54 +02:00 committed by Alberto Fanjul
parent 1953defe63
commit f689d8b32d
14 changed files with 100 additions and 89 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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);

View file

@ -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)
{
var ret = new T[0];
foreach (var elem in d_available_elements)
{
ret += (T)elem;
}
return ret;
ret += (T)elem;
}
return ret;
}
public void update()

View file

@ -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);

View file

@ -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();
}

View file

@ -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;
}
}
}

View file

@ -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)

View file

@ -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++)
{

View file

@ -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;
buffer.get_start_iter(out iter);
while (buffer.forward_iter_to_source_mark(ref iter, d_selection_category))
{
var ret = new int[0];
Gtk.TextIter iter;
var buffer = source_view.buffer as Gtk.SourceBuffer;
buffer.get_start_iter(out iter);
while (buffer.forward_iter_to_source_mark(ref iter, d_selection_category))
{
ret += iter.get_line();
}
return ret;
ret += iter.get_line();
}
return ret;
}
public DiffViewFileSelectable(Gtk.SourceView source_view)

View file

@ -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)

View file

@ -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

View file

@ -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;