public IEnumerable<Node> GetNodes(DragDropInfo dragDropInfo)
        {
            try
            {
                if (!dragDropInfo.Data.GetDataPresent(PROJECTITEMFORMAT))
                {
                    _log.Debug("Data not found");
                    return null;
                }

                // create nodes from the projectitems
                var data = dragDropInfo.Data.GetData(PROJECTITEMFORMAT);
                var nodeIsProject = false;
                var droppedData = SolutionExplorerNodeData.DecodeProjectItemData(dragDropInfo.Data, nodeIsProject);

                // find the nodes in the solution
                var solutionItems = findSolutionItems(droppedData);
                if (solutionItems != null) return solutionItems;

                _log.Debug("FAiled to find items in IVSHierarchy. Generating items based on filename only");
                var nodes = droppedData.Select(x => new Node() {Type = getClassNameFromFileName(x.FileName)});
                _log.Debug("Found data");

                return nodes;
            }
            catch (Exception e)
            {
                throw new Exception("GetNodes failed", e);
            }

            return null;
        }
Exemple #2
0
 public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo) {
     Task.Run(async () => {
         var folder = await GetRUserFolder();
         _editorShell.DispatchOnUIThread(() => HandleDrop(dragDropInfo, folder));
     }).DoNotWait();
     return DragDropPointerEffects.None;
 }
Exemple #3
0
        /// <summary>
        /// Called when a file is dropped onto the TextView
        /// </summary>
        /// <param name="dragDropInfo"></param>
        /// <returns></returns>
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            // This function is basically doing three things:
            // 1. Detects user drop position and on ambiguity asks user if replace current link.
            // 2. Detects if user provided file's valid path (in Documentation/Source hierarchy)
            //    exists. If it does, then asks user if the file should be overwritten and copy
            //    the file as needed.
            // 3. Replaces or appends a valid link.

            try
            {
                var spanToReplace = GetSpanToReplace(dragDropInfo); // 1.
                var referenceText = CreateReference(dragDropInfo); // 2.

                using (var editTextView = TextView.TextBuffer.CreateEdit())
                {
                    editTextView.Replace(spanToReplace, referenceText);

                    editTextView.Apply();
                }
            }
            catch (OperationCanceledException)
            {
                // ignore as it is just stopping the whole operation
            }

            return DragDropPointerEffects.Link;
        }
        private static DragDropInfo GetDragDropInfo(UIElement target, DragEventArgs e,
            PokemonDragDropData data)
        {
            var dragDropInfo = new DragDropInfo();
            dragDropInfo.Action = DragDropActions.None;
            int folderIndex = DragDropState.GetDraggingOverIndex(target);

            var collection = (target as FrameworkElement).DataContext as CollectionViewModel;
            if (collection != null && folderIndex != -1)
            {
                dragDropInfo.TargetFolder = collection.Folders[folderIndex];
                if (dragDropInfo.TargetFolder.CanAddPokemon)
                {
                    if (e.KeyStates.HasFlag(DragDropKeyStates.ControlKey))
                    {
                        dragDropInfo.Action = DragDropActions.CopyTo;
                    }
                    else if (dragDropInfo.TargetFolder != data.SourceFolder)
                    {
                        dragDropInfo.Action = DragDropActions.MoveTo;
                    }
                }
            }
            return dragDropInfo;
        }
 public bool CanUnderstand(DragDropInfo dragDropInfo)
 {
     if (!dragDropInfo.Data.GetDataPresent(PROJECTITEMFORMAT))
     {
         return false;
     }
     return true;
 }
        public bool IsDropEnabled(DragDropInfo dragDropInfo)
        {
            _filename = FontDropHandler.GetImageFilename(dragDropInfo);

            if (string.IsNullOrEmpty(_filename))
                return false;

            return this._imageExtensions.Contains(Path.GetExtension(_filename));
        }
        public bool IsDropEnabled(DragDropInfo dragDropInfo)
        {
            _draggedFileName = GetImageFilename(dragDropInfo);
            string ext = Path.GetExtension(_draggedFileName);

            if (!_imageExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase))
                return false;

            return File.Exists(_draggedFileName) || Directory.Exists(_draggedFileName);
        }
        public override IExecuteResult Execute(IEnumerable<Node> nodes, IWpfTextView textView,
            DragDropInfo dragDropInfo)
        {
            var msg = string.Format("You dropped:\n{0}",
                string.Join("\n",
                    nodes.Select(x => string.Format("{0}.{1}.{2}.{3}", x.Assembly, x.Namespace, x.Type, x.Member))));
            _log.Debug(msg);
            MessageBox.Show(msg);

            return ExecuteResult.None;
        }
        public bool IsDropEnabled(DragDropInfo dragDropInfo)
        {
            _imageFilename = dragDropInfo.GetFilePath();

            if (string.IsNullOrEmpty(_imageFilename))
                return false;

            if (_imageExtensions.Contains(Path.GetExtension(_imageFilename)))
                return true;

            return false;
        }
 protected override void Context()
 {
     _repository = A.Fake <DataRepository>();
     _data       = new DragDropInfo(
         new List <ITreeNode>
     {
         new ObservedDataNode(new ClassifiableObservedData {
             Subject = _repository
         })
     });
     base.Context();
 }
