Пример #1
0
 public void frmCreateActivity_Load(object sender, EventArgs e)
 {
     Strings.Translate(this);
     GUIUtilities.ScaleDPI(this);             // no need to scale since the entire form is auto size
     m_AppliedUser    = Globals.Root.GenerateAppliedConfig(Users.User, Globals.Root.CurrentDocument);
     m_AppliedTeacher = Globals.Root.GenerateAppliedConfig(Users.Editor, Globals.Root.CurrentDocument);
 }
Пример #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
        /// <summary>Notification that settings have changed and this may need to update the engine</summary>
        /// <param name="appliedConfig">Supplied so that frmEditConfig can use what is displayed (which may not be current user/teacher)</param>
        public void SettingsChanged(AppliedConfig appliedConfig)
        {
            if (m_Failed)
            {
                return;
            }
            string voice = appliedConfig.ReadString(Config.Speech_Voice);

            if (!string.IsNullOrEmpty(voice) && voice == m_SelectedVoice)
            {
                // we just reapply the other settings, although they may not have changed.  I think these are probably quite fast
                ApplySettings(appliedConfig);
                return;
            }
            // wrong voice is selected; but we will only select the correct voice when it is needed
            m_SelectedVoice = "x";
        }
Пример #4
0
 private void MergeSettings(Config newSettings, Config previous, AppliedConfig applied)
 {
     if (previous == null)
     {
         return;
     }
     if (previous.ReadBooleanEx(Config.Shapes_DefaultOff))
     {
         // this is not supported at the activity level, so we'll need to hide every shape
         foreach (Shape.Shapes shape in Shape.UserShapes)
         {
             newSettings.Write(Config.ShapeEnableKey(shape), false.ToString());
         }
     }
     foreach (string key in previous.Values.Keys)
     {
         newSettings.Write(key, previous.Values[key]);
     }
 }
Пример #5
0
 private void ApplySettings(AppliedConfig appliedConfig)
 {
     //applies the settings other than the voices selection
     if (m_Failed)
     {
         return;
     }
     try
     {                                                                     // volume still 0-100
         Speaker.Volume = appliedConfig.ReadInteger(Config.Speech_Volume, 100);
         int rate100 = appliedConfig.ReadInteger(Config.Speech_Speed, 50); // note default was 70 in V2-
         Speaker.Rate = rate100 / 5 - 10;                                  // this is on a -10 to +10 scale
         // no pitch available
     }
     catch (Exception ex)
     {
         Utilities.LogSubError(ex);
     }
 }
Пример #6
0
        public static void UpdateCustomPalettes(AppliedConfig applied)
        {
            // should be called (by frmMain) when the configuration changes.  Adds any new custom palettes to the list.
            // Any custom palettes listed here which are no longer valid are not deleted, rather just marked Valid = false.  The chances are they will come back in scope again
            // if we are moving between user and teacher mode or changing between documents in a multi-document view.  Deleting the palette completely would delete its position information
            // causing it to reappear somewhere else.  So these records are kept.  This is analogous to what happens with the system palettes - the Palette object isn't wiped!
            Dictionary <string, Document> customPalettes = applied.CustomPalettes(true);

            // First check any palettes already in our list, to see if they are still valid
            foreach (Palette palette in List.Values.Where(x => x.UserDefined))
            {
                palette.IsValid = customPalettes.ContainsKey(palette.ID);
            }
            foreach (string custom in customPalettes.Keys)
            {
                if (!List.ContainsKey(custom))
                {
                    Register(new Palette(customPalettes[custom]));
                }
            }
        }
Пример #7
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;
        }
