Ejemplo n.º 1
0
        public static void SaveAs(bool worksheet, EditableView pnlView)
        {
            var strFilename = FileDialog.ShowSave(FileDialog.Context.Document, "SAW 7|*" + Document.StandardExtension + "|SAW 6|*.sss", Path.GetFileName(CurrentDocument.FilenameWithExtension(Document.StandardExtension)));

            if (string.IsNullOrEmpty(strFilename))
            {
                return;
            }
            CurrentDocument.SAWHeader.SetWindowBounds(pnlView.GetDocumentScreenCoords());
            if (strFilename.ToLower().EndsWith(".sss"))
            {
                using (var op = new Globals.Operation("[Save_SAW6]"))
                {
                    var oldDoc = new SAW6Doc(CurrentDocument);

                    using (var writer = new ArchiveWriter(strFilename, oldDoc.m_Header.Version))
                    {
                        oldDoc.Write(writer);
                    }
                    op.ConfirmSuccess(true);
                }
            }
            else
            {
                if (!CurrentDocument.IsPaletteWithin)
                {
                    CurrentDocument.Filename = strFilename;
                }
                CurrentDocument.DisplayName = "";                 // otherwise the original worksheet name remains in the title bar, rather than the filename
                SaveFile(pnlView);
            }
        }
Ejemplo n.º 2
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            IShapeContainer container = CurrentPage.SelectionContainer();

            if (container == null)
            {
                MessageBox.Show(Strings.Item("Container_Mismatch"));
                return;
            }

            transaction.Edit((Datum)container);
            List <Shape> moved = new List <Shape>();

            foreach (Scriptable scriptable in CurrentPage.SelectedShapes)
            {
                transaction.Delete(scriptable);
                Shape shape = scriptable.Element;
                transaction.Edit(shape);
                shape.Parent = container;
                container.Contents.Remove(scriptable);
                container.Contents.Add(shape);
                moved.Add(shape);
            }
            container.FinishedModifyingContents(transaction);
            CurrentPage.SelectOnly(moved);
        }
Ejemplo n.º 3
0
 public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
 {
     if (CurrentPageIndex > 0)
     {
         Editor.DisplayPage(CurrentPageIndex - 1);
     }
 }
Ejemplo n.º 4
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            TransformRotate.IncludeText = !TransformRotate.IncludeText;
            ctrRotation palette = (ctrRotation)Palette.Item("Rotation").Control;

            palette.IncludeTextChanged();
        }
Ejemplo n.º 5
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            float newValue = frmFont.AdjustSize(Editor.ParameterValue(Parameters.FontSize) / 100f, Delta);

            Editor.SetParameterValue((int)(newValue * 100), Parameters.FontSize);
            ((ctrTextStyle)Palette.Item(Parameters.FontSize).Control).EnableButtons();
        }
Ejemplo n.º 6
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            Shape           moving       = CurrentPage.SelectedShapes.First();
            IShapeContainer oldContainer = moving.Container;
            int             targetIndex  = oldContainer.Contents.IndexOf(moving) - 1; // index of new container

            if (targetIndex < 0)
            {
                return;
            }
            IShapeContainer newContainer = oldContainer.Contents[targetIndex].AsContainer;

            if (newContainer == null)
            {
                return;                 // item cannot accept contents
            }
            transaction.Edit((Datum)oldContainer);
            transaction.Edit((Datum)newContainer);
            transaction.Edit(moving);
            oldContainer.Contents.Remove(moving);
            newContainer.Contents.Add(moving);
            moving.Parent = newContainer;

            // move child physically within
            (newContainer as Container)?.BringChildWithinBounds(moving, transaction);

            oldContainer.FinishedModifyingContents(transaction);
            newContainer.FinishedModifyingContents(transaction);

            moving.Parent.NotifyIndirectChange(moving, ChangeAffects.GrabSpots);
        }
Ejemplo n.º 7
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            string key = Config.ShowPaletteKey(Purpose);

            Config.UserCurrent.Write(key, !Config.UserCurrent.ReadBooleanEx(key));
            Globals.OnSettingsChanged();
        }
