public override void SwitchToThisWithoutSaveLoad(OpenedFile file, IViewContent oldView)
		{
			if (file == this.PrimaryFile && oldView != this) {
				primaryViewContent.SwitchToThisWithoutSaveLoad(file, oldView);
				LoadFromPrimary();
			}
		}
		public override void SwitchFromThisWithoutSaveLoad(OpenedFile file, IViewContent newView)
		{
			if (file == this.PrimaryFile && this != newView) {
				SaveToPrimary();
				primaryViewContent.SwitchFromThisWithoutSaveLoad(file, newView);
			}
		}
        public IViewContent CreateContentForFile(OpenedFile file)
        {
            var codons = SD.DisplayBindingService.GetCodonsPerFileName(file.FileName);
            DisplayBindingDescriptor bestMatch = null;
            double max = double.NegativeInfinity;
            const int BUFFER_LENGTH = 4 * 1024;

            using (var stream = file.OpenRead()) {
                string mime = "text/plain";
                if (stream.Length > 0) {
                    stream.Position = 0;
                    mime = MimeTypeDetection.FindMimeType(new BinaryReader(stream).ReadBytes(BUFFER_LENGTH));
                }
                foreach (var codon in codons) {
                    stream.Position = 0;
                    double value = codon.Binding.AutoDetectFileContent(file.FileName, stream, mime);
                    if (value > max) {
                        max = value;
                        bestMatch = codon;
                    }
                }
            }

            if (bestMatch == null)
                throw new InvalidOperationException();

            return bestMatch.Binding.CreateContentForFile(file);
        }
		public override void Save(OpenedFile file, Stream stream)
		{
			if (file != this.PrimaryFile)
				throw new ArgumentException("file must be the primary file of the primary view content, override Save() to handle other files");
			SaveToPrimary();
			primaryViewContent.Save(file, stream);
		}
Beispiel #5
0
		void IViewContent.Save(OpenedFile file, Stream stream)
		{
			if (document != null)
				document.Save(stream, SaveOptions.DisableFormatting);
			else if (fileData != null)
				stream.Write(fileData, 0, fileData.Length);
		}
		public override bool SupportsSwitchToThisWithoutSaveLoad(OpenedFile file, IViewContent oldView)
		{
			if (file == this.PrimaryFile)
				return oldView.SupportsSwitchToThisWithoutSaveLoad(file, primaryViewContent);
			else
				return base.SupportsSwitchFromThisWithoutSaveLoad(file, oldView);
		}
 public IViewContent CreateContentForFile(OpenedFile file)
 {
     var viewCmd = new CreateDesignerCommand(file);
     viewCmd.Run();
     LoggingService.Info("DesignerBinding -> Designer started");
     return viewCmd.DesignerView;
 }
