예제 #1
0
        private void OpenProject(object sender, RoutedEventArgs e)
        {
            var dialog = new VistaFolderBrowserDialog();

            dialog.Description            = "Open Project Folder";
            dialog.ShowNewFolderButton    = false;
            dialog.UseDescriptionForTitle = true;

            if (dialog.ShowDialog(this) == true)
            {
                var basePath = dialog.SelectedPath;

                Log(string.Format("Attempting to open project at '{0}'", basePath));

                noProjectLabel.Visibility     = Visibility.Visible;
                projectLoadedLabel.Visibility = Visibility.Hidden;
                updateButton.Visibility       = Visibility.Hidden;

                string logMessage = "";

                if (!StaticWikiCore.GetWorkspaceDetails(basePath, ref sourceDirectory, ref destinationDirectory, ref themeFileName, ref titleName, ref navigationFileName, ref contentExtensions,
                                                        ref disableAutoPageExtension, ref disableLinkCorrection, ref logMessage))
                {
                    MessageBox.Show("Unable to load project details", "Error", MessageBoxButton.OK, MessageBoxImage.Error);

                    return;
                }

                fileSystemWatcher                       = new FileSystemWatcher();
                fileSystemWatcher.Path                  = sourceDirectory;
                fileSystemWatcher.NotifyFilter          = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.CreationTime;
                fileSystemWatcher.Filter                = "*.md";
                fileSystemWatcher.IncludeSubdirectories = true;
                fileSystemWatcher.Created              += new FileSystemEventHandler(OnChanged);
                fileSystemWatcher.Deleted              += new FileSystemEventHandler(OnChanged);
                fileSystemWatcher.Changed              += new FileSystemEventHandler(OnChanged);
                fileSystemWatcher.Renamed              += new RenamedEventHandler(OnRenamed);
                fileSystemWatcher.EnableRaisingEvents   = true;

                Log("Successfully loaded project");

                noProjectLabel.Visibility = Visibility.Hidden;

                projectLoadedLabel.Visibility = Visibility.Visible;
                projectLoadedLabel.Content    = string.Format("Loaded '{0}'", titleName);

                updateButton.Visibility = Visibility.Visible;

                if (autoUpdatesEnabled)
                {
                    lock (this)
                    {
                        shouldUpdate = true;
                    }
                }
            }
        }
예제 #2
0
        void OpenProject(NSObject sender)
        {
            var dialog = NSOpenPanel.OpenPanel;

            dialog.CanChooseFiles       = false;
            dialog.CanChooseDirectories = true;

            if (dialog.RunModal() == 1)
            {
                if (fileSystemWatcher != null)
                {
                    fileSystemWatcher.EnableRaisingEvents = false;
                    fileSystemWatcher.Dispose();
                    fileSystemWatcher = null;
                }

                lock (this)
                {
                    shouldUpdate = false;
                }

                var basePath = dialog.Url.Path;

                Log(string.Format("Attempting to open project at '{0}'", basePath));

                noProjectLabel.Hidden     = false;
                projectLoadedLabel.Hidden = true;
                updateNowButton.Hidden    = true;

                string logMessage = "";

                if (!StaticWikiCore.GetWorkspaceDetails(basePath, ref sourceDirectory, ref destinationDirectory, ref defaultThemeName, ref themes, ref titleName, ref navigationFileName, ref contentExtensions,
                                                        ref disableAutoPageExtension, ref disableLinkCorrection, ref markdownExtensions, ref logMessage))
                {
                    var alert = new NSAlert()
                    {
                        AlertStyle      = NSAlertStyle.Warning,
                        InformativeText = "Unable to load project details",
                        MessageText     = "Error"
                    };

                    alert.RunModal();

                    return;
                }

                fileSystemWatcher                       = new FileSystemWatcher();
                fileSystemWatcher.Path                  = sourceDirectory;
                fileSystemWatcher.NotifyFilter          = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.CreationTime;
                fileSystemWatcher.Filter                = "*.md";
                fileSystemWatcher.IncludeSubdirectories = true;
                fileSystemWatcher.Created              += new FileSystemEventHandler(OnChanged);
                fileSystemWatcher.Deleted              += new FileSystemEventHandler(OnChanged);
                fileSystemWatcher.Changed              += new FileSystemEventHandler(OnChanged);
                fileSystemWatcher.Renamed              += new RenamedEventHandler(OnRenamed);
                fileSystemWatcher.EnableRaisingEvents   = true;

                Log("Successfully loaded project");

                noProjectLabel.Hidden = true;

                projectLoadedLabel.Hidden      = false;
                projectLoadedLabel.StringValue = string.Format("Loaded '{0}'", titleName);

                updateNowButton.Hidden = false;

                if (autoUpdatesEnabled)
                {
                    lock (this)
                    {
                        shouldUpdate = true;
                    }
                }
            }
        }