Exemple #11
0
        public override bool IsDropEnabled(DragDropInfo dragDropInfo)
        {
            _targetFileName = GetScriptFileName(dragDropInfo);
            if (_targetFileName == null)
            {
                return(false);
            }
            var ext = Path.GetExtension(_targetFileName);

            return(_supportedFileExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase) &&
                   (File.Exists(_targetFileName) || Directory.Exists(_targetFileName)));
        }
 /// <summary>
 /// See <see cref="IDropHandler.HandleDataDropped"/> for more information.
 /// </summary>
 /// <param name="dragDropInfo"></param>
 /// <returns></returns>
 public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
 {
     try
     {
         manager.AddImageAdornment(manager.PreviewImageAdornment.VisualElement);
         return DragDropPointerEffects.Copy;
     }
     finally
     {
         RemovePreviewImage();
     }
 }
        private static void ToolBarGiveFeedback(object sender, Telerik.Windows.DragDrop.GiveFeedbackEventArgs e)
        {
            if (lastInitializedInfo != null && lastInitializedInfo.Tray.Items.Contains(lastInitializedInfo.ToolBar) && !lastInitializedInfo.Tray.IsMouseOver)
            {
                // Handle cases when DragInitialized was raised when the mouse was not in tray's bounds.
                ClearHitTesting(lastInitializedInfo.Tray.Items);
                MoveToolBarToDragVisual(lastInitializedInfo, lastInitializedInfo.Tray);
                lastInitializedInfo = null;
            }

            e.SetCursor(System.Windows.Input.Cursors.SizeAll);
            e.Handled = true;
        }
        private static void TrayDragLeft(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
        {
            RadToolBarTray tray = sender as RadToolBarTray;
            DragDropInfo   info = GetDragDropInfo(e.Data);

            if (tray == null || info == null)
            {
                return;
            }

            ClearHitTesting(tray.Items);
            HideNewBandIndicator(tray);
        }
        public bool IsDropEnabled(DragDropInfo dragDropInfo)
        {
            _fileName = GetImageFilename(dragDropInfo);

            if (string.IsNullOrEmpty(_fileName) || !CommandHelpers.IsFileSupported(_fileName) || _dte.ActiveDocument == null)
                return false;

            string activeFile = Path.GetFileName(_dte.ActiveDocument.FullName);

            if (Constants.FILENAME.Equals(activeFile, StringComparison.OrdinalIgnoreCase))
                return true;

            return false;
        }
Exemple #16
0
        private void HandleDrop(DragDropInfo dragDropInfo, string userFolder)
        {
            var dataObject = dragDropInfo.Data;

            var document = REditorDocument.FindInProjectedBuffers(_wpfTextView.TextBuffer);

            Debug.Assert(document != null, "Text view does not have associated R document.");

            var text = dataObject.GetPlainText(userFolder, dragDropInfo.KeyStates);
            var line = _wpfTextView.TextViewLines.GetTextViewLineContainingYCoordinate(dragDropInfo.Location.Y);

            line = line ?? _wpfTextView.TextViewLines.LastVisibleLine;
            if (line == null)
            {
                return;
            }

            var bufferPosition = line.GetBufferPositionFromXCoordinate(dragDropInfo.Location.X);

            bufferPosition = bufferPosition ?? line.End;

            var textBuffer   = _wpfTextView.TextBuffer;
            var dropPosition = bufferPosition.Value;

            if (REditorSettings.FormatOnPaste)
            {
                _wpfTextView.Caret.MoveTo(dropPosition);
            }

            if (text.StartsWithOrdinal(Environment.NewLine) && Whitespace.IsNewLineBeforePosition(new TextProvider(textBuffer.CurrentSnapshot), dropPosition))
            {
                text = text.TrimStart();
            }

            using (var undoAction = EditorShell.Current.CreateCompoundAction(_wpfTextView, textBuffer)) {
                undoAction.Open(Resources.DragDropOperation);
                textBuffer.Replace(new Span(dropPosition, 0), text);

                if (REditorSettings.FormatOnPaste)
                {
                    RangeFormatter.FormatRange(_wpfTextView, document.TextBuffer, new TextRange(dropPosition, text.Length), REditorSettings.FormatOptions, _editorShell);
                }

                if (_wpfTextView.Selection != null)
                {
                    _wpfTextView.Caret.MoveTo(_wpfTextView.Selection.End);
                }
                undoAction.Commit();
            }
        }
        /// <summary>
        /// Can this handler deal with the dropped object?
        /// </summary>
        /// <param name="DragDropInfo"></param>
        /// <returns></returns>
        public bool IsDropEnabled(DragDropInfo DragDropInfo)
        {
            bool Result = false;

            string DroppedFilename = GetFilename(DragDropInfo);

            if (!string.IsNullOrEmpty(DroppedFilename))
            {
                // We support all file extension types, if not an image or udn file treat as an attachment
                Result = true;
            }

            return(Result);
        }
        protected override void Context()
        {
            _view = A.Fake <IEditTimeProfileAnalysisChartView>();
            _timeProfilerChartPresenter          = A.Fake <ITimeProfileChartPresenter>();
            _timeProfileChartDataCreator         = A.Fake <ITimeProfileChartDataCreator>();
            _populationSimulationAnalysisStarter = A.Fake <IPopulationSimulationAnalysisStarter>();
            _populationAnalysisTask = A.Fake <IPopulationAnalysisTask>();
            _colorGenerator         = A.Fake <IColorGenerator>();
            _observedDataTask       = A.Fake <IObservedDataTask>();
            _pkAnalysisPresenter    = A.Fake <IPopulationPKAnalysisPresenter>();
            _dimensionRepository    = A.Fake <IDimensionRepository>();

            _presenterSettingsTask = A.Fake <IPresentationSettingsTask>();
            sut = new EditTimeProfileAnalysisChartPresenter(_view, _timeProfilerChartPresenter, _timeProfileChartDataCreator,
                                                            _populationSimulationAnalysisStarter, _populationAnalysisTask, _colorGenerator, _observedDataTask, _pkAnalysisPresenter, _dimensionRepository, _presenterSettingsTask);

            _timeProfileAnalysisChart      = new TimeProfileAnalysisChart();
            _populationStatisticalAnalysis = new PopulationStatisticalAnalysis();
            _timeProfileAnalysisChart.PopulationAnalysis = _populationStatisticalAnalysis;
            _populationDataCollector = A.Fake <IPopulationDataCollector>();
            sut.InitializeAnalysis(_timeProfileAnalysisChart, _populationDataCollector);

            _observedDataRepository = DomainHelperForSpecs.ObservedData();
            var data = new DragDropInfo(
                new List <ITreeNode> {
                new ObservedDataNode(new ClassifiableObservedData {
                    Subject = _observedDataRepository
                })
            }
                );

            _dragEventArgs = new DragEventArgs(new DataObject(data), 0, 0, 0, DragDropEffects.All, DragDropEffects.All);

            _chartData = new ChartData <TimeProfileXValue, TimeProfileYValue>(null, null);
            var concentrationDimension = DomainHelperForSpecs.ConcentrationDimensionForSpecs();
            var yAxis = new AxisData(concentrationDimension, concentrationDimension.DefaultUnit, Scalings.Linear);

            _paneData = new PaneData <TimeProfileXValue, TimeProfileYValue>(yAxis);
            _chartData.AddPane(_paneData);
            A.CallTo(_timeProfileChartDataCreator).WithReturnType <ChartData <TimeProfileXValue, TimeProfileYValue> >().Returns(_chartData);

            var outputField = new PopulationAnalysisOutputField {
                Dimension = DomainHelperForSpecs.MassConcentrationDimensionForSpecs()
            };

            _populationStatisticalAnalysis.Add(outputField);

            A.CallTo(() => _dimensionRepository.MergedDimensionFor(A <NumericFieldContext> ._)).Returns(concentrationDimension);
        }
Exemple #19
0
        public bool IsDropEnabled(DragDropInfo dragDropInfo)
        {
            _imageFilename = FontDropHandler.GetImageFilename(dragDropInfo);

            if (!string.IsNullOrEmpty(_imageFilename))
            {
                string fileExtension = Path.GetExtension(_imageFilename).ToLowerInvariant();
                if (this._imageExtensions.Contains(fileExtension))
                {
                    return(true);
                }
            }

            return(false);
        }
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            string reference = FileHelpers.RelativePath(ProjectHelpers.GetRootFolder(), _draggedFilename);

            if (reference.StartsWith("http://localhost:"))
            {
                int index = reference.IndexOf('/', 20);
                if (index > -1)
                    reference = reference.Substring(index + 1).ToLowerInvariant();
            }

            _view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, string.Format(_format, reference));

            return DragDropPointerEffects.Copy;
        }
