示例#1
0
        // ********************************************************************************
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        /// <created>UPh,29.08.2015</created>
        /// <changed>UPh,29.08.2015</changed>
        // ********************************************************************************
        protected override void OnMouseClick(MouseEventArgs e)
        {
            base.OnMouseClick(e);

            HitPosition hit;
            int         inx = HitTest(e.Location, out hit);

            if (inx < 0)
            {
                return;
            }

            if (hit == HitPosition.CheckBox)
            {
                TermBaseFile file = Items[inx] as TermBaseFile;
                if (file != null)
                {
                    file.Active = !file.Active;

                    // Raise Event without args
                    if (ActiveChanged != null)
                    {
                        ActiveChanged(this, new ActiveChangedEventArgs(file));
                    }


                    Invalidate(GetCheckBoxRect(inx));
                }
            }
        }
示例#2
0
        // ********************************************************************************
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        /// <param name="g"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        /// <created>UPh,29.08.2015</created>
        /// <changed>UPh,29.08.2015</changed>
        // ********************************************************************************
        private void DrawText(DrawItemEventArgs e, TermBaseFile file)
        {
            Rectangle rcText = e.Bounds;
            Graphics  g      = e.Graphics;

            using (Region rgnClip = new Region(e.Bounds))
            {
                g.Clip = rgnClip;

                rcText.X += 30;
                rcText.Y += 2;

                bool bError = !string.IsNullOrEmpty(file.OpenError);

                string name = Path.GetFileName(file.FilePath);
                string dir  = Path.GetDirectoryName(file.FilePath);

                SizeF size = g.MeasureString(name, _BoldFont);

                g.DrawString(name, _BoldFont, _FgBrush, rcText);

                rcText.Y += (int)(size.Height + 2);
                g.DrawString(dir, e.Font, _FgBrush, rcText);

                if (bError)
                {
                    rcText.Y += (int)(size.Height + 2);
                    g.DrawString(file.OpenError, e.Font, _FgBrushError, rcText);
                }

                g.ResetClip();
            }
        }
