Exemplo n.º 1
0
        public static Workplace Open(string path)
        {
            Workplace doc = SerializableObject <Workplace> .Open(path);

            doc.File = new System.IO.FileInfo(path);
            return(doc);
        }
Exemplo n.º 2
0
        public void OpenWorkplace(Workplace workplace)
        {
            if (CloseWorkplace())
            {
                this.activeWorkplace = workplace;
                this.OnActiveWorkplaceOpen(EventArgs.Empty);

                mruWorkplaces.Insert(workplace.File.FullName);
            }
        }
Exemplo n.º 3
0
        public void OpenDocument(String fullName, Workplace owner)
        {
            // First: verify if the document isn't already open
            IDockContent[] openDocuments = dockPanel.DocumentsToArray();

            foreach (SinapseDocumentView openDocument in openDocuments)
            {
                if (openDocument.Document != null &&
                    openDocument.Document.File.FullName == fullName)
                {
                    // The document was already open
                    openDocument.DockHandler.Show(); // Activate it
                    return;
                }
            }

            // The document wasn't open, lets open it:
            ISinapseDocument document = DocumentManager.Open(fullName);
            document.Owner = owner; // If we have an owner Workplace, set it

            // Now lets determine the adequate viewer for this document type
            Type viewerType = SinapseDocumentView.GetViewer(Utils.GetExtension(fullName, true));

            // Activate the viewer,
            SinapseDocumentView viewer = Activator.CreateInstance(viewerType, this, document) as SinapseDocumentView;

            // And then lets show the new viewer on the main window.
            viewer.DockHandler.Show(dockPanel, DockState.Document);

            mruDocuments.Insert(fullName);
        }
Exemplo n.º 4
0
        public bool CloseWorkplace()
        {
            if (activeWorkplace != null)
            {
                CancelEventArgs e = new CancelEventArgs();
                this.OnActiveWorkplaceClosing(e);
                if (e.Cancel == true)
                    return false;

                if (this.CloseAllDocuments(this.activeWorkplace, true))
                {
                    this.activeWorkplace = null;
                    this.OnActiveWorkplaceClosed(EventArgs.Empty);
                    return true;
                }
                else return false;
            }
            else return true;
        }
Exemplo n.º 5
0
        /// <summary>
        ///   Attempts to close all open documents belonging to the
        ///   given Workplace. If null, all documents will be closed.
        /// </summary>
        /// <param name="workplace">The workplace owning the documents to be closed.</param>
        /// <param name="askForUnsavedChanges">Asks confirmation before closing unsaved documents.</param>
        /// <returns>Returns true if all documents were closed, false if the operation was cancelled by the user.</returns>
        public bool CloseAllDocuments(Workplace workplace, bool askForUnsavedChanges)
        {
            IDockContent[] documents = dockPanel.DocumentsToArray();

            foreach (IDockContent content in documents)
            {
                if (content is SinapseDocumentView)
                {
                    SinapseDocumentView document = content as SinapseDocumentView;
                    if (askForUnsavedChanges && document.HasChanges)
                    {
                        DialogResult r = MessageBox.Show(String.Format("Save changes to {0}?", document.Name),
                            "Save changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                        if (r == DialogResult.Yes)
                            document.Save();
                        else if (r == DialogResult.Cancel)
                            return false;
                    }
                }
            }
            return true;
        }
Exemplo n.º 6
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            // Check if we already have a Workplace open
            if (workbench.Workplace != null)
            {
                // Try to close and check if successful
                if (workbench.CloseAllDocuments(true) == false)
                {
                    this.Close(); // the operation was cancelled by the user.
                    return;
                }
            }

            // Verify if name is good
            if (tbName.Text.Length > 0)
            {
                string location = cbLocation.Text;

                // Check if directory exists
                if (!Directory.Exists(location))
                {
                    // Directory does not exist
                    DialogResult r = MessageBox.Show("Directory creation","The directory does not exist. Do you want Sinapse to automatically create it for you?", MessageBoxButtons.YesNo);
                    if (r == DialogResult.Yes)
                    {
                        Directory.CreateDirectory(location);
                    }
                    else return;
                }

                Sinapse.Data.HistoryListener.Write("Creating Workplace Directory");

                if (cbCreateFolder.Checked)
                {
                    location = Path.Combine(location, tbName.Text);
                    Directory.CreateDirectory(location);
                }

                Sinapse.Data.HistoryListener.Write("Creating Workplace");

                Workplace workplace = new Workplace(tbName.Text,
                    new FileInfo(Path.Combine(location, tbName.Text + ".workplace")));

                workplace.Save(); // creates the directory structure
                workbench.OpenWorkplace(workplace); // opens the workplace in the current workbench.

                this.Close();
            }
        }