Ejemplo n.º 1
0
        internal static Plugin GetDefaultHandler(OpenFileArgs args)
        {
            if (App.Settings.DefaultHandlers.ContainsKey(args.FileTypeKey))
            {
                var handlerKey = App.Settings.DefaultHandlers[args.FileTypeKey];
                if (plugins.ContainsKey(handlerKey)) //in case the plugin is no longer installed
                {
                    return(plugins[handlerKey]);
                }
            }

            var handler = AllPlugins
                          .Where(p => p.CanOpenFile(args))
                          .OrderByDescending(p => p.FilePriority ?? int.MaxValue)
                          .ThenBy(p => p.Name)
                          .FirstOrDefault();

            if (handler == null)
            {
                return(handler);
            }

            if (App.Settings.DefaultHandlers.ContainsKey(args.FileTypeKey))
            {
                App.Settings.DefaultHandlers.Remove(args.FileTypeKey);
            }

            App.Settings.DefaultHandlers.Add(args.FileTypeKey, handler.Key);

            return(handler);
        }
Ejemplo n.º 2
0
 public override IEnumerable <PluginContextItem> GetContextItems(OpenFileArgs context)
 {
     if (context.File.OfType <IRenderGeometry>().Any())
     {
         yield return(ExtractBitmapsContextItem);
     }
 }
