Ejemplo n.º 1
0
        public void DoCut(EditorCanvas editorCanvas)
        {
            if (editorCanvas == null)
            {
                return;
            }

            if (editorCanvas.FocusManager.IsEditorFocused)
            {
                var focus = editorCanvas.FocusManager.Focus as StyledTextFocus;
                if (focus != null)
                {
                    focus.Cut();
                }
            }
            else if (editorCanvas.CanCut())
            {
                var targets = editorCanvas.SelectionManager.SelectedEditors;
                var req     = new CopyRequest(targets);
                var bundle  = new EditorBundle(targets);
                var copy    = bundle.GetGroupCommand(req);
                if (copy == null)
                {
                    return;
                }
                var remove = bundle.GetCompositeCommand(new RemoveRequest());
                if (remove == null)
                {
                    return;
                }
                var cmd = copy.Chain(remove);
                editorCanvas.CommandExecutor.Execute(cmd);
            }
        }
Ejemplo n.º 2
0
        private FileStreamAndHeaders GetFileStreamAndHeaders(CopyRequest request)
        {
            FileStreamAndHeaders result = new FileStreamAndHeaders();

            try
            {
                result.FileName = request.Name;

                result.Offset = request.Offset;

                result.Stream = new FileStream(request.Name, FileMode.Open, FileAccess.Read, FileShare.Read, CopyConstants.BufferSize, FileOptions.Asynchronous | FileOptions.SequentialScan);

                result.FileSize = result.Stream.Length;

                Debug.Assert(result.Stream.Position == 0L);
                result.Stream.Seek(request.Offset, SeekOrigin.Begin);
                Debug.Assert(result.Stream.Position == request.Offset);

                result.ChunkSize = CopyConstants.BufferSize;

                // Decide whether to use compression.
                if (request.Compression == CopyCompression.Gzip && result.FileSize > CopyConstants.BigSize)
                {
                    result.Compression = CopyCompression.Gzip;
                }
            }
            catch (Exception e)
            {
                result.Error = e;
            }

            return(result);
        }
