Пример #1
0
 /// <summary>
 /// TabPages右键点击弹出菜单
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void listView1MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         //绑定前先清空菜单
         strip.Items.Clear();
         //绑定tabPage右键菜单
         strip.Items.Add("移动到");
         strip.Items.Add("删除此快捷方式");
         //绑定"移动到"的子级菜单,即从json获取所有tabPage名称
         JObject jobject = JsonHelper.readJson();
         foreach (JToken child in jobject["Settings"]["tabControl_Main"].Children())
         {
             if (child.Count() != 0)
             {
                 string tabpagename = JsonHelper.GetJsonValue(child.Children(), "tabpagename");
                 if (tabpagename != tabControl_Main.SelectedTab.Text)
                 {
                     ToolStripItem stripitem = new ToolStripMenuItem();
                     stripitem.Name   = tabpagename;
                     stripitem.Text   = tabpagename;
                     stripitem.Click += new EventHandler(itemClicked);
                     /*只能通过ContextMenuStrip的Item的索引为其添加子菜单,通过Item的Text属性会报错*/
                     ((ToolStripDropDownItem)(strip.Items[0])).DropDownItems.Add(stripitem);
                 }
             }
         }
         strip.Show(listView1, e.Location);//鼠标右键按下弹出菜单
     }
 }
Пример #2
0
        private void LoadTabControl_Main()
        {
            tabControl_Main.TabPages.Clear();
            //foreach the JObject add the value
            JObject jobject = JsonHelper.readJson();

            foreach (JToken child in jobject["Settings"]["tabControl_Main"].Children())
            {
                if (child.Count() != 0)
                {
                    string tabpageid    = JsonHelper.GetJsonValue(child.Children(), "tabpageid");
                    string tabpagename  = JsonHelper.GetJsonValue(child.Children(), "tabpagename");
                    string tabpageindex = JsonHelper.GetJsonValue(child.Children(), "tabpageindex");
                    //if(tabpageid != "tabPage_default")
                    //{
                    //tabControl_Main.TabPages.Insert(int.Parse(tabpageindex), tabpagename);
                    TabPage Page = new TabPage();
                    Page.Name     = tabpageid;
                    Page.Text     = tabpagename;
                    Page.TabIndex = int.Parse(tabpageindex);
                    Page.Tag      = "386;620;0;0;9";
                    this.tabControl_Main.Controls.Add(Page);
                    //}
                }
            }
            MatchTabPage(tabControl_Main.SelectedTab.Text);
            listView1.MouseClick += new MouseEventHandler(listView1MouseClick);
            strip.ItemClicked    += new ToolStripItemClickedEventHandler(stripItemClicked);
        }
Пример #3
0
        public static List <TabPages> GetJsonList(JEnumerable <JToken> jToken, string key)
        {
            JObject jsonObj = JsonHelper.readJson();
            //foreach the JObject add the value
            List <TabPages> tabpageindexlist = new List <TabPages>()
            {
            };

            //List<string> tabpageindexlist = new List<string>();
            foreach (JToken child in jToken)
            {
                if (child.Count() != 0)
                {
                    string tabpageid    = JsonHelper.GetJsonValue(child.Children(), "tabpageid");
                    string tabpagename  = JsonHelper.GetJsonValue(child.Children(), "tabpagename");
                    int    tabpageindex = int.Parse(JsonHelper.GetJsonValue(child.Children(), "tabpageindex"));
                    tabpageindexlist.Add(new TabPages()
                    {
                        tabpageid = tabpageid, tabpagename = tabpagename, tabpageindex = tabpageindex
                    });
                    //tabpageindexlist.Add(JsonHelper.GetJsonValue(child.Children(), "tabpageindex"));
                }
            }
            return(tabpageindexlist);
        }
Пример #4
0
        /// <summary>
        /// "移动到"子级菜单点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void itemClicked(object sender, EventArgs e)
        {
            JObject       jobject = JsonHelper.readJson();
            ToolStripItem item    = (ToolStripItem)sender;

            Console.WriteLine(item.Text + " : " + listView1.SelectedItems[0].Text);
            JsonHelper.SetListviewJson(jobject, listView1.SelectedItems[0].Text, "apptag", item.Text, 0);
            LoadImageList();
        }
Пример #5
0
        /// <summary>
        /// "删除此快捷方式"点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void stripItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem.Text == "删除此快捷方式")
            {
                Console.WriteLine(e.ClickedItem.Text + " : " + listView1.SelectedItems[0].Text);

                JObject jobject = JsonHelper.readJson();
                JsonHelper.DeleteListviewJson(jobject, listView1.SelectedItems[0].Text, 0);
                LoadImageList();
            }
        }
