Exemple #1
0
        private void TagTreeView_MouseDown(object sender, MouseEventArgs e)
        {
            var      pt = new Point(e.X, e.Y);
            TreeNode DestinationNode = ((TreeView)sender).GetNodeAt(pt);

            ((TreeView)sender).SelectedNode = DestinationNode;

            TreeNode selnode = ((TreeView)sender).SelectedNode;

            if (selnode != null && selnode.Tag != null)
            {
                if (e.Button == MouseButtons.Left)
                {
                    var selecttag = (string)selnode.Tag;
                    var listview  = getActiveListView();
                    if (listview == null)
                    {
                        var tabpage = OpenNewTab(selecttag);
                        listview = tabListviewMap[tabpage];

                        //FileListView<TableData> filelistview = listview as FileListView<TableData>;
                        //filelistview.inputData(datas);
                        //filelistview.setitem();
                        //OpenNewTab(tagdb.selectFileData(new string[] { (string)selnode.Tag }), (string)selnode.Tag);
                    }
                    else
                    {
                        getTabControl().SelectedTab.Text = selecttag;

                        //getTabControl().SelectedTab.Text = (string)selnode.Tag;
                        //listview.Items.Clear();
                        //UpdateListView(listview, tagdb.selectFileData(new string[] { (string)selnode.Tag }));
                    }

                    var datas = new List <TableData>();
                    using (FileDataModelContainer db = new FileDataModelContainer()) {
                        //db.FileTable.Where(c => c.ext == "ok").Select(s => s);
                        var query = from c in db.FileTable
                                    where c.TagTable.Any(t => t.tag.Contains(selecttag))
                                    select c;
                        foreach (FileTable f in query)
                        {
                            string stag = String.Empty;

                            var tagquery = from c in db.TagTable
                                           where c.FileTable.filetableid == f.filetableid
                                           select c.tag;

                            datas.Add(new TableData(f.guid, f.name, f.size, f.ext, tagquery.ToList <string>(), f.comment, f.creationtime, f.lastwritetime));
                        }
                    }

                    FileListView <TableData> filelistview = listview as FileListView <TableData>;
                    filelistview.inputData(datas);
                    filelistview.setitem();
                }
                else if (e.Button == MouseButtons.Middle)
                {
                    //OpenNewTab(tagdb.selectFileData(new string[] { (string)selnode.Tag }), (string)selnode.Tag);
                }
            }
        }
