WIP: Filter by path

This commit is contained in:
Alberto Fanjul 2019-01-14 08:59:17 +01:00
parent 5455a5ebe1
commit 4e0d78b83e
11 changed files with 187 additions and 22 deletions

View file

@ -127,6 +127,22 @@ class DashView : Gtk.Grid, GitgExt.UIElement, GitgExt.Activity, GitgExt.Selectab
owned get { return null; }
}
private string d_search_path;
public string search_path
{
owned get { return d_search_path; }
set
{
if (d_search_path != value)
{
d_search_path = value;
update_search_path();
}
}
}
private string d_search_text;
public string search_text
@ -150,6 +166,10 @@ class DashView : Gtk.Grid, GitgExt.UIElement, GitgExt.Activity, GitgExt.Selectab
public bool search_visible { get; set; }
private void update_search_path()
{
}
private void update_search_text()
{
if (d_repository_list_box != null)

View file

@ -291,7 +291,8 @@ public class UIElements<T> : Object
public UIElements.with_builtin(T[] builtin,
Peas.ExtensionSet extensions,
Gtk.Stack? stack = null)
Gtk.Stack? stack = null,
string? search_path = null)
{
d_extensions = extensions;
d_stack = stack;
@ -304,7 +305,10 @@ public class UIElements<T> : Object
foreach (var b in builtin)
{
GitgExt.UIElement elem = (GitgExt.UIElement)b;
if (elem is Gitg.DiffView) {
var diff_view = elem as Gitg.DiffView;
diff_view.search_path = search_path;
}
d_builtin_elements[elem.id] = i++;
add_ui_element(elem);
}
@ -323,9 +327,9 @@ public class UIElements<T> : Object
}
public UIElements(Peas.ExtensionSet extensions,
Gtk.Stack? stack = null)
Gtk.Stack? stack = null, string? search_path = null)
{
this.with_builtin(new T[] {}, extensions, stack);
this.with_builtin(new T[] {}, extensions, stack, search_path);
}
}

View file

@ -89,8 +89,9 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
[GtkChild]
private unowned Gtk.SearchBar d_search_bar;
[GtkChild]
private unowned Gtk.SearchEntry d_search_entry;
private Gtk.SearchEntry d_search_entry_text;
[GtkChild]
private unowned Gtk.SearchEntry d_search_entry_path;
[GtkChild]
private unowned Gtk.Stack d_main_stack;
@ -242,11 +243,11 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
if (button.get_active())
{
d_search_entry.grab_focus_without_selecting();
d_search_entry_text.grab_focus_without_selecting();
d_search_entry.text = searchable.search_text;
d_search_entry_text.text = searchable.search_text;
searchable.search_visible = true;
searchable.search_entry = d_search_entry;
searchable.search_entry = d_search_entry_text;
}
else
{
@ -256,7 +257,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
}
[GtkCallback]
private void search_entry_changed(Gtk.Editable entry)
private void search_entry_text_changed(Gtk.Editable entry)
{
var searchable = current_activity as GitgExt.Searchable;
var ntext = ((Gtk.Entry) entry).text;
@ -267,6 +268,18 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
}
}
[GtkCallback]
private void search_entry_path_changed(Gtk.Editable entry)
{
var searchable = current_activity as GitgExt.Searchable;
var ntext = (entry as Gtk.Entry).text;
if (ntext != searchable.search_path)
{
searchable.search_path = ntext;
}
}
[GtkCallback]
public bool on_key_pressed (Gtk.Widget widget, Gdk.EventKey event) {
bool ret = d_search_bar.handle_event(event);
@ -323,7 +336,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
d_activities_model = Builder.load_object<MenuModel>("ui/gitg-menus.ui", "win-menu-views");
// search bar
d_search_bar.connect_entry(d_search_entry);
d_search_bar.connect_entry(d_search_entry_text);
d_search_button.bind_property("active",
d_search_bar,
"search-mode-enabled",
@ -813,7 +826,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
if (searchable != null)
{
d_search_button.visible = true;
d_search_entry.text = searchable.search_text;
d_search_entry_text.text = searchable.search_text;
d_search_button.active = searchable.search_visible;
d_searchable_available_binding = searchable.bind_property("search-available",
@ -827,7 +840,7 @@ public class Window : Gtk.ApplicationWindow, GitgExt.Application, Initable
d_search_button.visible = false;
d_search_button.active = false;
d_search_button.sensitive = false;
d_search_entry.text = "";
d_search_entry_text.text = "";
}
var selectable = (current as GitgExt.Selectable);

View file

@ -1238,6 +1238,17 @@ namespace GitgHistory
}
public string search_text { owned get; set; default = ""; }
private string d_search_path;
public string search_path
{
owned get { return d_search_path; }
set
{
d_search_path = value;
d_commit_list_model.search_path = d_search_path;
d_commit_list_model.reload();
}
}
public bool search_visible { get; set; }
}
}