Exemple #21
0
        public bool IsDropEnabled(DragDropInfo dragDropInfo)
        {
            _draggedFilename = GetImageFilename(dragDropInfo);

            if (!string.IsNullOrEmpty(_draggedFilename))
            {
                string fileExtension = Path.GetExtension(_draggedFilename).ToLowerInvariant();
                if (this._formats.ContainsKey(fileExtension))
                {
                    return(true);
                }
            }

            return(false);
        }
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            string reference = FileHelpers.RelativePath(EditorExtensionsPackage.DTE.ActiveDocument.FullName, _imageFilename);

            if (reference.Contains("://"))
            {
                int index = reference.IndexOf('/', 12);
                if (index > -1)
                    reference = reference.Substring(index).ToLowerInvariant();
            }

            _view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, string.Format(_background, reference));

            return DragDropPointerEffects.Copy;
        }
        public DragDropPointerEffects HandleDraggingOver(DragDropInfo dragDropInfo)
        {
            try
            {
                //set the insertion point to follow the drop location
                _tgt.Caret.MoveTo(dragDropInfo.VirtualBufferPosition);

                return DragDropPointerEffects.Copy;
            }
            catch (Exception e)
            {
                _log.Error("HandleDraggingOver", e );
            }
            return DragDropPointerEffects.Copy;
        }
        public bool IsDropEnabled(DragDropInfo dragDropInfo)
        {
            _imageFilename = FontDropHandler.GetImageFilename(dragDropInfo);

            if (!string.IsNullOrEmpty(_imageFilename))
            {
                string fileExtension = Path.GetExtension(_imageFilename).ToLowerInvariant();
                if (this._imageExtensions.Contains(fileExtension))
                {
                    return true;
                }
            }

            return false;
        }
