Exemple #1
0
        public static OneWayUpdater <String> BindTextAsSource(this ToolStripItem textBox, Action <String> destinationSetter)
        {
            EventLink textChangeEventLinks = new EventLink(textBox, _ControlTextChangedEventInfo);
            OneWayUpdater <String> binding = new OneWayUpdater <String>(() => textBox.Text, destinationSetter, textChangeEventLinks);

            return(binding);
        }
Exemple #2
0
        public static OneWayUpdater <String> BindTextAsSource(this Control textBox, PropertyLink <String> destinationPropertyLink)
        {
            EventLink textChangeEventLinks = new EventLink(textBox, _ControlTextChangedEventInfo);
            OneWayUpdater <String> binding = new OneWayUpdater <String>(() => textBox.Text, destinationPropertyLink.Set, textChangeEventLinks);

            return(binding);
        }
Exemple #3
0
        public EncodingsViewer()
        {
            InitializeComponent();
            AddEventHandlers();

            //Link 'lvFavoriteEncodings.SelectedEncoding' to 'lblSelectedEncodingFavorites.Text':
            OneWayUpdater <string> SelFavEnc = new OneWayUpdater <string>(() => this.lvFavoriteEncodings.SelectedEncoding?.DisplayName, x => lblSelectedEncodingFavorites.Text = x
                                                                          , new EventLink(lvFavoriteEncodings, nameof(lvFavoriteEncodings.SelectedEncodingChanged)));

            //Link 'lvAllEncodings.SelectedEncoding' to 'lblSelectedEncoding.Text':
            OneWayUpdater <string> SelEnc = new OneWayUpdater <string>(() => this.lvAllEncodings.SelectedEncoding?.DisplayName, x => lblSelectedEncoding.Text = x
                                                                       , new EventLink(lvAllEncodings, nameof(lvAllEncodings.SelectedEncodingChanged)));
        }