Пример #8
0
        public void Fill(AppliedConfig applied)
        {
            // fill the Treeview showing the possible actions
            try
            {
                TV.Nodes.Clear();                                          // should already be empty, but just in case...
                ActionImageList.Images.Clear();
                ActionImageList.Images.Add("Folder", Resources.AM.folder); // must be first, because by default the Treeview uses index 0 for the folders
                ActionImageList.Images.Add("Empty", Resources.AM.Empty);
                ActionImageList.Images.Add("CursorClick", Resources.AM.CursorClick);

                // shapes...
                TreeNode folder = TV.Nodes.Add(Strings.Item("Config_ShapesTools"));
                foreach (Shape.Shapes shape in Shape.UserShapes.Union(new[] { Shape.Shapes.SetRotation }))                 // set rotation is included in here, although not entirely a normal user shape
                {
                    //If Shape.HideShapeType (eShape) andalso not **advanced continue for
                    ToolAction action = new ToolAction(shape);
                    TreeNode   node   = folder.Nodes.Add(action.DescriptionWithoutAccelerator());
                    Image      image  = GUIUtilities.ShapeImage(shape, 32);
                    if (image != null)
                    {
                        ActionImageList.Images.Add(action.ToString(), image);
                        node.ImageKey         = action.ToString();
                        node.SelectedImageKey = action.ToString();
                    }
                    else
                    {
                        node.ImageKey = node.SelectedImageKey = "Empty";
                    }
                    node.Tag = action;
                }


                // Drawing area...
                folder = TV.Nodes.Add(Strings.Item("Config_KeysDrawing"));
                AddKeyVerbs(1000, (int)Codes.Decrement, "Config_ShapeVerbs", folder.Nodes);                 // excludes ChooseExisting
                if (Mode != Modes.Button)
                {
                    AddKeyVerbs(1100, 1149, "Config_MouseControl", folder.Nodes);
                }
                AddKeyVerbs(1150, 1199, "Config_Scrolling", folder.Nodes);
                AddKeyVerbs(1200, 1249, "Config_ShapeSelection", folder.Nodes);
                TreeNode subFolder = folder.Nodes.Add(Strings.Item("Config_Keys_Snapping"));
                foreach (Shape.SnapModes snap in new[] { Shape.SnapModes.Off, Shape.SnapModes.Grid, Shape.SnapModes.Shape, Shape.SnapModes.Angle })
                {
                    AddAction(subFolder, new SnapAction(snap));
                }
                AddAction(subFolder, new ShowGridAction(1));
                if (Mode != Modes.Button)
                {
                    Action tools = new PaletteAction(Parameters.Tool);
                    AddAction(folder, tools, tools.DescriptionWithoutAccelerator(), "CursorClick");
                }

                // Verbs...
                TreeNode verbs = AddKeyVerbs(0, 999, "Config_Verbs");

                // Styles...
                folder = TV.Nodes.Add(Strings.Item("Config_Keys_Styles"));
                FillStyleActions(folder, Parameters.FillColour, true);
                FillStyleActions(folder, Parameters.FillPattern);
                FillStyleActions(folder, Parameters.LineColour, true);
                FillStyleActions(folder, Parameters.LineWidth, true);
                FillStyleActions(folder, Parameters.LinePattern);

                // font doesn't use normal parameters
                subFolder = folder.Nodes.Add(Strings.Item("Palette_TextStyle"));
                if (Mode == Modes.Key)
                {
                    AddAction(subFolder, new PaletteAction(Parameters.FontSize), Strings.Item("Config_SwitchToPalette"), "CursorClick");
                }
                AddAction(subFolder, new ParameterAction(Parameters.TextAlignment, (int)StringAlignment.Near), Strings.Item("Align_Left"));
                AddAction(subFolder, new ParameterAction(Parameters.TextAlignment, (int)StringAlignment.Center), Strings.Item("Align_Centre"));
                AddAction(subFolder, new ParameterAction(Parameters.TextAlignment, (int)StringAlignment.Far), Strings.Item("Align_Right"));
                AddAction(subFolder, new ParameterAction(Parameters.TextVerticalAlignment, (int)StringAlignment.Near), Strings.Item("Align_Top"));
                AddAction(subFolder, new ParameterAction(Parameters.TextVerticalAlignment, (int)StringAlignment.Center), Strings.Item("Align_Middle"));
                AddAction(subFolder, new ParameterAction(Parameters.TextVerticalAlignment, (int)StringAlignment.Far), Strings.Item("Align_Bottom"));
                AddAction(subFolder, Verb.Find(Codes.TextSmaller));
                AddAction(subFolder, Verb.Find(Codes.TextLarger));

                // arrows just select palette
                //subFolder = folder.Nodes.Add(Strings.Item("Palette_Arrowheads"));
                //if (Mode == Modes.Key)
                //	AddAction(subFolder, new PaletteAction(Parameters.ArrowheadEndType), Strings.Item("Config_SwitchToPalette"), "CursorClick");

                subFolder = folder.Nodes.Add(Strings.Item("Config_Keys_Palettes"));
                AddAction(subFolder, new PaletteButtonAction(1), Strings.Item("Config_Keys_Palette_Refine"), "Empty");
                AddAction(subFolder, new PaletteButtonAction(2), Strings.Item("Config_Keys_Palette_Transparent"), "Empty");
                // in palettes main folder:
                AddAction(folder, Verb.Find(Codes.MovePalette));
                AddAction(folder, Verb.Find(Codes.ResizePalette));
                if (Mode == Modes.Key)
                {
                    subFolder = folder.Nodes.Add(Strings.Item("Config_SwitchToPalette_Other"));
                    foreach (Palette objPalette in from p in Palette.List.Values where p.PalettePurpose.IsCustom orderby Strings.Translate(p.Title) select p)
                    {
                        // only lists custom ones - assuming all purposes can be/have been listed separately
                        AddAction(subFolder, objPalette.PalettePurpose.GetSelectAction(), Strings.Translate(objPalette.EditDescription));
                    }
                }

                subFolder = folder.Nodes.Add(Strings.Item("Config_PalettesToggle"));
                AddAction(subFolder, new ShowPaletteAction(Palette.Purpose.Specials.Rotation), Strings.Item("Palette_Rotation"));
                AddAction(subFolder, new ShowPaletteAction(Palette.Purpose.Specials.CoordEdit), Strings.Item("Palette_CoordEdit"));
                AddAction(subFolder, new ShowPaletteAction(Palette.Purpose.Specials.Scale), Strings.Item("Palette_ShowScale"));

                if (Mode == Modes.Button)
                {
                    m_KeyNode                  = TV.Nodes.Add(Strings.Item("Action_SimulateKey"));
                    m_KeyNode.ImageIndex       = -1;
                    m_KeyNode.Tag              = new KeyAction(Keys.None);        // actual key will be selected in the editing screen
                    m_CharacterNode            = TV.Nodes.Add(Strings.Item("Action_TypeCharacter"));
                    m_CharacterNode.ImageIndex = -1;
                    m_CharacterNode.Tag        = new CharAction((char)0);              // actual text will be selected in the editing screen
                    m_TextNode                 = TV.Nodes.Add(Strings.Item("Action_TypeText"));
                    m_TextNode.ImageIndex      = -1;
                    m_TextNode.Tag             = new TextAction("");         // actual text will be selected in the editing screen
                }
            }
            catch (Exception ex) when(!Globals.Root.IsDebug)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #9
0
        private Action m_Action;                    // cannot directly update m_Button because the View (on the original document) can have trouble rendering if the action is updated but not the image

        public frmButton(ButtonStyle style, ButtonShape button, Transaction transaction)
        {
            m_Filling = true;
            InitializeComponent();
            Strings.Translate(this);             // must not be in Load, as the data occasionally has translatable items
            Strings.Translate(mnuImage);

            m_Button        = button;
            m_Style         = style;     // must be before any parameters are attached
            m_OriginalStyle = style;
            m_Transaction   = transaction;
            m_Action        = button.Action;

            FillStylesList();
            ReflectCustomState();
            ctrStyle.DisplayStyle(m_Style);

            // content
            txtText.Text          = button.LabelText;
            pnlImagePreview.Image = button.GetImageForPreview();
            if (button.TextRatio < 0)
            {
                sldTextRatio.Value          = 50;
                rdoTextRatioDefault.Checked = true;
            }
            else
            {
                sldTextRatio.Value      = (int)(button.TextRatio * 100);
                rdoTextRatioSet.Checked = true;
            }
            pnlImagePreview.NoImageString = Strings.Item("Button_NoImage");
            PrepareLayout();
            pnlLayout.SelectedIndex = Math.Min((int)m_Button.Layout & ((int)ButtonShape.Layouts.Superimpose - 1), pnlLayout.Controls.Count - 1);
            chkSuperimpose.Checked  = (m_Button.Layout & ButtonShape.Layouts.Superimpose) > 0;
            ShowRatioAndLayout();

            // We need the configuration which will (probably) be in effect when the palette is used.  We assume user mode
            // as this is mainly to detect custom shapes.  Any available in user mode will also be available in teacher mode
            Document document = Globals.Root.CurrentDocument;             // document being edited; PROBABLY a palette, although buttons can be placed on pages ??

            if (document.PaletteWithin != null)
            {
                document = document.PaletteWithin.Document;
            }
            AppliedConfig applied = new AppliedConfig();

            applied.AddConfigAtEnd(document.UserSettings);             // Doesn't matter if any of the items passed to AddConfigAtEnd are nothing
            applied.AddConfigAtEnd(document.BothSettings);
            // Add the activity, if there is one specified in the document...
            if (!document.ActivityID.Equals(Guid.Empty))
            {
                Document activity = Activities.GetActivitySettings(document.ActivityID);
                if (activity != null)
                {
                    applied.AddConfigAtEnd(activity.UserSettings);
                    applied.AddConfigAtEnd(activity.BothSettings);
                }
            }
            applied.AddConfigAtEnd(Config.UserCurrent);             // User mode is assumed.  Any custom shapes only present in teacher mode will be ignored
            // (Note that the actions list isn't really interested in what is visible; only what is defined)
            applied.AddConfigAtEnd(Config.SystemConfig);
            ctrActions.Fill(applied);

            // Actions data
            chkDisplayFromAction.Checked = button.DisplayFromAction;
            ctrActions.SelectedAction    = m_Action;
            if (button.Action.Change == Parameters.Action_Key)
            {
                chkActionKeyAuto.Checked = !string.IsNullOrEmpty(button.LabelText) && button.LabelText[0].ToKeyData() == (button.Action as KeyAction).Key;
            }
            else if (button.Action.Change == Parameters.Action_Character)
            {
                chkActionKeyAuto.Checked = true;                 // I think the only way of achieving this is using the checkbox
            }
            else if (button.Action.Change == Parameters.Action_Text)
            {
                chkActionKeyAuto.Checked = button.LabelText == (button.Action as TextAction).Text;
            }
            ReflectAction();
            m_Filling = false;
        }
Пример #10
0
        public RootApplication(frmMenu frm)
        {
#if DEBUG
            IsDebug = true;
#endif
            Menu = frm;
            m_Documents.Add(null);             // because the editor will just assign the current document into the current index

            // folders...
            EXEFolder      = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            InternalFolder = EXEFolder;

            SharedFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), AppName);
            ConfigFolder = SharedFolder;
            bool sharedCreated = false;
            // create shared folder and set permissions
            try
            {
                if (!System.IO.Directory.Exists(SharedFolder))
                {
                    System.IO.Directory.CreateDirectory(SharedFolder);
                    System.Security.AccessControl.DirectorySecurity    dirSecurity = System.IO.Directory.GetAccessControl(SharedFolder);
                    System.Security.Principal.SecurityIdentifier       user        = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.BuiltinUsersSid, null);
                    System.Security.AccessControl.FileSystemAccessRule newRule     = new System.Security.AccessControl.FileSystemAccessRule(user, System.Security.AccessControl.FileSystemRights.FullControl,
                                                                                                                                            System.Security.AccessControl.InheritanceFlags.ContainerInherit | System.Security.AccessControl.InheritanceFlags.ObjectInherit, System.Security.AccessControl.PropagationFlags.None, System.Security.AccessControl.AccessControlType.Allow);
                    dirSecurity.AddAccessRule(newRule);
                    System.IO.Directory.SetAccessControl(SharedFolder, dirSecurity);

                    sharedCreated = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cannot create required folder: " + SharedFolder + "\r\n" + "Error: " + ex);
                Application.Exit();
            }

