void updater_Tick(object sender, EventArgs e)
        {
            updater.Stop();
            string src = File.Exists(logFile) ? File.ReadAllText(logFile) : "";
            MatchCollection matches = reError.Matches(src);

            TextEvent te;
            if (matches.Count == 0)
            {
                te = new TextEvent(EventType.ProcessEnd, "Done(0)");
                EventManager.DispatchEvent(this, te);
                if (!te.Handled) PlaySWF();
                return;
            }

            NotifyEvent ne = new NotifyEvent(EventType.ProcessStart);
            EventManager.DispatchEvent(this, ne);
            foreach (Match m in matches)
            {
                string file = m.Groups["file"].Value;
                string line = m.Groups["line"].Value;
                string desc = m.Groups["desc"].Value.Trim();
                TraceManager.Add(String.Format("{0}:{1}: {2}", file, line, desc), -3);
            }
            te = new TextEvent(EventType.ProcessEnd, "Done(" + matches.Count + ")");
            EventManager.DispatchEvent(this, te);

            (PluginBase.MainForm as Form).Activate();
            (PluginBase.MainForm as Form).Focus();
        }
        void updater_Tick(object sender, EventArgs e)
        {
            updater.Stop();
            string src = File.Exists(logFile) ? File.ReadAllText(logFile) : "";
            MatchCollection errorMatches = reError.Matches(src);
            MatchCollection warningMatches = warnError.Matches(src);

            TextEvent te;
            if (errorMatches.Count == 0 && warningMatches.Count == 0)
            {
                te = new TextEvent(EventType.ProcessEnd, "Done(0)");
                EventManager.DispatchEvent(this, te);
                if (!te.Handled) PlaySWF();
                return;
            }

            NotifyEvent ne = new NotifyEvent(EventType.ProcessStart);
            EventManager.DispatchEvent(this, ne);
            foreach (Match m in errorMatches)
            {
                string file = m.Groups["file"].Value;
                string line = m.Groups["line"].Value;
                string desc = m.Groups["desc"].Value.Trim();
                Match mCol = Regex.Match(desc, @"\s*[a-z]+\s([0-9]+)\s");
                if (mCol.Success)
                {
                    line += "," + mCol.Groups[1].Value;
                    desc = desc.Substring(mCol.Length);
                }
                TraceManager.Add(String.Format("{0}({1}): {2}", file, line, desc), -3);
            }
            foreach (Match m in warningMatches)
            {
                string file = m.Groups["file"].Value;
                string line = m.Groups["line"].Value;
                string desc = m.Groups["desc"].Value.Trim();
                Match mCol = Regex.Match(desc, @"\s*[a-z]+\s([0-9]+)\s");
                if (mCol.Success)
                {
                    line += "," + mCol.Groups[1].Value;
                    desc = desc.Substring(mCol.Length);
                }
                TraceManager.Add(String.Format("{0}({1}): {2}", file, line, desc), -3);
            }
            te = new TextEvent(EventType.ProcessEnd, "Done(" + errorMatches.Count + ")");
            EventManager.DispatchEvent(this, te);

            if (errorMatches.Count == 0)
            {
                if (!te.Handled)
                {
                    PlaySWF();
                    return;
                }
            }
            
            (PluginBase.MainForm as Form).Activate();
            (PluginBase.MainForm as Form).Focus();
        }
Esempio n. 3
0
 /// <summary>
 /// Detect syntax, ask from plugins if its correct and update
 /// </summary>
 public static void UpdateControlSyntax(ScintillaControl sci)
 {
     String language = SciConfig.GetLanguageFromFile(sci.FileName);
     TextEvent te = new TextEvent(EventType.SyntaxDetect, language);
     EventManager.DispatchEvent(SciConfig, te);
     if (te.Handled && te.Value != null) language = te.Value;
     if (sci.ConfigurationLanguage != language)
     {
         sci.ConfigurationLanguage = language;
     }
     ApplySciSettings(sci);
 }