View file

@ -247,11 +247,44 @@
<property name="can_focus">False</property>
<property name="show-close-button">False</property>
<child>
<object class="GtkSearchEntry" id="d_search_entry">
<object class="GtkBox" id="search_box">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="width-request">500</property>
<signal name="changed" handler="search_entry_changed" swapped="no"/>
<property name="orientation">horizontal</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="label_text">
<property name="label" translatable="yes">Text:</property>
<property name="visible">True</property>
</object>
<packing>
<property name="expand">False</property>
</packing>
</child>
<child>
<object class="GtkSearchEntry" id="d_search_entry_text">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="width-request">500</property>
<signal name="changed" handler="search_entry_text_changed" swapped="no"/>
</object>
</child>
<child>
<object class="GtkLabel" id="label_path">
<property name="label" translatable="yes">Path:</property>
<property name="visible">True</property>
</object>
<packing>
<property name="expand">False</property>
</packing>
</child>
<child>
<object class="GtkSearchEntry" id="d_search_entry_path">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="width-request">300</property>
<signal name="changed" handler="search_entry_path_changed" swapped="no"/>
</object>
</child>
</object>
</child>
</object>

View file

@ -29,6 +29,7 @@ namespace GitgExt
public interface Searchable : Object, Activity
{
public abstract string search_text { owned get; set; }
public abstract string search_path { owned get; set; }
public abstract bool search_visible { get; set; }
public abstract bool search_available { get; }
public abstract Gtk.Entry? search_entry { set; }

View file

@ -104,6 +104,10 @@ namespace Gitg
foreach (var lane in commit.get_lanes())
{
if (!lane.interesting)
{
continue;
}
var color = lane.color;
context.set_source_rgb(color.r, color.g, color.b);
@ -137,6 +141,11 @@ namespace Gitg
foreach (var lane in commit.get_lanes())
{
if (!lane.interesting)
{
continue;
}
if ((lane.tag & LaneTag.HIDDEN) != 0)
{
++to;
@ -214,7 +223,7 @@ namespace Gitg
context.set_source_rgb(0, 0, 0);
context.stroke_preserve();
if (commit.lane != null)
if (commit.lane != null && commit.lane.interesting)
{
var color = commit.lane.color;
context.set_source_rgb(color.r, color.g, color.b);

View file

@ -123,6 +123,8 @@ namespace Gitg
_permanent_lanes = value;
}
public string search_path { get; set; default=""; }
public signal void started();
public signal void update(uint added);
public signal void finished();
@ -418,7 +420,63 @@ namespace Gitg
int mylane;
SList<Lane> lanes;
bool finded = d_lanes.next(commit, out lanes, out mylane, true);
var interesting = true;
if (search_path != null && search_path != "")
{
interesting = false;
var tree = commit.get_tree();
Commit c = commit;
var opts = new Ggit.DiffOptions();
opts.flags |= Ggit.DiffOption.IGNORE_WHITESPACE;
opts.flags |= Ggit.DiffOption.PATIENCE;
opts.n_context_lines = 3;
opts.n_interhunk_lines = 3;
opts.flags |= Ggit.DiffOption.SHOW_BINARY;
var diff = c.get_diff(opts, 0);
var search_path_copy = search_path;
try {
diff.foreach(
(delta, progress) => {
var old_file_path = delta.get_old_file().get_path();
var new_file_path = delta.get_new_file().get_path();
if (new_file_path.contains(search_path_copy) || old_file_path.contains(search_path_copy)) {
return -7;
}
return 0;
},
(delta, binary) => {
return interesting ? -7: 0;
},
(delta, hunk) => {
return interesting ? -7: 0;
},
(delta, hunk, line) => {
return interesting ? -7: 0;
}
);
/*
tree.walk(Ggit.TreeWalkMode.PRE, (root, entry) => {
var file = root.concat(entry.get_name());
var found = file.contains(search_path);
return found ? -7 : 0;
});
*/
} catch (Error e) {
interesting = e.code == -7;
}
/*
if (!interesting) {
continue;
}
*/
}
bool finded = d_lanes.next(commit, interesting, out lanes, out mylane, true);
if (finded)
{
debug ("finded parent for %s %s\n", commit.get_subject(), commit.get_id().to_string());
@ -450,7 +508,7 @@ namespace Gitg
{
var miss_commit = iter.get();
debug ("trying again %s %s", miss_commit.get_subject(), miss_commit.get_id().to_string());
bool tmp_finded = d_lanes.next(miss_commit, out lanes, out mylane);
bool tmp_finded = d_lanes.next(miss_commit, interesting, out lanes, out mylane);
if (tmp_finded)
{
finded = true;
@ -575,7 +633,7 @@ namespace Gitg
public Gtk.TreeModelFlags get_flags()
{
return Gtk.TreeModelFlags.LIST_ONLY |
Gtk.TreeModelFlags.ITERS_PERSIST;
Gtk.TreeModelFlags.ITERS_PERSIST;
}
public bool get_iter(out Gtk.TreeIter iter, Gtk.TreePath path)

View file

@ -57,6 +57,7 @@ public class Gitg.DiffView : Gtk.Grid
private uint d_reveal_options_timeout;
private uint d_unreveal_options_timeout;
public string search_path { owned get; set; }
private static Gee.HashSet<string> s_image_mime_types;
public Ggit.DiffOptions options
@ -773,6 +774,11 @@ public class Gitg.DiffView : Gtk.Grid
return 1;
}
var new_file_path = delta.get_new_file().get_path();
var old_file_path = delta.get_old_file().get_path();
if (search_path != null && search_path != "" && (!new_file_path.contains(search_path) || !old_file_path.contains(search_path))){
return 0;
}
add_file();
DiffViewFileInfo? info = null;

View file

@ -38,6 +38,7 @@ public class Lane : Object
public SList<int> from;
public LaneTag tag;
public Ggit.OId? boundary_id;
public bool interesting {get; set;}
public Lane()
{
@ -61,6 +62,7 @@ public class Lane : Object
Lane ret = new Lane.with_color(color);
ret.from = from.copy();
ret.tag = tag;
ret.interesting = interesting;
ret.boundary_id = boundary_id;
return ret;
@ -71,6 +73,7 @@ public class Lane : Object
Lane ret = new Lane.with_color(color.copy());
ret.from = from.copy();
ret.tag = tag;
ret.interesting = interesting;
ret.boundary_id = boundary_id;
return ret;

View file

@ -37,6 +37,7 @@ public class Lanes : Object
{
public Lane lane;
public int inactive;
public bool interesting {get; set; default=true; }
public Ggit.OId? from;
public Ggit.OId? to;
@ -47,6 +48,7 @@ public class Lanes : Object
this.from = from;
this.to = to;
this.lane = new Lane.with_color(color);
this.lane.interesting = interesting;
this.inactive = 0;
}
@ -63,6 +65,7 @@ public class Lanes : Object
lane.tag = LaneTag.NONE;
lane.from = new SList<int>();
lane.interesting = interesting;
if (!hidden)
{
@ -155,7 +158,8 @@ public class Lanes : Object
d_previous = new SList<weak Commit>();
}
public bool next(Commit next,
public bool next(Commit next,
bool interesting,
out SList<Lane> lanes,
out int nextpos,
bool save_miss = false)
@ -185,6 +189,7 @@ public class Lanes : Object
{
// there is no lane reserved for this commit, add a new lane
mylane = new LaneContainer(myoid, null);
mylane.interesting = interesting;
d_lanes.add(mylane);
nextpos = (int)d_lanes.size - 1;
@ -193,6 +198,8 @@ public class Lanes : Object
{
// copy the color here because the commit is a new stop
mylane.lane.color = mylane.lane.color.copy();
mylane.lane.interesting = interesting;
mylane.interesting = interesting;
mylane.to = null;
mylane.from = next.get_id();