Example #1
0
 public void AddData(GaoVM vm)
 {
     vm.CommandAction = On_Command_Execute;
     _gaoList.Add(vm);
     //AddToTable(vm);
     SaveData();
 }
Example #2
0
        public void DeleteData(GaoVM vm)
        {
            int idx = _gaoList.IndexOf(vm);

            _gaoList.RemoveAt(idx);
            DelFromTable(vm);
            SaveData();
        }
Example #3
0
        public void MoveTo(int oldIdx, int newIdx)
        {
            GaoVM vm = _gaoList.ElementAt(oldIdx);

            _gaoList.RemoveAt(oldIdx);
            _gaoList.Insert(newIdx, vm);
            SaveData();
        }
Example #4
0
 private bool On_Command_Execute(String cmdKey, GaoVM vm)
 {
     if (this.CommandAction != null)
     {
         this.CommandAction(cmdKey, vm);
         return(true);
     }
     return(false);
 }
Example #5
0
        private void On_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            GaoVM vm = this.DataContext as GaoVM;

            if (vm != null)
            {
                vm.CmdSendText.Execute(null);
            }
        }
Example #6
0
 private bool On_GaoVM_CommandAction_Execute(String cmdKey, GaoVM vm)
 {
     if (cmdKey == GaoVM.CmdKey_SendText)
     {
         SendText(vm);
         this.Hide();
         return(true);
     }
     return(false);
 }
Example #7
0
        private void On_BTN_Load_Click(object sender, RoutedEventArgs e)
        {
            GaoVM vm = LB_Gaos.SelectedItem as GaoVM;

            if (vm != null)
            {
                TXT_Name.Text = vm.Name;
                TXT_Text.Text = vm.Text;
            }
        }
Example #8
0
        private void AddToTable(GaoVM vm)
        {
            DataRow row = _gaoTable.NewRow();

            foreach (PropertyInfo prop in GetDataTablePropList(vm))
            {
                row[prop.Name] = prop.GetValue(vm);
            }
            _gaoTable.Rows.Add(row);
        }
Example #9
0
        private void On_BTN_Add_Click(object sender, RoutedEventArgs e)
        {
            GaoVM vm = new GaoVM();

            vm.Name = TXT_Name.Text;
            vm.Text = TXT_Text.Text;
            GaoData.Data.AddData(vm);
            _colle.Add(vm);
            TXT_Text.Clear();
            LB_Gaos.ScrollIntoView(vm);
        }
Example #10
0
        private void On_BTN_Replace_Click(object sender, RoutedEventArgs e)
        {
            GaoVM vm = LB_Gaos.SelectedItem as GaoVM;

            if (vm != null)
            {
                vm.Name = TXT_Name.Text;
                vm.Text = TXT_Text.Text;
                GaoData.Data.SaveData();
            }
        }
Example #11
0
        /// <summary>
        /// Initial the Gao table and create the columns.
        /// </summary>
        private void CreateTableColumn()
        {
            _gaoTable.TableName = TABLE_NAME;

            GaoVM vm = new GaoVM();

            foreach (PropertyInfo info in GetDataTablePropList(vm))
            {
                _gaoTable.Columns.Add(info.Name, info.PropertyType);
            }
        }
Example #12
0
        private void On_BTN_Del_Click(object sender, RoutedEventArgs e)
        {
            GaoVM vm = LB_Gaos.SelectedItem as GaoVM;

            if (vm != null)
            {
                int idx = LB_Gaos.SelectedIndex + 1;
                _colle.Remove(vm);
                GaoData.Data.DeleteData(vm);
                LB_Gaos.SelectedIndex = idx;
            }
        }
Example #13
0
 private void On_BTN_Insert_Click(object sender, RoutedEventArgs e)
 {
     if (LB_Gaos.SelectedIndex != -1)
     {
         int   idx = LB_Gaos.SelectedIndex + 1;
         GaoVM vm  = new GaoVM();
         vm.Name = TXT_Name.Text;
         vm.Text = TXT_Text.Text;
         GaoData.Data.Insert(idx, vm);
         _colle.Insert(idx, vm);
         TXT_Text.Clear();
         LB_Gaos.ScrollIntoView(vm);
     }
 }
Example #14
0
        private void DelFromTable(GaoVM vm)
        {
            List <DataRow> rows = new List <DataRow>();

            foreach (DataRow row in _gaoTable.Rows)
            {
                if ((String)row["Text"] == vm.Text)
                {
                    rows.Add(row);
                }
            }
            foreach (DataRow row in rows)
            {
                _gaoTable.Rows.Remove(row);
            }
        }
Example #15
0
        public void LoadData()
        {
            String dataPath = AppDomain.CurrentDomain.BaseDirectory + "\\" + TABLE_NAME;

            if (File.Exists(dataPath))
            {
                _gaoTable.ReadXml(dataPath);
                foreach (DataRow row in _gaoTable.Rows)
                {
                    GaoVM vm = new GaoVM();
                    vm.CommandAction = On_Command_Execute;
                    foreach (PropertyInfo prop in GetDataTablePropList(vm))
                    {
                        prop.SetValue(vm, row[prop.Name]);
                    }
                    _gaoList.Add(vm);
                }
            }
        }
