private void loadJson(object sender, RoutedEventArgs e)
        {
            clearMacroComboBox();
            clearSingleKeyComboBox();

            OnTapMacroTextBlock.Text  = "";
            OnHoldMacroTextBlock.Text = "";

            if (mainWindow.keyboardinfomodel.SelectedJsonLayout == null)
            {
                // return;
            }

            //store the path to the json file
            var json_path = mainWindow.keyboardinfomodel.SelectedJsonLayout.layoutPath;

            //create keyboard oject and initialize with the contents within the json file
            try
            {
                keeb = get_keyboard_json_from_path(json_path);
                //create the grid for the binding editor

                keyBoardGridPicker.Children.Clear();

                GridCreate(keeb.ui_desc.rows, keeb.ui_desc.cols);
                //generate the json specified keycaps
                generateKeyCaps(keeb);
            }
            catch (Exception dse)
            {
                MessageBox.Show("Error Deserializing: " + dse);
            }
        }
        private void generateKeyCaps(QK.Keyboard kc)
        {
            foreach (var key in kc.keys)
            {
                int row = key.graphics.row;
                int col = key.graphics.col;

                key.binding.on_hold.Clear();
                key.binding.on_tap.Clear();

                KeyCapButton kcb = new KeyCapButton(key);
                if (key.matrix.row == null && key.matrix.col == null)
                {/*skip*/
                }
                else
                {
                    //open model here.
                    kcb.keyButton.Click += selectKeyView;
                }
                keyBoardGridPicker.Children.Add(kcb);
                Grid.SetRow(kcb, row);
                Grid.SetColumn(kcb, col);
            }
        }
Пример #3
0
        /* User button event for creating the json layout */
        private void createJson_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string KeyboardLayoutName = layoutNameTextbox.Text;     //Layout Name

                validateLayoutName(KeyboardLayoutName);

                qk.Keyboard keeb = new qk.Keyboard();
                List <QKeyCommon.Keyboard_items.Keyboard> JsonInfo = new List <QKeyCommon.Keyboard_items.Keyboard>(); //List Contains Json Info
                List <qk.Key_items.Key> KeyItems = getKeyData();                                                      //List Contains Json Info using GetKeyData()



                if (mainWindow.layouteditormodel.SelectedDiodeDirection != null)
                {
                    keeb.spec.diode_direction = mainWindow.layouteditormodel.SelectedDiodeDirection.diodeValue;
                }
                else
                {
                    throw new Exception("No diode direction selected. [Define Keyboard Matrix]");
                }


                keeb.ui_desc.rows      = int.Parse(gridRow.Text);
                keeb.ui_desc.cols      = int.Parse(gridColumn.Text);
                keeb.desc.product_name = model.layoutname;

                if (mainWindow.keyboardinfomodel.SelectedMicroProc != null)
                {
                    keeb.spec.avrdude.partno         = mainWindow.keyboardinfomodel.SelectedMicroProc.mpCode;
                    keeb.spec.avrdude.partno_verbose = mainWindow.keyboardinfomodel.SelectedMicroProc.mpName;
                }
                else
                {
                    throw new Exception("We are confused as to how you got here without selecting a microprocessor.");
                }


                if (KeyItems.Count <= 0)
                {
                    throw new Exception("Keyboard should have keys added.");
                }

                keeb.keys = KeyItems;

                if (model.SelectedKeyboardRowPins.Count() <= 0 || model.SelectedKeyboardColPins.Count() <= 0)
                {
                    throw new Exception("Keyboard must have valid keyboard matrix size defined. Atleast 1 pin row/col [Define Keyboard Matrix]");
                }

                keeb.spec.matrix_spec.rows     = model.SelectedKeyboardRowPins.Count();
                keeb.spec.matrix_spec.row_pins = model.KeyboardMatrixRow.TrimEnd(',').Split(',').ToList();

                keeb.spec.matrix_spec.cols     = model.SelectedKeyboardColPins.Count();
                keeb.spec.matrix_spec.col_pins = model.KeyboardMatrixCol.TrimEnd(',').Split(',').ToList();

                //string jsonPath = (mainWindow.approot + KeyboardLayoutName + ".json");
                string output           = JsonConvert.SerializeObject(keeb, Formatting.Indented); //Serialize the List and add to output string
                var    userTemplatePath = System.IO.Path.Combine(mainWindow.userTemplatesFolderPath, KeyboardLayoutName + ".json");
                try
                {
                    System.IO.File.WriteAllText(userTemplatePath, output); //Save file
                }
                catch
                {
                    throw new Exception("Invalid Folder Name.");
                }


                mainWindow.keyboardinfomodel.SelectedJsonLayout.layoutPath = userTemplatePath;
                mainWindow.keyboardinfomodel.JsonLayouts.Add(new JsonTemplateLayout(keeb.desc.product_name, userTemplatePath));
                NavigationService.Navigate(mainWindow.bindingEditorPage);
            }
            catch (Exception err)
            {
                MessageBox.Show("An error occured while serializing the object: " + err.Message);
            }
        }