Ejemplo n.º 8
0
        public override bool IsApplicable(EditableView pnlView)
        {
            if (CurrentPage.SelectedCount != 1)
            {
                return(false);
            }
            if (CurrentPage.SelectedPath == null)
            {
                return(false);
            }
            if (!CurrentPage.SelectedShapes.First().VertexVerbApplicable(Code, CurrentPage.SelectedPath))
            {
                return(false);
            }
            switch (Code)
            {
            case Codes.AddVertex:
            case Codes.ConvertToBezier:
            case Codes.ConvertToLine:
                return(CurrentPage.SelectedPath.Type == Target.Types.Line);

            case Codes.RemoveVertex:
            case Codes.SmoothVertex:
            case Codes.CornerVertex:
                return(CurrentPage.SelectedPath.Type == Target.Types.Vertex);

            default: throw new InvalidOperationException();
            }
        }
Ejemplo n.º 9
0
        /// <summary>Used by the Paste verb to do the paste in this case</summary>
        public static void Paste(Transaction transaction, EditableView pnlView)
        {
            DataObject data = (DataObject)Clipboard.GetDataObject();

            byte[] buffer = (byte[])data.GetData("Splash presentation", false);
            if (buffer == null)
            {
                Debug.Fail("Deserialisation failed");
                return;
            }
            using (MemoryStream stream = new MemoryStream(buffer, false))
                using (DataReader reader = new DataReader(stream, (FileMarkers)Shape.Shapes.SAWItem))
                {
                    Item copied = (Item)reader.ReadData((FileMarkers)Shape.Shapes.SAWItem);
                    copied.UpdateReferencesObjectsCreated(CurrentDocument, reader);
                    //copied.UpdateReferencesIDsChanged(hashIDChanges, Globals.Root.CurrentDocument);
                    foreach (Shape target in CurrentPage.SelectedShapes)
                    {
                        Item itemTarget = (Item)((target as Scriptable)?.Element ?? target);                 // unwraps the Scriptable if that was selected
                        transaction.Edit(itemTarget);
                        if (string.IsNullOrEmpty(itemTarget.LabelText))
                        {
                            itemTarget.LabelText = copied.LabelText;
                        }
                        itemTarget.FillStyle?.CopyFrom(copied.FillStyle);
                        itemTarget.LineStyle?.CopyFrom(copied.LineStyle);
                        itemTarget.TextStyle?.CopyFrom(copied.TextStyle);
                        itemTarget.CopyPresentationFrom(copied, true);
                        Scriptable scriptableTarget = target as Scriptable ?? (Scriptable)(target as Item).Parent;
                        scriptableTarget.CopyPresentationFrom((Scriptable)copied.Parent, true);
                    }
                }
            pnlView.InvalidateData(CurrentPage.SelectedRefreshBoundary(), StaticView.InvalidationBuffer.All);
        }
Ejemplo n.º 10
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            Scriptable scriptable = pnlView.CurrentPage.SelectedShapes.First() as Scriptable;

            if (scriptable == null)
            {
                return;
            }
            // write the list of shapes into a byte buffer; this way we control the serialisation
            DataObject data = new DataObject();

            using (MemoryStream buffer = new MemoryStream(1000))
                using (DataWriter writer = new DataWriter(buffer, (FileMarkers)Shape.Shapes.Scriptable))
                {
                    writer.Write(scriptable);
                    data.SetData("Splash scripts", false, buffer.GetBuffer());
                }

            IndentStringBuilder output = new IndentStringBuilder();

            // store as text as well
            foreach (Scriptable.ScriptTypes type in Enum.GetValues(typeof(Scriptable.ScriptTypes)))
            {
                Script script = scriptable.GetScript(type);
                script?.WriteExportText(output, Strings.Item("SAW_ScriptType_" + type));
            }

            if (output.Length > 0)
            {
                data.SetText(output.ToString());
            }

            // store result on clipboard
            Clipboard.SetDataObject(data);
        }
Ejemplo n.º 11
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            // passed to the current colour panel if any
            Control ctrFocused = GUIUtilities.GetFocusControl();

            (ctrFocused as ColourPanel)?.TriggerAction(this);
        }