Example #16
0
        /// <summary>
        /// Get the Gao view model properties whitch has "DataTableProp" description attribute.
        /// </summary>
        private List <PropertyInfo> GetDataTablePropList(GaoVM vm)
        {
            List <PropertyInfo> propList = new List <PropertyInfo>();

            foreach (PropertyInfo prop in vm.GetType().GetProperties())
            {
                foreach (CustomAttributeData attr in prop.CustomAttributes)
                {
                    CustomAttributeTypedArgument arg = attr.ConstructorArguments.FirstOrDefault(x => (String)x.Value == GaoVM.ATTR_DESC_DATATABLEPROP);
                    if (arg != null)
                    {
                        propList.Add(prop);
                        break;
                    }
                }
            }

            return(propList);
        }
Example #17
0
        private void SendText(GaoVM vm)
        {
            //Save current clipboard data.
            Dictionary <String, Object> dict = new Dictionary <String, Object>();
            var dataObject = System.Windows.Forms.Clipboard.GetDataObject();

            foreach (var format in dataObject.GetFormats())
            {
                dict.Add(format, dataObject.GetData(format));
            }

            bool isAppActivated = Convert.ToBoolean(App.Current.Properties[AppEnums.APP_PROP_KEY_ISACTIVATED]);

            if (isAppActivated)
            {
                this.Hide();
            }

            //Change the clipboard data to Gao text.
            String goaText = "";
            int    count   = 0;

            do
            {
                try
                {
                    SkipClipboardUpdate(100);
                    System.Windows.Forms.Clipboard.SetText(vm.Text);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                }
                goaText = System.Windows.Forms.Clipboard.GetText();
                SpinWait.SpinUntil(() => false, 10);
            } while (goaText != vm.Text && count < 100);

            //Send Gao text.
            SendKeys.SendWait("^{v}");
            SpinWait.SpinUntil(() => false, 100);

            //Restore clipboard data.
            System.Windows.Forms.DataObject obj = new System.Windows.Forms.DataObject();
            foreach (String format in dict.Keys)
            {
                obj.SetData(format, dict[format]);
            }

            //Restore the clipboard data.
            bool bRestore = false;

            for (int i = 0; i < 100 && !bRestore; i++)
            {
                try
                {
                    SkipClipboardUpdate(100);
                    System.Windows.Forms.Clipboard.SetDataObject(obj);
                    bRestore = true;
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                    bRestore = false;
                }
            }
        }
Example #18
0
 private void On_Window_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
 {
     if (e.Key == Key.Escape)
     {
         Close();
     }
     else if (e.Key == Key.Enter)
     {
         if (_gaoPanel)
         {
             if (LB_Gaos.SelectedItem != null)
             {
                 GaoVM vm = LB_Gaos.SelectedItem as GaoVM;
                 vm.CmdSendText.Execute(null);
             }
         }
         else
         {
             if (LB_ClipItems.SelectedItem != null)
             {
                 ClipboardVM vm = LB_ClipItems.SelectedItem as ClipboardVM;
                 vm.CmdSendData.Execute(null);
             }
         }
     }
     else if (e.Key == Key.Up ||
              e.Key == Key.Down)
     {
         if (_gaoPanel)
         {
             int idx = LB_Gaos.SelectedIndex + (e.Key == Key.Up ? -1 : 1);
             if (idx >= 0 &&
                 idx <= LB_Gaos.Items.Count)
             {
                 LB_Gaos.SelectedIndex = idx;
                 LB_Gaos.ScrollIntoView(LB_Gaos.SelectedItem);
             }
         }
         else
         {
             int idx = LB_ClipItems.SelectedIndex + (e.Key == Key.Up ? -1 : 1);
             if (idx >= 0 &&
                 idx <= LB_ClipItems.Items.Count)
             {
                 LB_ClipItems.SelectedIndex = idx;
                 LB_ClipItems.ScrollIntoView(LB_ClipItems.SelectedItem);
             }
         }
     }
     else if (e.Key == Key.Left ||
              e.Key == Key.Right)
     {
         _gaoPanel = (e.Key == Key.Left);
         if (_gaoPanel)
         {
             LB_Gaos.Visibility      = Visibility.Visible;
             LB_ClipItems.Visibility = Visibility.Collapsed;
         }
         else
         {
             LB_Gaos.Visibility      = Visibility.Collapsed;
             LB_ClipItems.Visibility = Visibility.Visible;
         }
     }
     else
     {
         TXTBOX_Search.Focus();
     }
 }
Example #19
0
 public void Insert(int idx, GaoVM vm)
 {
     vm.CommandAction = On_Command_Execute;
     _gaoList.Insert(idx, vm);
     SaveData();
 }