예제 #1
0
        /// <summary>
        /// Deletes a map.
        /// </summary>
        /// <param name="map">The map to delete.</param>
        /// <param name="showConfirmation">If true, a confirmation will be shown to make sure the user wants to
        /// perform this operation.</param>
        public static void DeleteMap(EditorMap map, bool showConfirmation = true)
        {
            try
            {
                if (map == null)
                {
                    return;
                }

                // Show the confirmation message
                if (showConfirmation)
                {
                    const string confirmMsg = "Are you sure you wish to delete map `{0}`? This cannot be undone!";
                    if (MessageBox.Show(string.Format(confirmMsg, map), "Delete map?", MessageBoxButtons.YesNo) == DialogResult.No)
                    {
                        return;
                    }
                }

                // If a MapScreenControl is open for this map, set the map on it to null then dispose of the control
                var msc = MapScreenControl.TryFindInstance(map);
                if (msc != null)
                {
                    msc.Map = null;
                    msc.Dispose();
                }

                // Delete the map file
                var path = MapBase.GetMapFilePath(ContentPaths.Dev, map.ID);
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                // Update the database
                GlobalState.Instance.DbController.GetQuery <DeleteMapQuery>().Execute(map.ID);

                // Delete successful
                if (showConfirmation)
                {
                    const string deletedMsg = "Successfully deleted map `{0}`!";
                    MessageBox.Show(string.Format(deletedMsg, map), "Map deleted", MessageBoxButtons.OK);
                }
            }
            catch (Exception ex)
            {
                const string errmsg = "Failed to delete map `{0}`. Exception: {1}";
                if (log.IsErrorEnabled)
                {
                    log.ErrorFormat(errmsg, map, ex);
                }
                Debug.Fail(string.Format(errmsg, map, ex));
            }
        }
예제 #2
0
        /// <summary>
        /// Handles the corresponding event.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="ValueChangedEventArgs{EditorMap}"/> instance containing the event data.</param>
        void MapScreenControl_MapChanged(MapScreenControl sender, ValueChangedEventArgs<EditorMap> e)
        {
            // When the map changes, and it was our map that made the ToolBar visibile, then update the reference on the ToolBar

            var tb = ToolBar.GetToolBar(ToolBarVisibility);
            if (tb == null)
                return;

            var dispObj = GetToolBarObject();
            if (dispObj != null && tb.DisplayObject == dispObj)
                tb.DisplayObject = dispObj;
        }
예제 #3
0
        /// <summary>
        /// Handles the corresponding event.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="ValueChangedEventArgs{EditorMap}"/> instance containing the event data.</param>
        void MapScreenControl_MapChanged(MapScreenControl sender, ValueChangedEventArgs <EditorMap> e)
        {
            // When the map changes, and it was our map that made the ToolBar visibile, then update the reference on the ToolBar

            var tb = ToolBar.GetToolBar(ToolBarVisibility);

            if (tb == null)
            {
                return;
            }

            var dispObj = GetToolBarObject();

            if (dispObj != null && tb.DisplayObject == dispObj)
            {
                tb.DisplayObject = dispObj;
            }
        }