Esempio n. 1
0
        public void OpenProgram(string fullpath)
        {
            var openedProgram = OpenedDocuments.FirstOrDefault(op => op.ProgramFullPath == fullpath);

            if (openedProgram != null)
            {
                DocumentOpened?.Invoke(this, new DocumentOpenEventArgs(openedProgram));
                return;
            }

            var programforOpening =
                RecentPrograms.FirstOrDefault(p => p.ProgramFullPath == fullpath);

            if (programforOpening == null)
            {
                programforOpening = ProgramViewModel.Create(fullpath, this, TvcStudioSettings);
                RecentPrograms.Add(programforOpening);
            }

            if (programforOpening.ProgramState == ProgramState.NotFound)
            {
                TraceEngine.TraceError($"{programforOpening.ProgramFullPath} beolvasása sikertelen, a file nem található!");
                return;
            }

            openedProgram = programforOpening.GetDocumentViewModel();
            openedProgram.DocumentClosedEvent += OnDocumentClose;
            OpenedDocuments.Add(openedProgram);
            programforOpening.ProgramState = ProgramState.Opened;
            DocumentOpened?.Invoke(this, new DocumentOpenEventArgs(openedProgram));
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
                CurrentDocument = new TournamentViewModel(CreateDesignTimeVm());
                OpenedDocuments.Add(CurrentDocument);
            }
            else
            {
                new List <Model.Models.Tournament>(App.RestClient.GetAllWithHttpMessagesAsync().Result.Body).ForEach(t => Tournaments.Add(new TournamentViewModel(t)));
            }

            MessengerInstance.Register <OpenTournamentMessage>(this, m =>
            {
                OpenedDocuments.Add(m.Tournament);
                CurrentDocument = m.Tournament;
            });
            MessengerInstance.Register <CloseTournamentMessage>(this, m =>
            {
                if (OpenedDocuments.Contains(m.Sender))
                {
                    CurrentDocument = OpenedDocuments[0];
                    OpenedDocuments.Remove(m.Sender);
                }
            });
        }
Esempio n. 3
0
        public void OpenReadonlyDocument(string fullPath)
        {
            var openedProgram = OpenedDocuments.FirstOrDefault(op => op.ProgramFullPath == fullPath);

            if (openedProgram != null)
            {
                DocumentOpened?.Invoke(this, new DocumentOpenEventArgs(openedProgram));
                return;
            }

            openedProgram = new ReadOnlyDocumentViewModel(fullPath, TvcStudioSettings);
            openedProgram.DocumentClosedEvent += OnDocumentClose;
            OpenedDocuments.Add(openedProgram);
            DocumentOpened?.Invoke(this, new DocumentOpenEventArgs(openedProgram));
        }
Esempio n. 4
0
        private void OpenCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter           = "RTF-файлы (*.rtf)|*.rtf";
            ofd.InitialDirectory = Directory.GetCurrentDirectory();

            if (ofd.ShowDialog() == true)
            {
                bool sameFileIsOpen = false;

                foreach (UserDocumentTab udt in Tabs.Items)
                {
                    if (udt.Path == ofd.FileName)
                    {
                        sameFileIsOpen = true;
                        break;
                    }
                }

                if (!sameFileIsOpen)
                {
                    AddNewTab();

                    UserDocumentTab currentUserDocumentTab = GetSelectedUserDocumentTab();
                    RichTextBox     documentContent        = (currentUserDocumentTab.Content as RichTextBox);

                    using (FileStream fs = new FileStream(ofd.FileName, FileMode.Open))
                    {
                        new TextRange(documentContent.Document.ContentStart, documentContent.Document.ContentEnd).Load(fs, DataFormats.Rtf);

                        currentUserDocumentTab.Header = ofd.SafeFileName;
                        currentUserDocumentTab.Path   = ofd.FileName;
                        OpenedDocuments.Add(ofd.FileName);

                        UpdateStatusBar();
                    }
                    ChangeWindowTitle();
                }
            }
        }