예제 #1
0
        protected override void OnActivated(System.EventArgs e) // {{{ focus
        {
            string caller = "OnActivated";

            //FIXME if( DX1Utility.Debug ) log_Clear();
            if (DX1Utility.Debug)
            {
                log("===============");
            }
            if (DX1Utility.Debug)
            {
                log("= " + caller + "  =");
            }
            if (DX1Utility.Debug)
            {
                log("===============");
            }

            if (ShutDown_Requested)
            {
                return;
            }

            // UI .. (update version age)
            this.Text = DX1Utility.APP_WINDOW_TITLE + Util.RetrieveLinkerTimestamp();

            if (DX1UtilityInstance.InvokeRequired)
            {
                DX1UtilityInstance.Invoke((MethodInvoker) delegate() { SyncUI.L_Status_set_text(this.Text); });
            }
            else
            {
                SyncUI.L_Status_set_text(this.Text);
            }

            // UI .. (focus changed)
            DX1UtilityHasFocus = DX1UtilityInstance.ContainsFocus;
            if (DX1Utility.Debug)
            {
                log("OnActivated:    DX1UtilityInstance.ContainsFocus " + DX1UtilityHasFocus);
            }

            ApplyKeySet(caller);
        }
예제 #2
0
        //}}}
        public void ApplyKeySet(string caller)  //{{{
        {
            if (DX1Utility.Debug)
            {
                Log("ApplyKeySet" + Globals.SYMBOL_ARROW_L + " " + caller);
            }
            if (DX1Utility.Debug)
            {
                Log("DX1UtilityHasFocus " + DX1UtilityHasFocus);
            }

            // 1/2 - PUSH PENDING COMMIT .. (on shutdown or loosing focus) {{{
            if (!DX1UtilityHasFocus || ShutDown_Requested)
            {
                ApplyKeySet_post();
            }
            //}}}
            // 2/2 - DISPLAY PENDING COMMIT {{{
            else
            {
                // CANCEL PENDING UPDATES {{{
                if (ApplyKeySet_thread != null)
                {
                    ApplyKeySet_thread = null;

                    Log(Globals.SYMBOL_ARROW_L + "UPDATES CANCELED .. NOW UNDER USER CONTROL");
                }
                //}}}
                // LOG PENDING UPDATES TO COMMIT {{{
                string msg_line1 = "";
                if (profile.keyProgrammer.Profile_changeToCommit != "")
                {
                    msg_line1 = "PENDING UPDATE: PROFILE [" + profile.CurrentProfileName + "] .. (" + profile.keyProgrammer.Profile_changeToCommit + ")";
                }
                else
                if (DX1Utility.Debug)
                {
                    Log(".. no pending [" + profile.CurrentProfileName + "] PROFILE UPDATE");
                }

                string msg_line2 = "";
                if (profile.keyProgrammer.KeyMap_changeToCommit != "")
                {
                    msg_line2 = "PENDING UPDATE: KEYMAP [" + profile.CurrentProfileName + "] ..  (" + profile.keyProgrammer.KeyMap_changeToCommit + ")";
                }
                else
                if (DX1Utility.Debug)
                {
                    Log(".. no pending [" + profile.CurrentProfileName + "] KEYMAP UPDATE");
                }

                if (msg_line1 != "")
                {
                    Log(msg_line1);
                }
                if (msg_line2 != "")
                {
                    Log(msg_line2);
                }

                //}}}
            }
            //}}}
            // UI COLORS AND FOCUS {{{
            stopWizard("ApplyKeySet" + Globals.SYMBOL_ARROW_L + " " + caller);

            if (ShutDown_Requested)
            {
                SyncUI.sync_colors();
            }

            G_DX1_KEYS.Focus();
            //}}}
        } //}}}
