コード例 #1
0
 /// <summary>
 /// パレットツールを実行します
 /// </summary>
 /// <param name="id">実行するパレットツールのID</param>
 /// <param name="track">編集対象のトラック番号</param>
 /// <param name="vsq_event_intrenal_ids">編集対象のInternalIDのリスト</param>
 /// <param name="button">パレットツールが押し下げられた時のマウスボタンの種類</param>
 /// <returns>パレットツールによって編集が加えられた場合true。そうでなければfalse(パレットツールがエラーを起こした場合も含む)。</returns>
 public static boolean invokePaletteTool( String id, int track, int[] vsq_event_intrenal_ids, MouseButtons button ) {
     if ( loadedTools.containsKey( id ) ) {
         VsqFileEx vsq = AppManager.getVsqFile();
         VsqTrack item = (VsqTrack)vsq.Track.get( track ).clone();
         Object objPal = loadedTools.get( id );
         if ( objPal == null ) {
             return false;
         }
         if ( !(objPal is IPaletteTool) ) {
             return false;
         }
         IPaletteTool pal = (IPaletteTool)objPal;
         boolean edited = false;
         try {
             edited = pal.edit( item, vsq_event_intrenal_ids, button );
         } catch ( Exception ex ) {
             AppManager.showMessageBox(
                 PortUtil.formatMessage( _( "Palette tool '{0}' reported an error.\nPlease copy the exception text and report it to developper." ), id ),
                 "Error",
                 cadencii.windows.forms.Utility.MSGBOX_DEFAULT_OPTION,
                 cadencii.windows.forms.Utility.MSGBOX_ERROR_MESSAGE );
             serr.println( typeof( PaletteToolServer ) + ".invokePaletteTool; ex=" + ex );
             edited = false;
         }
         if ( edited ) {
             CadenciiCommand run = VsqFileEx.generateCommandTrackReplace( track, item, vsq.AttachedCurves.get( track - 1 ) );
             AppManager.editHistory.register( vsq.executeCommand( run ) );
         }
         return edited;
     } else {
         return false;
     }
 }
コード例 #2
0
        /// <summary>
        /// スクリプトを実行します。
        /// </summary>
        /// <param name="evsd"></param>
        public static boolean invokeScript(String id, VsqFileEx vsq)
        {
            ScriptInvoker script_invoker = null;

            if (scripts.containsKey(id))
            {
                script_invoker = scripts.get(id);
            }
            else
            {
                return(false);
            }
            if (script_invoker != null && script_invoker.scriptDelegate != null)
            {
                try {
                    VsqFileEx          work = (VsqFileEx)vsq.clone();
                    ScriptReturnStatus ret  = ScriptReturnStatus.ERROR;
                    if (script_invoker.scriptDelegate is EditVsqScriptDelegate)
                    {
                        boolean b_ret = ((EditVsqScriptDelegate)script_invoker.scriptDelegate).Invoke(work);
                        if (b_ret)
                        {
                            ret = ScriptReturnStatus.EDITED;
                        }
                        else
                        {
                            ret = ScriptReturnStatus.ERROR;
                        }
                    }
                    else if (script_invoker.scriptDelegate is EditVsqScriptDelegateEx)
                    {
                        boolean b_ret = ((EditVsqScriptDelegateEx)script_invoker.scriptDelegate).Invoke(work);
                        if (b_ret)
                        {
                            ret = ScriptReturnStatus.EDITED;
                        }
                        else
                        {
                            ret = ScriptReturnStatus.ERROR;
                        }
                    }
                    else if (script_invoker.scriptDelegate is EditVsqScriptDelegateWithStatus)
                    {
                        ret = ((EditVsqScriptDelegateWithStatus)script_invoker.scriptDelegate).Invoke(work);
                    }
                    else if (script_invoker.scriptDelegate is EditVsqScriptDelegateExWithStatus)
                    {
                        ret = ((EditVsqScriptDelegateExWithStatus)script_invoker.scriptDelegate).Invoke(work);
                    }
                    else
                    {
                        ret = ScriptReturnStatus.ERROR;
                    }
                    if (ret == ScriptReturnStatus.ERROR)
                    {
                        AppManager.showMessageBox(_("Script aborted"), "Cadencii", cadencii.windows.forms.Utility.MSGBOX_DEFAULT_OPTION, cadencii.windows.forms.Utility.MSGBOX_INFORMATION_MESSAGE);
                    }
                    else if (ret == ScriptReturnStatus.EDITED)
                    {
                        CadenciiCommand run = VsqFileEx.generateCommandReplace(work);
                        AppManager.editHistory.register(vsq.executeCommand(run));
                    }
                    String           config_file          = configFileNameFromScriptFileName(script_invoker.ScriptFile);
                    FileOutputStream fs                   = null;
                    boolean          delete_xml_when_exit = false; // xmlを消すときtrue
                    try {
                        fs = new FileOutputStream(config_file);
                        script_invoker.Serializer.serialize(fs, null);
                    } catch (Exception ex) {
                        serr.println("AppManager#invokeScript; ex=" + ex);
                        delete_xml_when_exit = true;
                    } finally {
                        if (fs != null)
                        {
                            try {
                                fs.close();
                                if (delete_xml_when_exit)
                                {
                                    PortUtil.deleteFile(config_file);
                                }
                            } catch (Exception ex2) {
                                serr.println("AppManager#invokeScript; ex2=" + ex2);
                            }
                        }
                    }
                    return(ret == ScriptReturnStatus.EDITED);
                } catch (Exception ex) {
                    AppManager.showMessageBox(_("Script runtime error:") + " " + ex, _("Error"), cadencii.windows.forms.Utility.MSGBOX_DEFAULT_OPTION, cadencii.windows.forms.Utility.MSGBOX_INFORMATION_MESSAGE);
                    serr.println("AppManager#invokeScript; ex=" + ex);
                }
            }
            else
            {
                AppManager.showMessageBox(_("Script compilation failed."), _("Error"), cadencii.windows.forms.Utility.MSGBOX_DEFAULT_OPTION, cadencii.windows.forms.Utility.MSGBOX_WARNING_MESSAGE);
            }
            return(false);
        }