Beispiel #8
0
		public Editor(OpenedFile file)
		{
			Files.Add(file);
			OnFileNameChanged(file);
			file.ForceInitializeView(this);

			rtb.Dock = DockStyle.Fill;
			rtb.TextChanged += TextChanged;
		}
 public FileChangeWatcher(OpenedFile file)
 {
     if (file == null)
         throw new ArgumentNullException("file");
     this.file = file;
     SD.Workbench.MainWindow.Activated += MainForm_Activated;
     file.FileNameChanged += file_FileNameChanged;
     activeWatchers.Add(this);
     SetWatcher();
 }
		public EDMDesignerViewContent(OpenedFile primaryFile)
			: base(primaryFile)
		{
			if (primaryFile == null)
				throw new ArgumentNullException("primaryFile");
			
			primaryFile.ForceInitializeView(this); // call Load()

			EDMDesignerChangeWatcher.AddEDMDesignerViewContent(this);
		}
        protected AbstractSecondaryViewContent(IViewContent primaryViewContent)
        {
            if (primaryViewContent == null)
                throw new ArgumentNullException("primaryViewContent");
            if (primaryViewContent.PrimaryFile == null)
                throw new ArgumentException("primaryViewContent.PrimaryFile must not be null");
            this.primaryViewContent = primaryViewContent;

            primaryFile = primaryViewContent.PrimaryFile;
            this.Files.Add(primaryFile);
        }
		/// <summary>
		/// The load method takes a copy of the image and saves the
		/// image format so the image can be saved later without throwing
		/// a GDI+ exception. This is because the stream is disposed during
		/// the lifetime of the image:
		/// 
		/// http://support.microsoft.com/?id=814675
		/// </summary>
		public override void Load(OpenedFile file, Stream stream)
		{
			Image image = Image.FromStream(stream);
			format = image.RawFormat;
			
			box.SizeMode = PictureBoxSizeMode.Zoom;
			box.Image = new Bitmap(image.Width, image.Height);
			using (Graphics graphics = Graphics.FromImage(box.Image)) {
				graphics.DrawImage(image, 0, 0);
			}
		}
		public override void Load(OpenedFile file, Stream stream)
		{
			Debug.Assert(file == this.PrimaryFile);

			EDMDesignerChangeWatcher.Init = true;

			// Load EDMX from stream
			XElement edmxElement = null;
			Action<XElement> readMoreAction = edmxElt => edmxElement = edmxElt;
			_edmView = new EDMView(stream, readMoreAction);
			
			// If EDMX is empty run EDM Wizard
			if (_edmView.EDM.IsEmpty) {
				edmxElement = null;
				
				string ns = String.Empty;
				if (ProjectService.CurrentProject == null) {
					ns = ICSharpCode.Core.MessageService.ShowInputBox("EDMDesigner","Enter NameSpace","DefaultNamespace");
				} else {
					ns = ProjectService.CurrentProject.RootNamespace;
				}
				
				EDMWizardWindow wizard = RunWizard(file, ns);

				if (wizard.DialogResult == true)
					_edmView = new EDMView(wizard.EDMXDocument, readMoreAction);
				else
					throw new WizardCancelledException();
			}

			// Load or generate DesignerView and EntityTypeDesigners
			EntityTypeDesigner.Init = true;

			XElement designerViewsElement = null;

			if (edmxElement == null || (designerViewsElement = EDMXIO.ReadSection(edmxElement, EDMXIO.EDMXSection.DesignerViews)) == null) {
				designerViewsElement = DesignerIO.GenerateNewDesignerViewsFromCSDLView(_edmView);
			}

			if (edmxElement != null && designerViewsElement != null)
				DesignerIO.Read(_edmView, designerViewsElement, entityType => new EntityTypeDesigner(entityType), complexType => new ComplexTypeDesigner(complexType));

			EntityTypeDesigner.Init = false;

			// Gets the designer canvas
			_designerCanvas = DesignerCanvas.GetDesignerCanvas(this, _edmView, _edmView.DesignerViews.FirstOrDefault());
			_scrollViewer.Content = _designerCanvas;
			
			// Register CSDL of EDMX in CSDL DatabaseTreeView
			CSDLViews.Add(_edmView.CSDL);
			
			EDMDesignerChangeWatcher.Init = false;
		}
        public IViewContent CreateContentForFile(OpenedFile file)
        {
            string fileName = file.FileName;

            BrowserPane browserPane = new BrowserPane();
            if (fileName.StartsWith("browser://", StringComparison.OrdinalIgnoreCase)) {
                browserPane.Navigate(fileName.Substring("browser://".Length));
            } else {
                browserPane.Navigate(fileName);
            }
            return browserPane;
        }
Beispiel #15
0
		public DesignerView (OpenedFile openedFile,IDesignerGenerator generator) : base(openedFile){
			if (openedFile == null) {
				throw new ArgumentNullException("openedFile");
			}
			LoggingService.Info("DesignerView: Load from: " + openedFile.FileName);
			
			TabPageText = ResourceService.GetString("SharpReport.Design");
			
			this.generator = generator;
			this.generator.Attach(this);
			//Start Toolbox
			ToolboxProvider.AddViewContent(this);
		}
		public IViewContent CreateContentForFile(OpenedFile file)
		{
			if (file.IsDirty) {
				// TODO: warn user that the file must be saved
			}
			try {
				Process.Start(new ProcessStartInfo(file.FileName) {
				              	WorkingDirectory = Path.GetDirectoryName(file.FileName)
				              });
			} catch (Exception ex) {
				MessageService.ShowError(ex.Message);
			}
			return null;
		}
 public IViewContent CreateContentForFile(OpenedFile file)
 {
     if (file.IsDirty) {
         // TODO: warn user that the file must be saved
     }
     try {
         string cmd;
         if (CommandLine.Contains("%1"))
             cmd = CommandLine.Replace("%1", file.FileName);
         else
             cmd = CommandLine + " \"" + file.FileName + "\"";
         StartCommandLine(cmd, Path.GetDirectoryName(file.FileName));
     } catch (Exception ex) {
         MessageService.ShowError(ex.Message);
     }
     return null;
 }
