示例#1
0
        private void ToolPanel_SelectedToolChanged(object sender, EventArgs e)
        {
            IToolPanel toolPanel = (IToolPanel)sender;
            object     tool      = toolPanel.SelectedTool;

            ICustomFramesSupport framesSupport = tool as ICustomFramesSupport;
            ICustomAreaSupport   areaSupport   = tool as ICustomAreaSupport;
            ITunerSupport        tunerSupport  = tool as ITunerSupport;

            toolPanel.SetTuner(tunerSupport?.Tuner);

            foreach (IImagePanel imagePanel in View.ImagePanels)
            {
                imagePanel.MultiSelection = framesSupport != null;
                imagePanel.AreaSelection  = areaSupport != null;
            }

            foreach (string imageKey in Originals.Keys)
            {
                Originals[imageKey].CloneTo(Repository[imageKey]);
                Repository.OnItemChanged(imageKey);
            }
        }
示例#2
0
        private void ToolPanel_Tuning(object sender, EventArgs e)
        {
            IImagePanel imagePanel = View.ImagePanels.SelectedPanel;
            string      imageKey   = View.ImagePanels.SelectedPanelKey;
            object      tool       = ((IToolPanel)sender).SelectedTool;

            ICustomFramesSupport  framesSupport = tool as ICustomFramesSupport;
            ICustomAreaSupport    areaSupport   = tool as ICustomAreaSupport;
            IAsyncApplyingSupport asyncSupport  = tool as IAsyncApplyingSupport;

            if (framesSupport != null)
            {
                framesSupport.CustomFrames = imagePanel.SelectedIcons;
            }

            if (areaSupport != null)
            {
                areaSupport.CustomArea = imagePanel.SelectedArea;
            }

            if (asyncSupport != null)
            {
                asyncSupport.AllowMultipleTasks = false;
                asyncSupport.ApplyAsync         = Settings.Default.UseAsyncMode;
                AppController.EventController.UnsubscribeAll(asyncSupport, nameof(asyncSupport.AsyncApplyingCompleted));
                AppController.EventController.Subscribe(asyncSupport, nameof(asyncSupport.AsyncApplyingCompleted),
                                                        delegate { Repository.OnItemChanged(imageKey); });
            }

            IImageListSupport imageListSupport = tool as IImageListSupport;
            IImageSupport     imageSupport     = tool as IImageSupport;

            try
            {
                if (!Originals.ContainsKey(imageKey))
                {
                    Originals.Add(imageKey, Repository[imageKey].Clone());
                }

                if (imageListSupport != null)
                {
                    imageListSupport.Apply(Originals[imageKey], Repository[imageKey]);

                    if (!Settings.Default.UseAsyncMode)
                    {
                        Repository.OnItemChanged(imageKey);
                    }
                }
                else if (imageSupport != null)
                {
                    int frame = imagePanel.SelectedIcons.ElementAtOrDefault(0);

                    imageSupport.Apply(Originals[imageKey][frame], Repository[imageKey][frame]);

                    if (!Settings.Default.UseAsyncMode)
                    {
                        Repository.OnItemChanged(imageKey);
                    }
                }
                else
                {
                    throw new Exception("Unsupported tool type");
                }
            }
            catch (OutOfMemoryException ex)
            {
                GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
                MessageService.ShowError(ex.Message);
            }
#if !DEBUG
            catch (Exception ex)
            {
                MessageService.ShowError(Resources.ApplyToolError);
                LogService.LogError(ex);
            }
#endif
        }