Exemple #25
0
        private static DragDropInfo GetDragDropInfo(UIElement target, DragEventArgs e,
            PokemonDragDropData data)
        {
            var dragDropInfo = new DragDropInfo();
            dragDropInfo.Action = DragDropActions.None;

            dragDropInfo.Folder = (target as FrameworkElement).DataContext as IFolderViewModel;
            if (dragDropInfo.Folder == null)
                return dragDropInfo;

            dragDropInfo.InsertIndex = DragDropState.GetInsertionIndex(target);
            dragDropInfo.PokemonIndex = DragDropState.GetDraggingOverIndex(target);

            if (dragDropInfo.PokemonIndex != -1)
            {
                if (data.SourceFolder != dragDropInfo.Folder ||
                    data.PokemonIndexInFolder != dragDropInfo.PokemonIndex)
                {
                    if (e.KeyStates.HasFlag(DragDropKeyStates.ControlKey))
                    {
                        dragDropInfo.Action = DragDropActions.Replace;
                    }
                    else
                    {
                        dragDropInfo.Action = DragDropActions.SwapWith;
                    }
                }
            }
            else if (dragDropInfo.InsertIndex != -1)
            {
                if (e.KeyStates.HasFlag(DragDropKeyStates.ControlKey))
                {
                    if (dragDropInfo.Folder.CanAddPokemon)
                        dragDropInfo.Action = DragDropActions.CopyTo;
                }
                else if (data.SourceFolder != dragDropInfo.Folder)//movement between folders
                {
                    if (dragDropInfo.Folder.CanAddPokemon)
                        dragDropInfo.Action = DragDropActions.MoveTo;
                }
                else//movement within folder
                {
                    if (IsValidMovement(data.PokemonIndexInFolder, dragDropInfo.InsertIndex))
                        dragDropInfo.Action = DragDropActions.MoveTo;
                }
            }
            return dragDropInfo;
        }
        private string GetFilename(DragDropInfo info)
        {
            if (info.Data.GetData("CF_VSSTGPROJECTITEMS") is MemoryStream stream)
            {
                var    tryCount  = 0;
                string reference = null;

                // Calls to DragQueryFile (within EnumerateDroppedFiles) aren't returning consistently.
                // Retrying a few times (although far from ideal) seems to work ok.
                while (tryCount < 5 && string.IsNullOrWhiteSpace(reference))
                {
                    reference = EnumerateDroppedFiles(stream).FirstOrDefault();
                    tryCount += 1;
                }

                if (ErrorHandler.Succeeded(this.solution.GetItemOfProjref(reference, out IVsHierarchy hierarchy, out uint itemId, out _, new VSUPDATEPROJREFREASON[1])))
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            string reference = FileHelpers.RelativePath(EditorExtensionsPackage.DTE.ActiveDocument.FullName, _imageFilename);

            if (reference.StartsWith("http://localhost:"))
            {
                int index = reference.IndexOf('/', 24);
                if (index > -1)
                    reference = reference.Substring(index).ToLowerInvariant();
            }
            reference = HttpUtility.UrlPathEncode(reference);

            _view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, string.Format(_import, reference));

            return DragDropPointerEffects.Copy;
        }
        public bool IsDropEnabled(DragDropInfo dragDropInfo)
        {
            _imageFilename = FontDropHandler.GetImageFilename(dragDropInfo);

            if (string.IsNullOrEmpty(_imageFilename))
            {
                return(false);
            }

            if (_imageExtensions.Contains(Path.GetExtension(_imageFilename)))
            {
                return(true);
            }

            return(false);
        }
        private static void TrayDraggedOver(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
        {
            RadToolBarTray tray = sender as RadToolBarTray;
            DragDropInfo   info = GetDragDropInfo(e.Data);

            if (tray == null || info == null)
            {
                return;
            }

            var  positionInfo         = BandsUtilities.CalculateToolBarPositionInfo(info.ToolBar, tray, e.GetPosition(tray));
            bool allowNewBandCreation = GetNewBandMode(tray) == NewBandMode.Live;

            BandsUtilities.UpdateToolBarPosition(tray, info.ToolBar, positionInfo, allowNewBandCreation);
            UpdateNewBandIndicator(info, positionInfo, tray);
        }
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            if (File.Exists(draggedFilename))
            {
                //var files = GetRelativeFiles(draggedFilename);
                //string[] sources = new string[files.Count()];

                //for (int i = 0; i < files.Count(); i++)
                //{
                //    string file = files.ElementAt(i);
                //    string extension = Path.GetExtension(file).ToLowerInvariant();
                //    string reference = RelativePath(document.FilePath, file);

                //    if (reference.StartsWith("http://localhost:"))
                //    {
                //        int index = reference.IndexOf('/', 24);
                //        if (index > -1)
                //            reference = reference.Substring(index + 1).ToLowerInvariant();
                //    }

                //    sources[i] = string.Format(fontUrls, reference, formats[extension]);
                //}

                //string sourceUrls = string.Join(", ", sources);
                string fontFamily;
                view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, GetCodeFromFile(draggedFilename, out fontFamily));

                return DragDropPointerEffects.Copy;
            }
            else if (draggedFilename.StartsWith("http://localhost:", StringComparison.OrdinalIgnoreCase))
            {
                //int index = draggedFilename.IndexOf('/', 24);
                //if (index > -1)
                //    draggedFilename = draggedFilename.Substring(index).ToLowerInvariant();

                //string extension = Path.GetExtension(draggedFilename).ToLowerInvariant();
                //string sourceUrl = string.Format(fontUrls, draggedFilename, formats[extension]);

                view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, GetCodeFromLocalhost());

                return DragDropPointerEffects.Copy;
            }
            else
            {
                return DragDropPointerEffects.None;
            }
        }