Beispiel #18
0
		void IViewContent.Load(OpenedFile file, Stream stream)
		{
			document = null;
			fileData = null;
			
			try {
				document = XDocument.Load(stream, LoadOptions.PreserveWhitespace);
			} catch (XmlException) {
				stream.Position = 0;
				fileData = new byte[(int)stream.Length];
				int pos = 0;
				while (pos < fileData.Length) {
					int c = stream.Read(fileData, pos, fileData.Length - pos);
					if (c == 0) break;
					pos += c;
				}
			}
		}
		public IViewContent CreateContentForFile(OpenedFile file)
		{
			if (file.IsDirty) {
				var cmd = new ReportWizardCommand(file);
				cmd.Run();
				if (!cmd.Canceled) {
					LoggingService.Info("reportWizard canceled");
					//return null;
					var reportModel = cmd.ReportModel;
					
					var xml = CreateFormSheetFromModel.ToXml(reportModel);
					var doc = new XmlDocument();
					doc.LoadXml(xml.ToString());
					var ar = XmlToArray(doc);
					file.SetData(ar);
				} else {
					return null;
				}
			}

			var viewCmd = new CreateDesignerCommand(file);
			viewCmd.Run();
			LoggingService.Info("return DesignerView");
			return viewCmd.DesignerView;
			
			/*
			if (file.IsDirty) {

				var reportModel = ReportModelFactory.Create();
				var xml = CreateFormSheetFromModel.ToXml(reportModel);
				
				var doc = new XmlDocument();
				doc.LoadXml(xml.ToString());
				var ar = XmlToArray(doc);
				file.SetData(ar);
			}
			
			
			 */
		}
Beispiel #20
0
		internal static void Save(OpenedFile file)
		{
			Debug.Assert(file != null);
			
			using (SaveFileDialog fdiag = new SaveFileDialog()) {
				fdiag.OverwritePrompt = true;
				fdiag.AddExtension    = true;
				
				var fileFilters = ProjectService.GetFileFilters();
				fdiag.Filter = String.Join("|", fileFilters);
				for (int i = 0; i < fileFilters.Count; ++i) {
					if (fileFilters[i].ContainsExtension(Path.GetExtension(file.FileName))) {
						fdiag.FilterIndex = i + 1;
						break;
					}
				}
				
				if (fdiag.ShowDialog(SD.WinForms.MainWin32Window) == DialogResult.OK) {
					FileName fileName = FileName.Create(fdiag.FileName);
					if (!FileService.CheckFileName(fileName)) {
						return;
					}
					if (FileUtility.ObservedSave(new NamedFileOperationDelegate(file.SaveToDisk), fileName) == FileOperationResult.OK) {
						SD.FileService.RecentOpen.AddRecentFile(fileName);
						MessageService.ShowMessage(fileName, "${res:ICSharpCode.SharpDevelop.Commands.SaveFile.FileSaved}");
					}
				}
			}
		}
Beispiel #21
0
			public IViewContent CreateContentForFile(OpenedFile file)
			{
				return new SimpleViewContent(errorMessage) { TitleName = Path.GetFileName(file.FileName) };
			}
 void IViewContent.SwitchToThisWithoutSaveLoad(OpenedFile file, IViewContent oldView)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Executes an action before switching from this view content to the new view content.
 /// </summary>
 public virtual void SwitchFromThisWithoutSaveLoad(OpenedFile file, IViewContent newView)
 {
 }
 static void QueueFileForReloadDialog(OpenedFile file)
 {
     if (file == null)
         throw new ArgumentNullException("file");
     lock (queue) {
         queue.Add(file);
     }
 }
Beispiel #25
0
		public CreateDesignViewCommand (OpenedFile openedFile) {
			if (openedFile == null)
				throw new ArgumentNullException("openedFile");
			this.openedFile = openedFile;
		}
Beispiel #26
0
		public override void Save(OpenedFile file, Stream stream)
		{
			if (IsDirty) {
				if (hasUnmergedChanges) {
					MergeFormChanges();
				}
				using(var writer = new StreamWriter(stream)) {
					writer.Write(ReportFileContent);
				}
			}
		}
 /// <summary>
 /// Gets switching without a Save/Load cycle for <paramref name="file"/> is supported
 /// when switching from <paramref name="oldView"/> to this view content.
 /// </summary>
 public virtual bool SupportsSwitchToThisWithoutSaveLoad(OpenedFile file, IViewContent oldView)
 {
     return(oldView == this);
 }
 public virtual void Load(OpenedFile file, Stream stream)
 {
 }
