Ejemplo n.º 1
0
        /// <summary>
        /// Opens a dialog to edit a Locale's languageid.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void contextclick_EditLocale(object sender, EventArgs e)
        {
            var parent = (GffData.Field)SelectedNode.Parent.Tag;

            if (parent.localeflags != LocaleDialog.Loc_ALL)
            {
                var field = (GffData.Field)SelectedNode.Tag;

                GffData.Locale locale;

                locale  = parent.Locales[(int)field.localeid];
                _langid = locale.langid;
                _langf  = locale.F;

                using (var f = new LocaleDialog(parent.localeflags, true))
                {
                    if (f.ShowDialog(this) == DialogResult.OK &&
                        (locale.langid != _langid || locale.F != _langf))
                    {
                        LocaleDialog.ClearLocaleFlag(ref parent.localeflags,
                                                     locale.langid,
                                                     locale.F);

                        field.label = GffData.Locale.GetLanguageString(locale.langid = _langid,
                                                                       locale.F = _langf);
                        ((Sortable)SelectedNode)._label = field.label;

                        LocaleDialog.SetLocaleFlag(ref parent.localeflags,
                                                   _langid,
                                                   _langf);

                        SelectedNode.Text = GeneralGFF.ConstructNodetext(field, locale);

                        _f.GffData.Changed = true;
                        _f.GffData         = _f.GffData;
                    }
                }
            }
            else
            {
                using (var f = new InfoDialog(Globals.Error, "All locales are taken."))
                    f.ShowDialog(this);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deletes a field in the TreeList along with any of its subnodes.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        internal void contextclick_Delete(object sender, EventArgs e)
        {
            bool delete;

            if (SelectedNode.Tag == null)             // is TopLevelStruct's node
            {
                delete = false;
                using (var f = new DeleteDialog("Confirm delete TopLevelStruct"))
                {
                    f.cb_Bypass.Visible = false;
                    if (f.ShowDialog(this) == DialogResult.Yes)
                    {
                        delete = true;

                        if (_f.GffData.Pfe == Globals.TopLevelStruct)
                        {
                            _f.GffData = null;
                        }
                    }
                }
            }
            else if (!_bypassDeleteWarning)
            {
                string head = "Confirm delete";
                if (SelectedNode.Nodes.Count != 0)
                {
                    head += " multiple fields";
                }

                delete = false;
                using (var f = new DeleteDialog(head))
                {
                    f.cb_Bypass.Visible = true;

                    if (f.ShowDialog(this) == DialogResult.Yes)
                    {
                        delete = true;
                        _bypassDeleteWarning = f.cb_Bypass.Checked;
                    }
                }
            }
            else
            {
                delete = true;
            }

            if (delete)
            {
                if (SelectedNode.Tag != null)
                {
                    switch (((GffData.Field)SelectedNode.Tag).type)
                    {
                    case FieldTypes.Struct:
                    {
                        // Structs in Lists do not have a Label so keep their pseudo-labels' sequential order

                        var parent = SelectedNode.Parent;
                        if (parent.Tag != null &&                              // parent is NOT TopLevelStruct
                            ((GffData.Field)parent.Tag).type == FieldTypes.List)
                        {
                            Sortable node;

                            var field = (GffData.Field)SelectedNode.Tag;
                            int id    = Int32.Parse(field.label);
                            while (++id != parent.Nodes.Count)
                            {
                                node            = parent.Nodes[id] as Sortable;
                                field           = (GffData.Field)node.Tag;
                                node._label     =
                                    field.label = (id - 1).ToString();

                                node.Text = GeneralGFF.ConstructNodetext(field);
                            }
                        }
                        break;
                    }

                    case FieldTypes.locale:
                    {
                        var parent  = (GffData.Field)SelectedNode.Parent.Tag;
                        var locales = parent.Locales;

                        int            localeid = (int)((GffData.Field)SelectedNode.Tag).localeid;
                        GffData.Locale locale   = locales[localeid];

                        LocaleDialog.ClearLocaleFlag(ref parent.localeflags,
                                                     locale.langid,
                                                     locale.F);

                        for (int i = 0; i != SelectedNode.Parent.Nodes.Count; ++i)
                        {
                            var field = (GffData.Field)SelectedNode.Parent.Nodes[i].Tag;
                            if (field.localeid > localeid)
                            {
                                --field.localeid;
                            }
                        }

                        locales.Remove(locale);
                        break;
                    }
                    }
                }

                SelectedNode.Remove();

                if (SelectedNode == null)
                {
                    _f.ResetEditPanel();
                }

                if (_f.GffData != null)
                {
                    _f.GffData.Changed = true;
                }
                _f.GffData = _f.GffData;
            }
        }