Exemple #31
0
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            if (File.Exists(draggedFilename))
            {
                //var files = GetRelativeFiles(draggedFilename);
                //string[] sources = new string[files.Count()];

                //for (int i = 0; i < files.Count(); i++)
                //{
                //    string file = files.ElementAt(i);
                //    string extension = Path.GetExtension(file).ToLowerInvariant();
                //    string reference = RelativePath(document.FilePath, file);

                //    if (reference.StartsWith("http://localhost:"))
                //    {
                //        int index = reference.IndexOf('/', 24);
                //        if (index > -1)
                //            reference = reference.Substring(index + 1).ToLowerInvariant();
                //    }

                //    sources[i] = string.Format(fontUrls, reference, formats[extension]);
                //}

                //string sourceUrls = string.Join(", ", sources);
                string fontFamily;
                view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, GetCodeFromFile(draggedFilename, out fontFamily));

                return(DragDropPointerEffects.Copy);
            }
            else if (draggedFilename.StartsWith("http://localhost:"))
            {
                //int index = draggedFilename.IndexOf('/', 24);
                //if (index > -1)
                //    draggedFilename = draggedFilename.Substring(index).ToLowerInvariant();

                //string extension = Path.GetExtension(draggedFilename).ToLowerInvariant();
                //string sourceUrl = string.Format(fontUrls, draggedFilename, formats[extension]);

                view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, GetCodeFromLocalhost(draggedFilename));

                return(DragDropPointerEffects.Copy);
            }
            else
            {
                return(DragDropPointerEffects.None);
            }
        }
        /// <summary>
        /// See <see cref="IDropHandler.HandleDraggingOver"/> for more information.
        /// </summary>
        /// <param name="dragDropInfo"></param>
        /// <returns></returns>
        public DragDropPointerEffects HandleDraggingOver(DragDropInfo dragDropInfo)
        {
            this.manager.PreviewImageAdornment.MoveTo(dragDropInfo.Location);

            ITextViewLine targetLine = this.manager.GetTargetTextViewLine(this.manager.PreviewImageAdornment.VisualElement);
            if (targetLine != null && targetLine.Length > 0)
            {
                this.manager.HighlightLineAdornment.Highlight(targetLine);

                return DragDropPointerEffects.Copy;
            }
            else
            {
                this.manager.HighlightLineAdornment.Clear();
                return DragDropPointerEffects.None;
            }
        }
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            string reference = FileHelpers.RelativePath(EditorExtensionsPackage.DTE.ActiveDocument.FullName, _filename);

            if (reference.StartsWith("http://localhost:", StringComparison.OrdinalIgnoreCase))
            {
                reference = Path.Combine(ProjectHelpers.GetRootFolder(),
                    Path.Combine(new Uri(reference).Segments).TrimStart('/'));
            }

            reference = HttpUtility.UrlPathEncode(FileHelpers.RelativePath(_targetFileName, reference));

            string import = Path.GetExtension(_filename).Equals(".css", StringComparison.OrdinalIgnoreCase) ? _cssImport : _preprocessorImport;
            _view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, string.Format(CultureInfo.CurrentCulture, import, reference));

            return DragDropPointerEffects.Copy;
        }
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            string reference = FileHelpers.RelativePath(ProjectHelpers.GetRootFolder(), _draggedFilename);

            if (reference.StartsWith("http://localhost:", StringComparison.OrdinalIgnoreCase))
            {
                int index = reference.IndexOf('/', 20);
                if (index > -1)
                {
                    reference = reference.Substring(index + 1).ToLowerInvariant();
                }
            }

            _view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, string.Format(_format, reference));

            return(DragDropPointerEffects.Copy);
        }
Exemple #35
0
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            string reference = FileHelpers.RelativePath(EditorExtensionsPackage.DTE.ActiveDocument.FullName, _imageFilename);

            if (reference.Contains("://"))
            {
                int index = reference.IndexOf('/', 12);
                if (index > -1)
                {
                    reference = reference.Substring(index).ToLowerInvariant();
                }
            }

            _view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, string.Format(_background, reference));

            return(DragDropPointerEffects.Copy);
        }
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            string reference = FileHelpers.RelativePath(EditorExtensionsPackage.DTE.ActiveDocument.FullName, _filename);

            if (reference.StartsWith("http://localhost:"))
            {
                int index = reference.IndexOf('/', 24);
                if (index > -1)
                    reference = reference.Substring(index).ToLowerInvariant();
            }
            reference = HttpUtility.UrlPathEncode(reference);

            string import = Path.GetExtension(_filename).Equals(".less", StringComparison.OrdinalIgnoreCase) ? _lessImport : _cssImport;
            _view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, string.Format(import, reference));

            return DragDropPointerEffects.Copy;
        }
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            string reference = FileHelpers.RelativePath(EditorExtensionsPackage.DTE.ActiveDocument.FullName, _imageFilename);

            if (reference.StartsWith("http://localhost:"))
            {
                int index = reference.IndexOf('/', 24);
                if (index > -1)
                {
                    reference = reference.Substring(index).ToLowerInvariant();
                }
            }
            reference = HttpUtility.UrlPathEncode(reference);

            _view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, string.Format(_import, reference));

            return(DragDropPointerEffects.Copy);
        }
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            if (File.Exists(draggedFilename))
            {
                string fontFamily;
                view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, GetCodeFromFile(draggedFilename, out fontFamily));

                return DragDropPointerEffects.Copy;
            }
            else if (draggedFilename.StartsWith("http://localhost:", StringComparison.OrdinalIgnoreCase))
            {
                view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, GetCodeFromLocalhost());

                return DragDropPointerEffects.Copy;
            }
            else
                return DragDropPointerEffects.None;
        }
