示例#1
0
        /// <summary>
        /// Event Handler for Rename Event Handler
        /// </summary>
        protected void RenameFileHandler(object o, EventArgs args)
        {
            string newFileName = nameConflictEntry.Text;

            TreeModel      tModel;
            ConflictHolder ch = null;

            TreeSelection tSelect = ConflictTreeView.Selection;

            if (tSelect.CountSelectedRows() == 1)
            {
                Array    treePaths = tSelect.GetSelectedRows(out tModel);
                TreeIter iter;
                if (ConflictTreeStore.GetIter(out iter, (TreePath)treePaths.GetValue(0)))
                {
                    ch = (ConflictHolder)tModel.GetValue(iter, 0);
                    Conflict lnc = ch.LocalNameConflict;
                    Conflict snc = ch.ServerNameConflict;

                    try
                    {
                        if (snc != null && ifolder.CurrentUserRights == "ReadOnly")
                        {
                            ifws.RenameAndResolveConflict(snc.iFolderID,
                                                          snc.ConflictID,
                                                          newFileName);
                        }
                        else
                        {
                            if (lnc != null)
                            {
                                //server file rename is not certified so we are not allowing the local file renamed to same name
                                // this is a work around later we will fix the sever rename as well
                                if (newFileName == oldFileName)
                                {
                                    iFolderMsgDialog dg = new iFolderMsgDialog(
                                        this,
                                        iFolderMsgDialog.DialogType.Error,
                                        iFolderMsgDialog.ButtonSet.Ok,
                                        "",
                                        Util.GS("Name Already Exists"),
                                        Util.GS("The specified name already exists.  Please choose a different name."),
                                        null);
                                    dg.Run();
                                    dg.Hide();
                                    dg.Destroy();
                                    return;
                                }
                                Conflict[] conflictList = ifws.GetiFolderConflicts(lnc.iFolderID);

                                ifws.ResolveNameConflict(lnc.iFolderID, lnc.ConflictID, newFileName);

                                foreach (Conflict con in conflictList)
                                {
                                    if (con.IsNameConflict && con.ServerName != null)
                                    {
                                        if (String.Compare(lnc.LocalFullPath, con.ServerFullPath, true) == 0)
                                        {
                                            if (ifolder.CurrentUserRights == "ReadOnly")
                                            {
                                                ifws.RenameAndResolveConflict(con.iFolderID, con.ConflictID, con.ServerName);
                                                break;
                                            }
                                            else
                                            {
                                                ifws.ResolveNameConflict(con.iFolderID, con.ConflictID, con.ServerName);
                                                break;
                                            }
                                        }
                                    }
                                }
                                ifws.SynciFolderNow(lnc.iFolderID);
                            }
                            // If this is a name conflict because of case-sensitivity
                            // on Linux, there won't be a conflict on the server.
                            if (snc != null)
                            {
                                //server file rename is not certified so we are not allowing the server file rename, rather rename to the same name
                                // this is a work around later we will fix the sever rename as well
                                if (newFileName != oldFileName)
                                {
                                    iFolderMsgDialog dg = new iFolderMsgDialog(
                                        this,
                                        iFolderMsgDialog.DialogType.Error,
                                        iFolderMsgDialog.ButtonSet.Ok,
                                        "",
                                        Util.GS("Name Already Exists"),
                                        Util.GS("The specified name already exists.  Please choose a different name."),
                                        null);
                                    dg.Run();
                                    dg.Hide();
                                    dg.Destroy();
                                    return;
                                }

                                ifws.ResolveNameConflict(snc.iFolderID,
                                                         snc.ConflictID,
                                                         ch.Name);
                            }
                        }

                        ConflictTreeStore.Remove(ref iter);
                    }
                    catch (Exception e)
                    {
                        bool   bKnownError = true;
                        string headerText  = Util.GS("iFolder Conflict Error");
                        string errText     = Util.GS("An error was encountered while resolving the conflict.");

                        if (e.Message.IndexOf("Malformed") >= 0)
                        {
                            headerText = Util.GS("Invalid Characters in Name");
                            errText    = string.Format(Util.GS("The specified name contains invalid characters.  Please choose a different name and try again.\n\nNames must not contain any of these characters: {0}"),
                                                       simws.GetInvalidSyncFilenameChars());
                        }
                        else if (e.Message.IndexOf("already exists") >= 0)
                        {
                            headerText = Util.GS("Name Already Exists");
                            errText    = Util.GS("The specified name already exists.  Please choose a different name.");
                        }
                        else
                        {
                            //bKnownError = false;
                        }

                        iFolderMsgDialog dg = new iFolderMsgDialog(
                            this,
                            iFolderMsgDialog.DialogType.Error,
                            iFolderMsgDialog.ButtonSet.Ok,
                            "",
                            headerText,
                            errText,
                            bKnownError ? null : e.Message);
                        dg.Run();
                        dg.Hide();
                        dg.Destroy();

                        tSelect.SelectIter(iter);

                        // FIXME: Figure out why if the user clicks the "Save" button the focus doesn't return back to the entry text box.  (i.e., the next line of code isn't really doing anything)
                        this.FocusChild = nameConflictEntry;
                        return;
                    }

                    UpdateFields(null, false);
                }
            }
        }