Esempio n. 1
0
        public InfoItem GetActiveItem()
        {
            IntPtr hActiveWin  = GetActiveWindowHandle();
            String activeTitle = GetActiveWindowText(hActiveWin);

            // Get the active item if it is a Web page
            Process[] procs = Process.GetProcesses();

            foreach (Process proc in procs)
            {
                if ((proc.MainWindowHandle) == hActiveWin)
                {
                    const int     nChars = 256;
                    StringBuilder Buff   = new StringBuilder(nChars);

                    GetWindowText((int)hActiveWin, Buff, nChars);

                    activeItem = GetActiveItemFromHandle(proc.ProcessName, hActiveWin);
                    if (activeItem != null)
                    {
                        return(activeItem);
                    }
                }
            }

            // Get the active item if it is a File with type of pdf, word, excel, ppt
            activeItem = GetActiveItemFromROT(hActiveWin);
            if (activeItem != null)
            {
                return(activeItem);
            }

            return(null);
        }
Esempio n. 2
0
        private InfoItem GetActiveItemFromROT(IntPtr handle)
        {
            activeItem = new InfoItem();
            String activeTitle = GetActiveWindowText(handle);
            String title;

            IntPtr numFetched = IntPtr.Zero;
            IRunningObjectTable runningObjectTable;
            IEnumMoniker        monikerEnumerator;

            IMoniker[] monikers = new IMoniker[1];

            GetRunningObjectTable(0, out runningObjectTable);
            runningObjectTable.EnumRunning(out monikerEnumerator);
            monikerEnumerator.Reset();

            while (monikerEnumerator.Next(1, monikers, numFetched) == 0)
            {
                IBindCtx ctx;
                CreateBindCtx(0, out ctx);

                string runningObjectName;
                monikers[0].GetDisplayName(ctx, null, out runningObjectName);

                object runningObjectVal;
                runningObjectTable.GetObject(monikers[0], out runningObjectVal);

                try
                {
                    string ext = Path.GetExtension(runningObjectName).ToLower();
                    if (ext == ".pdf" ||
                        ext == ".docx" || ext == ".doc" ||
                        ext == ".xlsx" || ext == ".xls" ||
                        ext == ".pptx" || ext == ".ppt")
                    {
                        title = Path.GetFileNameWithoutExtension(runningObjectName);
                        if (activeTitle.IndexOf(title) != -1)
                        {
                            activeItem.Title = Path.GetFileNameWithoutExtension(runningObjectName);
                            activeItem.Uri   = runningObjectName;
                            activeItem.Type  = InfoItemType.File;

                            return(activeItem);
                        }
                    }
                }
                catch (Exception)
                {
                    continue;
                }
            }

            return(null);
        }
Esempio n. 3
0
        public List <InfoItem> GetActiveItemList()
        {
            List <InfoItem> itemList = new List <InfoItem>();

            Process[] procs = Process.GetProcesses();
            IntPtr    hWnd;

            foreach (Process proc in procs)
            {
                if ((hWnd = proc.MainWindowHandle) != IntPtr.Zero)
                {
                    InfoItem item = GetActiveItemFromHandle(proc.ProcessName, hWnd);
                    if (item != null)
                    {
                        itemList.Add(item);
                    }
                }
            }

            itemList.AddRange(GetActiveItemFromROT().ToList());

            return(itemList);
        }
Esempio n. 4
0
        private InfoItem GetActiveItemFromROT(IntPtr handle)
        {
            activeItem = new InfoItem();
            String activeTitle = GetActiveWindowText(handle);
            String title;

            IntPtr numFetched = IntPtr.Zero;
            IRunningObjectTable runningObjectTable;
            IEnumMoniker monikerEnumerator;
            IMoniker[] monikers = new IMoniker[1];

            GetRunningObjectTable(0, out runningObjectTable);
            runningObjectTable.EnumRunning(out monikerEnumerator);
            monikerEnumerator.Reset();

            while (monikerEnumerator.Next(1, monikers, numFetched) == 0)
            {
                IBindCtx ctx;
                CreateBindCtx(0, out ctx);

                string runningObjectName;
                monikers[0].GetDisplayName(ctx, null, out runningObjectName);

                object runningObjectVal;
                runningObjectTable.GetObject(monikers[0], out runningObjectVal);

                try
                {
                    string ext = Path.GetExtension(runningObjectName).ToLower();
                    if (ext == ".pdf" ||
                        ext == ".docx" || ext == ".doc" ||
                        ext == ".xlsx" || ext == ".xls" ||
                        ext == ".pptx" || ext == ".ppt")
                    {
                        title = Path.GetFileNameWithoutExtension(runningObjectName);
                        if (activeTitle.IndexOf(title) != -1)
                        {
                            activeItem.Title = Path.GetFileNameWithoutExtension(runningObjectName);
                            activeItem.Uri = runningObjectName;
                            activeItem.Type = InfoItemType.File;

                            return activeItem;
                        }

                    }
                }
                catch (Exception)
                {
                    continue;
                }
            }

            return null;
        }