Exemple #4
0
        void AddEventHandlers()
        {
            //Binding to Encoding converter core:
            EncodingConverterCore ECC = Program.ECC;

            //Bind 'ECC.AutoDetectInputEncoding' to 'chkAutoDetect.Checked':
            WinFormsHelpers.Bind(new PropertyLink <bool>(() => chkAutoDetect.Checked, x => chkAutoDetect.Checked = x)
                                 , new EventLink(chkAutoDetect, nameof(CheckBox.CheckedChanged))
                                 , new PropertyLink <bool>(() => ECC.AutoDetectInputEncoding, x => ECC.AutoDetectInputEncoding = x)
                                 , new EventLink(ECC, nameof(ECC.AutoDetectInputEncodingChanged)))
            .UpdateObj2To1();
            //Bind 'ECC.PreferredInputEncoding' to 'txtPreferredInputEncoding':
            txtPreferredInputEncoding.BindText(new PropertyLink <string>(() => ECC.PreferredInputEncoding, x => ECC.PreferredInputEncoding = x)
                                               , new EventLink(ECC, nameof(ECC.PreferredInputEncodingChanged)))
            .UpdateObj2To1();
            //Bind 'ECC.InputFilePath' to 'txtInputPath':
            txtInputPath.BindText(new PropertyLink <string>(() => ECC.InputFilePath, x => ECC.InputFilePath = x)
                                  , new EventLink(ECC, nameof(ECC.InputFilePathChanged)))
            .UpdateObj2To1();
            //Bind 'ECC.OutputFilePath' to 'txtOutputPath':
            txtOutputPath.BindText(new PropertyLink <string>(() => ECC.OutputFilePath, x => ECC.OutputFilePath = x)
                                   , new EventLink(ECC, nameof(ECC.OutputFilePathChanged)))
            .UpdateObj2To1();
            //Bind 'ECC.InputText' to 'tbInputText':
            _InputTextLink = tbInputText.BindTextAsDestination(
                () => (!splitContainer1.Panel2Collapsed && File.Exists(ECC.InputFilePath)) ? ECC.InputText : null
                , new EventLink(ECC, nameof(ECC.InputTextChanged)));
            _InputTextLink.Update();

            //ECC.InputTextChanged += ECC_InputTextChanged; //One way update.
            //if (File.Exists(ECC.InputFilePath))
            //{
            //    tbInputText.Text = ECC.InputText;
            //}

            var text = File.Exists(ECC.InputFilePath) ? ECC.InputText : null;

            var inputEncodingEventLink = new EventLink(ECC, nameof(ECC.InputEncodingChanged));

            //Bind 'ECC.InputEncoding' to 'evInputEncoding.SelectedEncodingInfo':
            WinFormsHelpers.Bind(new PropertyLink <EncodingInfo>(() => evInputEncoding.SelectedEncodingInfo, x => evInputEncoding.SelectedEncodingInfo = x)
                                 , new EventLink(evInputEncoding, nameof(evInputEncoding.SelectedEncodingInfoChanged))
                                 , new PropertyLink <EncodingInfo>(() => encodingInfos?.FirstOrDefault(x => x.CodePage == ECC.InputEncoding.CodePage), x => ECC.InputEncoding = x?.GetEncoding())
                                 , inputEncodingEventLink)
            .UpdateObj2To1();
            //Bind 'ECC.InputEncoding' to 'lblInputEncoding':
            tsddInputEncoding.BindTextAsDestination(() => ECC.InputEncoding?.EncodingName, inputEncodingEventLink).Update();

            //Bind 'ECC.OutputEncoding' to 'evOutputEncoding.SelectedEncodingInfo':
            var outputEncodingEventLink = new EventLink(ECC, nameof(ECC.OutputEncodingChanged));

            WinFormsHelpers.Bind(new PropertyLink <EncodingInfo>(() => evOutputEncoding.SelectedEncodingInfo, x => evOutputEncoding.SelectedEncodingInfo = x)
                                 , new EventLink(evOutputEncoding, nameof(evOutputEncoding.SelectedEncodingInfoChanged))
                                 , new PropertyLink <EncodingInfo>(() => encodingInfos?.FirstOrDefault(x => x.CodePage == ECC.OutputEncoding.CodePage), x => ECC.OutputEncoding = x?.GetEncoding())
                                 , outputEncodingEventLink)
            .UpdateObj2To1();
            //Bind 'ECC.OutputEncoding' to 'lblOutputEncoding':
            tsddOutputEncoding.BindTextAsDestination(() => ECC.OutputEncoding?.EncodingName, outputEncodingEventLink).Update();


            txtOutputPathFormat.BindText(new PropertyLink <string>(() => _OFF.FormatString, x => _OFF.FormatString = x)
                                         , new EventLink(_OFF, nameof(_OFF.FormatStringChanged))).UpdateObj2To1();
            txtCompanionFileSearchPattern.BindText(new PropertyLink <string>(() => _OFF.CompanionFileSearchPattern, x => _OFF.CompanionFileSearchPattern = x)
                                                   , new EventLink(_OFF, nameof(_OFF.CompanionFileSearchPatternChanged))).UpdateObj2To1();

            txtCompanionFile.BindText(new PropertyLink <string>(() => _OFF.CompanionFile, x => _OFF.CompanionFile = x)
                                      , new EventLink(_OFF, nameof(_OFF.CompanionFileChanged))).UpdateObj2To1();


            //Bind favorite encoding of OutputEncodingsViewer to favorite encoding of InputEncodingsViewer
            var OutputEncodingFavsPropLink = new PropertyLink <EncodingInfo[]>(() => evOutputEncoding.FavoriteEncodingInfos, x => evOutputEncoding.FavoriteEncodingInfos = x);
            var evLink = new EventLink(evOutputEncoding, nameof(evOutputEncoding.FavoriteEncodingInfosChanged));

            WinFormsHelpers.Bind(OutputEncodingFavsPropLink
                                 , evLink
                                 , new PropertyLink <EncodingInfo[]>(() => evInputEncoding.FavoriteEncodingInfos, x => evInputEncoding.FavoriteEncodingInfos = x)
                                 , new EventLink(evInputEncoding, nameof(evInputEncoding.FavoriteEncodingInfosChanged)))
            ;

            //WinFormsHelpers.Bind(OutputEncodingFavsPropLink
            //    , evLink
            //    , new PropertyLink<EncodingsCollection>(() => evInputEncoding.FavoriteEncodingInfos, x => evInputEncoding.FavoriteEncodingInfos = x)
            //    , new EventLink(evInputEncoding, nameof(evInputEncoding.FavoriteEncodingInfosChanged)))
            //    ;

            //this.gbInput.DragEnter += InputControl_DragEnter;
            //this.gbInput.DragDrop += InputControl_DragDrop;

            this.splitContainer1.DragEnter += InputControl_DragEnter;
            this.splitContainer1.DragDrop  += InputControl_DragDrop;


            this.linkAbout.LinkClicked          += this.linkAbout_LinkClicked;
            this.btnChangeOutputFile.Click      += this.btnChangeOutputFile_Click;
            this.linkLabel1.LinkClicked         += this.linkLabel1_LinkClicked;
            this.btnSave.Click                  += this.btnSave_Click;
            this.btnOpen.Click                  += BtnOpen_Click;
            this.btnApplyOutputFormatting.Click += BtnApplyOutputFormatting_Click;
            this.splitContainer1.SplitterMoved  += SplitContainer1_SplitterMoved;
            this.btnTogleSidePanel.Click        += BtnTogleSidePanel_Click;
            this.splitContainer1.Resize         += SplitContainer1_Resize;

            this.Load       += MainForm3_Load;
            this.FormClosed += FormMain_FormClosed;
        }