Ejemplo n.º 12
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            if (CurrentPage.SelectedCount != 1)
            {
                return;
            }
            Shape        shape = CurrentPage.SelectedShapes.First();
            GraphicsPath path  = shape.ConvertToPath();

            if (path == null)
            {
                Utilities.LogSubError("ConvertToPath returned null from: " + shape.ShapeCode);
                MessageBox.Show(Strings.Item("ConvertPath_Null"));
                return;
            }
            GenericPath create = new GenericPath(path);

            create.DeriveStyles(new[] { shape });             // {} because it takes a list of shapes
            transaction.Edit((Datum)shape.Parent);
            transaction.Create(create);
            IShapeContainer container = (IShapeContainer)shape.Parent;

            container.Contents.Remove(shape);
            container.Contents.Add(create);
            container.FinishedModifyingContents(transaction);
            create.Parent = shape.Parent;
            transaction.Delete(shape);
            CurrentPage.SelectOnly(create);
        }
Ejemplo n.º 13
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            IShapeContainer container = CurrentPage.SelectionContainer();

            if (container == null)
            {
                MessageBox.Show(Strings.Item("Container_Mismatch"));
                return;
            }

            transaction.Edit((Datum)container);
            Lined         mask  = FindSourceShape();
            ImportedImage image = FindSourceImage();

            transaction.Edit(mask);
            transaction.Edit(image);
            (mask as Pencil).ForceClosure(transaction);
            if (mask is Curve curve && !curve.Closed())
            {
                throw new UserException("[Mask_Not_Closed]");
            }
            MaskedImage result = new MaskedImage(image, mask);

            transaction.Create(result);

            int index = Math.Max(mask.Z, image.Z);             // this will be the Z-order of the new group

            result.Parent = container;
            container.Contents.Insert(index + 1, result);             // This index will be valid as the individual shapes are still in the list
            container.Contents.Remove(mask);
            container.Contents.Remove(image);
            container.FinishedModifyingContents(transaction, null);
            CurrentPage.SelectOnly(result);
        }
Ejemplo n.º 14
0
        public override bool IsApplicable(EditableView pnlView)
        {
            DataObject data = (DataObject)Clipboard.GetDataObject();

            if (data != null)
            {
                if (data.GetDataPresent("Splash shapes", false) || data.ContainsImage() || ContainsFileImage(data))
                {
                    return(true);
                }
#if SAW && !SPLASH
                if (data.GetDataPresent("Splash scripts", false))
                {
                    return(CopyScripts.PasteApplicable(data));
                }
                if (data.GetDataPresent("Splash presentation", false))
                {
                    return(CopyPresentation.PasteApplicable(data));
                }
#endif
                if (data.ContainsText())
                {
                    if (CurrentPage.SelectedCount == 1 && CurrentPage.SelectedShapes[0].SupportsTextLabel)
                    {
                        return(true);
                    }
                    Shape shape = pnlView.TypingShape();
                    if (shape != null && shape.SupportsTextLabel)
                    {
                        return(true);                        // Second condition is needed because some "typing" shapes only actually do custom processing of certain keys
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 15
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            if (Editor.MovingPalette != null)
            {
                Editor.CompletePaletteMove();
            }
            Control over = GUIUtilities.YoungestChildUnderMouse(Editor);

            if (source == EditableView.ClickPosition.Sources.Pad)
            {
                over = pnlView;                 // if triggered by mouse in control pad, target must be drawing area, not living back to the control pad!
            }
            if (over == pnlView)
            {
                pnlView.TriggerVerb(Codes.Choose, source);
            }
            else if (over is Button)
            {
                ((Button)over).PerformClick();
            }
            else if (over is IInvokeable)
            {
                ((IInvokeable)over).PerformClick();
            }
        }
Ejemplo n.º 16
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            bool ongoing = pnlView.OngoingShape != null;

            pnlView.ConcludeOngoing();
            if (ongoing)
            {
                return;                 // we cancelled the current;  better to not also undo a previous - that can look like 2 operations
            }
            if (CurrentDocument.UndoTransactions.Count == 0)
            {
                return;
            }
            CurrentPage.DeselectAll();             // in case undo deletes something in selected list
            Transaction actualTransaction = CurrentDocument.UndoTransactions[CurrentDocument.UndoTransactions.Count - 1];

            CurrentDocument.UndoTransactions.RemoveAt(CurrentDocument.UndoTransactions.Count - 1);
            actualTransaction.Undo();
            pnlView.InvalidateAll();
            CurrentDocument.RedoTransactions.Add(actualTransaction);

            if (CurrentDocument.Changed != actualTransaction.ChangedAtStart)
            {
                CurrentDocument.Changed = actualTransaction.ChangedAtStart;
            }
            Editor.IndirectEffectsUndoRedo(actualTransaction, true);
            Shape.RestoreCaretState(actualTransaction);             // Ignored unless objTransaction.CaretState is defined
        }
Ejemplo n.º 17
0
 public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
 {
     if (CurrentDocument.AddPage(CurrentPage, transaction, true, CurrentPageIndex + Offset, Duplicate) != null)
     {
         Editor.DisplayPage(CurrentPageIndex + Offset);
     }
 }
Ejemplo n.º 18
0
Archivo: IRM.cs Proyecto: stuart2w/SAW
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            if (!Globals.Root.CurrentConfig.ReadBoolean(Config.Multiple_Documents) && !Editor.CheckDiscardCurrent(false))
            {
                return;
            }
            string file = FileDialog.ShowOpen(FileDialog.Context.OtherUserDoc, Filter);

            if (string.IsNullOrEmpty(file))
            {
                return;
            }
            using (var operation = new Globals.Operation(this.DescriptionWithoutAccelerator()))
                try
                {
                    ParseFile(file);
                    Document document = GenerateDocument();
                    if (operation.ConfirmSuccess())
                    {
                        Globals.Root.SelectDocument(document);
                    }
                }
                catch (Exception ex) when(!Globals.Root.IsDebug)
                {
                    MessageBox.Show(ex.Message);
                }
            finally
            { m_Elements = null; }
        }
Ejemplo n.º 19
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            if (CurrentDocument.Count < 2)
            {
                return;
            }
            // deleting the last page would bugger things up completely
            // Only confirm with user if the page is not empty
            if (!CurrentPage.IsEmpty)
            {
                if (MessageBox.Show(Strings.Item("Confirm_DeletePage"), RootApplication.AppName, MessageBoxButtons.OKCancel) != DialogResult.OK)
                {
                    return;
                }
            }
            CurrentDocument.DeletePage(CurrentPageIndex, transaction);
            // Usually we will display the page following this one, which now has the same page index, unless there isn't one
            int newIndex = CurrentPageIndex;

            if (newIndex >= CurrentDocument.Count)
            {
                newIndex = CurrentDocument.Count - 1;
            }
            Editor.DisplayPage(newIndex);
        }
