Ejemplo n.º 1
0
        public void RefreshResource()
        {
            string v = CCommon.GetValue(CCommon.key_tableP);

            if (Directory.Exists(v))
            {
                #region 1.file ext
                List <string> p       = new List <string>();
                bool          isExcel = CCommon.GetValue(CCommon.key_fileExcel) == "1";
                bool          isTxt   = CCommon.GetValue(CCommon.key_fileTxt) == "1";
                bool          isCode  = CCommon.GetValue(CCommon.key_fileCode) == "1";
                if (isExcel)
                {
                    p.Add(".xlsm");
                }
                if (isTxt)
                {
                    p.Add(".txt");
                }
                if (isCode)
                {
                    p.Add(".cs");
                }
                #endregion

                #region 2. filter is change the root path
                if (m_ResItems.Count > 0)
                {
                    if (m_ResItems.First().Path != v)
                    {
                        m_ResItems.Clear();
                    }
                }
                CResourceItem resItemRoot;
                if (m_ResItems.Count > 0)
                {
                    resItemRoot = m_ResItems[0];
                }
                else
                {
                    resItemRoot = new CResourceItem();
                    string curName = System.IO.Path.GetFileName(v);
                    resItemRoot.Icon        = CCommon.StrFolderIconPath;
                    resItemRoot.DisplayName = curName;
                    resItemRoot.Path        = v;
                    m_ResItems.Add(resItemRoot);
                }
                m_ResManager.GetResources(v, resItemRoot, p.ToArray());
                tw_item.ItemsSource = m_ResItems;
                if (tw_item.ItemContainerGenerator.Items.Count > 0)
                {
                    TreeViewItem ti = (TreeViewItem)(tw_item.ItemContainerGenerator.ContainerFromIndex(0));
                    if (ti != null)
                    {
                        ti.IsExpanded = true;
                    }
                }
                #endregion
            }
        }
Ejemplo n.º 2
0
        private void MenuItem_CodeGenerate_Click(object sender, RoutedEventArgs e)
        {
            CResourceItem obj = m_CurSelectedResItem.DataContext as CResourceItem;
            CResourceItem ri  = obj as CResourceItem;

            if (ri != null)
            {
                //if (File.Exists(ri.Path))
                //{
                //    Ensure ensure = new Ensure();
                //    ensure.Init("全部覆盖原有文件吗?");
                //    ensure.ShowDialog();
                //}
                //else
                //{
                //    ThreadPool.QueueUserWorkItem((o) =>
                //    {

                //    }, ri);
                //}
                ThreadPool.QueueUserWorkItem((o) =>
                {
                    m_CodeManager.CreateCode(ri.Path);
                }, ri);
            }
        }
Ejemplo n.º 3
0
        private void MenuItem_ExportTable_Click(object sender, RoutedEventArgs e)
        {
            CResourceItem obj = m_CurSelectedResItem.DataContext as CResourceItem;

            ThreadPool.QueueUserWorkItem((o) =>
            {
                DateTime start   = DateTime.Now;
                CResourceItem ri = o as CResourceItem;
                if (ri != null)
                {
                    if (Directory.Exists(ri.Path))
                    {
                        m_TableManager.ExportTables(ri.Path);
                    }
                    else
                    {
                        if (File.Exists(ri.Path))
                        {
                            m_TableManager.ExportTable(ri.Path);
                        }
                    }
                }
                string time = "用时" + DateTime.Now.Subtract(start).TotalSeconds + "秒";
                Clog.Instance.Log(time);
            }, obj);
        }
Ejemplo n.º 4
0
 private void MenuItem_OpenFileExplore(object sender, RoutedEventArgs e)
 {
     if (m_CurSelectedResItem != null)
     {
         CResourceItem ri = m_CurSelectedResItem.DataContext as CResourceItem;
         if (ri != null)
         {
             string dir = System.IO.Path.GetDirectoryName(ri.Path);
             Process.Start("explorer.exe ", dir);
         }
     }
 }
