X-Git-Url: https://ecere.com/cgi-bin/gitweb.cgi?p=ede;a=blobdiff_plain;f=explorer%2Fsrc%2FExplorerWindow.ec;h=eb690c357346f4d565071809d44ed97c94a6e34e;hp=5a5b37fcd6c6ed1062d84cebb6b9da580898cec7;hb=9e16f30612eb73393d7fde121037b1546c98c22b;hpb=ddec1cfe7674fc97b59db1fae712107c596e6444 diff --git a/explorer/src/ExplorerWindow.ec b/explorer/src/ExplorerWindow.ec index 5a5b37f..eb690c3 100644 --- a/explorer/src/ExplorerWindow.ec +++ b/explorer/src/ExplorerWindow.ec @@ -1,58 +1,1446 @@ -public import "ecere" +import "Explorer" +//import "IconBag" +//import "ToolBar" +import "SearchBox" -private: -define guiApp = ((GuiApplication)__thisModule); -define selectionColor = guiApp.currentSkin.selectionColor; //Color { 10, 36, 106 }; +#ifdef _DEBUG + define title = "Ecere Explorer (Debug)"; +#else + define title = "Ecere Explorer"; +#endif -static char * iconNames[] = +/* +define backgroundColor = Color { 30, 40, 50 }; //Color { 20, 20, 60 }; +define foregroundColor = lightGray; //white; +define selectionColor = lightYellow; +define selectionText = Color { 20, 30, 40 }; +define toolBarBackgroundColor = backgroundColor;//white; //Color { 240, 240, 250 }; +define toolBarForegroundColor = foregroundColor;//white; //Color { 240, 240, 250 }; +*/ +define backgroundColor = Color { 155, 170, 160 }; +//define backgroundColor = Color { 250, 250, 255 }; +//define backgroundColor = beige;//white; //Color { 128, 145, 175 }; //200, 224, 224 }; //lightGray; +define foregroundColor = Color { 45, 45, 45 };//black; +define selectionColor = Color { 80, 140, 110 };//app.currentSkin.selectionColor; +define selectionText = black;//app.currentSkin.selectionText; +define toolBarBackgroundColor = Color { 170, 187, 176 }; //backgroundColor;//white; //Color { 240, 240, 250 }; +define toolBarForegroundColor = foregroundColor;//white; //Color { 240, 240, 250 }; + +enum ExplorerToolId { - "<:ecere>tango/16x16/mimetypes/file-x-generic.png", /*none*/ - - "<:ecere>tango/16x16/mimetypes/file-x-generic.png", /*normalFile*/ - "<:ecere>tango/16x16/mimetypes/text-ews-work.png", /*ewsFile*/ - "<:ecere>tango/16x16/mimetypes/text-epj-assembly.png", /*epjFile*/ - "<:ecere>tango/16x16/mimetypes/text-ec-source.png", /*ecFile*/ - "<:ecere>tango/16x16/mimetypes/text-eh-header.png", /*ehFile*/ - "<:ecere>tango/16x16/mimetypes/text-c-source.png", /*cFile*/ - "<:ecere>tango/16x16/mimetypes/text-h-header.png", /*hFile*/ - "<:ecere>tango/16x16/mimetypes/text-cpp-source.png", /*cppFile*/ - "<:ecere>tango/16x16/mimetypes/text-hpp-header.png", /*hppFile*/ - "<:ecere>tango/16x16/mimetypes/text-x-generic.png", /*textFile*/ - "<:ecere>tango/16x16/mimetypes/text-html.png", /*webFile*/ - "<:ecere>tango/16x16/mimetypes/image-x-generic.png", /*pictureFile*/ - "<:ecere>tango/16x16/status/audio-volume-high.png", /*soundFile*/ - "<:ecere>tango/16x16/mimetypes/package-x-generic.png", /*archiveFile*/ - "<:ecere>tango/16x16/mimetypes/package-x-software.png", /*packageFile*/ - "<:ecere>tango/16x16/mimetypes/package-x-optical-disc.png", /*opticalMediaImageFile*/ - - "<:ecere>tango/16x16/places/folder.png", - "<:ecere>tango/16x16/status/folder-open.png", - "<:ecere>tango/16x16/devices/computer.png", - "<:ecere>tango/16x16/devices/drive-harddisk.png", - "<:ecere>tango/16x16/places/folder-remote.png", - "<:ecere>tango/16x16/devices/media-optical.png", - "<:ecere>tango/16x16/devices/drive-removable-media.png", - "<:ecere>tango/16x16/devices/media-floppy.png", - "<:ecere>tango/16x16/places/network-workgroup.png", - "<:ecere>tango/16x16/places/network-server.png", - "<:ecere>tango/16x16/places/folder-remote.png", - - "<:ecere>tango/16x16/mimetypes/package-x-generic.png", /*treeLoader*/ - "<:ecere>tango/16x16/places/start-here.png" /*lineNumbers*/ + none, + newWindow, goBack, goForward, goUp, goHome, + newFile, newFolder, + browse, + panelTree, panelSearch, + addressBar, + refresh, + viewList, viewDetails, viewIcons, viewCards, viewShowcase, viewTree, viewCustom, + previewPictures, + + searchInFileName, + inFileNameMatchCase, + inFileNameMatchWord, + searchInFileContent, + inFileContentMatchCase, + inFileContentMatchWord, + searchInSubDirs, + searchStart, + searchStop, + + hasHeader }; -public class FileSystemToolWindow : public Window +enum Icon +{ + missing, + newWindow, goBack, goForward, goUp, goHome, newFile, newFolder, + browse, + panelTree, panelSearch, + addressBar, + refresh, + viewList, viewDetails, viewIcons, viewCards, viewShowcase, viewTree, viewCustom, + previewPictures, + searchInFileName, inFileNameMatchCase, inFileNameMatchWord, + searchInFileContent, inFileContentMatchCase, inFileContentMatchWord, + searchInSubDirs, searchStart, searchStop, + hasHeader +}; +static const char * iconNames[Icon::enumSize] = { - BitmapResource icons[FileItemType]; + "<:ecere>emblems/unreadable.png", /* missing */ + + "<:ecere>actions/windowNew.png", /* newWindow */ + "<:ecere>actions/goPrevious.png", /* goBack */ + "<:ecere>actions/goNext.png", /* goForward */ + "<:ecere>actions/goUp.png", /* goUp */ + "<:ecere>actions/goHome.png", /* goHome */ + "<:ecere>mimeTypes/file.png", /* newFile */ + "<:ecere>actions/folderNew.png", /* newFolder */ + + ":browse.png", /* browse */ + + ":panel-tree.png", /* panelTree */ + "<:ecere>actions/editFind.png", /* panelSearch */ + + "", /* addressBar */ + + "<:ecere>actions/viewRefresh.png", /* refresh */ - FileSystemToolWindow() + ":view-list.png", /* viewList */ + ":view-details.png", /* viewDetails */ + ":view-icons.png", /* viewIcons */ + ":view-cards.png", /* viewCards */ + ":view-showcase-right.png", /* viewShowcase */ + ":panel-tree.png", /* viewTree */ + ":view-custom.png", /* viewCustom */ + + "<:ecere>mimeTypes/image.png", /* previewPictures */ + + "", /* searchInFileName */ + "<:ecere>emblems/unreadable.png", /* inFileNameMatchCase */ + "<:ecere>emblems/unreadable.png", /* inFileNameMatchWord */ + "", /* searchInFileContent */ + "<:ecere>emblems/unreadable.png", /* inFileContentMatchCase */ + "<:ecere>emblems/unreadable.png", /* inFileContentMatchWord */ + ":browse.png", /* searchInSubDirs */ + "<:ecere>actions/editFind.png", /* searchStart */ + "<:ecere>emblems/unreadable.png", /* searchStop */ + "<:ecere>emblems/unreadable.png" /* hasHeader */ +}; + +class IconToolButton : ToolButton +{ + //inactive = true; + //bitmapAlignment = left; + + property Icon icon { - FileItemType c; - for(c = 0; c < FileItemType::enumSize; c++) + set { - icons[c] = BitmapResource { iconNames[c], alphaBlend = true }; - AddResource(icons[c]); + bitmap = BitmapResource { fileName = iconNames[value], alphaBlend = true }; + //id = value; } } } +class ToggleIconToolButton : IconToolButton +{ + toggle = true; +} + + +class ExplorerWindow : Window +{ + text = title; + background = backgroundColor; + borderStyle = sizable; + hasMaximize = true; + hasMinimize = true; + hasClose = true; + hasMenuBar = true; + //tabCycle = true; + size = { 840, 480 }; + minClientSize = { 600, 300 }; + nativeDecorations = true; + tabCycle = true; + icon = { ":explorerIcon.png" }; + + /* + bool userMode; + bool clipboard; + + int treeSplit; + int searchSplit; + + ExplorerToolId lastViewId; +*/ + + bool treeInitialized; + int historyIndex; + Array history { }; + + + menu = Menu { }; + + Menu fileMenu { menu, "File", f }; + Menu windowMenu { menu, "Window", w }; + MenuItem itemNewWindow { windowMenu, "New Window", n, NotifySelect = NewWindow_NotifySelect }; + + bool NewWindow_NotifySelect(MenuItem selection, Modifiers mods) + { + //ExplorerWindow { }.Create(); + ExplorerWindow w { };//.Create(); + w.location = location; + w.view.autoLoad = true; + w.Create(); + w.Activate(); // tocheck: not working? + return true; + } + +#if 0 + IconBag iconBag + { + //window = guiApp.desktop; + window = this; + alphaBlend = true; + iconNames = + [ + ]; + }; +#endif + + Stacker stack + { + this; + gap = 0; + direction = vertical; + background = backgroundColor; + opacity = 0.0f; + tabCycle = true; + + flipper = panels; + flipSpring = true; + + anchor = { left = 0, top = 0, right = 0, bottom = 0 }; + //moveable = false; + }; + + ToolBar/**/ toolBar + { + stack, this; + size = { h = 32 }; + //moveable = false; + borderStyle = none; + background = toolBarBackgroundColor; + tabCycle = true; + + //iconBag = iconBag; + inactive = false; + + flipper = addressBar; + flipSpring = true; + +#if 0 + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + bool noViewActivation = false; + ExplorerToolId id = (ExplorerToolId)button.id; + switch(id) + { + case none: + break; + case newWindow: + { + noViewActivation = true; + NewWindow_NotifySelect(null, 0); + break; + } + case goBack: + case goForward: + historyIndex += id == goBack ? -1 : 1; + GoToHistoryIndex(/*false, false, */false); + break; + case goHome: + { + char * home = getenv("HOME"); + if(home && home[0] && FileExists(home).isDirectory) + location = home;//GoTo(home, false, false); + break; + } + case goUp: + { + char * path = view.path; + char * newPath = new char[strlen(path)+1]; + StripLastDirectory(path, newPath); + if(!newPath[0]) + { + newPath[0] = '/'; + newPath[1] = 0; + } + location = newPath;//GoTo(newPath, false, false); + delete newPath; + break; + } + case newFile: + NewFile(view, null, 0); + break; + case newFolder: + NewFolder(view, null, 0); + break; + case panelTree: + SearchStop(); + //ToggleSearchMode(false); + tree.visible = button.checked; + split.visible = button.checked; + if(button.checked) + { + split.rightPane = view; + view.anchor = { top = 0, bottom = 0, right = 0 }; + location = addressBar.path;//GoTo(addressBar.path, false, false); + ReadyTree(); + } + else + { + split.rightPane = null; + view.anchor = { left = 2, top = 0, bottom = 0, right = 0 }; + } + //search.visible = !button.checked; + break; + case panelSearch: + ToggleSearchMode(button.checked); + + //tree.visible = false; //!button.checked; + //split.visible = false; //!button.checked; + if(button.checked) + { + /*split.rightPane = view; + view.anchor = { top = 0, bottom = 0, right = 0 };*/ + //split.rightPane = null; + //view.anchor = { left = 2, top = 0, bottom = 0, right = 0 }; + + //SearchStart(); + searchInFileName.Activate(); + } + else + { + //split.rightPane = null; + //view.anchor = { left = 2, top = 0, bottom = 0, right = 0 }; + + location = addressBar.path;//GoTo(addressBar.path, false, false); + } + break; + case refresh: + Refresh(); + break; + case previewPictures: + view.previewPictures = button.checked; + view.Refresh(); + break; + case viewList: + view.details = false; + view.treeBranches = false; + view.Refresh(); + break; + case viewDetails: + view.details = true; + view.treeBranches = false; + view.Refresh(); + break; + case viewIcons: + case viewCards: + //SwitchViews(toolId); + view.details = false; + view.treeBranches = false; + view.Refresh(); + break; + case viewShowcase: + view.preview = button.checked; + view.Refresh(); + break; + case viewTree: + view.treeBranches = button.checked; + view.Refresh(); + break; + case hasHeader: + view.hasHeader ^= true; + break; + } + if(!noViewActivation) + view.Activate(); + return true; + } +#endif + }; + + Window { toolBar, size = { w = 8 }, inactive = true }; + IconToolButton goBack { toolBar, this, icon = goBack, hotKey = { left, alt = true }, toolTip = "Back", disabled = true; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + historyIndex += -1; + GoToHistoryIndex(/*false, false, */false); + view.Activate(); + return true; + } + }; + Window { toolBar, size = { w = 2 }, inactive = true }; + IconToolButton goForward { toolBar, this, icon = goForward, hotKey = { right, alt = true }, toolTip = "Forward", disabled = true; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + historyIndex += 1; + GoToHistoryIndex(/*false, false, */false); + view.Activate(); + return true; + } + }; + Window { toolBar, size = { w = 2 }, inactive = true }; + IconToolButton refresh { toolBar, this, icon = refresh, hotKey = { r, ctrl = true }, toolTip = "Refresh"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + Refresh(); + view.Activate(); + return true; + } + }; + Window { toolBar, size = { w = 2 }, inactive = true }; + IconToolButton goHome { toolBar, this, icon = goHome, hotKey = { h, ctrl = true }, toolTip = "Go Home"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + char * home = getenv("HOME"); + if(home && home[0] && FileExists(home).isDirectory) + location = home;//GoTo(home, false, false); + view.Activate(); + return true; + } + }; + Window { toolBar, size = { w = 8 }, inactive = true }; + PathBox addressBar + { + toolBar, this; + size = { 300, 22 };//, icon = addressBar; + typeExpected = directory; + borderStyle = deep; + background = toolBarBackgroundColor; + foreground = toolBarForegroundColor; + selectionColor = selectionColor; + selectionText = selectionText; + toolTip = "Location"; + + bool OnKeyDown(Key key, unichar ch) + { + if((SmartKey)key == enter) + { + // how to make enter effect a modification + // how to implement in PathBox + } + return true; + } + + bool NotifyModified(PathBox pathBox) + { + location = pathBox.path;//GoTo(pathBox.path, false, false); + return true; + } + }; + //FlipStacker { toolBar, spring = previous }; + Window { toolBar, size = { w = 8 }, inactive = true }; + IconToolButton newFile { toolBar, this, icon = newFile, hotKey = { l, ctrl = true }, toolTip = "Create New File"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + NewFile(view, null, 0); + view.Activate(); + return true; + } + }; + Window { toolBar, size = { w = 2 }, inactive = true }; + IconToolButton newFolder { toolBar, this, icon = newFolder, hotKey = { d, ctrl = true }, toolTip = "Create New Folder"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + NewFolder(view, null, 0); + view.Activate(); + return true; + } + }; + Window { toolBar, size = { w = 8 }, inactive = true }; + IconToolButton goUp { toolBar, this, icon = goUp, hotKey = { up, alt = true }, toolTip = "Go to Parent Folder"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + const char * path = view.path; + char * newPath = new char[strlen(path)+1]; + StripLastDirectory(path, newPath); + if(!newPath[0]) + { + newPath[0] = '/'; + newPath[1] = 0; + } + location = newPath;//GoTo(newPath, false, false); + delete newPath; + view.Activate(); + return true; + } + }; + Window { toolBar, size = { w = 8 }, inactive = true }; + //GroupToggleIconToolButton selectedPanel; + ToggleIconToolButton panelTree { toolBar, this, icon = panelTree/*, selected = &selectedPanel*//*, checked = true*/, toolTip = "Toggle Tree Panel"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + SearchStop(); + //ToggleSearchMode(false); + tree.visible = button.checked; + split.visible = button.checked; + if(button.checked) + { + split.rightPane = view; + view.anchor = { top = 0, bottom = 0, right = 0 }; + location = addressBar.path;//GoTo(addressBar.path, false, false); + ReadyTree(); + } + else + { + split.rightPane = null; + view.anchor = { left = 2, top = 0, bottom = 0, right = 0 }; + } + //search.visible = !button.checked; + view.Activate(); + return true; + } + }; + ToggleIconToolButton panelSearch { toolBar, this, icon = panelSearch, hotKey = { f, ctrl = true }/*, selected = &selectedPanel*/, toolTip = "Toggle Search"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + ToggleSearchMode(button.checked); + + //tree.visible = false; //!button.checked; + //split.visible = false; //!button.checked; + if(button.checked) + { + /*split.rightPane = view; + view.anchor = { top = 0, bottom = 0, right = 0 };*/ + //split.rightPane = null; + //view.anchor = { left = 2, top = 0, bottom = 0, right = 0 }; + + //SearchStart(); + searchInFileName.Activate(); + } + else + { + //split.rightPane = null; + //view.anchor = { left = 2, top = 0, bottom = 0, right = 0 }; + + location = addressBar.path;//GoTo(addressBar.path, false, false); + } + view.Activate(); + return true; + } + }; + //selectedPanel = panelTree; + Window { toolBar, size = { w = 8 }, inactive = true }; + /*OptionIconToolButton selectedView; + OptionIconToolButton viewList { toolBar, this, icon = viewList, selected = &selectedView, checked = true }; + OptionIconToolButton viewDetails { toolBar, this, icon = viewDetails, selected = &selectedView }; + OptionIconToolButton viewIcons { toolBar, this, icon = viewIcons, selected = &selectedView }; + OptionIconToolButton viewTiles { toolBar, this, icon = viewCards, selected = &selectedView }; + OptionIconToolButton viewShowcase { toolBar, this, icon = viewShowcase, selected = &selectedView }; + OptionIconToolButton viewTree { toolBar, this, icon = viewTree, selected = &selectedView }; + selectedView = viewList;*/ + //ToggleIconToolButton viewList { toolBar, this, icon = viewList, checked = true }; + /*case viewList: + view.details = false; + view.treeBranches = false; + view.Refresh(); + break;*/ + ToggleIconToolButton viewDetails { toolBar, this, icon = viewDetails, toolTip = "Toggle Listing Details"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + view.details = button.checked; + view.treeBranches = false; + view.Refresh(); + view.Activate(); + return true; + } + }; + /*case viewCards: + //SwitchViews(toolId); + view.details = false; + view.treeBranches = false; + view.Refresh(); + break;*/ + //ToggleIconToolButton viewIcons { toolBar, this, icon = viewIcons }; + //ToggleIconToolButton viewTiles { toolBar, this, icon = viewCards }; + ToggleIconToolButton viewShowcase { toolBar, this, icon = viewShowcase, toolTip = "Toggle Showcase"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + view.preview = button.checked; + view.Refresh(); + view.Activate(); + return true; + } + }; + ToggleIconToolButton viewTree { toolBar, this, icon = viewTree, hotKey = { t, ctrl = true }, toolTip = "Toggle Tree Listing"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + view.treeBranches = button.checked; + view.Refresh(); + view.Activate(); + return true; + } + }; + Window { toolBar, size = { w = 8 }, inactive = true }; + ToggleIconToolButton previewPictures { toolBar, this, icon = previewPictures, toolTip = "Toggle Picture Preview"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + view.previewPictures = button.checked; + view.Refresh(); + view.Activate(); + return true; + } + }; + + Window { toolBar, size = { w = 8 }, inactive = true }; + ToggleIconToolButton hasHeader { toolBar, this, icon = hasHeader, toolTip = "Toggle Listing Header"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + view.hasHeader ^= true; + view.Activate(); + return true; + } + }; + Window { toolBar, size = { w = 8 }, inactive = true }; + IconToolButton newWindow { toolBar, this, icon = newWindow, hotKey = { w, ctrl = true }, toolTip = "Open New Window"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + NewWindow_NotifySelect(null, 0); + return true; + } + }; + Window { toolBar, size = { w = 8 }, inactive = true }; + + +#if 0 + /*void OnDestroy() + { + iconBag.window = null; + delete iconBag; + }*/ + + bool OnLoadGraphics() + { + iconBag.Load(); + return true; + } + + void OnUnloadGraphics() + { + iconBag.Unload(); + } +#endif + + Stacker panels + { + stack, this; + gap = 0; + direction = horizontal; + opacity = 0.0f; + tabCycle = true; + + anchor.left = 0; + //anchor.bottom = 0; + anchor.right = 0; + + //size = { h = 400 }; + }; + + //FlipStacker flipStack { stack, spring = previous }; + + //Window searchSpace { stack, size = { h = 32 }, background = toolBarBackgroundColor, inactive = true, opacity = 0.0f }; + + ToolBar/**/ searchBar + { + stack, this; + size = { h = 32 }; + visible = false; + //moveable = false; + borderStyle = none; + background = toolBarBackgroundColor; + tabCycle = true; + //iconBag = iconBag; + inactive = false; + + flipper = searchInFileContent; + flipSpring = true; + +#if 0 + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + ExplorerToolId id = (ExplorerToolId)button.id; + switch(id) + { + case none: + break; + case searchStart: + SearchStart(); + break; + case searchStop: + SearchStop(); + break; + } + view.Activate(); + return true; + } +#endif + }; + + Window { searchBar, size = { w = 8 }, inactive = true }; + //Label { searchBar, this, labeledWindow = searchInFileName}; + //Window { searchBar, size = { w = 2 }, inactive = true }; + SearchBox searchInFileName + { + searchBar, this; + size = { 200, 22 };//, icon = searchInFileName; + borderStyle = deep; + background = toolBarBackgroundColor; + foreground = toolBarForegroundColor; + selectionColor = selectionColor; + selectionText = selectionText; + //text = "File Name:"; + caption = "Search File Names"; + toolTip = "Search File Names"; + + bool NotifyKeyDown(EditBox editBox, Key key, unichar ch) + { + if((SmartKey)key == enter) + SearchStart(); + return true; + } + + /*bool NotifyActivate(Window window, bool active, Window previous) + { + if(active) + { + toolBar.focusHolder = window; + } + return true; + }*/ + }; + Window { searchBar, size = { w = 2 }, inactive = true }; +#ifndef __WIN32__ + ToggleIconToolButton inFileNameMatchCase { searchBar, this, icon = inFileNameMatchCase, toolTip = "Toggle Match Case"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + return true; + } + }; +#endif + ToggleIconToolButton inFileNameMatchWord { searchBar, this, icon = inFileNameMatchWord, toolTip = "Toggle Match Whole Word"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + return true; + } + }; + Window { searchBar, size = { w = 8 }, inactive = true }; + //Label { searchBar, this, labeledWindow = searchInFileContent}; + //Window { searchBar, size = { w = 2 }, inactive = true }; + SearchBox searchInFileContent + { + searchBar, this; + size = { 200, 22 };//, icon = searchInFileContent; + borderStyle = deep; + background = toolBarBackgroundColor; + foreground = toolBarForegroundColor; + selectionColor = selectionColor; + selectionText = selectionText; + //text = "File Content:"; + caption = "Search File Contents"; + toolTip = "Search File Contents"; + + bool NotifyKeyDown(EditBox editBox, Key key, unichar ch) + { + if((SmartKey)key == enter) + SearchStart(); + return true; + } + + /*bool NotifyActivate(Window window, bool active, Window previous) + { + if(active) + toolBar.focusHolder = window; + return true; + }*/ + }; + //FlipStacker { searchBar, spring = previous }; + ToggleIconToolButton inFileContentMatchCase { searchBar, this, icon = inFileContentMatchCase, toolTip = "Toggle Match Case"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + return true; + } + }; + ToggleIconToolButton inFileContentMatchWord { searchBar, this, icon = inFileContentMatchWord, toolTip = "Toggle Match Whole Word"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + return true; + } + }; + Window { searchBar, size = { w = 8 }, inactive = true }; + ToggleIconToolButton searchInSubDirs { searchBar, this, icon = searchInSubDirs, checked = true, toolTip = "Toggle Include Subfolders"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + return true; + } + }; + Window { searchBar, size = { w = 8 }, inactive = true }; + IconToolButton searchStart { searchBar, this, icon = searchStart, hotKey = { s, ctrl = true }, toolTip = "Start Search"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + SearchStart(); + view.Activate(); + return true; + } + }; + Window { searchBar, size = { w = 8 }, inactive = true }; + IconToolButton searchStop { searchBar, this, icon = searchStop, hotKey = { escape }, disabled = true, toolTip = "Stop Search"; + bool NotifyClicked(Button button, int x, int y, Modifiers mods) + { + SearchStop(); + view.Activate(); + return true; + } + }; + Window { searchBar, size = { w = 8 }, inactive = true }; + + + + //Window { searchBar, size = { h = 1 } }; + + /*SearchPanel searchPanel + { + panels, this; + };*/ + + /*Window hack + { + panels, this; + anchor.top = 0; + anchor.bottom = 0; + anchor.right = 0; + borderStyle = none; + background = backgroundColor; + };*/ + + /*Tree*/FileSystemBox tree//; + { + panels, this; + size = { w = 240 }; + borderStyle = none; + background = backgroundColor; + foreground = foregroundColor; + selectionColor = selectionColor; + selectionText = selectionText; + visible = false; + anchor.top = 0; + anchor.bottom = 0; + //anchor = { left = 0, top = 0, bottom = 0 }; + + treeBranches = true; + foldersOnly = true; + autoLoad = false; + + bool NotifyNodeSelect(FileSystemBox box, FileSystemBoxSelection selection) + { + if(treeInitialized) + { + FileSystemNode node = selection.node; + if(node) + { + char p[MAX_LOCATION]; + node.GetPath(p); + location = node.path;//GoTo(node.path, false, true); + } + } + return true; + } + + /*bool NotifyActivate(Window window, bool active, Window previous) + { + if(active) + toolBar.focusHolder = window; + return true; + }*/ + }; + + PaneSplitter split + { + panels, this; + visible = false; + leftPane = tree;//, rightPane = view; + split = 300; + }; + + //FileSystemCache testCache; + FileSystemBox view + { + panels, this; + borderStyle = none; + background = backgroundColor; + foreground = foregroundColor; + selectionColor = selectionColor; + selectionText = selectionText; + anchor.top = 0; + anchor.bottom = 0; + anchor.right = 0; + //anchor = { left = 2, top = 0, bottom = 0, right = 0 }; + + locationBox = addressBar; + navigateFolders = true; + multiSelect = true; + autoLoad = false; + + //iteratorClass = class(FileSystemCacheIterator); + //iteratorClass = class(FileSystemIterator); + + bool NotifyIteratorInit(FileSystemBox box, FileSystemIterator fileSystemIterator) + { + //((FileSystemCacheIterator)fileSystemIterator).cache = testCache; + //((FileSystemIterator)fileSystemIterator) + return true; + } + + bool NotifyNodeOpen(FileSystemBox box, FileSystemBoxSelection selection) + { + FileSystemNode node = selection.node; + if(node) + { + if(node.type.isFile) + { + char path[MAX_LOCATION]; + //#ifndef __WIN32__ + // char command[MAX_LOCATION]; + // node.GetPath(path); + // /*_FileType t = node.type; + // if(t == ewsFile || t == epjFile || + // t == ecFile || t == ehFile || + // t == cppFile || t == hppFile || + // t == cFile || t == hFile || + // t == textFile || t == webFile)*/ + // sprintf(command, "gnome-open \"%s\"", path); + // /*else + // sprintf(command, "%s", path);*/ + // Execute(command); + //#else + node.GetPath(path); + ShellOpen(path); + //#endif + } + else if(node.type.isFolder) + location = node.path;//GoTo(node.path, true, false); + } + UpdateHistoryItem(selection); + return true; + } + + bool NotifyNodeSelect(FileSystemBox box, FileSystemBoxSelection selection) + { + if(!comparedLocations) + UpdateHistoryItem(selection); + return true; + } + + bool NotifyNodeMenu(FileSystemBox box, Menu menu, FileSystemBoxSelection selection) + { + char * text; + char * itemString; + FileSystemNode node = selection.node; + + //PrintLn(node.name); + if(box.selection.nodes.count == 1) + itemString = CopyString(node.name); + else + itemString = PrintString(box.selection.nodes.count, " items"); + text = PrintString("Open ", itemString); + MenuItem { menu, text, o, disabled = false; + NotifySelect = FileSystemBox::MenuOpen + /*bool FileSystemBox::NotifySelect(MenuItem selection, Modifiers mods) + { + for(node : this.selection.nodes) + { + // todo: somehow bring MenuOpen / OpenNode behavior ourside + } + return true; + }*/ + }; + //delete text; + if(node.type == folder) + { + text = PrintString("Open ", itemString, " in another window"); + MenuItem { menu, text, w, disabled = false; + bool FileSystemBox::NotifySelect(MenuItem selection, Modifiers mods) + { + for(node : this.selection.nodes) + { + ExplorerWindow ew { /*location = this.selection.node.path*/ };//.Create(); + ew.Create(); + ew.location = /*this.selection.*/node.path; + } + return true; + } + }; + //delete text; + MenuDivider { menu }; + text = PrintString("Open ", itemString, " in shell"); + MenuItem { menu, text, w, disabled = false; + bool FileSystemBox::NotifySelect(MenuItem selection, Modifiers mods) + { + for(node : this.selection.nodes) + { + if(node.stats.attribs) + ShellOpen(/*this.selection.*/node.path); + } + return true; + } + }; + //delete text; + MenuDivider { menu }; + MenuItem { menu, "Create File", w, NotifySelect = NewFile, disabled = false }; + MenuItem { menu, "Create Folder", w, NotifySelect = NewFolder, disabled = false }; + } + if(panelSearch.checked) + { + MenuDivider { menu }; + MenuItem { menu, "Open Containing Folder", f, NotifySelect = FileSystemBox::MenuOpen, disabled = false; + bool FileSystemBox::NotifySelect(MenuItem selection, Modifiers mods) + { + char path[MAX_LOCATION]; + StripLastDirectory(this.selection.node.path, path); + this.path = path; + return true; + } + }; + MenuItem { menu, "Open Containing Folder in another window", r, NotifySelect = FileSystemBox::MenuOpen, disabled = false; + bool FileSystemBox::NotifySelect(MenuItem selection, Modifiers mods) + { + char path[MAX_LOCATION]; + ExplorerWindow ew { /*location = this.selection.node.path*/ };//.Create(); + ew.Create(); + StripLastDirectory(this.selection.node.path, path); + ew.location = path; + return true; + } + }; + delete itemString; + } + if(node.isListItem/* && TODO: unless node is at root location*/) + { + MenuDivider { menu }; + MenuItem { menu, "Replace by Parent\tCtrl+R", r, NotifySelect = FileSystemBox::MenuReplaceListItemByContainingDir, disabled = false }; + } + else if(box.mode == list) + { + MenuDivider { menu }; + MenuItem { menu, "Replace List Item\tCtrl+R", r, NotifySelect = FileSystemBox::MenuReplaceListItemByChild, disabled = false }; + } + MenuDivider { menu }; + MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false }; + MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false }; + MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /*!clipboard*/ }; + MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false }; + //MenuDivider { menu }; + return true; + } + + /*bool NotifyActivate(Window window, bool active, Window previous) + { + if(active) + toolBar.focusHolder = window; + return true; + }*/ + }; + + FileSystemSearch searchThread + { + owner = this, fsb = view, tree = tree/*, searchPanel = this*/; + + /*bool ExplorerWindow::NotifyUpdateSearchLocation(FileSystemSearch search, char * location) + { + char string[MAX_LOCATION + 2048]; + sprintf(string, "%s (Searching %s)", title, location); + PrintLn(string); //view.results.text = string; + text = string; + return true; + }*/ + + bool ExplorerWindow::NotifySearchTerminated(FileSystemSearch search) + { + searchStop.disabled = true; + return true; + } + }; + + void ToggleSearchMode(bool inSearch) + { + SearchStop(); + //search.visible = inSearch; + //panelSearch.checked = inSearch; // <------ this is toggling panelSearch even though it shouldn't + //searchSpace.visible = !inSearch; + searchBar.visible = inSearch; + history[historyIndex].inSearch = inSearch; + view.pathColumn = inSearch; + /*if(inSearch) + searchThread.InitResults();*/ + if(inSearch && /*(*/searchInFileName.contents[0]/* || searchInFileContents.contents[0])*/) + SearchStart(); + } + + void ReadyTree() + { + if(tree.visible) + { + if(!treeInitialized) + { + tree.path = "/"; // this should be available as a parameter + treeInitialized = true; + } + tree.SelectLocation(view.path); + } + } + + void Refresh() + { + if(searchBar.visible) + SearchStart(); + else + { + if(tree.visible) + tree.Refresh(); + view.Refresh(); + } + } + + //void NewFile() + bool FileSystemBox::NewFile(MenuItem selection, Modifiers mods) + { + if(master._class == class(ExplorerWindow)) + { + ExplorerWindow ew = (ExplorerWindow)master; + if(CreateNewFileDialog { /*master = */ew/*, parent = parent*/, currentDirectory = selection ? ew.view.selection.node.path : ew.view.path }.Modal() == ok ) + ew.Refresh(); + } + return true; + } + + //void NewFolder() + bool FileSystemBox::NewFolder(MenuItem selection, Modifiers mods) + { + if(master._class == class(ExplorerWindow)) + { + ExplorerWindow ew = (ExplorerWindow)master; + if(CreateDirectoryDialog { /*master = */ew/*, parent = parent*/, currentDirectory = selection ? ew.view.selection.node.path : ew.view.path }.Modal() == ok ) + ew.Refresh(); + } + return true; + } + + //void GoTo(char * location/*, bool viewIsAtLocation, bool treeIsAtLocation*/) + property const char * location + { + set + { + HistoryItem item = null; + if(!history.count || fstrcmp(history[historyIndex].path, value)) + { + int c; + for(c = 0; c < history.count; c++) + if(!fstrcmp(history[c].path, value)) + break; + if(c == history.count) + { + item = { path = CopyString(value) }; + if(history.count) + { + while(historyIndex < history.count-1) + { + delete history[history.count-1].path; + history.count--; + } + } + history.Add(item); + historyIndex = history.count-1; + } + else + historyIndex = c; + } + GoToHistoryIndex(/*viewIsAtLocation, treeIsAtLocation, */item != null); + } + get { return view.path; } + } + + property Array comparedLocations + { + set + { + // dd + view.comparedPaths = value; + } + get + { + return view.comparedPaths; + } + } + + void GoToHistoryIndex(/*bool viewIsAtLocation, bool treeIsAtLocation, */bool updateHistoryItem) + { + bool viewIsAtLocation; + bool treeIsAtLocation; + HistoryItem item = history[historyIndex]; + + goBack.disabled = historyIndex == 0; + goForward.disabled = historyIndex == history.count-1; + goUp.disabled = !fstrcmp(item.path, "/"); + + viewIsAtLocation = !fstrcmp(item.path, tree.path); + treeIsAtLocation = !fstrcmp(item.path, view.path); + + if(!viewIsAtLocation) + { + if(item.inSearch != panelSearch.checked) + { + ToggleSearchMode(item.inSearch); + if(item.inSearch) + SearchStart(); + } + if(!item.inSearch) + /*{ + //SearchStart(); + } + else*/ + { + if(fstrcmp(view.path, item.path)) + view.path = item.path; + item.holdRecordingSelection = true; + view.SelectMultipleByPath(item.selection); + } + } + if(tree.visible && !treeIsAtLocation) + tree.SelectLocation(item.path); + + if(updateHistoryItem) + UpdateHistoryItem(view.selection); + } + + void UpdateHistoryItem(FileSystemBoxSelection selection) + { + if(history.count > historyIndex) // TODO: Review why this would happen... + { + HistoryItem item = history[historyIndex]; + + if(!item.holdRecordingSelection) + { + if(selection.node || (selection.nodes && selection.nodes.count)) + { + item.selection.Free(); + if(selection.nodes.count) + { + for(node : selection.nodes) + item.selection.Add(CopyString(node.path)); + } + else if(selection.node) + item.selection.Add(CopyString(selection.node.path)); + } + } + else + item.holdRecordingSelection = false; + } + } + + void SearchStart() + { + SearchStop(); + searchThread.active = true; + + searchThread.optionSubdirs = searchInSubDirs.checked == true; + searchThread.optionTree = view.treeBranches; //(options.subdirs.checked && options.tree.checked); + searchThread.optionBrowser = tree.visible; //(options.subdirs.checked && options.browser.checked); +#ifndef __WIN32__ + searchThread.optionNameMatchCase = inFileNameMatchCase.checked; +#else + searchThread.optionNameMatchCase = false; +#endif + searchThread.optionNameMatchWord = inFileNameMatchWord.checked; + searchThread.optionContentMatchCase = inFileContentMatchCase.checked; + searchThread.optionContentMatchWord = inFileContentMatchWord.checked; + + strcpy(searchThread.location, view.path); + strcpy(searchThread.nameSearch, searchInFileName.contents); + strcpy(searchThread.contentSearch, searchInFileContent.contents); + + //actions.startStop.text = "Stop Search"; + //actions.clear.disabled = false; + //view.results.Clear(); + //view.results.hasHeader = !searchThread.optionTree; + //view.results.treeBranches = searchThread.optionTree; + //view.browser.Clear(); + //ToggleBrowserDisplay(searchThread.optionBrowser); + + //view.browser.text = "Browser"; + /*{ + char string[MAX_LOCATION + 2048]; + sprintf(string, "%s (Searching %s)", title, view.path); + //PrintLn(string); //view.results.text = string; + text = string; + }*/ + searchThread.InitResults(); + searchThread.Create(); + searchStop.disabled = false; + //Update(null); + } + + bool SearchStop() + { + if(searchThread.active) + { + searchThread.terminate = true; + //searchStop.disabled = true; + app.Unlock(); + searchThread.Wait(); + app.Lock(); + return true; + } + return false; + } + + /*ExplorerSearch search + { + deep, this; + visible = false; + tabCycle = true; + size = Size { 624, 268 }; + anchor = Anchor { left = 0, top = 0, bottom = 0 }; + }; + + ExplorerViewSearch results;*/ + + /*Window viewHolder + { + parent = deep, master = this; + tabCycle = true; + anchor = Anchor { top = 0, bottom = 0, right = 0 }; + };*/ + + // Preview / Showcase + /*PreviewArea previewArea + { + panels, this; + };*/ + + //FlipStacker flipPanels { panels, spring = previous }; + + /*bool TreeNotifyBranchSelect(ExplorerTree tree, ExplorerFileBranch branch) + { + if(branch) + { + char path[MAX_LOCATION]; + branch.GetPath(path); + toolBar.addressBar.contents = path; + view.Load(branch); + } + return true; + }*/ + + /*bool ViewNotifyItemOpen(ExplorerView view, ExplorerFileItem item) + { + ExplorerFileBranch branch = tree.branch; + if(item && branch) + { + if(item.type.isFolderType) + { + ExplorerFileBranch child; + + if(!branch.loaded || !branch.childrenLoaded) + BranchLoad(branch, tree.tree); + + for(child = branch.children.first; child; child = child.next) + if(!strcmp(child.name, item.name)) + break; + + if(child) + { + if(branch.row.collapsed) + child.row.collapsed = true; + child.EnsureVisible(false); + tree.Select(child); + } + } + else + { + char path[MAX_LOCATION]; + branch.GetPath(path); + PathCat(path, item.name); + ShellOpen(path); + } + } + }*/ + + /*void SwitchViews(ExplorerToolId viewId) + { + ExplorerFileBranch branch = tree.branch; + view.Destroy(0); + switch(viewId) + { + case viewList: view = ExplorerViewList { parent = viewHolder, master = this }; break; + case viewDetails: view = ExplorerViewDetails { parent = viewHolder, master = this }; break; + case viewIcons: view = ExplorerViewIcons { parent = viewHolder, master = this }; break; + case viewCards: view = ExplorerViewCards { parent = viewHolder, master = this }; break; + case viewShowcase: view = ExplorerViewShowcase { parent = viewHolder, master = this }; break; + } + view.tabCycle = true; + view.previewPictures = toolBar.previewPictures.checked; + view.anchor = Anchor { left = 0, top = 0, bottom = 0, right = 0 }; + view.NotifyItemOpen = ViewNotifyItemOpen; + view.Create(); + view.Load(branch); + lastViewId = viewId; + }*/ + + /*void SearchLocation(char * location) + { + location = location;//GoTo(location); + search.location.editBox.contents = location; + }*/ + + bool OnPostCreate() + { + //userMode = true; + addressBar.path = view.path; + ReadyTree(); + view.Refresh(); + return true; + } + + bool OnClose(bool parentClosing) + { + SearchStop(); + return true; + } + + /*ExplorerWindow() + { + userMode = false; + + treeSplit = 300; + searchSplit = 200; + + view = ExplorerViewList + { + parent = viewHolder, master = this; + tabCycle = true; + previewPictures = toolBar.previewPictures.checked; + anchor = Anchor { left = 0, top = 0, bottom = 0, right = 0 }; + NotifyItemOpen = ViewNotifyItemOpen; + }; + lastViewId = viewList; + + tree.Load(); + view.Load(tree.root); + }*/ + + /*void InitTree() + { + }*/ + + /*void InitSearch() + { + }*/ +} + +//class TreeFileSystemBox : FileSystemBox { } + +class HistoryItem +{ + char * path; + bool holdRecordingSelection; + bool inSearch; + Array selection { }; + + ~HistoryItem() + { + delete path; + } +}