Esempio n. 1
0
        public MainViewModel(MyAppStateService appStateService)
        {
            this.appStateService = appStateService;

            // global error handling
            Application.Current.DispatcherUnhandledException += Application_DispatcherUnhandledException;

            // set up view
            CodeDocumentXshd.Text   = @"";
            CodeDocumentSample.Text = @"";
            CodeDocumentXshd.UndoStack.ClearAll();
            CodeDocumentSample.UndoStack.ClearAll();

            CodeDocumentXshd.Changed += CodeDocument_Changed;

            // assign commands
            CmdWindow_Loaded               = new RelayCommand(_CmdWindow_Loaded);
            CmdWindow_Closing              = new RelayCommand(_CmdWindow_Closing);
            CmdUser_OnDragDropXshd         = new RelayCommand <string>(_CmdUser_OnDragDropXshd);
            CmdUser_OnDragDropSample       = new RelayCommand <string>(_CmdUser_OnDragDropSample);
            CmdUser_SaveFile               = new RelayCommand(_CmdUser_SaveFile);
            CmdUser_TriggerBuild           = new RelayCommand(_CmdUser_TriggerBuild);
            CmdUser_RevealInExplorer       = new RelayCommand(_CmdUser_RevealInExplorer);
            CmdAvalon_CaretPositionChanged = new RelayCommand <Caret>(_CmdAvalon_CaretPositionChanged);
        }
        public MainViewModel(
            FileDialogsServiceWin32 fileDialogsService,
            MyAppStateService appStateService
            )
        {
            this.appStateService    = appStateService;
            this.fileDialogsService = fileDialogsService;

            // .... set up view
            SyntaxHighlighting     = MyPrologUtils.LoadSyntaxHighlightingFromResource(Constants.Resources.AvalonSyntaxProlog2);
            CodeDocument.Text      = Constants.Samples.SampleProlog;
            CodeDocumentQuery.Text = Constants.Samples.SampleQuery;

            // .... assign commands
            CmdWindow_Loaded               = new RelayCommand(_CmdWindow_Loaded);
            CmdWindow_Closing              = new RelayCommand(_CmdWindow_Closing);
            CmdWindow_Activated            = new RelayCommand(_CmdWindow_Activated);
            CmdUser_TriggerBuild           = new RelayCommand(_CmdUser_TriggerBuild);
            CmdAvalon_CaretPositionChanged = new RelayCommand <Caret>(_CmdAvalon_CaretPositionChanged);
            CmdConsole_CopyAll             = new RelayCommand(_CmdConsole_CopyAll);
            CmdConsole_ClearAll            = new RelayCommand(_CmdConsole_ClearAll);
            CmdUser_OnDragDropProlog       = new RelayCommand <string>(_CmdUser_OnDragDropProlog);
            CmdUser_Open             = new RelayCommand(_CmdUser_Open);
            CmdUser_RevealInExplorer = new RelayCommand(_CmdUser_RevealInExplorer);
            CmdUser_Save             = new RelayCommand(_CmdUser_Save);
            CmdUser_SaveAs           = new RelayCommand(_CmdUser_SaveAs);

            this.PropertyChanged += THIS_PropertyChanged;
            CodeDocument.UndoStack.PropertyChanged += CodeDocument_UndoStack_PropertyChanged;

            // .... restore from previous state
            var appState = appStateService.LoadOrCreateNew();

            if (appState.LastQueryText != null)
            {
                CodeDocumentQuery.Text = appState.LastQueryText;
            }
            IsResultsPanelTextWrappingEnabled = appState.IsResultsPanelTextWrappingEnabled;
            Config_ReplaceTabsWithSpaces      = appState.MainPanelReplaceTabsWithSpaces;

            // .... load file in question
            var argFilename = (string)Application.Current.Resources[Constants.Resources.Arg1Key];

            if (argFilename != null && File.Exists(argFilename))
            {
                LoadFile(argFilename);
            }
            else if (appState.LastFilename != null && File.Exists(appState.LastFilename))
            {
                LoadFile(appState.LastFilename);
            }

            CodeDocument.UndoStack.ClearAll();
            CodeDocumentQuery.UndoStack.ClearAll();
        }