-
Notifications
You must be signed in to change notification settings - Fork 319
Add File Type Support When Open File and Update Test Project to NET 8 #393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -26,10 +26,11 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||||||
*/ | ||||||
using System; | ||||||
using System; | ||||||
using System.Diagnostics; | ||||||
using System.IO; | ||||||
using System.Windows.Forms; | ||||||
using DgmlParser; | ||||||
using Dot2Graph; | ||||||
using Microsoft.Msagl.Drawing; | ||||||
using Microsoft.Msagl.GraphViewerGdi; | ||||||
|
@@ -41,7 +42,7 @@ public class FormStuff { | |||||
protected static GViewer GViewer; | ||||||
|
||||||
public static Form CreateOrAttachForm(GViewer gviewer, Form form) { | ||||||
GViewer=gviewer; | ||||||
GViewer = gviewer; | ||||||
if (form == null) | ||||||
form = new Form(); | ||||||
form.SuspendLayout(); | ||||||
|
@@ -58,13 +59,13 @@ public static Form CreateOrAttachForm(GViewer gviewer, Form form) { | |||||
return form; | ||||||
} | ||||||
|
||||||
static void form_Load(object sender,EventArgs e) { | ||||||
((Form) sender).Focus(); | ||||||
static void form_Load(object sender, EventArgs e) { | ||||||
((Form)sender).Focus(); | ||||||
} | ||||||
|
||||||
|
||||||
static MenuStrip GetMainMenuStrip() { | ||||||
var menu=new MenuStrip(); | ||||||
var menu = new MenuStrip(); | ||||||
menu.Items.Add(FileStripItem()); | ||||||
|
||||||
return menu; | ||||||
|
@@ -73,7 +74,7 @@ static MenuStrip GetMainMenuStrip() { | |||||
|
||||||
static ToolStripItem FileStripItem() { | ||||||
var item = new ToolStripMenuItem("File"); | ||||||
item.DropDownItems.Add((ToolStripItem) OpenDotFileItem()); | ||||||
item.DropDownItems.Add((ToolStripItem)OpenDotFileItem()); | ||||||
item.DropDownItems.Add(ReloadDotFileItem()); | ||||||
return item; | ||||||
} | ||||||
|
@@ -86,8 +87,8 @@ static ToolStripItem ReloadDotFileItem() { | |||||
} | ||||||
|
||||||
static void ReloadFileClick(object sender, EventArgs e) { | ||||||
if(lastFileName!=null) | ||||||
ReadGraphFromFile(lastFileName, GViewer, false); | ||||||
if (lastFileName != null) | ||||||
ReadGraphFromFile(lastFileName, GViewer, false); | ||||||
} | ||||||
|
||||||
static ToolStripItem OpenDotFileItem() { | ||||||
|
@@ -101,7 +102,7 @@ static void OpenFileClick(object sender, EventArgs e) { | |||||
|
||||||
var openFileDialog = new OpenFileDialog { | ||||||
RestoreDirectory = true, | ||||||
Filter = "DOT (*.dot,*.gv)|*.dot;*.gv| All(*.*)|*.*" | ||||||
Filter = "MSAGL Files(*.msagl)|*.msagl|DOT (*.dot,*.gv)|*.dot;*.gv|DGML Files(*.dgml)|*.dgml|All(*.*)|*.*" | ||||||
}; | ||||||
|
||||||
if (openFileDialog.ShowDialog() == DialogResult.OK) | ||||||
|
@@ -110,24 +111,46 @@ static void OpenFileClick(object sender, EventArgs e) { | |||||
|
||||||
internal static Graph CreateDrawingGraphFromFile(string fileName, out int line, out int column, out bool msaglFile) { | ||||||
string msg; | ||||||
var graph = Parser.Parse(fileName, out line, out column, out msg); | ||||||
if (graph != null) { | ||||||
msaglFile = false; | ||||||
return graph; | ||||||
Graph graph = null; | ||||||
msaglFile = false; | ||||||
line = column = 0; | ||||||
|
||||||
// Get extension | ||||||
string ext = Path.GetExtension(fileName); | ||||||
switch (ext.ToLower()) { | ||||||
case ".dgml": | ||||||
try { | ||||||
graph = DgmlParser.DgmlParser.Parse(fileName); | ||||||
line = column = 0; | ||||||
return graph; | ||||||
} | ||||||
catch (Exception) { | ||||||
System.Diagnostics.Debug.WriteLine("cannot read " + fileName); | ||||||
} | ||||||
break; | ||||||
case ".dot": | ||||||
case ".gv": | ||||||
graph = Parser.Parse(fileName, out line, out column, out msg); | ||||||
if (graph != null) { | ||||||
return graph; | ||||||
} | ||||||
break; | ||||||
case ".msagl": | ||||||
default: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default case assumes MSAGL format for unknown extensions, which may not be intuitive. Consider adding explicit handling for .msagl extension and making the default case more explicit about fallback behavior. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
try { | ||||||
graph = Graph.Read(fileName); | ||||||
msaglFile = true; | ||||||
return graph; | ||||||
} | ||||||
catch (Exception) { | ||||||
System.Diagnostics.Debug.WriteLine("cannot read " + fileName); | ||||||
} | ||||||
Comment on lines
+145
to
+147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Catching generic Exception without re-throwing or proper error handling can mask important errors. Consider catching specific exceptions or logging more detailed error information for debugging. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
break; | ||||||
} | ||||||
|
||||||
try { | ||||||
graph = Graph.Read(fileName); | ||||||
msaglFile = true; | ||||||
return graph; | ||||||
} catch (Exception) { | ||||||
System.Diagnostics.Debug.WriteLine("cannot read " + fileName); | ||||||
} | ||||||
msaglFile = false; | ||||||
return null; | ||||||
return graph; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function can return null when all parsing attempts fail, but the method signature doesn't indicate this possibility. Consider returning a default empty graph or updating the method signature to make the nullable return explicit.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
} | ||||||
|
||||||
|
||||||
public static void ReadGraphFromFile(string fileName, GViewer gViewer, bool verbose) { | ||||||
int eLine, eColumn; | ||||||
bool msaglFile; | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching generic Exception without re-throwing or proper error handling can mask important errors. Consider catching specific exceptions or logging more detailed error information for debugging.
Copilot uses AI. Check for mistakes.