Пример #1
0
        private void BtnOkClick(object sender, System.EventArgs e)
        {
            DialogResult = DialogResult.None;

            string layoutName = LayoutName;

            if (string.IsNullOrEmpty(layoutName))
            {
                m_toolTip.Show(m_txtLayout, null, ToolTipIcon.Warning, "Layout name cannot be empty!");
                return;
            }

            if (!WindowLayoutService.IsValidLayoutName(layoutName))
            {
                m_toolTip.Show(m_txtLayout, null, ToolTipIcon.Warning, "Invalid layout name!");
                return;
            }

            if (m_existingItems.Contains(layoutName))
            {
                m_toolTip.Show(m_txtLayout, null, ToolTipIcon.Warning, "A layout with this name already exists!");
                return;
            }

            DialogResult = DialogResult.OK;
        }
Пример #2
0
        /// <summary>
        /// Shows the manage layouts dialog</summary>
        /// <remarks>Programmatic method for showing the 'manage layouts' dialog</remarks>
        public override void ShowManageLayoutsDialog()
        {
            var layouts = new List <Pair <string, Keys> >();

            foreach (var layoutName in WindowLayoutService.Layouts)
            {
                Keys shortcut = Keys.None;
                {
                    IEnumerable <Keys> keys;
                    if (m_dictCommandKeys.TryGetValue(layoutName, out keys))
                    {
                        shortcut = keys.FirstOrDefault();
                    }
                }

                layouts.Add(new Pair <string, Keys>(layoutName, shortcut));
            }

            var vm = new ManageWindowLayoutsDialogViewModel(layouts);

            vm.ScreenshotDirectory = LayoutScreenshotDirectory;
            var dialog = new WindowLayoutManageDialog(vm);

            if (dialog.ShowParentedDialog() != true)
            {
                return;
            }

            // Re-associate shortcuts for proper persisting
            foreach (var kv in vm.RenamedLayouts)
            {
                IEnumerable <Keys> shortcuts;
                if (!m_dictCommandKeys.TryGetValue(kv.Key, out shortcuts))
                {
                    continue;
                }

                m_dictCommandKeys.Remove(kv.Key);
                m_dictCommandKeys[kv.Value] = shortcuts;
            }

            foreach (var kv in vm.RenamedLayouts)
            {
                WindowLayoutService.RenameLayout(kv.Key, kv.Value);
            }

            foreach (var layoutName in vm.DeletedLayouts)
            {
                WindowLayoutService.RemoveLayout(layoutName);
            }
        }
Пример #3
0
        public static string IsValidName(string layoutName)
        {
            if (string.IsNullOrEmpty(layoutName))
            {
                return("Layout name is empty");
            }

            if (!WindowLayoutService.IsValidLayoutName(layoutName))
            {
                return("Layout name contains invalid characters");
            }

            return(null);
        }
Пример #4
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used when the application is launched to open a specific file, to display
        /// search results, and so forth.
        /// </summary>
        /// <param name="args">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs args)
        {
            // Do not repeat app initialization when already running, just ensure that
            // the window is active
            if (args.PreviousExecutionState == ApplicationExecutionState.Running)
            {
                Window.Current.Activate();
                return;
            }

            if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                //TODO: Load state from previously suspended application
            }

            //// Create a Frame to act navigation context and navigate to the first page
            //var rootFrame = new Frame();
            //if (!rootFrame.Navigate(typeof(MainPage)))
            //{
            //    throw new Exception("Failed to create initial page");
            //}

            LoggingService.Init(AppDatabase.Current);
            LoggingService.Start();
            LoggingService.LogInformation("launching app...", "App.OnLaunched");

            AlertService.Init(AppDatabase.Current);
            AlertService.Start();
            LoggingService.LogInformation("initialized alerts...", "App.OnLaunched");

            GestureService.Init();
            LoggingService.LogInformation("initialized gensture manager...", "App.OnLaunched");

            AppDatabase.Current.LoadInstances();
            LoggingService.LogInformation("loaded appstate ...", "App.OnLaunched");

            AppService.Init();
            AppService.Start();
            LoggingService.LogInformation("initialized app services ...", "App.OnLaunched");

            WindowLayoutService.Init();
            LoggingService.LogInformation("initialized window layout services ...", "App.OnLaunched");


            // Place the frame in the current Window and ensure that it is active
            Window.Current.Content = new MasterPage(false); //rootFrame;
            Window.Current.Activate();
        }
Пример #5
0
        string IsValidName(string layoutName)
        {
            if (string.IsNullOrEmpty(layoutName))
            {
                return("Layout name is empty");
            }

            if (!WindowLayoutService.IsValidLayoutName(layoutName))
            {
                return("Layout name contains invalid characters");
            }

            if (m_existingItems.Contains(layoutName))
            {
                return("Layout name already exists");
            }

            return(null);
        }