Ejemplo n.º 3
0
        private void OnContextItemClick(string key, OpenFileArgs context)
        {
            if (!isBusy)
            {
                if (!GetDataFolder(out lastDataFolder))
                {
                    return;
                }
            }

            var node = context.File.OfType <TreeItemModel>().FirstOrDefault();

            if (node != null)
            {
                BatchQueue(node, lastDataFolder);
            }
            else
            {
                var item = context.File.Select(f => GetExtractable(f, lastDataFolder)).FirstOrDefault(e => e != null);
                if (item != null)
                {
                    extractionQueue.Enqueue(item);
                }
            }

            if (isBusy)
            {
                return;
            }

            tokenSource = new CancellationTokenSource();

            Task.Run(ProcessQueueAsync, tokenSource.Token);
        }
        public override bool CanOpenFile(OpenFileArgs args)
        {
#if DEBUG
            return(args.File.OfType <IIndexItem>().Any(i => Controls.DXEditor.CanOpenTag(i)) ||
                   args.File.OfType <IIndexItem>().Any(i => Controls.BspEditor.CanOpenTag(i)));
#else
            return(args.File.OfType <IIndexItem>().Any(i => Controls.DXEditor.CanOpenTag(i)));
#endif
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Opens a file object with the associated default handler.
        /// </summary>
        /// <param name="args">The file arguments.</param>
        public static bool OpenWithDefault(OpenFileArgs args)
        {
            var defaultHandler = GetDefaultHandler(args);

            if (defaultHandler == null || !defaultHandler.CanOpenFile(args))
            {
                return(false);
            }

            defaultHandler.OpenFile(args);
            return(true);
        }
Ejemplo n.º 6
0
        public override void OpenFile(OpenFileArgs args)
        {
            var model = args.File.OfType <IRenderGeometry>().FirstOrDefault();

            if (model != null)
            {
                DisplayModel(args.TargetWindow, model, args.FileName);
                return;
            }

            var modelTag = args.File.OfType <IIndexItem>().FirstOrDefault();

            DisplayModel(args.TargetWindow, modelTag, args.FileName);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Prompts the user to select which handler to open a file object with.
        /// </summary>
        /// <param name="args">The file arguments.</param>
        public static bool OpenWithPrompt(OpenFileArgs args)
        {
            var defaultHandler = GetDefaultHandler(args);

            if (defaultHandler == null)
            {
                return(false);
            }

            var allHandlers = AllPlugins
                              .Where(p => p.CanOpenFile(args));

            OpenWithDialog.HandleFile(allHandlers, args);
            return(true);
        }
Ejemplo n.º 8
0
        public override IEnumerable <PluginContextItem> GetContextItems(OpenFileArgs context)
        {
            Match match;

            if ((match = Regex.Match(context.FileTypeKey, BlamFileRegex)).Success)
            {
                if (!ValidateCacheType(match.Groups[1].Value))
                {
                    yield break;
                }

                if (match.Groups[2].Value == FileKeyWildcard && context.File.Any(i => i is TreeItemModel))
                {
                    yield return(ExtractMultipleContextItem);
                }
                else
                {
                    if (context.File.Any(f => IsExtractable(f)))
                    {
                        yield return(ExtractSingleContextItem);
                    }
                }
            }
            else if ((match = Regex.Match(context.FileTypeKey, SaberFileRegex)).Success)
            {
                if (match.Groups[1].Value != "Halo1X")
                {
                    yield break;
                }

                if (match.Groups[2].Value == FileKeyWildcard && context.File.Any(i => i is TreeItemModel))
                {
                    yield return(ExtractMultipleContextItem);
                }
                else
                {
                    if (context.File.Any(f => IsExtractable(f)))
                    {
                        yield return(ExtractSingleContextItem);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public override void OpenFile(OpenFileArgs args)
        {
            var bitm = args.File.OfType <IBitmap>().FirstOrDefault();

            DisplayBitmap(args.TargetWindow, bitm, args.FileName);
        }
Ejemplo n.º 10
0
 public override bool CanOpenFile(OpenFileArgs args)
 {
     return(args.File.Any(i => i is IBitmap));
 }
Ejemplo n.º 11
0
        private void OnContextItemClick(string key, OpenFileArgs context)
        {
            var geometry = context.File.OfType <IRenderGeometry>().FirstOrDefault();

            ExportBitmaps(geometry);
        }
Ejemplo n.º 12
0
        public override void OpenFile(OpenFileArgs args)
        {
            var model = args.File.OfType <IRenderGeometry>().FirstOrDefault();

            DisplayModel(args.TargetWindow, model, args.FileName);
        }
Ejemplo n.º 13
0
 public override bool CanOpenFile(OpenFileArgs args)
 {
     return(args.File.Any(i => i is IRenderGeometry));
 }
Ejemplo n.º 14
0
 /// <summary>
 /// When overidden in a derived class, gets a value indicating if the current
 /// plugin accepts a particular type of file object. If this method returns true,
 /// the <see cref="Substrate"/> may proceed to call <see cref="OpenFile(OpenFileArgs)"/>.
 /// </summary>
 /// <param name="args">The file arguments.</param>
 public virtual bool CanOpenFile(OpenFileArgs args) => false;
Ejemplo n.º 15
0
 /// <summary>
 /// Fetches context items from across all plugins for a particular file object.
 /// </summary>
 /// <param name="context">The file arguments.</param>
 public static IEnumerable <PluginContextItem> GetContextItems(OpenFileArgs context)
 {
     return(AllPlugins.SelectMany(p => p.GetContextItems(context)));
 }
Ejemplo n.º 16
0
 /// <summary>
 /// When overidden in a derived class, processes the request to handle a particular file object.
 /// This method is called by the <see cref="Substrate"/> when the user requests for a file to be handled.
 /// </summary>
 /// <param name="args">The file arguments.</param>
 public virtual void OpenFile(OpenFileArgs args)
 {
 }
Ejemplo n.º 17
0
 /// <summary>
 /// When overidden in a derived class, gets a list of context menu items provided by the current plugin
 /// for a particular file object. This method is called by the <see cref="Substrate"/> when another plugin
 /// requests context items for a particular file object.
 /// </summary>
 /// <param name="context">The file arguments.</param>
 public virtual IEnumerable <PluginContextItem> GetContextItems(OpenFileArgs context)
 {
     yield break;
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Executes the handler associated with the context menu item.
 /// </summary>
 /// <param name="context">The file object that the context menu is attached to.</param>
 public void ExecuteHandler(OpenFileArgs context) => handler(key, context);
        public override void OpenFile(OpenFileArgs args)
        {
            var modelTag = args.File.OfType <IIndexItem>().FirstOrDefault();

            DisplayModel(args.TargetWindow, modelTag, args.FileName);
        }
Ejemplo n.º 20
0
 public override bool CanOpenFile(OpenFileArgs args)
 {
     return(args.File.Any(i => i is IRenderGeometry) ||
            args.File.OfType <IIndexItem>().Any(i => Controls.DXViewer.CanOpenTag(i)));
 }