コード例 #3
0
ファイル: ScriptServer.cs プロジェクト: cadencii/cadencii
 /// <summary>
 /// スクリプトを実行します。
 /// </summary>
 /// <param name="evsd"></param>
 public static boolean invokeScript( String id, VsqFileEx vsq ) {
     ScriptInvoker script_invoker = null;
     if ( scripts.containsKey( id ) ) {
         script_invoker = scripts.get( id );
     } else {
         return false;
     }
     if ( script_invoker != null && script_invoker.scriptDelegate != null ) {
         try {
             VsqFileEx work = (VsqFileEx)vsq.clone();
             ScriptReturnStatus ret = ScriptReturnStatus.ERROR;
             if ( script_invoker.scriptDelegate is EditVsqScriptDelegate ) {
                 boolean b_ret = ((EditVsqScriptDelegate)script_invoker.scriptDelegate).Invoke( work );
                 if ( b_ret ) {
                     ret = ScriptReturnStatus.EDITED;
                 } else {
                     ret = ScriptReturnStatus.ERROR;
                 }
             } else if ( script_invoker.scriptDelegate is EditVsqScriptDelegateEx ) {
                 boolean b_ret = ((EditVsqScriptDelegateEx)script_invoker.scriptDelegate).Invoke( work );
                 if ( b_ret ) {
                     ret = ScriptReturnStatus.EDITED;
                 } else {
                     ret = ScriptReturnStatus.ERROR;
                 }
             } else if ( script_invoker.scriptDelegate is EditVsqScriptDelegateWithStatus ) {
                 ret = ((EditVsqScriptDelegateWithStatus)script_invoker.scriptDelegate).Invoke( work );
             } else if ( script_invoker.scriptDelegate is EditVsqScriptDelegateExWithStatus ) {
                 ret = ((EditVsqScriptDelegateExWithStatus)script_invoker.scriptDelegate).Invoke( work );
             } else {
                 ret = ScriptReturnStatus.ERROR;
             }
             if ( ret == ScriptReturnStatus.ERROR ) {
                 AppManager.showMessageBox( _( "Script aborted" ), "Cadencii", cadencii.windows.forms.Utility.MSGBOX_DEFAULT_OPTION, cadencii.windows.forms.Utility.MSGBOX_INFORMATION_MESSAGE );
             } else if ( ret == ScriptReturnStatus.EDITED ) {
                 CadenciiCommand run = VsqFileEx.generateCommandReplace( work );
                 AppManager.editHistory.register( vsq.executeCommand( run ) );
             }
             String config_file = configFileNameFromScriptFileName( script_invoker.ScriptFile );
             FileOutputStream fs = null;
             boolean delete_xml_when_exit = false; // xmlを消すときtrue
             try {
                 fs = new FileOutputStream( config_file );
                 script_invoker.Serializer.serialize( fs, null );
             } catch ( Exception ex ) {
                 serr.println( "AppManager#invokeScript; ex=" + ex );
                 delete_xml_when_exit = true;
             } finally {
                 if ( fs != null ) {
                     try {
                         fs.close();
                         if ( delete_xml_when_exit ) {
                             PortUtil.deleteFile( config_file );
                         }
                     } catch ( Exception ex2 ) {
                         serr.println( "AppManager#invokeScript; ex2=" + ex2 );
                     }
                 }
             }
             return (ret == ScriptReturnStatus.EDITED);
         } catch ( Exception ex ) {
             AppManager.showMessageBox( _( "Script runtime error:" ) + " " + ex, _( "Error" ), cadencii.windows.forms.Utility.MSGBOX_DEFAULT_OPTION, cadencii.windows.forms.Utility.MSGBOX_INFORMATION_MESSAGE );
             serr.println( "AppManager#invokeScript; ex=" + ex );
         }
     } else {
         AppManager.showMessageBox( _( "Script compilation failed." ), _( "Error" ), cadencii.windows.forms.Utility.MSGBOX_DEFAULT_OPTION, cadencii.windows.forms.Utility.MSGBOX_WARNING_MESSAGE );
     }
     return false;
 }