Пример #6
0
        //private void LoadImageList(string filePath)
        //{
        //    ////for test
        //    //var path = Environment.CurrentDirectory + "\\Images\\";
        //    //var list = new List<string>();
        //    //list.Add("close.ico");
        //    //list.Add("logo2.ico");
        //    //list.Add("settings2.ico");

        //    //ImageList imageList1 = new ImageList();
        //    //imageList1.ImageSize = new Size(48, 48);
        //    //imageList1.ColorDepth = ColorDepth.Depth32Bit;
        //    //foreach (var fileName in list)
        //    //{
        //    //    imageList1.Images.Add(Image.FromFile(path + fileName));
        //    //}

        //    //filePath = GetFilePath(@"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Notepad++\Notepad++.lnk");

        //    filePath = GetFilePath(filePath);
        //    if (filePath != "")
        //    {
        //        ImageList imageList1 = new ImageList();
        //        imageList1.ImageSize = new Size(48, 48);
        //        imageList1.ColorDepth = ColorDepth.Depth32Bit;
        //        imageList1.Images.Add(Icon.ExtractAssociatedIcon(filePath));
        //        listView1.LargeImageList = imageList1;

        //        for (int i = 0; i < imageList1.Images.Count; i++)
        //        {
        //            var lvi = new ListViewItem();
        //            lvi.ImageIndex = i;
        //            lvi.Text = Path.GetFileNameWithoutExtension(filePath);//"P" + i;
        //            lvi.ToolTipText = Path.GetFileNameWithoutExtension(filePath);//"P" + i;
        //            listView1.Items.Add(lvi);
        //        }
        //    }
        //    else
        //    {
        //        MessageBox.Show("该目录不存在!");
        //    }
        //}
        private void LoadImageList()
        {
            imageList1.Images.Clear();
            listView1.Clear();
            MatchTabPage(tabControl_Main.SelectedTab.Text);
            //foreach the JObject add the value
            JObject       jobject      = JsonHelper.readJson();
            int           count        = 0;
            List <string> apptitlelist = new List <string>();
            List <string> apppathlist  = new List <string>();

            foreach (JToken child in jobject["AppListModel"].Children())
            {
                if (child.Count() != 0)
                {
                    if (tabControl_Main.SelectedTab.Text.Equals(JsonHelper.GetJsonValue(child.Children(), "apptag")))
                    {
                        count++;
                        string apptitle = JsonHelper.GetJsonValue(child.Children(), "apptitle");
                        apptitlelist.Add(JsonHelper.GetJsonValue(child.Children(), "apptitle"));
                        string apppath = JsonHelper.GetJsonValue(child.Children(), "appiconpath").Replace("/", "\\");
                        apppathlist.Add(apppath);
                        string appiconpath = apppath;
                        if (JsonHelper.GetJsonValue(child.Children(), "apptype").Equals(".lnk"))
                        {
                            appiconpath = GetFilePath(apppath);
                        }
                        if (appiconpath != "")
                        {
                            //ImageList imageList1 = new ImageList();
                            imageList1.ImageSize  = new Size(48, 48);
                            imageList1.ColorDepth = ColorDepth.Depth32Bit;
                            //imageList1.Images.Add(Icon.ExtractAssociatedIcon(appiconpath));
                            imageList1.Images.Add(GetIcon(appiconpath));
                        }
                        else
                        {
                            MessageBox.Show("该目录不存在!");
                        }
                    }
                }
            }
            listView1.LargeImageList = imageList1;

            for (int i = 0; i < imageList1.Images.Count; i++)
            {
                var lvi = new ListViewItem();
                lvi.ImageIndex  = i;
                lvi.Text        = apptitlelist[i]; //Path.GetFileNameWithoutExtension(filePath);//"P" + i;
                lvi.ToolTipText = apppathlist[i];  //Path.GetFileNameWithoutExtension(filePath);//"P" + i;
                listView1.Items.Add(lvi);
            }
        }
Пример #7
0
        private void checkBox_isautobackup_CheckedChanged(object sender, EventArgs e)
        {
            JObject jobject = JsonHelper.readJson();

            if (isautobackup != checkBox_isautobackup.Checked.ToString().ToLower())
            {
                isautobackup = checkBox_isautobackup.Checked.ToString().ToLower();
                if (JsonHelper.SetShortcutKeyJsonValue(jobject, "isautobackup", isautobackup))
                {
                    MessageBox.Show("修改成功!");
                }
            }
        }