Exemple #39
0
        public bool IsDropEnabled(DragDropInfo dragDropInfo)
        {
            _fileName = GetImageFilename(dragDropInfo);

            if (string.IsNullOrEmpty(_fileName) || !CommandHelpers.IsFileSupported(_fileName) || VSPackage._dte.ActiveDocument == null)
            {
                return(false);
            }

            string activeFile = Path.GetFileName(VSPackage._dte.ActiveDocument.FullName);

            if (Constants.FILENAME.Equals(activeFile, StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            return(false);
        }
Exemple #40
0
        public bool IsDropEnabled(DragDropInfo dragDropInfo)
        {
            //if (!Path.GetExtension(document.FilePath).Equals(".css", StringComparison.OrdinalIgnoreCase))
            //    return false;

            draggedFilename = GetImageFilename(dragDropInfo);

            if (!string.IsNullOrEmpty(draggedFilename))
            {
                string fileExtension = Path.GetExtension(draggedFilename).ToLowerInvariant();
                if (this.formats.ContainsKey(fileExtension))
                {
                    return(true);
                }
            }

            return(false);
        }
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            string reference = FileHelpers.RelativePath(EditorExtensionsPackage.DTE.ActiveDocument.FullName, _imageFilename);

            if (reference.StartsWith("http://localhost:", StringComparison.OrdinalIgnoreCase))
            {
                int index = reference.IndexOf('/', 24);
                if (index > -1)
                    reference = reference.Substring(index).ToLowerInvariant();
            }

            reference = reference.Trim('/');
            string comment = string.Format(CultureInfo.CurrentCulture, _background, reference);

            _view.TextBuffer.Insert(0, comment + Environment.NewLine);

            return DragDropPointerEffects.Copy;
        }
Exemple #42
0
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            string reference = FileHelpers.RelativePath(EditorExtensionsPackage.DTE.ActiveDocument.FullName, _filename);

            if (reference.StartsWith("http://localhost:", StringComparison.OrdinalIgnoreCase))
            {
                reference = Path.Combine(ProjectHelpers.GetRootFolder(),
                                         Path.Combine(new Uri(reference).Segments).TrimStart('/'));
            }

            reference = HttpUtility.UrlPathEncode(FileHelpers.RelativePath(_targetFileName, reference));

            string import = Path.GetExtension(_filename).Equals(".css", StringComparison.OrdinalIgnoreCase) ? _cssImport : _preprocessorImport;

            _view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, string.Format(CultureInfo.CurrentCulture, import, reference));

            return(DragDropPointerEffects.Copy);
        }
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            ITextDocument document;

            if (!_documentFactory.TryGetTextDocument(_view.TextDataModel.DocumentBuffer, out document))
                return DragDropPointerEffects.None;

            var snapshot = _view.TextBuffer.CurrentSnapshot;
            string bufferContent = snapshot.GetText();
            var json = CommandHelpers.GetJsonContent(document.FilePath, _fileName, bufferContent);

            using (var edit = _view.TextBuffer.CreateEdit())
            {
                edit.Replace(0, snapshot.Length, json.ToString());
                edit.Apply();
            }

            return DragDropPointerEffects.Link;
        }
        private static void ToolBarDragDropCompleted(object sender, DragDropCompletedEventArgs e)
        {
            RadToolBar   toolBar = e.Source as RadToolBar;
            DragDropInfo info    = GetDragDropInfo(e.Data);

            if (toolBar == null || info == null)
            {
                return;
            }

            DragDropManager.RemoveDragDropCompletedHandler(info.ToolBar, ToolBarDragDropCompleted);

            ClearActiveToolBarStyle(info.ToolBar);
            ClearHitTesting(info.Tray.Items);

            HideNewBandIndicator(info.Tray);

            e.Handled = true;
        }
        /// <summary>
        /// Get the dropped filename
        /// </summary>
        /// <param name="Info"></param>
        /// <returns></returns>
        private static string GetFilename(DragDropInfo Info)
        {
            DataObject Data = new DataObject(Info.Data);

            if (Info.Data.GetDataPresent(DragDropHandlerProvider.FileDropDataFormat))
            {
                // The drag and drop operation came from the file system
                StringCollection Files = Data.GetFileDropList();

                if (Files != null && Files.Count == 1)
                {
                    return(Files[0]);
                }
            }
            else if (Info.Data.GetDataPresent(DragDropHandlerProvider.VSProjectStorageItemDataFormat))
            {
                // The drag and drop operation came from the VS solution explorer as a storage item
                return(Data.GetText());
            }
            else if (Info.Data.GetDataPresent(DragDropHandlerProvider.VSProjectReferenceItemDataFormat))
            {
                // The drag and drop operation came from the VS solution explorer as a reference item have to
                // get the selected item from the solution explorer
                DTE2 dte = Package.GetGlobalService(typeof(DTE)) as DTE2;

                UIHierarchy solutionExplorer = dte.ToolWindows.SolutionExplorer;

                var SolutionExplorerSeclectedItems = solutionExplorer.SelectedItems as System.Array;

                if (SolutionExplorerSeclectedItems != null && SolutionExplorerSeclectedItems.Length == 1)
                {
                    foreach (UIHierarchyItem SolutionExplorerSelectedItem in SolutionExplorerSeclectedItems)
                    {
                        ProjectItem SolutionExplorerSelectedObject = SolutionExplorerSelectedItem.Object as ProjectItem;

                        return(SolutionExplorerSelectedObject.Properties.Item("FullPath").Value.ToString());
                    }
                }
            }

            return(null);
        }
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            string reference = FileHelpers.RelativePath(WebEssentialsPackage.DTE.ActiveDocument.FullName, _imageFilename);

            if (reference.Contains("://"))
            {
                int index = reference.IndexOf('/', 12);
                if (index > -1)
                    reference = reference.Substring(index);
            }
            reference = HttpUtility.UrlPathEncode(reference);

            ITextDocument document;
            if (!_documentFactory.TryGetTextDocument(_view.TextDataModel.DocumentBuffer, out document))
                return DragDropPointerEffects.None;

            _view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, string.Format(CultureInfo.CurrentCulture, MarkdownTemplate, Path.GetFileName(reference), reference, HttpUtility.HtmlAttributeEncode(reference)));

            return DragDropPointerEffects.Link;
        }
