Skip to content

Commit 324942a

Browse files
committed
Merge pull request #670 from Neverbirth/openeditabledocument
Changed most uses of MainForm.OpenEditableDocument
2 parents 44871aa + 4308c73 commit 324942a

File tree

7 files changed

+24
-19
lines changed

7 files changed

+24
-19
lines changed

External/Plugins/CodeRefactor/Commands/FindAllReferences.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ private void FindFinished(FRResults results)
126126
if (fileEntries.Value.Count > 0 && System.IO.File.Exists(fileEntries.Key))
127127
{
128128
SearchMatch entry = fileEntries.Value[0];
129-
PluginBase.MainForm.OpenEditableDocument(fileEntries.Key, false);
130-
RefactoringHelper.SelectMatch(PluginBase.MainForm.CurrentDocument.SciControl, entry);
129+
var doc = (ITabbedDocument)PluginBase.MainForm.OpenEditableDocument(fileEntries.Key, false);
130+
RefactoringHelper.SelectMatch(doc.SciControl, entry);
131131
break;
132132
}
133133
}
@@ -158,7 +158,7 @@ private IDictionary<String, List<SearchMatch>> ResolveActualMatches(FRResults re
158158
// we have to open/reopen the entry's file
159159
// there are issues with evaluating the declaration targets with non-open, non-current files
160160
// we have to do it each time as the process of checking the declaration source can change the currently open file!
161-
ScintillaControl sci = this.AssociatedDocumentHelper.LoadDocument(currentFileName);
161+
ScintillaControl sci = this.AssociatedDocumentHelper.LoadDocument(currentFileName).SciControl;
162162
// if the search result does point to the member source, store it
163163
if (RefactoringHelper.DoesMatchPointToTarget(sci, match, target, this.AssociatedDocumentHelper))
164164
{

External/Plugins/CodeRefactor/Commands/Move.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ private void UpdateReferencesNextTarget()
358358
oldType = oldType.Trim('.');
359359
MessageBar.Locked = true;
360360
string newFilePath = currentTarget.NewFilePath;
361-
ScintillaControl sci = AssociatedDocumentHelper.LoadDocument(currentTarget.TmpFilePath ?? newFilePath);
361+
var doc = AssociatedDocumentHelper.LoadDocument(currentTarget.TmpFilePath ?? newFilePath);
362+
ScintillaControl sci = doc.SciControl;
362363
List<SearchMatch> matches = search.Matches(sci.Text);
363364
string packageReplacement = "package";
364365
if (currentTarget.NewPackage != "")
@@ -383,7 +384,7 @@ private void UpdateReferencesNextTarget()
383384
}
384385
//Do we want to open modified files?
385386
//if (sci.IsModify) AssociatedDocumentHelper.MarkDocumentToKeep(file);
386-
PluginBase.MainForm.CurrentDocument.Save();
387+
doc.Save();
387388
MessageBar.Locked = false;
388389
UserInterfaceManager.ProgressDialog.Show();
389390
UserInterfaceManager.ProgressDialog.SetTitle(TextHelper.GetString("Info.FindingReferences"));
@@ -507,21 +508,23 @@ private void FindFinished(FRResults results)
507508
entry.Key == currentTarget.NewFilePath) continue;
508509
string file = entry.Key;
509510
UserInterfaceManager.ProgressDialog.UpdateStatusMessage(TextHelper.GetString("Info.Updating") + " \"" + file + "\"");
511+
ITabbedDocument doc;
510512
ScintillaControl sci;
511513
var actualMatches = new List<SearchMatch>();
512514
foreach (SearchMatch match in entry.Value)
513515
{
514516
// we have to open/reopen the entry's file
515517
// there are issues with evaluating the declaration targets with non-open, non-current files
516518
// we have to do it each time as the process of checking the declaration source can change the currently open file!
517-
sci = AssociatedDocumentHelper.LoadDocument(file);
519+
sci = AssociatedDocumentHelper.LoadDocument(file).SciControl;
518520
// if the search result does point to the member source, store it
519521
if (RefactoringHelper.DoesMatchPointToTarget(sci, match, currentTargetResult, this.AssociatedDocumentHelper))
520522
actualMatches.Add(match);
521523
}
522524
if (actualMatches.Count == 0) continue;
523525
int currLine = -1;
524-
sci = AssociatedDocumentHelper.LoadDocument(file);
526+
doc = AssociatedDocumentHelper.LoadDocument(file);
527+
sci = doc.SciControl;
525528
string directory = Path.GetDirectoryName(file);
526529
// Let's check if we need to add the import. Check the considerations at the start of the file
527530
// directory != currentTarget.OwnerPath -> renamed owner directory, so both files in the same place
@@ -579,7 +582,7 @@ private void FindFinished(FRResults results)
579582
Results[file].AddRange(actualMatches);
580583
//Do we want to open modified files?
581584
//if (sci.IsModify) AssociatedDocumentHelper.MarkDocumentToKeep(file);
582-
PluginBase.MainForm.CurrentDocument.Save();
585+
doc.Save();
583586
}
584587

