Пример #1
0
        public Config GetCurrentConfig(Config.Levels level, Document document, Users user = Users.Undefined)
        {
            switch (level)
            {
            case Config.Levels.System:
                return(Config.SystemConfig);

            case Config.Levels.ActivityUser:
                Document objActivity_1 = Activities.GetActivitySettings();
                return(objActivity_1?.UserSettings);

            case Config.Levels.ActivityBoth:
                Document objActivity = Activities.GetActivitySettings();
                return(objActivity?.BothSettings);

            case Config.Levels.DocumentUser:
                return(document?.UserSettings);

            case Config.Levels.DocumentBoth:
                return(document?.BothSettings);

            case Config.Levels.User:
                return(Config.UserCurrent);

            default:
                Debug.Fail("Unexpected config level in AM.GetCurrentConfig");
                return(null);
            }
        }
Пример #2
0
        public AppliedConfig GenerateAppliedConfig(Users user, Document document)
        {
            AppliedConfig create = new AppliedConfig();

            for (Config.Levels level = Config.Levels._First; level <= Config.Levels._Last; level++)
            {
                if (level != Config.Levels.DocumentUser && level != Config.Levels.ActivityUser || user == Users.User)
                {
                    create.AddConfigAtEnd(GetCurrentConfig(level, document, user));
                }
            }
            return(create);
        }
Пример #3
0
        private frmEditConfig(Config config, Config.Levels level, Document document)
        {
            m_Filling = true;
            InitializeComponent();
            m_Level   = level;
            m_Config  = config;
            m_Applied = new AppliedConfig(new[] { config, Config.SystemConfig }.ToList());
            // we don't scale (most controls are auto-size), except for the list on the left:
            pnlSections.Width = pnlSections.Width * GUIUtilities.SystemDPI / 96;

            m_Document = document;
            CreatePanels();

            Strings.Translate(this, ttMain);
            m_Transaction = new Transaction();
            m_Transaction.DocumentNotChanged = true;             // will be cleared again if any actual edits made to doc config
            m_Filling = false;

            pnlSections.SelectedIndex = 0;
            pnlSections_SelectedIndexChanged(this, null);

            Switches.Switching.PhysicalSwitch.MasterSwitchChanged += PhysicalSwitch_MasterSwitchChanged;
        }
Пример #4
0
        internal Config LoadConfig(string file, Config.Levels level, string defaultFile = "")
        {
            // defaultFile can be the name of the file used as a default - ie the one in InternalFolder which will be copied in.
            Debug.Assert(!file.StartsWith("\\"));
            if (level == Config.Levels.DocumentBoth || level == Config.Levels.ActivityBoth)
            {
                throw new ArgumentException("level");
            }
            if (string.IsNullOrEmpty(defaultFile))
            {
                defaultFile = file;
            }
            string path = ConfigFolder + System.IO.Path.DirectorySeparatorChar + (level == Config.Levels.ActivityUser ? "Activities" + System.IO.Path.DirectorySeparatorChar : "");

            path += file;
            Log.WriteLine("Load config: " + path);
            if (System.IO.File.Exists(path))
            {
                try
                {
                    Config config = Config.FromFile(path, level);
                    if (level == Config.Levels.User)
                    {
                        config.EnsureUserResources();
                    }
                    return(config);
                }
                catch (Exception ex) when(!IsDebug)
                {
                    Globals.Root.LogPermanent.WriteLine("Failed to load configuration: " + file + ": " + ex.Message);
                    Utilities.LogSubError(ex);
                }
            }
            try
            {
                path = InternalFolder + System.IO.Path.DirectorySeparatorChar + (level == Config.Levels.ActivityUser ? "Activities" + System.IO.Path.DirectorySeparatorChar : "") + defaultFile;
                if (System.IO.File.Exists(path))
                {
                    // The default copies of these are installed by the installer, and they are then copied to the shared folder when first referenced
                    Globals.Root.Log.WriteLine("Loading config from default at: " + path);                     // + ", code=" + (New StackTrace).ToString)
                    Config config = Config.FromFile(path, level);
                    if (level == Config.Levels.User)
                    {
                        // want to force ID change
                        Mapping  map    = new Mapping();
                        Document newDoc = (Document)config.Document.Clone(map);
                        config = newDoc.UserSettings;
                        if (level == Config.Levels.User)
                        {
                            config.EnsureUserResources();
                        }
                        newDoc.UpdateReferencesIDsChanged(map, newDoc);
                    }
                    // will be saved back to the config folder when it is saved
                    return(config);
                }
            }
            catch (Exception ex)
            {
                Globals.Root.LogPermanent.WriteLine("Failed to load DEFAULT configuration: " + file + ": " + ex.Message);
                Utilities.LogSubError(ex);
            }
            Config create = new Config();

            create.Document = new Document(true);
            create.Document.UserSettings = create;
            Utilities.LogSubError("Config not found (" + file + ").  Creating a blank one", true);
            if (level == Config.Levels.System)
            {
                create.InitialiseAsDefaultSystem();
            }
            if (level == Config.Levels.User)
            {
                create.EnsureUserResources();
            }
            create.AutoCreated = true;
            return(create);
        }
Пример #5
0
        /// <summary>Edits the config.  Document should be the document being edited, not the config container document</summary>
        public static DialogResult EditConfig(Config.Levels level, Document document, Config config = null, bool userOnly = false, Sections initialSection = (Sections)(-1))
        {
            // returns DialogResult = Yes if OK, but has stored doc settings transaction which will have triggered refresh of main screen settings already
            Config.UserCurrent.StorePalettePositions();
            if (config == null)
            {
                config = Globals.Root.GetCurrentConfig(level, document);
            }
            frmEditConfig frm = new frmEditConfig(config, level, document);

            if (initialSection >= 0)
            {
                frm.pnlSections.SelectedIndex = (int)initialSection;
            }
            DialogResult result = frm.ShowDialog();

            if (result == DialogResult.OK)
            {
                bool usersChanged    = false;
                bool documentChanged = false;
                bool activityChanged = false;
                foreach (Config changed in frm.m_Changed.Values)
                {
                    if (changed == Config.UserUser)
                    {
                        usersChanged = true;
                    }
                    else if (changed == Config.SystemConfig)
                    {
                        Globals.Root.SaveSystemConfig();
                    }
                    else if (changed == document.UserSettings || changed == document.BothSettings)
                    {
                        documentChanged = true;
                    }
                    else
                    {
                        // must be from current activity; could be either part
                        activityChanged = true;
                    }
                }
                if (documentChanged)
                {
                    Globals.Root.StoreNewTransaction(frm.m_Transaction);
                }
                if (usersChanged)
                {
                    Globals.Root.SaveUserConfigs();
                }
                if (activityChanged)
                {
                    Globals.Root.SaveActivityConfig();
                }
                if (frm.m_PalettePurposeChanged)
                {
                    // One or more user-defined palettes have had their purpose changed
                    foreach (Palette palette in Palette.List.Values)
                    {
                        if (palette.UserDefined)
                        {
                            palette.PalettePurpose = palette.CustomDocument.PalettePurpose;
                        }
                    }
                }
                if (frm.m_OpenPaletteOnExit != null)
                {
                    if (Globals.Root.User == Users.User)
                    {
                        Globals.Root.User = Users.Editor;
                    }
                    Globals.Root.SelectDocument(frm.m_OpenPaletteOnExit);
                }
                Globals.OnSettingsChanged();
            }
            else
            {
                frm.m_Transaction.Cancel();
            }
            return(result);
        }