@@ -26,10 +26,11 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
2626OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
2727WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2828*/
29- using System ;
29+ using System ;
3030using System . Diagnostics ;
3131using System . IO ;
3232using System . Windows . Forms ;
33+ using DgmlParser ;
3334using Dot2Graph ;
3435using Microsoft . Msagl . Drawing ;
3536using Microsoft . Msagl . GraphViewerGdi ;
@@ -41,7 +42,7 @@ public class FormStuff {
4142 protected static GViewer GViewer ;
4243
4344 public static Form CreateOrAttachForm ( GViewer gviewer , Form form ) {
44- GViewer = gviewer ;
45+ GViewer = gviewer ;
4546 if ( form == null )
4647 form = new Form ( ) ;
4748 form . SuspendLayout ( ) ;
@@ -58,13 +59,13 @@ public static Form CreateOrAttachForm(GViewer gviewer, Form form) {
5859 return form ;
5960 }
6061
61- static void form_Load ( object sender , EventArgs e ) {
62- ( ( Form ) sender ) . Focus ( ) ;
62+ static void form_Load ( object sender , EventArgs e ) {
63+ ( ( Form ) sender ) . Focus ( ) ;
6364 }
6465
6566
6667 static MenuStrip GetMainMenuStrip ( ) {
67- var menu = new MenuStrip ( ) ;
68+ var menu = new MenuStrip ( ) ;
6869 menu . Items . Add ( FileStripItem ( ) ) ;
6970
7071 return menu ;
@@ -73,7 +74,7 @@ static MenuStrip GetMainMenuStrip() {
7374
7475 static ToolStripItem FileStripItem ( ) {
7576 var item = new ToolStripMenuItem ( "File" ) ;
76- item . DropDownItems . Add ( ( ToolStripItem ) OpenDotFileItem ( ) ) ;
77+ item . DropDownItems . Add ( ( ToolStripItem ) OpenDotFileItem ( ) ) ;
7778 item . DropDownItems . Add ( ReloadDotFileItem ( ) ) ;
7879 return item ;
7980 }
@@ -86,8 +87,8 @@ static ToolStripItem ReloadDotFileItem() {
8687 }
8788
8889 static void ReloadFileClick ( object sender , EventArgs e ) {
89- if ( lastFileName != null )
90- ReadGraphFromFile ( lastFileName , GViewer , false ) ;
90+ if ( lastFileName != null )
91+ ReadGraphFromFile ( lastFileName , GViewer , false ) ;
9192 }
9293
9394 static ToolStripItem OpenDotFileItem ( ) {
@@ -101,7 +102,7 @@ static void OpenFileClick(object sender, EventArgs e) {
101102
102103 var openFileDialog = new OpenFileDialog {
103104 RestoreDirectory = true ,
104- Filter = "DOT (*.dot,*.gv)|*.dot;*.gv| All(*.*)|*.*"
105+ Filter = "MSAGL Files(*.msagl)|*.msagl| DOT (*.dot,*.gv)|*.dot;*.gv|DGML Files(*.dgml)|*.dgml| All(*.*)|*.*"
105106 } ;
106107
107108 if ( openFileDialog . ShowDialog ( ) == DialogResult . OK )
@@ -110,24 +111,46 @@ static void OpenFileClick(object sender, EventArgs e) {
110111
111112 internal static Graph CreateDrawingGraphFromFile ( string fileName , out int line , out int column , out bool msaglFile ) {
112113 string msg ;
113- var graph = Parser . Parse ( fileName , out line , out column , out msg ) ;
114- if ( graph != null ) {
115- msaglFile = false ;
116- return graph ;
114+ Graph graph = null ;
115+ msaglFile = false ;
116+ line = column = 0 ;
117+
118+ // Get extension
119+ string ext = Path . GetExtension ( fileName ) ;
120+ switch ( ext . ToLower ( ) ) {
121+ case ".dgml" :
122+ try {
123+ graph = DgmlParser . DgmlParser . Parse ( fileName ) ;
124+ line = column = 0 ;
125+ return graph ;
126+ }
127+ catch ( Exception ) {
128+ System . Diagnostics . Debug . WriteLine ( "cannot read " + fileName ) ;
129+ }
130+ break ;
131+ case ".dot" :
132+ case ".gv" :
133+ graph = Parser . Parse ( fileName , out line , out column , out msg ) ;
134+ if ( graph != null ) {
135+ return graph ;
136+ }
137+ break ;
138+ case ".msagl" :
139+ default :
140+ try {
141+ graph = Graph . Read ( fileName ) ;
142+ msaglFile = true ;
143+ return graph ;
144+ }
145+ catch ( Exception ) {
146+ System . Diagnostics . Debug . WriteLine ( "cannot read " + fileName ) ;
147+ }
148+ break ;
117149 }
118150
119- try {
120- graph = Graph . Read ( fileName ) ;
121- msaglFile = true ;
122- return graph ;
123- } catch ( Exception ) {
124- System . Diagnostics . Debug . WriteLine ( "cannot read " + fileName ) ;
125- }
126- msaglFile = false ;
127- return null ;
151+ return graph ;
128152 }
129153
130-
131154 public static void ReadGraphFromFile ( string fileName , GViewer gViewer , bool verbose ) {
132155 int eLine , eColumn ;
133156 bool msaglFile ;
0 commit comments