Ejemplo n.º 5
0
 private void MenuItem_Delete(object sender, RoutedEventArgs e)
 {
     if (m_CurSelectedResItem != null)
     {
         CResourceItem ri = m_CurSelectedResItem.DataContext as CResourceItem;
         if (ri != null)
         {
             EFileFlag f = CFileManager.Delete(ri.Path);
             if (f == EFileFlag.Success)
             {
                 RefreshResource();
             }
         }
     }
 }
Ejemplo n.º 6
0
 private void MenuItem_Create_Text(object sender, RoutedEventArgs e)
 {
     if (m_CurSelectedResItem != null)
     {
         CResourceItem ri = m_CurSelectedResItem.DataContext as CResourceItem;
         if (ri != null)
         {
             CreateNew c = new CreateNew();
             c.ShowDialog();
             if (!string.IsNullOrEmpty(c.InputName))
             {
                 EFileFlag f = CFileManager.CreateFile(ri.Path, c.InputName, EFileType.Text);
                 if (f == EFileFlag.Success)
                 {
                     RefreshResource();
                 }
             }
         }
     }
 }
Ejemplo n.º 7
0
        private void ResItem_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (sender is TreeViewItem)
            {
                if (!((TreeViewItem)sender).IsSelected)
                {
                    return;
                }
            }
            TreeViewItem tviSender = sender as TreeViewItem;

            if (tviSender != null)
            {
                CResourceItem ri = tviSender.DataContext as CResourceItem;
                if (ri != null)
                {
                    if (File.Exists(ri.Path))
                    {
                        Process.Start("explorer.exe ", ri.Path);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public void GetResources(string dir, CResourceItem res, string[] p)
        {
            if (Directory.Exists(dir))
            {
                #region dir
                string[]             ds  = Directory.GetDirectories(dir);
                string[]             fss = Directory.GetFiles(dir, "*.*");
                IEnumerable <string> fs  = fss.Where(f => p.Contains(Path.GetExtension(f).ToLower()));
                foreach (var c in res.Children)
                {
                    c.IsKeep = false;
                }
                foreach (var d in ds)
                {
                    bool          isNew   = true;
                    CResourceItem resItem = null;
                    foreach (var c in res.Children)
                    {
                        if (c.Path == d)
                        {
                            c.IsKeep = true;
                            resItem  = c;
                            isNew    = false;
                        }
                    }
                    if (isNew)
                    {
                        resItem = new CResourceItem();
                        string curName = Path.GetFileNameWithoutExtension(d);
                        resItem.Icon        = CCommon.StrFolderIconPath;
                        resItem.DisplayName = curName;
                        resItem.Path        = d;
                        resItem.IsKeep      = true;
                        res.Children.Add(resItem);
                    }
                    GetResources(d, resItem, p);
                }
                #endregion

                #region file
                foreach (var f in fs)
                {
                    bool isNew = true;
                    foreach (var c in res.Children)
                    {
                        if (c.Path == f)
                        {
                            c.IsKeep = true;
                            isNew    = false;
                        }
                    }
                    if (isNew)
                    {
                        if (f.Contains("~$"))
                        {
                            continue;
                        }
                        CResourceItem resItem = new CResourceItem();
                        string        curName = Path.GetFileNameWithoutExtension(f);
                        resItem.Icon        = CCommon.StrExcelIconPath;
                        resItem.DisplayName = curName;
                        resItem.Path        = f;
                        resItem.IsKeep      = true;
                        res.Children.Add(resItem);
                    }
                }
                #endregion

                #region Remove
                m_CacheResItems.Clear();
                foreach (var item in res.Children)
                {
                    if (!item.IsKeep)
                    {
                        m_CacheResItems.Add(item);
                    }
                }
                foreach (var item in m_CacheResItems)
                {
                    res.Children.Remove(item);
                }
                #endregion
            }
        }