示例#3
0
        // ********************************************************************************
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        /// <created>UPh,07.11.2015</created>
        /// <changed>UPh,07.11.2015</changed>
        // ********************************************************************************
        protected override void OnMeasureItem(MeasureItemEventArgs e)
        {
            if (DesignMode)
            {
                return;
            }

            if (_TextHeight == 0)
            {
                SizeF size = e.Graphics.MeasureString("X", Font);
                _TextHeight = (int)(2 + size.Height);
            }

            if (e.Index >= 0)
            {
                TermBaseFile file = Items[e.Index] as TermBaseFile;

                if (!string.IsNullOrEmpty(file.OpenError))
                {
                    e.ItemHeight = 5 + 3 * _TextHeight;
                }
                else
                {
                    e.ItemHeight = 5 + 2 * _TextHeight;
                }
            }
        }
        // ********************************************************************************
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        /// <created>UPh,01.11.2015</created>
        /// <changed>UPh,01.11.2015</changed>
        // ********************************************************************************
        private void btnRemove_Click(object sender, EventArgs e)
        {
            TermBaseFile file = lstFiles.SelectedItem as TermBaseFile;

            if (file == null)
            {
                return;
            }

            if (file.IsAutomatic)
            {
                MessageBox.Show("This file is added automatically,\n" +
                                "because it's in one of the configured term base folders.\n\n" +
                                "It cannot be removed from the list.\n" +
                                "Clear the activation check box if you don't want to use this file", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (MessageBox.Show("Do you want to remove this term base file from the list?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
            {
                return;
            }

            int index = _TermbaseSet.Files.IndexOf(file);

            if (index >= 0)
            {
                _TermbaseSet.Files.RemoveAt(index);
            }

            lstFiles.Items.RemoveAt(lstFiles.SelectedIndex);
            UpdateControls();

            DataChanged = true;
        }
        // ********************************************************************************
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        /// <created>UPh,04.10.2015</created>
        /// <changed>UPh,04.10.2015</changed>
        // ********************************************************************************
        private void btnAdd_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Filter = "Term base files|*.tbx;*.sdltb;*.csv|All files (*.*)|*.*";
                if (dlg.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                foreach (TermBaseFile file in _TermbaseSet.Files)
                {
                    if (string.Compare(file.FilePath, dlg.FileName, true) == 0)
                    {
                        MessageBox.Show("This file is already in the list.");
                        return;
                    }
                }

                TermBaseFile newfile = new TermBaseFile(dlg.FileName);
                newfile.Active = true;
                _TermbaseSet.Files.Add(newfile);

                int index = lstFiles.Items.Add(newfile);

                lstFiles.SelectedIndex = index;

                DataChanged = true;
            }
        }
        // ********************************************************************************
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        /// <created>UPh,01.11.2015</created>
        /// <changed>UPh,01.11.2015</changed>
        // ********************************************************************************
        void UpdateControls()
        {
            TermBaseFile file = lstFiles.SelectedItem as TermBaseFile;

            btnRemove.Enabled       = (file != null);
            btnDisplayColor.Enabled = (file != null);
        }
示例#7
0
        // ********************************************************************************
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        /// <created>UPh,29.08.2015</created>
        /// <changed>UPh,29.08.2015</changed>
        // ********************************************************************************
        private void DrawCheckBox(DrawItemEventArgs e, TermBaseFile file)
        {
            Rectangle rcCheck = GetCheckBoxRect(e.Index);

            Graphics g = e.Graphics;

            g.DrawImage(file.Active ? Resources.ImgageCheck : Resources.ImageUnCheck, rcCheck.Left, rcCheck.Top);
        }
示例#8
0
        // ********************************************************************************
        /// <summary>
        ///
        /// </summary>
        /// <param name="termbaseID"></param>
        /// <returns></returns>
        /// <created>UPh,31.10.2015</created>
        /// <changed>UPh,31.10.2015</changed>
        // ********************************************************************************
        public Color GetDisplayColor(int termbaseID)
        {
            TermBaseFile file = FindTermBaseID(termbaseID);

            if (file != null)
            {
                return(file.DisplayColor);
            }

            return(Color.Empty);
        }
示例#9
0
        // ********************************************************************************
        /// <summary>
        ///
        /// </summary>
        /// <param name="termbaseID"></param>
        /// <returns></returns>
        /// <created>UPh,01.11.2015</created>
        /// <changed>UPh,01.11.2015</changed>
        // ********************************************************************************
        public string GetDisplayName(int termbaseID)
        {
            TermBaseFile file = FindTermBaseID(termbaseID);

            if (file != null)
            {
                return(file.DisplayName);
            }

            return("");
        }
示例#10
0
        // ********************************************************************************
        /// <summary>
        /// Find a term base given by the attached TermBaseFile
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        /// <created>UPh,25.10.2015</created>
        /// <changed>UPh,25.10.2015</changed>
        // ********************************************************************************
        internal TermBase FindTermBase(TermBaseFile file)
        {
            foreach (TermBase tb in this)
            {
                if (tb.File == file)
                {
                    return(tb);
                }
            }

            return(null);
        }
        // ********************************************************************************
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        /// <created>UPh,07.11.2015</created>
        /// <changed>UPh,07.11.2015</changed>
        // ********************************************************************************
        void picker_ColorSelected(object sender, ColorSelectedEventArgs e)
        {
            TermBaseFile file = lstFiles.SelectedItem as TermBaseFile;

            if (file == null)
            {
                return;
            }

            file.DisplayColor = e.Color;
            lstFiles.Invalidate();

            DataChanged = true;
        }
        // ********************************************************************************
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        /// <created>UPh,01.11.2015</created>
        /// <changed>UPh,01.11.2015</changed>
        // ********************************************************************************
        private void btnDisplayColor_Click(object sender, EventArgs e)
        {
            TermBaseFile file = lstFiles.SelectedItem as TermBaseFile;

            if (file == null)
            {
                return;
            }

            Rectangle rc = btnDisplayColor.Bounds;

            rc = RectangleToScreen(rc);

            ColorPopup.Show(new Point(rc.Right, rc.Bottom), ToolStripDropDownDirection.BelowLeft);
        }
示例#13
0
        // ********************************************************************************
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        /// <created>UPh,29.08.2015</created>
        /// <changed>UPh,29.08.2015</changed>
        // ********************************************************************************
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (DesignMode)
            {
                return;
            }

            Graphics g = e.Graphics;

            if ((e.State & DrawItemState.Selected) != 0)
            {
                g.FillRectangle(_BkBrushSel, e.Bounds);
            }
            else
            {
                g.FillRectangle(_BkBrush, e.Bounds);
            }

            TermBaseFile file = null;

            if (e.Index >= 0)
            {
                file = Items[e.Index] as TermBaseFile;
            }

            if (_BoldFont == null)
            {
                _BoldFont = new Font(e.Font, FontStyle.Bold);
            }

            if (file != null)
            {
                Rectangle rcColor = e.Bounds;
                rcColor.Width = 4;
                SolidBrush brush = new SolidBrush(file.DisplayColor);
                e.Graphics.FillRectangle(brush, rcColor);


                DrawCheckBox(e, file);
                DrawText(e, file);
            }

            e.DrawFocusRectangle();
        }
示例#14
0
        // ********************************************************************************
        /// <summary>
        ///
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        /// <created>UPh,28.08.2015</created>
        /// <changed>UPh,28.08.2015</changed>
        // ********************************************************************************
        private void Load()
        {
            ClearData();
            if (!File.Exists(SettingsFile))
            {
                return;
            }

            using (XmlReader reader = XmlReader.Create(SettingsFile))
            {
                CXmlNode elRoot = new CXmlNode();
                if (!reader.ReadRootElement(ref elRoot))
                {
                    return;
                }

                CXmlNode elChild = new CXmlNode();
                while (elRoot.ReadChildNode(ref elChild))
                {
                    if (elChild.IsElement("termbases"))
                    {
                        CXmlNode elTermBase = new CXmlNode();
                        while (elChild.ReadChildNode(ref elTermBase, "file"))
                        {
                            string path;
                            bool   active;
                            if (elTermBase.GetAttribute("path", out path) &&
                                elTermBase.GetBoolAttribute("active", out active))
                            {
                                TermBaseFile file = new TermBaseFile(path);
                                file.Active = active;
                                Files.Add(file);

                                Color displayColor;
                                if (elTermBase.GetColorAttribute("display_color", out displayColor))
                                {
                                    file.DisplayColor = displayColor;
                                }
                            }
                        }
                    }
                }
            }
        }
示例#15
0
        // ********************************************************************************
        /// <summary>
        /// Create the correct term base instance, depending on the file extension
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        /// <created>UPh,25.10.2015</created>
        /// <changed>UPh,25.10.2015</changed>
        // ********************************************************************************
        static public TermBase CreateTermBase(TermBaseFile file)
        {
            try
            {
                file.OpenError = "";
                TermBase termBase = null;

                string ext = Path.GetExtension(file.StoragePath);

                if (string.Compare(ext, ".csv", true) == 0)
                {
                    termBase = new TermBaseCSV();
                }
                else if (string.Compare(ext, ".tbx", true) == 0)
                {
                    termBase = new TermBaseTBX();
                }
                else if (string.Compare(ext, ".sdltb", true) == 0)
                {
                    termBase = new TermBaseDB();
                }

                if (termBase != null)
                {
                    termBase.File = file;
                    termBase.OnOpenFile();
                }
                else
                {
                    file.OpenError = string.Format("Unknown term base type: {0}", ext);
                }

                return(termBase);
            }
            catch (Exception ex)
            {
                file.OpenError = ex.Message;
                return(null);
            }
        }
示例#16
0
        // ********************************************************************************
        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        /// <created>UPh,28.08.2015</created>
        /// <changed>UPh,28.08.2015</changed>
        // ********************************************************************************
        private void Load()
        {
            ClearData();
            if (!File.Exists(SettingsFile))
                return;

            using (XmlReader reader = XmlReader.Create(SettingsFile))
            {
                CXmlNode elRoot = new CXmlNode();
                if (!reader.ReadRootElement(ref elRoot))
                    return;

                CXmlNode elChild = new CXmlNode();
                while (elRoot.ReadChildNode(ref elChild))
                {
                    if (elChild.IsElement("termbases"))
                    {
                        CXmlNode elTermBase = new CXmlNode();
                        while (elChild.ReadChildNode(ref elTermBase, "file"))
                        {
                            string path;
                            bool active;
                            if (elTermBase.GetAttribute("path", out path) &&
                                elTermBase.GetBoolAttribute("active", out active))
                            {
                                TermBaseFile file = new TermBaseFile(path);
                                file.Active = active;
                                Files.Add(file);

                                Color displayColor;
                                if (elTermBase.GetColorAttribute("display_color", out displayColor))
                                    file.DisplayColor = displayColor;

                            }

                        }
                    }
                }
            }
        }
示例#17
0
 public ActiveChangedEventArgs(TermBaseFile file)
 {
     File = file;
 }
示例#18
0
        // ********************************************************************************
        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        /// <created>UPh,29.08.2015</created>
        /// <changed>UPh,29.08.2015</changed>
        // ********************************************************************************
        private void DrawCheckBox(DrawItemEventArgs e, TermBaseFile file)
        {
            Rectangle rcCheck = GetCheckBoxRect(e.Index);

            Graphics g = e.Graphics;
            g.DrawImage(file.Active ? Resources.ImgageCheck : Resources.ImageUnCheck, rcCheck.Left, rcCheck.Top);
        }
示例#19
0
        // ********************************************************************************
        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        /// <param name="g"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        /// <created>UPh,29.08.2015</created>
        /// <changed>UPh,29.08.2015</changed>
        // ********************************************************************************
        private void DrawText(DrawItemEventArgs e, TermBaseFile file)
        {
            Rectangle rcText = e.Bounds;
            Graphics g = e.Graphics;

            using (Region rgnClip = new Region(e.Bounds))
            {
                g.Clip = rgnClip;

                rcText.X += 30;
                rcText.Y += 2;

                bool bError = !string.IsNullOrEmpty(file.OpenError);

                string name = Path.GetFileName(file.FilePath);
                string dir = Path.GetDirectoryName(file.FilePath);

                SizeF size = g.MeasureString(name, _BoldFont);

                g.DrawString(name, _BoldFont, _FgBrush, rcText);

                rcText.Y += (int)(size.Height + 2);
                g.DrawString(dir, e.Font, _FgBrush, rcText);

                if (bError)
                {
                    rcText.Y += (int)(size.Height + 2);
                    g.DrawString(file.OpenError, e.Font, _FgBrushError, rcText);
                }

                g.ResetClip();
            }
        }
示例#20
0
 public ActiveChangedEventArgs(TermBaseFile file)
 {
     File = file;
 }
示例#21
0
        // ********************************************************************************
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        /// <created>UPh,29.08.2015</created>
        /// <changed>UPh,29.08.2015</changed>
        // ********************************************************************************
        private bool AddLocalFiles()
        {
            string localdir = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location);
            bool bChanged = false;

            List<string> searchfolders = new List<string>();
            for(int n = 1; n < 8; n++)
            {
                string pathvar = string.Format("TermBaseFolder{0}", n);
                string path = ConfigurationManager.AppSettings[pathvar];
                if (string.IsNullOrEmpty(path))
                    break;

                string searchpath;
                if (path.StartsWith("."))
                    searchpath = Path.GetFullPath(Path.Combine(localdir, path));
                else
                    searchpath = path;

                searchfolders.Add(searchpath);

                Environment.SetEnvironmentVariable(pathvar, searchpath);
            }

            // Hold local files to find which one can be deleted
            List<TermBaseFile> localFiles = new List<TermBaseFile>();
            foreach (TermBaseFile file in Files)
            {
                if (file.IsAutomatic)
                    localFiles.Add(file);
            }

            // Loop directories where we expect termbases
            for (int iRelDir = 0; iRelDir < searchfolders.Count; iRelDir++)
            {
                string reldir = searchfolders[iRelDir];

                string searchpath;
                if (reldir.StartsWith("."))
                    searchpath = Path.GetFullPath(Path.Combine(localdir, reldir));
                else
                    searchpath = reldir;
                if (!Directory.Exists(searchpath))
                    continue;

                // Collect files in that directory
                var filteredFiles = Directory
                    .EnumerateFiles(searchpath)
                    .Where(file => string.Compare(Path.GetExtension(file), ".tbx", true) == 0 ||
                                   string.Compare(Path.GetExtension(file), ".sdltb", true) == 0 ||
                                   string.Compare(Path.GetExtension(file), ".csv", true) == 0)
                    .ToList();

                // Loop files
                foreach (string filepath in filteredFiles)
                {
                    string storagePath = string.Format("%TermBaseFolder{0}%\\{1}", iRelDir + 1,
                        Path.GetFileName(filepath));

                    TermBaseFile existingFile = FindStoragePath(storagePath);
                    if (existingFile == null)
                    {
                        // Add new file
                        existingFile = new TermBaseFile(storagePath);
                        existingFile.Active = true;
                        Files.Add(existingFile);
                        bChanged = true;
                    }
                    else
                    {
                        // Remove from localFiles
                        int inx = localFiles.IndexOf(existingFile);
                        if (inx >= 0)
                            localFiles.RemoveAt(inx);
                    }
                }
            }

            // Remove remaining local files
            foreach (TermBaseFile file in localFiles)
            {
                int inx = Files.IndexOf(file);
                if (inx >= 0)
                {
                    Files.RemoveAt(inx);
                }
            }

            return bChanged;
        }
示例#22
0
        // ********************************************************************************
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        /// <created>UPh,29.08.2015</created>
        /// <changed>UPh,29.08.2015</changed>
        // ********************************************************************************
        private bool AddLocalFiles()
        {
            string localdir = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location);
            bool   bChanged = false;

            List <string> searchfolders = new List <string>();

            for (int n = 1; n < 8; n++)
            {
                string pathvar = string.Format("TermBaseFolder{0}", n);
                string path    = ConfigurationManager.AppSettings[pathvar];
                if (string.IsNullOrEmpty(path))
                {
                    break;
                }



                string searchpath;
                if (path.StartsWith("."))
                {
                    searchpath = Path.GetFullPath(Path.Combine(localdir, path));
                }
                else
                {
                    searchpath = path;
                }

                searchfolders.Add(searchpath);

                Environment.SetEnvironmentVariable(pathvar, searchpath);
            }

            // Hold local files to find which one can be deleted
            List <TermBaseFile> localFiles = new List <TermBaseFile>();

            foreach (TermBaseFile file in Files)
            {
                if (file.IsAutomatic)
                {
                    localFiles.Add(file);
                }
            }

            // Loop directories where we expect termbases
            for (int iRelDir = 0; iRelDir < searchfolders.Count; iRelDir++)
            {
                string reldir = searchfolders[iRelDir];

                string searchpath;
                if (reldir.StartsWith("."))
                {
                    searchpath = Path.GetFullPath(Path.Combine(localdir, reldir));
                }
                else
                {
                    searchpath = reldir;
                }
                if (!Directory.Exists(searchpath))
                {
                    continue;
                }

                // Collect files in that directory
                var filteredFiles = Directory
                                    .EnumerateFiles(searchpath)
                                    .Where(file => string.Compare(Path.GetExtension(file), ".tbx", true) == 0 ||
                                           string.Compare(Path.GetExtension(file), ".sdltb", true) == 0 ||
                                           string.Compare(Path.GetExtension(file), ".csv", true) == 0)
                                    .ToList();

                // Loop files
                foreach (string filepath in filteredFiles)
                {
                    string storagePath = string.Format("%TermBaseFolder{0}%\\{1}", iRelDir + 1,
                                                       Path.GetFileName(filepath));

                    TermBaseFile existingFile = FindStoragePath(storagePath);
                    if (existingFile == null)
                    {
                        // Add new file
                        existingFile        = new TermBaseFile(storagePath);
                        existingFile.Active = true;
                        Files.Add(existingFile);
                        bChanged = true;
                    }
                    else
                    {
                        // Remove from localFiles
                        int inx = localFiles.IndexOf(existingFile);
                        if (inx >= 0)
                        {
                            localFiles.RemoveAt(inx);
                        }
                    }
                }
            }

            // Remove remaining local files
            foreach (TermBaseFile file in localFiles)
            {
                int inx = Files.IndexOf(file);
                if (inx >= 0)
                {
                    Files.RemoveAt(inx);
                }
            }

            return(bChanged);
        }
示例#23
0
        // ********************************************************************************
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        /// <created>UPh,04.10.2015</created>
        /// <changed>UPh,04.10.2015</changed>
        // ********************************************************************************
        private void btnAdd_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dlg = new OpenFileDialog())
            {
                dlg.Filter = "Term base files|*.tbx;*.sdltb;*.csv|All files (*.*)|*.*";
                if (dlg.ShowDialog() != DialogResult.OK)
                    return;

                foreach (TermBaseFile file in _TermbaseSet.Files)
                {
                    if (string.Compare(file.FilePath, dlg.FileName, true) == 0)
                    {
                        MessageBox.Show("This file is already in the list.");
                        return;
                    }
                }

                TermBaseFile newfile = new TermBaseFile(dlg.FileName);
                newfile.Active = true;
                _TermbaseSet.Files.Add(newfile);

                int index = lstFiles.Items.Add(newfile);

                lstFiles.SelectedIndex = index;

                DataChanged = true;
            }
        }