///<summary>
        /// Default constructor for FerdaArchive class.
        ///</summary>
        public FerdaArchive(Menu.ILocalizationManager locManager,
            Menu.IMenuDisplayer menuDisp, IFerdaClipboard clipboard,
            ProjectManager.Archive arch, IIconProvider iconProvider,
            Menu.IMenuDisplayer toolBar,
            ProjectManager.ProjectManager projManager)
            : base()
        {
            //setting the icon
            naIcon = iconProvider.GetIcon("NAIcon");
            this.iconProvider = iconProvider;

            //setting the localization
            localizationManager = locManager;
            ResManager = localizationManager.ResManager;

            //setting the menu displayer
            menuDisplayer = menuDisp;
            this.toolBar = toolBar;

            //setting the archive
            Archive = arch;

            //setting the projectManager
            projectManager = projManager;

            InitializeComponent();

            //Setting the texts of the radiobuttons
            RBAlong.Text = ResManager.GetString("ArchiveAlongText");
            RBAgainst.Text = ResManager.GetString("ArchiveAgainstText");
            RBAlong.Checked = true;

            //Setting the clipboard
            this.Clipboard = clipboard;

            //events
            GotFocus += new EventHandler(FerdaArchive_GotFocus);
            TVArchive.GotFocus += new EventHandler(FerdaArchive_GotFocus);
            TVArchive.MouseDown += new MouseEventHandler(TVArchive_MouseDown);
            TVArchive.MouseMove += new MouseEventHandler(TVArchive_MouseMove);

            //the labelEdit property
            TVArchive.LabelEdit = true;
            TVArchive.AfterLabelEdit += new NodeLabelEditEventHandler(TVArchive_AfterLabelEdit);

            CBCategories.SelectedIndexChanged += new EventHandler(CBArchive_SelectedIndexChanged);
            CBTypes.SelectedIndexChanged += new EventHandler(CBTypes_SelectedIndexChanged);
            RBAlong.CheckedChanged += new EventHandler(RBAlong_CheckedChanged);
            TVArchive.AfterSelect += new TreeViewEventHandler(TVArchive_AfterSelect);

            ArchiveSetupAfterLoadProject();
        }
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="locManager">Localization manager of the application</param>
        /// <param name="menuDisp">Menu of the application</param>
        /// <param name="modManager">Modules manager</param>
        /// <param name="iconProvider">Provider of the icons for the component</param>
        /// <param name="toolBar">ToolBar of the application</param>
        public NewBoxTreeView(Menu.ILocalizationManager locManager, 
            Menu.IMenuDisplayer menuDisp, ModulesManager.ModulesManager modManager,
            IIconProvider iconProvider, Menu.IMenuDisplayer toolBar)
            : base()
        {
            //setting the icons
            naIcon = iconProvider.GetIcon("NAIcon");
            folderIcon = iconProvider.GetIcon("FolderIcon");

            localizationManager = locManager;
            menuDisplayer = menuDisp;
            this.toolBar = toolBar;
            modulesManager = modManager;

            InitializeComponent();

            IBoxModuleFactoryCreator[] creators = modulesManager.BoxModuleFactoryCreators;

            FillImageList(creators);
            FillTreeView(creators);

            AfterSelect += new TreeViewEventHandler(NewBoxTreeView_AfterSelect);
            GotFocus += new EventHandler(NewBox_GotFocus);
            MouseMove += new MouseEventHandler(NewBoxTreeView_MouseMove);
            MouseDown += new MouseEventHandler(NewBoxTreeView_MouseDown);
        }
        /// <summary>
        /// Fills the static fields of context menu for the node
        /// </summary>
        /// <param name="cMenu">Context menu of the TreeNode</param>
        /// <param name="provider">Interface that provides icons for the boxes</param>
        protected void SetStaticContextMenu(ContextMenuStrip cMenu, IIconProvider provider)
        {
            //handling normal items
            ToolStripMenuItem rename =
                new ToolStripMenuItem(ParentTreeView.ResManager.GetString("MenuEditRename"));
            ToolStripMenuItem copy =
                new ToolStripMenuItem(ParentTreeView.ResManager.GetString("MenuEditCopy"));
            ToolStripMenuItem clone =
                new ToolStripMenuItem(ParentTreeView.ResManager.GetString("MenuEditClone"));

            copy.Click += new EventHandler(copy_Click);
            rename.Click += new EventHandler(rename_Click);
            clone.Click += new EventHandler(clone_Click);

            //shortcuts
            rename.ShortcutKeys = Keys.F2;
            copy.ShortcutKeys = (Keys)Shortcut.CtrlC;
            clone.ShortcutKeys = (Keys)Shortcut.CtrlE;

            //icons
            rename.Image = provider.GetIcon("Rename").ToBitmap();
            copy.Image = provider.GetIcon("Copy").ToBitmap();
            clone.Image = provider.GetIcon("Clone").ToBitmap();

            cMenu.Items.AddRange(new ToolStripItem[] {rename, copy, clone });

            if (!ParentTreeView.Clipboard.IsEmpty)
            {
                ToolStripMenuItem paste =
                    new ToolStripMenuItem(ParentTreeView.ResManager.GetString("MenuEditPaste"));
                paste.Click += new EventHandler(paste_Click);
                paste.ShortcutKeys = (Keys)Shortcut.CtrlV;
                paste.Image = provider.GetIcon("Paste").ToBitmap();
                cMenu.Items.Add(paste);
            }

            ToolStripSeparator sep = new ToolStripSeparator();
            ToolStripMenuItem delete =
                new ToolStripMenuItem(ParentTreeView.ResManager.GetString("MenuArchiveDelete"));
            delete.Click += new EventHandler(delete_Click);
            delete.ShortcutKeys = (Keys)Shortcut.ShiftDel;
            delete.Image = provider.GetIcon("DeleteFromArchive").ToBitmap();
            cMenu.Items.AddRange(new ToolStripItem[] { sep, delete });
        }