예제 #3
0
        //}}}
        private void ApplyKeySet_handler() //{{{
        {
            // CANCELED BEFORE COUNTDOWN {{{
            if (ApplyKeySet_thread == null)
            {
                Log("UPDATES .. CANCELED BEFORE COUNTDOWN");

                return;
            }
            //}}}
            // [something_to_commit] {{{
            bool something_to_commit
                = (profile.keyProgrammer.Profile_changeToCommit != "") ||
                  (profile.keyProgrammer.KeyMap_changeToCommit != "")
                ;

            if (!something_to_commit)
            {
                if (DX1Utility.Debug)
                {
                    Log("UPDATES .. NONE");
                }

                return;
            }
            else
            {
                L_STANDBY.Text = ""; // CLEAR PROGRESS BAR
            }
            //}}}
            // SHUTDOWN .. OR FOCUS LOST DELAY {{{
            if (!ShutDown_Requested)
            {
                int delay_sec
                    = (cmdLine_apply_delay_sec > 0)
                    ?  cmdLine_apply_delay_sec
                    :  FOCUS_LOST_APPLY_DELAY_SEC;

                cmdLine_apply_delay_sec = -1; /* consume single usage command-line argument */

                if (Environment.UserInteractive)
                {
                    Log("UPDATES .. TO BE APPLIED IN " + delay_sec + "s");
                }

                ApplyKeySet_countDown(delay_sec);
            }
            //}}}
            // CANCELED DURING COUNTDOWN {{{
            if (ApplyKeySet_thread == null)
            {
                Log(Globals.SYMBOL_ARROW_L + Globals.SYMBOL_ARROW_L + " UPDATES .. CANCELED BY USER DURING COUNTDOWN");

                return;
            }
            else
            {
                // USE PENDING COLOR FOR STANDBY CHECKMARK
                L_STANDBY.ForeColor = L_WRITING.ForeColor;

                Log("UPDATES .. APPLYING");
            }
            //}}}
            //{{{ [apply_cause]
            string apply_cause
                = (!DX1UtilityHasFocus ? "FOCUS LOST" : "")
                  + " " + (ShutDown_Requested ? "SHUTDOWN"   : "")
                ;

            apply_cause = apply_cause.Trim();
            //}}}
            // COMMIT PROFILE UPDATE {{{
            if (profile.keyProgrammer.Profile_changeToCommit != "")
            {
                if (DX1Utility.Debug)
                {
                    Log("===");
                }

                Log("UPDATING PROFILE: " + profile.CurrentProfileName + "");

                if (DX1Utility.Debug)
                {
                    Log(".. commited by [" + profile.keyProgrammer.Profile_changeToCommit + " ON " + apply_cause + "]");
                }

                ProfileManager.SaveProfile(profile.CurrentProfileName, profile.keyMapList);

                Log(Globals.SYMBOL_ARROW_L + Globals.SYMBOL_ARROW_L + " PROFILE UPDATE .. DONE");

                if (DX1Utility.Debug)
                {
                    Log("===");
                }
            }
            else
            {
                if (DX1Utility.Debug)
                {
                    Log("===");
                }
                if (DX1Utility.Debug)
                {
                    Log("PROFILE UNCHANGED: [" + profile.CurrentProfileName + "]");
                }
                if (DX1Utility.Debug)
                {
                    Log("===");
                }
            }
            //}}}
            // COMMIT KEY MAPPINGS {{{
            if (profile.keyProgrammer.KeyMap_changeToCommit != "")
            {
                if (DX1Utility.Debug)
                {
                    Log("===");
                }

                Log("SENDING KEYMAP: [" + profile.CurrentProfileName + "]");

                if (DX1Utility.Debug)
                {
                    Log(".. commited by [" + profile.keyProgrammer.KeyMap_changeToCommit + " ON " + apply_cause + "]");
                }

                update_notifyIcon(profile.CurrentProfileName + " profile\n.. SENDING KEYMAP");

                dx1Device.sendProgramPacket(profile.keyProgrammer.get_keyMapList_num_type_code_byteArray(profile.keyMapList));

                Log(Globals.SYMBOL_ARROW_L + Globals.SYMBOL_ARROW_L + " KEYSET  UPDATE .. DONE");

                if (DX1Utility.Debug)
                {
                    Log("===");
                }
            }
            else
            {
                if (DX1Utility.Debug)
                {
                    Log("===");
                }
                if (DX1Utility.Debug)
                {
                    Log("KEYMAP UNCHANGED: [" + profile.CurrentProfileName + "]");
                }
                if (DX1Utility.Debug)
                {
                    Log("===");
                }
            }
            //}}}
            /* 1/2 - EXIT FROM UNATTENDED SERVICE MODE {{{*/
            ApplyKeySet_thread = null;
            if (!Environment.UserInteractive)
            {
                ShutDown_Requested = true;
                exitApp_Handler();
            }
            /*}}}*/
            // 2/2 - OR CLEAR UI COMMIT TRIGGERS {{{
            if (something_to_commit)
            {
                L_STANDBY.Text = Globals.SYMBOL_CHECK; // CHECK PROGRESS BAR
            }
            //                                         profile.keyProgrammer.notify_all_commit_done();
            this.Invoke((MethodInvoker) delegate() { profile.keyProgrammer.notify_all_commit_done(); });

            if (C2_KeyMap_commit.Checked)
            {
                set_C2_KeyMap_commit_Checked(false);
            }
            if (C1_Profile_commit.Checked)
            {
                set_C1_Profile_commit_Checked(false);
            }

            SyncUI.sync("ApplyKeySet_handler");
            //}}}
        } //}}}