Ejemplo n.º 20
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            IShapeContainer container = CurrentPage.SelectionContainer();

            if (container == null)
            {
                MessageBox.Show(Strings.Item("Container_Mismatch"));
                return;
            }

            transaction.Edit((Datum)container);
            List <Shape> created = new List <Shape>();
            int          nextID  = (from p in Globals.Root.CurrentDocument.Pages select p.FindHighestUsedID()).Max() + 1;

            foreach (Shape s in CurrentPage.SelectedShapes)
            {
                transaction.Edit(s);
                Scriptable scriptable = new Scriptable(s);
                transaction.Create(scriptable);
                scriptable.Parent = container;
                scriptable.SAWID  = nextID++;
                container.Contents.Remove(s);
                container.Contents.Add(scriptable);
                // note this makes no attempt to maintain Z order.  Edited items will be brought to the front (but are likely to maintain relative order)
                created.Add(scriptable);
            }
            container.FinishedModifyingContents(transaction);
            // it should still be the contained elements which are listed as selected I think
            CurrentPage.SelectOnly(created);
        }
Ejemplo n.º 21
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            string existing = "";

            if (Globals.Root.ManualSettingsFile != null)
            {
                existing = Path.GetFileName(Globals.Root.ManualSettingsFile);
            }
            string file = FileDialog.ShowOpen(FileDialog.Context.OtherUserDoc, SaveSettings.ExtensionFilter, existing);

            if (string.IsNullOrEmpty(file))
            {
                return;
            }
            Globals.Root.ManualSettingsFile = file;
            Globals.Root.SaveUserConfigs();
            try
            {
                var config = Config.FromFile(file, Config.Levels.User);
                config.EnsureUserResources();
                Config.UserUser = config;
            }
            catch (Exception ex)
            {
                Utilities.LogSubError(ex);
                MessageBox.Show(ex.Message);
            }
            Globals.OnSettingsChanged();
        }
