Remove ResultOpened related events

Since we are going to refactor plugin-UI interaction mechanism in the
near future, we just keep current implementation as simple as possible.
This commit is contained in:
Colin Liu 2016-02-19 23:26:13 +08:00
parent d5245f0730
commit 6f83bf3af2
3 changed files with 60 additions and 155 deletions

View File

@ -417,20 +417,6 @@ namespace Wox.ViewModel
{
this._searchResultPanel = new ResultPanelViewModel();
this.IsSearchResultPanelVisible = false;
this._searchResultPanel.ResultOpenedInPanel += (o, e) =>
{
if (e.HideWindow)
{
this.IsVisible = false;
}
UserSelectedRecordStorage.Instance.Add(e.Result.RawResult);
QueryHistoryStorage.Instance.Add(this.QueryText);
};
this._searchResultPanel.ResultActionPanelOpenedInPanel += (o, e) =>
{
this.ShowActionPanel(e.Result.RawResult);
};
}
private void ShowActionPanel(Result result)
@ -501,13 +487,6 @@ namespace Wox.ViewModel
{
this._actionPanel = new ResultPanelViewModel();
this.IsActionPanelVisible = false;
this._actionPanel.ResultOpenedInPanel += (o, e) =>
{
if (e.HideWindow)
{
this.IsVisible = false;
}
};
}
private void HandleQueryTextUpdated()

View File

@ -3,6 +3,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wox.Core.Plugin;
using Wox.Core.Resource;
using Wox.Infrastructure;
using Wox.Infrastructure.Hotkey;
using Wox.Plugin;
using Wox.Storage;
@ -33,23 +36,36 @@ namespace Wox.ViewModel
SpecialKeyState = GlobalHotkey.Instance.CheckModifiers()
});
if (null != this.ResultOpened)
if (hideWindow)
{
this.ResultOpened(this, new ResultOpenedEventArgs(hideWindow));
App.API.HideApp();
UserSelectedRecordStorage.Instance.Add(this._result);
QueryHistoryStorage.Instance.Add(this._result.OriginQuery.RawQuery);
}
});
this.OpenResultActionPanelCommand = new RelayCommand((parameter) => {
this.OpenResultActionPanelCommand = new RelayCommand((parameter) =>
{
if(null!= ResultActionPanelOpened)
var actions = PluginManager.GetContextMenusForPlugin(result);
var pluginMetaData = PluginManager.GetPluginForId(result.PluginID).Metadata;
actions.ForEach(o =>
{
this.ResultActionPanelOpened(this, new EventArgs());
}
o.PluginDirectory = pluginMetaData.PluginDirectory;
o.PluginID = result.PluginID;
o.OriginQuery = result.OriginQuery;
});
actions.Add(GetTopMostContextMenu(result));
App.API.ShowContextMenu(pluginMetaData, actions);
});
}
}
#endregion
#region ViewModel Properties
@ -112,6 +128,41 @@ namespace Wox.ViewModel
}
}
#endregion
#region Private Methods
private Result GetTopMostContextMenu(Result result)
{
if (TopMostRecordStorage.Instance.IsTopMost(result))
{
return new Result(InternationalizationManager.Instance.GetTranslation("cancelTopMostInThisQuery"), "Images\\down.png")
{
PluginDirectory = WoxDirectroy.Executable,
Action = _ =>
{
TopMostRecordStorage.Instance.Remove(result);
App.API.ShowMsg("Succeed", "", "");
return false;
}
};
}
else
{
return new Result(InternationalizationManager.Instance.GetTranslation("setAsTopMostInThisQuery"), "Images\\up.png")
{
PluginDirectory = WoxDirectroy.Executable,
Action = _ =>
{
TopMostRecordStorage.Instance.AddOrUpdate(result);
App.API.ShowMsg("Succeed", "", "");
return false;
}
};
}
}
#endregion
public override bool Equals(object obj)
@ -135,24 +186,5 @@ namespace Wox.ViewModel
return _result.ToString();
}
public event EventHandler<ResultOpenedEventArgs> ResultOpened;
public event EventHandler ResultActionPanelOpened;
}
public class ResultOpenedEventArgs : EventArgs
{
public bool HideWindow
{
get;
private set;
}
public ResultOpenedEventArgs(bool hideWindow)
{
this.HideWindow = hideWindow;
}
}
}

