コード例 #1
0
ファイル: MainView.cs プロジェクト: xyder/x-bookmark-tools
        private void mainTreeView_SelectionChanged(object sender, EventArgs e)
        {
            if (_ignoreTreeSelect)
            {
                _ignoreTreeSelect = false;
                return;
            }

            var bkm = (BookmarkItem)mainTreeView.SelectedObject;

            if (bkm != null)
            {
                var objects = _dbc.GetBookmarksChildren(bkm.Id);
                mainContentsView.SetObjects(objects);
                mainContentsView.RefreshObjects(objects);
                if (objects.Count > 0)
                {
                    if (_idToSelectInContentView == -1)
                    {
                        mainContentsView.SelectedIndex = 0;
                        mainContentsView.EnsureVisible(0);
                        _ignoreContentSelect = true;
                    }
                    else
                    {
                        foreach (var bi in (mainContentsView.Objects).Cast <BookmarkItem>()
                                 .Where(bi => bi.Id == _idToSelectInContentView))
                        {
                            mainContentsView.SelectObject(bi);
                            mainContentsView.EnsureModelVisible(bi);
                            break;
                        }
                        _idToSelectInContentView = -1;
                    }
                    mainContentsView.Focus();
                }
            }
            else
            {
                //disable deselection
                _ignoreTreeSelect           = true;
                mainTreeView.SelectedObject = _backupSelectedObjectTreeView;
            }

            EnableEdit(true);
            _mainEditPanel.SelectedBookmark = (BookmarkItem)mainTreeView.SelectedObject;
        }
コード例 #2
0
ファイル: MainView.cs プロジェクト: xyder/x-bookmark-tools
        /// <summary>
        /// Constructor for a MainView form object.
        /// </summary>
        /// <param name="logger">Message handler for all messages.</param>
        public MainView(Logger logger)
        {
            //TODO: split this into bits and see for code duplicate with duplicateview
            InitializeComponent();

            //initialize logger
            _logger = logger;
            _logger.MessageHandler += LogEventHandler;

            //OVERRIDE
            _dbfilename = "..\\places.sqlite";
            //OVERRIDE

            _duplicatesView = new DuplicatesView(_dbfilename);
            _duplicatesView.PathSelectionEvent += DuplicatesView_pathSelectionEvent;

            _dbc = new DbController(_dbfilename);
            _dbc.RefreshFoldersList();

            _mainEditPanel = new EditPanel(_dbc);
            _mainInfoPanel = new InfoPanel(_dbc);
            Controls.Add(_mainEditPanel);
            Controls.Add(_mainInfoPanel);
            _mainEditPanel.Parent = editContainerPanel;
            _mainEditPanel.Dock   = DockStyle.Fill;
            _mainInfoPanel.Parent = editContainerPanel;
            _mainInfoPanel.Dock   = DockStyle.Fill;

            //set up delegates for mainTreeView
            mainTreeView.CanExpandGetter = x => _dbc.HasChildrenBookmarks(((BookmarkItem)x).Id);
            mainTreeView.ChildrenGetter  = x => _dbc.GetBookmarksChildren(((BookmarkItem)x).Id, 2);

            //cell tooltip initialization delegate
            Action <ToolTipControl> initCellToolTip = delegate(ToolTipControl control)
            {
                control.IsBalloon = true;
                control.SetMaxWidth(400);
                control.StandardIcon = ToolTipControl.StandardIcons.InfoLarge;
                control.BackColor    = Color.AliceBlue;
                control.ForeColor    = Color.IndianRed;
                control.AutoPopDelay = 15000;
                control.InitialDelay = 750;
                control.ReshowDelay  = 750;
                control.Font         = new Font("Tahoma", 10.0f);
            };

            initCellToolTip(mainContentsView.CellToolTip);
            initCellToolTip(mainTreeView.CellToolTip);
            initCellToolTip(_duplicatesView.mainTreeView.CellToolTip);

            EventHandler <ToolTipShowingEventArgs> tooltipDelegate = delegate(object x, ToolTipShowingEventArgs e)
            {
                var bi = (BookmarkItem)e.Model;
                if (bi.IsSeparator)
                {
                    return;
                }
                e.Title = "INFO";
                const string dateFormat = "dd/MM/yyyy HH:mm:ss";
                e.Text = "ID:\t\t" + bi.Id + "\r\n"
                         + (bi.Title != "" ? "Title:\t\t" + bi.Title + "\r\n" : "")
                         + (bi.Location != "" ? "Location:\t" + bi.Location + "\r\n" : "")
                         + (bi.Description != "" ? "Description:\t" + bi.Description + "\r\n" : "")
                         + (bi.DateAdded != 0 ? "Date Created:\t" + bi.DateAddedDt.ToString(dateFormat) + "\r\n" : "")
                         + (bi.LastModified != 0
                             ? "Last Modified:\t" + bi.LastModifiedDt.ToString(dateFormat) + "\r\n"
                             : "");
            };

            mainTreeView.CellToolTipShowing     += tooltipDelegate;
            mainContentsView.CellToolTipShowing += tooltipDelegate;

            ImageGetterDelegate dg = delegate(object x)
            {
                if (!((BookmarkItem)x).IsSeparator)
                {
                    return(((BookmarkItem)x).IsDirectory ? 0 : 1); //0 - folder; 1 - bookmark
                }
                return(-1);
            };

            titleColMCV.ImageGetter = dg;
            titleColMTV.ImageGetter = dg;

            //TODO: OPT - find a way to display a separator graphically
            const string separator = "----------";

            titleColMCV.AspectGetter    = x => ((BookmarkItem)x).Type != 3 ? ((BookmarkItem)x).Title : separator;
            locationColMCV.AspectGetter = x => ((BookmarkItem)x).Type != 3 ? ((BookmarkItem)x).Location : separator;

            InitContextMenuStrip();


            //OVERRIDE
            mainTreeView.Roots = _dbc.GetBookmarksRoots();
            if (mainTreeView.Items.Count > 0)
            {
                mainTreeView.SelectedIndex = 0;
            }
            _logger.LogInfo("Database connected.");
            UpdateInfoLabel();
            //OVERRIDE
        }