private static void RemoveInstanceListener(int priority, EventComponent target, EventCallback callback) { SortedList <int, List <EventCallback> > instance; // See if we we have any events registered to this target already if (InstanceListeners.TryGetValue(target, out instance)) { List <EventCallback> listeners; if (instance.TryGetValue(priority, out listeners)) { listeners.Remove(callback); // Remove this priority if there are no more listeners if (listeners == null || listeners.Count == 0) { GlobalListeners.RemoveAt(priority); } } else { // Only log as a warning as this isn't technically an error, just something to keep an eye on as it shouldn't happen. Debug.LogWarning($"Trying to remove a callback from priority {priority}, which does not exist for {GenericTypeName}."); } } else { // Only log as a warning as this isn't technically an error, just something to keep an eye on as it shouldn't happen. Debug.LogWarning($"Trying to remove a callback from the instance {target.name} but there are no listeners for it"); } }
public void Callback() { var cb = new CustomCallback(); GlobalListeners.Attach(cb); var fs = new FeatureSet(Path.Combine(UsaShapefilesPath, "cities.shp")); fs.StartEditingShapes(); fs.Close(); }
private static void RegisterGlobalListener(int priority, EventCallback callback) { List <EventCallback> listeners; if (GlobalListeners.TryGetValue(priority, out listeners)) { listeners.Add(callback); } else { GlobalListeners.Add(priority, new List <EventCallback> { callback }); } }
private static void RemoveGlobalListener(int priority, EventCallback callback) { List <EventCallback> listeners; if (GlobalListeners.TryGetValue(priority, out listeners)) { listeners.Remove(callback); // Remove this priority if there are no more listeners if (listeners == null || listeners.Count == 0) { GlobalListeners.RemoveAt(priority); } } else { // Only log as a warning as this isn't technically an error, just something to keep an eye on as it shouldn't happen. Debug.LogWarning($"Trying to remove a callback from priority {priority}, which does not exist for {GenericTypeName}."); } }
// TODO: 增加鼠标监听事件 /// <summary> /// Constructor of <see cref="GlobalListenerManager"/> /// </summary> /// <param name="inputListeners"> /// 默认同时开启键盘和鼠标监听事件 /// </param> public GlobalListenerManager( GlobalListeners inputListeners = GlobalListeners.KeyListener | GlobalListeners.MouseListener) { InputListener = inputListeners; switch (InputListener) { case GlobalListeners.MouseListener: break; case GlobalListeners.KeyListener: KeyboardListener = new GlobalListenerToKeyboard(); break; // TODO: 完成鼠标监听事件初始化 case GlobalListeners.MouseListener | GlobalListeners.KeyListener: KeyboardListener = new GlobalListenerToKeyboard(); break; default: Debugger.Break(); break; } }
/// <summary> /// Runs the task on the current thread. /// </summary> public bool Run(CancellationToken cancellationToken) { ThreadId = Thread.CurrentThread.ManagedThreadId; GlobalListeners.Attach(this); bool result = false; try { var handle = new TaskHandle(Progress, _cancellationTokenSource.Token, _pauseEvent, this); result = Tool.Run(handle); } finally { GlobalListeners.Detach(this); ThreadId = -1; } return(result); }
private void Calculate() { var map = _context.Map; var table = Model.Table; const string msg = "Updating measurements"; GlobalListeners.ReportProgress(string.Empty, 0, msg); int featureCount = Model.Features.Count; foreach (var ft in Model.Features) { GlobalListeners.ReportProgress(string.Empty, Convert.ToInt32((ft.Index + 1) * 100.0 / featureCount), msg); var g = ft.Geometry; if (_lengthInfo.Active) { double length = map.GeodesicLength(g); length = UnitConversionHelper.Convert(LengthUnits.Meters, View.LengthUnits, length); table.EditCellValue(_lengthInfo.FieldIndex, ft.Index, length); } if (_areaInfo.Active) { double area = map.GeodesicArea(g); area = UnitConversionHelper.Convert(AreaUnits.SquareMeters, View.AreaUnits, area); table.EditCellValue(_areaInfo.FieldIndex, ft.Index, area); } } GlobalListeners.ClearProgress(); }
public MainPresenter( IAppContext context, IMainView view, IProjectService projectService, IConfigService configService, LegendPresenter legendPresenter, ToolboxPresenter toolboxPresenter, IRepository repository) : base(view) { Logger.Current.Trace("Start MainPresenter"); if (view == null) { throw new ArgumentNullException("view"); } if (projectService == null) { throw new ArgumentNullException("projectService"); } if (configService == null) { throw new ArgumentNullException("configService"); } if (repository == null) { throw new ArgumentNullException("repository"); } // PM 2016-03-02 Added: if (legendPresenter == null) { throw new ArgumentNullException("legendPresenter"); } if (toolboxPresenter == null) { throw new ArgumentNullException("toolboxPresenter"); } _context = context; _projectService = projectService; _configService = configService; GlobalListeners.Attach(Logger.Current); view.Map.Lock(); try { var appContext = context as AppContext; if (appContext == null) { throw new InvalidCastException("Invalid type of IAppContext instance"); } appContext.Init(view, projectService, configService, legendPresenter, toolboxPresenter, repository); view.Map.Initialize(); view.Map.ApplyConfig(configService); view.ViewClosing += OnViewClosing; view.ViewUpdating += OnViewUpdating; view.BeforeShow += OnBeforeShow; var container = context.Container; _statusBarListener = container.GetSingleton <StatusBarListener>(); _menuGenerator = container.GetSingleton <MenuGenerator>(); _menuListener = container.GetSingleton <MenuListener>(); _mapListener = container.GetSingleton <MapListener>(); _mainPluginListener = container.GetSingleton <MainPluginListener>(); _legendListener = container.GetSingleton <LegendListener>(); _menuUpdater = new MenuUpdater(_context, PluginIdentity.Default); SplashView.Instance.ShowStatus("Loading plugins"); // must be called after docking is initialized: appContext.InitPlugins(configService, p => SplashView.Instance.ShowStatus($"Loading plugins: {p.Name}")); // this will display progress updates and debug window // file based-logger is already working Logger.Current.Init(appContext); } finally { view.Map.Unlock(); context.Legend.Unlock(); } View.AsForm.Shown += ViewShown; Logger.Current.Trace("End MainPresenter"); }
public MainPresenter( IAppContext context, IMainView view, IProjectService projectService, IConfigService configService ) : base(view) { Logger.Current.Trace("Start MainPresenter"); if (view == null) { throw new ArgumentNullException("view"); } if (projectService == null) { throw new ArgumentNullException("projectService"); } if (configService == null) { throw new ArgumentNullException("configService"); } // PM 2016-03-02 Added: //修改,依据界面类型来判断是否为一般形态还是Ribbon _context = context; _projectService = projectService; _configService = configService; GdalConfiguration.ConfigureOgr(); GlobalListeners.Attach(Logger.Current); try { var appContext = context as AppContext; if (appContext == null) { throw new InvalidCastException("Invalid type of IAppContext instance"); } appContext.Init(view, projectService, configService); view.ViewClosing += OnViewClosing; view.ViewUpdating += OnViewUpdating; view.BeforeShow += OnBeforeShow; var container = context.Container; _statusBarListener = container.GetSingleton <StatusBarListener>(); _menuGenerator = container.GetSingleton <MenuGenerator>(); _menuListener = container.GetSingleton <MenuListener>(); _mainPluginListener = container.GetSingleton <MainPluginListener>(); _menuUpdater = new MenuUpdater(_context, PluginIdentity.Default); SplashView.Instance.ShowStatus("Loading plugins"); appContext.InitPlugins(configService); // must be called after docking is initialized // this will display progress updates and debug window // file based-logger is already working Logger.Current.Init(appContext); } finally { } View.AsForm.Shown += ViewShown; Logger.Current.Trace("End MainPresenter"); }