Esempio n. 4
0
 /// <summary>
 /// Renames the found documents based on the specified path
 /// NOTE: Directory paths should be without the last separator
 /// </summary>
 public static void MoveDocuments(String oldPath, String newPath)
 {
     Boolean reactivate = false;
     oldPath = Path.GetFullPath(oldPath);
     newPath = Path.GetFullPath(newPath);
     ITabbedDocument current = PluginBase.MainForm.CurrentDocument;
     foreach (ITabbedDocument document in PluginBase.MainForm.Documents)
     {
         /* We need to check for virtual models, another more generic option would be 
          * Path.GetFileName(document.FileName).IndexOfAny(Path.GetInvalidFileNameChars()) == -1
          * But this one is used in more places */
         if (document.IsEditable && !document.Text.StartsWith("[model] "))
         {
             String filename = Path.GetFullPath(document.FileName);
             if (filename.StartsWith(oldPath))
             {
                 TextEvent ce = new TextEvent(EventType.FileClose, document.FileName);
                 EventManager.DispatchEvent(PluginBase.MainForm, ce);
                 document.SciControl.FileName = filename.Replace(oldPath, newPath);
                 TextEvent oe = new TextEvent(EventType.FileOpen, document.FileName);
                 EventManager.DispatchEvent(PluginBase.MainForm, oe);
                 if (current != document)
                 {
                     document.Activate();
                     reactivate = true;
                 }
                 else
                 {
                     TextEvent se = new TextEvent(EventType.FileSwitch, document.FileName);
                     EventManager.DispatchEvent(PluginBase.MainForm, se);
                 }
             }
             PluginBase.MainForm.ClearTemporaryFiles(filename);
             document.RefreshTexts();
         }
     }
     PluginBase.MainForm.RefreshUI();
     if (reactivate) current.Activate();
 }