Exemple #5
0
        public static OneWayUpdater <String> BindTextAsDestination(this ToolStripItem textBox, Func <string> sourceGetter, EventLink obj2ChangeEvent)
        {
            OneWayUpdater <String> binding = new OneWayUpdater <String>(sourceGetter, x => textBox.Text = x, obj2ChangeEvent);

            return(binding);
        }
Exemple #6
0
        public static OneWayUpdater <String> BindTextAsDestination(this Control textBox, PropertyLink <String> property2, EventLink obj2ChangeEvent)
        {
            OneWayUpdater <String> binding = new OneWayUpdater <String>(property2.Get, x => textBox.Text = x, obj2ChangeEvent);

            return(binding);
        }
        void AddEventHandlers()
        {
            EncodingConverterCore ECC = Program.ECC;

            #region Bindings

            //Binding to Encoding converter core:
            //Bind 'ECC.AutoDetectInputEncoding' to 'chkAutoDetect.Checked':
            WinFormsHelpers.Bind(new PropertyLink <bool>(() => chkAutoDetect.Checked, x => chkAutoDetect.Checked = x)
                                 , new EventLink(chkAutoDetect, nameof(CheckBox.CheckedChanged))
                                 , new PropertyLink <bool>(() => ECC.AutoDetectInputEncoding, x => ECC.AutoDetectInputEncoding = x)
                                 , new EventLink(ECC, nameof(ECC.AutoDetectInputEncodingChanged)))
            .UpdateObj2To1();
            //Bind 'ECC.PreferredInputEncoding' to 'txtPreferredInputEncoding':
            txtPreferredInputEncoding.BindText(new PropertyLink <string>(() => ECC.PreferredInputEncoding, x => ECC.PreferredInputEncoding = x)
                                               , new EventLink(ECC, nameof(ECC.PreferredInputEncodingChanged)))
            .UpdateObj2To1();
            //Bind 'ECC.InputFilePath' to 'txtInputPath':
            txtInputPath.BindText(new PropertyLink <string>(() => ECC.InputFilePath, x => ECC.InputFilePath = x)
                                  , new EventLink(ECC, nameof(ECC.InputFilePathChanged)))
            .UpdateObj2To1();


            //Bind 'ECC.OutputFilePath' to 'txtOutputPath':
            txtOutputPath.BindText(new PropertyLink <string>(() => ECC.OutputFilePath, (x) => { ECC.OutputFilePath = x; })
                                   , new EventLink(ECC, nameof(ECC.OutputFilePathChanged)))
            .UpdateObj2To1();
            //Bind 'ECC.InputText' to 'tbInputText':
            _InputTextLink = tbInputText.BindTextAsDestination(
                () => (!splitContainer1.Panel2Collapsed && File.Exists(ECC.InputFilePath)) ? ECC.InputText : null
                , new EventLink(ECC, nameof(ECC.InputTextChanged)));
            _InputTextLink.Update();

            //ECC.InputTextChanged += ECC_InputTextChanged; //One way update.
            //if (File.Exists(ECC.InputFilePath))
            //{
            //    tbInputText.Text = ECC.InputText;
            //}

            var text = File.Exists(ECC.InputFilePath) ? ECC.InputText : null;

            var inputEncodingEventLink = new EventLink(ECC, nameof(ECC.InputEncodingChanged));
            //Bind 'ECC.InputEncoding' to 'evInputEncoding.SelectedEncodingInfo':
            WinFormsHelpers.Bind(new PropertyLink <EncodingInfo>(() => evInputEncoding.SelectedEncodingInfo, x => evInputEncoding.SelectedEncodingInfo = x)
                                 , new EventLink(evInputEncoding, nameof(evInputEncoding.SelectedEncodingInfoChanged))
                                 , new PropertyLink <EncodingInfo>(() => encodingInfos?.FirstOrDefault(x => x.CodePage == ECC.InputEncoding?.CodePage), x => ECC.InputEncoding = x?.GetEncoding())
                                 , inputEncodingEventLink)
            .UpdateObj2To1();
            //Bind 'ECC.InputEncoding' to 'lblInputEncoding':
            tsddInputEncoding.BindTextAsDestination(() => ECC.InputEncoding?.EncodingName, inputEncodingEventLink).Update();

            //Bind 'ECC.OutputEncoding' to 'evOutputEncoding.SelectedEncodingInfo' and 'Settings.LastOutputEncoding':
            Properties.Settings defSet = Properties.Settings.Default;
            //1- Setup PropertyLink to 'ECC.OutputEncoding':
            var ECCOutputEncodingPropertyLink = new PropertyLink <Encoding>
                                                    (() => ECC.OutputEncoding       //getter
                                                    , x => ECC.OutputEncoding = x); //setter

            //2- Setup EventLink of 'OutputEncodingChanged':
            var ECCOutputEncodingEventLink = new EventLink(ECC, nameof(ECC.OutputEncodingChanged));
            //3- Now make the Bindings:
            //  Bind 'ECC.OutputEncoding' to 'Settings.LastOutputEncoding':
            WinFormsHelpers.Bind(new PropertyLink <Encoding>
                                     (() => encodingInfos?.FirstOrDefault(x => x.CodePage == defSet.LastOutputEncoding)?.GetEncoding()
                                     , x => defSet.LastOutputEncoding = x.CodePage)
                                 , new EventLink(evOutputEncoding, nameof(evOutputEncoding.SelectedEncodingInfoChanged))
                                 , ECCOutputEncodingPropertyLink
                                 , ECCOutputEncodingEventLink)
            .UpdateObj1To2();    //Update Settings to ECC.

            //  Bind 'ECC.OutputEncoding' to 'evOutputEncoding.SelectedEncodingInfo':
            //WinFormsHelpers.Bind(new PropertyLink<EncodingInfo>(() => evOutputEncoding.SelectedEncodingInfo, x => evOutputEncoding.SelectedEncodingInfo = x)
            //    , new EventLink(evOutputEncoding, nameof(evOutputEncoding.SelectedEncodingInfoChanged))
            //    , new PropertyLink<EncodingInfo>(() => encodingInfos?.FirstOrDefault(x => x.CodePage == ECC.OutputEncoding.CodePage), x => ECC.OutputEncoding = x?.GetEncoding())
            //    , ECCOutputEncodingEventLink)
            //    .UpdateObj2To1();
            WinFormsHelpers.Bind(new PropertyLink <Encoding>(
                                     () => evOutputEncoding.SelectedEncodingInfo.GetEncoding()
                                     , x => evOutputEncoding.SelectedEncodingInfo = encodingInfos?.FirstOrDefault(ei => x?.CodePage == ei.CodePage))
                                 , new EventLink(evOutputEncoding, nameof(evOutputEncoding.SelectedEncodingInfoChanged))
                                 , ECCOutputEncodingPropertyLink
                                 , ECCOutputEncodingEventLink)
            .UpdateObj2To1();

            //  Bind 'ECC.OutputEncoding' to 'lblOutputEncoding':
            tsddOutputEncoding.BindTextAsDestination(() => ECC.OutputEncoding?.EncodingName, ECCOutputEncodingEventLink).Update();


            txtOutputPathFormat.BindText(new PropertyLink <string>(() => _OPF.FormatString, x => _OPF.FormatString = x)
                                         , new EventLink(_OPF, nameof(_OPF.FormatStringChanged))).UpdateObj2To1();
            txtCompanionFileSearchPattern.BindText(new PropertyLink <string>(() => _OPF.CompanionFileSearchPattern, x => _OPF.CompanionFileSearchPattern = x)
                                                   , new EventLink(_OPF, nameof(_OPF.CompanionFileSearchPatternChanged))).UpdateObj2To1();

            txtCompanionFile.BindText(new PropertyLink <string>(() => _OPF.CompanionFile, x => _OPF.CompanionFile = x)
                                      , new EventLink(_OPF, nameof(_OPF.CompanionFileChanged))).UpdateObj2To1();


            //Bind favorite encoding of OutputEncodingsViewer to favorite encoding of InputEncodingsViewer
            var OutputEncodingFavsPropLink = new PropertyLink <EncodingInfo[]>(() => evOutputEncoding.FavoriteEncodingInfos, x => evOutputEncoding.FavoriteEncodingInfos = x);
            var evLink = new EventLink(evOutputEncoding, nameof(evOutputEncoding.FavoriteEncodingInfosChanged));

            WinFormsHelpers.Bind(OutputEncodingFavsPropLink
                                 , evLink
                                 , new PropertyLink <EncodingInfo[]>(() => evInputEncoding.FavoriteEncodingInfos, x => evInputEncoding.FavoriteEncodingInfos = x)
                                 , new EventLink(evInputEncoding, nameof(evInputEncoding.FavoriteEncodingInfosChanged)))
            ;

            //WinFormsHelpers.Bind(OutputEncodingFavsPropLink
            //    , evLink
            //    , new PropertyLink<EncodingsCollection>(() => evInputEncoding.FavoriteEncodingInfos, x => evInputEncoding.FavoriteEncodingInfos = x)
            //    , new EventLink(evInputEncoding, nameof(evInputEncoding.FavoriteEncodingInfosChanged)))
            //    ;
            #endregion//Bindings

            ECC.OutputFilePathChanged += ECC_OutputFilePathChanged;

            this.splitContainer1.AllowDrop  = true;
            this.splitContainer1.DragEnter += InputControl_DragEnter;
            this.splitContainer1.DragDrop  += InputControl_DragDrop;

            this.linkAbout.LinkClicked     += this.linkAbout_LinkClicked;
            this.btnChangeOutputFile.Click += this.btnChangeOutputFile_Click;
            this.linkLabelDetectInputEncoding.LinkClicked += this.linkLabelDetectInputEncoding_LinkClicked;
            this.btnSave.Click += this.btnSave_Click;
            this.btnOpen.Click += BtnOpen_Click;
            this.btnApplyOutputFormatting.Click += BtnApplyOutputFormatting_Click;

            this.Load       += MainForm_Load;
            this.FormClosed += FormMain_FormClosed;

            this.txtInputPath.TextChanged     += TxtPath_TextChanged;
            this.txtOutputPath.TextChanged    += TxtPath_TextChanged;
            this.txtCompanionFile.TextChanged += TxtPath_TextChanged;

            ECC.DetectedEncodingsChanged += ECC_DetectedEncodingsChanged;
            ECC.InputEncodingChanged     += ECC_InputEncodingChanged;
        }