2016-02-18 19:31:15 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-02-19 23:26:13 +08:00
|
|
|
|
using Wox.Core.Plugin;
|
|
|
|
|
using Wox.Core.Resource;
|
|
|
|
|
using Wox.Infrastructure;
|
2016-02-18 19:31:15 +08:00
|
|
|
|
using Wox.Infrastructure.Hotkey;
|
|
|
|
|
using Wox.Plugin;
|
|
|
|
|
using Wox.Storage;
|
|
|
|
|
|
|
|
|
|
namespace Wox.ViewModel
|
|
|
|
|
{
|
2016-02-21 23:19:42 +08:00
|
|
|
|
public class ResultViewModel : BaseViewModel
|
2016-02-18 19:31:15 +08:00
|
|
|
|
{
|
|
|
|
|
#region Private Fields
|
|
|
|
|
|
|
|
|
|
private Result _result;
|
2016-02-19 21:36:44 +08:00
|
|
|
|
private bool _isSelected;
|
2016-02-18 19:31:15 +08:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Constructor
|
|
|
|
|
|
2016-02-21 23:19:42 +08:00
|
|
|
|
public ResultViewModel(Result result)
|
2016-02-18 19:31:15 +08:00
|
|
|
|
{
|
2016-02-21 22:40:10 +08:00
|
|
|
|
if (null != result)
|
2016-02-18 19:31:15 +08:00
|
|
|
|
{
|
|
|
|
|
this._result = result;
|
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this.OpenResultListBoxItemCommand = new RelayCommand((parameter) =>
|
|
|
|
|
{
|
2016-02-18 19:31:15 +08:00
|
|
|
|
|
|
|
|
|
bool hideWindow = result.Action(new ActionContext
|
|
|
|
|
{
|
|
|
|
|
SpecialKeyState = GlobalHotkey.Instance.CheckModifiers()
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-19 23:26:13 +08:00
|
|
|
|
if (hideWindow)
|
2016-02-18 19:31:15 +08:00
|
|
|
|
{
|
2016-02-19 23:26:13 +08:00
|
|
|
|
App.API.HideApp();
|
|
|
|
|
UserSelectedRecordStorage.Instance.Add(this._result);
|
|
|
|
|
QueryHistoryStorage.Instance.Add(this._result.OriginQuery.RawQuery);
|
2016-02-18 19:31:15 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
this.OpenContextMenuItemCommand = new RelayCommand((parameter) =>
|
2016-02-19 23:26:13 +08:00
|
|
|
|
{
|
2016-02-18 19:31:15 +08:00
|
|
|
|
|
2016-02-19 23:26:13 +08:00
|
|
|
|
var actions = PluginManager.GetContextMenusForPlugin(result);
|
|
|
|
|
|
|
|
|
|
var pluginMetaData = PluginManager.GetPluginForId(result.PluginID).Metadata;
|
|
|
|
|
actions.ForEach(o =>
|
2016-02-18 19:31:15 +08:00
|
|
|
|
{
|
2016-02-19 23:26:13 +08:00
|
|
|
|
o.PluginDirectory = pluginMetaData.PluginDirectory;
|
|
|
|
|
o.PluginID = result.PluginID;
|
|
|
|
|
o.OriginQuery = result.OriginQuery;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
actions.Add(GetTopMostContextMenu(result));
|
|
|
|
|
|
|
|
|
|
App.API.ShowContextMenu(pluginMetaData, actions);
|
2016-02-18 19:31:15 +08:00
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-19 23:26:13 +08:00
|
|
|
|
|
2016-02-18 19:31:15 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ViewModel Properties
|
|
|
|
|
|
|
|
|
|
public string Title
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this._result.Title;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string SubTitle
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this._result.SubTitle;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string FullIcoPath
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this._result.FullIcoPath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-19 21:36:44 +08:00
|
|
|
|
public bool IsSelected
|
|
|
|
|
{
|
|
|
|
|
get { return _isSelected; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_isSelected = value;
|
|
|
|
|
OnPropertyChanged("IsSelected");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
public RelayCommand OpenResultListBoxItemCommand { get; set; }
|
2016-02-18 19:31:15 +08:00
|
|
|
|
|
2016-02-21 22:40:10 +08:00
|
|
|
|
public RelayCommand OpenContextMenuItemCommand { get; set; }
|
2016-02-18 19:31:15 +08:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Properties
|
|
|
|
|
|
|
|
|
|
public Result RawResult
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return this._result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-19 23:26:13 +08:00
|
|
|
|
#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;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-02-18 19:31:15 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
2016-02-18 22:53:41 +08:00
|
|
|
|
public override bool Equals(object obj)
|
|
|
|
|
{
|
2016-02-21 23:19:42 +08:00
|
|
|
|
ResultViewModel r = obj as ResultViewModel;
|
2016-02-18 22:53:41 +08:00
|
|
|
|
if (r != null)
|
|
|
|
|
{
|
2016-02-19 22:55:58 +08:00
|
|
|
|
return _result.Equals(r.RawResult);
|
2016-02-18 22:53:41 +08:00
|
|
|
|
}
|
2016-02-21 22:40:10 +08:00
|
|
|
|
|
2016-02-19 22:55:58 +08:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
return _result.GetHashCode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
|
|
|
|
return _result.ToString();
|
2016-02-18 22:53:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-02-18 19:31:15 +08:00
|
|
|
|
}
|
|
|
|
|
}
|