Пример #8
0
        private void LoadTabPages()
        {
            listView1.Clear();
            DisableEdit();

            //ColumnHeader ch = new ColumnHeader();
            //ch.Text = "选项卡ID";   //设置列标题
            //ch.Width = 120;    //设置列宽度
            //ch.TextAlign = HorizontalAlignment.Left;   //设置列的对齐方式
            //this.listView1.Columns.Add(ch);    //将列头添加到ListView控件。
            this.listView1.Columns.Add("选项卡ID", 140, HorizontalAlignment.Left); //一步添加
            this.listView1.Columns.Add("选项卡名称", 100, HorizontalAlignment.Left); //一步添加
            this.listView1.Columns.Add("选项卡排序", 100, HorizontalAlignment.Left); //一步添加
            this.listView1.View = View.Details;

            this.listView1.BeginUpdate();   //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度
            //从json文件读取数据
            JObject       jsonObj      = JsonHelper.readJson();
            int           count        = 0;
            List <string> apptitlelist = new List <string>();
            List <string> apppathlist  = new List <string>();

            foreach (JToken child in jsonObj["Settings"]["tabControl_Main"].Children())
            {
                if (child.Count() != 0)
                {
                    count++;
                    string       tabpageid    = JsonHelper.GetJsonValue(child.Children(), "tabpageid");
                    string       tabpagename  = JsonHelper.GetJsonValue(child.Children(), "tabpagename");
                    string       tabpageindex = JsonHelper.GetJsonValue(child.Children(), "tabpageindex");
                    ListViewItem lvi          = new ListViewItem();
                    lvi.ImageIndex = count;     //通过与imageList绑定,显示imageList中第i项图标
                    lvi.Text       = tabpageid;
                    lvi.SubItems.Add(tabpagename);
                    lvi.SubItems.Add(tabpageindex);
                    this.listView1.Items.Add(lvi);
                }
            }
            ////测试数据foreach the JObject add the value
            //for (int i = 0; i < 10; i++)   //添加10行数据
            //{
            //    ListViewItem lvi = new ListViewItem();
            //    lvi.ImageIndex = i;     //通过与imageList绑定,显示imageList中第i项图标
            //    lvi.Text = "subitem" + i;
            //    lvi.SubItems.Add("第2列,第" + i + "行");
            //    lvi.SubItems.Add("第3列,第" + i + "行");
            //    this.listView1.Items.Add(lvi);
            //}
            this.listView1.EndUpdate();  //结束数据处理,UI界面一次性绘制。
        }
Пример #9
0
        private void LoadIsAutoBackup()
        {
            JObject jobject = JsonHelper.readJson();

            isautobackup = JsonHelper.GetJsonValue(jobject["Settings"].Children(), "isautobackup");
            if (isautobackup == "false")
            {
                checkBox_isautobackup.Checked = false;
            }
            else
            {
                checkBox_isautobackup.Checked = true;
            }
        }
Пример #10
0
        private void btn_Edit_Click(object sender, EventArgs e)
        {
            if (btn_Edit.Text == "编辑")
            {
                if (txt_tabpageid.Text != "")
                {
                    EnableEdit();
                    btn_Edit.Text = "保存";
                }
                else
                {
                    MessageBox.Show("请先点击一条TabPage记录!");
                }
            }
            else
            {
                if (txt_tabpageid.Text != "" &&
                    txt_tabpagename.Text != "" &&
                    txt_tabpageindex.Text != "")
                {
                    if (txt_tabpageid.Text != lbl_tabpageid.Text ||
                        txt_tabpagename.Text != lbl_tabpagename.Text ||
                        txt_tabpageindex.Text != lbl_tabpageindex.Text)
                    {
                        JObject jobject = JsonHelper.readJson();
                        if (JsonHelper.SetTabPageJsonValue(jobject, txt_tabpageid.Text, "tabpagename", txt_tabpagename.Text, 0) &&
                            JsonHelper.SetTabPageJsonValue(jobject, txt_tabpageid.Text, "tabpageindex", txt_tabpageindex.Text, 0))
                        {
                            JsonHelper.UpdateTabPagename("edit", jobject, "apptag", lbl_tabpagename.Text, txt_tabpagename.Text, 0);
                            MessageBox.Show("修改成功!");
                        }
                        LoadTabPages();

                        if (MyEvent != null)
                        {
                            MyEvent("修改成功");//触发事件
                        }
                    }
                    else
                    {
                        MessageBox.Show("数据未更改!");
                        DisableEdit();
                        btn_Edit.Text = "编辑";
                    }
                    Cancel();
                }
            }
        }
Пример #11
0
        private void LoadShortcutKey()
        {
            JObject jobject     = JsonHelper.readJson();
            string  shortcutkey = JsonHelper.GetJsonValue(jobject["Settings"].Children(), "shortcutkey");

            txt_shortcutkey.Text = shortcutkey;
            lbl_shortcutkey.Text = shortcutkey;

            isdoubleclick          = JsonHelper.GetJsonValue(jobject["Settings"].Children(), "isdoubleclick");
            lbl_isdoubleclick.Text = isdoubleclick;
            if (isdoubleclick == "false")
            {
                radioButton1.Checked = true;
            }
            else
            {
                radioButton2.Checked = true;
            }
        }