Exemple #2
0
        public MainForm()
        {
            InitializeComponent();

            setDetailView();

            AddTagMenuItem.Click += (sender, e) =>
            {
                InputForm    input = new InputForm();
                DialogResult res   = input.ShowDialog(this);
                if (res == DialogResult.OK)
                {
                    string tag = input.input;
                    if (tag.Length > 0)
                    {
                        //tagdb.insertTag(new string[] { input.input });
                        //IEnumerable<string> newtags = insertTags(new string[] { input.input });
                        string[] newtags = tag.Split(' ');
                        foreach (string newtag in newtags)
                        {
                            TreeNode tagnode = TagTreeView.Nodes["TagNode"].Nodes.Add(newtag);
                            tagnode.Tag = newtag;
                        }
                    }
                }
            };

            ToolStripMenuItem openfolder = new ToolStripMenuItem("open folder");

            openfolder.Click += (sender, e) => {
                var listview = getActiveListView() as FileListView <TableData>;
                var datas    = listview.getSelectItemData();
                if (datas.Count() > 0)
                {
                    string guid = datas.ElementAt(0).guid;
                    string path = Win32.getFullPathByObjectID(Win32.FILEGUID.parse(guid));

                    //ProcessStartInfo psi = new ProcessStartInfo();

                    //FileInfo info = new FileInfo(path);
                    //psi.FileName = info.Directory.FullName;
                    //psi.Verb = "open";
                    //System.Diagnostics.Process.Start(psi);
                    System.Diagnostics.Process.Start("EXPLORER.EXE", @"/select," + path);
                }
            };
            ListViewContextMenu.Items.Add(openfolder);

            ToolStripMenuItem openitem = new ToolStripMenuItem("open");

            openitem.Click += (sender, e) =>
            {
                var listview = getActiveListView() as FileListView <TableData>;
                var datas    = listview.getSelectItemData();
                if (datas.Count() > 0)
                {
                    string guid = datas.ElementAt(0).guid;
                    string path = Win32.getFullPathByObjectID(Win32.FILEGUID.parse(guid));
                    System.Diagnostics.Process.Start("Notepad", path);
                }
            };
            ListViewContextMenu.Items.Add(openitem);

            //tagdb.Connection();
            //tagdb.createTable();

            //sqlitewrap.Connection();
            createTable();

            //string[] tags = tagdb.getAllTags();
            IEnumerable <string> tags = getAllTags();
            TreeNode             node = TagTreeView.Nodes["TagNode"];

            foreach (string tag in tags)
            {
                TreeNode tagnode = node.Nodes.Add(tag);
                tagnode.Tag = tag;
            }

            getTabControl().Selecting += (sender, e) =>
            {
                if (tabListviewMap.ContainsKey(e.TabPage))
                {
                    ListViewPanel.Controls.Remove(tabListviewMap[e.TabPage]);
                }
            };

            getTabControl().Selected += (sender, e) =>
            {
                var control = ListViewPanel.Controls[0];
                if (control != null)
                {
                    ListViewPanel.Controls.Remove(control);
                }

                if (tabListviewMap.ContainsKey(e.TabPage))
                {
                    ListViewPanel.Controls.Add(tabListviewMap[e.TabPage]);
                }
            };

            SearchComboBox.KeyPress += (sender, e) =>
            {
                if (e.KeyChar == '\r')
                {
                    e.Handled = true;
                    string text = SearchComboBox.Text;

                    var tabpage  = OpenNewTab(text);
                    var listview = tabListviewMap[tabpage];
                    if (text.IndexOf(",") == -1)
                    {
                        var values = text.Split(' ', ' ');

                        var datas = new List <TableData>();

                        using (FileDataModelContainer db = new FileDataModelContainer()) {
                            //db.FileTable.Where(c => c.ext == "ok").Select(s => s);
                            //var query = from c in db.FileTable
                            //            where c.comment.Contains(text) || c.name.Contains(text) || c.TagTable.Any(t => t.tag.Contains(text))
                            //            select c;
                            //foreach (FileTable f in query) {
                            //    string stag = String.Empty;

                            //    var tagquery = from c in db.TagTable
                            //                   where c.FileTable.filetableid == f.filetableid
                            //                   select c.tag;

                            //    datas.Add(new TableData(f.guid, f.name, f.size, f.ext, tagquery.ToList<string>(), f.comment, f.creationtime, f.lastwritetime));
                            //}
                            string[] targets = { "name", "comment", "ext" };
                            var      query   = from c in db.FileTable
                                               select c;
                            var        contains  = typeof(string).GetMethod("Contains");
                            var        paramExpr = Expression.Parameter(typeof(FileTable), "c");
                            Expression mainExpr  = null;

                            foreach (string target in targets)
                            {
                                Expression bodyExpr = null;
                                foreach (var o in values)
                                {
                                    if (o.Length == 0)
                                    {
                                        continue;
                                    }

                                    if (bodyExpr == null)
                                    {
                                        // d.FileName.Contains("値")のコードと等価
                                        bodyExpr = Expression.Call(
                                            Expression.Property(paramExpr, target), contains, Expression.Constant(o)
                                            );
                                    }
                                    else
                                    {
                                        // 既に式があればOR演算する
                                        bodyExpr = Expression.AndAlso(
                                            bodyExpr,
                                            Expression.Call(
                                                Expression.Property(paramExpr, target), contains, Expression.Constant(o)
                                                )
                                            );
                                    }
                                }
                                if (mainExpr == null)
                                {
                                    mainExpr = bodyExpr;
                                }
                                else
                                {
                                    mainExpr = Expression.OrElse(mainExpr, bodyExpr);
                                }
                            }

                            if (values.Length != 0)
                            {
                                var res = query.Where(Expression.Lambda <Func <FileTable, bool> >(mainExpr, paramExpr));

                                foreach (FileTable f in res)
                                {
                                    string stag = String.Empty;

                                    var tagquery = from c in db.TagTable
                                                   where c.FileTable.filetableid == f.filetableid
                                                   select c.tag;

                                    datas.Add(new TableData(f.guid, f.name, f.size, f.ext, tagquery.ToList <string>(), f.comment, f.creationtime, f.lastwritetime));
                                }
                            }
                        }

                        FileListView <TableData> filelistview = listview as FileListView <TableData>;
                        filelistview.inputData(datas);
                        filelistview.setitem();
                    }
                    else
                    {
                        string[] strs = text.Split(',');
                    }
                    //OpenNewTab();
                }
            };
        }