585588
currentTargetIndex++;

External/Plugins/CodeRefactor/Commands/Rename.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,13 @@ private void OnFindAllReferencesCompleted(Object sender, RefactorCompleteEventAr
242242
{
243243
UserInterfaceManager.ProgressDialog.UpdateStatusMessage(TextHelper.GetString("Info.Updating") + " \"" + entry.Key + "\"");
244244
// re-open the document and replace all the text
245-
var sci = AssociatedDocumentHelper.LoadDocument(entry.Key);
245+
var doc = AssociatedDocumentHelper.LoadDocument(entry.Key);
246+
var sci = doc.SciControl;
246247
// replace matches in the current file with the new name
247248
RefactoringHelper.ReplaceMatches(entry.Value, sci, this.newName);
248249
//Uncomment if we want to keep modified files
249250
//if (sci.IsModify) AssociatedDocumentHelper.MarkDocumentToKeep(entry.Key);
250-
PluginBase.MainForm.CurrentDocument.Save();
251+
doc.Save();
251252
}
252253
if (newFileName != null) RenameFile(eventArgs.Results);
253254
this.Results = eventArgs.Results;

External/Plugins/CodeRefactor/Provider/DocumentHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ public void MarkDocumentToKeep(String fileName)
130130
/// If the document was not already previously opened, this will flag
131131
/// it as a temporary file.
132132
/// </summary>
133-
public ScintillaControl LoadDocument(String fileName)
133+
public ITabbedDocument LoadDocument(String fileName)
134134
{
135135
ITabbedDocument newDocument = (ITabbedDocument)PluginBase.MainForm.OpenEditableDocument(fileName);
136136
this.RegisterLoadedDocument(newDocument);
137-
return ASContext.CurSciControl;
137+
return newDocument;
138138
}
139139

140140
/// <summary>

External/Plugins/CodeRefactor/Provider/RefactoringHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ public static ASResult GetRefactorTargetFromFile(string path, DocumentHelper ass
107107
{
108108
String fileName = Path.GetFileNameWithoutExtension(path);
109109
Int32 line = 0;
110-
ScintillaControl sci = associatedDocumentHelper.LoadDocument(path);
110+
var doc = associatedDocumentHelper.LoadDocument(path);
111+
ScintillaControl sci = doc != null ? doc.SciControl : null;
111112
if (sci == null) return null; // Should not happen...
112113
List<ClassModel> classes = ASContext.Context.CurrentModel.Classes;
113114
if (classes.Count > 0)

External/Plugins/FlashDebugger/Helpers/ScintillaHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,9 @@ static public void ActivateDocument(string filefullpath)
332332

333333
static public ScintillaControl ActivateDocument(string filefullpath, int line, Boolean bSelectLine)
334334
{
335-
PluginBase.MainForm.OpenEditableDocument(filefullpath, false);
336-
if (PluginBase.MainForm.CurrentDocument.FileName != filefullpath) return null;
337-
ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl;
335+
var doc = PluginBase.MainForm.OpenEditableDocument(filefullpath, false) as ITabbedDocument;
336+
if (doc == null || doc.FileName != filefullpath) return null;
337+
ScintillaControl sci = doc.SciControl;
338338
if (line >= 0)
339339
{
340340
sci.EnsureVisible(line);

FlashDevelop/Dialogs/FRInFilesDialog.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -631,10 +631,10 @@ private void ResultsViewDoubleClick(Object sender, System.EventArgs e)
631631
if (File.Exists(data.Key))
632632
{
633633
Globals.MainForm.Activate();
634-
Globals.MainForm.OpenEditableDocument(data.Key, false);
635-
if (Globals.CurrentDocument.IsEditable)
634+
var doc = Globals.MainForm.OpenEditableDocument(data.Key, false) as ITabbedDocument;
635+
if (doc != null && doc.IsEditable)
636636
{
637-
ScintillaControl sci = Globals.CurrentDocument.SciControl;
637+
ScintillaControl sci = doc.SciControl;
638638
if (this.resultsView.Columns.Count == 4)
639639
{
640640
Int32 column = sci.MBSafeTextLength(data.Value.LineText.Substring(0, data.Value.Column));

0 commit comments

Comments
 (0)