Exemplo n.º 1
0
        /*
         *      {
         *        "CustomStrings": [
         *          {
         *            "Name": "New Tab",
         *            "Description": "",
         *            "Index": 0,
         *            "List": [
         *              {
         *                "Name": "Example",
         *                "Description": "",
         *                "Command": "Welcome to use Easycom!"
         *              }
         *            ]
         *          }
         *        ]
         *      }
         */

        private void LoadFromFile()
        {
            if (!File.Exists(CommandListFilePath))
            {
                CreateExampleCommandFile();
            }

            try
            {
                using (StreamReader sr = File.OpenText(CommandListFilePath))
                {
                    CommandsJson = JObject.Parse(sr.ReadToEnd());
                    JToken TabList = null;
                    TabList = CommandsJson.Property("CustomStrings", StringComparison.InvariantCulture)?.Value;
                    if (TabList != null && TabList is JArray)
                    {
                        foreach (JObject tab in TabList)
                        {
                            string tabName       = (string)tab.Property("Name", StringComparison.InvariantCulture)?.Value;
                            string Description   = (string)tab.Property("Description", StringComparison.InvariantCulture)?.Value;
                            JToken CustomStrings = tab.Property("StrList", StringComparison.InvariantCulture)?.Value;

                            if (tabName != null && Description != null && CustomStrings is JArray)
                            {
                                CustomStrTab newTab = new CustomStrTab(tabName);
                                newTab.Description = Description;
                                CustomStrTabList.Add(newTab);
                                foreach (JObject cs in (JArray)CustomStrings)
                                {
                                    string csName        = (string)cs.Property("Name", StringComparison.InvariantCulture)?.Value;
                                    string csDescription = (string)cs.Property("Description", StringComparison.InvariantCulture)?.Value;
                                    string csStr         = (string)cs.Property("Text", StringComparison.InvariantCulture)?.Value;
                                    if (csName != null && csDescription != null && csStr != null)
                                    {
                                        ;
                                    }
                                    newTab.StrList.Add(new CustomStrData(csName, csDescription, csStr));
                                }
                            }
                        }

                        OnLoadFinish?.Invoke();
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                CreateExampleCommandFile();
            }
        }
Exemplo n.º 2
0
        private void ButtonEditConfirm_Click(object sender, RoutedEventArgs e)
        {
            if (editMode == EditMode.EditString || editMode == EditMode.EditTab)
            {
                if (editMode == EditMode.EditTab)
                {
                    Object tab = ListBox_Tab.SelectedItem;
                    if (tab != null)
                    {
                        TabItemModel item = (TabItemModel)tab;

                        item.Data.Name        = TextBox_Name.Text;
                        item.Data.Description = TextBox_Description.Text;
                        item.SetPropertyChanged("Data");
                    }
                }
                else
                {
                    Object str = ListBox_Str.SelectedItem;
                    if (str != null)
                    {
                        StrItemModel item = (StrItemModel)str;
                        item.Data.Name        = TextBox_Name.Text;
                        item.Data.Description = TextBox_Description.Text;
                        item.Data.Text        = TextBox_Command.Text;
                        item.SetPropertyChanged("Data");
                    }
                }
            }
            else
            {
                if (editMode == EditMode.AddTab)
                {
                    CustomStrTab newTab = new CustomStrTab(TextBox_Name.Text);
                    newTab.Description = TextBox_Description.Text;
                    TabList.Add(newTab);
                    TabItemModel newModel = new TabItemModel(newTab);
                    tabListBoxViewModel.ModelCollection.Add(newModel);
                    ListBox_Tab.SelectedItem = newModel;
                }
                else
                {
                    CustomStrData newStr = new CustomStrData(TextBox_Name.Text, TextBox_Description.Text, TextBox_Command.Text);
                    Object        tab    = ListBox_Tab.SelectedItem;
                    if (tab != null)
                    {
                        TabItemModel item = (TabItemModel)tab;
                        item.Data.StrList.Add(newStr);
                        TabStrRefresh(item.Data.StrList);
                        ListBox_Str.SelectedIndex = item.Data.StrList.Count - 1;
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void InfoChangeCheck()
        {
            bool changed = false;
            bool isNull  = false;

            if (editMode == EditMode.EditTab || editMode == EditMode.EditString)
            {
                string Name        = null;
                string Description = null;
                string Command     = null;


                if (editMode == EditMode.EditTab)
                {
                    Object tab = ListBox_Tab.SelectedItem;
                    if (tab != null)
                    {
                        CustomStrTab tabData = ((TabItemModel)tab).Data;

                        Name        = tabData.Name;
                        Description = tabData.Description;
                    }
                    else
                    {
                        isNull = true;
                    }
                }
                else
                {
                    Object str = ListBox_Str.SelectedItem;
                    if (str != null)
                    {
                        CustomStrData strData = ((StrItemModel)str).Data;
                        Name        = strData.Name;
                        Description = strData.Description;
                        Command     = strData.Text;
                    }
                    else
                    {
                        isNull = true;
                    }
                }
                if (!isNull)
                {
                    if (TextBox_Name.Text != Name)
                    {
                        changed = true;
                    }
                    else if (TextBox_Description.Text != Description)
                    {
                        changed = true;
                    }
                    else if (editMode == EditMode.EditString && TextBox_Command.Text != Command)
                    {
                        changed = true;
                    }
                }
                if (changed)
                {
                    ButtonEditConfirm.IsEnabled = (TextBox_Name.Text.Length != 0);
                    ButtonEditCancel.IsEnabled  = true;
                }
                else
                {
                    ButtonEditConfirm.IsEnabled = false;
                    ButtonEditCancel.IsEnabled  = false;
                }
            }
            else
            {
                ButtonEditConfirm.IsEnabled = (TextBox_Name.Text.Length != 0);
                ButtonEditCancel.IsEnabled  = true;
            }
        }