2013-07-19 17:27:02 +02:00
//#define ADD_CHANNELS_FROM_REF_LIST
2016-05-05 03:06:11 +02:00
2013-07-19 17:27:02 +02:00
using System ;
2013-03-31 14:09:38 +02:00
using System.Collections.Generic ;
2016-05-05 03:06:11 +02:00
using System.ComponentModel ;
2013-03-31 14:09:38 +02:00
using System.Drawing ;
using System.Globalization ;
using System.IO ;
2016-05-05 03:06:11 +02:00
using System.Linq ;
2013-03-31 14:09:38 +02:00
using System.Reflection ;
using System.Text ;
2016-05-05 03:06:11 +02:00
using System.Text.RegularExpressions ;
2013-03-31 14:09:38 +02:00
using System.Threading ;
using System.Windows.Forms ;
using ChanSort.Api ;
2016-05-05 03:06:11 +02:00
using ChanSort.Ui.Printing ;
2013-03-31 14:09:38 +02:00
using ChanSort.Ui.Properties ;
2016-05-05 03:06:11 +02:00
using DevExpress.Data ;
2013-03-31 14:09:38 +02:00
using DevExpress.Utils ;
using DevExpress.XtraBars ;
using DevExpress.XtraEditors ;
using DevExpress.XtraEditors.Controls ;
using DevExpress.XtraGrid ;
using DevExpress.XtraGrid.Columns ;
using DevExpress.XtraGrid.Views.Base ;
using DevExpress.XtraGrid.Views.Grid ;
2016-05-05 03:06:11 +02:00
using DevExpress.XtraGrid.Views.Grid.ViewInfo ;
2013-04-10 00:35:25 +02:00
using DevExpress.XtraTab ;
2013-03-31 14:09:38 +02:00
namespace ChanSort.Ui
{
public partial class MainForm : XtraForm
{
2017-10-29 16:11:00 +01:00
public static string AppVersion { get ; private set ; }
2020-12-29 18:49:25 +01:00
public static string AppVersionFull { get ; private set ; }
2013-05-11 16:45:29 +02:00
2013-11-20 09:55:42 +01:00
private const int MaxMruEntries = 10 ;
2016-05-05 03:06:11 +02:00
private readonly List < string > isoEncodings = new List < string > ( ) ;
private readonly List < string > mruFiles = new List < string > ( ) ;
2013-04-03 18:44:54 +02:00
2016-05-05 03:06:11 +02:00
private readonly string title ;
private EditMode curEditMode = EditMode . InsertAfter ;
2013-03-31 14:09:38 +02:00
private ISerializerPlugin currentPlugin ;
2016-05-05 03:06:11 +02:00
private string currentRefFile ;
private string currentTvFile ;
2013-03-31 14:09:38 +02:00
private SerializerBase currentTvSerializer ;
private Encoding defaultEncoding = Encoding . Default ;
2013-04-06 01:46:28 +02:00
private bool dontOpenEditor ;
2016-05-05 03:06:11 +02:00
private GridHitInfo downHit ;
2013-06-23 14:58:44 +02:00
private DragDropInfo dragDropInfo ;
2016-05-05 03:06:11 +02:00
private bool ignoreLanguageChange ;
private GridView lastFocusedGrid ;
private int subListIndex ;
2020-05-02 19:04:43 +02:00
private SizeF absScaleFactor = new SizeF ( 1 , 1 ) ;
2013-03-31 14:09:38 +02:00
#region ctor ( )
2016-05-05 03:06:11 +02:00
2013-03-31 14:09:38 +02:00
public MainForm ( )
{
2019-07-20 14:54:01 +02:00
if ( ! string . IsNullOrEmpty ( Config . Default . Language ) )
Thread . CurrentThread . CurrentUICulture = new CultureInfo ( Config . Default . Language ) ;
2013-03-31 14:09:38 +02:00
this . LookAndFeel . SetSkinStyle ( "Office 2010 Blue" ) ;
InitializeComponent ( ) ;
2013-07-19 17:27:02 +02:00
2017-10-29 16:11:00 +01:00
var version = this . GetType ( ) . Assembly . GetName ( ) . Version ;
AppVersion = new DateTime ( 2000 , 1 , 1 ) . AddDays ( version . Build ) . ToString ( "yyyy-MM-dd" ) ;
2020-12-29 18:49:25 +01:00
AppVersionFull = new DateTime ( 2000 , 1 , 1 ) . AddDays ( version . Build ) . AddSeconds ( version . Revision * 2 ) . ToString ( "yyyy-MM-dd_HHmm" ) ;
2017-10-29 16:11:00 +01:00
2016-05-06 02:30:46 +02:00
// remember which columns should be visible by default
foreach ( GridColumn col in this . gviewLeft . Columns )
col . Tag = col . Visible ;
foreach ( GridColumn col in this . gviewRight . Columns )
col . Tag = col . Visible ;
2019-11-10 20:09:27 +01:00
this . colOutSource . Caption = this . colSource . Caption ; // copy translated caption
2019-07-20 14:54:01 +02:00
if ( ! Config . Default . WindowSize . IsEmpty )
2020-05-02 19:04:43 +02:00
this . ClientSize = Config . Default . WindowSize . Scale ( absScaleFactor ) ;
2013-07-19 17:27:02 +02:00
this . title = string . Format ( base . Text , AppVersion ) ;
base . Text = title ;
2016-05-05 03:06:11 +02:00
this . Plugins = this . LoadSerializerPlugins ( ) ;
2013-03-31 14:09:38 +02:00
this . FillMenuWithIsoEncodings ( ) ;
2013-07-19 17:27:02 +02:00
using ( var stream = Assembly . GetExecutingAssembly ( ) . GetManifestResourceStream ( "ChanSort.Ui.app.ico" ) )
{
if ( stream ! = null )
this . Icon = new Icon ( stream ) ;
}
2013-03-31 14:09:38 +02:00
var bcLeft = new BindingContext ( ) ;
this . grpOutputList . BindingContext = bcLeft ;
2013-04-06 01:46:28 +02:00
this . lastFocusedGrid = this . gviewRight ;
if ( this . curEditMode = = EditMode . InsertAfter ) this . rbInsertAfter . Checked = true ;
else if ( this . curEditMode = = EditMode . InsertBefore ) this . rbInsertBefore . Checked = true ;
else this . rbInsertSwap . Checked = true ;
this . ActiveControl = this . gridRight ;
2013-07-19 17:27:02 +02:00
2016-05-06 02:30:46 +02:00
2013-07-19 17:27:02 +02:00
#if ! ADD_CHANNELS_FROM_REF_LIST
this . miAddFromRefList . Visibility = BarItemVisibility . Never ;
this . miAddFromRefList . Enabled = false ;
#endif
2017-10-28 13:20:39 +02:00
2020-05-06 22:07:48 +02:00
// The Api.View.Default object gives loaders access to UI functions
Api . View . Default = new Api . View ( ) ;
Api . View . Default . CreateActionBox = msg = > new ActionBoxDialog ( msg ) ;
Api . View . Default . MessageBoxImpl = ( msg , caption , buttons , icon ) = > ( int ) XtraMessageBox . Show ( this , msg , caption , ( MessageBoxButtons ) buttons , ( MessageBoxIcon ) icon ) ;
2019-02-05 19:30:47 +01:00
var defaultColumns = new List < string > ( ) ;
2020-01-01 13:56:19 +01:00
foreach ( GridColumn col in this . gviewRight . Columns . OrderBy ( c = > c . VisibleIndex ) )
2019-02-05 19:30:47 +01:00
{
if ( col . Visible )
defaultColumns . Add ( col . FieldName ) ;
}
ChannelList . DefaultVisibleColumns = defaultColumns ;
2013-04-08 10:08:49 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
internal IList < ISerializerPlugin > Plugins { get ; }
internal DataRoot DataRoot { get ; private set ; }
internal Editor Editor { get ; private set ; }
internal ChannelList CurrentChannelList { get ; private set ; }
#region IsLeftGridSortedByNewProgNr
private bool IsLeftGridSortedByNewProgNr
{
get
{
return this . gviewLeft . SortedColumns . Count > = 1 & &
this . gviewLeft . SortedColumns [ 0 ] . FieldName = = this . colOutSlot . FieldName ;
}
}
2013-04-08 10:08:49 +02:00
#endregion
2013-04-07 16:54:07 +02:00
2013-04-08 10:08:49 +02:00
#region InitAppAfterMainWindowWasShown ( )
2016-05-05 03:06:11 +02:00
2013-04-08 10:08:49 +02:00
private void InitAppAfterMainWindowWasShown ( )
{
2017-10-28 13:20:39 +02:00
if ( ! DepencencyChecker . IsVc2010RedistPackageX86Installed ( ) )
{
if ( XtraMessageBox . Show ( this ,
"Some channel list file formats can only be read when the\n" +
2017-10-29 15:55:01 +01:00
"Microsoft Visual C++ 2010 Redistributable Package (x86) is installed.\n" +
2017-10-28 13:20:39 +02:00
"\nDo you want to open the download page and quit ChanSort?" ,
"ChanSort" ,
MessageBoxButtons . YesNo ,
MessageBoxIcon . Question ,
MessageBoxDefaultButton . Button1 ) = = DialogResult . Yes )
{
System . Diagnostics . Process . Start ( "https://www.microsoft.com/en-us/download/details.aspx?id=5555" ) ;
Application . Exit ( ) ;
return ;
}
}
2019-07-20 14:54:01 +02:00
if ( Config . Default . CheckForUpdates )
2019-07-14 22:54:46 +02:00
this . BeginInvoke ( ( Action ) UpdateCheck . CheckForNewVersion ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
2013-03-31 14:09:38 +02:00
#endregion
#region LoadSerializerPlugins ( )
2016-05-05 03:06:11 +02:00
2013-03-31 14:09:38 +02:00
private IList < ISerializerPlugin > LoadSerializerPlugins ( )
{
var list = new List < ISerializerPlugin > ( ) ;
2016-05-05 03:06:11 +02:00
list . Add ( new RefSerializerPlugin ( ) ) ;
var exeDir = Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ? ? "" ;
2013-04-03 12:47:24 +02:00
foreach ( var file in Directory . GetFiles ( exeDir , "ChanSort.Loader.*.dll" ) )
2013-03-31 14:09:38 +02:00
{
try
{
2013-07-19 22:19:18 +02:00
var assembly = Assembly . UnsafeLoadFrom ( file ) ;
2016-05-05 03:06:11 +02:00
foreach ( var type in assembly . GetTypes ( ) )
2013-03-31 14:09:38 +02:00
{
2017-10-28 13:20:39 +02:00
if ( typeof ( ISerializerPlugin ) . IsAssignableFrom ( type ) & & ! type . IsAbstract )
{
var plugin = ( ISerializerPlugin ) Activator . CreateInstance ( type ) ;
plugin . DllName = Path . GetFileName ( file ) ;
list . Add ( plugin ) ;
}
2013-03-31 14:09:38 +02:00
}
}
2016-05-05 03:06:11 +02:00
catch ( Exception ex )
{
HandleException ( new IOException ( "Plugin " + file + "\n" + ex . Message , ex ) ) ;
}
2013-03-31 14:09:38 +02:00
}
2019-07-20 14:54:01 +02:00
list . Sort ( ( a , b ) = > a . PluginName . CompareTo ( b . PluginName ) ) ;
2013-03-31 14:09:38 +02:00
return list ;
}
2016-05-05 03:06:11 +02:00
2013-03-31 14:09:38 +02:00
#endregion
#region ShowOpenFileDialog ( )
2016-05-05 03:06:11 +02:00
2013-03-31 14:09:38 +02:00
private void ShowOpenFileDialog ( )
{
2013-05-11 16:45:29 +02:00
string supportedExtensions ;
int numberOfFilters ;
var filter = GetTvDataFileFilter ( out supportedExtensions , out numberOfFilters ) ;
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
using ( var dlg = new OpenFileDialog ( ) )
2013-03-31 14:09:38 +02:00
{
dlg . InitialDirectory = Environment . GetFolderPath ( Environment . SpecialFolder . MyComputer ) ;
dlg . AddExtension = true ;
2013-05-11 16:45:29 +02:00
dlg . Filter = filter + string . Format ( Resources . MainForm_FileDialog_OpenFileFilter , supportedExtensions ) ;
dlg . FilterIndex = numberOfFilters + 1 ;
2013-03-31 14:09:38 +02:00
dlg . CheckFileExists = true ;
2020-11-16 20:43:56 +01:00
dlg . DereferenceLinks = true ;
2013-03-31 14:09:38 +02:00
dlg . RestoreDirectory = true ;
2020-11-16 20:43:56 +01:00
dlg . CheckPathExists = true ;
dlg . ValidateNames = true ;
2013-07-22 20:13:34 +02:00
if ( dlg . ShowDialog ( ) ! = DialogResult . OK )
return ;
2016-05-05 03:06:11 +02:00
var plugin = dlg . FilterIndex < = this . Plugins . Count ? this . Plugins [ dlg . FilterIndex - 1 ] : null ;
this . LoadFiles ( plugin , dlg . FileName ) ;
2013-03-31 14:09:38 +02:00
}
}
2016-05-05 03:06:11 +02:00
2013-03-31 14:09:38 +02:00
#endregion
2013-05-11 16:45:29 +02:00
#region GetTvDataFileFilter ( )
2016-05-05 03:06:11 +02:00
2016-04-20 00:33:47 +02:00
internal string GetTvDataFileFilter ( out string supportedExtensions , out int numberOfFilters )
2013-05-11 16:45:29 +02:00
{
numberOfFilters = 0 ;
2016-05-05 03:06:11 +02:00
var filter = new StringBuilder ( ) ;
2013-05-11 16:45:29 +02:00
var extension = new StringBuilder ( ) ;
2019-07-20 14:54:01 +02:00
foreach ( var plugin in this . Plugins )
2013-05-11 16:45:29 +02:00
{
filter . Append ( plugin . PluginName ) . Append ( "|" ) . Append ( plugin . FileFilter ) ;
filter . Append ( "|" ) ;
2020-11-16 20:43:56 +01:00
foreach ( var ext in plugin . FileFilter . ToLower ( ) . Split ( ';' ) )
2017-06-08 20:01:42 +02:00
{
2020-11-16 20:43:56 +01:00
if ( ! ( ";" + extension + ";" ) . Contains ( ";" + ext + ";" ) )
{
extension . Append ( ext ) ;
extension . Append ( ";" ) ;
}
+ + numberOfFilters ;
2017-06-08 20:01:42 +02:00
}
2013-05-11 16:45:29 +02:00
}
if ( extension . Length > 0 )
extension . Remove ( extension . Length - 1 , 1 ) ;
supportedExtensions = extension . ToString ( ) ;
return filter . ToString ( ) ;
}
#endregion
2013-03-31 14:09:38 +02:00
#region SetFileName ( )
2016-05-05 03:06:11 +02:00
2013-03-31 14:09:38 +02:00
private void SetFileName ( string tvDataFile )
{
this . currentTvFile = tvDataFile ;
if ( ! string . IsNullOrEmpty ( tvDataFile ) )
{
2016-05-05 00:12:06 +02:00
this . currentRefFile = Path . Combine ( Path . GetDirectoryName ( this . currentTvFile ) ? ? "" ,
Path . GetFileNameWithoutExtension ( this . currentTvFile ) + ".txt" ) ;
2013-03-31 14:09:38 +02:00
}
2019-11-10 20:09:27 +01:00
this . Text = this . title + " - " + this . currentTvFile ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
2013-03-31 14:09:38 +02:00
#endregion
2013-04-06 01:46:28 +02:00
#region ReLoadFiles ( )
2016-05-05 03:06:11 +02:00
2013-04-06 01:46:28 +02:00
private void ReLoadFiles ( ISerializerPlugin plugin )
{
2016-05-05 03:06:11 +02:00
var listIndex = this . tabChannelList . SelectedTabPageIndex ;
2013-05-11 16:45:29 +02:00
this . LoadFiles ( plugin , this . currentTvFile ) ;
2013-04-06 01:46:28 +02:00
this . tabChannelList . SelectedTabPageIndex = listIndex ;
}
2016-05-05 03:06:11 +02:00
2013-04-06 01:46:28 +02:00
#endregion
2013-03-31 14:09:38 +02:00
#region LoadFiles ( )
2013-05-11 16:45:29 +02:00
private void LoadFiles ( ISerializerPlugin plugin , string tvDataFile )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
var dataUpdated = false ;
2013-03-31 14:09:38 +02:00
try
{
2015-09-19 23:24:31 +02:00
if ( DetectCommonFileCorruptions ( tvDataFile ) )
return ;
2013-05-11 16:45:29 +02:00
if ( ! this . LoadTvDataFile ( plugin , tvDataFile ) )
2013-03-31 14:09:38 +02:00
return ;
dataUpdated = true ;
2013-04-06 01:46:28 +02:00
this . gviewRight . BeginDataUpdate ( ) ;
this . gviewLeft . BeginDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
this . Editor = new Editor ( ) ;
this . Editor . DataRoot = this . DataRoot ;
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
this . CurrentChannelList = null ;
this . Editor . ChannelList = null ;
2013-04-06 01:46:28 +02:00
this . gridRight . DataSource = null ;
this . gridLeft . DataSource = null ;
2017-06-08 20:01:42 +02:00
this . FillChannelListTabs ( ) ;
2013-03-31 14:09:38 +02:00
2013-06-29 16:44:47 +02:00
//this.SetControlsEnabled(!this.dataRoot.IsEmpty);
2016-05-05 03:06:11 +02:00
this . UpdateFavoritesEditor ( this . DataRoot . SupportedFavorites ) ;
2015-11-21 19:34:30 +01:00
this . colEncrypted . OptionsColumn . AllowEdit = this . currentTvSerializer . Features . EncryptedFlagEdit ;
2021-01-02 13:18:37 +01:00
this . colAudioPid . OptionsColumn . AllowEdit = this . currentTvSerializer . Features . CanEditAudioPid ;
2019-11-17 14:56:19 +01:00
this . UpdateMenu ( true ) ;
2013-04-28 12:44:40 +02:00
2016-05-05 03:06:11 +02:00
if ( this . DataRoot . Warnings . Length > 0 & & this . miShowWarningsAfterLoad . Checked )
this . BeginInvoke ( ( Action ) this . ShowFileInformation ) ;
2013-05-03 19:02:30 +02:00
2016-05-05 03:06:11 +02:00
this . BeginInvoke ( ( Action ) this . InitInitialChannelOrder ) ;
2013-03-31 14:09:38 +02:00
}
catch ( Exception ex )
{
2013-04-06 01:46:28 +02:00
if ( ! ( ex is IOException ) )
2013-03-31 14:09:38 +02:00
throw ;
2016-05-05 03:06:11 +02:00
var name = plugin ! = null ? plugin . PluginName : "Loader" ;
2013-03-31 14:09:38 +02:00
XtraMessageBox . Show ( this , name + "\n\n" + ex . Message , Resources . MainForm_LoadFiles_IOException ,
2016-05-05 03:06:11 +02:00
MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
2013-03-31 14:09:38 +02:00
this . currentPlugin = null ;
this . currentTvFile = null ;
this . currentTvSerializer = null ;
this . Text = this . title ;
}
finally
{
if ( dataUpdated )
{
2013-04-06 01:46:28 +02:00
this . gviewRight . EndDataUpdate ( ) ;
this . gviewLeft . EndDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
}
}
}
2016-05-05 03:06:11 +02:00
2013-05-03 19:02:30 +02:00
#endregion
2013-04-06 01:46:28 +02:00
2015-09-19 23:24:31 +02:00
#region DetectCommonFileCorruptions ( )
2016-05-05 03:06:11 +02:00
2016-04-20 00:33:47 +02:00
internal bool DetectCommonFileCorruptions ( string tvDataFile )
2015-09-19 23:24:31 +02:00
{
2019-11-17 14:56:19 +01:00
if ( ! File . Exists ( tvDataFile ) ) // a loader (like Philips) may use internal file names that don't match the one in the UI, i.e. tvDataFile might be a directory path
return true ;
2015-09-19 23:24:31 +02:00
var content = File . ReadAllBytes ( tvDataFile ) ;
2020-02-02 23:31:44 +01:00
var isAllSame = true ;
var val = content . Length > 0 ? content [ 0 ] : 0 ;
2015-09-19 23:24:31 +02:00
for ( int i = 0 , c = content . Length ; i < c ; i + + )
{
2020-02-02 23:31:44 +01:00
if ( content [ i ] ! = val )
2015-09-19 23:24:31 +02:00
{
2020-02-02 23:31:44 +01:00
isAllSame = false ;
2015-09-19 23:24:31 +02:00
break ;
}
}
2020-02-02 23:31:44 +01:00
if ( isAllSame )
2015-09-19 23:24:31 +02:00
{
XtraMessageBox . Show ( this ,
Resources . MainForm_LoadFiles_AllZero ,
"ChanSort" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
return true ;
}
return false ;
}
#endregion
2017-06-08 20:01:42 +02:00
#region FillChannelListTabs ( )
2016-05-05 03:06:11 +02:00
2017-06-08 20:01:42 +02:00
private void FillChannelListTabs ( )
2013-04-06 01:46:28 +02:00
{
this . tabChannelList . TabPages . Clear ( ) ;
2016-05-05 03:06:11 +02:00
2014-07-11 10:07:33 +02:00
var itemList = new List < BarItem > ( ) ;
2016-05-05 03:06:11 +02:00
foreach ( BarItemLink link in this . mnuInputSource . ItemLinks )
2014-07-11 10:07:33 +02:00
itemList . Add ( link . Item ) ;
2016-05-05 03:06:11 +02:00
foreach ( var item in itemList )
2014-07-11 10:07:33 +02:00
{
this . barManager1 . Items . Remove ( item ) ;
item . Dispose ( ) ;
}
this . mnuInputSource . ClearLinks ( ) ;
2020-03-14 16:54:42 +01:00
XtraTabPage mostChannels = null ;
int mostChannelsCount = 0 ;
2016-05-05 03:06:11 +02:00
var i = 0 ;
foreach ( var list in this . DataRoot . ChannelLists )
2013-04-06 01:46:28 +02:00
{
2013-06-23 00:11:16 +02:00
if ( list . Channels . Count = = 0 )
continue ;
2013-04-06 01:46:28 +02:00
var tab = this . tabChannelList . TabPages . Add ( list . Caption ) ;
tab . Tag = list ;
2020-05-02 19:04:43 +02:00
if ( ! list . IsMixedSourceFavoritesList & & ( mostChannels = = null | | list . Count > mostChannelsCount ) )
2020-03-14 16:54:42 +01:00
{
mostChannels = tab ;
mostChannelsCount = list . Count ;
}
2014-07-11 10:07:33 +02:00
var item = new BarButtonItem ( this . barManager1 , list . Caption ) ;
2016-05-05 03:06:11 +02:00
item . ItemShortcut = new BarShortcut ( ( Keys ) ( ( int ) ( Keys . Alt | Keys . D1 ) + i ) ) ;
2014-07-11 10:07:33 +02:00
item . Tag = i ;
item . ItemClick + = this . miInputSource_ItemClick ;
this . mnuInputSource . AddItem ( item ) ;
+ + i ;
2013-04-06 01:46:28 +02:00
}
2013-04-10 00:35:25 +02:00
2013-05-30 09:28:01 +02:00
if ( tabChannelList . TabPages . Count > 0 )
{
2020-03-14 16:54:42 +01:00
if ( mostChannels = = null )
mostChannels = tabChannelList . TabPages [ 0 ] ;
if ( mostChannels = = this . tabChannelList . SelectedTabPage )
this . ShowChannelList ( ( ChannelList ) mostChannels . Tag ) ;
2013-05-30 09:28:01 +02:00
else
2020-03-14 16:54:42 +01:00
this . tabChannelList . SelectedTabPage = mostChannels ;
2013-05-30 09:28:01 +02:00
}
2013-06-29 16:44:47 +02:00
else
{
this . tabChannelList . TabPages . Add ( this . pageEmpty ) ;
2016-05-05 03:06:11 +02:00
this . CurrentChannelList = null ;
2013-06-29 16:44:47 +02:00
}
2013-04-06 01:46:28 +02:00
}
2013-03-31 14:09:38 +02:00
#endregion
#region UpdateFavoritesEditor ( )
2016-05-05 03:06:11 +02:00
2013-03-31 14:09:38 +02:00
private void UpdateFavoritesEditor ( Favorites favorites )
{
2019-08-13 13:29:59 +02:00
foreach ( var link in this . mnuFavSet . ItemLinks . ToList ( ) )
link . Item ? . Dispose ( ) ;
foreach ( var link in this . mnuFavUnset . ItemLinks . ToList ( ) )
link . Item ? . Dispose ( ) ;
2019-08-05 23:50:53 +02:00
2013-03-31 14:09:38 +02:00
this . repositoryItemCheckedComboBoxEdit1 . Items . Clear ( ) ;
this . repositoryItemCheckedComboBoxEdit2 . Items . Clear ( ) ;
2016-05-05 03:06:11 +02:00
var regex = "[" ;
var favCount = 0 ;
2019-08-13 13:29:59 +02:00
for ( var favMask = ( uint ) favorites ; ( favMask & 1 ) ! = 0 ; favMask > > = 1 )
2013-03-31 14:09:38 +02:00
{
2019-08-13 13:29:59 +02:00
var c = ( char ) ( 'A' + favCount ) ;
+ + favCount ;
this . repositoryItemCheckedComboBoxEdit1 . Items . Add ( c ) ;
this . repositoryItemCheckedComboBoxEdit2 . Items . Add ( c ) ;
var miSet = new BarButtonItem ( this . barManager1 , "&" + c ) ;
miSet . Tag = c . ToString ( ) ;
miSet . ItemShortcut = new BarShortcut ( Keys . Control | ( Keys ) ( ( int ) Keys . D0 + favCount % 10 ) ) ;
miSet . ItemClick + = this . miFavSet_ItemClick ;
this . mnuFavSet . AddItem ( miSet ) ;
var miUnset = new BarButtonItem ( this . barManager1 , "&" + c ) ;
miUnset . Tag = c . ToString ( ) ;
miUnset . ItemShortcut = new BarShortcut ( Keys . Control | Keys . Shift | ( Keys ) ( ( int ) Keys . D0 + favCount % 10 ) ) ;
miUnset . ItemClick + = this . miFavUnset_ItemClick ;
this . mnuFavUnset . AddItem ( miUnset ) ;
regex + = c ;
2013-03-31 14:09:38 +02:00
}
regex + = "]*" ;
this . repositoryItemCheckedComboBoxEdit1 . Mask . EditMask = regex ;
this . repositoryItemCheckedComboBoxEdit2 . Mask . EditMask = regex ;
2013-07-02 23:55:02 +02:00
while ( this . tabSubList . TabPages . Count > favCount + 1 )
2016-05-05 03:06:11 +02:00
this . tabSubList . TabPages . RemoveAt ( this . tabSubList . TabPages . Count - 1 ) ;
2013-07-02 23:55:02 +02:00
while ( this . tabSubList . TabPages . Count < favCount + 1 )
2020-02-11 21:06:37 +01:00
this . tabSubList . TabPages . Add ( ) ;
for ( int i = 1 ; i < this . tabSubList . TabPages . Count ; i + + )
this . tabSubList . TabPages [ i ] . Text = this . DataRoot . GetFavListCaption ( i - 1 , true ) ;
2016-05-05 03:06:11 +02:00
if ( ! this . DataRoot . SortedFavorites | | this . subListIndex > = favCount )
2013-07-02 23:55:02 +02:00
{
this . tabSubList . SelectedTabPageIndex = 0 ;
this . subListIndex = 0 ;
}
2016-05-05 03:06:11 +02:00
this . colOutFav . OptionsColumn . AllowEdit = ! this . DataRoot . SortedFavorites ;
this . colFavorites . OptionsColumn . AllowEdit = ! this . DataRoot . SortedFavorites ;
2013-03-31 14:09:38 +02:00
}
#endregion
2017-06-08 20:01:42 +02:00
#region GetSerializerForFile ( )
2016-05-05 03:06:11 +02:00
2017-06-08 20:01:42 +02:00
internal SerializerBase GetSerializerForFile ( string inputFileName , ref ISerializerPlugin hint )
2013-03-31 14:09:38 +02:00
{
if ( ! File . Exists ( inputFileName ) )
{
2016-05-05 03:06:11 +02:00
XtraMessageBox . Show ( this , string . Format ( Resources . MainForm_LoadTll_SourceTllNotFound , inputFileName ) ) ;
2013-03-31 14:09:38 +02:00
return null ;
}
2017-06-08 20:01:42 +02:00
List < ISerializerPlugin > candidates = new List < ISerializerPlugin > ( ) ;
if ( hint ! = null )
candidates . Add ( hint ) ;
else
2013-03-31 14:09:38 +02:00
{
2017-06-08 20:01:42 +02:00
var upperFileName = ( Path . GetFileName ( inputFileName ) ? ? "" ) . ToUpper ( ) ;
foreach ( var plugin in this . Plugins )
2014-05-25 16:13:15 +02:00
{
2017-06-08 20:01:42 +02:00
foreach ( var filter in plugin . FileFilter . ToUpper ( ) . Split ( ';' ) )
{
var regex = filter . Replace ( "." , "\\." ) . Replace ( "*" , ".*" ) . Replace ( "?" , "." ) ;
if ( Regex . IsMatch ( upperFileName , regex ) )
{
candidates . Add ( plugin ) ;
break ;
}
}
}
}
2017-10-28 13:20:39 +02:00
var errorMsgs = new StringBuilder ( ) ;
2017-06-08 20:01:42 +02:00
foreach ( var plugin in candidates )
{
2019-11-08 19:35:59 +01:00
SerializerBase serializer = null ;
2017-06-08 20:01:42 +02:00
try
{
2019-11-08 19:35:59 +01:00
serializer = plugin . CreateSerializer ( inputFileName ) ;
2017-06-08 20:01:42 +02:00
if ( serializer ! = null )
{
serializer . DefaultEncoding = this . defaultEncoding ;
serializer . Load ( ) ;
hint = plugin ;
return serializer ;
}
}
catch ( Exception ex )
{
2019-11-08 19:35:59 +01:00
serializer ? . Dispose ( ) ;
2021-01-23 09:35:00 +01:00
var errMsg = ex is FileLoadException ? ex . Message : ex . ToString ( ) ; // FileLoadExceptions are normal when a Loader does not support a file. No stack trace needed
errorMsgs . AppendLine ( $"{plugin.DllName} ({plugin.PluginName}): {errMsg}\n\n" ) ;
2017-06-08 20:01:42 +02:00
if ( ex is ArgumentException )
{
var msg = ex . ToString ( ) ;
if ( msg . Contains ( "ZipFile..ctor()" ) )
{
XtraMessageBox . Show ( this , string . Format ( Resources . MainForm_LoadTll_InvalidZip , inputFileName ) ) ;
return null ;
}
}
2014-05-25 16:13:15 +02:00
}
2013-03-31 14:09:38 +02:00
}
2017-10-28 13:20:39 +02:00
XtraMessageBox . Show ( this , string . Format ( Resources . MainForm_LoadTll_SerializerNotFound , inputFileName ) + "\n\n" + errorMsgs ) ;
2013-03-31 14:09:38 +02:00
return null ;
}
2016-05-05 03:06:11 +02:00
2013-03-31 14:09:38 +02:00
#endregion
#region LoadTvDataFile ( )
2016-05-05 03:06:11 +02:00
2013-05-11 16:45:29 +02:00
private bool LoadTvDataFile ( ISerializerPlugin plugin , string tvDataFile )
{
if ( ! File . Exists ( tvDataFile ) )
{
2016-05-05 03:06:11 +02:00
XtraMessageBox . Show ( this , Resources . MainForm_LoadTvDataFile_FileNotFound_Caption ,
2013-05-11 16:45:29 +02:00
string . Format ( Resources . MainForm_LoadTvDataFile_FileNotFound_Message , tvDataFile ) ,
2016-05-05 03:06:11 +02:00
MessageBoxButtons . OK , MessageBoxIcon . Exclamation ) ;
2013-05-11 16:45:29 +02:00
return false ;
}
// abort action if there is no currentTvSerializer for the input file
2017-06-08 20:01:42 +02:00
SerializerBase serializer = this . GetSerializerForFile ( tvDataFile , ref plugin ) ;
2013-05-11 16:45:29 +02:00
if ( serializer = = null )
return false ;
if ( ! this . PromptSaveAndContinue ( ) )
return false ;
2019-11-08 19:35:59 +01:00
this . currentTvSerializer ? . Dispose ( ) ;
2019-11-08 02:31:44 +01:00
serializer . DataRoot . ValidateAfterLoad ( ) ;
2019-11-17 14:56:19 +01:00
this . SetFileName ( serializer . FileName ) ;
2016-05-05 03:06:11 +02:00
this . currentPlugin = plugin ;
2013-05-11 16:45:29 +02:00
this . currentTvSerializer = serializer ;
2017-11-30 14:50:22 +01:00
this . DataRoot = serializer . DataRoot ;
2019-11-17 14:56:19 +01:00
this . AddFileToMruList ( tvDataFile ) ;
2013-05-11 16:45:29 +02:00
this . UpdateMruMenu ( ) ;
2013-03-31 14:09:38 +02:00
return true ;
}
2016-05-05 03:06:11 +02:00
2013-03-31 14:09:38 +02:00
#endregion
2013-05-11 16:45:29 +02:00
#region AddFileToMruList ( )
2016-05-05 03:06:11 +02:00
2013-05-11 16:45:29 +02:00
private void AddFileToMruList ( string file )
{
2016-05-05 03:06:11 +02:00
if ( string . IsNullOrEmpty ( file ) )
return ;
2013-05-11 16:45:29 +02:00
this . mruFiles . Remove ( file ) ;
if ( this . mruFiles . Count > = MaxMruEntries )
2016-05-05 03:06:11 +02:00
this . mruFiles . RemoveAt ( this . mruFiles . Count - 1 ) ;
2013-05-11 16:45:29 +02:00
this . mruFiles . Insert ( 0 , file ) ;
}
2016-05-05 03:06:11 +02:00
2013-05-11 16:45:29 +02:00
#endregion
2013-03-31 14:09:38 +02:00
#region PromptSaveAndContinue ( )
2016-05-05 03:06:11 +02:00
2013-03-31 14:09:38 +02:00
private bool PromptSaveAndContinue ( )
{
2016-05-05 03:06:11 +02:00
if ( this . DataRoot = = null | | ! this . DataRoot . NeedsSaving )
2013-03-31 14:09:38 +02:00
return true ;
2016-05-05 03:06:11 +02:00
using ( var dlg = new ActionBoxDialog ( Resources . MainForm_PromptSaveAndContinue_Question ) )
2013-03-31 14:09:38 +02:00
{
2013-05-03 19:02:30 +02:00
dlg . AddAction ( Resources . MainForm_PromptSaveAndContinue_Save , DialogResult . Yes , dlg . Save ) ;
dlg . AddAction ( Resources . MainForm_PromptSaveAndContinue_Discard , DialogResult . No , dlg . Discard ) ;
dlg . AddAction ( Resources . MainForm_Cancel , DialogResult . Cancel , dlg . Cancel ) ;
switch ( dlg . ShowDialog ( this ) )
{
2016-05-05 03:06:11 +02:00
case DialogResult . Yes :
this . SaveFiles ( ) ;
break ;
case DialogResult . No :
break ;
case DialogResult . Cancel :
return false ;
2013-05-03 19:02:30 +02:00
}
2013-03-31 14:09:38 +02:00
}
return true ;
}
2016-05-05 03:06:11 +02:00
2013-03-31 14:09:38 +02:00
#endregion
2013-05-03 19:02:30 +02:00
#region InitInitialChannelOrder ( )
2016-05-05 03:06:11 +02:00
2013-05-03 19:02:30 +02:00
private void InitInitialChannelOrder ( )
2013-03-31 14:09:38 +02:00
{
2013-05-03 19:02:30 +02:00
DialogResult res ;
2016-05-05 03:06:11 +02:00
var msg = Resources . MainForm_InitInitialChannelOrder_Question ;
using ( var dlg = new ActionBoxDialog ( msg ) )
2013-04-03 23:26:09 +02:00
{
2016-05-06 02:30:46 +02:00
dlg . AddAction ( Resources . MainForm_InitInitialChannelOrder_ReferenceList , DialogResult . Yes , dlg . CopyList , true ) ;
dlg . AddAction ( Resources . MainForm_InitInitialChannelOrder_CurrentList , DialogResult . No , dlg . FullList ) ;
2013-05-03 19:02:30 +02:00
dlg . AddAction ( Resources . MainForm_InitInitialChannelOrder_EmptyList , DialogResult . Cancel , dlg . EmptyList ) ;
res = dlg . ShowDialog ( this ) ;
2013-04-03 23:26:09 +02:00
}
2013-05-03 19:02:30 +02:00
if ( res = = DialogResult . Yes )
2016-05-05 03:06:11 +02:00
this . BeginInvoke ( ( Action ) ( ( ) = > this . ShowOpenReferenceFileDialog ( false ) ) ) ;
2013-05-03 19:02:30 +02:00
else if ( res = = DialogResult . No )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
this . DataRoot . ApplyCurrentProgramNumbers ( ) ;
2013-05-05 22:40:57 +02:00
this . RefreshGrid ( this . gviewLeft , this . gviewRight ) ;
2013-03-31 14:09:38 +02:00
}
}
2016-05-05 03:06:11 +02:00
2013-03-31 14:09:38 +02:00
#endregion
#region ShowOpenReferenceFileDialog ( )
2016-05-05 03:06:11 +02:00
2013-07-19 17:27:02 +02:00
private void ShowOpenReferenceFileDialog ( bool addChannels )
2013-03-31 14:09:38 +02:00
{
2016-05-05 00:12:06 +02:00
new ReferenceListForm ( this ) . ShowDialog ( this ) ;
2013-05-11 16:45:29 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#region ShowChannelList ( )
2013-05-11 16:45:29 +02:00
2013-03-31 14:09:38 +02:00
private void ShowChannelList ( ChannelList channelList )
{
2016-05-05 03:06:11 +02:00
this . CurrentChannelList = channelList ;
this . Editor . ChannelList = channelList ;
2016-04-27 19:03:50 +02:00
2013-03-31 14:09:38 +02:00
if ( channelList ! = null )
{
2016-04-27 19:03:50 +02:00
this . LoadInputGridLayout ( ) ;
2013-04-06 01:46:28 +02:00
this . gridRight . DataSource = channelList . Channels ;
this . gridLeft . DataSource = channelList . Channels ;
2015-06-13 18:37:59 +02:00
SignalSource src = 0 ;
if ( ( this . currentTvSerializer . Features . ChannelNameEdit & ChannelNameEditMode . Analog ) ! = 0 )
src | = SignalSource . Analog ;
if ( ( this . currentTvSerializer . Features . ChannelNameEdit & ChannelNameEditMode . Digital ) ! = 0 )
src | = SignalSource . Digital ;
this . colName . OptionsColumn . AllowEdit = this . colOutName . OptionsColumn . AllowEdit = ( channelList . SignalSource & src ) ! = 0 ;
2016-04-16 20:01:51 +02:00
2016-05-05 03:06:11 +02:00
if ( this . DataRoot . MixedSourceFavorites )
2016-04-16 20:01:51 +02:00
{
2016-04-27 19:03:50 +02:00
if ( channelList . IsMixedSourceFavoritesList )
2016-04-16 20:01:51 +02:00
{
this . tabSubList . SelectedTabPageIndex = 1 ;
this . pageProgNr . PageVisible = false ;
this . grpSubList . Visible = true ;
}
else
{
this . grpSubList . Visible = false ;
this . pageProgNr . PageVisible = true ;
this . tabSubList . SelectedTabPageIndex = 0 ;
2016-05-05 03:06:11 +02:00
}
2016-04-16 20:01:51 +02:00
}
else
{
this . pageProgNr . PageVisible = true ;
2016-05-05 03:06:11 +02:00
this . grpSubList . Visible = DataRoot . SortedFavorites ;
2016-04-16 20:01:51 +02:00
}
2013-03-31 14:09:38 +02:00
}
else
{
2013-04-06 01:46:28 +02:00
this . gridRight . DataSource = null ;
2016-04-16 20:01:51 +02:00
this . gridLeft . DataSource = null ;
this . grpSubList . Visible = false ;
2013-03-31 14:09:38 +02:00
}
2013-04-06 01:46:28 +02:00
if ( gviewRight . IsValidRowHandle ( 0 ) )
this . SelectFocusedRow ( this . gviewRight , 0 ) ;
if ( gviewLeft . IsValidRowHandle ( 0 ) )
this . SelectFocusedRow ( this . gviewLeft , 0 ) ;
2015-11-27 01:51:08 +01:00
UpdateGridReadOnly ( ) ;
2013-05-16 21:06:44 +02:00
2015-06-13 18:37:59 +02:00
2017-06-08 20:01:42 +02:00
this . UpdateInsertSlotNumber ( ) ;
2013-05-16 21:06:44 +02:00
this . UpdateMenu ( ) ;
2016-04-16 20:01:51 +02:00
this . mnuFavList . Enabled = this . grpSubList . Visible ;
if ( ! this . grpSubList . Visible )
this . tabSubList . SelectedTabPageIndex = 0 ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region UpdateGridReadOnly
2015-11-27 01:51:08 +01:00
private void UpdateGridReadOnly ( )
{
2016-05-05 03:06:11 +02:00
var allowEdit = ! this . CurrentChannelList ? . ReadOnly ? ? true ;
var forceEdit = this . miAllowEditPredefinedLists . Down ;
2015-11-27 01:51:08 +01:00
this . gviewLeft . OptionsBehavior . Editable = allowEdit | | forceEdit ;
this . gviewRight . OptionsBehavior . Editable = allowEdit | | forceEdit ;
this . gviewLeft . Appearance . Row . BackColor = this . gviewRight . Appearance . Row . BackColor = Color . MistyRose ;
this . gviewLeft . Appearance . Empty . BackColor = this . gviewRight . Appearance . Empty . BackColor = Color . MistyRose ;
this . gviewLeft . Appearance . Row . Options . UseBackColor = this . gviewRight . Appearance . Row . Options . UseBackColor = ! allowEdit ;
this . gviewLeft . Appearance . Empty . Options . UseBackColor = this . gviewRight . Appearance . Empty . Options . UseBackColor = ! allowEdit ;
this . lblPredefinedList . Visible = ! ( allowEdit | | forceEdit ) ;
}
2016-05-05 03:06:11 +02:00
#endregion
2015-11-27 01:51:08 +01:00
2016-05-05 03:06:11 +02:00
#region ShowSaveFileDialog ( )
2013-03-31 14:09:38 +02:00
private void ShowSaveFileDialog ( )
{
2019-11-17 14:56:19 +01:00
var extension = Path . GetExtension ( this . currentTvFile ) ? ? "." ;
2016-05-05 03:06:11 +02:00
using ( var dlg = new SaveFileDialog ( ) )
2013-03-31 14:09:38 +02:00
{
2013-05-16 21:06:44 +02:00
dlg . InitialDirectory = Path . GetDirectoryName ( this . currentTvFile ) ;
dlg . FileName = Path . GetFileName ( this . currentTvFile ) ;
2013-03-31 14:09:38 +02:00
dlg . AddExtension = true ;
dlg . DefaultExt = extension ;
dlg . Filter = string . Format ( Resources . MainForm_FileDialog_SaveFileFilter , extension ) ;
dlg . FilterIndex = 0 ;
dlg . ValidateNames = true ;
dlg . RestoreDirectory = true ;
dlg . OverwritePrompt = true ;
if ( dlg . ShowDialog ( ) = = DialogResult . OK )
{
this . SetFileName ( dlg . FileName ) ;
this . SaveFiles ( ) ;
}
}
}
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#region SaveFiles ( )
2013-03-31 14:09:38 +02:00
private void SaveFiles ( )
{
2013-04-06 01:46:28 +02:00
this . gviewRight . PostEditor ( ) ;
this . gviewLeft . PostEditor ( ) ;
2013-05-03 19:02:30 +02:00
2013-03-31 14:09:38 +02:00
try
{
2015-09-19 23:24:31 +02:00
if ( ! this . HandleChannelNumberGaps ( ) )
return ;
2019-11-08 02:31:44 +01:00
if ( ! this . PromptHandlingOfUnsortedChannels ( ) )
return ;
2013-03-31 14:09:38 +02:00
this . SaveTvDataFile ( ) ;
2016-05-05 03:06:11 +02:00
this . DataRoot . NeedsSaving = false ;
2013-05-03 19:02:30 +02:00
this . RefreshGrid ( this . gviewLeft , this . gviewRight ) ;
2019-11-17 14:56:19 +01:00
this . UpdateMenu ( true ) ;
2013-03-31 14:09:38 +02:00
}
catch ( IOException ex )
{
2016-05-05 03:06:11 +02:00
XtraMessageBox . Show ( this ,
2013-03-31 14:09:38 +02:00
Resources . MainForm_SaveFiles_ErrorMsg +
2016-05-05 03:06:11 +02:00
ex . Message ,
Resources . MainForm_SaveFiles_ErrorTitle ,
2013-03-31 14:09:38 +02:00
MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
}
2013-05-03 19:02:30 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region PromptHandlingOfUnsortedChannels ( )
2013-05-03 19:02:30 +02:00
private bool PromptHandlingOfUnsortedChannels ( )
{
2016-05-05 03:06:11 +02:00
var hasUnsorted = false ;
foreach ( var list in this . DataRoot . ChannelLists )
2013-03-31 14:09:38 +02:00
{
2013-05-03 19:02:30 +02:00
foreach ( var channel in list . Channels )
{
2019-11-08 19:35:59 +01:00
if ( channel . NewProgramNr < 0 & & ! channel . IsDeleted )
2013-05-03 19:02:30 +02:00
{
hasUnsorted = true ;
break ;
}
}
2013-03-31 14:09:38 +02:00
}
2013-05-03 19:02:30 +02:00
2019-11-08 02:31:44 +01:00
UnsortedChannelMode mode = UnsortedChannelMode . Delete ;
2017-11-30 14:50:22 +01:00
if ( hasUnsorted )
2013-05-03 19:02:30 +02:00
{
2017-11-30 14:50:22 +01:00
var msg = Resources . MainForm_PromptHandlingOfUnsortedChannels_Question ;
DialogResult res ;
using ( var dlg = new ActionBoxDialog ( msg ) )
{
dlg . AddAction ( Resources . MainForm_PromptHandlingOfUnsortedChannels_Append , DialogResult . Yes , dlg . FullList ) ;
2019-11-08 19:35:59 +01:00
if ( this . currentTvSerializer . Features . DeleteMode ! = SerializerBase . DeleteMode . NotSupported )
2017-11-30 14:50:22 +01:00
dlg . AddAction ( Resources . MainForm_PromptHandlingOfUnsortedChannels_Delete , DialogResult . No , dlg . Delete ) ;
dlg . AddAction ( Resources . MainForm_Cancel , DialogResult . Cancel , dlg . Cancel ) ;
res = dlg . ShowDialog ( this ) ;
}
2013-05-03 19:02:30 +02:00
2017-11-30 14:50:22 +01:00
if ( res = = DialogResult . Cancel )
return false ;
if ( res = = DialogResult . Yes )
mode = UnsortedChannelMode . AppendInOrder ;
}
2013-03-31 14:09:38 +02:00
2017-11-30 14:50:22 +01:00
// ensure unsorted and deleted channels have a valid program number
2019-11-08 19:35:59 +01:00
this . DataRoot . AssignNumbersToUnsortedAndDeletedChannels ( mode ) ;
2013-05-03 19:02:30 +02:00
return true ;
}
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#endregion
#region HandleChannelNumberGaps ( )
2015-09-19 23:24:31 +02:00
private bool HandleChannelNumberGaps ( )
2015-01-14 21:38:01 +01:00
{
if ( this . currentTvSerializer . Features . CanHaveGaps )
2015-09-19 23:24:31 +02:00
return true ;
2016-05-05 03:06:11 +02:00
var hasGaps = this . ProcessChannelNumberGaps ( true ) ;
2015-09-19 23:24:31 +02:00
if ( hasGaps )
{
var action = XtraMessageBox . Show ( this ,
2016-05-05 03:06:11 +02:00
Resources . MainForm_HandleChannelNumberGaps ,
2015-09-19 23:24:31 +02:00
"ChanSort" , MessageBoxButtons . YesNoCancel , MessageBoxIcon . Question ) ;
if ( action = = DialogResult . Cancel )
return false ;
if ( action = = DialogResult . Yes )
this . ProcessChannelNumberGaps ( false ) ;
}
return true ;
}
2015-01-14 21:38:01 +01:00
2016-05-05 03:06:11 +02:00
#endregion
#region ProcessChannelNumberGaps ( )
2015-09-19 23:24:31 +02:00
private bool ProcessChannelNumberGaps ( bool testOnly )
{
2016-05-05 03:06:11 +02:00
var wasRenumbered = false ;
foreach ( var list in this . DataRoot . ChannelLists )
2015-01-14 21:38:01 +01:00
{
2016-05-05 03:06:11 +02:00
var chNr = 1 ;
2015-01-14 21:38:01 +01:00
foreach ( var channel in list . Channels . OrderBy ( c = > c . NewProgramNr ) )
{
if ( channel . IsDeleted | | channel . NewProgramNr < 0 )
continue ;
if ( channel . NewProgramNr = = 0 & & chNr = = 1 )
chNr = 0 ;
if ( channel . NewProgramNr ! = chNr )
{
2015-09-19 23:24:31 +02:00
if ( testOnly )
return true ;
2015-01-14 21:38:01 +01:00
wasRenumbered = true ;
channel . NewProgramNr = chNr ;
}
+ + chNr ;
}
}
2015-09-19 23:24:31 +02:00
return wasRenumbered ;
2015-01-14 21:38:01 +01:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region SaveReferenceFile ( )
2013-03-31 14:09:38 +02:00
private void SaveReferenceFile ( )
{
2013-07-19 17:27:02 +02:00
string fileName ;
using ( var dlg = new SaveFileDialog ( ) )
{
dlg . RestoreDirectory = true ;
2016-05-05 00:12:06 +02:00
dlg . InitialDirectory = Path . GetDirectoryName ( this . currentRefFile ) ;
dlg . FileName = Path . GetFileName ( this . currentRefFile ) ;
dlg . DefaultExt = ".txt" ;
dlg . Filter = "ChanSort Single-List|*.txt|ChanSort Multi-List|*.csv|SamToolBox|*.chl|All files|*" ;
2013-07-19 17:27:02 +02:00
dlg . FilterIndex = 1 ;
dlg . CheckPathExists = true ;
dlg . CheckFileExists = false ;
dlg . AddExtension = true ;
if ( dlg . ShowDialog ( this ) ! = DialogResult . OK )
return ;
fileName = dlg . FileName ;
}
2016-05-05 03:06:11 +02:00
var ext = ( Path . GetExtension ( fileName ) ? ? "" ) . ToLower ( ) ;
2013-07-19 17:27:02 +02:00
if ( ext = = ".csv" )
2016-05-06 02:30:46 +02:00
CsvRefListSerializer . Save ( fileName , this . DataRoot ) ;
2016-05-05 00:12:06 +02:00
else if ( ext = = ".chl" | | ext = = ".txt" )
2016-05-06 02:30:46 +02:00
TxtRefListSerializer . Save ( fileName , this . CurrentChannelList ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#region SaveTvDataFile ( )
2013-03-31 14:09:38 +02:00
private void SaveTvDataFile ( )
{
this . splashScreenManager1 . ShowWaitForm ( ) ;
try
{
2019-11-17 14:56:19 +01:00
foreach ( var filePath in this . currentTvSerializer . GetDataFilePaths ( ) )
2013-03-31 14:09:38 +02:00
{
2019-11-17 14:56:19 +01:00
if ( File . Exists ( filePath ) )
{
var bakFile = filePath + ".bak" ;
if ( ! File . Exists ( bakFile ) )
File . Copy ( filePath , bakFile ) ;
}
2013-03-31 14:09:38 +02:00
}
2019-11-17 14:56:19 +01:00
2013-04-11 01:38:37 +02:00
this . currentTvSerializer . Save ( this . currentTvFile ) ;
2019-11-08 02:31:44 +01:00
this . DataRoot . ValidateAfterSave ( ) ;
2013-03-31 14:09:38 +02:00
}
finally
{
this . splashScreenManager1 . CloseWaitForm ( ) ;
}
}
2016-05-05 03:06:11 +02:00
#endregion
#region AddChannels ( )
2013-03-31 14:09:38 +02:00
private void AddChannels ( )
{
2013-04-06 01:46:28 +02:00
if ( this . rbInsertSwap . Checked )
2016-05-06 23:54:54 +02:00
{
this . SwapChannels ( ) ;
return ;
}
var selectedChannels = this . GetSelectedChannels ( gviewRight ) ;
if ( selectedChannels . Count = = 0 ) return ;
2013-04-06 01:46:28 +02:00
2013-03-31 14:09:38 +02:00
ChannelInfo lastInsertedChannel ;
2013-04-06 01:46:28 +02:00
this . gviewLeft . BeginDataUpdate ( ) ;
this . gviewRight . BeginDataUpdate ( ) ;
2016-05-06 23:54:54 +02:00
// remove all the selected channels which are about to be added.
// This may require an adjustment of the insert position when channels are removed in front of it and gaps are closed.
var insertSlot = this . CurrentChannelList . InsertProgramNumber ;
2017-06-08 20:01:42 +02:00
if ( insertSlot = = 1 & & this . rbInsertAfter . Checked & & this . gviewLeft . RowCount = = 0 )
insertSlot = 0 ;
2016-05-06 23:54:54 +02:00
var contextRow = ( ChannelInfo ) this . gviewLeft . GetFocusedRow ( ) ;
if ( contextRow ! = null )
{
if ( ! ( this . rbInsertBefore . Checked & & insertSlot = = contextRow . NewProgramNr | | this . rbInsertAfter . Checked & & insertSlot = = contextRow . NewProgramNr + 1 ) )
contextRow = null ;
}
this . RemoveChannels ( gviewRight , this . cbCloseGap . Checked ) ;
if ( contextRow ! = null )
this . CurrentChannelList . InsertProgramNumber = this . rbInsertBefore . Checked ? contextRow . NewProgramNr : contextRow . NewProgramNr + 1 ;
else
this . CurrentChannelList . InsertProgramNumber = insertSlot ;
2013-03-31 14:09:38 +02:00
try
{
2016-05-05 03:06:11 +02:00
lastInsertedChannel = this . Editor . AddChannels ( selectedChannels ) ;
2013-03-31 14:09:38 +02:00
this . UpdateInsertSlotTextBox ( ) ;
}
finally
{
2013-04-06 01:46:28 +02:00
this . gviewRight . EndDataUpdate ( ) ;
this . gviewLeft . EndDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
}
if ( lastInsertedChannel = = null )
{
2013-04-06 01:46:28 +02:00
this . NavigateToChannel ( selectedChannels [ 0 ] , this . gviewLeft ) ;
2013-03-31 14:09:38 +02:00
return ;
}
2016-05-05 03:06:11 +02:00
var index = this . CurrentChannelList . Channels . IndexOf ( lastInsertedChannel ) ;
var rowHandle = this . gviewLeft . GetRowHandle ( index ) ;
2013-04-06 01:46:28 +02:00
if ( this . rbInsertBefore . Checked )
+ + rowHandle ;
this . SelectFocusedRow ( this . gviewLeft , rowHandle ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2016-05-06 23:54:54 +02:00
#region SwapChannels ( )
private void SwapChannels ( )
{
if ( this . gviewRight . SelectedRowsCount = = 0 )
return ;
if ( this . gviewLeft . SelectedRowsCount ! = this . gviewRight . SelectedRowsCount )
{
XtraMessageBox . Show ( this , Resources . MainForm_SwapChannels_RowCountMsg , Resources . MainForm_SwapChannels_RowCountTitle , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
return ;
}
// get selected channel objects from left and right grid before we start modifying the data
var leftChannels = this . GetSelectedChannels ( gviewLeft ) ;
var rightChannels = this . GetSelectedChannels ( gviewRight ) ;
// swap channel numbers
ChannelInfo ch1 = null , ch2 = null ;
for ( int i = 0 , c = leftChannels . Count ; i < c ; i + + )
{
ch1 = leftChannels [ i ] ;
ch2 = rightChannels [ i ] ;
int p = ch1 . NewProgramNr ;
ch1 . NewProgramNr = ch2 . NewProgramNr ;
ch2 . NewProgramNr = p ;
}
// resort the grids
this . RefreshGrids ( ) ;
// in the left grid, select the last swapped channel from the right grid
this . gviewLeft . ClearSelection ( ) ;
var h = this . gviewLeft . GetRowHandle ( this . CurrentChannelList . Channels . IndexOf ( ch2 ) ) ;
if ( h > = 0 )
{
this . gviewLeft . SelectRow ( h ) ;
this . gviewLeft . FocusedRowHandle = h ;
this . gviewLeft . MakeRowVisible ( h ) ;
}
// in the right grid, select the last swapped channel from the left grid
this . gviewRight . ClearSelection ( ) ;
h = this . gviewRight . GetRowHandle ( this . CurrentChannelList . Channels . IndexOf ( ch1 ) ) ;
if ( h > = 0 )
{
this . gviewRight . SelectRow ( h ) ;
this . gviewRight . FocusedRowHandle = h ;
this . gviewRight . MakeRowVisible ( h ) ;
}
}
#endregion
2016-05-05 03:06:11 +02:00
#region RemoveChannels ( )
2013-03-31 14:09:38 +02:00
2013-04-06 01:46:28 +02:00
private void RemoveChannels ( GridView grid , bool closeGap )
2013-03-31 14:09:38 +02:00
{
2013-04-06 01:46:28 +02:00
var selectedChannels = this . GetSelectedChannels ( grid ) ;
2013-03-31 14:09:38 +02:00
if ( selectedChannels . Count = = 0 ) return ;
2016-05-05 03:06:11 +02:00
var focusedRow = this . gviewLeft . FocusedRowHandle - selectedChannels . Count ;
2013-04-06 01:46:28 +02:00
if ( ! gviewLeft . IsLastRow )
2013-03-31 14:09:38 +02:00
+ + focusedRow ;
2015-09-19 23:24:31 +02:00
if ( focusedRow < 0 ) focusedRow = 0 ;
2013-04-06 01:46:28 +02:00
this . gviewRight . BeginDataUpdate ( ) ;
this . gviewLeft . BeginDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
try
{
2016-05-05 03:06:11 +02:00
this . Editor . RemoveChannels ( selectedChannels , closeGap ) ;
2013-03-31 14:09:38 +02:00
}
finally
{
2013-04-06 01:46:28 +02:00
this . gviewLeft . EndDataUpdate ( ) ;
this . gviewRight . EndDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
}
2013-04-06 01:46:28 +02:00
this . SelectFocusedRow ( this . gviewLeft , focusedRow ) ;
2013-03-31 14:09:38 +02:00
this . UpdateInsertSlotTextBox ( ) ;
}
2016-05-05 03:06:11 +02:00
#endregion
#region SelectFocusedRow ( )
2013-03-31 14:09:38 +02:00
2013-04-06 01:46:28 +02:00
private void SelectFocusedRow ( GridView grid , int rowHandle )
{
grid . BeginSelection ( ) ;
grid . ClearSelection ( ) ;
grid . FocusedRowHandle = rowHandle ;
grid . SelectRow ( rowHandle ) ;
2016-05-05 03:06:11 +02:00
grid . EndSelection ( ) ;
2013-04-06 01:46:28 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region MoveChannels ( )
2013-03-31 14:09:38 +02:00
private void MoveChannels ( bool up )
{
2013-06-23 14:58:44 +02:00
if ( ! this . IsLeftGridSortedByNewProgNr ) return ;
2013-04-06 01:46:28 +02:00
var selectedChannels = this . GetSelectedChannels ( this . gviewLeft ) ;
2013-03-31 14:09:38 +02:00
if ( selectedChannels . Count = = 0 ) return ;
2013-04-06 01:46:28 +02:00
this . gviewLeft . BeginDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
try
{
2016-05-05 03:06:11 +02:00
this . Editor . MoveChannels ( selectedChannels , up ) ;
2013-03-31 14:09:38 +02:00
}
finally
{
2013-04-06 01:46:28 +02:00
this . gviewLeft . EndDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
}
2013-07-02 23:55:02 +02:00
this . UpdateInsertSlotNumber ( ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region SetSlotNumber ( )
2013-03-31 14:09:38 +02:00
2013-04-06 01:46:28 +02:00
private bool SetSlotNumber ( string progNr )
2013-03-31 14:09:38 +02:00
{
2013-04-06 01:46:28 +02:00
int prog ;
if ( ! int . TryParse ( progNr , out prog ) | | prog < 0 )
2013-03-31 14:09:38 +02:00
return false ;
var selectedChannels = this . GetSelectedChannels ( this . lastFocusedGrid ) ;
if ( selectedChannels . Count = = 0 ) return true ;
2013-04-06 01:46:28 +02:00
this . gviewLeft . BeginDataUpdate ( ) ;
this . gviewRight . BeginDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
try
{
2016-05-05 03:06:11 +02:00
this . Editor . SetSlotNumber ( selectedChannels , prog , this . rbInsertSwap . Checked , this . cbCloseGap . Checked ) ;
2016-05-06 23:54:54 +02:00
this . txtSetSlot . Text = ( prog + selectedChannels . Count ) . ToString ( ) ;
2013-03-31 14:09:38 +02:00
}
finally
{
2013-04-06 01:46:28 +02:00
this . gviewRight . EndDataUpdate ( ) ;
this . gviewLeft . EndDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
}
return true ;
}
2016-05-05 03:06:11 +02:00
#endregion
#region SortSelectedChannels ( )
2013-03-31 14:09:38 +02:00
private void SortSelectedChannels ( )
{
2020-02-11 21:06:37 +01:00
var selectedChannels = this . GetSelectedChannels ( this . gviewLeft , true ) ;
2013-03-31 14:09:38 +02:00
if ( selectedChannels . Count = = 0 ) return ;
2013-04-06 01:46:28 +02:00
this . gviewLeft . BeginDataUpdate ( ) ;
this . gviewRight . BeginDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
try
{
2016-05-05 03:06:11 +02:00
this . Editor . SortSelectedChannels ( selectedChannels ) ;
2013-03-31 14:09:38 +02:00
}
finally
{
2013-04-06 01:46:28 +02:00
this . gviewRight . EndDataUpdate ( ) ;
this . gviewLeft . EndDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
}
}
2016-05-05 03:06:11 +02:00
#endregion
#region AddAllUnsortedChannels ( )
2013-04-06 01:46:28 +02:00
private void AddAllUnsortedChannels ( )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
if ( this . CurrentChannelList = = null ) return ;
2013-04-06 01:46:28 +02:00
this . gviewRight . BeginDataUpdate ( ) ;
this . gviewLeft . BeginDataUpdate ( ) ;
2016-05-05 03:06:11 +02:00
var maxNr = this . CurrentChannelList . InsertProgramNumber ;
foreach ( var channel in this . CurrentChannelList . Channels )
2013-07-02 23:55:02 +02:00
maxNr = Math . Max ( maxNr , channel . GetPosition ( this . subListIndex ) ) ;
2016-04-27 19:03:50 +02:00
var max = this . gviewRight . RowCount ;
2016-05-05 03:06:11 +02:00
for ( var handle = 0 ; handle < max ; handle + + )
2013-04-06 01:46:28 +02:00
{
2016-04-27 19:03:50 +02:00
var channel = ( ChannelInfo ) this . gviewRight . GetRow ( handle ) ;
if ( channel ! = null & & channel . GetPosition ( this . subListIndex ) = = - 1 & & ! channel . IsDeleted )
2013-07-02 23:55:02 +02:00
channel . SetPosition ( this . subListIndex , maxNr + + ) ;
2013-04-06 01:46:28 +02:00
}
2016-04-27 19:03:50 +02:00
2013-04-06 01:46:28 +02:00
this . gviewRight . EndDataUpdate ( ) ;
this . gviewLeft . EndDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region RenumberSelectedChannels ( )
2013-03-31 14:09:38 +02:00
private void RenumberSelectedChannels ( )
{
2020-02-11 21:06:37 +01:00
var list = this . GetSelectedChannels ( this . gviewLeft , true ) ;
2013-03-31 14:09:38 +02:00
if ( list . Count = = 0 ) return ;
2013-04-06 01:46:28 +02:00
this . gviewRight . BeginDataUpdate ( ) ;
this . gviewLeft . BeginDataUpdate ( ) ;
2016-05-05 03:06:11 +02:00
this . Editor . RenumberChannels ( list ) ;
2013-04-06 01:46:28 +02:00
this . gviewLeft . EndDataUpdate ( ) ;
this . gviewRight . EndDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region GetSelectedChannels ( )
2020-02-11 21:06:37 +01:00
private List < ChannelInfo > GetSelectedChannels ( GridView gview , bool selectAllIfOnlyOneIsSelected = false )
2013-03-31 14:09:38 +02:00
{
var channels = new List < ChannelInfo > ( ) ;
2020-02-11 21:06:37 +01:00
if ( gview . SelectedRowsCount < = 1 & & selectAllIfOnlyOneIsSelected )
2013-03-31 14:09:38 +02:00
{
2020-02-11 21:06:37 +01:00
for ( int rowHandle = 0 ; rowHandle < gview . RowCount ; rowHandle + + )
channels . Add ( ( ChannelInfo ) gview . GetRow ( rowHandle ) ) ;
}
else
{
foreach ( var rowHandle in gview . GetSelectedRows ( ) )
{
if ( gview . IsDataRow ( rowHandle ) )
channels . Add ( ( ChannelInfo ) gview . GetRow ( rowHandle ) ) ;
}
2013-03-31 14:09:38 +02:00
}
2020-02-11 21:06:37 +01:00
2013-03-31 14:09:38 +02:00
return channels ;
}
2016-05-05 03:06:11 +02:00
#endregion
#region TryExecute ( )
2013-03-31 14:09:38 +02:00
private void TryExecute ( Action action )
{
2016-05-05 03:06:11 +02:00
try
{
action ( ) ;
}
catch ( Exception ex )
{
HandleException ( ex ) ;
}
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region HandleException ( )
2013-03-31 14:09:38 +02:00
public static void HandleException ( Exception ex )
{
XtraMessageBox . Show ( string . Format ( Resources . MainForm_TryExecute_Exception , ex ) ) ;
}
2016-05-05 03:06:11 +02:00
#endregion
#region LoadSettings ( )
2013-05-11 16:45:29 +02:00
2013-03-31 14:09:38 +02:00
private void LoadSettings ( )
{
// note: WindowSize must be restored in ctor in order to make WindowStartPosition.CenterScreen work
2019-07-20 14:54:01 +02:00
if ( ! string . IsNullOrEmpty ( Config . Default . Encoding ) )
this . defaultEncoding = Encoding . GetEncoding ( Config . Default . Encoding ) ;
2016-05-05 03:06:11 +02:00
2019-07-20 14:54:01 +02:00
var width = Config . Default . LeftPanelWidth ;
2013-03-31 14:09:38 +02:00
if ( width > 0 )
2020-05-02 19:04:43 +02:00
this . splitContainerControl1 . SplitterPosition = width ; // set unscaled value because the whole Form will be scaled later
2013-03-31 14:09:38 +02:00
this . SelectLanguageMenuItem ( ) ;
2019-07-20 14:54:01 +02:00
//this.SetGridLayout(this.gviewLeft, Config.Default.OutputListLayout);
2013-03-31 14:09:38 +02:00
2019-07-20 14:54:01 +02:00
this . miShowWarningsAfterLoad . Checked = Config . Default . ShowWarningsAfterLoading ;
this . cbCloseGap . Checked = Config . Default . CloseGaps ;
2013-03-31 14:09:38 +02:00
this . ClearLeftFilter ( ) ;
2013-07-02 23:55:02 +02:00
this . ClearRightFilter ( ) ;
2019-08-05 23:50:53 +02:00
this . mruFiles . Clear ( ) ;
this . mruFiles . AddRange ( Config . Default . MruFiles ) ;
2013-05-11 16:45:29 +02:00
this . UpdateMruMenu ( ) ;
2019-07-13 12:59:51 +02:00
2019-07-20 14:54:01 +02:00
this . miExplorerIntegration . Down = Config . Default . ExplorerIntegration ;
this . miCheckUpdates . Down = Config . Default . CheckForUpdates ;
2020-05-02 19:04:43 +02:00
foreach ( var mi in new [ ] { miFontSmall , miFontMedium , miFontLarge , miFontXLarge , miFontXxLarge } )
{
if ( ( int ) mi . Tag = = Config . Default . FontSizeDelta )
{
mi . Down = true ;
break ;
}
}
2020-07-12 02:39:43 +02:00
if ( Config . Default . LeftGridLayout ! = null )
{
var xml = Config . Default . LeftGridLayout ;
this . gviewLeft . LoadLayoutFromXml ( xml ) ;
}
if ( Config . Default . RightGridLayout ! = null )
{
var xml = Config . Default . RightGridLayout ;
this . gviewRight . LoadLayoutFromXml ( xml ) ;
}
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region SelectLanguageMenuItem ( )
2013-03-31 14:09:38 +02:00
private void SelectLanguageMenuItem ( )
{
this . barManager1 . ForceLinkCreate ( ) ;
foreach ( BarItemLink itemLink in this . barSubItem1 . ItemLinks )
{
2019-07-20 14:54:01 +02:00
if ( Config . Default . Language . StartsWith ( ( string ) itemLink . Item . Tag ) )
2013-03-31 14:09:38 +02:00
{
this . ignoreLanguageChange = true ;
( ( BarButtonItem ) itemLink . Item ) . Down = true ;
this . ignoreLanguageChange = false ;
break ;
}
}
}
2016-05-05 03:06:11 +02:00
#endregion
#region SetGridLayout ( )
2013-03-31 14:09:38 +02:00
private void SetGridLayout ( GridView grid , string layout )
{
if ( string . IsNullOrEmpty ( layout ) ) return ;
2016-05-05 03:06:11 +02:00
var stream = new MemoryStream ( ) ;
using ( var wrt = new StreamWriter ( stream ) )
2013-03-31 14:09:38 +02:00
{
wrt . Write ( layout ) ;
wrt . Flush ( ) ;
stream . Seek ( 0 , SeekOrigin . Begin ) ;
2016-05-05 03:06:11 +02:00
var options = new OptionsLayoutGrid ( ) ;
2013-04-06 01:46:28 +02:00
options . StoreDataSettings = true ;
options . StoreAppearance = false ;
options . StoreVisualOptions = false ;
grid . RestoreLayoutFromStream ( stream , options ) ;
2013-03-31 14:09:38 +02:00
}
// put the filter text back into the auto-filter-row
foreach ( GridColumn col in grid . Columns )
{
2016-05-05 03:06:11 +02:00
var parts = ( col . FilterInfo . FilterString ? ? "" ) . Split ( '\'' ) ;
2013-03-31 14:09:38 +02:00
if ( parts . Length > = 2 )
2013-04-06 01:46:28 +02:00
this . gviewRight . SetRowCellValue ( GridControl . AutoFilterRowHandle , col , parts [ 1 ] ) ;
2013-03-31 14:09:38 +02:00
}
}
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#region UpdateInsertSlotNumber ( )
2013-03-31 14:09:38 +02:00
2013-07-02 23:55:02 +02:00
private void UpdateInsertSlotNumber ( )
{
2020-05-02 19:04:43 +02:00
if ( this . subListIndex < 0 )
return ;
2016-05-05 03:06:11 +02:00
var channel = ( ChannelInfo ) this . gviewLeft . GetFocusedRow ( ) ;
2013-07-02 23:55:02 +02:00
int programNr ;
if ( channel = = null )
2016-05-05 03:06:11 +02:00
programNr = this . CurrentChannelList = = null ? 1 : this . CurrentChannelList . FirstProgramNumber ;
2013-07-02 23:55:02 +02:00
else
{
programNr = channel . GetPosition ( this . subListIndex ) ;
if ( this . rbInsertAfter . Checked )
+ + programNr ;
}
2016-05-05 03:06:11 +02:00
if ( this . CurrentChannelList ! = null )
this . CurrentChannelList . InsertProgramNumber = programNr ;
2013-07-02 23:55:02 +02:00
this . UpdateInsertSlotTextBox ( ) ;
this . gviewLeft . SelectRow ( this . gviewLeft . FocusedRowHandle ) ;
}
2016-05-05 03:06:11 +02:00
#endregion
#region UpdateInsertSlotTextBox ( )
2013-03-31 14:09:38 +02:00
private void UpdateInsertSlotTextBox ( )
{
2016-05-05 03:06:11 +02:00
var programNr = this . CurrentChannelList = = null ? 0 : this . CurrentChannelList . InsertProgramNumber ;
2013-03-31 14:09:38 +02:00
this . txtSetSlot . Text = programNr . ToString ( ) ;
}
2016-05-05 03:06:11 +02:00
#endregion
#region FillMenuWithIsoEncodings ( )
2013-03-31 14:09:38 +02:00
private void FillMenuWithIsoEncodings ( )
{
this . miIsoCharSets . Strings . Clear ( ) ;
this . isoEncodings . Clear ( ) ;
2016-05-05 03:06:11 +02:00
foreach ( var encoding in Encoding . GetEncodings ( ) )
2013-03-31 14:09:38 +02:00
{
if ( ! encoding . Name . StartsWith ( "iso" ) )
continue ;
this . miIsoCharSets . Strings . Add ( encoding . DisplayName ) ;
this . isoEncodings . Add ( encoding . Name ) ;
}
}
2016-05-05 03:06:11 +02:00
#endregion
#region ShowCharsetForm ( )
2013-03-31 14:09:38 +02:00
private void ShowCharsetForm ( )
{
using ( var form = new CharsetForm ( this . defaultEncoding ) )
{
form . Location = new Point ( this . Location . X + 30 , this . Location . Y + 70 ) ;
form . EncodingChanged + = this . charsetForm_EncodingChanged ;
form . ShowDialog ( this ) ;
}
}
2016-05-05 03:06:11 +02:00
#endregion
#region SetDefaultEncoding ( )
2013-03-31 14:09:38 +02:00
private void SetDefaultEncoding ( Encoding encoding )
{
this . defaultEncoding = encoding ;
if ( this . currentTvSerializer = = null )
return ;
2013-04-06 01:46:28 +02:00
this . gviewRight . BeginDataUpdate ( ) ;
this . gviewLeft . BeginDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
this . currentTvSerializer . DefaultEncoding = encoding ;
2013-04-06 01:46:28 +02:00
this . gviewRight . EndDataUpdate ( ) ;
this . gviewLeft . EndDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#region LoadInputGridLayout ( )
2013-03-31 14:09:38 +02:00
2016-04-27 19:03:50 +02:00
private void LoadInputGridLayout ( )
2013-03-31 14:09:38 +02:00
{
2016-04-27 19:03:50 +02:00
this . ShowGridColumns ( this . gviewLeft ) ;
this . ShowGridColumns ( this . gviewRight ) ;
2013-03-31 14:09:38 +02:00
this . ClearRightFilter ( ) ;
}
2016-05-05 03:06:11 +02:00
#endregion
#region ShowGridColumns ( )
2020-07-12 02:39:43 +02:00
private void ShowGridColumns ( XGridView gview )
2016-04-27 19:03:50 +02:00
{
foreach ( GridColumn col in gview . Columns )
2020-07-12 02:39:43 +02:00
gview . SetColumnVisibility ( col , GetGridColumnVisibility ( col ) ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region GetGridColumnVisibility ( )
2013-03-31 14:09:38 +02:00
2016-04-27 19:03:50 +02:00
private bool GetGridColumnVisibility ( GridColumn col )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
var list = this . CurrentChannelList ;
2017-11-16 12:05:02 +01:00
if ( list = = null )
return false ;
2019-02-10 15:56:03 +01:00
2019-11-10 20:09:27 +01:00
if ( list . IsMixedSourceFavoritesList )
{
if ( col = = this . colSource | | col = = this . colOutSource ) return true ;
if ( col = = this . colOutHide | | col = = this . colOutLock | | col = = this . colOutSkip ) return false ;
}
2015-09-24 12:46:52 +02:00
var filter = list . VisibleColumnFieldNames ;
2019-02-10 15:56:03 +01:00
if ( filter ! = null )
{
if ( filter . Contains ( "+" + col . FieldName ) ) // force-show without further checks
return true ;
2019-11-24 20:00:48 +01:00
if ( filter . Contains ( "-" + col . FieldName ) | | ! filter . Contains ( col . FieldName ) ) // force-hide without further checks
2019-08-29 16:57:20 +02:00
return false ;
2019-02-10 15:56:03 +01:00
}
else if ( col . Tag is bool originalVisible & & ! originalVisible )
2015-09-24 12:46:52 +02:00
return false ;
var source = list . SignalSource ;
2020-08-27 12:48:37 +02:00
if ( col = = this . colFavorites ) return this . DataRoot . SupportedFavorites ! = 0 ;
if ( col = = this . colOutFav ) return this . DataRoot . SupportedFavorites ! = 0 ;
2016-04-27 19:03:50 +02:00
if ( col = = this . colPrNr ) return this . subListIndex > 0 ;
2013-05-16 21:06:44 +02:00
if ( col = = this . colChannelOrTransponder ) return ( source & SignalSource . Sat ) = = 0 ;
2013-03-31 14:09:38 +02:00
if ( col = = this . colShortName ) return ( source & SignalSource . Digital ) ! = 0 ;
if ( col = = this . colEncrypted ) return ( source & SignalSource . Digital ) ! = 0 ;
if ( col = = this . colServiceId ) return ( source & SignalSource . Digital ) ! = 0 ;
2019-02-10 15:56:03 +01:00
if ( col = = this . colPcrPid ) return ( source & SignalSource . Digital ) ! = 0 ;
2013-03-31 14:09:38 +02:00
if ( col = = this . colVideoPid ) return ( source & SignalSource . Digital ) ! = 0 ;
if ( col = = this . colAudioPid ) return ( source & SignalSource . Digital ) ! = 0 ;
2016-05-06 02:30:46 +02:00
//if (col == this.colServiceType) return (source & SignalSource.Digital) != 0;
2013-03-31 14:09:38 +02:00
if ( col = = this . colServiceTypeName ) return ( source & SignalSource . Digital ) ! = 0 ;
if ( col = = this . colTransportStreamId ) return ( source & SignalSource . Digital ) ! = 0 ;
if ( col = = this . colNetworkName ) return ( source & SignalSource . Digital ) ! = 0 ;
if ( col = = this . colNetworkOperator ) return ( source & SignalSource . Digital ) ! = 0 ;
2014-01-19 19:08:17 +01:00
if ( col = = this . colProvider ) return ( source & SignalSource . Digital ) ! = 0 ;
2013-03-31 14:09:38 +02:00
if ( col = = this . colSatellite ) return ( source & SignalSource . Sat ) ! = 0 ;
if ( col = = this . colNetworkId ) return ( source & SignalSource . Digital ) ! = 0 ;
2019-02-10 15:56:03 +01:00
if ( col = = this . colSymbolRate ) return ( source & SignalSource . Digital ) ! = 0 ;
2019-11-24 20:00:48 +01:00
if ( col = = this . colSkip ) return ( source & SignalSource . Digital ) ! = 0 & & this . DataRoot . CanSkip ;
if ( col = = this . colLock ) return ( source & SignalSource . Digital ) ! = 0 & & this . DataRoot . CanLock ;
if ( col = = this . colHidden ) return ( source & SignalSource . Digital ) ! = 0 & & this . DataRoot . CanHide ;
2013-03-31 14:09:38 +02:00
if ( col = = this . colIndex ) return col . Visible ;
if ( col = = this . colUid ) return col . Visible ;
2019-02-10 15:56:03 +01:00
if ( col = = this . colDebug ) return col . Visible ;
2013-04-21 22:04:06 +02:00
if ( col = = this . colSignalSource ) return col . Visible ;
2019-02-10 15:56:03 +01:00
if ( col = = this . colLogicalIndex ) return col . Visible ;
2020-01-02 11:48:00 +01:00
if ( col = = this . colPolarity ) return ( source & SignalSource . Sat ) ! = 0 | | ( source & SignalSource . IP ) ! = 0 ;
2013-03-31 14:09:38 +02:00
2019-02-10 15:56:03 +01:00
return true ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region SetFavorite ( )
2013-03-31 14:09:38 +02:00
private void SetFavorite ( string fav , bool set )
{
if ( string . IsNullOrEmpty ( fav ) ) return ;
2019-08-13 13:29:59 +02:00
int idx = char . ToUpper ( fav [ 0 ] ) - 'A' ;
if ( idx < 0 | | idx > = this . mnuFavSet . ItemLinks . Count | | this . subListIndex = = idx + 1 ) return ;
2013-03-31 14:09:38 +02:00
var list = this . GetSelectedChannels ( this . lastFocusedGrid ) ;
if ( list . Count = = 0 ) return ;
2013-04-06 01:46:28 +02:00
this . gviewRight . BeginDataUpdate ( ) ;
this . gviewLeft . BeginDataUpdate ( ) ;
2020-02-11 21:06:37 +01:00
this . Editor . SetFavorites ( list , idx , set ) ;
2013-04-06 01:46:28 +02:00
this . gviewRight . EndDataUpdate ( ) ;
this . gviewLeft . EndDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region SetChannelFlag ( )
2013-03-31 14:09:38 +02:00
private void SetChannelFlag ( Action < ChannelInfo > setFlag )
{
var list = this . GetSelectedChannels ( this . lastFocusedGrid ) ;
if ( list . Count = = 0 ) return ;
2013-04-06 01:46:28 +02:00
this . gviewRight . BeginDataUpdate ( ) ;
this . gviewLeft . BeginDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
foreach ( var channel in list )
setFlag ( channel ) ;
2013-04-06 01:46:28 +02:00
this . gviewRight . EndDataUpdate ( ) ;
this . gviewLeft . EndDataUpdate ( ) ;
2016-05-05 03:06:11 +02:00
this . DataRoot . NeedsSaving = true ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region NavigateToChannel
2013-03-31 14:09:38 +02:00
private void NavigateToChannel ( ChannelInfo channel , GridView view )
{
if ( channel = = null ) return ;
2016-05-05 03:06:11 +02:00
var rowHandle = view . GetRowHandle ( this . CurrentChannelList . Channels . IndexOf ( channel ) ) ;
2013-03-31 14:09:38 +02:00
if ( view . IsValidRowHandle ( rowHandle ) )
{
2013-04-06 01:46:28 +02:00
this . SelectFocusedRow ( view , rowHandle ) ;
2013-03-31 14:09:38 +02:00
view . MakeRowVisible ( rowHandle ) ;
}
}
2016-05-05 03:06:11 +02:00
#endregion
#region SetActiveGrid ( )
2013-04-06 01:46:28 +02:00
private void SetActiveGrid ( GridView grid )
{
if ( grid = = this . gviewLeft )
{
this . grpOutputList . AppearanceCaption . ForeColor = Color . DodgerBlue ;
this . grpOutputList . AppearanceCaption . Options . UseForeColor = true ;
this . grpInputList . AppearanceCaption . Options . UseForeColor = false ;
this . lastFocusedGrid = this . gviewLeft ;
}
else
{
this . grpInputList . AppearanceCaption . ForeColor = Color . DodgerBlue ;
this . grpInputList . AppearanceCaption . Options . UseForeColor = true ;
this . grpOutputList . AppearanceCaption . Options . UseForeColor = false ;
this . lastFocusedGrid = this . gviewRight ;
}
this . UpdateMenu ( ) ;
}
2016-05-05 03:06:11 +02:00
#endregion
#region UpdateMenu
2019-11-17 14:56:19 +01:00
private void UpdateMenu ( bool afterFileLoad = false )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
var fileLoaded = this . DataRoot ! = null ;
var isRight = this . lastFocusedGrid = = this . gviewRight ;
var mayEdit = fileLoaded & & this . CurrentChannelList ! = null & & ( ! this . CurrentChannelList . ReadOnly | | this . miAllowEditPredefinedLists . Down ) ;
2013-05-16 21:06:44 +02:00
foreach ( BarItemLink link in this . miEdit . ItemLinks )
link . Item . Enabled = mayEdit ;
this . btnAdd . Enabled = mayEdit ;
this . btnAddAll . Enabled = mayEdit ;
this . btnRemoveLeft . Enabled = mayEdit ;
this . btnRemoveRight . Enabled = mayEdit ;
this . btnRenum . Enabled = mayEdit ;
2016-05-05 03:06:11 +02:00
this . btnToggleFavA . Enabled = mayEdit & & ( this . DataRoot . SupportedFavorites & Favorites . A ) ! = 0 & & this . subListIndex ! = 1 ;
this . btnToggleFavB . Enabled = mayEdit & & ( this . DataRoot . SupportedFavorites & Favorites . B ) ! = 0 & & this . subListIndex ! = 2 ;
this . btnToggleFavC . Enabled = mayEdit & & ( this . DataRoot . SupportedFavorites & Favorites . C ) ! = 0 & & this . subListIndex ! = 3 ;
this . btnToggleFavD . Enabled = mayEdit & & ( this . DataRoot . SupportedFavorites & Favorites . D ) ! = 0 & & this . subListIndex ! = 4 ;
this . btnToggleFavE . Enabled = mayEdit & & ( this . DataRoot . SupportedFavorites & Favorites . E ) ! = 0 & & this . subListIndex ! = 5 ;
2019-08-13 13:29:59 +02:00
this . btnToggleFavF . Enabled = mayEdit & & ( this . DataRoot . SupportedFavorites & Favorites . F ) ! = 0 & & this . subListIndex ! = 6 ;
this . btnToggleFavG . Enabled = mayEdit & & ( this . DataRoot . SupportedFavorites & Favorites . G ) ! = 0 & & this . subListIndex ! = 7 ;
this . btnToggleFavH . Enabled = mayEdit & & ( this . DataRoot . SupportedFavorites & Favorites . H ) ! = 0 & & this . subListIndex ! = 8 ;
2020-01-02 11:48:00 +01:00
this . btnToggleLock . Enabled = mayEdit & & this . DataRoot . CanLock ;
2013-05-11 16:45:29 +02:00
2019-11-17 14:56:19 +01:00
if ( afterFileLoad )
{
// this block may contain some time-expensive checks that only need to be done after loading a file
this . miReload . Enabled = fileLoaded ;
this . miFileInformation . Enabled = fileLoaded ;
this . miRestoreOriginal . Enabled = fileLoaded & & this . GetPathOfMissingBackupFile ( ) = = null ;
this . miSave . Enabled = fileLoaded ;
this . miSaveAs . Enabled = fileLoaded & & this . currentTvSerializer . Features . CanSaveAs ;
this . miOpenReferenceFile . Enabled = fileLoaded ;
this . miSaveReferenceFile . Enabled = fileLoaded ;
this . miExcelExport . Enabled = fileLoaded ;
this . miPrint . Enabled = fileLoaded ;
}
2013-05-11 16:45:29 +02:00
2019-08-13 13:29:59 +02:00
this . miAddChannel . Enabled = fileLoaded & & isRight ;
2013-03-31 14:09:38 +02:00
var visRight = isRight ? BarItemVisibility . Always : BarItemVisibility . Never ;
var visLeft = isRight ? BarItemVisibility . Never : BarItemVisibility . Always ;
this . miSort . Visibility = visLeft ;
this . miRenum . Visibility = visLeft ;
this . miMoveUp . Visibility = visLeft ;
this . miMoveDown . Visibility = visLeft ;
this . miAddChannel . Visibility = visRight ;
2016-04-20 00:33:47 +02:00
this . miSkipOn . Enabled = this . miSkipOff . Enabled = this . currentTvSerializer ? . Features . CanSkipChannels ? ? false ;
2019-11-24 20:00:48 +01:00
this . miLockOn . Enabled = this . miLockOff . Enabled = this . currentTvSerializer ? . Features . CanLockChannels ? ? false ;
this . miHideOn . Enabled = this . miHideOff . Enabled = this . currentTvSerializer ? . Features . CanHideChannels ? ? false ;
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
var isLeftGridSortedByNewProgNr = this . IsLeftGridSortedByNewProgNr ;
2013-04-06 01:46:28 +02:00
var sel = this . gviewLeft . GetSelectedRows ( ) ;
2014-01-19 19:08:17 +01:00
var channel = sel . Length = = 0 ? null : ( ChannelInfo ) this . gviewLeft . GetRow ( sel [ 0 ] ) ;
2020-05-02 19:04:43 +02:00
this . miMoveUp . Enabled = this . btnUp . Enabled = mayEdit & & this . subListIndex > = 0 & & isLeftGridSortedByNewProgNr & & channel ! = null
2016-05-05 03:06:11 +02:00
& & channel . GetPosition ( this . subListIndex ) > this . CurrentChannelList . FirstProgramNumber ;
2013-06-23 14:58:44 +02:00
this . miMoveDown . Enabled = this . btnDown . Enabled = mayEdit & & isLeftGridSortedByNewProgNr ;
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
this . miTvSettings . Enabled = this . currentTvSerializer ! = null & & this . currentTvSerializer . Features . DeviceSettings ;
2013-11-09 16:30:59 +01:00
this . miCleanupChannels . Enabled = this . currentTvSerializer ! = null & & this . currentTvSerializer . Features . CleanUpChannelData ;
2013-08-19 13:49:30 +02:00
2014-07-11 10:07:33 +02:00
this . mnuFavList . Enabled = this . grpSubList . Visible ;
2013-08-19 13:49:30 +02:00
this . txtSetSlot . Enabled = mayEdit ;
2013-05-11 16:45:29 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region UpdateMruMenu ( )
2013-05-11 16:45:29 +02:00
private void UpdateMruMenu ( )
{
this . miRecentFiles . Strings . Clear ( ) ;
foreach ( var file in this . mruFiles )
{
var key = Path . GetFileName ( Path . GetDirectoryName ( file ) ) + "\\" + Path . GetFileName ( file ) ;
if ( key ! = file )
key = "...\\" + key ;
2016-05-05 03:06:11 +02:00
this . miRecentFiles . Strings . Add ( key ) ;
2013-05-11 16:45:29 +02:00
}
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2019-11-17 14:56:19 +01:00
#region GetPathOfMissingBackupFile ( )
/// <summary>
/// If any backup file exists, return NULL. Otherwise the name of any expected .bak file (in case the loader has multiple data files)
/// </summary>
/// <returns></returns>
private string GetPathOfMissingBackupFile ( )
{
var files = this . currentTvSerializer . GetDataFilePaths ( ) . ToList ( ) ;
string bakFile = null ;
foreach ( var dataFilePath in files )
{
bakFile = dataFilePath + ".bak" ;
if ( File . Exists ( bakFile ) )
return null ;
}
return bakFile ;
}
#endregion
2016-05-05 03:06:11 +02:00
#region RestoreBackupFile ( )
2013-03-31 14:09:38 +02:00
private void RestoreBackupFile ( )
{
2019-11-17 14:56:19 +01:00
var bakFile = this . GetPathOfMissingBackupFile ( ) ;
if ( bakFile ! = null )
2013-03-31 14:09:38 +02:00
{
XtraMessageBox . Show ( this , string . Format ( Resources . MainForm_miRestoreOriginal_ItemClick_NoBackup , bakFile ) ,
this . miRestoreOriginal . Caption ,
MessageBoxButtons . OK , MessageBoxIcon . Exclamation ) ;
return ;
}
if ( XtraMessageBox . Show ( this ,
2016-05-05 03:06:11 +02:00
Resources . MainForm_miRestoreOriginal_ItemClick_Confirm ,
this . miRestoreOriginal . Caption ,
MessageBoxButtons . YesNo , MessageBoxIcon . Question , MessageBoxDefaultButton . Button2 ) ! =
2013-03-31 14:09:38 +02:00
DialogResult . Yes )
{
return ;
}
2021-01-02 13:18:37 +01:00
foreach ( var dataFilePath in this . currentTvSerializer . GetDataFilePaths ( ) )
2013-03-31 14:09:38 +02:00
{
2021-01-02 13:18:37 +01:00
bakFile = dataFilePath + ".bak" ;
try
2019-11-17 14:56:19 +01:00
{
File . Copy ( bakFile , dataFilePath , true ) ;
var attr = File . GetAttributes ( dataFilePath ) ;
File . SetAttributes ( dataFilePath , attr & ~ FileAttributes . ReadOnly ) ;
}
2021-01-02 13:18:37 +01:00
catch ( Exception )
{
XtraMessageBox . Show ( this , string . Format ( Resources . MainForm_miRestoreOriginal_Message , dataFilePath ) ,
this . miRestoreOriginal . Caption ,
MessageBoxButtons . OK , MessageBoxIcon . Exclamation ) ;
}
2016-05-05 03:06:11 +02:00
}
2021-01-02 13:18:37 +01:00
this . currentTvSerializer . DataRoot . NeedsSaving = false ;
if ( this . currentPlugin ! = null )
this . LoadFiles ( this . currentPlugin , this . currentTvFile ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region ShowFileInformation ( )
2013-03-31 14:09:38 +02:00
private void ShowFileInformation ( )
{
if ( this . currentTvSerializer = = null )
return ;
var info = this . currentTvSerializer . GetFileInformation ( ) ;
2013-04-21 22:04:06 +02:00
2016-05-05 03:06:11 +02:00
if ( this . DataRoot . Warnings . Length > 0 )
2013-04-21 22:04:06 +02:00
{
2016-05-05 03:06:11 +02:00
var lines = this . DataRoot . Warnings . ToString ( ) . Split ( '\n' ) ;
2013-04-21 22:04:06 +02:00
Array . Sort ( lines ) ;
2016-05-05 03:06:11 +02:00
var sortedWarnings = string . Join ( "\n" , lines ) ;
2013-04-28 12:44:40 +02:00
info + = "\r\n\r\n\r\n" + Resources . MainForm_LoadFiles_ValidationWarningMsg + "\r\n\r\n" + sortedWarnings ;
2013-04-21 22:04:06 +02:00
}
2016-05-05 03:06:11 +02:00
InfoBox . Show ( this , info , this . miFileInformation . Caption . Replace ( "..." , "" ) . Replace ( "&" , "" ) ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region VerifyChannelNameModified ( )
2013-03-31 14:09:38 +02:00
private void VerifyChannelNameModified ( ChannelInfo info , string newName )
{
if ( newName ! = info . Name )
info . IsNameModified = true ;
}
2016-04-27 01:58:38 +02:00
2016-05-05 03:06:11 +02:00
#endregion
2016-04-27 01:58:38 +02:00
2016-05-05 03:06:11 +02:00
#region ShowTvCountrySettings ( )
2013-04-03 18:44:54 +02:00
2013-03-31 14:09:38 +02:00
private void ShowTvCountrySettings ( )
{
if ( this . currentTvSerializer ! = null )
this . currentTvSerializer . ShowDeviceSettingsForm ( this ) ;
}
2016-05-05 03:06:11 +02:00
#endregion
#region ToggleFavorite ( )
2013-04-06 01:46:28 +02:00
private void ToggleFavorite ( string fav )
{
var list = this . GetSelectedChannels ( this . gviewLeft ) ;
if ( list . Count = = 0 ) return ;
2016-05-05 03:06:11 +02:00
var value = ( Favorites ) Enum . Parse ( typeof ( Favorites ) , fav ) ;
this . SetFavorite ( fav , ( list [ 0 ] . Favorites & value ) = = 0 ) ;
2013-04-06 01:46:28 +02:00
this . RefreshGrid ( gviewLeft , gviewRight ) ;
}
2016-05-05 03:06:11 +02:00
#endregion
#region ToggleLock ( )
2013-04-06 01:46:28 +02:00
private void ToggleLock ( )
{
var list = this . GetSelectedChannels ( this . gviewLeft ) ;
if ( list . Count = = 0 ) return ;
2016-05-05 03:06:11 +02:00
var setLock = ! list [ 0 ] . Lock ;
2013-04-06 01:46:28 +02:00
foreach ( var channel in list )
channel . Lock = setLock ;
this . RefreshGrid ( gviewLeft , gviewRight ) ;
}
2016-05-05 03:06:11 +02:00
#endregion
#region RenameChannel ( )
2013-04-21 22:04:06 +02:00
private void RenameChannel ( )
{
if ( this . lastFocusedGrid = = null ) return ;
if ( this . lastFocusedGrid = = this . gviewLeft )
this . gviewLeft . FocusedColumn = this . colOutName ;
else
this . gviewRight . FocusedColumn = this . colName ;
this . dontOpenEditor = false ;
this . lastFocusedGrid . ShowEditor ( ) ;
}
2016-05-05 03:06:11 +02:00
#endregion
#region CleanupChannelData ( )
2013-04-29 00:35:40 +02:00
private void CleanupChannelData ( )
{
if ( this . currentTvSerializer ! = null & & this . currentTvSerializer . Features . CleanUpChannelData )
{
var msg = this . currentTvSerializer . CleanUpChannelData ( ) ;
2017-06-08 20:01:42 +02:00
this . FillChannelListTabs ( ) ;
2013-04-29 00:35:40 +02:00
InfoBox . Show ( this , msg , this . miCleanupChannels . Caption ) ;
this . RefreshGrid ( gviewLeft , gviewRight ) ;
}
}
2016-05-05 03:06:11 +02:00
#endregion
#region ExportExcelList ( )
2013-05-11 16:45:29 +02:00
private void ExportExcelList ( )
{
const string header = "List;Pr#;Channel Name;Favorites;Lock;Skip;Hide;Encrypted;Satellite;Ch/Tp;Freq;ONID;TSID;SymRate;SID;VPID;APID" ;
const char sep = '\t' ;
var sb = new StringBuilder ( ) ;
sb . AppendLine ( header . Replace ( ';' , sep ) ) ;
2016-05-05 03:06:11 +02:00
foreach ( var list in this . DataRoot . ChannelLists )
2013-05-11 16:45:29 +02:00
{
foreach ( var channel in list . Channels . OrderBy ( c = > c . NewProgramNr ) )
{
2017-11-30 14:50:22 +01:00
if ( channel . IsDeleted | | channel . NewProgramNr = = - 1 )
2013-05-11 16:45:29 +02:00
continue ;
sb . Append ( list . ShortCaption ) . Append ( sep ) ;
sb . Append ( channel . NewProgramNr ) . Append ( sep ) ;
sb . Append ( '"' ) . Append ( channel . Name ) . Append ( '"' ) . Append ( sep ) ;
sb . Append ( channel . Favorites ) . Append ( sep ) ;
sb . Append ( channel . Lock ? "L" : "" ) . Append ( sep ) ;
sb . Append ( channel . Skip ? "S" : "" ) . Append ( sep ) ;
sb . Append ( channel . Hidden ? "H" : "" ) . Append ( sep ) ;
sb . Append ( channel . Encrypted = = null ? "?" : channel . Encrypted . Value ? "C" : "" ) . Append ( sep ) ;
sb . Append ( '"' ) . Append ( channel . Satellite ) . Append ( '"' ) . Append ( sep ) ;
sb . Append ( channel . ChannelOrTransponder ) . Append ( sep ) ;
sb . Append ( channel . FreqInMhz ) . Append ( sep ) ;
sb . Append ( channel . OriginalNetworkId ) . Append ( sep ) ;
sb . Append ( channel . TransportStreamId ) . Append ( sep ) ;
sb . Append ( channel . SymbolRate ) . Append ( sep ) ;
sb . Append ( channel . ServiceId ) . Append ( sep ) ;
sb . Append ( channel . VideoPid ) . Append ( sep ) ;
sb . Append ( channel . AudioPid ) ;
2016-05-05 03:06:11 +02:00
2013-05-11 16:45:29 +02:00
sb . AppendLine ( ) ;
}
}
Clipboard . Clear ( ) ;
Clipboard . SetData ( DataFormats . Text , sb . ToString ( ) ) ;
2016-05-05 03:06:11 +02:00
XtraMessageBox . Show ( this ,
Resources . MainForm_ExportExcelList_Message ,
this . miExcelExport . Caption ,
MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
2014-07-08 22:16:16 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2014-07-08 22:16:16 +02:00
2016-05-05 03:06:11 +02:00
#region Print ( )
2014-07-08 22:16:16 +02:00
2016-05-05 03:06:11 +02:00
private void Print ( )
2014-07-08 22:16:16 +02:00
{
2016-05-05 03:06:11 +02:00
using ( var dlg = new ReportOptionsDialog ( this . CurrentChannelList , this . subListIndex ) )
dlg . ShowDialog ( this ) ;
2014-07-08 22:16:16 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2014-07-08 22:16:16 +02:00
2019-08-13 13:29:59 +02:00
#region GetFavString ( )
private string GetFavString ( Favorites fav )
{
if ( fav = = 0 )
return string . Empty ;
var sb = new StringBuilder ( ) ;
int i = 0 ;
for ( var mask = ( int ) fav ; mask ! = 0 ; mask > > = 1 )
{
if ( ( mask & 1 ) ! = 0 )
sb . Append ( ( char ) ( 'A' + i ) ) ;
+ + i ;
}
return sb . ToString ( ) ;
}
#endregion
2013-03-31 14:09:38 +02:00
// UI events
2016-05-05 03:06:11 +02:00
#region MainForm_Load
2013-03-31 14:09:38 +02:00
private void MainForm_Load ( object sender , EventArgs e )
{
2013-04-08 10:08:49 +02:00
this . TryExecute ( this . LoadSettings ) ;
this . TryExecute ( this . InitAppAfterMainWindowWasShown ) ;
2019-07-13 12:59:51 +02:00
var args = Environment . GetCommandLineArgs ( ) ;
if ( args . Length > 1 )
this . TryExecute ( ( ) = > this . LoadFiles ( null , args [ args . Length - 1 ] ) ) ;
}
#endregion
#region MainForm_DragEnter , DragDrop
private void MainForm_DragEnter ( object sender , DragEventArgs e )
{
e . Effect = DragDropEffects . None ;
if ( e . Data . GetDataPresent ( "FileNameW" ) )
{
if ( e . Data . GetData ( "FileNameW" ) is string [ ] files & & files . Length = = 1 )
e . Effect = DragDropEffects . Copy ;
}
2013-03-31 14:09:38 +02:00
}
2019-07-13 12:59:51 +02:00
private void MainForm_DragDrop ( object sender , DragEventArgs e )
{
try
{
if ( e . Data . GetDataPresent ( "FileNameW" ) )
{
if ( e . Data . GetData ( "FileNameW" ) is string [ ] files & & files . Length = = 1 )
this . LoadFiles ( null , files [ 0 ] ) ;
}
}
catch ( Exception ex )
{
HandleException ( ex ) ;
}
}
2016-05-05 03:06:11 +02:00
#endregion
#region ProcessCmdKey ( )
2014-07-08 22:16:16 +02:00
protected override bool ProcessCmdKey ( ref Message msg , Keys keyData )
{
2014-07-11 10:07:33 +02:00
if ( keyData = = Keys . F1 )
2014-07-08 22:16:16 +02:00
{
2014-07-11 10:07:33 +02:00
this . popupInputSource . ShowPopup ( this . tabChannelList . PointToScreen ( new Point ( 0 , this . tabChannelList . Height ) ) ) ;
2014-07-08 22:16:16 +02:00
return true ;
}
2014-07-11 10:07:33 +02:00
if ( keyData = = ( Keys . F1 | Keys . Shift ) )
2014-07-08 22:16:16 +02:00
{
2014-07-11 10:07:33 +02:00
this . popupFavList . ShowPopup ( this . tabSubList . PointToScreen ( new Point ( 0 , this . tabSubList . Height ) ) ) ;
2014-07-08 22:16:16 +02:00
return true ;
}
return base . ProcessCmdKey ( ref msg , keyData ) ;
}
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2020-05-02 19:04:43 +02:00
#region OnDpiChanged , OnScaleControl
protected override void OnDpiChanged ( DpiChangedEventArgs e )
{
GlobalImageCollection . Scale ( ( float ) e . DeviceDpiNew / e . DeviceDpiOld , true ) ;
base . OnDpiChanged ( e ) ;
}
2013-03-31 14:09:38 +02:00
2020-05-02 19:04:43 +02:00
protected override void OnScaleControl ( )
2013-03-31 14:09:38 +02:00
{
2020-05-02 19:04:43 +02:00
this . absScaleFactor = absScaleFactor . Scale ( this . AutoScaleFactor ) ;
GlobalImageCollection . Scale ( this . AutoScaleFactor . Height , true ) ;
base . OnScaleControl ( ) ;
2013-07-19 17:27:02 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2020-05-02 19:04:43 +02:00
2016-05-05 03:06:11 +02:00
// -- controls
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#region picDonate_Click
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
private void picDonate_Click ( object sender , EventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
BrowserHelper . OpenHtml ( Resources . paypal_button ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#region tabChannelList_SelectedPageChanged
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
private void tabChannelList_SelectedPageChanged ( object sender , TabPageChangedEventArgs e )
2013-05-05 22:40:57 +02:00
{
2016-05-05 03:06:11 +02:00
this . TryExecute ( ( ) = > ShowChannelList ( e . Page = = null ? null : ( ChannelList ) e . Page . Tag ) ) ;
2013-05-05 22:40:57 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2013-05-11 16:45:29 +02:00
2016-05-05 03:06:11 +02:00
#region tabSubList_SelectedPageChanged
2013-11-23 15:09:20 +01:00
2016-05-05 03:06:11 +02:00
private void tabSubList_SelectedPageChanged ( object sender , TabPageChangedEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
this . subListIndex = this . tabSubList . SelectedTabPageIndex ;
this . ShowGridColumns ( this . gviewRight ) ;
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
this . Editor . SubListIndex = this . subListIndex ;
this . gviewLeft . BeginSort ( ) ;
this . gviewLeft . EndSort ( ) ;
this . gviewRight . BeginSort ( ) ;
2017-06-08 20:01:42 +02:00
if ( this . subListIndex > 0 & & ! this . CurrentChannelList . IsMixedSourceFavoritesList )
2016-05-05 03:06:11 +02:00
this . colPrNr . FilterInfo = new ColumnFilterInfo ( "[NewProgramNr]<>-1" ) ;
else
this . colPrNr . ClearFilter ( ) ;
this . gviewRight . EndSort ( ) ;
2017-06-08 20:01:42 +02:00
this . UpdateInsertSlotNumber ( ) ;
2013-05-11 16:45:29 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#region gview_CustomUnboundColumnData
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
private void gview_CustomUnboundColumnData ( object sender , CustomColumnDataEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
var channel = ( ChannelInfo ) e . Row ;
if ( e . Column . FieldName = = "Position" )
e . Value = channel . GetPosition ( this . subListIndex ) ;
else if ( e . Column . FieldName = = "OldPosition" )
e . Value = channel . GetOldPosition ( this . subListIndex ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#region gview_MouseMove
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
private void gview_MouseMove ( object sender , MouseEventArgs e )
2013-04-21 22:04:06 +02:00
{
2016-05-05 03:06:11 +02:00
try
{
var view = ( GridView ) sender ;
if ( this . downHit = = null | | downHit . RowHandle < 0 | | e . Button ! = MouseButtons . Left | | view . ActiveEditor ! = null | | ModifierKeys ! = Keys . None )
return ;
if ( this . CurrentChannelList = = null | | this . CurrentChannelList . ReadOnly )
return ;
// drag/drop only allowed when left grid is sorted by NewSlotNr
if ( ! this . IsLeftGridSortedByNewProgNr )
return ;
if ( Math . Abs ( e . Y - downHit . HitPoint . Y ) < SystemInformation . DragSize . Height & &
Math . Abs ( e . X - downHit . HitPoint . X ) < SystemInformation . DragSize . Width )
return ;
2013-04-21 22:04:06 +02:00
2016-05-05 03:06:11 +02:00
// start drag operation
var channel = ( ChannelInfo ) view . GetRow ( downHit . RowHandle ) ;
this . dragDropInfo = new DragDropInfo ( view , channel . GetPosition ( this . subListIndex ) ) ;
view . GridControl . DoDragDrop ( this . dragDropInfo , DragDropEffects . Move ) ;
this . downHit = null ;
}
catch ( Exception ex )
{
HandleException ( ex ) ;
}
2013-04-06 01:46:28 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#region grid_GiveFeedback
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
private void grid_GiveFeedback ( object sender , GiveFeedbackEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
// this event is called on the source of the drag operation
e . UseDefaultCursors = false ;
if ( e . Effect = = DragDropEffects . Move )
{
if ( this . dragDropInfo . EditMode = = EditMode . InsertBefore )
Cursor . Current = Cursors . PanNE ;
else if ( this . dragDropInfo . EditMode = = EditMode . InsertAfter )
Cursor . Current = Cursors . PanSE ;
else
Cursor . Current = Cursors . HSplit ;
}
else if ( sender = = this . gridRight )
Cursor . Current = Cursors . PanWest ;
else
Cursor . Current = Cursors . No ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#region gridLeft_DragOver
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
private void gridLeft_DragOver ( object sender , DragEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
if ( this . dragDropInfo = = null ) // drag operation from outside ChanSort
2019-07-13 12:59:51 +02:00
{
MainForm_DragEnter ( sender , e ) ;
2016-05-05 03:06:11 +02:00
return ;
2019-07-13 12:59:51 +02:00
}
2016-05-05 03:06:11 +02:00
// this event is called on the current target of the drag operation
var point = this . gridLeft . PointToClient ( MousePosition ) ;
var hit = this . gviewLeft . CalcHitInfo ( point ) ;
if ( hit . RowHandle > = 0 )
{
var vi = ( GridViewInfo ) this . gviewLeft . GetViewInfo ( ) ;
var rowInfo = vi . GetGridRowInfo ( hit . RowHandle ) ;
var dropChannel = ( ChannelInfo ) this . gviewLeft . GetRow ( hit . RowHandle ) ;
var moveUp = this . dragDropInfo . SourcePosition < 0 | | dropChannel . GetPosition ( this . subListIndex ) < = this . dragDropInfo . SourcePosition ;
if ( moveUp & & point . Y < rowInfo . Bounds . Top + rowInfo . Bounds . Height / 2 )
this . dragDropInfo . EditMode = EditMode . InsertBefore ;
else if ( ! moveUp & & point . Y > rowInfo . Bounds . Top + rowInfo . Bounds . Height / 2 )
this . dragDropInfo . EditMode = EditMode . InsertAfter ;
else if ( this . dragDropInfo . SourceView = = this . gviewLeft )
this . dragDropInfo . EditMode = EditMode . Swap ;
else if ( moveUp )
this . dragDropInfo . EditMode = EditMode . InsertAfter ;
else
this . dragDropInfo . EditMode = EditMode . InsertBefore ;
this . dragDropInfo . DropRowHandle = hit . RowHandle ;
e . Effect = DragDropEffects . Move ;
return ;
}
e . Effect = DragDropEffects . None ;
this . dragDropInfo . DropRowHandle = GridControl . InvalidRowHandle ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region gridLeft_DragDrop
private void gridLeft_DragDrop ( object sender , DragEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
try
{
2019-07-13 12:59:51 +02:00
if ( this . dragDropInfo = = null )
{
MainForm_DragDrop ( sender , e ) ;
return ;
}
2016-05-05 03:06:11 +02:00
if ( this . dragDropInfo . DropRowHandle < 0 ) return ;
this . curEditMode = this . dragDropInfo . EditMode ;
var dropChannel = ( ChannelInfo ) this . gviewLeft . GetRow ( this . dragDropInfo . DropRowHandle ) ;
var selectedChannels = this . GetSelectedChannels ( this . dragDropInfo . SourceView ) ;
int newProgNr ;
var dropPos = dropChannel . GetPosition ( this . subListIndex ) ;
if ( this . dragDropInfo . EditMode ! = EditMode . InsertAfter | | ! this . cbCloseGap . Checked )
newProgNr = dropPos ;
else
{
var numberOfChannelsToMoveDown = 0 ;
foreach ( var channel in selectedChannels )
{
var curPos = channel . GetPosition ( this . subListIndex ) ;
if ( curPos ! = - 1 & & curPos < = dropPos )
+ + numberOfChannelsToMoveDown ;
}
newProgNr = dropPos + 1 - numberOfChannelsToMoveDown ;
}
this . Editor . SetSlotNumber ( selectedChannels , newProgNr , this . dragDropInfo . EditMode = = EditMode . Swap , this . cbCloseGap . Checked ) ;
this . RefreshGrid ( this . gviewLeft , this . gviewRight ) ;
}
catch ( Exception ex )
{
HandleException ( ex ) ;
}
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region gridLeft_ProcessGridKey
private void gridLeft_ProcessGridKey ( object sender , KeyEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
if ( this . CurrentChannelList ! = null & & this . CurrentChannelList . ReadOnly )
return ;
if ( gviewLeft . ActiveEditor ! = null )
return ;
if ( e . KeyCode = = Keys . Delete )
TryExecute ( ( ) = > this . RemoveChannels ( this . gviewLeft , this . cbCloseGap . Checked ) ) ;
else if ( e . KeyCode = = Keys . Add )
TryExecute ( ( ) = > this . MoveChannels ( false ) ) ;
else if ( e . KeyCode = = Keys . Subtract )
TryExecute ( ( ) = > this . MoveChannels ( true ) ) ;
else
return ;
e . Handled = true ;
e . SuppressKeyPress = true ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region gviewLeft_FocusedRowChanged
private void gviewLeft_FocusedRowChanged ( object sender , FocusedRowChangedEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
TryExecute ( UpdateInsertSlotNumber ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region gviewLeft_SelectionChanged
private void gviewLeft_SelectionChanged ( object sender , SelectionChangedEventArgs e )
{
this . UpdateMenu ( ) ;
}
#endregion
#region gviewLeft_CustomColumnDisplayText
private void gviewLeft_CustomColumnDisplayText ( object sender , CustomColumnDisplayTextEventArgs e )
{
if ( e . Column = = this . colOutFav )
{
2019-08-13 13:29:59 +02:00
if ( e . Value is Favorites fav )
e . DisplayText = GetFavString ( fav ) ;
2016-05-05 03:06:11 +02:00
}
}
#endregion
#region gviewLeft_RowCellStyle
private void gviewLeft_RowCellStyle ( object sender , RowCellStyleEventArgs e )
{
var channel = ( ChannelInfo ) this . gviewLeft . GetRow ( e . RowHandle ) ;
if ( channel = = null ) return ;
2019-08-11 10:04:29 +02:00
if ( channel . IsProxy | | channel . IsDeleted )
2016-05-05 03:06:11 +02:00
{
e . Appearance . ForeColor = Color . Red ;
e . Appearance . Options . UseForeColor = true ;
}
else if ( channel . Hidden )
{
e . Appearance . ForeColor = Color . LightGray ;
e . Appearance . Options . UseForeColor = true ;
}
else if ( channel . Skip )
{
e . Appearance . ForeColor = Color . Blue ;
e . Appearance . Options . UseForeColor = true ;
}
}
#endregion
#region gviewLeft_ValidatingEditor
private void gviewLeft_ValidatingEditor ( object sender , BaseContainerValidateEditorEventArgs e )
2013-03-31 14:09:38 +02:00
{
try
{
2016-05-05 03:06:11 +02:00
if ( gviewLeft . FocusedRowHandle = = GridControl . AutoFilterRowHandle )
2013-03-31 14:09:38 +02:00
return ;
2016-05-05 03:06:11 +02:00
if ( this . gviewLeft . FocusedColumn = = this . colOutSlot & & e . Value is string )
e . Valid = this . SetSlotNumber ( ( string ) e . Value ) ;
else if ( this . gviewLeft . FocusedColumn = = this . colOutFav & & e . Value is string )
e . Value = ChannelInfo . ParseFavString ( ( string ) e . Value ) ;
else if ( gviewLeft . FocusedColumn = = this . colOutName )
{
this . VerifyChannelNameModified ( this . gviewLeft . GetFocusedRow ( ) as ChannelInfo , e . Value as string ) ;
this . BeginInvoke ( ( Action ) ( ( ) = > RefreshGrid ( this . gviewLeft ) ) ) ;
}
DataRoot . NeedsSaving = true ;
}
catch ( Exception ex )
{
HandleException ( ex ) ;
2013-03-31 14:09:38 +02:00
}
}
2016-05-05 03:06:11 +02:00
#endregion
#region gviewLeft_CellValueChanged
private void gviewLeft_CellValueChanged ( object sender , CellValueChangedEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
this . gviewRight . BeginDataUpdate ( ) ;
this . gviewRight . EndDataUpdate ( ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region gviewLeft_PopupMenuShowing
private void gviewLeft_PopupMenuShowing ( object sender , PopupMenuShowingEventArgs e )
2013-04-29 00:35:40 +02:00
{
2016-05-05 03:06:11 +02:00
this . lastFocusedGrid = this . gviewLeft ;
this . UpdateMenu ( ) ;
if ( e . MenuType = = GridMenuType . Row & & e . HitInfo . InRow & & this . gviewLeft . IsDataRow ( e . HitInfo . RowHandle ) )
this . popupContext . ShowPopup ( this . gridLeft . PointToScreen ( e . Point ) ) ;
2013-04-29 00:35:40 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#region gviewLeft_RowClick
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
private void gviewLeft_RowClick ( object sender , RowClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
if ( e . Clicks = = 2 & & e . Button = = MouseButtons . Left & & this . gviewLeft . IsDataRow ( e . RowHandle ) )
{
var channel = ( ChannelInfo ) this . gviewLeft . GetRow ( e . RowHandle ) ;
this . NavigateToChannel ( channel , this . gviewRight ) ;
}
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region gviewLeft_EndSorting
private void gviewLeft_EndSorting ( object sender , EventArgs e )
2013-03-31 14:09:38 +02:00
{
2019-11-17 14:56:19 +01:00
TryExecute ( ( ) = > this . UpdateMenu ( ) ) ;
2016-05-05 03:06:11 +02:00
}
#endregion
#region gridRight_ProcessGridKey
private void gridRight_ProcessGridKey ( object sender , KeyEventArgs e )
{
if ( this . gviewRight . ActiveEditor ! = null )
return ;
if ( e . KeyCode = = Keys . Enter & & this . CurrentChannelList ! = null & & ! this . CurrentChannelList . ReadOnly )
{
TryExecute ( this . AddChannels ) ;
e . Handled = true ;
}
}
#endregion
2019-07-13 12:59:51 +02:00
#region gridRight_DragEnter , DragDrop
private void gridRight_DragEnter ( object sender , DragEventArgs e )
{
MainForm_DragEnter ( sender , e ) ;
}
private void gridRight_DragDrop ( object sender , DragEventArgs e )
{
MainForm_DragDrop ( sender , e ) ;
}
#endregion
2016-05-05 03:06:11 +02:00
#region gviewRight_FocusedRowChanged
private void gviewRight_FocusedRowChanged ( object sender , FocusedRowChangedEventArgs e )
{
this . gviewRight . SelectRow ( e . FocusedRowHandle ) ;
}
#endregion
#region gviewRight_CustomColumnDisplayText
private void gviewRight_CustomColumnDisplayText ( object sender , CustomColumnDisplayTextEventArgs e )
{
if ( e . Column = = this . colSlotNew | | e . Column = = this . colSlotOld | | e . Column = = this . colPrNr )
{
if ( ! ( e . Value is int ) ) return ;
if ( ( int ) e . Value = = - 1 )
e . DisplayText = string . Empty ;
}
else if ( e . Column = = this . colFavorites )
{
2019-08-13 13:29:59 +02:00
if ( e . Value is Favorites fav )
e . DisplayText = GetFavString ( fav ) ;
2016-05-05 03:06:11 +02:00
}
}
#endregion
#region gviewRight_RowCellStyle
private void gviewRight_RowCellStyle ( object sender , RowCellStyleEventArgs e )
{
var channel = ( ChannelInfo ) this . gviewRight . GetRow ( e . RowHandle ) ;
if ( channel = = null ) return ;
2017-06-08 20:01:42 +02:00
if ( channel . IsProxy )
2016-05-05 03:06:11 +02:00
{
e . Appearance . ForeColor = Color . Red ;
e . Appearance . Options . UseForeColor = true ;
}
else if ( channel . GetPosition ( this . subListIndex ) ! = - 1 )
{
e . Appearance . ForeColor = Color . Gray ;
e . Appearance . Options . UseForeColor = true ;
}
}
#endregion
#region gviewRight_RowClick
private void gviewRight_RowClick ( object sender , RowClickEventArgs e )
{
if ( e . Clicks = = 2 & & e . Button = = MouseButtons . Left & & this . gviewRight . IsDataRow ( e . RowHandle ) )
2016-05-06 23:54:54 +02:00
{
if ( this . rbInsertSwap . Checked )
{
TryExecute ( this . SwapChannels ) ;
}
else
TryExecute ( this . AddChannels ) ;
// rows were re-arranged and the pending MouseDown event handler would focus+select the wrong row again
this . dontFocusClickedRow = true ;
}
2016-05-05 03:06:11 +02:00
}
#endregion
#region gviewRight_ValidatingEditor
private void gviewRight_ValidatingEditor ( object sender , BaseContainerValidateEditorEventArgs e )
{
try
{
if ( gviewRight . FocusedRowHandle = = GridControl . AutoFilterRowHandle )
return ;
if ( this . gviewRight . FocusedColumn = = this . colSlotNew & & e . Value is string )
e . Valid = this . SetSlotNumber ( ( string ) e . Value ) ;
else if ( this . gviewRight . FocusedColumn = = this . colFavorites & & e . Value is string )
e . Value = ChannelInfo . ParseFavString ( ( string ) e . Value ) ;
else if ( gviewRight . FocusedColumn = = this . colName )
{
var ci = this . gviewRight . GetFocusedRow ( ) as ChannelInfo ;
this . VerifyChannelNameModified ( ci , e . Value as string ) ;
//this.BeginInvoke((Action) (() => RefreshGrid(this.gviewLeft)));
}
DataRoot . NeedsSaving = true ;
}
catch ( Exception ex )
{
HandleException ( ex ) ;
}
}
#endregion
#region gviewRight_CellValueChanged
private void gviewRight_CellValueChanged ( object sender , CellValueChangedEventArgs e )
{
TryExecute ( ( ) = > RefreshGrid ( this . gviewLeft ) ) ;
}
#endregion
2017-06-08 20:01:42 +02:00
#region gviewRight_CustomColumnSort
private void gviewRight_CustomColumnSort ( object sender , CustomColumnSortEventArgs e )
{
if ( e . Column = = this . colSlotOld )
{
// sort unassigned channels (PrNr = -1) to the bottom of the list
var ch1 = ( int ) this . gviewRight . GetListSourceRowCellValue ( e . ListSourceRowIndex1 , e . Column ) ;
var ch2 = ( int ) this . gviewRight . GetListSourceRowCellValue ( e . ListSourceRowIndex2 , e . Column ) ;
if ( ch1 < 0 ) ch1 = int . MaxValue ;
if ( ch2 < 0 ) ch2 = int . MaxValue ;
e . Result = System . Collections . Comparer . Default . Compare ( ch1 , ch2 ) ;
e . Handled = true ;
}
}
#endregion
2016-05-05 03:06:11 +02:00
#region gviewRight_PopupMenuShowing
private void gviewRight_PopupMenuShowing ( object sender , PopupMenuShowingEventArgs e )
{
this . lastFocusedGrid = this . gviewRight ;
this . UpdateMenu ( ) ;
if ( e . MenuType = = GridMenuType . Row )
this . popupContext . ShowPopup ( this . gridRight . PointToScreen ( e . Point ) ) ;
}
#endregion
#region rbInsertMode_CheckedChanged
private void rbInsertMode_CheckedChanged ( object sender , EventArgs e )
{
if ( ! ( ( CheckEdit ) sender ) . Checked )
return ;
try
{
2016-05-06 23:54:54 +02:00
this . btnAdd . ImageIndex = this . rbInsertSwap . Checked ? 38 : this . rbInsertAfter . Checked ? 39 : 40 ;
2019-02-16 11:34:49 +01:00
this . miAddChannel . ImageIndex = this . btnAdd . ImageIndex ;
2016-05-06 23:54:54 +02:00
2016-05-05 03:06:11 +02:00
if ( this . CurrentChannelList = = null )
return ;
2016-05-06 23:54:54 +02:00
2017-06-08 20:01:42 +02:00
if ( this . gviewLeft . RowCount = = 0 )
this . CurrentChannelList . InsertProgramNumber = 1 ;
else
{
var delta = this . curEditMode = = EditMode . InsertAfter
? - 1
: this . rbInsertAfter . Checked ? + 1 : 0 ;
this . CurrentChannelList . InsertProgramNumber + = delta ;
}
2016-05-05 03:06:11 +02:00
this . UpdateInsertSlotTextBox ( ) ;
this . curEditMode = this . rbInsertBefore . Checked
? EditMode . InsertBefore
: this . rbInsertAfter . Checked
? EditMode . InsertAfter
: EditMode . Swap ;
}
catch ( Exception ex )
{
HandleException ( ex ) ;
}
}
#endregion
#region btnAdd_Click
private void btnAdd_Click ( object sender , EventArgs e )
{
TryExecute ( this . AddChannels ) ;
}
#endregion
#region txtSetSlot_EditValueChanged
private void txtSetSlot_EditValueChanged ( object sender , EventArgs e )
{
TryExecute ( ( ) = >
{
int nr ;
int . TryParse ( this . txtSetSlot . Text , out nr ) ;
if ( this . CurrentChannelList ! = null )
this . CurrentChannelList . InsertProgramNumber = nr ;
} ) ;
}
#endregion
#region btnRenum_Click
private void btnRenum_Click ( object sender , EventArgs e )
{
TryExecute ( this . RenumberSelectedChannels ) ;
}
#endregion
#region MainForm_FormClosing
private void MainForm_FormClosing ( object sender , FormClosingEventArgs e )
{
2019-07-25 18:02:17 +02:00
try
{
if ( this . PromptSaveAndContinue ( ) )
2019-11-08 19:35:59 +01:00
{
2019-07-25 18:02:17 +02:00
this . SaveSettings ( ) ;
2019-11-08 19:35:59 +01:00
this . currentTvSerializer ? . Dispose ( ) ;
}
2019-07-25 18:02:17 +02:00
else
e . Cancel = true ;
}
catch
{
// ignore - always allow to exit
}
2016-05-05 03:06:11 +02:00
}
#endregion
#region btnAddAll_Click
private void btnAddAll_Click ( object sender , EventArgs e )
{
this . TryExecute ( this . AddAllUnsortedChannels ) ;
}
#endregion
#region miRenumFavByPrNr_ItemClick
private void miRenumFavByPrNr_ItemClick ( object sender , ItemClickEventArgs e )
{
TryExecute ( this . Editor . ApplyPrNrToFavLists ) ;
this . RefreshGrid ( this . gviewLeft , this . gviewRight ) ;
}
#endregion
#region miAllowEditPredefinedLists_DownChanged
private void miAllowEditPredefinedLists_DownChanged ( object sender , ItemClickEventArgs e )
{
TryExecute ( ( ) = >
{
this . UpdateGridReadOnly ( ) ;
this . UpdateMenu ( ) ;
} ) ;
}
#endregion
#region enum EditMode
private enum EditMode
{
InsertBefore = 0 ,
InsertAfter = 1 ,
Swap = 2
}
#endregion
#region class DragDropInfo
private class DragDropInfo
{
public readonly int SourcePosition ;
public readonly GridView SourceView ;
public int DropRowHandle = - 1 ;
public EditMode EditMode ;
public DragDropInfo ( GridView source , int sourcePosition )
{
this . SourceView = source ;
this . SourcePosition = sourcePosition ;
}
}
#endregion
#region SaveSettings ( ) , GetGridLayout ( )
private void SaveSettings ( )
{
this . gviewRight . PostEditor ( ) ;
this . gviewLeft . PostEditor ( ) ;
2020-05-02 19:04:43 +02:00
Config . Default . WindowSize = Tools . Unscale ( this . WindowState = = FormWindowState . Normal ? this . ClientSize : this . RestoreBounds . Size , this . absScaleFactor ) ;
2019-07-20 14:54:01 +02:00
Config . Default . Encoding = this . defaultEncoding . WebName ;
Config . Default . Language = Thread . CurrentThread . CurrentUICulture . Name ;
2020-05-02 19:04:43 +02:00
Config . Default . LeftPanelWidth = this . splitContainerControl1 . SplitterPosition . Unscale ( this . absScaleFactor . Width ) ;
2019-07-20 14:54:01 +02:00
Config . Default . ShowWarningsAfterLoading = this . miShowWarningsAfterLoad . Checked ;
Config . Default . CloseGaps = this . cbCloseGap . Checked ;
Config . Default . MruFiles . Clear ( ) ;
Config . Default . MruFiles . AddRange ( this . mruFiles ) ;
Config . Default . ExplorerIntegration = this . miExplorerIntegration . Down ;
Config . Default . CheckForUpdates = this . miCheckUpdates . Down ;
2020-07-12 02:39:43 +02:00
Config . Default . LeftGridLayout = this . gviewLeft . SaveLayoutToXml ( ) ;
Config . Default . RightGridLayout = this . gviewRight . SaveLayoutToXml ( ) ;
2016-05-05 03:06:11 +02:00
2019-07-20 14:54:01 +02:00
Config . Default . Save ( ) ;
2016-05-05 03:06:11 +02:00
}
#endregion
#region ClearLeftFilter ( ) , ClearRightFilter ( )
private void ClearLeftFilter ( )
{
this . gviewLeft . BeginSort ( ) ;
this . gviewLeft . ClearColumnsFilter ( ) ;
this . colOutSlot . FilterInfo = new ColumnFilterInfo ( "[Position]<>-1" ) ;
this . gviewLeft . EndSort ( ) ;
}
private void ClearRightFilter ( )
{
this . gviewRight . BeginSort ( ) ;
this . gviewRight . ClearColumnsFilter ( ) ;
2019-11-08 02:31:44 +01:00
this . colSlotOld . FilterInfo = new ColumnFilterInfo ( "[OldProgramNr]<>-1" ) ;
2017-06-08 20:01:42 +02:00
if ( this . subListIndex > 0 & & ! this . CurrentChannelList . IsMixedSourceFavoritesList )
2016-05-05 03:06:11 +02:00
this . colPrNr . FilterInfo = new ColumnFilterInfo ( "[NewProgramNr]<>-1" ) ;
this . gviewRight . EndSort ( ) ;
}
#endregion
#region RefreshGrid ( )
internal void RefreshGrids ( )
{
RefreshGrid ( this . gviewLeft , this . gviewRight ) ;
}
private void RefreshGrid ( params GridView [ ] grids )
{
foreach ( var grid in grids )
{
grid . BeginDataUpdate ( ) ;
grid . EndDataUpdate ( ) ;
}
}
#endregion
#region Accessibility
private void FocusRightList ( )
{
if ( this . gviewRight . SelectedRowsCount > 0 )
{
this . gviewRight . FocusedRowHandle = this . gviewRight . GetSelectedRows ( ) [ 0 ] ;
this . gridRight . Focus ( ) ;
}
}
private void FocusRightListFilter ( )
{
this . gviewRight . FocusedRowHandle = GridControl . AutoFilterRowHandle ;
this . gviewRight . FocusedColumn = this . colName ;
this . gridRight . Focus ( ) ;
}
private void FocusLeftList ( )
{
if ( this . gviewLeft . SelectedRowsCount > 0 )
{
this . gviewLeft . FocusedRowHandle = this . gviewLeft . GetSelectedRows ( ) [ 0 ] ;
this . gridLeft . Focus ( ) ;
}
}
private void FocusLeftListFilter ( )
{
this . gviewLeft . FocusedRowHandle = GridControl . AutoFilterRowHandle ;
this . gviewLeft . FocusedColumn = this . colOutName ;
this . gridLeft . Focus ( ) ;
}
#endregion
// -- menus
#region File menu
private void miOpen_ItemClick ( object sender , ItemClickEventArgs e )
{
TryExecute ( this . ShowOpenFileDialog ) ;
}
private void miOpenReferenceFile_ItemClick ( object sender , ItemClickEventArgs e )
{
this . TryExecute ( ( ) = > this . ShowOpenReferenceFileDialog ( false ) ) ;
}
private void miAddFromRefList_ItemClick ( object sender , ItemClickEventArgs e )
{
this . TryExecute ( ( ) = > this . ShowOpenReferenceFileDialog ( true ) ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
private void miReload_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
TryExecute ( ( ) = > this . ReLoadFiles ( this . currentPlugin ) ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
private void miRestoreOriginal_ItemClick ( object sender , ItemClickEventArgs e )
2013-04-06 01:46:28 +02:00
{
2016-05-05 03:06:11 +02:00
TryExecute ( this . RestoreBackupFile ) ;
2013-04-06 01:46:28 +02:00
}
2016-05-05 03:06:11 +02:00
private void miFileInformation_ItemClick ( object sender , ItemClickEventArgs e )
2013-04-06 01:46:28 +02:00
{
2016-05-05 03:06:11 +02:00
TryExecute ( this . ShowFileInformation ) ;
2013-04-06 01:46:28 +02:00
}
2016-05-05 03:06:11 +02:00
private void miSave_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
TryExecute ( this . SaveFiles ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
private void miSaveAs_ItemClick ( object sender , ItemClickEventArgs e )
2014-07-08 22:16:16 +02:00
{
2016-05-05 03:06:11 +02:00
TryExecute ( this . ShowSaveFileDialog ) ;
2014-07-08 22:16:16 +02:00
}
2016-05-05 03:06:11 +02:00
private void miSaveReferenceFile_ItemClick ( object sender , ItemClickEventArgs e )
2014-07-08 22:16:16 +02:00
{
2016-05-05 03:06:11 +02:00
TryExecute ( this . SaveReferenceFile ) ;
2014-07-08 22:16:16 +02:00
}
2016-05-05 03:06:11 +02:00
private void miExcelExport_ItemClick ( object sender , ItemClickEventArgs e )
2014-07-08 22:16:16 +02:00
{
2016-05-05 03:06:11 +02:00
TryExecute ( this . ExportExcelList ) ;
2014-07-08 22:16:16 +02:00
}
2016-05-05 03:06:11 +02:00
private void miPrint_ItemClick ( object sender , ItemClickEventArgs e )
2014-07-08 22:16:16 +02:00
{
2016-05-05 03:06:11 +02:00
this . TryExecute ( this . Print ) ;
2014-07-08 22:16:16 +02:00
}
2016-05-05 03:06:11 +02:00
private void miQuit_ItemClick ( object sender , ItemClickEventArgs e )
2014-07-08 22:16:16 +02:00
{
2016-05-05 03:06:11 +02:00
this . Close ( ) ;
2014-07-08 22:16:16 +02:00
}
2016-05-05 03:06:11 +02:00
private void miRecentFiles_ListItemClick ( object sender , ListItemClickEventArgs e )
2014-07-08 22:16:16 +02:00
{
2016-05-05 03:06:11 +02:00
TryExecute ( ( ) = > this . LoadFiles ( null , this . mruFiles [ e . Index ] ) ) ;
2014-07-08 22:16:16 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2014-07-08 22:16:16 +02:00
2016-05-05 03:06:11 +02:00
#region Edit menu
2013-03-31 14:09:38 +02:00
2019-08-13 13:29:59 +02:00
private void miCopyCsv_ItemClick ( object sender , ItemClickEventArgs e )
{
var gview = this . gridRight . ContainsFocus ? this . gviewRight : this . gviewLeft ;
var cols = gview . VisibleColumns ;
var sb = new StringBuilder ( ) ;
foreach ( GridColumn col in cols )
sb . Append ( col . Caption ) . Append ( '\t' ) ;
sb [ sb . Length - 1 ] = '\n' ;
for ( int i = 0 , c = gview . RowCount ; i < c ; i + + )
{
foreach ( GridColumn col in cols )
{
if ( col . ColumnType = = typeof ( bool ) )
{
var val = gview . GetRowCellValue ( i , col ) ;
if ( val is bool b & & b )
sb . Append ( 'x' ) ;
sb . Append ( '\t' ) ;
}
else
{
var val = gview . GetRowCellDisplayText ( i , col ) ;
sb . Append ( val ) . Append ( '\t' ) ;
}
}
sb [ sb . Length - 1 ] = '\n' ;
}
Clipboard . SetText ( sb . ToString ( ) , TextDataFormat . Text ) ;
}
2019-02-16 11:34:49 +01:00
private void miAddChannel_ItemClick ( object sender , ItemClickEventArgs e )
{
this . TryExecute ( this . AddChannels ) ;
}
2016-05-05 03:06:11 +02:00
private void miMoveDown_ItemClick ( object sender , ItemClickEventArgs e )
2013-04-06 01:46:28 +02:00
{
2016-05-05 03:06:11 +02:00
this . TryExecute ( ( ) = > this . MoveChannels ( false ) ) ;
2013-04-06 01:46:28 +02:00
}
2016-05-05 03:06:11 +02:00
private void miMoveUp_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
this . TryExecute ( ( ) = > this . MoveChannels ( true ) ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
private void miRemove_ItemClick ( object sender , ItemClickEventArgs e )
2013-07-02 23:55:02 +02:00
{
2016-05-05 03:06:11 +02:00
this . TryExecute ( ( ) = > this . RemoveChannels ( this . lastFocusedGrid , this . cbCloseGap . Checked ) ) ;
2013-07-02 23:55:02 +02:00
}
2016-05-05 03:06:11 +02:00
private void miRenameChannel_ItemClick ( object sender , ItemClickEventArgs e )
2013-07-02 23:55:02 +02:00
{
2016-05-05 03:06:11 +02:00
this . TryExecute ( this . RenameChannel ) ;
2013-07-02 23:55:02 +02:00
}
2013-04-06 01:46:28 +02:00
2016-05-05 03:06:11 +02:00
private void miSort_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
this . TryExecute ( this . SortSelectedChannels ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
private void miRenum_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
this . TryExecute ( this . RenumberSelectedChannels ) ;
2013-04-21 22:04:06 +02:00
}
2016-05-05 03:06:11 +02:00
private void miFavSet_ItemClick ( object sender , ItemClickEventArgs e )
2013-04-21 22:04:06 +02:00
{
2016-05-05 03:06:11 +02:00
var fav = e . Item . Tag as string ;
this . SetFavorite ( fav , true ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
private void miFavUnset_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
var fav = e . Item . Tag as string ;
this . SetFavorite ( fav , false ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
private void miLockOn_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
this . TryExecute ( ( ) = > this . SetChannelFlag ( ch = > ch . Lock = true ) ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
private void miLockOff_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
this . TryExecute ( ( ) = > this . SetChannelFlag ( ch = > ch . Lock = false ) ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
private void miSkipOn_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
this . TryExecute ( ( ) = > this . SetChannelFlag ( ch = > ch . Skip = true ) ) ;
}
2013-06-23 14:58:44 +02:00
2016-05-05 03:06:11 +02:00
private void miSkipOff_ItemClick ( object sender , ItemClickEventArgs e )
{
this . TryExecute ( ( ) = > this . SetChannelFlag ( ch = > ch . Skip = false ) ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
private void miHideOn_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
this . TryExecute ( ( ) = > this . SetChannelFlag ( ch = > ch . Hidden = true ) ) ;
2013-06-23 14:58:44 +02:00
}
2016-05-05 03:06:11 +02:00
private void miHideOff_ItemClick ( object sender , ItemClickEventArgs e )
2013-06-23 14:58:44 +02:00
{
2016-05-05 03:06:11 +02:00
this . TryExecute ( ( ) = > this . SetChannelFlag ( ch = > ch . Hidden = false ) ) ;
}
2013-11-16 21:00:51 +01:00
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#region TV - Set menu
private void miTvCountrySetup_ItemClick ( object sender , ItemClickEventArgs e )
{
this . TryExecute ( this . ShowTvCountrySettings ) ;
2013-06-23 14:58:44 +02:00
}
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
private void miCleanupChannels_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
this . TryExecute ( this . CleanupChannelData ) ;
}
2013-06-23 14:58:44 +02:00
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#region Character set menu
2020-07-12 02:39:43 +02:00
private void miUtf8Charset_ItemClick ( object sender , ItemClickEventArgs e )
2019-08-05 23:50:53 +02:00
{
TryExecute ( ( ) = > this . SetDefaultEncoding ( Encoding . UTF8 ) ) ;
}
2016-05-05 03:06:11 +02:00
private void miIsoCharSets_ListItemClick ( object sender , ListItemClickEventArgs e )
{
TryExecute ( ( ) = > this . SetDefaultEncoding ( Encoding . GetEncoding ( this . isoEncodings [ e . Index ] ) ) ) ;
2013-04-06 01:46:28 +02:00
}
2016-05-05 03:06:11 +02:00
private void miCharset_ItemClick ( object sender , ItemClickEventArgs e )
2013-04-06 01:46:28 +02:00
{
2016-05-05 03:06:11 +02:00
TryExecute ( ShowCharsetForm ) ;
}
2020-07-12 02:39:43 +02:00
private void miUtf16BigEndian_ItemClick ( object sender , ItemClickEventArgs e )
{
TryExecute ( ( ) = > this . SetDefaultEncoding ( Encoding . BigEndianUnicode ) ) ;
}
private void miUtf16LittleEndian_ItemClick ( object sender , ItemClickEventArgs e )
{
TryExecute ( ( ) = > this . SetDefaultEncoding ( Encoding . Unicode ) ) ;
}
2016-05-05 03:06:11 +02:00
private void charsetForm_EncodingChanged ( object sender , EncodingChangedEventArgs e )
{
SetDefaultEncoding ( e . Encoding ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2020-05-02 19:04:43 +02:00
#region Language menu
private void miLanguage_DownChanged ( object sender , ItemClickEventArgs e )
{
try
{
if ( this . ignoreLanguageChange )
return ;
var menuItem = ( BarButtonItem ) sender ;
if ( ! menuItem . Down )
return ;
if ( ! this . PromptSaveAndContinue ( ) )
return ;
var locale = ( string ) menuItem . Tag ;
Program . ChangeLanguage = true ;
Thread . CurrentThread . CurrentUICulture = new CultureInfo ( locale ) ;
this . Close ( ) ;
}
catch ( Exception ex )
{
HandleException ( ex ) ;
}
}
#endregion
2016-05-05 03:06:11 +02:00
#region Help menu
2013-04-06 01:46:28 +02:00
2016-05-05 03:06:11 +02:00
private void miWiki_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
BrowserHelper . OpenUrl ( "https://github.com/PredatH0r/ChanSort/wiki" ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
private void miOpenWebsite_ItemClick ( object sender , ItemClickEventArgs e )
2013-04-06 01:46:28 +02:00
{
2016-05-05 03:06:11 +02:00
BrowserHelper . OpenUrl ( "https://github.com/PredatH0r/ChanSort" ) ;
2013-04-06 01:46:28 +02:00
}
2016-05-05 03:06:11 +02:00
private void miAbout_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
TryExecute ( ( ) = > new AboutForm ( this . Plugins ) . ShowDialog ( ) ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region Accessibility menu
private void miInputSource_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
this . tabChannelList . SelectedTabPageIndex = ( int ) e . Item . Tag ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
private void miSelectFavList_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
try
{
2016-05-05 03:06:11 +02:00
var idx = Convert . ToInt32 ( e . Item . Tag ) ;
if ( this . grpSubList . Visible & & idx < this . tabSubList . TabPages . Count )
this . tabSubList . SelectedTabPageIndex = idx ;
}
catch ( Exception ex )
{
HandleException ( ex ) ;
2013-03-31 14:09:38 +02:00
}
}
2016-05-05 03:06:11 +02:00
private void miGotoLeftFilter_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
TryExecute ( this . FocusLeftListFilter ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
private void miGotoLeftList_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
TryExecute ( this . FocusLeftList ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
private void miRightListFilter_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
TryExecute ( this . FocusRightListFilter ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
private void miGotoRightList_ItemClick ( object sender , ItemClickEventArgs e )
2013-03-31 14:09:38 +02:00
{
2016-05-05 03:06:11 +02:00
TryExecute ( this . FocusRightList ) ;
2013-06-23 14:58:44 +02:00
}
2020-05-02 19:04:43 +02:00
private void miFont_DownChanged ( object sender , ItemClickEventArgs e )
{
TryExecute ( ( ) = >
{
var deltaSize = ( int ) e . Item . Tag ;
if ( ! ( ( BarButtonItem ) e . Item ) . Down )
{
// reselect the current font size
if ( deltaSize = = Config . Default . FontSizeDelta )
( ( BarButtonItem ) e . Item ) . Down = true ;
return ;
}
if ( deltaSize = = Config . Default . FontSizeDelta ) // no change => early exit
return ;
var font = new Font ( deltaSize = = 0 ? "Tahoma" : "Segoe UI" , 8.25f + deltaSize ) ;
WindowsFormsSettings . DefaultFont = font ;
font = new Font ( "Segoe UI" , 9 + deltaSize ) ;
WindowsFormsSettings . DefaultMenuFont = font ;
Config . Default . FontSizeDelta = deltaSize ;
foreach ( var mi in new [ ] { miFontSmall , miFontMedium , miFontLarge , miFontXLarge , miFontXxLarge } )
mi . Down = e . Item = = mi ;
} ) ;
}
2016-05-05 03:06:11 +02:00
#endregion
2013-06-23 14:58:44 +02:00
2019-07-13 12:59:51 +02:00
#region miExplorerIntegration_ItemClick
private void miExplorerIntegration_ItemClick ( object sender , ItemClickEventArgs e )
{
try
{
2019-07-20 14:54:01 +02:00
if ( this . miExplorerIntegration . Down = = Config . Default . ExplorerIntegration )
2019-07-14 22:54:46 +02:00
return ;
2019-07-13 12:59:51 +02:00
// get all file extensions from loader plugins
var ext = new HashSet < string > ( ) ;
foreach ( var loader in this . Plugins )
{
var filters = loader . FileFilter . Split ( ';' ) ;
foreach ( var filter in filters )
{
int i = filter . LastIndexOf ( '.' ) ;
if ( i > = 0 & & i < filter . Length - 1 )
ext . Add ( filter . Substring ( i ) . ToLowerInvariant ( ) ) ;
}
}
if ( this . miExplorerIntegration . Down )
FileAssociations . CreateMissingAssociations ( ext ) ;
else
FileAssociations . DeleteAssociations ( ext ) ;
this . SaveSettings ( ) ;
}
catch ( Exception ex )
{
HandleException ( ex ) ;
}
}
#endregion
2019-07-14 22:54:46 +02:00
#region miCheckUpdates_ItemClick
private void miCheckUpdates_ItemClick ( object sender , ItemClickEventArgs e )
{
try
{
2019-07-20 14:54:01 +02:00
if ( this . miCheckUpdates . Down = = Config . Default . CheckForUpdates )
2019-07-14 22:54:46 +02:00
return ;
if ( this . miCheckUpdates . Down )
UpdateCheck . CheckForNewVersion ( ) ;
this . SaveSettings ( ) ;
}
catch ( Exception ex )
{
HandleException ( ex ) ;
}
}
#endregion
2019-07-13 12:59:51 +02:00
2020-05-02 19:04:43 +02:00
2016-05-05 03:06:11 +02:00
#region gview_MouseDown , gview_MouseUp , timerEditDelay_Tick , gview_ShowingEditor
2013-06-23 14:58:44 +02:00
2016-05-05 03:06:11 +02:00
// these 4 event handler in combination override the default row-selection and editor-opening
// behavior of the grid control.
2016-05-06 23:54:54 +02:00
private bool dontFocusClickedRow ;
2016-05-05 03:06:11 +02:00
private void gview_MouseDown ( object sender , MouseEventArgs e )
2013-06-23 14:58:44 +02:00
{
2016-05-05 03:06:11 +02:00
var view = ( GridView ) sender ;
this . downHit = view . CalcHitInfo ( e . Location ) ;
this . dragDropInfo = null ;
if ( ! view . IsDataRow ( downHit . RowHandle ) )
2013-03-31 14:09:38 +02:00
return ;
2016-05-05 03:06:11 +02:00
if ( e . Button = = MouseButtons . Left )
2013-06-23 14:58:44 +02:00
{
2016-05-05 03:06:11 +02:00
if ( ModifierKeys = = Keys . None )
{
2016-05-06 23:54:54 +02:00
if ( downHit . RowHandle ! = view . FocusedRowHandle & & ! dontFocusClickedRow )
2016-05-05 03:06:11 +02:00
SelectFocusedRow ( view , downHit . RowHandle ) ;
this . timerEditDelay . Start ( ) ;
}
else
{
if ( ModifierKeys = = Keys . Control & & ! view . IsRowSelected ( downHit . RowHandle ) )
this . BeginInvoke ( ( Action ) ( ( ) = > view . SelectRow ( downHit . RowHandle ) ) ) ;
}
}
else if ( e . Button = = MouseButtons . Right )
{
if ( ! view . IsRowSelected ( downHit . RowHandle ) )
SelectFocusedRow ( view , downHit . RowHandle ) ;
2013-06-23 14:58:44 +02:00
}
2016-05-05 03:06:11 +02:00
this . dontOpenEditor = true ;
2016-05-06 23:54:54 +02:00
this . dontFocusClickedRow = false ;
2016-05-05 03:06:11 +02:00
}
2013-06-23 14:58:44 +02:00
2016-05-05 03:06:11 +02:00
private void gview_MouseUp ( object sender , MouseEventArgs e )
2013-06-23 14:58:44 +02:00
{
2016-05-05 03:06:11 +02:00
this . timerEditDelay . Stop ( ) ;
this . BeginInvoke ( ( Action ) ( ( ) = > { this . dontOpenEditor = false ; } ) ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
private void timerEditDelay_Tick ( object sender , EventArgs e )
2013-06-23 14:58:44 +02:00
{
2016-05-05 03:06:11 +02:00
this . timerEditDelay . Stop ( ) ;
this . dontOpenEditor = false ;
if ( this . lastFocusedGrid ! = null )
2013-06-23 14:58:44 +02:00
{
2016-05-05 03:06:11 +02:00
var hit = this . lastFocusedGrid . CalcHitInfo ( this . lastFocusedGrid . GridControl . PointToClient ( MousePosition ) ) ;
if ( hit . Column = = this . lastFocusedGrid . FocusedColumn & & hit . RowHandle = = this . lastFocusedGrid . FocusedRowHandle )
this . lastFocusedGrid . ShowEditor ( ) ;
2013-06-23 14:58:44 +02:00
}
}
2016-05-05 03:06:11 +02:00
private void gview_ShowingEditor ( object sender , CancelEventArgs e )
2013-06-23 14:58:44 +02:00
{
2016-05-05 03:06:11 +02:00
var field = ( ( GridView ) sender ) . FocusedColumn . FieldName ;
if ( this . dontOpenEditor & & ( field = = this . colSlotNew . FieldName | | field = = this . colName . FieldName ) )
e . Cancel = true ;
2013-06-23 14:58:44 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region gview_ShownEditor , gview_KeyPress
private void gview_ShownEditor ( object sender , EventArgs e )
2013-06-23 14:58:44 +02:00
{
2016-05-05 03:06:11 +02:00
var view = ( GridView ) sender ;
2017-06-08 23:27:34 +02:00
if ( view . FocusedRowHandle < 0 )
return ;
2016-05-05 03:06:11 +02:00
var edit = view . ActiveEditor as TextEdit ;
if ( edit = = null ) return ;
edit . Properties . MaxLength = view . FocusedColumn . FieldName = = "Name" ? this . CurrentChannelList . MaxChannelNameLength : 0 ;
2013-06-23 14:58:44 +02:00
}
2016-05-05 03:06:11 +02:00
private void gview_KeyPress ( object sender , KeyPressEventArgs e )
2013-06-23 14:58:44 +02:00
{
2016-05-05 03:06:11 +02:00
var view = ( GridView ) sender ;
if ( view . FocusedColumn . DisplayFormat . FormatType = = FormatType . Numeric & & ( e . KeyChar < '0' | | e . KeyChar > '9' ) )
e . Handled = true ;
2013-06-23 14:58:44 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region gviewLeft_LayoutUpgrade , gviewRight_LayoutUpgrade
private void gviewLeft_LayoutUpgrade ( object sender , LayoutUpgradeEventArgs e )
2013-06-23 14:58:44 +02:00
{
2016-05-05 03:06:11 +02:00
this . gviewLeft . ClearGrouping ( ) ;
this . gviewLeft . OptionsCustomization . AllowGroup = false ;
2013-06-23 14:58:44 +02:00
}
2016-05-05 03:06:11 +02:00
private void gviewRight_LayoutUpgrade ( object sender , LayoutUpgradeEventArgs e )
2013-06-23 14:58:44 +02:00
{
2016-05-05 03:06:11 +02:00
this . gviewRight . ClearGrouping ( ) ;
this . gviewRight . OptionsCustomization . AllowGroup = false ;
2013-06-23 14:58:44 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
2013-06-23 14:58:44 +02:00
2016-05-05 03:06:11 +02:00
#region btnClearLeftFilter_Click , btnClearRightFilter_Click
2013-03-31 14:09:38 +02:00
private void btnClearLeftFilter_Click ( object sender , EventArgs e )
{
TryExecute ( this . ClearLeftFilter ) ;
}
private void btnClearRightFilter_Click ( object sender , EventArgs e )
{
TryExecute ( this . ClearRightFilter ) ;
}
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#region btnRemoveLeft_Click , btnRemoveRight_Click
2013-03-31 14:09:38 +02:00
2013-04-21 22:04:06 +02:00
private void btnRemoveLeft_Click ( object sender , EventArgs e )
2013-03-31 14:09:38 +02:00
{
2013-04-06 01:46:28 +02:00
TryExecute ( ( ) = > this . RemoveChannels ( this . gviewLeft , this . cbCloseGap . Checked ) ) ;
2013-03-31 14:09:38 +02:00
}
2013-04-21 22:04:06 +02:00
private void btnRemoveRight_Click ( object sender , EventArgs e )
{
this . TryExecute ( ( ) = > this . RemoveChannels ( this . gviewRight , this . cbCloseGap . Checked ) ) ;
}
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#endregion
#region btnUp_Click , btnDown_Click
2013-03-31 14:09:38 +02:00
private void btnUp_Click ( object sender , EventArgs e )
{
TryExecute ( ( ) = > MoveChannels ( true ) ) ;
}
private void btnDown_Click ( object sender , EventArgs e )
{
TryExecute ( ( ) = > MoveChannels ( false ) ) ;
}
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#region txtSetSlot_ButtonClick , txtSetSlot_KeyDown
2013-03-31 14:09:38 +02:00
private void txtSetSlot_ButtonClick ( object sender , ButtonPressedEventArgs e )
{
TryExecute ( ( ) = > this . SetSlotNumber ( this . txtSetSlot . Text ) ) ;
}
private void txtSetSlot_KeyDown ( object sender , KeyEventArgs e )
{
if ( e . KeyData = = Keys . Enter )
{
TryExecute ( ( ) = > this . SetSlotNumber ( this . txtSetSlot . Text ) ) ;
e . Handled = true ;
}
}
2016-05-05 03:06:11 +02:00
#endregion
2013-03-31 14:09:38 +02:00
2016-05-05 03:06:11 +02:00
#region btnToggleFav_Click , btnToggleLock_Click
2013-03-31 14:09:38 +02:00
2013-04-06 01:46:28 +02:00
private void btnToggleFav_Click ( object sender , EventArgs e )
{
2016-05-05 03:06:11 +02:00
var fav = ( ( Control ) sender ) . Text . Substring ( 1 ) ;
2013-04-06 01:46:28 +02:00
this . TryExecute ( ( ) = > this . ToggleFavorite ( fav ) ) ;
2013-03-31 14:09:38 +02:00
}
2013-04-06 01:46:28 +02:00
private void btnToggleLock_Click ( object sender , EventArgs e )
2013-03-31 14:09:38 +02:00
{
2013-04-06 01:46:28 +02:00
this . TryExecute ( this . ToggleLock ) ;
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
#endregion
#region grpOutputList_Enter , grpInputList_Enter
2013-04-06 01:46:28 +02:00
private void grpOutputList_Enter ( object sender , EventArgs e )
2013-03-31 14:09:38 +02:00
{
2013-04-06 01:46:28 +02:00
this . SetActiveGrid ( this . gviewLeft ) ;
2013-03-31 14:09:38 +02:00
}
2013-04-06 01:46:28 +02:00
private void grpInputList_Enter ( object sender , EventArgs e )
2013-03-31 14:09:38 +02:00
{
2013-04-06 01:46:28 +02:00
this . SetActiveGrid ( this . gviewRight ) ;
2013-03-31 14:09:38 +02:00
}
2014-07-11 10:07:33 +02:00
2016-05-05 03:06:11 +02:00
#endregion
2019-08-13 13:29:59 +02:00
2020-02-11 21:06:37 +01:00
#region tabSubList_MouseUp
private void tabSubList_MouseUp ( object sender , MouseEventArgs e )
{
if ( e . Button = = MouseButtons . Right )
{
var hit = this . tabSubList . CalcHitInfo ( e . Location ) ;
if ( hit . IsValid & & hit . Page ! = null )
{
using var dlg = new TextInputForm ( ) ;
dlg . StartPosition = FormStartPosition . Manual ;
dlg . Location = this . tabSubList . PointToScreen ( e . Location ) ;
var favIndex = this . tabSubList . TabPages . IndexOf ( hit . Page ) - 1 ;
dlg . Text = this . DataRoot . GetFavListCaption ( favIndex ) ;
if ( dlg . ShowDialog ( this ) = = DialogResult . OK )
{
this . DataRoot . SetFavListCaption ( favIndex , dlg . Text ) ;
hit . Page . Text = this . DataRoot . GetFavListCaption ( favIndex , true ) ;
}
}
}
}
#endregion
2013-03-31 14:09:38 +02:00
}
2016-05-05 03:06:11 +02:00
}