Esempio n. 5
0
        public InfoItem GetActiveItem()
        {
            IntPtr hActiveWin = GetActiveWindowHandle();
            String activeTitle = GetActiveWindowText(hActiveWin);

            // Get the active item if it is a Web page
            Process[] procs = Process.GetProcesses();

            foreach (Process proc in procs)
            {
                if ((proc.MainWindowHandle) == hActiveWin)
                {
                    const int nChars = 256;
                    StringBuilder Buff = new StringBuilder(nChars);

                    GetWindowText((int)hActiveWin, Buff, nChars);

                    activeItem = GetActiveItemFromHandle(proc.ProcessName, hActiveWin);
                    if (activeItem != null)
                        return activeItem;
                }
            }

            // Get the active item if it is a File with type of pdf, word, excel, ppt
            activeItem = GetActiveItemFromROT(hActiveWin);
            if (activeItem != null)
                return activeItem;

            return null;
        }
        private void button_OK_Click(object sender, RoutedEventArgs e)
        {
            // return;
            // Click to save the note
            //none of URI or note is available, there is nothing to save

            if (newNoteText.Length == 0 && newInfoItem == null)
                return;

            bNoteModified = false;
            bSkipModifyConfirmation = false;

            //use the title as note, if only URI is available
            if (newInfoItem!=null && newNoteText.Length == 0 )
                newNoteText = newInfoItem.Title;

            ComboBoxItem cbi_sel = (ComboBoxItem) comboBox_SaveLoc.SelectedItem;

            string xmlFileFullPath = cbi_sel.Tag.ToString();

            Element parentElement = new Element
            {
                ParentElement = null,
                HeadImageSource = String.Empty,
                TailImageSource = String.Empty,
                NoteText = String.Empty,
                IsExpanded = true,
                Path = xmlFileFullPath,
                Type = ElementType.Heading,
            };

            Element newElement = new Element
            {
                ParentElement = parentElement,
                HeadImageSource = String.Empty,
                TailImageSource = String.Empty,
                NoteText = newNoteText,
                IsExpanded = false,
                Path = xmlFileFullPath,
                Type = ElementType.Note,
                FontColor = ElementColor.Blue.ToString(),
                Status = ElementStatus.New,
            };

            newElement.ParentElement = parentElement;
            newElement.Position = 0;

            if ((newInfoItem != null) && (bool)checkBox_URI.IsChecked)
            {
                ElementAssociationType newType;
                switch (newInfoItem.Type)
                {
                    case InfoItemType.Email:
                        newType = ElementAssociationType.Email;
                        break;
                    case InfoItemType.File:
                        newType = ElementAssociationType.FileShortcut;
                        break;
                    case InfoItemType.Web:
                        newType = ElementAssociationType.Web;
                        break;
                    default:
                        newType = ElementAssociationType.None;
                        break;
                }
                newElement.AssociationType = newType;
            }

            try
            {
                newElement.ParentElement.Elements.Insert(0, newElement);

                DatabaseControl temp_dbControl = new DatabaseControl(newElement.ParentElement.Path);
                temp_dbControl.OpenConnection();
                temp_dbControl.InsertElementIntoXML(newElement);
                temp_dbControl.CloseConnection();

                ElementControl elementControl = new ElementControl(newElement.ParentElement.Path);
                elementControl.CurrentElement = newElement;

                //if URI is available and selected, association will be added together with the note
                if ((newInfoItem!= null) && (bool)checkBox_URI.IsChecked)
                {
                    elementControl.AddAssociation(newElement, newInfoItem.Uri, newElement.AssociationType, newNoteText);
                }

                string eventInfo = LogEventInfo.NoteText + LogControl.COMMA + newElement.NoteText;

                if ((bool)checkBox_URI.IsChecked)
                    eventInfo += LogControl.DELIMITER + LogEventInfo.LinkStatus + LogControl.COMMA + "check";
                else
                    eventInfo += LogControl.DELIMITER + LogEventInfo.LinkStatus + LogControl.COMMA + "unCheck";

                if(newInfoItem!=null && newInfoItem.Uri!=null)
                    eventInfo += LogControl.DELIMITER + LogEventInfo.LinkedFile + LogControl.COMMA + newInfoItem.Uri;

                eventInfo += LogControl.DELIMITER + LogEventInfo.PutUnder + LogControl.COMMA + newElement.Path;

                LogControl.Write(
                elementControl.CurrentElement,
                LogEventAccess.QuickCapture,
                LogEventType.CreateNewNote,
                LogEventStatus.NULL,
                eventInfo);

                newInfoItem = null;

            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("QuickCapture_button_OK_Click\n" + ex.Message);

                LogControl.Write(
                   newElement,
                   LogEventAccess.QuickCapture,
                   LogEventType.CreateNewNote,
                   LogEventStatus.Error,
                   LogEventInfo.ErrorMessage + LogControl.COMMA + ex.Message);
            }

            ReInitilize();

            this.Visibility = Visibility.Hidden;
            this.ShowInTaskbar = true;
        }
        public void On_Activate()
        {
            ActiveWindow aw = new ActiveWindow();
            TextSelHandler textsel = new TextSelHandler(this);

            IntPtr hWnd = IntPtr.Zero;
            InfoItem activeItem = null;
            System.Windows.Clipboard.Clear();

            try
            {
                //support for synchronizing droplist with filesystem dynamically

                hWnd = aw.GetActiveWindowHandle();

                textsel.SendCtrlC(hWnd);

                //wait for the copy to be completed
                Thread.Sleep(100);

                activeItem = aw.GetActiveItem();

                newNoteText = System.Windows.Clipboard.GetText().Replace("\r\n", " ").Replace("\t", " ").Trim();
                if (newNoteText.Length > StartProcess.MAX_EXTRACTTEXT_LENGTH)
                    newNoteText = newNoteText.Substring(0, StartProcess.MAX_EXTRACTTEXT_LENGTH) + "...";

                if ((activeItem != null) && (activeItem.Uri!=null) && (activeItem.Uri.Length!=0))
                {
                    newInfoItem = activeItem;

                    if (newNoteText.Length != 0)
                        newNoteText = "\"" + newNoteText + "\" ";
                    else if(newInfoItem.Title!=null)
                        newNoteText = "\"" + newInfoItem.Title + "\" ";

                    string title;
                    if (newInfoItem.Title == null || newInfoItem.Title.Length == 0)
                    {
                        title = newNoteText.Replace("/", "").Replace("\\", "").Replace("*", "").Replace("?", "").Replace("\"", "").Replace("<", "").Replace(">", "").Replace("|", "").Replace(":", "");
                        if (title.Length > StartProcess.MAX_EXTRACTNAME_LENGTH)
                            title = title.Substring(0, StartProcess.MAX_EXTRACTNAME_LENGTH);
                    }
                    else
                        title = newInfoItem.Title;

                    checkBox_URI.IsEnabled = true;
                    checkBox_URI.IsChecked = true;

                    if (title.Length > ACTIVEITEM_TITLE_LENGTH)
                        checkBox_URI.Content = "Include link to: " + "\"" + title.Substring(0, ACTIVEITEM_TITLE_LENGTH) + "..." + "\"";
                    else
                        checkBox_URI.Content = "Include link to: " + "\"" + title + "\"";
                }
                textBox_Note.Text = newNoteText;
            }
            catch (Exception)
            {
                ReInitilize();
            }

            updateComboBox_SaveLoc();
            int selectedIndex = 0;
            int i;
            for (i = 0; i < comboBox_SaveLoc.Items.Count; i++)
            {
                ComboBoxItem cbi_Item = (ComboBoxItem)comboBox_SaveLoc.Items[i];
                if (cbi_Item.Tag.ToString() == selectedItem.Tag.ToString() && cbi_Item.Content.ToString() == selectedItem.Content.ToString())
                    selectedIndex = i;
            }
            comboBox_SaveLoc.SelectedIndex = selectedIndex;

            this.Visibility = Visibility.Visible;
            this.Activate();
            textBox_Note.Focus();
            textBox_Note.Select(newNoteText.Length, 0);
            bNoteModified = false;
            this.Topmost = true;
            System.Windows.Clipboard.Clear();

            aw = null;
            textsel = null;
            hWnd = IntPtr.Zero;
            activeItem = null;
            GC.Collect();
        }