Example #1
0
		private void TreeToHashtable(ShortcutCollection node)
		{
			foreach (CustomShortcut cs in node)
			{
				_shortcutMap.Add(cs.OwnerType, cs);
				TreeToHashtable(cs.Nodes);
			}
		}
Example #2
0
		private static void BuildTree(TreeNodeCollection treeNodes,
			ShortcutCollection shortcutNodes)
		{
			foreach (CustomShortcut shortcut in shortcutNodes)
			{
				var node = new TreeNode(shortcut.Name, 0, 1) {Tag = shortcut};

				treeNodes.Add(node);

				BuildTree(node.Nodes, shortcut.Nodes);
			}
		}
        public MainWindow()
        {
            try
            {
                eventBus = new EventBus();
                Container.Current.Register <IEventBus>(eventBus);

                //Fixes an issue with current directory being system32 for the plugin loader and not the application path as desired
                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Setting base directory...", EventLogEntryType.Information));
                Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initializing components...", EventLogEntryType.Information));
                InitializeComponent();

                var logService = new LogService(eventBus);
                Container.Current.Register <ILogService>(logService);

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initializing plugin loader...", EventLogEntryType.Information));
                pluginLoader = new PluginLoader(eventBus, Container.Current);
                Container.Current.Register <IPluginLoader>(pluginLoader);

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initializing shortcut collection...", EventLogEntryType.Information));
                var shortcutCollection = new ShortcutCollection(pluginLoader, eventBus);
                Container.Current.Register <IShortcutCollection <string, ILaunchShortcut> >(shortcutCollection);

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initializing shortcut executor...", EventLogEntryType.Information));
                var shortcutExecutor = new ShortcutExecutor(shortcutCollection);
                Container.Current.Register <IShortcutExecutor>(shortcutExecutor);

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initializing setting collection...", EventLogEntryType.Information));
                var settingCollection = new SettingCollection(eventBus);
                Container.Current.Register <ISettingCollection>(settingCollection);

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initializing plugins...", EventLogEntryType.Information));
                pluginLoader.Load();
                eventBus.Publish(new ProgramLoadedEvent());

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initializing main view model...", EventLogEntryType.Information));
                DataContext = new MainViewModel(eventBus, shortcutCollection, shortcutExecutor, settingCollection, pluginLoader);

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initializing hooks...", EventLogEntryType.Information));
                hookId   = SetHook(proc);
                Closing += OnMainWindowClosing;

                eventBus.Publish(new LogEntryPublished("Heibroch.Launch - Initializing", "Initialization complete", EventLogEntryType.Information));
            }
            catch (Exception ex)
            {
                eventBus.Publish(new LogEntryPublished("Heibroch.Launch", ex.StackTrace, EventLogEntryType.Error));
                throw ex;
            }
        }
Example #4
0
        public ShortcutProvider()
        {
            string folder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\Keymaps\";
            string filter = "*.yml";
            if (!Directory.Exists(folder)) return;
            string[] files = Directory.GetFiles(folder, filter);

            var yaml = new YamlStream();

            foreach (string file in files)
            {
                yaml.Load(File.OpenText(file));
                var root = yaml.Documents[0].RootNode;

                var collection = root as YamlMappingNode;
                if (collection != null)
                {
                    string group = GetValueByKey(collection, "group");
                    string process = GetValueByKey(collection, "process");
                    var shortcutCollection = new ShortcutCollection { Process = process, Group = group };

                    var groupShortcuts = collection.Children.First(n => n.Key.ToString() == "shortcuts").Value as YamlSequenceNode;

                    foreach (YamlMappingNode entry in groupShortcuts.Children)
                    {
                        string name = GetValueByKey(entry, "name");

                        if (entry.Children.First(n => n.Key.ToString() == "keys").Value as YamlSequenceNode == null)
                            continue;

                        var keys = entry.Children.First(n => n.Key.ToString() == "keys").Value as YamlSequenceNode;

                        foreach (var keyCombo in keys.Children)
                        {
                            var definitions = new List<KeyPressDefinition>();
                            string[] combos = keyCombo.ToString().Split(',');
                            foreach (string combo in combos)
                            {
                                var definition = GetKeyPressDefintion(combo);
                                if (definition != null)
                                    definitions.Add(definition);
                            }
                            if (definitions.Count > 0)
                                shortcutCollection.Add(new KeyShortcut(name, definitions.ToArray()));
                        }
                    }

                    shortcuts.Add(shortcutCollection);
                }
            }
        }
Example #5
0
		private static void BuildTree(TreeNode currentNode, ShortcutCollection node)
		{
			if (node == null)
				return;

			foreach (CustomShortcut cs in node)
			{
				var treeNode = new TreeNode(cs.Name) {Tag = cs.OwnerType.ToString()};

				currentNode.Nodes.Add(treeNode);

				BuildTree(treeNode, cs.Nodes);
			}
		}
