Skip to content

Commit 68ebdfa

Browse files
authored
Merge pull request #55 from visualHFT/minor-updates-dashboard
user control for plugins
2 parents 618cd57 + bbd49ab commit 68ebdfa

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

ViewModel/vmDashboard.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,23 @@ private async Task LoadTilesAsync()
4848
{
4949
try
5050
{
51-
//first, load single studies
52-
foreach (var study in PluginManager.PluginManager.AllPlugins.Where(x => x is IStudy && x.GetCustomUI() == null))
53-
{
51+
var allPlugins = PluginManager.PluginManager.AllPlugins;
52+
53+
// Group plugins by their type and UI characteristics
54+
var singleStudiesWithoutUI = allPlugins.Where(x => x is IStudy && x.GetCustomUI() == null);
55+
var multiStudiesWithoutUI = allPlugins.Where(x => x is IMultiStudy && x.GetCustomUI() == null);
56+
var pluginsWithUI = allPlugins.Where(x => x is PluginManager.IPlugin && x.GetCustomUI() != null);
57+
58+
// Load tiles in this specific order (single studies, multi studies, plugins with UI)
59+
foreach (var study in singleStudiesWithoutUI)
5460
Tiles.Add(new vmTile(study as IStudy));
55-
}
56-
//then, load multi-studies
57-
foreach (var study in PluginManager.PluginManager.AllPlugins.Where(x => x is IMultiStudy && x.GetCustomUI() == null))
58-
{
61+
62+
foreach (var study in multiStudiesWithoutUI)
5963
Tiles.Add(new vmTile(study as IMultiStudy));
60-
}
61-
//then, load custom UIs
62-
foreach (var study in PluginManager.PluginManager.AllPlugins.Where(x => x is PluginManager.IPlugin && x.GetCustomUI() != null))
63-
{
64+
65+
foreach (var study in pluginsWithUI)
6466
Tiles.Add(new vmTile(study as PluginManager.IPlugin));
65-
}
67+
6668
}
6769
catch (Exception ex)
6870
{
@@ -155,7 +157,8 @@ public string SelectedStrategy
155157
RaisePropertyChanged(nameof(SelectedStrategy));
156158
RaisePropertyChanged(nameof(SelectedSymbol));
157159
RaisePropertyChanged(nameof(SelectedLayer));
158-
};
160+
}
161+
;
159162
}
160163
}
161164
public string SelectedSymbol

ViewModel/vmTile.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using VisualHFT.Commons.Studies;
1111
using VisualHFT.View;
1212
using System.Collections.ObjectModel;
13-
using System.Windows.Controls;
13+
using System.Windows.Controls;
1414

1515
namespace VisualHFT.ViewModel
1616
{
@@ -52,9 +52,11 @@ public vmTile(IStudy study)
5252
IsGroup = false;
5353

5454
_study = study;
55+
_customControl = _study.GetCustomUI() as UserControl;
56+
IsUserControl = _customControl != null;
5557
_tile_id = ((PluginManager.IPlugin)_study).GetPluginUniqueID();
5658
Title = _study.TileTitle;
57-
Tooltip = _study.TileToolTip;
59+
Tooltip = _study.TileToolTip;
5860

5961
_localModel.ValueFormatted = ".";
6062
_localModel.Tooltip = "Waiting for data...";
@@ -63,13 +65,18 @@ public vmTile(IStudy study)
6365

6466
OpenSettingsCommand = new RelayCommand<vmTile>(OpenSettings);
6567
OpenChartCommand = new RelayCommand<vmTile>(OpenChartClick);
66-
67-
6868
uiUpdater = new UIUpdater(uiUpdaterAction, UI_UPDATE_TIME_MS);
6969

70+
if (IsUserControl)
71+
{
72+
IsGroup = true;
73+
ValueVisibility = Visibility.Hidden;
74+
UCVisibility = Visibility.Visible;
75+
76+
OpenSettingsCommand = new RelayCommand<vmTile>(OpenSettings);
77+
}
7078
RaisePropertyChanged(nameof(SelectedSymbol));
7179
RaisePropertyChanged(nameof(SelectedProviderName));
72-
7380
RaisePropertyChanged(nameof(IsGroup));
7481
SettingButtonVisibility = Visibility.Visible;
7582
ChartButtonVisibility = Visibility.Visible;
@@ -194,7 +201,7 @@ public void UpdateAllUI()
194201
RaisePropertyChanged(nameof(SelectedProviderName));
195202
}
196203

197-
public ICommand OpenSettingsCommand { get; set; }
204+
public ICommand OpenSettingsCommand { get; set; }
198205
public ICommand OpenChartCommand { get; private set; }
199206

200207
public string Value { get => _value; set => SetProperty(ref _value, value); }
@@ -300,7 +307,7 @@ private void OpenSettings(object obj)
300307
RaisePropertyChanged(nameof(SelectedProviderName));
301308

302309
}
303-
310+
304311
protected virtual void Dispose(bool disposing)
305312
{
306313
if (!_disposed)

VisualHFT.Commons/Studies/IStudy.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ public interface IStudy : IDisposable
1111
Task StopAsync();
1212
string TileTitle { get; set; }
1313
string TileToolTip { get; set; }
14+
object GetCustomUI(); //Allow to setup own UI for the plugin
15+
//using object type because this csproj doesn't support UI
16+
1417
}
1518

1619
}

0 commit comments

Comments
 (0)