Exemple #47
0
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            var position = dragDropInfo.VirtualBufferPosition.Position;

            var insertLineLength = this.view.GetTextViewLineContainingBufferPosition(position).Length;

            ThreadHelper.JoinableTaskFactory.Run(async() =>
            {
                var logic = new DropHandlerLogic(this.logger, this.vs, this.fileSystem);

                var textOutput = await logic.ExecuteAsync(this.draggedFilename, insertLineLength);

                if (!string.IsNullOrEmpty(textOutput))
                {
                    this.view.TextBuffer.Insert(position.Position, textOutput);
                }
            });

            return(DragDropPointerEffects.Copy);
        }
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            string reference = FileHelpers.RelativePath(EditorExtensionsPackage.DTE.ActiveDocument.FullName, _imageFilename);

            if (reference.StartsWith("http://localhost:", StringComparison.OrdinalIgnoreCase))
            {
                int index = reference.IndexOf('/', 24);
                if (index > -1)
                {
                    reference = reference.Substring(index).ToLowerInvariant();
                }
            }

            reference = reference.Trim('/');
            string comment = string.Format(CultureInfo.CurrentCulture, _background, reference);

            _view.TextBuffer.Insert(0, comment + Environment.NewLine);

            return(DragDropPointerEffects.Copy);
        }
Exemple #49
0
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            if (File.Exists(draggedFilename))
            {
                string fontFamily;
                view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, GetCodeFromFile(draggedFilename, out fontFamily));

                return(DragDropPointerEffects.Copy);
            }
            else if (draggedFilename.StartsWith("http://localhost:", StringComparison.OrdinalIgnoreCase))
            {
                view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, GetCodeFromLocalhost());

                return(DragDropPointerEffects.Copy);
            }
            else
            {
                return(DragDropPointerEffects.None);
            }
        }
Exemple #50
0
        private void HandleDrop(DragDropInfo dragDropInfo, string userFolder) {
            var dataObject = dragDropInfo.Data;

            var document = REditorDocument.FindInProjectedBuffers(_wpfTextView.TextBuffer);
            Debug.Assert(document != null, "Text view does not have associated R document.");

            var text = dataObject.GetPlainText(userFolder, dragDropInfo.KeyStates);
            var line = _wpfTextView.TextViewLines.GetTextViewLineContainingYCoordinate(dragDropInfo.Location.Y);
            line = line ?? _wpfTextView.TextViewLines.LastVisibleLine;
            if (line == null) {
                return;
            }

            var bufferPosition = line.GetBufferPositionFromXCoordinate(dragDropInfo.Location.X);
            bufferPosition = bufferPosition ?? line.End;

            var textBuffer = _wpfTextView.TextBuffer;
            var dropPosition = bufferPosition.Value;

            if (REditorSettings.FormatOnPaste) {
                _wpfTextView.Caret.MoveTo(dropPosition);
            }

            if (text.StartsWithOrdinal(Environment.NewLine) && Whitespace.IsNewLineBeforePosition(new TextProvider(textBuffer.CurrentSnapshot), dropPosition)) {
                text = text.TrimStart();
            }

            using (var undoAction = EditorShell.Current.CreateCompoundAction(_wpfTextView, textBuffer)) {
                undoAction.Open(Resources.DragDropOperation);
                textBuffer.Replace(new Span(dropPosition, 0), text);

                if (REditorSettings.FormatOnPaste) {
                    RangeFormatter.FormatRange(_wpfTextView, document.TextBuffer, new TextRange(dropPosition, text.Length), REditorSettings.FormatOptions, _editorShell);
                }

                if (_wpfTextView.Selection != null) {
                    _wpfTextView.Caret.MoveTo(_wpfTextView.Selection.End);
                }
                undoAction.Commit();
            }
        }
Exemple #51
0
        protected override void Context()
        {
            _repository1 = A.Fake <DataRepository>();
            _repository2 = A.Fake <DataRepository>();
            var rootNode           = new RootNode(new RootNodeType("ObservedDataFolder", ApplicationIcons.ObservedDataFolder, ClassificationType.ObservedData));
            var classificationNode = new ClassificationNode(new Classification());

            classificationNode.AddChild(new ObservedDataNode(new ClassifiableObservedData {
                Subject = _repository1
            }));
            rootNode.AddChild(classificationNode);
            rootNode.AddChild(new ObservedDataNode(new ClassifiableObservedData {
                Subject = _repository2
            }));
            _data = new DragDropInfo(
                new List <ITreeNode>
            {
                rootNode
            });
            base.Context();
        }
Exemple #52
0
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            ITextDocument document;

            if (!_documentFactory.TryGetTextDocument(_view.TextDataModel.DocumentBuffer, out document))
            {
                return(DragDropPointerEffects.None);
            }

            var    snapshot      = _view.TextBuffer.CurrentSnapshot;
            string bufferContent = snapshot.GetText();
            var    json          = CommandHelpers.GetJsonContent(document.FilePath, _fileName, bufferContent);

            using (var edit = _view.TextBuffer.CreateEdit())
            {
                edit.Replace(0, snapshot.Length, json.ToString());
                edit.Apply();
            }

            return(DragDropPointerEffects.Link);
        }