Пример #12
0
 private void AutoBackup(object sender, System.Timers.ElapsedEventArgs elap)
 {
     try
     {
         JObject jobject      = JsonHelper.readJson();
         string  isautobackup = JsonHelper.GetJsonValue(jobject["Settings"].Children(), "isautobackup");
         if (isautobackup == "true")
         {
             string jsonPath      = Environment.CurrentDirectory + "\\resourse.json";
             string directionPath = Environment.CurrentDirectory + "\\Backup\\resourse.json";
             FileHelper.CopyFile(jsonPath, directionPath, true);
             Console.WriteLine("备份成功!");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("e.Message: " + e.Message + ";e.StackTrace: " + e.StackTrace);
     }
 }
Пример #13
0
 private void button_apply_Click(object sender, EventArgs e)
 {
     if (txt_shortcutkey.Text != lbl_shortcutkey.Text)
     {
         JObject jobject = JsonHelper.readJson();
         if (JsonHelper.SetShortcutKeyJsonValue(jobject, "shortcutkey", txt_shortcutkey.Text))
         {
             MessageBox.Show("修改成功!");
         }
     }
     else if (isdoubleclick != lbl_isdoubleclick.Text)
     {
         JObject jobject = JsonHelper.readJson();
         if (JsonHelper.SetShortcutKeyJsonValue(jobject, "isdoubleclick", isdoubleclick))
         {
             MessageBox.Show("修改成功!");
         }
     }
     this.Close();
 }
Пример #14
0
        /// <summary>
        /// 判断拖进来快捷方式是否存在
        /// </summary>
        /// <param name="file">拖进来的快捷方式路径</param>
        /// <returns></returns>
        private bool IsExist(string file)
        {
            bool    flag     = false;
            JObject jobject  = JsonHelper.readJson();
            var     apppaths = from applistmodel in jobject["AppListModel"].Children().Children().Children()
                               select applistmodel["appiconpath"];

            foreach (var apppath in apppaths)
            {
                Console.WriteLine(apppath);
                if (file.Equals(apppath.ToString().Replace("/", "\\")))
                {
                    return(true);
                }
                else
                {
                    flag = false;
                }
            }

            //foreach (JToken child in jsonObj["AppListModel"].Children())
            //{
            //    if (child.Count() != 0)
            //    {
            //        if (file.Equals(JsonHelper.GetJsonValue(child.Children(), "appiconpath")))
            //            return true;
            //        else
            //            flag = false;
            //    }
            //}
            //foreach (ListViewItem item in listView1.Items)   //需要对所有tabpage里的图标及进行循环
            //{
            //    if (item.ToolTipText.Equals(file))
            //        return true;
            //    else
            //        flag = false;
            //}
            return(flag);
        }
Пример #15
0
 private void btn_Delete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("删除此选项卡会将此选项卡内的快捷方式全部删除,请先确认是否删除此选项卡?", "删除", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
     {
         JObject jobject = JsonHelper.readJson();
         if (JsonHelper.DeleteTabPageJsonValue(jobject, txt_tabpageid.Text, 0))
         {
             JsonHelper.UpdateTabPagename("delete", jobject, "apptag", lbl_tabpagename.Text, txt_tabpagename.Text, 0);
             MessageBox.Show("删除成功!");
             LoadTabPages();
             if (MyEvent != null)
             {
                 MyEvent("删除成功");//触发事件
             }
         }
         else
         {
             MessageBox.Show("删除失败!");
         }
         Cancel();
     }
 }
Пример #16
0
        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            JObject jobject = JsonHelper.readJson();

            if (JsonHelper.GetJsonValue(jobject["Settings"].Children(), "isdoubleclick") == "true")
            {
                if (this.listView1.SelectedItems.Count == 0)
                {
                    return;
                }

                //前提,listview禁止多选
                ListViewItem currentRow = listView1.SelectedItems[0];
                if (currentRow.ToolTipText.LastIndexOf(".lnk") > 0)
                {
                    System.Diagnostics.Process.Start(GetFilePath(currentRow.ToolTipText));
                }
                else
                {
                    System.Diagnostics.Process.Start(currentRow.ToolTipText);
                }
            }
        }
Пример #17
0
        private void SetShortcutKey()
        {
            JObject jobject = JsonHelper.readJson();

            shortcutkey = JsonHelper.GetJsonValue(jobject["Settings"].Children(), "shortcutkey");
        }