예제 #4
0
        } //}}}

        public void EditProfile(string profileName) // {{{
        {
            // Cannot Edit the Global profile {{{

/*{{{
*       if(profileName == Globals.MENU_GLOBAL_PROFILE)
*       {
*           if( Environment.UserInteractive )
*               MessageBox.Show("Cannot Edit the Global profile's properties", "", MessageBoxButtons.OK);
*
*           return;
*       }
*  }}}*/
            //}}}
            // CHECK PROFILE NAME .. (NEW OR EXISTING) {{{
            ProfileSearcher   Searcher = new ProfileSearcher();
            ProfileProperties PProp    = new ProfileProperties();

            //}}}
            // [PProp DIALOG BOX] .. f(New menu entry) .. f(profile name .. from ui.D_Profiles.Text) {{{
            bool bNewProfile
                = (profileName == Globals.MENU_NEW_PROFILE)
                ;

            CurrentProfileName
                = bNewProfile
            ?  "New"
            :  Searcher.ProfileSearchByName(ProfileList, ui.get_D_Profiles_Text());

            PProp.EditProfile(CurrentProfileName);
            //}}}

            bool         clearProfile = false;
            DialogResult PPropAnswer  = PProp.ShowDialog();

            // DIALOG [CANCEL] {{{
            if (PPropAnswer != DialogResult.OK)
            {
                // if we were creating a new profile switch to the Global profile
                if (bNewProfile)
                {
                    SelectProfile(Globals.MENU_GLOBAL_PROFILE);
                }
            }
            //}}}

            // DIALOG [OK] {{{
            else
            {
                // [bNewProfile] {{{
                if (bNewProfile)
                {
                    // REJECT ALREADY EXISTING PROFILE NAME {{{
                    if (Searcher.ProfileSearchByName(ProfileList, PProp.GetProfileNameOnly()) != null)
                    {
                        if (Environment.UserInteractive)
                        {
                            MessageBox.Show("This profile already exists, you should load it first. Changes cancelled.", "", MessageBoxButtons.OK);
                        }

                        ui.set_D_Profiles_Text(Globals.MENU_NEW_PROFILE);
                    }
                    //}}}
                    else
                    {
                        // CREATE NEW PROFILE {{{
                        ui.set_D_Profiles_Text(CurrentProfileName);

                        PProp.GetEditedProfile(ref CurrentProfileName, ref clearProfile);
                        ui.add_D_Profiles_Item(CurrentProfileName);

                        ProfileList.Add(CurrentProfileName);
                        _Save_ProfileList_to_Dx1Profiles_dat();
                        //}}}
                        // [UNASSIGN ALL KEYS] {{{
                        if (clearProfile)
                        {
                            init_keyMapList();
                            ProfileManager.SaveProfile(CurrentProfileName, keyMapList);
                            SyncUI.sync("EditProfile");
                        }
                        else
                        {
                            ProfileManager.SaveProfile(CurrentProfileName, keyMapList);
                        }
                        //}}}
                    }
                }
                //}}}
                // UPDATE SELECTED PROFILE {{{
                else
                {
                    PProp.GetEditedProfile(ref CurrentProfileName, ref clearProfile);
                    if (clearProfile)
                    {
                        //Clear all the currently programmed keys on this profile
                        init_keyMapList();
                        ProfileManager.SaveProfile(CurrentProfileName, keyMapList);
                    }
                }
                //}}}
                ui.set_B_Delete_Enabled(true);
            } //}}}
        }     //}}}