Exemple #53
0
        public static string GetImageFilename(DragDropInfo info)
        {
            DataObject data = new DataObject(info.Data);

            if (info.Data.GetDataPresent("FileDrop"))
            {
                // The drag and drop operation came from the file system
                StringCollection files = data.GetFileDropList();

                if (files != null && files.Count == 1)
                {
                    return(files[0]);
                }
            }
            else if (info.Data.GetDataPresent("CF_VSSTGPROJECTITEMS"))
            {
                return(data.GetText());
            }

            return(null);
        }
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            //dump(dragDropInfo);
            var nodes = getNodesfromDropInfo(dragDropInfo);

            if (nodes == null)
            {
                _log.Debug("did not understand dropped info");
                return DragDropPointerEffects.None;
            }
            if (_dropAction == null)
            {
                _log.Debug("No DropAction specified");
                return DragDropPointerEffects.None;
            }

            var result = _dropAction.Execute(nodes, _tgt, dragDropInfo);
            if (result.DropActionResultEnum  == DropActionResultEnum.AllowCopy) return DragDropPointerEffects.Copy;

            return DragDropPointerEffects.None;
        }
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            var    position = dragDropInfo.VirtualBufferPosition.Position;
            var    line     = _view.GetTextViewLineContainingBufferPosition(position);
            string text     = PackageUtilities.MakeRelative(_documentFileName, _draggedFileName)
                              .Replace("\\", "/");

            // Insert a new line if dragged after existing text
            if (line.Start < position)
            {
                text = Environment.NewLine + text;
            }

            using (var edit = _view.TextBuffer.CreateEdit())
            {
                edit.Insert(position, text);
                edit.Apply();
            }

            return(DragDropPointerEffects.Copy);
        }
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            if (File.Exists(_draggedFilename))
            {
                string fontFamily;
                _view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, GetCodeFromFile(_draggedFilename, out fontFamily));

                return DragDropPointerEffects.Copy;
            }
            else if (_draggedFilename.StartsWith("http://localhost:"))
            {

                _view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, GetCodeFromLocalhost(_draggedFilename));

                return DragDropPointerEffects.Copy;
            }
            else
            {
                return DragDropPointerEffects.None;
            }
        }
        public IExecuteResult Execute(IEnumerable<Node> enodes, IWpfTextView textView, DragDropInfo dragDropInfo)
        {
            var dropLocation = GetDropLocation();
            var nodes = new List<Node>(enodes);
            normaliseNamespaces(dropLocation, nodes);

            var dropAction = getDropAction(nodes, dragDropInfo, dropLocation);

            if (dropAction != null)
            {
                // store the start buffer position
                var droppedPosition = dragDropInfo.VirtualBufferPosition.Position.Position;

                var result =  dropAction.Execute(nodes, textView, dragDropInfo);

                if (result.SelectAfterDrop)
                {

                    var startLine = textView.TextSnapshot.GetLineFromPosition(droppedPosition);
                    if (result.SelectionStartLine > 0)
                    {
                        startLine = textView.TextSnapshot.GetLineFromLineNumber(result.SelectionStartLine);
                    }
                    var start = new VirtualSnapshotPoint(startLine,Math.Max(0,  result.SelectionStartInChars));

                    var endLine = startLine;
                    if (result.SelectionHeightInLines > 1)
                       endLine= textView.TextSnapshot.GetLineFromLineNumber(startLine.LineNumber +
                                                                    result.SelectionHeightInLines - 1);

                    var end = new VirtualSnapshotPoint(endLine, result.SelectionWidthInChars + result.SelectionStartInChars );
                    textView.Selection.Mode = TextSelectionMode.Box;

                    textView.Selection.Select(start, end);
                }
                textView.Caret.MoveTo(textView.Selection.End);

            }
            return ExecuteResult.None ;
        }
Exemple #58
0
        protected override void Context()
        {
            _repository1 = new DataRepository();
            _repository2 = new DataRepository();
            var classificationNode = new ClassificationNode(new Classification {
                ClassificationType = ClassificationType.ObservedData
            });

            classificationNode.AddChild(new ObservedDataNode(new ClassifiableObservedData {
                Subject = _repository1
            }));
            classificationNode.AddChild(new ObservedDataNode(new ClassifiableObservedData {
                Subject = _repository2
            }));

            _data = new DragDropInfo(
                new List <ITreeNode>
            {
                classificationNode
            });
            base.Context();
        }
Exemple #59
0
        public static string GetImageFilename(DragDropInfo info)
        {
            DataObject data = new DataObject(info.Data);

            if (info.Data.GetDataPresent("FileDrop"))
            {
                // The drag and drop operation came from the file system
                StringCollection files = data.GetFileDropList();

                if (files != null && files.Count == 1)
                {
                    return files[0];
                }
            }
            else if (info.Data.GetDataPresent("CF_VSSTGPROJECTITEMS"))
            {
                // The drag and drop operation came from the VS solution explorer
                return data.GetText();
            }

            return null;
        }
        private static void TrayDragEntered(object sender, Telerik.Windows.DragDrop.DragEventArgs e)
        {
            RadToolBarTray tray = sender as RadToolBarTray;
            DragDropInfo   info = GetDragDropInfo(e.Data);

            if (tray == null || info == null)
            {
                return;
            }

            lastInitializedInfo = null;

            if (!tray.Items.Contains(info.ToolBar))
            {
                var positionInfo = BandsUtilities.CalculateToolBarPositionInfo(info.ToolBar, tray, e.GetPosition(tray));
                MoveToolBarToTray(info, tray);
                bool allowNewBandCreation = GetNewBandMode(tray) == NewBandMode.Live;
                BandsUtilities.UpdateToolBarPosition(tray, info.ToolBar, positionInfo, allowNewBandCreation);
                UpdateNewBandIndicator(info, positionInfo, tray);
            }

            e.Handled = true;
        }