Пример #1
0
        public void Remove(ILayout layout)
        {
            Layouts.Remove(layout);

            if (!layout.Shortcut.IsEmpty())
            {
                keyboard_hook.UnregisterHotKey(layout.Shortcut);
            }
        }
Пример #2
0
        public void Move(ILayout source, int insert_index)
        {
            var index = Layouts.IndexOf(source);

            Layouts.Remove(source);
            if (index < insert_index)
            {
                --insert_index;
            }
            Layouts.Insert(insert_index, source);
        }
        /// <summary> Add a new item layout configuration </summary>
        /// <param name="Layout"> Object with all the layout details </param>
        public void Add_Layout(ItemWriterLayoutConfig Layout)
        {
            // Ensure the dictionary is built
            if (layoutsLookup == null)
            {
                layoutsLookup = new Dictionary <string, ItemWriterLayoutConfig>(StringComparer.OrdinalIgnoreCase);
            }

            // Ensure all items in the list are in the dictionary
            if (layoutsLookup.Count != Layouts.Count)
            {
                layoutsLookup.Clear();
                foreach (ItemWriterLayoutConfig exstingConfig in Layouts)
                {
                    layoutsLookup[exstingConfig.ID] = exstingConfig;

                    if (exstingConfig.Default)
                    {
                        defaultLayout = exstingConfig;
                    }
                }
            }

            // Did this already exist?
            if (layoutsLookup.ContainsKey(Layout.ID))
            {
                ItemWriterLayoutConfig existing = null;
                foreach (ItemWriterLayoutConfig thisOne in Layouts)
                {
                    if (String.Compare(thisOne.ID, Layout.ID, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        existing = thisOne;
                        break;
                    }
                }
                if (existing != null)
                {
                    Layouts.Remove(existing);
                }
                layoutsLookup.Remove(Layout.ID);
            }

            // Add this
            layoutsLookup[Layout.ID] = Layout;
            Layouts.Add(Layout);

            // Was this the new default?
            if (Layout.Default)
            {
                defaultLayout = Layout;
            }
        }
 private void OnDelete()
 {
     try
     {
         Layouts.Remove(SelectedLayout);
         TempLayout     = null;
         DetailsEnabled = false;
         Layout.SaveLayouts(Layouts);
     }
     catch
     {
         //Throw message - tbi
     }
 }
Пример #5
0
        private void Delete(LayoutSlot param)
        {
            var selectedItem = GetCurrentSlot();

            if (selectedItem != null)
            {
                var name = selectedItem.OldName;

                // Don't schedule a rename
                m_renamedLayouts.Remove(name);

                // Make sure to use the old name
                m_deletedLayouts.Add(name);

                Layouts.Remove(selectedItem);

                try
                {
                    selectedItem.Image = null;

                    if (m_screenshots.Contains(selectedItem))
                    {
                        m_screenshots.Remove(selectedItem);
                    }

                    // Remove screenshot
                    string path =
                        Path.Combine(
                            m_screenshotDirectory.FullName + Path.DirectorySeparatorChar,
                            selectedItem.Name + WindowLayoutServiceCommandsBase.ScreenshotExtension);

                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
                catch (Exception ex)
                {
                    Outputs.WriteLine(
                        OutputMessageType.Error,
                        "Manage layouts: Exception " + "deleting screenshot: {0}",
                        ex.Message);
                }
            }
        }
        internal void Delete(WindowLayout layout)
        {
            Debug.Assert(layout != null);
            Debug.Assert(layout != ActiveLayout, "Cannot delete active window layout.");

            Logger.Info("Deleting window layout \"{0}\".", layout.Name);

            Layouts.Remove(layout);
            UpdateWindowLayoutItem();

            try
            {
                DeleteUserSession(layout);
                DeleteUserPreset(layout);
            }
            catch (Exception exception)
            {
                Logger.Warn(exception, "Failed to delete window layout \"{0}\".", layout.Name);
            }
        }
Пример #7
0
 public void DeleteLayout(Layout layout)
 {
     Layouts.Remove(layout);
 }
        internal void RenameWindowLayout(WindowLayout layout)
        {
            Debug.Assert(layout != null);
            Debug.Assert(Layouts.Contains(layout));

            string oldLayoutName = layout.Name;

            Logger.Info("Renaming window layout \"{0}\".", oldLayoutName);

ShowSaveLayoutDialog:
            var saveLayoutDialog = new SaveLayoutViewModel
            {
                DisplayName = "Rename Window Layout",
                LayoutName  = oldLayoutName
            };

            string       newLayoutName  = null;
            WindowLayout existingLayout = null;
            var          result         = _windowService.ShowDialog(saveLayoutDialog);

            if (result.HasValue && result.Value && saveLayoutDialog.LayoutName != oldLayoutName)
            {
                Debug.Assert(!string.IsNullOrEmpty(saveLayoutDialog.LayoutName), "The layout name must not be null or empty.");
                Debug.Assert(saveLayoutDialog.LayoutName.IndexOfAny(Path.GetInvalidFileNameChars()) == -1, "The layout name must not contain invalid characters.");

                newLayoutName = saveLayoutDialog.LayoutName;

                // Overwrite existing file?
                existingLayout = Layouts.FirstOrDefault(l => l.Name == newLayoutName);
                if (existingLayout != null)
                {
                    if (existingLayout.IsFactoryPreset)
                    {
                        MessageBox.Show(
                            $"\"{newLayoutName}\" is a factory preset. Factory presets cannot be overwritten.",
                            Editor.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Exclamation);

                        // Try again.
                        goto ShowSaveLayoutDialog;
                    }
                    else
                    {
                        var messageBoxResult = MessageBox.Show(
                            $"The layout \"{newLayoutName}\" already exists. Overwrite existing?",
                            Editor.ApplicationName, MessageBoxButton.YesNoCancel, MessageBoxImage.Exclamation);

                        if (messageBoxResult == MessageBoxResult.No)
                        {
                            // Try again.
                            goto ShowSaveLayoutDialog;
                        }

                        if (messageBoxResult == MessageBoxResult.Cancel)
                        {
                            // Abort.
                            newLayoutName = null;
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(newLayoutName))
            {
                try
                {
                    // Rename window layout.
                    RenameUserSession(layout.Name, newLayoutName);
                    RenameUserPreset(layout.Name, newLayoutName);

                    if (existingLayout != null)
                    {
                        Layouts.Remove(existingLayout);
                    }

                    layout.Name = newLayoutName;
                    UpdateWindowLayoutItem();
                }
                catch (Exception exception)
                {
                    Logger.Error(exception, "Could not rename window layout (old name: \"{0}\", new name: \"{1}\").", oldLayoutName, newLayoutName);

                    string message = $"Could not rename window layout.\n\n{exception.Message}";
                    MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
        private void SavePresetAs()
        {
            Logger.Info("Saving window layout as new preset.");

ShowSaveLayoutDialog:
            var saveLayoutDialog = new SaveLayoutViewModel
            {
                DisplayName = "Save Window Layout",
                LayoutName  = "New layout"
            };

            string       layoutName     = null;
            WindowLayout existingLayout = null;
            var          result         = _windowService.ShowDialog(saveLayoutDialog);

            if (result.HasValue && result.Value)
            {
                Debug.Assert(!string.IsNullOrEmpty(saveLayoutDialog.LayoutName), "The layout name must not be null or empty.");
                Debug.Assert(saveLayoutDialog.LayoutName.IndexOfAny(Path.GetInvalidFileNameChars()) == -1, "The layout name must not contain invalid characters.");

                layoutName = saveLayoutDialog.LayoutName;

                // Overwrite existing window layout?
                existingLayout = Layouts.FirstOrDefault(l => string.Compare(l.Name, layoutName, StringComparison.OrdinalIgnoreCase) == 0);
                if (existingLayout != null)
                {
                    if (existingLayout.IsFactoryPreset)
                    {
                        MessageBox.Show(
                            $"\"{layoutName}\" is a factory preset. Factory presets cannot be overwritten.",
                            Editor.ApplicationName, MessageBoxButton.OK, MessageBoxImage.Exclamation);

                        // Try again.
                        goto ShowSaveLayoutDialog;
                    }
                    else
                    {
                        var messageBoxResult = MessageBox.Show(
                            $"The layout \"{layoutName}\" already exists. Overwrite existing?",
                            Editor.ApplicationName, MessageBoxButton.YesNoCancel, MessageBoxImage.Exclamation);

                        if (messageBoxResult == MessageBoxResult.No)
                        {
                            // Try again.
                            goto ShowSaveLayoutDialog;
                        }

                        if (messageBoxResult == MessageBoxResult.Cancel)
                        {
                            // Abort.
                            layoutName = null;
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(layoutName))
            {
                try
                {
                    // Save window layout as new preset.
                    var serializedLayout = Editor.SaveLayout(true);
                    var layout           = new WindowLayout(layoutName, false)
                    {
                        SerializedLayout = serializedLayout
                    };
                    SaveUserPreset(layout);

                    if (existingLayout != null)
                    {
                        Layouts.Remove(existingLayout);
                    }

                    Layouts.Add(layout);
                    ActiveLayout = layout;
                    UpdateWindowLayoutItem();
                }
                catch (Exception exception)
                {
                    Logger.Error(exception, "Could not save window layout as new preset \"{0}\".", layoutName);

                    string message = $"Could not save window layout as new preset \"{layoutName}\".\n\n{exception.Message}";
                    MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }