|
From: <nic...@us...> - 2014-05-16 13:19:06
|
Revision: 4805
http://sourceforge.net/p/mp-plugins/code/4805
Author: nicsergio
Date: 2014-05-16 13:19:01 +0000 (Fri, 16 May 2014)
Log Message:
-----------
Modified Paths:
--------------
trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuts.cs
Modified: trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuts.cs
===================================================================
--- trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuts.cs 2014-05-12 14:52:42 UTC (rev 4804)
+++ trunk/plugins/ShortCuter&SkinEditor/Source/ShortCuter/ShortCuts.cs 2014-05-16 13:19:01 UTC (rev 4805)
@@ -508,8 +508,118 @@
#endregion
#region Metodi Pubblici
+ public bool LoadConfig(string settingsFile) //Caricamento configurazione
+ {
+ _items.Clear(); //--> pulizia lista elementi di navigazione
+ FileStream userConfig = null;
+ try
+ {
+ XmlDocument xmlFile = new XmlDocument();
+ if (settingsFile.Length>0)
+ {
+ userConfig = new FileStream(settingsFile, FileMode.Open, FileAccess.Read);
+ xmlFile.Load(userConfig); //Lettura file xml delle ultime impostazioni
+ userConfig.Close(); //--> chiusura file
+ }
+ else
+ using (Stream defaultConfig = Assembly.GetExecutingAssembly().GetManifestResourceStream("ProcessPlugins.ShortCuter.Resources.XmlFiles.DefaultNavigatorConfig.xml"))
+ {
+ xmlFile.Load(defaultConfig); //Configurazione predefinita --> lettura file xml incapsulato
+ }
-
+
+ XmlNode innerNode;
+ XmlNode generalNode = xmlFile.DocumentElement.SelectSingleNode("/ShortCuter/Navigator/General");
+ if (generalNode != null) //Se presente sezione "General"
+ {
+ innerNode = generalNode.SelectSingleNode("ForcingCapsLock");
+ if (innerNode != null)
+ _general.ForcingCapsLock = (LockKeys.LockKeyActions)Enum.Parse(typeof(LockKeys.LockKeyActions), innerNode.InnerText);
+ else
+ {
+ innerNode = generalNode.SelectSingleNode("ResetCapsLock"); //Necessario per compatibilità con file di configurazione V2.0.5
+ if (innerNode != null && Convert.ToBoolean(Convert.ToInt16(innerNode.InnerText)))
+ _general.ForcingCapsLock = LockKeys.LockKeyActions.Off;
+ }
+ innerNode = generalNode.SelectSingleNode("ForcingNumLock");
+ if (innerNode != null)
+ _general.ForcingNumLock = (LockKeys.LockKeyActions)Enum.Parse(typeof(LockKeys.LockKeyActions), innerNode.InnerText);
+ else
+ {
+ innerNode = generalNode.SelectSingleNode("ResetNumLock"); //Necessario per compatibilità con file di configurazione V2.0.5
+ if (innerNode != null && Convert.ToBoolean(Convert.ToInt16(innerNode.InnerText)))
+ _general.ForcingNumLock = LockKeys.LockKeyActions.Off;
+ }
+ }
+ else
+ return false; //--> altrimenti configurazione non presente
+ XmlNodeList nodeList = xmlFile.DocumentElement.SelectNodes("/ShortCuter/Items/Item");
+ foreach (XmlNode node in nodeList) //Iterazione per memorizzazione impostazioni shortcuts
+ {
+ ShortCut sc = new ShortCut();
+ innerNode = node.SelectSingleNode("Caption");
+ if (innerNode != null)
+ sc.Caption = innerNode.InnerText;
+ innerNode = node.SelectSingleNode("Key");
+ if (innerNode != null)
+ sc.Key = innerNode.InnerText;
+ innerNode = node.SelectSingleNode("Ctrl");
+ if (innerNode != null)
+ sc.Ctrl = Convert.ToBoolean(Convert.ToInt16(innerNode.InnerText));
+ innerNode = node.SelectSingleNode("Alt");
+ if (innerNode != null)
+ sc.Alt = Convert.ToBoolean(Convert.ToInt16(innerNode.InnerText));
+ innerNode = node.SelectSingleNode("Shift");
+ if (innerNode != null)
+ sc.Shift = Convert.ToBoolean(Convert.ToInt16(innerNode.InnerText));
+ innerNode = node.SelectSingleNode("WindowID");
+ if (innerNode != null)
+ sc.WindowID = Convert.ToInt32(innerNode.InnerText);
+ else
+ {
+ innerNode = node.SelectSingleNode("Hyperlink"); //Necessario per compatibilità con file di configurazione V2.0.0
+ if (innerNode != null)
+ sc.WindowID = Convert.ToInt32(innerNode.InnerText);
+ }
+ innerNode = node.SelectSingleNode("LoadParameter");
+ if (innerNode != null)
+ sc.LoadParameter = innerNode.InnerText;
+ else
+ {
+ innerNode = node.SelectSingleNode("HyperlinkParameter"); //Necessario per compatibilità con file di configurazione V2.0.0
+ if (innerNode != null)
+ sc.LoadParameter = innerNode.InnerText;
+ }
+ innerNode = node.SelectSingleNode("Return");
+ if (innerNode != null)
+ sc.Return = Convert.ToBoolean(Convert.ToInt16(innerNode.InnerText));
+ innerNode = node.SelectSingleNode("SoundEffect");
+ if (innerNode != null)
+ sc.SoundEffect = innerNode.InnerText;
+ if (sc.IsValid) //Se shortcut valido
+ _items.Add(sc); //--> aggiunta dello shortcut nella lista
+ }
+ if (_items.Count > 0)
+ return true; //--> lettura configurazione effettuata
+ else
+ {
+ if (defaultSettings && Log != null) //Se nessun shortcut trovato nella configurazione predefinita: emissione messaggio
+ Log(this, new LogEventArgs(LogEventArgs.LogLevels.Info, "No shortcuts found loading DefaultConfig.xml."));
+ return false;
+ }
+ }
+ catch (Exception e)
+ {
+ if (defaultSettings && Log != null) //Se lettura configurazione predefinita fallita: emissione messaggio di errore
+ Log(this, new LogEventArgs(LogEventArgs.LogLevels.Error, "Error loading DefaultConfig.xml.", e));
+ return false;
+ }
+ finally
+ {
+ if (userConfig != null)
+ userConfig.Close(); //--> eventuale chiusura oggetto FileStream
+ }
+ }
public WindowLink Go() //Gestione finestra di dialogo e navigazione alla destinazione selezionata
{
if (Log != null)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|