#if DEBUG
            EXEFolder      = "d:\\data\\ace\\SAW\\Installer\\installer files";
            InternalFolder = EXEFolder;
            // config certainly needs to write back to the installation folder
            ConfigFolder = "d:\\data\\ace\\SAW\\test data";
            SharedFolder = "d:\\data\\ace\\SAW\\test data";
#else
            // Temporary version using folder location for everything
            //SharedFolder = EXEFolder + System.IO.Path.DirectorySeparatorChar + "Data";
            //ConfigFolder = SharedFolder;
#endif

            Globals.Root = this;
            try
            {
                Log                      = new CLogFile(SharedFolder + System.IO.Path.DirectorySeparatorChar + "log.txt");
                LogPermanent             = new CLogFile(SharedFolder + System.IO.Path.DirectorySeparatorChar + "permanent.txt", 100000);
                LogPermanent.TimeStampEx = TimeStamps.Date;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not create log files: " + ex.Message);
            }
            Log.WriteLine("Starting, version = " + SoftwareVersion.VersionString);
            Log.WriteLine("EXEFolder = " + EXEFolder);
            Log.WriteLine("SharedFolder = " + SharedFolder);
            Log.WriteLine("InternalFolder = " + InternalFolder);
            Log.WriteLine("OS = " + Environment.OSVersion);
            Log.WriteLine("64-bit = " + Environment.Is64BitOperatingSystem);
            Log.WriteLine("CLR = " + Environment.Version);
            Globals.CheckThemeOnStartup();

            if (sharedCreated)
            {
                // need to copy across from Splash 1 if applicable
                LogPermanent.WriteLine("Shared folder created");
            }

            Strings.Load();
            Log.WriteLine("SystemDPI = " + GUIUtilities.SystemDPI);

            Functions.Verb.CreateList();             // must before any configs loaded
            Functions.SAWVerbs.RegisterVerbs();

            // load configurations...
            Config.SystemConfig = LoadConfig("system" + Config.Extension, Config.Levels.System);
            Config.UserUser     = LoadConfig("User" + Config.Extension, Config.Levels.User, "user_Default" + Config.Extension);
            Config.UserUser.EnsureUserResources();
            if (!System.IO.Directory.Exists(Activities.ActivityConfigFolder))
            {
                System.IO.Directory.CreateDirectory(Activities.ActivityConfigFolder);
            }
            // activities are now loaded as needed

#if !DEBUG
            AppDomain.CurrentDomain.UnhandledException += frmErrorReport.UnhandledException;
            Application.ThreadException += frmErrorReport.ThreadException;
#else
            Config.Delta.ApplyV8Changes();
#endif
            CurrentConfig = new AppliedConfig();
            CurrentConfig.AddConfigAtEnd(Config.SystemConfig);
            CurrentConfig.AddConfigWithPriority(Config.UserUser);
        }