Esempio n. 1
0
 private void SheetActivated(dynamic sheet)
 {
     Logger.Debug("SheetActivated: _lockEvents is {0}", _lockEvents);
     if (sheet != null) // && _lockEvents <= 0)
     {
         _lockEvents += 1;
         SheetViewModel svm = Sheets.FirstOrDefault(s => s.IsSelected);
         if (svm != null)
         {
             svm.IsSelected = false;
         }
         int index = IndexOf(sheet);
         Logger.Info("SheetActivated: Sheet index is {0}", index);
         if (index >= 0 && index < Sheets.Count)
         {
             Sheets[index].IsSelected = true;
         }
         else
         {
             Logger.Warn("SheetActivated: Index {0} is out of bounds!", index);
         }
         _lockEvents -= 1;
     }
     Dispatch(() => OnPropertyChanged("ActiveSheet"));
 }
Esempio n. 2
0
        private void DoRenameSheet()
        {
            Logger.Info("DoRenameSheet");
            StringMessageContent content = new StringMessageContent();

            content.Value     = _lastSelectedSheet.DisplayString;
            content.Validator = (value) =>
            {
                if (SheetViewModel.IsValidName(value))
                {
                    return(String.Empty);
                }
                else
                {
                    // TODO: Find a way that does not require human language here
                    return("1-21, not () /\\ [] *?");
                }
            };
            RenameSheetMessage.Send(
                content,
                (stringMessage) =>
            {
                ConfirmRenameSheet(stringMessage);
            }
                );
        }
Esempio n. 3
0
 protected void BuildSheetList()
 {
     NumSelectedSheets = 0;
     if (Workbook != null)
     {
         _lastSheetsString = SheetsString;
         ObservableCollection <SheetViewModel> sheetViewModels = new ObservableCollection <SheetViewModel>();
         SheetViewModel svm;
         Sheets         excelSheets = Workbook.Sheets;
         for (int i = 1; i <= excelSheets.Count; i++)
         {
             dynamic sheet = excelSheets[i];
             // Need to cast because directly comparing the Visible property with
             // XlSheetVisibility.xlSheetVisible caused exceptions.
             if ((XlSheetVisibility)sheet.Visible == XlSheetVisibility.xlSheetVisible)
             {
                 svm = new SheetViewModel(sheet);
                 svm.PropertyChanged += svm_PropertyChanged;
                 sheetViewModels.Add(svm);
             }
             Bovender.ComHelpers.ReleaseComObject(sheet);
         }
         ;
         Bovender.ComHelpers.ReleaseComObject(excelSheets);
         Sheets = sheetViewModels;
         dynamic activeSheet = Workbook.ActiveSheet;
         if (activeSheet != null)
         {
             Logger.Info("BuildSheetList: Selecting active sheet in list");
             SheetActivated(activeSheet);
             Bovender.ComHelpers.ReleaseComObject(activeSheet);
         }
         else
         {
             Logger.Info("BuildSheetList: Cannot select active sheet in list; ActiveSheet is null.");
         }
     }
     else
     {
         Sheets = null;
     }
 }
Esempio n. 4
0
 private void svm_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == "IsSelected")
     {
         SheetViewModel svm = sender as SheetViewModel;
         if (svm.IsSelected)
         {
             NumSelectedSheets++;
             _lastSelectedSheet = svm;
             if (_lockEvents <= 0)
             {
                 svm.Sheet.Activate();
             }
         }
         else
         {
             NumSelectedSheets--;
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Finds the index of a given sheet (worksheet or chart sheet)
        /// in the Sheets collection.
        /// </summary>
        /// <param name="sheet">Worksheet or chart sheet</param>
        /// <returns>Index of the sheet in the Sheets collection</returns>
        public int IndexOf(dynamic sheet)
        {
            string         name = sheet.Name;
            SheetViewModel svm  = Sheets.FirstOrDefault(s => s.DisplayString == name);

            if (svm == null)
            {
                // If the sheet was not found, rebuild the sheet list.
                // Maybe the sheet was just added, before the watch timer got active.
                BuildSheetList();
                svm = Sheets.FirstOrDefault(s => s.DisplayString == name);
            }
            if (svm != null)
            {
                Logger.Info("IndexOf: Found view model for this sheet");
                return(Sheets.IndexOf(svm));
            }
            else
            {
                Logger.Warn("IndexOf: Requested sheet not found in collection!");
                return(-1);
            }
        }