Beispiel #29
0
 protected abstract void SaveInternal(OpenedFile file, Stream stream);
Beispiel #30
0
 protected AbstractViewContentHandlingLoadErrors(OpenedFile file) : base(file)
 {
 }
Beispiel #31
0
		public static void Save(OpenedFile file)
		{
			if (file.IsUntitled) {
				SaveFileAs.Save(file);
			} else {
				FileAttributes attr = FileAttributes.ReadOnly | FileAttributes.Directory | FileAttributes.Offline | FileAttributes.System;
				if (File.Exists(file.FileName) && (File.GetAttributes(file.FileName) & attr) != 0) {
					SaveFileAs.Save(file);
				} else {
					FileUtility.ObservedSave(new NamedFileOperationDelegate(file.SaveToDisk), file.FileName, FileErrorPolicy.ProvideAlternative);
				}
			}
		}
Beispiel #32
0
		public override void Load(OpenedFile file, Stream stream)
		{
			LoggingService.Debug("ReportDesigner: Load from: " + file.FileName);
			base.Load(file, stream);
			LoadDesigner(stream);
			SetupSecondaryView();
		}
 public virtual void Save(OpenedFile file, Stream stream)
 {
 }
 /// <summary>
 /// Is called when the file name of a file opened in this view content changes.
 /// </summary>
 protected virtual void OnFileNameChanged(OpenedFile file)
 {
 }
 public VB6FormsDesignerViewContent(OpenedFile file)
     : base(file)
 {
     this.TabPageText = "Designer";
 }
 public void Dispose()
 {
     SD.MainThread.VerifyAccess();
     activeWatchers.Remove(this);
     if (file != null) {
         SD.Workbench.MainWindow.Activated -= MainForm_Activated;
         file.FileNameChanged -= file_FileNameChanged;
         file = null;
     }
     if (watcher != null) {
         watcher.Dispose();
         watcher = null;
     }
 }
Beispiel #37
0
		/// <summary>Called by OpenedFile.set_FileName to update the dictionary.</summary>
		internal void OpenedFileFileNameChange(OpenedFile file, FileName oldName, FileName newName)
		{
			if (oldName == null) return; // File just created with NewFile where name is being initialized.
			
			LoggingService.Debug("OpenedFileFileNameChange: " + oldName + " => " + newName);
			
			if (openedFileDict[oldName] != file)
				throw new ArgumentException("file must be registered as oldName");
			if (openedFileDict.ContainsKey(newName)) {
				OpenedFile oldFile = openedFileDict[newName];
				if (oldFile.CurrentView != null) {
					if (oldFile.CurrentView.WorkbenchWindow != null)
						oldFile.CurrentView.WorkbenchWindow.CloseWindow(true);
				} else {
					throw new ArgumentException("there already is a file with the newName");
				}
			}
			openedFileDict.Remove(oldName);
			openedFileDict[newName] = file;
		}
 /// <summary>
 /// Executes an action before switching from the old view content to this view content.
 /// </summary>
 public virtual void SwitchToThisWithoutSaveLoad(OpenedFile file, IViewContent oldView)
 {
 }
Beispiel #39
0
		/// <summary>Called by OpenedFile.UnregisterView to update the dictionary.</summary>
		internal void OpenedFileClosed(OpenedFile file)
		{
			OpenedFile existing;
			if (openedFileDict.TryGetValue(file.FileName, out existing) && existing != file)
				throw new ArgumentException("file must be registered");
			
			openedFileDict.Remove(file.FileName);
			LoggingService.Debug("OpenedFileClosed: " + file.FileName);
		}
 /// <summary>
 /// Gets switching without a Save/Load cycle for <paramref name="file"/> is supported
 /// when switching from this view content to <paramref name="newView"/>.
 /// </summary>
 public virtual bool SupportsSwitchFromThisWithoutSaveLoad(OpenedFile file, IViewContent newView)
 {
     return(newView == this);
 }
 bool IViewContent.SupportsSwitchToThisWithoutSaveLoad(OpenedFile file, IViewContent oldView)
 {
     return(false);
 }