| 29 | | private import std.string; |
|---|
| 30 | | |
|---|
| 31 | | //alias ArbitraryObj!(char[][]) FileArguments; |
|---|
| 32 | | |
|---|
| 33 | | |
|---|
| 34 | | // static properties |
|---|
| 35 | | private static MenuManager menuMan() { return sGUI.menuMan; }; |
|---|
| 36 | | private static ToolBarManager toolMan() { return sGUI.toolMan; }; |
|---|
| 37 | | private static ActionManager pthis; |
|---|
| 38 | | |
|---|
| 39 | | public NavCache navCache; |
|---|
| 40 | | |
|---|
| 41 | | |
|---|
| 42 | | public this() |
|---|
| 43 | | { |
|---|
| 44 | | navCache = new NavCache(); |
|---|
| 45 | | } |
|---|
| 46 | | |
|---|
| 47 | | public void actionExit(Event e) |
|---|
| 48 | | { |
|---|
| 49 | | // do save and close doc |
|---|
| 50 | | sGUI.onClose(e); |
|---|
| 51 | | |
|---|
| 52 | | /** Only dispose if is closing */ |
|---|
| 53 | | if (GUI.isClosing) |
|---|
| 54 | | sShell.dispose(); |
|---|
| 55 | | } |
|---|
| 56 | | |
|---|
| 57 | | |
|---|
| 58 | | public void actionNewProject(Event e) |
|---|
| 59 | | { |
|---|
| 60 | | auto PrjProperty dlg = new PrjProperty(sShell, null); |
|---|
| 61 | | if(dlg.open() == "OK"){ |
|---|
| 62 | | if(dlg.createNew && dlg.project) |
|---|
| 63 | | { |
|---|
| 64 | | // create the new project |
|---|
| 65 | | sGUI.packageExp.addProject(dlg.project); |
|---|
| 66 | | toolMan.updateToolBar(); |
|---|
| 67 | | } |
|---|
| 68 | | } |
|---|
| 69 | | } |
|---|
| 70 | | |
|---|
| 71 | | public void actionOpenProject(Event e) |
|---|
| 72 | | { |
|---|
| 73 | | auto DirectoryDialog dlg = new DirectoryDialog(sShell, SWT.OPEN); |
|---|
| 74 | | dlg.dh_setFilterPath(Globals.recentDir); |
|---|
| 75 | | char[] fullpath = dlg.dh_open(); |
|---|
| 76 | | if(fullpath) { |
|---|
| 77 | | if(!Project.checkDir(fullpath)){ |
|---|
| 78 | | MessageBox_showMessage(Globals.getTranslation("mb.root_as_prjdir")); |
|---|
| 79 | | return; |
|---|
| 80 | | } |
|---|
| 81 | | |
|---|
| 82 | | char[] file = std.path.join(fullpath, Project.EXT); |
|---|
| 83 | | if(!std.file.exists(file)){ |
|---|
| 84 | | if(SWT.YES != MessageBox_showMessage(Globals.getTranslation("mb.open_plain_prj"), |
|---|
| 85 | | Globals.getTranslation("QUESTION"), sShell, SWT.ICON_QUESTION | SWT.YES | SWT.NO)) |
|---|
| 86 | | return; |
|---|
| 87 | | } |
|---|
| 88 | | |
|---|
| 89 | | sGUI.packageExp.loadProject(fullpath); |
|---|
| 90 | | toolMan.updateToolBar(); |
|---|
| 91 | | } |
|---|
| 92 | | } |
|---|
| 93 | | |
|---|
| 94 | | public void actionSave(Event e) |
|---|
| 95 | | { |
|---|
| 96 | | sGUI.editor.save(); |
|---|
| 97 | | toolMan.updateToolBar(); |
|---|
| 98 | | } |
|---|
| 99 | | |
|---|
| 100 | | public void actionSaveAll(Event e) |
|---|
| 101 | | { |
|---|
| 102 | | sGUI.editor.saveAll(); |
|---|
| 103 | | toolMan.updateToolBar(); |
|---|
| 104 | | } |
|---|
| 105 | | |
|---|
| 106 | | public void actionUndo( Event e ) |
|---|
| 107 | | { |
|---|
| 108 | | EditItem ei = sGUI.editor.getSelectedEditItemHSU(); |
|---|
| 109 | | if( ei ) ei.toolbarDirectlyHSU( 0 ); |
|---|
| 110 | | toolMan.updateToolBar(); |
|---|
| 111 | | } |
|---|
| 112 | | |
|---|
| 113 | | public void actionRedo( Event e ) |
|---|
| 114 | | { |
|---|
| 115 | | EditItem ei = sGUI.editor.getSelectedEditItemHSU(); |
|---|
| 116 | | if( ei ) ei.toolbarDirectlyHSU( 1 ); |
|---|
| 117 | | toolMan.updateToolBar(); |
|---|
| 118 | | } |
|---|
| 119 | | |
|---|
| 120 | | public void actionCut( Event e ) |
|---|
| 121 | | { |
|---|
| 122 | | EditItem ei = sGUI.editor.getSelectedEditItemHSU(); |
|---|
| 123 | | if( ei ) ei.toolbarDirectlyHSU( 2 ); |
|---|
| 124 | | toolMan.updateToolBar(); |
|---|
| 125 | | } |
|---|
| 126 | | |
|---|
| 127 | | public void actionCopy( Event e ) |
|---|
| 128 | | { |
|---|
| 129 | | EditItem ei = sGUI.editor.getSelectedEditItemHSU(); |
|---|
| 130 | | if( ei ) ei.toolbarDirectlyHSU( 3 ); |
|---|
| 131 | | toolMan.updateToolBar(); |
|---|
| 132 | | } |
|---|
| 133 | | |
|---|
| 134 | | public void actionPaste( Event e ) |
|---|
| 135 | | { |
|---|
| 136 | | EditItem ei = sGUI.editor.getSelectedEditItemHSU(); |
|---|
| 137 | | if( ei ) ei.toolbarDirectlyHSU( 4 ); |
|---|
| 138 | | toolMan.updateToolBar(); |
|---|
| 139 | | } |
|---|
| 140 | | |
|---|
| 141 | | public void actionNavigate(Event e) |
|---|
| 142 | | { |
|---|
| 143 | | NavPoint pt; |
|---|
| 144 | | Integer ii = cast(Integer)e.data; |
|---|
| 145 | | if(ii.intValue() == 0){ |
|---|
| 146 | | // back |
|---|
| 147 | | pt = navCache.navBack(); |
|---|
| 148 | | }else{ |
|---|
| 149 | | // forward |
|---|
| 150 | | pt = navCache.navForward(); |
|---|
| 151 | | } |
|---|
| 152 | | } |
|---|
| 153 | | |
|---|
| 154 | | public void actionClearNavCache(Event e) |
|---|
| 155 | | { |
|---|
| 156 | | navCache.clear(); |
|---|
| 157 | | } |
|---|
| 158 | | |
|---|
| 159 | | /** |
|---|
| 160 | | * invoke when use click the external tools menu item |
|---|
| 161 | | */ |
|---|
| 162 | | public void actionExtTool(Event e) { |
|---|
| 163 | | MenuItem mi = cast(MenuItem)e.widget; |
|---|
| 164 | | assert(mi); |
|---|
| 165 | | ToolEntry entry = cast(ToolEntry)mi.getData(); |
|---|
| 166 | | |
|---|
| 167 | | /** |
|---|
| 168 | | * set the most recently operation to the toolItem, |
|---|
| 169 | | */ |
|---|
| 170 | | // save the last tool name |
|---|
| 171 | | ToolEntry.lastTool = entry; |
|---|
| 172 | | toolMan.updateExtToolInfo(); |
|---|
| 173 | | |
|---|
| 174 | | execExtTool(entry); |
|---|
| 175 | | } |
|---|
| 176 | | |
|---|
| 177 | | /** |
|---|
| 178 | | * invoke when use click the external tools in toolbar |
|---|
| 179 | | */ |
|---|
| 180 | | public void actionTbarExtTools(Event event) { |
|---|
| 181 | | /** |
|---|
| 182 | | * A selection event will be fired when a drop down tool |
|---|
| 183 | | * item is selected in the main area and in the drop |
|---|
| 184 | | * down arrow. Examine the event detail to determine |
|---|
| 185 | | * where the widget was selected. |
|---|
| 186 | | */ |
|---|
| 187 | | if (event.detail == SWT.ARROW) { |
|---|
| 188 | | /* |
|---|
| 189 | | * The drop down arrow was selected. |
|---|
| 190 | | */ |
|---|
| 191 | | |
|---|
| 192 | | // Position the menu below and vertically aligned with the the drop down tool button. |
|---|
| 193 | | ToolItem toolItem = cast(ToolItem) event.widget; |
|---|
| 194 | | ToolBar toolBar = toolItem.getParent(); |
|---|
| 195 | | |
|---|
| 196 | | Rectangle toolItemBounds = toolItem.getBounds(); |
|---|
| 197 | | Point point = toolBar.toDisplay(toolItemBounds.x, toolItemBounds.y); |
|---|
| 198 | | Menu menu = menuMan.getExtToolMenu(); |
|---|
| 199 | | menu.setLocation(point.x, point.y + toolItemBounds.height); |
|---|
| 200 | | menu.setVisible(true); |
|---|
| 201 | | } else { |
|---|
| 202 | | /* |
|---|
| 203 | | * Main area of drop down tool item selected. |
|---|
| 204 | | * An application would invoke the code to perform the action for the tool item. |
|---|
| 205 | | */ |
|---|
| 206 | | if(ToolEntry.lastTool) |
|---|
| 207 | | execExtTool(ToolEntry.lastTool); |
|---|
| 208 | | } |
|---|
| 209 | | } |
|---|
| 210 | | |
|---|
| 211 | | |
|---|
| 212 | | // COMPILER |
|---|
| 213 | | private bool checkCmdExist() |
|---|
| 214 | | { |
|---|
| 215 | | sGUI.outputPanel.setForeColor( 255, 0, 0 ); |
|---|
| 216 | | |
|---|
| 217 | | if( !std.file.exists( Globals.DMDPath ~ "\\bin\\dmd.exe" ) ) |
|---|
| 218 | | { |
|---|
| 219 | | sGUI.outputPanel.bringToFront(); |
|---|
| 220 | | sGUI.outputPanel.setString( " ERROR >>> Wrong DMD Path!!\n" ); |
|---|
| 221 | | return false; |
|---|
| 222 | | } |
|---|
| 223 | | |
|---|
| 224 | | if( Globals.useBUILD ) |
|---|
| 225 | | if( !std.file.exists( Globals.BUILDPath ) ) |
|---|
| 226 | | { |
|---|
| 227 | | sGUI.outputPanel.bringToFront(); |
|---|
| 228 | | sGUI.outputPanel.setString( " ERROR >>> Wrong BUILD Path!!\n" ); |
|---|
| 229 | | return false; |
|---|
| 230 | | } |
|---|
| 231 | | else |
|---|
| 232 | | { |
|---|
| 233 | | ItemInfo itemInfo; |
|---|
| 234 | | if( sGUI.editor.getItemCount()> 0 ) |
|---|
| 235 | | itemInfo = sGUI.editor.getSelectedItemInfoHSU(); |
|---|
| 236 | | else |
|---|
| 237 | | itemInfo = sGUI.packageExp.getSelection(); |
|---|
| 238 | | |
|---|
| 239 | | if( itemInfo ) |
|---|
| 240 | | { |
|---|
| 241 | | Project prj = itemInfo.getProject(); |
|---|
| 242 | | |
|---|
| 243 | | if( prj.projectBuildType > 0 ) |
|---|
| 244 | | if( !std.file.exists( Globals.DMCPath ~ "\\bin\\lib.exe" ) ) |
|---|
| 245 | | { |
|---|
| 246 | | sGUI.outputPanel.bringToFront(); |
|---|
| 247 | | sGUI.outputPanel.setString( " ERROR >>> Wrong DMC Path!!\n" ); |
|---|
| 248 | | return false; |
|---|
| 249 | | } |
|---|
| 250 | | } |
|---|
| 251 | | } |
|---|
| 252 | | |
|---|
| 253 | | return true; |
|---|
| 254 | | } |
|---|
| 255 | | |
|---|
| 256 | | // Clean |
|---|
| 257 | | public void actionCleanSourceRunning( Event e ) |
|---|
| 258 | | { |
|---|
| 259 | | if( !sGUI.editor ) return; |
|---|
| 260 | | |
|---|
| 261 | | Project prj; |
|---|
| 262 | | if( sGUI.editor.getItemCount()> 0 ) |
|---|
| 263 | | prj = sGUI.editor.getSelectedProjectHSU(); |
|---|
| 264 | | else |
|---|
| 265 | | prj = sGUI.packageExp.activeProject(); |
|---|
| 266 | | |
|---|
| 267 | | sGUI.outputPanel.bringToFront(); |
|---|
| 268 | | sGUI.outputPanel.setForeColor( 0, 0x33, 0x66 ); |
|---|
| 269 | | sGUI.outputPanel.setString( "Command >>> Clean Project: " ~ prj.projectName ); |
|---|
| 270 | | sGUI.outputPanel.appendString( "\nClean all files created during compiling: " ); |
|---|
| 271 | | |
|---|
| 272 | | char[][] d_running_files = std.file.listdir( prj.projectDir, "*.map" ); |
|---|
| 273 | | foreach( char[] d; d_running_files ) std.file.remove( d ); |
|---|
| 274 | | |
|---|
| 275 | | d_running_files = std.file.listdir( prj.projectDir, "*.rsp" ); |
|---|
| 276 | | foreach( char[] d; d_running_files ) std.file.remove( d ); |
|---|
| 277 | | |
|---|
| 278 | | d_running_files = std.file.listdir( prj.projectDir, "*.ksp" ); |
|---|
| 279 | | foreach( char[] d; d_running_files ) std.file.remove( d ); |
|---|
| 280 | | |
|---|
| 281 | | d_running_files = std.file.listdir( prj.projectDir, "*.lsp" ); |
|---|
| 282 | | foreach( char[] d; d_running_files ) std.file.remove( d ); |
|---|
| 283 | | |
|---|
| 284 | | d_running_files = std.file.listdir( prj.projectDir, "*.def" ); |
|---|
| 285 | | foreach( char[] d; d_running_files ) std.file.remove( d ); |
|---|
| 286 | | |
|---|
| 287 | | d_running_files = std.file.listdir( prj.projectDir, "*.lst" ); |
|---|
| 288 | | foreach( char[] d; d_running_files ) std.file.remove( d ); |
|---|
| 289 | | |
|---|
| 290 | | d_running_files = std.file.listdir( prj.projectDir, "*.obj" ); |
|---|
| 291 | | foreach( char[] d; d_running_files ) std.file.remove( d ); |
|---|
| 292 | | |
|---|
| 293 | | |
|---|
| 294 | | /* |
|---|
| 295 | | char[] exeName; |
|---|
| 296 | | if( prj.projectEXEName.length == 0 ) |
|---|
| 297 | | exeName = prj.projectDir ~ "\\" ~ prj.projectName ~ ".exe"; |
|---|
| 298 | | else |
|---|
| 299 | | exeName = prj.projectDir ~ "\\" ~ prj.projectEXEName ~ ".exe"; |
|---|
| 300 | | |
|---|
| 301 | | if( std.file.exists( exeName ) ) std.file.remove( exeName ); |
|---|
| 302 | | */ |
|---|
| 303 | | /* |
|---|
| 304 | | char[] objDir; |
|---|
| 305 | | if( prj.projectObjDir.length > 0 ) objDir = prj.projectDir ~ "\\" ~ prj.projectObjDir; else objDir = prj.projectDir; |
|---|
| 306 | | d_running_files = std.file.listdir( objDir, "*.obj" ); |
|---|
| 307 | | foreach( char[] d; d_running_files ) std.file.remove( d ); |
|---|
| 308 | | */ |
|---|
| 309 | | sGUI.outputPanel.appendString( "......OK!\n" ); |
|---|
| 310 | | } |
|---|
| 311 | | |
|---|
| 312 | | // Compile |
|---|
| 313 | | public void actionDefaultCompile( Event e ) |
|---|
| 314 | | { |
|---|
| 315 | | if( !checkCmdExist() ) return; |
|---|
| 316 | | |
|---|
| 317 | | ItemInfo itemInfo; |
|---|
| 318 | | if( sGUI.editor.getItemCount()> 0 ) |
|---|
| 319 | | itemInfo = sGUI.editor.getSelectedItemInfoHSU(); |
|---|
| 320 | | else |
|---|
| 321 | | itemInfo = sGUI.packageExp.getSelection(); |
|---|
| 322 | | |
|---|
| 323 | | sGUI.editor.saveAll(); |
|---|
| 324 | | |
|---|
| 325 | | if( itemInfo.isFile() ) |
|---|
| 326 | | { |
|---|
| 327 | | char filename[] = itemInfo.getFileName(); |
|---|
| 328 | | Project prj =itemInfo.getProject(); |
|---|
| 329 | | ToolEntry entry = prj.generateCompileCmdHSU( filename ); |
|---|
| 330 | | |
|---|
| 331 | | if( entry.name == "wrong -od path!" ) |
|---|
| 332 | | { |
|---|
| 333 | | sGUI.outputPanel.bringToFront(); |
|---|
| 334 | | sGUI.outputPanel.setForeColor( 0xff, 0, 0 ); |
|---|
| 335 | | sGUI.outputPanel.setString( "Command >>> Compiling File ......\n" ); |
|---|
| 336 | | sGUI.outputPanel.appendString( " ERROR >>> Wrong OBJ Files Path!!!\n" ); |
|---|
| 337 | | return; |
|---|
| 338 | | } |
|---|
| 339 | | |
|---|
| 340 | | sGUI.outputPanel.setForeColor( 0, 0x33, 0x66 ); |
|---|
| 341 | | char[] title = "Command >>> Compiling File: " ~ filename ~ "......\n"; |
|---|
| 342 | | execExtToolHSU( entry, title, true ); |
|---|
| 343 | | }else |
|---|
| 344 | | { |
|---|
| 345 | | sGUI.outputPanel.setForeColor( 0xff, 0, 0 ); |
|---|
| 346 | | sGUI.outputPanel.bringToFront(); |
|---|
| 347 | | sGUI.outputPanel.setString( "Command >>> Compiling File ......\n" ); |
|---|
| 348 | | sGUI.outputPanel.appendString( " ERROR >>> Not A D Source File!!!\n" ); |
|---|
| 349 | | } |
|---|
| 350 | | } |
|---|
| 351 | | |
|---|
| 352 | | // Run |
|---|
| 353 | | public void actionDefaultRun( Event e ) |
|---|
| 354 | | { |
|---|
| 355 | | Project prj; |
|---|
| 356 | | if( sGUI.editor.getItemCount()> 0 ) |
|---|
| 357 | | prj = sGUI.editor.getSelectedProjectHSU(); |
|---|
| 358 | | else |
|---|
| 359 | | prj = sGUI.packageExp.activeProject(); |
|---|
| 360 | | |
|---|
| 361 | | if( prj.projectBuildType > 0 ) |
|---|
| 362 | | { |
|---|
| 363 | | sGUI.outputPanel.setForeColor( 0xff, 0, 0 ); |
|---|
| 364 | | sGUI.outputPanel.bringToFront(); |
|---|
| 365 | | sGUI.outputPanel.setString( "Command >>> Running Project: " ~ prj.projectName ~ "......\n" ); |
|---|
| 366 | | sGUI.outputPanel.appendString( " ERROR >>> Can't Run Static/Dynamic Library!!!\n" ); |
|---|
| 367 | | return; |
|---|
| 368 | | } |
|---|
| 369 | | |
|---|
| 370 | | ToolEntry entry = prj.generateRunCmdHSU(); |
|---|
| 371 | | char[] title = "Command >>> Running Project: " ~ prj.projectName ~ "......\n"; |
|---|
| 372 | | |
|---|
| 373 | | if( entry ) |
|---|
| 374 | | { |
|---|
| 375 | | sGUI.outputPanel.setForeColor( 0, 0x33, 0x66 ); |
|---|
| 376 | | execExtToolHSU( entry, title, true ); |
|---|
| 377 | | }else |
|---|
| 378 | | { |
|---|
| 379 | | char[] exeFileName; |
|---|
| 380 | | if( prj.projectEXEName.length > 0 ) |
|---|
| 381 | | exeFileName = prj.projectEXEName ~ ".exe"; |
|---|
| 382 | | else |
|---|
| 383 | | exeFileName = prj.projectName ~ ".exe"; |
|---|
| 384 | | |
|---|
| 385 | | sGUI.outputPanel.setForeColor( 0xff, 0, 0 ); |
|---|
| 386 | | sGUI.outputPanel.bringToFront(); |
|---|
| 387 | | sGUI.outputPanel.setString( title ); |
|---|
| 388 | | sGUI.outputPanel.appendLine( " ERROR >>> No " ~ exeFileName ~" Exist!!!" ); |
|---|
| 389 | | sGUI.outputPanel.appendLine("\nFinished"); |
|---|
| 390 | | } |
|---|
| 391 | | } |
|---|
| 392 | | |
|---|
| 393 | | // Build |
|---|
| 394 | | public void actionDefaultBuildHSU( Event e ) |
|---|
| 395 | | { |
|---|
| 396 | | if( !checkCmdExist() ) return; |
|---|
| 397 | | |
|---|
| 398 | | Project prj; |
|---|
| 399 | | if( sGUI.editor.getItemCount()> 0 ) |
|---|
| 400 | | prj = sGUI.editor.getSelectedProjectHSU(); |
|---|
| 401 | | else |
|---|
| 402 | | prj = sGUI.packageExp.activeProject(); |
|---|
| 403 | | |
|---|
| 404 | | sGUI.editor.saveAll(); |
|---|
| 405 | | |
|---|
| 406 | | ToolEntry entry = prj.generateBuildCmdHSU(); |
|---|
| 407 | | char[] title = "Command >>> Building Project: " ~ prj.projectName ~ "......\n"; |
|---|
| 408 | | |
|---|
| 409 | | if( !entry ) |
|---|
| 410 | | { |
|---|
| 411 | | sGUI.outputPanel.setForeColor( 255, 107, 36 ); |
|---|
| 412 | | sGUI.outputPanel.bringToFront(); |
|---|
| 413 | | sGUI.outputPanel.setString( title ); |
|---|
| 414 | | sGUI.outputPanel.appendLine( " WARING >>> It Isn't Necessary To Build Anything!!" ); |
|---|
| 415 | | sGUI.outputPanel.appendLine("\nFinished"); |
|---|
| 416 | | }else |
|---|
| 417 | | { |
|---|
| 418 | | if( entry.name == "wrong -od path!" ) |
|---|
| 419 | | { |
|---|
| 420 | | sGUI.outputPanel.bringToFront(); |
|---|
| 421 | | sGUI.outputPanel.setForeColor( 0xff, 0, 0 ); |
|---|
| 422 | | sGUI.outputPanel.setString( title ); |
|---|
| 423 | | sGUI.outputPanel.appendString( " ERROR >>> Wrong OBJ Files Path!!!\n" ); |
|---|
| 424 | | return; |
|---|
| 425 | | } |
|---|
| 426 | | |
|---|
| 427 | | sGUI.outputPanel.setForeColor( 0, 0x33, 0x66 ); |
|---|
| 428 | | |
|---|
| 429 | | if( prj.projectBuildType > 0 ) |
|---|
| 430 | | actionDefaultMakeLibHSU( entry, prj ); |
|---|
| 431 | | else |
|---|
| 432 | | execExtToolHSU( entry, title, true ); |
|---|
| 433 | | } |
|---|
| 434 | | } |
|---|
| 435 | | |
|---|
| 436 | | // Build and Run |
|---|
| 437 | | public void actionDefaultBuild_RunHSU( Event e ) |
|---|
| 438 | | { |
|---|
| 439 | | sGUI.outputPanel.clear(); |
|---|
| 440 | | if( !checkCmdExist() ) return; |
|---|
| 441 | | |
|---|
| 442 | | Project prj; |
|---|
| 443 | | if( sGUI.editor.getItemCount()> 0 ) |
|---|
| 444 | | prj = sGUI.editor.getSelectedProjectHSU(); |
|---|
| 445 | | else |
|---|
| 446 | | prj = sGUI.packageExp.activeProject(); |
|---|
| 447 | | |
|---|
| 448 | | sGUI.editor.saveAll(); |
|---|
| 449 | | |
|---|
| 450 | | ToolEntry entry = prj.generateBuildCmdHSU(); |
|---|
| 451 | | |
|---|
| 452 | | char[] title = "Command >>> Running Project: " ~ prj.projectName ~ "......\n"; |
|---|
| 453 | | if( !entry ) |
|---|
| 454 | | { |
|---|
| 455 | | if( prj.projectBuildType > 0 ) |
|---|
| 456 | | { |
|---|
| 457 | | sGUI.outputPanel.setForeColor( 0xff, 0, 0 ); |
|---|
| 458 | | sGUI.outputPanel.bringToFront(); |
|---|
| 459 | | sGUI.outputPanel.setString( title ); |
|---|
| 460 | | sGUI.outputPanel.appendString( " ERROR >>> Can't Run Static/Dynamic Library!!!\n" ); |
|---|
| 461 | | return; |
|---|
| 462 | | } |
|---|
| 463 | | |
|---|
| 464 | | entry = prj.generateRunCmdHSU(); |
|---|
| 465 | | sGUI.outputPanel.setForeColor( 0, 0x33, 0x66 ); |
|---|
| 466 | | execExtToolHSU( entry, title, true ); |
|---|
| 467 | | }else |
|---|
| 468 | | { |
|---|
| 469 | | if( entry.name == "wrong -od path!" ) |
|---|
| 470 | | { |
|---|
| 471 | | sGUI.outputPanel.bringToFront(); |
|---|
| 472 | | sGUI.outputPanel.setForeColor( 0xff, 0, 0 ); |
|---|
| 473 | | sGUI.outputPanel.setString( title ); |
|---|
| 474 | | sGUI.outputPanel.appendString( " ERROR >>> Wrong OBJ Files Path!!!\n" ); |
|---|
| 475 | | return; |
|---|
| 476 | | } |
|---|
| 477 | | // delete EXE |
|---|
| 478 | | |
|---|
| 479 | | char[] exeFileName; |
|---|
| 480 | | if( prj.projectEXEName.length > 0 ) |
|---|
| 481 | | exeFileName = prj.projectDir ~ "\\" ~ prj.projectEXEName ~ ".exe"; |
|---|
| 482 | | else |
|---|
| 483 | | exeFileName = prj.projectDir ~ "\\" ~ prj.projectName ~ ".exe"; |
|---|
| 484 | | |
|---|
| 485 | | try |
|---|
| 486 | | { |
|---|
| 487 | | if( std.file.exists( exeFileName ) ) std.file.remove( exeFileName ); |
|---|
| 488 | | } |
|---|
| 489 | | catch |
|---|
| 490 | | { |
|---|
| 491 | | sGUI.outputPanel.setForeColor( 0xff, 0, 0 ); |
|---|
| 492 | | sGUI.outputPanel.bringToFront(); |
|---|
| 493 | | sGUI.outputPanel.setString( " ERROR >>> File Is Under Running!!!\n " ); |
|---|
| 494 | | return; |
|---|
| 495 | | } |
|---|
| 496 | | |
|---|
| 497 | | title = "Command >>> Building Project: " ~ prj.projectName ~ "......\n"; |
|---|
| 498 | | sGUI.outputPanel.setForeColor( 0, 0x33, 0x66 ); |
|---|
| 499 | | execExtToolHSU( entry, title, true, true ); |
|---|
| 500 | | |
|---|
| 501 | | title = "\nCommand >>> Running Project: " ~ prj.projectName ~ "......\n"; |
|---|
| 502 | | if( prj.projectBuildType > 0 ) |
|---|
| 503 | | { |
|---|
| 504 | | sGUI.outputPanel.setForeColor( 0xff, 0, 0 ); |
|---|
| 505 | | sGUI.outputPanel.bringToFront(); |
|---|
| 506 | | sGUI.outputPanel.setString( title ); |
|---|
| 507 | | sGUI.outputPanel.appendString( " ERROR >>> Can't Run Static/Dynamic Library!!!\n" ); |
|---|
| 508 | | return; |
|---|
| 509 | | } |
|---|
| 510 | | |
|---|
| 511 | | entry = prj.generateRunCmdHSU(); |
|---|
| 512 | | if( entry ) execExtToolHSU( entry, title, true, false ); |
|---|
| 513 | | } |
|---|
| 514 | | } |
|---|
| 515 | | |
|---|
| 516 | | // ReBuild All |
|---|
| 517 | | public void actionDefaultBuild(Event e) |
|---|
| 518 | | { |
|---|
| 519 | | if( !checkCmdExist() ) return; |
|---|
| 520 | | |
|---|
| 521 | | Project prj; |
|---|
| 522 | | if( sGUI.editor.getItemCount()> 0 ) |
|---|
| 523 | | prj = sGUI.editor.getSelectedProjectHSU(); |
|---|
| 524 | | else |
|---|
| 525 | | prj = sGUI.packageExp.activeProject(); |
|---|
| 526 | | |
|---|
| 527 | | sGUI.editor.saveAll(); |
|---|
| 528 | | |
|---|
| 529 | | ToolEntry entry = prj.generateBuildCmdHSU( true ); |
|---|
| 530 | | char[] title = "Command >>> ReBuilding Project: " ~ prj.projectName ~ "......\n"; |
|---|
| 531 | | |
|---|
| 532 | | if( entry.name == "wrong -od path!" ) |
|---|
| 533 | | { |
|---|
| 534 | | sGUI.outputPanel.bringToFront(); |
|---|
| 535 | | sGUI.outputPanel.setForeColor( 0xff, 0, 0 ); |
|---|
| 536 | | sGUI.outputPanel.setString( title ); |
|---|
| 537 | | sGUI.outputPanel.appendString( " ERROR >>> Wrong OBJ Files Path!!!\n" ); |
|---|
| 538 | | return; |
|---|
| 539 | | } |
|---|
| 540 | | |
|---|
| 541 | | if( Globals.useBUILD ) |
|---|
| 542 | | { |
|---|
| 543 | | if( prj.mainFile.length == 0 ) |
|---|
| 544 | | { |
|---|
| 545 | | sGUI.outputPanel.setForeColor( 0xff, 0, 0 ); |
|---|
| 546 | | sGUI.outputPanel.bringToFront(); |
|---|
| 547 | | sGUI.outputPanel.setString( title ); |
|---|
| 548 | | sGUI.outputPanel.appendString( " ERROR >>> Please Setup The Main File In Project Property.\n" ); |
|---|
| 549 | | return; |
|---|
| 550 | | } |
|---|
| 551 | | } |
|---|
| 552 | | |
|---|
| 553 | | sGUI.outputPanel.setForeColor( 0, 0x33, 0x66 ); |
|---|
| 554 | | if( prj.projectBuildType > 0 ) |
|---|
| 555 | | actionDefaultMakeLibHSU( entry, prj ); |
|---|
| 556 | | else |
|---|
| 557 | | execExtToolHSU( entry, title, true ); |
|---|
| 558 | | } |
|---|
| 559 | | |
|---|
| 560 | | // Make Library |
|---|
| 561 | | private void actionDefaultMakeLibHSU( ToolEntry entry, Project prj ) |
|---|
| 562 | | { |
|---|
| 563 | | if( !checkCmdExist() ) return; |
|---|
| 564 | | |
|---|
| 565 | | char[] title; |
|---|
| 566 | | sGUI.outputPanel.setForeColor( 0, 0x33, 0x66 ); |
|---|
| 567 | | if( !Globals.useBUILD ) |
|---|
| 568 | | { |
|---|
| 569 | | title = "Command >>> Compile All Files: " ~ prj.projectName ~ "......\n"; |
|---|
| 570 | | execExtToolHSU( entry, title, true, true ); |
|---|
| 571 | | |
|---|
| 572 | | entry = prj.generateMakeLibCmdHSU(); |
|---|
| 573 | | title = "Command >>> Make Library: " ~ prj.projectName ~ "......\n"; |
|---|
| 574 | | execExtToolHSU( entry, title, true, false ); |
|---|
| 575 | | }else |
|---|
| 576 | | { |
|---|
| 577 | | title = "Command >>> Make Library: " ~ prj.projectName ~ "......\n"; |
|---|
| 578 | | execExtToolHSU( entry, title, true, true ); |
|---|
| 579 | | } |
|---|
| 580 | | } |
|---|
| 581 | | |
|---|
| 582 | | private void execExtToolHSU( ToolEntry entry, char[] title = "", bool bSoon = false, bool bCls = true ) |
|---|
| 583 | | { |
|---|
| 584 | | auto WaitCursor wc = new WaitCursor(sShell); |
|---|
| 585 | | |
|---|
| 586 | | // keep the old entry |
|---|
| 587 | | ToolEntry newEntry = entry.clone(); |
|---|
| 588 | | |
|---|
| 589 | | //if(newEntry.savefirst) sGUI.editor.saveAll(); |
|---|
| 590 | | |
|---|
| 591 | | if(newEntry.dir.length == 0) newEntry.dir = std.file.getcwd(); |
|---|
| 592 | | |
|---|
| 593 | | // substitute envirenment variable |
|---|
| 594 | | envSubstitute( newEntry.cmd, true ); |
|---|
| 595 | | envSubstitute( newEntry.args, true ); |
|---|
| 596 | | // the dir doesn't need quotation added |
|---|
| 597 | | envSubstitute( newEntry.dir, false ); |
|---|
| 598 | | |
|---|
| 599 | | std.file.chdir( newEntry.dir ); |
|---|
| 600 | | |
|---|
| 601 | | sGUI.outputPanel.bringToFront(); |
|---|
| 602 | | if( bCls ) |
|---|
| 603 | | sGUI.outputPanel.setString( title ); |
|---|
| 604 | | else |
|---|
| 605 | | sGUI.outputPanel.appendString( title ); |
|---|
| 606 | | |
|---|
| 607 | | sGUI.outputPanel.appendString(newEntry.cmd ~" " ~ newEntry.args ~ "\n\n" ); |
|---|
| 608 | | sGUI.outputPanel.setBusy( true ); |
|---|
| 609 | | |
|---|
| 610 | | if( bSoon ) |
|---|
| 611 | | _doExecExtTool( newEntry ); |
|---|
| 612 | | else |
|---|
| 613 | | { |
|---|
| 614 | | ThreadEx thread = new ThreadEx( newEntry, &_doExecExtTool ); |
|---|
| 615 | | thread.start(); |
|---|
| 616 | | } |
|---|
| 617 | | } |
|---|
| 618 | | |
|---|
| 619 | | private void execExtTool(ToolEntry entry) { |
|---|
| 620 | | auto WaitCursor wc = new WaitCursor(sShell); |
|---|
| 621 | | |
|---|
| 622 | | // keep the old entry |
|---|
| 623 | | ToolEntry newEntry = entry.clone(); |
|---|
| 624 | | |
|---|
| 625 | | if(newEntry.savefirst) |
|---|
| 626 | | sGUI.editor.saveAll(); |
|---|
| 627 | | |
|---|
| 628 | | if(newEntry.dir.length == 0) |
|---|
| 629 | | newEntry.dir = std.file.getcwd(); |
|---|
| 630 | | |
|---|
| 631 | | // substitute envirenment variable |
|---|
| 632 | | envSubstitute(newEntry.cmd, true); |
|---|
| 633 | | envSubstitute(newEntry.args, true); |
|---|
| 634 | | // the dir doesn't need quotation added |
|---|
| 635 | | envSubstitute(newEntry.dir, false); |
|---|
| 636 | | |
|---|
| 637 | | std.file.chdir(newEntry.dir); |
|---|
| 638 | | |
|---|
| 639 | | sGUI.outputPanel.bringToFront(); |
|---|
| 640 | | sGUI.outputPanel.setString("cwd > " ~ newEntry.dir ~ "\n"); |
|---|
| 641 | | |
|---|
| 642 | | sGUI.outputPanel.appendString(newEntry.cmd ~" " ~ newEntry.args ~ "\n\n" ); |
|---|
| 643 | | sGUI.outputPanel.setBusy(true); |
|---|
| 644 | | |
|---|
| 645 | | ThreadEx thread = new ThreadEx(newEntry, &_doExecExtTool); |
|---|
| 646 | | thread.start(); |
|---|
| 647 | | } |
|---|
| 648 | | |
|---|
| 649 | | int _doExecExtTool(Object args) |
|---|
| 650 | | { |
|---|
| 651 | | // nested functions |
|---|
| 652 | | void _echo(JObject args) |
|---|
| 653 | | { |
|---|
| 654 | | if(!sGUI.outputPanel.isDisposed()){ |
|---|
| 655 | | String s = cast(String)args; |
|---|
| 656 | | sGUI.outputPanel.appendLine(s.toUtf8); |
|---|
| 657 | | } |
|---|
| 658 | | } |
|---|
| 659 | | void _end(Object args) |
|---|
| 660 | | { |
|---|
| 661 | | if(!sGUI.outputPanel.isDisposed()){ |
|---|
| 662 | | sGUI.outputPanel.setBusy(false); |
|---|
| 663 | | sGUI.outputPanel.appendLine("\nFinished"); |
|---|
| 664 | | } |
|---|
| 665 | | } |
|---|
| 666 | | |
|---|
| 667 | | // code begin here |
|---|
| 668 | | /** |
|---|
| 669 | | * since here is not in GUI thread, Display.getCurrent() just return |
|---|
| 670 | | * null !!! use Display.getDefault() instead |
|---|
| 671 | | */ |
|---|
| 672 | | // Display display = Display.getCurrent(); |
|---|
| 673 | | Display display = Display.getDefault(); |
|---|
| 674 | | |
|---|
| 675 | | try{ |
|---|
| 676 | | ToolEntry entry = cast(ToolEntry)args; |
|---|
| 677 | | Executer.run(entry, &_echo, display); |
|---|
| 678 | | }catch(Object o){ |
|---|
| 679 | | Util.trace(o.toString()); |
|---|
| 680 | | }finally{ |
|---|
| 681 | | display.asyncExec( new class() JObjectImpl, Runnable{ |
|---|
| | 29 | private import std.string; |
|---|
| | 30 | |
|---|
| | 31 | //alias ArbitraryObj!(char[][]) FileArguments; |
|---|
| | 32 | |
|---|
| | 33 | |
|---|
| | 34 | // static properties |
|---|
| | 35 | private static MenuManager menuMan() { return sGUI.menuMan; }; |
|---|
| | 36 | private static ToolBarManager toolMan() { return sGUI.toolMan; }; |
|---|
| | 37 | private static ActionManager pthis; |
|---|
| | 38 | |
|---|
| | 39 | public NavCache navCache; |
|---|
| | 40 | |
|---|
| | 41 | |
|---|
| | 42 | public this() |
|---|
| | 43 | { |
|---|
| | 44 | navCache = new NavCache(); |
|---|
| | 45 | } |
|---|
| | 46 | |
|---|
| | 47 | public void actionExit(Event e) |
|---|
| | 48 | { |
|---|
| | 49 | // do save and close doc |
|---|
| | 50 | sGUI.onClose(e); |
|---|
| | 51 | |
|---|
| | 52 | /** Only dispose if is closing */ |
|---|
| | 53 | if (GUI.isClosing) |
|---|
| | 54 | sShell.dispose(); |
|---|
| | 55 | } |
|---|
| | 56 | |
|---|
| | 57 | |
|---|
| | 58 | public void actionNewProject(Event e) |
|---|
| | 59 | { |
|---|
| | 60 | auto PrjProperty dlg = new PrjProperty(sShell, null); |
|---|
| | 61 | if(dlg.open() == "OK"){ |
|---|
| | 62 | if(dlg.createNew && dlg.project) |
|---|
| | 63 | { |
|---|
| | 64 | // create the new project |
|---|
| | 65 | sGUI.packageExp.addProject(dlg.project); |
|---|
| | 66 | toolMan.updateToolBar(); |
|---|
| | 67 | } |
|---|
| | 68 | } |
|---|
| | 69 | } |
|---|
| | 70 | |
|---|
| | 71 | public void actionOpenProject(Event e) |
|---|
| | 72 | { |
|---|
| | 73 | auto DirectoryDialog dlg = new DirectoryDialog(sShell, SWT.OPEN); |
|---|
| | 74 | dlg.dh_setFilterPath(Globals.recentDir); |
|---|
| | 75 | char[] fullpath = dlg.dh_open(); |
|---|
| | 76 | if(fullpath) { |
|---|
| | 77 | if(!Project.checkDir(fullpath)){ |
|---|
| | 78 | MessageBox_showMessage(Globals.getTranslation("mb.root_as_prjdir")); |
|---|
| | 79 | return; |
|---|
| | 80 | } |
|---|
| | 81 | |
|---|
| | 82 | char[] file = std.path.join(fullpath, Project.EXT); |
|---|
| | 83 | if(!std.file.exists(file)){ |
|---|
| | 84 | if(SWT.YES != MessageBox_showMessage(Globals.getTranslation("mb.open_plain_prj"), |
|---|
| | 85 | Globals.getTranslation("QUESTION"), sShell, SWT.ICON_QUESTION | SWT.YES | SWT.NO)) |
|---|
| | 86 | return; |
|---|
| | 87 | } |
|---|
| | 88 | |
|---|
| | 89 | sGUI.packageExp.loadProject(fullpath); |
|---|
| | 90 | toolMan.updateToolBar(); |
|---|
| | 91 | } |
|---|
| | 92 | } |
|---|
| | 93 | |
|---|
| | 94 | public void actionSave(Event e) |
|---|
| | 95 | { |
|---|
| | 96 | sGUI.editor.save(); |
|---|
| | 97 | toolMan.updateToolBar(); |
|---|
| | 98 | } |
|---|
| | 99 | |
|---|
| | 100 | public void actionSaveAll(Event e) |
|---|
| | 101 | { |
|---|
| | 102 | sGUI.editor.saveAll(); |
|---|
| | 103 | toolMan.updateToolBar(); |
|---|
| | 104 | } |
|---|
| | 105 | |
|---|
| | 106 | public void actionUndo( Event e ) |
|---|
| | 107 | { |
|---|
| | 108 | EditItem ei = sGUI.editor.getSelectedEditItemHSU(); |
|---|
| | 109 | if( ei ) ei.toolbarDirectlyHSU( 0 ); |
|---|
| | 110 | toolMan.updateToolBar(); |
|---|
| | 111 | } |
|---|
| | 112 | |
|---|
| | 113 | public void actionRedo( Event e ) |
|---|
| | 114 | { |
|---|
| | 115 | EditItem ei = sGUI.editor.getSelectedEditItemHSU(); |
|---|
| | 116 | if( ei ) ei.toolbarDirectlyHSU( 1 ); |
|---|
| | 117 | toolMan.updateToolBar(); |
|---|
| | 118 | } |
|---|
| | 119 | |
|---|
| | 120 | public void actionCut( Event e ) |
|---|
| | 121 | { |
|---|
| | 122 | EditItem ei = sGUI.editor.getSelectedEditItemHSU(); |
|---|
| | 123 | if( ei ) ei.toolbarDirectlyHSU( 2 ); |
|---|
| | 124 | toolMan.updateToolBar(); |
|---|
| | 125 | } |
|---|
| | 126 | |
|---|
| | 127 | public void actionCopy( Event e ) |
|---|
| | 128 | { |
|---|
| | 129 | EditItem ei = sGUI.editor.getSelectedEditItemHSU(); |
|---|
| | 130 | if( ei ) ei.toolbarDirectlyHSU( 3 ); |
|---|
| | 131 | toolMan.updateToolBar(); |
|---|
| | 132 | } |
|---|
| | 133 | |
|---|
| | 134 | public void actionPaste( Event e ) |
|---|
| | 135 | { |
|---|
| | 136 | EditItem ei = sGUI.editor.getSelectedEditItemHSU(); |
|---|
| | 137 | if( ei ) ei.toolbarDirectlyHSU( 4 ); |
|---|
| | 138 | toolMan.updateToolBar(); |
|---|
| | 139 | } |
|---|
| | 140 | |
|---|
| | 141 | public void actionNavigate(Event e) |
|---|
| | 142 | { |
|---|
| | 143 | NavPoint pt; |
|---|
| | 144 | Integer ii = cast(Integer)e.data; |
|---|
| | 145 | if(ii.intValue() == 0){ |
|---|
| | 146 | // back |
|---|
| | 147 | pt = navCache.navBack(); |
|---|
| | 148 | }else{ |
|---|
| | 149 | // forward |
|---|
| | 150 | pt = navCache.navForward(); |
|---|
| | 151 | } |
|---|
| | 152 | } |
|---|
| | 153 | |
|---|
| | 154 | public void actionClearNavCache(Event e) |
|---|
| | 155 | { |
|---|
| | 156 | navCache.clear(); |
|---|
| | 157 | } |
|---|
| | 158 | |
|---|
| | 159 | /** |
|---|
| | 160 | * invoke when use click the external tools menu item |
|---|
| | 161 | */ |
|---|
| | 162 | public void actionExtTool(Event e) { |
|---|
| | 163 | MenuItem mi = cast(MenuItem)e.widget; |
|---|
| | 164 | assert(mi); |
|---|
| | 165 | ToolEntry entry = cast(ToolEntry)mi.getData(); |
|---|
| | 166 | |
|---|
| | 167 | /** |
|---|
| | 168 | * set the most recently operation to the toolItem, |
|---|
| | 169 | */ |
|---|
| | 170 | // save the last tool name |
|---|
| | 171 | ToolEntry.lastTool = entry; |
|---|
| | 172 | toolMan.updateExtToolInfo(); |
|---|
| | 173 | |
|---|
| | 174 | execExtTool(entry); |
|---|
| | 175 | } |
|---|
| | 176 | |
|---|
| | 177 | /** |
|---|
| | 178 | * invoke when use click the external tools in toolbar |
|---|
| | 179 | */ |
|---|
| | 180 | public void actionTbarExtTools(Event event) { |
|---|
| | 181 | /** |
|---|
| | 182 | * A selection event will be fired when a drop down tool |
|---|
| | 183 | * item is selected in the main area and in the drop |
|---|
| | 184 | * down arrow. Examine the event detail to determine |
|---|
| | 185 | * where the widget was selected. |
|---|
| | 186 | */ |
|---|
| | 187 | if (event.detail == SWT.ARROW) { |
|---|
| | 188 | /* |
|---|
| | 189 | * The drop down arrow was selected. |
|---|
| | 190 | */ |
|---|
| | 191 | |
|---|
| | 192 | // Position the menu below and vertically aligned with the the drop down tool button. |
|---|
| | 193 | ToolItem toolItem = cast(ToolItem) event.widget; |
|---|
| | 194 | ToolBar toolBar = toolItem.getParent(); |
|---|
| | 195 | |
|---|
| | 196 | Rectangle toolItemBounds = toolItem.getBounds(); |
|---|
| | 197 | Point point = toolBar.toDisplay(toolItemBounds.x, toolItemBounds.y); |
|---|
| | 198 | Menu menu = menuMan.getExtToolMenu(); |
|---|
| | 199 | menu.setLocation(point.x, point.y + toolItemBounds.height); |
|---|
| | 200 | menu.setVisible(true); |
|---|
| | 201 | } else { |
|---|
| | 202 | /* |
|---|
| | 203 | * Main area of drop down tool item selected. |
|---|
| | 204 | * An application would invoke the code to perform the action for the tool item. |
|---|
| | 205 | */ |
|---|
| | 206 | if(ToolEntry.lastTool) |
|---|
| | 207 | execExtTool(ToolEntry.lastTool); |
|---|
| | 208 | } |
|---|
| | 209 | } |
|---|
| | 210 | |
|---|
| | 211 | |
|---|
| | 212 | // COMPILER |
|---|
| | 213 | private bool checkCmdExist() |
|---|
| | 214 | { |
|---|
| | 215 | sGUI.outputPanel.setForeColor( 255, 0, 0 ); |
|---|
| | 216 | |
|---|
| | 217 | &nbs |
|---|