2828using System . Collections . Generic ;
2929using System . ComponentModel ;
3030using System . Drawing ;
31+ using System . Linq ;
3132using System . Text ;
3233using System . Threading ;
3334using System . Windows . Forms ;
@@ -547,9 +548,7 @@ private void recentConfiguration_Click(object sender, EventArgs e)
547548
548549 private void listViewKeys_SelectedIndexChanged ( object sender , EventArgs e )
549550 {
550- btnAppend . Enabled = ( 1 == listViewKeys . SelectedIndices . Count ) ;
551- btnUpdate . Enabled = ( 1 == listViewKeys . SelectedIndices . Count ) ;
552- btnRemove . Enabled = ( 0 < listViewKeys . SelectedIndices . Count ) ;
551+ UpdateActionEnableStates ( ) ;
553552 }
554553
555554 private void listViewKeys_Resize ( object sender , EventArgs e )
@@ -646,12 +645,46 @@ private void btnUpdate_Click(object sender, EventArgs e)
646645 {
647646 if ( listViewKeys . SelectedItems . Count == 1 )
648647 {
648+ var zSelectedEntry = ( RemapEntry ) listViewKeys . SelectedItems [ 0 ] . Tag ;
649+ if ( zSelectedEntry . OutputConfigCount > 1 )
650+ {
651+ switch ( MessageBox . Show ( this , "This entry has multiple outputs. Do you want to overwrite the outputs?" +
652+ "\n YES - overwrite input & outputs." +
653+ "\n NO - overwrite input only." , "Remap has multiple outputs" , MessageBoxButtons . YesNoCancel ,
654+ MessageBoxIcon . Question , MessageBoxDefaultButton . Button1 ) )
655+ {
656+ case DialogResult . Yes :
657+ // nothing
658+ break ;
659+ case DialogResult . No :
660+ btnUpdateInput_Click ( sender , e ) ;
661+ return ;
662+ case DialogResult . Cancel :
663+ return ;
664+ }
665+ }
649666 RemapEntry zRemapEntry = null ;
650- if ( ! CreateRemapEntryFromActiveConfigs ( ref zRemapEntry , ( RemapEntry ) listViewKeys . SelectedItems [ 0 ] . Tag ) ) return ;
667+ if ( ! CreateRemapEntryFromActiveConfigs ( ref zRemapEntry , ( RemapEntry ) listViewKeys . SelectedItems [ 0 ] . Tag ) )
668+ {
669+ MessageBox . Show ( "Unable to determine remap from configuration." , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
670+ return ;
671+ }
651672 AddRemapEntryToListView ( zRemapEntry , true , listViewKeys . SelectedItems [ 0 ] ) ;
652673 }
653674 }
654675
676+ private void btnUpdateInput_Click ( object sender , EventArgs e )
677+ {
678+ RemapEntry zRemapEntry = null ;
679+ if ( ! CreateRemapEntryFromActiveConfigs ( ref zRemapEntry , ( RemapEntry ) listViewKeys . SelectedItems [ 0 ] . Tag ,
680+ true ) )
681+ {
682+ MessageBox . Show ( "Unable to determine remap from configuration." , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
683+ return ;
684+ }
685+ AddRemapEntryToListView ( zRemapEntry , true , listViewKeys . SelectedItems [ 0 ] ) ;
686+ }
687+
655688 private void btnAppend_Click ( object sender , EventArgs e )
656689 {
657690 if ( 1 != listViewKeys . SelectedItems . Count )
@@ -662,12 +695,84 @@ private void btnAppend_Click(object sender, EventArgs e)
662695 var zItem = listViewKeys . SelectedItems [ 0 ] ;
663696 var zRemapEntry = ( RemapEntry ) zItem . Tag ;
664697 OutputConfig zOutputConfig = null ;
665- if ( ! RetrieveOutputConfigForAppend ( zRemapEntry , ref zOutputConfig ) ) return ;
698+ if ( ! RetrieveOutputConfigForAppend ( zRemapEntry , ref zOutputConfig ) )
699+ {
700+ MessageBox . Show ( "Unable to determine remap from configuration." , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
701+ return ;
702+ }
666703
667704 zRemapEntry . AppendOutputConfig ( zOutputConfig ) ;
668705 zItem . SubItems [ 1 ] . Text = zRemapEntry . GetOutputString ( ) ;
669706 MarkDirty ( ) ;
670707 txtKeyOut . Focus ( ) ; // restore focus to the output
708+ UpdateActionEnableStates ( ) ;
709+ }
710+
711+ private void btnAppendAt_Click ( object sender , EventArgs e )
712+ {
713+ if ( 1 != listViewKeys . SelectedItems . Count )
714+ {
715+ return ;
716+ }
717+
718+ var zItem = listViewKeys . SelectedItems [ 0 ] ;
719+ var zRemapEntry = ( RemapEntry ) zItem . Tag ;
720+ OutputConfig zOutputConfig = null ;
721+ if ( ! RetrieveOutputConfigForAppend ( zRemapEntry , ref zOutputConfig ) )
722+ {
723+ MessageBox . Show ( "Unable to determine remap from configuration." , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
724+ return ;
725+ }
726+
727+ const string IDX_QUERY_KEY = "idx" ;
728+ var zQuery = new QueryPanelDialog ( "Append output config" , 450 , false ) ;
729+ zQuery . SetIcon ( Icon ) ;
730+ zQuery . AddLabel ( "Select the index to append the output at (the selected output will be pushed forward to insert the new output)." , 48 ) ;
731+ var arrayOutputs = zRemapEntry . OutputConfigs . Select ( ( zOutput , nIdx ) => $ "{ nIdx } :{ zOutput . GetDescription ( ) } ") . ToArray ( ) ;
732+ zQuery . AddPullDownBox ( "Output To Append At" , arrayOutputs , 0 , IDX_QUERY_KEY ) ;
733+ if ( DialogResult . Cancel == zQuery . ShowDialog ( this ) )
734+ {
735+ return ;
736+ }
737+
738+ zRemapEntry . AppendOutputConfigAt ( zOutputConfig , zQuery . GetIndex ( IDX_QUERY_KEY ) ) ;
739+ zItem . SubItems [ 1 ] . Text = zRemapEntry . GetOutputString ( ) ;
740+ MarkDirty ( ) ;
741+ txtKeyOut . Focus ( ) ; // restore focus to the output
742+ UpdateActionEnableStates ( ) ;
743+ }
744+
745+ private void btnRemoveAt_Click ( object sender , EventArgs e )
746+ {
747+ if ( 1 != listViewKeys . SelectedItems . Count )
748+ {
749+ return ;
750+ }
751+
752+ var zItem = listViewKeys . SelectedItems [ 0 ] ;
753+ var zRemapEntry = ( RemapEntry ) zItem . Tag ;
754+ OutputConfig zOutputConfig = null ;
755+ if ( ! RetrieveOutputConfigForAppend ( zRemapEntry , ref zOutputConfig ) )
756+ {
757+ MessageBox . Show ( "Unable to determine remap from configuration." , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
758+ return ;
759+ }
760+
761+ const string IDX_QUERY_KEY = "idx" ;
762+ var zQuery = new QueryPanelDialog ( "Remove output config at index" , 450 , false ) ;
763+ zQuery . SetIcon ( Icon ) ;
764+ zQuery . AddLabel ( "Select the output to remove." , 24 ) ;
765+ var arrayOutputs = zRemapEntry . OutputConfigs . Select ( ( zOutput , nIdx ) => $ "{ nIdx } :{ zOutput . GetDescription ( ) } ") . ToArray ( ) ;
766+ zQuery . AddPullDownBox ( "Output To Remove" , arrayOutputs , 0 , IDX_QUERY_KEY ) ;
767+ if ( DialogResult . Cancel == zQuery . ShowDialog ( this ) )
768+ {
769+ return ;
770+ }
771+
772+ zRemapEntry . RemoveOutputConfigAt ( zQuery . GetIndex ( IDX_QUERY_KEY ) ) ;
773+ zItem . SubItems [ 1 ] . Text = zRemapEntry . GetOutputString ( ) ;
774+ MarkDirty ( ) ;
775+ UpdateActionEnableStates ( ) ;
671776 }
672777
673778 private void btnRemove_Click ( object sender , EventArgs e )
@@ -722,6 +827,16 @@ private void numericUpDownOutputParameter_ValueChanged(object sender, EventArgs
722827
723828 #region Support Methods
724829
830+ private void UpdateActionEnableStates ( )
831+ {
832+ btnAppend . Enabled = ( 1 == listViewKeys . SelectedIndices . Count ) ;
833+ btnAppendAt . Enabled = ( 1 == listViewKeys . SelectedIndices . Count ) ;
834+ btnUpdate . Enabled = ( 1 == listViewKeys . SelectedIndices . Count ) ;
835+ btnUpdateInput . Enabled = ( 1 == listViewKeys . SelectedIndices . Count ) ;
836+ btnRemoveAt . Enabled = ( listViewKeys . SelectedItems . Count == 1 ) &&
837+ ( ( ( RemapEntry ) listViewKeys . SelectedItems [ 0 ] . Tag ) . OutputConfigCount > 1 ) ;
838+ }
839+
725840 private void ResetInputOutputUI ( )
726841 {
727842 m_zActiveInputConfig . Reset ( ) ;
@@ -897,7 +1012,7 @@ private void FlushIniSettings()
8971012 m_zIniManager . FlushIniSettings ( ) ;
8981013 }
8991014
900- private bool CreateRemapEntryFromActiveConfigs ( ref RemapEntry zRemapEntry , RemapEntry updateEntry = null )
1015+ private bool CreateRemapEntryFromActiveConfigs ( ref RemapEntry zRemapEntry , RemapEntry updateEntry = null , bool bKeepOutputs = false )
9011016 {
9021017 var zCurrentInputConfig = CreateInputConfigFromUI ( ) ;
9031018 var zCurrentOutputConfig = CreateOutputConfigFromUI ( ) ;
@@ -906,7 +1021,8 @@ private bool CreateRemapEntryFromActiveConfigs(ref RemapEntry zRemapEntry, Remap
9061021 return false ;
9071022 }
9081023
909- zRemapEntry = new RemapEntry ( new InputConfig ( zCurrentInputConfig ) , new OutputConfig ( zCurrentOutputConfig ) ) ;
1024+ zRemapEntry = new RemapEntry ( new InputConfig ( zCurrentInputConfig ) ,
1025+ ( bKeepOutputs && updateEntry != null ) ? updateEntry . OutputConfigs : new List < OutputConfig > { new OutputConfig ( zCurrentOutputConfig ) } ) ;
9101026
9111027 // flip this result for indicator of a good remap entry
9121028 return ! IsInputAlreadyDefined ( zRemapEntry , updateEntry ) ;
@@ -1018,6 +1134,5 @@ public override void Reset()
10181134 }
10191135
10201136 #endregion
1021-
10221137 }
10231138}
0 commit comments