protected void LoadGrid() {
			int iRecCount = -1;
			List<EditHistory> lstHistory = null;

			DateTime? dtFilter = null;
			if (!String.IsNullOrEmpty(txtDate.Text)) {
				dtFilter = Convert.ToDateTime(txtDate.Text);
			}

			Guid? userID = null;
			if (ddlUsers.SelectedIndex > 0) {
				userID = new Guid(ddlUsers.SelectedValue);
			}

			iRecCount = EditHistory.GetHistoryListCount(SiteData.CurrentSiteID, chkLatest.Checked, dtFilter, userID);

			pagedDataGrid.PageSize = int.Parse(ddlSize.SelectedValue);

			lblPages.Text = String.Format(" {0} ", iRecCount);

			pagedDataGrid.BuildSorting();

			pagedDataGrid.TotalRecords = iRecCount;

			string sSort = pagedDataGrid.SortingBy;
			int iPgNbr = pagedDataGrid.PageNumber - 1;
			int iPageSize = pagedDataGrid.PageSize;

			lstHistory = EditHistory.GetHistoryList(sSort, iPgNbr, iPageSize, SiteData.CurrentSiteID, chkLatest.Checked, dtFilter, userID);

			GeneralUtilities.BindDataBoundControl(pagedDataGrid, lstHistory);
		}
Пример #2
0
        public void Add()
        {
            const int   len     = 1024;
            Document    doc     = new Document();
            EditHistory history = new EditHistory();
            EditAction  action;

            Assert.AreEqual(null, history.GetUndoAction());
            Assert.AreEqual(false, history.CanUndo);
            Assert.AreEqual(false, history.CanRedo);

            for (int i = 0; i < len; i++)
            {
                history.Add(
                    new EditAction(doc, i, i.ToString(), (i + 'a').ToString(), 0, 0, null)
                    );
            }

            Assert.AreEqual(true, history.CanUndo);
            Assert.AreEqual(false, history.CanRedo);

            for (int i = len - 1; 0 <= i; i--)
            {
                action = history.GetUndoAction();
                Assert.AreEqual(i + "-[" + i + "]+[" + (i + 'a') + "]", action.ToString());
            }

            Assert.AreEqual(null, history.GetUndoAction());
            Assert.AreEqual(false, history.CanUndo);
            Assert.AreEqual(true, history.CanRedo);
        }
Пример #3
0
        public MainForm()
        {
            Self = this;
            InitializeThreadLocale();
            InitializeComponent();
            this.konamiWatcher = new KonamiWatcher(() => {
                Options.Get.IsAdvancedModeEnabled = !Options.Get.IsAdvancedModeEnabled;
                MessageBox.Show("Advanced mode " + (Options.Get.IsAdvancedModeEnabled ? "enabled" : "disabled") + "!");
                doConfigureAdvancedMode();
            });
            this.imagePanelMain.SetImage(LoadedImage);
            this.Text = this.Text + " v" + Constants.Version;
#if !RELEASE
            this.Text += " (Debug)";
#endif
            this.History = new EditHistory(this);

            if (!Constants.IsFullVersion)
            {
#pragma warning disable CS0162 // Unreachable code detected
                this.togglePaletteToolStripMenuItem.Visible    = false;
                this.saveColorPaletteToolStripMenuItem.Visible = false;
                mi_PreRenderOptions.Visible = false;
                this.Text += " (Free Version)";
#pragma warning restore CS0162 // Unreachable code detected
            }
            SetViewModeCheckBoxStates();
        }
Пример #4
0
        public async Task UpdateHero(int id, UpdateHeroDTO hero)
        {
            var dbHero = this._heroRepository
                         .All()
                         .FirstOrDefault(x => x.Id == id);

            if (dbHero?.Name == hero.Name)
            {
                throw new ArgumentException("Please enter a name that is different from the previous one.");
            }

            if (string.IsNullOrEmpty(hero.Name) || string.IsNullOrWhiteSpace(hero.Name))
            {
                throw new InvalidOperationException("Name cannot be null or empty string.");
            }

            var editHistory = new EditHistory()
            {
                OldValue = dbHero.Name,
                NewValue = hero.Name,
                HeroId   = dbHero.Id
            };

            dbHero.EditHistory.Add(editHistory);

            dbHero.Name = hero.Name;

            await this._heroRepository.SaveChangesAsync();
        }