Ejemplo n.º 3
0
        // ------------------------------
        // private
        // ------------------------------
        private static void Copy(IEnumerable <IEditor> targets, ICommandExecutor commandExecutor)
        {
            var req  = new CopyRequest(targets);
            var list = new EditorBundle(targets);

            list.PerformGroupRequest(req, commandExecutor);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Copy(
            [FromForm] CopyRequest copyRequest)
        {
            try
            {
                if (copyRequest.source == null)
                {
                    return(BadRequest("Copy source is not specified"));
                }

                if (copyRequest.target == null)
                {
                    return(BadRequest("Copy target is not specified"));
                }

                var result = await _fileSystemService
                             .CopyAsync(
                    new CopyState(
                        new NPath(copyRequest.target),
                        new NPath(copyRequest.source)));

                if (result == null)
                {
                    throw new SystemException("Unable to process copy");
                }

                return(Json(result));
            }
            catch (Exception e)
            {
                return(BadRequest(e));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Copies the specified query.
        /// </summary>
        /// <param name="copyRequest">The query.</param>
        /// <param name="db">The database.</param>
        public ProcessResponse Copy(CopyRequest copyRequest, string db)
        {
            this.SetDatabase(db);

            var processId = Guid.NewGuid();

            progressStatus.TryAdd(processId, new ConcurrentQueue <string>());
            var targetItem = this.database.GetItem(copyRequest.TargetPath);

            copyRequest.Items.ForEach(t => progressStatus[processId].Enqueue(t));

            List <Action> actions = new List <Action>();

            for (int i = 0; i < this.MaximumNumberOfThreads; i++)
            {
                Action action = () =>
                {
                    string itemId;
                    while (progressStatus[processId].TryDequeue(out itemId))
                    {
                        try
                        {
                            var sourceItem = database.GetItem(new ID(itemId));
                            sourceItem.CopyTo(targetItem, sourceItem.Name, new ID(Guid.NewGuid()), copyRequest.CopySubItems);
                        }
                        catch (Exception ex)
                        {
                            List <string> errorMessages = new List <string>();
                            if (errors == null)
                            {
                                errors = new ConcurrentDictionary <Guid, List <string> >();
                            }

                            if (errors.TryGetValue(processId, out errorMessages))
                            {
                                var newErrors = new List <string>();
                                newErrors.AddRange(errorMessages);
                                newErrors.Add(ex.Message + " Item Id: " + itemId);
                                errors.TryUpdate(processId, newErrors, errorMessages);
                            }
                            else
                            {
                                errors.TryAdd(processId, new List <string> {
                                    ex.Message + " Item Id: " + itemId
                                });
                            }
                        }
                    }
                };

                actions.Add(action);
            }

            Task.Run(() => Parallel.Invoke(actions.ToArray()));

            return(new ProcessResponse {
                StatusId = processId
            });
        }
Ejemplo n.º 6
0
        private ICommand GetCutCommand(IEnumerable <IEditor> targets)
        {
            var bundle = new EditorBundle(targets);
            var req    = new CopyRequest(targets);
            var copy   = bundle.GetGroupCommand(req);
            var remove = bundle.GetCompositeCommand(new RemoveRequest());

            return(copy.Chain(remove));
        }
Ejemplo n.º 7
0
        // ========================================
        // field
        // ========================================

        // ========================================
        // constructor
        // ========================================

        // ========================================
        // property
        // ========================================

        // ========================================
        // method
        // ========================================
        public override bool CanUnderstand(IRequest request)
        {
            var req = request as CloneRequest;

            if (req == null)
            {
                return(false);
            }
            var copyReq = new CopyRequest(req.TargetEditors);

            return(req.TargetEditors.Any(editor => editor.CanUnderstand(copyReq)));
        }
Ejemplo n.º 8
0
        public void Copy(CopyRequest r)
        {
            var src = CheckPath(r.SrcDrive, r.SrcPath);
            var dst = GetPath(r.DstDrive, r.DstPath);

            if (src.ItemType == ItemType.File)
            {
                File.Copy(src.FullPath, dst);
            }
            else if (src.ItemType == ItemType.Directory)
            {
                // TODO
            }
        }
Ejemplo n.º 9
0
        public void TryCopy(IEnumerable <KeyValuePair <string, string> > keyCopies, DateTimeOffset expiry, out HashSet <string> fromKeysWhichDidNotExist,
                            out HashSet <string> toKeysWhichAlreadyExisted, AvailabilityLevel requiredAvailabilityLevel = AvailabilityLevel.SavedToDisk)
        {
            var keysCopied = keyCopies.ToArray();

            var request = new CopyRequest {
                CorrelationId = _correlationId
            };

            request.Entries.AddRange(keysCopied.Select(kv => new CopyRequest.Types.CopyRequestEntry {
                Expiry = expiry.ToTimestamp()
            }));
            var copyResponse = Task.Run(async() => await _lightClient.CopyAsync(request)).GetAwaiter().GetResult();

            var ret = copyResponse.Results.
                      Select((r, i) => (r, i)).
                      Aggregate((new List <string>(), new List <string>()), (acc, res) =>
            {
                switch (res.Item1)
                {
                case CopyResponse.Types.CopyResult.Success:
                    break;

                case CopyResponse.Types.CopyResult.FromKeyNotFound:
                    acc.Item1.Add(keysCopied[res.Item2].Key);
                    break;

                case CopyResponse.Types.CopyResult.ToKeyExists:
                    acc.Item2.Add(keysCopied[res.Item2].Value);
                    break;

                case CopyResponse.Types.CopyResult.Failure:         // TODO: What to do in a case of failures?
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                return(acc);
            });

            fromKeysWhichDidNotExist  = ret.Item1.ToHashSet();
            toKeysWhichAlreadyExisted = ret.Item2.ToHashSet();
        }
        private ICommand GetCutCommand()
        {
            var targets = _owner.SelectionManager.SelectedEditors;
            var req     = new CopyRequest(targets);
            var list    = new EditorBundle(targets);
            var copy    = list.GetGroupCommand(req);

            if (copy == null)
            {
                return(null);
            }
            var remove = list.GetCompositeCommand(new RemoveRequest());

            if (remove == null)
            {
                return(null);
            }
            return(copy.Chain(remove));
        }
Ejemplo n.º 11
0
        public override async Task Copy(CopyRequest request, IServerStreamWriter <CopyReply> responseStream, ServerCallContext context)
        {
            try
            {
                Console.WriteLine($"received request for {request.Name}");

                FileStreamAndHeaders streamAndHeaders = GetFileStreamAndHeaders(request);
                using (streamAndHeaders.Stream)
                {
                    await context.WriteResponseHeadersAsync(streamAndHeaders.GetHeaders()).ConfigureAwait(false);

                    if (streamAndHeaders.Error is null)
                    {
                        Debug.Assert(!(streamAndHeaders.Stream is null));
                        Debug.Assert(streamAndHeaders.ChunkSize > 0);
                        byte[] buffer = new byte[streamAndHeaders.ChunkSize];
                        long   chunks, bytes;
                        switch (streamAndHeaders.Compression)
                        {
                        case CopyCompression.None:
                            (chunks, bytes) = await StreamContent(streamAndHeaders.Stream, buffer, responseStream).ConfigureAwait(false);

                            break;

                        case CopyCompression.Gzip:
                            (chunks, bytes) = await StreamContentWithCompression(streamAndHeaders.Stream, buffer, responseStream).ConfigureAwait(false);

                            break;

                        default:
                            throw new NotSupportedException();
                        }
                        Console.WriteLine($"wrote {bytes} bytes in {chunks} chunks");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Ejemplo n.º 12
0
        public override async Task <CopyReply> CopyData(CopyRequest request, ServerCallContext context)
        {
            //Console.WriteLine($"Got request: {request.Topic} ({context.Peer})");

            try
            {
                var report = await _producer.ProduceAsync(request.Topic, request.Key.ToByteArray(), request.Value.ToByteArray(), request.Partition);

                return(new CopyReply
                {
                    Success = report.Error.Code == ErrorCode.NoError,
                    Message = report.Error.Code == ErrorCode.NoError ? "OK" : report.Error.Reason,
                });
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Ejemplo n.º 13
0
        // ========================================
        // method
        // ========================================
        public override void Execute()
        {
            var containerCtrl = _target.Controller as IContainerController;

            var clonings = new List <IEditor>();
            var copyReq  = new CopyRequest(_cloningEditors);

            foreach (var cloning in _cloningEditors)
            {
                if (cloning.CanUnderstand(copyReq))
                {
                    clonings.Add(cloning);
                }
            }

            var data = EditorFactory.CreateDataObject(clonings);

            _clonedEditors = EditorFactory.RestoreDataObject(data, _target.Site.ControllerFactory);

            _command = new AddEditorsCommand(_target, _clonedEditors, _moveDelta);
            _command.Execute();
        }
Ejemplo n.º 14
0
        public void DoCopy(EditorCanvas editorCanvas)
        {
            if (editorCanvas == null)
            {
                return;
            }

            if (editorCanvas.FocusManager.IsEditorFocused)
            {
                var focus = editorCanvas.FocusManager.Focus as StyledTextFocus;
                if (focus != null)
                {
                    focus.Copy();
                }
            }
            else if (editorCanvas.CanCopy())
            {
                var targets = editorCanvas.SelectionManager.SelectedEditors;
                var bundle  = new EditorBundle(targets);
                var copy    = new CopyRequest(targets);
                bundle.PerformGroupRequest(copy, editorCanvas.CommandExecutor);
            }
        }
Ejemplo n.º 15
0
        // Providing stream factory instead of stream allows stream
        // to be created only when content is actually available.
        public async Task Copy(string name, Func <Stream> streamFactory)
        {
            CopyRequest request = new CopyRequest()
            {
                Name        = name,
                Offset      = 0,
                Compression = CopyCompression.Gzip
            };

            bool            success       = true;
            long            headerSize    = -1;
            CopyCompression compression   = CopyCompression.None;
            Stopwatch       responseTimer = Stopwatch.StartNew();
            AsyncServerStreamingCall <CopyReply> reply = client.Copy(request);
            Metadata data = await reply.ResponseHeadersAsync.ConfigureAwait(false);

            responseTimer.Stop();
            foreach (Metadata.Entry header in data)
            {
                Console.WriteLine($"{header.Key}={header.Value}");
                if (String.Compare(header.Key, "exception", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    success = false;
                }
                if (String.Compare(header.Key, "fileSize", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    headerSize = Int64.Parse(header.Value);
                }
                if (String.Compare(header.Key, "compression", StringComparison.InvariantCultureIgnoreCase) == 0)
                {
                    compression = Enum.Parse <CopyCompression>(header.Value);
                }
            }
            if (!success)
            {
                return;
            }

            long      chunks = 0L;
            long      bytes  = 0L;
            Stopwatch streamTimer;
            long      measuredSize = 0L;

            using (Stream writeStream = streamFactory())
            {
                streamTimer = Stopwatch.StartNew();
                switch (compression)
                {
                case CopyCompression.None:
                    (chunks, bytes) = await StreamContent(writeStream, reply.ResponseStream).ConfigureAwait(false);

                    break;

                case CopyCompression.Gzip:
                    (chunks, bytes) = await StreamContentWithCompression(writeStream, reply.ResponseStream).ConfigureAwait(false);

                    break;
                }
                streamTimer.Stop();

                measuredSize = writeStream.Length;
            }

            Console.WriteLine($"responseTime = {responseTimer.ElapsedMilliseconds} chunks = {chunks} bytes = {bytes} headerSize = {headerSize} measuredSize = {measuredSize} streamTime = {streamTimer.ElapsedMilliseconds}");
        }
 // Copy a quote
 public async Task <Quote?> CopyQuoteAsync(int quoteId, CopyRequest data)
 => await _api.PostAsync <Quote>($"2.0/kb_offer/{quoteId}/copy", data);
        public override ContextMenuStrip GetContextMenu(MouseEventArgs e)
        {
            if (_remove == null)
            {
                InitItems();
            }

            _currentEvent = e;
            _ContextMenu.Items.Clear();

            var selectedCount = _owner.SelectionManager.SelectedEditors.Count();

            var target = _owner.RootEditor.FindEnabledEditor(e.Location);

            if (target == null)
            {
                return(_ContextMenu);
            }

            var sepaIndex = 0;
            var itemCount = 0;

            /// 削除,複製
            if (UpdateItem(_remove, target, () => new RemoveRequest(), false))
            {
                ++itemCount;
            }
            if (UpdateItem(_clone, target.Parent, () => new CloneRequest(_owner.SelectionManager.SelectedEditors)
            {
                MoveDelta = CloneMoveDelta
            }, false))
            {
                ++itemCount;
            }

            /// separate
            sepaIndex = itemCount;

            /// クリップボード
            if (UpdateItem(_cut, target, GetCutCommand(), true))
            {
                ++itemCount;
            }
            {
                var copyReq    = new CopyRequest(_owner.SelectionManager.SelectedEditors);
                var copyBundle = new EditorBundle(copyReq.TargetEditors);
                var canCopy    = copyBundle.CanUnderstandAll(copyReq);
                _copy.Enabled = canCopy;
                _ContextMenu.Items.Add(_copy);
                ++itemCount;
            }
            {
                _copyAsImage.Enabled = true;
                _ContextMenu.Items.Add(_copyAsImage);
                ++itemCount;
            }
            if (UpdateItem(_paste, target, () => new PasteRequest(), true))
            {
                ++itemCount;
            }
            if (Clipboard.ContainsText())
            {
                if (UpdateItem(_pasteInBlock, target, () => new PasteRequest(), false))
                {
                    ++itemCount;
                }
            }

            /// separate
            if (itemCount > sepaIndex && sepaIndex > 0)
            {
                _ContextMenu.Items.Insert(sepaIndex, new ToolStripSeparator());
                ++itemCount;
                sepaIndex = itemCount;
            }

            /// 前面,背面移動
            if (selectedCount == 1 && !(target.Parent.Figure.Layout is ListLayout))
            {
                /// Layoutが有効な場合は前面,背面移動の意味が違うことがあるので表示しない
                if (UpdateItem(_front, target, () => new ReorderRequest()
                {
                    Kind = ReorderKind.Front
                }, false))
                {
                    ++itemCount;
                }
                if (UpdateItem(_frontMost, target, () => new ReorderRequest()
                {
                    Kind = ReorderKind.FrontMost
                }, false))
                {
                    ++itemCount;
                }
                if (UpdateItem(_back, target, () => new ReorderRequest()
                {
                    Kind = ReorderKind.Back
                }, false))
                {
                    ++itemCount;
                }
                if (UpdateItem(_backMost, target, () => new ReorderRequest()
                {
                    Kind = ReorderKind.BackMost
                }, false))
                {
                    ++itemCount;
                }

                /// separate
                if (itemCount > sepaIndex && sepaIndex > 0)
                {
                    _ContextMenu.Items.Insert(sepaIndex, new ToolStripSeparator());
                    ++itemCount;
                    sepaIndex = itemCount;
                }
            }


            var canMove = target.CanUnderstand(new ChangeBoundsRequest());

            if (selectedCount > 1 && canMove)
            {
                /// 左揃え
                _ContextMenu.Items.Add(_arrangeHLeft);
                ++itemCount;

                /// 左右中央揃え
                _ContextMenu.Items.Add(_arrangeHCenter);
                ++itemCount;

                /// 右揃え
                _ContextMenu.Items.Add(_arrangeHRight);
                ++itemCount;

                /// separate
                _ContextMenu.Items.Insert(sepaIndex, new ToolStripSeparator());
                ++itemCount;
                sepaIndex = itemCount;

                /// 上揃え
                _ContextMenu.Items.Add(_arrangeVTop);
                ++itemCount;

                /// 上下中央揃え
                _ContextMenu.Items.Add(_arrangeVMiddle);
                ++itemCount;

                /// 下揃え
                _ContextMenu.Items.Add(_arrangeVBottom);
                ++itemCount;

                /// separate
                _ContextMenu.Items.Insert(sepaIndex, new ToolStripSeparator());
                ++itemCount;
                sepaIndex = itemCount;
            }

            /// 設定
            if (selectedCount == 1 && target.Controller.UIProvider != null && target.Controller.UIProvider.SupportDetailForm)
            {
                var enabled = target.Controller.UIProvider.SupportDetailForm;
                _detailForm.Enabled = enabled;
                _ContextMenu.Items.Add(_detailForm);
                ++itemCount;
            }

            /// separate
            if (itemCount > sepaIndex && sepaIndex > 0)
            {
                _ContextMenu.Items.Insert(sepaIndex, new ToolStripSeparator());
                ++itemCount;
                sepaIndex = itemCount;
            }

            return(_ContextMenu);
        }
Ejemplo n.º 18
0
        protected virtual void InitItems()
        {
            _export = new ToolStripMenuItem("取り出す(&E)");
            var exportCsv = new ToolStripMenuItem("CSV(&C)...");

            exportCsv.Click += (sender, e) => {
                var memoFile = _owner.Model;
                var dialog   = new SaveFileDialog();
                dialog.RestoreDirectory = true;
                dialog.ShowHelp         = true;
                dialog.FileName         = "Export.csv";
                dialog.Filter           = "Csv Files(*.csv)|*.csv";
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    var outputPath = dialog.FileName;
                    _owner.Host.Parent.RequestExport("Csv", outputPath);
                }
            };
            _export.DropDownItems.Add(exportCsv);

            _addPreviousColumn        = new ToolStripMenuItem();
            _addPreviousColumn.Text   = "左に列を挿入(&L)";
            _addPreviousColumn.Click += (sender, ev) => {
                var tableModel = GetTableModel();
                var col        = GetColumnIndex();
                GetExecutor().Execute(new InsertTableColumnCommand(tableModel, col));
            };

            _addNextColumn        = new ToolStripMenuItem();
            _addNextColumn.Text   = "右に列を挿入(&R)";
            _addNextColumn.Click += (sender, ev) => {
                var tableModel = GetTableModel();
                var col        = GetColumnIndex();
                GetExecutor().Execute(new InsertTableColumnCommand(tableModel, col + 1));
            };

            _addPreviousRow        = new ToolStripMenuItem();
            _addPreviousRow.Text   = "上に行を挿入(&U)";
            _addPreviousRow.Click += (sender, ev) => {
                var tableModel = GetTableModel();
                var row        = GetRowIndex();
                GetExecutor().Execute(new InsertTableRowCommand(tableModel, row));
            };

            _addNextRow        = new ToolStripMenuItem();
            _addNextRow.Text   = "下に行を挿入(&D)";
            _addNextRow.Click += (sender, ev) => {
                var tableModel = GetTableModel();
                var row        = GetRowIndex();
                GetExecutor().Execute(new InsertTableRowCommand(tableModel, row + 1));
            };



            _removeRow        = new ToolStripMenuItem();
            _removeRow.Text   = "行を削除(&R)";
            _removeRow.Click += (sender, ev) => {
                var rowIndex = GetRowIndex();


                var host        = _owner.Host;
                var tableEditor = host.Parent;
                var tableFig    = GetTableFigure();
                var tableData   = tableFig.TableData;

                var cmd      = default(ICommand);
                var unmerged = new HashSet <Cell <TableCellFigure> >();
                var row      = tableData.Rows.ElementAt(rowIndex);
                var colIndex = 0;
                foreach (var cell in row.Cells)
                {
                    if (cell.IsMerging)
                    {
                        var rs = cell.RowSpan;
                        var cs = cell.ColumnSpan;
                        cmd = new MergeTableCellsCommand(tableEditor, colIndex, rowIndex, 1, 1);
                        if (rowIndex < tableData.RowCount - 1)
                        {
                            cmd = cmd.Chain(new MergeTableCellsCommand(tableEditor, colIndex, rowIndex + 1, cs, rs - 1));
                        }
                        unmerged.Add(cell);
                    }
                    else if (cell.IsMerged)
                    {
                        var merging = cell.Merging;
                        if (!unmerged.Contains(merging))
                        {
                            var mColIndex = tableData.GetColumnIndex(merging);
                            var mRowIndex = tableData.GetRowIndex(merging);
                            cmd = new MergeTableCellsCommand(tableEditor, mColIndex, mRowIndex, merging.ColumnSpan, merging.RowSpan - 1);
                        }
                    }
                    ++colIndex;
                }

                var remove = new RemoveTableRowCommand(_owner.Host.Parent, rowIndex);
                cmd = cmd == null ? remove : cmd.Chain(remove);
                GetExecutor().Execute(cmd);
            };

            _removeColumn        = new ToolStripMenuItem();
            _removeColumn.Text   = "列を削除(&C)";
            _removeColumn.Click += (sender, ev) => {
                var colIndex = GetColumnIndex();

                var host        = _owner.Host;
                var tableEditor = host.Parent;
                var tableFig    = GetTableFigure();
                var tableData   = tableFig.TableData;

                var cmd      = default(ICommand);
                var unmerged = new HashSet <Cell <TableCellFigure> >();
                var col      = tableData.Columns.ElementAt(colIndex);
                var rowIndex = 0;
                foreach (var cell in col.Cells)
                {
                    if (cell.IsMerging)
                    {
                        var rs = cell.RowSpan;
                        var cs = cell.ColumnSpan;
                        cmd = new MergeTableCellsCommand(tableEditor, colIndex, rowIndex, 1, 1);
                        if (colIndex < tableData.ColumnCount - 1)
                        {
                            cmd = cmd.Chain(new MergeTableCellsCommand(tableEditor, colIndex + 1, rowIndex, cs - 1, rs));
                        }
                        unmerged.Add(cell);
                    }
                    else if (cell.IsMerged)
                    {
                        var merging = cell.Merging;
                        if (!unmerged.Contains(merging))
                        {
                            var mColIndex = tableData.GetColumnIndex(merging);
                            var mRowIndex = tableData.GetRowIndex(merging);
                            cmd = new MergeTableCellsCommand(tableEditor, mColIndex, mRowIndex, merging.ColumnSpan - 1, merging.RowSpan);
                        }
                    }
                    ++rowIndex;
                }

                var remove = new RemoveTableColumnCommand(_owner.Host.Parent, colIndex);
                cmd = cmd == null ? remove : cmd.Chain(remove);
                GetExecutor().Execute(cmd);
            };

            _removeTable        = new ToolStripMenuItem();
            _removeTable.Text   = "表を削除(&T)";
            _removeTable.Click += (sender, ev) => {
                var canvas    = _owner.Host.Site.EditorCanvas;
                var oldCursor = canvas.Cursor;
                canvas.Cursor = Cursors.WaitCursor;

                /// ここでsite変数に入れておかないとRemoveRequest後には
                /// _ownerからはたどれなくなってしまう
                var site = _owner.Host.Site;

                try {
                    _owner.Host.RequestSelect(SelectKind.False, true);

                    site.SuppressUpdateHandleLayer = true;
                    var parent = _owner.Host.Parent;
                    parent.PerformRequest(new RemoveRequest());
                    site.SuppressUpdateHandleLayer = false;
                    site.UpdateHandleLayer();
                } finally {
                    canvas.Cursor = oldCursor;
                }
            };

            _adjustRowHeight        = new ToolStripMenuItem("行の高さを調節(&H)");
            _adjustRowHeight.Click += (sender, ev) => {
                var edi = GetTableEditor();
                var fig = GetTableFigure();
                using (edi.Site.CommandExecutor.BeginChain()) {
                    int fr, lr, fc, lc;
                    GetSelectedCellRange(out fr, out lr, out fc, out lc);
                    for (int i = fr; i <= lr; ++i)
                    {
                        TableFigureHelper.AdjustRowSize(edi, fig, i);
                    }
                }
            };

            _adjustColumnWidth        = new ToolStripMenuItem("列の幅を調節(&W)");
            _adjustColumnWidth.Click += (sender, ev) => {
                var edi = GetTableEditor();
                var fig = GetTableFigure();
                using (edi.Site.CommandExecutor.BeginChain()) {
                    int fr, lr, fc, lc;
                    GetSelectedCellRange(out fr, out lr, out fc, out lc);
                    for (int i = fc; i <= lc; ++i)
                    {
                        TableFigureHelper.AdjustColumnSize(edi, fig, i);
                    }
                }
            };

            _adjustRowHeightsAtEvenInterval        = new ToolStripMenuItem("行の高さを揃える(&H)");
            _adjustRowHeightsAtEvenInterval.Click += (sender, ev) => {
                var edi = GetTableEditor();
                var fig = GetTableFigure();
                using (edi.Site.CommandExecutor.BeginChain()) {
                    int fr, lr, fc, lc;
                    GetSelectedCellRange(out fr, out lr, out fc, out lc);
                    TableFigureHelper.AdjustRowSizesAtEvenInterval(edi, fig, fr, lr);
                }
            };

            _adjustColumnWidthsAtEvenInterval        = new ToolStripMenuItem("列の幅を揃える(&W)");
            _adjustColumnWidthsAtEvenInterval.Click += (sender, ev) => {
                var edi = GetTableEditor();
                var fig = GetTableFigure();
                using (edi.Site.CommandExecutor.BeginChain()) {
                    int fr, lr, fc, lc;
                    GetSelectedCellRange(out fr, out lr, out fc, out lc);
                    TableFigureHelper.AdjustColumnSizesAtEvenInterval(edi, fig, fc, lc);
                }
            };


            _mergeCells        = new ToolStripMenuItem();
            _mergeCells.Text   = "セルを結合(&M)";
            _mergeCells.Click += (sender, ev) => {
                var host        = _owner.Host;
                var tableEditor = host.Parent;
                var tableFig    = tableEditor.Figure as TableFigure;
                var tableData   = tableFig.TableData;
                var tableModel  = tableEditor.Model as MemoTable;

                var leftColIndex   = -1;
                var rightColIndex  = -1;
                var topRowIndex    = -1;
                var bottomRowIndex = -1;

                var selecteds = host.Site.SelectionManager.SelectedEditors;
                foreach (var selected in selecteds)
                {
                    var colIndex = tableData.GetColumnIndex(selected.Figure as TableCellFigure);
                    var rowIndex = tableData.GetRowIndex(selected.Figure as TableCellFigure);
                    leftColIndex   = leftColIndex == -1? colIndex: Math.Min(leftColIndex, colIndex);
                    rightColIndex  = rightColIndex == -1? colIndex: Math.Max(rightColIndex, colIndex);
                    topRowIndex    = topRowIndex == -1? rowIndex: Math.Min(topRowIndex, rowIndex);
                    bottomRowIndex = bottomRowIndex == -1? rowIndex : Math.Max(bottomRowIndex, rowIndex);
                }


                GetExecutor().Execute(
                    new MergeTableCellsCommand(
                        tableEditor,
                        leftColIndex,
                        topRowIndex,
                        rightColIndex - leftColIndex + 1,
                        bottomRowIndex - topRowIndex + 1
                        )
                    );

                var cell       = tableData.GetCell(topRowIndex, leftColIndex);
                var cellEditor = cell.Value.GetEditor();
                cellEditor.RequestSelect(SelectKind.True, true);
            };

            _unmergeCells        = new ToolStripMenuItem();
            _unmergeCells.Text   = "セルを分割(&U)";
            _unmergeCells.Click += (sender, ev) => {
                var host        = _owner.Host;
                var tableEditor = host.Parent;
                var tableFig    = tableEditor.Figure as TableFigure;
                var tableData   = tableFig.TableData;
                var tableModel  = tableEditor.Model as MemoTable;

                var leftColIndex = -1;
                var topRowIndex  = -1;

                var selecteds = host.Site.SelectionManager.SelectedEditors;
                foreach (var selected in selecteds)
                {
                    var colIndex = tableData.GetColumnIndex(selected.Figure as TableCellFigure);
                    var rowIndex = tableData.GetRowIndex(selected.Figure as TableCellFigure);
                    leftColIndex = leftColIndex == -1? colIndex: Math.Min(leftColIndex, colIndex);
                    topRowIndex  = topRowIndex == -1? rowIndex: Math.Min(topRowIndex, rowIndex);
                }

                GetExecutor().Execute(
                    new MergeTableCellsCommand(
                        tableEditor,
                        leftColIndex,
                        topRowIndex,
                        1,
                        1
                        )
                    );

                var cell       = tableData.GetCell(topRowIndex, leftColIndex);
                var cellEditor = cell.Value.GetEditor();
                cellEditor.RequestSelect(SelectKind.True, true);
            };


            _copyTable        = new ToolStripMenuItem();
            _copyTable.Text   = "表をコピー(&C)";
            _copyTable.Click += (sender, ev) => {
                var tableEditor = GetTableEditor();
                if (tableEditor != null)
                {
                    var req = new CopyRequest(new [] { tableEditor });
                    tableEditor.PerformRequest(req);
                }
            };
        }
        private void InitItems()
        {
            _remove        = new ToolStripMenuItem();
            _remove.Text   = "削除(&R)";
            _remove.Click += (sender, e) => {
                using (_owner.CommandExecutor.BeginChain()) {
                    var req  = new RemoveRequest();
                    var cmds = new CompositeCommand();

                    var parent = default(IEditor);
                    foreach (var editor in _owner.SelectionManager.SelectedEditors)
                    {
                        if (parent == null)
                        {
                            parent = editor.Parent;
                        }
                        if (editor.CanUnderstand(req))
                        {
                            cmds.Children.Add(editor.GetCommand(req));
                        }
                    }
                    _owner.CommandExecutor.Execute(cmds);
                    if (parent != null)
                    {
                        parent.RequestSelect(SelectKind.True, true);
                    }
                }
            };

            _clone        = new ToolStripMenuItem();
            _clone.Text   = "複製(&C)";
            _clone.Click += (sender, e) => {
                var cloning = new List <IEditor>(_owner.SelectionManager.SelectedEditors);
                var req     = new CloneRequest(cloning);
                req.MoveDelta = CloneMoveDelta;

                if (cloning.Any())
                {
                    var target = cloning.First().Parent;
                    var cmd    = target.PerformRequest(req) as CloneCommand;
                    if (cmd != null && cmd.ClonedEditors != null)
                    {
                        _owner.SelectionManager.DeselectAll();
                        foreach (var cloned in cmd.ClonedEditors)
                        {
                            cloned.RequestSelect(SelectKind.True, false);
                        }
                    }
                }
            };

            _cut        = new ToolStripMenuItem();
            _cut.Text   = "切り取り(&X)";
            _cut.Click += (sender, e) => {
                var cmd = GetCutCommand();
                _owner.CommandExecutor.Execute(cmd);
            };

            _copy        = new ToolStripMenuItem();
            _copy.Text   = "コピー(&C)";
            _copy.Click += (sender, e) => {
                var targets = _owner.SelectionManager.SelectedEditors;
                var req     = new CopyRequest(targets);
                var list    = new EditorBundle(targets);
                list.PerformGroupRequest(req, _owner.CommandExecutor);
            };

            _copyAsImage        = new ToolStripMenuItem();
            _copyAsImage.Text   = "画像としてコピー(&I)";
            _copyAsImage.Click += (sender, e) => {
                _owner.CopySelectedAsImage();
            };

            _paste        = new ToolStripMenuItem();
            _paste.Text   = "貼り付け(&P)";
            _paste.Click += (sender, e) => {
                var found = _owner.RootEditor.FindEnabledEditor(
                    _currentEvent.Location
                    );
                if (found != null)
                {
                    var cmd = found.RequestPaste(_currentEvent.Location, null) as PasteCommand;
                    if (cmd != null && cmd.PastedEditors != null)
                    {
                        _owner.SelectionManager.DeselectAll();
                        foreach (var editor in cmd.PastedEditors)
                        {
                            editor.RequestSelect(SelectKind.True, false);
                        }
                    }
                }
            };

            _pasteInBlock        = new ToolStripMenuItem();
            _pasteInBlock.Text   = "段落内に貼り付け(&P)";
            _pasteInBlock.Click += (sender, e) => {
                var found = _owner.RootEditor.FindEnabledEditor(
                    _currentEvent.Location
                    );
                if (found != null)
                {
                    var cmd = found.RequestPaste(
                        _currentEvent.Location, EditorConsts.InBlockPasteDescription
                        ) as PasteCommand;
                    if (cmd != null && cmd.PastedEditors != null)
                    {
                        _owner.SelectionManager.DeselectAll();
                        foreach (var editor in cmd.PastedEditors)
                        {
                            editor.RequestSelect(SelectKind.True, false);
                        }
                    }
                }
            };


            _front        = new ToolStripMenuItem();
            _front.Text   = "前面に移動(&F)";
            _front.Click += (sender, e) => {
                var found = _owner.RootEditor.FindEnabledEditor(
                    _currentEvent.Location
                    );
                if (found != null)
                {
                    found.RequestReorder(ReorderKind.Front);
                }
            };

            _frontMost        = new ToolStripMenuItem();
            _frontMost.Text   = "最前面に移動(&F)";
            _frontMost.Click += (sender, e) => {
                var found = _owner.RootEditor.FindEnabledEditor(
                    _currentEvent.Location
                    );
                if (found != null)
                {
                    found.RequestReorder(ReorderKind.FrontMost);
                }
            };

            _back        = new ToolStripMenuItem();
            _back.Text   = "背面に移動(&B)";
            _back.Click += (sender, e) => {
                var found = _owner.RootEditor.FindEnabledEditor(
                    _currentEvent.Location
                    );
                if (found != null)
                {
                    found.RequestReorder(ReorderKind.Back);
                }
            };

            _backMost        = new ToolStripMenuItem();
            _backMost.Text   = "最背面に移動(&B)";
            _backMost.Click += (sender, e) => {
                var found = _owner.RootEditor.FindEnabledEditor(
                    _currentEvent.Location
                    );
                if (found != null)
                {
                    found.RequestReorder(ReorderKind.BackMost);
                }
            };

            _arrangeHLeft        = new ToolStripMenuItem("左揃え(&L)");
            _arrangeHLeft.Click += (sender, e) => {
                var editors = _owner.SelectionManager.SelectedEditors;
                var rect    = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2));
                using (_owner.CommandExecutor.BeginChain()) {
                    foreach (var edi in editors)
                    {
                        var left = rect.Left;
                        edi.RequestMove(new Size(left - edi.Figure.Left, 0));
                    }
                }
            };

            _arrangeHCenter        = new ToolStripMenuItem("左右中央揃え(&C)");
            _arrangeHCenter.Click += (sender, e) => {
                var editors = _owner.SelectionManager.SelectedEditors;
                var rect    = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2));
                var center  = RectUtil.GetCenter(rect);
                using (_owner.CommandExecutor.BeginChain()) {
                    foreach (var edi in editors)
                    {
                        var left = center.X - edi.Figure.Width / 2;
                        edi.RequestMove(new Size(left - edi.Figure.Left, 0));
                    }
                }
            };

            _arrangeHRight        = new ToolStripMenuItem("右揃え(&R)");
            _arrangeHRight.Click += (sender, e) => {
                var editors = _owner.SelectionManager.SelectedEditors;
                var rect    = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2));
                using (_owner.CommandExecutor.BeginChain()) {
                    foreach (var edi in editors)
                    {
                        var left = rect.Right - edi.Figure.Width;
                        edi.RequestMove(new Size(left - edi.Figure.Left, 0));
                    }
                }
            };

            _arrangeVTop        = new ToolStripMenuItem("上揃え(&T)");
            _arrangeVTop.Click += (sender, e) => {
                var editors = _owner.SelectionManager.SelectedEditors;
                var rect    = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2));
                using (_owner.CommandExecutor.BeginChain()) {
                    foreach (var edi in editors)
                    {
                        var top = rect.Top;
                        edi.RequestMove(new Size(0, top - edi.Figure.Top));
                    }
                }
            };

            _arrangeVMiddle        = new ToolStripMenuItem("上下中央揃え(&M)");
            _arrangeVMiddle.Click += (sender, e) => {
                var editors = _owner.SelectionManager.SelectedEditors;
                var rect    = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2));
                var center  = RectUtil.GetCenter(rect);
                using (_owner.CommandExecutor.BeginChain()) {
                    foreach (var edi in editors)
                    {
                        var top = center.Y - edi.Figure.Height / 2;
                        edi.RequestMove(new Size(0, top - edi.Figure.Top));
                    }
                }
            };

            _arrangeVBottom        = new ToolStripMenuItem("下揃え(&B)");
            _arrangeVBottom.Click += (sender, e) => {
                var editors = _owner.SelectionManager.SelectedEditors;
                var rect    = editors.Select(ed => ed.Figure.Bounds).Aggregate((r1, r2) => Rectangle.Union(r1, r2));
                using (_owner.CommandExecutor.BeginChain()) {
                    foreach (var edi in editors)
                    {
                        var top = rect.Bottom - edi.Figure.Height;
                        edi.RequestMove(new Size(0, top - edi.Figure.Top));
                    }
                }
            };


            _detailForm        = new ToolStripMenuItem();
            _detailForm.Text   = "設定(&S)";
            _detailForm.Click += (sender, e) => {
                var found = _owner.RootEditor.FindEnabledEditor(
                    _currentEvent.Location
                    );
                if (found != null)
                {
                    if (found.Controller != null && found.Controller.UIProvider != null)
                    {
                        var ui   = found.Controller.UIProvider;
                        var form = new DetailSettingsForm();
                        try {
                            form.Size  = _detailFormSize;
                            form.Theme = _owner.Theme;
                            ui.ConfigureDetailForm(form);
                            if (form.ShowDialog() == DialogResult.OK)
                            {
                                var cmd = form.GetUpdateCommand();
                                if (cmd != null)
                                {
                                    _owner.CommandExecutor.Execute(cmd);
                                }
                            }
                        } finally {
                            form.Dispose();
                        }
                    }
                }
            };
        }
Ejemplo n.º 20
0
 public override Task <CopyResponse> Copy(CopyRequest request, ServerCallContext context) =>
 GrpcSafeHandler(() => _kvTable.Copy(request));
Ejemplo n.º 21
0
 public void Copy(CopyRequest r)
 {
     _fileStorageService.Copy(r);
 }
        public async Task <OperationStatus> CopyEnvironment(CopyRequest request, CancellationToken cancellationToken)
        {
            var response = await this._handlers.OfType <IRequestHandler <CopyRequest, OperationStatus> >().FirstOrDefault().SendAsync(request, cancellationToken).ConfigureAwait(false);

            return(response);
        }
 // Copy a invoice
 public async Task <Invoice?> CopyInvoiceAsync(int invoiceId, CopyRequest data)
 => await _api.PostAsync <Invoice>($"2.0/kb_invoice/{invoiceId}/copy", data);
 public ProcessResponse Query([FromBody] CopyRequest query)
 {
     return(this._customRepositoryActions.Copy(query, query.Database));
 }