Example #1
0
        internal void HandleFileDragDrop(object sender, DragEventArgs e)
        {
            if (!CanDrop())
                return;

            float worldX, worldY;
            Renderer.Self.Camera.ScreenToWorld(Cursor.X, Cursor.Y, out worldX, out worldY);

            string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

            // If only one file was dropped, see if we're over an instance that can take a file
            if (files.Length == 1)
            {
                if (!ValidExtension(files[0]))
                    return;

                InstanceSave instance = FindInstanceWithSourceFile(worldX, worldY);
                if (instance != null)
                {
                    string fileName = FileManager.MakeRelative(files[0], FileLocations.Self.ProjectFolder);

                    MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                    mbmb.MessageText = "What do you want to do with the file " + fileName;

                    mbmb.AddButton("Set source file on " + instance.Name, DialogResult.OK);
                    mbmb.AddButton("Add new Sprite", DialogResult.Yes);
                    mbmb.AddButton("Nothing", DialogResult.Cancel);

                    var result = mbmb.ShowDialog();

                    if (result == DialogResult.OK)
                    {
                        SelectedState.Self.SelectedStateSave.SetValue(instance.Name + ".SourceFile", fileName, instance);
                        SaveAndRefresh();
                        return;
                    }
                    else if (result == DialogResult.Cancel)
                    {
                        return;
                    }
                    // continue for DialogResult.Yes
                }
            }

            bool shouldUpdate = false;

            foreach (string file in files)
            {
                if (!ValidExtension(file))
                    continue;

                string fileName = FileManager.MakeRelative(file, FileLocations.Self.ProjectFolder);
                AddNewInstanceForDrop(fileName, worldX, worldY);
                shouldUpdate = true;
            }

            if (shouldUpdate)
                SaveAndRefresh();
        }
Example #2
0
        public static void ShowReadOnlyDialog(string fileName)
        {
            MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
            mbmb.MessageText = "Could not save the file\n\n" + fileName + "\n\nbecause it is read-only." +
                "What would you like to do?";

            mbmb.AddButton("Nothing (file will not save, Gum will continue to work normally)", DialogResult.Cancel);
            mbmb.AddButton("Open folder containing file", DialogResult.OK);

            var dialogResult = mbmb.ShowDialog();

            if (dialogResult == DialogResult.OK)
            {
                // Let's select the file instead of just opening the folder
                //string folder = FileManager.GetDirectory(fileName);
                //Process.Start(folder);
                Process.Start("explorer.exe", "/select," + fileName);
            }
        }