Пример #4
0
        public void Run(string[] args)
        {
            if (args == null || args.Length < 2)
            {
                return;
            }

            var target = args[1];

            if (string.IsNullOrEmpty(target))
            {
                _dialogService.Warn("Empty target argument");
                return;
            }

            if (_config == null)
            {
                try {
                    _config = _configProvider.GetConfig();
                } catch (Exception ex) {
                    _dialogService.Error("Failed reading config:\n" + ex);
                    return;
                }
            }

            if (_config?.Mappings == null || !_config.Mappings.Any())
            {
                _dialogService.Info("No mappings in config");
                return;
            }

            List <Mapping> matchedMappings;

            try {
                matchedMappings =
                    _config.Mappings
                    .Where(m =>
                           m.Filters != null &&
                           m.Filters
                           .Select(f => _filterFactory.GetFilter(f.Key, f.Value))
                           .Where(f => f != null)
                           .All(f => f.Accepts(target))
                           )
                    .OrderBy(m => m.Priority).ThenBy(m => m.Name)
                    .Take(10)
                    .ToList();

                if (!matchedMappings.Any())
                {
                    matchedMappings =
                        _config.Mappings
                        .Where(m => m.Filters == null)
                        .OrderBy(m => m.Priority).ThenBy(m => m.Name)
                        .Take(10)
                        .ToList();
                }
            }
            catch (Exception ex) {
                _dialogService.Error(ex.ToString());
                return;
            }

            if (!matchedMappings.Any())
            {
                return;
            }

            var stringExpander = new VarsStringExpander(_config.Vars);

            bool StartMapping(Mapping mapping)
            {
                if (mapping != null)
                {
                    var command = stringExpander.Expand(mapping.Command);
                    try {
                        _processStarter.Start(
                            command,
                            mapping.Admin,
                            Path.GetDirectoryName(target),
                            stringExpander.Expand(mapping.Args),
                            args
                            );
                        return(true);
                    }
                    catch (Exception ex) {
                        _dialogService.Error($"Error starting '{command}':\n" + ex);
                    }
                }
                return(false);
            }

            if (matchedMappings.Count == 1)
            {
                var mapping = matchedMappings.First();
                StartMapping(mapping);
                return;
            }

            MainWindow mainWindow = null;

            mainWindow = new MainWindow {
                AllowsTransparency = _config.Opacity < 1.0,
                Opacity            = _config.Opacity,
                DataContext        = new MainViewModel {
                    Theme      = _config.Theme,
                    HeaderText = string.Format(_config.HeaderTemplate, target, Path.GetFileName(target)),
                    Items      = matchedMappings.Select((m, i) => new OptionViewModel {
                        Number       = i + 1,
                        Name         = m.Name,
                        IconSupplier = () => _iconProvider.GetIcon(stringExpander.Expand(m.Icon ?? m.Command)).Result,
                        Action       = () => { if (StartMapping(m))
                                               {
                                                   mainWindow.Close();
                                               }
                        }
                    }).ToList(),
                    CloseTimeout = _config.AutoCloseTimeout * 1000,
                    CloseAction  = () => mainWindow.Close()
                }
            };

            var app = new Application {
                ShutdownMode = ShutdownMode.OnMainWindowClose,
                MainWindow   = mainWindow
            };

            mainWindow.Show();
            app.Run();
        }