View File

@ -30,25 +30,7 @@ namespace Wox.ViewModel
public ResultPanelViewModel()
{
this._results = new ResultCollection(
(o, e)=> {
if(null != ResultOpenedInPanel)
{
this.ResultOpenedInPanel(this, new ResultOpenedInPanelEventArgs(o as ResultItemViewModel, e.HideWindow));
}
},
(o, e) => {
if(null != ResultActionPanelOpenedInPanel)
{
this.ResultActionPanelOpenedInPanel(this, new ResultActionPanelOpenedInPanelEventArgs(o as ResultItemViewModel));
}
}
);
this._results = new ResultCollection();
}
#endregion
@ -293,64 +275,12 @@ namespace Wox.ViewModel
#endregion
public event EventHandler<ResultOpenedInPanelEventArgs> ResultOpenedInPanel;
public event EventHandler<ResultActionPanelOpenedInPanelEventArgs> ResultActionPanelOpenedInPanel;
public class ResultCollection : ObservableCollection<ResultItemViewModel>
// todo implement custom moveItem,removeItem,insertItem for better performance
{
private EventHandler<ResultOpenedEventArgs> _resultOpenedHandler;
private EventHandler _resultActionPanelOpenedHandler;
public ResultCollection(EventHandler<ResultOpenedEventArgs> resultOpenedHandler,
EventHandler resultActionPanelOpenedHandler)
public ResultCollection()
{
this._resultOpenedHandler = resultOpenedHandler;
this._resultActionPanelOpenedHandler = resultActionPanelOpenedHandler;
}
protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
{
base.OnCollectionChanged(e);
if(e.Action == NotifyCollectionChangedAction.Add)
{
foreach(var item in e.NewItems)
{
var resultVM = item as ResultItemViewModel;
resultVM.ResultOpened += this._resultOpenedHandler;
resultVM.ResultActionPanelOpened += this._resultActionPanelOpenedHandler;
}
}
if(e.Action == NotifyCollectionChangedAction.Remove)
{
foreach (var item in e.OldItems)
{
var resultVM = item as ResultItemViewModel;
resultVM.ResultOpened -= this._resultOpenedHandler;
resultVM.ResultActionPanelOpened -= this._resultActionPanelOpenedHandler;
}
}
if(e.Action == NotifyCollectionChangedAction.Replace)
{
foreach (var item in e.NewItems)
{
var resultVM = item as ResultItemViewModel;
resultVM.ResultOpened += this._resultOpenedHandler;
resultVM.ResultActionPanelOpened += this._resultActionPanelOpenedHandler;
}
foreach (var item in e.OldItems)
{
var resultVM = item as ResultItemViewModel;
resultVM.ResultOpened -= this._resultOpenedHandler;
resultVM.ResultActionPanelOpened -= this._resultActionPanelOpenedHandler;
}
}
}
public void RemoveAll(Predicate<ResultItemViewModel> predicate)
@ -418,41 +348,5 @@ namespace Wox.ViewModel
}
}
public class ResultOpenedInPanelEventArgs : EventArgs
{
public bool HideWindow
{
get;
private set;
}
public ResultItemViewModel Result
{
get;
private set;
}
public ResultOpenedInPanelEventArgs(ResultItemViewModel result, bool hideWindow)
{
this.HideWindow = hideWindow;
this.Result = result;
}
}
public class ResultActionPanelOpenedInPanelEventArgs : EventArgs
{
public ResultItemViewModel Result
{
get;
private set;
}
public ResultActionPanelOpenedInPanelEventArgs(ResultItemViewModel result)
{
this.Result = result;
}
}
}