public SettingsDialog()
        {
            InitializeComponent();

            var commands = PerforceCommands.GetInstance();

            SetInitialMsg("Errors will be printed here...");

            try
            {
                _initialPort = PortTextBox.Text = commands.GetP4EnvironmentVar("P4PORT");
            }
            catch (P4Exception)
            {
                // optimization - it's useless to get client and user without port
                return;
            }

            try
            {
                _initialClient = ClientTextBox.Text = commands.GetP4EnvironmentVar("P4CLIENT");
            }
            catch (P4Exception)
            {
            }

            try
            {
                _initialUser = UserTextBox.Text = commands.GetP4EnvironmentVar("P4USER");
            }
            catch (P4Exception)
            {
            }
        }
示例#2
0
        private void ShowDifference()
        {
            var document = MarginCore.GetTextDocument();

            if (document != null)
            {
                PerforceCommands.GetInstance().StartExternalDiff(document);
            }
        }
        private void OnRefresh(object sender, EventArgs e)
        {
            string message_text = null;

            try
            {
                PerforceCommands.GetInstance().RefreshConnection();
                message_text = "Successfully connected!";
            }
            catch (P4Exception ex)
            {
                message_text = ex.Message;
            }

            MessageBox.Show(message_text, "Perforce Connection");
        }
示例#4
0
        internal DiffUpdateBackgroundParser(ITextBuffer textBuffer, ITextBuffer documentBuffer, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService)
            : base(textBuffer, taskScheduler, textDocumentFactoryService)
        {
            _documentBuffer = documentBuffer;
            ReparseDelay    = TimeSpan.FromMilliseconds(500);

            if (TextDocumentFactoryService.TryGetTextDocument(_documentBuffer, out _textDocument))
            {
                if (PerforceCommands.GetInstance().IsDiffPerformed(_textDocument.FilePath))
                {
                    _textDocument.FileActionOccurred += OnFileActionOccurred;
                    // TODO: implement a mechanism that will monitor perforce submit and update diff after submit
                    // Probably class which will check if current changelist already submitted using p4 describe every second can work as workaround
                    // or "Custom Tool": https://stackoverflow.com/questions/16053503/perforce-client-side-pre-commit-hook
                }
            }
        }
        protected IMarginCore TryGetMarginCore(IWpfTextViewHost textViewHost)
        {
            MarginCore marginCore;

            if (textViewHost.TextView.Properties.TryGetProperty(typeof(MarginCore), out marginCore))
            {
                return(marginCore);
            }

            // play nice with other source control providers
            ITextView      textView       = textViewHost.TextView;
            ITextDataModel textDataModel  = textView != null ? textView.TextDataModel : null;
            ITextBuffer    documentBuffer = textDataModel != null ? textDataModel.DocumentBuffer : null;

            if (documentBuffer == null)
            {
                return(null);
            }

            ITextDocument textDocument;

            if (!TextDocumentFactoryService.TryGetTextDocument(documentBuffer, out textDocument))
            {
                return(null);
            }

            var fullPath = GetFullPath(textDocument.FilePath);

            if (fullPath == null)
            {
                return(null);
            }

            if (!PerforceCommands.GetInstance().IsDiffPerformed(fullPath))
            {
                return(null);
            }

            return(textViewHost.TextView.Properties.GetOrCreateSingletonProperty(
                       () => new MarginCore(textViewHost.TextView, TextDocumentFactoryService, ClassificationFormatMapService, EditorFormatMapService)));
        }
示例#6
0
        protected override void ReParseImpl()
        {
            try
            {
                var stopwatch = Stopwatch.StartNew();

                var           snapshot = TextBuffer.CurrentSnapshot;
                ITextDocument textDocument;
                if (!TextDocumentFactoryService.TryGetTextDocument(_documentBuffer, out textDocument))
                {
                    return;
                }

                var diff   = PerforceCommands.GetInstance().GetDiffFor(textDocument, snapshot);
                var result = new DiffParseResultEventArgs(snapshot, stopwatch.Elapsed, diff.ToList());
                OnParseComplete(result);
            }
            catch (InvalidOperationException)
            {
                MarkDirty(true);
                throw;
            }
        }
