Skip to content

Commit

Permalink
[gvt-prj-plugin] Fix search on multiple name in different target
Browse files Browse the repository at this point in the history
  • Loading branch information
gandalfn committed Jun 29, 2012
1 parent 0e4f5bd commit 0b61ed0
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 38 deletions.
63 changes: 25 additions & 38 deletions plugins/prj/manager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -530,42 +530,29 @@ public class GVT.Manager : GLib.Object
build_target_for_filename (string inFilename)
{
bool ret = false;
string[] filename= GLib.Path.get_dirname (inFilename).substring (m_Project.path.length + 1).split ("/");
unowned Item? item = null;
int cpt = filename.length;
string filename= inFilename.substring (m_Project.path.length + 1);
unowned Item? item = m_Project.find_path (filename);

if (cpt > 0)
if (item != null)
{
do
{
string name = GLib.Path.get_basename (inFilename);
for (int i = filename.length - 1; i >= cpt; --i)
name = filename[i] + "/" + name;
item = m_Project.find (name);
cpt--;
} while (item == null && cpt >= 0);

if (item != null)
{
unowned Item? p = null;
for (p = item.parent; p != null && !(p is Target) && !(p is Group); p = p.parent);
unowned Item? p = null;
for (p = item.parent; p != null && !(p is Target) && !(p is Group); p = p.parent);

if (item != null && p != null)
if (item != null && p != null)
{
if (p is Target)
{
if (p is Target)
{
unowned Target? target = (Target?)p;
debug ("Build %s", target.name);
build_target (target);
ret = true;
}
else if (p is Group)
{
unowned Group? group = (Group?)p;
debug ("Build %s", group.name);
build (group);
ret = true;
}
unowned Target? target = (Target?)p;
debug ("Build %s", target.name);
build_target (target);
ret = true;
}
else if (p is Group)
{
unowned Group? group = (Group?)p;
debug ("Build %s", group.name);
build (group);
ret = true;
}
}
}
Expand Down Expand Up @@ -603,8 +590,8 @@ public class GVT.Manager : GLib.Object
public void
update_tag (string inFilename)
{
string name = GLib.Path.get_basename (inFilename);
unowned Item? item = m_Project.find (name);
string filename= inFilename.substring (m_Project.path.length + 1);
unowned Item? item = m_Project.find_path (filename);
if (item != null && item is Source)
{
unowned Source? source = (Source?)item;
Expand All @@ -620,8 +607,8 @@ public class GVT.Manager : GLib.Object
public void
add_tag (string inFilename)
{
string name = GLib.Path.get_basename (inFilename);
unowned Item? item = m_Project.find (name);
string filename= inFilename.substring (m_Project.path.length + 1);
unowned Item? item = m_Project.find_path (filename);
if (item != null && item is Source)
{
unowned Source? source = (Source?)item;
Expand All @@ -637,8 +624,8 @@ public class GVT.Manager : GLib.Object
public void
remove_tag (string inFilename)
{
string name = GLib.Path.get_basename (inFilename);
unowned Item? item = m_Project.find (name);
string filename= inFilename.substring (m_Project.path.length + 1);
unowned Item? item = m_Project.find_path (filename);
if (item != null && item is Source)
{
unowned Source? source = (Source?)item;
Expand Down
42 changes: 42 additions & 0 deletions plugins/prj/node.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,41 @@ public abstract class GVT.Node : Item
m_Childs.compare_func = Item.compare;
}

private unowned Item?
find_path_array (string[] inPath, int inPos)
requires (inPos < inPath.length)
{
unowned Item? item = get (inPath[inPos]);

if (item == null && inPos < inPath.length - 1)
{
string f = inPath[inPos];
for (int cpt = inPos + 1; cpt < inPath.length; cpt++)
{
f += "/" + inPath[cpt];
}
return find (f);
}

if (item != null && inPos < inPath.length - 1)
{
if (item is Node)
{
item = ((Node)item).find_path_array (inPath, inPos + 1);
}
else
{
item = null;
}
}
else if (item == null && inPos == inPath.length - 1)
{
item = find (inPath[inPos]);
}

return item;
}

public Set.Iterator<Item>
iterator ()
{
Expand Down Expand Up @@ -79,6 +114,13 @@ public abstract class GVT.Node : Item
return ret;
}

public unowned Item?
find_path (string inPath)
{
string[] path = inPath.split ("/");
return find_path_array (path, 0);
}

public bool
add (Item inChild)
{
Expand Down

0 comments on commit 0b61ed0

Please sign in to comment.