예제 #5
0
        } //}}}

        protected override void OnKeyUp(KeyEventArgs e) // {{{
        {
            string caller   = "OnKeyUp";
            bool   log_this = DX1Utility.Debug;

            if (log_this)
            {
                log_Clear();
            }
            if (log_this)
            {
                log(caller + "(" + e.KeyCode + "): DX1UtilityHasFocus=[" + DX1UtilityHasFocus + "]");
            }

            // propagate grid event first {{{
            base.OnKeyUp(e);

            //}}}
            // [wizard_is_running] .. AssignSingleKey {{{
            bool wizard_is_running
            // (B_KeyProgrammer.Text != B_START_MAPPING_TEXT)
                = dx1Device.is_in_KEYMAP_MODE() &&
                  (profile.keyProgrammer.KeyNum > 0)
                ;

            if (wizard_is_running)
            {
                e.SuppressKeyPress = true; // whether the key event should be passed on to the underlying control

                int keyCode = (int)e.KeyCode;

                if (log_this)
                {
                    log(".. mapping [" + e.KeyCode + "] to KEY #" + profile.keyProgrammer.KeyNum);
                }

                if (profile.keyMapList[profile.keyProgrammer.KeyNum - 1].AssignSingleKey(keyCode, e.KeyCode.ToString()))
                {
                    profile.keyProgrammer.notify_keyMap_KEY_CHANGED();
                    profile.keyProgrammer.notify_profile_KEYMAP_CHANGED();
                    if (!C2_KeyMap_commit.Checked)
                    {
                        set_C2_KeyMap_commit_Checked(true);
                    }
                    if (!C1_Profile_commit.Checked)
                    {
                        set_C1_Profile_commit_Checked(true);
                    }
                }

                select_keyNum(profile.keyProgrammer.KeyNum + 1);
            }
            //}}}
            // [Delete] a macro file {{{
            else if ((e.KeyCode == System.Windows.Forms.Keys.Delete) &&
                     (MacroList.Focused && MacroList.SelectedIndex != 0)
                     )
            {
                System.IO.File.Delete(Globals.ProfileMacroPath + MacroList.SelectedItem.ToString() + ".mac");
                RebuildMacroList();

                SyncUI.sync("OnKeyUp");
            }
            //}}}
            // select current Grid cell {{{
            else
            {
                // vk {{{
                int vk      = (int)e.KeyCode;
                int keyType = 1;
                // SHIFT, CTRL, ALT {{{
                if (vk >= 0x10 && vk <= 0x12)
                {
                    vk      = 0xa0 + 2 * (vk - 0x10);
                    keyType = 2;
                    if (log_this)
                    {
                        log("MODIFIER..=[" + vk + " " + vk.ToString("X2") + "]");
                    }
                }
                else
                {
                    if (log_this)
                    {
                        log(".. .....vk=[" + vk + " " + vk.ToString("X2") + "]");
                    }
                }
                //}}}

                //}}}
                // keyCode {{{
                int    keyCode  = 0;
                byte[] keyTuple = KeyConversionTable.KeyPairConversionTable[vk];
                if (keyTuple != null)
                {
                    keyCode = keyTuple[1];
                    if (log_this)
                    {
                        log(".. keyCode=[" + keyCode + "]");
                    }
                }

                //}}}
                // keyNum {{{
                byte keyNum = 0;
                if (keyCode > 0)
                {
                    foreach (KeyMap keyMap in profile.keyMapList)
                    {
                        if ((keyMap.KeyType == keyType) && (keyMap.KeyCode == keyCode))
                        {
                            keyNum = (byte)keyMap.KeyNum;
                            if (log_this)
                            {
                                log(".. .keyNum=[" + keyNum + "] .. keyMap=[" + keyMap.ToString() + "]");
                            }
                            break;
                        }
                    }
                }
                //}}}
                select_keyNum(keyNum);
            }
            //}}}
        }