Ejemplo n.º 22
0
        public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
        {
            MultiUpdate update = new MultiUpdate();

            if (!frmMultiUpdateOptions.Display(CurrentPage.SelectedShapes.OfType <Item>().Any(), update))
            {
                return;
            }
            IEnumerable <Item> list;

            if (update.OnlySelected)
            {
                list = CurrentPage.SelectedShapes.OfType <Item>();
            }
            else
            {
                list = Shape.FlattenList(CurrentPage.Shapes.ToList(), Shape.FlatListPurpose.Translate).OfType <Item>();
            }
            update.Start();
            try
            {
                foreach (Item item in list)
                {
                    string result = update.DoLookup(item.LabelText, item.ConceptID);
                    if (string.IsNullOrEmpty(result))
                    {
                        continue;
                    }
                    transaction.Edit(item);
                    switch (update.PerformFunction)
                    {
                    case MultiUpdate.Functions.ChangeSymbols:
                        string      imagePath = Path.Combine(Connection.LocalPath, result);
                        SharedImage image     = (SharedImage)Globals.Root.CurrentDocument.AddSharedResourceFromFile(imagePath, transaction);
                        item.Image     = new SharedReference <SharedImage>(image);
                        item.ImageName = Path.GetFileName(imagePath);
                        break;

                    case MultiUpdate.Functions.ChangeText:
                        item.LabelText = result;
                        if ((item.Parent is Scriptable scriptable) && scriptable.OutputAsDisplay)
                        {
                            scriptable.OutputText = result;
                        }
                        break;

                    case MultiUpdate.Functions.RemoveInfo:
                        item.ConceptID = null;
                        break;

                    default: throw new ArgumentException("update.PerformFunction");
                    }
                }
            }
            finally
            {
                update.Completed();
            }
        }
Ejemplo n.º 23
0
 public override bool IsApplicable(EditableView pnlView)
 {
     if (pnlView.OngoingShape != null)
     {
         return(false);
     }
     return(CurrentPage != null && CurrentPage.SelectedCount == 1 && CurrentPage.SelectedShapes.First() is Scriptable);
 }
Ejemplo n.º 24
0
 public override bool IsApplicable(EditableView pnlView)
 {
     if (CurrentPage.SelectedCount != 1)
     {
         return(false);
     }
     return(CurrentPage.SelectedShapes.First().ShapeCode == Shape.Shapes.MaskedImage);
 }
Ejemplo n.º 25
0
 public override bool IsApplicable(EditableView pnlView)
 {
     if (pnlView.OngoingShape != null)
     {
         return(false);                // if part way through a new shape can't delete any selected one (in practice probably only when doing Arcs on NaL otherwise there wouldn't be any current selection)
     }
     return(CurrentPage.SelectedCount > 0);
 }
Ejemplo n.º 26
0
 public override bool IsApplicable(EditableView pnlView)
 {
     if (pnlView.OngoingShape != null)
     {
         return(false);
     }
     return(CurrentPage != null && SelectedItem != null);
 }
Ejemplo n.º 27
0
 public override bool IsApplicable(EditableView pnlView)
 {
     if (Code == Codes.PrintDirectly)
     {
         return(!CurrentPage.IsEmpty);
     }
     return(!CurrentDocument.IsEmpty);
 }
Ejemplo n.º 28
0
 public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
 {
     foreach (var item in (from Scriptable s in CurrentPage.SelectedShapes.OfType <Scriptable>() where s.Element is Item select(s.Element as Item)))
     {
         transaction.Edit(item);
         item.TextShown = (Show);
     }
 }
Ejemplo n.º 29
0
 public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
 {
     pnlView.ConcludeOngoing();
     if (MessageBox.Show(Strings.Item("Confirm_ClearPage"), RootApplication.AppName, MessageBoxButtons.OKCancel) == DialogResult.OK)
     {
         CurrentPage.Clear(transaction);
     }
 }
Ejemplo n.º 30
0
 public override void Trigger(EditableView.ClickPosition.Sources source, EditableView pnlView, Transaction transaction)
 {
     // sends them as separate chars - this allows equation editor to do funky stuff like on "("
     foreach (var c in Strings.Translate(Text))
     {
         Editor.SimulateKey(c);
     }
 }