Skip to content

Commit

Permalink
ConfigRawParams: sort by Fav
Browse files Browse the repository at this point in the history
  • Loading branch information
meee1 committed Feb 2, 2018
1 parent 623ab5b commit e9b6b9d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
11 changes: 10 additions & 1 deletion GCSViews/ConfigurationView/ConfigFriendlyParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,24 @@ private void BindParamList()

var toadd = new List<Control>();

_params.OrderBy(x => x.Key).ForEach(x =>
var list = Settings.Instance.GetList("fav_params");

_params.OrderBy(x =>
{
if (list.Contains(x.Key))
return "0" + x.Key;
return x.Key;
}).ForEach(x =>
{
AddControl(x, toadd); //,ref ypos);
Console.WriteLine("add ctl " + x.Key + " " + DateTime.Now.ToString("ss.fff"));
});

tableLayoutPanel1.SuspendLayout();
tableLayoutPanel1.Visible = false;
tableLayoutPanel1.Controls.AddRange(toadd.ToArray());
tableLayoutPanel1.Visible = true;
tableLayoutPanel1.ResumeLayout();

Console.WriteLine("Add done" + DateTime.Now.ToString("ss.fff"));

Expand Down
17 changes: 15 additions & 2 deletions GCSViews/ConfigurationView/ConfigRawParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,22 @@ private void Params_CellContentClick(object sender, DataGridViewCellEventArgs e)

if (e.ColumnIndex == 5)
{
Params.Sort(Command, ListSortDirection.Ascending);
var check = Params[e.ColumnIndex, e.RowIndex].EditedFormattedValue;
var name = Params[Command.Index, e.RowIndex].Value.ToString();

if (check != null && (bool)check)
{
// add entry
Settings.Instance.AppendList("fav_params", name);
}
else
{
// remove entry
var list = Settings.Instance.GetList("fav_params");
Settings.Instance.SetList("fav_params", list.Where(s => s != name));
}

Settings.Instance.AppendList("fav_params", Params[Command.Index, e.RowIndex].Value.ToString());
Params.Sort(Command, ListSortDirection.Ascending);
}
}

Expand Down
26 changes: 25 additions & 1 deletion GCSViews/ConfigurationView/ConfigRawParamsTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ internal void processToScreen()
foreach (string item in MainV2.comPort.MAV.param.Keys)
sorted.Add(item);

sorted.Sort();
sorted.Sort(ComparisonTree);

var roots = new List<data>();
var lastroot = new data();
Expand Down Expand Up @@ -412,6 +412,30 @@ internal void processToScreen()
}
}

private int ComparisonTree(string s, string s1)
{
var list = Settings.Instance.GetList("fav_params");

var fav1 = list.Contains(s);
var fav2 = list.Contains(s1);

var ans = s.CompareTo(s1);

// both fav use string compare
if (fav1 == fav2)
return ans;

// fav1 is greater
if (fav1 && !fav2)
return -1;

// fav1 is not greater
if (!fav1 && fav2)
return 1;

return ans;
}

private void updatedefaultlist(object crap)
{
try
Expand Down

0 comments on commit e9b6b9d

Please sign in to comment.