Example #6
0
		private static void SerializeNodes(XmlWriter writer, ShortcutCollection nodes)
		{
			foreach (CustomShortcut cs in nodes)
			{
				writer.WriteStartElement("node");
				writer.WriteAttributeString("name", cs.Name);
				writer.WriteAttributeString("type", cs.OwnerType.ToString());

				HashtableToString(writer, cs.HashTable);

				writer.WriteEndElement();

				SerializeNodes(writer, cs.Nodes);
			}
		}
Example #7
0
		private bool SaveCore(Stream stream,
			ShortcutCollection nodes, bool forPreset)
		{
			var writer = new XmlTextWriter(stream, Encoding.UTF8) {Formatting = Formatting.Indented};

			writer.WriteStartElement("SerializeShortcuts");
			writer.WriteAttributeString("version", _version);

			SerializeNodes(writer, nodes);

			if (!forPreset)
				SerializePresets(writer);

			writer.WriteEndElement();
			writer.Flush();

			return true;
		}
Example #8
0
        public Form1()
        {
            InitializeComponent();


            // 特定の文字数区切りのプロダクトキー(数字で3,4,4文字区切り)を入力することを想定
            MaskPatternField field1 = new MaskPatternField("\\D", 3, 3);
            MaskPatternField field2 = new MaskPatternField("\\D", 4, 4);
            MaskPatternField field3 = new MaskPatternField("\\D", 4, 4);

            // 3つめのフィールドはパスワードとしてマスクする
            //field3.PasswordChar = '*';

            // 1つめのフィールドは青文字
            field1.ForeColor = Color.Blue;

            MaskLiteralField line  = new MaskLiteralField("-");
            MaskLiteralField line2 = new MaskLiteralField("-");

            gcMask1.Fields.Add(field1);
            gcMask1.Fields.Add(line);
            gcMask1.Fields.Add(field2);
            gcMask1.Fields.Add(line2);
            gcMask1.Fields.Add(field3);


            // ショートカットのコレクションを作成
            ShortcutCollection sc = new ShortcutCollection();

            // Ctr+Shift+Aでよく使う文字を入力
            sc.Add(Keys.A | Keys.Shift | Keys.Control, new MethodInvoker(() => { this.textBox1.Text = "いつもの定型文"; }));

            // ショートカット登録
            // この場合textBox1がアクティブな場合に有効
            // Windows Forms標準のTextBoxにも適用可能
            gcShortcut1.SetShortcuts(this.textBox1, sc);
        }
Example #9
0
		private static CustomShortcut FindNodeType(
			string typeName, ShortcutCollection nodes)
		{
			foreach (CustomShortcut cs in nodes)
			{
				if (cs.OwnerType.ToString() == typeName)
					return cs;

				return FindNodeType(typeName, cs.Nodes);
			}

			return null;
		}
Example #10
0
		private static void LoadNodes(XmlNode pnode, ShortcutCollection nodes)
		{
			foreach (XmlNode node in pnode.ChildNodes)
			{
				if (node.Name != "node")
					continue;

				//string name = node.Attributes["name"].Value;
				var typeName = node.Attributes["type"].Value;

				if (node.HasChildNodes)
				{
					var customShortcut = FindNodeType(typeName, nodes);

					if (customShortcut == null)
						continue;

					foreach (XmlNode entry in node.ChildNodes)
					{
						var key = entry.Attributes["key"].Value;
						var value = entry.Attributes["value"].Value;
						var sc = (Shortcut)Enum
							.Parse(typeof (Shortcut), key);

						customShortcut.HashTable[sc] = value;
					}
				}
			}
		}
Example #11
0
        public ShortcutProvider()
        {
            var shortcutCollection = new ShortcutCollection();
            var parsedShortcuts = resharperShortcuts.Split(new[] {"\r\n"}, StringSplitOptions.RemoveEmptyEntries)
                .Where(s => !s.StartsWith("#"))
                .Select(s =>
                            {
                                var strings = s.Split('|');
                                if (strings.Length != 2)
                                    return null;
                                return new
                                           {
                                               Label = strings[0],
                                               ShortcutKeys = strings[1].Split(',')
                                           };
                            })
                .Where(s => s != null)
                .Select(s => new KeyShortcut(s.Label,
                                             s.ShortcutKeys
                                                 .Select(k =>
                                                             {
                                                                 var key = k.Split('+').Last();
                                                                 var keys = ReplaceKey.ToKey(key);
                                                                 if (keys != null)
                                                                     return
                                                                         new KeyPressDefinition
                                                                             (keys.Value,
                                                                              shiftPressed:k.Contains("Shift"),
                                                                              controlPressed:k.Contains("Ctrl"),
                                                                              altPressed:k.Contains("Alt"));
                                                                 return null;
                                                             })
                                                             .Where(k=>k != null)
                                                 .ToArray())

                );

            foreach (var parsedShortcut in parsedShortcuts)
            {
                shortcutCollection.Add(parsedShortcut);
            }

            shortcuts.Add("devenv", shortcutCollection);
        }
 public PortableEnvironment()
 {
     Applications = new PortableApplicationCollection(this);
     Shortcuts = new ShortcutCollection(this);
 }