Пример #6
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
#if DEBUG
            if (System.Diagnostics.Debugger.IsAttached)
            {
                this.DebugSettings.EnableFrameRateCounter = true;
            }
#endif

            //Frame rootFrame = Window.Current.Content as Frame;

            //// Do not repeat app initialization when the Window already has content,
            //// just ensure that the window is active
            //if (rootFrame == null)
            //{
            //    // Create a Frame to act as the navigation context and navigate to the first page
            //    rootFrame = new Frame();

            //    // Set the default language
            //    rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0];

            //    if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
            //    {
            //        //TODO: Load state from previously suspended application
            //    }

            //    // Place the frame in the current Window
            //    Window.Current.Content = rootFrame;
            //}

            //if (rootFrame.Content == null)
            //{
            //    // When the navigation stack isn't restored navigate to the first page,
            //    // configuring the new page by passing required information as a navigation
            //    // parameter

            //    //if (!rootFrame.Navigate(typeof(SplashScreen), e.Arguments))
            //    if (!rootFrame.Navigate(typeof(ModernCSApp2.MasterPage), e.Arguments))
            //    {
            //        throw new Exception("Failed to create initial page");
            //    }
            //}



            LoggingService.Init(AppDatabase.Current);
            LoggingService.Start();
            LoggingService.LogInformation("launching app...", "App.OnLaunched");

            AlertService.Init(AppDatabase.Current);
            AlertService.Start();
            LoggingService.LogInformation("initialized alerts...", "App.OnLaunched");

            GestureService.Init();
            LoggingService.LogInformation("initialized gensture manager...", "App.OnLaunched");

            AppDatabase.Current.LoadInstances();
            LoggingService.LogInformation("loaded appstate ...", "App.OnLaunched");

            AppService.Init();
            AppService.Start();
            LoggingService.LogInformation("initialized app services ...", "App.OnLaunched");

            WindowLayoutService.Init();
            LoggingService.LogInformation("initialized window layout services ...", "App.OnLaunched");



            var mp = new ModernCSApp.MasterPage(false);
            Window.Current.Content = mp;

            // Ensure the current window is active
            Window.Current.Activate();
        }
Пример #7
0
        private void LayoutsAfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            ListViewItem lstItem    = m_layouts.Items[e.Item];
            Point        toolTipPos = GetSubItemTopRightPoint(lstItem.SubItems[0]);

            string oldName = lstItem.Text;
            string newName = e.Label;

            // Invalid label
            if (string.IsNullOrEmpty(newName))
            {
                e.CancelEdit = true;
                m_toolTip.Show(m_layouts, toolTipPos, null, ToolTipIcon.Warning, "Name can't be empty!");
                return;
            }

            // No duplicates
            if (m_names.Contains(newName))
            {
                e.CancelEdit = true;

                if (string.Compare(newName, oldName) != 0)
                {
                    m_toolTip.Show(m_layouts, toolTipPos, null, ToolTipIcon.Warning, "A layout with this name already exists!");
                }

                return;
            }

            // No invalid characters
            if (!WindowLayoutService.IsValidLayoutName(newName))
            {
                e.CancelEdit = true;
                m_toolTip.Show(m_layouts, toolTipPos, null, ToolTipIcon.Warning, "Name contains illegal characters!");
                return;
            }

            // Keep track of renames
            {
                var tag = (LayoutTag)lstItem.Tag;
                m_renamedLayouts[tag.OldName] = newName;
            }

            // Rename in the name of layouts list
            {
                m_names.Remove(oldName);
                m_names.Add(newName);
            }

            // Rename screenshot
            try
            {
                m_screenshot.Image = null;

                // Dispose of existing screenshot so it can be renamed
                Image image;
                if (m_screenshots.TryGetValue(oldName, out image))
                {
                    image.Dispose();
                    m_screenshots.Remove(oldName);
                }

                //
                // Try and remove existing screenshot on disk
                //

                string sourceFile =
                    Path.Combine(
                        m_screenshotDirectory.FullName + Path.DirectorySeparatorChar,
                        oldName + WindowLayoutServiceCommandsBase.ScreenshotExtension);

                if (!File.Exists(sourceFile))
                {
                    return;
                }

                string destFile =
                    Path.Combine(
                        m_screenshotDirectory.FullName + Path.DirectorySeparatorChar,
                        newName + WindowLayoutServiceCommandsBase.ScreenshotExtension);

                File.Move(sourceFile, destFile);

                // Add renamed screenshot back
                if (File.Exists(destFile))
                {
                    m_screenshots.Add(newName, Image.FromFile(destFile));
                }
            }
            catch (Exception ex)
            {
                Outputs.WriteLine(
                    OutputMessageType.Error,
                    "Manage Layouts: Exception " +
                    "renaming screenshot: {0}",
                    ex.Message);
            }
            finally
            {
                // Try and use the renamed screenshot
                Image image;
                if (m_screenshots.TryGetValue(newName, out image))
                {
                    m_screenshot.Image = image;
                }
            }
        }