Esempio n. 5
0
 /// <summary>
 /// When setting value has changed, dispatch event
 /// </summary>
 private void PropertyValueChanged(Object sender, PropertyValueChangedEventArgs e)
 {
     if (this.itemListView.SelectedIndices.Count > 0)
     {
         GridItem changedItem = (GridItem)e.ChangedItem;
         String settingId = this.nameLabel.Text + "." + changedItem.Label.Replace(" ", "");
         TextEvent te = new TextEvent(EventType.SettingChanged, settingId);
         EventManager.DispatchEvent(Globals.MainForm, te);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Reloads an editable document
 /// </summary>
 public void Reload(Boolean showQuestion)
 {
     if (!this.IsEditable) return;
     if (showQuestion)
     {
         String dlgTitle = TextHelper.GetString("Title.ConfirmDialog");
         String message = TextHelper.GetString("Info.AreYouSureToReload");
         if (MessageBox.Show(Globals.MainForm, message, " " + dlgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
     }
     Globals.MainForm.ReloadingDocument = true;
     Int32 position = this.SciControl.CurrentPos;
     TextEvent te = new TextEvent(EventType.FileReload, this.FileName);
     EventManager.DispatchEvent(Globals.MainForm, te);
     if (!te.Handled)
     {
         EncodingFileInfo info = FileHelper.GetEncodingFileInfo(this.FileName);
         if (info.CodePage == -1)
         {
             Globals.MainForm.ReloadingDocument = false;
             return; // If the files is locked, stop.
         }
         Encoding encoding = Encoding.GetEncoding(info.CodePage);
         this.SciControl.IsReadOnly = false;
         this.SciControl.Encoding = encoding;
         this.SciControl.CodePage = ScintillaManager.SelectCodePage(info.CodePage);
         this.SciControl.Text = info.Contents;
         this.SciControl.IsReadOnly = FileHelper.FileIsReadOnly(this.FileName);
         this.SciControl.SetSel(position, position);
         this.SciControl.EmptyUndoBuffer();
         this.SciControl.Focus();
     }
     Globals.MainForm.OnDocumentReload(this);
 }
Esempio n. 7
0
		/**
		* Saves the specified file with the specified encoding
		*/
		public void SaveSelectedFile(string file, string text)
		{
			DockContent doc = this.CurDocument;
			ScintillaControl sci = this.CurSciControl;
			bool otherFile = ((string)sci.Tag != file);
			if (otherFile)
			{
				NotifyEvent ne = new NotifyEvent(EventType.FileClose);
				Global.Plugins.NotifyPlugins(this, ne);
			}
			//
			TextEvent te = new TextEvent(EventType.FileSaving, file);
			Global.Plugins.NotifyPlugins(this, te);
			//
			sci.Tag = file;
			doc.Text = Path.GetFileName(file);
			FileSystem.Write(file, text, sci.Encoding);
			if (otherFile)
			{
				sci.ConfigurationLanguage = this.SciConfig.GetLanguageFromFile(file);
				TextEvent te2 = new TextEvent(EventType.FileSave, file);
				Global.Plugins.NotifyPlugins(this, te2);
				//
				this.notifyOpen = true;
				this.OnActiveDocumentChanged(null, null);
			}
			else this.OnFileSave(file);
		}
Esempio n. 8
0
		/**
		* Call custom plugin command
		*/
		public void PluginCommand(object sender, System.EventArgs e)
		{
			try
			{
				CommandBarButton cmButton;
				cmButton = (CommandBarButton)sender;
				NotifyEvent ne = new TextEvent(EventType.Command, cmButton.Tag.ToString());
				Global.Plugins.NotifyPlugins(this, ne);
			}
			catch (Exception ex)
			{
				ErrorHandler.ShowError("Error while sending a plugin command.", ex);
			}
		}
Esempio n. 9
0
		/**
		* Create a new blank document
		*/
		public void New(object sender, System.EventArgs e)
		{
			string fileName = this.GetNewDocumentName();
			TextEvent te = new TextEvent(EventType.FileNew, fileName);
			Global.Plugins.NotifyPlugins(this, te);
			if (!te.Handled)
			{
				this.CreateNewDocument(fileName, "", this.DefaultCodePage);
			}
		}
Esempio n. 10
0
		/**
		* Notifies the plugins for the LanguageChange event
		*/
		public void OnChangeLanguage(string lang)
		{
			TextEvent te = new TextEvent(EventType.LanguageChange, lang);
			Global.Plugins.NotifyPlugins(this, te);
		}
Esempio n. 11
0
 /// <summary>
 /// Notifies when the user is trying to modify a read only file
 /// </summary>
 public void OnScintillaControlModifyRO(ScintillaControl sci)
 {
     if (!sci.Enabled || !File.Exists(sci.FileName)) return;
     TextEvent te = new TextEvent(EventType.FileModifyRO, sci.FileName);
     EventManager.DispatchEvent(this, te);
     if (te.Handled) return; // Let plugin handle this...
     String dlgTitle = TextHelper.GetString("Title.ConfirmDialog");
     String message = TextHelper.GetString("Info.MakeReadOnlyWritable");
     if (MessageBox.Show(Globals.MainForm, message, dlgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         ScintillaManager.MakeFileWritable(sci);
     }
 }
Esempio n. 12
0
 /// <summary>
 /// Activates the previous document when document is closed
 /// </summary>
 public void OnDocumentClosed(Object sender, System.EventArgs e)
 {
     ITabbedDocument document = sender as ITabbedDocument;
     TabbingManager.TabHistory.Remove(document);
     TextEvent ne = new TextEvent(EventType.FileClose, document.FileName);
     EventManager.DispatchEvent(this, ne);
     if (this.appSettings.SequentialTabbing)
     {
         if (TabbingManager.SequentialIndex == 0) this.Documents[0].Activate();
         else TabbingManager.NavigateTabsSequentially(-1);
     }
     else TabbingManager.NavigateTabHistory(0);
     if (document.IsEditable && !document.IsUntitled)
     {
         if (this.appSettings.RestoreFileStates) FileStateManager.SaveFileState(document);
         RecoveryManager.RemoveTemporaryFile(document.FileName);
         OldTabsManager.SaveOldTabDocument(document.FileName);
     }
     ButtonManager.UpdateFlaggedButtons();
 }
Esempio n. 13
0
 /// <summary>
 /// Updates the UI, tabbing, working directory and the button states. 
 /// Also notifies the plugins for the FileOpen and FileSwitch events.
 /// </summary>
 public void OnActiveDocumentChanged(Object sender, System.EventArgs e)
 {
     try
     {
         if (this.CurrentDocument == null) return;
         this.OnScintillaControlUpdateControl(this.CurrentDocument.SciControl);
         this.quickFind.CanSearch = this.CurrentDocument.IsEditable;
         /**
         * Bring this newly active document to the top of the tab history
         * unless you're currently cycling through tabs with the keyboard
         */
         TabbingManager.UpdateSequentialIndex(this.CurrentDocument);
         if (!TabbingManager.TabTimer.Enabled)
         {
             TabbingManager.TabHistory.Remove(this.CurrentDocument);
             TabbingManager.TabHistory.Insert(0, this.CurrentDocument);
         }
         if (this.CurrentDocument.IsEditable)
         {
             /**
             * Apply correct extension when saving
             */
             if (this.appSettings.ApplyFileExtension)
             {
                 String extension = Path.GetExtension(this.CurrentDocument.FileName);
                 if (extension != "") this.saveFileDialog.DefaultExt = extension;
             }
             /**
             * Set current working directory
             */
             String path = Path.GetDirectoryName(this.CurrentDocument.FileName);
             if (!this.CurrentDocument.IsUntitled && Directory.Exists(path))
             {
                 this.workingDirectory = path;
             }
             /**
             * Checks the file changes
             */
             TabbedDocument document = (TabbedDocument)this.CurrentDocument;
             document.Activate();
             /**
             * Processes the opened file
             */
             if (this.notifyOpenFile)
             {
                 ScintillaManager.UpdateControlSyntax(this.CurrentDocument.SciControl);
                 if (File.Exists(this.CurrentDocument.FileName))
                 {
                     TextEvent te = new TextEvent(EventType.FileOpen, this.CurrentDocument.FileName);
                     EventManager.DispatchEvent(this, te);
                 }
                 this.notifyOpenFile = false;
             }
         }
         NotifyEvent ne = new NotifyEvent(EventType.FileSwitch);
         EventManager.DispatchEvent(this, ne);
     }
     catch (Exception ex)
     {
         ErrorManager.ShowError(ex);
     }
 }
Esempio n. 14
0
 /// <summary>
 /// Notifies the plugins for the FileSave event
 /// </summary>
 public void OnFileSave(ITabbedDocument document, String oldFile)
 {
     if (oldFile != null)
     {
         String args = document.FileName + ";" + oldFile;
         TextEvent rename = new TextEvent(EventType.FileRename, args);
         EventManager.DispatchEvent(this, rename);
         TextEvent open = new TextEvent(EventType.FileOpen, document.FileName);
         EventManager.DispatchEvent(this, open);
     }
     this.OnUpdateMainFormDialogTitle();
     if (document.IsEditable) document.SciControl.MarkerDeleteAll(2);
     TextEvent save = new TextEvent(EventType.FileSave, document.FileName);
     EventManager.DispatchEvent(this, save);
     ButtonManager.UpdateFlaggedButtons();
     TabTextManager.UpdateTabTexts();
 }
Esempio n. 15
0
 /// <summary>
 /// Creates a new blank document tracking current project
 /// </summary>
 public void SmartNew(Object sender, EventArgs e)
 {
     String ext = "";
     if (PluginBase.CurrentProject != null)
     {
         try
         {
             String filter = PluginBase.CurrentProject.DefaultSearchFilter;
             String tempExt = filter.Split(';')[0].Replace("*.", "");
             if (Regex.Match(tempExt, "^[A-Za-z0-9]+$").Success) ext = tempExt;
         }
         catch { /* NO ERRORS */ }
     }
     String fileName = DocumentManager.GetNewDocumentName(ext);
     TextEvent te = new TextEvent(EventType.FileNew, fileName);
     EventManager.DispatchEvent(this, te);
     if (!te.Handled)
     {
         this.CreateEditableDocument(fileName, "", (Int32)this.appSettings.DefaultCodePage);
     }
 }
Esempio n. 16
0
 /// <summary>
 /// Opens the specified file and creates a editable document
 /// </summary>
 public DockContent OpenEditableDocument(String org, Encoding encoding, Boolean restorePosition)
 {
     DockContent createdDoc;
     EncodingFileInfo info = new EncodingFileInfo();
     String file = PathHelper.GetPhysicalPathName(org);
     TextEvent te = new TextEvent(EventType.FileOpening, file);
     EventManager.DispatchEvent(this, te);
     if (te.Handled)
     {
         if (this.Documents.Length == 0)
         {
             this.New(null, null);
             return null;
         }
         else return null;
     }
     else if (file.EndsWith(".fdz"))
     {
         this.CallCommand("ExtractZip", file);
         return null;
     }
     try
     {
         Int32 count = this.Documents.Length;
         for (Int32 i = 0; i < count; i++)
         {
             if (this.Documents[i].IsEditable && this.Documents[i].FileName.ToUpper() == file.ToUpper())
             {
                 this.Documents[i].Activate();
                 return null;
             }
         }
     }
     catch {}
     if (encoding == null)
     {
         info = FileHelper.GetEncodingFileInfo(file);
         if (info.CodePage == -1) return null; // If the file is locked, stop.
     }
     else
     {
         info = FileHelper.GetEncodingFileInfo(file);
         info.Contents = FileHelper.ReadFile(file, encoding);
         info.CodePage = encoding.CodePage;
     }
     DataEvent de = new DataEvent(EventType.FileDecode, file, null);
     EventManager.DispatchEvent(this, de); // Lets ask if a plugin wants to decode the data..
     if (de.Handled)
     {
         info.Contents = de.Data as String;
         info.CodePage = Encoding.UTF8.CodePage; // assume plugin always return UTF8
     }
     try
     {
         if (this.CurrentDocument != null && this.CurrentDocument.IsUntitled && !this.CurrentDocument.IsModified && this.Documents.Length == 1)
         {
             this.closingForOpenFile = true;
             this.CurrentDocument.Close();
             this.closingForOpenFile = false;
             createdDoc = this.CreateEditableDocument(file, info.Contents, info.CodePage);
         }
         else createdDoc = this.CreateEditableDocument(file, info.Contents, info.CodePage);
         ButtonManager.AddNewReopenMenuItem(file);
     }
     catch
     {
         createdDoc = this.CreateEditableDocument(file, info.Contents, info.CodePage);
         ButtonManager.AddNewReopenMenuItem(file);
     }
     TabbedDocument document = (TabbedDocument)createdDoc;
     document.SciControl.SaveBOM = info.ContainsBOM;
     document.SciControl.BeginInvoke((MethodInvoker)delegate 
     {
         if (this.appSettings.RestoreFileStates)
         {
             FileStateManager.ApplyFileState(document, restorePosition);
         }
     });
     ButtonManager.UpdateFlaggedButtons();
     return createdDoc;
 }
Esempio n. 17
0
		/**
		* Updates the important edit buttons, selectes the corrent language 
		* and encoding. Also notifies the plugins for the FileSwitch event.
		*/
		public void OnActiveDocumentChanged(object sender, System.EventArgs e)
		{
			if (this.CurSciControl == null) return;
			this.CurSciControl.IsActive = true;
			try
			{
				/**
				* Bring this newly active document to the top of the tab history
				* unless you're currently cycling through tabs with the keyboard
				*/
				if (!this.tabTimer.Enabled)
				{
					tabHistory.Remove(this.CurDocument);
					tabHistory.Insert(0,this.CurDocument);
				}
				/**
				* Update UI
				*/
				this.OnScintillaControlUpdateControl(this.CurSciControl);
				/**
				* Set working directory
				*/
				string path = Path.GetDirectoryName(this.CurFile);
				if (!this.CurDocIsUntitled() && Directory.Exists(path))
				{
					Directory.SetCurrentDirectory(path);
				}
				/**
				* Check if file is changed outside of FlashDevelop
				*/
				TabbedDocument document = (TabbedDocument)this.CurDocument;
				document.CheckFileChange();
				/**
				* Send notifications
				*/
				if (this.notifyOpen)
				{
					this.notifyOpen = false;
					TextEvent te = new TextEvent(EventType.FileOpen, this.CurFile);
					Global.Plugins.NotifyPlugins(this, te);
				}
				NotifyEvent ne = new NotifyEvent(EventType.FileSwitch);
				Global.Plugins.NotifyPlugins(this, ne);
			}
			catch (Exception ex)
			{
				ErrorHandler.ShowError(ex.Message, ex);
			}
		}
Esempio n. 18
0
 /// <summary>
 /// Notifies the plugins for the SyntaxChange event
 /// </summary>
 public void OnSyntaxChange(String language)
 {
     TextEvent te = new TextEvent(EventType.SyntaxChange, language);
     EventManager.DispatchEvent(this, te);
 }
Esempio n. 19
0
		/**
		* Removes the "*" from the end of the document on file save 
		* and notifies the plugins for the FileSave event
		*/
		public void OnFileSave(string file)
		{
			this.UpdateButtonsEnabled();
			this.Text = this.CurDocument.Text+" - FlashDevelop";
			//
			TextEvent te = new TextEvent(EventType.FileSave, file);
			Global.Plugins.NotifyPlugins(this, te);
		}
Esempio n. 20
0
 /// <summary>
 /// Sets the current document modified
 /// </summary>
 public void OnDocumentModify(ITabbedDocument document)
 {
     if (document.IsEditable && !document.IsModified && !this.reloadingDocument && !this.processingContents)
     {
         document.IsModified = true;
         TextEvent te = new TextEvent(EventType.FileModify, document.FileName);
         EventManager.DispatchEvent(this, te);
     }
 }
Esempio n. 21
0
		private void ProcessEnded(object sender, int exitCode)
		{
			// This must be marshalled to the GUI thread since we're calling plugins
			if (this.InvokeRequired) this.BeginInvoke(new ProcessEndedHandler(this.ProcessEnded), new object[]{sender, exitCode});
			else
			{
				CommandBarButton killButton = this.GetCBButton("KillProcess");
				if (killButton != null) killButton.IsEnabled = false;
				// Restore working directory
				string path = Path.GetDirectoryName(this.CurFile);
				if (!this.CurDocIsUntitled() && Directory.Exists(path))
				{
					Directory.SetCurrentDirectory(path);
				}
				string result = string.Format("Done({0})", exitCode);
				TraceLog.AddMessage(result, TraceLog.ProcessEnd);
				//
				TextEvent te = new TextEvent(EventType.ProcessEnd, result);
				Global.Plugins.NotifyPlugins(this, te);
			}
		}
Esempio n. 22
0
 /// <summary>
 /// Notifies the plugins for the FileSave event
 /// </summary>
 public void OnFileSave(ITabbedDocument document, Boolean newFile)
 {
     if (newFile)
     {
         TextEvent te1 = new TextEvent(EventType.FileOpen, document.FileName);
         EventManager.DispatchEvent(this, te1);
     }
     this.OnUpdateMainFormDialogTitle();
     if (document.IsEditable) document.SciControl.MarkerDeleteAll(2);
     TextEvent te2 = new TextEvent(EventType.FileSave, document.FileName);
     EventManager.DispatchEvent(this, te2);
     ButtonManager.UpdateFlaggedButtons();
 }
Esempio n. 23
0
		/**
		* Opens the specified file and reads the file's encoding
		*/
		public void OpenSelectedFile(string file)
		{
			TextEvent te = new TextEvent(EventType.FileOpening, file);
			Global.Plugins.NotifyPlugins(this, te);
			DockContent[] elements = this.GetDocuments();
			if (te.Handled) 
			{
				if (elements.Length == 0)
				{
					this.New(null, null);
				}
				return;
			}
			try
			{
				int count = elements.Length;
				for (int i = 0; i<count; i++)
				{
					ScintillaControl ctrl = GetSciControl(elements[i]);
					if (ctrl.Tag.ToString().ToUpper() == file.ToUpper())
					{
						elements[i].Activate();
						return;
					}
				}
			}
			catch {}
			int codepage = FileSystem.GetFileCodepage(file);
			if (codepage == -1) return; // If the file is locked, stop.
			string text = FileSystem.Read(file, Encoding.GetEncoding(codepage));
			try
			{
				if (this.CurDocIsUntitled() && !this.CurDocIsModified() && elements.Length == 1)
				{
					this.closingForOpenFile = true;
					this.CurDocument.Close();
					this.closingForOpenFile = false;
					this.CreateNewDocument(file, text, codepage);
				}
				else
				{
					this.CreateNewDocument(file, text, codepage);
				}
				this.AddNewReopenMenuItem(file);
			}
			catch
			{
				this.CreateNewDocument(file, text, codepage);
				this.AddNewReopenMenuItem(file);
			}
			this.CheckActiveEncodingButton(codepage);
		}
Esempio n. 24
0
        /// <summary>
		/// Creates a new blank document
		/// </summary>
        public void New(Object sender, EventArgs e)
        {
            String fileName = DocumentManager.GetNewDocumentName(null);
            TextEvent te = new TextEvent(EventType.FileNew, fileName);
            EventManager.DispatchEvent(this, te);
            if (!te.Handled)
            {
                this.CreateEditableDocument(fileName, "", (Int32)this.appSettings.DefaultCodePage);
            }
        }
Esempio n. 25
0
 /// <summary>
 /// Saves an editable document
 /// </summary>
 public void Save(String file)
 {
     if (!this.IsEditable) return;
     if (!this.IsUntitled && FileHelper.FileIsReadOnly(this.FileName))
     {
         String dlgTitle = TextHelper.GetString("Title.ConfirmDialog");
         String message = TextHelper.GetString("Info.MakeReadOnlyWritable");
         if (MessageBox.Show(Globals.MainForm, message, dlgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             ScintillaManager.MakeFileWritable(this.SciControl);
         }
         else return;
     }
     String oldFile = this.SciControl.FileName;
     Boolean otherFile = (this.SciControl.FileName != file);
     if (otherFile)
     {
         String args = this.FileName + ";" + file;
         RecoveryManager.RemoveTemporaryFile(this.FileName);
         TextEvent renaming = new TextEvent(EventType.FileRenaming, args);
         EventManager.DispatchEvent(this, renaming);
         TextEvent close = new TextEvent(EventType.FileClose, this.FileName);
         EventManager.DispatchEvent(this, close);
     }
     TextEvent saving = new TextEvent(EventType.FileSaving, file);
     EventManager.DispatchEvent(this, saving);
     if (!saving.Handled)
     {
         this.UpdateDocumentIcon(file);
         this.SciControl.FileName = file;
         ScintillaManager.CleanUpCode(this.SciControl);
         DataEvent de = new DataEvent(EventType.FileEncode, file, this.SciControl.Text);
         EventManager.DispatchEvent(this, de); // Lets ask if a plugin wants to encode and save the data..
         if (!de.Handled) FileHelper.WriteFile(file, this.SciControl.Text, this.SciControl.Encoding, this.SciControl.SaveBOM);
         this.IsModified = false;
         this.SciControl.SetSavePoint();
         RecoveryManager.RemoveTemporaryFile(this.FileName);
         this.fileInfo = new FileInfo(this.FileName);
         if (otherFile)
         {
             ScintillaManager.UpdateControlSyntax(this.SciControl);
             Globals.MainForm.OnFileSave(this, oldFile);
         }
         else Globals.MainForm.OnFileSave(this, null);
     }
     this.RefreshTexts();
 }
Esempio n. 26
0
 /// <summary>
 /// Create a new document from a template
 /// </summary>
 public void NewFromTemplate(Object sender, EventArgs e)
 {
     try
     {
         ToolStripItem button = (ToolStripItem)sender;
         String[] args = this.ProcessArgString(((ItemData)button.Tag).Tag).Split(';');
         Encoding encoding = Encoding.GetEncoding((Int32)this.appSettings.DefaultCodePage);
         String fileName = DocumentManager.GetNewDocumentName(args[0]);
         String contents = FileHelper.ReadFile(args[1], encoding);
         String processed = this.ProcessArgString(contents);
         ActionPoint actionPoint = SnippetHelper.ProcessActionPoint(processed);
         if (this.Documents.Length == 1 && this.Documents[0].IsUntitled)
         {
             this.closingForOpenFile = true;
             this.Documents[0].Close();
             this.closingForOpenFile = false;
         }
         TextEvent te = new TextEvent(EventType.FileTemplate, fileName);
         EventManager.DispatchEvent(this, te);
         if (!te.Handled)
         {
             ITabbedDocument document = (ITabbedDocument)this.CreateEditableDocument(fileName, actionPoint.Text, encoding.CodePage);
             SnippetHelper.ExecuteActionPoint(actionPoint, document.SciControl);
         }
     }
     catch (Exception ex)
     {
         ErrorManager.ShowError(ex);
     }
 }
Esempio n. 27
0
 /// <summary>
 /// Reverts the document to the orginal state
 /// </summary>
 public void Revert(Boolean showQuestion)
 {
     if (!this.IsEditable) return;
     if (showQuestion)
     {
         String dlgTitle = TextHelper.GetString("Title.ConfirmDialog");
         String message = TextHelper.GetString("Info.AreYouSureToRevert");
         if (MessageBox.Show(Globals.MainForm, message, " " + dlgTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
     }
     TextEvent te = new TextEvent(EventType.FileRevert, Globals.SciControl.FileName);
     EventManager.DispatchEvent(this, te);
     if (!te.Handled)
     {
         while (this.SciControl.CanUndo) this.SciControl.Undo();
         ButtonManager.UpdateFlaggedButtons();
     }
 }
Esempio n. 28
0
        /// <summary>
        /// Create the specified new document from the given template
        /// </summary>
        public void FileFromTemplate(String templatePath, String newFilePath)
        {
            try
            {
                Encoding encoding = Encoding.GetEncoding((Int32)this.appSettings.DefaultCodePage);
                String contents = FileHelper.ReadFile(templatePath);
                String processed = this.ProcessArgString(contents);
                ActionPoint actionPoint = SnippetHelper.ProcessActionPoint(processed);
                FileHelper.WriteFile(newFilePath, actionPoint.Text, encoding, Globals.Settings.SaveUnicodeWithBOM);
                if (actionPoint.EntryPosition != -1)
                {
                    if (this.Documents.Length == 1 && this.Documents[0].IsUntitled)
                    {
                        this.closingForOpenFile = true;
                        this.Documents[0].Close();
                        this.closingForOpenFile = false;
                    }

                    TextEvent te = new TextEvent(EventType.FileTemplate, newFilePath);
                    EventManager.DispatchEvent(this, te);
                    if (!te.Handled)
                    {
                        ITabbedDocument document = (ITabbedDocument)this.CreateEditableDocument(newFilePath, actionPoint.Text, encoding.CodePage);
                        SnippetHelper.ExecuteActionPoint(actionPoint, document.SciControl);
                    }
                }
                else
                {
                    TextEvent te = new TextEvent(EventType.FileTemplate, newFilePath);
                    EventManager.DispatchEvent(this, te);
                }
            }
            catch (Exception ex)
            {
                ErrorManager.ShowError(ex);
            }
        }
Esempio n. 29
0
 /// <summary>
 /// Processes the argument String variables
 /// </summary>
 public static String ProcessString(String args, Boolean dispatch)
 {
     try
     {
         String result = args;
         if (result == null) return String.Empty;
         result = ProcessCodeStyleLineBreaks(result);
         if (!Globals.Settings.UseTabs) result = reTabs.Replace(result, new MatchEvaluator(ReplaceTabs));
         result = reArgs.Replace(result, new MatchEvaluator(ReplaceVars));
         if (!dispatch || result.IndexOf('$') < 0) return result;
         TextEvent te = new TextEvent(EventType.ProcessArgs, result);
         EventManager.DispatchEvent(Globals.MainForm, te);
         result = ReplaceArgsWithGUI(te.Value);
         PrevSelWord = String.Empty;
         PrevSelText = String.Empty;
         return result;
     }
     catch (Exception ex)
     {
         ErrorManager.ShowError(ex);
         return String.Empty;
     }
 }
Esempio n. 30
0
 /// <summary>
 /// Handles the ending of a process
 /// </summary>
 private void ProcessEnded(Object sender, Int32 exitCode)
 {
     if (this.InvokeRequired) this.BeginInvoke((MethodInvoker)delegate { this.ProcessEnded(sender, exitCode); });
     else
     {
         String result = String.Format("Done({0})", exitCode);
         TraceManager.Add(result, (Int32)TraceType.ProcessEnd);
         TextEvent te = new TextEvent(EventType.ProcessEnd, result);
         EventManager.DispatchEvent(this, te);
         ButtonManager.UpdateFlaggedButtons();
     }
 }