示例#7
0
        public MarginCore(IWpfTextView textView, ITextDocumentFactoryService textDocumentFactoryService, IClassificationFormatMapService classificationFormatMapService, IEditorFormatMapService editorFormatMapService)
        {
            _textView = textView;

            _classificationFormatMap = classificationFormatMapService.GetClassificationFormatMap(textView);

            _editorFormatMap = editorFormatMapService.GetEditorFormatMap(textView);
            _editorFormatMap.FormatMappingChanged += HandleFormatMappingChanged;

            _parser = new DiffUpdateBackgroundParser(textView.TextBuffer, textView.TextDataModel.DocumentBuffer, TaskScheduler.Default, textDocumentFactoryService);
            _parser.ParseComplete += HandleParseComplete;
            _parser.RequestParse(false);

            PerforceCommands.GetInstance().ConnectionChanged += (sender, e) => _parser.RequestParse(true);

            _textView.Closed += (sender, e) =>
            {
                _editorFormatMap.FormatMappingChanged -= HandleFormatMappingChanged;
                _parser.ParseComplete -= HandleParseComplete;
            };

            UpdateBrushes();
        }
        protected override void Initialize()
        {
            base.Initialize();
            // Add our command handlers for menu (commands must be declared in the .vsct file)
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                CommandID      refreshCommandID = new CommandID(new Guid(PerforceDiffMarginCommandHandler.PerforceDiffMarginStaticToolbarCommandSet), (int)PerforceDiffMarginStaticToolbarCommand.Refresh);
                OleMenuCommand refreshCommand   = new OleMenuCommand(new EventHandler(OnRefresh), refreshCommandID);
                mcs.AddCommand(refreshCommand);

                CommandID      disconnectCommandID = new CommandID(new Guid(PerforceDiffMarginCommandHandler.PerforceDiffMarginStaticToolbarCommandSet), (int)PerforceDiffMarginStaticToolbarCommand.Disconnect);
                OleMenuCommand disconnectCommand   = new OleMenuCommand(new EventHandler(OnDisconnect), disconnectCommandID);
                mcs.AddCommand(disconnectCommand);

                CommandID      settingsCommandID = new CommandID(new Guid(PerforceDiffMarginCommandHandler.PerforceDiffMarginStaticToolbarCommandSet), (int)PerforceDiffMarginStaticToolbarCommand.Settings);
                OleMenuCommand settingsCommand   = new OleMenuCommand(new EventHandler(OnSettings), settingsCommandID);
                mcs.AddCommand(settingsCommand);
            }

            // Initialize PerforceCommands
            PerforceCommands.GetInstance(this);
        }
        private void LoginClick(object sender, RoutedEventArgs e)
        {
            ResultTextBox.Text = "";

            var commands = PerforceCommands.GetInstance();

            if (_initialPort != PortTextBox.Text)
            {
                if (String.IsNullOrEmpty(PortTextBox.Text))
                {
                    SetError("Please, set the address");
                    return;
                }
                try
                {
                    commands.SetNewPort(PortTextBox.Text);
                    commands.SetP4EnvironmentVar("P4PORT", PortTextBox.Text);
                }
                catch (P4Exception ex)
                {
                    SetError("An error occured: " + ex.Message);
                    return;
                }
            }

            if (_initialClient != ClientTextBox.Text)
            {
                try
                {
                    commands.SetP4EnvironmentVar("P4CLIENT", ClientTextBox.Text);
                }
                catch (P4Exception)
                {
                }
            }

            if (_initialUser != UserTextBox.Text)
            {
                try
                {
                    commands.SetP4EnvironmentVar("P4USER", UserTextBox.Text);
                }
                catch (P4Exception)
                {
                }
            }

            string password = PasswordTextBox.Password;

            if (!String.IsNullOrEmpty(password))
            {
                try
                {
                    commands.Login(password);
                    commands.RefreshConnection();
                    SetInfo("Logged in successfully");
                }
                catch (P4Exception ex)
                {
                    SetError("An error occured: " + ex.Message);
                }
            }
            else
            {
                SetError("Please, enter the password");
            }
        }
 private void OnDisconnect(object sender, EventArgs e)
 {
     // TODO: add try-catch?
     PerforceCommands.GetInstance().Disconnect();
     MessageBox.Show("Disconnected", "Perforce Connection");
 }