예제 #1
0
파일: DataView.cs 프로젝트: switsys/bless
        public void Copy()
        {
            AreaGroup areaGroup = dvDisplay.Layout.AreaGroup;

            if (areaGroup.Areas.Count <= 0)
            {
                return;
            }

            if (!byteBuffer.ReadAllowed)
            {
                return;
            }

            byte[] ba = byteBuffer.RangeToByteArray(areaGroup.Selection);

            // if no selection, do nothing (keep old clipboard data)
            if (ba == null)
            {
                return;
            }

            clipdata = ba;

            // set clipboard
            clipboard.SetWithData(clipboardTargets, new ClipboardGetFunc(OnClipboardGet),
                                  new ClipboardClearFunc(OnClipboardClear));

            dvDisplay.MakeOffsetVisible(areaGroup.CursorOffset, DataViewDisplay.ShowType.Closest);
        }
예제 #2
0
        ///<summary>
        /// Sets the selection and the cursor position according to the values of selStartPos, selEndPos
        ///</summary>
        private void EvaluateSelection(DataViewDisplay.ShowType showType)
        {
            //System.Console.WriteLine("Evaluate (1) Start: {0},{1},{2} End: {3},{4},{5}", selStartPos.First, selStartPos.Second, selStartPos.Digit, selEndPos.First, selEndPos.Second, selEndPos.Digit);
            long cursorOffset;

            // no selection
            if (selStartPos.First == selEndPos.First && selStartPos.Second == selEndPos.Second)
            {
                cursorOffset = selStartPos.Second;
                // make sure cursor (or end of selection) is visible
                dvDisplay.MakeOffsetVisible(cursorOffset, showType);

                dataView.SetSelection(-1, -1);
                dataView.MoveCursor(selStartPos.Second, selEndPos.Digit);
            }
            // selection with start pos <= end pos
            else if (selStartPos.Second <= selEndPos.First)
            {
                // set end position between bytes
                // this is done so that selections performed with
                // the mouse can be continued with the keyboard
                // (keyboard selections always set positions between bytes)
                selEndPos.Second = selEndPos.First + 1;

                // if selEndPos.Second is at or beyond the EOF
                long off = ValidateOffset(selEndPos.Second);
                if (selEndPos.First >= off)
                {
                    off++;
                }
                cursorOffset = off;
                dvDisplay.MakeOffsetVisible(cursorOffset, showType);

                // set the selection only if the start position (which is the start of the selection)
                // is within the file's limits
                if (selStartPos.Second < dataView.Buffer.Size)
                {
                    dataView.SetSelection(ValidateOffset(selStartPos.Second), ValidateOffset(selEndPos.First));
                }
                else
                {
                    dataView.SetSelection(-1, -1);
                }

                dataView.MoveCursor(off, 0);
            }
            // selection with start pos > end pos
            else
            {
                // set start position between bytes
                // this is done so that selections performed with
                // the mouse can be continued with the keyboard
                // (keyboard selections always set positions between bytes)
                // TODO: This is currently disabled because it breaks mouse
                // selection
                //
                //selStartPos.Second = selStartPos.First + 1;

                long off = selEndPos.Second;
                cursorOffset = off;
                dvDisplay.MakeOffsetVisible(cursorOffset, showType);

                // set the selection only if the end position (which is the start of the selection)
                // is within the file's limits
                if (selEndPos.Second < dataView.Buffer.Size)
                {
                    dataView.SetSelection(ValidateOffset(selEndPos.Second), ValidateOffset(selStartPos.First));
                }
                else
                {
                    dataView.SetSelection(-1, -1);
                }

                dataView.MoveCursor(off, 0);
            }


            //System.Console.WriteLine("Evaluate (2) Start: {0},{1},{2} End: {3},{4},{5}", selStartPos.First, selStartPos.Second, selStartPos.Digit, selEndPos.First, selEndPos.Second, selEndPos.Digit);
        }