Example #1
0
    private void DestroyEnvironment()
    {
        DeviceMonitor.Stop();

        notificationService.Stop();

        DataModel.Save();

        ApplicationSettings.Save();

#if !LINUX
        trayIcon.Visible = false;
#endif

        if (HidSharp.PlatformDetector.RunningPlatform() == HidSharp.PlatformDetector.Platform.Windows)
        {
            instanceExistsEvent.Cancel();
        }

        if (ApplicationSettings.ExitTurnOffAllBlinkSticks)
        {
            this.DataModel.Devices.ForEach(delegate(BlinkStickDeviceSettings device) {
                if (device.Led != null && device.Led.Connected)
                {
                    device.TurnOff();
                    Thread.Sleep(50);
                    device.Led.CloseDevice();
                }
            });
        }
    }
        protected void OnTreeviewEventsCursorChanged(object sender, EventArgs e)
        {
            if (ignoreNexClick)
            {
                ignoreNexClick = false;
                return;
            }

            TreeModel model;
            TreeIter  iter;

            TreeSelection selection = (sender as TreeView).Selection;

            if (selection.GetSelected(out model, out iter))
            {
                SelectedNotification = (CustomNotification)model.GetValue(iter, 0);

                TreePath       path;
                TreeViewColumn column;
                (sender as TreeView).GetCursor(out path, out column);

                if (column == (sender as TreeView).Columns[DeleteColumnIndex]) //Delete clicked
                {
                    if (MainWindow.ConfirmDelete())
                    {
                        ignoreNexClick = true;
                        DataModel.Notifications.Remove(SelectedNotification);
                        NotificationListStore.Remove(ref iter);
                        DataModel.Save();
                    }
                }
                else if (column == (sender as TreeView).Columns[DeleteColumnIndex - 1]) //Copy clicked
                {
                    if (SelectedNotification.IsUnique())
                    {
                        MessageBox.Show(ParentForm, String.Format("Only one {0} notification can be used", SelectedNotification.GetTypeName()), MessageType.Error);
                        return;
                    }

                    CustomNotification notification = SelectedNotification.Copy();
                    notification.Name = DataModel.GetNotificationName(SelectedNotification.Name, 2);

                    if (EditNotification(notification, "Copy Notification"))
                    {
                        NotificationListStore.AppendValues(notification, "icon-dark-pencil-square-o", "icon-dark-clone", "icon-dark-trash", NotificationRegistry.FindIcon(notification.GetType()));
                        DataModel.Notifications.Add(notification);
                        ignoreNexClick = true;
                        SelectNotificationInTree(notification);
                    }
                }
                else if (column == (sender as TreeView).Columns[DeleteColumnIndex - 2]) //Edit clicked
                {
                    EditNotification();
                }
                else if (column == (sender as TreeView).Columns[0]) //Enabled-Disabled clicked
                {
                    SelectedNotification.Enabled = !SelectedNotification.Enabled;
                    DataModel.Save();
                    DataModel.Notifications.NotifyUpdate(SelectedNotification);
                }
            }
        }