Ejemplo n.º 1
0
        private void AssociationDropDownMenu_NewVersion(object sender, RoutedEventArgs e)
        {
            MenuItem mi = sender as MenuItem;
            Element element = mi.DataContext as Element;
            try
            {
                if (element != null)
                {
                    int index = 2;
                    string fileFullName = element.AssociationURIFullPath;
                    string fileFolder = System.IO.Path.GetDirectoryName(fileFullName) + System.IO.Path.DirectorySeparatorChar;
                    string fileName = System.IO.Path.GetFileNameWithoutExtension(fileFullName);
                    string fileExt = System.IO.Path.GetExtension(fileFullName);
                    System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\w*\([0-9]+\)");
                    if (regex.IsMatch(fileName))
                    {
                        int lastIndex = fileName.LastIndexOf('(');
                        index = 1 + Int32.Parse(fileName.Substring(lastIndex + 1, fileName.LastIndexOf(')') - lastIndex - 1));
                        fileName = fileName.Substring(0, lastIndex - 1);
                    }
                    while (System.IO.File.Exists(fileFullName))
                    {
                        fileFullName = fileFolder + fileName + " (" + index.ToString() + ")" + fileExt;
                        index++;
                    }

                    LogControl.Write(
                        element,
                        LogEventAccess.AssociationContextMenu,
                        LogEventType.NewVersion,
                        LogEventStatus.Begin,
                        null);

                    FileNameWindow fnw = new FileNameWindow(fileFullName, "Please enter the file name of a new version:");
                    if (fnw.ShowDialog().Value)
                    {
                        string newFileNameFullPath = fileFolder + fnw.FileName + fileExt;
                        System.IO.File.Copy(element.AssociationURIFullPath, newFileNameFullPath);

                        Element newElement = elementControl.CreateNewElement(ElementType.Note, " --- " + fnw.FileName);
                        newElement.AssociationType = ElementAssociationType.File;
                        newElement.AssociationURI = fnw.FileName + fileExt;
                        newElement.TailImageSource = FileTypeHandler.GetIcon(newElement.AssociationType, newElement.AssociationURIFullPath);

                        elementControl.InsertElement(newElement, element.ParentElement, element.Position);

                        LogControl.Write(
                            newElement,
                            LogEventAccess.AssociationContextMenu,
                            LogEventType.NewVersion,
                            LogEventStatus.End,
                            LogEventInfo.NewName + LogControl.COMMA + fnw.FileName + fileExt);
                    }
                    else
                    {
                        LogControl.Write(
                            element,
                            LogEventAccess.AssociationContextMenu,
                            LogEventType.NewVersion,
                            LogEventStatus.Cancel,
                            null);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Oops!\nSomething unexpected happened, please close this Planz window and reopen.");
                //MessageBox.Show("AssociationDropDownMenu_NewVersion\n" + ex.Message);

                LogControl.Write(
                    element,
                    LogEventAccess.AssociationContextMenu,
                    LogEventType.NewVersion,
                    LogEventStatus.Error,
                    LogEventInfo.ErrorMessage + LogControl.COMMA + ex.Message);
            }
        }
Ejemplo n.º 2
0
        private void AssociationDropDownMenu_Rename(object sender, RoutedEventArgs e)
        {
            MenuItem mi = sender as MenuItem;
            Element element = mi.DataContext as Element;
            try
            {
                if (element != null)
                {
                    FileNameWindow fnw = new FileNameWindow(element.AssociationURIFullPath, "Please rename:");
                    if (fnw.ShowDialog().Value)
                    {
                        if (element.IsLocalHeading)
                        {
                            if (elementControl.CheckOpenFiles(element))
                            {
                                return;
                            }

                            string newFolderPath = System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(element.Path)) + System.IO.Path.DirectorySeparatorChar +
                                fnw.FileName + System.IO.Path.DirectorySeparatorChar;
                            string previousPath = element.Path;
                            element.Path = newFolderPath;
                            elementControl.RenameFolder(element, previousPath);
                        }
                        else
                        {
                            string newFileNameFullPath = System.IO.Path.GetDirectoryName(element.AssociationURIFullPath) + System.IO.Path.DirectorySeparatorChar +
                                fnw.FileName + System.IO.Path.GetExtension(element.AssociationURIFullPath);
                            System.IO.File.Move(element.AssociationURIFullPath, newFileNameFullPath);
                            element.AssociationURI = System.IO.Path.GetFileName(newFileNameFullPath);
                            elementControl.UpdateElement(element);
                        }

                        LogControl.Write(
                            element,
                            LogEventAccess.AssociationContextMenu,
                            LogEventType.Rename,
                            LogEventStatus.NULL,
                            null);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Oops!\nSomething unexpected happened, please close this Planz window and reopen.");
                //MessageBox.Show("AssociationDropDownMenu_Rename\n" + ex.Message);

                LogControl.Write(
                    element,
                    LogEventAccess.AssociationContextMenu,
                    LogEventType.Rename,
                    LogEventStatus.Error,
                    LogEventInfo.ErrorMessage + LogControl.COMMA + ex.Message);
            }
        }
Ejemplo n.º 3
0
        private void HandleICC(Element element, ICCAssociationType type)
        {
            // Note: defaultName does NOT contain file extension
            string defaultName = String.Empty;

            bool insertBelow = true;
            TextBox tb = GetTextBox(element);
            if (tb.SelectionStart == 0 && tb.Text != String.Empty)
            {
                insertBelow = false;
            }

            if (tb.SelectedText != String.Empty)
            {
                defaultName = tb.SelectedText;
                insertBelow = true;
            }
            else
            {
                defaultName = element.NoteText;
            }

            if (defaultName.Length > StartProcess.MAX_EXTRACTNAME_LENGTH)
                defaultName = defaultName.Substring(0, StartProcess.MAX_EXTRACTNAME_LENGTH);
            while (defaultName.EndsWith("."))
                defaultName = defaultName.TrimEnd('.');

            switch (type)
            {
                case ICCAssociationType.TwitterUpdate:
                    TwitterWindow tw = new TwitterWindow(defaultName);
                    if (tw.ShowDialog().Value == true)
                    {
                        Tweet tweet = new Tweet{ Username = tw.Username, Password = tw.Password, Message = tw.Tweet, };
                        elementControl.ICC(element, tweet, insertBelow, type);
                    }
                    break;
                case ICCAssociationType.OutlookEmailMessage:
                    if (defaultName.Trim() == String.Empty)
                    {
                        defaultName = "New Email";
                    }
                    elementControl.ICC(element, defaultName, insertBelow, type);
                    break;
                default:
                    string fileFullName = element.Path + ICCFileNameHandler.GenerateFileName(defaultName, type);
                    FileNameWindow fnw = new FileNameWindow(fileFullName, type);
                    if (fnw.ShowDialog().Value == true)
                    {
                        elementControl.ICC(element, fnw.FileName, insertBelow, type);
                    }
                    break;
            };

            GetFocusToElementTextBox(elementControl.CurrentElement, elementControl.CurrentElement.NoteText.Length, false, false);
        }