Пример #5
0
        public void Load(Stream file)
        {
            EditHistory.ClearHistory();

            using (var reader = new StreamReader(file))
            {
                var data   = JObject.Parse(reader.ReadToEnd());
                var jtiles = (JArray)data["tiles"];
                var tiles  = (PrefabTileData[][])Items.ItemsSource;

                // Different sized maps require a reconstruction
                if (tiles.Length != jtiles.Count)
                {
                    SetEmpty(jtiles.Count, false);
                    tiles = (PrefabTileData[][])Items.ItemsSource;
                }

                for (var y = 0; y < jtiles.Count; ++y)
                {
                    var jrow = (JArray)jtiles[y];
                    for (var x = 0; x < jtiles.Count; ++x)
                    {
                        var jtile = (JObject)jrow[x];
                        var tile  = tiles[y][x];
                        tile.FromSerialized(jtile);
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Handles the event that occurs when the redo menu is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void RedoTextMenuClick(object sender, EventArgs e)
        {
            string edit  = (string)UndoHistory.Pop(); // Edit string
            int    loc   = (int)UndoHistory.Pop();    // Location of edit
            bool   isDel = (bool)UndoHistory.Pop();   // Indicates whether the edit is a deletion

            EditHistory.Push(isDel);
            EditHistory.Push(loc);
            EditHistory.Push(edit);
            DoEdit(isDel, loc, edit);
        }
Пример #7
0
        private void UIElement_OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (StartWall)
            {
                return;
            }

            var data = DataContext as PrefabTileData;

            if (data == null)
            {
                return;
            }

            var room      = this.GetParent <PrefabRoom>();
            var paintData = room.PaintTile.DataContext as PrefabTileData;

            if (paintData == null)
            {
                return;
            }

            var prevValue = (PrefabTileData)data.Clone();

            if (data.Base.Id == paintData.Base.Id)
            {
                data.Reassign((PrefabTileData)Tiles.Prefabs[0]);
            }
            else
            {
                data.Reassign(paintData);
            }

            var newValue = (PrefabTileData)data.Clone();

            if (room.HasFile())
            {
                room.Save();
            }

            if (paintData.Base.Id != 0)
            {
                EditHistory.PushUndo(new PrefabChangeHistory
                {
                    Room = room,
                    Data = data,
                    Prev = prevValue,
                    Next = newValue
                }.Undo);
            }
        }
Пример #8
0
 public EditHistoryWrapper(EditHistory editHistory, ApiDateTimeHelper apiDateTimeHelper, UserManager userManager, DisplayUserSettingsHelper displayUserSettingsHelper)
 {
     ID             = editHistory.ID;
     Key            = editHistory.Key;
     Version        = editHistory.Version;
     VersionGroup   = editHistory.VersionGroup;
     Changes        = editHistory.Changes.Select(r => new EditHistoryChangesWrapper(r, apiDateTimeHelper)).ToList();
     ChangesHistory = editHistory.ChangesString;
     Created        = apiDateTimeHelper.Get(editHistory.ModifiedOn);
     User           = new EditHistoryAuthor(userManager, displayUserSettingsHelper)
     {
         Id = editHistory.ModifiedBy
     };
     ServerVersion = editHistory.ServerVersion;
 }
Пример #9
0
        public MainForm()
        {
            Self = this;
            InitializeComponent();
            this.imagePanelMain.SetImage(LoadedImage);
            this.Text    = this.Text + " v" + Constants.Version;
            this.History = new EditHistory(this);

            if (!Constants.IsFullVersion)
            {
                togglePaletteToolStripMenuItem.Visible = false;
                mi_PreRenderOptions.Visible            = false;
                this.Text = this.Text + " (Free Version)";
            }
        }
Пример #10
0
        public List <EditHistory> GetEditHistory(object fileId, int fileVersion = 0)
        {
            using (var dbManager = GetDb())
            {
                var query = Query("files_file")
                            .Select("id")
                            .Select("version")
                            .Select("version_group")
                            .Select("modified_on")
                            .Select("modified_by")
                            .Select("changes")
                            .Select("create_on")
                            .Where(Exp.Eq("id", fileId))
                            .OrderBy("version", true);

                if (fileVersion > 0)
                {
                    query.Where(Exp.Eq("version", fileVersion));
                }

                return
                    (dbManager
                     .ExecuteList(query)
                     .ConvertAll(r =>
                {
                    var item = new EditHistory
                    {
                        ID = Convert.ToInt32(r[0]),
                        Version = Convert.ToInt32(r[1]),
                        VersionGroup = Convert.ToInt32(r[2]),
                        ModifiedOn = TenantUtil.DateTimeFromUtc(Convert.ToDateTime(r[3])),
                        ModifiedBy = new EditHistoryAuthor {
                            Id = new Guid((string)r[4])
                        },
                        ChangesString = (string)(r[5]),
                    };

                    item.Key = DocumentServiceHelper.GetDocKey(item.ID, item.Version, TenantUtil.DateTimeFromUtc(Convert.ToDateTime(r[6])));
                    return item;
                }));
            }
        }
Пример #11
0
        /// <summary>
        /// Records edits for undos
        /// </summary>
        private void RecordEdit()
        {
            bool   isDel = Text.Length < LastText.Length;                                   // Indicates whether the edit was a deletion
            int    len   = Math.Abs(Text.Length - LastText.Length);                         // The length of the string inserted or deleted
            int    loc   = isDel ? SelectionStart : (SelectionStart - len);                 // The location of the edit
            string edit  = isDel ? LastText.Substring(loc, len) : Text.Substring(loc, len); // Gets the edit string

            if (Text.Length != 0 && edit == "\t")
            {
                Text           = Text.Remove(loc, 1);    // Remove tab
                edit           = new string(' ', 4);
                Text           = Text.Insert(loc, edit); // Insert spaces for tab
                SelectionStart = loc + 4;                // Restore cursor location
            }

            EditHistory.Push(isDel);
            EditHistory.Push(loc);
            EditHistory.Push(edit);
            UndoHistory.Clear();
            LastText = Text;
        }
Пример #12
0
        public void Case2()
        {
            const int   len1    = 1024;
            const int   len2    = 512;
            const int   len3    = 768;
            Document    doc     = new Document();
            EditHistory history = new EditHistory();
            EditAction  action;

            Assert.AreEqual(null, history.GetUndoAction());

            Assert.AreEqual(false, history.CanUndo);
            Assert.AreEqual(false, history.CanRedo);

            // add some
            for (int i = 0; i < len1; i++)
            {
                history.Add(
                    new EditAction(doc, i, i.ToString(), (i + 'a').ToString(), 0, 0, null)
                    );
            }

            Assert.AreEqual(true, history.CanUndo);
            Assert.AreEqual(false, history.CanRedo);

            // pop some
            for (int i = len1 - 1; len2 <= i; i--)
            {
                action = history.GetUndoAction();
                Assert.AreEqual(i + "-[" + i + "]+[" + (i + 'a') + "]", action.ToString());
            }

            Assert.AreEqual(true, history.CanUndo);
            Assert.AreEqual(true, history.CanRedo);

            // redo some
            for (int i = len2; i < len3; i++)
            {
                action = history.GetRedoAction();
                Assert.AreEqual(i + "-[" + i + "]+[" + (i + 'a') + "]", action.ToString());
            }

            Assert.AreEqual(true, history.CanUndo);
            Assert.AreEqual(true, history.CanRedo);

            // add one and ensure that it can redo no more
            history.Add(
                new EditAction(doc, len3, (len3).ToString(), (len3 + 'a').ToString(), 0, 0, null)
                );
            Assert.AreEqual(true, history.CanUndo);
            Assert.AreEqual(false, history.CanRedo);

            // pop all
            for (int i = len3; 0 <= i; i--)
            {
                action = history.GetUndoAction();
                Assert.AreEqual(i + "-[" + i + "]+[" + (i + 'a') + "]", action.ToString());
            }

            Assert.AreEqual(false, history.CanUndo);
            Assert.AreEqual(true, history.CanRedo);
            Assert.AreEqual(null, history.GetUndoAction());
            Assert.AreEqual("0-[0]+[97]", history.GetRedoAction().ToString());
        }
Пример #13
0
        public void GroupUndoRedo()
        {
            // end before begin
            {
                EditHistory history = new EditHistory();
                history.EndUndo();
                history.EndUndo();
            }

            // double call of begin
            {
                EditHistory history = new EditHistory();
                history.BeginUndo();
                history.BeginUndo();
                history.EndUndo();
            }

            // double call of end
            {
                EditHistory history = new EditHistory();
                history.BeginUndo();
                history.EndUndo();
                history.EndUndo();
            }

            // grouping actions
            {
                Document doc = new Document();
                doc.Replace("a", 0, 0);
                doc.BeginUndo();
                doc.Replace("b", 1, 1);
                doc.Replace("c", 2, 2);
                doc.EndUndo();
                doc.Replace("d", 3, 3);

                Assert.AreEqual("abcd", doc.Text);
                doc.Undo();
                Assert.AreEqual("abc", doc.Text);
                doc.Undo();
                Assert.AreEqual("a", doc.Text);
                doc.Undo();
                Assert.AreEqual("", doc.Text);
                doc.Undo();
                Assert.AreEqual("", doc.Text);
                doc.Redo();
                Assert.AreEqual("a", doc.Text);
                doc.Redo();
                Assert.AreEqual("abc", doc.Text);
                doc.Redo();
                Assert.AreEqual("abcd", doc.Text);
                doc.Redo();
                Assert.AreEqual("abcd", doc.Text);
            }

            // undo during grouping actions
            {
                Document doc = new Document();
                doc.Replace("abc", 0, 0);
                doc.BeginUndo();
                doc.Replace("X", 1, 1);
                Assert.AreEqual("aXbc", doc.Text);
                doc.Replace("Y", 2, 2);
                Assert.AreEqual("aXYbc", doc.Text);
                doc.Undo();
                Assert.AreEqual("abc", doc.Text);
                doc.EndUndo();
                Assert.AreEqual("abc", doc.Text);
            }

            // redo during grouping actions
            {
                Document doc = new Document();
                doc.Replace("abc", 0, 0);
                doc.Replace("X", 1, 1);
                Assert.AreEqual("aXbc", doc.Text);
                doc.Undo();
                Assert.AreEqual("abc", doc.Text);
                doc.BeginUndo();
                doc.Redo();
                Assert.AreEqual("aXbc", doc.Text);
                doc.EndUndo();
                Assert.AreEqual("aXbc", doc.Text);
            }
            {
                Document doc = new Document();
                doc.Replace("abc", 0, 0);
                doc.Replace("X", 1, 1);
                Assert.AreEqual("aXbc", doc.Text);
                doc.Undo();
                Assert.AreEqual("abc", doc.Text);
                doc.BeginUndo();
                doc.Replace("Y", 1, 1);
                doc.Redo();
                Assert.AreEqual("aYbc", doc.Text);
                doc.EndUndo();
                Assert.AreEqual("aYbc", doc.Text);
            }

            // Nested call of group undo
            {
                Document doc = new Document();
                doc.Replace("a", doc.Length, doc.Length);
                doc.BeginUndo();
                doc.Replace("b", doc.Length, doc.Length);
                doc.BeginUndo();
                doc.Replace("c", doc.Length, doc.Length);
                doc.EndUndo();
                doc.Replace("d", doc.Length, doc.Length);
                doc.EndUndo();
                Assert.AreEqual("abcd", doc.Text);
                doc.Undo();
                Assert.AreEqual("a", doc.Text);
                doc.Undo();
                Assert.AreEqual("", doc.Text);
                doc.Undo();
                Assert.AreEqual("", doc.Text);
                doc.Redo();
                Assert.AreEqual("a", doc.Text);
                doc.Redo();
                Assert.AreEqual("abcd", doc.Text);
                doc.Redo();
                Assert.AreEqual("abcd", doc.Text);
            }
        }